From 59203c63bb777a3bacec32fb8830fba33540e809 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:29 +0200 Subject: Adding upstream version 127.0. Signed-off-by: Daniel Baumann --- toolkit/actors/AutoCompleteChild.sys.mjs | 153 + toolkit/actors/AutoCompleteParent.sys.mjs | 107 +- .../aboutprocesses/content/aboutProcesses.js | 2 +- .../aboutwebauthn/content/aboutWebauthn.css | 2 +- .../components/antitracking/AntiTrackingUtils.cpp | 34 +- toolkit/components/antitracking/StorageAccess.cpp | 14 +- .../StripOnShareLists/LGPL/StripOnShareLGPL.json | 26 +- .../URLQueryStrippingListService.sys.mjs | 60 +- .../BounceTrackingMapEntry.cpp | 22 + .../BounceTrackingMapEntry.h | 35 + .../BounceTrackingProtection.cpp | 246 +- .../BounceTrackingProtection.h | 27 +- .../BounceTrackingProtectionStorage.cpp | 9 +- .../BounceTrackingRecord.cpp | 4 + .../BounceTrackingState.cpp | 184 +- .../bouncetrackingprotection/BounceTrackingState.h | 39 +- .../BounceTrackingStateGlobal.cpp | 14 + .../BounceTrackingStorageObserver.cpp | 84 +- .../BounceTrackingStorageObserver.h | 9 +- .../bouncetrackingprotection/metrics.yaml | 64 + .../bouncetrackingprotection/moz.build | 3 + .../nsIBounceTrackingMapEntry.idl | 17 + .../nsIBounceTrackingProtection.idl | 11 +- .../test/browser/browser.toml | 16 +- .../test/browser/browser_bouncetracking_dry_run.js | 101 + .../test/browser/browser_bouncetracking_popup.js | 126 + .../test/browser/browser_bouncetracking_purge.js | 45 +- .../test/browser/browser_bouncetracking_schemes.js | 75 + .../test/browser/browser_bouncetracking_simple.js | 10 +- .../browser/browser_bouncetracking_stateful.js | 63 - .../browser_bouncetracking_stateful_cookies.js | 68 + .../browser_bouncetracking_stateful_storage.js | 54 + .../browser_bouncetracking_stateful_web_worker.js | 38 + ...wser_bouncetracking_telemetry_purge_duration.js | 66 + .../test/browser/file_bounce.html | 187 +- .../test/browser/file_web_worker.js | 40 + .../bouncetrackingprotection/test/browser/head.js | 174 +- .../test_bouncetracking_storage_persistence.py | 6 +- ...st_bouncetracking_clearExpiredUserActivation.js | 10 +- ...uncetracking_importUserActivationPermissions.js | 153 + .../test/xpcshell/test_bouncetracking_purge.js | 62 +- .../test/xpcshell/xpcshell.toml | 3 + .../antitracking/test/browser/browser.toml | 10 + .../browser/browser_partitionedDedicatedWorker.js | 58 + .../browser_urlQueryStringStrippingWithEncoding.js | 93 + .../antitracking/test/browser/dedicatedWorker.js | 7 + .../autocomplete/nsAutoCompleteController.cpp | 16 +- .../autocomplete/nsIAutoCompletePopup.idl | 27 + .../backgroundtasks/defaults/backgroundtasks.js | 2 - .../defaults/backgroundtasks_browser.js | 4 - toolkit/components/browser/moz.build | 1 - toolkit/components/browser/nsIWebBrowser.idl | 2 - toolkit/components/browser/nsIWebBrowserChrome.idl | 6 +- .../browser/nsIWebBrowserChromeFocus.idl | 32 - .../components/cleardata/SiteDataTestUtils.sys.mjs | 9 +- .../tests/unit/test_bounce_tracking_protection.js | 70 +- .../components/cleardata/tests/unit/xpcshell.toml | 1 + .../components/contentanalysis/ContentAnalysis.cpp | 334 +- .../components/contentanalysis/ContentAnalysis.h | 45 +- .../contentanalysis/ContentAnalysisIPCTypes.h | 1 + .../contentanalysis/tests/browser/browser.toml | 27 + .../browser/browser_clipboard_content_analysis.js | 363 + ...rowser_clipboard_paste_file_content_analysis.js | 202 + ...oard_paste_inputandtextarea_content_analysis.js | 112 + ...lipboard_paste_noformatting_content_analysis.js | 92 + ...wser_clipboard_paste_prompt_content_analysis.js | 92 + ...rowser_clipboard_read_async_content_analysis.js | 195 + .../browser/browser_content_analysis_policies.js | 17 +- ...browser_print_changing_page_content_analysis.js | 64 +- .../browser/browser_print_content_analysis.js | 68 +- .../tests/browser/clipboard_paste_file.html | 61 + .../browser/clipboard_paste_inputandtextarea.html | 41 + .../browser/clipboard_paste_noformatting.html | 46 + .../tests/browser/clipboard_paste_prompt.html | 7 + .../tests/browser/clipboard_read_async.html | 95 + .../contentanalysis/tests/browser/head.js | 124 + .../tests/gtest/TestContentAnalysis.cpp | 257 + .../tests/gtest/TestContentAnalysisAgent.cpp | 39 +- .../tests/gtest/TestContentAnalysisAgent.h | 24 - .../tests/gtest/TestContentAnalysisMisbehaving.cpp | 87 +- .../tests/gtest/TestContentAnalysisUtils.cpp | 24 +- .../tests/gtest/TestContentAnalysisUtils.h | 32 + .../ContentRelevancyManager.sys.mjs | 109 +- toolkit/components/contentrelevancy/docs/index.md | 119 +- .../components/contentrelevancy/docs/telemetry.md | 62 + toolkit/components/contentrelevancy/metrics.yaml | 103 + .../contentrelevancy/tests/browser/browser.toml | 1 + .../browser/browser_contentrelevancy_nimbus.js | 2 + .../tests/xpcshell/test_ContentRelevancyManager.js | 28 +- .../tests/xpcshell/test_Telemetry.js | 81 + .../contentrelevancy/tests/xpcshell/xpcshell.toml | 6 + toolkit/components/cookiebanners/metrics.yaml | 56 +- .../downloads/test/unit/test_DownloadPaths.js | 68 +- toolkit/components/extensions/Extension.sys.mjs | 93 +- .../components/extensions/ExtensionContent.sys.mjs | 18 +- toolkit/components/extensions/ExtensionDNR.sys.mjs | 30 +- .../extensions/ExtensionDNRLimits.sys.mjs | 129 +- .../components/extensions/ExtensionParent.sys.mjs | 69 + .../extensions/ExtensionShortcuts.sys.mjs | 32 +- .../extensions/ExtensionTelemetry.sys.mjs | 4 - .../extensions/ExtensionTestCommon.sys.mjs | 128 +- toolkit/components/extensions/Schemas.sys.mjs | 21 + .../components/extensions/WebNavigation.sys.mjs | 4 +- toolkit/components/extensions/child/ext-storage.js | 28 +- toolkit/components/extensions/metrics.yaml | 80 +- .../extensions/parent/ext-declarativeNetRequest.js | 12 +- .../components/extensions/parent/ext-management.js | 2 + .../components/extensions/parent/ext-runtime.js | 92 + .../schemas/declarative_net_request.json | 24 + .../extensions/schemas/geckoProfiler.json | 3 +- .../components/extensions/schemas/management.json | 4 +- .../components/extensions/schemas/manifest.json | 4 +- toolkit/components/extensions/schemas/runtime.json | 127 + .../browser_ext_themes_getCurrent_differentExt.js | 4 +- .../test/browser/browser_ext_themes_sidebars.js | 8 +- .../test/marionette/manifest-serviceworker.toml | 1 + .../test/mochitest/mochitest-common.toml | 10 +- .../extensions/test/mochitest/test_ext_all_apis.js | 2 + .../test_ext_contentscript_activeTab.html | 5 +- .../mochitest/test_ext_extension_getViews.html | 108 + .../mochitest/test_ext_runtime_getContexts.html | 126 + ...test_ext_scripting_executeScript_activeTab.html | 5 +- .../mochitest/test_ext_subframes_privileges.html | 67 +- .../test/xpcshell/test_ext_contentscript_errors.js | 32 +- .../test_ext_contentscript_permissions_change.js | 1 + .../test/xpcshell/test_ext_cookieBehaviors.js | 118 +- .../test/xpcshell/test_ext_dnr_dynamic_rules.js | 33 +- .../xpcshell/test_ext_dnr_regexFilter_limits.js | 44 +- .../test/xpcshell/test_ext_dnr_session_rules.js | 33 + .../test/xpcshell/test_ext_dnr_static_rules.js | 22 +- .../test/xpcshell/test_ext_downloads_urlencoded.js | 2 +- .../test/xpcshell/test_ext_manifest_incognito.js | 39 +- .../test/xpcshell/test_ext_permission_warnings.js | 2 +- .../test/xpcshell/test_ext_permissions.js | 144 +- .../test/xpcshell/test_ext_runtime_getContexts.js | 180 + .../xpcshell/test_ext_service_worker_messaging.js | 128 + .../test/xpcshell/test_ext_storage_telemetry.js | 45 +- .../test_ext_webRequest_eventPage_StreamFilter.js | 6 +- .../extensions/test/xpcshell/xpcshell-common.toml | 2 + .../test/xpcshell/xpcshell-serviceworker.toml | 2 + .../webidl-api/ExtensionEventListener.cpp | 3 +- .../extensions/webidl-api/ExtensionEventListener.h | 6 +- .../AutofillProfileAutoComplete.sys.mjs | 334 +- .../components/formautofill/FormAutofill.sys.mjs | 6 +- .../formautofill/FormAutofillChild.sys.mjs | 217 +- .../formautofill/FormAutofillParent.sys.mjs | 86 +- .../formautofill/FormAutofillPreferences.sys.mjs | 65 +- toolkit/components/formautofill/Helpers.ios.mjs | 5 + .../default/FormAutofillPrompter.sys.mjs | 30 +- .../shared/FormAutofillSection.sys.mjs | 1 + .../formautofill/shared/FormAutofillUtils.sys.mjs | 234 +- toolkit/components/glean/Cargo.toml | 2 +- toolkit/components/glean/api/Cargo.toml | 2 +- toolkit/components/glean/api/src/common_test.rs | 2 +- toolkit/components/glean/api/src/private/ping.rs | 6 +- toolkit/components/glean/bindings/GleanMetric.h | 2 + toolkit/components/glean/bindings/jog/JOG.cpp | 4 +- toolkit/components/glean/bindings/jog/src/lib.rs | 16 + .../glean/bindings/private/TimingDistribution.h | 2 - .../glean/build_scripts/glean_parser_ext/jog.py | 2 + .../glean_parser_ext/run_glean_parser.py | 15 +- .../glean_parser_ext/templates/jog_factory.jinja2 | 4 +- .../glean_parser_ext/templates/rust.jinja2 | 5 +- .../glean_parser_ext/templates/rust_pings.jinja2 | 2 + .../glean/build_scripts/mach_commands.py | 65 +- .../docs/user/geckoview_streaming_migration.md | 262 - toolkit/components/glean/docs/user/migration.md | 8 +- toolkit/components/glean/docs/user/ohttp.md | 77 + toolkit/components/glean/metrics_index.py | 3 + toolkit/components/glean/src/lib.rs | 6 +- toolkit/components/glean/tags.yaml | 2 + .../components/glean/tests/pytest/jogfile_output | 16 +- .../glean/tests/pytest/metrics_test.yaml | 30 +- .../glean/tests/pytest/metrics_test_output | 8 +- .../glean/tests/pytest/pings_test_output | 10 + toolkit/components/glean/tests/test_metrics.yaml | 36 + .../components/glean/tests/xpcshell/test_Glean.js | 76 +- .../glean/tests/xpcshell/test_GleanServerKnobs.js | 38 +- .../components/glean/tests/xpcshell/test_JOG.js | 37 +- toolkit/components/glean/xpcom/FOG.cpp | 27 +- toolkit/components/glean/xpcom/nsIFOG.idl | 5 +- .../maintenanceservice_installer.nsi | 2 +- .../schemas/TriggerActionSchemas/index.md | 1 + .../components/messaging-system/schemas/index.rst | 2 +- toolkit/components/ml/actors/MLEngineChild.sys.mjs | 156 +- .../components/ml/actors/MLEngineParent.sys.mjs | 175 +- .../components/ml/content/EngineProcess.sys.mjs | 188 +- toolkit/components/ml/content/MLEngine.worker.mjs | 98 +- toolkit/components/ml/content/ModelHub.sys.mjs | 317 +- toolkit/components/ml/content/ONNXPipeline.mjs | 297 + .../components/ml/content/SummarizerModel.sys.mjs | 160 - toolkit/components/ml/content/Utils.sys.mjs | 77 + toolkit/components/ml/docs/index.md | 44 - toolkit/components/ml/docs/index.rst | 47 + toolkit/components/ml/jar.mn | 10 +- toolkit/components/ml/tests/browser/browser.toml | 6 + .../ml/tests/browser/browser_ml_cache.js | 233 +- .../ml/tests/browser/browser_ml_engine.js | 155 +- .../ml/tests/browser/browser_ml_utils.js | 26 + .../data/acme/bert/resolve/v0.1/config.json | 21 + .../data/acme/bert/resolve/v0.1/onnx/config.json | 21 + toolkit/components/ml/tests/browser/head.js | 129 +- toolkit/components/ml/vendor/LICENSE | 202 + toolkit/components/ml/vendor/README.md | 12 + toolkit/components/ml/vendor/build.sh | 36 + toolkit/components/ml/vendor/gecko.patch | 84 + toolkit/components/ml/vendor/moz.yaml | 15 + toolkit/components/ml/vendor/ort-dev.js | 29506 +++++++++++++++++++ toolkit/components/ml/vendor/ort.js | 7 + toolkit/components/ml/vendor/transformers-dev.js | 25483 ++++++++++++++++ toolkit/components/ml/vendor/transformers.js | 77 + toolkit/components/nimbus/FeatureManifest.yaml | 139 +- .../nimbus/generate/generate_feature_manifest.py | 4 - .../nimbus/lib/ExperimentManager.sys.mjs | 2 +- toolkit/components/nimbus/test/unit/head.js | 7 +- .../test/unit/test_ExperimentAPI_NimbusFeatures.js | 28 +- .../test/unit/test_ExperimentManager_enroll.js | 3 +- .../test/unit/test_ExperimentManager_unenroll.js | 4 +- .../components/normandy/lib/AddonRollouts.sys.mjs | 4 +- .../passwordmgr/LoginAutoComplete.sys.mjs | 254 +- toolkit/components/passwordmgr/LoginHelper.sys.mjs | 105 +- .../passwordmgr/LoginManagerChild.sys.mjs | 338 +- .../passwordmgr/LoginManagerParent.sys.mjs | 50 +- toolkit/components/passwordmgr/moz.build | 1 - .../passwordmgr/nsILoginAutoCompleteSearch.idl | 31 - ...t_autocomplete_password_generation_confirm.html | 26 +- .../test/mochitest/test_autofocus_js.html | 6 +- .../test/unit/test_isProbablyANewPasswordField.js | 13 +- toolkit/components/pdfjs/content/build/pdf.mjs | 540 +- .../pdfjs/content/build/pdf.scripting.mjs | 9 +- .../components/pdfjs/content/build/pdf.worker.mjs | 2969 +- .../web/images/toolbarButton-editorStamp.svg | 2 +- .../pdfjs/content/web/viewer-geckoview.css | 19 +- .../pdfjs/content/web/viewer-geckoview.mjs | 865 +- toolkit/components/pdfjs/content/web/viewer.css | 21 +- toolkit/components/pdfjs/content/web/viewer.mjs | 1004 +- toolkit/components/pdfjs/moz.yaml | 4 +- toolkit/components/pdfjs/update.sh | 3 + .../pictureinpicture/PictureInPicture.sys.mjs | 2 - .../components/places/BookmarkHTMLUtils.sys.mjs | 18 +- .../components/places/BookmarkJSONUtils.sys.mjs | 22 +- toolkit/components/places/FaviconHelpers.cpp | 101 +- toolkit/components/places/FaviconHelpers.h | 42 +- toolkit/components/places/History.cpp | 105 +- toolkit/components/places/History.h | 10 + .../components/places/PlacesCompletionCallback.idl | 19 + toolkit/components/places/PlacesQuery.sys.mjs | 20 +- toolkit/components/places/moz.build | 1 + toolkit/components/places/nsFaviconService.cpp | 406 +- toolkit/components/places/nsFaviconService.h | 26 +- toolkit/components/places/nsIFaviconService.idl | 82 +- .../places/tests/PlacesTestUtils.sys.mjs | 37 + .../components/places/tests/browser/browser.toml | 12 + .../tests/browser/browser_visituri_restriction.js | 227 + .../browser/browser_visituri_restriction_origin.js | 92 + toolkit/components/places/tests/browser/head.js | 77 + .../places/tests/chrome/test_cached_favicon.xhtml | 15 +- .../tests/expiration/test_debug_expiration.js | 16 +- .../places/tests/favicons/head_favicons.js | 87 +- .../favicons/test_cached-favicon_mime_type.js | 20 +- .../tests/favicons/test_expire_on_new_icons.js | 38 +- .../tests/favicons/test_favicons_conversions.js | 37 +- .../tests/favicons/test_favicons_protocols_ref.js | 17 +- .../tests/favicons/test_getFaviconDataForPage.js | 16 +- .../tests/favicons/test_getFaviconURLForPage.js | 16 +- .../places/tests/favicons/test_heavy_favicon.js | 4 +- .../tests/favicons/test_incremental_vacuum.js | 7 +- .../places/tests/favicons/test_multiple_frames.js | 12 +- .../tests/favicons/test_page-icon_protocol.js | 44 +- .../tests/favicons/test_replaceFaviconData.js | 395 - .../favicons/test_replaceFaviconDataFromDataURL.js | 537 - .../places/tests/favicons/test_root_icons.js | 67 +- .../tests/favicons/test_setFaviconForPage.js | 245 + .../components/places/tests/favicons/xpcshell.toml | 6 +- .../places/tests/gtest/places_test_harness_tail.h | 8 +- toolkit/components/places/tests/head_common.js | 37 +- .../components/places/tests/history/test_remove.js | 15 +- .../places/tests/unit/test_PlacesQuery_history.js | 33 + .../tests/browser/browser_test_powerMetrics.js | 4 +- .../components/prompts/content/selectDialog.css | 12 + toolkit/components/prompts/content/selectDialog.js | 3 +- .../components/prompts/content/selectDialog.xhtml | 12 +- toolkit/components/prompts/jar.mn | 1 + toolkit/components/prompts/test/chromeScript.js | 2 +- toolkit/components/reader/AboutReader.sys.mjs | 242 +- toolkit/components/reader/content/aboutReader.html | 58 +- toolkit/components/reader/jar.mn | 2 + toolkit/components/reader/moz-slider.css | 43 + toolkit/components/reader/moz-slider.mjs | 126 + toolkit/components/reader/moz-slider.stories.mjs | 42 + .../tests/browser/browser_drag_url_readerMode.js | 2 +- .../tests/browser/browser_readerMode_bc_reuse.js | 2 +- toolkit/components/reader/tests/chrome/chrome.toml | 2 + .../reader/tests/chrome/test_moz_slider.html | 48 + .../FingerprintingWebCompatService.sys.mjs | 14 + .../components/resistfingerprinting/metrics.yaml | 524 + .../resistfingerprinting/nsRFPService.cpp | 17 +- .../resistfingerprinting/nsUserCharacteristics.cpp | 121 +- .../tests/browser/browser_canvas_randomization.js | 120 +- .../browser/browser_canvas_randomization_worker.js | 42 +- .../browser_fingerprintingRemoteOverrides.js | 45 + .../resistfingerprinting/tests/browser/head.js | 34 + .../satchel/FormHistoryAutoComplete.sys.mjs | 489 +- .../components/satchel/FormHistoryChild.sys.mjs | 154 +- .../components/satchel/FormHistoryParent.sys.mjs | 123 +- toolkit/components/satchel/components.conf | 2 +- .../satchel/integrations/FirefoxRelay.sys.mjs | 1 - toolkit/components/satchel/jar.mn | 2 +- .../satchel/megalist/MegalistViewModel.sys.mjs | 28 +- .../satchel/megalist/aggregator/Aggregator.sys.mjs | 14 + .../datasources/AddressesDataSource.sys.mjs | 168 +- .../datasources/BankCardDataSource.sys.mjs | 302 +- .../aggregator/datasources/DataSourceBase.sys.mjs | 41 +- .../aggregator/datasources/LoginDataSource.sys.mjs | 522 +- .../components/satchel/megalist/content/Dialog.mjs | 116 + .../satchel/megalist/content/MegalistView.mjs | 98 +- .../satchel/megalist/content/megalist.css | 93 +- .../satchel/megalist/content/megalist.ftl | 28 + .../satchel/megalist/content/megalist.html | 175 +- .../satchel/megalist/content/search-input.mjs | 36 - .../components/satchel/nsFormFillController.cpp | 249 +- toolkit/components/satchel/nsFormFillController.h | 14 +- .../components/satchel/nsIFormFillController.idl | 26 +- .../components/satchel/test/browser/browser.toml | 11 +- .../satchel/test/browser/browser_autocomplete.js | 403 + .../test/browser/browser_popup_mouseover.js | 8 +- .../test/browser/formhistory_autocomplete.sqlite | Bin 0 -> 72704 bytes .../satchel/test/unit/test_autocomplete.js | 388 - .../satchel/test/unit/test_previous_result.js | 25 - toolkit/components/satchel/test/unit/xpcshell.toml | 15 +- .../search/AppProvidedSearchEngine.sys.mjs | 4 + toolkit/components/search/SearchEngine.sys.mjs | 12 +- toolkit/components/search/SearchService.sys.mjs | 24 +- toolkit/components/search/SearchSettings.sys.mjs | 21 + .../components/search/SearchSuggestions.sys.mjs | 7 +- .../search/docs/SearchConfigurationSchema.rst | 722 +- .../docs/SearchConfigurationSchemaArchive.rst | 586 + toolkit/components/search/docs/SearchEngines.rst | 131 +- .../search/docs/SearchEnginesArchive.rst | 197 + .../search/docs/SearchServiceHighlevelOverview.rst | 37 +- .../docs/SearchServiceHighlevelOverviewArchive.rst | 85 + .../docs/assets/search-service-diagram-1.png | Bin 0 -> 134442 bytes .../docs/assets/search-service-diagram-2.png | Bin 0 -> 622630 bytes .../search/docs/assets/search-service-diagram.png | Bin 134442 -> 0 bytes toolkit/components/search/docs/index.rst | 3 + .../tests/xpcshell/searchconfigs/test_ebay.js | 36 +- .../tests/xpcshell/searchconfigs/xpcshell.toml | 7 + .../tests/xpcshell/test_appProvided_engine.js | 90 + .../search/tests/xpcshell/test_missing_engine.js | 59 +- .../tests/xpcshell/test_webextensions_startup.js | 111 + .../test_webextensions_startup_duplicate.js | 6 +- .../components/search/tests/xpcshell/xpcshell.toml | 3 + .../sessionstore/SessionStoreFunctions.idl | 23 - .../sessionstore/SessionStoreFunctions.sys.mjs | 87 - .../sessionstore/SessionStoreListener.cpp | 14 +- .../components/sessionstore/SessionStoreParent.cpp | 17 +- toolkit/components/sessionstore/moz.build | 6 +- .../sessionstore/nsISessionStoreFunctions.idl | 23 + toolkit/components/telemetry/Events.yaml | 27 - toolkit/components/telemetry/Histograms.json | 114 +- toolkit/components/telemetry/Scalars.yaml | 47 +- .../app/TelemetryControllerParent.sys.mjs | 21 + .../telemetry/app/TelemetryEnvironment.sys.mjs | 7 + .../build_scripts/mozparsers/parse_events.py | 6 - .../build_scripts/mozparsers/parse_histograms.py | 22 - .../build_scripts/mozparsers/parse_scalars.py | 7 - .../mozparsers/shared_telemetry_utils.py | 8 +- toolkit/components/telemetry/core/Telemetry.cpp | 3 - .../components/telemetry/core/TelemetryCommon.cpp | 6 +- .../components/telemetry/core/TelemetryCommon.h | 6 +- .../telemetry/core/TelemetryHistogram.cpp | 647 - .../components/telemetry/core/TelemetryHistogram.h | 14 - .../components/telemetry/core/TelemetryScalar.cpp | 794 +- .../components/telemetry/core/TelemetryScalar.h | 18 - .../telemetry/dap/DAPTelemetrySender.sys.mjs | 7 +- .../components/telemetry/dap/ffi-gtest/Cargo.toml | 2 +- toolkit/components/telemetry/dap/ffi-gtest/test.rs | 2 +- toolkit/components/telemetry/dap/ffi/Cargo.toml | 3 +- toolkit/components/telemetry/dap/ffi/src/lib.rs | 119 +- toolkit/components/telemetry/dap/ffi/src/types.rs | 83 +- .../telemetry/dap/tests/xpcshell/test_dap.js | 2 +- .../components/telemetry/docs/data/environment.rst | 12 +- .../telemetry/docs/internals/preferences.rst | 20 - .../components/telemetry/docs/internals/review.rst | 2 +- .../geckoview/gtest/TestGeckoViewStreaming.cpp | 237 - .../components/telemetry/geckoview/gtest/moz.build | 28 - .../streaming/GeckoViewStreamingTelemetry.cpp | 282 - .../streaming/GeckoViewStreamingTelemetry.h | 55 - .../telemetry/geckoview/streaming/metrics.yaml | 13 - toolkit/components/telemetry/moz.build | 17 +- .../telemetry/tests/gtest/TestScalars.cpp | 62 - .../tests/python/test_histogramtools_strict.py | 47 - .../telemetry/tests/python/test_parse_events.py | 16 - .../telemetry/tests/python/test_parse_scalars.py | 19 - .../tests/unit/TelemetryEnvironmentTesting.sys.mjs | 7 + .../tests/unit/test_TelemetryEnvironment.js | 58 + .../components/telemetry/tests/unit/xpcshell.toml | 1 + .../translations/actors/TranslationsChild.sys.mjs | 1 + .../translations/actors/TranslationsParent.sys.mjs | 54 +- .../components/translations/content/Translator.mjs | 137 +- .../content/translations-document.sys.mjs | 43 +- .../translations/content/translations.mjs | 5 +- .../translations/tests/browser/browser.toml | 2 +- .../tests/browser/browser_translations_actor.js | 26 + .../browser_translations_pdf_is_disabled.js | 2 +- .../browser_translations_translation_document.js | 90 +- .../translations/tests/browser/shared-head.js | 30 +- .../tests/browser/translations-test.mjs | 13 + .../browser/translations-tester-empty-pdf-file.pdf | 0 .../tests/browser/translations-tester-pdf-file.pdf | Bin 0 -> 150611 bytes toolkit/components/translations/translations.d.ts | 19 + .../components/generated/RustRelevancy.sys.mjs | 129 +- .../generated/RustRemoteSettings.sys.mjs | 189 +- .../components/generated/RustSuggest.sys.mjs | 88 +- .../components/generated/RustTabs.sys.mjs | 36 +- .../components/uniffi-bindgen-gecko-js/config.toml | 22 +- .../fixtures/generated/RustArithmetic.sys.mjs | 8 +- .../fixtures/generated/RustCustomTypes.sys.mjs | 2 +- .../fixtures/generated/RustExternalTypes.sys.mjs | 4 +- .../fixtures/generated/RustGeometry.sys.mjs | 4 +- .../fixtures/generated/RustRefcounts.sys.mjs | 6 +- .../fixtures/generated/RustRondpoint.sys.mjs | 120 +- .../fixtures/generated/RustSprites.sys.mjs | 12 +- .../fixtures/generated/RustTodolist.sys.mjs | 30 +- .../fixtures/tests/xpcshell/xpcshell.toml | 10 - .../src/templates/UniFFIScaffolding.cpp | 6 +- .../uniffi-example-custom-types/Cargo.toml | 21 - .../uniffi-example-custom-types/build.rs | 7 - .../src/custom-types.udl | 14 - .../uniffi-example-custom-types/src/lib.rs | 52 - .../tests/bindings/test_custom_types.kts | 21 - .../tests/bindings/test_custom_types.swift | 20 - .../tests/test_generated_bindings.rs | 7 - .../uniffi-example-custom-types/uniffi.toml | 40 - .../components/uniffi-fixture-callbacks/Cargo.toml | 14 - .../components/uniffi-fixture-callbacks/build.rs | 7 - .../uniffi-fixture-callbacks/src/callbacks.udl | 12 - .../components/uniffi-fixture-callbacks/src/lib.rs | 23 - .../uniffi-fixture-external-types/Cargo.toml | 15 - .../uniffi-fixture-external-types/build.rs | 7 - .../src/external-types.udl | 11 - .../uniffi-fixture-external-types/src/lib.rs | 18 - .../components/uniffi-fixture-refcounts/Cargo.toml | 12 - .../components/uniffi-fixture-refcounts/build.rs | 7 - .../components/uniffi-fixture-refcounts/src/lib.rs | 28 - .../uniffi-fixture-refcounts/src/refcounts.udl | 8 - .../uniffi-fixtures/arithmetic/Cargo.toml | 21 + .../components/uniffi-fixtures/arithmetic/build.rs | 7 + .../uniffi-fixtures/arithmetic/src/arithmetic.udl | 16 + .../uniffi-fixtures/arithmetic/src/lib.rs | 34 + .../arithmetic/tests/bindings/test_arithmetic.kts | 29 + .../arithmetic/tests/bindings/test_arithmetic.py | 37 + .../arithmetic/tests/bindings/test_arithmetic.rb | 31 + .../tests/bindings/test_arithmetic.swift | 32 + .../arithmetic/tests/test_generated_bindings.rs | 6 + .../uniffi-fixtures/arithmetic/uniffi.toml | 2 + .../uniffi-fixtures/callbacks/Cargo.toml | 14 + .../components/uniffi-fixtures/callbacks/build.rs | 7 + .../uniffi-fixtures/callbacks/src/callbacks.udl | 12 + .../uniffi-fixtures/callbacks/src/lib.rs | 23 + .../uniffi-fixtures/custom-types/Cargo.toml | 21 + .../uniffi-fixtures/custom-types/build.rs | 7 + .../custom-types/src/custom-types.udl | 14 + .../uniffi-fixtures/custom-types/src/lib.rs | 52 + .../tests/bindings/test_custom_types.kts | 21 + .../tests/bindings/test_custom_types.swift | 20 + .../custom-types/tests/test_generated_bindings.rs | 7 + .../uniffi-fixtures/custom-types/uniffi.toml | 40 + .../uniffi-fixtures/external-types/Cargo.toml | 15 + .../uniffi-fixtures/external-types/build.rs | 7 + .../external-types/src/external-types.udl | 11 + .../uniffi-fixtures/external-types/src/lib.rs | 18 + .../components/uniffi-fixtures/geometry/Cargo.toml | 20 + .../components/uniffi-fixtures/geometry/build.rs | 7 + .../uniffi-fixtures/geometry/src/geometry.udl | 15 + .../components/uniffi-fixtures/geometry/src/lib.rs | 47 + .../geometry/tests/bindings/test_geometry.kts | 10 + .../geometry/tests/bindings/test_geometry.py | 10 + .../geometry/tests/bindings/test_geometry.rb | 16 + .../geometry/tests/bindings/test_geometry.swift | 10 + .../geometry/tests/test_generated_bindings.rs | 6 + .../uniffi-fixtures/refcounts/Cargo.toml | 12 + .../components/uniffi-fixtures/refcounts/build.rs | 7 + .../uniffi-fixtures/refcounts/src/lib.rs | 32 + .../uniffi-fixtures/refcounts/src/refcounts.udl | 8 + .../uniffi-fixtures/rondpoint/Cargo.toml | 20 + .../components/uniffi-fixtures/rondpoint/build.rs | 7 + .../uniffi-fixtures/rondpoint/src/lib.rs | 293 + .../uniffi-fixtures/rondpoint/src/rondpoint.udl | 146 + .../rondpoint/tests/bindings/test_rondpoint.kts | 250 + .../rondpoint/tests/bindings/test_rondpoint.py | 183 + .../rondpoint/tests/bindings/test_rondpoint.rb | 147 + .../rondpoint/tests/bindings/test_rondpoint.swift | 232 + .../rondpoint/tests/test_generated_bindings.rs | 6 + .../components/uniffi-fixtures/sprites/Cargo.toml | 20 + .../components/uniffi-fixtures/sprites/build.rs | 7 + .../components/uniffi-fixtures/sprites/src/lib.rs | 65 + .../uniffi-fixtures/sprites/src/sprites.udl | 22 + .../sprites/tests/bindings/test_sprites.kts | 25 + .../sprites/tests/bindings/test_sprites.py | 16 + .../sprites/tests/bindings/test_sprites.rb | 22 + .../sprites/tests/bindings/test_sprites.swift | 16 + .../sprites/tests/test_generated_bindings.rs | 6 + .../components/uniffi-fixtures/todolist/Cargo.toml | 22 + .../components/uniffi-fixtures/todolist/build.rs | 7 + .../components/uniffi-fixtures/todolist/src/lib.rs | 150 + .../uniffi-fixtures/todolist/src/todolist.udl | 38 + .../todolist/tests/bindings/test_todolist.kts | 83 + .../todolist/tests/bindings/test_todolist.py | 56 + .../todolist/tests/bindings/test_todolist.rb | 47 + .../todolist/tests/bindings/test_todolist.swift | 69 + .../todolist/tests/test_generated_bindings.rs | 6 + toolkit/components/uniffi-js/OwnedRustBuffer.cpp | 16 +- toolkit/components/uniffi-js/ScaffoldingCall.h | 17 +- .../components/uniffi-js/ScaffoldingConverter.h | 12 +- .../uniffi-js/UniFFIFixtureScaffolding.cpp | 402 +- .../uniffi-js/UniFFIGeneratedScaffolding.cpp | 218 +- toolkit/components/uniffi-js/UniFFIPointer.cpp | 19 +- toolkit/components/uniffi-js/UniFFIScaffolding.cpp | 14 +- toolkit/components/uniffi-js/UniFFIScaffolding.h | 6 +- .../components/windowcreator/nsIWindowProvider.idl | 2 +- .../components/windowwatcher/nsIOpenWindowInfo.idl | 6 + .../components/windowwatcher/nsOpenWindowInfo.cpp | 8 + toolkit/content/aboutLogging.js | 2 +- toolkit/content/aboutNetError.mjs | 3 +- toolkit/content/aboutTelemetry.js | 6 + toolkit/content/customElements.js | 62 +- toolkit/content/jar.mn | 2 - toolkit/content/license.html | 5 +- toolkit/content/preferencesBindings.js | 5 + .../content/tests/browser/browser_bug1693577.js | 4 +- toolkit/content/tests/chrome/chrome.toml | 1 - .../tests/chrome/file_editor_with_autocomplete.js | 4 + ...est_autocomplete_with_composition_on_input.html | 2 - .../test_editor_for_input_with_autocomplete.html | 2 - .../content/tests/chrome/window_largemenu.xhtml | 15 +- toolkit/content/tests/widgets/mochitest.toml | 2 + toolkit/content/tests/widgets/test_moz_button.html | 132 +- .../tests/widgets/test_moz_button_group.html | 144 +- .../tests/widgets/test_moz_message_bar.html | 28 +- .../content/tests/widgets/test_moz_page_nav.html | 61 + .../widgets/test_videocontrols_src_change.html | 56 + .../widgets/test_videocontrols_video_noaudio.html | 2 +- toolkit/content/widgets.css | 2 +- toolkit/content/widgets/arrowscrollbox.js | 4 +- .../content/widgets/autocomplete-richlistitem.js | 4 +- toolkit/content/widgets/datetimebox.js | 28 +- toolkit/content/widgets/message-bar.css | 219 - toolkit/content/widgets/message-bar.js | 91 - .../widgets/moz-button-group/moz-button-group.css | 3 +- .../widgets/moz-button-group/moz-button-group.mjs | 25 +- toolkit/content/widgets/moz-button/moz-button.css | 26 +- toolkit/content/widgets/moz-button/moz-button.mjs | 21 +- .../widgets/moz-button/moz-button.stories.mjs | 29 +- .../widgets/moz-message-bar/moz-message-bar.mjs | 12 +- .../content/widgets/moz-page-nav/README.stories.md | 46 +- .../widgets/moz-page-nav/moz-page-nav-button.css | 23 +- .../content/widgets/moz-page-nav/moz-page-nav.mjs | 86 +- .../widgets/moz-page-nav/moz-page-nav.stories.mjs | 32 +- .../widgets/moz-support-link/moz-support-link.mjs | 6 +- toolkit/content/widgets/notificationbox.js | 3 +- toolkit/content/widgets/panel-list/panel-list.js | 4 - toolkit/content/widgets/popupnotification.js | 2 - toolkit/content/widgets/videocontrols.js | 17 +- toolkit/content/xul.css | 14 - .../linux/crash_generation/client_info.h | 12 +- .../crash_generation/crash_generation_server.cc | 11 +- .../linux/handler/exception_handler.cc | 6 +- toolkit/crashreporter/client/app/Cargo.toml | 2 +- .../client/app/src/ui/crashreporter.png | Bin 2001 -> 1562 bytes .../client/app/src/ui/windows/window.rs | 9 + .../generate_crash_reporter_sources.py | 25 +- toolkit/crashreporter/nsExceptionHandler.cpp | 21 +- .../rust_minidump_writer_linux/Cargo.toml | 3 +- .../rust_minidump_writer_linux/src/lib.rs | 74 +- toolkit/crashreporter/tools/upload_symbols.py | 72 +- toolkit/docs/javascript-logging.md | 3 + toolkit/library/build/moz.build | 2 +- toolkit/library/gen_buildid.py | 11 +- toolkit/library/gtest/rust/lib.rs | 2 +- toolkit/library/rust/shared/Cargo.toml | 20 +- .../locales/en-US/toolkit/about/aboutReader.ftl | 58 +- .../locales/en-US/toolkit/about/abuseReports.ftl | 116 - .../locales/en-US/toolkit/branding/accounts.ftl | 11 - .../toolkit/contentanalysis/contentanalysis.ftl | 29 +- .../en-US/toolkit/global/arrowscrollbox.ftl | 10 +- toolkit/modules/AppConstants.sys.mjs | 7 + toolkit/modules/AsyncPrefs.sys.mjs | 3 + toolkit/modules/GMPInstallManager.sys.mjs | 98 +- toolkit/modules/IndexedDB.sys.mjs | 8 +- toolkit/modules/LightweightThemeConsumer.sys.mjs | 5 +- toolkit/modules/LogManager.sys.mjs | 475 + toolkit/modules/ProfileAge.sys.mjs | 21 + toolkit/modules/RemotePageAccessManager.sys.mjs | 1 + toolkit/modules/SelectionUtils.sys.mjs | 2 +- toolkit/modules/Sqlite.sys.mjs | 41 +- toolkit/modules/moz.build | 2 + .../sessionstore/SessionStoreHelper.sys.mjs | 110 + .../modules/tests/browser/browser_BrowserUtils.js | 33 +- .../browser/file_getSelectionDetails_inputs.html | 7 + toolkit/modules/tests/xpcshell/test_LogManager.js | 377 + .../modules/tests/xpcshell/test_MatchURLFilters.js | 4 +- toolkit/modules/tests/xpcshell/test_ProfileAge.js | 31 + toolkit/modules/tests/xpcshell/xpcshell.toml | 2 + toolkit/moz.configure | 23 + .../BackgroundTask_defaultagent.sys.mjs | 2 +- .../defaultagent/assets/fox-doodle-peek.png | Bin 0 -> 49744 bytes toolkit/mozapps/defaultagent/jar.mn | 6 + toolkit/mozapps/defaultagent/moz.build | 2 + toolkit/mozapps/extensions/AbuseReporter.sys.mjs | 587 +- toolkit/mozapps/extensions/AddonManager.sys.mjs | 88 +- toolkit/mozapps/extensions/amWebAPI.sys.mjs | 19 - toolkit/mozapps/extensions/content/aboutaddons.css | 6 +- .../mozapps/extensions/content/aboutaddons.html | 8 - .../extensions/content/aboutaddonsCommon.js | 4 +- .../extensions/content/abuse-report-frame.html | 213 - .../extensions/content/abuse-report-panel.css | 181 - .../extensions/content/abuse-report-panel.js | 873 - .../mozapps/extensions/content/abuse-reports.js | 357 +- .../extensions/internal/XPIDatabase.sys.mjs | 59 + .../mozapps/extensions/internal/XPIInstall.sys.mjs | 18 +- toolkit/mozapps/extensions/jar.mn | 3 - toolkit/mozapps/extensions/metrics.yaml | 47 +- .../mozapps/extensions/test/browser/browser.toml | 14 +- .../test/browser/browser_amo_abuse_report.js | 21 +- .../test/browser/browser_html_abuse_report.js | 1091 - .../browser/browser_html_abuse_report_dialog.js | 185 - .../browser/browser_html_detail_permissions.js | 44 +- .../test/browser/browser_html_detail_view.js | 6 +- .../test/browser/browser_html_discover_view.js | 7 +- .../test/browser/browser_html_message_bar.js | 185 - .../browser/browser_html_options_ui_dark_theme.js | 173 + .../browser/browser_html_scroll_restoration.js | 14 +- .../test/browser/browser_webapi_abuse_report.js | 375 - .../extensions/test/browser/head_abuse_report.js | 492 +- .../extensions/test/xpcshell/test_AbuseReporter.js | 687 +- .../test/xpcshell/test_dictionary_webextension.js | 15 +- .../test/xpcshell/test_webextension_install.js | 196 +- .../mozapps/extensions/test/xpcshell/xpcshell.toml | 199 +- .../xpinstall/browser_required_useractivation.js | 1 + toolkit/mozapps/installer/package-name.mk | 3 + toolkit/mozapps/installer/packager.mk | 9 + toolkit/mozapps/installer/upload-files.mk | 4 + .../ChannelPrefs-localbuild/Makefile.in | 25 + .../ChannelPrefs-localbuild/moz.build | 21 + .../macos-frameworks/ChannelPrefs/ChannelPrefs.mm | 8 +- .../macos-frameworks/ChannelPrefs/Makefile.in | 23 +- toolkit/mozapps/macos-frameworks/moz.build | 1 + toolkit/mozapps/update/BackgroundUpdate.sys.mjs | 40 +- toolkit/mozapps/update/UpdateService.sys.mjs | 1200 +- toolkit/mozapps/update/common/readstrings.cpp | 9 +- .../update/docs/MaintenanceServiceTests.rst | 4 +- toolkit/mozapps/update/nsUpdateService.manifest | 2 +- toolkit/mozapps/update/updater/Makefile.in | 11 + .../UpdateSettings-localbuild/Makefile.in | 25 + .../UpdateSettings-localbuild/moz.build | 18 + .../update/updater/macos-frameworks/moz.build | 7 +- toolkit/mozapps/update/updater/updater.cpp | 2 +- toolkit/profile/gtest/moz.build | 6 +- toolkit/themes/osx/global/in-content/common.css | 4 + toolkit/themes/osx/reftests/482681-ref.xhtml | 21 - toolkit/themes/osx/reftests/checkboxsize-ref.xhtml | 33 - toolkit/themes/osx/reftests/checkboxsize.xhtml | 31 - toolkit/themes/osx/reftests/radiosize-ref.xhtml | 33 - toolkit/themes/osx/reftests/radiosize.xhtml | 31 - toolkit/themes/osx/reftests/reftest.list | 5 - toolkit/themes/shared/aboutReader.css | 141 +- .../themes/shared/design-system/design-tokens.json | 5 +- .../themes/shared/design-system/tokens-shared.css | 3 + .../shared/design-system/tokens-storybook.mjs | 13 +- toolkit/themes/shared/desktop-jar.inc.mn | 12 +- toolkit/themes/shared/desktop-non-mac.jar.inc.mn | 3 - toolkit/themes/shared/icons/blocked.svg | 2 +- toolkit/themes/shared/icons/content-analysis.svg | 8 + toolkit/themes/shared/icons/developer.svg | 2 +- toolkit/themes/shared/icons/info-filled.svg | 2 +- toolkit/themes/shared/icons/info.svg | 2 +- toolkit/themes/shared/icons/performance.svg | 4 +- toolkit/themes/shared/icons/settings.svg | 2 +- toolkit/themes/shared/icons/warning.svg | 2 +- toolkit/themes/shared/in-content/common-shared.css | 8 - toolkit/themes/shared/reader/align-center-20.svg | 6 + toolkit/themes/shared/reader/align-left-20.svg | 6 + toolkit/themes/shared/reader/align-right-20.svg | 6 + .../themes/shared/reader/character-spacing-20.svg | 7 + toolkit/themes/shared/reader/content-width-20.svg | 6 + toolkit/themes/shared/reader/line-spacing-20.svg | 6 + toolkit/themes/shared/reader/word-spacing-20.svg | 7 + toolkit/themes/shared/tree.css | 281 - toolkit/themes/shared/tree/sort-asc.svg | 6 + toolkit/themes/shared/tree/sort-dsc.svg | 6 + toolkit/themes/shared/tree/tree.css | 289 + toolkit/themes/windows/global/tree/sort-asc.svg | 6 - toolkit/themes/windows/global/tree/sort-dsc.svg | 6 - toolkit/toolkit.mozbuild | 1 + .../xre/dllservices/UntrustedModulesProcessor.cpp | 8 +- .../xre/dllservices/UntrustedModulesProcessor.h | 2 +- toolkit/xre/nsAppRunner.cpp | 9 +- 698 files changed, 81745 insertions(+), 21600 deletions(-) create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.cpp create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.h create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/metrics.yaml create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingMapEntry.idl create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_dry_run.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_popup.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js delete mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_cookies.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_storage.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_web_worker.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_telemetry_purge_duration.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_web_worker.js create mode 100644 toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_importUserActivationPermissions.js create mode 100644 toolkit/components/antitracking/test/browser/browser_partitionedDedicatedWorker.js create mode 100644 toolkit/components/antitracking/test/browser/browser_urlQueryStringStrippingWithEncoding.js delete mode 100644 toolkit/components/browser/nsIWebBrowserChromeFocus.idl create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_file_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_inputandtextarea_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_noformatting_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_prompt_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/browser_clipboard_read_async_content_analysis.js create mode 100644 toolkit/components/contentanalysis/tests/browser/clipboard_paste_file.html create mode 100644 toolkit/components/contentanalysis/tests/browser/clipboard_paste_inputandtextarea.html create mode 100644 toolkit/components/contentanalysis/tests/browser/clipboard_paste_noformatting.html create mode 100644 toolkit/components/contentanalysis/tests/browser/clipboard_paste_prompt.html create mode 100644 toolkit/components/contentanalysis/tests/browser/clipboard_read_async.html delete mode 100644 toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.h create mode 100644 toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.h create mode 100644 toolkit/components/contentrelevancy/docs/telemetry.md create mode 100644 toolkit/components/contentrelevancy/metrics.yaml create mode 100644 toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js create mode 100644 toolkit/components/extensions/test/mochitest/test_ext_extension_getViews.html create mode 100644 toolkit/components/extensions/test/mochitest/test_ext_runtime_getContexts.html create mode 100644 toolkit/components/extensions/test/xpcshell/test_ext_runtime_getContexts.js create mode 100644 toolkit/components/extensions/test/xpcshell/test_ext_service_worker_messaging.js delete mode 100644 toolkit/components/glean/docs/user/geckoview_streaming_migration.md create mode 100644 toolkit/components/glean/docs/user/ohttp.md create mode 100644 toolkit/components/ml/content/ONNXPipeline.mjs delete mode 100644 toolkit/components/ml/content/SummarizerModel.sys.mjs create mode 100644 toolkit/components/ml/content/Utils.sys.mjs delete mode 100644 toolkit/components/ml/docs/index.md create mode 100644 toolkit/components/ml/docs/index.rst create mode 100644 toolkit/components/ml/tests/browser/browser_ml_utils.js create mode 100644 toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/config.json create mode 100644 toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/onnx/config.json create mode 100644 toolkit/components/ml/vendor/LICENSE create mode 100644 toolkit/components/ml/vendor/README.md create mode 100755 toolkit/components/ml/vendor/build.sh create mode 100644 toolkit/components/ml/vendor/gecko.patch create mode 100644 toolkit/components/ml/vendor/moz.yaml create mode 100644 toolkit/components/ml/vendor/ort-dev.js create mode 100644 toolkit/components/ml/vendor/ort.js create mode 100644 toolkit/components/ml/vendor/transformers-dev.js create mode 100644 toolkit/components/ml/vendor/transformers.js delete mode 100644 toolkit/components/passwordmgr/nsILoginAutoCompleteSearch.idl create mode 100644 toolkit/components/places/PlacesCompletionCallback.idl create mode 100644 toolkit/components/places/tests/browser/browser_visituri_restriction.js create mode 100644 toolkit/components/places/tests/browser/browser_visituri_restriction_origin.js delete mode 100644 toolkit/components/places/tests/favicons/test_replaceFaviconData.js delete mode 100644 toolkit/components/places/tests/favicons/test_replaceFaviconDataFromDataURL.js create mode 100644 toolkit/components/places/tests/favicons/test_setFaviconForPage.js create mode 100644 toolkit/components/prompts/content/selectDialog.css create mode 100644 toolkit/components/reader/moz-slider.css create mode 100644 toolkit/components/reader/moz-slider.mjs create mode 100644 toolkit/components/reader/moz-slider.stories.mjs create mode 100644 toolkit/components/reader/tests/chrome/test_moz_slider.html create mode 100644 toolkit/components/satchel/megalist/content/Dialog.mjs delete mode 100644 toolkit/components/satchel/megalist/content/search-input.mjs create mode 100644 toolkit/components/satchel/test/browser/browser_autocomplete.js create mode 100644 toolkit/components/satchel/test/browser/formhistory_autocomplete.sqlite delete mode 100644 toolkit/components/satchel/test/unit/test_autocomplete.js delete mode 100644 toolkit/components/satchel/test/unit/test_previous_result.js create mode 100644 toolkit/components/search/docs/SearchConfigurationSchemaArchive.rst create mode 100644 toolkit/components/search/docs/SearchEnginesArchive.rst create mode 100644 toolkit/components/search/docs/SearchServiceHighlevelOverviewArchive.rst create mode 100644 toolkit/components/search/docs/assets/search-service-diagram-1.png create mode 100644 toolkit/components/search/docs/assets/search-service-diagram-2.png delete mode 100644 toolkit/components/search/docs/assets/search-service-diagram.png create mode 100644 toolkit/components/search/tests/xpcshell/test_webextensions_startup.js delete mode 100644 toolkit/components/sessionstore/SessionStoreFunctions.idl delete mode 100644 toolkit/components/sessionstore/SessionStoreFunctions.sys.mjs create mode 100644 toolkit/components/sessionstore/nsISessionStoreFunctions.idl delete mode 100644 toolkit/components/telemetry/geckoview/gtest/TestGeckoViewStreaming.cpp delete mode 100644 toolkit/components/telemetry/geckoview/gtest/moz.build delete mode 100644 toolkit/components/telemetry/geckoview/streaming/GeckoViewStreamingTelemetry.cpp delete mode 100644 toolkit/components/telemetry/geckoview/streaming/GeckoViewStreamingTelemetry.h delete mode 100644 toolkit/components/telemetry/geckoview/streaming/metrics.yaml delete mode 100644 toolkit/components/translations/tests/browser/translations-tester-empty-pdf-file.pdf create mode 100644 toolkit/components/translations/tests/browser/translations-tester-pdf-file.pdf delete mode 100644 toolkit/components/uniffi-example-custom-types/Cargo.toml delete mode 100644 toolkit/components/uniffi-example-custom-types/build.rs delete mode 100644 toolkit/components/uniffi-example-custom-types/src/custom-types.udl delete mode 100644 toolkit/components/uniffi-example-custom-types/src/lib.rs delete mode 100644 toolkit/components/uniffi-example-custom-types/tests/bindings/test_custom_types.kts delete mode 100644 toolkit/components/uniffi-example-custom-types/tests/bindings/test_custom_types.swift delete mode 100644 toolkit/components/uniffi-example-custom-types/tests/test_generated_bindings.rs delete mode 100644 toolkit/components/uniffi-example-custom-types/uniffi.toml delete mode 100644 toolkit/components/uniffi-fixture-callbacks/Cargo.toml delete mode 100644 toolkit/components/uniffi-fixture-callbacks/build.rs delete mode 100644 toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl delete mode 100644 toolkit/components/uniffi-fixture-callbacks/src/lib.rs delete mode 100644 toolkit/components/uniffi-fixture-external-types/Cargo.toml delete mode 100644 toolkit/components/uniffi-fixture-external-types/build.rs delete mode 100644 toolkit/components/uniffi-fixture-external-types/src/external-types.udl delete mode 100644 toolkit/components/uniffi-fixture-external-types/src/lib.rs delete mode 100644 toolkit/components/uniffi-fixture-refcounts/Cargo.toml delete mode 100644 toolkit/components/uniffi-fixture-refcounts/build.rs delete mode 100644 toolkit/components/uniffi-fixture-refcounts/src/lib.rs delete mode 100644 toolkit/components/uniffi-fixture-refcounts/src/refcounts.udl create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/build.rs create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/src/arithmetic.udl create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/tests/bindings/test_arithmetic.kts create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/tests/bindings/test_arithmetic.py create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/tests/bindings/test_arithmetic.rb create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/tests/bindings/test_arithmetic.swift create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/tests/test_generated_bindings.rs create mode 100644 toolkit/components/uniffi-fixtures/arithmetic/uniffi.toml create mode 100644 toolkit/components/uniffi-fixtures/callbacks/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/callbacks/build.rs create mode 100644 toolkit/components/uniffi-fixtures/callbacks/src/callbacks.udl create mode 100644 toolkit/components/uniffi-fixtures/callbacks/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/custom-types/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/custom-types/build.rs create mode 100644 toolkit/components/uniffi-fixtures/custom-types/src/custom-types.udl create mode 100644 toolkit/components/uniffi-fixtures/custom-types/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/custom-types/tests/bindings/test_custom_types.kts create mode 100644 toolkit/components/uniffi-fixtures/custom-types/tests/bindings/test_custom_types.swift create mode 100644 toolkit/components/uniffi-fixtures/custom-types/tests/test_generated_bindings.rs create mode 100644 toolkit/components/uniffi-fixtures/custom-types/uniffi.toml create mode 100644 toolkit/components/uniffi-fixtures/external-types/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/external-types/build.rs create mode 100644 toolkit/components/uniffi-fixtures/external-types/src/external-types.udl create mode 100644 toolkit/components/uniffi-fixtures/external-types/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/geometry/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/geometry/build.rs create mode 100644 toolkit/components/uniffi-fixtures/geometry/src/geometry.udl create mode 100644 toolkit/components/uniffi-fixtures/geometry/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/geometry/tests/bindings/test_geometry.kts create mode 100644 toolkit/components/uniffi-fixtures/geometry/tests/bindings/test_geometry.py create mode 100644 toolkit/components/uniffi-fixtures/geometry/tests/bindings/test_geometry.rb create mode 100644 toolkit/components/uniffi-fixtures/geometry/tests/bindings/test_geometry.swift create mode 100644 toolkit/components/uniffi-fixtures/geometry/tests/test_generated_bindings.rs create mode 100644 toolkit/components/uniffi-fixtures/refcounts/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/refcounts/build.rs create mode 100644 toolkit/components/uniffi-fixtures/refcounts/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/refcounts/src/refcounts.udl create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/build.rs create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/src/rondpoint.udl create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.kts create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.rb create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.swift create mode 100644 toolkit/components/uniffi-fixtures/rondpoint/tests/test_generated_bindings.rs create mode 100644 toolkit/components/uniffi-fixtures/sprites/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/sprites/build.rs create mode 100644 toolkit/components/uniffi-fixtures/sprites/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/sprites/src/sprites.udl create mode 100644 toolkit/components/uniffi-fixtures/sprites/tests/bindings/test_sprites.kts create mode 100644 toolkit/components/uniffi-fixtures/sprites/tests/bindings/test_sprites.py create mode 100644 toolkit/components/uniffi-fixtures/sprites/tests/bindings/test_sprites.rb create mode 100644 toolkit/components/uniffi-fixtures/sprites/tests/bindings/test_sprites.swift create mode 100644 toolkit/components/uniffi-fixtures/sprites/tests/test_generated_bindings.rs create mode 100644 toolkit/components/uniffi-fixtures/todolist/Cargo.toml create mode 100644 toolkit/components/uniffi-fixtures/todolist/build.rs create mode 100644 toolkit/components/uniffi-fixtures/todolist/src/lib.rs create mode 100644 toolkit/components/uniffi-fixtures/todolist/src/todolist.udl create mode 100644 toolkit/components/uniffi-fixtures/todolist/tests/bindings/test_todolist.kts create mode 100644 toolkit/components/uniffi-fixtures/todolist/tests/bindings/test_todolist.py create mode 100644 toolkit/components/uniffi-fixtures/todolist/tests/bindings/test_todolist.rb create mode 100644 toolkit/components/uniffi-fixtures/todolist/tests/bindings/test_todolist.swift create mode 100644 toolkit/components/uniffi-fixtures/todolist/tests/test_generated_bindings.rs create mode 100644 toolkit/content/tests/widgets/test_videocontrols_src_change.html delete mode 100644 toolkit/content/widgets/message-bar.css delete mode 100644 toolkit/content/widgets/message-bar.js delete mode 100644 toolkit/locales/en-US/toolkit/about/abuseReports.ftl delete mode 100644 toolkit/locales/en-US/toolkit/branding/accounts.ftl create mode 100644 toolkit/modules/LogManager.sys.mjs create mode 100644 toolkit/modules/sessionstore/SessionStoreHelper.sys.mjs create mode 100644 toolkit/modules/tests/xpcshell/test_LogManager.js create mode 100644 toolkit/mozapps/defaultagent/assets/fox-doodle-peek.png create mode 100644 toolkit/mozapps/defaultagent/jar.mn delete mode 100644 toolkit/mozapps/extensions/content/abuse-report-frame.html delete mode 100644 toolkit/mozapps/extensions/content/abuse-report-panel.css delete mode 100644 toolkit/mozapps/extensions/content/abuse-report-panel.js delete mode 100644 toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js delete mode 100644 toolkit/mozapps/extensions/test/browser/browser_html_abuse_report_dialog.js delete mode 100644 toolkit/mozapps/extensions/test/browser/browser_html_message_bar.js create mode 100644 toolkit/mozapps/extensions/test/browser/browser_html_options_ui_dark_theme.js delete mode 100644 toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js create mode 100644 toolkit/mozapps/macos-frameworks/ChannelPrefs-localbuild/Makefile.in create mode 100644 toolkit/mozapps/macos-frameworks/ChannelPrefs-localbuild/moz.build create mode 100644 toolkit/mozapps/update/updater/macos-frameworks/UpdateSettings-localbuild/Makefile.in create mode 100644 toolkit/mozapps/update/updater/macos-frameworks/UpdateSettings-localbuild/moz.build delete mode 100644 toolkit/themes/osx/reftests/482681-ref.xhtml delete mode 100644 toolkit/themes/osx/reftests/checkboxsize-ref.xhtml delete mode 100644 toolkit/themes/osx/reftests/checkboxsize.xhtml delete mode 100644 toolkit/themes/osx/reftests/radiosize-ref.xhtml delete mode 100644 toolkit/themes/osx/reftests/radiosize.xhtml delete mode 100644 toolkit/themes/osx/reftests/reftest.list create mode 100644 toolkit/themes/shared/icons/content-analysis.svg create mode 100644 toolkit/themes/shared/reader/align-center-20.svg create mode 100644 toolkit/themes/shared/reader/align-left-20.svg create mode 100644 toolkit/themes/shared/reader/align-right-20.svg create mode 100644 toolkit/themes/shared/reader/character-spacing-20.svg create mode 100644 toolkit/themes/shared/reader/content-width-20.svg create mode 100644 toolkit/themes/shared/reader/line-spacing-20.svg create mode 100644 toolkit/themes/shared/reader/word-spacing-20.svg delete mode 100644 toolkit/themes/shared/tree.css create mode 100644 toolkit/themes/shared/tree/sort-asc.svg create mode 100644 toolkit/themes/shared/tree/sort-dsc.svg create mode 100644 toolkit/themes/shared/tree/tree.css delete mode 100644 toolkit/themes/windows/global/tree/sort-asc.svg delete mode 100644 toolkit/themes/windows/global/tree/sort-dsc.svg (limited to 'toolkit') diff --git a/toolkit/actors/AutoCompleteChild.sys.mjs b/toolkit/actors/AutoCompleteChild.sys.mjs index 3694e497d5..61d48e9124 100644 --- a/toolkit/actors/AutoCompleteChild.sys.mjs +++ b/toolkit/actors/AutoCompleteChild.sys.mjs @@ -13,6 +13,10 @@ ChromeUtils.defineESModuleGetters(lazy, { LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs", }); +const gFormFillController = Cc[ + "@mozilla.org/satchel/form-fill-controller;1" +].getService(Ci.nsIFormFillController); + let autoCompleteListeners = new Set(); export class AutoCompleteChild extends JSWindowActorChild { @@ -137,6 +141,7 @@ export class AutoCompleteChild extends JSWindowActorChild { dir, inputElementIdentifier, formOrigin, + actorName: this.lastAutoCompleteProviderName, }); this._input = input; @@ -190,6 +195,154 @@ export class AutoCompleteChild extends JSWindowActorChild { return results; } + + getNoRollupOnEmptySearch(input) { + const providers = this.providersByInput(input); + return Array.from(providers).find(p => p.actorName == "LoginManager"); + } + + // Store the input to interested autocomplete providers mapping + #providersByInput = new WeakMap(); + + // This functions returns the interested providers that have called + // `markAsAutoCompletableField` for the given input and also the hard-coded + // autocomplete providers based on input type. + providersByInput(input) { + const providers = new Set(this.#providersByInput.get(input)); + + if (input.hasBeenTypePassword) { + providers.add( + input.ownerGlobal.windowGlobalChild.getActor("LoginManager") + ); + } else { + // The current design is that FormHisotry doesn't call `markAsAutoCompletable` + // for every eligilbe input. Instead, when FormFillController receives a focus event, + // it would control the if the is eligible to show form history. + // Because of the design, we need to ask FormHistory whether to search for autocomplete entries + // for every startSearch call + providers.add( + input.ownerGlobal.windowGlobalChild.getActor("FormHistory") + ); + } + return providers; + } + + /** + * This API should be used by an autocomplete entry provider to mark an input field + * as eligible for autocomplete for its type. + * When users click on an autocompletable input, we will search autocomplete entries + * from all the providers that have called this API for the given . + * + * An autocomplete provider should be a JSWindowActor and implements the following + * functions: + * - string actorName() + * - bool shouldSearchForAutoComplete(element); + * - jsval getAutoCompleteSearchOption(element); + * - jsval searchResultToAutoCompleteResult(searchString, element, record); + * See `FormAutofillChild` for example + * + * @param input - The HTML element that is considered autocompletable by the + * given provider + * @param provider - A module that provides autocomplete entries for a , for example, + * FormAutofill provides address or credit card autocomplete entries, + * LoginManager provides logins entreis. + */ + markAsAutoCompletableField(input, provider) { + gFormFillController.markAsAutoCompletableField(input); + + let providers = this.#providersByInput.get(input); + if (!providers) { + providers = new Set(); + this.#providersByInput.set(input, providers); + } + providers.add(provider); + } + + // Record the current ongoing search request. This is used by stopSearch + // to prevent notifying the autocomplete controller after receiving search request + // results that were issued prior to the call to stop the search. + #ongoingSearches = new Set(); + + async startSearch(searchString, input, listener) { + // TODO: This should be removed once we implement triggering autocomplete + // from the parent. + this.lastProfileAutoCompleteFocusedInput = input; + + // For all the autocomplete entry providers that previsouly marked + // this as autocompletable, ask the provider whether we should + // search for autocomplete entries in the parent. This is because the current + // design doesn't rely on the provider constantly monitor the and + // then mark/unmark an input. The provider generally calls the + // `markAsAutoCompletbleField` when it sees an is eliglbe for autocomplete. + // Here we ask the provider to exam the more detailedly to see + // whether we need to search for autocomplete entries at the time users + // click on the + const providers = this.providersByInput(input); + const data = Array.from(providers) + .filter(p => p.shouldSearchForAutoComplete(input, searchString)) + .map(p => ({ + actorName: p.actorName, + options: p.getAutoCompleteSearchOption(input, searchString), + })); + + let result = []; + + // We don't return empty result when no provider requests seaching entries in the + // parent because for some special cases, the autocomplete entries are coming + // from the content. For example, . + if (data.length) { + const promise = this.sendQuery("AutoComplete:StartSearch", { + searchString, + data, + }); + this.#ongoingSearches.add(promise); + result = await promise.catch(e => { + this.#ongoingSearches.delete(promise); + }); + result ||= []; + + // If the search is stopped, don't report back. + if (!this.#ongoingSearches.delete(promise)) { + return; + } + } + + for (const provider of providers) { + // Search result could be empty. However, an autocomplete provider might + // want to show an autocomplete popup when there is no search result. For example, + // for FormHisotry, insecure warning for LoginManager. + const searchResult = result.find(r => r.actorName == provider.actorName); + const acResult = provider.searchResultToAutoCompleteResult( + searchString, + input, + searchResult + ); + + // We have not yet supported showing autocomplete entries from multiple providers, + // Note: The prioty is defined in AutoCompleteParent. + if (acResult) { + // `lastAutoCompleteProviderName` should be removed once we implement + // the mapping of autocomplete entry to provider in the parent process. + this.lastAutoCompleteProviderName = provider.actorName; + + this.lastProfileAutoCompleteResult = acResult; + listener.onSearchCompletion(acResult); + return; + } + } + this.lastProfileAutoCompleteResult = null; + } + + stopSearch() { + this.lastProfileAutoCompleteResult = null; + this.#ongoingSearches.clear(); + } + + selectEntry() { + // we don't need to pass the selected index to the parent process because + // the selected index is maintained in the parent. + this.sendAsyncMessage("AutoComplete:SelectEntry"); + } } AutoCompleteChild.prototype.QueryInterface = ChromeUtils.generateQI([ diff --git a/toolkit/actors/AutoCompleteParent.sys.mjs b/toolkit/actors/AutoCompleteParent.sys.mjs index 70cbcea44d..4e0b030211 100644 --- a/toolkit/actors/AutoCompleteParent.sys.mjs +++ b/toolkit/actors/AutoCompleteParent.sys.mjs @@ -143,9 +143,13 @@ var AutoCompleteResultView = { this.results = []; }, - setResults(actor, results) { + setResults(actor, results, providerActorName) { this.currentActor = actor; this.results = results; + + if (providerActorName) { + this.providerActor = actor.manager.getActor(providerActorName); + } }, }; @@ -203,7 +207,7 @@ export class AutoCompleteParent extends JSWindowActorParent { } } - showPopupWithResults({ rect, dir, results }) { + showPopupWithResults({ rect, dir, results, actorName }) { if (!results.length || this.openedPopup) { // We shouldn't ever be showing an empty popup, and if we // already have a popup open, the old one needs to close before @@ -237,7 +241,8 @@ export class AutoCompleteParent extends JSWindowActorParent { ); this.openedPopup.style.direction = dir; - AutoCompleteResultView.setResults(this, results); + AutoCompleteResultView.setResults(this, results, actorName); + this.openedPopup.view = AutoCompleteResultView; this.openedPopup.selectedIndex = -1; @@ -376,7 +381,7 @@ export class AutoCompleteParent extends JSWindowActorParent { } } - receiveMessage(message) { + async receiveMessage(message) { let browser = this.browsingContext.top.embedderElement; if ( @@ -394,6 +399,13 @@ export class AutoCompleteParent extends JSWindowActorParent { } switch (message.name) { + case "AutoComplete:SelectEntry": { + if (this.openedPopup) { + this.autofillProfile(this.openedPopup.selectedIndex); + } + break; + } + case "AutoComplete:SetSelectedIndex": { let { index } = message.data; if (this.openedPopup) { @@ -403,8 +415,14 @@ export class AutoCompleteParent extends JSWindowActorParent { } case "AutoComplete:MaybeOpenPopup": { - let { results, rect, dir, inputElementIdentifier, formOrigin } = - message.data; + let { + results, + rect, + dir, + inputElementIdentifier, + formOrigin, + actorName, + } = message.data; if (lazy.DELEGATE_AUTOCOMPLETE) { lazy.GeckoViewAutocomplete.delegateSelection({ browsingContext: this.browsingContext, @@ -413,7 +431,7 @@ export class AutoCompleteParent extends JSWindowActorParent { formOrigin, }); } else { - this.showPopupWithResults({ results, rect, dir }); + this.showPopupWithResults({ results, rect, dir, actorName }); this.notifyListeners(); } break; @@ -433,6 +451,12 @@ export class AutoCompleteParent extends JSWindowActorParent { this.closePopup(); break; } + + case "AutoComplete:StartSearch": { + const { searchString, data } = message.data; + const result = await this.#startSearch(searchString, data); + return Promise.resolve(result); + } } // Returning false to pacify ESLint, but this return value is // ignored by the messaging infrastructure. @@ -493,8 +517,77 @@ export class AutoCompleteParent extends JSWindowActorParent { } } + // This defines the supported autocomplete providers and the prioity to show the autocomplete + // entry. + #AUTOCOMPLETE_PROVIDERS = ["FormAutofill", "LoginManager", "FormHistory"]; + + /** + * Search across multiple module to gather autocomplete entries for a given search string. + * + * @param {string} searchString + * The input string used to query autocomplete entries across different + * autocomplete providers. + * @param {Array} providers + * An array of objects where each object has a `name` used to identify the actor + * name of the provider and `options` that are passed to the `searchAutoCompleteEntries` + * method of the actor. + * @returns {Array} An array of results objects with `name` of the provider and `entries` + * that are returned from the provider module's `searchAutoCompleteEntries` method. + */ + async #startSearch(searchString, providers) { + for (const name of this.#AUTOCOMPLETE_PROVIDERS) { + const provider = providers.find(p => p.actorName == name); + if (!provider) { + continue; + } + const { actorName, options } = provider; + const actor = + this.browsingContext.currentWindowGlobal.getActor(actorName); + const entries = await actor?.searchAutoCompleteEntries( + searchString, + options + ); + + // We have not yet supported showing autocomplete entries from multiple providers, + if (entries) { + return [{ actorName, ...entries }]; + } + } + return []; + } + stopSearch() {} + previewAutofillProfile(index) { + const actor = AutoCompleteResultView.providerActor; + if (!actor) { + return; + } + + // Clear preview when the selected index is not valid + if (index < 0) { + actor.previewFields(null); + return; + } + + const result = AutoCompleteResultView.results[index]; + actor.previewFields(result); + } + + /** + * When a field is autocompleted, fill relevant fields + */ + autofillProfile(index) { + // Find the provider of this autocomplete + const actor = AutoCompleteResultView.providerActor; + if (index < 0 || !actor) { + return; + } + + const result = AutoCompleteResultView.results[index]; + actor.autofillFields(result); + } + /** * Sends a message to the browser that is requesting the input * that the open popup should be focused. diff --git a/toolkit/components/aboutprocesses/content/aboutProcesses.js b/toolkit/components/aboutprocesses/content/aboutProcesses.js index 3d80512407..88159c84ea 100644 --- a/toolkit/components/aboutprocesses/content/aboutProcesses.js +++ b/toolkit/components/aboutprocesses/content/aboutProcesses.js @@ -1110,7 +1110,7 @@ var Control = { // We've clicked on the extensions process, open or reuse window. let parentWin = window.docShell.browsingContext.embedderElement.ownerGlobal; - parentWin.BrowserOpenAddonsMgr(); + parentWin.BrowserAddonUI.openAddonsMgr(); return; } // Otherwise, proceed. diff --git a/toolkit/components/aboutwebauthn/content/aboutWebauthn.css b/toolkit/components/aboutwebauthn/content/aboutWebauthn.css index 5654e4276b..4f1cab1191 100644 --- a/toolkit/components/aboutwebauthn/content/aboutWebauthn.css +++ b/toolkit/components/aboutwebauthn/content/aboutWebauthn.css @@ -32,7 +32,7 @@ label { height: 1.5em; &.success { - background-color: var(--green-50); + background-color: var(--background-color-success); } &.error { diff --git a/toolkit/components/antitracking/AntiTrackingUtils.cpp b/toolkit/components/antitracking/AntiTrackingUtils.cpp index d9624237de..56d1b9e9e5 100644 --- a/toolkit/components/antitracking/AntiTrackingUtils.cpp +++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp @@ -567,9 +567,8 @@ AntiTrackingUtils::GetStoragePermissionStateInParent(nsIChannel* aChannel) { if (policyType == ExtContentPolicy::TYPE_SUBDOCUMENT) { // For loads of framed documents, we only use storage access - // if the load is the result of a same-origin, self-initiated + // if the load is the result of a same-origin, same-site-initiated // navigation of the frame. - uint64_t targetWindowIdNoTop = bc->GetCurrentInnerWindowId(); uint64_t triggeringWindowId; rv = loadInfo->GetTriggeringWindowId(&triggeringWindowId); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -581,10 +580,29 @@ AntiTrackingUtils::GetStoragePermissionStateInParent(nsIChannel* aChannel) { if (NS_WARN_IF(NS_FAILED(rv))) { return nsILoadInfo::NoStoragePermission; } + + nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); + RefPtr channelResultPrincipal; + rv = ssm->GetChannelResultPrincipal(aChannel, + getter_AddRefs(channelResultPrincipal)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return nsILoadInfo::NoStoragePermission; + } RefPtr httpChannel = do_QueryObject(aChannel); + bool crossSiteInitiated = false; + if (bc && bc->GetParent()->GetCurrentWindowContext()) { + RefPtr triggeringWGP = + WindowGlobalParent::GetByInnerWindowId(triggeringWindowId); + if (triggeringWGP && triggeringWGP->DocumentPrincipal()) { + rv = triggeringWGP->DocumentPrincipal()->IsThirdPartyPrincipal( + channelResultPrincipal, &crossSiteInitiated); + if (NS_FAILED(rv)) { + crossSiteInitiated = false; + } + } + } - if (targetWindowIdNoTop == triggeringWindowId && - triggeringWindowHasStorageAccess && + if (!crossSiteInitiated && triggeringWindowHasStorageAccess && trackingPrincipal->Equals(framePrincipal) && httpChannel && !httpChannel->HasRedirectTaintedOrigin()) { return nsILoadInfo::HasStoragePermission; @@ -880,7 +898,9 @@ bool AntiTrackingUtils::IsThirdPartyChannel(nsIChannel* aChannel) { } bool thirdParty = true; rv = tpuService->IsThirdPartyChannel(aChannel, nullptr, &thirdParty); - NS_ENSURE_SUCCESS(rv, true); + if (NS_FAILED(rv)) { + return true; + } return thirdParty; } @@ -955,7 +975,9 @@ bool AntiTrackingUtils::IsThirdPartyDocument(Document* aDocument) { nsresult rv = tpuService->IsThirdPartyChannel(aDocument->GetChannel(), nullptr, &thirdParty); - NS_ENSURE_SUCCESS(rv, true); + if (NS_FAILED(rv)) { + return true; + } return thirdParty; } diff --git a/toolkit/components/antitracking/StorageAccess.cpp b/toolkit/components/antitracking/StorageAccess.cpp index c18efb2b4c..9a3b6f7e2c 100644 --- a/toolkit/components/antitracking/StorageAccess.cpp +++ b/toolkit/components/antitracking/StorageAccess.cpp @@ -766,11 +766,23 @@ bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, RefPtr targetBC; rv = loadInfo->GetTargetBrowsingContext(getter_AddRefs(targetBC)); - if (!targetBC || NS_WARN_IF(NS_FAILED(rv))) { + if (NS_WARN_IF(NS_FAILED(rv))) { LOG(("Failed to get the channel's target browsing context")); return false; } + // If we cannot get the target browsing context from the loadInfo, the channel + // could be a fetch request from a worker scope. In this case, we get the + // target browsing context from the worker associated browsing context + // instead. + if (!targetBC) { + rv = loadInfo->GetWorkerAssociatedBrowsingContext(getter_AddRefs(targetBC)); + } + if (!targetBC || NS_WARN_IF(NS_FAILED(rv))) { + LOG(("No browsing context is available for the channel.")); + return false; + } + if (Document::StorageAccessSandboxed(targetBC->GetSandboxFlags())) { LOG(("Our document is sandboxed")); *aRejectedReason = blockedReason; diff --git a/toolkit/components/antitracking/StripOnShareLists/LGPL/StripOnShareLGPL.json b/toolkit/components/antitracking/StripOnShareLists/LGPL/StripOnShareLGPL.json index b34fbfff6b..78dd314f3f 100644 --- a/toolkit/components/antitracking/StripOnShareLists/LGPL/StripOnShareLGPL.json +++ b/toolkit/components/antitracking/StripOnShareLists/LGPL/StripOnShareLGPL.json @@ -114,7 +114,7 @@ }, "wikipedia": { "queryParams": ["wprov"], - "topLevelSites": ["www.wikipedia.org"] + "topLevelSites": ["www.wikipedia.org", "en.wikipedia.org"] }, "wallstreetjournal": { "queryParams": ["reflink"], @@ -166,7 +166,7 @@ }, "cnn": { "queryParams": ["ref"], - "topLevelSites": ["www.cnn.co.jp", "www.cnn.com"] + "topLevelSites": ["www.cnn.co.jp", "www.cnn.com", "edition.cnn.com"] }, "imdb": { "queryParams": [ @@ -177,7 +177,7 @@ "pf_rd_t", "pf_rd_r" ], - "topLevelSites": ["www.imdb.com"] + "topLevelSites": ["www.imdb.com", "m.imdb.com"] }, "mirror": { "queryParams": ["int_source"], @@ -210,7 +210,9 @@ "www.lazada.com.ph", "www.lazada.vn", "www.lazada.sg", - "www.lazada.com.my" + "www.lazada.com.my", + "pages.lazada.co.id", + "www.lazada.co.id" ] }, "msn": { @@ -240,7 +242,11 @@ "algo_expid", "gps-id" ], - "topLevelSites": ["www.tiktok.com"] + "topLevelSites": [ + "www.aliexpress.com", + "robotime.aliexpress.com", + "ar.aliexpress.com" + ] }, "reddit": { "queryParams": [ @@ -286,7 +292,7 @@ "_from", "hash" ], - "topLevelSites": ["www.ebay.com"] + "topLevelSites": ["www.ebay.com", "www.ebay.co.uk"] }, "flipkart": { "queryParams": [ @@ -518,7 +524,9 @@ "www.google.co.za", "www.google.co.zm", "www.google.co.zw", - "www.google.cat" + "www.google.cat", + "consent.google.de", + "support.google.com" ] }, "bing": { @@ -527,7 +535,7 @@ }, "twitch": { "queryParams": ["tt_content", "tt_medium"], - "topLevelSites": ["www.twitch.tv"] + "topLevelSites": ["www.twitch.tv", "dev.twitch.tv"] }, "cnet": { "queryParams": ["ftag"], @@ -543,7 +551,7 @@ }, "linkedin": { "queryParams": ["refId", "trk", "trackingId"], - "topLevelSites": ["ca.linkedin.com"] + "topLevelSites": ["ca.linkedin.com", "ro.linkedin.com"] }, "newyorker": { "queryParams": ["esrc", "bxid", "cndid", "source", "mbid"], diff --git a/toolkit/components/antitracking/URLQueryStrippingListService.sys.mjs b/toolkit/components/antitracking/URLQueryStrippingListService.sys.mjs index d9c1995821..2880ef4356 100644 --- a/toolkit/components/antitracking/URLQueryStrippingListService.sys.mjs +++ b/toolkit/components/antitracking/URLQueryStrippingListService.sys.mjs @@ -31,7 +31,7 @@ XPCOMUtils.defineLazyPreferenceGetter( PREF_STRIP_IS_TEST ); -async function fetchAndParseList(fileName) { +async function fetchList(fileName) { let response = await fetch( "chrome://global/content/antitracking/" + fileName ); @@ -43,14 +43,14 @@ async function fetchAndParseList(fileName) { "Error fetching strip-on-share strip list" + response.status ); } - return await response.json(); + return response.json(); } // Lazy getter for the strip-on-share strip list. ChromeUtils.defineLazyGetter(lazy, "StripOnShareList", async () => { let [stripOnShareList, stripOnShareLGPLParams] = await Promise.all([ - fetchAndParseList("StripOnShare.json"), - fetchAndParseList("StripOnShareLGPL.json"), + fetchList("StripOnShare.json"), + fetchList("StripOnShareLGPL.json"), ]); if (!stripOnShareList || !stripOnShareLGPLParams) { @@ -60,32 +60,40 @@ ChromeUtils.defineLazyGetter(lazy, "StripOnShareList", async () => { // Combines the mozilla licensed strip on share param // list and the LGPL licensed strip on share param list - for (const key in stripOnShareLGPLParams) { - if (Object.hasOwn(stripOnShareList, key)) { - stripOnShareList[key].queryParams.push( - ...stripOnShareLGPLParams[key].queryParams - ); - - stripOnShareList[key].topLevelSites.push( - ...stripOnShareLGPLParams[key].topLevelSites - ); + return combineAndParseLists(stripOnShareList, [stripOnShareLGPLParams]); +}); - // Removes duplicates topLevelSitres - stripOnShareList[key].topLevelSites = [ - ...new Set(stripOnShareList[key].topLevelSites), - ]; +function combineAndParseLists(mainList, arrOfLists) { + arrOfLists.forEach(additionalList => { + for (let key in additionalList) { + if (Object.hasOwn(mainList, key)) { + mainList[key].queryParams.push(...additionalList[key].queryParams); - // Removes duplicates queryParams - stripOnShareList[key].queryParams = [ - ...new Set(stripOnShareList[key].queryParams), - ]; - } else { - stripOnShareList[key] = stripOnShareLGPLParams[key]; + mainList[key].topLevelSites.push(...additionalList[key].topLevelSites); + } else { + mainList[key] = additionalList[key]; + } } + }); + + for (let key in mainList) { + mainList[key].queryParams = mainList[key].queryParams.map(param => + param.toLowerCase() + ); + + mainList[key].topLevelSites = mainList[key].topLevelSites.map(param => + param.toLowerCase() + ); + + // Removes duplicates topLevelSites + mainList[key].topLevelSites = [...new Set(mainList[key].topLevelSites)]; + + // Removes duplicates queryParams + mainList[key].queryParams = [...new Set(mainList[key].queryParams)]; } - return stripOnShareList; -}); + return mainList; +} export class URLQueryStrippingListService { classId = Components.ID("{afff16f0-3fd2-4153-9ccd-c6d9abd879e4}"); @@ -121,7 +129,7 @@ export class URLQueryStrippingListService { } async testSetList(testList) { - this.#stripOnShareTestList = testList; + this.#stripOnShareTestList = combineAndParseLists(testList, []); await this._notifyStripOnShareObservers(); } diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.cpp new file mode 100644 index 0000000000..2c00306441 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.cpp @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "BounceTrackingMapEntry.h" + +namespace mozilla { + +NS_IMPL_ISUPPORTS(BounceTrackingMapEntry, nsIBounceTrackingMapEntry); + +NS_IMETHODIMP BounceTrackingMapEntry::GetSiteHost(nsACString& aSiteHost) { + aSiteHost = mSiteHost; + return NS_OK; +} +NS_IMETHODIMP BounceTrackingMapEntry::GetTimeStamp(int64_t* aTimeStamp) { + *aTimeStamp = mTimeStamp; + return NS_OK; +} + +} // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.h b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.h new file mode 100644 index 0000000000..45d7237cff --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingMapEntry.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BounceTrackingMapEntry_h +#define mozilla_BounceTrackingMapEntry_h + +#include "nsIBounceTrackingMapEntry.h" +#include "nsString.h" + +namespace mozilla { + +/** + * Represents an entry in the global bounce tracker or user activation map. + */ +class BounceTrackingMapEntry final : public nsIBounceTrackingMapEntry { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIBOUNCETRACKINGMAPENTRY + + BounceTrackingMapEntry(const nsACString& aSiteHost, PRTime aTimeStamp) + : mSiteHost(aSiteHost), mTimeStamp(aTimeStamp) {} + + private: + ~BounceTrackingMapEntry() = default; + + nsAutoCString mSiteHost; + PRTime mTimeStamp; +}; + +} // namespace mozilla + +#endif diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.cpp index 2b0577d5c6..7882cd6d79 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.cpp @@ -7,6 +7,7 @@ #include "BounceTrackingProtectionStorage.h" #include "BounceTrackingState.h" #include "BounceTrackingRecord.h" +#include "BounceTrackingMapEntry.h" #include "BounceTrackingStateGlobal.h" #include "ErrorList.h" @@ -14,6 +15,7 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/ContentBlockingAllowList.h" #include "mozilla/Logging.h" +#include "mozilla/Maybe.h" #include "mozilla/Services.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/dom/Promise.h" @@ -21,6 +23,7 @@ #include "nsHashPropertyBag.h" #include "nsIClearDataService.h" #include "nsIObserverService.h" +#include "nsIPermissionManager.h" #include "nsIPrincipal.h" #include "nsISupports.h" #include "nsServiceManagerUtils.h" @@ -39,6 +42,10 @@ LazyLogModule gBounceTrackingProtectionLog("BounceTrackingProtection"); static StaticRefPtr sBounceTrackingProtection; +// Keeps track of whether the feature is enabled based on pref state. +// Initialized on first call of GetSingleton. +Maybe BounceTrackingProtection::sFeatureIsEnabled; + static constexpr uint32_t TRACKER_PURGE_FLAGS = nsIClearDataService::CLEAR_ALL_CACHES | nsIClearDataService::CLEAR_COOKIES | nsIClearDataService::CLEAR_DOM_STORAGES | @@ -53,10 +60,33 @@ already_AddRefed BounceTrackingProtection::GetSingleton() { MOZ_ASSERT(XRE_IsParentProcess()); - if (!StaticPrefs::privacy_bounceTrackingProtection_enabled_AtStartup()) { + // First call to GetSingleton, check main feature pref and record telemetry. + if (sFeatureIsEnabled.isNothing()) { + if (StaticPrefs::privacy_bounceTrackingProtection_enabled_AtStartup()) { + sFeatureIsEnabled = Some(true); + + glean::bounce_tracking_protection::enabled_at_startup.Set(true); + glean::bounce_tracking_protection::enabled_dry_run_mode_at_startup.Set( + StaticPrefs::privacy_bounceTrackingProtection_enableDryRunMode()); + } else { + sFeatureIsEnabled = Some(false); + + glean::bounce_tracking_protection::enabled_at_startup.Set(false); + glean::bounce_tracking_protection::enabled_dry_run_mode_at_startup.Set( + false); + + // Feature is disabled. + return nullptr; + } + } + MOZ_ASSERT(sFeatureIsEnabled.isSome()); + + // Feature is disabled. + if (!sFeatureIsEnabled.value()) { return nullptr; } + // Feature is enabled, lazily create singleton instance. if (!sBounceTrackingProtection) { sBounceTrackingProtection = new BounceTrackingProtection(); @@ -67,7 +97,25 @@ BounceTrackingProtection::GetSingleton() { } BounceTrackingProtection::BounceTrackingProtection() { - MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, ("constructor")); + MOZ_LOG( + gBounceTrackingProtectionLog, LogLevel::Info, + ("Init BounceTrackingProtection. Config: enableDryRunMode: %d, " + "bounceTrackingActivationLifetimeSec: %d, bounceTrackingGracePeriodSec: " + "%d, bounceTrackingPurgeTimerPeriodSec: %d, " + "clientBounceDetectionTimerPeriodMS: %d, requireStatefulBounces: %d, " + "HasMigratedUserActivationData: %d", + StaticPrefs::privacy_bounceTrackingProtection_enableDryRunMode(), + StaticPrefs:: + privacy_bounceTrackingProtection_bounceTrackingActivationLifetimeSec(), + StaticPrefs:: + privacy_bounceTrackingProtection_bounceTrackingGracePeriodSec(), + StaticPrefs:: + privacy_bounceTrackingProtection_bounceTrackingPurgeTimerPeriodSec(), + StaticPrefs:: + privacy_bounceTrackingProtection_clientBounceDetectionTimerPeriodMS(), + StaticPrefs::privacy_bounceTrackingProtection_requireStatefulBounces(), + StaticPrefs:: + privacy_bounceTrackingProtection_hasMigratedUserActivationData())); mStorage = new BounceTrackingProtectionStorage(); @@ -78,6 +126,12 @@ BounceTrackingProtection::BounceTrackingProtection() { return; } + rv = MaybeMigrateUserInteractionPermissions(); + if (NS_WARN_IF(NS_FAILED(rv))) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Error, + ("user activation permission migration failed")); + } + // Schedule timer for tracker purging. The timer interval is determined by // pref. uint32_t purgeTimerPeriod = StaticPrefs:: @@ -134,6 +188,11 @@ nsresult BounceTrackingProtection::RecordStatefulBounces( // For each host in navigable’s bounce tracking record's bounce set: for (const nsACString& host : record->GetBounceHosts()) { + // Skip "null" entries, they are only used for logging purposes. + if (host.EqualsLiteral("null")) { + continue; + } + // If host equals navigable’s bounce tracking record's initial host, // continue. if (host == record->GetInitialHost()) { @@ -187,9 +246,10 @@ nsresult BounceTrackingProtection::RecordStatefulBounces( } MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Info, - ("%s: Added candidate to mBounceTrackers: %s, Time: %" PRIu64, + ("%s: Added bounce tracker candidate. siteHost: %s, " + "aBounceTrackingState: %s", __FUNCTION__, PromiseFlatCString(host).get(), - static_cast(now))); + aBounceTrackingState->Describe().get())); } // Set navigable’s bounce tracking record to null. @@ -220,30 +280,34 @@ nsresult BounceTrackingProtection::RecordStatefulBounces( } nsresult BounceTrackingProtection::RecordUserActivation( - nsIPrincipal* aPrincipal) { + nsIPrincipal* aPrincipal, Maybe aActivationTime) { MOZ_ASSERT(XRE_IsParentProcess()); - NS_ENSURE_ARG_POINTER(aPrincipal); - NS_ENSURE_TRUE(aPrincipal->GetIsContentPrincipal(), NS_ERROR_FAILURE); + + if (!BounceTrackingState::ShouldTrackPrincipal(aPrincipal)) { + return NS_OK; + } nsAutoCString siteHost; nsresult rv = aPrincipal->GetBaseDomain(siteHost); NS_ENSURE_SUCCESS(rv, rv); - MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Info, + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, ("%s: siteHost: %s", __FUNCTION__, siteHost.get())); RefPtr globalState = mStorage->GetOrCreateStateGlobal(aPrincipal); MOZ_ASSERT(globalState); - return globalState->RecordUserActivation(siteHost, PR_Now()); + // aActivationTime defaults to current time if no value is provided. + return globalState->RecordUserActivation(siteHost, + aActivationTime.valueOr(PR_Now())); } NS_IMETHODIMP BounceTrackingProtection::TestGetBounceTrackerCandidateHosts( JS::Handle aOriginAttributes, JSContext* aCx, - nsTArray& aCandidates) { + nsTArray>& aCandidates) { MOZ_ASSERT(aCx); OriginAttributes oa; @@ -254,8 +318,11 @@ BounceTrackingProtection::TestGetBounceTrackerCandidateHosts( BounceTrackingStateGlobal* globalState = mStorage->GetOrCreateStateGlobal(oa); MOZ_ASSERT(globalState); - for (const nsACString& host : globalState->BounceTrackersMapRef().Keys()) { - aCandidates.AppendElement(host); + for (auto iter = globalState->BounceTrackersMapRef().ConstIter(); + !iter.Done(); iter.Next()) { + RefPtr candidate = + new BounceTrackingMapEntry(iter.Key(), iter.Data()); + aCandidates.AppendElement(candidate); } return NS_OK; @@ -264,7 +331,7 @@ BounceTrackingProtection::TestGetBounceTrackerCandidateHosts( NS_IMETHODIMP BounceTrackingProtection::TestGetUserActivationHosts( JS::Handle aOriginAttributes, JSContext* aCx, - nsTArray& aHosts) { + nsTArray>& aHosts) { MOZ_ASSERT(aCx); OriginAttributes oa; @@ -275,8 +342,11 @@ BounceTrackingProtection::TestGetUserActivationHosts( BounceTrackingStateGlobal* globalState = mStorage->GetOrCreateStateGlobal(oa); MOZ_ASSERT(globalState); - for (const nsACString& host : globalState->UserActivationMapRef().Keys()) { - aHosts.AppendElement(host); + for (auto iter = globalState->UserActivationMapRef().ConstIter(); + !iter.Done(); iter.Next()) { + RefPtr candidate = + new BounceTrackingMapEntry(iter.Key(), iter.Data()); + aHosts.AppendElement(candidate); } return NS_OK; @@ -419,6 +489,11 @@ BounceTrackingProtection::TestAddUserActivation( return stateGlobal->RecordUserActivation(host, aActivationTime); } +NS_IMETHODIMP +BounceTrackingProtection::TestMaybeMigrateUserInteractionPermissions() { + return MaybeMigrateUserInteractionPermissions(); +} + RefPtr BounceTrackingProtection::PurgeBounceTrackers() { // Prevent multiple purge operations from running at the same time. @@ -468,7 +543,7 @@ BounceTrackingProtection::PurgeBounceTrackers() { aResults) { MOZ_ASSERT(aResults.IsResolve(), "AllSettled never rejects"); - MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Info, + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, ("%s: Done. Cleared %zu hosts.", __FUNCTION__, aResults.ResolveValue().Length())); @@ -572,6 +647,10 @@ nsresult BounceTrackingProtection::PurgeBounceTrackersForStateGlobal( __FUNCTION__, PromiseFlatCString(host).get(), originAttributeSuffix.get())); } + // Remove allow-listed host so we don't need to check in again next purge + // run. If it gets classified again and the allow-list entry gets removed + // it will be purged in the next run. + bounceTrackerCandidatesToRemove.AppendElement(host); continue; } @@ -581,15 +660,23 @@ nsresult BounceTrackingProtection::PurgeBounceTrackersForStateGlobal( new ClearDataMozPromise::Private(__func__); RefPtr cb = new ClearDataCallback(clearPromise, host); - MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, - ("%s: Purge state for host: %s", __FUNCTION__, - PromiseFlatCString(host).get())); - - // TODO: Bug 1842067: Clear by site + OA. - rv = clearDataService->DeleteDataFromBaseDomain(host, false, - TRACKER_PURGE_FLAGS, cb); - if (NS_WARN_IF(NS_FAILED(rv))) { - clearPromise->Reject(0, __func__); + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Info, + ("%s: Purging bounce tracker. siteHost: %s, bounceTime: %" PRIu64 + " aStateGlobal: %s", + __FUNCTION__, PromiseFlatCString(host).get(), bounceTime, + aStateGlobal->Describe().get())); + + if (StaticPrefs::privacy_bounceTrackingProtection_enableDryRunMode()) { + // In dry-run mode, we don't actually clear the data, but we still want to + // resolve the promise to indicate that the data would have been cleared. + clearPromise->Resolve(host, __func__); + } else { + // TODO: Bug 1842067: Clear by site + OA. + rv = clearDataService->DeleteDataFromBaseDomain(host, false, + TRACKER_PURGE_FLAGS, cb); + if (NS_WARN_IF(NS_FAILED(rv))) { + clearPromise->Reject(0, __func__); + } } aClearPromises.AppendElement(clearPromise); @@ -642,22 +729,129 @@ nsresult BounceTrackingProtection::ClearExpiredUserInteractions( return NS_OK; } +nsresult BounceTrackingProtection::MaybeMigrateUserInteractionPermissions() { + // Only run the migration once. + if (StaticPrefs:: + privacy_bounceTrackingProtection_hasMigratedUserActivationData()) { + return NS_OK; + } + + MOZ_LOG( + gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: Importing user activation data from permissions", __FUNCTION__)); + + // Get all user activation permissions that are within our user activation + // lifetime. We don't care about the rest since they are considered expired + // for BTP. + + nsresult rv = NS_OK; + nsCOMPtr permManager = + do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(permManager, NS_ERROR_FAILURE); + + // Construct the since time param. The permission manager expects epoch in + // miliseconds. + int64_t nowMS = PR_Now() / PR_USEC_PER_MSEC; + int64_t activationLifetimeMS = + static_cast( + StaticPrefs:: + privacy_bounceTrackingProtection_bounceTrackingActivationLifetimeSec()) * + PR_MSEC_PER_SEC; + int64_t since = nowMS - activationLifetimeMS; + MOZ_ASSERT(since > 0); + + // Get all user activation permissions last modified between "since" and now. + nsTArray> userActivationPermissions; + rv = permManager->GetAllByTypeSince("storageAccessAPI"_ns, since, + userActivationPermissions); + NS_ENSURE_SUCCESS(rv, rv); + + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: Found %zu (non-expired) user activation permissions", + __FUNCTION__, userActivationPermissions.Length())); + + for (const auto& perm : userActivationPermissions) { + nsCOMPtr permPrincipal; + + rv = perm->GetPrincipal(getter_AddRefs(permPrincipal)); + if (NS_WARN_IF(NS_FAILED(rv))) { + continue; + } + MOZ_ASSERT(permPrincipal); + + // The time the permission was last modified is the time of last user + // activation. + int64_t modificationTimeMS; + rv = perm->GetModificationTime(&modificationTimeMS); + NS_ENSURE_SUCCESS(rv, rv); + MOZ_ASSERT(modificationTimeMS >= since, + "Unexpected permission modification time"); + + // We may end up with duplicates here since user activation permissions are + // tracked by origin, while BTP tracks user activation by site host. + // RecordUserActivation is responsible for only keeping the most recent user + // activation flag for a given site host and needs to make sure existing + // activation flags are not overwritten by older timestamps. + // RecordUserActivation expects epoch in microseconds. + rv = RecordUserActivation(permPrincipal, + Some(modificationTimeMS * PR_USEC_PER_MSEC)); + if (NS_WARN_IF(NS_FAILED(rv))) { + continue; + } + } + + // Migration successful, set the pref to indicate that we have migrated. + return mozilla::Preferences::SetBool( + "privacy.bounceTrackingProtection.hasMigratedUserActivationData", true); +} + // ClearDataCallback NS_IMPL_ISUPPORTS(BounceTrackingProtection::ClearDataCallback, nsIClearDataCallback); +BounceTrackingProtection::ClearDataCallback::ClearDataCallback( + ClearDataMozPromise::Private* aPromise, const nsACString& aHost) + : mHost(aHost), mClearDurationTimer(0), mPromise(aPromise) { + MOZ_ASSERT(!aHost.IsEmpty(), "Host must not be empty"); + if (!StaticPrefs::privacy_bounceTrackingProtection_enableDryRunMode()) { + // Only collect timing information when actually performing the deletion + mClearDurationTimer = + glean::bounce_tracking_protection::purge_duration.Start(); + MOZ_ASSERT(mClearDurationTimer); + } +}; + +BounceTrackingProtection::ClearDataCallback::~ClearDataCallback() { + mPromise->Reject(0, __func__); + if (mClearDurationTimer) { + glean::bounce_tracking_protection::purge_duration.Cancel( + std::move(mClearDurationTimer)); + } +} + // nsIClearDataCallback implementation NS_IMETHODIMP BounceTrackingProtection::ClearDataCallback::OnDataDeleted( uint32_t aFailedFlags) { if (aFailedFlags) { mPromise->Reject(aFailedFlags, __func__); } else { - MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Info, + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, ("%s: Cleared %s", __FUNCTION__, mHost.get())); mPromise->Resolve(std::move(mHost), __func__); } + RecordClearDurationTelemetry(); return NS_OK; } +void BounceTrackingProtection::ClearDataCallback:: + RecordClearDurationTelemetry() { + if (mClearDurationTimer) { + glean::bounce_tracking_protection::purge_duration.StopAndAccumulate( + std::move(mClearDurationTimer)); + mClearDurationTimer = 0; + } +} + } // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.h b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.h index e99cf895be..98b235ead1 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.h +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtection.h @@ -6,8 +6,10 @@ #include "mozilla/Logging.h" #include "mozilla/MozPromise.h" +#include "mozilla/glean/GleanMetrics.h" #include "nsIBounceTrackingProtection.h" #include "nsIClearDataService.h" +#include "mozilla/Maybe.h" class nsIPrincipal; class nsITimer; @@ -37,8 +39,11 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection { [[nodiscard]] nsresult RecordStatefulBounces( BounceTrackingState* aBounceTrackingState); - // Stores a user activation flag with a timestamp for the given principal. - [[nodiscard]] nsresult RecordUserActivation(nsIPrincipal* aPrincipal); + // Stores a user activation flag with a timestamp for the given principal. The + // timestamp defaults to the current time, but can be overridden via + // aActivationTime. + [[nodiscard]] nsresult RecordUserActivation( + nsIPrincipal* aPrincipal, Maybe aActivationTime = Nothing()); // Clears expired user interaction flags for the given state global. If // aStateGlobal == nullptr, clears expired user interaction flags for all @@ -50,6 +55,10 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection { BounceTrackingProtection(); ~BounceTrackingProtection() = default; + // Keeps track of whether the feature is enabled based on pref state. + // Initialized on first call of GetSingleton. + static Maybe sFeatureIsEnabled; + // Timer which periodically runs PurgeBounceTrackers. nsCOMPtr mBounceTrackingPurgeTimer; @@ -82,15 +91,23 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection { NS_DECL_NSICLEARDATACALLBACK explicit ClearDataCallback(ClearDataMozPromise::Private* aPromise, - const nsACString& aHost) - : mHost(aHost), mPromise(aPromise){}; + const nsACString& aHost); private: - virtual ~ClearDataCallback() { mPromise->Reject(0, __func__); } + virtual ~ClearDataCallback(); nsCString mHost; + + void RecordClearDurationTelemetry(); + + glean::TimerId mClearDurationTimer; RefPtr mPromise; }; + + // Imports user activation permissions from permission manager if needed. This + // is important so we don't purge data for sites the user has interacted with + // before the feature was enabled. + [[nodiscard]] nsresult MaybeMigrateUserInteractionPermissions(); }; } // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtectionStorage.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtectionStorage.cpp index bdd2c7dc18..d3a7cb9062 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtectionStorage.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingProtectionStorage.cpp @@ -15,9 +15,8 @@ #include "mozStorageCID.h" #include "mozilla/Components.h" #include "mozilla/Monitor.h" -#include "mozilla/AppShutdown.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Services.h" -#include "mozilla/ShutdownPhase.h" #include "nsCOMPtr.h" #include "nsDirectoryServiceUtils.h" #include "nsIObserverService.h" @@ -464,19 +463,19 @@ nsresult BounceTrackingProtectionStorage::Init() { nsresult rv = self->CreateDatabaseConnection(); if (NS_WARN_IF(NS_FAILED(rv))) { self->mErrored.Flip(); - self->mMonitor.Notify(); + self->mMonitor.NotifyAll(); return; } rv = self->LoadMemoryStateFromDisk(); if (NS_WARN_IF(NS_FAILED(rv))) { self->mErrored.Flip(); - self->mMonitor.Notify(); + self->mMonitor.NotifyAll(); return; } self->mInitialized.Flip(); - self->mMonitor.Notify(); + self->mMonitor.NotifyAll(); }), NS_DISPATCH_EVENT_MAY_BLOCK); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingRecord.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingRecord.cpp index d4b33f9edb..c522895638 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingRecord.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingRecord.cpp @@ -29,6 +29,8 @@ const nsACString& BounceTrackingRecord::GetFinalHost() const { } void BounceTrackingRecord::AddBounceHost(const nsACString& aHost) { + MOZ_ASSERT(!aHost.IsEmpty()); + mBounceHosts.Insert(aHost); MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, ("%s: %s", __FUNCTION__, Describe().get())); @@ -54,6 +56,8 @@ nsCString BounceTrackingRecord::DescribeSet(const nsTHashSet& set) { } void BounceTrackingRecord::AddStorageAccessHost(const nsACString& aHost) { + MOZ_ASSERT(!aHost.IsEmpty()); + mStorageAccessHosts.Insert(aHost); } diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp index b4af3daa07..08716b44ae 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp @@ -29,6 +29,7 @@ #include "mozilla/ClearOnShutdown.h" #include "nsTHashMap.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/WindowContext.h" namespace mozilla { @@ -54,8 +55,13 @@ BounceTrackingState::~BounceTrackingState() { // static already_AddRefed BounceTrackingState::GetOrCreate( - dom::BrowsingContextWebProgress* aWebProgress) { - MOZ_ASSERT(aWebProgress); + dom::BrowsingContextWebProgress* aWebProgress, nsresult& aRv) { + aRv = NS_OK; + + if (!aWebProgress) { + aRv = NS_ERROR_INVALID_ARG; + return nullptr; + } if (!ShouldCreateBounceTrackingStateForWebProgress(aWebProgress)) { return nullptr; @@ -73,8 +79,8 @@ already_AddRefed BounceTrackingState::GetOrCreate( sStorageObserver = new BounceTrackingStorageObserver(); ClearOnShutdown(&sStorageObserver); - DebugOnly rv = sStorageObserver->Init(); - NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to init storage observer"); + aRv = sStorageObserver->Init(); + NS_ENSURE_SUCCESS(aRv, nullptr); } dom::BrowsingContext* browsingContext = aWebProgress->GetBrowsingContext(); @@ -82,7 +88,8 @@ already_AddRefed BounceTrackingState::GetOrCreate( return nullptr; } uint64_t browserId = browsingContext->BrowserId(); - bool createdNew; + bool createdNew = false; + RefPtr bounceTrackingState = do_AddRef(sBounceTrackingStates->LookupOrInsertWith(browserId, [&] { createdNew = true; @@ -90,8 +97,10 @@ already_AddRefed BounceTrackingState::GetOrCreate( })); if (createdNew) { - nsresult rv = bounceTrackingState->Init(aWebProgress); - if (NS_WARN_IF(NS_FAILED(rv))) { + aRv = bounceTrackingState->Init(aWebProgress); + if (NS_FAILED(aRv)) { + NS_WARNING("Failed to initialize BounceTrackingState."); + sBounceTrackingStates->Remove(browserId); return nullptr; } } @@ -116,6 +125,10 @@ void BounceTrackingState::ResetAllForOriginAttributesPattern( nsresult BounceTrackingState::Init( dom::BrowsingContextWebProgress* aWebProgress) { + MOZ_ASSERT(!mIsInitialized, + "BounceTrackingState must not be initialized twice."); + mIsInitialized = true; + NS_ENSURE_ARG_POINTER(aWebProgress); NS_ENSURE_TRUE( StaticPrefs::privacy_bounceTrackingProtection_enabled_AtStartup(), @@ -156,9 +169,10 @@ nsCString BounceTrackingState::Describe() { OriginAttributesRef().CreateSuffix(oaSuffix); return nsPrintfCString( - "{ mBounceTrackingRecord: %s, mOriginAttributes: %s }", + "{ mBounceTrackingRecord: %s, mOriginAttributes: %s, mBrowserId: %" PRIu64 + " }", mBounceTrackingRecord ? mBounceTrackingRecord->Describe().get() : "null", - oaSuffix.get()); + oaSuffix.get(), mBrowserId); } // static @@ -211,6 +225,28 @@ bool BounceTrackingState::ShouldCreateBounceTrackingStateForWebProgress( return true; } +// static +bool BounceTrackingState::ShouldTrackPrincipal(nsIPrincipal* aPrincipal) { + MOZ_ASSERT(aPrincipal); + + // Only track content principals. + if (!aPrincipal->GetIsContentPrincipal()) { + return false; + } + + // Skip non http schemes. + if (!aPrincipal->SchemeIs("http") && !aPrincipal->SchemeIs("https")) { + return false; + } + + // Skip partitioned principals. + if (!aPrincipal->OriginAttributesRef().mPartitionKey.IsEmpty()) { + return false; + } + + return true; +} + // static nsresult BounceTrackingState::HasBounceTrackingStateForSite( const nsACString& aSiteHost, bool& aResult) { @@ -285,6 +321,10 @@ nsresult BounceTrackingState::OnDocumentStartRequest(nsIChannel* aChannel) { nsresult rv = aChannel->GetLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_SUCCESS(rv, rv); + // Used to keep track of whether we added entries to the site list that are + // not "null". + bool siteListIsEmpty = true; + // Collect uri list including any redirects. nsTArray siteList; @@ -294,8 +334,8 @@ nsresult BounceTrackingState::OnDocumentStartRequest(nsIChannel* aChannel) { rv = redirectHistoryEntry->GetPrincipal(getter_AddRefs(principal)); NS_ENSURE_SUCCESS(rv, rv); - // Filter out non-content principals. - if (!principal->GetIsContentPrincipal()) { + if (!BounceTrackingState::ShouldTrackPrincipal(principal)) { + siteList.AppendElement("null"_ns); continue; } @@ -303,7 +343,12 @@ nsresult BounceTrackingState::OnDocumentStartRequest(nsIChannel* aChannel) { rv = principal->GetBaseDomain(baseDomain); NS_ENSURE_SUCCESS(rv, rv); - siteList.AppendElement(baseDomain); + if (NS_WARN_IF(baseDomain.IsEmpty())) { + siteList.AppendElement("null"); + } else { + siteList.AppendElement(baseDomain); + siteListIsEmpty = false; + } } // Add site via the current URI which is the end of the chain. @@ -311,18 +356,35 @@ nsresult BounceTrackingState::OnDocumentStartRequest(nsIChannel* aChannel) { rv = aChannel->GetURI(getter_AddRefs(channelURI)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr tldService = - do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (channelURI->SchemeIs("http") || channelURI->SchemeIs("https")) { + nsCOMPtr tldService = + do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - nsAutoCString siteHost; - rv = tldService->GetSchemelessSite(channelURI, siteHost); + nsAutoCString siteHost; + rv = tldService->GetSchemelessSite(channelURI, siteHost); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to retrieve site for final channel URI."); + // Skip URIs where we can't get a site host. + if (NS_FAILED(rv)) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: Failed to get site host from channelURI: %s", __FUNCTION__, + channelURI->GetSpecOrDefault().get())); + siteList.AppendElement("null"_ns); + } else { + MOZ_ASSERT(!siteHost.IsEmpty(), "siteHost should not be empty."); + siteList.AppendElement(siteHost); + siteListIsEmpty = false; + } } - siteList.AppendElement(siteHost); + // Do not record empty site lists. This can happen if none of the principals + // are suitable for tracking. It includes when OnDocumentStartRequest is + // called for the initial about:blank. + if (siteListIsEmpty) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: skip empty site list.", __FUNCTION__)); + return NS_OK; + } return OnResponseReceived(siteList); } @@ -437,16 +499,16 @@ nsresult BounceTrackingState::OnStartNavigation( // If origin is an opaque origin, set initialHost to empty host. Strictly // speaking we only need to check IsNullPrincipal, but we're generally only - // interested in content principals. Other principal types are not considered - // to be trackers. - if (!aTriggeringPrincipal->GetIsContentPrincipal()) { - siteHost = ""; - } - - // obtain site - nsresult rv = aTriggeringPrincipal->GetBaseDomain(siteHost); - if (NS_WARN_IF(NS_FAILED(rv))) { + // interested in content principals with http/s scheme. Other principal types + // or schemes are not considered to be trackers. + if (!BounceTrackingState::ShouldTrackPrincipal(aTriggeringPrincipal)) { siteHost = ""; + } else { + // obtain site + nsresult rv = aTriggeringPrincipal->GetBaseDomain(siteHost); + if (NS_WARN_IF(NS_FAILED(rv))) { + siteHost = ""; + } } // If navigable’s bounce tracking record is null: Set navigable’s bounce @@ -474,7 +536,7 @@ nsresult BounceTrackingState::OnStartNavigation( ("%s: site: %s, hasUserActivation? %d", __FUNCTION__, siteHost.get(), hasUserActivation)); if (hasUserActivation) { - rv = mBounceTrackingProtection->RecordStatefulBounces(this); + nsresult rv = mBounceTrackingProtection->RecordStatefulBounces(this); NS_ENSURE_SUCCESS(rv, rv); MOZ_ASSERT(!mBounceTrackingRecord); @@ -485,7 +547,11 @@ nsresult BounceTrackingState::OnStartNavigation( } // There is no transient user activation. Add host as a bounce candidate. - mBounceTrackingRecord->AddBounceHost(siteHost); + if (siteHost.IsEmpty()) { + mBounceTrackingRecord->AddBounceHost("null"_ns); + } else { + mBounceTrackingRecord->AddBounceHost(siteHost); + } return NS_OK; } @@ -494,7 +560,12 @@ nsresult BounceTrackingState::OnStartNavigation( nsresult BounceTrackingState::OnResponseReceived( const nsTArray& aSiteList) { - NS_ENSURE_TRUE(mBounceTrackingRecord, NS_ERROR_FAILURE); +#ifdef DEBUG + MOZ_ASSERT(!aSiteList.IsEmpty(), "siteList should not be empty."); + for (const nsCString& site : aSiteList) { + MOZ_ASSERT(!site.IsEmpty(), "site should not be an empty string."); + } +#endif // Logging if (MOZ_LOG_TEST(gBounceTrackingProtectionLog, LogLevel::Debug)) { @@ -510,6 +581,9 @@ nsresult BounceTrackingState::OnResponseReceived( siteListStr.get())); } + // Record should exist by now. It gets created in OnStartNavigation. + NS_ENSURE_TRUE(mBounceTrackingRecord, NS_ERROR_FAILURE); + // Check if there is still an active timeout. This shouldn't happen since // OnStartNavigation already cancels it. if (NS_WARN_IF(mClientBounceDetectionTimeout)) { @@ -567,9 +641,6 @@ nsresult BounceTrackingState::OnDocumentLoaded( nsIPrincipal* aDocumentPrincipal) { NS_ENSURE_ARG_POINTER(aDocumentPrincipal); - // Assert: navigable’s bounce tracking record is not null. - NS_ENSURE_TRUE(mBounceTrackingRecord, NS_ERROR_FAILURE); - // Logging if (MOZ_LOG_TEST(gBounceTrackingProtectionLog, LogLevel::Debug)) { nsAutoCString origin; @@ -578,14 +649,15 @@ nsresult BounceTrackingState::OnDocumentLoaded( origin = "err"; } MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, - ("%s: origin: %s, mBounceTrackingRecord: %s", __FUNCTION__, - origin.get(), - mBounceTrackingRecord ? mBounceTrackingRecord->Describe().get() - : "null")); + ("%s: origin: %s, this: %s", __FUNCTION__, origin.get(), + Describe().get())); } + // Assert: navigable’s bounce tracking record is not null. + NS_ENSURE_TRUE(mBounceTrackingRecord, NS_ERROR_FAILURE); + nsAutoCString siteHost; - if (!aDocumentPrincipal->GetIsContentPrincipal()) { + if (!BounceTrackingState::ShouldTrackPrincipal(aDocumentPrincipal)) { siteHost = ""; } else { nsresult rv = aDocumentPrincipal->GetBaseDomain(siteHost); @@ -614,4 +686,36 @@ nsresult BounceTrackingState::OnCookieWrite(const nsACString& aSiteHost) { return NS_OK; } +nsresult BounceTrackingState::OnStorageAccess(nsIPrincipal* aPrincipal) { + NS_ENSURE_ARG_POINTER(aPrincipal); + // The caller should already filter out principals for us. + MOZ_ASSERT(BounceTrackingState::ShouldTrackPrincipal(aPrincipal)); + + if (MOZ_LOG_TEST(gBounceTrackingProtectionLog, LogLevel::Debug)) { + nsAutoCString origin; + nsresult rv = aPrincipal->GetOrigin(origin); + if (NS_FAILED(rv)) { + origin = "err"; + } + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: origin: %s, mBounceTrackingRecord: %s", __FUNCTION__, + origin.get(), + mBounceTrackingRecord ? mBounceTrackingRecord->Describe().get() + : "null")); + } + + if (!mBounceTrackingRecord) { + return NS_OK; + } + + nsAutoCString siteHost; + nsresult rv = aPrincipal->GetBaseDomain(siteHost); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(!siteHost.IsEmpty(), NS_ERROR_FAILURE); + + mBounceTrackingRecord->AddStorageAccessHost(siteHost); + + return NS_OK; +} + } // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.h b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.h index 17d324bda9..a9e186206a 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.h +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.h @@ -45,7 +45,7 @@ class BounceTrackingState : public nsIWebProgressListener, // return nullptr if the given web progress / browsing context is not suitable // (see ShouldCreateBounceTrackingStateForWebProgress). static already_AddRefed GetOrCreate( - dom::BrowsingContextWebProgress* aWebProgress); + dom::BrowsingContextWebProgress* aWebProgress, nsresult& aRv); // Reset state for all BounceTrackingState instances this includes resetting // BounceTrackingRecords and cancelling any running timers. @@ -62,31 +62,35 @@ class BounceTrackingState : public nsIWebProgressListener, // Callback for when we received a response from the server and are about to // create a document for the response. Calls into // BounceTrackingState::OnResponseReceived. - nsresult OnDocumentStartRequest(nsIChannel* aChannel); + [[nodiscard]] nsresult OnDocumentStartRequest(nsIChannel* aChannel); // At the start of a navigation, either initialize a new bounce tracking // record, or append a client-side redirect to the current bounce tracking // record. // Should only be called for top level content navigations. - nsresult OnStartNavigation(nsIPrincipal* aTriggeringPrincipal, - const bool aHasValidUserGestureActivation); + [[nodiscard]] nsresult OnStartNavigation( + nsIPrincipal* aTriggeringPrincipal, + const bool aHasValidUserGestureActivation); // Record sites which have written cookies in the current extended // navigation. - nsresult OnCookieWrite(const nsACString& aSiteHost); + [[nodiscard]] nsresult OnCookieWrite(const nsACString& aSiteHost); // Whether the given BrowsingContext should hold a BounceTrackingState // instance to monitor bounce tracking navigations. static bool ShouldCreateBounceTrackingStateForBC( dom::CanonicalBrowsingContext* aBrowsingContext); + // Whether the given principal should be tracked for bounce tracking. + static bool ShouldTrackPrincipal(nsIPrincipal* aPrincipal); + // Check if there is a BounceTrackingState which current browsing context is // associated with aSiteHost. // This is an approximation for checking if a given site is currently loaded // in the top level context, e.g. in a tab. See Bug 1842047 for adding a more // accurate check that calls into the browser implementations. - static nsresult HasBounceTrackingStateForSite(const nsACString& aSiteHost, - bool& aResult); + [[nodiscard]] static nsresult HasBounceTrackingStateForSite( + const nsACString& aSiteHost, bool& aResult); // Get the currently associated BrowsingContext. Returns nullptr if it has not // been attached yet. @@ -99,10 +103,16 @@ class BounceTrackingState : public nsIWebProgressListener, // Create a string that describes this object. Used for logging. nsCString Describe(); + // Record sites which have accessed storage in the current extended + // navigation. + [[nodiscard]] nsresult OnStorageAccess(nsIPrincipal* aPrincipal); + private: explicit BounceTrackingState(); virtual ~BounceTrackingState(); + bool mIsInitialized{false}; + uint64_t mBrowserId{}; // OriginAttributes associated with the browser this state is attached to. @@ -130,25 +140,20 @@ class BounceTrackingState : public nsIWebProgressListener, dom::BrowsingContextWebProgress* aWebProgress); // Init to be called after creation, attaches nsIWebProgressListener. - nsresult Init(dom::BrowsingContextWebProgress* aWebProgress); + [[nodiscard]] nsresult Init(dom::BrowsingContextWebProgress* aWebProgress); // When the response is received at the end of a navigation, fill the // bounce set. - nsresult OnResponseReceived(const nsTArray& aSiteList); + [[nodiscard]] nsresult OnResponseReceived( + const nsTArray& aSiteList); // When the document is loaded at the end of a navigation, update the // final host. - nsresult OnDocumentLoaded(nsIPrincipal* aDocumentPrincipal); - - // TODO: Bug 1839918: Detection of stateful bounces. - - // Record sites which have accessed storage in the current extended - // navigation. - nsresult OnStorageAccess(); + [[nodiscard]] nsresult OnDocumentLoaded(nsIPrincipal* aDocumentPrincipal); // Record sites which have activated service workers in the current // extended navigation. - nsresult OnServiceWorkerActivation(); + [[nodiscard]] nsresult OnServiceWorkerActivation(); }; } // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStateGlobal.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStateGlobal.cpp index b94c887c90..bcd9e57bd8 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStateGlobal.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStateGlobal.cpp @@ -9,6 +9,7 @@ #include "ErrorList.h" #include "mozilla/Assertions.h" #include "mozilla/Logging.h" +#include "mozilla/IntegerPrintfMacros.h" #include "nsIPrincipal.h" namespace mozilla { @@ -42,6 +43,19 @@ nsresult BounceTrackingStateGlobal::RecordUserActivation( __FUNCTION__, PromiseFlatCString(aSiteHost).get())); } + // Make sure we don't overwrite an existing, more recent user activation. This + // is only relevant for callers that pass in a timestamp that isn't PR_Now(), + // e.g. when importing user activation data. + Maybe existingUserActivation = mUserActivation.MaybeGet(aSiteHost); + if (existingUserActivation.isSome() && + existingUserActivation.value() >= aTime) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug, + ("%s: Skip: A more recent user activation " + "already exists for %s", + __FUNCTION__, PromiseFlatCString(aSiteHost).get())); + return NS_OK; + } + mUserActivation.InsertOrUpdate(aSiteHost, aTime); if (aSkipStorage || !ShouldPersistToDisk()) { diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.cpp index cc9c3ce971..fcc806e0f4 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.cpp @@ -6,14 +6,15 @@ #include "BounceTrackingState.h" #include "mozilla/Services.h" -#include "mozilla/StaticPrefs_privacy.h" -#include "mozilla/ClearOnShutdown.h" -#include "mozilla/dom/CanonicalBrowsingContext.h" +#include "mozilla/dom/WindowContext.h" +#include "mozilla/dom/WindowGlobalChild.h" +#include "mozilla/dom/WindowGlobalParent.h" #include "nsCOMPtr.h" #include "nsICookieNotification.h" #include "nsIObserverService.h" #include "mozilla/dom/BrowsingContext.h" #include "nsICookie.h" +#include "nsIPrincipal.h" namespace mozilla { @@ -69,13 +70,25 @@ BounceTrackingStorageObserver::Observe(nsISupports* aSubject, return NS_OK; } - // Check if the cookie is partitioned. Partitioned cookies can not be used for - // bounce tracking. + // Filter http(s) cookies nsCOMPtr cookie; rv = notification->GetCookie(getter_AddRefs(cookie)); NS_ENSURE_SUCCESS(rv, rv); MOZ_ASSERT(cookie); + nsICookie::schemeType schemeMap; + rv = cookie->GetSchemeMap(&schemeMap); + NS_ENSURE_SUCCESS(rv, rv); + + if (!(schemeMap & (nsICookie::schemeType::SCHEME_HTTP | + nsICookie::schemeType::SCHEME_HTTPS))) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Verbose, + ("Skipping non-HTTP(S) cookie.")); + return NS_OK; + } + + // Check if the cookie is partitioned. Partitioned cookies can not be used for + // bounce tracking. if (!cookie->OriginAttributesNative().mPartitionKey.IsEmpty()) { MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Verbose, ("Skipping partitioned cookie.")); @@ -104,4 +117,65 @@ BounceTrackingStorageObserver::Observe(nsISupports* aSubject, return bounceTrackingState->OnCookieWrite(baseDomain); } +// static +nsresult BounceTrackingStorageObserver::OnInitialStorageAccess( + dom::WindowContext* aWindowContext) { + NS_ENSURE_ARG_POINTER(aWindowContext); + + if (!XRE_IsParentProcess()) { + // Check if the principal needs to be tracked for bounce tracking. Checking + // this in the content process may save us IPC to the parent. + nsIPrincipal* storagePrincipal = + aWindowContext->GetInnerWindow()->GetEffectiveStoragePrincipal(); + if (!BounceTrackingState::ShouldTrackPrincipal(storagePrincipal)) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Verbose, + ("%s: Skipping principal (content process).", __FUNCTION__)); + return NS_OK; + } + + dom::WindowGlobalChild* windowGlobalChild = + aWindowContext->GetWindowGlobalChild(); + NS_ENSURE_TRUE(windowGlobalChild, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(windowGlobalChild->SendOnInitialStorageAccess(), + NS_ERROR_FAILURE); + + return NS_OK; + } + + MOZ_ASSERT(XRE_IsParentProcess()); + nsCOMPtr storagePrincipal = + aWindowContext->Canonical()->DocumentStoragePrincipal(); + NS_ENSURE_TRUE(storagePrincipal, NS_ERROR_FAILURE); + + if (!BounceTrackingState::ShouldTrackPrincipal(storagePrincipal)) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Verbose, + ("%s: Skipping principal.", __FUNCTION__)); + return NS_OK; + } + + if (!storagePrincipal->OriginAttributesRef().mPartitionKey.IsEmpty()) { + MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Verbose, + ("Skipping partitioned storage access.")); + return NS_OK; + } + + dom::BrowsingContext* browsingContext = aWindowContext->GetBrowsingContext(); + NS_ENSURE_TRUE(browsingContext, NS_ERROR_FAILURE); + + nsresult rv = NS_OK; + RefPtr bounceTrackingState = + BounceTrackingState::GetOrCreate( + browsingContext->Top()->Canonical()->GetWebProgress(), rv); + NS_ENSURE_SUCCESS(rv, rv); + + // We may not always get a BounceTrackingState, e.g. if the feature is + // disabled or we don't keep track of bounce tracking for the given + // BrowsingContext. + if (!bounceTrackingState) { + return NS_OK; + } + + return bounceTrackingState->OnStorageAccess(storagePrincipal); +} + } // namespace mozilla diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.h b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.h index 1e76c85a3c..50fdc79c64 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.h +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingStorageObserver.h @@ -9,6 +9,10 @@ namespace mozilla { +namespace dom { +class WindowContext; +} + extern LazyLogModule gBounceTrackingProtectionLog; class BounceTrackingStorageObserver final : public nsIObserver { @@ -17,7 +21,10 @@ class BounceTrackingStorageObserver final : public nsIObserver { public: BounceTrackingStorageObserver() = default; - nsresult Init(); + [[nodiscard]] nsresult Init(); + + [[nodiscard]] static nsresult OnInitialStorageAccess( + dom::WindowContext* aWindowContext); private: ~BounceTrackingStorageObserver() = default; diff --git a/toolkit/components/antitracking/bouncetrackingprotection/metrics.yaml b/toolkit/components/antitracking/bouncetrackingprotection/metrics.yaml new file mode 100644 index 0000000000..a298fa6d4c --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/metrics.yaml @@ -0,0 +1,64 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Adding a new metric? We have docs for that! +# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 +$tags: + - 'Core :: Privacy: Anti-Tracking' + +bounce.tracking.protection: + purge_duration: + type: timing_distribution + description: > + For every purge that is scheduled, we call the ClearDataService to + purge persistent storage for each detected bounce tracker. This may + do some blocking work on main thread and dispatch some cleanups to + other threads. + Collect telemetry on how long it takes to clear in the wild to + determine whether we need to improve performance here. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1890582 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1890582#c4 + data_sensitivity: + - technical + notification_emails: + - pbz@mozilla.com + - bvandersloot@mozilla.com + - manuel@mozilla.com + expires: 130 + enabled_at_startup: + type: boolean + description: > + Keeps track of whether the feature is enabled at startup. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1893964 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1893964#c4 + data_sensitivity: + - technical + notification_emails: + - pbz@mozilla.com + - bvandersloot@mozilla.com + - manuel@mozilla.com + expires: never + enabled_dry_run_mode_at_startup: + type: boolean + description: > + Keeps track of whether the feature is enabled and running in dry-run mode + at startup. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1893964 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1893964#c4 + data_sensitivity: + - technical + notification_emails: + - pbz@mozilla.com + - bvandersloot@mozilla.com + - manuel@mozilla.com + expires: never diff --git a/toolkit/components/antitracking/bouncetrackingprotection/moz.build b/toolkit/components/antitracking/bouncetrackingprotection/moz.build index 09107bb782..cc35d81bd9 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/moz.build +++ b/toolkit/components/antitracking/bouncetrackingprotection/moz.build @@ -8,6 +8,7 @@ with Files("**"): BUG_COMPONENT = ("Core", "Privacy: Anti-Tracking") XPIDL_SOURCES += [ + "nsIBounceTrackingMapEntry.idl", "nsIBounceTrackingProtection.idl", ] @@ -19,6 +20,7 @@ XPCOM_MANIFESTS += [ ] EXPORTS.mozilla += [ + "BounceTrackingMapEntry.h", "BounceTrackingProtection.h", "BounceTrackingProtectionStorage.h", "BounceTrackingRecord.h", @@ -28,6 +30,7 @@ EXPORTS.mozilla += [ ] UNIFIED_SOURCES += [ + "BounceTrackingMapEntry.cpp", "BounceTrackingProtection.cpp", "BounceTrackingProtectionStorage.cpp", "BounceTrackingRecord.cpp", diff --git a/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingMapEntry.idl b/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingMapEntry.idl new file mode 100644 index 0000000000..2e2f1823ab --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingMapEntry.idl @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +/** + * This interface represents an entry in the global bounce tracker or user activation map. + */ +[scriptable, uuid(51B0B5AE-0AC2-4A3C-8C7E-3523FA42881B)] +interface nsIBounceTrackingMapEntry : nsISupports { + // The host of the site that has received user activation or is a bounce tracker candidate. + readonly attribute ACString siteHost; + // The time when the user activation or bounce tracker candidate was added. + // This is a PRTime, which is USEC since the epoch. + readonly attribute int64_t timeStamp; +}; diff --git a/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingProtection.idl b/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingProtection.idl index 1163492333..d52113118e 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingProtection.idl +++ b/toolkit/components/antitracking/bouncetrackingprotection/nsIBounceTrackingProtection.idl @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsISupports.idl" +#include "nsIBounceTrackingMapEntry.idl" [scriptable, uuid(4866F748-29DA-4C10-8EAA-ED2F7851E6B1)] interface nsIBounceTrackingProtection : nsISupports { @@ -37,14 +38,20 @@ interface nsIBounceTrackingProtection : nsISupports { // State is keyed by OriginAttributes. [implicit_jscontext] - Array testGetBounceTrackerCandidateHosts(in jsval originAttributes); + Array testGetBounceTrackerCandidateHosts(in jsval originAttributes); [implicit_jscontext] - Array testGetUserActivationHosts(in jsval originAttributes); + Array testGetUserActivationHosts(in jsval originAttributes); [implicit_jscontext] void testAddBounceTrackerCandidate(in jsval originAttributes, in ACString aSiteHost, in PRTime aBounceTime); [implicit_jscontext] void testAddUserActivation(in jsval originAttributes, in ACString aSiteHost, in PRTime aActivationTime); + + // Test helper to trigger user activation import from the permission + // manager. Will only import if the pref + // privacy.bounceTrackingProtection.hasMigratedUserActivationData is set to + // false. + void testMaybeMigrateUserInteractionPermissions(); }; diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser.toml b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser.toml index 1c44d7804e..0e8a01db4a 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser.toml +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser.toml @@ -4,17 +4,31 @@ prefs = [ "privacy.bounceTrackingProtection.enabled=true", "privacy.bounceTrackingProtection.enableTestMode=true", "privacy.bounceTrackingProtection.bounceTrackingPurgeTimerPeriodSec=0", + "privacy.bounceTrackingProtection.enableDryRunMode=false", ] support-files = [ "file_start.html", "file_bounce.sjs", "file_bounce.html", + "file_web_worker.js", ] +["browser_bouncetracking_dry_run.js"] + ["browser_bouncetracking_oa_isolation.js"] +["browser_bouncetracking_popup.js"] + ["browser_bouncetracking_purge.js"] +["browser_bouncetracking_schemes.js"] + ["browser_bouncetracking_simple.js"] -["browser_bouncetracking_stateful.js"] +["browser_bouncetracking_stateful_cookies.js"] + +["browser_bouncetracking_stateful_storage.js"] + +["browser_bouncetracking_stateful_web_worker.js"] + +["browser_bouncetracking_telemetry_purge_duration.js"] diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_dry_run.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_dry_run.js new file mode 100644 index 0000000000..627a5f233a --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_dry_run.js @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_ORIGIN = "https://itisatracker.org"; +const TEST_BASE_DOMAIN = "itisatracker.org"; + +async function runPurgeTest(expectPurge) { + ok(!SiteDataTestUtils.hasCookies(TEST_ORIGIN), "No cookies initially."); + + // Adding a cookie that should later be purged. + info("Add a test cookie to be purged later."); + SiteDataTestUtils.addToCookies({ origin: TEST_ORIGIN }); + ok(SiteDataTestUtils.hasCookies(TEST_ORIGIN), "Cookie added."); + + // The bounce adds localStorage. Test that there is none initially. + ok( + !SiteDataTestUtils.hasLocalStorage(TEST_ORIGIN), + "No localStorage initially." + ); + + info("Test client bounce with cookie."); + await runTestBounce({ + bounceType: "client", + setState: "localStorage", + skipSiteDataCleanup: true, + postBounceCallback: () => { + info( + "Test that after the bounce but before purging cookies and localStorage are present." + ); + ok(SiteDataTestUtils.hasCookies(TEST_ORIGIN), "Cookies not purged."); + ok( + SiteDataTestUtils.hasLocalStorage(TEST_ORIGIN), + "localStorage not purged." + ); + + Assert.deepEqual( + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost), + [TEST_BASE_DOMAIN], + `Bounce tracker candidate '${TEST_BASE_DOMAIN}' added` + ); + }, + }); + + if (expectPurge) { + info("After purging the site shouldn't have any data."); + ok(!SiteDataTestUtils.hasCookies(TEST_ORIGIN), "Cookies purged."); + ok(!SiteDataTestUtils.hasLocalStorage(TEST_ORIGIN), "localStorage purged."); + } else { + info("Purging did not run meaning the site should still have data."); + + ok(SiteDataTestUtils.hasCookies(TEST_ORIGIN), "Cookies still set."); + ok( + SiteDataTestUtils.hasLocalStorage(TEST_ORIGIN), + "localStorage still set." + ); + } + + info( + "Candidates should have been removed after running the purging algorithm. This is true for both regular and dry-run mode where we pretend to purge." + ); + Assert.deepEqual( + bounceTrackingProtection.testGetBounceTrackerCandidateHosts({}), + [], + "No bounce tracker candidates after purging." + ); + + // Cleanup. + bounceTrackingProtection.clearAll(); + await SiteDataTestUtils.clear(); +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + // Required to use SiteDataTestUtils localStorage helpers. + ["dom.storage.client_validation", false], + ], + }); +}); + +add_task(async function test_purge_in_regular_mode() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.bounceTrackingProtection.enableDryRunMode", false]], + }); + + await runPurgeTest(true); +}); + +add_task(async function test_purge_in_dry_run_mode() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.bounceTrackingProtection.enableDryRunMode", true]], + }); + + await runPurgeTest(false); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_popup.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_popup.js new file mode 100644 index 0000000000..9e6fa8caf1 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_popup.js @@ -0,0 +1,126 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + ], + }); + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); +}); + +async function runTest(spawnWindowType) { + if (!spawnWindowType || !["newTab", "popup"].includes(spawnWindowType)) { + throw new Error(`Invalid option '${spawnWindowType}' for spawnWindowType`); + } + + Assert.equal( + bounceTrackingProtection.testGetBounceTrackerCandidateHosts({}).length, + 0, + "No bounce tracker hosts initially." + ); + Assert.equal( + bounceTrackingProtection.testGetUserActivationHosts({}).length, + 0, + "No user activation hosts initially." + ); + + // Spawn a tab with A, the start of the bounce chain. + await BrowserTestUtils.withNewTab( + getBaseUrl(ORIGIN_A) + "file_start.html", + async browser => { + // The destination site C to navigate to after the bounce. + let finalURL = new URL(getBaseUrl(ORIGIN_B) + "file_start.html"); + // The middle hop in the bounce chain B that redirects to finalURL C. + let bounceURL = getBounceURL({ + bounceType: "client", + targetURL: finalURL, + setState: "cookie-client", + }); + + // Register a promise for the new popup window. This resolves once the popup + // has opened and the final url (C) has been loaded. + let openPromise; + + if (spawnWindowType == "newTab") { + openPromise = BrowserTestUtils.waitForNewTab(gBrowser, finalURL.href); + } else { + openPromise = BrowserTestUtils.waitForNewWindow({ url: finalURL.href }); + } + + // Navigate through the bounce chain by opening a popup to the bounce URL. + await navigateLinkClick(browser, bounceURL, { + spawnWindow: spawnWindowType, + }); + + let tabOrWindow = await openPromise; + + let tabOrWindowBrowser; + if (spawnWindowType == "newTab") { + tabOrWindowBrowser = tabOrWindow.linkedBrowser; + } else { + tabOrWindowBrowser = tabOrWindow.gBrowser.selectedBrowser; + } + + let promiseRecordBounces = waitForRecordBounces(tabOrWindowBrowser); + + // Navigate again with user gesture which triggers + // BounceTrackingProtection::RecordStatefulBounces. We could rely on the + // timeout (mClientBounceDetectionTimeout) here but that can cause races + // in debug where the load is quite slow. + await navigateLinkClick( + tabOrWindowBrowser, + new URL(getBaseUrl(ORIGIN_C) + "file_start.html") + ); + + info("Wait for bounce trackers to be recorded."); + await promiseRecordBounces; + + // Cleanup popup or tab. + if (spawnWindowType == "newTab") { + await BrowserTestUtils.removeTab(tabOrWindow); + } else { + await BrowserTestUtils.closeWindow(tabOrWindow); + } + } + ); + + // Check that the bounce tracker was detected. + Assert.deepEqual( + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost), + [SITE_TRACKER], + "Bounce tracker in popup detected." + ); + + // Cleanup. + bounceTrackingProtection.clearAll(); + await SiteDataTestUtils.clear(); +} + +/** + * Tests that bounce trackers which use popups as the first hop in the bounce + * chain can not bypass detection. + * + * A -> popup -> B -> C + * + * A opens a popup and loads B in it. B is the tracker that performs a + * short-lived redirect and C is the final destination. + */ + +add_task(async function test_popup() { + await runTest("popup"); +}); + +add_task(async function test_new_tab() { + await runTest("newTab"); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_purge.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_purge.js index eedd374197..676ac5fe92 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_purge.js +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_purge.js @@ -133,8 +133,21 @@ add_task(async function test_purging_skip_content_blocking_allow_list() { "Should only purge example.net. example.org is within the grace period, example.com is allow-listed." ); + // example.net is removed because it is purged, example.com is removed because + // it is allow-listed. + Assert.deepEqual( + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost), + ["example.org"], + "Should have removed example.net and example.com from bounce tracker candidate list." + ); + + info("Add example.com as a bounce tracker candidate again."); + bounceTrackingProtection.testAddBounceTrackerCandidate({}, "example.com", 1); + info( - "Remove the allow-list entry for example.com and test that it gets purged now." + "Remove the allow-list entry for example.com and test that it gets purged now." ); await BrowserTestUtils.withNewTab("https://example.com", async browser => { @@ -146,6 +159,16 @@ add_task(async function test_purging_skip_content_blocking_allow_list() { "example.com should have been purged now that it is no longer allow-listed." ); + // example.org is still in the grace period so it neither gets purged nor + // removed from the candidate list. + Assert.deepEqual( + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost), + ["example.org"], + "Should have removed example.com from bounce tracker candidate list." + ); + bounceTrackingProtection.clearAll(); }); @@ -166,8 +189,24 @@ add_task( "Should only purge example.net. example.org is within the grace period, example.com is allow-listed via test1.example.com." ); + // example.net is removed because it is purged, example.com is removed because it is allow-listed. + Assert.deepEqual( + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost), + ["example.org"], + "Should have removed example.net and example.com from bounce tracker candidate list." + ); + + info("Add example.com as a bounce tracker candidate again."); + bounceTrackingProtection.testAddBounceTrackerCandidate( + {}, + "example.com", + 1 + ); + info( - "Remove the allow-list entry for test1.example.com and test that it gets purged now." + "Remove the allow-list entry for test1.example.com and test that it gets purged now." ); await BrowserTestUtils.withNewTab( @@ -179,7 +218,7 @@ add_task( Assert.deepEqual( await bounceTrackingProtection.testRunPurgeBounceTrackers(), ["example.com"], - "example.com should have been purged now that test1.example.com it is no longer allow-listed." + "example.com should have been purged now that test1.example.com is no longer allow-listed." ); bounceTrackingProtection.clearAll(); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js new file mode 100644 index 0000000000..21b72cdc45 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +add_setup(async function () { + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); + bounceTrackingProtection.clearAll(); +}); + +async function testInteractWithSite(origin, expectRecorded) { + is( + bounceTrackingProtection.testGetUserActivationHosts({}).length, + 0, + "No user activation hosts initially" + ); + + let baseDomain; + let scheme; + + await BrowserTestUtils.withNewTab(origin, async browser => { + baseDomain = browser.contentPrincipal.baseDomain; + scheme = browser.contentPrincipal.URI.scheme; + + info( + `Trigger a user activation, which should ${ + expectRecorded ? "" : "not " + }be recorded.` + ); + // We intentionally turn off this a11y check, because the following click + // is purposefully sent on an arbitrary web content that is not expected + // to be tested by itself with the browser mochitests, therefore this rule + // check shall be ignored by a11y_checks suite. + AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false }); + await BrowserTestUtils.synthesizeMouseAtPoint(50, 50, {}, browser); + AccessibilityUtils.resetEnv(); + }); + if (expectRecorded) { + Assert.deepEqual( + bounceTrackingProtection + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost), + [baseDomain], + `User activation should be recorded for ${scheme} scheme.` + ); + } else { + Assert.deepEqual( + bounceTrackingProtection.testGetUserActivationHosts({}), + [], + `User activation should not be recorded for ${scheme} scheme.` + ); + } + + bounceTrackingProtection.clearAll(); +} + +/** + * Test that we only record user activation for supported schemes. + */ +add_task(async function test_userActivationSchemes() { + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await testInteractWithSite("http://example.com", true); + await testInteractWithSite("https://example.com", true); + + await testInteractWithSite("about:blank", false); + await testInteractWithSite("about:robots", false); + await testInteractWithSite( + "file://" + Services.dirsvc.get("TmpD", Ci.nsIFile).path, + false + ); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_simple.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_simple.js index dfbd4d0fc0..cdc21eb788 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_simple.js +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_simple.js @@ -73,12 +73,18 @@ add_task(async function test_bounce_chain() { await promiseRecordBounces; Assert.deepEqual( - bounceTrackingProtection.testGetBounceTrackerCandidateHosts({}).sort(), + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost) + .sort(), [SITE_TRACKER_B, SITE_TRACKER].sort(), `Identified all bounce trackers in the redirect chain.` ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts({}).sort(), + bounceTrackingProtection + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost) + .sort(), [SITE_A, SITE_B].sort(), "Should only have user activation for sites where we clicked links." ); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful.js deleted file mode 100644 index e7fb4521a7..0000000000 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful.js +++ /dev/null @@ -1,63 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -let bounceTrackingProtection; - -add_setup(async function () { - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.bounceTrackingProtection.requireStatefulBounces", true], - ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], - ], - }); - bounceTrackingProtection = Cc[ - "@mozilla.org/bounce-tracking-protection;1" - ].getService(Ci.nsIBounceTrackingProtection); -}); - -// Cookie tests. - -add_task(async function test_bounce_stateful_cookies_client() { - info("Test client bounce with cookie."); - await runTestBounce({ - bounceType: "client", - setState: "cookie-client", - }); - info("Test client bounce without cookie."); - await runTestBounce({ - bounceType: "client", - setState: null, - expectCandidate: false, - expectPurge: false, - }); -}); - -add_task(async function test_bounce_stateful_cookies_server() { - info("Test server bounce with cookie."); - await runTestBounce({ - bounceType: "server", - setState: "cookie-server", - }); - info("Test server bounce without cookie."); - await runTestBounce({ - bounceType: "server", - setState: null, - expectCandidate: false, - expectPurge: false, - }); -}); - -// Storage tests. - -// TODO: Bug 1848406: Implement stateful bounce detection for localStorage. -add_task(async function test_bounce_stateful_localStorage() { - info("TODO: client bounce with localStorage."); - await runTestBounce({ - bounceType: "client", - setState: "localStorage", - expectCandidate: false, - expectPurge: false, - }); -}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_cookies.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_cookies.js new file mode 100644 index 0000000000..d4940e668d --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_cookies.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + ], + }); + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); +}); + +// Cookie tests. + +add_task(async function test_bounce_stateful_cookies_client() { + info("Test client bounce with cookie."); + await runTestBounce({ + bounceType: "client", + setState: "cookie-client", + }); + info("Test client bounce without cookie."); + await runTestBounce({ + bounceType: "client", + setState: null, + expectCandidate: false, + expectPurge: false, + }); +}); + +add_task(async function test_bounce_stateful_cookies_client_sameSiteFrame() { + info("Test client bounce with cookie set in same site frame."); + await runTestBounce({ + bounceType: "client", + setState: "cookie-client", + setStateSameSiteFrame: true, + }); +}); + +add_task(async function test_bounce_stateful_cookies_server() { + info("Test server bounce with cookie."); + await runTestBounce({ + bounceType: "server", + setState: "cookie-server", + }); + info("Test server bounce without cookie."); + await runTestBounce({ + bounceType: "server", + setState: null, + expectCandidate: false, + expectPurge: false, + }); +}); + +add_task(async function test_bounce_stateful_cookies_server_sameSiteFrame() { + info("Test client bounce with cookie set in same site frame."); + await runTestBounce({ + bounceType: "server", + setState: "cookie-server", + setStateSameSiteFrame: true, + }); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_storage.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_storage.js new file mode 100644 index 0000000000..ff9daabcdb --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_storage.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + ], + }); + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); +}); + +// Storage tests. + +add_task(async function test_bounce_stateful_localStorage() { + info("Client bounce with localStorage."); + await runTestBounce({ + bounceType: "client", + setState: "localStorage", + }); +}); + +add_task(async function test_bounce_stateful_localStorage_sameSiteFrame() { + info("Client bounce with localStorage set in same site frame."); + await runTestBounce({ + bounceType: "client", + setState: "localStorage", + setStateSameSiteFrame: true, + }); +}); + +add_task(async function test_bounce_stateful_indexedDB() { + info("Client bounce with indexedDB."); + await runTestBounce({ + bounceType: "client", + setState: "indexedDB", + }); +}); + +add_task(async function test_bounce_stateful_indexedDB_sameSiteFrame() { + info("Client bounce with indexedDB populated in same site frame."); + await runTestBounce({ + bounceType: "client", + setState: "indexedDB", + setStateSameSiteFrame: true, + }); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_web_worker.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_web_worker.js new file mode 100644 index 0000000000..1e6672e784 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_stateful_web_worker.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + ], + }); + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); +}); + +add_task(async function test_bounce_stateful_indexedDB() { + info("Client bounce with indexedDB."); + await runTestBounce({ + bounceType: "client", + setState: "indexedDB", + setStateInWebWorker: true, + }); +}); + +// FIXME: (Bug 1889898) This test is skipped because it triggers a shutdown +// hang. +add_task(async function test_bounce_stateful_indexedDB_nestedWorker() { + info("Client bounce with indexedDB access from a nested worker."); + await runTestBounce({ + bounceType: "client", + setState: "indexedDB", + setStateInNestedWebWorker: true, + }); +}).skip(); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_telemetry_purge_duration.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_telemetry_purge_duration.js new file mode 100644 index 0000000000..74b1fdb30d --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_telemetry_purge_duration.js @@ -0,0 +1,66 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let bounceTrackingProtection; + +async function test_purge_duration(isDryRunMode) { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.bounceTrackingProtection.enableDryRunMode", isDryRunMode]], + }); + + is( + Glean.bounceTrackingProtection.purgeDuration.testGetValue(), + null, + "Histogram should not exist initially." + ); + + info("Run server bounce with cookie."); + await runTestBounce({ + bounceType: "server", + setState: "cookie-server", + postBounceCallback: () => { + is( + Glean.bounceTrackingProtection.purgeDuration.testGetValue(), + null, + "Histogram should still be empty after bounce, because we haven't purged yet." + ); + }, + }); + + let events = Glean.bounceTrackingProtection.purgeDuration.testGetValue(); + if (isDryRunMode) { + is(events, null, "Should not collect purge timining in dry mode"); + } else { + is(events.count, 1, "Histogram should contain one value."); + } + + // Cleanup + Services.fog.testResetFOG(); + await SpecialPowers.popPrefEnv(); + bounceTrackingProtection.clearAll(); +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.bounceTrackingProtection.requireStatefulBounces", true], + ["privacy.bounceTrackingProtection.bounceTrackingGracePeriodSec", 0], + ], + }); + bounceTrackingProtection = Cc[ + "@mozilla.org/bounce-tracking-protection;1" + ].getService(Ci.nsIBounceTrackingProtection); + + // Clear telemetry before test. + Services.fog.testResetFOG(); +}); + +add_task(async function test_purge_duration_dry_mode() { + await test_purge_duration(true); +}); + +add_task(async function test_purge_duration_enabled() { + await test_purge_duration(false); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_bounce.html b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_bounce.html index 2756555fa5..d7aa117481 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_bounce.html +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_bounce.html @@ -1,59 +1,150 @@ - - - - Bounce! - - - -

Nothing to see here...

- + - let target = url.searchParams.get("target"); - if (target) { - console.info("redirecting to", target); - setTimeout(() => { - location.href = target; - }, redirectDelay); - } - })(); - - diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_web_worker.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_web_worker.js new file mode 100644 index 0000000000..78fdf2a149 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_web_worker.js @@ -0,0 +1,40 @@ +// A web worker which can set indexedDB. + +function setIndexedDB() { + return new Promise((resolve, reject) => { + let request = self.indexedDB.open("bounce", 1); + request.onsuccess = () => { + console.info("Opened indexedDB"); + resolve(); + }; + request.onerror = event => { + console.error("Error opening indexedDB", event); + reject(); + }; + request.onupgradeneeded = event => { + console.info("Initializing indexedDB"); + let db = event.target.result; + db.createObjectStore("bounce"); + }; + }); +} + +self.onmessage = function (event) { + console.info("Web worker received message", event.data); + + if (event.data === "setIndexedDB") { + setIndexedDB().then(() => { + self.postMessage("indexedDBSet"); + }); + } else if (event.data === "setIndexedDBNested") { + console.info("set state nested"); + // Rather than setting indexedDB in this worker spawn a nested worker to set + // indexedDB. + let nestedWorker = new Worker("file_web_worker.js"); + nestedWorker.postMessage("setIndexedDB"); + nestedWorker.onmessage = () => { + console.info("IndexedDB set in nested worker"); + self.postMessage("indexedDBSet"); + }; + } +}; diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/head.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/head.js index f5857b6919..71d9acedc6 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/head.js +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/head.js @@ -3,6 +3,17 @@ "use strict"; +const { SiteDataTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SiteDataTestUtils.sys.mjs" +); + +XPCOMUtils.defineLazyServiceGetter( + this, + "bounceTrackingProtection", + "@mozilla.org/bounce-tracking-protection;1", + "nsIBounceTrackingProtection" +); + const SITE_A = "example.com"; const ORIGIN_A = `https://${SITE_A}`; @@ -25,13 +36,6 @@ const OBSERVER_MSG_RECORD_BOUNCES_FINISHED = "test-record-bounces-finished"; const ROOT_DIR = getRootDirectory(gTestPath); -XPCOMUtils.defineLazyServiceGetter( - this, - "bounceTrackingProtection", - "@mozilla.org/bounce-tracking-protection;1", - "nsIBounceTrackingProtection" -); - /** * Get the base url for the current test directory using the given origin. * @param {string} origin - Origin to use in URL. @@ -48,8 +52,14 @@ function getBaseUrl(origin) { * the bounce. * @param {string} [options.bounceOrigin] - The origin of the bounce URL. * @param {string} [options.targetURL] - URL to redirect to after the bounce. - * @param {("cookie"|null)} [options.setState] - What type of state should be set during - * the bounce. No state by default. + * @param {('cookie-server'|'cookie-client'|'localStorage')} [options.setState] + * Type of state to set during the redirect. Defaults to non stateful redirect. + * @param {boolean} [options.setStateSameSiteFrame=false] - Whether to set the + * state in a sub frame that is same site to the top window. + * @param {boolean} [options.setStateInWebWorker=false] - Whether to set the + * state in a web worker. This only supports setState == "indexedDB". + * @param {boolean} [options.setStateInWebWorker=false] - Whether to set the + * state in a nested web worker. Otherwise the same as setStateInWebWorker. * @param {number} [options.statusCode] - HTTP status code to use for server * side redirect. Only applies to bounceType == "server". * @param {number} [options.redirectDelayMS] - How long to wait before @@ -62,6 +72,9 @@ function getBounceURL({ bounceOrigin = ORIGIN_TRACKER, targetURL = new URL(getBaseUrl(ORIGIN_B) + "file_start.html"), setState = null, + setStateSameSiteFrame = false, + setStateInWebWorker = false, + setStateInNestedWebWorker = false, statusCode = 302, redirectDelayMS = 50, }) { @@ -79,6 +92,25 @@ function getBounceURL({ if (setState) { searchParams.set("setState", setState); } + if (setStateSameSiteFrame) { + searchParams.set("setStateSameSiteFrame", setStateSameSiteFrame); + } + if (setStateInWebWorker) { + if (setState != "indexedDB") { + throw new Error( + "setStateInWebWorker only supports setState == 'indexedDB'" + ); + } + searchParams.set("setStateInWebWorker", setStateInWebWorker); + } + if (setStateInNestedWebWorker) { + if (setState != "indexedDB") { + throw new Error( + "setStateInNestedWebWorker only supports setState == 'indexedDB'" + ); + } + searchParams.set("setStateInNestedWebWorker", setStateInNestedWebWorker); + } if (bounceType == "server") { searchParams.set("statusCode", statusCode); @@ -94,23 +126,58 @@ function getBounceURL({ * click on it. * @param {MozBrowser} browser - Browser to insert the link in. * @param {URL} targetURL - Destination for navigation. + * @param {Object} options - Additional options. + * @param {string} [options.spawnWindow] - If set to "newTab" or "popup" the + * link will be opened in a new tab or popup window respectively. If unset the + * link is opened in the given browser. * @returns {Promise} Resolves once the click is done. Does not wait for * navigation or load. */ -async function navigateLinkClick(browser, targetURL) { - await SpecialPowers.spawn(browser, [targetURL.href], targetURL => { - let link = content.document.createElement("a"); - - link.href = targetURL; - link.textContent = targetURL; - // The link needs display: block, otherwise synthesizeMouseAtCenter doesn't - // hit it. - link.style.display = "block"; - - content.document.body.appendChild(link); - }); +async function navigateLinkClick( + browser, + targetURL, + { spawnWindow = null } = {} +) { + if (spawnWindow && !["newTab", "popup"].includes(spawnWindow)) { + throw new Error(`Invalid option '${spawnWindow}' for spawnWindow`); + } - await BrowserTestUtils.synthesizeMouseAtCenter("a[href]", {}, browser); + await SpecialPowers.spawn( + browser, + [targetURL.href, spawnWindow], + async (targetURL, spawnWindow) => { + let link = content.document.createElement("a"); + link.id = "link"; + link.textContent = "Click Me"; + link.style.display = "block"; + link.style.fontSize = "40px"; + + // For opening a popup we attach an event listener to trigger via click. + if (spawnWindow) { + link.href = "#"; + link.addEventListener("click", event => { + event.preventDefault(); + if (spawnWindow == "newTab") { + // Open a new tab. + content.window.open(targetURL, "bounce"); + } else { + // Open a popup window. + content.window.open(targetURL, "bounce", "height=200,width=200"); + } + }); + } else { + // For regular navigation add href and click. + link.href = targetURL; + } + + content.document.body.appendChild(link); + + // TODO: Bug 1892091: Use EventUtils.synthesizeMouse instead for a real click. + SpecialPowers.wrap(content.document).notifyUserGestureActivation(); + content.document.userInteractionForTesting(); + link.click(); + } + ); } /** @@ -141,25 +208,38 @@ async function waitForRecordBounces(browser) { * or server side redirect. * @param {('cookie-server'|'cookie-client'|'localStorage')} [options.setState] * Type of state to set during the redirect. Defaults to non stateful redirect. - * @param {boolean} [options.expectCandidate=true] - Expect the redirecting site to be - * identified as a bounce tracker (candidate). - * @param {boolean} [options.expectPurge=true] - Expect the redirecting site to have - * its storage purged. + * @param {boolean} [options.setStateSameSiteFrame=false] - Whether to set the + * state in a sub frame that is same site to the top window. + * @param {boolean} [options.setStateInWebWorker=false] - Whether to set the + * state in a web worker. This only supports setState == "indexedDB". + * @param {boolean} [options.setStateInWebWorker=false] - Whether to set the + * state in a nested web worker. Otherwise the same as setStateInWebWorker. + * @param {boolean} [options.expectCandidate=true] - Expect the redirecting site + * to be identified as a bounce tracker (candidate). + * @param {boolean} [options.expectPurge=true] - Expect the redirecting site to + * have its storage purged. * @param {OriginAttributes} [options.originAttributes={}] - Origin attributes * to use for the test. This determines whether the test is run in normal - * browsing, a private window or a container tab. By default the test is run - * in normal browsing. - * @param {function} [options.postBounceCallback] - Optional function to run after the - * bounce has completed. + * browsing, a private window or a container tab. By default the test is run in + * normal browsing. + * @param {function} [options.postBounceCallback] - Optional function to run + * after the bounce has completed. + * @param {boolean} [options.skipSiteDataCleanup=false] - Skip the cleanup of + * site data after the test. When this is enabled the caller is responsible for + * cleaning up site data. */ async function runTestBounce(options = {}) { let { bounceType, setState = null, + setStateSameSiteFrame = false, + setStateInWebWorker = false, + setStateInNestedWebWorker = false, expectCandidate = true, expectPurge = true, originAttributes = {}, postBounceCallback = () => {}, + skipSiteDataCleanup = false, } = options; info(`runTestBounce ${JSON.stringify(options)}`); @@ -191,28 +271,42 @@ async function runTestBounce(options = {}) { win = await BrowserTestUtils.openNewBrowserWindow({ private: true }); } - let tab = win.gBrowser.addTab(getBaseUrl(ORIGIN_A) + "file_start.html", { + let initialURL = getBaseUrl(ORIGIN_A) + "file_start.html"; + let tab = win.gBrowser.addTab(initialURL, { triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), userContextId, }); win.gBrowser.selectedTab = tab; let browser = tab.linkedBrowser; - await BrowserTestUtils.browserLoaded(browser); + await BrowserTestUtils.browserLoaded(browser, true, initialURL); let promiseRecordBounces = waitForRecordBounces(browser); // The final destination after the bounce. let targetURL = new URL(getBaseUrl(ORIGIN_B) + "file_start.html"); + // Wait for the final site to be loaded which complete the BounceTrackingRecord. + let targetURLLoadedPromise = BrowserTestUtils.browserLoaded( + browser, + false, + targetURL + ); + // Navigate through the bounce chain. await navigateLinkClick( browser, - getBounceURL({ bounceType, targetURL, setState }) + getBounceURL({ + bounceType, + targetURL, + setState, + setStateSameSiteFrame, + setStateInWebWorker, + setStateInNestedWebWorker, + }) ); - // Wait for the final site to be loaded which complete the BounceTrackingRecord. - await BrowserTestUtils.browserLoaded(browser, false, targetURL); + await targetURLLoadedPromise; // Navigate again with user gesture which triggers // BounceTrackingProtection::RecordStatefulBounces. We could rely on the @@ -226,9 +320,9 @@ async function runTestBounce(options = {}) { await promiseRecordBounces; Assert.deepEqual( - bounceTrackingProtection.testGetBounceTrackerCandidateHosts( - originAttributes - ), + bounceTrackingProtection + .testGetBounceTrackerCandidateHosts(originAttributes) + .map(entry => entry.siteHost), expectCandidate ? [SITE_TRACKER] : [], `Should ${ expectCandidate ? "" : "not " @@ -237,6 +331,7 @@ async function runTestBounce(options = {}) { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(originAttributes) + .map(entry => entry.siteHost) .sort(), [SITE_A, SITE_B].sort(), "Should only have user activation for sites where we clicked links." @@ -272,4 +367,7 @@ async function runTestBounce(options = {}) { ); } bounceTrackingProtection.clearAll(); + if (!skipSiteDataCleanup) { + await SiteDataTestUtils.clear(); + } } diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/marionette/test_bouncetracking_storage_persistence.py b/toolkit/components/antitracking/bouncetrackingprotection/test/marionette/test_bouncetracking_storage_persistence.py index afc3239839..3b0fe351e2 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/marionette/test_bouncetracking_storage_persistence.py +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/marionette/test_bouncetracking_storage_persistence.py @@ -48,7 +48,7 @@ class BounceTrackingStoragePersistenceTestCase(MarionetteTestCase): let bounceTrackingProtection = Cc["@mozilla.org/bounce-tracking-protection;1"].getService( Ci.nsIBounceTrackingProtection ); - return bounceTrackingProtection.testGetBounceTrackerCandidateHosts({}).sort(); + return bounceTrackingProtection.testGetBounceTrackerCandidateHosts({}).map(entry => entry.siteHost).sort(); """, ) self.assertEqual( @@ -64,7 +64,7 @@ class BounceTrackingStoragePersistenceTestCase(MarionetteTestCase): let bounceTrackingProtection = Cc["@mozilla.org/bounce-tracking-protection;1"].getService( Ci.nsIBounceTrackingProtection ); - return bounceTrackingProtection.testGetBounceTrackerCandidateHosts({ userContextId: 3 }).sort(); + return bounceTrackingProtection.testGetBounceTrackerCandidateHosts({ userContextId: 3 }).map(entry => entry.siteHost).sort(); """, ) self.assertEqual( @@ -109,7 +109,7 @@ class BounceTrackingStoragePersistenceTestCase(MarionetteTestCase): let bounceTrackingProtection = Cc["@mozilla.org/bounce-tracking-protection;1"].getService( Ci.nsIBounceTrackingProtection ); - return bounceTrackingProtection.testGetUserActivationHosts({}).sort(); + return bounceTrackingProtection.testGetUserActivationHosts({}).map(entry => entry.siteHost).sort(); """, ) self.assertEqual( diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_clearExpiredUserActivation.js b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_clearExpiredUserActivation.js index 28a1350b3e..a52fb7fd46 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_clearExpiredUserActivation.js +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_clearExpiredUserActivation.js @@ -69,13 +69,19 @@ add_task(async function test() { // Assert that expired user activations have been cleared. Assert.deepEqual( - btp.testGetUserActivationHosts({}).sort(), + btp + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost) + .sort(), ["not-expired1.com", "not-expired2.com"], "Expired user activation flags have been cleared for normal browsing." ); Assert.deepEqual( - btp.testGetUserActivationHosts({ privateBrowsingId: 1 }).sort(), + btp + .testGetUserActivationHosts({ privateBrowsingId: 1 }) + .map(entry => entry.siteHost) + .sort(), ["pbm-not-expired.com"], "Expired user activation flags have been cleared for private browsing." ); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_importUserActivationPermissions.js b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_importUserActivationPermissions.js new file mode 100644 index 0000000000..5150d074c2 --- /dev/null +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_importUserActivationPermissions.js @@ -0,0 +1,153 @@ +/* Any copyright is dedicated to the Public Domain. +https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { PermissionTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PermissionTestUtils.sys.mjs" +); + +const DOMAIN_A = "example.com"; +const SUB_DOMAIN_A = "sub." + DOMAIN_A; +const DOMAIN_B = "example.org"; +const DOMAIN_C = "example.net"; + +const ORIGIN_A = "https://" + DOMAIN_A; +const ORIGIN_SUB_A = "https://" + SUB_DOMAIN_A; +const ORIGIN_B = "https://" + DOMAIN_B; +const ORIGIN_C = "https://" + DOMAIN_C; +const ORIGIN_NON_HTTP = "file:///foo/bar.html"; + +const OA_PBM = { privateBrowsingId: 1 }; +const PRINCIPAL_C_PBM = Services.scriptSecurityManager.createContentPrincipal( + Services.io.newURI(ORIGIN_C), + OA_PBM +); + +let btp; +let userActivationLifetimeSec = Services.prefs.getIntPref( + "privacy.bounceTrackingProtection.bounceTrackingActivationLifetimeSec" +); + +function cleanup() { + btp.clearAll(); + Services.perms.removeAll(); + Services.prefs.setBoolPref( + "privacy.bounceTrackingProtection.hasMigratedUserActivationData", + false + ); +} + +add_setup(function () { + // Need a profile to data clearing calls. + do_get_profile(); + + btp = Cc["@mozilla.org/bounce-tracking-protection;1"].getService( + Ci.nsIBounceTrackingProtection + ); + + // Clean initial state. + cleanup(); +}); + +add_task(async function test_user_activation_perm_migration() { + // Assert initial test state. + Assert.deepEqual( + btp.testGetUserActivationHosts({}), + [], + "No user activation hosts initially." + ); + Assert.equal( + Services.perms.getAllByTypes(["storageAccessAPI"]).length, + 0, + "No user activation permissions initially." + ); + + info("Add test user activation permissions."); + + let now = Date.now(); + + // Non-expired permissions. + PermissionTestUtils.addWithModificationTime( + ORIGIN_A, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now + ); + PermissionTestUtils.addWithModificationTime( + ORIGIN_C, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now - 1000 + ); + + // A non expired permission for a subdomain of DOMAIN_A that has an older modification time. + PermissionTestUtils.addWithModificationTime( + ORIGIN_SUB_A, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now - 500 + ); + + // An expired permission. + PermissionTestUtils.addWithModificationTime( + ORIGIN_B, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now - userActivationLifetimeSec * 1.2 * 1000 + ); + + // A non-HTTP permission. + PermissionTestUtils.addWithModificationTime( + ORIGIN_NON_HTTP, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now + ); + + // A permission for PBM. Ideally we'd test a more persistent permission type + // here with custom oa, but permission seperation by userContextId isn't + // enabled yet (Bug 1641584). + PermissionTestUtils.addWithModificationTime( + PRINCIPAL_C_PBM, + "storageAccessAPI", + Services.perms.ALLOW_ACTION, + now + ); + + info("Trigger migration."); + btp.testMaybeMigrateUserInteractionPermissions(); + + Assert.deepEqual( + btp + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost) + .sort(), + [DOMAIN_A, DOMAIN_C].sort(), + "Should have imported the correct user activation flags." + ); + Assert.deepEqual( + btp.testGetUserActivationHosts(OA_PBM).map(entry => entry.siteHost), + [DOMAIN_C], + "Should have imported the correct user activation flags for PBM." + ); + + info("Reset the BTP user activation store"); + btp.clearAll(); + + info("Trigger migration again."); + btp.testMaybeMigrateUserInteractionPermissions(); + + Assert.deepEqual( + btp.testGetUserActivationHosts({}), + [], + "Should not have imported the user activation flags again." + ); + Assert.deepEqual( + btp.testGetUserActivationHosts(OA_PBM), + [], + "Should not have imported the user activation flags again for PBM." + ); + + cleanup(); +}); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_purge.js b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_purge.js index 5ede57a08b..2fbd8a0a02 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_purge.js +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/test_bouncetracking_purge.js @@ -6,6 +6,9 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ const { SiteDataTestUtils } = ChromeUtils.importESModule( "resource://testing-common/SiteDataTestUtils.sys.mjs" ); +const { PermissionTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PermissionTestUtils.sys.mjs" +); let btp; let bounceTrackingGracePeriodSec; @@ -138,6 +141,14 @@ add_task(async function test_purge() { message: "Should purge after grace period.", shouldPurge: true, }, + // Don't purge if the site is allowlisted. + "example2.net": { + bounceTime: timestampOutsideGracePeriodFiveSeconds, + userActivationTime: null, + isAllowListed: true, + message: "Should not purge after grace period if allowlisted.", + shouldPurge: false, + }, // Also ensure that clear data calls with IP sites succeed. "1.2.3.4": { bounceTime: timestampOutsideGracePeriodThreeDays, @@ -191,16 +202,30 @@ add_task(async function test_purge() { let expectedBounceTrackerHosts = []; let expectedUserActivationHosts = []; + let allowListedHosts = []; let expiredUserActivationHosts = []; let expectedPurgedHosts = []; // This would normally happen over time while browsing. let initPromises = Object.entries(TEST_TRACKERS).map( - async ([siteHost, { bounceTime, userActivationTime, shouldPurge }]) => { + async ([ + siteHost, + { bounceTime, userActivationTime, isAllowListed, shouldPurge }, + ]) => { // Add site state so we can later assert it has been purged. await addStateForHost(siteHost); + // Add allowlist entry if needed. + if (isAllowListed) { + PermissionTestUtils.add( + `https://${siteHost}`, + "trackingprotection", + Services.perms.ALLOW_ACTION + ); + allowListedHosts.push(siteHost); + } + if (bounceTime != null) { if (userActivationTime != null) { throw new Error( @@ -210,7 +235,7 @@ add_task(async function test_purge() { expectedBounceTrackerHosts.push(siteHost); - // Convert bounceTime timestamp to nanoseconds (PRTime). + // Convert bounceTime timestamp to microseconds (PRTime). info( `Adding bounce. siteHost: ${siteHost}, bounceTime: ${bounceTime} ms` ); @@ -232,7 +257,7 @@ add_task(async function test_purge() { expiredUserActivationHosts.push(siteHost); } - // Convert userActivationTime timestamp to nanoseconds (PRTime). + // Convert userActivationTime timestamp to microseconds (PRTime). info( `Adding user interaction. siteHost: ${siteHost}, userActivationTime: ${userActivationTime} ms` ); @@ -250,12 +275,18 @@ add_task(async function test_purge() { "Check that bounce and user activation data has been correctly recorded." ); Assert.deepEqual( - btp.testGetBounceTrackerCandidateHosts({}).sort(), + btp + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost) + .sort(), expectedBounceTrackerHosts.sort(), "Has added bounce tracker hosts." ); Assert.deepEqual( - btp.testGetUserActivationHosts({}).sort(), + btp + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost) + .sort(), expectedUserActivationHosts.sort(), "Has added user activation hosts." ); @@ -269,17 +300,29 @@ add_task(async function test_purge() { "Should have purged all expected hosts." ); + // After the purge only the bounce trackers that have not been purged should + // remain in the candidate map. Additionally the allowlisted hosts should be + // removed from the candidate map. let expectedBounceTrackerHostsAfterPurge = expectedBounceTrackerHosts - .filter(host => !expectedPurgedHosts.includes(host)) + .filter( + host => + !expectedPurgedHosts.includes(host) && !allowListedHosts.includes(host) + ) .sort(); Assert.deepEqual( - btp.testGetBounceTrackerCandidateHosts({}).sort(), + btp + .testGetBounceTrackerCandidateHosts({}) + .map(entry => entry.siteHost) + .sort(), expectedBounceTrackerHostsAfterPurge.sort(), "After purge the bounce tracker candidate host set should be updated correctly." ); Assert.deepEqual( - btp.testGetUserActivationHosts({}).sort(), + btp + .testGetUserActivationHosts({}) + .map(entry => entry.siteHost) + .sort(), expiredUserActivationHosts.sort(), "After purge any expired user activation records should have been removed" ); @@ -302,6 +345,7 @@ add_task(async function test_purge() { btp.clearAll(); assertEmpty(); - info("Clean up site data."); + info("Clean up site data and permissions."); await SiteDataTestUtils.clear(); + Services.perms.removeAll(); }); diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/xpcshell.toml b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/xpcshell.toml index c3aeee502f..8195ea7224 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/xpcshell.toml +++ b/toolkit/components/antitracking/bouncetrackingprotection/test/xpcshell/xpcshell.toml @@ -3,8 +3,11 @@ prefs = [ "privacy.bounceTrackingProtection.enabled=true", "privacy.bounceTrackingProtection.enableTestMode=true", "privacy.bounceTrackingProtection.bounceTrackingPurgeTimerPeriodSec=0", + "privacy.bounceTrackingProtection.enableDryRunMode=false", ] ["test_bouncetracking_clearExpiredUserActivation.js"] +["test_bouncetracking_importUserActivationPermissions.js"] + ["test_bouncetracking_purge.js"] diff --git a/toolkit/components/antitracking/test/browser/browser.toml b/toolkit/components/antitracking/test/browser/browser.toml index edb429b49e..76023a1f9d 100644 --- a/toolkit/components/antitracking/test/browser/browser.toml +++ b/toolkit/components/antitracking/test/browser/browser.toml @@ -122,6 +122,12 @@ support-files = ["clearSiteData.sjs"] ["browser_partitionedCookies.js"] support-files = ["cookies.sjs"] +["browser_partitionedDedicatedWorker.js"] +support-files = [ + "cookies.sjs", + "dedicatedWorker.js", +] + ["browser_partitionedDOMCache.js"] ["browser_partitionedIndexedDB.js"] @@ -322,6 +328,10 @@ tags = "remote-settings" skip-if = ["os == 'linux' && asan"] # Bug 1713909 - new Fission platform triage support-files = ["file_stripping.html"] +["browser_urlQueryStringStrippingWithEncoding.js"] +skip-if = ["os == 'linux' && asan"] +support-files = ["file_stripping.html"] + ["browser_urlQueryStringStripping_allowList.js"] support-files = ["file_stripping.html"] diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedDedicatedWorker.js b/toolkit/components/antitracking/test/browser/browser_partitionedDedicatedWorker.js new file mode 100644 index 0000000000..55156beca3 --- /dev/null +++ b/toolkit/components/antitracking/test/browser/browser_partitionedDedicatedWorker.js @@ -0,0 +1,58 @@ +PartitionedStorageHelper.runTestInNormalAndPrivateMode( + "DedicatedWorkers", + async (win3rdParty, win1stParty) => { + // Set one cookie to the first party context. + await win1stParty.fetch("cookies.sjs?first").then(r => r.text()); + + // Create a dedicated worker in the first-party context. + let firstPartyWorker = new win1stParty.Worker("dedicatedWorker.js"); + + // Verify that the cookie from the first-party worker. + await new Promise(resolve => { + firstPartyWorker.addEventListener("message", msg => { + is( + msg.data, + "cookie:foopy=first", + "Got the expected first-party cookie." + ); + resolve(); + }); + + firstPartyWorker.postMessage("getCookies"); + }); + + // Set one cookie to the third-party context. + await win3rdParty + .fetch("cookies.sjs?3rd;Partitioned;Secure") + .then(r => r.text()); + + // Create a dedicated worker in the third-party context. + let thirdPartyWorker = new win3rdParty.Worker("dedicatedWorker.js"); + + // Verify that the third-party worker cannot access first-party cookies. + await new Promise(resolve => { + thirdPartyWorker.addEventListener("message", msg => { + is( + msg.data, + "cookie:foopy=3rd", + "Got the expected third-party cookie." + ); + resolve(); + }); + + thirdPartyWorker.postMessage("getCookies"); + }); + + firstPartyWorker.terminate(); + thirdPartyWorker.terminate(); + }, + + async _ => { + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () => + resolve() + ); + }); + }, + [] +); diff --git a/toolkit/components/antitracking/test/browser/browser_urlQueryStringStrippingWithEncoding.js b/toolkit/components/antitracking/test/browser/browser_urlQueryStringStrippingWithEncoding.js new file mode 100644 index 0000000000..9cc7c381c8 --- /dev/null +++ b/toolkit/components/antitracking/test/browser/browser_urlQueryStringStrippingWithEncoding.js @@ -0,0 +1,93 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const TEST_THIRD_PARTY_DOMAIN = TEST_DOMAIN_2; +const TEST_URI = TEST_DOMAIN + TEST_PATH + "file_stripping.html"; +const TEST_THIRD_PARTY_URI = + TEST_THIRD_PARTY_DOMAIN + TEST_PATH + "file_stripping.html"; + +async function verifyQueryString(browser, expected) { + await SpecialPowers.spawn(browser, [expected], expected => { + // Strip the first question mark. + let search = content.location.search.slice(1); + + is(search, expected, "The query string is correct."); + }); +} + +let listService; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.query_stripping.strip_list", "paramToStrip1 paramToStrip2"], + ["privacy.query_stripping.redirect", true], + ["privacy.query_stripping.enabled", true], + ["privacy.query_stripping.listService.logLevel", "Debug"], + ["privacy.query_stripping.strip_on_share.enabled", false], + ], + }); + + // Get the list service so we can wait for it to be fully initialized before running tests. + listService = Cc["@mozilla.org/query-stripping-list-service;1"].getService( + Ci.nsIURLQueryStrippingListService + ); + // Here we don't care about the actual enabled state, we just want any init to be done so we get reliable starting conditions. + await listService.testWaitForInit(); +}); + +add_task(async function testRedirectWithStrippingMultipleTimes() { + info( + "Start testing query stripping for redirect link with multiple query paramaters" + ); + + const NESTED_QUERY = "paramToStrip1=123¶mToKeep=123"; + const NESTED_QUERY_STRIPPED = "paramToKeep=123"; + const INITIAL_QUERY = "paramToStrip2=123"; + + let encodedURI = encodeURIComponent( + `${TEST_THIRD_PARTY_URI}?${NESTED_QUERY}` + ); + + let testThirdPartyURI = `${TEST_URI}?redirect=${encodedURI}&${INITIAL_QUERY}`; + let testThirdPartyURIStrippedQuery = `redirect=${encodedURI}`; + let targetURI = `${TEST_THIRD_PARTY_URI}?${NESTED_QUERY_STRIPPED}`; + + // 1. Open a new tab with the redirect link + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + testThirdPartyURI + ); + let browser = tab.linkedBrowser; + + // 2. Ensure the initial query parameter is stripped before the redirect + await verifyQueryString(browser, testThirdPartyURIStrippedQuery); + + // Create the promise to wait for the location change. + let targetURLLoadedPromise = BrowserTestUtils.browserLoaded( + browser, + false, + targetURI + ); + + // 4. Trigger redirect by decoding the embedded URI + await SpecialPowers.spawn(browser, [], async function () { + let url = new URL(content.location); + let value = url.searchParams.get("redirect"); + let decodedValue = decodeURIComponent(value); + + content.location.href = decodedValue; + }); + + // 5. Wait for the location change + await targetURLLoadedPromise; + + // 6. Verify that the query parameters in the nested link have been stripped + await verifyQueryString(browser, NESTED_QUERY_STRIPPED); + + BrowserTestUtils.removeTab(tab); +}); diff --git a/toolkit/components/antitracking/test/browser/dedicatedWorker.js b/toolkit/components/antitracking/test/browser/dedicatedWorker.js index 72fd4ad850..6766709a8a 100644 --- a/toolkit/components/antitracking/test/browser/dedicatedWorker.js +++ b/toolkit/components/antitracking/test/browser/dedicatedWorker.js @@ -1,3 +1,10 @@ self.onmessage = msg => { + if (msg.data == "getCookies") { + fetch("cookies.sjs") + .then(response => response.text()) + .then(data => postMessage(data)); + return; + } + self.postMessage(msg.data); }; diff --git a/toolkit/components/autocomplete/nsAutoCompleteController.cpp b/toolkit/components/autocomplete/nsAutoCompleteController.cpp index 126199e3cf..c8278f55a7 100644 --- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp +++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp @@ -490,6 +490,13 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) { } } + // Some script may have changed the value of the text field since our + // last keypress or after our focus handler and we don't want to + // search for a stale string. + nsAutoString value; + input->GetTextValue(value); + SetSearchStringInternal(value); + // Open the popup if there has been a previous non-errored search, or // else kick off a new search bool hadPreviousSearch = false; @@ -522,13 +529,6 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) { return NS_OK; } - // Some script may have changed the value of the text field since our - // last keypress or after our focus handler and we don't want to - // search for a stale string. - nsAutoString value; - input->GetTextValue(value); - SetSearchStringInternal(value); - StartSearches(); } @@ -1235,6 +1235,8 @@ nsresult nsAutoCompleteController::EnterMatch(bool aIsPopupSelection, SetSearchStringInternal(value); } + popup->SelectEntry(); + obsSvc->NotifyObservers(input, "autocomplete-did-enter-text", nullptr); input->OnTextEntered(aEvent); diff --git a/toolkit/components/autocomplete/nsIAutoCompletePopup.idl b/toolkit/components/autocomplete/nsIAutoCompletePopup.idl index 607863c9a7..556c0d49b8 100644 --- a/toolkit/components/autocomplete/nsIAutoCompletePopup.idl +++ b/toolkit/components/autocomplete/nsIAutoCompletePopup.idl @@ -5,6 +5,7 @@ #include "nsISupports.idl" interface nsIAutoCompleteInput; +interface nsIFormFillCompleteObserver; webidl Element; @@ -32,6 +33,11 @@ interface nsIAutoCompletePopup : nsISupports */ readonly attribute boolean popupOpen; + /* + * Don't rollup the popup when the search string becomes "". + */ + boolean getNoRollupOnEmptySearch(in Element element); + /* * Bind the popup to an input object and display it with the given coordinates * @@ -69,4 +75,25 @@ interface nsIAutoCompletePopup : nsISupports * @return The currently selected result item index */ void selectBy(in boolean reverse, in boolean page); + + /* + * Search for a given string and notify a listener (either synchronously + * or asynchronously) of the result + * + * @param searchString - The string to search for + * @param searchParam - An extra parameter + * @param previousResult - A previous result to use for faster searching + * @param listener - A listener to notify when the search is complete + */ + void startSearch(in AString searchString, in Element element, in nsIFormFillCompleteObserver listener); + + /* + * Stop the search that is in progress + */ + void stopSearch(); + + /** + * Notify the autocomplete popup that an autocomplete entry is selected. + */ + void selectEntry(); }; diff --git a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js b/toolkit/components/backgroundtasks/defaults/backgroundtasks.js index 874c136420..43a937def4 100644 --- a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js +++ b/toolkit/components/backgroundtasks/defaults/backgroundtasks.js @@ -54,5 +54,3 @@ pref("app.update.background.automaticRestartEnabled", true); #else pref("app.update.background.automaticRestartEnabled", false); #endif - -pref("defaultAgent.cppFallback.enabled", false); diff --git a/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js b/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js index 0df5bafd1a..8ce1e5bc5e 100644 --- a/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js +++ b/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js @@ -28,10 +28,6 @@ pref( // is required for the system to function. pref("browser.newtabpage.activity-stream.asrouter.providers.cfr", "null"); pref("browser.newtabpage.activity-stream.asrouter.providers.snippets", "null"); -pref( - "browser.newtabpage.activity-stream.asrouter.providers.whats-new-panel", - "null" -); // The `browser.newtabpage.activity-stream.asrouter.providers.cfr` provider is // disabled, but belt and braces: disable extension recommendations and feature diff --git a/toolkit/components/browser/moz.build b/toolkit/components/browser/moz.build index 903390a3c8..848c135afc 100644 --- a/toolkit/components/browser/moz.build +++ b/toolkit/components/browser/moz.build @@ -12,7 +12,6 @@ DIRS += ["build"] XPIDL_SOURCES += [ "nsIWebBrowser.idl", "nsIWebBrowserChrome.idl", - "nsIWebBrowserChromeFocus.idl", ] XPIDL_SOURCES += [ diff --git a/toolkit/components/browser/nsIWebBrowser.idl b/toolkit/components/browser/nsIWebBrowser.idl index a644dcd31e..40812ea429 100644 --- a/toolkit/components/browser/nsIWebBrowser.idl +++ b/toolkit/components/browser/nsIWebBrowser.idl @@ -38,7 +38,6 @@ interface nsIWebBrowser : nsISupports * window via the browser's nsIBaseWindow interface. * * The chrome may optionally implement nsIInterfaceRequestor, - * nsIWebBrowserChromeFocus, * nsIContextMenuListener and * nsITooltipListener to receive additional notifications * from the browser object. @@ -57,7 +56,6 @@ interface nsIWebBrowser : nsISupports * @see nsIBaseWindow * @see nsIWebBrowserChrome * @see nsIInterfaceRequestor - * @see nsIWebBrowserChromeFocus * @see nsIContextMenuListener * @see nsITooltipListener * @see nsIWeakReference diff --git a/toolkit/components/browser/nsIWebBrowserChrome.idl b/toolkit/components/browser/nsIWebBrowserChrome.idl index 517c87a285..217beda78e 100644 --- a/toolkit/components/browser/nsIWebBrowserChrome.idl +++ b/toolkit/components/browser/nsIWebBrowserChrome.idl @@ -15,7 +15,7 @@ interface nsIDocShellTreeItem; * containing an embedded Gecko web browser. */ -[scriptable, uuid(E8C414C4-DC38-4BA3-AB4E-EC4CBBE22907)] +[scriptable, builtinclass, uuid(E8C414C4-DC38-4BA3-AB4E-EC4CBBE22907)] interface nsIWebBrowserChrome : nsISupports { /** @@ -124,7 +124,7 @@ interface nsIWebBrowserChrome : nsISupports * * @see nsIBaseWindow */ - void setDimensions(in DimensionRequest aRequest); + [noscript] void setDimensions(in DimensionRequest aRequest); /** * Gets the dimensions of the window. The caller may pass @@ -134,7 +134,7 @@ interface nsIWebBrowserChrome : nsISupports * * @see nsIBaseWindow */ - void getDimensions(in DimensionKind aDimensionKind, out long aX, out long aY, out long aCX, out long aCY); + [noscript] void getDimensions(in DimensionKind aDimensionKind, out long aX, out long aY, out long aCX, out long aCY); /** * Blur the window. This should unfocus the window and send an onblur event. diff --git a/toolkit/components/browser/nsIWebBrowserChromeFocus.idl b/toolkit/components/browser/nsIWebBrowserChromeFocus.idl deleted file mode 100644 index 077ce39201..0000000000 --- a/toolkit/components/browser/nsIWebBrowserChromeFocus.idl +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 0 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" - -/** - * The nsIWebBrowserChromeFocus is implemented by the same object as the - * nsIEmbeddingSiteWindow. It represents the focus up-calls from mozilla - * to the embedding chrome. See mozilla bug #70224 for gratuitous info. - */ - -[scriptable, uuid(947B2EE6-51ED-4C2B-9F45-426C27CA84C6)] -interface nsIWebBrowserChromeFocus : nsISupports -{ - /** - * Set the focus at the next focusable element in the chrome. If - * aForDocumentNavigation is true, this was a document navigation, so - * focus the parent window. - */ - - void focusNextElement(in boolean aForDocumentNavigation); - - /** - * Set the focus at the previous focusable element in the chrome. - */ - - void focusPrevElement(in boolean aForDocumentNavigation); - -}; diff --git a/toolkit/components/cleardata/SiteDataTestUtils.sys.mjs b/toolkit/components/cleardata/SiteDataTestUtils.sys.mjs index 99bd1f72b0..f38f3aff4b 100644 --- a/toolkit/components/cleardata/SiteDataTestUtils.sys.mjs +++ b/toolkit/components/cleardata/SiteDataTestUtils.sys.mjs @@ -114,7 +114,11 @@ export var SiteDataTestUtils = { }, /** - * Adds a new localStorage entry for the specified origin, with the specified contents. + * Adds a new localStorage entry for the specified origin, with the specified + * contents. + * + * This method requires the pref dom.storage.client_validation=false in order + * to access LS without a window. * * @param {String} origin - the origin of the site to add test data for * @param {String} [key] - the localStorage key @@ -139,6 +143,9 @@ export var SiteDataTestUtils = { * @param {{key: String, value: String}[]} [testEntries] - An array of entries * to test for. * + * This method requires the pref dom.storage.client_validation=false in order + * to access LS without a window. + * * @returns {Boolean} whether the origin has localStorage data */ hasLocalStorage(origin, testEntries) { diff --git a/toolkit/components/cleardata/tests/unit/test_bounce_tracking_protection.js b/toolkit/components/cleardata/tests/unit/test_bounce_tracking_protection.js index ac0eb40fd9..a54d92eab1 100644 --- a/toolkit/components/cleardata/tests/unit/test_bounce_tracking_protection.js +++ b/toolkit/components/cleardata/tests/unit/test_bounce_tracking_protection.js @@ -139,6 +139,7 @@ async function runDeleteBySiteHostTest(clearDataServiceFn) { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_DEFAULT) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-normal-browsing.com", @@ -147,7 +148,10 @@ async function runDeleteBySiteHostTest(clearDataServiceFn) { "Should have deleted only 'common-bounce-tracker.com' for default OA." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_DEFAULT).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_DEFAULT) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-normal-browsing.com", @@ -159,6 +163,7 @@ async function runDeleteBySiteHostTest(clearDataServiceFn) { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-private-browsing.com", @@ -169,6 +174,7 @@ async function runDeleteBySiteHostTest(clearDataServiceFn) { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "common-user-activation.com", @@ -181,13 +187,17 @@ async function runDeleteBySiteHostTest(clearDataServiceFn) { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_CONTAINER) + .map(entry => entry.siteHost) .sort(), ["bounce-tracker-container.com", "bounce-tracker-container2.com"], "Should have deleted only 'common-bounce-tracker.com' for container." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_CONTAINER).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_CONTAINER) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-container.com", @@ -280,6 +290,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_DEFAULT) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-normal-browsing.com", @@ -288,7 +299,10 @@ add_task(async function test_deleteByPrincipal() { "Should have deleted only 'common-bounce-tracker.com' for default OA." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_DEFAULT).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_DEFAULT) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-normal-browsing.com", @@ -300,6 +314,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-private-browsing.com", @@ -311,6 +326,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "common-user-activation.com", @@ -323,6 +339,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_CONTAINER) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-container.com", @@ -332,7 +349,10 @@ add_task(async function test_deleteByPrincipal() { "Should not have deleted 'common-bounce-tracker.com' for container." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_CONTAINER).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_CONTAINER) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-container.com", @@ -362,6 +382,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_DEFAULT) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-normal-browsing.com", @@ -370,7 +391,10 @@ add_task(async function test_deleteByPrincipal() { "Should not have deleted any bounce tracker candidates for default OA." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_DEFAULT).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_DEFAULT) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-normal-browsing.com", @@ -382,6 +406,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-private-browsing.com", @@ -393,6 +418,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "common-user-activation.com", @@ -405,6 +431,7 @@ add_task(async function test_deleteByPrincipal() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_CONTAINER) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-container.com", @@ -414,7 +441,10 @@ add_task(async function test_deleteByPrincipal() { "Should not have deleted any bounce tracker candidates for container." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_CONTAINER).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_CONTAINER) + .map(entry => entry.siteHost) + .sort(), ["user-activation-container.com", "user-activation-container2.com"], "Should have deleted 'common-user-activation.com' for private browsing.." ); @@ -450,12 +480,16 @@ add_task(async function test_deleteByRange() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_DEFAULT) + .map(entry => entry.siteHost) .sort(), ["common-bounce-tracker.com"], "Should have only kept 'common-bounce-tracker.com' for default OA." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_DEFAULT).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_DEFAULT) + .map(entry => entry.siteHost) + .sort(), [], "Should not have kept any user activations for default OA." ); @@ -463,6 +497,7 @@ add_task(async function test_deleteByRange() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [], "Should not have kept any bounces for private browsing." @@ -470,6 +505,7 @@ add_task(async function test_deleteByRange() { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [], "Should not have kept any user activations for private browsing." @@ -478,12 +514,16 @@ add_task(async function test_deleteByRange() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_CONTAINER) + .map(entry => entry.siteHost) .sort(), ["bounce-tracker-container.com", "bounce-tracker-container2.com"], "Should have only kept some bouncer trackers for container." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_CONTAINER).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_CONTAINER) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-container.com", @@ -517,6 +557,7 @@ add_task(async function test_deleteByOriginAttributes() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_DEFAULT) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-normal-browsing.com", @@ -526,7 +567,10 @@ add_task(async function test_deleteByOriginAttributes() { "Should not have deleted any bounce tracker candidates for default OA." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_DEFAULT).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_DEFAULT) + .map(entry => entry.siteHost) + .sort(), [ "common-user-activation.com", "user-activation-normal-browsing.com", @@ -538,6 +582,7 @@ add_task(async function test_deleteByOriginAttributes() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "bounce-tracker-private-browsing.com", @@ -549,6 +594,7 @@ add_task(async function test_deleteByOriginAttributes() { Assert.deepEqual( bounceTrackingProtection .testGetUserActivationHosts(OA_PRIVATE_BROWSING) + .map(entry => entry.siteHost) .sort(), [ "common-user-activation.com", @@ -561,12 +607,16 @@ add_task(async function test_deleteByOriginAttributes() { Assert.deepEqual( bounceTrackingProtection .testGetBounceTrackerCandidateHosts(OA_CONTAINER) + .map(entry => entry.siteHost) .sort(), [], "Should have deleted all bounce tracker candidates for container." ); Assert.deepEqual( - bounceTrackingProtection.testGetUserActivationHosts(OA_CONTAINER).sort(), + bounceTrackingProtection + .testGetUserActivationHosts(OA_CONTAINER) + .map(entry => entry.siteHost) + .sort(), [], "Should have deleted all user activations for container." ); diff --git a/toolkit/components/cleardata/tests/unit/xpcshell.toml b/toolkit/components/cleardata/tests/unit/xpcshell.toml index bf2813a401..3a1386836e 100644 --- a/toolkit/components/cleardata/tests/unit/xpcshell.toml +++ b/toolkit/components/cleardata/tests/unit/xpcshell.toml @@ -13,6 +13,7 @@ prefs = [ ["test_basic.js"] ["test_bounce_tracking_protection.js"] +skip-if = ["condprof"] # Bug 1893058 ["test_certs.js"] diff --git a/toolkit/components/contentanalysis/ContentAnalysis.cpp b/toolkit/components/contentanalysis/ContentAnalysis.cpp index 2977072984..4f4c53a324 100644 --- a/toolkit/components/contentanalysis/ContentAnalysis.cpp +++ b/toolkit/components/contentanalysis/ContentAnalysis.cpp @@ -17,9 +17,11 @@ #include "mozilla/Logging.h" #include "mozilla/ScopeExit.h" #include "mozilla/Services.h" +#include "mozilla/SpinEventLoopUntil.h" #include "mozilla/StaticMutex.h" #include "mozilla/StaticPrefs_browser.h" #include "nsAppRunner.h" +#include "nsBaseClipboard.h" #include "nsComponentManagerUtils.h" #include "nsIClassInfoImpl.h" #include "nsIFile.h" @@ -28,6 +30,8 @@ #include "nsIOutputStream.h" #include "nsIPrintSettings.h" #include "nsIStorageStream.h" +#include "nsISupportsPrimitives.h" +#include "nsITransferable.h" #include "ScopedNSSTypes.h" #include "xpcpublic.h" @@ -61,7 +65,6 @@ namespace { const char* kIsDLPEnabledPref = "browser.contentanalysis.enabled"; const char* kIsPerUserPref = "browser.contentanalysis.is_per_user"; const char* kPipePathNamePref = "browser.contentanalysis.pipe_path_name"; -const char* kDefaultAllowPref = "browser.contentanalysis.default_allow"; const char* kClientSignature = "browser.contentanalysis.client_signature"; const char* kAllowUrlPref = "browser.contentanalysis.allow_url_regex_list"; const char* kDenyUrlPref = "browser.contentanalysis.deny_url_regex_list"; @@ -793,6 +796,17 @@ static bool ShouldAllowAction( aResponseCode == nsIContentAnalysisResponse::Action::eReportOnly || aResponseCode == nsIContentAnalysisResponse::Action::eWarn; } + +static DefaultResult GetDefaultResultFromPref() { + uint32_t value = StaticPrefs::browser_contentanalysis_default_result(); + if (value > static_cast(DefaultResult::eLastValue)) { + LOGE( + "Invalid value for browser.contentanalysis.default_result pref " + "value"); + return DefaultResult::eBlock; + } + return static_cast(value); +} } // namespace NS_IMETHODIMP ContentAnalysisResponse::GetShouldAllowContent( @@ -805,7 +819,7 @@ NS_IMETHODIMP ContentAnalysisResult::GetShouldAllowContent( bool* aShouldAllowContent) { if (mValue.is()) { NoContentAnalysisResult result = mValue.as(); - if (Preferences::GetBool(kDefaultAllowPref)) { + if (GetDefaultResultFromPref() == DefaultResult::eAllow) { *aShouldAllowContent = result != NoContentAnalysisResult::DENY_DUE_TO_CANCELED; } else { @@ -816,6 +830,7 @@ NS_IMETHODIMP ContentAnalysisResult::GetShouldAllowContent( ALLOW_DUE_TO_CONTENT_ANALYSIS_NOT_ACTIVE || result == NoContentAnalysisResult:: ALLOW_DUE_TO_CONTEXT_EXEMPT_FROM_CONTENT_ANALYSIS || + result == NoContentAnalysisResult::ALLOW_DUE_TO_SAME_TAB_SOURCE || result == NoContentAnalysisResult::ALLOW_DUE_TO_COULD_NOT_GET_DATA; } } else { @@ -1062,7 +1077,7 @@ nsresult ContentAnalysis::CancelWithError(nsCString aRequestToken, nsresult aResult) { return NS_DispatchToMainThread(NS_NewCancelableRunnableFunction( "ContentAnalysis::CancelWithError", - [aResult, aRequestToken = std::move(aRequestToken)] { + [aResult, aRequestToken = std::move(aRequestToken)]() mutable { RefPtr owner = GetContentAnalysisFromService(); if (!owner) { // May be shutting down @@ -1071,12 +1086,24 @@ nsresult ContentAnalysis::CancelWithError(nsCString aRequestToken, owner->SetLastResult(aResult); nsCOMPtr obsServ = mozilla::services::GetObserverService(); - bool allow = Preferences::GetBool(kDefaultAllowPref); + DefaultResult defaultResponse = GetDefaultResultFromPref(); + nsIContentAnalysisResponse::Action action; + switch (defaultResponse) { + case DefaultResult::eAllow: + action = nsIContentAnalysisResponse::Action::eAllow; + break; + case DefaultResult::eWarn: + action = nsIContentAnalysisResponse::Action::eWarn; + break; + case DefaultResult::eBlock: + action = nsIContentAnalysisResponse::Action::eCanceled; + break; + default: + MOZ_ASSERT(false); + action = nsIContentAnalysisResponse::Action::eCanceled; + } RefPtr response = - ContentAnalysisResponse::FromAction( - allow ? nsIContentAnalysisResponse::Action::eAllow - : nsIContentAnalysisResponse::Action::eCanceled, - aRequestToken); + ContentAnalysisResponse::FromAction(action, aRequestToken); response->SetOwner(owner); nsIContentAnalysisResponse::CancelError cancelError; switch (aResult) { @@ -1092,20 +1119,29 @@ nsresult ContentAnalysis::CancelWithError(nsCString aRequestToken, break; } response->SetCancelError(cancelError); - obsServ->NotifyObservers(response, "dlp-response", nullptr); - nsMainThreadPtrHandle callbackHolder; + Maybe maybeCallbackData; { auto lock = owner->mCallbackMap.Lock(); - auto callbackData = lock->Extract(aRequestToken); - if (callbackData.isSome()) { - callbackHolder = callbackData->TakeCallbackHolder(); + maybeCallbackData = lock->Extract(aRequestToken); + if (maybeCallbackData.isNothing()) { + LOGD("Content analysis did not find callback for token %s", + aRequestToken.get()); + return; } } + if (action == nsIContentAnalysisResponse::Action::eWarn) { + owner->SendWarnResponse(std::move(aRequestToken), + std::move(*maybeCallbackData), response); + return; + } + nsMainThreadPtrHandle callbackHolder = + maybeCallbackData->TakeCallbackHolder(); + obsServ->NotifyObservers(response, "dlp-response", nullptr); if (callbackHolder) { - if (allow) { - callbackHolder->ContentResult(response); - } else { + if (action == nsIContentAnalysisResponse::Action::eCanceled) { callbackHolder->Error(aResult); + } else { + callbackHolder->ContentResult(response); } } })); @@ -1184,6 +1220,22 @@ nsresult ContentAnalysis::RunAnalyzeRequestTask( ConvertToProtobuf(aRequest, GetUserActionId(), aRequestCount, &pbRequest); NS_ENSURE_SUCCESS(rv, rv); LogRequest(&pbRequest); + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + // Avoid serializing the string here if no one is observing this message + if (obsServ->HasObservers("dlp-request-sent-raw")) { + std::string requestString = pbRequest.SerializeAsString(); + nsTArray requestArray; + requestArray.SetLength(requestString.size() + 1); + for (size_t i = 0; i < requestString.size(); ++i) { + // Since NotifyObservers() expects a null-terminated string, + // make sure none of these values are 0. + requestArray[i] = requestString[i] + 0xFF00; + } + requestArray[requestString.size()] = 0; + obsServ->NotifyObservers(this, "dlp-request-sent-raw", + requestArray.Elements()); + } mCaClientPromise->Then( GetCurrentSerialEventTarget(), __func__, @@ -1289,6 +1341,20 @@ void ContentAnalysis::DoAnalyzeRequest( })); } +void ContentAnalysis::SendWarnResponse( + nsCString&& aResponseRequestToken, CallbackData aCallbackData, + RefPtr& aResponse) { + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + { + auto warnResponseDataMap = mWarnResponseDataMap.Lock(); + warnResponseDataMap->InsertOrUpdate( + aResponseRequestToken, + WarnResponseData(std::move(aCallbackData), aResponse)); + } + obsServ->NotifyObservers(aResponse, "dlp-response", nullptr); +} + void ContentAnalysis::IssueResponse(RefPtr& response) { MOZ_ASSERT(NS_IsMainThread()); nsCString responseRequestToken; @@ -1336,13 +1402,8 @@ void ContentAnalysis::IssueResponse(RefPtr& response) { nsCOMPtr obsServ = mozilla::services::GetObserverService(); if (action == nsIContentAnalysisResponse::Action::eWarn) { - { - auto warnResponseDataMap = mWarnResponseDataMap.Lock(); - warnResponseDataMap->InsertOrUpdate( - responseRequestToken, - WarnResponseData(std::move(*maybeCallbackData), response)); - } - obsServ->NotifyObservers(response, "dlp-response", nullptr); + SendWarnResponse(std::move(responseRequestToken), + std::move(*maybeCallbackData), response); return; } @@ -1696,6 +1757,233 @@ ContentAnalysis::PrintToPDFToDetermineIfPrintAllowed( } #endif +NS_IMPL_ISUPPORTS(ContentAnalysis::SafeContentAnalysisResultCallback, + nsIContentAnalysisCallback); + +// - true means a content analysis request was fired +// - false means there is no text data in the transferable +// - NoContentAnalysisResult means there was an error +using ClipboardContentAnalysisResult = + mozilla::Result; + +NS_IMETHODIMP ContentAnalysis::SafeContentAnalysisResultCallback::ContentResult( + nsIContentAnalysisResponse* aResponse) { + RefPtr result = + ContentAnalysisResult::FromContentAnalysisResponse(aResponse); + Callback(result); + return NS_OK; +} + +NS_IMETHODIMP ContentAnalysis::SafeContentAnalysisResultCallback::Error( + nsresult aError) { + Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR)); + return NS_OK; +} + +ClipboardContentAnalysisResult CheckClipboardContentAnalysisAsText( + uint64_t aInnerWindowId, + ContentAnalysis::SafeContentAnalysisResultCallback* aResolver, + nsIURI* aDocumentURI, nsIContentAnalysis* aContentAnalysis, + nsITransferable* aTextTrans, const char* aFlavor) { + nsCOMPtr transferData; + if (NS_FAILED( + aTextTrans->GetTransferData(aFlavor, getter_AddRefs(transferData)))) { + return false; + } + nsCOMPtr textData = do_QueryInterface(transferData); + if (MOZ_UNLIKELY(!textData)) { + return false; + } + nsString text; + if (NS_FAILED(textData->GetData(text))) { + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + if (text.IsEmpty()) { + // Content Analysis doesn't expect to analyze an empty string. + // Just approve it. + return true; + } + RefPtr window = + mozilla::dom::WindowGlobalParent::GetByInnerWindowId(aInnerWindowId); + if (!window) { + // The window has gone away in the meantime + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + nsCOMPtr contentAnalysisRequest = + new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, + std::move(text), false, EmptyCString(), aDocumentURI, + nsIContentAnalysisRequest::OperationType::eClipboard, window); + nsresult rv = aContentAnalysis->AnalyzeContentRequestCallback( + contentAnalysisRequest, /* aAutoAcknowledge */ true, aResolver); + if (NS_FAILED(rv)) { + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + return true; +} + +ClipboardContentAnalysisResult CheckClipboardContentAnalysisAsFile( + uint64_t aInnerWindowId, + ContentAnalysis::SafeContentAnalysisResultCallback* aResolver, + nsIURI* aDocumentURI, nsIContentAnalysis* aContentAnalysis, + nsITransferable* aFileTrans) { + nsCOMPtr transferData; + nsresult rv = + aFileTrans->GetTransferData(kFileMime, getter_AddRefs(transferData)); + nsString filePath; + if (NS_SUCCEEDED(rv)) { + if (nsCOMPtr file = do_QueryInterface(transferData)) { + rv = file->GetPath(filePath); + } else { + MOZ_ASSERT_UNREACHABLE("clipboard data had kFileMime but no nsIFile!"); + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + } + if (NS_FAILED(rv) || filePath.IsEmpty()) { + return false; + } + RefPtr window = + mozilla::dom::WindowGlobalParent::GetByInnerWindowId(aInnerWindowId); + if (!window) { + // The window has gone away in the meantime + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + // Let the content analysis code calculate the digest + nsCOMPtr contentAnalysisRequest = + new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, + std::move(filePath), true, EmptyCString(), aDocumentURI, + nsIContentAnalysisRequest::OperationType::eCustomDisplayString, + window); + rv = aContentAnalysis->AnalyzeContentRequestCallback( + contentAnalysisRequest, + /* aAutoAcknowledge */ true, aResolver); + if (NS_FAILED(rv)) { + return mozilla::Err(NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR); + } + return true; +} + +void ContentAnalysis::CheckClipboardContentAnalysis( + nsBaseClipboard* aClipboard, mozilla::dom::WindowGlobalParent* aWindow, + nsITransferable* aTransferable, int32_t aClipboardType, + SafeContentAnalysisResultCallback* aResolver) { + using namespace mozilla::contentanalysis; + + // Content analysis is only needed if an outside webpage has access to + // the data. So, skip content analysis if there is: + // - no associated window (for example, scripted clipboard read by system + // code) + // - the window is a chrome docshell + // - the window is being rendered in the parent process (for example, + // about:support and the like) + if (!aWindow || aWindow->GetBrowsingContext()->IsChrome() || + aWindow->IsInProcess()) { + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult:: + ALLOW_DUE_TO_CONTEXT_EXEMPT_FROM_CONTENT_ANALYSIS)); + return; + } + nsCOMPtr contentAnalysis = + mozilla::components::nsIContentAnalysis::Service(); + if (!contentAnalysis) { + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR)); + return; + } + + bool contentAnalysisIsActive; + nsresult rv = contentAnalysis->GetIsActive(&contentAnalysisIsActive); + if (MOZ_LIKELY(NS_FAILED(rv) || !contentAnalysisIsActive)) { + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::ALLOW_DUE_TO_CONTENT_ANALYSIS_NOT_ACTIVE)); + return; + } + + uint64_t innerWindowId = aWindow->InnerWindowId(); + if (mozilla::StaticPrefs:: + browser_contentanalysis_bypass_for_same_tab_operations()) { + mozilla::Maybe cacheInnerWindowId = + aClipboard->GetClipboardCacheInnerWindowId(aClipboardType); + if (cacheInnerWindowId.isSome() && *cacheInnerWindowId == innerWindowId) { + // If the same page copied this data to the clipboard (and the above + // preference is set) we can skip content analysis and immediately allow + // this. + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::ALLOW_DUE_TO_SAME_TAB_SOURCE)); + return; + } + } + + nsCOMPtr currentURI = aWindow->Canonical()->GetDocumentURI(); + nsTArray flavors; + rv = aTransferable->FlavorsTransferableCanExport(flavors); + if (NS_WARN_IF(NS_FAILED(rv))) { + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::DENY_DUE_TO_OTHER_ERROR)); + return; + } + bool keepChecking = true; + if (flavors.Contains(kFileMime)) { + auto fileResult = CheckClipboardContentAnalysisAsFile( + innerWindowId, aResolver, currentURI, contentAnalysis, aTransferable); + + if (fileResult.isErr()) { + aResolver->Callback( + ContentAnalysisResult::FromNoResult(fileResult.unwrapErr())); + return; + } + keepChecking = !fileResult.unwrap(); + } + if (keepChecking) { + // Failed to get the clipboard data as a file, so try as text + auto textResult = CheckClipboardContentAnalysisAsText( + innerWindowId, aResolver, currentURI, contentAnalysis, aTransferable, + kTextMime); + if (textResult.isErr()) { + aResolver->Callback( + ContentAnalysisResult::FromNoResult(textResult.unwrapErr())); + return; + } + keepChecking = !textResult.unwrap(); + } + if (keepChecking) { + // Failed to get the clipboard data as a file or text, so try as html + auto htmlResult = CheckClipboardContentAnalysisAsText( + innerWindowId, aResolver, currentURI, contentAnalysis, aTransferable, + kHTMLMime); + if (htmlResult.isErr()) { + aResolver->Callback( + ContentAnalysisResult::FromNoResult(htmlResult.unwrapErr())); + return; + } + if (!htmlResult.unwrap()) { + // Couldn't get file or text or html data from this + aResolver->Callback(ContentAnalysisResult::FromNoResult( + NoContentAnalysisResult::ALLOW_DUE_TO_COULD_NOT_GET_DATA)); + return; + } + } +} + +bool ContentAnalysis::CheckClipboardContentAnalysisSync( + nsBaseClipboard* aClipboard, mozilla::dom::WindowGlobalParent* aWindow, + const nsCOMPtr& trans, int32_t aClipboardType) { + bool requestDone = false; + RefPtr result; + auto callback = mozilla::MakeRefPtr( + [&requestDone, &result](RefPtr&& aResult) { + result = std::move(aResult); + requestDone = true; + }); + CheckClipboardContentAnalysis(aClipboard, aWindow, trans, aClipboardType, + callback); + mozilla::SpinEventLoopUntil("CheckClipboardContentAnalysisSync"_ns, + [&requestDone]() -> bool { return requestDone; }); + return result->GetShouldAllowContent(); +} + NS_IMETHODIMP ContentAnalysisResponse::Acknowledge( nsIContentAnalysisAcknowledgement* aAcknowledgement) { diff --git a/toolkit/components/contentanalysis/ContentAnalysis.h b/toolkit/components/contentanalysis/ContentAnalysis.h index f2545624fd..2d8a1891b7 100644 --- a/toolkit/components/contentanalysis/ContentAnalysis.h +++ b/toolkit/components/contentanalysis/ContentAnalysis.h @@ -7,6 +7,7 @@ #define mozilla_contentanalysis_h #include "mozilla/DataMutex.h" +#include "mozilla/MoveOnlyFunction.h" #include "mozilla/MozPromise.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/MaybeDiscarded.h" @@ -24,6 +25,7 @@ # include #endif // XP_WIN +class nsBaseClipboard; class nsIPrincipal; class nsIPrintSettings; class ContentAnalysisTest; @@ -42,6 +44,13 @@ class ContentAnalysisResponse; namespace mozilla::contentanalysis { +enum class DefaultResult : uint8_t { + eBlock = 0, + eWarn = 1, + eAllow = 2, + eLastValue = 2 +}; + class ContentAnalysisDiagnosticInfo final : public nsIContentAnalysisDiagnosticInfo { public: @@ -149,6 +158,7 @@ class ContentAnalysis final : public nsIContentAnalysis { nsCString GetUserActionId(); void SetLastResult(nsresult aLastResult) { mLastResult = aLastResult; } +#if defined(XP_WIN) struct PrintAllowedResult final { bool mAllowed; dom::MaybeDiscarded @@ -175,13 +185,42 @@ class ContentAnalysis final : public nsIContentAnalysis { }; using PrintAllowedPromise = MozPromise; -#if defined(XP_WIN) MOZ_CAN_RUN_SCRIPT static RefPtr PrintToPDFToDetermineIfPrintAllowed( dom::CanonicalBrowsingContext* aBrowsingContext, nsIPrintSettings* aPrintSettings); #endif // defined(XP_WIN) + class SafeContentAnalysisResultCallback final + : public nsIContentAnalysisCallback { + public: + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSICONTENTANALYSISCALLBACK + explicit SafeContentAnalysisResultCallback( + std::function&&)> aResolver) + : mResolver(std::move(aResolver)) {} + void Callback(RefPtr&& aResult) { + MOZ_ASSERT(mResolver, "Called SafeContentAnalysisResultCallback twice!"); + if (auto resolver = std::move(mResolver)) { + resolver(std::move(aResult)); + } + } + + private: + ~SafeContentAnalysisResultCallback() { + MOZ_ASSERT(!mResolver, "SafeContentAnalysisResultCallback never called!"); + } + mozilla::MoveOnlyFunction&&)> + mResolver; + }; + static bool CheckClipboardContentAnalysisSync( + nsBaseClipboard* aClipboard, mozilla::dom::WindowGlobalParent* aWindow, + const nsCOMPtr& trans, int32_t aClipboardType); + static void CheckClipboardContentAnalysis( + nsBaseClipboard* aClipboard, mozilla::dom::WindowGlobalParent* aWindow, + nsITransferable* aTransferable, int32_t aClipboardType, + SafeContentAnalysisResultCallback* aResolver); + private: ~ContentAnalysis(); // Remove unneeded copy constructor/assignment @@ -210,7 +249,6 @@ class ContentAnalysis final : public nsIContentAnalysis { const std::shared_ptr& aClient); void IssueResponse(RefPtr& response); bool LastRequestSucceeded(); - // Did the URL filter completely handle the request or do we need to check // with the agent. enum UrlFilterResult { eCheck, eDeny, eAllow }; @@ -259,6 +297,9 @@ class ContentAnalysis final : public nsIContentAnalysis { RefPtr mResponse; }; DataMutex> mWarnResponseDataMap; + void SendWarnResponse(nsCString&& aResponseRequestToken, + CallbackData aCallbackData, + RefPtr& aResponse); std::vector mAllowUrlList; std::vector mDenyUrlList; diff --git a/toolkit/components/contentanalysis/ContentAnalysisIPCTypes.h b/toolkit/components/contentanalysis/ContentAnalysisIPCTypes.h index a554036257..48e650d778 100644 --- a/toolkit/components/contentanalysis/ContentAnalysisIPCTypes.h +++ b/toolkit/components/contentanalysis/ContentAnalysisIPCTypes.h @@ -19,6 +19,7 @@ namespace contentanalysis { enum class NoContentAnalysisResult : uint8_t { ALLOW_DUE_TO_CONTENT_ANALYSIS_NOT_ACTIVE, ALLOW_DUE_TO_CONTEXT_EXEMPT_FROM_CONTENT_ANALYSIS, + ALLOW_DUE_TO_SAME_TAB_SOURCE, ALLOW_DUE_TO_COULD_NOT_GET_DATA, DENY_DUE_TO_CANCELED, DENY_DUE_TO_INVALID_JSON_RESPONSE, diff --git a/toolkit/components/contentanalysis/tests/browser/browser.toml b/toolkit/components/contentanalysis/tests/browser/browser.toml index bdbf350593..7a9a3533d1 100644 --- a/toolkit/components/contentanalysis/tests/browser/browser.toml +++ b/toolkit/components/contentanalysis/tests/browser/browser.toml @@ -4,6 +4,33 @@ support-files = [ "head.js", ] +["browser_clipboard_content_analysis.js"] + +["browser_clipboard_paste_file_content_analysis.js"] +support-files = [ + "clipboard_paste_file.html", +] + +["browser_clipboard_paste_inputandtextarea_content_analysis.js"] +support-files = [ + "clipboard_paste_inputandtextarea.html", +] + +["browser_clipboard_paste_noformatting_content_analysis.js"] +support-files = [ + "clipboard_paste_noformatting.html", +] + +["browser_clipboard_paste_prompt_content_analysis.js"] +support-files = [ + "clipboard_paste_prompt.html", +] + +["browser_clipboard_read_async_content_analysis.js"] +support-files = [ + "clipboard_read_async.html", +] + ["browser_content_analysis_policies.js"] ["browser_print_changing_page_content_analysis.js"] diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_content_analysis.js new file mode 100644 index 0000000000..875dbaa6e3 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_content_analysis.js @@ -0,0 +1,363 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// This test is used to check copy and paste in editable areas to ensure that non-text +// types (html and images) are copied to and pasted from the clipboard properly. + +var testPage = + "" + + " " + + "
Test Bold After Text
" + + ""; + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); +}); + +async function testClipboardWithContentAnalysis(allowPaste) { + mockCA.setupForTest(allowPaste); + let tab = BrowserTestUtils.addTab(gBrowser); + let browser = gBrowser.getBrowserForTab(tab); + + gBrowser.selectedTab = tab; + + await promiseTabLoadEvent(tab, "data:text/html," + escape(testPage)); + await SimpleTest.promiseFocus(browser); + + function sendKey(key, code) { + return BrowserTestUtils.synthesizeKey( + key, + { code, accelKey: true }, + browser + ); + } + + // On windows, HTML clipboard includes extra data. + // The values are from widget/windows/nsDataObj.cpp. + const htmlPrefix = navigator.platform.includes("Win") + ? "\n" + : ""; + const htmlPostfix = navigator.platform.includes("Win") + ? "\n\n" + : ""; + + await SpecialPowers.spawn(browser, [], () => { + var doc = content.document; + var main = doc.getElementById("main"); + main.focus(); + + // Select an area of the text. + let selection = doc.getSelection(); + selection.modify("move", "left", "line"); + selection.modify("move", "right", "character"); + selection.modify("move", "right", "character"); + selection.modify("move", "right", "character"); + selection.modify("extend", "right", "word"); + selection.modify("extend", "right", "word"); + }); + + // The data is empty as the selection was copied during the event default phase. + let copyEventPromise = BrowserTestUtils.waitForContentEvent( + browser, + "copy", + false, + event => { + return event.clipboardData.mozItemCount == 0; + } + ); + await SpecialPowers.spawn(browser, [], () => {}); + await sendKey("c"); + await copyEventPromise; + + let pastePromise = SpecialPowers.spawn( + browser, + [htmlPrefix, htmlPostfix, allowPaste], + (htmlPrefixChild, htmlPostfixChild, allowPaste) => { + let selection = content.document.getSelection(); + selection.modify("move", "right", "line"); + + return new Promise((resolve, _reject) => { + content.addEventListener( + "paste", + event => { + let clipboardData = event.clipboardData; + Assert.equal( + clipboardData.mozItemCount, + 1, + "One item on clipboard" + ); + Assert.equal( + clipboardData.types.length, + 2, + "Two types on clipboard" + ); + Assert.equal( + clipboardData.types[0], + "text/html", + "text/html on clipboard" + ); + Assert.equal( + clipboardData.types[1], + "text/plain", + "text/plain on clipboard" + ); + Assert.equal( + clipboardData.getData("text/html"), + allowPaste + ? htmlPrefixChild + "t Bold" + htmlPostfixChild + : "", + "text/html value" + ); + Assert.equal( + clipboardData.getData("text/plain"), + allowPaste ? "t Bold" : "", + "text/plain value" + ); + resolve(); + }, + { capture: true, once: true } + ); + }); + } + ); + + await SpecialPowers.spawn(browser, [], () => {}); + + await sendKey("v"); + await pastePromise; + // 2 calls because there are two formats on the clipboard + is(mockCA.calls.length, 2, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest( + mockCA.calls[0], + htmlPrefix + "t Bold" + htmlPostfix + ); + assertContentAnalysisRequest(mockCA.calls[1], "t Bold"); + mockCA.clearCalls(); + + let copyPromise = SpecialPowers.spawn(browser, [], () => { + var main = content.document.getElementById("main"); + + Assert.equal( + main.innerHTML, + "Test Bold After Textt Bold", + "Copy and paste html" + ); + + let selection = content.document.getSelection(); + selection.modify("extend", "left", "word"); + selection.modify("extend", "left", "word"); + selection.modify("extend", "left", "character"); + + return new Promise((resolve, _reject) => { + content.addEventListener( + "cut", + event => { + event.clipboardData.setData("text/plain", "Some text"); + event.clipboardData.setData("text/html", "Italic "); + selection.deleteFromDocument(); + event.preventDefault(); + resolve(); + }, + { capture: true, once: true } + ); + }); + }); + + await SpecialPowers.spawn(browser, [], () => {}); + + await sendKey("x"); + await copyPromise; + + pastePromise = SpecialPowers.spawn( + browser, + [htmlPrefix, htmlPostfix, allowPaste], + (htmlPrefixChild, htmlPostfixChild, allowPaste) => { + let selection = content.document.getSelection(); + selection.modify("move", "left", "line"); + + return new Promise((resolve, _reject) => { + content.addEventListener( + "paste", + event => { + let clipboardData = event.clipboardData; + Assert.equal( + clipboardData.mozItemCount, + 1, + "One item on clipboard 2" + ); + Assert.equal( + clipboardData.types.length, + 2, + "Two types on clipboard 2" + ); + Assert.equal( + clipboardData.types[0], + "text/html", + "text/html on clipboard 2" + ); + Assert.equal( + clipboardData.types[1], + "text/plain", + "text/plain on clipboard 2" + ); + Assert.equal( + clipboardData.getData("text/html"), + allowPaste + ? htmlPrefixChild + "Italic " + htmlPostfixChild + : "", + "text/html value 2" + ); + Assert.equal( + clipboardData.getData("text/plain"), + allowPaste ? "Some text" : "", + "text/plain value 2" + ); + resolve(); + }, + { capture: true, once: true } + ); + }); + } + ); + + await SpecialPowers.spawn(browser, [], () => {}); + + await sendKey("v"); + await pastePromise; + // 2 calls because there are two formats on the clipboard + is(mockCA.calls.length, 2, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest( + mockCA.calls[0], + htmlPrefix + "Italic " + htmlPostfix + ); + assertContentAnalysisRequest(mockCA.calls[1], "Some text"); + mockCA.clearCalls(); + + await SpecialPowers.spawn(browser, [], () => { + var main = content.document.getElementById("main"); + Assert.equal( + main.innerHTML, + "Italic Test Bold After", + "Copy and paste html 2" + ); + }); + + // Next, check that the Copy Image command works. + + // The context menu needs to be opened to properly initialize for the copy + // image command to run. + let contextMenu = document.getElementById("contentAreaContextMenu"); + let contextMenuShown = promisePopupShown(contextMenu); + BrowserTestUtils.synthesizeMouseAtCenter( + "#img", + { type: "contextmenu", button: 2 }, + gBrowser.selectedBrowser + ); + await contextMenuShown; + + document.getElementById("context-copyimage-contents").doCommand(); + + contextMenu.hidePopup(); + await promisePopupHidden(contextMenu); + + // Focus the content again + await SimpleTest.promiseFocus(browser); + + pastePromise = SpecialPowers.spawn( + browser, + [htmlPrefix, htmlPostfix, allowPaste], + (htmlPrefixChild, htmlPostfixChild, allowPaste) => { + var doc = content.document; + var main = doc.getElementById("main"); + main.focus(); + + return new Promise((resolve, reject) => { + content.addEventListener( + "paste", + event => { + let clipboardData = event.clipboardData; + + // DataTransfer doesn't support the image types yet, so only text/html + // will be present. + let clipboardText = clipboardData.getData("text/html"); + if (allowPaste) { + if ( + clipboardText !== + htmlPrefixChild + + '' + + htmlPostfixChild + ) { + reject( + "Clipboard Data did not contain an image, was " + + clipboardText + ); + } + } else if (clipboardText !== "") { + reject("Clipboard Data should be empty, was " + clipboardText); + } + resolve(); + }, + { capture: true, once: true } + ); + }); + } + ); + + await SpecialPowers.spawn(browser, [], () => {}); + await sendKey("v"); + await pastePromise; + is(mockCA.calls.length, 1, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest( + mockCA.calls[0], + htmlPrefix + + '' + + htmlPostfix + ); + mockCA.clearCalls(); + + // The new content should now include an image. + await SpecialPowers.spawn(browser, [], () => { + var main = content.document.getElementById("main"); + Assert.equal( + main.innerHTML, + 'Italic ' + + "Test Bold After", + "Paste after copy image" + ); + }); + + gBrowser.removeCurrentTab(); +} + +function assertContentAnalysisRequest(request, expectedText) { + is( + request.url.spec, + "data:text/html," + escape(testPage), + "request has correct URL" + ); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + Ci.nsIContentAnalysisRequest.eClipboard, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, "", "request filePath should be empty"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} +add_task(async function testClipboardWithContentAnalysisAllow() { + await testClipboardWithContentAnalysis(true); +}); + +add_task(async function testClipboardWithContentAnalysisBlock() { + await testClipboardWithContentAnalysis(false); +}); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_file_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_file_content_analysis.js new file mode 100644 index 0000000000..8441c4d7fd --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_file_content_analysis.js @@ -0,0 +1,202 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that (real) files can be pasted into chrome/content. +// Pasting files should also hide all other data from content. + +function setClipboard(path) { + const file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); + file.initWithPath(path); + + const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + trans.addDataFlavor("application/x-moz-file"); + trans.setTransferData("application/x-moz-file", file); + + trans.addDataFlavor("text/plain"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = "Alternate"; + trans.setTransferData("text/plain", str); + + // Write to clipboard. + Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); +} + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); +}); + +const PAGE_URL = + "https://example.com/browser/toolkit/components/contentanalysis/tests/browser/clipboard_paste_file.html"; + +function assertContentAnalysisRequest( + request, + expectedDisplayType, + expectedFilePath, + expectedText +) { + is(request.url.spec, PAGE_URL, "request has correct URL"); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + expectedDisplayType, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, expectedFilePath, "request filePath should match"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} +function assertContentAnalysisRequestFile(request, expectedFilePath) { + assertContentAnalysisRequest( + request, + Ci.nsIContentAnalysisRequest.eCustomDisplayString, + expectedFilePath, + "" + ); +} +function assertContentAnalysisRequestText(request, expectedText) { + assertContentAnalysisRequest( + request, + Ci.nsIContentAnalysisRequest.eClipboard, + "", + expectedText + ); +} + +async function testClipboardPasteFileWithContentAnalysis(allowPaste) { + mockCA.setupForTest(allowPaste); + await SpecialPowers.pushPrefEnv({ + set: [["dom.events.dataTransfer.mozFile.enabled", true]], + }); + + // Create a temporary file that will be pasted. + const file = await IOUtils.createUniqueFile( + PathUtils.tempDir, + "test-file.txt", + 0o600 + ); + const FILE_TEXT = "Hello World!"; + await IOUtils.writeUTF8(file, FILE_TEXT); + + // Put the data directly onto the native clipboard to make sure + // it isn't handled internally in Gecko somehow. + setClipboard(file); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + + let resultPromise = SpecialPowers.spawn(browser, [allowPaste], allowPaste => { + return new Promise(resolve => { + content.document.addEventListener("testresult", event => { + resolve(event.detail.result); + }); + content.document.getElementById("pasteAllowed").checked = allowPaste; + }); + }); + + // Focus in content + await SpecialPowers.spawn(browser, [], async function () { + content.document.getElementById("input").focus(); + }); + + // Paste file into in content + await BrowserTestUtils.synthesizeKey("v", { accelKey: true }, browser); + + let result = await resultPromise; + is( + result, + allowPaste ? PathUtils.filename(file) : "", + "Correctly pasted file in content" + ); + is(mockCA.calls.length, 2, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequestFile(mockCA.calls[0], file); + assertContentAnalysisRequestText(mockCA.calls[1], "Alternate"); + mockCA.clearCalls(); + + // The following part of the test is done in-process (note the use of document here instead of + // content.document) so none of this should go through content analysis. + var input = document.createElement("input"); + document.documentElement.appendChild(input); + input.focus(); + + await new Promise((resolve, _reject) => { + input.addEventListener( + "paste", + function (event) { + let dt = event.clipboardData; + is(dt.types.length, 3, "number of types"); + ok(dt.types.includes("text/plain"), "text/plain exists in types"); + ok( + dt.types.includes("application/x-moz-file"), + "application/x-moz-file exists in types" + ); + is(dt.types[2], "Files", "Last type should be 'Files'"); + ok( + dt.mozTypesAt(0).contains("text/plain"), + "text/plain exists in mozTypesAt" + ); + is( + dt.getData("text/plain"), + "Alternate", + "text/plain returned in getData" + ); + is( + dt.mozGetDataAt("text/plain", 0), + "Alternate", + "text/plain returned in mozGetDataAt" + ); + + ok( + dt.mozTypesAt(0).contains("application/x-moz-file"), + "application/x-moz-file exists in mozTypesAt" + ); + let mozFile = dt.mozGetDataAt("application/x-moz-file", 0); + + ok( + mozFile instanceof Ci.nsIFile, + "application/x-moz-file returned nsIFile with mozGetDataAt" + ); + + is( + mozFile.leafName, + PathUtils.filename(file), + "nsIFile has correct leafName" + ); + + is(mozFile.fileSize, FILE_TEXT.length, "nsIFile has correct length"); + + resolve(); + }, + { capture: true, once: true } + ); + + EventUtils.synthesizeKey("v", { accelKey: true }); + }); + is(mockCA.calls.length, 0, "Correct number of calls to Content Analysis"); + + input.remove(); + + BrowserTestUtils.removeTab(tab); + + await IOUtils.remove(file); +} + +add_task(async function testClipboardPasteFileWithContentAnalysisAllow() { + await testClipboardPasteFileWithContentAnalysis(true); +}); + +add_task(async function testClipboardPasteFileWithContentAnalysisBlock() { + await testClipboardPasteFileWithContentAnalysis(false); +}); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_inputandtextarea_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_inputandtextarea_content_analysis.js new file mode 100644 index 0000000000..6fe37c3368 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_inputandtextarea_content_analysis.js @@ -0,0 +1,112 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); +}); + +const PAGE_URL = + "https://example.com/browser/toolkit/components/contentanalysis/tests/browser/clipboard_paste_inputandtextarea.html"; +const CLIPBOARD_TEXT_STRING = "Just some text"; +async function testClipboardPaste(allowPaste) { + mockCA.setupForTest(allowPaste); + + setClipboardData(); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + + await SpecialPowers.spawn(browser, [allowPaste], async allowPaste => { + content.document.getElementById("pasteAllowed").checked = allowPaste; + }); + await testPasteWithElementId("testInput", browser, allowPaste); + await testPasteWithElementId("testTextArea", browser, allowPaste); + + BrowserTestUtils.removeTab(tab); +} + +function setClipboardData() { + const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + trans.addDataFlavor("text/plain"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = CLIPBOARD_TEXT_STRING; + trans.setTransferData("text/plain", str); + + // Write to clipboard. + Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); +} + +async function testPasteWithElementId(elementId, browser, allowPaste) { + let resultPromise = SpecialPowers.spawn(browser, [], () => { + return new Promise(resolve => { + content.document.addEventListener( + "testresult", + event => { + resolve(event.detail.result); + }, + { once: true } + ); + }); + }); + + // Paste into content + await SpecialPowers.spawn(browser, [elementId], async elementId => { + content.document.getElementById(elementId).focus(); + }); + await BrowserTestUtils.synthesizeKey("v", { accelKey: true }, browser); + let result = await resultPromise; + is(result, undefined, "Got unexpected result from page"); + + // Because we call event.clipboardData.getData in the test, this causes another call to + // content analysis. + is(mockCA.calls.length, 2, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest(mockCA.calls[0], CLIPBOARD_TEXT_STRING); + assertContentAnalysisRequest(mockCA.calls[1], CLIPBOARD_TEXT_STRING); + mockCA.clearCalls(); + let value = await getElementValue(browser, elementId); + is( + value, + allowPaste ? CLIPBOARD_TEXT_STRING : "", + "element has correct value" + ); +} + +function assertContentAnalysisRequest(request, expectedText) { + is(request.url.spec, PAGE_URL, "request has correct URL"); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + Ci.nsIContentAnalysisRequest.eClipboard, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, "", "request filePath should match"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} + +async function getElementValue(browser, elementId) { + return await SpecialPowers.spawn(browser, [elementId], async elementId => { + return content.document.getElementById(elementId).value; + }); +} + +add_task(async function testClipboardPasteWithContentAnalysisAllow() { + await testClipboardPaste(true); +}); + +add_task(async function testClipboardPasteWithContentAnalysisBlock() { + await testClipboardPaste(false); +}); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_noformatting_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_noformatting_content_analysis.js new file mode 100644 index 0000000000..0eedcddd17 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_noformatting_content_analysis.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); +}); + +const PAGE_URL = + "https://example.com/browser/toolkit/components/contentanalysis/tests/browser/clipboard_paste_noformatting.html"; +async function testClipboardPasteNoFormatting(allowPaste) { + mockCA.setupForTest(allowPaste); + + const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + const CLIPBOARD_TEXT_STRING = "Some text"; + const CLIPBOARD_HTML_STRING = "Some HTML"; + { + trans.addDataFlavor("text/plain"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = CLIPBOARD_TEXT_STRING; + trans.setTransferData("text/plain", str); + } + { + trans.addDataFlavor("text/html"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = CLIPBOARD_HTML_STRING; + trans.setTransferData("text/html", str); + } + + // Write to clipboard. + Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + let result = await SpecialPowers.spawn(browser, [allowPaste], allowPaste => { + return new Promise(resolve => { + content.document.addEventListener("testresult", event => { + resolve(event.detail.result); + }); + content.document.getElementById("pasteAllowed").checked = allowPaste; + content.document.dispatchEvent(new content.CustomEvent("teststart", {})); + }); + }); + is(result, true, "Got unexpected result from page"); + + // Because we call event.clipboardData.getData in the test, this causes another call to + // content analysis. + is(mockCA.calls.length, 2, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest(mockCA.calls[0], CLIPBOARD_TEXT_STRING); + assertContentAnalysisRequest(mockCA.calls[1], CLIPBOARD_TEXT_STRING); + + BrowserTestUtils.removeTab(tab); +} + +function assertContentAnalysisRequest(request, expectedText) { + is(request.url.spec, PAGE_URL, "request has correct URL"); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + Ci.nsIContentAnalysisRequest.eClipboard, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, "", "request filePath should match"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} + +add_task( + async function testClipboardPasteNoFormattingWithContentAnalysisAllow() { + await testClipboardPasteNoFormatting(true); + } +); + +add_task( + async function testClipboardPasteNoFormattingWithContentAnalysisBlock() { + await testClipboardPasteNoFormatting(false); + } +); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_prompt_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_prompt_content_analysis.js new file mode 100644 index 0000000000..9e57250cc7 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_paste_prompt_content_analysis.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { PromptTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromptTestUtils.sys.mjs" +); + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); +}); + +// Using an external page so the test can checks that the URL matches in the nsIContentAnalysisRequest +const PAGE_URL = + "https://example.com/browser/toolkit/components/contentanalysis/tests/browser/clipboard_paste_prompt.html"; +const CLIPBOARD_TEXT_STRING = "Just some text"; +async function testClipboardPaste(allowPaste) { + mockCA.setupForTest(allowPaste); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + + let promptPromise = SpecialPowers.spawn(browser, [], async () => { + return content.prompt(); + }); + + let prompt = await PromptTestUtils.waitForPrompt(browser, { + modalType: Services.prompt.MODAL_TYPE_CONTENT, + }); + // Paste text into prompt() in content + let pastePromise = new Promise(resolve => { + prompt.ui.loginTextbox.addEventListener( + "paste", + () => { + // Since mockCA uses setTimeout before invoking the callback, + // do it here too + setTimeout(() => { + resolve(); + }, 0); + }, + { once: true } + ); + }); + let ev = new ClipboardEvent("paste", { + dataType: "text/plain", + data: CLIPBOARD_TEXT_STRING, + }); + prompt.ui.loginTextbox.dispatchEvent(ev); + await pastePromise; + + // Close the prompt + await PromptTestUtils.handlePrompt(prompt); + + let result = await promptPromise; + is( + result, + allowPaste ? CLIPBOARD_TEXT_STRING : "", + "prompt has correct value" + ); + is(mockCA.calls.length, 1, "Correct number of calls to Content Analysis"); + assertContentAnalysisRequest(mockCA.calls[0], CLIPBOARD_TEXT_STRING); + + BrowserTestUtils.removeTab(tab); +} + +function assertContentAnalysisRequest(request, expectedText) { + is(request.url.spec, PAGE_URL, "request has correct URL"); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + Ci.nsIContentAnalysisRequest.eClipboard, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, null, "request filePath should match"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} + +add_task(async function testClipboardPasteWithContentAnalysisAllow() { + await testClipboardPaste(true); +}); + +add_task(async function testClipboardPasteWithContentAnalysisBlock() { + await testClipboardPaste(false); +}); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_clipboard_read_async_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_read_async_content_analysis.js new file mode 100644 index 0000000000..7d180a048b --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/browser_clipboard_read_async_content_analysis.js @@ -0,0 +1,195 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +let mockCA = makeMockContentAnalysis(); + +add_setup(async function test_setup() { + mockCA = mockContentAnalysisService(mockCA); + await SpecialPowers.pushPrefEnv({ + set: [ + ["dom.events.asyncClipboard.readText", true], + // This pref turns off the "Paste" popup + ["dom.events.testing.asyncClipboard", true], + ], + }); +}); + +const PAGE_URL = + "https://example.com/browser/toolkit/components/contentanalysis/tests/browser/clipboard_read_async.html"; +const CLIPBOARD_TEXT_STRING = "Some plain text"; +const CLIPBOARD_HTML_STRING = "Some HTML"; +async function testClipboardReadAsync(allowPaste) { + mockCA.setupForTest(allowPaste); + + setClipboardData(); + + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + { + let result = await setDataAndStartTest(browser, allowPaste, "read"); + is(result, true, "Got unexpected result from page for read()"); + + is( + mockCA.calls.length, + 2, + "Correct number of calls to Content Analysis for read()" + ); + // On Windows, widget adds extra data into HTML clipboard. + let expectedHtml = navigator.platform.includes("Win") + ? `\n${CLIPBOARD_HTML_STRING}\n\n` + : CLIPBOARD_HTML_STRING; + + assertContentAnalysisRequest(mockCA.calls[0], expectedHtml); + assertContentAnalysisRequest(mockCA.calls[1], CLIPBOARD_TEXT_STRING); + mockCA.clearCalls(); + } + + { + let result = await setDataAndStartTest(browser, allowPaste, "readText"); + is(result, true, "Got unexpected result from page for readText()"); + + is( + mockCA.calls.length, + 1, + "Correct number of calls to Content Analysis for read()" + ); + assertContentAnalysisRequest(mockCA.calls[0], CLIPBOARD_TEXT_STRING); + mockCA.clearCalls(); + } + + BrowserTestUtils.removeTab(tab); +} + +async function testClipboardReadAsyncWithErrorHelper() { + mockCA.setupForTestWithError(Cr.NS_ERROR_NOT_AVAILABLE); + + setClipboardData(); + + // This test throws a number of exceptions, so tell the framework this is OK. + // If an exception is thrown we won't get the right response from setDataAndStartTest() + // so this should be safe to do. + ignoreAllUncaughtExceptions(); + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL); + let browser = tab.linkedBrowser; + { + let result = await setDataAndStartTest(browser, false, "read", true); + is(result, true, "Got unexpected result from page for read()"); + + is( + mockCA.calls.length, + 2, + "Correct number of calls to Content Analysis for read()" + ); + // On Windows, widget adds extra data into HTML clipboard. + let expectedHtml = navigator.platform.includes("Win") + ? `\n${CLIPBOARD_HTML_STRING}\n\n` + : CLIPBOARD_HTML_STRING; + + assertContentAnalysisRequest(mockCA.calls[0], expectedHtml); + assertContentAnalysisRequest(mockCA.calls[1], CLIPBOARD_TEXT_STRING); + mockCA.clearCalls(); + } + + { + let result = await setDataAndStartTest(browser, false, "readText", true); + is(result, true, "Got unexpected result from page for readText()"); + + is( + mockCA.calls.length, + 1, + "Correct number of calls to Content Analysis for read()" + ); + assertContentAnalysisRequest(mockCA.calls[0], CLIPBOARD_TEXT_STRING); + mockCA.clearCalls(); + } + + BrowserTestUtils.removeTab(tab); +} + +function setDataAndStartTest( + browser, + allowPaste, + testType, + shouldError = false +) { + return SpecialPowers.spawn( + browser, + [allowPaste, testType, shouldError], + (allowPaste, testType, shouldError) => { + return new Promise(resolve => { + content.document.addEventListener( + "testresult", + event => { + resolve(event.detail.result); + }, + { once: true } + ); + content.document.getElementById("pasteAllowed").checked = allowPaste; + content.document.getElementById("contentAnalysisReturnsError").checked = + shouldError; + content.document.dispatchEvent( + new content.CustomEvent("teststart", { + detail: Cu.cloneInto({ testType }, content), + }) + ); + }); + } + ); +} + +function assertContentAnalysisRequest(request, expectedText) { + is(request.url.spec, PAGE_URL, "request has correct URL"); + is( + request.analysisType, + Ci.nsIContentAnalysisRequest.eBulkDataEntry, + "request has correct analysisType" + ); + is( + request.operationTypeForDisplay, + Ci.nsIContentAnalysisRequest.eClipboard, + "request has correct operationTypeForDisplay" + ); + is(request.filePath, "", "request filePath should match"); + is(request.textContent, expectedText, "request textContent should match"); + is(request.printDataHandle, 0, "request printDataHandle should not be 0"); + is(request.printDataSize, 0, "request printDataSize should not be 0"); + ok(!!request.requestToken.length, "request requestToken should not be empty"); +} + +function setClipboardData() { + const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + { + trans.addDataFlavor("text/plain"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = CLIPBOARD_TEXT_STRING; + trans.setTransferData("text/plain", str); + } + { + trans.addDataFlavor("text/html"); + const str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + str.data = CLIPBOARD_HTML_STRING; + trans.setTransferData("text/html", str); + } + + // Write to clipboard. + Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); +} + +add_task(async function testClipboardReadAsyncWithContentAnalysisAllow() { + await testClipboardReadAsync(true); +}); + +add_task(async function testClipboardReadAsyncWithContentAnalysisBlock() { + await testClipboardReadAsync(false); +}); + +add_task(async function testClipboardReadAsyncWithError() { + await testClipboardReadAsyncWithErrorHelper(); +}); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_content_analysis_policies.js b/toolkit/components/contentanalysis/tests/browser/browser_content_analysis_policies.js index b226c0a37a..e7122508e1 100644 --- a/toolkit/components/contentanalysis/tests/browser/browser_content_analysis_policies.js +++ b/toolkit/components/contentanalysis/tests/browser/browser_content_analysis_policies.js @@ -25,7 +25,8 @@ const kAgentNamePref = "agent_name"; const kClientSignaturePref = "client_signature"; const kPerUserPref = "is_per_user"; const kShowBlockedPref = "show_blocked_result"; -const kDefaultAllowPref = "default_allow"; +const kDefaultResultPref = "default_result"; +const kBypassForSameTabOperationsPref = "bypass_for_same_tab_operations"; const ca = Cc["@mozilla.org/contentanalysis;1"].getService( Ci.nsIContentAnalysis @@ -87,7 +88,8 @@ add_task(async function test_ca_enterprise_config() { ClientSignature: string4, IsPerUser: true, ShowBlockedResult: false, - DefaultAllow: true, + DefaultResult: 1, + BypassForSameTabOperations: true, }, }, }); @@ -135,9 +137,16 @@ add_task(async function test_ca_enterprise_config() { "show blocked match" ); is( - Services.prefs.getBoolPref("browser.contentanalysis." + kDefaultAllowPref), + Services.prefs.getIntPref("browser.contentanalysis." + kDefaultResultPref), + 1, + "default result match" + ); + is( + Services.prefs.getBoolPref( + "browser.contentanalysis." + kBypassForSameTabOperationsPref + ), true, - "default allow match" + "bypass for same tab operations match" ); PoliciesPrefTracker.stop(); }); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_print_changing_page_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_print_changing_page_content_analysis.js index 72a7dcbb91..0f2d846627 100644 --- a/toolkit/components/contentanalysis/tests/browser/browser_print_changing_page_content_analysis.js +++ b/toolkit/components/contentanalysis/tests/browser/browser_print_changing_page_content_analysis.js @@ -12,69 +12,7 @@ const PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"].getService( Ci.nsIPrintSettingsService ); -let mockCA = { - isActive: true, - mightBeActive: true, - errorValue: undefined, - - setupForTest(shouldAllowRequest) { - this.shouldAllowRequest = shouldAllowRequest; - this.errorValue = undefined; - this.calls = []; - }, - - setupForTestWithError(errorValue) { - this.errorValue = errorValue; - this.calls = []; - }, - - getAction() { - if (this.shouldAllowRequest === undefined) { - this.shouldAllowRequest = true; - } - return this.shouldAllowRequest - ? Ci.nsIContentAnalysisResponse.eAllow - : Ci.nsIContentAnalysisResponse.eBlock; - }, - - // nsIContentAnalysis methods - async analyzeContentRequest(request, _autoAcknowledge) { - info( - "Mock ContentAnalysis service: analyzeContentRequest, this.shouldAllowRequest=" + - this.shouldAllowRequest + - ", this.errorValue=" + - this.errorValue - ); - this.calls.push(request); - if (this.errorValue) { - throw this.errorValue; - } - // Use setTimeout to simulate an async activity - await new Promise(res => setTimeout(res, 0)); - return makeContentAnalysisResponse(this.getAction(), request.requestToken); - }, - - analyzeContentRequestCallback(request, autoAcknowledge, callback) { - info( - "Mock ContentAnalysis service: analyzeContentRequestCallback, this.shouldAllowRequest=" + - this.shouldAllowRequest + - ", this.errorValue=" + - this.errorValue - ); - this.calls.push(request); - if (this.errorValue) { - throw this.errorValue; - } - let response = makeContentAnalysisResponse( - this.getAction(), - request.requestToken - ); - // Use setTimeout to simulate an async activity - setTimeout(() => { - callback.contentResult(response); - }, 0); - }, -}; +let mockCA = makeMockContentAnalysis(); add_setup(async function test_setup() { mockCA = mockContentAnalysisService(mockCA); diff --git a/toolkit/components/contentanalysis/tests/browser/browser_print_content_analysis.js b/toolkit/components/contentanalysis/tests/browser/browser_print_content_analysis.js index 9b4c0ffa60..05897b5ca6 100644 --- a/toolkit/components/contentanalysis/tests/browser/browser_print_content_analysis.js +++ b/toolkit/components/contentanalysis/tests/browser/browser_print_content_analysis.js @@ -12,73 +12,7 @@ const PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"].getService( Ci.nsIPrintSettingsService ); -let mockCA = { - isActive: true, - mightBeActive: true, - errorValue: undefined, - - setupForTest(shouldAllowRequest) { - this.shouldAllowRequest = shouldAllowRequest; - this.errorValue = undefined; - this.calls = []; - }, - - setupForTestWithError(errorValue) { - this.errorValue = errorValue; - this.calls = []; - }, - - clearCalls() { - this.calls = []; - }, - - getAction() { - if (this.shouldAllowRequest === undefined) { - this.shouldAllowRequest = true; - } - return this.shouldAllowRequest - ? Ci.nsIContentAnalysisResponse.eAllow - : Ci.nsIContentAnalysisResponse.eBlock; - }, - - // nsIContentAnalysis methods - async analyzeContentRequest(request, _autoAcknowledge) { - info( - "Mock ContentAnalysis service: analyzeContentRequest, this.shouldAllowRequest=" + - this.shouldAllowRequest + - ", this.errorValue=" + - this.errorValue - ); - this.calls.push(request); - if (this.errorValue) { - throw this.errorValue; - } - // Use setTimeout to simulate an async activity - await new Promise(res => setTimeout(res, 0)); - return makeContentAnalysisResponse(this.getAction(), request.requestToken); - }, - - analyzeContentRequestCallback(request, autoAcknowledge, callback) { - info( - "Mock ContentAnalysis service: analyzeContentRequestCallback, this.shouldAllowRequest=" + - this.shouldAllowRequest + - ", this.errorValue=" + - this.errorValue - ); - this.calls.push(request); - if (this.errorValue) { - throw this.errorValue; - } - let response = makeContentAnalysisResponse( - this.getAction(), - request.requestToken - ); - // Use setTimeout to simulate an async activity - setTimeout(() => { - callback.contentResult(response); - }, 0); - }, -}; +let mockCA = makeMockContentAnalysis(); add_setup(async function test_setup() { mockCA = mockContentAnalysisService(mockCA); diff --git a/toolkit/components/contentanalysis/tests/browser/clipboard_paste_file.html b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_file.html new file mode 100644 index 0000000000..9604633842 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_file.html @@ -0,0 +1,61 @@ + + + + + + + + diff --git a/toolkit/components/contentanalysis/tests/browser/clipboard_paste_inputandtextarea.html b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_inputandtextarea.html new file mode 100644 index 0000000000..db93e85955 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_inputandtextarea.html @@ -0,0 +1,41 @@ + + + +
+ + + + +
+ + + + diff --git a/toolkit/components/contentanalysis/tests/browser/clipboard_paste_noformatting.html b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_noformatting.html new file mode 100644 index 0000000000..eefc40de85 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_noformatting.html @@ -0,0 +1,46 @@ + + + + + +
Formatted Text
+ + + + diff --git a/toolkit/components/contentanalysis/tests/browser/clipboard_paste_prompt.html b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_prompt.html new file mode 100644 index 0000000000..8017cc87a1 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/clipboard_paste_prompt.html @@ -0,0 +1,7 @@ + + + +
+ + + diff --git a/toolkit/components/contentanalysis/tests/browser/clipboard_read_async.html b/toolkit/components/contentanalysis/tests/browser/clipboard_read_async.html new file mode 100644 index 0000000000..14414a0f28 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/browser/clipboard_read_async.html @@ -0,0 +1,95 @@ + + + + + + + + + + diff --git a/toolkit/components/contentanalysis/tests/browser/head.js b/toolkit/components/contentanalysis/tests/browser/head.js index e645caa2d7..9422a62ff2 100644 --- a/toolkit/components/contentanalysis/tests/browser/head.js +++ b/toolkit/components/contentanalysis/tests/browser/head.js @@ -112,3 +112,127 @@ async function waitForFileToAlmostMatchSize(filePath, expectedSize) { return Math.abs(fileStat.size - expectedSize) <= maxSizeDifference; }, "Sizes should (almost) match"); } + +function makeMockContentAnalysis() { + return { + isActive: true, + mightBeActive: true, + errorValue: undefined, + + setupForTest(shouldAllowRequest) { + this.shouldAllowRequest = shouldAllowRequest; + this.errorValue = undefined; + this.calls = []; + }, + + setupForTestWithError(errorValue) { + this.errorValue = errorValue; + this.calls = []; + }, + + clearCalls() { + this.calls = []; + }, + + getAction() { + if (this.shouldAllowRequest === undefined) { + this.shouldAllowRequest = true; + } + return this.shouldAllowRequest + ? Ci.nsIContentAnalysisResponse.eAllow + : Ci.nsIContentAnalysisResponse.eBlock; + }, + + // nsIContentAnalysis methods + async analyzeContentRequest(request, _autoAcknowledge) { + info( + "Mock ContentAnalysis service: analyzeContentRequest, this.shouldAllowRequest=" + + this.shouldAllowRequest + + ", this.errorValue=" + + this.errorValue + ); + this.calls.push(request); + if (this.errorValue) { + throw this.errorValue; + } + // Use setTimeout to simulate an async activity + await new Promise(res => setTimeout(res, 0)); + return makeContentAnalysisResponse( + this.getAction(), + request.requestToken + ); + }, + + analyzeContentRequestCallback(request, autoAcknowledge, callback) { + info( + "Mock ContentAnalysis service: analyzeContentRequestCallback, this.shouldAllowRequest=" + + this.shouldAllowRequest + + ", this.errorValue=" + + this.errorValue + ); + this.calls.push(request); + if (this.errorValue) { + throw this.errorValue; + } + let response = makeContentAnalysisResponse( + this.getAction(), + request.requestToken + ); + // Use setTimeout to simulate an async activity + setTimeout(() => { + callback.contentResult(response); + }, 0); + }, + }; +} + +function whenTabLoaded(aTab, aCallback) { + promiseTabLoadEvent(aTab).then(aCallback); +} + +function promiseTabLoaded(aTab) { + return new Promise(resolve => { + whenTabLoaded(aTab, resolve); + }); +} + +/** + * Waits for a load (or custom) event to finish in a given tab. If provided + * load an uri into the tab. + * + * @param {object} tab + * The tab to load into. + * @param {string} [url] + * The url to load, or the current url. + * @returns {Promise} resolved when the event is handled. Rejected if + * a valid load event is not received within a meaningful interval + */ +function promiseTabLoadEvent(tab, url) { + info("Wait tab event: load"); + + function handle(loadedUrl) { + if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) { + info(`Skipping spurious load event for ${loadedUrl}`); + return false; + } + + info("Tab event received: load"); + return true; + } + + let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle); + + if (url) { + BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, url); + } + + return loaded; +} + +function promisePopupShown(popup) { + return BrowserTestUtils.waitForPopupEvent(popup, "shown"); +} + +function promisePopupHidden(popup) { + return BrowserTestUtils.waitForPopupEvent(popup, "hidden"); +} diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysis.cpp b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysis.cpp index cd083a7779..d974ac78db 100644 --- a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysis.cpp +++ b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysis.cpp @@ -8,13 +8,25 @@ #include "mozilla/Assertions.h" #include "mozilla/Logging.h" #include "mozilla/Preferences.h" +#include "mozilla/SpinEventLoopUntil.h" +#include "nsComponentManagerUtils.h" #include "nsNetUtil.h" +#include "nsIFile.h" +#include "nsIObserverService.h" +#include "nsIURI.h" +#include "nsIURIMutator.h" #include "ContentAnalysis.h" +#include "SpecialSystemDirectory.h" +#include "TestContentAnalysisUtils.h" #include #include +#include const char* kAllowUrlPref = "browser.contentanalysis.allow_url_regex_list"; const char* kDenyUrlPref = "browser.contentanalysis.deny_url_regex_list"; +const char* kPipePathNamePref = "browser.contentanalysis.pipe_path_name"; +const char* kIsDLPEnabledPref = "browser.contentanalysis.enabled"; +const char* kTimeoutPref = "browser.contentanalysis.agent_timeout"; using namespace mozilla; using namespace mozilla::contentanalysis; @@ -24,6 +36,9 @@ class ContentAnalysisTest : public testing::Test { ContentAnalysisTest() { auto* logmodule = LogModule::Get("contentanalysis"); logmodule->SetLevel(LogLevel::Verbose); + MOZ_ALWAYS_SUCCEEDS( + Preferences::SetString(kPipePathNamePref, mPipeName.get())); + MOZ_ALWAYS_SUCCEEDS(Preferences::SetBool(kIsDLPEnabledPref, true)); nsCOMPtr caSvc = do_GetService("@mozilla.org/contentanalysis;1"); @@ -35,17 +50,39 @@ class ContentAnalysisTest : public testing::Test { mContentAnalysis->mAllowUrlList = {}; mContentAnalysis->mDenyUrlList = {}; + MOZ_ALWAYS_SUCCEEDS(mContentAnalysis->TestOnlySetCACmdLineArg(true)); + MOZ_ALWAYS_SUCCEEDS(Preferences::SetCString(kAllowUrlPref, "")); MOZ_ALWAYS_SUCCEEDS(Preferences::SetCString(kDenyUrlPref, "")); + + bool isActive = false; + MOZ_ALWAYS_SUCCEEDS(mContentAnalysis->GetIsActive(&isActive)); + EXPECT_TRUE(isActive); + } + + // Note that the constructor (and SetUp() method) get called once per test, + // not once for the whole fixture. Because Firefox does not currently + // reconnect to an agent after the DLP pipe is closed (bug 1888293), we only + // want to create the agent once and make sure the same process stays alive + // through all of these tests. + static void SetUpTestSuite() { + GeneratePipeName(L"contentanalysissdk-gtest-", mPipeName); + mAgentInfo = LaunchAgentNormal(L"block", mPipeName); } + static void TearDownTestSuite() { mAgentInfo.TerminateProcess(); } + void TearDown() override { mContentAnalysis->mParsedUrlLists = false; mContentAnalysis->mAllowUrlList = {}; mContentAnalysis->mDenyUrlList = {}; + MOZ_ALWAYS_SUCCEEDS(mContentAnalysis->TestOnlySetCACmdLineArg(false)); + MOZ_ALWAYS_SUCCEEDS(Preferences::SetCString(kAllowUrlPref, "")); MOZ_ALWAYS_SUCCEEDS(Preferences::SetCString(kDenyUrlPref, "")); + MOZ_ALWAYS_SUCCEEDS(Preferences::ClearUser(kPipePathNamePref)); + MOZ_ALWAYS_SUCCEEDS(Preferences::ClearUser(kIsDLPEnabledPref)); } already_AddRefed CreateRequest(const char* aUrl) { @@ -62,6 +99,8 @@ class ContentAnalysisTest : public testing::Test { } RefPtr mContentAnalysis; + static nsString mPipeName; + static MozAgentInfo mAgentInfo; // Proxies for private members of ContentAnalysis. TEST_F // creates new subclasses -- they do not inherit `friend`s. @@ -71,6 +110,8 @@ class ContentAnalysisTest : public testing::Test { return mContentAnalysis->FilterByUrlLists(aReq); } }; +nsString ContentAnalysisTest::mPipeName; +MozAgentInfo ContentAnalysisTest::mAgentInfo; TEST_F(ContentAnalysisTest, AllowUrlList) { MOZ_ALWAYS_SUCCEEDS( @@ -124,3 +165,219 @@ TEST_F(ContentAnalysisTest, DenyOverridesAllowUrlList) { CreateRequest("https://example.org/matchme/"); ASSERT_EQ(FilterByUrlLists(car), UrlFilterResult::eDeny); } + +nsCOMPtr GetExampleDotComURI() { + nsCOMPtr uri; + MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(uri), "https://example.com")); + return uri; +} + +void SendRequestAndExpectResponse( + RefPtr contentAnalysis, + const nsCOMPtr& request, + Maybe expectedShouldAllow, + Maybe expectedAction) { + std::atomic gotResponse = false; + std::atomic timedOut = false; + auto callback = MakeRefPtr( + [&](nsIContentAnalysisResponse* response) { + if (expectedShouldAllow.isSome()) { + bool shouldAllow = false; + MOZ_ALWAYS_SUCCEEDS(response->GetShouldAllowContent(&shouldAllow)); + EXPECT_EQ(*expectedShouldAllow, shouldAllow); + } + if (expectedAction.isSome()) { + nsIContentAnalysisResponse::Action action; + MOZ_ALWAYS_SUCCEEDS(response->GetAction(&action)); + EXPECT_EQ(*expectedAction, action); + } + nsCString requestToken, originalRequestToken; + MOZ_ALWAYS_SUCCEEDS(response->GetRequestToken(requestToken)); + MOZ_ALWAYS_SUCCEEDS(request->GetRequestToken(originalRequestToken)); + EXPECT_EQ(originalRequestToken, requestToken); + gotResponse = true; + }, + [&gotResponse](nsresult error) { + EXPECT_EQ(NS_OK, error); + gotResponse = true; + // Make sure that we didn't somehow get passed NS_OK + FAIL() << "Got error response"; + }); + + MOZ_ALWAYS_SUCCEEDS( + contentAnalysis->AnalyzeContentRequestCallback(request, false, callback)); + RefPtr timer = + NS_NewCancelableRunnableFunction("Content Analysis timeout", [&] { + if (!gotResponse.load()) { + timedOut = true; + } + }); + NS_DelayedDispatchToCurrentThread(do_AddRef(timer), 10000); + mozilla::SpinEventLoopUntil("Waiting for ContentAnalysis result"_ns, [&]() { + return gotResponse.load() || timedOut.load(); + }); + timer->Cancel(); + EXPECT_TRUE(gotResponse); + EXPECT_FALSE(timedOut); +} + +TEST_F(ContentAnalysisTest, SendAllowedTextToAgent_GetAllowedResponse) { + nsCOMPtr uri = GetExampleDotComURI(); + nsString allow(L"allow"); + nsCOMPtr request = new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, std::move(allow), + false, EmptyCString(), uri, + nsIContentAnalysisRequest::OperationType::eClipboard, nullptr); + + SendRequestAndExpectResponse(mContentAnalysis, request, Some(true), + Some(nsIContentAnalysisResponse::eAllow)); +} + +TEST_F(ContentAnalysisTest, SendBlockedTextToAgent_GetBlockResponse) { + nsCOMPtr uri = GetExampleDotComURI(); + nsString block(L"block"); + nsCOMPtr request = new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, std::move(block), + false, EmptyCString(), uri, + nsIContentAnalysisRequest::OperationType::eClipboard, nullptr); + + SendRequestAndExpectResponse(mContentAnalysis, request, Some(false), + Some(nsIContentAnalysisResponse::eBlock)); +} + +class RawRequestObserver final : public nsIObserver { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + RawRequestObserver() {} + + const std::vector& + GetRequests() { + return mRequests; + } + + private: + ~RawRequestObserver() = default; + std::vector mRequests; +}; + +NS_IMPL_ISUPPORTS(RawRequestObserver, nsIObserver); + +NS_IMETHODIMP RawRequestObserver::Observe(nsISupports* aSubject, + const char* aTopic, + const char16_t* aData) { + std::wstring dataWideString(reinterpret_cast(aData)); + std::vector dataVector(dataWideString.size()); + for (size_t i = 0; i < dataWideString.size(); ++i) { + // Since this data is really bytes and not a null-terminated string, the + // calling code adds 0xFF00 to every member to ensure there are no 0 values. + dataVector[i] = static_cast(dataWideString[i] - 0xFF00); + } + content_analysis::sdk::ContentAnalysisRequest request; + EXPECT_TRUE(request.ParseFromArray(dataVector.data(), dataVector.size())); + mRequests.push_back(std::move(request)); + return NS_OK; +} + +TEST_F(ContentAnalysisTest, CheckRawRequestWithText) { + MOZ_ALWAYS_SUCCEEDS(Preferences::SetInt(kTimeoutPref, 65)); + nsCOMPtr uri = GetExampleDotComURI(); + nsString allow(L"allow"); + nsCOMPtr request = new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, std::move(allow), + false, EmptyCString(), uri, + nsIContentAnalysisRequest::OperationType::eClipboard, nullptr); + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + auto rawRequestObserver = MakeRefPtr(); + MOZ_ALWAYS_SUCCEEDS( + obsServ->AddObserver(rawRequestObserver, "dlp-request-sent-raw", false)); + time_t now = time(nullptr); + + SendRequestAndExpectResponse(mContentAnalysis, request, Nothing(), Nothing()); + auto requests = rawRequestObserver->GetRequests(); + EXPECT_EQ(static_cast(1), requests.size()); + time_t t = requests[0].expires_at(); + time_t secs_remaining = t - now; + // There should be around 65 seconds remaining + EXPECT_LE(abs(secs_remaining - 65), 2); + const auto& request_url = requests[0].request_data().url(); + EXPECT_EQ(uri->GetSpecOrDefault(), + nsCString(request_url.data(), request_url.size())); + nsCString request_user_action_id(requests[0].user_action_id().data(), + requests[0].user_action_id().size()); + // The user_action_id has a GUID appended to the end, just make sure the + // beginning is right. + request_user_action_id.Truncate(8); + EXPECT_EQ(nsCString("Firefox "), request_user_action_id); + const auto& request_text = requests[0].text_content(); + EXPECT_EQ(nsCString("allow"), + nsCString(request_text.data(), request_text.size())); + + MOZ_ALWAYS_SUCCEEDS( + obsServ->RemoveObserver(rawRequestObserver, "dlp-request-sent-raw")); + MOZ_ALWAYS_SUCCEEDS(Preferences::ClearUser(kTimeoutPref)); +} + +TEST_F(ContentAnalysisTest, CheckRawRequestWithFile) { + nsCOMPtr uri = GetExampleDotComURI(); + nsCOMPtr file; + MOZ_ALWAYS_SUCCEEDS(GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, + getter_AddRefs(file))); + nsString allowRelativePath(L"allowedFile.txt"); + MOZ_ALWAYS_SUCCEEDS(file->AppendRelativePath(allowRelativePath)); + nsString allowPath; + MOZ_ALWAYS_SUCCEEDS(file->GetPath(allowPath)); + + nsCOMPtr request = new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, allowPath, true, + EmptyCString(), uri, nsIContentAnalysisRequest::OperationType::eClipboard, + nullptr); + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + auto rawRequestObserver = MakeRefPtr(); + MOZ_ALWAYS_SUCCEEDS( + obsServ->AddObserver(rawRequestObserver, "dlp-request-sent-raw", false)); + + SendRequestAndExpectResponse(mContentAnalysis, request, Nothing(), Nothing()); + auto requests = rawRequestObserver->GetRequests(); + EXPECT_EQ(static_cast(1), requests.size()); + const auto& request_url = requests[0].request_data().url(); + EXPECT_EQ(uri->GetSpecOrDefault(), + nsCString(request_url.data(), request_url.size())); + nsCString request_user_action_id(requests[0].user_action_id().data(), + requests[0].user_action_id().size()); + // The user_action_id has a GUID appended to the end, just make sure the + // beginning is right. + request_user_action_id.Truncate(8); + EXPECT_EQ(nsCString("Firefox "), request_user_action_id); + const auto& request_file_path = requests[0].file_path(); + EXPECT_EQ(NS_ConvertUTF16toUTF8(allowPath), + nsCString(request_file_path.data(), request_file_path.size())); + + MOZ_ALWAYS_SUCCEEDS( + obsServ->RemoveObserver(rawRequestObserver, "dlp-request-sent-raw")); +} + +TEST_F(ContentAnalysisTest, CheckTwoRequestsHaveSameUserActionId) { + nsCOMPtr uri = GetExampleDotComURI(); + nsString allow(L"allow"); + nsCOMPtr request = new ContentAnalysisRequest( + nsIContentAnalysisRequest::AnalysisType::eBulkDataEntry, std::move(allow), + false, EmptyCString(), uri, + nsIContentAnalysisRequest::OperationType::eClipboard, nullptr); + nsCOMPtr obsServ = + mozilla::services::GetObserverService(); + auto rawRequestObserver = MakeRefPtr(); + MOZ_ALWAYS_SUCCEEDS( + obsServ->AddObserver(rawRequestObserver, "dlp-request-sent-raw", false)); + + SendRequestAndExpectResponse(mContentAnalysis, request, Nothing(), Nothing()); + SendRequestAndExpectResponse(mContentAnalysis, request, Nothing(), Nothing()); + auto requests = rawRequestObserver->GetRequests(); + EXPECT_EQ(static_cast(2), requests.size()); + EXPECT_EQ(requests[0].user_action_id(), requests[1].user_action_id()); + + MOZ_ALWAYS_SUCCEEDS( + obsServ->RemoveObserver(rawRequestObserver, "dlp-request-sent-raw")); +} diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.cpp b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.cpp index 5b2b76b963..d7a41cc5ff 100644 --- a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.cpp +++ b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.cpp @@ -8,29 +8,12 @@ #include "mozilla/Assertions.h" #include "mozilla/CmdLineAndEnvUtils.h" #include "content_analysis/sdk/analysis_client.h" -#include "TestContentAnalysisAgent.h" +#include "TestContentAnalysisUtils.h" #include #include using namespace content_analysis::sdk; -MozAgentInfo LaunchAgentNormal(const wchar_t* aToBlock) { - nsString cmdLineArguments; - if (aToBlock && aToBlock[0] != 0) { - cmdLineArguments.Append(L" --toblock=.*"); - cmdLineArguments.Append(aToBlock); - cmdLineArguments.Append(L".*"); - } - cmdLineArguments.Append(L" --user"); - cmdLineArguments.Append(L" --path="); - nsString pipeName; - GeneratePipeName(L"contentanalysissdk-gtest-", pipeName); - cmdLineArguments.Append(pipeName); - MozAgentInfo agentInfo; - LaunchAgentWithCommandLineArguments(cmdLineArguments, pipeName, agentInfo); - return agentInfo; -} - TEST(ContentAnalysisAgent, TextShouldNotBeBlocked) { auto MozAgentInfo = LaunchAgentNormal(L"block"); @@ -49,10 +32,7 @@ TEST(ContentAnalysisAgent, TextShouldNotBeBlocked) response.results().Get(0).status()); ASSERT_EQ(0, response.results().Get(0).triggered_rules_size()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisAgent, TextShouldBeBlocked) @@ -75,10 +55,7 @@ TEST(ContentAnalysisAgent, TextShouldBeBlocked) ASSERT_EQ(ContentAnalysisResponse_Result_TriggeredRule_Action_BLOCK, response.results().Get(0).triggered_rules(0).action()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisAgent, FileShouldNotBeBlocked) @@ -99,10 +76,7 @@ TEST(ContentAnalysisAgent, FileShouldNotBeBlocked) response.results().Get(0).status()); ASSERT_EQ(0, response.results().Get(0).triggered_rules_size()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisAgent, FileShouldBeBlocked) @@ -125,8 +99,5 @@ TEST(ContentAnalysisAgent, FileShouldBeBlocked) ASSERT_EQ(ContentAnalysisResponse_Result_TriggeredRule_Action_BLOCK, response.results().Get(0).triggered_rules(0).action()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.h b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.h deleted file mode 100644 index 9e31036262..0000000000 --- a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisAgent.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef mozilla_testcontentanalysis_h -#define mozilla_testcontentanalysis_h - -#include - -#include "content_analysis/sdk/analysis_client.h" -#include "gtest/gtest.h" -#include "nsString.h" - -struct MozAgentInfo { - PROCESS_INFORMATION processInfo; - std::unique_ptr client; -}; - -void GeneratePipeName(const wchar_t* prefix, nsString& pipeName); -void LaunchAgentWithCommandLineArguments(const nsString& cmdLineArguments, - const nsString& pipeName, - MozAgentInfo& agentInfo); -#endif diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisMisbehaving.cpp b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisMisbehaving.cpp index 7c944ed6e3..a120a82f7c 100644 --- a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisMisbehaving.cpp +++ b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisMisbehaving.cpp @@ -8,7 +8,7 @@ #include "mozilla/Assertions.h" #include "mozilla/CmdLineAndEnvUtils.h" #include "content_analysis/sdk/analysis_client.h" -#include "TestContentAnalysisAgent.h" +#include "TestContentAnalysisUtils.h" #include #include #include @@ -70,10 +70,7 @@ TEST(ContentAnalysisMisbehaving, InvalidUtf8StringStartByteIsContinuationByte) // or invalid memory access or something. ASSERT_STREQ("\x80\x41\x41\x41", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, @@ -95,10 +92,7 @@ TEST(ContentAnalysisMisbehaving, // or invalid memory access or something. ASSERT_STREQ("\x41\xf0\x90\x8d", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, InvalidUtf8StringMultibyteSequenceTooShort) @@ -119,10 +113,7 @@ TEST(ContentAnalysisMisbehaving, InvalidUtf8StringMultibyteSequenceTooShort) // or invalid memory access or something. ASSERT_STREQ("\xf0\x90\x8d\x41", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, InvalidUtf8StringDecodesToInvalidCodePoint) @@ -143,10 +134,7 @@ TEST(ContentAnalysisMisbehaving, InvalidUtf8StringDecodesToInvalidCodePoint) // or invalid memory access or something. ASSERT_STREQ("\xf7\xbf\xbf\xbf", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, InvalidUtf8StringOverlongEncoding) @@ -167,10 +155,7 @@ TEST(ContentAnalysisMisbehaving, InvalidUtf8StringOverlongEncoding) // or invalid memory access or something. ASSERT_STREQ("\xf0\x82\x82\xac", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, StringWithEmbeddedNull) @@ -188,10 +173,7 @@ TEST(ContentAnalysisMisbehaving, StringWithEmbeddedNull) std::string expected("\x41\x00\x41"); ASSERT_EQ(expected, response.request_token()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, ZeroResults) @@ -208,10 +190,7 @@ TEST(ContentAnalysisMisbehaving, ZeroResults) ASSERT_EQ(0, MozAgentInfo.client->Send(request, &response)); ASSERT_EQ(0, response.results().size()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, ResultWithInvalidStatus) @@ -232,10 +211,7 @@ TEST(ContentAnalysisMisbehaving, ResultWithInvalidStatus) // just make sure we can get the value without throwing ASSERT_GE(static_cast(response.results(0).status()), 0); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfString) @@ -252,10 +228,7 @@ TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfString) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithInvalidWireType) @@ -271,10 +244,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithInvalidWireType) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithUnusedFieldNumber) @@ -292,10 +262,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithUnusedFieldNumber) // just make sure we can get a value without throwing ASSERT_STREQ("", response.request_token().c_str()); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithWrongStringWireType) @@ -311,10 +278,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithWrongStringWireType) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithZeroTag) @@ -330,10 +294,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithZeroTag) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithZeroFieldButNonzeroWireType) @@ -350,10 +311,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithZeroFieldButNonzeroWireType) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageWithGroupEnd) @@ -370,10 +328,7 @@ TEST(ContentAnalysisMisbehaving, MessageWithGroupEnd) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfVarint) @@ -390,10 +345,7 @@ TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfVarint) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfTag) @@ -409,8 +361,5 @@ TEST(ContentAnalysisMisbehaving, MessageTruncatedInMiddleOfTag) // The response is an invalid serialization of protobuf, so this should fail ASSERT_EQ(-1, MozAgentInfo.client->Send(request, &response)); - BOOL terminateResult = - ::TerminateProcess(MozAgentInfo.processInfo.hProcess, 0); - ASSERT_NE(FALSE, terminateResult) - << "Failed to terminate content_analysis_sdk_agent process"; + MozAgentInfo.TerminateProcess(); } diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.cpp b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.cpp index 0e14de6b81..8bcfe018ee 100644 --- a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.cpp +++ b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.cpp @@ -3,13 +3,35 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "TestContentAnalysisAgent.h" +#include "TestContentAnalysisUtils.h" #include #include #include #include #include +MozAgentInfo LaunchAgentNormal(const wchar_t* aToBlock) { + nsString pipeName; + GeneratePipeName(L"contentanalysissdk-gtest-", pipeName); + return LaunchAgentNormal(aToBlock, pipeName); +} + +MozAgentInfo LaunchAgentNormal(const wchar_t* aToBlock, + const nsString& pipeName) { + nsString cmdLineArguments; + if (aToBlock && aToBlock[0] != 0) { + cmdLineArguments.Append(L" --toblock=.*"); + cmdLineArguments.Append(aToBlock); + cmdLineArguments.Append(L".*"); + } + cmdLineArguments.Append(L" --user"); + cmdLineArguments.Append(L" --path="); + cmdLineArguments.Append(pipeName); + MozAgentInfo agentInfo; + LaunchAgentWithCommandLineArguments(cmdLineArguments, pipeName, agentInfo); + return agentInfo; +} + void GeneratePipeName(const wchar_t* prefix, nsString& pipeName) { pipeName = u""_ns; pipeName.Append(prefix); diff --git a/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.h b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.h new file mode 100644 index 0000000000..fd437de3f7 --- /dev/null +++ b/toolkit/components/contentanalysis/tests/gtest/TestContentAnalysisUtils.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef mozilla_testcontentanalysis_h +#define mozilla_testcontentanalysis_h + +#include + +#include "content_analysis/sdk/analysis_client.h" +#include "gtest/gtest.h" +#include "nsString.h" + +struct MozAgentInfo { + PROCESS_INFORMATION processInfo; + std::unique_ptr client; + void TerminateProcess() { + BOOL terminateResult = ::TerminateProcess(processInfo.hProcess, 0); + ASSERT_NE(FALSE, terminateResult) + << "Failed to terminate content_analysis_sdk_agent process"; + } +}; + +void GeneratePipeName(const wchar_t* prefix, nsString& pipeName); +void LaunchAgentWithCommandLineArguments(const nsString& cmdLineArguments, + const nsString& pipeName, + MozAgentInfo& agentInfo); +MozAgentInfo LaunchAgentNormal(const wchar_t* aToBlock); +MozAgentInfo LaunchAgentNormal(const wchar_t* aToBlock, + const nsString& pipeName); +#endif diff --git a/toolkit/components/contentrelevancy/ContentRelevancyManager.sys.mjs b/toolkit/components/contentrelevancy/ContentRelevancyManager.sys.mjs index ea3f2a78a2..aec1ba30db 100644 --- a/toolkit/components/contentrelevancy/ContentRelevancyManager.sys.mjs +++ b/toolkit/components/contentrelevancy/ContentRelevancyManager.sys.mjs @@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, { "resource://gre/modules/contentrelevancy/private/InputUtils.sys.mjs", NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", RelevancyStore: "resource://gre/modules/RustRelevancy.sys.mjs", + InterestVector: "resource://gre/modules/RustRelevancy.sys.mjs", }); XPCOMUtils.defineLazyServiceGetter( @@ -40,6 +41,7 @@ const NIMBUS_VARIABLE_ENABLED = "enabled"; const NIMBUS_VARIABLE_MAX_INPUT_URLS = "maxInputUrls"; const NIMBUS_VARIABLE_MIN_INPUT_URLS = "minInputUrls"; const NIMBUS_VARIABLE_TIMER_INTERVAL = "timerInterval"; +const NIMBUS_VARIABLE_INGEST_ENABLED = "ingestEnabled"; ChromeUtils.defineLazyGetter(lazy, "log", () => { return console.createInstance({ @@ -66,7 +68,7 @@ class RelevancyManager { * Note that this should be called once only. `#enable` and `#disable` can be * used to toggle the feature once the manager is initialized. */ - async init() { + init() { if (this.initialized) { return; } @@ -74,7 +76,7 @@ class RelevancyManager { lazy.log.info("Initializing the manager"); if (this.shouldEnable) { - await this.#enable(); + this.#enable(); } this._nimbusUpdateCallback = this.#onNimbusUpdate.bind(this); @@ -143,14 +145,14 @@ class RelevancyManager { ); } - async #enable() { + #enable() { if (!this.#_store) { // Init the relevancy store. const path = this.#storePath; lazy.log.info(`Initializing RelevancyStore: ${path}`); try { - this.#_store = await lazy.RelevancyStore.init(path); + this.#_store = lazy.RelevancyStore.init(path); } catch (error) { lazy.log.error(`Error initializing RelevancyStore: ${error}`); return; @@ -166,13 +168,16 @@ class RelevancyManager { * called. */ #disable() { - this.#_store = null; + if (this._isStoreReady) { + this.#_store.close(); + this.#_store = null; + } lazy.timerManager.unregisterTimer(TIMER_ID); } - async #toggleFeature() { + #toggleFeature() { if (this.shouldEnable) { - await this.#enable(); + this.#enable(); } else { this.#disable(); } @@ -199,8 +204,11 @@ class RelevancyManager { * * The classification will not be performed if the total number of input URLs * is less than `DEFAULT_MIN_URLS` (or the corresponding Nimbus value). + * + * @param {object} options + * options.minUrlsForTest {number} A minimal URL count used only for testing. */ - async #doClassification() { + async #doClassification(options = {}) { if (this.isInProgress) { lazy.log.info( "Another classification is in progress, aborting interest classification" @@ -212,6 +220,8 @@ class RelevancyManager { // exit points & success. this.#isInProgress = true; + let timerId; + try { lazy.log.info("Fetching input data for interest classification"); @@ -222,21 +232,47 @@ class RelevancyManager { const minUrls = lazy.NimbusFeatures.contentRelevancy.getVariable( NIMBUS_VARIABLE_MIN_INPUT_URLS - ) ?? DEFAULT_MIN_URLS; + ) ?? + options.minUrlsForTest ?? + DEFAULT_MIN_URLS; const urls = await lazy.getFrecentRecentCombinedUrls(maxUrls); if (urls.length < minUrls) { lazy.log.info("Aborting interest classification: insufficient input"); + Glean.relevancyClassify.fail.record({ reason: "insufficient-input" }); return; } lazy.log.info("Starting interest classification"); - await this.#doClassificationHelper(urls); + timerId = Glean.relevancyClassify.duration.start(); + + const interestVector = await this.#doClassificationHelper(urls); + const sortedVector = Object.entries(interestVector).sort( + ([, a], [, b]) => b - a // descending + ); + lazy.log.info(`Classification results: ${JSON.stringify(sortedVector)}`); + + Glean.relevancyClassify.duration.stopAndAccumulate(timerId); + Glean.relevancyClassify.succeed.record({ + input_size: urls.length, + input_classified_size: sortedVector.reduce((acc, [, v]) => acc + v, 0), + input_inconclusive_size: interestVector.inconclusive, + output_interest_size: sortedVector.filter(([, v]) => v != 0).length, + interest_top_1_hits: sortedVector[0][1], + interest_top_2_hits: sortedVector[1][1], + interest_top_3_hits: sortedVector[2][1], + }); } catch (error) { + let reason; + if (error instanceof StoreNotAvailableError) { lazy.log.error("#store became null, aborting interest classification"); + reason = "store-not-ready"; } else { lazy.log.error("Classification error: " + (error.reason ?? error)); + reason = "component-errors"; } + Glean.relevancyClassify.fail.record({ reason }); + Glean.relevancyClassify.duration.cancel(timerId); // No error is recorded if `start` was not called. } finally { this.#isInProgress = false; } @@ -244,6 +280,13 @@ class RelevancyManager { lazy.log.info("Finished interest classification"); } + /** + * Exposed for testing. + */ + async _test_doClassification(options = {}) { + await this.#doClassification(options); + } + /** * Classification helper. Use the getter `this.#store` rather than `#_store` * to access the store so that when it becomes null, a `StoreNotAvailableError` @@ -252,28 +295,48 @@ class RelevancyManager { * * @param {Array} urls * An array of URLs. + * @returns {InterestVector} + * An interest vector. * @throws {StoreNotAvailableError} * Thrown when the store became unavailable (i.e. set to null elsewhere). * @throws {RelevancyAPIError} * Thrown for other API errors on the store. */ async #doClassificationHelper(urls) { - // The following logs are unnecessary, only used to suppress the linting error. - // TODO(nanj): delete me once the following TODO is done. - if (!this.#store) { - lazy.log.error("#store became null, aborting interest classification"); - } lazy.log.info("Classification input: " + urls); - // TODO(nanj): uncomment the following once `ingest()` is implemented. - // await this.#store.ingest(urls); - } + let interestVector = new lazy.InterestVector({ + animals: 0, + arts: 0, + autos: 0, + business: 0, + career: 0, + education: 0, + fashion: 0, + finance: 0, + food: 0, + government: 0, + hobbies: 0, + home: 0, + news: 0, + realEstate: 0, + society: 0, + sports: 0, + tech: 0, + travel: 0, + inconclusive: 0, + }); + + if ( + lazy.NimbusFeatures.contentRelevancy.getVariable( + NIMBUS_VARIABLE_INGEST_ENABLED + ) ?? + false + ) { + interestVector = await this.#store.ingest(urls); + } - /** - * Exposed for testing. - */ - async _test_doClassification(urls) { - await this.#doClassificationHelper(urls); + return interestVector; } /** diff --git a/toolkit/components/contentrelevancy/docs/index.md b/toolkit/components/contentrelevancy/docs/index.md index bd377d68dc..e7f6802495 100644 --- a/toolkit/components/contentrelevancy/docs/index.md +++ b/toolkit/components/contentrelevancy/docs/index.md @@ -1,3 +1,120 @@ # Content Relevancy -This is the home for the project: Interest-based Content Relevance Ranking & Personalization for Firefox, a client-based privacy preserving approach to enhancing content experience of Firefox. +This is the home for the project: Interest-based Content Relevance Ranking & Personalization for Firefox, +a client-based privacy preserving approach to enhancing content experience of Firefox. + +```{toctree} +:titlesonly: +:maxdepth: 1 +:glob: + +telemetry.md +``` + +## Overview + +The following diagram illustrates the system overview of the component. +The system consists of three main parts: the relevancy manager, the relevancy store, +and the internal & external data sources. +The cross-platform component [`relevancy`][relevancy-component] serves as the backbone +that is responsible for interest classification, persistence, and ranking. + +```{mermaid} +graph TB +subgraph Firefox + direction LR + subgraph rmgr[Relevancy Manager] + subgraph rcmp[Rust Component] + classify[Perform Interest Classification] + manage[Manage] + query[Query & Rank] + end + iic[Initiate Interest Classification] + rtuc[Respond to User Commands] + irt[Input Retriever] + end + + subgraph places[Places] + direction TB + tfv[(Top Frecent Visits)] + mrv[(Most Recent Visits)] + others[(Other Inputs)] + end + + subgraph rstore[Relevancy Store] + direction TB + iui[Inferred User Interests] + icm[Ingested Classifier Metadata] + end +end + +subgraph settings[Remote Settings] + rs[("content-relevancy")] +end + +iic --> |call| classify +classify --> |write| rstore +query --> |"query (read-only)"| rstore +manage --> |update| rstore +places --> |input| irt --> iic +rs --- |fetch
classification
data| classify +rtuc --> |call| manage +``` + +### Relevancy Manager + +The relevancy manager manages the following tasks for the relevancy component: +- Start a browser update timer to periodically perform interest classifications +- Listen and respond to user commands such as enable / disable the component, + update / reset the relevancy store upon Places changes, etc. +- Nimbus integration +- Telemetry + +The interest classification is fulfilled by the `relevancy` Rust component. +The `relevancy` component downloads & ingests interest data (e.g. "small classifiers") +from Remote Settings and then applies those classifiers to the chosen inputs. +Classification results are persisted in the relevancy store for future uses. + +### Relevancy Store + +The relevancy store, an SQLite database, serves as the storage for both +the user interests and the ingested classifier metadata. It's managed by the +`relevancy` Rust component, which provides consumers (e.g. the relevancy manager) +with a series of APIs for ingestion, querying, ranking, and updating. + +### Data Sources + +Interest classification relies on various internal & external data sources to function. +- Interest classifiers and metadata are prepared offline and served through + Remote Settings. The download and ingestion are handled by the Rust component +- Classification inputs (e.g. top frecent visits and most recent visits) are retrieved + from Places. An input utility module is provided to facilitate the input retrieval + +## Working on the Code + +### Component Structure + +- `ContentRelevancyManager.sys.mjs` implements the relevancy manager. A singleton + relevancy manager is initialized as a background task in `BrowserGlue.sys.mjs` +- Modules defined in `private` should be treated as internal artifacts for the + component and should not be consumed by other browser components. + `InputUtils.sys.mjs` defines several utility functions for input retrieval + +### Telemetry + +Please reference the [telemetry](./telemetry.md) section. + +### Testing + +Since the component is relatively small and does not have any user facing interfaces, +XPCShell tests are recommended for general testing. Mochitests can be used if you're +testing functionalities that would require a more complete browser environment. Only +the Nimbus tests are written as Mochitests at the moment. + +Notes: +- The component requires a browser profile for both Places and the relevancy store, + `do_get_profile()` is called in `head.js` +- Most XPCShell tests are skipped for Android as some test dependencies (`PlacesTestUtils`) + are not available on Android + +[relevancy-component]: https://github.com/mozilla/application-services/tree/main/components/relevancy diff --git a/toolkit/components/contentrelevancy/docs/telemetry.md b/toolkit/components/contentrelevancy/docs/telemetry.md new file mode 100644 index 0000000000..90baa28cae --- /dev/null +++ b/toolkit/components/contentrelevancy/docs/telemetry.md @@ -0,0 +1,62 @@ +# Telemetry + +This document serves as a complementary doc for all the telemetry we collect for `contentrelevancy`. +Note that we use FoG ([Firefox on Glean][FoG]) to record telemetry, +all the metrics described below follow the standard Glean metric types. +You can reference `metrics.yaml` or [Glean Dictionary][glean-dictionary] for more details for each metric. + +## Classification Metrics - `relevancyClassify` + +When the `contentrelevancy` feature is enabled, it will periodically perform classifications in the background. +The following metrics will be recorded for each classification. + +### Events + +#### `succeed` + +This is recorded when a classification is successfully performed. +Various counters are recorded in the `extra_keys` to measure the classification results. + +Example: + +``` +"extra_keys": { + "input_size": 100, // The input size was 100 items + "input_classified_size": 50, // 50 items (out of 100) were classified with at least one conclusive interest + "input_inconclusive_size": 10, // 10 items were classified with the inconclusive interest + "output_interest_size": 4 // The total number of unique interests classified + "interest_top_1_hits": 20, // 20 items were classified with the interest with the most hits + "interest_top_2_hits": 15, // 15 items were classified with the interest with the 2nd most hits + "interest_top_3_hits": 10, // 10 items were classified with the interest with the 3rd most hits +} +``` + +#### `fail` + +This is recorded when a classification is failed or aborted. +The `reason` of the failure is recorded in the `extra_keys`. + +``` +"extra_keys": { + "reason": "insufficient-input" // The classification was aborted due to insufficient input. + // `store-not-ready` indicates the store is null. + // `component-errors` indicates an error in the Rust component. +} +``` + +### Timing Distribution + +#### `duration` + +This records the time duration (in milliseconds) of a successful classification. +The durations of unsuccessful classifications are not measured. + +## Changelog + +### 2024-04 + +* [Bug 1889404][bug-1889404]: Added basic metrics for relevancy manager + +[FoG]: https://firefox-source-docs.mozilla.org/toolkit/components/glean/index.html +[glean-dictionary]: https://dictionary.telemetry.mozilla.org/ +[bug-1889404]: https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 diff --git a/toolkit/components/contentrelevancy/metrics.yaml b/toolkit/components/contentrelevancy/metrics.yaml new file mode 100644 index 0000000000..a17e40bab4 --- /dev/null +++ b/toolkit/components/contentrelevancy/metrics.yaml @@ -0,0 +1,103 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Adding a new metric? We have docs for that! +# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 +$tags: + - "Application Services :: Relevancy" + +relevancy.classify: + succeed: + type: event + description: > + Record an event of a successful user interest classification. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_sensitivity: + - interaction + notification_emails: + - disco-team@mozilla.com + - najiang@mozilla.com + expires: never + extra_keys: + input_size: + description: > + The total number of input elements used for classification. + type: quantity + input_classified_size: + description: > + The total number of input elements classified with at least one conclusive interest. + type: quantity + input_inconclusive_size: + description: > + The total number of input elements classified with the inconclusive interest. + type: quantity + output_interest_size: + description: > + The total number of output interests for classification. + type: quantity + interest_top_1_hits: + description: > + The total number of input elements for the interest with the most hits. + Defaults to 0. This, along with `input_size` and `input_classified_size`, + can be used to calculate the top-N classification percentages and top-N + hit percentages. + type: quantity + interest_top_2_hits: + description: > + The total number of input elements for the interest with the 2nd most hits. + Defaults to 0. This, along with `input_size` and `input_classified_size`, + can be used to calculate the top-N classification percentages and top-N + hit percentages. + type: quantity + interest_top_3_hits: + description: > + The total number of input elements for the interest with the 3rd most hits. + Defaults to 0. This, along with `input_size` and `input_classified_size`, + can be used to calculate the top-N classification percentages and top-N + hit percentages. + type: quantity + fail: + type: event + description: > + Record an event of a failed / aborted user interest classification. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_sensitivity: + - interaction + notification_emails: + - disco-team@mozilla.com + - najiang@mozilla.com + expires: never + extra_keys: + reason: + description: > + The reason of the failed / aborted classification. + One of + * `insufficient-input` + * `component-errors` + * `store-not-ready` + type: string + duration: + type: timing_distribution + time_unit: millisecond + description: > + Record the duration (in ms) of a successful classification. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1889404 + data_sensitivity: + - interaction + notification_emails: + - disco-team@mozilla.com + - najiang@mozilla.com + expires: never diff --git a/toolkit/components/contentrelevancy/tests/browser/browser.toml b/toolkit/components/contentrelevancy/tests/browser/browser.toml index ec1d3a3e66..8de1bd7c46 100644 --- a/toolkit/components/contentrelevancy/tests/browser/browser.toml +++ b/toolkit/components/contentrelevancy/tests/browser/browser.toml @@ -4,3 +4,4 @@ prefs = [ ] ["browser_contentrelevancy_nimbus.js"] +lineno = "6" diff --git a/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js b/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js index 47d54c2a87..5147b3792f 100644 --- a/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js +++ b/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js @@ -41,6 +41,7 @@ add_task(async function test_NimbusIntegration_enable() { maxInputUrls: 3, // Set the timer interval to 0 will trigger the timer right away. timerInterval: 0, + ingestEnabled: false, }, }); @@ -73,6 +74,7 @@ add_task(async function test_NimbusIntegration_disable() { maxInputUrls: 3, // Set the timer interval to 0 will trigger the timer right away. timerInterval: 0, + ingestEnabled: false, }, }); diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js b/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js index 633f9fc49b..7f89c7d615 100644 --- a/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js +++ b/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js @@ -23,11 +23,11 @@ const CATEGORY_UPDATE_TIMER = "update-timer"; let gSandbox; -add_setup(async () => { +add_setup(() => { gSandbox = sinon.createSandbox(); initUpdateTimerManager(); Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true); - await ContentRelevancyManager.init(); + ContentRelevancyManager.init(); registerCleanupFunction(() => { Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED); @@ -35,11 +35,11 @@ add_setup(async () => { }); }); -add_task(async function test_init() { +add_task(function test_init() { Assert.ok(ContentRelevancyManager.initialized, "Init should succeed"); }); -add_task(async function test_uninit() { +add_task(function test_uninit() { ContentRelevancyManager.uninit(); Assert.ok(!ContentRelevancyManager.initialized, "Uninit should succeed"); @@ -50,7 +50,7 @@ add_task(async function test_timer() { Services.prefs.setIntPref(PREF_TIMER_INTERVAL, 0); gSandbox.spy(ContentRelevancyManager, "notify"); - await ContentRelevancyManager.init(); + ContentRelevancyManager.init(); await TestUtils.waitForCondition( () => ContentRelevancyManager.notify.called, @@ -100,24 +100,6 @@ add_task(async function test_call_disable_twice() { Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED); }); -add_task(async function test_doClassification() { - Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true); - await TestUtils.waitForCondition(() => ContentRelevancyManager._isStoreReady); - await ContentRelevancyManager._test_doClassification([]); - - // Disable it to reset the store. - Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, false); - await TestUtils.waitForTick(); - - await Assert.rejects( - ContentRelevancyManager._test_doClassification([]), - /Store is not available/, - "Should throw with an unset store" - ); - - Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED); -}); - /** * Sets up the update timer manager for testing: makes it fire more often, * removes all existing timers, and initializes it for testing. The body of this diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js b/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js new file mode 100644 index 0000000000..9deef6bad5 --- /dev/null +++ b/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { ContentRelevancyManager } = ChromeUtils.importESModule( + "resource://gre/modules/ContentRelevancyManager.sys.mjs" +); + +const PREF_CONTENT_RELEVANCY_ENABLED = "toolkit.contentRelevancy.enabled"; + +add_setup(async function setup() { + // FOG needs a profile directory to put its data in. + do_get_profile(); + + // FOG needs to be initialized in order for data to flow. + Services.fog.initializeFOG(); + + Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true); + ContentRelevancyManager.init(); + + registerCleanupFunction(() => { + Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED); + }); +}); + +/** + * Test classification metrics - succeed. + */ +add_task(async function test_classify_succeed() { + Services.fog.testResetFOG(); + + Assert.equal(null, Glean.relevancyClassify.succeed.testGetValue()); + Assert.equal(null, Glean.relevancyClassify.duration.testGetValue()); + + await ContentRelevancyManager._test_doClassification(); + + Assert.deepEqual( + { + input_size: 0, + input_classified_size: 0, + input_inconclusive_size: 0, + output_interest_size: 0, + interest_top_1_hits: 0, + interest_top_2_hits: 0, + interest_top_3_hits: 0, + }, + Glean.relevancyClassify.succeed.testGetValue()[0].extra, + "Should record the succeed event" + ); + Assert.ok( + Glean.relevancyClassify.duration.testGetValue().sum > 0, + "Should record the duration" + ); +}); + +/** + * Test classification metrics - fail - insufficient-input. + */ +add_task(async function test_classify_fail_case1() { + Services.fog.testResetFOG(); + + Assert.equal(null, Glean.relevancyClassify.fail.testGetValue()); + Assert.equal(null, Glean.relevancyClassify.duration.testGetValue()); + + // Require at least 1 input to trigger the failure. + await ContentRelevancyManager._test_doClassification({ minUrlsForTest: 1 }); + + Assert.deepEqual( + { + reason: "insufficient-input", + }, + Glean.relevancyClassify.fail.testGetValue()[0].extra, + "Should record the fail event" + ); + Assert.equal( + null, + Glean.relevancyClassify.duration.testGetValue(), + "Should not record the duration" + ); +}); diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml b/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml index 70f6d45c2d..0d76584e6c 100644 --- a/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml +++ b/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml @@ -4,6 +4,12 @@ firefox-appdir = "browser" ["test_ContentRelevancyManager.js"] skip-if = ["os == 'android'"] # bug 1886601 +lineno = "5" ["test_InputUtils.js"] skip-if = ["os == 'android'"] # bug 1886601 +lineno = "9" + +["test_Telemetry.js"] +skip-if = ["os == 'android'"] # bug 1886601 +run-sequentially = "concurrent runs would interfere with each other" diff --git a/toolkit/components/cookiebanners/metrics.yaml b/toolkit/components/cookiebanners/metrics.yaml index 98f86fd4a7..78ce343d37 100644 --- a/toolkit/components/cookiebanners/metrics.yaml +++ b/toolkit/components/cookiebanners/metrics.yaml @@ -75,17 +75,19 @@ cookie.banners: - https://bugzilla.mozilla.org/1827765 - https://bugzilla.mozilla.org/1850874 - https://bugzilla.mozilla.org/1861317 + - https://bugzilla.mozilla.org/1892152 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1797073#c6 - https://bugzilla.mozilla.org/show_bug.cgi?id=1827765#c9 - https://bugzilla.mozilla.org/show_bug.cgi?id=1850874#c7 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861317#c3 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892152#c6 data_sensitivity: - interaction notification_emails: - tihuang@mozilla.com - pbz@mozilla.com - expires: 128 + expires: 134 labels: - top_hit - top_hit_opt_in @@ -126,17 +128,19 @@ cookie.banners: - https://bugzilla.mozilla.org/1827765 - https://bugzilla.mozilla.org/1850874 - https://bugzilla.mozilla.org/1861317 + - https://bugzilla.mozilla.org/1892152 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1797073#c6 - https://bugzilla.mozilla.org/show_bug.cgi?id=1827765#c9 - https://bugzilla.mozilla.org/show_bug.cgi?id=1850874#c7 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861317#c3 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892152#c6 data_sensitivity: - interaction notification_emails: - tihuang@mozilla.com - pbz@mozilla.com - expires: 128 + expires: 134 labels: - top_hit - top_hit_opt_in @@ -173,15 +177,17 @@ cookie.banners: - https://bugzilla.mozilla.org/1827765 - https://bugzilla.mozilla.org/1850874 - https://bugzilla.mozilla.org/1861317 + - https://bugzilla.mozilla.org/1892152 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1797079#c6 - https://bugzilla.mozilla.org/show_bug.cgi?id=1827765#c9 - https://bugzilla.mozilla.org/show_bug.cgi?id=1850874#c7 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861317#c3 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892152#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 data_sensitivity: - interaction extra_keys: @@ -202,14 +208,16 @@ cookie.banners: cookies. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128#c10 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 data_sensitivity: - interaction notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 google_gdpr_choice_cookie: type: labeled_string description: > @@ -289,15 +297,17 @@ cookie.banners.click: - https://bugzilla.mozilla.org/1827765 - https://bugzilla.mozilla.org/1850874 - https://bugzilla.mozilla.org/1861317 + - https://bugzilla.mozilla.org/1892152 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1797078#c6 - https://bugzilla.mozilla.org/show_bug.cgi?id=1827765#c9 - https://bugzilla.mozilla.org/show_bug.cgi?id=1850874#c7 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861317#c3 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892152#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 telemetry_mirror: COOKIE_BANNERS_CLICK_HANDLE_DURATION_MS # TODO: consider moving this out of "click". It also records cookie injection. result: @@ -316,15 +326,17 @@ cookie.banners.click: - https://bugzilla.mozilla.org/1827765 - https://bugzilla.mozilla.org/1850874 - https://bugzilla.mozilla.org/1861317 + - https://bugzilla.mozilla.org/1892152 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1797078#c6 - https://bugzilla.mozilla.org/show_bug.cgi?id=1827765#c9 - https://bugzilla.mozilla.org/show_bug.cgi?id=1850874#c7 - https://bugzilla.mozilla.org/show_bug.cgi?id=1861317#c3 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892152#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 labels: - success - success_cookie_injected @@ -348,13 +360,15 @@ cookie.banners.click: content window. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495#c3 - https://bugzilla.mozilla.org/show_bug.cgi?id=1871200#c4 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 query_selector_run_count_per_window_frame: type: custom_distribution bucket_count: 20 @@ -365,13 +379,15 @@ cookie.banners.click: content window. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495#c3 - https://bugzilla.mozilla.org/show_bug.cgi?id=1871200#c4 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 query_selector_run_duration_per_window_top_level: type: custom_distribution bucket_count: 8 @@ -382,13 +398,15 @@ cookie.banners.click: lifetime of a top-level content window. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495#c3 - https://bugzilla.mozilla.org/show_bug.cgi?id=1871200#c4 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 query_selector_run_duration_per_window_frame: type: custom_distribution bucket_count: 8 @@ -399,13 +417,15 @@ cookie.banners.click: lifetime of a sub-frame content window. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1855495#c3 - https://bugzilla.mozilla.org/show_bug.cgi?id=1871200#c4 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 cookie.banners.cmp: ratio_handled_by_cmp_rule: type: rate @@ -414,14 +434,16 @@ cookie.banners.cmp: number of cases handled, including those handled by site-specific rules. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128#c10 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 data_sensitivity: - interaction notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 detected_cmp: type: labeled_counter description: > @@ -429,14 +451,16 @@ cookie.banners.cmp: handling. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128#c10 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 data_sensitivity: - interaction notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 result: type: labeled_counter description: > @@ -446,14 +470,16 @@ cookie.banners.cmp: incremented after the content window has been destroyed. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128#c10 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 data_sensitivity: - interaction notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 labels: - success - success_dom_content_loaded @@ -474,11 +500,13 @@ cookie.banners.cmp: cookieBanners.click.handle_duration. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154 data_reviews: - https://bugzilla.mozilla.org/show_bug.cgi?id=1813128#c10 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1892154#c6 data_sensitivity: - interaction notification_emails: - pbz@mozilla.com - tihuang@mozilla.com - expires: 128 + expires: 134 diff --git a/toolkit/components/downloads/test/unit/test_DownloadPaths.js b/toolkit/components/downloads/test/unit/test_DownloadPaths.js index 00fb070669..45be10256f 100644 --- a/toolkit/components/downloads/test/unit/test_DownloadPaths.js +++ b/toolkit/components/downloads/test/unit/test_DownloadPaths.js @@ -34,29 +34,29 @@ add_task(async function test_sanitize() { // Platform-dependent conversion of special characters to spaces. const kSpecialChars = 'A:*?|""<<>>;,+=[]B][=+,;>><<""|?*:C'; if (AppConstants.platform == "android") { - testSanitize(kSpecialChars, "A B C"); - testSanitize(" :: Website :: ", "Website"); - testSanitize("* Website!", "Website!"); - testSanitize("Website | Page!", "Website Page!"); - testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_"); + testSanitize(kSpecialChars, "A________________B________________C"); + testSanitize(" :: Website :: ", "__ Website __"); + testSanitize("* Website!", "_ Website!"); + testSanitize("Website | Page!", "Website _ Page!"); + testSanitize("Directory Listing: /a/b/", "Directory Listing_ _a_b_"); } else if (AppConstants.platform == "win") { - testSanitize(kSpecialChars, "A ;,+=[]B][=+,; C"); - testSanitize(" :: Website :: ", "Website"); - testSanitize("* Website!", "Website!"); - testSanitize("Website | Page!", "Website Page!"); - testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_"); + testSanitize(kSpecialChars, "A__________;,+=[]B][=+,;__________C"); + testSanitize(" :: Website :: ", "__ Website __"); + testSanitize("* Website!", "_ Website!"); + testSanitize("Website | Page!", "Website _ Page!"); + testSanitize("Directory Listing: /a/b/", "Directory Listing_ _a_b_"); } else if (AppConstants.platform == "macosx") { - testSanitize(kSpecialChars, "A ;,+=[]B][=+,; C"); - testSanitize(" :: Website :: ", "Website"); - testSanitize("* Website!", "Website!"); - testSanitize("Website | Page!", "Website Page!"); - testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_"); + testSanitize(kSpecialChars, "A__________;,+=[]B][=+,;__________C"); + testSanitize(" :: Website :: ", "__ Website __"); + testSanitize("* Website!", "_ Website!"); + testSanitize("Website | Page!", "Website _ Page!"); + testSanitize("Directory Listing: /a/b/", "Directory Listing_ _a_b_"); } else { - testSanitize(kSpecialChars, "A ;,+=[]B][=+,; C"); - testSanitize(" :: Website :: ", "Website"); - testSanitize("* Website!", "Website!"); - testSanitize("Website | Page!", "Website Page!"); - testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_"); + testSanitize(kSpecialChars, "A__________;,+=[]B][=+,;__________C"); + testSanitize(" :: Website :: ", "__ Website __"); + testSanitize("* Website!", "_ Website!"); + testSanitize("Website | Page!", "Website _ Page!"); + testSanitize("Directory Listing: /a/b/", "Directory Listing_ _a_b_"); } // Conversion of consecutive runs of slashes and backslashes to underscores. @@ -64,9 +64,9 @@ add_task(async function test_sanitize() { // Removal of leading and trailing whitespace and dots after conversion. testSanitize(" Website ", "Website"); - testSanitize(". . Website . Page . .", "Website . Page"); - testSanitize(" File . txt ", "File . txt"); - testSanitize("\f\n\r\t\v\x00\x1f\x7f\x80\x9f\xa0 . txt", "txt"); + testSanitize(". . Website . Page . .", "Website .Page"); + testSanitize(" File . txt ", "File .txt"); + testSanitize("\f\n\r\t\v\x00\x1f\x7f\x80\x9f\xa0 . txt", "_________ .txt"); testSanitize("\u1680\u180e\u2000\u2008\u200a . txt", "txt"); testSanitize("\u2028\u2029\u202f\u205f\u3000\ufeff . txt", "txt"); @@ -77,25 +77,25 @@ add_task(async function test_sanitize() { testSanitize(" . ", ""); // Stripping of BIDI formatting characters. - testSanitize("\u200e \u202b\u202c\u202d\u202etest\x7f\u200f", "_ ____test _"); - testSanitize("AB\x7f\u202a\x7f\u202a\x7fCD", "AB _ _ CD"); + testSanitize("\u200e \u202b\u202c\u202d\u202etest\x7f\u200f", "_ ____test__"); + testSanitize("AB\x7f\u202a\x7f\u202a\x7fCD", "AB_____CD"); // Stripping of colons: - testSanitize("foo:bar", "foo bar"); + testSanitize("foo:bar", "foo_bar"); // not compressing whitespaces. - testSanitize("foo : bar", "foo bar", { compressWhitespaces: false }); + testSanitize("foo : bar", "foo _ bar", { compressWhitespaces: false }); testSanitize("thing.lnk", "thing.lnk.download"); - testSanitize("thing.lnk\n", "thing.lnk.download"); + testSanitize("thing.lnk\n", "thing.lnk_"); testSanitize("thing.lnk", "thing.lnk", { allowInvalidFilenames: true, }); - testSanitize("thing.lnk\n", "thing.lnk", { + testSanitize("thing.lnk\n", "thing.lnk_", { allowInvalidFilenames: true, }); testSanitize("thing.URl", "thing.URl.download"); - testSanitize("thing.URl \n", "thing.URl", { + testSanitize("thing.URl \n", "thing.URl_", { allowInvalidFilenames: true, }); @@ -107,12 +107,12 @@ add_task(async function test_sanitize() { allowInvalidFilenames: true, }); - testSanitize("thing.local|", "thing.local.download"); - testSanitize("thing.lo|cal", "thing.lo cal"); - testSanitize('thing.local/*"', "thing.local_"); + testSanitize("thing.local|", "thing.local_"); + testSanitize("thing.lo|cal", "thing.lo_cal"); + testSanitize('thing.local/*"', "thing.local___"); testSanitize("thing.desktoP", "thing.desktoP.download"); - testSanitize("thing.desktoP \n", "thing.desktoP", { + testSanitize("thing.desktoP \n", "thing.desktoP_", { allowInvalidFilenames: true, }); }); diff --git a/toolkit/components/extensions/Extension.sys.mjs b/toolkit/components/extensions/Extension.sys.mjs index 8ab3c30234..56f1320d6c 100644 --- a/toolkit/components/extensions/Extension.sys.mjs +++ b/toolkit/components/extensions/Extension.sys.mjs @@ -161,6 +161,13 @@ XPCOMUtils.defineLazyPreferenceGetter( 30 * 1000 ); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "installIncludesOrigins", + "extensions.originControls.grantByDefault", + false +); + var { GlobalManager, IconDetails, @@ -509,14 +516,36 @@ var ExtensionAddonObserver = { }, onUninstalled(addon) { + this.clearOnUninstall(addon.id); + }, + + /** + * Clears persistent state from the add-on post install. + * + * @param {string} addonId The ID of the addon that has been uninstalled. + */ + clearOnUninstall(addonId) { + const tasks = []; + function addShutdownBlocker(name, promise) { + lazy.AsyncShutdown.profileChangeTeardown.addBlocker(name, promise); + tasks.push({ name, promise }); + } + function notifyUninstallTaskObservers() { + Management.emit("cleanupAfterUninstall", addonId, tasks); + } + // Cleanup anything that is used by non-extension addon types // since only extensions have uuid's. - lazy.ExtensionPermissions.removeAll(addon.id); + addShutdownBlocker( + `Clear ExtensionPermissions for ${addonId}`, + lazy.ExtensionPermissions.removeAll(addonId) + ); - lazy.QuarantinedDomains.clearUserPref(addon.id); + lazy.QuarantinedDomains.clearUserPref(addonId); - let uuid = UUIDMap.get(addon.id, false); + let uuid = UUIDMap.get(addonId, false); if (!uuid) { + notifyUninstallTaskObservers(); return; } @@ -527,8 +556,8 @@ var ExtensionAddonObserver = { ); // Clear all cached resources (e.g. CSS and images); - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear cache for ${addon.id}`, + addShutdownBlocker( + `Clear cache for ${addonId}`, clearCacheForExtensionPrincipal(principal, /* clearAll */ true) ); @@ -549,38 +578,38 @@ var ExtensionAddonObserver = { // down because is being uninstalled) and then cleared from // the persisted serviceworker registration on the next // startup. - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear ServiceWorkers for ${addon.id}`, + addShutdownBlocker( + `Clear ServiceWorkers for ${addonId}`, lazy.ServiceWorkerCleanUp.removeFromPrincipal(principal) ); // Clear the persisted dynamic content scripts created with the scripting // API (if any). - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear scripting store for ${addon.id}`, - lazy.ExtensionScriptingStore.clearOnUninstall(addon.id) + addShutdownBlocker( + `Clear scripting store for ${addonId}`, + lazy.ExtensionScriptingStore.clearOnUninstall(addonId) ); // Clear the DNR API's rules data persisted on disk (if any). - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear declarativeNetRequest store for ${addon.id}`, + addShutdownBlocker( + `Clear declarativeNetRequest store for ${addonId}`, lazy.ExtensionDNRStore.clearOnUninstall(uuid) ); if (!Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false)) { // Clear browser.storage.local backends. - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear Extension Storage ${addon.id} (File Backend)`, - lazy.ExtensionStorage.clear(addon.id, { shouldNotifyListeners: false }) + addShutdownBlocker( + `Clear Extension Storage ${addonId} (File Backend)`, + lazy.ExtensionStorage.clear(addonId, { shouldNotifyListeners: false }) ); // Clear browser.storage.sync rust-based backend. // (storage.sync clearOnUninstall will resolve and log an error on the // browser console in case of unexpected failures). if (!lazy.storageSyncOldKintoBackend) { - lazy.AsyncShutdown.profileChangeTeardown.addBlocker( - `Clear Extension StorageSync ${addon.id}`, - lazy.extensionStorageSync.clearOnUninstall(addon.id) + addShutdownBlocker( + `Clear Extension StorageSync ${addonId}`, + lazy.extensionStorageSync.clearOnUninstall(addonId) ); } @@ -595,7 +624,7 @@ var ExtensionAddonObserver = { }); Services.qms.clearStoragesForPrincipal(storagePrincipal); - lazy.ExtensionStorageIDB.clearMigratedExtensionPref(addon.id); + lazy.ExtensionStorageIDB.clearMigratedExtensionPref(addonId); // If LSNG is not enabled, we need to clear localStorage explicitly using // the old API. @@ -632,8 +661,10 @@ var ExtensionAddonObserver = { if (!Services.prefs.getBoolPref(LEAVE_UUID_PREF, false)) { // Clear the entry in the UUID map - UUIDMap.remove(addon.id); + UUIDMap.remove(addonId); } + + notifyUninstallTaskObservers(); }, onPropertyChanged(addon, properties) { @@ -1172,8 +1203,10 @@ export class ExtensionData { * includes the contents of the "permissions" property as well as other * capabilities that are derived from manifest fields that users should * be informed of (e.g., origins where content scripts are injected). + * + * For MV3 extensions with origin controls, this does not include origins. */ - get manifestPermissions() { + getRequiredPermissions() { if (this.type !== "extension") { return null; } @@ -1216,6 +1249,20 @@ export class ExtensionData { return Array.from(origins); } + /** + * Returns additional permissions that extensions is requesting based on its + * manifest. For now, this is host_permissions (and content scripts) in mv3. + */ + getRequestedPermissions() { + if (this.type !== "extension") { + return null; + } + if (this.originControls && lazy.installIncludesOrigins) { + return { permissions: [], origins: this.getManifestOrigins() }; + } + return { permissions: [], origins: [] }; + } + /** * Returns optional permissions from the manifest, including host permissions * if originControls is true. @@ -3705,8 +3752,8 @@ export class Extension extends ExtensionData { if ( this.originControls && - this.manifest.granted_host_permissions && - this.startupReason === "ADDON_INSTALL" + this.startupReason === "ADDON_INSTALL" && + (this.manifest.granted_host_permissions || lazy.installIncludesOrigins) ) { let origins = this.getManifestOrigins(); lazy.ExtensionPermissions.add(this.id, { permissions: [], origins }); diff --git a/toolkit/components/extensions/ExtensionContent.sys.mjs b/toolkit/components/extensions/ExtensionContent.sys.mjs index a2fce282ee..83d17ca84e 100644 --- a/toolkit/components/extensions/ExtensionContent.sys.mjs +++ b/toolkit/components/extensions/ExtensionContent.sys.mjs @@ -475,6 +475,10 @@ class Script { * execution is complete. */ async inject(context, reportExceptions = true) { + // NOTE: Avoid unnecessary use of "await" in this function, because doing + // so can delay script execution beyond the scheduled point. In particular, + // document_start scripts should run "immediately" in most cases. + DocumentManager.lazyInit(); if (this.requiresCleanup) { context.addScript(this); @@ -552,11 +556,19 @@ class Script { let scripts = this.getCompiledScripts(context); if (scripts instanceof Promise) { + // Note: in theory, the following async await could result in script + // execution being scheduled too late. That would be an issue for + // document_start scripts. In practice, this is not a problem because the + // compiled script is cached in the process, and preloading to compile + // starts as soon as the network request for the document has been + // received (see ExtensionPolicyService::CheckRequest). scripts = await scripts; } - // Make sure we've injected any related CSS before we run content scripts. - await cssPromise; + if (cssPromise) { + // Make sure we've injected any related CSS before we run content scripts. + await cssPromise; + } let result; @@ -623,7 +635,7 @@ class Script { p.catch(error => { Services.console.logMessage( new ScriptError( - `${error.name}: ${error.message}`, + error.toString(), error.fileName, null, error.lineNumber, diff --git a/toolkit/components/extensions/ExtensionDNR.sys.mjs b/toolkit/components/extensions/ExtensionDNR.sys.mjs index afc7d30751..6fec9f7639 100644 --- a/toolkit/components/extensions/ExtensionDNR.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNR.sys.mjs @@ -2175,12 +2175,34 @@ class RuleManager { this.#updateAllowAllRequestRules(); } - getSessionRules() { - return this.sessionRules.rules; + /** + * Get the session scoped rules. + * + * @param {Array|null} ruleIds + Optional array of rule IDs to return. By default, all the session + scoped rules are returned. + */ + getSessionRules(ruleIds = null) { + if (!ruleIds) { + return this.sessionRules.rules; + } + + return this.sessionRules.rules.filter(rule => ruleIds.includes(rule.id)); } - getDynamicRules() { - return this.dynamicRules.rules; + /** + * Get the dynamic rules. + * + * @param {Array|null} ruleIds + Optional array of rule IDs to return. By default, all the dynamic + rules are returned. + */ + getDynamicRules(ruleIds = null) { + if (!ruleIds) { + return this.dynamicRules.rules; + } + + return this.dynamicRules.rules.filter(rule => ruleIds.includes(rule.id)); } getRulesCount() { diff --git a/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs b/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs index ac4cd79c44..12919e4ee1 100644 --- a/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNRLimits.sys.mjs @@ -2,58 +2,99 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// TODO(Bug 1803370): consider allowing changing DNR limits through about:config prefs). +import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; -/** - * The minimum number of static rules guaranteed to an extension across its - * enabled static rulesets. Any rules above this limit will count towards the - * global static rule limit. - */ -const GUARANTEED_MINIMUM_STATIC_RULES = 30000; +// TODO(Bug 1803370): allow extension to exceed the GUARANTEED_MINIMUM_STATIC_RULES limit. +// +// The maximum number of static rules exceeding the per-extension +// GUARANTEED_MINIMUM_STATIC_RULES across every extensions. +// +// const MAX_GLOBAL_NUMBER_OF_STATIC_RULES = 300000; -/** - * The maximum number of static Rulesets an extension can specify as part of - * the "rule_resources" manifest key. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/318 - */ -const MAX_NUMBER_OF_STATIC_RULESETS = 50; +const lazy = {}; -/** - * The maximum number of static Rulesets an extension can enable at any one time. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/318 - */ -const MAX_NUMBER_OF_ENABLED_STATIC_RULESETS = 10; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "GUARANTEED_MINIMUM_STATIC_RULES", + "extensions.dnr.guaranteed_minimum_static_rules", + 30000 +); -/** - * The maximum number of dynamic and session rules an extension can add. - * NOTE: in the Firefox we are enforcing this limit to the session and dynamic rules count separately, - * instead of enforcing it to the rules count for both combined as the Chrome implementation does. - * - * NOTE: this limit may be increased in the future, see https://github.com/w3c/webextensions/issues/319 - */ -const MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES = 5000; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_STATIC_RULESETS", + "extensions.dnr.max_number_of_static_rulesets", + 100 +); + +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_ENABLED_STATIC_RULESETS", + "extensions.dnr.max_number_of_enabled_static_rulesets", + 20 +); /** - * The maximum number of regular expression rules that an extension can add. - * Session, dynamic and static rules have their own quota. - * - * TODO bug 1821033: Bump limit after optimizing regexFilter. + * NOTE: this limit may be increased in the future, see + * https://github.com/w3c/webextensions/issues/319 */ -const MAX_NUMBER_OF_REGEX_RULES = 1000; +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES", + "extensions.dnr.max_number_of_dynamic_and_session_rules", + 5000 +); -// TODO(Bug 1803370): allow extension to exceed the GUARANTEED_MINIMUM_STATIC_RULES limit. -// -// The maximum number of static rules exceeding the per-extension -// GUARANTEED_MINIMUM_STATIC_RULES across every extensions. -// -// const MAX_GLOBAL_NUMBER_OF_STATIC_RULES = 300000; +// TODO bug 1821033: Bump limit after optimizing regexFilter. +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MAX_NUMBER_OF_REGEX_RULES", + "extensions.dnr.max_number_of_regex_rules", + 1000 +); export const ExtensionDNRLimits = { - GUARANTEED_MINIMUM_STATIC_RULES, - MAX_NUMBER_OF_STATIC_RULESETS, - MAX_NUMBER_OF_ENABLED_STATIC_RULESETS, - MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES, - MAX_NUMBER_OF_REGEX_RULES, + /** + * The minimum number of static rules guaranteed to an extension across its + * enabled static rulesets. Any rules above this limit will count towards the + * global static rule limit. + */ + get GUARANTEED_MINIMUM_STATIC_RULES() { + return lazy.GUARANTEED_MINIMUM_STATIC_RULES; + }, + + /** + * The maximum number of static Rulesets an extension can specify as part of + * the "rule_resources" manifest key. + */ + get MAX_NUMBER_OF_STATIC_RULESETS() { + return lazy.MAX_NUMBER_OF_STATIC_RULESETS; + }, + + /** + * The maximum number of static Rulesets an extension can enable at any one + * time. + */ + get MAX_NUMBER_OF_ENABLED_STATIC_RULESETS() { + return lazy.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS; + }, + + /** + * The maximum number of dynamic and session rules an extension can add. + * + * NOTE: in the Firefox we are enforcing this limit to the session and + * dynamic rules count separately, instead of enforcing it to the rules count + * for both combined as the Chrome implementation does. + */ + get MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES() { + return lazy.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES; + }, + + /** + * The maximum number of regular expression rules that an extension can add. + * Session, dynamic and static rules have their own quota. + */ + get MAX_NUMBER_OF_REGEX_RULES() { + return lazy.MAX_NUMBER_OF_REGEX_RULES; + }, }; diff --git a/toolkit/components/extensions/ExtensionParent.sys.mjs b/toolkit/components/extensions/ExtensionParent.sys.mjs index f951433713..bbc82092b0 100644 --- a/toolkit/components/extensions/ExtensionParent.sys.mjs +++ b/toolkit/components/extensions/ExtensionParent.sys.mjs @@ -31,6 +31,7 @@ ChromeUtils.defineESModuleGetters(lazy, { PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", Schemas: "resource://gre/modules/Schemas.sys.mjs", getErrorNameForTelemetry: "resource://gre/modules/ExtensionTelemetry.sys.mjs", + WebNavigationFrames: "resource://gre/modules/WebNavigationFrames.sys.mjs", }); XPCOMUtils.defineLazyServiceGetters(lazy, { @@ -508,6 +509,7 @@ class ProxyContextParent extends BaseContext { this.childId = params.childId; this.uri = Services.io.newURI(params.url); + this.browsingContext = browsingContext; this.incognito = params.incognito; @@ -548,6 +550,39 @@ class ProxyContextParent extends BaseContext { return true; } + get frameId() { + if (!this.browsingContext) { + return -1; + } + + return lazy.WebNavigationFrames.getFrameId(this.browsingContext); + } + + get contextType() { + switch (this.viewType) { + case "background_worker": // intentionally fall-through + case "background": + return "BACKGROUND"; + case "popup": + return "POPUP"; + case "sidebar": + return "SIDE_PANEL"; + case "tab": + return "TAB"; + default: + throw new Error( + `Unexpected missing contextType mapping for viewType "${this.viewType}"` + ); + } + } + + toExtensionContext() { + // NOTE: implemented in subclasses that should be listed in runtime.getContexts results + // when they match the ContextFilter, whereas instances from subclasses that don't + // implement it will always be filtered out. + return undefined; + } + trackRunListenerPromise(runListenerPromise) { if ( // The extension was already shutdown. @@ -746,6 +781,34 @@ class ExtensionPageContextParent extends ProxyContextParent { return undefined; } + toExtensionContext() { + const { tabTracker } = apiManager.global; + const { tabId, windowId } = tabTracker.getBrowserDataForContext(this); + const windowContext = this.browsingContext?.currentWindowContext; + return { + // NOTE: the contextId property in the final set of properties returned to + // extensions code is filled in on the ext-runtime.js and it is not to be + // confused with the internal property called contextId. + contextId: undefined, + // NOTE: contextType is a getter that maps the viewType property used + // internally with the value expected for the runtime.ExtensionContext + // contextType property (which should be one of the values part of the + // runtime.ContextType enum). + contextType: this.contextType, + // TODO(Bug 1891478): add documentId. + // TODO(Bug 1890739): consider switching this to use webExposedOriginSerialization when available + // Using nsIPrincipal.originNoSuffix to avoid including the + // private browsing (or contextual identity ones) + documentOrigin: windowContext?.documentPrincipal.originNoSuffix, + documentUrl: windowContext?.documentURI.spec, + incognito: this.incognito, + frameId: this.frameId, + tabId, + windowId, + // TODO: File followup to also add a Firefox-only userContextId? + }; + } + unload() { super.unload(); this.extension.views.delete(this); @@ -775,6 +838,12 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent { this._onResourceAvailable = this._onResourceAvailable.bind(this); } + toExtensionContext() { + // NOTE: devtools extension contexts are currently omitted in getContexts + // results. + return undefined; + } + set devToolsToolbox(toolbox) { if (this._devToolsToolbox) { throw new Error("Cannot set the context DevTools toolbox twice"); diff --git a/toolkit/components/extensions/ExtensionShortcuts.sys.mjs b/toolkit/components/extensions/ExtensionShortcuts.sys.mjs index 17cff67eb9..e800fcc22d 100644 --- a/toolkit/components/extensions/ExtensionShortcuts.sys.mjs +++ b/toolkit/components/extensions/ExtensionShortcuts.sys.mjs @@ -261,7 +261,24 @@ export class ExtensionShortcuts { if (storedCommand && storedCommand.value) { commands.set(name, { ...manifestCommands.get(name) }); + lazy.ExtensionSettingsStore.removeSetting(extension.id, "commands", name); + if ( + name === "_execute_action" && + extension.manifestVersion > 2 && + lazy.ExtensionSettingsStore.hasSetting( + extension.id, + "commands", + "_execute_browser_action" + ) + ) { + lazy.ExtensionSettingsStore.removeSetting( + extension.id, + "commands", + "_execute_browser_action" + ); + } + this.registerKeys(commands); } } @@ -285,6 +302,19 @@ export class ExtensionShortcuts { let savedCommands = await this.loadCommandsFromStorage(extension.id); savedCommands.forEach((update, name) => { let command = commands.get(name); + if ( + name === "_execute_browser_action" && + extension.manifestVersion > 2 + ) { + // Ignore the old _execute_browser_action if there is data stored for + // the new _execute_action command. Otherwise use the stored data for + // `_execute_action` (since we renamed `_execute_browser_action` to + // `_execute_action` in MV3). + command = savedCommands.has("_execute_action") + ? null + : commands.get("_execute_action"); + } + if (command) { // We will only update commands, not add them. Object.assign(command, update); @@ -419,7 +449,7 @@ export class ExtensionShortcuts { } doc.documentElement.appendChild(keyset); if (sidebarKey) { - window.SidebarUI.updateShortcut({ keyId: sidebarKey.id }); + window.SidebarController.updateShortcut({ keyId: sidebarKey.id }); } this.keysetsMap.set(window, keyset); } diff --git a/toolkit/components/extensions/ExtensionTelemetry.sys.mjs b/toolkit/components/extensions/ExtensionTelemetry.sys.mjs index 95b71ce007..58368c01f2 100644 --- a/toolkit/components/extensions/ExtensionTelemetry.sys.mjs +++ b/toolkit/components/extensions/ExtensionTelemetry.sys.mjs @@ -18,8 +18,6 @@ const HISTOGRAMS_IDS = { eventPageIdleResult: "WEBEXT_EVENTPAGE_IDLE_RESULT_COUNT", extensionStartup: "WEBEXT_EXTENSION_STARTUP_MS", pageActionPopupOpen: "WEBEXT_PAGEACTION_POPUP_OPEN_MS", - storageLocalGetJson: "WEBEXT_STORAGE_LOCAL_GET_MS", - storageLocalSetJson: "WEBEXT_STORAGE_LOCAL_SET_MS", storageLocalGetIdb: "WEBEXT_STORAGE_LOCAL_IDB_GET_MS", storageLocalSetIdb: "WEBEXT_STORAGE_LOCAL_IDB_SET_MS", }; @@ -33,8 +31,6 @@ const GLEAN_METRICS_TYPES = { eventPageIdleResult: "labeled_counter", extensionStartup: "timing_distribution", pageActionPopupOpen: "timing_distribution", - storageLocalGetJson: "timing_distribution", - storageLocalSetJson: "timing_distribution", storageLocalGetIdb: "timing_distribution", storageLocalSetIdb: "timing_distribution", }; diff --git a/toolkit/components/extensions/ExtensionTestCommon.sys.mjs b/toolkit/components/extensions/ExtensionTestCommon.sys.mjs index 701a85d97b..6a3b068dd2 100644 --- a/toolkit/components/extensions/ExtensionTestCommon.sys.mjs +++ b/toolkit/components/extensions/ExtensionTestCommon.sys.mjs @@ -17,10 +17,13 @@ ChromeUtils.defineESModuleGetters(lazy, { AddonManager: "resource://gre/modules/AddonManager.sys.mjs", Assert: "resource://testing-common/Assert.sys.mjs", Extension: "resource://gre/modules/Extension.sys.mjs", + ExtensionAddonObserver: "resource://gre/modules/Extension.sys.mjs", ExtensionData: "resource://gre/modules/Extension.sys.mjs", ExtensionParent: "resource://gre/modules/ExtensionParent.sys.mjs", ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.sys.mjs", FileUtils: "resource://gre/modules/FileUtils.sys.mjs", + clearInterval: "resource://gre/modules/Timer.sys.mjs", + setInterval: "resource://gre/modules/Timer.sys.mjs", }); ChromeUtils.defineLazyGetter( @@ -36,6 +39,110 @@ const { flushJarCache } = ExtensionUtils; const { instanceOf } = ExtensionCommon; +// The tasks received here have already been registered as shutdown blockers +// (with AsyncShutdown). That means that in reality, if these tasks take +// long, that they affect Firefox's ability to quit, with a warning after 10 +// seconds and a forced quit without waiting for shutdown after 60 seconds +// (or whatever is in the toolkit.asyncshutdown.crash_timeout pref). +// +// To help with detecting unreasonable slowness in tests, we log when these +// tasks are taking too long at shutdown. +const MS_SLOW_TASK_DURATION = 2000; + +/** + * ExtensionUninstallTracker should be instantiated before extension shutdown, + * and can be used to await the completion of the uninstall and post-uninstall + * cleanup logic. Log messages are printed to aid debugging if the cleanup is + * observed to be slow (i.e. taking longer than MS_SLOW_TASK_DURATION). + * + * // Usage: + * let uninstallTracker = new ExtensionUninstallTracker(extension.id); + * await extension.shutdown(); + * await uninstallTracker.waitForUninstallCleanupDone(); + */ +class ExtensionUninstallTracker { + #resolveOnCleanupDone; + constructor(addonId) { + this.id = addonId; + + this.remainingTasks = new Set(); + // The uninstall/cleanup observer needs to be registered early, to not miss + // the notifications. + this._uninstallPromise = this.#promiseUninstallComplete(); + this._cleanupPromise = this.#promiseCleanupAfterUninstall(); + } + + async waitForUninstallCleanupDone() { + // Call #addTask() now instead of in the constructor, so that we only track + // the time after extension.shutdown() has completed. + this.#addTask("Awaiting uninstall-complete", this._uninstallPromise); + this.#addTask("Awaiting cleanupAfterUninstall", this._cleanupPromise); + // For debugging purposes, if shutdown is slow, regularly print a message + // with the remaining tasks. + let timer = lazy.setInterval( + () => this.#checkRemainingTasks(), + 2 * MS_SLOW_TASK_DURATION + ); + await new Promise(resolve => { + this.#resolveOnCleanupDone = resolve; + this.#checkRemainingTasks(); + }); + lazy.clearInterval(timer); + } + + #addTask(name, promise) { + const task = { name, promise, timeStart: Date.now() }; + this.remainingTasks.add(task); + promise.finally(() => { + this.remainingTasks.delete(task); + this.#checkRemainingTasks(); + }); + } + + #checkRemainingTasks() { + for (let task of this.remainingTasks) { + const timeSinceStart = Date.now() - task.timeStart; + if (timeSinceStart > MS_SLOW_TASK_DURATION) { + dump( + `WARNING: Detected slow post-uninstall task: ${timeSinceStart}ms for extension ${this.id}: ${task.name}\n` + ); + } + } + if (this.remainingTasks.size === 0) { + this.#resolveOnCleanupDone?.(); + } + } + + #promiseUninstallComplete() { + return new Promise(resolve => { + const onUninstallComplete = (eventName, { id }) => { + if (id === this.id) { + lazy.apiManager.off("uninstall-complete", onUninstallComplete); + resolve(); + } + }; + lazy.apiManager.on("uninstall-complete", onUninstallComplete); + }); + } + + #promiseCleanupAfterUninstall() { + return new Promise(resolve => { + const onCleanupAfterUninstall = (eventName, id, tasks) => { + if (id === this.id) { + lazy.apiManager.off("cleanupAfterUninstall", onCleanupAfterUninstall); + for (const task of tasks) { + if (task.promise) { + this.#addTask(task.name, task.promise); + } + } + resolve(); + } + }; + lazy.apiManager.on("cleanupAfterUninstall", onCleanupAfterUninstall); + }); + } +} + /** * A skeleton Extension-like object, used for testing, which installs an * add-on via the add-on manager when startup() is called, and @@ -75,7 +182,6 @@ export class MockExtension { this._extension = null; this._extensionPromise = promiseEvent("startup"); this._readyPromise = promiseEvent("ready"); - this._uninstallPromise = promiseEvent("uninstall-complete"); } maybeSetID(uri, id) { @@ -674,4 +780,24 @@ export var ExtensionTestCommon = class ExtensionTestCommon { data.startupReason ?? "ADDON_INSTALL" ); } + + /** + * Unload an extension and await completion of post-uninstall cleanup tasks. + * + * @param {Extension|MockExtension} extension + */ + static async unloadTestExtension(extension) { + const { id } = extension; + const uninstallTracker = new ExtensionUninstallTracker(id); + await extension.shutdown(); + if (extension instanceof lazy.Extension) { + // AddonManager-managed add-ons run additional (cleanup) tasks after + // shutting down an extension. Do the same even without useAddonManager. + lazy.Extension.getBootstrapScope().uninstall({ id }); + + // Data removal by ExtensionAddonObserver.onUninstalled: + lazy.ExtensionAddonObserver.clearOnUninstall(id); + } + await uninstallTracker.waitForUninstallCleanupDone(); + } }; diff --git a/toolkit/components/extensions/Schemas.sys.mjs b/toolkit/components/extensions/Schemas.sys.mjs index b107036355..e95cbd6bb5 100644 --- a/toolkit/components/extensions/Schemas.sys.mjs +++ b/toolkit/components/extensions/Schemas.sys.mjs @@ -316,6 +316,27 @@ const POSTPROCESSORS = { } return value; }, + + incognitoSplitUnsupportedAndFallback(value, context) { + if (value === "split") { + // incognito:split has not been implemented (bug 1380812). There are two + // alternatives: "spanning" and "not_allowed". + // + // "incognito":"split" is required by Chrome when extensions want to load + // any extension page in a tab in Chrome. In Firefox that is not required, + // so extensions could replace "split" with "spanning". + // Another (poorly documented) effect of "incognito":"split" is separation + // of some state between some extension APIs. Because this can in theory + // result in unwanted mixing of state between private and non-private + // browsing, we fall back to "not_allowed", which prevents the user from + // enabling the extension in private browsing windows. + value = "not_allowed"; + context.logWarning( + `incognito "split" is unsupported. Falling back to incognito "${value}".` + ); + } + return value; + }, }; // Parses a regular expression, with support for the Python extended diff --git a/toolkit/components/extensions/WebNavigation.sys.mjs b/toolkit/components/extensions/WebNavigation.sys.mjs index c33a45db81..98d537d85c 100644 --- a/toolkit/components/extensions/WebNavigation.sys.mjs +++ b/toolkit/components/extensions/WebNavigation.sys.mjs @@ -8,6 +8,7 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { + BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", ClickHandlerParent: "resource:///actors/ClickHandlerParent.sys.mjs", UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs", @@ -249,8 +250,7 @@ export var WebNavigationManager = { onContentClick(target, data) { // We are interested only on clicks to links which are not "add to bookmark" commands if (data.href && !data.bookmark) { - let ownerWin = target.ownerGlobal; - let where = ownerWin.whereToOpenLink(data); + let where = lazy.BrowserUtils.whereToOpenLink(data); if (where == "current") { this.setRecentTabTransitionData({ link: true }); } diff --git a/toolkit/components/extensions/child/ext-storage.js b/toolkit/components/extensions/child/ext-storage.js index 3d71a1cd60..c6c67a8736 100644 --- a/toolkit/components/extensions/child/ext-storage.js +++ b/toolkit/components/extensions/child/ext-storage.js @@ -28,28 +28,16 @@ this.storage = class extends ExtensionAPI { getLocalFileBackend(context, { deserialize, serialize }) { return { get(keys) { - return measureOp( - ExtensionTelemetry.storageLocalGetJson, - context.extension, - () => { - return context.childManager - .callParentAsyncFunction("storage.local.JSONFileBackend.get", [ - serialize(keys), - ]) - .then(deserialize); - } - ); + return context.childManager + .callParentAsyncFunction("storage.local.JSONFileBackend.get", [ + serialize(keys), + ]) + .then(deserialize); }, set(items) { - return measureOp( - ExtensionTelemetry.storageLocalSetJson, - context.extension, - () => { - return context.childManager.callParentAsyncFunction( - "storage.local.JSONFileBackend.set", - [serialize(items)] - ); - } + return context.childManager.callParentAsyncFunction( + "storage.local.JSONFileBackend.set", + [serialize(items)] ); }, remove(keys) { diff --git a/toolkit/components/extensions/metrics.yaml b/toolkit/components/extensions/metrics.yaml index 6d36dae614..7993832a64 100644 --- a/toolkit/components/extensions/metrics.yaml +++ b/toolkit/components/extensions/metrics.yaml @@ -58,6 +58,8 @@ extensions: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_STARTUPCACHE_LOAD_TIME + no_lint: + - GIFFT_NON_PING_LIFETIME startup_cache_read_errors: type: labeled_counter @@ -75,6 +77,8 @@ extensions: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_STARTUPCACHE_READ_ERRORS + no_lint: + - GIFFT_NON_PING_LIFETIME startup_cache_write_bytelength: type: quantity @@ -92,6 +96,8 @@ extensions: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_STARTUPCACHE_WRITE_BYTELENGTH + no_lint: + - GIFFT_NON_PING_LIFETIME process_event: type: labeled_counter @@ -130,7 +136,6 @@ extensions.apis.dnr: expires: 138 description: | Amount of data read from the DNR startup cache file. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -149,7 +154,6 @@ extensions.apis.dnr: expires: 138 description: | Amount of time it takes to read data into the DNR startup cache file. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -168,7 +172,6 @@ extensions.apis.dnr: expires: 138 description: | Amount of data written to the DNR startup cache file. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -187,7 +190,6 @@ extensions.apis.dnr: expires: 138 description: | Amount of time it takes to write data into the DNR startup cache file. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -221,6 +223,8 @@ extensions.apis.dnr: - hit - miss telemetry_mirror: EXTENSIONS_APIS_DNR_STARTUP_CACHE_ENTRIES + no_lint: + - GIFFT_NON_PING_LIFETIME validate_rules_time: type: timing_distribution @@ -229,7 +233,6 @@ extensions.apis.dnr: description: | Amount of time it takes to validate DNR rules of individual ruleset when dynamic or static rulesets have been loaded from disk. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -248,7 +251,6 @@ extensions.apis.dnr: expires: 138 description: | Amount of time it takes to evaluate DNR rules for one network request. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -378,6 +380,8 @@ extensions.quarantined_domains: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_QUARANTINEDDOMAINS_LISTSIZE + no_lint: + - GIFFT_NON_PING_LIFETIME listhash: type: string @@ -396,6 +400,8 @@ extensions.quarantined_domains: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_QUARANTINEDDOMAINS_LISTHASH + no_lint: + - GIFFT_NON_PING_LIFETIME remotehash: type: string @@ -417,6 +423,8 @@ extensions.quarantined_domains: data_sensitivity: - technical telemetry_mirror: EXTENSIONS_QUARANTINEDDOMAINS_REMOTEHASH + no_lint: + - GIFFT_NON_PING_LIFETIME extensions.counters: @@ -488,7 +496,6 @@ extensions.timing: description: | Amount of time it takes to load a WebExtensions background page, from when the build function is called to when the page has finished processing the onload event. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -506,7 +513,6 @@ extensions.timing: expires: never description: | Amount of time it takes for a BrowserAction popup to open. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -532,7 +538,6 @@ extensions.timing: expires: never description: | Amount of time it takes for content scripts from a WebExtension to be injected into a window. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -555,7 +560,6 @@ extensions.timing: description: | Amount of time (keyed by addon id) that an event page has been running before being suspended, or the entire addon shutdown. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -573,7 +577,6 @@ extensions.timing: description: | Amount of time it takes for a WebExtension to start up, from when the startup function is called to when the startup promise resolves. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -591,7 +594,6 @@ extensions.timing: expires: never description: | Amount of time it takes for a PageAction popup to open. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -611,65 +613,12 @@ extensions.timing: data_sensitivity: - technical - storage_local_get_json: - type: timing_distribution - time_unit: millisecond - expires: 128 - description: | - Amount of time it takes to perform a get via storage.local using the JSONFile backend. - lifetime: application - notification_emails: - - addons-dev-internal@mozilla.com - bugs: - - https://bugzilla.mozilla.org/1371398 - - https://bugzilla.mozilla.org/1513556 - - https://bugzilla.mozilla.org/1578225 - - https://bugzilla.mozilla.org/1623315 - - https://bugzilla.mozilla.org/1666980 - - https://bugzilla.mozilla.org/1706839 - - https://bugzilla.mozilla.org/1745271 - - https://bugzilla.mozilla.org/1777402 - - https://bugzilla.mozilla.org/1811155 - - https://bugzilla.mozilla.org/1861303 - - https://bugzilla.mozilla.org/1820158 - data_reviews: - - https://bugzilla.mozilla.org/show_bug.cgi?id=1820158#c8 - data_sensitivity: - - technical - - storage_local_set_json: - type: timing_distribution - time_unit: millisecond - expires: 128 - description: | - Amount of time it takes to perform a set via storage.local using the JSONFile backend. - lifetime: application - notification_emails: - - addons-dev-internal@mozilla.com - bugs: - - https://bugzilla.mozilla.org/1371398 - - https://bugzilla.mozilla.org/1513556 - - https://bugzilla.mozilla.org/1578225 - - https://bugzilla.mozilla.org/1623315 - - https://bugzilla.mozilla.org/1666980 - - https://bugzilla.mozilla.org/1706839 - - https://bugzilla.mozilla.org/1745271 - - https://bugzilla.mozilla.org/1777402 - - https://bugzilla.mozilla.org/1811155 - - https://bugzilla.mozilla.org/1861303 - - https://bugzilla.mozilla.org/1820158 - data_reviews: - - https://bugzilla.mozilla.org/show_bug.cgi?id=1820158#c8 - data_sensitivity: - - technical - storage_local_get_idb: type: timing_distribution time_unit: millisecond expires: never description: | Amount of time it takes to perform a get via storage.local using the IndexedDB backend. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: @@ -695,7 +644,6 @@ extensions.timing: expires: never description: | Amount of time it takes to perform a set via storage.local using the Indexed backend. - lifetime: application notification_emails: - addons-dev-internal@mozilla.com bugs: diff --git a/toolkit/components/extensions/parent/ext-declarativeNetRequest.js b/toolkit/components/extensions/parent/ext-declarativeNetRequest.js index fab1d941a4..2ca66cd1d4 100644 --- a/toolkit/components/extensions/parent/ext-declarativeNetRequest.js +++ b/toolkit/components/extensions/parent/ext-declarativeNetRequest.js @@ -92,17 +92,21 @@ this.declarativeNetRequest = class extends ExtensionAPI { }); }, - async getDynamicRules() { + async getDynamicRules(details) { await ExtensionDNR.ensureInitialized(extension); - return ExtensionDNR.getRuleManager(extension).getDynamicRules(); + return ExtensionDNR.getRuleManager(extension).getDynamicRules( + details?.ruleIds + ); }, - getSessionRules() { + getSessionRules(details) { // ruleManager.getSessionRules() returns an array of Rule instances. // When these are structurally cloned (to send them to the child), // the enumerable public fields of the class instances are copied to // plain objects, as desired. - return ExtensionDNR.getRuleManager(extension).getSessionRules(); + return ExtensionDNR.getRuleManager(extension).getSessionRules( + details?.ruleIds + ); }, isRegexSupported(regexOptions) { diff --git a/toolkit/components/extensions/parent/ext-management.js b/toolkit/components/extensions/parent/ext-management.js index fb28eca92c..67c254de99 100644 --- a/toolkit/components/extensions/parent/ext-management.js +++ b/toolkit/components/extensions/parent/ext-management.js @@ -42,6 +42,8 @@ const installType = addon => { return "sideload"; } else if (addon.isSystem) { return "other"; + } else if (addon.isInstalledByEnterprisePolicy) { + return "admin"; } return "normal"; }; diff --git a/toolkit/components/extensions/parent/ext-runtime.js b/toolkit/components/extensions/parent/ext-runtime.js index 3f9c0f8857..ff7aae6e5f 100644 --- a/toolkit/components/extensions/parent/ext-runtime.js +++ b/toolkit/components/extensions/parent/ext-runtime.js @@ -12,6 +12,8 @@ var { ExtensionParent } = ChromeUtils.importESModule( "resource://gre/modules/ExtensionParent.sys.mjs" ); +var { DefaultWeakMap } = ExtensionUtils; + ChromeUtils.defineESModuleGetters(this, { AddonManager: "resource://gre/modules/AddonManager.sys.mjs", AddonManagerPrivate: "resource://gre/modules/AddonManager.sys.mjs", @@ -126,10 +128,100 @@ this.runtime = class extends ExtensionAPIPersistent { }, }; + // Although we have an internal context.contextId field, we generate a new one here because + // the internal type is an integer and the public field a (UUID) string. + // TODO: Move the implementation elsewhere when contextId is used anywhere other than + // runtime.getContexts. See https://bugzilla.mozilla.org/show_bug.cgi?id=1628178#c5 + // + // Map + #contextUUIDMap = new DefaultWeakMap(_context => + String(Services.uuid.generateUUID()).slice(1, -1) + ); + + getContexts(filter) { + const { extension } = this; + const { proxyContexts } = ExtensionParent.ParentAPIManager; + const results = []; + for (const proxyContext of proxyContexts.values()) { + if (proxyContext.extension !== extension) { + continue; + } + let ctx; + try { + ctx = proxyContext.toExtensionContext(); + } catch (err) { + // toExtensionContext may throw if the contextType getter + // raised an exception due to an internal viewType has + // not be mapped with a contextType value. + // + // When running in DEBUG builds we reject the getContexts + // call, while in non DEBUG build we just omit the result + // and log a warning in the Browser Console. + if (AppConstants.DEBUG) { + throw err; + } else { + Cu.reportError(err); + } + } + + if (this.matchContextFilter(filter, ctx)) { + results.push({ + ...ctx, + contextId: this.#contextUUIDMap.get(proxyContext), + }); + } + } + return results; + } + + matchContextFilter(filter, ctx) { + if (!ctx) { + // Filter out subclasses that do not return any ExtensionContext details + // from their toExtensionContext method. + return false; + } + if (filter.contextIds && !filter.contextIds.includes(ctx.contextId)) { + return false; + } + if (filter.contextTypes && !filter.contextTypes.includes(ctx.contextType)) { + return false; + } + if (filter.documentIds && !filter.documentIds.includes(ctx.documentId)) { + return false; + } + if ( + filter.documentOrigins && + !filter.documentOrigins.includes(ctx.documentOrigin) + ) { + return false; + } + if (filter.documentUrls && !filter.documentUrls.includes(ctx.documentUrl)) { + return false; + } + if (filter.frameIds && !filter.frameIds.includes(ctx.frameId)) { + return false; + } + if (filter.tabIds && !filter.tabIds.includes(ctx.tabId)) { + return false; + } + if (filter.windowIds && !filter.windowIds.includes(ctx.windowId)) { + return false; + } + if ( + typeof filter.incognito === "boolean" && + ctx.incognito !== filter.incognito + ) { + return false; + } + return true; + } + getAPI(context) { let { extension } = context; return { runtime: { + getContexts: filter => this.getContexts(filter), + // onStartup is special-cased in ext-backgroundPages to cause // an immediate startup. We do not prime onStartup. onStartup: new EventManager({ diff --git a/toolkit/components/extensions/schemas/declarative_net_request.json b/toolkit/components/extensions/schemas/declarative_net_request.json index e7bdc02041..5c91fc1e35 100644 --- a/toolkit/components/extensions/schemas/declarative_net_request.json +++ b/toolkit/components/extensions/schemas/declarative_net_request.json @@ -439,6 +439,18 @@ } } } + }, + { + "id": "GetRulesFilter", + "type": "object", + "properties": { + "ruleIds": { + "type": "array", + "optional": true, + "description": "If specified, only rules with matching IDs are included.", + "items": { "type": "integer" } + } + } } ], "functions": [ @@ -588,6 +600,12 @@ "description": "Returns the current set of dynamic rules for the extension.", "async": "callback", "parameters": [ + { + "name": "filter", + "$ref": "GetRulesFilter", + "optional": true, + "description": "An object to filter the set of dynamic rules for the extension." + }, { "name": "callback", "type": "function", @@ -609,6 +627,12 @@ "description": "Returns the current set of session scoped rules for the extension.", "async": "callback", "parameters": [ + { + "name": "filter", + "$ref": "GetRulesFilter", + "optional": true, + "description": "An object to filter the set of session scoped rules for the extension." + }, { "name": "callback", "type": "function", diff --git a/toolkit/components/extensions/schemas/geckoProfiler.json b/toolkit/components/extensions/schemas/geckoProfiler.json index f2c6bec4cd..6da180fd49 100644 --- a/toolkit/components/extensions/schemas/geckoProfiler.json +++ b/toolkit/components/extensions/schemas/geckoProfiler.json @@ -47,7 +47,8 @@ "power", "responsiveness", "cpufreq", - "bandwidth" + "bandwidth", + "memory" ] }, { diff --git a/toolkit/components/extensions/schemas/management.json b/toolkit/components/extensions/schemas/management.json index b75c0e2b4c..069f3b030a 100644 --- a/toolkit/components/extensions/schemas/management.json +++ b/toolkit/components/extensions/schemas/management.json @@ -46,9 +46,9 @@ }, { "id": "ExtensionInstallType", - "description": "How the extension was installed. One of
development: The extension was loaded unpacked in developer mode,
normal: The extension was installed normally via an .xpi file,
sideload: The extension was installed by other software on the machine,
other: The extension was installed by other means.", + "description": "How the extension was installed. One of
development: The extension was loaded unpacked in developer mode,
normal: The extension was installed normally via an .xpi file,
sideload: The extension was installed by other software on the machine,
admin: The extension was installed by policy,
other: The extension was installed by other means.", "type": "string", - "enum": ["development", "normal", "sideload", "other"] + "enum": ["development", "normal", "sideload", "admin", "other"] }, { "id": "ExtensionInfo", diff --git a/toolkit/components/extensions/schemas/manifest.json b/toolkit/components/extensions/schemas/manifest.json index 384b168e39..9701eda25a 100644 --- a/toolkit/components/extensions/schemas/manifest.json +++ b/toolkit/components/extensions/schemas/manifest.json @@ -121,7 +121,9 @@ "incognito": { "type": "string", - "enum": ["not_allowed", "spanning"], + "description": "The 'split' value is not supported.", + "enum": ["not_allowed", "spanning", "split"], + "postprocess": "incognitoSplitUnsupportedAndFallback", "default": "spanning", "optional": true }, diff --git a/toolkit/components/extensions/schemas/runtime.json b/toolkit/components/extensions/schemas/runtime.json index 75ff341393..d2e21706e4 100644 --- a/toolkit/components/extensions/schemas/runtime.json +++ b/toolkit/components/extensions/schemas/runtime.json @@ -18,6 +18,108 @@ "allowedContexts": ["content", "devtools"], "description": "Use the browser.runtime API to retrieve the background page, return details about the manifest, and listen for and respond to events in the app or extension lifecycle. You can also use this API to convert the relative path of URLs to fully-qualified URLs.", "types": [ + { + "id": "ContextFilter", + "min_manifest_version": 3, + "type": "object", + "description": "A filter to match against existing extension context. Matching contexts must match all specified filters.", + "properties": { + "contextIds": { + "optional": true, + "type": "array", + "items": { "type": "string" } + }, + "contextTypes": { + "optional": true, + "type": "array", + "items": { "$ref": "ContextType" } + }, + "documentIds": { + "optional": true, + "type": "array", + "items": { "type": "string" } + }, + "documentOrigins": { + "optional": true, + "type": "array", + "items": { "type": "string" } + }, + "documentUrls": { + "optional": true, + "type": "array", + "items": { "type": "string" } + }, + "frameIds": { + "optional": true, + "type": "array", + "items": { "type": "integer" } + }, + "tabIds": { + "optional": true, + "type": "array", + "items": { "type": "integer" } + }, + "windowIds": { + "optional": true, + "type": "array", + "items": { "type": "integer" } + }, + "incognito": { "optional": true, "type": "boolean" } + } + }, + { + "id": "ContextType", + "type": "string", + "enum": ["BACKGROUND", "POPUP", "SIDE_PANEL", "TAB"], + "description": "The type of extension view." + }, + { + "id": "ExtensionContext", + "type": "object", + "description": "A context hosting extension content", + "properties": { + "contextId": { + "type": "string", + "description": "An unique identifier associated to this context" + }, + "contextType": { + "$ref": "ContextType", + "description": "The type of the context" + }, + "documentId": { + "type": "string", + "unsupported": true, + "optional": true, + "description": "An UUID for the document associated with this context, or undefined if it is not hosted in a document" + }, + "documentOrigin": { + "type": "string", + "optional": true, + "description": "The origin of the document associated with this context, or undefined if it is not hosted in a document" + }, + "documentUrl": { + "type": "string", + "optional": true, + "description": "The URL of the document associated with this context, or undefined if it is not hosted in a document" + }, + "incognito": { + "type": "boolean", + "description": "Whether the context is associated with an private browsing context." + }, + "frameId": { + "type": "integer", + "description": "The frame ID for this context, or -1 if it is not hosted in a frame." + }, + "tabId": { + "type": "integer", + "description": "The tab ID for this context, or -1 if it is not hosted in a tab." + }, + "windowId": { + "type": "integer", + "description": "The window ID for this context, or -1 if it is not hosted in a window." + } + } + }, { "id": "Port", "type": "object", @@ -218,6 +320,31 @@ } ] }, + { + "name": "getContexts", + "type": "function", + "description": "Fetches information about active contexts associated with this extension", + "async": "callback", + "parameters": [ + { + "name": "filter", + "$ref": "ContextFilter", + "description": "A filter to find matching context." + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "contexts", + "type": "array", + "items": { "$ref": "ExtensionContext" }, + "description": "The matching contexts, if any." + } + ] + } + ] + }, { "name": "openOptionsPage", "type": "function", diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_getCurrent_differentExt.js b/toolkit/components/extensions/test/browser/browser_ext_themes_getCurrent_differentExt.js index 587c5d4efe..86d794669d 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_getCurrent_differentExt.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_getCurrent_differentExt.js @@ -139,7 +139,9 @@ add_task(async function test_getcurrent_privateBrowsing() { "resource://gre/modules/ExtensionCommon.sys.mjs" ); const { makeWidgetId } = ExtensionCommon; - privateWin.SidebarUI.show(`${makeWidgetId(extension.id)}-sidebar-action`); + privateWin.SidebarController.show( + `${makeWidgetId(extension.id)}-sidebar-action` + ); let imageLoaded = extension.awaitMessage("theme-image"); Assert.deepEqual(await imageLoaded, { success: true }, "theme image loaded"); diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_sidebars.js b/toolkit/components/extensions/test/browser/browser_ext_themes_sidebars.js index 0d2e69716d..492fe3a263 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_sidebars.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_sidebars.js @@ -17,7 +17,7 @@ async function test_sidebar_theme(theme, isBrightText) { const sidebarBox = document.getElementById("sidebar-box"); const browserRoot = document.documentElement; - const content = SidebarUI.browser.contentWindow; + const content = SidebarController.browser.contentWindow; const root = content.document.documentElement; ok( @@ -184,7 +184,7 @@ add_task(async function test_support_sidebar_colors() { for (let command of ["viewBookmarksSidebar", "viewHistorySidebar"]) { info("Executing command: " + command); - await SidebarUI.show(command); + await SidebarController.show(command); await test_sidebar_theme( { @@ -263,7 +263,7 @@ add_task(async function test_support_sidebar_border_color() { "Sidebar splitter should be colored properly" ); - SidebarUI.reversePosition(); + SidebarController.reversePosition(); is( sidebarSplitterCS.borderInlineStartColor, @@ -271,7 +271,7 @@ add_task(async function test_support_sidebar_border_color() { "Sidebar splitter should be colored properly after switching sides" ); - SidebarUI.reversePosition(); + SidebarController.reversePosition(); } await extension.unload(); diff --git a/toolkit/components/extensions/test/marionette/manifest-serviceworker.toml b/toolkit/components/extensions/test/marionette/manifest-serviceworker.toml index c8035f80c2..04bdc4e17e 100644 --- a/toolkit/components/extensions/test/marionette/manifest-serviceworker.toml +++ b/toolkit/components/extensions/test/marionette/manifest-serviceworker.toml @@ -1,4 +1,5 @@ [DEFAULT] +skip-if = ["!nightly_build"] # MOZ_WEBEXT_WEBIDL_ENABLED is only defined on nightly ["test_extension_serviceworkers_purged_on_pref_disabled.py"] ["test_temporary_extension_serviceworkers_not_persisted.py"] diff --git a/toolkit/components/extensions/test/mochitest/mochitest-common.toml b/toolkit/components/extensions/test/mochitest/mochitest-common.toml index 782069a79c..f49fb131c5 100644 --- a/toolkit/components/extensions/test/mochitest/mochitest-common.toml +++ b/toolkit/components/extensions/test/mochitest/mochitest-common.toml @@ -268,6 +268,8 @@ skip-if = [ "http2", ] +["test_ext_extension_getViews.html"] + ["test_ext_extension_iframe_messaging.html"] skip-if = [ "http3", @@ -350,6 +352,8 @@ skip-if = [ "http2", ] +["test_ext_runtime_getContexts.html"] + ["test_ext_script_filenames.html"] ["test_ext_scripting_contentScripts.html"] @@ -443,12 +447,6 @@ skip-if = [ ] ["test_ext_subframes_privileges.html"] -skip-if = [ - "os == 'android'", # Bug 1845918 - "verify", # Bug 1489771 - "http3", - "http2", -] ["test_ext_tabs_captureTab.html"] skip-if = [ diff --git a/toolkit/components/extensions/test/mochitest/test_ext_all_apis.js b/toolkit/components/extensions/test/mochitest/test_ext_all_apis.js index 95ac9af50d..8dec0c6ae5 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_all_apis.js +++ b/toolkit/components/extensions/test/mochitest/test_ext_all_apis.js @@ -89,8 +89,10 @@ let expectedBackgroundApis = [ "permissions.remove", "permissions.onAdded", "permissions.onRemoved", + "runtime.ContextType", "runtime.getBackgroundPage", "runtime.getBrowserInfo", + "runtime.getContexts", "runtime.getPlatformInfo", "runtime.onConnectExternal", "runtime.onInstalled", diff --git a/toolkit/components/extensions/test/mochitest/test_ext_contentscript_activeTab.html b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_activeTab.html index 076c177dfa..28bbe3b253 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript_activeTab.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_activeTab.html @@ -14,7 +14,10 @@ add_task(async function setup() { await SpecialPowers.pushPrefEnv({ - set: [["extensions.manifestV3.enabled", true]], + set: [ + ["extensions.manifestV3.enabled", true], + ["extensions.originControls.grantByDefault", false], + ], }); }); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_extension_getViews.html b/toolkit/components/extensions/test/mochitest/test_ext_extension_getViews.html new file mode 100644 index 0000000000..9309d45cdf --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_extension_getViews.html @@ -0,0 +1,108 @@ + + + + extension.getViews Test + + + + + + + + + + diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_getContexts.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_getContexts.html new file mode 100644 index 0000000000..fa3b7385da --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_getContexts.html @@ -0,0 +1,126 @@ + + + + runtime.getContexts Test + + + + + + + + + + diff --git a/toolkit/components/extensions/test/mochitest/test_ext_scripting_executeScript_activeTab.html b/toolkit/components/extensions/test/mochitest/test_ext_scripting_executeScript_activeTab.html index 5eb2193409..a0ceed72d5 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_scripting_executeScript_activeTab.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_scripting_executeScript_activeTab.html @@ -27,7 +27,10 @@ const makeExtension = ({ manifest: manifestProps, ...otherProps }) => { add_task(async function setup() { await SpecialPowers.pushPrefEnv({ - set: [["extensions.manifestV3.enabled", true]], + set: [ + ["extensions.manifestV3.enabled", true], + ["extensions.originControls.grantByDefault", false], + ], }); }); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html b/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html index f791d08602..0586275808 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html @@ -14,6 +14,32 @@ "use strict"; /* eslint-disable mozilla/balanced-listeners */ +const { + WebExtensionPolicy, +} = SpecialPowers.Cu.getGlobalForObject(SpecialPowers.Services); + + +// Some tests load non-moz-extension:-URLs in their extension document. When +// extensions run in-process (extensions.webextensions.remote set to false), +// that fails. +// For details, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1724099 and +// the same function in toolkit/components/extensions/test/xpcshell/head.js +async function allow_unsafe_parent_loads_when_extensions_not_remote() { + if (!WebExtensionPolicy.useRemoteWebExtensions) { + await SpecialPowers.pushPrefEnv({ + set: [["security.allow_unsafe_parent_loads", true]], + }); + } +} + +async function revert_allow_unsafe_parent_loads_when_extensions_not_remote() { + if (!WebExtensionPolicy.useRemoteWebExtensions) { + // Assume that the previous call to pushPrefEnv was from + // allow_unsafe_parent_loads_when_extensions_not_remote. + await SpecialPowers.popPrefEnv(); + } +} + add_task(async function test_webext_tab_subframe_privileges() { function background() { browser.runtime.onMessage.addListener(async ({msg, success, tabId, error}) => { @@ -198,19 +224,25 @@ add_task(async function test_webext_contentscript_iframe_subframe_privileges() { }); add_task(async function test_webext_background_remote_subframe_privileges() { - function backgroundSubframeScript() { + // file_remote_frame.html is opened at the same origin as this test page. + document.cookie = "cookie=monster"; + + function backgroundScript() { window.addEventListener("message", evt => { - browser.test.assertEq("http://mochi.test:8888", evt.origin, "postmessage origin ok"); + browser.test.assertTrue( + evt.origin === "http://mochi.test:8888" || + evt.origin === "https://mochi.test:8888", // using https-first, http2/http3 server. + `postmessage origin ok: ${evt.origin}` + ); browser.test.assertFalse(evt.data.tabs, "remote frame cannot access webextension APIs"); browser.test.assertEq("cookie=monster", evt.data.cookie, "Expected cookie value"); browser.test.notifyPass("webext-background-subframe-privileges"); }, {once: true}); - browser.cookies.set({url: "http://mochi.test:8888", name: "cookie", "value": "monster"}); } let extensionData = { manifest: { - permissions: ["cookies", "*://mochi.test/*", "tabs"], + permissions: ["*://mochi.test/*", "tabs"], background: { page: "background.html", }, @@ -219,32 +251,32 @@ add_task(async function test_webext_background_remote_subframe_privileges() { "background.html": ` - ', + "page.js"() { + browser.runtime.onMessage.addListener((msg, sender) => { + browser.test.assertEq( + "hello-from-sw", + msg, + "expected message from service worker" + ); + + const { contextId, ...otherProps } = sender; + browser.test.assertTrue(!!contextId, "expected a truthy contextId"); + browser.test.assertDeepEq( + { + envType: "addon_child", + id: "@test-messaging", + origin: self.origin, + url: browser.runtime.getURL("sw.js"), + }, + otherProps, + "expected correct sender props" + ); + + browser.test.sendMessage("page-done"); + }); + + browser.test.sendMessage("page-ready"); + }, + }, + }); + + await extension.startup(); + await extension.awaitMessage("background-ready"); + + const page = await ExtensionTestUtils.loadContentPage( + `moz-extension://${extension.uuid}/page.html`, + { extension } + ); + await extension.awaitMessage("page-ready"); + + extension.sendMessage("send"); + await extension.awaitMessage("page-done"); + + await page.close(); + await extension.unload(); +}); + +add_task(async function test_runtime_connect() { + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + background: { + service_worker: "sw.js", + }, + browser_specific_settings: { + gecko: { id: "@test-messaging" }, + }, + }, + files: { + "sw.js": async function () { + browser.test.onMessage.addListener(msg => { + browser.test.assertEq("connect", msg, "expected correct message"); + browser.runtime.connect(); + }); + + browser.test.sendMessage("background-ready"); + }, + "page.html": '', + "page.js"() { + browser.runtime.onConnect.addListener(port => { + const { contextId, ...otherProps } = port.sender; + browser.test.assertTrue(!!contextId, "expected a truthy contextId"); + browser.test.assertDeepEq( + { + envType: "addon_child", + id: "@test-messaging", + origin: self.origin, + url: browser.runtime.getURL("sw.js"), + }, + otherProps, + "expected correct sender props" + ); + + browser.test.sendMessage("page-done"); + }); + + browser.test.sendMessage("page-ready"); + }, + }, + }); + + await extension.startup(); + await extension.awaitMessage("background-ready"); + + const page = await ExtensionTestUtils.loadContentPage( + `moz-extension://${extension.uuid}/page.html`, + { extension } + ); + await extension.awaitMessage("page-ready"); + + extension.sendMessage("connect"); + await extension.awaitMessage("page-done"); + + await page.close(); + await extension.unload(); +}); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js index d0448b7b2e..4b98597b11 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js @@ -15,55 +15,42 @@ const { TelemetryTestUtils } = ChromeUtils.importESModule( "resource://testing-common/TelemetryTestUtils.sys.mjs" ); -const HISTOGRAM_JSON_IDS = [ - "WEBEXT_STORAGE_LOCAL_SET_MS", - "WEBEXT_STORAGE_LOCAL_GET_MS", -]; -const KEYED_HISTOGRAM_JSON_IDS = [ - "WEBEXT_STORAGE_LOCAL_SET_MS_BY_ADDONID", - "WEBEXT_STORAGE_LOCAL_GET_MS_BY_ADDONID", -]; - -const HISTOGRAM_IDB_IDS = [ +const HISTOGRAM_IDS = [ "WEBEXT_STORAGE_LOCAL_IDB_SET_MS", "WEBEXT_STORAGE_LOCAL_IDB_GET_MS", ]; -const KEYED_HISTOGRAM_IDB_IDS = [ +const KEYED_HISTOGRAM_IDS = [ "WEBEXT_STORAGE_LOCAL_IDB_SET_MS_BY_ADDONID", "WEBEXT_STORAGE_LOCAL_IDB_GET_MS_BY_ADDONID", ]; -const HISTOGRAM_IDS = [].concat(HISTOGRAM_JSON_IDS, HISTOGRAM_IDB_IDS); -const KEYED_HISTOGRAM_IDS = [].concat( - KEYED_HISTOGRAM_JSON_IDS, - KEYED_HISTOGRAM_IDB_IDS -); - const EXTENSION_ID1 = "@test-extension1"; const EXTENSION_ID2 = "@test-extension2"; async function test_telemetry_background() { const { GleanTimingDistribution } = globalThis; + + // NOTE: we do not collect telemetry for the legacy JSON backend anymore + // and so if the IDB backend is not enabled we expect the related telemetry + // histograms and timing distributions to be empty. const expectedEmptyGleanMetrics = ExtensionStorageIDB.isBackendEnabled - ? ["storageLocalGetJson", "storageLocalSetJson"] + ? [] : ["storageLocalGetIdb", "storageLocalSetIdb"]; const expectedNonEmptyGleanMetrics = ExtensionStorageIDB.isBackendEnabled ? ["storageLocalGetIdb", "storageLocalSetIdb"] - : ["storageLocalGetJson", "storageLocalSetJson"]; - + : []; const expectedEmptyHistograms = ExtensionStorageIDB.isBackendEnabled - ? HISTOGRAM_JSON_IDS - : HISTOGRAM_IDB_IDS; + ? [] + : HISTOGRAM_IDS; const expectedEmptyKeyedHistograms = ExtensionStorageIDB.isBackendEnabled - ? KEYED_HISTOGRAM_JSON_IDS - : KEYED_HISTOGRAM_IDB_IDS; - + ? [] + : KEYED_HISTOGRAM_IDS; const expectedNonEmptyHistograms = ExtensionStorageIDB.isBackendEnabled - ? HISTOGRAM_IDB_IDS - : HISTOGRAM_JSON_IDS; + ? HISTOGRAM_IDS + : []; const expectedNonEmptyKeyedHistograms = ExtensionStorageIDB.isBackendEnabled - ? KEYED_HISTOGRAM_IDB_IDS - : KEYED_HISTOGRAM_JSON_IDS; + ? KEYED_HISTOGRAM_IDS + : []; const server = createHttpServer(); server.registerDirectory("/data/", do_get_file("data")); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_eventPage_StreamFilter.js b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_eventPage_StreamFilter.js index 23c29aa155..820e04956e 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_eventPage_StreamFilter.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_eventPage_StreamFilter.js @@ -105,7 +105,11 @@ async function test_idletimeout_on_streamfilter({ ).catch(err => { // This request is expected to be aborted when cleared after the test is exiting, // otherwise rethrow the error to trigger an explicit failure. - if (/The operation was aborted/.test(err.message)) { + if ( + /Content-Length header of network response exceeds response Body/.test( + err.message + ) + ) { info(`Test webRequest fetching "${testURL}" aborted`); } else { ok( diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml b/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml index 6d47012eca..fd0b2d50d2 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml @@ -432,6 +432,8 @@ skip-if = ["os == 'android' && debug"] ["test_ext_runtime_getBrowserInfo.js"] +["test_ext_runtime_getContexts.js"] + ["test_ext_runtime_getPlatformInfo.js"] ["test_ext_runtime_id.js"] diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-serviceworker.toml b/toolkit/components/extensions/test/xpcshell/xpcshell-serviceworker.toml index b300959970..83ca99bc2f 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-serviceworker.toml +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-serviceworker.toml @@ -49,3 +49,5 @@ run-sequentially = "very high failure rate in parallel" ["test_ext_scripting_contentScripts_file.js"] ["test_ext_scripting_updateContentScripts.js"] + +["test_ext_service_worker_messaging.js"] diff --git a/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp b/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp index 5ad9f2dfd8..3dd4303729 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp @@ -299,7 +299,7 @@ NS_IMETHODIMP ExtensionEventListener::CallListener( RefPtr runnable = new ExtensionListenerCallWorkerRunnable(this, std::move(argsHolder), aCallOptions, retPromise); - runnable->Dispatch(); + runnable->Dispatch(GetWorkerPrivate()); retPromise.forget(aPromiseResult); return NS_OK; @@ -332,7 +332,6 @@ bool ExtensionListenerCallWorkerRunnable::WorkerRun( JSContext* aCx, dom::WorkerPrivate* aWorkerPrivate) { MOZ_ASSERT(aWorkerPrivate); aWorkerPrivate->AssertIsOnWorkerThread(); - MOZ_ASSERT(aWorkerPrivate == mWorkerPrivate); auto global = mListener->GetGlobalObject(); if (NS_WARN_IF(!global)) { return true; diff --git a/toolkit/components/extensions/webidl-api/ExtensionEventListener.h b/toolkit/components/extensions/webidl-api/ExtensionEventListener.h index e986e4f58b..f11d3e7f6b 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionEventListener.h +++ b/toolkit/components/extensions/webidl-api/ExtensionEventListener.h @@ -120,7 +120,8 @@ class ExtensionEventListener final : public mozIExtensionEventListener { // A WorkerRunnable subclass used to call an ExtensionEventListener // in the thread that owns the dom::Function wrapped by the // ExtensionEventListener class. -class ExtensionListenerCallWorkerRunnable final : public dom::WorkerRunnable { +class ExtensionListenerCallWorkerRunnable final + : public dom::WorkerThreadRunnable { friend class ExtensionListenerCallPromiseResultHandler; public: @@ -133,8 +134,7 @@ class ExtensionListenerCallWorkerRunnable final : public dom::WorkerRunnable { UniquePtr aArgsHolder, ListenerCallOptions* aCallOptions, RefPtr aPromiseRetval = nullptr) - : WorkerRunnable(aExtensionEventListener->GetWorkerPrivate(), - "ExtensionListenerCallWorkerRunnable", WorkerThread), + : WorkerThreadRunnable("ExtensionListenerCallWorkerRunnable"), mListener(aExtensionEventListener), mArgsHolder(std::move(aArgsHolder)), mPromiseResult(std::move(aPromiseRetval)), diff --git a/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs b/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs index 7594fc8fcf..21282ff936 100644 --- a/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs +++ b/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs @@ -6,38 +6,21 @@ * Form Autofill content process module. */ -import { - GenericAutocompleteItem, - sendFillRequestToParent, -} from "resource://gre/modules/FillHelpers.sys.mjs"; +import { sendFillRequestToParent } from "resource://gre/modules/FillHelpers.sys.mjs"; /* eslint-disable no-use-before-define */ -const Cm = Components.manager; - const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { - AddressResult: "resource://autofill/ProfileAutoCompleteResult.sys.mjs", - ComponentUtils: "resource://gre/modules/ComponentUtils.sys.mjs", - CreditCardResult: "resource://autofill/ProfileAutoCompleteResult.sys.mjs", FormAutofill: "resource://autofill/FormAutofill.sys.mjs", - FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs", FormAutofillContent: "resource://autofill/FormAutofillContent.sys.mjs", - FormScenarios: "resource://gre/modules/FormScenarios.sys.mjs", - InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.sys.mjs", }); const autocompleteController = Cc[ "@mozilla.org/autocomplete/controller;1" ].getService(Ci.nsIAutoCompleteController); -ChromeUtils.defineLazyGetter( - lazy, - "FIELD_STATES", - () => lazy.FormAutofillUtils.FIELD_STATES -); - function getActorFromWindow(contentWindow, name = "FormAutofill") { // In unit tests, contentWindow isn't a real window. if (!contentWindow) { @@ -49,257 +32,10 @@ function getActorFromWindow(contentWindow, name = "FormAutofill") { : null; } -// Register/unregister a constructor as a factory. -function AutocompleteFactory() {} -AutocompleteFactory.prototype = { - register(targetConstructor) { - let proto = targetConstructor.prototype; - this._classID = proto.classID; - - let factory = - lazy.ComponentUtils.generateSingletonFactory(targetConstructor); - this._factory = factory; - - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory( - proto.classID, - proto.classDescription, - proto.contractID, - factory - ); - - if (proto.classID2) { - this._classID2 = proto.classID2; - registrar.registerFactory( - proto.classID2, - proto.classDescription, - proto.contractID2, - factory - ); - } - }, - - unregister() { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(this._classID, this._factory); - if (this._classID2) { - registrar.unregisterFactory(this._classID2, this._factory); - } - this._factory = null; - }, -}; - -/** - * @class - * - * @implements {nsIAutoCompleteSearch} - */ -function AutofillProfileAutoCompleteSearch() { - this.log = lazy.FormAutofill.defineLogGetter( - this, - "AutofillProfileAutoCompleteSearch" - ); -} -AutofillProfileAutoCompleteSearch.prototype = { - classID: Components.ID("4f9f1e4c-7f2c-439e-9c9e-566b68bc187d"), - contractID: "@mozilla.org/autocomplete/search;1?name=autofill-profiles", - classDescription: "AutofillProfileAutoCompleteSearch", - QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteSearch"]), - - // Begin nsIAutoCompleteSearch implementation - - /** - * Searches for a given string and notifies a listener (either synchronously - * or asynchronously) of the result - * - * @param {string} searchString the string to search for - * @param {string} searchParam - * @param {object} previousResult a previous result to use for faster searchinig - * @param {object} listener the listener to notify when the search is complete - */ - startSearch(searchString, searchParam, previousResult, listener) { - let { - activeInput, - activeSection, - activeFieldDetail, - activeHandler, - savedFieldNames, - } = lazy.FormAutofillContent; - this.forceStop = false; - - let isAddressField = lazy.FormAutofillUtils.isAddressField( - activeFieldDetail.fieldName - ); - const isCreditCardField = lazy.FormAutofillUtils.isCreditCardField( - activeFieldDetail.fieldName - ); - let isInputAutofilled = - activeHandler.getFilledStateByElement(activeInput) == - lazy.FIELD_STATES.AUTO_FILLED; - let allFieldNames = activeSection.allFieldNames; - let filledRecordGUID = activeSection.filledRecordGUID; - - let searchPermitted = isAddressField - ? lazy.FormAutofill.isAutofillAddressesEnabled - : lazy.FormAutofill.isAutofillCreditCardsEnabled; - let AutocompleteResult = isAddressField - ? lazy.AddressResult - : lazy.CreditCardResult; - let isFormAutofillSearch = true; - let pendingSearchResult = null; - - ProfileAutocomplete.lastProfileAutoCompleteFocusedInput = activeInput; - // Fallback to form-history if ... - // - specified autofill feature is pref off. - // - no profile can fill the currently-focused input. - // - the current form has already been populated and the field is not - // an empty credit card field. - // - (address only) less than 3 inputs are covered by all saved fields in the storage. - if ( - !searchPermitted || - !savedFieldNames.has(activeFieldDetail.fieldName) || - (!isInputAutofilled && - filledRecordGUID && - !(isCreditCardField && activeInput.value === "")) || - (isAddressField && - allFieldNames.filter(field => savedFieldNames.has(field)).length < - lazy.FormAutofillUtils.AUTOFILL_FIELDS_THRESHOLD) - ) { - isFormAutofillSearch = false; - if (activeInput.autocomplete == "off") { - // Create a dummy result as an empty search result. - pendingSearchResult = new AutocompleteResult("", "", [], [], {}); - } else { - pendingSearchResult = new Promise(resolve => { - let formHistory = Cc[ - "@mozilla.org/autocomplete/search;1?name=form-history" - ].createInstance(Ci.nsIAutoCompleteSearch); - formHistory.startSearch(searchString, searchParam, previousResult, { - onSearchResult: (_, result) => resolve(result), - }); - }); - } - } else if (isInputAutofilled) { - pendingSearchResult = new AutocompleteResult(searchString, "", [], [], { - isInputAutofilled, - }); - } else { - const data = { - fieldName: activeFieldDetail.fieldName, - searchString, - }; - - pendingSearchResult = this._getRecords(activeInput, data).then( - ({ records, externalEntries }) => { - if (this.forceStop) { - return null; - } - // Sort addresses by timeLastUsed for showing the lastest used address at top. - records.sort((a, b) => b.timeLastUsed - a.timeLastUsed); - - let adaptedRecords = activeSection.getAdaptedProfiles(records); - let handler = lazy.FormAutofillContent.activeHandler; - let isSecure = lazy.InsecurePasswordUtils.isFormSecure(handler.form); - - const result = new AutocompleteResult( - searchString, - activeFieldDetail.fieldName, - allFieldNames, - adaptedRecords, - { isSecure, isInputAutofilled } - ); - - result.externalEntries.push( - ...externalEntries.map( - entry => - new GenericAutocompleteItem( - entry.image, - entry.title, - entry.subtitle, - entry.fillMessageName, - entry.fillMessageData - ) - ) - ); - - return result; - } - ); - } - - Promise.resolve(pendingSearchResult).then(result => { - if (this.forceStop) { - // If we notify the listener the search result when the search is already - // cancelled, it corrupts the internal state of the listener. So we only - // reset the controller's state in this case. - if (isFormAutofillSearch) { - autocompleteController.resetInternalState(); - } - return; - } - - listener.onSearchResult(this, result); - // Don't save cache results or reset state when returning non-autofill results such as the - // form history fallback above. - if (isFormAutofillSearch) { - ProfileAutocomplete.lastProfileAutoCompleteResult = result; - // Reset AutoCompleteController's state at the end of startSearch to ensure that - // none of form autofill result will be cached in other places and make the - // result out of sync. - autocompleteController.resetInternalState(); - } else { - // Clear the cache so that we don't try to autofill from it after falling - // back to form history. - ProfileAutocomplete.lastProfileAutoCompleteResult = null; - } - }); - }, - - /** - * Stops an asynchronous search that is in progress - */ - stopSearch() { - ProfileAutocomplete.lastProfileAutoCompleteResult = null; - this.forceStop = true; - }, - - /** - * Get the records from parent process for AutoComplete result. - * - * @private - * @param {object} input - * Input element for autocomplete. - * @param {object} data - * Parameters for querying the corresponding result. - * @param {string} data.searchString - * The typed string for filtering out the matched records. - * @param {string} data.fieldName - * The identified field name for the input - * @returns {Promise} - * Promise that resolves when addresses returned from parent process. - */ - _getRecords(input, data) { - if (!input) { - return []; - } - - let actor = getActorFromWindow(input.ownerGlobal); - return actor.sendQuery("FormAutofill:GetRecords", { - scenarioName: lazy.FormScenarios.detect({ input }).signUpForm - ? "SignUpFormScenario" - : "", - ...data, - }); - }, -}; - export const ProfileAutocomplete = { QueryInterface: ChromeUtils.generateQI(["nsIObserver"]), - lastProfileAutoCompleteResult: null, - lastProfileAutoCompleteFocusedInput: null, _registered: false, - _factory: null, ensureRegistered() { if (this._registered) { @@ -308,8 +44,6 @@ export const ProfileAutocomplete = { this.log = lazy.FormAutofill.defineLogGetter(this, "ProfileAutocomplete"); this.debug("ensureRegistered"); - this._factory = new AutocompleteFactory(); - this._factory.register(AutofillProfileAutoCompleteSearch); this._registered = true; Services.obs.addObserver(this, "autocomplete-will-enter-text"); @@ -326,10 +60,7 @@ export const ProfileAutocomplete = { } this.debug("ensureUnregistered"); - this._factory.unregister(); - this._factory = null; this._registered = false; - this._lastAutoCompleteResult = null; Services.obs.removeObserver(this, "autocomplete-will-enter-text"); }, @@ -341,27 +72,14 @@ export const ProfileAutocomplete = { // The observer notification is for autocomplete in a different process. break; } - lazy.FormAutofillContent.autofillPending = true; - Services.obs.notifyObservers(null, "autofill-fill-starting"); await this._fillFromAutocompleteRow( lazy.FormAutofillContent.activeInput ); - Services.obs.notifyObservers(null, "autofill-fill-complete"); - lazy.FormAutofillContent.autofillPending = false; break; } } }, - _getSelectedIndex(contentWindow) { - let actor = getActorFromWindow(contentWindow, "AutoComplete"); - if (!actor) { - throw new Error("Invalid autocomplete selectedIndex"); - } - - return actor.selectedIndex; - }, - async _fillFromAutocompleteRow(focusedInput) { this.debug("_fillFromAutocompleteRow:", focusedInput); let formDetails = lazy.FormAutofillContent.activeFormDetails; @@ -369,20 +87,24 @@ export const ProfileAutocomplete = { // The observer notification is for a different frame. return; } + const actor = getActorFromWindow(focusedInput.ownerGlobal, "AutoComplete"); + if (!actor) { + throw new Error("Invalid autocomplete selectedIndex"); + } - let selectedIndex = this._getSelectedIndex(focusedInput.ownerGlobal); + const selectedIndex = actor.selectedIndex; + const lastProfileAutoCompleteResult = actor.lastProfileAutoCompleteResult; const validIndex = selectedIndex >= 0 && - selectedIndex < this.lastProfileAutoCompleteResult?.matchCount; + selectedIndex < lastProfileAutoCompleteResult?.matchCount; const comment = validIndex - ? this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex) + ? lastProfileAutoCompleteResult.getCommentAt(selectedIndex) : null; let profile = JSON.parse(comment); if ( selectedIndex == -1 || - !this.lastProfileAutoCompleteResult || - this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill" + lastProfileAutoCompleteResult?.getStyleAt(selectedIndex) != "autofill" ) { if ( focusedInput && @@ -400,42 +122,6 @@ export const ProfileAutocomplete = { ); } } - return; - } - - await lazy.FormAutofillContent.activeHandler.autofillFormFields(profile); - }, - - _clearProfilePreview() { - if ( - !this.lastProfileAutoCompleteFocusedInput || - !lazy.FormAutofillContent.activeSection - ) { - return; - } - - lazy.FormAutofillContent.activeSection.clearPreviewedFormFields(); - }, - - _previewSelectedProfile(selectedIndex) { - if ( - !lazy.FormAutofillContent.activeInput || - !lazy.FormAutofillContent.activeFormDetails - ) { - // The observer notification is for a different process/frame. - return; - } - - if ( - !this.lastProfileAutoCompleteResult || - this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill" - ) { - return; } - - let profile = JSON.parse( - this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex) - ); - lazy.FormAutofillContent.activeSection.previewFormFields(profile); }, }; diff --git a/toolkit/components/formautofill/FormAutofill.sys.mjs b/toolkit/components/formautofill/FormAutofill.sys.mjs index 8f50aad7bd..08b6acaee1 100644 --- a/toolkit/components/formautofill/FormAutofill.sys.mjs +++ b/toolkit/components/formautofill/FormAutofill.sys.mjs @@ -24,8 +24,8 @@ const ENABLED_AUTOFILL_ADDRESSES_SUPPORTED_COUNTRIES_PREF = "extensions.formautofill.addresses.supportedCountries"; const ENABLED_AUTOFILL_CREDITCARDS_PREF = "extensions.formautofill.creditCards.enabled"; -const ENABLED_AUTOFILL_CREDITCARDS_REAUTH_PREF = - "extensions.formautofill.reauth.enabled"; +const AUTOFILL_CREDITCARDS_REAUTH_PREF = + "extensions.formautofill.creditCards.reauth.optout"; const AUTOFILL_CREDITCARDS_HIDE_UI_PREF = "extensions.formautofill.creditCards.hideui"; const FORM_AUTOFILL_SUPPORT_RTL_PREF = "extensions.formautofill.supportRTL"; @@ -44,7 +44,7 @@ export const FormAutofill = { ENABLED_AUTOFILL_CAPTURE_ON_FORM_REMOVAL_PREF, ENABLED_AUTOFILL_CAPTURE_ON_PAGE_NAVIGATION_PREF, ENABLED_AUTOFILL_CREDITCARDS_PREF, - ENABLED_AUTOFILL_CREDITCARDS_REAUTH_PREF, + AUTOFILL_CREDITCARDS_REAUTH_PREF, AUTOFILL_CREDITCARDS_AUTOCOMPLETE_OFF_PREF, AUTOFILL_ADDRESSES_AUTOCOMPLETE_OFF_PREF, diff --git a/toolkit/components/formautofill/FormAutofillChild.sys.mjs b/toolkit/components/formautofill/FormAutofillChild.sys.mjs index af84459432..f45c962d2b 100644 --- a/toolkit/components/formautofill/FormAutofillChild.sys.mjs +++ b/toolkit/components/formautofill/FormAutofillChild.sys.mjs @@ -8,15 +8,18 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { + AddressResult: "resource://autofill/ProfileAutoCompleteResult.sys.mjs", AutoCompleteChild: "resource://gre/actors/AutoCompleteChild.sys.mjs", AutofillTelemetry: "resource://gre/modules/shared/AutofillTelemetry.sys.mjs", + CreditCardResult: "resource://autofill/ProfileAutoCompleteResult.sys.mjs", + GenericAutocompleteItem: "resource://gre/modules/FillHelpers.sys.mjs", + InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.sys.mjs", FormAutofill: "resource://autofill/FormAutofill.sys.mjs", FormAutofillContent: "resource://autofill/FormAutofillContent.sys.mjs", FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs", + FormScenarios: "resource://gre/modules/FormScenarios.sys.mjs", FormStateManager: "resource://gre/modules/shared/FormStateManager.sys.mjs", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", - ProfileAutocomplete: - "resource://autofill/AutofillProfileAutoComplete.sys.mjs", setTimeout: "resource://gre/modules/Timer.sys.mjs", FORM_SUBMISSION_REASON: "resource://gre/actors/FormHandlerChild.sys.mjs", }); @@ -94,6 +97,9 @@ const observer = { * Handles content's interactions for the frame. */ export class FormAutofillChild extends JSWindowActorChild { + // Flag indicating whether the form is waiting to be filled by Autofill. + #autofillPending = false; + constructor() { super(); @@ -104,9 +110,6 @@ export class FormAutofillChild extends JSWindowActorChild { this._hasDOMContentLoadedHandler = false; this._hasPendingTask = false; - // Flag indicating whether the form is waiting to be filled by Autofill. - this._autofillPending = false; - /** * @type {FormAutofillFieldDetailsManager} handling state management of current forms and handlers. */ @@ -473,14 +476,14 @@ export class FormAutofillChild extends JSWindowActorChild { this.unregisterProgressListener(); } - receiveMessage(message) { + async receiveMessage(message) { if (!lazy.FormAutofill.isAutofillEnabled) { return; } switch (message.name) { case "FormAutofill:PreviewProfile": { - this.previewProfile(message.data.selectedIndex); + this.previewProfile(message.data); break; } case "FormAutofill:ClearForm": { @@ -488,7 +491,7 @@ export class FormAutofillChild extends JSWindowActorChild { break; } case "FormAutofill:FillForm": { - this.activeHandler.autofillFormFields(message.data); + await this.autofillFields(message.data); break; } } @@ -610,7 +613,7 @@ export class FormAutofillChild extends JSWindowActorChild { this.debug("updateActiveElement: checking for popup-on-focus"); // We know this element just received focus. If it's a credit card field, // open its popup. - if (this._autofillPending) { + if (this.#autofillPending) { this.debug("updateActiveElement: skipping check; autofill is imminent"); } else if (element.value?.length !== 0) { this.debug( @@ -631,16 +634,8 @@ export class FormAutofillChild extends JSWindowActorChild { } } - set autofillPending(flag) { - this.debug("Setting autofillPending to", flag); - this._autofillPending = flag; - } - clearForm() { - let focusedInput = - this.activeInput || - lazy.ProfileAutocomplete._lastAutoCompleteFocusedInput; - if (!focusedInput) { + if (!this.activeSection) { return; } @@ -656,26 +651,41 @@ export class FormAutofillChild extends JSWindowActorChild { } } - previewProfile(selectedIndex) { - let lastAutoCompleteResult = - lazy.ProfileAutocomplete.lastProfileAutoCompleteResult; - let focusedInput = this.activeInput; + get lastProfileAutoCompleteResult() { + return this.manager.getActor("AutoComplete")?.lastProfileAutoCompleteResult; + } - if ( - selectedIndex === -1 || - !focusedInput || - !lastAutoCompleteResult || - lastAutoCompleteResult.getStyleAt(selectedIndex) != "autofill" - ) { - lazy.ProfileAutocomplete._clearProfilePreview(); + get lastProfileAutoCompleteFocusedInput() { + return this.manager.getActor("AutoComplete") + ?.lastProfileAutoCompleteFocusedInput; + } + + previewProfile(profile) { + if (profile && this.activeSection) { + const adaptedProfile = this.activeSection.getAdaptedProfiles([ + profile, + ])[0]; + this.activeSection.previewFormFields(adaptedProfile); } else { - lazy.ProfileAutocomplete._previewSelectedProfile(selectedIndex); + this.activeSection.clearPreviewedFormFields(); + } + } + + async autofillFields(profile) { + this.#autofillPending = true; + Services.obs.notifyObservers(null, "autofill-fill-starting"); + try { + Services.obs.notifyObservers(null, "autofill-fill-starting"); + await this.activeHandler.autofillFormFields(profile); + Services.obs.notifyObservers(null, "autofill-fill-complete"); + } finally { + this.#autofillPending = false; } } onPopupClosed() { this.debug("Popup has closed."); - lazy.ProfileAutocomplete._clearProfilePreview(); + this.activeSection?.clearPreviewedFormFields(); } onPopupOpened() { @@ -701,6 +711,149 @@ export class FormAutofillChild extends JSWindowActorChild { return; } - formFillController.markAsAutofillField(field); + this.manager + .getActor("AutoComplete") + ?.markAsAutoCompletableField(field, this); + } + + get actorName() { + return "FormAutofill"; + } + + /** + * Get the search options when searching for autocomplete entries in the parent + * + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @returns {object} the search options for the input + */ + getAutoCompleteSearchOption(input) { + const fieldDetail = this._fieldDetailsManager + ._getFormHandler(input) + ?.getFieldDetailByElement(input); + + const scenarioName = lazy.FormScenarios.detect({ input }).signUpForm + ? "SignUpFormScenario" + : ""; + return { fieldName: fieldDetail?.fieldName, scenarioName }; + } + + /** + * Ask the provider whether it might have autocomplete entry to show + * for the given input. + * + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @returns {boolean} true if we shold search for autocomplete entries + */ + shouldSearchForAutoComplete(input) { + const fieldDetail = this._fieldDetailsManager + ._getFormHandler(input) + ?.getFieldDetailByElement(input); + if (!fieldDetail) { + return false; + } + const fieldName = fieldDetail.fieldName; + const isAddressField = lazy.FormAutofillUtils.isAddressField(fieldName); + const searchPermitted = isAddressField + ? lazy.FormAutofill.isAutofillAddressesEnabled + : lazy.FormAutofill.isAutofillCreditCardsEnabled; + // If the specified autofill feature is pref off, do not search + if (!searchPermitted) { + return false; + } + + // No profile can fill the currently-focused input. + if (!lazy.FormAutofillContent.savedFieldNames.has(fieldName)) { + return false; + } + + // The current form has already been populated and the field is not + // an empty credit card field. + const isCreditCardField = + lazy.FormAutofillUtils.isCreditCardField(fieldName); + const isInputAutofilled = + this.activeHandler.getFilledStateByElement(input) == + lazy.FormAutofillUtils.FIELD_STATES.AUTO_FILLED; + const filledRecordGUID = this.activeSection.filledRecordGUID; + if ( + !isInputAutofilled && + filledRecordGUID && + !(isCreditCardField && this.activeInput.value === "") + ) { + return false; + } + + // (address only) less than 3 inputs are covered by all saved fields in the storage. + if ( + isAddressField && + this.activeSection.allFieldNames.filter(field => + lazy.FormAutofillContent.savedFieldNames.has(field) + ).length < lazy.FormAutofillUtils.AUTOFILL_FIELDS_THRESHOLD + ) { + return false; + } + + return true; + } + + /** + * Convert the search result to autocomplete results + * + * @param {string} searchString - The string to search for + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @param {Array} records - autocomplete records + * @returns {AutocompleteResult} + */ + searchResultToAutoCompleteResult(searchString, input, records) { + if (!records) { + return null; + } + + const entries = records.records; + const externalEntries = records.externalEntries; + + const fieldDetail = this._fieldDetailsManager + ._getFormHandler(input) + ?.getFieldDetailByElement(input); + if (!fieldDetail) { + return null; + } + + const adaptedRecords = this.activeSection.getAdaptedProfiles(entries); + const isSecure = lazy.InsecurePasswordUtils.isFormSecure( + this.activeHandler.form + ); + const isInputAutofilled = + this.activeHandler.getFilledStateByElement(input) == + lazy.FormAutofillUtils.FIELD_STATES.AUTO_FILLED; + const allFieldNames = this.activeSection.allFieldNames; + + const AutocompleteResult = lazy.FormAutofillUtils.isAddressField( + fieldDetail.fieldName + ) + ? lazy.AddressResult + : lazy.CreditCardResult; + + const acResult = new AutocompleteResult( + searchString, + fieldDetail.fieldName, + allFieldNames, + adaptedRecords, + { isSecure, isInputAutofilled } + ); + + acResult.externalEntries.push( + ...externalEntries.map( + entry => + new lazy.GenericAutocompleteItem( + entry.image, + entry.title, + entry.subtitle, + entry.fillMessageName, + entry.fillMessageData + ) + ) + ); + + return acResult; } } diff --git a/toolkit/components/formautofill/FormAutofillParent.sys.mjs b/toolkit/components/formautofill/FormAutofillParent.sys.mjs index 34dac8ce15..026801c83f 100644 --- a/toolkit/components/formautofill/FormAutofillParent.sys.mjs +++ b/toolkit/components/formautofill/FormAutofillParent.sys.mjs @@ -48,8 +48,11 @@ ChromeUtils.defineLazyGetter(lazy, "log", () => FormAutofill.defineLogGetter(lazy, "FormAutofillParent") ); -const { ENABLED_AUTOFILL_ADDRESSES_PREF, ENABLED_AUTOFILL_CREDITCARDS_PREF } = - FormAutofill; +const { + ENABLED_AUTOFILL_ADDRESSES_PREF, + ENABLED_AUTOFILL_CREDITCARDS_PREF, + AUTOFILL_CREDITCARDS_REAUTH_PREF, +} = FormAutofill; const { ADDRESSES_COLLECTION_NAME, CREDITCARDS_COLLECTION_NAME } = FormAutofillUtils; @@ -267,17 +270,8 @@ export class FormAutofillParent extends JSWindowActorParent { break; } case "FormAutofill:GetRecords": { - const relayPromise = lazy.FirefoxRelay.autocompleteItemsAsync({ - formOrigin: this.formOrigin, - scenarioName: data.scenarioName, - hasInput: !!data.searchString?.length, - }); - const recordsPromise = FormAutofillParent.getRecords(data); - const [records, externalEntries] = await Promise.all([ - recordsPromise, - relayPromise, - ]); - return { records, externalEntries }; + const records = await FormAutofillParent.getRecords(data); + return { records }; } case "FormAutofill:OnFormSubmit": { this.notifyMessageObservers("onFormSubmitted", data); @@ -291,7 +285,9 @@ export class FormAutofillParent extends JSWindowActorParent { } case "FormAutofill:GetDecryptedString": { let { cipherText, reauth } = data; - if (!FormAutofillUtils._reauthEnabledByUser) { + if ( + !FormAutofillUtils.getOSAuthEnabled(AUTOFILL_CREDITCARDS_REAUTH_PREF) + ) { lazy.log.debug("Reauth is disabled"); reauth = false; } @@ -327,7 +323,9 @@ export class FormAutofillParent extends JSWindowActorParent { break; } case "FormAutofill:SaveCreditCard": { - if (!(await FormAutofillUtils.ensureLoggedIn()).authenticated) { + // Setting the first parameter of OSKeyStore.ensurLoggedIn as false + // since this case only called in tests. Also the reason why we're not calling FormAutofill.verifyUserOSAuth. + if (!(await lazy.OSKeyStore.ensureLoggedIn(false)).authenticated) { lazy.log.warn("User canceled encryption login"); return undefined; } @@ -401,6 +399,43 @@ export class FormAutofillParent extends JSWindowActorParent { } } + /** + * Retrieves autocomplete entries for a given search string and data context. + * + * @param {string} searchString + * The search string used to filter autocomplete entries. + * @param {object} options + * @param {string} options.fieldName + * The name of the field for which autocomplete entries are being fetched. + * @param {string} options.scenarioName + * The scenario name used in the autocomplete operation to fetch external entries. + * @returns {Promise} A promise that resolves to an object containing two properties: `records` and `externalEntries`. + * `records` is an array of autofill records from the form's internal data, sorted by `timeLastUsed`. + * `externalEntries` is an array of external autocomplete items fetched based on the scenario. + */ + async searchAutoCompleteEntries(searchString, options) { + const { fieldName, scenarioName } = options; + const relayPromise = lazy.FirefoxRelay.autocompleteItemsAsync({ + formOrigin: this.formOrigin, + scenarioName, + hasInput: !!searchString?.length, + }); + + const recordsPromise = FormAutofillParent.getRecords({ + searchString, + fieldName, + }); + const [records, externalEntries] = await Promise.all([ + recordsPromise, + relayPromise, + ]); + + // Sort addresses by timeLastUsed for showing the lastest used address at top. + records.sort((a, b) => b.timeLastUsed - a.timeLastUsed); + + return { records, externalEntries }; + } + /** * Get the records from profile store and return results back to content * process. It will decrypt the credit card number and append @@ -668,4 +703,25 @@ export class FormAutofillParent extends JSWindowActorParent { return true; } + + previewFields(result) { + try { + const profile = + result.style == "autofill" ? JSON.parse(result.comment) : null; + this.sendAsyncMessage("FormAutofill:PreviewProfile", profile); + } catch (e) { + lazy.log.debug("Fail to get preview profile: ", e.message); + } + } + + autofillFields(result) { + if (result.style == "autofill") { + try { + const profile = JSON.parse(result.comment); + this.sendAsyncMessage("FormAutofill:FillForm", profile); + } catch (e) { + lazy.log.debug("Fail to get autofill profile."); + } + } + } } diff --git a/toolkit/components/formautofill/FormAutofillPreferences.sys.mjs b/toolkit/components/formautofill/FormAutofillPreferences.sys.mjs index 18937371b9..40438a128e 100644 --- a/toolkit/components/formautofill/FormAutofillPreferences.sys.mjs +++ b/toolkit/components/formautofill/FormAutofillPreferences.sys.mjs @@ -16,7 +16,6 @@ const MANAGE_CREDITCARDS_URL = import { FormAutofill } from "resource://autofill/FormAutofill.sys.mjs"; import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs"; -import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { @@ -25,13 +24,17 @@ ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineLazyGetter( lazy, "l10n", - () => new Localization(["browser/preferences/preferences.ftl"], true) + () => + new Localization( + ["branding/brand.ftl", "browser/preferences/preferences.ftl"], + true + ) ); const { ENABLED_AUTOFILL_ADDRESSES_PREF, ENABLED_AUTOFILL_CREDITCARDS_PREF, - ENABLED_AUTOFILL_CREDITCARDS_REAUTH_PREF, + AUTOFILL_CREDITCARDS_REAUTH_PREF, } = FormAutofill; const { MANAGE_ADDRESSES_L10N_IDS, @@ -267,7 +270,13 @@ FormAutofillPreferences.prototype = { reauthCheckbox.setAttribute( "label", - lazy.l10n.formatValueSync("autofill-reauth-checkbox") + lazy.l10n.formatValueSync("autofill-reauth-payment-methods-checkbox") + ); + + // If target.checked is checked, enable OSAuth. Otherwise, reset the pref value. + reauthCheckbox.setAttribute( + "checked", + FormAutofillUtils.getOSAuthEnabled(AUTOFILL_CREDITCARDS_REAUTH_PREF) ); reauthLearnMore.setAttribute( @@ -275,11 +284,6 @@ FormAutofillPreferences.prototype = { "credit-card-autofill#w_require-authentication-for-autofill" ); - // Manually set the checked state - if (FormAutofillUtils._reauthEnabledByUser) { - reauthCheckbox.setAttribute("checked", true); - } - reauthCheckboxGroup.setAttribute("align", "center"); reauthCheckboxGroup.setAttribute("flex", "1"); @@ -321,36 +325,31 @@ FormAutofillPreferences.prototype = { break; } - let messageTextId = "autofillReauthOSDialog"; - // We reuse the if/else order from wizard markup to increase - // odds of consistent behavior. - if (AppConstants.platform == "macosx") { - messageTextId += "Mac"; - } else if (AppConstants.platform == "linux") { - messageTextId += "Lin"; - } else { - messageTextId += "Win"; - } - - let messageText = this.bundle.GetStringFromName(messageTextId); - - const brandBundle = Services.strings.createBundle( - "chrome://branding/locale/brand.properties" + let messageText = await lazy.l10n.formatValueSync( + "autofill-creditcard-os-dialog-message" ); - let win = target.ownerGlobal.docShell.chromeEventHandler.ownerGlobal; - let loggedIn = await lazy.OSKeyStore.ensureLoggedIn( - messageText, - brandBundle.GetStringFromName("brandFullName"), - win, - false + let captionText = await lazy.l10n.formatValueSync( + "autofill-creditcard-os-auth-dialog-caption" ); - if (!loggedIn.authenticated) { + let win = target.ownerGlobal.docShell.chromeEventHandler.ownerGlobal; + // Calling OSKeyStore.ensureLoggedIn() instead of FormAutofillUtils.verifyOSAuth() + // since we want to authenticate user each time this stting is changed. + let isAuthorized = ( + await lazy.OSKeyStore.ensureLoggedIn( + messageText, + captionText, + win, + false + ) + ).authenticated; + if (!isAuthorized) { target.checked = !target.checked; break; } - Services.prefs.setBoolPref( - ENABLED_AUTOFILL_CREDITCARDS_REAUTH_PREF, + // If target.checked is checked, enable OSAuth. Otherwise, reset the pref value. + FormAutofillUtils.setOSAuthEnabled( + AUTOFILL_CREDITCARDS_REAUTH_PREF, target.checked ); } else if (target == this.refs.savedAddressesBtn) { diff --git a/toolkit/components/formautofill/Helpers.ios.mjs b/toolkit/components/formautofill/Helpers.ios.mjs index 83137331f1..0b83f84c2e 100644 --- a/toolkit/components/formautofill/Helpers.ios.mjs +++ b/toolkit/components/formautofill/Helpers.ios.mjs @@ -111,6 +111,11 @@ export const XPCOMUtils = withNotImplementedError({ defineLazyModuleGetters(obj, modules) { internalModuleResolvers.resolveModules(obj, modules); }, + defineLazyServiceGetter() { + // Don't do anything + // We need this for OS Auth fixes for formautofill. + // TODO(issam, Bug 1894967): Move os auth to separate module and remove this. + }, }); // eslint-disable-next-line no-shadow diff --git a/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs b/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs index 05dcf5bace..2a72f302fe 100644 --- a/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs +++ b/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs @@ -19,6 +19,7 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { CreditCard: "resource://gre/modules/CreditCard.sys.mjs", formAutofillStorage: "resource://autofill/FormAutofillStorage.sys.mjs", + OSKeyStore: "resource://gre/modules/OSKeyStore.sys.mjs", }); ChromeUtils.defineLazyGetter(lazy, "log", () => @@ -475,9 +476,29 @@ export class AddressSaveDoorhanger extends AutofillDoorhanger { ]; break; case "address": - data = ["address-level2", "address-level1", "postal-code"].map( - field => [field, this.oldRecord[field], this.newRecord[field]] - ); + data = [ + [ + "address-level2", + this.oldRecord["address-level2"], + this.newRecord["address-level2"], + ], + [ + "address-level1", + FormAutofillUtils.getAbbreviatedSubregionName( + this.oldRecord["address-level1"], + this.oldRecord.country + ) || this.oldRecord["address-level1"], + FormAutofillUtils.getAbbreviatedSubregionName( + this.newRecord["address-level1"], + this.newRecord.country + ) || this.newRecord["address-level1"], + ], + [ + "postal-code", + this.oldRecord["postal-code"], + this.newRecord["postal-code"], + ], + ]; break; case "name": case "country": @@ -1301,7 +1322,7 @@ export let FormAutofillPrompter = { return; } - if (!(await FormAutofillUtils.ensureLoggedIn()).authenticated) { + if (!(await lazy.OSKeyStore.ensureLoggedIn(false)).authenticated) { lazy.log.warn("User canceled encryption login"); return; } @@ -1338,7 +1359,6 @@ export let FormAutofillPrompter = { ); const { ownerGlobal: win } = browser; - await win.ensureCustomElements("moz-support-link"); win.MozXULElement.insertFTLIfNeeded( "toolkit/formautofill/formAutofill.ftl" ); diff --git a/toolkit/components/formautofill/shared/FormAutofillSection.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillSection.sys.mjs index 1a5b3014c9..aa4f795521 100644 --- a/toolkit/components/formautofill/shared/FormAutofillSection.sys.mjs +++ b/toolkit/components/formautofill/shared/FormAutofillSection.sys.mjs @@ -413,6 +413,7 @@ export class FormAutofillSection { profile[`${fieldDetail.fieldName}-formatted`] || profile[fieldDetail.fieldName] || ""; + if (HTMLSelectElement.isInstance(element)) { // Unlike text input, select element is always previewed even if // the option is already selected. diff --git a/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs index c2b48a53a3..b09f611db1 100644 --- a/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs +++ b/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs @@ -26,10 +26,19 @@ ChromeUtils.defineLazyGetter( ) ); +XPCOMUtils.defineLazyServiceGetter( + lazy, + "Crypto", + "@mozilla.org/login-manager/crypto/SDR;1", + "nsILoginManagerCrypto" +); + export let FormAutofillUtils; const ADDRESSES_COLLECTION_NAME = "addresses"; const CREDITCARDS_COLLECTION_NAME = "creditCards"; +const AUTOFILL_CREDITCARDS_REAUTH_PREF = + FormAutofill.AUTOFILL_CREDITCARDS_REAUTH_PREF; const MANAGE_ADDRESSES_L10N_IDS = [ "autofill-add-address-title", "autofill-manage-addresses-title", @@ -38,6 +47,7 @@ const EDIT_ADDRESS_L10N_IDS = [ "autofill-address-given-name", "autofill-address-additional-name", "autofill-address-family-name", + "autofill-address-name", "autofill-address-organization", "autofill-address-street", "autofill-address-state", @@ -48,6 +58,27 @@ const EDIT_ADDRESS_L10N_IDS = [ "autofill-address-postal-code", "autofill-address-email", "autofill-address-tel", + "autofill-edit-address-title", + "autofill-address-neighborhood", + "autofill-address-village-township", + "autofill-address-island", + "autofill-address-townland", + "autofill-address-district", + "autofill-address-county", + "autofill-address-post-town", + "autofill-address-suburb", + "autofill-address-parish", + "autofill-address-prefecture", + "autofill-address-area", + "autofill-address-do-si", + "autofill-address-department", + "autofill-address-emirate", + "autofill-address-oblast", + "autofill-address-pin", + "autofill-address-eircode", + "autofill-address-country-only", + "autofill-cancel-button", + "autofill-save-button", ]; const MANAGE_CREDITCARDS_L10N_IDS = [ "autofill-add-card-title", @@ -85,6 +116,7 @@ FormAutofillUtils = { ADDRESSES_COLLECTION_NAME, CREDITCARDS_COLLECTION_NAME, + AUTOFILL_CREDITCARDS_REAUTH_PREF, MANAGE_ADDRESSES_L10N_IDS, EDIT_ADDRESS_L10N_IDS, MANAGE_CREDITCARDS_L10N_IDS, @@ -146,12 +178,90 @@ FormAutofillUtils = { return ccNumber && lazy.CreditCard.isValidNumber(ccNumber); }, - ensureLoggedIn(promptMessage) { - return lazy.OSKeyStore.ensureLoggedIn( - this._reauthEnabledByUser && promptMessage ? promptMessage : false + /** + * Get the decrypted value for a string pref. + * + * @param {string} prefName -> The pref whose value is needed. + * @param {string} safeDefaultValue -> Value to be returned incase the pref is not yet set. + * @returns {string} + */ + getSecurePref(prefName, safeDefaultValue) { + try { + const encryptedValue = Services.prefs.getStringPref(prefName, ""); + return encryptedValue === "" + ? safeDefaultValue + : lazy.Crypto.decrypt(encryptedValue); + } catch { + return safeDefaultValue; + } + }, + + /** + * Set the pref to the encrypted form of the value. + * + * @param {string} prefName -> The pref whose value is to be set. + * @param {string} value -> The value to be set in its encrypted form. + */ + setSecurePref(prefName, value) { + if (value) { + const encryptedValue = lazy.Crypto.encrypt(value); + Services.prefs.setStringPref(prefName, encryptedValue); + } else { + Services.prefs.clearUserPref(prefName); + } + }, + + /** + * Get whether the OSAuth is enabled or not. + * + * @param {string} prefName -> The name of the pref (creditcards or addresses) + * @returns {boolean} + */ + getOSAuthEnabled(prefName) { + return ( + lazy.OSKeyStore.canReauth() && + this.getSecurePref(prefName, "") !== "opt out" ); }, + /** + * Set whether the OSAuth is enabled or not. + * + * @param {string} prefName -> The pref to encrypt. + * @param {boolean} enable -> Whether the pref is to be enabled. + */ + setOSAuthEnabled(prefName, enable) { + this.setSecurePref(prefName, enable ? null : "opt out"); + }, + + async verifyUserOSAuth( + prefName, + promptMessage, + captionDialog = "", + parentWindow = null, + generateKeyIfNotAvailable = true + ) { + if (!this.getOSAuthEnabled(prefName)) { + promptMessage = false; + } + try { + return ( + await lazy.OSKeyStore.ensureLoggedIn( + promptMessage, + captionDialog, + parentWindow, + generateKeyIfNotAvailable + ) + ).authenticated; + } catch (ex) { + // Since Win throws an exception whereas Mac resolves to false upon cancelling. + if (ex.result !== Cr.NS_ERROR_FAILURE) { + throw ex; + } + } + return false; + }, + /** * Get the array of credit card network ids ("types") we expect and offer as valid choices * @@ -636,7 +746,7 @@ FormAutofillUtils = { findSelectOption(selectEl, record, fieldName) { if (this.isAddressField(fieldName)) { - return this.findAddressSelectOption(selectEl, record, fieldName); + return this.findAddressSelectOption(selectEl.options, record, fieldName); } if (this.isCreditCardField(fieldName)) { return this.findCreditCardSelectOption(selectEl, record, fieldName); @@ -710,13 +820,13 @@ FormAutofillUtils = { * 3. Second pass try to identify values from address value and options, * and look for a match. * - * @param {DOMElement} selectEl + * @param {Array<{text: string, value: string}>} options * @param {object} address * @param {string} fieldName * @returns {DOMElement} */ - findAddressSelectOption(selectEl, address, fieldName) { - if (selectEl.options.length > 512) { + findAddressSelectOption(options, address, fieldName) { + if (options.length > 512) { // Allow enough space for all countries (roughly 300 distinct values) and all // timezones (roughly 400 distinct values), plus some extra wiggle room. return null; @@ -728,7 +838,7 @@ FormAutofillUtils = { let collators = this.getSearchCollators(address.country); - for (let option of selectEl.options) { + for (const option of options) { if ( this.strCompare(value, option.value, collators) || this.strCompare(value, option.text, collators) @@ -763,7 +873,7 @@ FormAutofillUtils = { "\\b" + this.escapeRegExp(identifiedValue) + "\\b", "i" ); - for (let option of selectEl.options) { + for (const option of options) { let optionValue = this.identifyValue( keys, names, @@ -789,7 +899,7 @@ FormAutofillUtils = { } case "country": { if (this.getCountryAddressData(value)) { - for (let option of selectEl.options) { + for (const option of options) { if ( this.identifyCountryCode(option.text, value) || this.identifyCountryCode(option.value, value) @@ -822,23 +932,13 @@ FormAutofillUtils = { * @returns {XULElement} */ findAddressSelectOptionWithMenuPopup(menupopup, address, fieldName) { - class MenuitemProxy { - constructor(menuitem) { - this.menuitem = menuitem; - } - get text() { - return this.menuitem.label; - } - get value() { - return this.menuitem.value; - } - } - const selectEl = { - options: Array.from(menupopup.childNodes).map( - menuitem => new MenuitemProxy(menuitem) - ), - }; - return this.findAddressSelectOption(selectEl, address, fieldName)?.menuitem; + const options = Array.from(menupopup.childNodes).map(menuitem => ({ + text: menuitem.label, + value: menuitem.value, + menuitem, + })); + + return this.findAddressSelectOption(options, address, fieldName)?.menuitem; }, findCreditCardSelectOption(selectEl, creditCard, fieldName) { @@ -1055,6 +1155,86 @@ FormAutofillUtils = { postalCodePattern: dataset.zip, }; }, + /** + * Converts a Map to an array of objects with `value` and `text` properties ( option like). + * + * @param {Map} optionsMap + * @returns {Array<{ value: string, text: string }>|null} + */ + optionsMapToArray(optionsMap) { + return optionsMap?.size + ? [...optionsMap].map(([value, text]) => ({ value, text })) + : null; + }, + + /** + * Get flattened form layout information of a given country + * TODO(Bug 1891730): Remove getFormFormat and use this instead. + * + * @param {object} record - An object containing at least the 'country' property. + * @returns {Array} Flattened array with the address fiels in order. + */ + getFormLayout(record) { + const formFormat = this.getFormFormat(record.country); + let fieldsInOrder = formFormat.fieldsOrder; + + // Add missing fields that are always present but not in the .fmt of addresses + // TODO: extend libaddress later to support this if possible + fieldsInOrder = [ + ...fieldsInOrder, + { + fieldId: "country", + options: this.optionsMapToArray(FormAutofill.countries), + required: true, + }, + { fieldId: "tel", type: "tel" }, + { fieldId: "email", type: "email" }, + ]; + + const addressLevel1Options = this.optionsMapToArray( + formFormat.addressLevel1Options + ); + + const addressLevel1SelectedValue = addressLevel1Options + ? this.findAddressSelectOption( + addressLevel1Options, + record, + "address-level1" + )?.value + : record["address-level1"]; + + for (const field of fieldsInOrder) { + const flattenedObject = { + fieldId: field.fieldId, + newLine: field.newLine, + l10nId: this.getAddressFieldL10nId(field.fieldId), + required: formFormat.countryRequiredFields.includes(field.fieldId), + value: record[field.fieldId] ?? "", + ...(field.fieldId === "street-address" && { + l10nId: "autofill-address-street", + multiline: true, + }), + ...(field.fieldId === "address-level1" && { + l10nId: formFormat.addressLevel1L10nId, + options: addressLevel1Options, + value: addressLevel1SelectedValue, + }), + ...(field.fieldId === "address-level2" && { + l10nId: formFormat.addressLevel2L10nId, + }), + ...(field.fieldId === "address-level3" && { + l10nId: formFormat.addressLevel3L10nId, + }), + ...(field.fieldId === "postal-code" && { + pattern: formFormat.postalCodePattern, + l10nId: formFormat.postalCodeL10nId, + }), + }; + Object.assign(field, flattenedObject); + } + + return fieldsInOrder; + }, getAddressFieldL10nId(type) { return "autofill-address-" + type.replace(/_/g, "-"); diff --git a/toolkit/components/glean/Cargo.toml b/toolkit/components/glean/Cargo.toml index ba563f514a..ff65f74143 100644 --- a/toolkit/components/glean/Cargo.toml +++ b/toolkit/components/glean/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "MPL-2.0" [dependencies] -glean = "59.0.0" +glean = "60.0.1" log = "0.4" nserror = { path = "../../../xpcom/rust/nserror" } nsstring = { path = "../../../xpcom/rust/nsstring" } diff --git a/toolkit/components/glean/api/Cargo.toml b/toolkit/components/glean/api/Cargo.toml index af507f499f..62e3477adb 100644 --- a/toolkit/components/glean/api/Cargo.toml +++ b/toolkit/components/glean/api/Cargo.toml @@ -9,7 +9,7 @@ license = "MPL-2.0" [dependencies] bincode = "1.0" chrono = "0.4.10" -glean = "59.0.0" +glean = "60.0.1" inherent = "1.0.0" log = "0.4" nsstring = { path = "../../../../xpcom/rust/nsstring", optional = true } diff --git a/toolkit/components/glean/api/src/common_test.rs b/toolkit/components/glean/api/src/common_test.rs index 46062736f2..1e02bfccf4 100644 --- a/toolkit/components/glean/api/src/common_test.rs +++ b/toolkit/components/glean/api/src/common_test.rs @@ -43,7 +43,7 @@ fn setup_glean(tempdir: Option) -> tempfile::TempDir { rate_limit: None, enable_event_timestamps: false, experimentation_id: None, - enable_internal_pings: true + enable_internal_pings: true, }; let client_info = glean::ClientInfoMetrics { diff --git a/toolkit/components/glean/api/src/private/ping.rs b/toolkit/components/glean/api/src/private/ping.rs index 7e03c1ff00..5defa9b5c6 100644 --- a/toolkit/components/glean/api/src/private/ping.rs +++ b/toolkit/components/glean/api/src/private/ping.rs @@ -31,6 +31,8 @@ impl Ping { send_if_empty: bool, precise_timestamps: bool, include_info_sections: bool, + enabled: bool, + schedules_pings: Vec, reason_codes: Vec, ) -> Self { if need_ipc() { @@ -42,6 +44,8 @@ impl Ping { send_if_empty, precise_timestamps, include_info_sections, + enabled, + schedules_pings, reason_codes, )) } @@ -105,7 +109,7 @@ mod test { // Smoke test for what should be the generated code. static PROTOTYPE_PING: Lazy = - Lazy::new(|| Ping::new("prototype", false, true, true, true, vec![])); + Lazy::new(|| Ping::new("prototype", false, true, true, true, true, vec![], vec![])); #[test] fn smoke_test_custom_ping() { diff --git a/toolkit/components/glean/bindings/GleanMetric.h b/toolkit/components/glean/bindings/GleanMetric.h index c6bf6b4066..f2b96d3cce 100644 --- a/toolkit/components/glean/bindings/GleanMetric.h +++ b/toolkit/components/glean/bindings/GleanMetric.h @@ -21,6 +21,8 @@ enum class ScalarID : uint32_t; namespace mozilla::glean { +typedef uint64_t TimerId; + class GleanMetric : public nsISupports, public nsWrapperCache { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS; diff --git a/toolkit/components/glean/bindings/jog/JOG.cpp b/toolkit/components/glean/bindings/jog/JOG.cpp index 56119cef0e..c5b2bad6b7 100644 --- a/toolkit/components/glean/bindings/jog/JOG.cpp +++ b/toolkit/components/glean/bindings/jog/JOG.cpp @@ -12,6 +12,7 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/glean/bindings/jog/jog_ffi_generated.h" #include "mozilla/Logging.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/StaticPrefs_telemetry.h" #include "mozilla/AppShutdown.h" #include "nsDirectoryServiceDefs.h" @@ -22,8 +23,7 @@ namespace mozilla::glean { -using mozilla::LogLevel; -static mozilla::LazyLogModule sLog("jog"); +static LazyLogModule sLog("jog"); // Storage // Thread Safety: Only used on the main thread. diff --git a/toolkit/components/glean/bindings/jog/src/lib.rs b/toolkit/components/glean/bindings/jog/src/lib.rs index b62e54f6e8..e1ea60b7ad 100644 --- a/toolkit/components/glean/bindings/jog/src/lib.rs +++ b/toolkit/components/glean/bindings/jog/src/lib.rs @@ -139,6 +139,8 @@ pub extern "C" fn jog_test_register_ping( send_if_empty: bool, precise_timestamps: bool, include_info_sections: bool, + enabled: bool, + schedules_pings: &ThinVec, reason_codes: &ThinVec, ) -> u32 { let ping_name = name.to_string(); @@ -146,12 +148,18 @@ pub extern "C" fn jog_test_register_ping( .iter() .map(|reason| reason.to_string()) .collect(); + let schedules_pings = schedules_pings + .iter() + .map(|ping| ping.to_string()) + .collect(); create_and_register_ping( ping_name, include_client_id, send_if_empty, precise_timestamps, include_info_sections, + enabled, + schedules_pings, reason_codes, ) .expect("Creation or registration of ping failed.") // permitted to panic in test-only method. @@ -163,6 +171,8 @@ fn create_and_register_ping( send_if_empty: bool, precise_timestamps: bool, include_info_sections: bool, + enabled: bool, + schedules_pings: Vec, reason_codes: Vec, ) -> Result> { let ns_name = nsCString::from(&ping_name); @@ -172,6 +182,8 @@ fn create_and_register_ping( send_if_empty, precise_timestamps, include_info_sections, + enabled, + schedules_pings, reason_codes, ); extern "C" { @@ -219,6 +231,8 @@ struct PingDefinitionData { send_if_empty: bool, precise_timestamps: bool, include_info_sections: bool, + enabled: bool, + schedules_pings: Option>, reason_codes: Option>, } @@ -266,6 +280,8 @@ pub extern "C" fn jog_load_jogfile(jogfile_path: &nsAString) -> bool { ping.send_if_empty, ping.precise_timestamps, ping.include_info_sections, + ping.enabled, + ping.schedules_pings.unwrap_or_else(Vec::new), ping.reason_codes.unwrap_or_else(Vec::new), ); } diff --git a/toolkit/components/glean/bindings/private/TimingDistribution.h b/toolkit/components/glean/bindings/private/TimingDistribution.h index ae4a796279..ecf8689fad 100644 --- a/toolkit/components/glean/bindings/private/TimingDistribution.h +++ b/toolkit/components/glean/bindings/private/TimingDistribution.h @@ -21,8 +21,6 @@ struct GleanDistributionData; namespace mozilla::glean { -typedef uint64_t TimerId; - namespace impl { class TimingDistributionMetric { public: diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/jog.py b/toolkit/components/glean/build_scripts/glean_parser_ext/jog.py index b42827989e..08418bbce5 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/jog.py +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/jog.py @@ -56,6 +56,8 @@ known_ping_args = [ "send_if_empty", "precise_timestamps", "include_info_sections", + "enabled", + "schedules_pings", "reason_codes", ] diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/run_glean_parser.py b/toolkit/components/glean/build_scripts/glean_parser_ext/run_glean_parser.py index bc9f09f0d3..436cca974c 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/run_glean_parser.py +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/run_glean_parser.py @@ -12,7 +12,7 @@ import cpp import jinja2 import jog import rust -from glean_parser import lint, parser, translate, util +from glean_parser import lint, metrics, parser, translate, util from mozbuild.util import FileAvoidWrite, memoize from util import generate_metric_ids @@ -189,6 +189,19 @@ def output_gifft_map(output_fd, probe_type, all_objs, cpp_fd): file=sys.stderr, ) sys.exit(1) + # We only support mirrors for lifetime: ping + # If you understand and are okay with how Legacy Telemetry has no + # mechanism to which to mirror non-ping lifetimes, + # you may use `no_lint: [GIFFT_NON_PING_LIFETIME]` + elif ( + metric.lifetime != metrics.Lifetime.ping + and "GIFFT_NON_PING_LIFETIME" not in metric.no_lint + ): + print( + f"Glean lifetime semantics are not mirrored. {category_name}.{metric.name}'s lifetime of {metric.lifetime} is not supported.", + file=sys.stderr, + ) + sys.exit(1) env = jinja2.Environment( loader=jinja2.PackageLoader("run_glean_parser", "templates"), diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/jog_factory.jinja2 b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/jog_factory.jinja2 index a31bdbabf0..ef2088bec4 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/jog_factory.jinja2 +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/jog_factory.jinja2 @@ -148,10 +148,12 @@ pub fn create_and_register_ping( send_if_empty: bool, precise_timestamps: bool, include_info_sections: bool, + enabled: bool, + schedules_pings: Vec, reason_codes: Vec, ) -> Result> { let ping_id = NEXT_PING_ID.fetch_add(1, Ordering::SeqCst); - let ping = Ping::new(ping_name, include_client_id, send_if_empty, precise_timestamps, include_info_sections, reason_codes); + let ping = Ping::new(ping_name, include_client_id, send_if_empty, precise_timestamps, include_info_sections, enabled, schedules_pings, reason_codes); assert!( __jog_metric_maps::PING_MAP.write()?.insert(ping_id.into(), ping).is_none(), "We should never insert a runtime ping with an already-used id." diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 index 5723ff5d58..3b29a0f252 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 @@ -20,10 +20,13 @@ Jinja2 template is not. Please file bugs! #} pub struct {{ name }} { {% for itemname, val in struct.properties.items() %} {% if val.type == "object" %} - pub {{itemname|snake_case}}: {{ name ~ "Item" ~ itemname|Camelize ~ "Object" }}, + #[serde(skip_serializing_if = "Option::is_none")] + pub {{itemname|snake_case}}: Option<{{ name ~ "Item" ~ itemname|Camelize ~ "Object" }}>, {% elif val.type == "array" %} + #[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")] pub {{itemname|snake_case}}: {{ name ~ "Item" ~ itemname|Camelize }}, {% else %} + #[serde(skip_serializing_if = "Option::is_none")] pub {{itemname|snake_case}}: Option<{{val.type|structure_type_name}}>, {% endif %} {% endfor %} diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust_pings.jinja2 b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust_pings.jinja2 index 8afdae61ae..1a95b8f25c 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust_pings.jinja2 +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust_pings.jinja2 @@ -21,6 +21,8 @@ pub static {{ obj.name|snake_case }}: Lazy = Lazy::new(|| { {{ obj.send_if_empty|rust }}, {{ obj.precise_timestamps|rust }}, {{ obj.include_info_sections|rust }}, + {{ obj.enabled|rust }}, + {{ obj.schedules_pings|rust }}, {{ obj.reason_codes|rust }}, ) }); diff --git a/toolkit/components/glean/build_scripts/mach_commands.py b/toolkit/components/glean/build_scripts/mach_commands.py index b8d270c088..627f9f3c37 100644 --- a/toolkit/components/glean/build_scripts/mach_commands.py +++ b/toolkit/components/glean/build_scripts/mach_commands.py @@ -15,56 +15,39 @@ GENERATED_HEADER = """ """ -@Command( - "data-review", - category="misc", - description="Generate a skeleton data review request form for a given bug's data", -) -@CommandArgument( - "bug", default=None, nargs="?", type=str, help="bug number or search pattern" -) -def data_review(command_context, bug=None): - # Get the metrics_index's list of metrics indices - # by loading the index as a module. - import sys - from os import path +DATA_REVIEW_HELP = """ +Beginning 2024-05-07[1], data reviews for projects in mozilla-central are now +conducted on Phabricator. Simply duplicate your bug URL from the `bugs` list to +the `data_reviews` list in your metrics and pings definitions, and push for code +review in the normal way[2]. - sys.path.append(path.join(path.dirname(__file__), path.pardir)) - from pathlib import Path +More details about this process can be found in the in-tree docs[3] and wiki[4]. - from glean_parser import data_review - from metrics_index import metrics_yamls +If you'd like to generate a Data Review Request template anyway (if, for +instance, you can't use Phabricator for your data review or you need a Data +Review Request to aid in a Sensitive Data Review process. Or you're just +curious), you can invoke glean_parser directly: - return data_review.generate( - bug, [Path(command_context.topsrcdir) / x for x in metrics_yamls] - ) +./mach python -m glean_parser data-review + +[1]: https://groups.google.com/a/mozilla.org/g/firefox-dev/c/7z-i6UhPoKY +[2]: https://firefox-source-docs.mozilla.org/contributing/index.html +[3]: https://firefox-source-docs.mozilla.org/contributing/data-review.html +[4]: https://wiki.mozilla.org/Data_Collection +""" @Command( - "perf-data-review", + "data-review", category="misc", - description="Generate a skeleton performance data review request form for a given bug's data", -) -@CommandArgument( - "bug", default=None, nargs="?", type=str, help="bug number or search pattern" + description="Describe how Data Review works in mozilla-central", ) -def perf_data_review(command_context, bug=None): - # Get the metrics_index's list of metrics indices - # by loading the index as a module. - import sys - from os import path +def data_review(command_context): + # Data Review happens in Phabricator now + # (https://groups.google.com/a/mozilla.org/g/firefox-dev/c/7z-i6UhPoKY) + # so explain how to do it. - sys.path.append(path.join(path.dirname(__file__), path.pardir)) - from metrics_index import metrics_yamls - - sys.path.append(path.dirname(__file__)) - from pathlib import Path - - import perf_data_review - - return perf_data_review.generate( - bug, [Path(command_context.topsrcdir) / x for x in metrics_yamls] - ) + print(DATA_REVIEW_HELP) @Command( diff --git a/toolkit/components/glean/docs/user/geckoview_streaming_migration.md b/toolkit/components/glean/docs/user/geckoview_streaming_migration.md deleted file mode 100644 index 6dede3e90e..0000000000 --- a/toolkit/components/glean/docs/user/geckoview_streaming_migration.md +++ /dev/null @@ -1,262 +0,0 @@ -# Migrating Telemetry Collected via Geckoview Streaming to Glean - -With Geckoview Streaming (GVST) having been deprecated, -this is a guide to migrating collections to [Glean][book-of-glean] -via [Firefox on Glean](../index.md). - -```{contents} -``` - -## Before we Begin - -You should familiarize yourself with the guide on -[Adding New Metrics to Firefox Desktop](./new_definitions_file.md). - -You should also read through the guide for -[Migrating Metrics from Legacy Telemetry to Glean](./migration.md). - -This guide assumes some basic familiarity with the above. -The [Glean book][book-of-glean] has a full API reference, as well. - -## Process - -There are 3 main steps: - -1. Move the metric definition and make necessary updates -2. Update the call to use the Glean API -3. Update the tests to use the Glean test API - -### Move and Update the Metric Definition - -Existing metrics that make use of the GVST will already have a fully specified YAML -entry that we will use as a starting point. -This is convenient, but we want to make some minor updates rather than take it fully as is. -At a minimum we need to move the definition out of the -[Geckoview metrics.yaml][gv-metrics-yaml] file and change from GVST to [GIFFT](./gifft.md). -It can go into whichever metrics.yaml file you feel is most appropriate. -If an appropriate one does not exist, create a new one [following this guide][new-yaml]. -Completely remove the metric definition from the Geckoview `metrics.yaml`. - -For all metric types other than `labeled counters` the first step is to change the key -of the `gecko_datapoint` entry to `telemetry_mirror`. -Next, update the value as per the rules outlined in the [GIFFT guide][telemetry-mirror-doc]. -This change is required to keep data flowing in the Legacy Telemetry version of the metric. -Doing so will ensure that downstream analyses do not break unintentionally. -It is not necessary to modify the [Histograms.json][histograms-json] or -[Scalars.yaml][scalars-yaml] file. - -To migrate `labeled counters` instead fully remove the `gecko_datapoint` entry. -Note that our overall treatment of this type is slightly different. - -Next add the bug that covers the migration to the `bugs` field. -Update the `description` field as well to indicate the metric used to be collected -via the Geckoview Streaming API. Other fields should be updated as makes sense. -For example, you may need to update the field for `notification_emails`. -Since you are not changing the collection a new data review is not necessary. -However, if you notice a metric is set to expire soon and it should continue to be collected, -complete a [data review renewal][dr-renewal] form. - -Do not change the name or metric type. -**If you need to change or one both you are creating a new collection.** - -### Update Calls to Use the Glean API - -The next step is to update the metric calls to the Glean API. -Fortunately, for the vast matjority of metricsthis is a 1:1 swapout, -or for `labeled counters` (which are `categorical histograms` in legacy) we add a second call. -We identify the Glean API, remove the old call, and put in its place the Glean call. -You can find a full API reference in the [Glean][book-of-glean], but we'll look at how to record -values for the types that have existing GVST metrics. - -One way to mentally organize the metrics is to break them into two groups, those that are set, -and those that are accumulated to. As when you use the Legacy Telemetry API for GVST, -they are invoked slightly differently. - -To record in C++, you need to include `#include "mozilla/glean/GleanMetrics.h"`. -In Javascript, it is extremely unlikely that you will not already have access to `Glean`. -If you do not, please reach out to a Data Collection Tools team member on -[the #glean:mozilla.org Matrix channel](https://chat.mozilla.org/#/room/#glean:mozilla.org). - -Let's try a few examples. - -#### Migrating a Set Value (string) in C++ - -Let's look at the case of the Graphics Adaptor Vendor ID. -This is a String, -and it's recorded via GVST in C++ - -GVST YAML entry (slightly truncated): - -```YAML -geckoview: - version: - description: > - The version of the Gecko engine, example: 74.0a1 - type: string - gecko_datapoint: gecko.version -``` - -And this is recorded: - -```CPP -Telemetry::ScalarSet(Telemetry::ScalarID::GECKO_VERSION, - NS_ConvertASCIItoUTF16(gAppData->version)); -``` - -To migrate this, let's update our YAML entry, again moving it out of the GVST -metrics.yaml into the most appropriate one: - -```YAML -geckoview: - version: - description: > - The version of the Gecko engine, example: 74.0a1 - (Migrated from geckoview.gfx.adapter.primary) - type: string - telemetry_mirror: GECKO_VERSION -``` - -Notice how we've checked all of our boxes: - -* Made sure our category makes sense -* Changed gecko_datapoint to telemetry_mirror -* Updated the description to note that it was migrated from another collection -* Kept the type identical. - -Now we can update our call: - -```CPP -mozilla::glean::geckoview::version.Set(nsDependentCString(gAppData->version)); -``` - -#### Migrating a Labeled Counter in C++ - -Let's look at probably the most complicated scenario, one where we need to accumulate -to a labeled collection. Because the glean `labeled counter` and legacy `categorical histogram` -type do not support GIFFT, we will add a second call. -Let's take a look at an elided version of how this would be done with GVST: - -```CPP -switch (aResult.as()) { - case NonDecoderResult::SizeOverflow: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::size_overflow); - return; - case NonDecoderResult::OutOfMemory: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::out_of_memory); - return; - case NonDecoderResult::PipeInitError: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::pipe_init_error); - return; -} -``` - -And we update it by adding a call with the FOG API: - -```CPP -switch (aResult.as()) { - case NonDecoderResult::SizeOverflow: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::size_overflow); - mozilla::glean::avif::decode_result.EnumGet(avif::DecodeResult::eSizeOverflow).Add(); - return; - case NonDecoderResult::OutOfMemory: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::out_of_memory); - mozilla::glean::avif::decode_result.EnumGet(avif::DecodeResult::eOutOfMemory).Add(); - return; - case NonDecoderResult::PipeInitError: - AccumulateCategorical(LABELS_AVIF_DECODE_RESULT::pipe_init_error); - mozilla::glean::avif::decode_result.EnumGet(avif::DecodeResult::ePipeInitError).Add(); - return; -} -``` - -#### Migrating an Accumulated Value (Histogram) in Javascript - -Javascript follows the same pattern. Consider the case when want to record the number -of uniqiue site origins. Here's the original JS implementation: - -```Javascript -let originCount = this.computeSiteOriginCount(aWindows, aIsGeckoView); -let histogram = Services.telemetry.getHistogramById( - "FX_NUMBER_OF_UNIQUE_SITE_ORIGINS_ALL_TABS", -); - -if (!this._lastRecordSiteOrigin) { - this._lastRecordSiteOrigin = currentTime; -} else if (currentTime >= this._lastRecordSiteOrigin + this.min_interval) { - this._lastRecordSiteOrigin = currentTime; - - histogram.add(originCount); -} -``` - -And here is the direct Glean version - -```Javascript -let originCount = this.computeSiteOriginCount(aWindows, aIsGeckoView); - -if (!this._lastRecordSiteOrigin) { - this._lastRecordSiteOrigin = currentTime; -} else if (currentTime >= this._lastRecordSiteOrigin + this.min_interval) { - this._lastRecordSiteOrigin = currentTime; - - Glean.tabs.uniqueSiteOriginsAllTabs.accumulateSamples([originCount]); -} - -``` - -Note that we don't have to call into Services to get the histogram object. - -### Update the tests to use the Glean test API - -The last piece is updating tests. If tests don't exist -(which is often the case since testing metrics collected via GVST can be challenging), -we recommend that you write them as the -[the Glean test API is quite straightforward](./instrumentation_tests.md). - -The main test method is `testGetValue()`. Returning to our earlier example of -Number of Unique Site Origins, in a Javascript test we can invoke: - -```Javascript -let result = Glean.tabs.uniqueSiteOriginsAllTabs.testGetValue(); - -// This collection is a histogram, we can check the sum for this test -Assert.equal(result.sum, 144); -``` - -If your collection is in a child process, it can be helpful to invoke -`await Services.fog.testFlushAllChildren();` - -If you wish to write a C++ test, `testGetValue()` is also our main method: - -```CPP -#include "mozilla/glean/GleanMetrics.h" - -ASSERT_EQ(1, - mozilla::glean::avif::image_decode_result - .EnumGet(avif::DecodeResult::eSizeOverflow) - .TestGetValue() - .unwrap() - .ref()); - -ASSERT_EQ(3, - mozilla::glean::avif::image_decode_result - .EnumGet(avif::DecodeResult::eOutOfMemory) - .TestGetValue() - .unwrap() - .ref()); - -ASSERT_EQ(0, - mozilla::glean::avif::image_decode_result - .EnumGet(avif::DecodeResult::ePipeInitError) - .TestGetValue() - .unwrap() - .ref()); -``` - -[book-of-glean]: https://mozilla.github.io/glean/book/index.html -[gv-metrics-yaml]: https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/geckoview/streaming/metrics.yaml -[histograms-json]: https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/Histograms.json -[scalars-yaml]: https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/Scalars.yaml -[new-yaml]: ./new_definitions_file.md#where-do-i-define-new-metrics-and-pings -[dr-renewal]: https://github.com/mozilla/data-review/blob/main/renewal_request.md -[telemetry-mirror-doc]: https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/gifft.html#the-telemetry-mirror-property-in-metrics-yaml diff --git a/toolkit/components/glean/docs/user/migration.md b/toolkit/components/glean/docs/user/migration.md index f3c86a182b..5743b488e6 100644 --- a/toolkit/components/glean/docs/user/migration.md +++ b/toolkit/components/glean/docs/user/migration.md @@ -138,7 +138,7 @@ So for a Histogram that records timing samples like this: ``` "GC_MS": { "record_in_processes": ["main", "content"], - "products": ["firefox", "geckoview_streaming"], + "products": ["firefox"], "alert_emails": ["dev-telemetry-gc-alerts@mozilla.org", "jcoppeard@mozilla.com"], "expires_in_version": "never", "releaseChannelCollection": "opt-out", @@ -259,7 +259,7 @@ So for a Histogram with artisinal samples like: ``` "CHECKERBOARD_SEVERITY": { "record_in_processes": ["main", "content", "gpu"], - "products": ["firefox", "fennec", "geckoview_streaming"], + "products": ["firefox"], "alert_emails": ["gfx-telemetry-alerts@mozilla.com", "botond@mozilla.com"], "bug_numbers": [1238040, 1539309, 1584109], "releaseChannelCollection": "opt-out", @@ -326,7 +326,7 @@ For example, for a Histogram of kind `categorical` like: ``` "AVIF_DECODE_RESULT": { "record_in_processes": ["main", "content"], - "products": ["firefox", "geckoview_streaming"], + "products": ["firefox"], "alert_emails": ["cchang@mozilla.com", "jbauman@mozilla.com"], "expires_in_version": "never", "releaseChannelCollection": "opt-out", @@ -560,7 +560,7 @@ gfx.display: - gfx-telemetry-alerts@mozilla.com - ktaeleman@mozilla.com products: - - 'geckoview_streaming' + - 'firefox' record_in_processes: - 'main' release_channel_collection: opt-out diff --git a/toolkit/components/glean/docs/user/ohttp.md b/toolkit/components/glean/docs/user/ohttp.md new file mode 100644 index 0000000000..ec73612db6 --- /dev/null +++ b/toolkit/components/glean/docs/user/ohttp.md @@ -0,0 +1,77 @@ +# Using Oblivious HTTP in Firefox on Glean + +[Oblivious HTTP (RFC 9458)][ohttp-spec] +is an Internet standard transport that permits a separation of privacy concerns. + +A client sending an HTTP(S) request necessarily exposes both +their network address and the request's contents to the destination server. +OHTTP allows, through the introduction of encapsulation and a relay, +for a system by which a third-party relay may learn only the network address and not the contents, +and the server may learn only the request contents and not the network address. + +This can be a useful risk mitigation for data collections we do not wish to associate with an IP address. + +## Can I use OHTTP for my Data? + +Any data collection that meets the following criteria can use OHTTP: +* Your data must be solely collected on Firefox Desktop + * At this time, no other Mozilla project supports OHTTP. +* Your data must be recorded via Glean. + * It is the sole data collection system at Mozilla that supports OHTTP. +* Your data must be in its own [custom ping][custom-ping-doc]. + * OHTTP is a transport-level decision and pings are Glean's transport payload. +* Your data (like all new or expanded data collections in Mozilla projects) + must have gone through [Data Collection Review][data-review]. + * If you're considering OHTTP it's likely because the data you intend to collect is sensitive. + That'll mean you'll probably specifically need to go through + [Sensitive Data Collection Review][sensitive-review]. +* Your data must not need to be associated with an id that is sent without OHTTP. + * This includes `client_id` and the Mozilla Accounts identifier. + The `client_id` and other fingerprinting information are explicitly excluded + from pings using OHTTP. + +## How can I use OHTTP for my Data? + +### Short Version: add two metadata fields to your ping definition + +Most simply, you opt a ping into using OHTTP by augmenting its +`pings.yaml` definition with these three lines: + +```yaml + metadata: + include_info_sections: false + use_ohttp: true +``` + +[Here is a convenience link to a searchfox search for `use_ohttp: true`][use-ohttp-searchfox] +if you'd like to see existing uses in tree. + +### Longer Version + +0. Ensure you've followed the necessary steps for + [adding new instrumentation to Firefox Desktop][new-instrumentation-doc]: + * Name your ping, + * Design and implement your instrumentation, + * Design and implement your ping submission schedule, + * Arrange for [data review][data-review] (probably [sensitive][sensitive-review]). +1. Augment your ping's definition in its `pings.yaml` with + `metadata.include_info_sections: false` and + `metadata.use_ohttp: true`: + * `include_info_sections: false` ensures that there is no + `client_id` or fingerprintable pieces of `client_info` or `ping_info` + fields that would allow us to trivially map this ping to a specific client. + * `use_ohttp: true` signals to Firefox on Glean's (FOG's) `glean_parser` extensions to + generate the necessary code to recognize this ping as needing OHTTP transport. + It is read in FOG's uploader to ensure the ping is only sent using OHTTP. +2. [Test your instrumentation][instrumentation-tests]. + +And that's it! + + +[ohttp-spec]: https://datatracker.ietf.org/doc/rfc9458/ +[custom-ping-doc]: https://mozilla.github.io/glean/book/reference/pings/index.html +[data-review]: https://wiki.mozilla.org/Data_Collection +[sensitive-review]: https://wiki.mozilla.org/Data_Collection#Step_3:_Sensitive_Data_Collection_Review_Process +[use-ohttp-searchfox]: https://searchfox.org/mozilla-central/search?q=use_ohttp%3A%20true +[new-instrumentation-doc]: ./new_definitions_file.md +[instrumentation-tests]: ./instrumentation_tests.md diff --git a/toolkit/components/glean/metrics_index.py b/toolkit/components/glean/metrics_index.py index 28759a15fa..3390f711ab 100644 --- a/toolkit/components/glean/metrics_index.py +++ b/toolkit/components/glean/metrics_index.py @@ -35,6 +35,7 @@ gecko_metrics = [ "netwerk/protocol/http/metrics.yaml", "security/certverifier/metrics.yaml", "security/manager/ssl/metrics.yaml", + "toolkit/components/antitracking/bouncetrackingprotection/metrics.yaml", "toolkit/components/cookiebanners/metrics.yaml", "toolkit/components/extensions/metrics.yaml", "toolkit/components/formautofill/metrics.yaml", @@ -67,6 +68,7 @@ firefox_desktop_metrics = [ "browser/components/urlbar/metrics.yaml", "browser/modules/metrics.yaml", "dom/media/platforms/wmf/metrics.yaml", + "toolkit/components/contentrelevancy/metrics.yaml", "toolkit/components/crashes/metrics.yaml", "toolkit/components/nimbus/metrics.yaml", "toolkit/components/search/metrics.yaml", @@ -128,6 +130,7 @@ firefox_desktop_pings = [ "browser/components/pocket/pings.yaml", "browser/components/search/pings.yaml", "browser/components/urlbar/pings.yaml", + "browser/modules/pings.yaml", "toolkit/components/crashes/pings.yaml", "toolkit/components/resistfingerprinting/pings.yaml", "toolkit/components/telemetry/pings.yaml", diff --git a/toolkit/components/glean/src/lib.rs b/toolkit/components/glean/src/lib.rs index b682f43066..6c9af50183 100644 --- a/toolkit/components/glean/src/lib.rs +++ b/toolkit/components/glean/src/lib.rs @@ -197,12 +197,12 @@ pub extern "C" fn fog_test_get_experiment_data( /// /// See [`glean_core::Glean::set_metrics_disabled_config`]. #[no_mangle] -pub extern "C" fn fog_set_metrics_feature_config(config_json: &nsACString) { +pub extern "C" fn fog_apply_server_knobs_config(config_json: &nsACString) { // Normalize null and empty strings to a stringified empty map if config_json == "null" || config_json.is_empty() { - glean::glean_set_metrics_enabled_config("{}".to_owned()); + glean::glean_apply_server_knobs_config("{}".to_owned()); } - glean::glean_set_metrics_enabled_config(config_json.to_string()); + glean::glean_apply_server_knobs_config(config_json.to_string()); } /// Performs Glean tasks when client state changes to inactive diff --git a/toolkit/components/glean/tags.yaml b/toolkit/components/glean/tags.yaml index c935371b28..2313eda344 100644 --- a/toolkit/components/glean/tags.yaml +++ b/toolkit/components/glean/tags.yaml @@ -9,6 +9,8 @@ --- $schema: moz://mozilla.org/schemas/glean/tags/1-0-0 +'Application Services :: Relevancy': + description: The Bugzilla component which applies to this object. 'Cloud Services :: Firefox: Common': description: The Bugzilla component which applies to this object. 'Conduit :: mots': diff --git a/toolkit/components/glean/tests/pytest/jogfile_output b/toolkit/components/glean/tests/pytest/jogfile_output index 510b4995c5..7456bb1ffd 100644 --- a/toolkit/components/glean/tests/pytest/jogfile_output +++ b/toolkit/components/glean/tests/pytest/jogfile_output @@ -25,7 +25,7 @@ [ "metrics" ], - "application", + "ping", false, { "bucket_count": 100, @@ -129,7 +129,7 @@ [ "metrics" ], - "application", + "ping", false, { "memory_unit": "kilobyte" @@ -180,7 +180,7 @@ [ "metrics" ], - "application", + "ping", false, { "time_unit": "nanosecond" @@ -313,6 +313,8 @@ false, true, true, + true, + [], [ "background", "dirty_startup", @@ -325,6 +327,8 @@ true, true, true, + true, + [], [] ], [ @@ -333,6 +337,8 @@ false, true, true, + true, + [], [ "background", "max_capacity", @@ -345,6 +351,8 @@ false, true, true, + true, + [], [ "overdue", "reschedule", @@ -359,6 +367,8 @@ true, true, false, + true, + [], [] ] ] diff --git a/toolkit/components/glean/tests/pytest/metrics_test.yaml b/toolkit/components/glean/tests/pytest/metrics_test.yaml index 6d9a4f8c0e..2bdcd1877f 100644 --- a/toolkit/components/glean/tests/pytest/metrics_test.yaml +++ b/toolkit/components/glean/tests/pytest/metrics_test.yaml @@ -6,11 +6,6 @@ # automatically converted to platform-specific code at build time using the # `glean_parser` PyPI package. -# This file is presently for Internal FOG Use Only. -# You should not add metrics here until probably about January of 2021. -# If you're looking for the metrics.yaml for Geckoveiw Streaming Telemetry, -# you can find that one in toolkit/components/telemetry/geckoview/streaming. - --- $schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 @@ -29,6 +24,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_BOOL_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME labeled_boolean_metric: type: labeled_boolean @@ -44,6 +41,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_KEYED_BOOL_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME labeled_boolean_metric_labels: type: labeled_boolean @@ -70,6 +69,8 @@ test: - nine_labels - ten_labels telemetry_mirror: SOME_OTHER_KEYED_BOOL_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME counter_metric: type: counter @@ -85,6 +86,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_UINT_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME labeled_counter_metric: type: labeled_counter @@ -100,6 +103,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_KEYED_UINT_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME labeled_counter_metric_labels: type: labeled_counter @@ -118,6 +123,8 @@ test: - one_label - two_labels telemetry_mirror: SOME_OTHER_KEYED_UINT_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME string_metric: type: string @@ -133,6 +140,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_STRING_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME labeled_string_metric: type: labeled_string @@ -179,6 +188,8 @@ test: data_reviews: - https://example.com telemetry_mirror: YET_ANOTHER_KEYED_BOOL_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME text_metric: type: text @@ -209,6 +220,8 @@ test: data_reviews: - https://example.com telemetry_mirror: SOME_OTHER_UINT_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME timing_distribution_metric: type: timing_distribution @@ -216,7 +229,6 @@ test: description: | A multi-line description - lifetime: application notification_emails: - glean-team@mozilla.com bugs: @@ -231,7 +243,6 @@ test: description: | A multi-line description - lifetime: application notification_emails: - glean-team@mozilla.com bugs: @@ -247,7 +258,6 @@ test: description: | A multi-line description - lifetime: application notification_emails: - glean-team@mozilla.com bugs: @@ -275,6 +285,8 @@ test.nested: data_reviews: - https://example.com telemetry_mirror: SOME_OTHER_STRING_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME datetime_metric: type: datetime @@ -290,6 +302,8 @@ test.nested: data_reviews: - https://example.com telemetry_mirror: SOME_STILL_OTHER_STRING_SCALAR + no_lint: + - GIFFT_NON_PING_LIFETIME event_metric: type: event diff --git a/toolkit/components/glean/tests/pytest/metrics_test_output b/toolkit/components/glean/tests/pytest/metrics_test_output index 0f93eb032d..79a1b487fa 100644 --- a/toolkit/components/glean/tests/pytest/metrics_test_output +++ b/toolkit/components/glean/tests/pytest/metrics_test_output @@ -62,7 +62,7 @@ pub mod test { name: "custom_distribution_metric".into(), category: "test".into(), send_in_pings: vec!["metrics".into()], - lifetime: Lifetime::Application, + lifetime: Lifetime::Ping, disabled: false, ..Default::default() }, 0, 100, 100, HistogramType::Linear) @@ -270,7 +270,7 @@ pub mod test { name: "memory_distribution_metric".into(), category: "test".into(), send_in_pings: vec!["metrics".into()], - lifetime: Lifetime::Application, + lifetime: Lifetime::Ping, disabled: false, ..Default::default() }, MemoryUnit::Kilobyte) @@ -350,7 +350,7 @@ pub mod test { name: "timing_distribution_metric".into(), category: "test".into(), send_in_pings: vec!["metrics".into()], - lifetime: Lifetime::Application, + lifetime: Lifetime::Ping, disabled: false, ..Default::default() }, TimeUnit::Nanosecond) @@ -373,7 +373,9 @@ pub mod test_nested { #[derive(Debug, Hash, Eq, PartialEq, ::glean::traits::__serde::Serialize, ::glean::traits::__serde::Deserialize)] #[serde(deny_unknown_fields)] pub struct AnObjectObjectItem { + #[serde(skip_serializing_if = "Option::is_none")] pub colour: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub diameter: Option, } diff --git a/toolkit/components/glean/tests/pytest/pings_test_output b/toolkit/components/glean/tests/pytest/pings_test_output index 97c0793b1f..7214cd1756 100644 --- a/toolkit/components/glean/tests/pytest/pings_test_output +++ b/toolkit/components/glean/tests/pytest/pings_test_output @@ -21,6 +21,8 @@ pub static not_baseline: Lazy = Lazy::new(|| { false, true, true, + true, + vec![], vec!["background".into(), "dirty_startup".into(), "foreground".into()], ) }); @@ -38,6 +40,8 @@ pub static not_deletion_request: Lazy = Lazy::new(|| { true, true, true, + true, + vec![], vec![], ) }); @@ -53,6 +57,8 @@ pub static not_events: Lazy = Lazy::new(|| { false, true, true, + true, + vec![], vec!["background".into(), "max_capacity".into(), "startup".into()], ) }); @@ -72,6 +78,8 @@ pub static not_metrics: Lazy = Lazy::new(|| { false, true, true, + true, + vec![], vec!["overdue".into(), "reschedule".into(), "today".into(), "tomorrow".into(), "upgrade".into()], ) }); @@ -85,6 +93,8 @@ pub static not_ohttp: Lazy = Lazy::new(|| { true, true, false, + true, + vec![], vec![], ) }); diff --git a/toolkit/components/glean/tests/test_metrics.yaml b/toolkit/components/glean/tests/test_metrics.yaml index 47587241b1..3db601610d 100644 --- a/toolkit/components/glean/tests/test_metrics.yaml +++ b/toolkit/components/glean/tests/test_metrics.yaml @@ -423,6 +423,42 @@ test_only: diameter: type: number + crash_stack: + type: object + description: A not-real crash stack + bugs: + - https://bugzilla.mozilla.org/1839640 + data_reviews: + - http://example.com/reviews + notification_emails: + - CHANGE-ME@example.com + expires: never + structure: + type: object + properties: + status: + type: string + main_module: + type: number + crash_info: + type: object + properties: + typ: + type: string + address: + type: string + crashing_thread: + type: number + modules: + type: array + items: + type: object + properties: + base_addr: + type: string + end_addr: + type: string + test_only.ipc: a_counter: type: counter diff --git a/toolkit/components/glean/tests/xpcshell/test_Glean.js b/toolkit/components/glean/tests/xpcshell/test_Glean.js index 18b450a69b..f5661f91b6 100644 --- a/toolkit/components/glean/tests/xpcshell/test_Glean.js +++ b/toolkit/components/glean/tests/xpcshell/test_Glean.js @@ -514,7 +514,7 @@ add_task(async function test_fog_object_works() { let expected = [ { colour: "red", diameter: 5 }, { colour: "blue", diameter: 7 }, - { colour: "orange", diameter: null }, + { colour: "orange" }, ]; Assert.deepEqual(expected, result); @@ -528,10 +528,10 @@ add_task(async function test_fog_object_works() { Glean.testOnly.balloons.set(balloons); result = Glean.testOnly.balloons.testGetValue(); expected = [ - { colour: "inf", diameter: null }, - { colour: "negative-inf", diameter: null }, - { colour: "nan", diameter: null }, - { colour: "undef", diameter: null }, + { colour: "inf" }, + { colour: "negative-inf" }, + { colour: "nan" }, + { colour: "undef" }, ]; Assert.deepEqual(expected, result); @@ -562,3 +562,69 @@ add_task(async function test_fog_object_works() { "Should throw because last object was invalid." ); }); + +add_task(async function test_fog_complex_object_works() { + if (!Glean.testOnly.crashStack) { + // FIXME(bug 1883857): object metric type not available, e.g. in artifact builds. + // Skipping this test. + return; + } + + Assert.equal( + undefined, + Glean.testOnly.crashStack.testGetValue(), + "No object stored" + ); + + Glean.testOnly.crashStack.set({}); + let result = Glean.testOnly.crashStack.testGetValue(); + Assert.deepEqual({}, result); + + let stack = { + status: "OK", + crash_info: { + typ: "main", + address: "0xf001ba11", + crashing_thread: 1, + }, + main_module: 0, + modules: [ + { + base_addr: "0x00000000", + end_addr: "0x00004000", + }, + ], + }; + + Glean.testOnly.crashStack.set(stack); + result = Glean.testOnly.crashStack.testGetValue(); + Assert.deepEqual(stack, result); + + stack = { + status: "OK", + modules: [ + { + base_addr: "0x00000000", + end_addr: "0x00004000", + }, + ], + }; + Glean.testOnly.crashStack.set(stack); + result = Glean.testOnly.crashStack.testGetValue(); + Assert.deepEqual(stack, result); + + stack = { + status: "OK", + modules: [], + }; + Glean.testOnly.crashStack.set(stack); + result = Glean.testOnly.crashStack.testGetValue(); + Assert.deepEqual({ status: "OK" }, result); + + stack = { + status: "OK", + }; + Glean.testOnly.crashStack.set(stack); + result = Glean.testOnly.crashStack.testGetValue(); + Assert.deepEqual(stack, result); +}); diff --git a/toolkit/components/glean/tests/xpcshell/test_GleanServerKnobs.js b/toolkit/components/glean/tests/xpcshell/test_GleanServerKnobs.js index 31ed262798..6b36d74ec4 100644 --- a/toolkit/components/glean/tests/xpcshell/test_GleanServerKnobs.js +++ b/toolkit/components/glean/tests/xpcshell/test_GleanServerKnobs.js @@ -21,9 +21,11 @@ add_task(function test_fog_metrics_disabled_remotely() { // Create and set a feature configuration that disables the test metric. const feature_config = { - "test_only.cheesy_string": false, + metrics_enabled: { + "test_only.cheesy_string": false, + }, }; - Services.fog.setMetricsFeatureConfig(JSON.stringify(feature_config)); + Services.fog.applyServerKnobsConfig(JSON.stringify(feature_config)); // Attempt to set another cheesy string in the test metric. This should not // record because of the override to the metric's default value in the @@ -49,10 +51,12 @@ add_task(function test_fog_multiple_metrics_disabled_remotely() { // Create and set a feature configuration that disables multiple test // metrics. var feature_config = { - "test_only.cheesy_string": false, - "test_only.meaning_of_life": false, + metrics_enabled: { + "test_only.cheesy_string": false, + "test_only.meaning_of_life": false, + }, }; - Services.fog.setMetricsFeatureConfig(JSON.stringify(feature_config)); + Services.fog.applyServerKnobsConfig(JSON.stringify(feature_config)); // Attempt to set the metrics again. This should not record because of the // override to the metrics' default value in the feature configuration. @@ -65,10 +69,12 @@ add_task(function test_fog_multiple_metrics_disabled_remotely() { // Change the feature configuration to re-enable the `cheesy_string` metric. feature_config = { - "test_only.cheesy_string": true, - "test_only.meaning_of_life": false, + metrics_enabled: { + "test_only.cheesy_string": true, + "test_only.meaning_of_life": false, + }, }; - Services.fog.setMetricsFeatureConfig(JSON.stringify(feature_config)); + Services.fog.applyServerKnobsConfig(JSON.stringify(feature_config)); // Attempt to set the metrics again. This should only record `cheesy_string` // because of the most recent feature configuration. @@ -101,9 +107,11 @@ add_task(function test_fog_metrics_feature_config_api_handles_null_values() { // Create and set a feature configuration that disables the test metric. const feature_config = { - "test_only.cheesy_string": false, + metrics_enabled: { + "test_only.cheesy_string": false, + }, }; - Services.fog.setMetricsFeatureConfig(JSON.stringify(feature_config)); + Services.fog.applyServerKnobsConfig(JSON.stringify(feature_config)); // Attempt to set another cheesy string in the test metric. This should not // record because of the override to the metric's default value in the @@ -113,7 +121,7 @@ add_task(function test_fog_metrics_feature_config_api_handles_null_values() { Assert.equal(str1, Glean.testOnly.cheesyString.testGetValue("test-ping")); // Set the configuration to `null`. - Services.fog.setMetricsFeatureConfig(null); + Services.fog.applyServerKnobsConfig(null); // Attempt to set another cheesy string in the test metric. This should now // record because `null` doesn't change already existing configuration. @@ -122,7 +130,7 @@ add_task(function test_fog_metrics_feature_config_api_handles_null_values() { // Set the configuration to `""` to replicate getting an empty string from // Nimbus. - Services.fog.setMetricsFeatureConfig(""); + Services.fog.applyServerKnobsConfig(""); // Attempt to set another cheesy string in the test metric. This should now // record again because `""` doesn't change already existing configuration. @@ -140,9 +148,11 @@ add_task(function test_fog_metrics_disabled_reset_fog_behavior() { // Create and set a feature configuration that disables the test metric. const feature_config = { - "test_only.cheesy_string": false, + metrics_enabled: { + "test_only.cheesy_string": false, + }, }; - Services.fog.setMetricsFeatureConfig(JSON.stringify(feature_config)); + Services.fog.applyServerKnobsConfig(JSON.stringify(feature_config)); // Attempt to set another cheesy string in the test metric. This should not // record because of the override to the metric's default value in the diff --git a/toolkit/components/glean/tests/xpcshell/test_JOG.js b/toolkit/components/glean/tests/xpcshell/test_JOG.js index 00f3ded135..2017d7a52e 100644 --- a/toolkit/components/glean/tests/xpcshell/test_JOG.js +++ b/toolkit/components/glean/tests/xpcshell/test_JOG.js @@ -289,7 +289,16 @@ add_task(async function test_jog_custom_pings() { `"ping"`, false ); - Services.fog.testRegisterRuntimePing("jog-ping", true, true, true, true, []); + Services.fog.testRegisterRuntimePing( + "jog-ping", + true, + true, + true, + true, + true, + [], + [] + ); Assert.ok("jogPing" in GleanPings); let submitted = false; Glean.jogCat.jogPingBool.set(false); @@ -639,9 +648,16 @@ add_task(function test_jog_dotted_categories_work() { add_task(async function test_jog_ping_works() { const kReason = "reason-1"; - Services.fog.testRegisterRuntimePing("my-ping", true, true, true, true, [ - kReason, - ]); + Services.fog.testRegisterRuntimePing( + "my-ping", + true, + true, + true, + true, + true, + [], + [kReason] + ); let submitted = false; GleanPings.myPing.testBeforeNextSubmit(reason => { submitted = true; @@ -653,9 +669,16 @@ add_task(async function test_jog_ping_works() { add_task(async function test_jog_noinfo_ping_works() { const kReason = "reason-1"; - Services.fog.testRegisterRuntimePing("noinfo-ping", true, true, true, false, [ - kReason, - ]); + Services.fog.testRegisterRuntimePing( + "noinfo-ping", + true, + true, + true, + false, + true, + [], + [kReason] + ); let submitted = false; GleanPings.noinfoPing.testBeforeNextSubmit(reason => { submitted = true; diff --git a/toolkit/components/glean/xpcom/FOG.cpp b/toolkit/components/glean/xpcom/FOG.cpp index 955f2511b6..1517bd0597 100644 --- a/toolkit/components/glean/xpcom/FOG.cpp +++ b/toolkit/components/glean/xpcom/FOG.cpp @@ -11,7 +11,6 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/Promise.h" #include "mozilla/FOGIPC.h" -#include "mozilla/browser/NimbusFeatures.h" #include "mozilla/glean/bindings/Common.h" #include "mozilla/glean/bindings/jog/jog_ffi_generated.h" #include "mozilla/glean/fog_ffi_generated.h" @@ -119,8 +118,7 @@ extern "C" bool FOG_TooLateToSend(void) { // This allows us to pass the configurable maximum ping limit (in pings per // minute) to Rust. Default value is 15. extern "C" uint32_t FOG_MaxPingLimit(void) { - return NimbusFeatures::GetInt("gleanInternalSdk"_ns, - "gleanMaxPingsPerMinute"_ns, 15); + return Preferences::GetInt("telemetry.glean.internal.maxPingsPerMinute", 15); } // Called when knowing if we're in automation is necessary. @@ -134,8 +132,8 @@ FOG::InitializeFOG(const nsACString& aDataPathOverride, gInitializeCalled = true; RunOnShutdown( [&] { - if (NimbusFeatures::GetBool("gleanInternalSdk"_ns, "finalInactive"_ns, - false)) { + if (Preferences::GetBool("telemetry.glean.internal.finalInactive", + false)) { glean::impl::fog_internal_glean_handle_client_inactive(); } }, @@ -314,14 +312,14 @@ FOG::TestGetExperimentData(const nsACString& aExperimentId, JSContext* aCx, } NS_IMETHODIMP -FOG::SetMetricsFeatureConfig(const nsACString& aJsonConfig) { +FOG::ApplyServerKnobsConfig(const nsACString& aJsonConfig) { #ifdef MOZ_GLEAN_ANDROID NS_WARNING( "Don't set metric feature configs from Gecko in Android. Ignoring."); return NS_OK; #else MOZ_ASSERT(XRE_IsParentProcess()); - glean::impl::fog_set_metrics_feature_config(&aJsonConfig); + glean::impl::fog_apply_server_knobs_config(&aJsonConfig); return NS_OK; #endif } @@ -410,17 +408,16 @@ FOG::TestRegisterRuntimeMetric( } NS_IMETHODIMP -FOG::TestRegisterRuntimePing(const nsACString& aName, - const bool aIncludeClientId, - const bool aSendIfEmpty, - const bool aPreciseTimestamps, - const bool aIncludeInfoSections, - const nsTArray& aReasonCodes, - uint32_t* aPingIdOut) { +FOG::TestRegisterRuntimePing( + const nsACString& aName, const bool aIncludeClientId, + const bool aSendIfEmpty, const bool aPreciseTimestamps, + const bool aIncludeInfoSections, const bool aEnabled, + const nsTArray& aSchedulesPings, + const nsTArray& aReasonCodes, uint32_t* aPingIdOut) { *aPingIdOut = 0; *aPingIdOut = glean::jog::jog_test_register_ping( &aName, aIncludeClientId, aSendIfEmpty, aPreciseTimestamps, - aIncludeInfoSections, &aReasonCodes); + aIncludeInfoSections, aEnabled, &aSchedulesPings, &aReasonCodes); return NS_OK; } diff --git a/toolkit/components/glean/xpcom/nsIFOG.idl b/toolkit/components/glean/xpcom/nsIFOG.idl index 67041d6228..86409b2f6d 100644 --- a/toolkit/components/glean/xpcom/nsIFOG.idl +++ b/toolkit/components/glean/xpcom/nsIFOG.idl @@ -113,7 +113,7 @@ interface nsIFOG : nsISupports * {metric_base_identifier: boolean,} * which may contain multiple metric object entries. */ - void setMetricsFeatureConfig(in ACString aJsonConfig); + void applyServerKnobsConfig(in ACString aJsonConfig); /** * ** Test-only Method ** @@ -184,6 +184,7 @@ interface nsIFOG : nsISupports * @param aSendIfEmpty - Whether the ping should send even if empty. * @param aIncludeInfoSections - Whether the ping should include * {client|ping}_info sections. + * TODO(jer): docs * @param aReasonCodes - The list of valid reasons for ping submission. */ uint32_t testRegisterRuntimePing(in ACString aName, @@ -191,5 +192,7 @@ interface nsIFOG : nsISupports in boolean aSendIfEmpty, in boolean aPreciseTimestamps, in boolean aIncludeInfoSections, + in boolean aEnabled, + in Array aSchedulesPings, in Array aReasonCodes); }; diff --git a/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi b/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi index 685458db0e..88e994b3bd 100644 --- a/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi +++ b/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi @@ -205,7 +205,7 @@ Section "MaintenanceService" ; These keys are used to bypass the installation dir is a valid installation ; check from the service so that tests can be run. WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation" - WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert SHA2 Assured ID Code Signing CA" + WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1" WriteRegStr HKLM "${FallbackKey}\1" "name" "Mozilla Fake SPC" WriteRegStr HKLM "${FallbackKey}\1" "issuer" "Mozilla Fake CA" ${If} ${RunningX64} diff --git a/toolkit/components/messaging-system/schemas/TriggerActionSchemas/index.md b/toolkit/components/messaging-system/schemas/TriggerActionSchemas/index.md index 45df09249a..30a6ddc975 100644 --- a/toolkit/components/messaging-system/schemas/TriggerActionSchemas/index.md +++ b/toolkit/components/messaging-system/schemas/TriggerActionSchemas/index.md @@ -53,6 +53,7 @@ let patterns: string[]; * [cookieBannerDetected](#cookiebannerdetected) * [cookieBannerHandled](#cookiebannerhandled) * [messagesLoaded](#messagesloaded) +* [pageActionInUrlbar](#pageactioninurlbar) ### `openArticleURL` diff --git a/toolkit/components/messaging-system/schemas/index.rst b/toolkit/components/messaging-system/schemas/index.rst index 957dd06c3a..182e33ca52 100644 --- a/toolkit/components/messaging-system/schemas/index.rst +++ b/toolkit/components/messaging-system/schemas/index.rst @@ -174,7 +174,7 @@ Triggers and actions .. _make_schemas_script: https://searchfox.org/mozilla-central/source/browser/components/asrouter/content-src/schemas/make-schemas.py .. _jsonschema_bundling: https://json-schema.org/understanding-json-schema/structuring.html#bundling -.. _make_schemas_check: https://searchfox.org/mozilla-central/source/taskcluster/ci/source-test/python.yml#425-438 +.. _make_schemas_check: https://searchfox.org/mozilla-central/source/taskcluster/kinds/source-test/python.yml#425-438 .. _Experimenter: https://experimenter.info diff --git a/toolkit/components/ml/actors/MLEngineChild.sys.mjs b/toolkit/components/ml/actors/MLEngineChild.sys.mjs index 925ce59266..17a8b3511a 100644 --- a/toolkit/components/ml/actors/MLEngineChild.sys.mjs +++ b/toolkit/components/ml/actors/MLEngineChild.sys.mjs @@ -21,6 +21,8 @@ ChromeUtils.defineESModuleGetters(lazy, { BasePromiseWorker: "resource://gre/modules/PromiseWorker.sys.mjs", setTimeout: "resource://gre/modules/Timer.sys.mjs", clearTimeout: "resource://gre/modules/Timer.sys.mjs", + ModelHub: "chrome://global/content/ml/ModelHub.sys.mjs", + PipelineOptions: "chrome://global/content/ml/EngineProcess.sys.mjs", }); ChromeUtils.defineLazyGetter(lazy, "console", () => { @@ -32,9 +34,20 @@ ChromeUtils.defineLazyGetter(lazy, "console", () => { XPCOMUtils.defineLazyPreferenceGetter( lazy, - "loggingLevel", - "browser.ml.logLevel" + "CACHE_TIMEOUT_MS", + "browser.ml.modelCacheTimeout" ); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MODEL_HUB_ROOT_URL", + "browser.ml.modelHubRootUrl" +); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "MODEL_HUB_URL_TEMPLATE", + "browser.ml.modelHubUrlTemplate" +); +XPCOMUtils.defineLazyPreferenceGetter(lazy, "LOG_LEVEL", "browser.ml.logLevel"); /** * The engine child is responsible for the life cycle and instantiation of the local @@ -52,10 +65,21 @@ export class MLEngineChild extends JSWindowActorChild { async receiveMessage({ name, data }) { switch (name) { case "MLEngine:NewPort": { - const { engineName, port, timeoutMS } = data; + const { port, pipelineOptions } = data; + + // Override some options using prefs + let options = new lazy.PipelineOptions(pipelineOptions); + + options.updateOptions({ + modelHubRootUrl: lazy.MODEL_HUB_ROOT_URL, + modelHubUrlTemplate: lazy.MODEL_HUB_URL_TEMPLATE, + timeoutMS: lazy.CACHE_TIMEOUT_MS, + logLevel: lazy.LOG_LEVEL, + }); + this.#engineDispatchers.set( - engineName, - new EngineDispatcher(this, port, engineName, timeoutMS) + options.taskName, + new EngineDispatcher(this, port, options) ); break; } @@ -78,12 +102,23 @@ export class MLEngineChild extends JSWindowActorChild { } /** - * @returns {ArrayBuffer} + * Gets the wasm array buffer from RemoteSettings. + * + * @returns {Promise} */ getWasmArrayBuffer() { return this.sendQuery("MLEngine:GetWasmArrayBuffer"); } + /** + * Gets the inference options from RemoteSettings. + * + * @returns {Promise} + */ + getInferenceOptions(taskName) { + return this.sendQuery(`MLEngine:GetInferenceOptions:${taskName}`); + } + /** * @param {string} engineName */ @@ -113,28 +148,45 @@ class EngineDispatcher { #engine = null; /** @type {string} */ - #engineName; + #taskName; + + /** Creates the inference engine given the wasm runtime and the run options. + * + * The initialization is done in three steps: + * 1. The wasm runtime is fetched from RS + * 2. The inference options are fetched from RS and augmented with the pipeline options. + * 3. The inference engine is created with the wasm runtime and the options. + * + * Any exception here will be bubbled up for the constructor to log. + * + * @param {PipelineOptions} pipelineOptions + * @returns {Promise} + */ + async initializeInferenceEngine(pipelineOptions) { + // Create the inference engine given the wasm runtime and the options. + const wasm = await this.mlEngineChild.getWasmArrayBuffer(); + const inferenceOptions = await this.mlEngineChild.getInferenceOptions( + this.#taskName + ); + lazy.console.debug("Inference engine options:", inferenceOptions); + pipelineOptions.updateOptions(inferenceOptions); + + return InferenceEngine.create(wasm, pipelineOptions); + } /** * @param {MLEngineChild} mlEngineChild * @param {MessagePort} port - * @param {string} engineName - * @param {number} timeoutMS + * @param {PipelineOptions} pipelineOptions */ - constructor(mlEngineChild, port, engineName, timeoutMS) { - /** @type {MLEngineChild} */ + constructor(mlEngineChild, port, pipelineOptions) { this.mlEngineChild = mlEngineChild; + this.#taskName = pipelineOptions.taskName; + this.timeoutMS = pipelineOptions.timeoutMS; - /** @type {number} */ - this.timeoutMS = timeoutMS; - - this.#engineName = engineName; - - this.#engine = Promise.all([ - this.mlEngineChild.getWasmArrayBuffer(), - this.getModel(port), - ]).then(([wasm, model]) => FakeEngine.create(wasm, model)); + this.#engine = this.initializeInferenceEngine(pipelineOptions); + // Trigger the keep alive timer. this.#engine .then(() => void this.keepAlive()) .catch(error => { @@ -265,20 +317,61 @@ class EngineDispatcher { port.close(); } this.#ports = new Set(); - this.mlEngineChild.removeEngine(this.#engineName); + this.mlEngineChild.removeEngine(this.#taskName); try { const engine = await this.#engine; engine.terminate(); } catch (error) { - console.error("Failed to get the engine", error); + lazy.console.error("Failed to get the engine", error); } } } +let modelHub = null; // This will hold the ModelHub instance to reuse it. + +/** + * Retrieves a model file as an ArrayBuffer from the specified URL. + * This function normalizes the URL, extracts the organization, model name, and file path, + * then fetches the model file using the ModelHub API. The `modelHub` instance is created + * only once and reused for subsequent calls to optimize performance. + * + * @param {string} url - The URL of the model file to fetch. Can be a path relative to + * the model hub root or an absolute URL. + * @returns {Promise} A promise that resolves to a Meta object containing the URL, response headers, + * and data as an ArrayBuffer. The data is marked for transfer to avoid cloning. + */ +async function getModelFile(url) { + // Create the model hub instance if needed + if (!modelHub) { + lazy.console.debug("Creating model hub instance"); + modelHub = new lazy.ModelHub({ + rootUrl: lazy.MODEL_HUB_ROOT_URL, + urlTemplate: lazy.MODEL_HUB_URL_TEMPLATE, + }); + } + + if (url.startsWith(lazy.MODEL_HUB_ROOT_URL)) { + url = url.slice(lazy.MODEL_HUB_ROOT_URL.length); + // Make sure we get a front slash + if (!url.startsWith("/")) { + url = `/${url}`; + } + } + + // Parsing url to get model name, and file path. + // if this errors out, it will be caught in the worker + const parsedUrl = modelHub.parseUrl(url); + + let [data, headers] = await modelHub.getModelFileAsArrayBuffer(parsedUrl); + return new lazy.BasePromiseWorker.Meta([url, headers, data], { + transfers: [data], + }); +} + /** - * Fake the engine by slicing the text in half. + * Wrapper around the ChromeWorker that runs the inference. */ -class FakeEngine { +class InferenceEngine { /** @type {BasePromiseWorker} */ #worker; @@ -286,21 +379,22 @@ class FakeEngine { * Initialize the worker. * * @param {ArrayBuffer} wasm - * @param {ArrayBuffer} model - * @returns {FakeEngine} + * @param {PipelineOptions} pipelineOptions + * @returns {InferenceEngine} */ - static async create(wasm, model) { + static async create(wasm, pipelineOptions) { /** @type {BasePromiseWorker} */ const worker = new lazy.BasePromiseWorker( "chrome://global/content/ml/MLEngine.worker.mjs", - { type: "module" } + { type: "module" }, + { getModelFile } ); - const args = [wasm, model, lazy.loggingLevel]; + const args = [wasm, pipelineOptions]; const closure = {}; - const transferables = [wasm, model]; + const transferables = [wasm]; await worker.post("initializeEngine", args, closure, transferables); - return new FakeEngine(worker); + return new InferenceEngine(worker); } /** diff --git a/toolkit/components/ml/actors/MLEngineParent.sys.mjs b/toolkit/components/ml/actors/MLEngineParent.sys.mjs index 05203e5f69..65941d9d4e 100644 --- a/toolkit/components/ml/actors/MLEngineParent.sys.mjs +++ b/toolkit/components/ml/actors/MLEngineParent.sys.mjs @@ -5,6 +5,7 @@ /** * @typedef {object} Lazy * @property {typeof console} console + * @property {typeof import("../content/Utils.sys.mjs").getRuntimeWasmFilename} getRuntimeWasmFilename * @property {typeof import("../content/EngineProcess.sys.mjs").EngineProcess} EngineProcess * @property {typeof import("../../../../services/settings/remote-settings.sys.mjs").RemoteSettings} RemoteSettings * @property {typeof import("../../translations/actors/TranslationsParent.sys.mjs").TranslationsParent} TranslationsParent @@ -21,16 +22,14 @@ ChromeUtils.defineLazyGetter(lazy, "console", () => { }); ChromeUtils.defineESModuleGetters(lazy, { + getRuntimeWasmFilename: "chrome://global/content/ml/Utils.sys.mjs", EngineProcess: "chrome://global/content/ml/EngineProcess.sys.mjs", RemoteSettings: "resource://services-settings/remote-settings.sys.mjs", TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs", }); -/** - * @typedef {import("../../translations/translations").WasmRecord} WasmRecord - */ - -const DEFAULT_CACHE_TIMEOUT_MS = 15_000; +const RS_RUNTIME_COLLECTION = "ml-onnx-runtime"; +const RS_INFERENCE_OPTIONS_COLLECTION = "ml-inference-options"; /** * The ML engine is in its own content process. This actor handles the @@ -40,9 +39,9 @@ export class MLEngineParent extends JSWindowActorParent { /** * The RemoteSettingsClient that downloads the wasm binaries. * - * @type {RemoteSettingsClient | null} + * @type {Record} */ - static #remoteClient = null; + static #remoteClients = {}; /** @type {Promise | null} */ static #wasmRecord = null; @@ -61,11 +60,11 @@ export class MLEngineParent extends JSWindowActorParent { /** * Remote settings isn't available in tests, so provide mocked responses. * - * @param {RemoteSettingsClient} remoteClient + * @param {RemoteSettingsClient} remoteClients */ - static mockRemoteSettings(remoteClient) { + static mockRemoteSettings(remoteClients) { lazy.console.log("Mocking remote settings in MLEngineParent."); - MLEngineParent.#remoteClient = remoteClient; + MLEngineParent.#remoteClients = remoteClients; MLEngineParent.#wasmRecord = null; } @@ -74,24 +73,49 @@ export class MLEngineParent extends JSWindowActorParent { */ static removeMocks() { lazy.console.log("Removing mocked remote client in MLEngineParent."); - MLEngineParent.#remoteClient = null; + MLEngineParent.#remoteClients = {}; MLEngineParent.#wasmRecord = null; } - /** - * @param {string} engineName - * @param {() => Promise} getModel - * @param {number} cacheTimeoutMS - How long the engine cache remains alive between - * uses, in milliseconds. In automation the engine is manually created and destroyed - * to avoid timing issues. + /** Creates a new MLEngine. + * + * @param {PipelineOptions} pipelineOptions * @returns {MLEngine} */ - getEngine(engineName, getModel, cacheTimeoutMS = DEFAULT_CACHE_TIMEOUT_MS) { - return new MLEngine(this, engineName, getModel, cacheTimeoutMS); + getEngine(pipelineOptions) { + return new MLEngine({ mlEngineParent: this, pipelineOptions }); + } + + /** Extracts the task name from the name and validates it. + * + * Throws an exception if the task name is invalid. + * + * @param {string} name + * @returns {string} + */ + nameToTaskName(name) { + // Extract taskName after the specific prefix + const taskName = name.split("MLEngine:GetInferenceOptions:")[1]; + + // Define a regular expression to verify taskName pattern (alphanumeric and underscores/dashes) + const validTaskNamePattern = /^[a-zA-Z0-9_\-]+$/; + + // Check if taskName matches the pattern + if (!validTaskNamePattern.test(taskName)) { + // Handle invalid taskName, e.g., throw an error or return null + throw new Error( + "Invalid task name. Task name should contain only alphanumeric characters and underscores/dashes." + ); + } + return taskName; } // eslint-disable-next-line consistent-return async receiveMessage({ name }) { + if (name.startsWith("MLEngine:GetInferenceOptions")) { + return MLEngineParent.getInferenceOptions(this.nameToTaskName(name)); + } + switch (name) { case "MLEngine:Ready": if (lazy.EngineProcess.resolveMLEngineParent) { @@ -112,19 +136,18 @@ export class MLEngineParent extends JSWindowActorParent { } } - /** + /** Gets the wasm file from remote settings. + * * @param {RemoteSettingsClient} client */ static async #getWasmArrayRecord(client) { - // Load the wasm binary from remote settings, if it hasn't been already. - lazy.console.log(`Getting remote wasm records.`); + const wasmFilename = lazy.getRuntimeWasmFilename(this.browsingContext); /** @type {WasmRecord[]} */ const wasmRecords = await lazy.TranslationsParent.getMaxVersionRecords( client, { - // TODO - This record needs to be created with the engine wasm payload. - filters: { name: "inference-engine" }, + filters: { name: wasmFilename }, majorVersion: MLEngineParent.WASM_MAJOR_VERSION, } ); @@ -142,20 +165,47 @@ export class MLEngineParent extends JSWindowActorParent { ); } const [record] = wasmRecords; - lazy.console.log( - `Using ${record.name}@${record.release} release version ${record.version} first released on Fx${record.fx_release}`, - record - ); + lazy.console.log(`Using runtime ${record.name}@${record.version}`, record); return record; } + /** Gets the inference options from remote settings given a task name. + * + * @type {string} taskName - name of the inference :wtask + * @returns {Promise} + */ + static async getInferenceOptions(taskName) { + const client = MLEngineParent.#getRemoteClient( + RS_INFERENCE_OPTIONS_COLLECTION + ); + const records = await client.get({ + filters: { + taskName, + }, + }); + + if (records.length === 0) { + throw new Error(`No inference options found for task ${taskName}`); + } + const options = records[0]; + return { + modelRevision: options.modelRevision, + modelId: options.modelId, + tokenizerRevision: options.tokenizerRevision, + tokenizerId: options.tokenizerId, + processorRevision: options.processorRevision, + processorId: options.processorId, + runtimeFilename: lazy.getRuntimeWasmFilename(this.browsingContext), + }; + } + /** * Download the wasm for the ML inference engine. * * @returns {Promise} */ static async getWasmArrayBuffer() { - const client = MLEngineParent.#getRemoteClient(); + const client = MLEngineParent.#getRemoteClient(RS_RUNTIME_COLLECTION); if (!MLEngineParent.#wasmRecord) { // Place the records into a promise to prevent any races. @@ -184,20 +234,23 @@ export class MLEngineParent extends JSWindowActorParent { /** * Lazily initializes the RemoteSettingsClient for the downloaded wasm binary data. * + * @param {string} collectionName - The name of the collection to use. * @returns {RemoteSettingsClient} */ - static #getRemoteClient() { - if (MLEngineParent.#remoteClient) { - return MLEngineParent.#remoteClient; + static #getRemoteClient(collectionName) { + if (MLEngineParent.#remoteClients[collectionName]) { + return MLEngineParent.#remoteClients[collectionName]; } /** @type {RemoteSettingsClient} */ - const client = lazy.RemoteSettings("ml-wasm"); + const client = lazy.RemoteSettings(collectionName, { + bucketName: "main", + }); - MLEngineParent.#remoteClient = client; + MLEngineParent.#remoteClients[collectionName] = client; client.on("sync", async ({ data: { created, updated, deleted } }) => { - lazy.console.log(`"sync" event for ml-wasm`, { + lazy.console.log(`"sync" event for ${collectionName}`, { created, updated, deleted, @@ -228,17 +281,6 @@ export class MLEngineParent extends JSWindowActorParent { } } -/** - * This contains all of the information needed to perform a translation request. - * - * @typedef {object} TranslationRequest - * @property {Node} node - * @property {string} sourceText - * @property {boolean} isHTML - * @property {Function} resolve - * @property {Function} reject - */ - /** * The interface to communicate to an MLEngine in the parent process. The engine manages * its own lifetime, and is kept alive with a timeout. A reference to this engine can @@ -271,21 +313,13 @@ class MLEngine { engineStatus = "uninitialized"; /** - * @param {MLEngineParent} mlEngineParent - * @param {string} engineName - * @param {() => Promise} getModel - * @param {number} timeoutMS + * @param {object} config - The configuration object for the instance. + * @param {object} config.mlEngineParent - The parent machine learning engine associated with this instance. + * @param {object} config.pipelineOptions - The options for configuring the pipeline associated with this instance. */ - constructor(mlEngineParent, engineName, getModel, timeoutMS) { - /** @type {MLEngineParent} */ + constructor({ mlEngineParent, pipelineOptions }) { this.mlEngineParent = mlEngineParent; - /** @type {string} */ - this.engineName = engineName; - /** @type {() => Promise} */ - this.getModel = getModel; - /** @type {number} */ - this.timeoutMS = timeoutMS; - + this.pipelineOptions = pipelineOptions; this.#setupPortCommunication(); } @@ -296,14 +330,12 @@ class MLEngine { const { port1: childPort, port2: parentPort } = new MessageChannel(); const transferables = [childPort]; this.#port = parentPort; - this.#port.onmessage = this.handlePortMessage; this.mlEngineParent.sendAsyncMessage( "MLEngine:NewPort", { port: childPort, - engineName: this.engineName, - timeoutMS: this.timeoutMS, + pipelineOptions: this.pipelineOptions.getOptions(), }, transferables ); @@ -393,11 +425,20 @@ class MLEngine { const resolvers = Promise.withResolvers(); const requestId = this.#nextRequestId++; this.#requests.set(requestId, resolvers); - this.#port.postMessage({ - type: "EnginePort:Run", - requestId, - request, - }); + + let transferables = []; + if (request.data instanceof ArrayBuffer) { + transferables.push(request.data); + } + + this.#port.postMessage( + { + type: "EnginePort:Run", + requestId, + request, + }, + transferables + ); return resolvers.promise; } } diff --git a/toolkit/components/ml/content/EngineProcess.sys.mjs b/toolkit/components/ml/content/EngineProcess.sys.mjs index 36a9381192..0fe6403cc8 100644 --- a/toolkit/components/ml/content/EngineProcess.sys.mjs +++ b/toolkit/components/ml/content/EngineProcess.sys.mjs @@ -2,10 +2,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +// known to be loaded early in the startup process, and should be loaded eagerly +import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; + const lazy = {}; -ChromeUtils.defineESModuleGetters(lazy, { - HiddenFrame: "resource://gre/modules/HiddenFrame.sys.mjs", -}); +ChromeUtils.defineESModuleGetters( + lazy, + { + HiddenFrame: "resource://gre/modules/HiddenFrame.sys.mjs", + }, + { global: "current" } +); /** * @typedef {import("../actors/MLEngineParent.sys.mjs").MLEngineParent} MLEngineParent @@ -15,6 +22,172 @@ ChromeUtils.defineESModuleGetters(lazy, { * @typedef {import("../../translations/actors/TranslationsEngineParent.sys.mjs").TranslationsEngineParent} TranslationsEngineParent */ +/** + * This class encapsulates the options for a pipeline process. + */ +export class PipelineOptions { + /** + * The name of the task the pipeline is configured for. + * + * @type {?string} + */ + taskName = null; + + /** + * The maximum amount of time in milliseconds the pipeline should wait for a response. + * + * @type {?number} + */ + timeoutMS = null; + + /** + * The root URL of the model hub where models are hosted. + * + * @type {?string} + */ + modelHubRootUrl = null; + + /** + * A template URL for building the full URL for the model. + * + * @type {?string} + */ + modelHubUrlTemplate = null; + + /** + * The identifier for the specific model to be used by the pipeline. + * + * @type {?string} + */ + modelId = null; + + /** + * The revision for the specific model to be used by the pipeline. + * + * @type {?string} + */ + modelRevision = null; + + /** + * The identifier for the tokenizer associated with the model, used for pre-processing inputs. + * + * @type {?string} + */ + tokenizerId = null; + + /** + * The revision for the tokenizer associated with the model, used for pre-processing inputs. + * + * @type {?string} + */ + tokenizerRevision = null; + + /** + * The identifier for any processor required by the model, used for additional input processing. + * + * @type {?string} + */ + processorId = null; + + /** + * The revision for any processor required by the model, used for additional input processing. + * + * @type {?string} + */ + + processorRevision = null; + + /** + * The log level used in the worker + * + * @type {?string} + */ + logLevel = null; + + /** + * Name of the runtime wasm file + * + * @type {?string} + */ + runtimeFilename = null; + + /** + * Create a PipelineOptions instance. + * + * @param {object} options - The options for the pipeline. Must include mandatory fields. + */ + constructor(options) { + this.updateOptions(options); + } + + /** + * Updates multiple options at once. + * + * @param {object} options - An object containing the options to update. + * @throws {Error} Throws an error if an invalid option is provided. + */ + updateOptions(options) { + const allowedKeys = [ + "taskName", + "modelHubRootUrl", + "modelHubUrlTemplate", + "timeoutMS", + "modelId", + "modelRevision", + "tokenizerId", + "tokenizerRevision", + "processorId", + "processorRevision", + "logLevel", + "runtimeFilename", + ]; + + Object.keys(options).forEach(key => { + if (allowedKeys.includes(key)) { + this[key] = options[key]; // Use bracket notation to access setter + } else { + throw new Error(`Invalid option: ${key}`); + } + }); + } + + /** + * Returns an object containing all current options. + + * @returns {object} An object with the current options. + */ + getOptions() { + return { + taskName: this.taskName, + modelHubRootUrl: this.modelHubRootUrl, + modelHubUrlTemplate: this.modelHubUrlTemplate, + timeoutMS: this.timeoutMS, + modelId: this.modelId, + modelRevision: this.modelRevision, + tokenizerId: this.tokenizerId, + tokenizerRevision: this.tokenizerRevision, + processorId: this.processorId, + processorRevision: this.processorRevision, + logLevel: this.logLevel, + runtimeFilename: this.runtimeFilename, + }; + } + + /** + * Updates the given configuration object with the options. + * + * @param {object} config - The configuration object to be updated. + */ + applyToConfig(config) { + const options = this.getOptions(); + Object.keys(options).forEach(key => { + if (options[key] !== null) { + config[key] = options[key]; + } + }); + } +} + /** * This class controls the life cycle of the engine process used both in the * Translations engine and the MLEngine component. @@ -68,6 +241,15 @@ export class EngineProcess { * @returns {Promise} */ static async getMLEngineParent() { + // Bug 1890946 - enable the inference engine in release + if (!AppConstants.NIGHTLY_BUILD) { + throw new Error("MLEngine is only available in Nightly builds."); + } + // the pref is off by default + if (!Services.prefs.getBoolPref("browser.ml.enable")) { + throw new Error("MLEngine is disabled. Check the browser.ml prefs."); + } + if (!this.mlEngineParent) { this.mlEngineParent = this.#attachBrowser({ id: "ml-engine-browser", diff --git a/toolkit/components/ml/content/MLEngine.worker.mjs b/toolkit/components/ml/content/MLEngine.worker.mjs index 1013977e07..585ac4ab04 100644 --- a/toolkit/components/ml/content/MLEngine.worker.mjs +++ b/toolkit/components/ml/content/MLEngine.worker.mjs @@ -2,74 +2,99 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { PromiseWorker } from "resource://gre/modules/workers/PromiseWorker.mjs"; +const lazy = {}; -// Respect the preference "browser.ml.logLevel". -let _loggingLevel = "Error"; -function log(...args) { - if (_loggingLevel !== "Error" && _loggingLevel !== "Warn") { - console.log("ML:", ...args); - } -} -function trace(...args) { - if (_loggingLevel === "Trace" || _loggingLevel === "All") { - console.log("ML:", ...args); - } -} +ChromeUtils.defineESModuleGetters( + lazy, + { + PromiseWorker: "resource://gre/modules/workers/PromiseWorker.mjs", + Pipeline: "chrome://global/content/ml/ONNXPipeline.mjs", + PipelineOptions: "chrome://global/content/ml/EngineProcess.sys.mjs", + }, + { global: "current" } +); /** * The actual MLEngine lives here in a worker. */ class MLEngineWorker { - /** @type {ArrayBuffer} */ - #wasm; - /** @type {ArrayBuffer} */ - #model; + #pipeline; constructor() { // Connect the provider to the worker. this.#connectToPromiseWorker(); } + /** Implements the `match` function from the Cache API for Transformers.js custom cache. + * + * See https://developer.mozilla.org/en-US/docs/Web/API/Cache + * + * Attempts to match and retrieve a model file based on a provided key. + * Fetches a model file by delegating the call to the worker's main thread. + * Then wraps the fetched model file into a response object compatible with Transformers.js expectations. + * + * @param {string} key The unique identifier for the model to fetch. + * @returns {Promise} A promise that resolves with a Response object containing the model file or null if not found. + */ + async match(key) { + let res = await this.getModelFile(key); + if (res.fail) { + return null; + } + let headers = res.ok[1]; + let modelFile = res.ok[2]; + // Transformers.js expects a response object, so we wrap the array buffer + const response = new Response(modelFile, { + status: 200, + headers, + }); + return response; + } + + async getModelFile(...args) { + let result = await self.callMainThread("getModelFile", args); + return result; + } + /** - * @param {ArrayBuffer} wasm - * @param {ArrayBuffer} model - * @param {string} loggingLevel + * Placeholder for the `put` method from the Cache API for Transformers.js custom cache. + * + * @throws {Error} Always thrown to indicate the method is not implemented. */ - initializeEngine(wasm, model, loggingLevel) { - this.#wasm = wasm; - this.#model = model; - _loggingLevel = loggingLevel; - // TODO - Initialize the engine for real here. - log("MLEngineWorker is initalized"); + put() { + throw new Error("Method not implemented."); } + /** + * @param {ArrayBuffer} wasm + * @param {object} options received as an object, converted to a PipelineOptions instance + */ + async initializeEngine(wasm, options) { + this.#pipeline = await lazy.Pipeline.initialize( + this, + wasm, + new lazy.PipelineOptions(options) + ); + } /** * Run the worker. * * @param {string} request */ - run(request) { - if (!this.#wasm) { - throw new Error("Expected the wasm to exist."); - } - if (!this.#model) { - throw new Error("Expected the model to exist"); - } + async run(request) { if (request === "throw") { throw new Error( 'Received the message "throw", so intentionally throwing an error.' ); } - trace("inference run requested with:", request); - return request.slice(0, Math.floor(request.length / 2)); + return await this.#pipeline.run(request); } /** * Glue code to connect the `MLEngineWorker` to the PromiseWorker interface. */ #connectToPromiseWorker() { - const worker = new PromiseWorker.AbstractWorker(); + const worker = new lazy.PromiseWorker.AbstractWorker(); worker.dispatch = (method, args = []) => { if (!this[method]) { throw new Error("Method does not exist: " + method); @@ -81,6 +106,7 @@ class MLEngineWorker { self.postMessage(message, ...transfers); }; + self.callMainThread = worker.callMainThread.bind(worker); self.addEventListener("message", msg => worker.handleMessage(msg)); self.addEventListener("unhandledrejection", function (error) { throw error.reason; diff --git a/toolkit/components/ml/content/ModelHub.sys.mjs b/toolkit/components/ml/content/ModelHub.sys.mjs index 4c2181ff14..10f83c3000 100644 --- a/toolkit/components/ml/content/ModelHub.sys.mjs +++ b/toolkit/components/ml/content/ModelHub.sys.mjs @@ -24,8 +24,7 @@ const ALLOWED_HUBS = [ ]; const ALLOWED_HEADERS_KEYS = ["Content-Type", "ETag", "status"]; -const DEFAULT_URL_TEMPLATE = - "${organization}/${modelName}/resolve/${modelVersion}/${file}"; +const DEFAULT_URL_TEMPLATE = "{model}/resolve/{revision}"; /** * Checks if a given URL string corresponds to an allowed hub. @@ -238,18 +237,37 @@ export class IndexedDBCache { }); } + /** + * Checks if a specified model file exists in storage. + * + * @param {string} model - The model name (organization/name) + * @param {string} revision - The model revision. + * @param {string} file - The file name. + * @returns {Promise} A promise that resolves with `true` if the key exists, otherwise `false`. + */ + async fileExists(model, revision, file) { + const storeName = this.fileStoreName; + const cacheKey = `${model}/${revision}/${file}`; + return new Promise((resolve, reject) => { + const transaction = this.db.transaction([storeName], "readonly"); + const store = transaction.objectStore(storeName); + const request = store.getKey(cacheKey); + request.onerror = event => reject(event.target.error); + request.onsuccess = event => resolve(event.target.result !== undefined); + }); + } + /** * Retrieves the headers for a specific cache entry. * - * @param {string} organization - The organization name. - * @param {string} modelName - The model name. - * @param {string} modelVersion - The model version. + * @param {string} model - The model name (organization/name) + * @param {string} revision - The model revision. * @param {string} file - The file name. * @returns {Promise} The headers or null if not found. */ - async getHeaders(organization, modelName, modelVersion, file) { - const headersKey = `${organization}/${modelName}/${modelVersion}`; - const cacheKey = `${organization}/${modelName}/${modelVersion}/${file}`; + async getHeaders(model, revision, file) { + const headersKey = `${model}/${revision}`; + const cacheKey = `${model}/${revision}/${file}`; const headers = await this.#getData(this.headersStoreName, headersKey); if (headers && headers.files[cacheKey]) { return headers.files[cacheKey]; @@ -260,22 +278,16 @@ export class IndexedDBCache { /** * Retrieves the file for a specific cache entry. * - * @param {string} organization - The organization name. - * @param {string} modelName - The model name. - * @param {string} modelVersion - The model version. + * @param {string} model - The model name (organization/name). + * @param {string} revision - The model version. * @param {string} file - The file name. * @returns {Promise<[ArrayBuffer, object]|null>} The file ArrayBuffer and its headers or null if not found. */ - async getFile(organization, modelName, modelVersion, file) { - const cacheKey = `${organization}/${modelName}/${modelVersion}/${file}`; + async getFile(model, revision, file) { + const cacheKey = `${model}/${revision}/${file}`; const stored = await this.#getData(this.fileStoreName, cacheKey); if (stored) { - const headers = await this.getHeaders( - organization, - modelName, - modelVersion, - file - ); + const headers = await this.getHeaders(model, revision, file); return [stored.data, headers]; } return null; // Return null if no file is found @@ -284,29 +296,21 @@ export class IndexedDBCache { /** * Adds or updates a cache entry. * - * @param {string} organization - The organization name. - * @param {string} modelName - The model name. - * @param {string} modelVersion - The model version. + * @param {string} model - The model name (organization/name). + * @param {string} revision - The model version. * @param {string} file - The file name. * @param {ArrayBuffer} arrayBuffer - The data to cache. * @param {object} [headers] - The headers for the file. * @returns {Promise} */ - async put( - organization, - modelName, - modelVersion, - file, - arrayBuffer, - headers = {} - ) { - const cacheKey = `${organization}/${modelName}/${modelVersion}/${file}`; + async put(model, revision, file, arrayBuffer, headers = {}) { + const cacheKey = `${model}/${revision}/${file}`; const newSize = this.totalSize + arrayBuffer.byteLength; if (newSize > this.#maxSize) { throw new Error("Exceeding total cache size limit of 1GB"); } - const headersKey = `${organization}/${modelName}/${modelVersion}`; + const headersKey = `${model}/${revision}`; const data = { id: cacheKey, data: arrayBuffer }; // Store the file data @@ -356,13 +360,12 @@ export class IndexedDBCache { /** * Deletes all data related to a specific model. * - * @param {string} organization - The organization name. - * @param {string} modelName - The model name. - * @param {string} modelVersion - The model version. + * @param {string} model - The model name (organization/name). + * @param {string} revision - The model version. * @returns {Promise} */ - async deleteModel(organization, modelName, modelVersion) { - const headersKey = `${organization}/${modelName}/${modelVersion}`; + async deleteModel(model, revision) { + const headersKey = `${model}/${revision}`; const headers = await this.#getData(this.headersStoreName, headersKey); if (headers) { for (const fileKey in headers.files) { @@ -409,9 +412,9 @@ export class ModelHub { this.cache = null; // Ensures the URL template is well-formed and does not contain any invalid characters. - const pattern = /^(?:\$\{\w+\}|\w+)(?:\/(?:\$\{\w+\}|\w+))*$/; + const pattern = /^(?:\{\w+\}|\w+)(?:\/(?:\{\w+\}|\w+))*$/; // ^ $ Start and end of string - // (?:\$\{\w+\}|\w+) Match a ${placeholder} or alphanumeric characters + // (?:\{\w+\}|\w+) Match a {placeholder} or alphanumeric characters // (?:\/(?:\$\{\w+\}|\w+))* Zero or more groups of a forward slash followed by a ${placeholder} or alphanumeric characters if (!pattern.test(urlTemplate)) { throw new Error(`Invalid URL template: ${urlTemplate}`); @@ -426,33 +429,94 @@ export class ModelHub { this.cache = await IndexedDBCache.init(); } + /** + * This method takes a model URL and parses it to extract the + * model name, optional model version, and file path. + * + * The expected URL format are : + * + * `/organization/model/revision/filePath` + * `https://hub/organization/model/revision/filePath` + * + * @param {string} url - The full URL to the model, including protocol and domain - or the relative path. + * @returns {object} An object containing the parsed components of the URL. The + * object has properties `model`, and `file`, + * and optionally `revision` if the URL includes a version. + * @throws {Error} Throws an error if the URL does not start with `this.rootUrl` or + * if the URL format does not match the expected structure. + * + * @example + * // For a URL + * parseModelUrl("https://example.com/org1/model1/v1/file/path"); + * // returns { model: "org1/model1", revision: "v1", file: "file/path" } + * + * @example + * // For a relative URL + * parseModelUrl("/org1/model1/revision/file/path"); + * // returns { model: "org1/model1", revision: "v1", file: "file/path" } + */ + parseUrl(url) { + let parts; + if (url.startsWith("/")) { + // relative URL + parts = url.slice(1).split("/"); + } else { + // absolute URL + if (!url.startsWith(this.rootUrl)) { + throw new Error(`Invalid domain for model URL: ${url}`); + } + const urlObject = new URL(url); + const rootUrlObject = new URL(this.rootUrl); + + // Remove the root URL's pathname from the full URL's pathname + const relativePath = urlObject.pathname.substring( + rootUrlObject.pathname.length + ); + + parts = relativePath.slice(1).split("/"); + } + + if (parts.length < 3) { + throw new Error(`Invalid model URL: ${url}`); + } + + const file = parts.slice(3).join("/"); + if (file == null || !file.length) { + throw new Error(`Invalid model URL: ${url}`); + } + + return { + model: `${parts[0]}/${parts[1]}`, + revision: parts[2], + file, + }; + } + /** Creates the file URL from the organization, model, and version. * - * @param {string} organization - * @param {string} modelName - * @param {string} modelVersion + * @param {string} model + * @param {string} revision * @param {string} file * @returns {string} The full URL */ - #fileUrl(organization, modelName, modelVersion, file) { + #fileUrl(model, revision, file) { const baseUrl = new URL(this.rootUrl); if (!baseUrl.pathname.endsWith("/")) { baseUrl.pathname += "/"; } - // Replace placeholders in the URL template with the provided data. // If some keys are missing in the data object, the placeholder is left as is. // If the placeholder is not found in the data object, it is left as is. const data = { - organization, - modelName, - modelVersion, - file, + model, + revision, }; - const path = this.urlTemplate.replace( - /\$\{(\w+)\}/g, + let path = this.urlTemplate.replace( + /\{(\w+)\}/g, (match, key) => data[key] || match ); + path = `${path}/${file}`; + const fullPath = `${baseUrl.pathname}${ path.startsWith("/") ? path.slice(1) : path }`; @@ -462,28 +526,29 @@ export class ModelHub { return urlObject.toString(); } - /** Checks the organization, model, and version inputs. + /** Checks the model and revision inputs. * - * @param { string } organization - * @param { string } modelName - * @param { string } modelVersion + * @param { string } model + * @param { string } revision * @param { string } file * @returns { Error } The error instance(can be null) */ - #checkInput(organization, modelName, modelVersion, file) { - // Ensures string consists only of letters, digits, and hyphens without starting/ending - // with a hyphen or containing consecutive hyphens. + #checkInput(model, revision, file) { + // Matches a string with the format 'organization/model' where: + // - 'organization' consists only of letters, digits, and hyphens, cannot start or end with a hyphen, + // and cannot contain consecutive hyphens. + // - 'model' can contain letters, digits, hyphens, underscores, or periods. // - // ^ $ Start and end of string - // (?!-) (?} ETag (can be null) */ - async #getETag(url, timeout = 1000) { + async getETag(url, timeout = 1000) { const controller = new AbortController(); const id = lazy.setTimeout(() => controller.abort(), timeout); @@ -559,24 +620,18 @@ export class ModelHub { * Given an organization, model, and version, fetch a model file in the hub as a Response. * * @param {object} config - * @param {string} config.organization - * @param {string} config.modelName - * @param {string} config.modelVersion + * @param {string} config.model + * @param {string} config.revision * @param {string} config.file * @returns {Promise} The file content */ - async getModelFileAsResponse({ - organization, - modelName, - modelVersion, - file, - }) { + async getModelFileAsResponse({ model, revision, file }) { const [blob, headers] = await this.getModelFileAsBlob({ - organization, - modelName, - modelVersion, + model, + revision, file, }); + return new Response(blob, { headers }); } @@ -584,22 +639,15 @@ export class ModelHub { * Given an organization, model, and version, fetch a model file in the hub as an ArrayBuffer. * * @param {object} config - * @param {string} config.organization - * @param {string} config.modelName - * @param {string} config.modelVersion + * @param {string} config.model + * @param {string} config.revision * @param {string} config.file * @returns {Promise<[ArrayBuffer, headers]>} The file content */ - async getModelFileAsArrayBuffer({ - organization, - modelName, - modelVersion, - file, - }) { + async getModelFileAsArrayBuffer({ model, revision, file }) { const [blob, headers] = await this.getModelFileAsBlob({ - organization, - modelName, - modelVersion, + model, + revision, file, }); return [await blob.arrayBuffer(), headers]; @@ -609,54 +657,44 @@ export class ModelHub { * Given an organization, model, and version, fetch a model file in the hub as blob. * * @param {object} config - * @param {string} config.organization - * @param {string} config.modelName - * @param {string} config.modelVersion + * @param {string} config.model + * @param {string} config.revision * @param {string} config.file * @returns {Promise<[Blob, object]>} The file content */ - async getModelFileAsBlob({ organization, modelName, modelVersion, file }) { + async getModelFileAsBlob({ model, revision, file }) { // Make sure inputs are clean. We don't sanitize them but throw an exception - let checkError = this.#checkInput( - organization, - modelName, - modelVersion, - file - ); + let checkError = this.#checkInput(model, revision, file); if (checkError) { throw checkError; } - - const url = this.#fileUrl(organization, modelName, modelVersion, file); + const url = this.#fileUrl(model, revision, file); lazy.console.debug(`Getting model file from ${url}`); await this.#initCache(); - // this can be null if no ETag was found or there were a network error - const hubETag = await this.#getETag(url); + let useCached; - lazy.console.debug( - `Checking the cache for ${organization}/${modelName}/${modelVersion}/${file}` - ); + // If the revision is `main` we want to check the ETag in the hub + if (revision === "main") { + // this can be null if no ETag was found or there were a network error + const hubETag = await this.getETag(url); - // storage lookup - const cachedHeaders = await this.cache.getHeaders( - organization, - modelName, - modelVersion, - file - ); - const cachedEtag = cachedHeaders ? cachedHeaders.ETag : null; - - // If we have something in store, and the hub ETag is null or it matches the cached ETag, return the cached response - if (cachedEtag !== null && (hubETag === null || cachedEtag === hubETag)) { - lazy.console.debug(`Cache Hit`); - return await this.cache.getFile( - organization, - modelName, - modelVersion, - file - ); + // Storage ETag lookup + const cachedHeaders = await this.cache.getHeaders(model, revision, file); + const cachedEtag = cachedHeaders ? cachedHeaders.ETag : null; + + // If we have something in store, and the hub ETag is null or it matches the cached ETag, return the cached response + useCached = + cachedEtag !== null && (hubETag === null || cachedEtag === hubETag); + } else { + // If we are dealing with a pinned revision, we ignore the ETag, to spare HEAD hits on every call + useCached = await this.cache.fileExists(model, revision, file); + } + + if (useCached) { + lazy.console.debug(`Cache Hit for ${url}`); + return await this.cache.getFile(model, revision, file); } lazy.console.debug(`Fetching ${url}`); @@ -668,13 +706,12 @@ export class ModelHub { // We don't store the boundary or the charset, just the content type, // so we drop what's after the semicolon. "Content-Type": response.headers.get("Content-Type").split(";")[0], - ETag: hubETag, + ETag: response.headers.get("ETag"), }; await this.cache.put( - organization, - modelName, - modelVersion, + model, + revision, file, await clone.blob(), headers diff --git a/toolkit/components/ml/content/ONNXPipeline.mjs b/toolkit/components/ml/content/ONNXPipeline.mjs new file mode 100644 index 0000000000..fcc1a0eb77 --- /dev/null +++ b/toolkit/components/ml/content/ONNXPipeline.mjs @@ -0,0 +1,297 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This import does not use Chromutils because the next version of the library +// will require an async import, which is not supported by importESModule, +// so we'll just add await here. +import { + env, + RawImage, + AutoProcessor, + AutoTokenizer, + AutoModelForVision2Seq, +} from "chrome://global/content/ml/transformers-dev.js"; + +/** + * Lazy initialization container. + * + * @type {object} + */ + +const lazy = {}; + +ChromeUtils.defineESModuleGetters( + lazy, + { + arrayBufferToBlobURL: "chrome://global/content/ml/Utils.sys.mjs", + }, + { global: "current" } +); + +// Using a custom console, see https://bugzilla.mozilla.org/show_bug.cgi?id=1891789 +let _logLevel = "Error"; + +function debug(...args) { + if (["Debug", "Trace", "All"].includes(_logLevel)) { + console.log("ML:", ...args); // eslint-disable-line no-console + } +} + +/** + * Echo inference for testing purposes. + * + * @async + * @param {object} request - The request object containing image data. + * @param {object} _model - The model used for inference. + * @param {object} _tokenizer - The tokenizer used for decoding. + * @param {object} _processor - The processor used for preparing image data. + * @returns {Promise} The result object containing the processed text. + */ +async function echo(request, _model, _tokenizer, _processor) { + return { + metrics: { + tokenizingTime: 0, + }, + output: request.data, + }; +} + +/** + * Converts an image to text using a machine learning model. + * + * @async + * @param {object} request - The request object containing image data. + * @param {string} [request.imageUrl] - The URL of the image to process. Either `imageUrl` or `data` must be provided, but not both. + * @param {ArrayBuffer} [request.data] - The raw image data to process. Either `data` or `imageUrl` must be provided, but not both. + * @param {string} request.mimeType - The MIME type of the image data. + * @param {object} model - The model used for inference. + * @param {object} tokenizer - The tokenizer used for decoding. + * @param {object} processor - The processor used for preparing image data. + * @returns {Promise} The result object containing the processed text. + */ +async function imageToText(request, model, tokenizer, processor) { + let result = { + metrics: { + inferenceTime: 0, + tokenizingTime: 0, + }, + }; + let start = Date.now(); + let rawImage; + + if ("imageUrl" in request) { + rawImage = await RawImage.fromUrl(request.imageUrl); + } else { + const blob = new Blob([request.data], { type: request.mimeType }); + rawImage = await RawImage.fromBlob(blob); + } + + debug("Image loaded in ", Date.now() - start); + + const { pixel_values } = await processor(rawImage); + result.metrics.tokenizingTime += Date.now() - start; + const toReturn = []; + for (const batch of pixel_values) { + batch.dims = [1, ...batch.dims]; + start = Date.now(); + const output = await model.generate(batch); + result.metrics.inferenceTime += Date.now() - start; + start = Date.now(); + const decoded = tokenizer + .batch_decode(output, { + skip_special_tokens: true, + }) + .map(x => ({ generated_text: x.trim() })); + result.metrics.tokenizingTime += Date.now() - start; + toReturn.push(decoded); + } + debug("Inference done in ", Date.now() - start); + result.output = toReturn[0][0].generated_text; + return result; +} + +/** + * Configuration for engine. Each task has a configuration object that + * gets merged at runtime with the options from PipelineOptions. + * + * When a key exists in both the default configuration and the options, + * the value from the options is used. + * + * The configuration keys that are not exposed as options are all the + * callables that are used in the pipeline: + * + * - modelClass + * - tokenizerClass + * - processorClass + * - pipelineFunction + * + * @type {object} + */ +const ENGINE_CONFIGURATION = { + "image-to-text": { + modelId: "mozilla/distilvit", + modelClass: AutoModelForVision2Seq, + tokenizerId: "mozilla/distilvit", + tokenizerClass: AutoTokenizer, + processorId: "mozilla/distilvit", + processorClass: AutoProcessor, + pipelineFunction: imageToText, + }, + echo: { + modelId: null, + modelClass: null, + tokenizerId: null, + tokenizerClass: null, + processorId: null, + processorClass: null, + pipelineFunction: echo, + }, +}; + +/** + * Represents a pipeline for processing machine learning tasks. + */ +export class Pipeline { + #modelCache = null; + #model = null; + #tokenizer = null; + #processor = null; + #pipelineFunction = null; + #taskName = null; + #initTime = 0; + #isReady = false; + + /** + * Creates an instance of a Pipeline. + * + * @param {object} modelCache - Implements the Cache interface and used to get models + * @param {object} config - The configuration options + */ + constructor(modelCache, config) { + let start = Date.now(); + this.#modelCache = modelCache; + + _logLevel = config.logLevel || "Error"; + // Setting up the Transformers.js environment + // See https://huggingface.co/docs/transformers.js/api/env + + // Caching strategy. + // Here we make sure that everytime transformers.js requires a file, it uses + // modelCache, which transfers the request to the main thread and uses the + // ModelHub that caches files into IndexDB. + env.useBrowserCache = false; + env.allowLocalModels = false; + env.remoteHost = config.modelHubRootUrl; + env.remotePathTemplate = config.modelHubUrlTemplate; + env.useCustomCache = true; + env.customCache = this.#modelCache; + env.localModelPath = "/"; + + // ONNX runtime - we set up the wasm runtime we got from RS for the ONNX backend to pick + debug("Setting up ONNX backend"); + env.backends.onnx.wasm.wasmPaths = {}; + env.backends.onnx.wasm.wasmPaths[config.runtimeFilename] = + lazy.arrayBufferToBlobURL(config.runtime); + + if (config.modelClass && config.modelId) { + debug(`Loading model ${config.modelId} with class ${config.modelClass}`); + this.#model = config.modelClass.from_pretrained(config.modelId); + } + if (config.tokenizerClass && config.tokenizerId) { + debug( + `Loading tokenizer ${config.tokenizerId} with class ${config.tokenizerClass}` + ); + this.#tokenizer = config.tokenizerClass.from_pretrained( + config.tokenizerId + ); + } + if (config.processorClass && config.processorId) { + debug( + `Loading processor ${config.processorId} with class ${config.processorClass}` + ); + this.#processor = config.processorClass.from_pretrained( + config.processorId + ); + } + this.#taskName = config.taskName; + this.#pipelineFunction = config.pipelineFunction.bind(this); + this.#initTime = Date.now() - start; + debug("Pipeline initialized, took ", this.#initTime); + } + + /** + * Initializes the pipeline with given options. + * + * @static + * @async + * @param {object} modelCache - Implements the Cache interface and used to get models + * @param {ArrayBuffer} runtime - The runtime wasm file. + * @param {PipelineOptions} options - The options for initialization. + * @returns {Promise} The initialized pipeline instance. + */ + static async initialize(modelCache, runtime, options) { + const taskName = options.taskName; + debug(`Initializing Pipeline for task ${taskName}`); + + if (!ENGINE_CONFIGURATION[taskName]) { + throw new Error(`Task ${taskName} is not supported`); + } + + // Loading the config defaults for the task + let config = { ...ENGINE_CONFIGURATION[taskName] }; + config.runtime = runtime; + + // Overriding the defaults with the options + options.applyToConfig(config); + + if (!config.pipelineFunction) { + throw new Error("pipelineFunction is required for the pipeline"); + } + return new Pipeline(modelCache, config); + } + + /** + * Runs the pipeline with the given request. + * + * @async + * @param {T} request - The request object to be processed. The fields it may contain + * depends on the task. See each pipeline function for more details. + * @returns {Promise} The result object from the pipeline execution. + */ + async run(request) { + debug("Running task: ", this.#taskName); + // Calling all promises to ensure they are resolved before running the first pipeline + if (!this.#isReady) { + let start = Date.now(); + debug("Initializing model, tokenizer and processor"); + + // deactive console.warn, see https://bugzilla.mozilla.org/show_bug.cgi?id=1891003 + const originalWarn = console.warn; + console.warn = () => {}; + try { + this.#model = await this.#model; + this.#tokenizer = await this.#tokenizer; + this.#processor = await this.#processor; + this.#isReady = true; + } catch (error) { + debug("Error initializing pipeline", error); + throw error; + } finally { + console.warn = originalWarn; + } + + this.#initTime += Date.now() - start; + debug("Pipeline is fully initialized, took ", this.#initTime); + } + + let result = await this.#pipelineFunction( + request, + this.#model, + this.#tokenizer, + this.#processor + ); + result.metrics.initTime = this.#initTime; + return result; + } +} diff --git a/toolkit/components/ml/content/SummarizerModel.sys.mjs b/toolkit/components/ml/content/SummarizerModel.sys.mjs deleted file mode 100644 index 7cac55d92f..0000000000 --- a/toolkit/components/ml/content/SummarizerModel.sys.mjs +++ /dev/null @@ -1,160 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * @typedef {object} LazyImports - * @property {typeof import("../actors/MLEngineParent.sys.mjs").MLEngineParent} MLEngineParent - */ - -/** @type {LazyImports} */ -const lazy = {}; - -ChromeUtils.defineESModuleGetters(lazy, { - RemoteSettings: "resource://services-settings/remote-settings.sys.mjs", - TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs", -}); - -ChromeUtils.defineLazyGetter(lazy, "console", () => { - return console.createInstance({ - maxLogLevelPref: "browser.ml.logLevel", - prefix: "ML", - }); -}); - -export class SummarizerModel { - /** - * The RemoteSettingsClient that downloads the summarizer model. - * - * @type {RemoteSettingsClient | null} - */ - static #remoteClient = null; - - /** @type {Promise | null} */ - static #modelRecord = null; - - /** - * The following constant controls the major version for wasm downloaded from - * Remote Settings. When a breaking change is introduced, Nightly will have these - * numbers incremented by one, but Beta and Release will still be on the previous - * version. Remote Settings will ship both versions of the records, and the latest - * asset released in that version will be used. For instance, with a major version - * of "1", assets can be downloaded for "1.0", "1.2", "1.3beta", but assets marked - * as "2.0", "2.1", etc will not be downloaded. - */ - static MODEL_MAJOR_VERSION = 1; - - /** - * Remote settings isn't available in tests, so provide mocked responses. - */ - static mockRemoteSettings(remoteClient) { - lazy.console.log("Mocking remote client in SummarizerModel."); - SummarizerModel.#remoteClient = remoteClient; - SummarizerModel.#modelRecord = null; - } - - /** - * Remove anything that could have been mocked. - */ - static removeMocks() { - lazy.console.log("Removing mocked remote client in SummarizerModel."); - SummarizerModel.#remoteClient = null; - SummarizerModel.#modelRecord = null; - } - /** - * Download or load the model from remote settings. - * - * @returns {Promise} - */ - static async getModel() { - const client = SummarizerModel.#getRemoteClient(); - - if (!SummarizerModel.#modelRecord) { - // Place the records into a promise to prevent any races. - SummarizerModel.#modelRecord = (async () => { - // Load the wasm binary from remote settings, if it hasn't been already. - lazy.console.log(`Getting the summarizer model record.`); - - // TODO - The getMaxVersionRecords should eventually migrated to some kind of - // shared utility. - const { getMaxVersionRecords } = lazy.TranslationsParent; - - /** @type {WasmRecord[]} */ - const wasmRecords = await getMaxVersionRecords(client, { - // TODO - This record needs to be created with the engine wasm payload. - filters: { name: "summarizer-model" }, - majorVersion: SummarizerModel.MODEL_MAJOR_VERSION, - }); - - if (wasmRecords.length === 0) { - // The remote settings client provides an empty list of records when there is - // an error. - throw new Error("Unable to get the models from Remote Settings."); - } - - if (wasmRecords.length > 1) { - SummarizerModel.reportError( - new Error("Expected the ml engine to only have 1 record."), - wasmRecords - ); - } - const [record] = wasmRecords; - lazy.console.log( - `Using ${record.name}@${record.release} release version ${record.version} first released on Fx${record.fx_release}`, - record - ); - return record; - })(); - } - - try { - /** @type {{buffer: ArrayBuffer}} */ - const { buffer } = await client.attachments.download( - await SummarizerModel.#modelRecord - ); - - return buffer; - } catch (error) { - SummarizerModel.#modelRecord = null; - throw error; - } - } - - /** - * Lazily initializes the RemoteSettingsClient. - * - * @returns {RemoteSettingsClient} - */ - static #getRemoteClient() { - if (SummarizerModel.#remoteClient) { - return SummarizerModel.#remoteClient; - } - - /** @type {RemoteSettingsClient} */ - const client = lazy.RemoteSettings("ml-model"); - - SummarizerModel.#remoteClient = client; - - client.on("sync", async ({ data: { created, updated, deleted } }) => { - lazy.console.log(`"sync" event for ml-model`, { - created, - updated, - deleted, - }); - - // Remove all the deleted records. - for (const record of deleted) { - await client.attachments.deleteDownloaded(record); - } - - // Remove any updated records, and download the new ones. - for (const { old: oldRecord } of updated) { - await client.attachments.deleteDownloaded(oldRecord); - } - - // Do nothing for the created records. - }); - - return client; - } -} diff --git a/toolkit/components/ml/content/Utils.sys.mjs b/toolkit/components/ml/content/Utils.sys.mjs new file mode 100644 index 0000000000..b3a25e84d7 --- /dev/null +++ b/toolkit/components/ml/content/Utils.sys.mjs @@ -0,0 +1,77 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +/** + * Converts an ArrayBuffer to a Blob URL. + * + * @param {ArrayBuffer} buffer - The ArrayBuffer to convert. + * @returns {string} The Blob URL. + */ +export function arrayBufferToBlobURL(buffer) { + let blob = new Blob([buffer], { type: "application/wasm" }); + return URL.createObjectURL(blob); +} + +/** + * Validate some simple Wasm that uses a SIMD operation. + */ +function detectSimdSupport() { + return WebAssembly.validate( + new Uint8Array( + // ``` + // ;; Detect SIMD support. + // ;; Compile by running: wat2wasm --enable-all simd-detect.wat + // + // (module + // (func (result v128) + // i32.const 0 + // i8x16.splat + // i8x16.popcnt + // ) + // ) + // ``` + + // prettier-ignore + [ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x01, 0x60, 0x00, + 0x01, 0x7b, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x0a, 0x01, 0x08, 0x00, 0x41, 0x00, + 0xfd, 0x0f, 0xfd, 0x62, 0x0b + ] + ) + ); +} + +let cachedRuntimeWasmFilename = null; + +/** + * Determines the appropriate WebAssembly (Wasm) filename based on the runtime capabilities of the browser. + * This function considers both SIMD and multi-threading support. + * It returns a filename that matches the browser's capabilities, ensuring the most optimized version of the Wasm file is used. + * + * The result is cached to avoid re-computation. + * + * @param {Window|null} browsingContext - The browsing context to use for feature detection. + * @returns {string} The filename of the Wasm file best suited for the current browser's capabilities. + */ +export function getRuntimeWasmFilename(browsingContext = null) { + if (cachedRuntimeWasmFilename != null) { + return cachedRuntimeWasmFilename; + } + + // The cross-origin isolation flag is used to determine if we have multi-threading support. + const hasMultiThreadSupport = browsingContext + ? browsingContext.crossOriginIsolated + : false; + + let res; + if (detectSimdSupport()) { + res = hasMultiThreadSupport + ? "ort-wasm-simd-threaded.wasm" + : "ort-wasm-simd.wasm"; + } else { + res = hasMultiThreadSupport ? "ort-wasm-threaded.wasm" : "ort-wasm.wasm"; + } + cachedRuntimeWasmFilename = res; + return res; +} diff --git a/toolkit/components/ml/docs/index.md b/toolkit/components/ml/docs/index.md deleted file mode 100644 index 1b2015456b..0000000000 --- a/toolkit/components/ml/docs/index.md +++ /dev/null @@ -1,44 +0,0 @@ -# Machine Learning - -This component is an experimental machine learning local inference engine. Currently there is no inference engine actually integrated yet. - -Here is an example of the API: - -```js -// The engine process manages the life cycle of the engine. It runs in its own process. -// Models can consume large amounts of memory, and this helps encapsulate it at the -// operating system level. -const EngineProcess = ChromeUtils.importESModule("chrome://global/content/ml/EngineProcess.sys.mjs"); - -// The MLEngineParent is a JSActor that can communicate with the engine process. -const mlEngineParent = await EngineProcess.getMLEngineParent(); - - -/** - * When implementing a model, there should be a class that provides a `getModel` function - * that is responsible for providing the `ArrayBuffer` of the model. Typically this - * download is managed by RemoteSettings. - */ -class SummarizerModel { - /** - * @returns {ArrayBuffer} - */ - static getModel() { ... } -} - -// An engine can be created using a unique name for the engine, and the function -// to get the model. This class handles the life cycle of the engine. -const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel -); - -// In order to run the model, use the `run` method. This will initiate the engine if -// it is needed, and return the result. The messaging to the engine process happens -// through a MessagePort. -const result = await summarizer.run("A sentence that can be summarized.") - -// The engine can be explicitly terminated, or it will be destroyed through an idle -// timeout when not in use, as the memory requirements for models can be quite large. -summarizer.terminate(); -``` diff --git a/toolkit/components/ml/docs/index.rst b/toolkit/components/ml/docs/index.rst new file mode 100644 index 0000000000..a171a982a3 --- /dev/null +++ b/toolkit/components/ml/docs/index.rst @@ -0,0 +1,47 @@ +Machine Learning +================ + +This component is an experimental machine learning local inference engine based on +Transformers.js and the ONNX runtime. + +In the example below, an image is converted to text using the `image-to-text` task. + + +.. code-block:: javascript + + const {PipelineOptions, EngineProcess } = ChromeUtils.importESModule("chrome://global/content/ml/EngineProcess.sys.mjs"); + + // First we create a pipeline options object, which contains the task name + // and any other options needed for the task + const options = new PipelineOptions({taskName: "image-to-text" }); + + // Next, we create an engine parent object via EngineProcess + const engineParent = await EngineProcess.getMLEngineParent(); + + // We then create the engine object, using the options + const engine = engineParent.getEngine(options); + + // At this point we are ready to do some inference. + + // We need to get the image as an array buffer and wrap it into a request object + const response = await fetch("https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg"); + const buffer = await response.arrayBuffer(); + const mimeType = response.headers.get('Content-Type'); + const request = { + data: buffer, + mimeType: mimeType + }; + + // Finally, we run the engine with the request object + const res = await engine.run(request); + + // The result is a string containing the text extracted from the image + console.log(res); + + +Supported Inference Tasks +::::::::::::::::::::::::: + +The following tasks are supported by the machine learning engine: + +.. js:autofunction:: imageToText diff --git a/toolkit/components/ml/jar.mn b/toolkit/components/ml/jar.mn index c9c82e0b26..6676096524 100644 --- a/toolkit/components/ml/jar.mn +++ b/toolkit/components/ml/jar.mn @@ -2,9 +2,17 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +# For the vendored lib, see https://bugzilla.mozilla.org/show_bug.cgi?id=1890946 toolkit.jar: content/global/ml/EngineProcess.sys.mjs (content/EngineProcess.sys.mjs) content/global/ml/MLEngine.worker.mjs (content/MLEngine.worker.mjs) content/global/ml/MLEngine.html (content/MLEngine.html) content/global/ml/ModelHub.sys.mjs (content/ModelHub.sys.mjs) - content/global/ml/SummarizerModel.sys.mjs (content/SummarizerModel.sys.mjs) + content/global/ml/ONNXPipeline.mjs (content/ONNXPipeline.mjs) + content/global/ml/Utils.sys.mjs (content/Utils.sys.mjs) +#ifdef NIGHTLY_BUILD + content/global/ml/ort.js (vendor/ort.js) + content/global/ml/ort-dev.js (vendor/ort-dev.js) + content/global/ml/transformers.js (vendor/transformers.js) + content/global/ml/transformers-dev.js (vendor/transformers-dev.js) +#endif diff --git a/toolkit/components/ml/tests/browser/browser.toml b/toolkit/components/ml/tests/browser/browser.toml index 57637c8bda..ed3c04f066 100644 --- a/toolkit/components/ml/tests/browser/browser.toml +++ b/toolkit/components/ml/tests/browser/browser.toml @@ -1,9 +1,15 @@ [DEFAULT] +run-if = ["nightly_build"] # Bug 1890946 - enable the inference engine in release support-files = [ "head.js", "data/**/*.*" ] ["browser_ml_cache.js"] +lineno = "7" ["browser_ml_engine.js"] +lineno = "10" + +["browser_ml_utils.js"] +lineno = "13" diff --git a/toolkit/components/ml/tests/browser/browser_ml_cache.js b/toolkit/components/ml/tests/browser/browser_ml_cache.js index d8725368bd..8d879fc74d 100644 --- a/toolkit/components/ml/tests/browser/browser_ml_cache.js +++ b/toolkit/components/ml/tests/browser/browser_ml_cache.js @@ -11,16 +11,20 @@ const FAKE_HUB = "chrome://mochitests/content/browser/toolkit/components/ml/tests/browser/data"; const FAKE_MODEL_ARGS = { - organization: "acme", - modelName: "bert", - modelVersion: "main", + model: "acme/bert", + revision: "main", + file: "config.json", +}; + +const FAKE_RELEASED_MODEL_ARGS = { + model: "acme/bert", + revision: "v0.1", file: "config.json", }; const FAKE_ONNX_MODEL_ARGS = { - organization: "acme", - modelName: "bert", - modelVersion: "main", + model: "acme/bert", + revision: "main", file: "onnx/config.json", }; @@ -35,6 +39,9 @@ const badHubs = [ "https://model-hub.mozilla.org.hack", // Domain that contains allowed domain ]; +/** + * Make sure we reject bad model hub URLs. + */ add_task(async function test_bad_hubs() { for (const badHub of badHubs) { Assert.throws( @@ -60,60 +67,57 @@ add_task(async function test_allowed_hub() { const badInputs = [ [ { - organization: "ac me", - modelName: "bert", - modelVersion: "main", + model: "ac me/bert", + revision: "main", file: "config.json", }, "Org can only contain letters, numbers, and hyphens", ], [ { - organization: "1111", - modelName: "bert", - modelVersion: "main", + model: "1111/bert", + revision: "main", file: "config.json", }, "Org cannot contain only numbers", ], [ { - organization: "-acme", - modelName: "bert", - modelVersion: "main", + model: "-acme/bert", + revision: "main", file: "config.json", }, "Org start or end with a hyphen, or use consecutive hyphens", ], [ { - organization: "a-c-m-e", - modelName: "#bert", - modelVersion: "main", + model: "a-c-m-e/#bert", + revision: "main", file: "config.json", }, "Models can only contain letters, numbers, and hyphens, underscord, periods", ], [ { - organization: "a-c-m-e", - modelName: "b$ert", - modelVersion: "main", + model: "a-c-m-e/b$ert", + revision: "main", file: "config.json", }, "Models cannot contain spaces or control characters", ], [ { - organization: "a-c-m-e", - modelName: "b$ert", - modelVersion: "main", + model: "a-c-m-e/b$ert", + revision: "main", file: ".filename", }, "File", ], ]; +/** + * Make sure we reject bad inputs. + */ add_task(async function test_bad_inputs() { const hub = new ModelHub({ rootUrl: FAKE_HUB }); @@ -129,6 +133,9 @@ add_task(async function test_bad_inputs() { } }); +/** + * Test that we can retrieve a file as an ArrayBuffer. + */ add_task(async function test_getting_file() { const hub = new ModelHub({ rootUrl: FAKE_HUB }); @@ -144,6 +151,35 @@ add_task(async function test_getting_file() { Assert.equal(jsonData.hidden_size, 768); }); +/** + * Test that we can retrieve a file from a released model and skip head calls + */ +add_task(async function test_getting_released_file() { + const hub = new ModelHub({ rootUrl: FAKE_HUB }); + console.log(hub); + + let spy = sinon.spy(hub, "getETag"); + let [array, headers] = await hub.getModelFileAsArrayBuffer( + FAKE_RELEASED_MODEL_ARGS + ); + + Assert.equal(headers["Content-Type"], "application/json"); + + // check the content of the file. + let jsonData = JSON.parse( + String.fromCharCode.apply(null, new Uint8Array(array)) + ); + + Assert.equal(jsonData.hidden_size, 768); + + // check that head calls were not made + Assert.ok(!spy.called, "getETag should have never been called."); + spy.restore(); +}); + +/** + * Make sure files can be located in sub directories + */ add_task(async function test_getting_file_in_subdir() { const hub = new ModelHub({ rootUrl: FAKE_HUB }); @@ -161,10 +197,13 @@ add_task(async function test_getting_file_in_subdir() { Assert.equal(jsonData.hidden_size, 768); }); +/** + * Test that we can use a custom URL template. + */ add_task(async function test_getting_file_custom_path() { const hub = new ModelHub({ rootUrl: FAKE_HUB, - urlTemplate: "${organization}/${modelName}/resolve/${modelVersion}/${file}", + urlTemplate: "{model}/resolve/{revision}", }); let res = await hub.getModelFileAsArrayBuffer(FAKE_MODEL_ARGS); @@ -172,9 +211,11 @@ add_task(async function test_getting_file_custom_path() { Assert.equal(res[1]["Content-Type"], "application/json"); }); +/** + * Test that we can't use an URL with a query for the template + */ add_task(async function test_getting_file_custom_path_rogue() { - const urlTemplate = - "${organization}/${modelName}/resolve/${modelVersion}/${file}?some_id=bedqwdw"; + const urlTemplate = "{model}/resolve/{revision}/?some_id=bedqwdw"; Assert.throws( () => new ModelHub({ rootUrl: FAKE_HUB, urlTemplate }), /Invalid URL template/, @@ -182,6 +223,9 @@ add_task(async function test_getting_file_custom_path_rogue() { ); }); +/** + * Test that the file can be returned as a response and its content correct. + */ add_task(async function test_getting_file_as_response() { const hub = new ModelHub({ rootUrl: FAKE_HUB }); @@ -192,6 +236,10 @@ add_task(async function test_getting_file_as_response() { Assert.equal(jsonData.hidden_size, 768); }); +/** + * Test that the cache is used when the data is retrieved from the server + * and that the cache is updated with the new data. + */ add_task(async function test_getting_file_from_cache() { const hub = new ModelHub({ rootUrl: FAKE_HUB }); let array = await hub.getModelFileAsArrayBuffer(FAKE_MODEL_ARGS); @@ -213,6 +261,75 @@ add_task(async function test_getting_file_from_cache() { Assert.deepEqual(array, array2); }); +/** + * Test parsing of a well-formed full URL, including protocol and path. + */ +add_task(async function testWellFormedFullUrl() { + const hub = new ModelHub({ rootUrl: FAKE_HUB }); + const url = `${FAKE_HUB}/org1/model1/v1/file/path`; + const result = hub.parseUrl(url); + + Assert.equal( + result.model, + "org1/model1", + "Model should be parsed correctly." + ); + Assert.equal(result.revision, "v1", "Revision should be parsed correctly."); + Assert.equal( + result.file, + "file/path", + "File path should be parsed correctly." + ); +}); + +/** + * Test parsing of a well-formed relative URL, starting with a slash. + */ +add_task(async function testWellFormedRelativeUrl() { + const hub = new ModelHub({ rootUrl: FAKE_HUB }); + + const url = "/org1/model1/v1/file/path"; + const result = hub.parseUrl(url); + + Assert.equal( + result.model, + "org1/model1", + "Model should be parsed correctly." + ); + Assert.equal(result.revision, "v1", "Revision should be parsed correctly."); + Assert.equal( + result.file, + "file/path", + "File path should be parsed correctly." + ); +}); + +/** + * Ensures an error is thrown when the URL does not start with the expected root URL or a slash. + */ +add_task(async function testInvalidDomain() { + const hub = new ModelHub({ rootUrl: FAKE_HUB }); + const url = "https://example.com/org1/model1/v1/file/path"; + Assert.throws( + () => hub.parseUrl(url), + new RegExp(`Error: Invalid domain for model URL: ${url}`), + `Should throw with ${url}` + ); +}); + +/** Tests the method's error handling when the URL format does not include the required segments. + * + */ +add_task(async function testTooFewParts() { + const hub = new ModelHub({ rootUrl: FAKE_HUB }); + const url = "/org1/model1"; + Assert.throws( + () => hub.parseUrl(url), + new RegExp(`Error: Invalid model URL: ${url}`), + `Should throw with ${url}` + ); +}); + // IndexedDB tests /** @@ -247,19 +364,42 @@ add_task(async function test_Init() { await deleteCache(cache); }); +/** + * Test checking existence of data in the cache. + */ +add_task(async function test_PutAndCheckExists() { + const cache = await initializeCache(); + const testData = new ArrayBuffer(8); // Example data + const key = "file.txt"; + await cache.put("org/model", "v1", "file.txt", testData, { + ETag: "ETAG123", + }); + + // Checking if the file exists + let exists = await cache.fileExists("org/model", "v1", key); + Assert.ok(exists, "The file should exist in the cache."); + + // Removing all files from the model + await cache.deleteModel("org/model", "v1"); + + exists = await cache.fileExists("org/model", "v1", key); + Assert.ok(!exists, "The file should be gone from the cache."); + + await deleteCache(cache); +}); + /** * Test adding data to the cache and retrieving it. */ add_task(async function test_PutAndGet() { const cache = await initializeCache(); const testData = new ArrayBuffer(8); // Example data - await cache.put("org", "model", "v1", "file.txt", testData, { + await cache.put("org/model", "v1", "file.txt", testData, { ETag: "ETAG123", }); const [retrievedData, headers] = await cache.getFile( - "org", - "model", + "org/model", "v1", "file.txt" ); @@ -289,14 +429,9 @@ add_task(async function test_GetHeaders() { extra: "extra", }; - await cache.put("org", "model", "v1", "file.txt", testData, headers); + await cache.put("org/model", "v1", "file.txt", testData, headers); - const storedHeaders = await cache.getHeaders( - "org", - "model", - "v1", - "file.txt" - ); + const storedHeaders = await cache.getHeaders("org/model", "v1", "file.txt"); // The `extra` field should be removed from the stored headers because // it's not part of the allowed keys. @@ -318,22 +453,8 @@ add_task(async function test_GetHeaders() { */ add_task(async function test_ListModels() { const cache = await initializeCache(); - await cache.put( - "org1", - "modelA", - "v1", - "file1.txt", - new ArrayBuffer(8), - null - ); - await cache.put( - "org2", - "modelB", - "v1", - "file2.txt", - new ArrayBuffer(8), - null - ); + await cache.put("org1/modelA", "v1", "file1.txt", new ArrayBuffer(8), null); + await cache.put("org2/modelB", "v1", "file2.txt", new ArrayBuffer(8), null); const models = await cache.listModels(); Assert.ok( @@ -348,10 +469,10 @@ add_task(async function test_ListModels() { */ add_task(async function test_DeleteModel() { const cache = await initializeCache(); - await cache.put("org", "model", "v1", "file.txt", new ArrayBuffer(8), null); - await cache.deleteModel("org", "model", "v1"); + await cache.put("org/model", "v1", "file.txt", new ArrayBuffer(8), null); + await cache.deleteModel("org/model", "v1"); - const dataAfterDelete = await cache.getFile("org", "model", "v1", "file.txt"); + const dataAfterDelete = await cache.getFile("org/model", "v1", "file.txt"); Assert.equal( dataAfterDelete, null, diff --git a/toolkit/components/ml/tests/browser/browser_ml_engine.js b/toolkit/components/ml/tests/browser/browser_ml_engine.js index 6942809d6d..3a93b78182 100644 --- a/toolkit/components/ml/tests/browser/browser_ml_engine.js +++ b/toolkit/components/ml/tests/browser/browser_ml_engine.js @@ -5,6 +5,8 @@ /// +requestLongerTimeout(2); + async function setup({ disabled = false, prefs = [] } = {}) { const { removeMocks, remoteClients } = await createAndMockMLRemoteSettings({ autoDownloadFromRemoteSettings: false, @@ -15,6 +17,7 @@ async function setup({ disabled = false, prefs = [] } = {}) { // Enabled by default. ["browser.ml.enable", !disabled], ["browser.ml.logLevel", "All"], + ["browser.ml.modelCacheTimeout", 1000], ...prefs, ], }); @@ -33,6 +36,8 @@ async function setup({ disabled = false, prefs = [] } = {}) { }; } +const PIPELINE_OPTIONS = new PipelineOptions({ taskName: "echo" }); + add_task(async function test_ml_engine_basics() { const { cleanup, remoteClients } = await setup(); @@ -40,22 +45,18 @@ add_task(async function test_ml_engine_basics() { const mlEngineParent = await EngineProcess.getMLEngineParent(); info("Get summarizer"); - const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel - ); + const summarizer = mlEngineParent.getEngine(PIPELINE_OPTIONS); info("Run the summarizer"); - const summarizePromise = summarizer.run("This gets cut in half."); + const inferencePromise = summarizer.run({ data: "This gets echoed." }); info("Wait for the pending downloads."); - await remoteClients.models.resolvePendingDownloads(1); - await remoteClients.wasm.resolvePendingDownloads(1); + await remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1); - is( - await summarizePromise, - "This gets c", - "The text gets cut in half simulating summarizing" + Assert.equal( + (await inferencePromise).output, + "This gets echoed.", + "The text get echoed exercising the whole flow." ); ok( @@ -68,40 +69,6 @@ add_task(async function test_ml_engine_basics() { await cleanup(); }); -add_task(async function test_ml_engine_model_rejection() { - const { cleanup, remoteClients } = await setup(); - - info("Get the engine process"); - const mlEngineParent = await EngineProcess.getMLEngineParent(); - - info("Get summarizer"); - const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel - ); - - info("Run the summarizer"); - const summarizePromise = summarizer.run("This gets cut in half."); - - info("Wait for the pending downloads."); - await remoteClients.wasm.resolvePendingDownloads(1); - await remoteClients.models.rejectPendingDownloads(1); - - let error; - try { - await summarizePromise; - } catch (e) { - error = e; - } - is( - error?.message, - "Intentionally rejecting downloads.", - "The error is correctly surfaced." - ); - - await cleanup(); -}); - add_task(async function test_ml_engine_wasm_rejection() { const { cleanup, remoteClients } = await setup(); @@ -109,21 +76,18 @@ add_task(async function test_ml_engine_wasm_rejection() { const mlEngineParent = await EngineProcess.getMLEngineParent(); info("Get summarizer"); - const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel - ); + const summarizer = mlEngineParent.getEngine(PIPELINE_OPTIONS); info("Run the summarizer"); - const summarizePromise = summarizer.run("This gets cut in half."); + const inferencePromise = summarizer.run({ data: "This gets echoed." }); info("Wait for the pending downloads."); - await remoteClients.wasm.rejectPendingDownloads(1); - await remoteClients.models.resolvePendingDownloads(1); + await remoteClients["ml-onnx-runtime"].rejectPendingDownloads(1); + //await remoteClients.models.resolvePendingDownloads(1); let error; try { - await summarizePromise; + await inferencePromise; } catch (e) { error = e; } @@ -146,21 +110,18 @@ add_task(async function test_ml_engine_model_error() { const mlEngineParent = await EngineProcess.getMLEngineParent(); info("Get summarizer"); - const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel - ); + const summarizer = mlEngineParent.getEngine(PIPELINE_OPTIONS); info("Run the summarizer with a throwing example."); - const summarizePromise = summarizer.run("throw"); + const inferencePromise = summarizer.run("throw"); info("Wait for the pending downloads."); - await remoteClients.wasm.resolvePendingDownloads(1); - await remoteClients.models.resolvePendingDownloads(1); + await remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1); + //await remoteClients.models.resolvePendingDownloads(1); let error; try { - await summarizePromise; + await inferencePromise; } catch (e) { error = e; } @@ -186,22 +147,18 @@ add_task(async function test_ml_engine_destruction() { const mlEngineParent = await EngineProcess.getMLEngineParent(); info("Get summarizer"); - const summarizer = mlEngineParent.getEngine( - "summarizer", - SummarizerModel.getModel - ); + const summarizer = mlEngineParent.getEngine(PIPELINE_OPTIONS); info("Run the summarizer"); - const summarizePromise = summarizer.run("This gets cut in half."); + const inferencePromise = summarizer.run({ data: "This gets echoed." }); info("Wait for the pending downloads."); - await remoteClients.models.resolvePendingDownloads(1); - await remoteClients.wasm.resolvePendingDownloads(1); + await remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1); - is( - await summarizePromise, - "This gets c", - "The text gets cut in half simulating summarizing" + Assert.equal( + (await inferencePromise).output, + "This gets echoed.", + "The text get echoed exercising the whole flow." ); ok( @@ -217,3 +174,57 @@ add_task(async function test_ml_engine_destruction() { await cleanup(); }); + +/** + * Tests that we display a nice error message when the pref is off + */ +add_task(async function test_pref_is_off() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.ml.enable", false]], + }); + + info("Get the engine process"); + let error; + + try { + await EngineProcess.getMLEngineParent(); + } catch (e) { + error = e; + } + is( + error?.message, + "MLEngine is disabled. Check the browser.ml prefs.", + "The error is correctly surfaced." + ); + + await SpecialPowers.pushPrefEnv({ + set: [["browser.ml.enable", true]], + }); +}); + +/** + * Tests that we verify the task name is valid + */ +add_task(async function test_invalid_task_name() { + const { cleanup, remoteClients } = await setup(); + + const options = new PipelineOptions({ taskName: "inv#alid" }); + const mlEngineParent = await EngineProcess.getMLEngineParent(); + const summarizer = mlEngineParent.getEngine(options); + + let error; + + try { + const res = summarizer.run({ data: "This gets echoed." }); + await remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1); + await res; + } catch (e) { + error = e; + } + is( + error?.message, + "Invalid task name. Task name should contain only alphanumeric characters and underscores/dashes.", + "The error is correctly surfaced." + ); + await cleanup(); +}); diff --git a/toolkit/components/ml/tests/browser/browser_ml_utils.js b/toolkit/components/ml/tests/browser/browser_ml_utils.js new file mode 100644 index 0000000000..c215349af4 --- /dev/null +++ b/toolkit/components/ml/tests/browser/browser_ml_utils.js @@ -0,0 +1,26 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const { arrayBufferToBlobURL } = ChromeUtils.importESModule( + "chrome://global/content/ml/Utils.sys.mjs" +); + +/** + * Test arrayBufferToBlobURL function. + */ +add_task(async function test_ml_utils_array_buffer_to_blob_url() { + const buffer = new ArrayBuffer(8); + const blobURL = arrayBufferToBlobURL(buffer); + + Assert.equal( + typeof blobURL, + "string", + "arrayBufferToBlobURL should return a string" + ); + Assert.equal( + blobURL.startsWith("blob:"), + true, + "The returned string should be a Blob URL" + ); +}); diff --git a/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/config.json b/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/config.json new file mode 100644 index 0000000000..50dbb760bb --- /dev/null +++ b/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/config.json @@ -0,0 +1,21 @@ +{ + "architectures": ["BertForMaskedLM"], + "attention_probs_dropout_prob": 0.1, + "gradient_checkpointing": false, + "hidden_act": "gelu", + "hidden_dropout_prob": 0.1, + "hidden_size": 768, + "initializer_range": 0.02, + "intermediate_size": 3072, + "layer_norm_eps": 1e-12, + "max_position_embeddings": 512, + "model_type": "bert", + "num_attention_heads": 12, + "num_hidden_layers": 12, + "pad_token_id": 0, + "position_embedding_type": "absolute", + "transformers_version": "4.6.0.dev0", + "type_vocab_size": 2, + "use_cache": true, + "vocab_size": 30522 +} diff --git a/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/onnx/config.json b/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/onnx/config.json new file mode 100644 index 0000000000..50dbb760bb --- /dev/null +++ b/toolkit/components/ml/tests/browser/data/acme/bert/resolve/v0.1/onnx/config.json @@ -0,0 +1,21 @@ +{ + "architectures": ["BertForMaskedLM"], + "attention_probs_dropout_prob": 0.1, + "gradient_checkpointing": false, + "hidden_act": "gelu", + "hidden_dropout_prob": 0.1, + "hidden_size": 768, + "initializer_range": 0.02, + "intermediate_size": 3072, + "layer_norm_eps": 1e-12, + "max_position_embeddings": 512, + "model_type": "bert", + "num_attention_heads": 12, + "num_hidden_layers": 12, + "pad_token_id": 0, + "position_embedding_type": "absolute", + "transformers_version": "4.6.0.dev0", + "type_vocab_size": 2, + "use_cache": true, + "vocab_size": 30522 +} diff --git a/toolkit/components/ml/tests/browser/head.js b/toolkit/components/ml/tests/browser/head.js index 9fc20c0e84..25e611a753 100644 --- a/toolkit/components/ml/tests/browser/head.js +++ b/toolkit/components/ml/tests/browser/head.js @@ -5,13 +5,6 @@ "use strict"; -/** - * @type {import("../../content/SummarizerModel.sys.mjs")} - */ -const { SummarizerModel } = ChromeUtils.importESModule( - "chrome://global/content/ml/SummarizerModel.sys.mjs" -); - /** * @type {import("../../actors/MLEngineParent.sys.mjs")} */ @@ -23,6 +16,14 @@ const { ModelHub, IndexedDBCache } = ChromeUtils.importESModule( "chrome://global/content/ml/ModelHub.sys.mjs" ); +const { getRuntimeWasmFilename } = ChromeUtils.importESModule( + "chrome://global/content/ml/Utils.sys.mjs" +); + +const { PipelineOptions } = ChromeUtils.importESModule( + "chrome://global/content/ml/EngineProcess.sys.mjs" +); + // This test suite shares some utility functions with translations as they work in a very // similar fashion. Eventually, the plan is to unify these two components. Services.scriptloader.loadSubScript( @@ -30,94 +31,39 @@ Services.scriptloader.loadSubScript( this ); -function getDefaultModelRecords() { - return [ - { - name: "summarizer-model", - version: SummarizerModel.MODEL_MAJOR_VERSION + ".0", - }, - ]; -} - function getDefaultWasmRecords() { return [ { - name: "inference-engine", + name: getRuntimeWasmFilename(), version: MLEngineParent.WASM_MAJOR_VERSION + ".0", }, ]; } -/** - * Creates a local RemoteSettingsClient for use within tests. - * - * @param {boolean} autoDownloadFromRemoteSettings - * @param {object[]} models - * @returns {AttachmentMock} - */ -async function createMLModelsRemoteClient( - autoDownloadFromRemoteSettings, - models = getDefaultModelRecords() -) { - const { RemoteSettings } = ChromeUtils.importESModule( - "resource://services-settings/remote-settings.sys.mjs" - ); - const mockedCollectionName = "test-ml-models"; - const client = RemoteSettings( - `${mockedCollectionName}-${_remoteSettingsMockId++}` - ); - const metadata = {}; - await client.db.clear(); - await client.db.importChanges( - metadata, - Date.now(), - models.map(({ name, version }) => ({ - id: crypto.randomUUID(), - name, - version, - last_modified: Date.now(), - schema: Date.now(), - attachment: { - hash: `${crypto.randomUUID()}`, - size: `123`, - filename: name, - location: `main-workspace/ml-models/${crypto.randomUUID()}.bin`, - mimetype: "application/octet-stream", - }, - })) - ); - - return createAttachmentMock( - client, - mockedCollectionName, - autoDownloadFromRemoteSettings - ); -} - async function createAndMockMLRemoteSettings({ - models = getDefaultModelRecords(), autoDownloadFromRemoteSettings = false, } = {}) { + const runtime = await createMLWasmRemoteClient( + autoDownloadFromRemoteSettings + ); + const options = await createOptionsRemoteClient(); + const remoteClients = { - models: await createMLModelsRemoteClient( - autoDownloadFromRemoteSettings, - models - ), - wasm: await createMLWasmRemoteClient(autoDownloadFromRemoteSettings), + "ml-onnx-runtime": runtime, + "ml-inference-options": options, }; - MLEngineParent.mockRemoteSettings(remoteClients.wasm.client); - SummarizerModel.mockRemoteSettings(remoteClients.models.client); + MLEngineParent.mockRemoteSettings({ + "ml-onnx-runtime": runtime.client, + "ml-inference-options": options, + }); return { async removeMocks() { - await remoteClients.models.client.attachments.deleteAll(); - await remoteClients.models.client.db.clear(); - await remoteClients.wasm.client.attachments.deleteAll(); - await remoteClients.wasm.client.db.clear(); - + await runtime.client.attachments.deleteAll(); + await runtime.client.db.clear(); + await options.db.clear(); MLEngineParent.removeMocks(); - SummarizerModel.removeMocks(); }, remoteClients, }; @@ -157,3 +103,32 @@ async function createMLWasmRemoteClient(autoDownloadFromRemoteSettings) { autoDownloadFromRemoteSettings ); } + +/** + * Creates a local RemoteSettingsClient for use within tests. + * + * @returns {RemoteSettings} + */ +async function createOptionsRemoteClient() { + const { RemoteSettings } = ChromeUtils.importESModule( + "resource://services-settings/remote-settings.sys.mjs" + ); + const mockedCollectionName = "test-ml-inference-options"; + const client = RemoteSettings( + `${mockedCollectionName}-${_remoteSettingsMockId++}` + ); + + const record = { + taskName: "echo", + modelId: "mozilla/distilvit", + processorId: "mozilla/distilvit", + tokenizerId: "mozilla/distilvit", + modelRevision: "main", + processorRevision: "main", + tokenizerRevision: "main", + id: "74a71cfd-1734-44e6-85c0-69cf3e874138", + }; + await client.db.clear(); + await client.db.importChanges({}, Date.now(), [record]); + return client; +} diff --git a/toolkit/components/ml/vendor/LICENSE b/toolkit/components/ml/vendor/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/toolkit/components/ml/vendor/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/toolkit/components/ml/vendor/README.md b/toolkit/components/ml/vendor/README.md new file mode 100644 index 0000000000..6a57fae8b1 --- /dev/null +++ b/toolkit/components/ml/vendor/README.md @@ -0,0 +1,12 @@ +# vendored dependencies + +- onnxruntime-web 1.14.0 (UMD modules) +- Transformers.js 2.16.1 (patched for gecko) + +To build the vendored dependencies, run `./build.sh`. + +The Transformers.js patch is required for building Transformers.js +without including the `onnxruntime-web` NPM bundle. It uses +webpack's `externals` feature to include the onnxruntime-web UMD +module and changes the import statement in `backends/onnx.js` to +point to it. diff --git a/toolkit/components/ml/vendor/build.sh b/toolkit/components/ml/vendor/build.sh new file mode 100755 index 0000000000..b8cd19e6f3 --- /dev/null +++ b/toolkit/components/ml/vendor/build.sh @@ -0,0 +1,36 @@ +# !/bin/bash +set -xe + +# grabbing and patching transformers.js for gecko +rm -rf tmp +mkdir tmp +pushd tmp +git clone --depth 1 --branch 2.16.1 https://github.com/xenova/transformers.js +cd transformers.js +git apply ../../gecko.patch +npm install +npm run build +cp dist/transformers.js ../../transformers-dev.js +cp dist/transformers.min.js ../../transformers.js +popd +rm -rf tmp + +# grabbing and patching onnxruntime-web for gecko. + +# fetch the tarball URL from npm +TARBALL_URL=$(npm view onnxruntime-web@1.14.0 dist.tarball) +wget "${TARBALL_URL}" -O dist.tgz + +# grab the two files we need +tar -xzf dist.tgz +rm dist.tgz +cp package/dist/ort.js ort-dev.js +cp package/dist/ort.min.js ort.js +rm -rf package + +# remove the eval() calls +sed -i '' '1855,1859d' ort-dev.js +sed -i '' 's/function inquire(moduleName){try{var mod=eval("quire".replace(\/^\/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(t){}return null}/function inquire(moduleName){return null}/g' ort.js + +# remove the last line of ort-dev.js (map) +sed -i '' '$d' ort-dev.js diff --git a/toolkit/components/ml/vendor/gecko.patch b/toolkit/components/ml/vendor/gecko.patch new file mode 100644 index 0000000000..8c0392e3aa --- /dev/null +++ b/toolkit/components/ml/vendor/gecko.patch @@ -0,0 +1,84 @@ +From 2804004525c65df99cd8a563cfd316e796618ebd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Tarek=20Ziad=C3=A9?= +Date: Wed, 10 Apr 2024 10:06:19 +0200 +Subject: [PATCH 1/1] patched +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Tarek Ziadé +--- + package.json | 2 +- + src/backends/onnx.js | 8 ++++++-- + tsconfig.json | 13 +++++++++++++ + webpack.config.js | 4 ++++ + 4 files changed, 24 insertions(+), 3 deletions(-) + create mode 100644 tsconfig.json + +diff --git a/package.json b/package.json +index 446fd5f..24825d6 100644 +--- a/package.json ++++ b/package.json +@@ -6,7 +6,7 @@ + "types": "./types/transformers.d.ts", + "type": "module", + "scripts": { +- "typegen": "tsc ./src/transformers.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outDir types", ++ "typegen": "tsc", + "dev": "webpack serve --no-client-overlay", + "build": "webpack && npm run typegen", + "generate-tests": "python -m tests.generate_tests", +diff --git a/src/backends/onnx.js b/src/backends/onnx.js +index 0bee3dc..030eff7 100644 +--- a/src/backends/onnx.js ++++ b/src/backends/onnx.js +@@ -18,8 +18,12 @@ + + // NOTE: Import order matters here. We need to import `onnxruntime-node` before `onnxruntime-web`. + // In either case, we select the default export if it exists, otherwise we use the named export. +-import * as ONNX_NODE from 'onnxruntime-node'; +-import * as ONNX_WEB from 'onnxruntime-web'; ++//import * as ONNX_NODE from 'onnxruntime-node'; ++//import * as ONNX_WEB from 'onnxruntime-web'; ++ ++import 'onnxruntime-web'; ++const ONNX_WEB = ort; ++ + + /** @type {import('onnxruntime-web')} The ONNX runtime module. */ + export let ONNX; +diff --git a/tsconfig.json b/tsconfig.json +new file mode 100644 +index 0000000..8892b18 +--- /dev/null ++++ b/tsconfig.json +@@ -0,0 +1,13 @@ ++{ ++ "files": [ ++ "./src/transformers.js" ++ ], ++ "compilerOptions": { ++ "allowJs": true, ++ "declaration": true, ++ "emitDeclarationOnly": true, ++ "declarationMap": true, ++ "outDir": "types", ++ "types": [] // Or specify only the types you need ++ } ++} +diff --git a/webpack.config.js b/webpack.config.js +index c958b45..8b6b98b 100644 +--- a/webpack.config.js ++++ b/webpack.config.js +@@ -51,4 +51,8 @@ export default { + experiments: { + outputModule: true, + }, ++ externals: { ++ 'onnxruntime-node': 'NOT_USED', ++ 'onnxruntime-web': 'chrome://global/content/ml/ort-dev.js', ++ }, + }; +-- +2.43.0 + diff --git a/toolkit/components/ml/vendor/moz.yaml b/toolkit/components/ml/vendor/moz.yaml new file mode 100644 index 0000000000..a111941603 --- /dev/null +++ b/toolkit/components/ml/vendor/moz.yaml @@ -0,0 +1,15 @@ +schema: 1 + +bugzilla: + product: Core + component: Machine Learning + +origin: + name: transformers.js + description: Transformers.js Machine Learning Library for the web + url: https://huggingface.co/docs/transformers.js/index + release: 2.16.1 + revision: 314b7f0dc4291e8a38a516073b710d7c6a29aefb + license: Apache-2.0 + license-file: LICENSE + notes: see README.md for more details. diff --git a/toolkit/components/ml/vendor/ort-dev.js b/toolkit/components/ml/vendor/ort-dev.js new file mode 100644 index 0000000000..8c53b1521d --- /dev/null +++ b/toolkit/components/ml/vendor/ort-dev.js @@ -0,0 +1,29506 @@ +/*! +* ONNX Runtime Web v1.14.0 +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. +*/ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["ort"] = factory(); + else + root["ort"] = factory(); +})(self, () => { +return /******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ "../common/dist/lib/backend-impl.js": +/*!******************************************!*\ + !*** ../common/dist/lib/backend-impl.js ***! + \******************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "registerBackend": () => (/* binding */ registerBackend), +/* harmony export */ "resolveBackend": () => (/* binding */ resolveBackend) +/* harmony export */ }); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +const backends = {}; +const backendsSortedByPriority = []; +/** + * Register a backend. + * + * @param name - the name as a key to lookup as an execution provider. + * @param backend - the backend object. + * @param priority - an integer indicating the priority of the backend. Higher number means higher priority. if priority + * < 0, it will be considered as a 'beta' version and will not be used as a fallback backend by default. + * + * @internal + */ +const registerBackend = (name, backend, priority) => { + if (backend && typeof backend.init === 'function' && typeof backend.createSessionHandler === 'function') { + const currentBackend = backends[name]; + if (currentBackend === undefined) { + backends[name] = { backend, priority }; + } + else if (currentBackend.priority > priority) { + // same name is already registered with a higher priority. skip registeration. + return; + } + else if (currentBackend.priority === priority) { + if (currentBackend.backend !== backend) { + throw new Error(`cannot register backend "${name}" using priority ${priority}`); + } + } + if (priority >= 0) { + const i = backendsSortedByPriority.indexOf(name); + if (i !== -1) { + backendsSortedByPriority.splice(i, 1); + } + for (let i = 0; i < backendsSortedByPriority.length; i++) { + if (backends[backendsSortedByPriority[i]].priority <= priority) { + backendsSortedByPriority.splice(i, 0, name); + return; + } + } + backendsSortedByPriority.push(name); + } + return; + } + throw new TypeError('not a valid backend'); +}; +/** + * Resolve backend by specified hints. + * + * @param backendHints - a list of execution provider names to lookup. If omitted use registered backends as list. + * @returns a promise that resolves to the backend. + * + * @internal + */ +const resolveBackend = async (backendHints) => { + const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints; + const errors = []; + for (const backendName of backendNames) { + const backendInfo = backends[backendName]; + if (backendInfo) { + if (backendInfo.initialized) { + return backendInfo.backend; + } + else if (backendInfo.aborted) { + continue; // current backend is unavailable; try next + } + const isInitializing = !!backendInfo.initPromise; + try { + if (!isInitializing) { + backendInfo.initPromise = backendInfo.backend.init(); + } + await backendInfo.initPromise; + backendInfo.initialized = true; + return backendInfo.backend; + } + catch (e) { + if (!isInitializing) { + errors.push({ name: backendName, err: e }); + } + backendInfo.aborted = true; + } + finally { + delete backendInfo.initPromise; + } + } + } + throw new Error(`no available backend found. ERR: ${errors.map(e => `[${e.name}] ${e.err}`).join(', ')}`); +}; +//# sourceMappingURL=backend-impl.js.map + +/***/ }), + +/***/ "../common/dist/lib/backend.js": +/*!*************************************!*\ + !*** ../common/dist/lib/backend.js ***! + \*************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "registerBackend": () => (/* reexport safe */ _backend_impl__WEBPACK_IMPORTED_MODULE_0__.registerBackend) +/* harmony export */ }); +/* harmony import */ var _backend_impl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./backend-impl */ "../common/dist/lib/backend-impl.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +//# sourceMappingURL=backend.js.map + +/***/ }), + +/***/ "../common/dist/lib/env-impl.js": +/*!**************************************!*\ + !*** ../common/dist/lib/env-impl.js ***! + \**************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "EnvImpl": () => (/* binding */ EnvImpl) +/* harmony export */ }); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +class EnvImpl { + constructor() { + this.wasm = {}; + this.webgl = {}; + this.logLevelInternal = 'warning'; + } + // TODO standadize the getter and setter convention in env for other fields. + set logLevel(value) { + if (value === undefined) { + return; + } + if (typeof value !== 'string' || ['verbose', 'info', 'warning', 'error', 'fatal'].indexOf(value) === -1) { + throw new Error(`Unsupported logging level: ${value}`); + } + this.logLevelInternal = value; + } + get logLevel() { + return this.logLevelInternal; + } +} +//# sourceMappingURL=env-impl.js.map + +/***/ }), + +/***/ "../common/dist/lib/env.js": +/*!*********************************!*\ + !*** ../common/dist/lib/env.js ***! + \*********************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "env": () => (/* binding */ env) +/* harmony export */ }); +/* harmony import */ var _env_impl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./env-impl */ "../common/dist/lib/env-impl.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Represent a set of flags as a global singleton. + */ +const env = new _env_impl__WEBPACK_IMPORTED_MODULE_0__.EnvImpl(); +//# sourceMappingURL=env.js.map + +/***/ }), + +/***/ "../common/dist/lib/index.js": +/*!***********************************!*\ + !*** ../common/dist/lib/index.js ***! + \***********************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "InferenceSession": () => (/* reexport safe */ _inference_session__WEBPACK_IMPORTED_MODULE_2__.InferenceSession), +/* harmony export */ "Tensor": () => (/* reexport safe */ _tensor__WEBPACK_IMPORTED_MODULE_3__.Tensor), +/* harmony export */ "env": () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_1__.env), +/* harmony export */ "registerBackend": () => (/* reexport safe */ _backend__WEBPACK_IMPORTED_MODULE_0__.registerBackend) +/* harmony export */ }); +/* harmony import */ var _backend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./backend */ "../common/dist/lib/backend.js"); +/* harmony import */ var _env__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./env */ "../common/dist/lib/env.js"); +/* harmony import */ var _inference_session__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./inference-session */ "../common/dist/lib/inference-session.js"); +/* harmony import */ var _tensor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./tensor */ "../common/dist/lib/tensor.js"); +/* harmony import */ var _onnx_value__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./onnx-value */ "../common/dist/lib/onnx-value.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +/** + * # ONNX Runtime JavaScript API + * + * ONNX Runtime JavaScript API is a unified API for all JavaScript usages, including the following NPM packages: + * + * - [onnxruntime-node](https://www.npmjs.com/package/onnxruntime-node) + * - [onnxruntime-web](https://www.npmjs.com/package/onnxruntime-web) + * - [onnxruntime-react-native](https://www.npmjs.com/package/onnxruntime-react-native) + * + * See also: + * - [Get Started](https://onnxruntime.ai/docs/get-started/with-javascript.html) + * - [Inference examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) + * + * @packageDocumentation + */ + + + + + +//# sourceMappingURL=index.js.map + +/***/ }), + +/***/ "../common/dist/lib/inference-session-impl.js": +/*!****************************************************!*\ + !*** ../common/dist/lib/inference-session-impl.js ***! + \****************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "InferenceSession": () => (/* binding */ InferenceSession) +/* harmony export */ }); +/* harmony import */ var _backend_impl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./backend-impl */ "../common/dist/lib/backend-impl.js"); +/* harmony import */ var _tensor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./tensor */ "../common/dist/lib/tensor.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + + +class InferenceSession { + constructor(handler) { + this.handler = handler; + } + async run(feeds, arg1, arg2) { + const fetches = {}; + let options = {}; + // check inputs + if (typeof feeds !== 'object' || feeds === null || feeds instanceof _tensor__WEBPACK_IMPORTED_MODULE_1__.Tensor || Array.isArray(feeds)) { + throw new TypeError('\'feeds\' must be an object that use input names as keys and OnnxValue as corresponding values.'); + } + let isFetchesEmpty = true; + // determine which override is being used + if (typeof arg1 === 'object') { + if (arg1 === null) { + throw new TypeError('Unexpected argument[1]: cannot be null.'); + } + if (arg1 instanceof _tensor__WEBPACK_IMPORTED_MODULE_1__.Tensor) { + throw new TypeError('\'fetches\' cannot be a Tensor'); + } + if (Array.isArray(arg1)) { + if (arg1.length === 0) { + throw new TypeError('\'fetches\' cannot be an empty array.'); + } + isFetchesEmpty = false; + // output names + for (const name of arg1) { + if (typeof name !== 'string') { + throw new TypeError('\'fetches\' must be a string array or an object.'); + } + if (this.outputNames.indexOf(name) === -1) { + throw new RangeError(`'fetches' contains invalid output name: ${name}.`); + } + fetches[name] = null; + } + if (typeof arg2 === 'object' && arg2 !== null) { + options = arg2; + } + else if (typeof arg2 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + } + else { + // decide whether arg1 is fetches or options + // if any output name is present and its value is valid OnnxValue, we consider it fetches + let isFetches = false; + const arg1Keys = Object.getOwnPropertyNames(arg1); + for (const name of this.outputNames) { + if (arg1Keys.indexOf(name) !== -1) { + const v = arg1[name]; + if (v === null || v instanceof _tensor__WEBPACK_IMPORTED_MODULE_1__.Tensor) { + isFetches = true; + isFetchesEmpty = false; + fetches[name] = v; + } + } + } + if (isFetches) { + if (typeof arg2 === 'object' && arg2 !== null) { + options = arg2; + } + else if (typeof arg2 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + } + else { + options = arg1; + } + } + } + else if (typeof arg1 !== 'undefined') { + throw new TypeError('Unexpected argument[1]: must be \'fetches\' or \'options\'.'); + } + // check if all inputs are in feed + for (const name of this.inputNames) { + if (typeof feeds[name] === 'undefined') { + throw new Error(`input '${name}' is missing in 'feeds'.`); + } + } + // if no fetches is specified, we use the full output names list + if (isFetchesEmpty) { + for (const name of this.outputNames) { + fetches[name] = null; + } + } + // feeds, fetches and options are prepared + const results = await this.handler.run(feeds, fetches, options); + const returnValue = {}; + for (const key in results) { + if (Object.hasOwnProperty.call(results, key)) { + returnValue[key] = new _tensor__WEBPACK_IMPORTED_MODULE_1__.Tensor(results[key].type, results[key].data, results[key].dims); + } + } + return returnValue; + } + static async create(arg0, arg1, arg2, arg3) { + // either load from a file or buffer + let filePathOrUint8Array; + let options = {}; + if (typeof arg0 === 'string') { + filePathOrUint8Array = arg0; + if (typeof arg1 === 'object' && arg1 !== null) { + options = arg1; + } + else if (typeof arg1 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + } + else if (arg0 instanceof Uint8Array) { + filePathOrUint8Array = arg0; + if (typeof arg1 === 'object' && arg1 !== null) { + options = arg1; + } + else if (typeof arg1 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + } + else if (arg0 instanceof ArrayBuffer || + (typeof SharedArrayBuffer !== 'undefined' && arg0 instanceof SharedArrayBuffer)) { + const buffer = arg0; + let byteOffset = 0; + let byteLength = arg0.byteLength; + if (typeof arg1 === 'object' && arg1 !== null) { + options = arg1; + } + else if (typeof arg1 === 'number') { + byteOffset = arg1; + if (!Number.isSafeInteger(byteOffset)) { + throw new RangeError('\'byteOffset\' must be an integer.'); + } + if (byteOffset < 0 || byteOffset >= buffer.byteLength) { + throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`); + } + byteLength = arg0.byteLength - byteOffset; + if (typeof arg2 === 'number') { + byteLength = arg2; + if (!Number.isSafeInteger(byteLength)) { + throw new RangeError('\'byteLength\' must be an integer.'); + } + if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) { + throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`); + } + if (typeof arg3 === 'object' && arg3 !== null) { + options = arg3; + } + else if (typeof arg3 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + } + else if (typeof arg2 !== 'undefined') { + throw new TypeError('\'byteLength\' must be a number.'); + } + } + else if (typeof arg1 !== 'undefined') { + throw new TypeError('\'options\' must be an object.'); + } + filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength); + } + else { + throw new TypeError('Unexpected argument[0]: must be \'path\' or \'buffer\'.'); + } + // get backend hints + const eps = options.executionProviders || []; + const backendHints = eps.map(i => typeof i === 'string' ? i : i.name); + const backend = await (0,_backend_impl__WEBPACK_IMPORTED_MODULE_0__.resolveBackend)(backendHints); + const handler = await backend.createSessionHandler(filePathOrUint8Array, options); + return new InferenceSession(handler); + } + startProfiling() { + this.handler.startProfiling(); + } + endProfiling() { + this.handler.endProfiling(); + } + get inputNames() { + return this.handler.inputNames; + } + get outputNames() { + return this.handler.outputNames; + } +} +//# sourceMappingURL=inference-session-impl.js.map + +/***/ }), + +/***/ "../common/dist/lib/inference-session.js": +/*!***********************************************!*\ + !*** ../common/dist/lib/inference-session.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "InferenceSession": () => (/* binding */ InferenceSession) +/* harmony export */ }); +/* harmony import */ var _inference_session_impl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./inference-session-impl */ "../common/dist/lib/inference-session-impl.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// eslint-disable-next-line @typescript-eslint/naming-convention +const InferenceSession = _inference_session_impl__WEBPACK_IMPORTED_MODULE_0__.InferenceSession; +//# sourceMappingURL=inference-session.js.map + +/***/ }), + +/***/ "../common/dist/lib/onnx-value.js": +/*!****************************************!*\ + !*** ../common/dist/lib/onnx-value.js ***! + \****************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +//# sourceMappingURL=onnx-value.js.map + +/***/ }), + +/***/ "../common/dist/lib/tensor-impl.js": +/*!*****************************************!*\ + !*** ../common/dist/lib/tensor-impl.js ***! + \*****************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "Tensor": () => (/* binding */ Tensor) +/* harmony export */ }); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +const isBigInt64ArrayAvailable = typeof BigInt64Array !== 'undefined' && typeof BigInt64Array.from === 'function'; +const isBigUint64ArrayAvailable = typeof BigUint64Array !== 'undefined' && typeof BigUint64Array.from === 'function'; +// a runtime map that maps type string to TypedArray constructor. Should match Tensor.DataTypeMap. +const NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = new Map([ + ['float32', Float32Array], + ['uint8', Uint8Array], + ['int8', Int8Array], + ['uint16', Uint16Array], + ['int16', Int16Array], + ['int32', Int32Array], + ['bool', Uint8Array], + ['float64', Float64Array], + ['uint32', Uint32Array], +]); +// a runtime map that maps type string to TypedArray constructor. Should match Tensor.DataTypeMap. +const NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = new Map([ + [Float32Array, 'float32'], + [Uint8Array, 'uint8'], + [Int8Array, 'int8'], + [Uint16Array, 'uint16'], + [Int16Array, 'int16'], + [Int32Array, 'int32'], + [Float64Array, 'float64'], + [Uint32Array, 'uint32'], +]); +if (isBigInt64ArrayAvailable) { + NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('int64', BigInt64Array); + NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, 'int64'); +} +if (isBigUint64ArrayAvailable) { + NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('uint64', BigUint64Array); + NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, 'uint64'); +} +/** + * calculate size from dims. + * + * @param dims the dims array. May be an illegal input. + */ +const calculateSize = (dims) => { + let size = 1; + for (let i = 0; i < dims.length; i++) { + const dim = dims[i]; + if (typeof dim !== 'number' || !Number.isSafeInteger(dim)) { + throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`); + } + if (dim < 0) { + throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`); + } + size *= dim; + } + return size; +}; +class Tensor { + constructor(arg0, arg1, arg2) { + let type; + let data; + let dims; + // check whether arg0 is type or data + if (typeof arg0 === 'string') { + // + // Override: constructor(type, data, ...) + // + type = arg0; + dims = arg2; + if (arg0 === 'string') { + // string tensor + if (!Array.isArray(arg1)) { + throw new TypeError('A string tensor\'s data must be a string array.'); + } + // we don't check whether every element in the array is string; this is too slow. we assume it's correct and + // error will be populated at inference + data = arg1; + } + else { + // numeric tensor + const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0); + if (typedArrayConstructor === undefined) { + throw new TypeError(`Unsupported tensor type: ${arg0}.`); + } + if (Array.isArray(arg1)) { + // use 'as any' here because TypeScript's check on type of 'SupportedTypedArrayConstructors.from()' produces + // incorrect results. + // 'typedArrayConstructor' should be one of the typed array prototype objects. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data = typedArrayConstructor.from(arg1); + } + else if (arg1 instanceof typedArrayConstructor) { + data = arg1; + } + else { + throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`); + } + } + } + else { + // + // Override: constructor(data, ...) + // + dims = arg1; + if (Array.isArray(arg0)) { + // only boolean[] and string[] is supported + if (arg0.length === 0) { + throw new TypeError('Tensor type cannot be inferred from an empty array.'); + } + const firstElementType = typeof arg0[0]; + if (firstElementType === 'string') { + type = 'string'; + data = arg0; + } + else if (firstElementType === 'boolean') { + type = 'bool'; + // 'arg0' is of type 'boolean[]'. Uint8Array.from(boolean[]) actually works, but typescript thinks this is + // wrong type. We use 'as any' to make it happy. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data = Uint8Array.from(arg0); + } + else { + throw new TypeError(`Invalid element type of data array: ${firstElementType}.`); + } + } + else { + // get tensor type from TypedArray + const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor); + if (mappedType === undefined) { + throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`); + } + type = mappedType; + data = arg0; + } + } + // type and data is processed, now processing dims + if (dims === undefined) { + // assume 1-D tensor if dims omitted + dims = [data.length]; + } + else if (!Array.isArray(dims)) { + throw new TypeError('A tensor\'s dims must be a number array'); + } + // perform check + const size = calculateSize(dims); + if (size !== data.length) { + throw new Error(`Tensor's size(${size}) does not match data length(${data.length}).`); + } + this.dims = dims; + this.type = type; + this.data = data; + this.size = size; + } + // #endregion + /** + * Create a new tensor object from image object + * + * @param buffer - Extracted image buffer data - assuming RGBA format + * @param imageFormat - input image configuration - required configurations height, width, format + * @param tensorFormat - output tensor configuration - Default is RGB format + */ + static bufferToTensor(buffer, options) { + if (buffer === undefined) { + throw new Error('Image buffer must be defined'); + } + if (options.height === undefined || options.width === undefined) { + throw new Error('Image height and width must be defined'); + } + const { height, width } = options; + const norm = options.norm; + let normMean; + let normBias; + if (norm === undefined || norm.mean === undefined) { + normMean = 255; + } + else { + normMean = norm.mean; + } + if (norm === undefined || norm.bias === undefined) { + normBias = 0; + } + else { + normBias = norm.bias; + } + const inputformat = options.bitmapFormat !== undefined ? options.bitmapFormat : 'RGBA'; + // default value is RGBA since imagedata and HTMLImageElement uses it + const outputformat = options.tensorFormat !== undefined ? + (options.tensorFormat !== undefined ? options.tensorFormat : 'RGB') : + 'RGB'; + const offset = height * width; + const float32Data = outputformat === 'RGBA' ? new Float32Array(offset * 4) : new Float32Array(offset * 3); + // Default pointer assignments + let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3; + let rTensorPointer = 0, gTensorPointer = offset, bTensorPointer = offset * 2, aTensorPointer = -1; + // Updating the pointer assignments based on the input image format + if (inputformat === 'RGB') { + step = 3; + rImagePointer = 0; + gImagePointer = 1; + bImagePointer = 2; + aImagePointer = -1; + } + // Updating the pointer assignments based on the output tensor format + if (outputformat === 'RGBA') { + aTensorPointer = offset * 3; + } + else if (outputformat === 'RBG') { + rTensorPointer = 0; + bTensorPointer = offset; + gTensorPointer = offset * 2; + } + else if (outputformat === 'BGR') { + bTensorPointer = 0; + gTensorPointer = offset; + rTensorPointer = offset * 2; + } + for (let i = 0; i < offset; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) { + float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias) / normMean; + float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias) / normMean; + float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias) / normMean; + if (aTensorPointer !== -1 && aImagePointer !== -1) { + float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias) / normMean; + } + } + // Float32Array -> ort.Tensor + const outputTensor = outputformat === 'RGBA' ? new Tensor('float32', float32Data, [1, 4, height, width]) : + new Tensor('float32', float32Data, [1, 3, height, width]); + return outputTensor; + } + static async fromImage(image, options) { + // checking the type of image object + const isHTMLImageEle = typeof (HTMLImageElement) !== 'undefined' && image instanceof HTMLImageElement; + const isImageDataEle = typeof (ImageData) !== 'undefined' && image instanceof ImageData; + const isImageBitmap = typeof (ImageBitmap) !== 'undefined' && image instanceof ImageBitmap; + const isURL = typeof (String) !== 'undefined' && (image instanceof String || typeof image === 'string'); + let data; + let tensorConfig = {}; + // filling and checking image configuration options + if (isHTMLImageEle) { + // HTMLImageElement - image object - format is RGBA by default + const canvas = document.createElement('canvas'); + const pixels2DContext = canvas.getContext('2d'); + if (pixels2DContext != null) { + let height = image.naturalHeight; + let width = image.naturalWidth; + if (options !== undefined && options.resizedHeight !== undefined && options.resizedWidth !== undefined) { + height = options.resizedHeight; + width = options.resizedWidth; + } + if (options !== undefined) { + tensorConfig = options; + if (options.tensorFormat !== undefined) { + throw new Error('Image input config format must be RGBA for HTMLImageElement'); + } + else { + tensorConfig.tensorFormat = 'RGBA'; + } + if (options.height !== undefined && options.height !== height) { + throw new Error('Image input config height doesn\'t match HTMLImageElement height'); + } + else { + tensorConfig.height = height; + } + if (options.width !== undefined && options.width !== width) { + throw new Error('Image input config width doesn\'t match HTMLImageElement width'); + } + else { + tensorConfig.width = width; + } + } + else { + tensorConfig.tensorFormat = 'RGBA'; + tensorConfig.height = height; + tensorConfig.width = width; + } + canvas.width = width; + canvas.height = height; + pixels2DContext.drawImage(image, 0, 0, width, height); + data = pixels2DContext.getImageData(0, 0, width, height).data; + } + else { + throw new Error('Can not access image data'); + } + } + else if (isImageDataEle) { + // ImageData - image object - format is RGBA by default + const format = 'RGBA'; + let height; + let width; + if (options !== undefined && options.resizedWidth !== undefined && options.resizedHeight !== undefined) { + height = options.resizedHeight; + width = options.resizedWidth; + } + else { + height = image.height; + width = image.width; + } + if (options !== undefined) { + tensorConfig = options; + if (options.bitmapFormat !== undefined && options.bitmapFormat !== format) { + throw new Error('Image input config format must be RGBA for ImageData'); + } + else { + tensorConfig.bitmapFormat = 'RGBA'; + } + } + else { + tensorConfig.bitmapFormat = 'RGBA'; + } + tensorConfig.height = height; + tensorConfig.width = width; + if (options !== undefined) { + const tempCanvas = document.createElement('canvas'); + tempCanvas.width = width; + tempCanvas.height = height; + const pixels2DContext = tempCanvas.getContext('2d'); + if (pixels2DContext != null) { + pixels2DContext.putImageData(image, 0, 0); + data = pixels2DContext.getImageData(0, 0, width, height).data; + } + else { + throw new Error('Can not access image data'); + } + } + else { + data = image.data; + } + } + else if (isImageBitmap) { + // ImageBitmap - image object - format must be provided by user + if (options === undefined) { + throw new Error('Please provide image config with format for Imagebitmap'); + } + if (options.bitmapFormat !== undefined) { + throw new Error('Image input config format must be defined for ImageBitmap'); + } + const pixels2DContext = document.createElement('canvas').getContext('2d'); + if (pixels2DContext != null) { + const height = image.height; + const width = image.width; + pixels2DContext.drawImage(image, 0, 0, width, height); + data = pixels2DContext.getImageData(0, 0, width, height).data; + if (options !== undefined) { + // using square brackets to avoid TS error - type 'never' + if (options.height !== undefined && options.height !== height) { + throw new Error('Image input config height doesn\'t match ImageBitmap height'); + } + else { + tensorConfig.height = height; + } + // using square brackets to avoid TS error - type 'never' + if (options.width !== undefined && options.width !== width) { + throw new Error('Image input config width doesn\'t match ImageBitmap width'); + } + else { + tensorConfig.width = width; + } + } + else { + tensorConfig.height = height; + tensorConfig.width = width; + } + return Tensor.bufferToTensor(data, tensorConfig); + } + else { + throw new Error('Can not access image data'); + } + } + else if (isURL) { + return new Promise((resolve, reject) => { + const canvas = document.createElement('canvas'); + const context = canvas.getContext('2d'); + if (!image || !context) { + return reject(); + } + const newImage = new Image(); + newImage.crossOrigin = 'Anonymous'; + newImage.src = image; + newImage.onload = () => { + canvas.width = newImage.width; + canvas.height = newImage.height; + context.drawImage(newImage, 0, 0, canvas.width, canvas.height); + const img = context.getImageData(0, 0, canvas.width, canvas.height); + if (options !== undefined) { + // using square brackets to avoid TS error - type 'never' + if (options.height !== undefined && options.height !== canvas.height) { + throw new Error('Image input config height doesn\'t match ImageBitmap height'); + } + else { + tensorConfig.height = canvas.height; + } + // using square brackets to avoid TS error - type 'never' + if (options.width !== undefined && options.width !== canvas.width) { + throw new Error('Image input config width doesn\'t match ImageBitmap width'); + } + else { + tensorConfig.width = canvas.width; + } + } + else { + tensorConfig.height = canvas.height; + tensorConfig.width = canvas.width; + } + resolve(Tensor.bufferToTensor(img.data, tensorConfig)); + }; + }); + } + else { + throw new Error('Input data provided is not supported - aborted tensor creation'); + } + if (data !== undefined) { + return Tensor.bufferToTensor(data, tensorConfig); + } + else { + throw new Error('Input data provided is not supported - aborted tensor creation'); + } + } + toImageData(options) { + var _a, _b; + const pixels2DContext = document.createElement('canvas').getContext('2d'); + let image; + if (pixels2DContext != null) { + // Default values for height and width & format + const width = this.dims[3]; + const height = this.dims[2]; + const channels = this.dims[1]; + const inputformat = options !== undefined ? (options.format !== undefined ? options.format : 'RGB') : 'RGB'; + const normMean = options !== undefined ? (((_a = options.norm) === null || _a === void 0 ? void 0 : _a.mean) !== undefined ? options.norm.mean : 255) : 255; + const normBias = options !== undefined ? (((_b = options.norm) === null || _b === void 0 ? void 0 : _b.bias) !== undefined ? options.norm.bias : 0) : 0; + const offset = height * width; + if (options !== undefined) { + if (options.height !== undefined && options.height !== height) { + throw new Error('Image output config height doesn\'t match tensor height'); + } + if (options.width !== undefined && options.width !== width) { + throw new Error('Image output config width doesn\'t match tensor width'); + } + if (options.format !== undefined && (channels === 4 && options.format !== 'RGBA') || + (channels === 3 && (options.format !== 'RGB' && options.format !== 'BGR'))) { + throw new Error('Tensor format doesn\'t match input tensor dims'); + } + } + // Default pointer assignments + const step = 4; + let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3; + let rTensorPointer = 0, gTensorPointer = offset, bTensorPointer = offset * 2, aTensorPointer = -1; + // Updating the pointer assignments based on the input image format + if (inputformat === 'RGBA') { + rTensorPointer = 0; + gTensorPointer = offset; + bTensorPointer = offset * 2; + aTensorPointer = offset * 3; + } + else if (inputformat === 'RGB') { + rTensorPointer = 0; + gTensorPointer = offset; + bTensorPointer = offset * 2; + } + else if (inputformat === 'RBG') { + rTensorPointer = 0; + bTensorPointer = offset; + gTensorPointer = offset * 2; + } + image = pixels2DContext.createImageData(width, height); + for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) { + image.data[rImagePointer] = (this.data[rTensorPointer++] - normBias) * normMean; // R value + image.data[gImagePointer] = (this.data[gTensorPointer++] - normBias) * normMean; // G value + image.data[bImagePointer] = (this.data[bTensorPointer++] - normBias) * normMean; // B value + image.data[aImagePointer] = + aTensorPointer === -1 ? 255 : (this.data[aTensorPointer++] - normBias) * normMean; // A value + } + } + else { + throw new Error('Can not access image data'); + } + return image; + } + // #endregion + // #region tensor utilities + reshape(dims) { + return new Tensor(this.type, this.data, dims); + } +} +//# sourceMappingURL=tensor-impl.js.map + +/***/ }), + +/***/ "../common/dist/lib/tensor.js": +/*!************************************!*\ + !*** ../common/dist/lib/tensor.js ***! + \************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "Tensor": () => (/* binding */ Tensor) +/* harmony export */ }); +/* harmony import */ var _tensor_impl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tensor-impl */ "../common/dist/lib/tensor-impl.js"); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// eslint-disable-next-line @typescript-eslint/naming-convention +const Tensor = _tensor_impl__WEBPACK_IMPORTED_MODULE_0__.Tensor; +//# sourceMappingURL=tensor.js.map + +/***/ }), + +/***/ "./lib/wasm/binding/ort-wasm-threaded.js": +/*!***********************************************!*\ + !*** ./lib/wasm/binding/ort-wasm-threaded.js ***! + \***********************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +var __filename = "/index.js"; +var __dirname = "/"; + +var ortWasmThreaded = (() => { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + if (true) _scriptDir = _scriptDir || __filename; + return ( +function(ortWasmThreaded) { + ortWasmThreaded = ortWasmThreaded || {}; + + +function d(){m.buffer!=n&&p(m.buffer);return aa}function q(){m.buffer!=n&&p(m.buffer);return ba}function r(){m.buffer!=n&&p(m.buffer);return ca}function v(){m.buffer!=n&&p(m.buffer);return da}function ea(){m.buffer!=n&&p(m.buffer);return fa}var x;x||(x=typeof ortWasmThreaded !== 'undefined' ? ortWasmThreaded : {});var ha,ia;x.ready=new Promise(function(a,b){ha=a;ia=b}); +var ja=Object.assign({},x),ka="./this.program",la=(a,b)=>{throw b;},ma="object"==typeof window,y="function"==typeof importScripts,B="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,C=x.ENVIRONMENT_IS_PTHREAD||!1,D="";function na(a){return x.locateFile?x.locateFile(a,D):D+a}var oa,pa,qa,fs,ra,sa; +if(B){D=y?(__webpack_require__(/*! path */ "?75c6").dirname)(D)+"/":__dirname+"/";sa=()=>{ra||(fs=__webpack_require__(/*! fs */ "?63c8"),ra=__webpack_require__(/*! path */ "?75c6"))};oa=function(b,c){sa();b=ra.normalize(b);return fs.readFileSync(b,c?void 0:"utf8")};qa=b=>{b=oa(b,!0);b.buffer||(b=new Uint8Array(b));return b};pa=(b,c,e)=>{sa();b=ra.normalize(b);fs.readFile(b,function(f,h){f?e(f):c(h.buffer)})};1{if(F())throw process.exitCode=b,c;c instanceof E||G("exiting due to exception: "+c);process.exit(b)};x.inspect=function(){return"[Emscripten Module object]"};let a;try{a=__webpack_require__(/*! worker_threads */ "?c6f7")}catch(b){throw console.error('The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?'),b;}__webpack_require__.g.Worker=a.Worker}else if(ma||y)y?D=self.location.href:"undefined"!=typeof document&&document.currentScript&&(D=document.currentScript.src), +_scriptDir&&(D=_scriptDir),0!==D.indexOf("blob:")?D=D.substr(0,D.replace(/[?#].*/,"").lastIndexOf("/")+1):D="",B||(oa=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},y&&(qa=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),pa=(a,b,c)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?b(e.response):c()};e.onerror= +c;e.send(null)});B&&"undefined"==typeof performance&&(__webpack_require__.g.performance=(__webpack_require__(/*! perf_hooks */ "?674f").performance));var ta=console.log.bind(console),ua=console.warn.bind(console);B&&(sa(),ta=a=>fs.writeSync(1,a+"\n"),ua=a=>fs.writeSync(2,a+"\n"));var va=x.print||ta,G=x.printErr||ua;Object.assign(x,ja);ja=null;x.thisProgram&&(ka=x.thisProgram);x.quit&&(la=x.quit);var H;x.wasmBinary&&(H=x.wasmBinary);var noExitRuntime=x.noExitRuntime||!1;"object"!=typeof WebAssembly&&I("no native wasm support detected"); +var m,wa,xa=!1,ya="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0; +function za(a,b,c){b>>>=0;var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e} +function Aa(a,b){return(a>>>=0)?za(q(),a,b):""} +function Ba(a,b,c,e){c>>>=0;if(!(0=k){var l=a.charCodeAt(++h);k=65536+((k&1023)<<10)|l&1023}if(127>=k){if(c>=e)break;b[c++>>>0]=k}else{if(2047>=k){if(c+1>=e)break;b[c++>>>0]=192|k>>6}else{if(65535>=k){if(c+2>=e)break;b[c++>>>0]=224|k>>12}else{if(c+3>=e)break;b[c++>>>0]=240|k>>18;b[c++>>>0]=128|k>>12&63}b[c++>>>0]=128|k>>6&63}b[c++>>>0]=128|k&63}}b[c>>>0]=0;return c-f} +function Ca(a){for(var b=0,c=0;c=e?b++:2047>=e?b+=2:55296<=e&&57343>=e?(b+=4,++c):b+=3}return b}var n,aa,ba,ca,da,fa;C&&(n=x.buffer);function p(a){n=a;x.HEAP8=aa=new Int8Array(a);x.HEAP16=new Int16Array(a);x.HEAP32=ca=new Int32Array(a);x.HEAPU8=ba=new Uint8Array(a);x.HEAPU16=new Uint16Array(a);x.HEAPU32=da=new Uint32Array(a);x.HEAPF32=new Float32Array(a);x.HEAPF64=fa=new Float64Array(a)}var Da=x.INITIAL_MEMORY||16777216; +if(C)m=x.wasmMemory,n=x.buffer;else if(x.wasmMemory)m=x.wasmMemory;else if(m=new WebAssembly.Memory({initial:Da/65536,maximum:65536,shared:!0}),!(m.buffer instanceof SharedArrayBuffer))throw G("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),B&&console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)"), +Error("bad memory");m&&(n=m.buffer);Da=n.byteLength;p(n);var Ea,Fa=[],Ga=[],Ha=[],Ia=[],Ja=0;function F(){return noExitRuntime||0{c.time=performance.now();b.postMessage(c,a.Nc)};b.loaded&&(b.$b(),delete b.$b);return 0}function Sa(a){if(C)return Q(1,1,a);if(!F()){P.oc();if(x.onExit)x.onExit(a);xa=!0}la(a,new E(a))} +function Ta(a,b){if(!b&&C)throw Ua(a),"unwind";F()||C||(Va(),R(Ha),Wa(0),Xa[1].length&&Ya(1,10),Xa[2].length&&Ya(2,10),P.oc());Sa(a)} +var P={Yb:[],ac:[],qc:[],Vb:{},fc:function(){C&&P.Ec()},Pc:function(){},Ec:function(){P.receiveObjectTransfer=P.Gc;P.threadInitTLS=P.pc;P.setExitStatus=P.nc;noExitRuntime=!1},nc:function(){},oc:function(){for(var a of Object.values(P.Vb))P.mc(a);for(a of P.Yb)a.terminate();P.Yb=[]},mc:function(a){var b=a.Ub;delete P.Vb[b];P.Yb.push(a);P.ac.splice(P.ac.indexOf(a),1);a.Ub=0;Za(b)},Gc:function(){},pc:function(){P.qc.forEach(a=>a())},Fc:function(a,b){a.onmessage=c=>{c=c.data;var e=c.cmd;a.Ub&&(P.Bc=a.Ub); +if(c.targetThread&&c.targetThread!=$a()){var f=P.Vb[c.Qc];f?f.postMessage(c,c.transferList):G('Internal error! Worker sent a message "'+e+'" to target pthread '+c.targetThread+", but that thread no longer exists!")}else if("processProxyingQueue"===e)ab(c.queue);else if("spawnThread"===e)Ra(c);else if("cleanupThread"===e)Qa(c.thread);else if("killThread"===e)c=c.thread,e=P.Vb[c],delete P.Vb[c],e.terminate(),Za(c),P.ac.splice(P.ac.indexOf(e),1),e.Ub=0;else if("cancelThread"===e)P.Vb[c.thread].postMessage({cmd:"cancel"}); +else if("loaded"===e)a.loaded=!0,b&&b(a),a.$b&&(a.$b(),delete a.$b);else if("print"===e)va("Thread "+c.threadId+": "+c.text);else if("printErr"===e)G("Thread "+c.threadId+": "+c.text);else if("alert"===e)alert("Thread "+c.threadId+": "+c.text);else if("setimmediate"===c.target)a.postMessage(c);else if("onAbort"===e){if(x.onAbort)x.onAbort(c.arg)}else e&&G("worker sent an unknown command "+e);P.Bc=void 0};a.onerror=c=>{G("worker sent an error! "+c.filename+":"+c.lineno+": "+c.message);throw c;};B&& +(a.on("message",function(c){a.onmessage({data:c})}),a.on("error",function(c){a.onerror(c)}),a.on("detachedExit",function(){}));a.postMessage({cmd:"load",urlOrBlob:x.mainScriptUrlOrBlob||_scriptDir,wasmMemory:m,wasmModule:wa})},yc:function(){var a=na("ort-wasm-threaded.worker.js");P.Yb.push(new Worker(a))},Cc:function(){0==P.Yb.length&&(P.yc(),P.Fc(P.Yb[0]));return P.Yb.pop()}};x.PThread=P;function R(a){for(;0>2>>>0];a=r()[a+48>>2>>>0];cb(b,b-a);U(b)};function Ua(a){if(C)return Q(2,0,a);try{Ta(a)}catch(b){b instanceof E||"unwind"==b||la(1,b)}}var db=[];function V(a){var b=db[a];b||(a>=db.length&&(db.length=a+1),db[a]=b=Ea.get(a));return b}x.invokeEntryPoint=function(a,b){a=V(a)(b);F()?P.nc(a):eb(a)};function fb(a,b){d().set(a,b>>>0)}var gb=[],hb=0,W=0; +function X(a){this.Zb=a;this.Sb=a-24;this.xc=function(b){v()[this.Sb+4>>2>>>0]=b};this.bc=function(){return v()[this.Sb+4>>2>>>0]};this.wc=function(b){v()[this.Sb+8>>2>>>0]=b};this.Dc=function(){return v()[this.Sb+8>>2>>>0]};this.rc=function(){r()[this.Sb>>2>>>0]=0};this.hc=function(b){b=b?1:0;d()[this.Sb+12>>0>>>0]=b};this.uc=function(){return 0!=d()[this.Sb+12>>0>>>0]};this.ic=function(b){b=b?1:0;d()[this.Sb+13>>0>>>0]=b};this.kc=function(){return 0!=d()[this.Sb+13>>0>>>0]};this.fc=function(b,c){this.cc(0); +this.xc(b);this.wc(c);this.rc();this.hc(!1);this.ic(!1)};this.sc=function(){Atomics.add(r(),this.Sb>>2,1)};this.Hc=function(){return 1===Atomics.sub(r(),this.Sb>>2,1)};this.cc=function(b){v()[this.Sb+16>>2>>>0]=b};this.tc=function(){return v()[this.Sb+16>>2>>>0]};this.vc=function(){if(ib(this.bc()))return v()[this.Zb>>2>>>0];var b=this.tc();return 0!==b?b:this.Zb}}function jb(a){return kb((new X(a)).Sb)}function lb(a,b,c,e){return C?Q(3,1,a,b,c,e):mb(a,b,c,e)} +function mb(a,b,c,e){if("undefined"==typeof SharedArrayBuffer)return G("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var f=[];if(C&&0===f.length)return lb(a,b,c,e);a={Ic:c,Ub:a,zc:e,Nc:f};return C?(a.Oc="spawnThread",postMessage(a,f),0):Ra(a)}function nb(a,b,c){return C?Q(4,1,a,b,c):0}function ob(a,b){if(C)return Q(5,1,a,b)}function pb(a,b){if(C)return Q(6,1,a,b)}function qb(a,b,c){if(C)return Q(7,1,a,b,c)}function rb(a,b,c){return C?Q(8,1,a,b,c):0} +function sb(a,b){if(C)return Q(9,1,a,b)}function tb(a,b,c){if(C)return Q(10,1,a,b,c)}function ub(a,b,c,e){if(C)return Q(11,1,a,b,c,e)}function vb(a,b,c,e){if(C)return Q(12,1,a,b,c,e)}function wb(a,b,c,e){if(C)return Q(13,1,a,b,c,e)}function xb(a){if(C)return Q(14,1,a)}function yb(a,b){if(C)return Q(15,1,a,b)}function zb(a,b,c){if(C)return Q(16,1,a,b,c)}function ab(a){Atomics.store(r(),a>>2,1);$a()&&Ab(a);Atomics.compareExchange(r(),a>>2,1,0)}x.executeNotifiedProxyingQueue=ab; +function Bb(a){return v()[a>>>2]+4294967296*r()[a+4>>>2]}function Cb(a,b,c,e,f,h){return C?Q(17,1,a,b,c,e,f,h):-52}function Db(a,b,c,e,f,h){if(C)return Q(18,1,a,b,c,e,f,h)}function Eb(a){var b=Ca(a)+1,c=Fb(b);c&&Ba(a,d(),c,b);return c} +function Gb(a,b,c){function e(t){return(t=t.toTimeString().match(/\(([A-Za-z ]+)\)$/))?t[1]:"GMT"}if(C)return Q(19,1,a,b,c);var f=(new Date).getFullYear(),h=new Date(f,0,1),k=new Date(f,6,1);f=h.getTimezoneOffset();var l=k.getTimezoneOffset(),u=Math.max(f,l);r()[a>>2>>>0]=60*u;r()[b>>2>>>0]=Number(f!=l);a=e(h);b=e(k);a=Eb(a);b=Eb(b);l>2>>>0]=a,v()[c+4>>2>>>0]=b):(v()[c>>2>>>0]=b,v()[c+4>>2>>>0]=a)}function Hb(a,b,c){Hb.Ac||(Hb.Ac=!0,Gb(a,b,c))}var Ib,Jb; +Jb=B?()=>{var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:C?()=>performance.now()-x.__performance_now_clock_drift:()=>performance.now();function Q(a,b){var c=arguments.length-2,e=arguments;return bb(()=>{for(var f=Kb(8*c),h=f>>3,k=0;k>>0]=l}return Lb(a,c,f,b)})}var Mb=[],Nb={}; +function Ob(){if(!Pb){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:ka||"./this.program"},b;for(b in Nb)void 0===Nb[b]?delete a[b]:a[b]=Nb[b];var c=[];for(b in a)c.push(b+"="+a[b]);Pb=c}return Pb}var Pb; +function Qb(a,b){if(C)return Q(20,1,a,b);var c=0;Ob().forEach(function(e,f){var h=b+c;f=v()[a+4*f>>2>>>0]=h;for(h=0;h>0>>>0]=e.charCodeAt(h);d()[f>>0>>>0]=0;c+=e.length+1});return 0}function Rb(a,b){if(C)return Q(21,1,a,b);var c=Ob();v()[a>>2>>>0]=c.length;var e=0;c.forEach(function(f){e+=f.length+1});v()[b>>2>>>0]=e;return 0}function Sb(a){return C?Q(22,1,a):52}function Tb(a,b,c,e){return C?Q(23,1,a,b,c,e):52}function Ub(a,b,c,e,f){return C?Q(24,1,a,b,c,e,f):70} +var Xa=[null,[],[]];function Ya(a,b){var c=Xa[a];0===b||10===b?((1===a?va:G)(za(c,0)),c.length=0):c.push(b)}function Vb(a,b,c,e){if(C)return Q(25,1,a,b,c,e);for(var f=0,h=0;h>2>>>0],l=v()[b+4>>2>>>0];b+=8;for(var u=0;u>>0]);f+=l}v()[e>>2>>>0]=f;return 0}var Y=0; +function Wb(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(B)try{var b=__webpack_require__(Object(function webpackMissingModule() { var e = new Error("Cannot find module 'crypto'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));return()=>b.randomBytes(1)[0]}catch(c){}return()=>I("randomDevice")}function Xb(a,b){Xb.lc||(Xb.lc=Wb());for(var c=0;c>0>>>0]=Xb.lc();return 0}function Yb(a){return 0===a%4&&(0!==a%100||0===a%400)}var Zb=[31,29,31,30,31,30,31,31,30,31,30,31],$b=[31,28,31,30,31,30,31,31,30,31,30,31]; +function ac(a){var b=Array(Ca(a)+1);Ba(a,b,0,b.length);return b} +function bc(a,b,c,e){function f(g,w,z){for(g="number"==typeof g?g.toString():g||"";g.lengthT?-1:0N-g.getDate())w-=N-g.getDate()+1,g.setDate(1),11>z?g.setMonth(z+1):(g.setMonth(0),g.setFullYear(g.getFullYear()+1));else{g.setDate(g.getDate()+w);break}}z=new Date(g.getFullYear()+1,0,4);w=l(new Date(g.getFullYear(), +0,4));z=l(z);return 0>=k(w,g)?0>=k(z,g)?g.getFullYear()+1:g.getFullYear():g.getFullYear()-1}var t=r()[e+40>>2>>>0];e={Lc:r()[e>>2>>>0],Kc:r()[e+4>>2>>>0],dc:r()[e+8>>2>>>0],jc:r()[e+12>>2>>>0],ec:r()[e+16>>2>>>0],Xb:r()[e+20>>2>>>0],Tb:r()[e+24>>2>>>0],Wb:r()[e+28>>2>>>0],Rc:r()[e+32>>2>>>0],Jc:r()[e+36>>2>>>0],Mc:t?Aa(t):""};c=Aa(c);t={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C", +"%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var A in t)c=c.replace(new RegExp(A,"g"),t[A]);var K="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),J="January February March April May June July August September October November December".split(" ");t={"%a":function(g){return K[g.Tb].substring(0,3)},"%A":function(g){return K[g.Tb]}, +"%b":function(g){return J[g.ec].substring(0,3)},"%B":function(g){return J[g.ec]},"%C":function(g){return h((g.Xb+1900)/100|0,2)},"%d":function(g){return h(g.jc,2)},"%e":function(g){return f(g.jc,2," ")},"%g":function(g){return u(g).toString().substring(2)},"%G":function(g){return u(g)},"%H":function(g){return h(g.dc,2)},"%I":function(g){g=g.dc;0==g?g=12:12g.dc?"AM":"PM"},"%S":function(g){return h(g.Lc,2)},"%t":function(){return"\t"},"%u":function(g){return g.Tb||7},"%U":function(g){return h(Math.floor((g.Wb+7-g.Tb)/7),2)},"%V":function(g){var w=Math.floor((g.Wb+7-(g.Tb+6)%7)/7);2>=(g.Tb+371-g.Wb-2)%7&&w++;if(w)53==w&&(z=(g.Tb+371-g.Wb)%7,4==z||3==z&&Yb(g.Xb)||(w=1));else{w=52;var z=(g.Tb+7-g.Wb-1)%7;(4==z||5==z&&Yb(g.Xb%400-1))&&w++}return h(w, +2)},"%w":function(g){return g.Tb},"%W":function(g){return h(Math.floor((g.Wb+7-(g.Tb+6)%7)/7),2)},"%y":function(g){return(g.Xb+1900).toString().substring(2)},"%Y":function(g){return g.Xb+1900},"%z":function(g){g=g.Jc;var w=0<=g;g=Math.abs(g)/60;return(w?"+":"-")+String("0000"+(g/60*100+g%60)).slice(-4)},"%Z":function(g){return g.Mc},"%%":function(){return"%"}};c=c.replace(/%%/g,"\x00\x00");for(A in t)c.includes(A)&&(c=c.replace(new RegExp(A,"g"),t[A](e)));c=c.replace(/\0\0/g,"%");A=ac(c);if(A.length> +b)return 0;fb(A,a);return A.length-1}P.fc(); +var cc=[null,Sa,Ua,lb,nb,ob,pb,qb,rb,sb,tb,ub,vb,wb,xb,yb,zb,Cb,Db,Gb,Qb,Rb,Sb,Tb,Ub,Vb],Pc={b:function(a){return Fb(a+24)+24},n:function(a){a=new X(a);a.uc()||(a.hc(!0),hb--);a.ic(!1);gb.push(a);a.sc();return a.vc()},ma:function(a){G("Unexpected exception thrown, this is not properly supported - aborting");xa=!0;throw a;},x:function(){Z(0);var a=gb.pop();if(a.Hc()&&!a.kc()){var b=a.Dc();b&&V(b)(a.Zb);jb(a.Zb)}W=0},e:function(){var a=W;if(!a)return Y=0;var b=new X(a);b.cc(a);var c=b.bc();if(!c)return Y= +0,a;for(var e=Array.prototype.slice.call(arguments),f=0;fab(e));else if(C)postMessage({targetThread:a,cmd:"processProxyingQueue", +queue:e});else{a=P.Vb[a];if(!a)return;a.postMessage({cmd:"processProxyingQueue",queue:e})}return 1},Ea:function(){return-1},Pa:function(a,b){a=new Date(1E3*Bb(a));r()[b>>2>>>0]=a.getUTCSeconds();r()[b+4>>2>>>0]=a.getUTCMinutes();r()[b+8>>2>>>0]=a.getUTCHours();r()[b+12>>2>>>0]=a.getUTCDate();r()[b+16>>2>>>0]=a.getUTCMonth();r()[b+20>>2>>>0]=a.getUTCFullYear()-1900;r()[b+24>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;r()[b+28>>2>>>0]=a},Qa:function(a,b){a= +new Date(1E3*Bb(a));r()[b>>2>>>0]=a.getSeconds();r()[b+4>>2>>>0]=a.getMinutes();r()[b+8>>2>>>0]=a.getHours();r()[b+12>>2>>>0]=a.getDate();r()[b+16>>2>>>0]=a.getMonth();r()[b+20>>2>>>0]=a.getFullYear()-1900;r()[b+24>>2>>>0]=a.getDay();var c=new Date(a.getFullYear(),0,1),e=(a.getTime()-c.getTime())/864E5|0;r()[b+28>>2>>>0]=e;r()[b+36>>2>>>0]=-(60*a.getTimezoneOffset());e=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();a=(e!=c&&a.getTimezoneOffset()==Math.min(c,e))|0;r()[b+ +32>>2>>>0]=a},Ra:function(a){var b=new Date(r()[a+20>>2>>>0]+1900,r()[a+16>>2>>>0],r()[a+12>>2>>>0],r()[a+8>>2>>>0],r()[a+4>>2>>>0],r()[a>>2>>>0],0),c=r()[a+32>>2>>>0],e=b.getTimezoneOffset(),f=new Date(b.getFullYear(),0,1),h=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),k=f.getTimezoneOffset(),l=Math.min(k,h);0>c?r()[a+32>>2>>>0]=Number(h!=k&&l==e):0>2>>>0]=b.getDay();c=(b.getTime()-f.getTime())/864E5|0;r()[a+28>> +2>>>0]=c;r()[a>>2>>>0]=b.getSeconds();r()[a+4>>2>>>0]=b.getMinutes();r()[a+8>>2>>>0]=b.getHours();r()[a+12>>2>>>0]=b.getDate();r()[a+16>>2>>>0]=b.getMonth();return b.getTime()/1E3|0},Aa:Cb,Ba:Db,Sa:Hb,y:function(){I("")},U:function(){if(!B&&!y){var a="Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread";Ib||(Ib={});Ib[a]||(Ib[a]=1,B&&(a="warning: "+a),G(a))}},ra:function(){return 4294901760},B:Jb,Ia:function(a,b, +c){q().copyWithin(a>>>0,b>>>0,b+c>>>0)},F:function(){return B?(__webpack_require__(/*! os */ "?aedb").cpus)().length:navigator.hardwareConcurrency},Da:function(a,b,c){Mb.length=b;c>>=3;for(var e=0;e>>0];return(0>a?Pa[-a-1]:cc[a]).apply(null,Mb)},qa:function(a){var b=q().length;a>>>=0;if(a<=b||4294901760=c;c*=2){var e=b*(1+.2/c);e=Math.min(e,a+100663296);var f=Math;e=Math.max(a,e);f=f.min.call(f,4294901760,e+(65536-e%65536)%65536);a:{try{m.grow(f-n.byteLength+65535>>>16);p(m.buffer); +var h=1;break a}catch(k){}h=void 0}if(h)return!0}return!1},Na:function(){throw"unwind";},Ga:Qb,Ha:Rb,J:Ta,I:Sb,S:Tb,ga:Ub,R:Vb,d:function(){return Y},na:Xb,ia:fc,ja:gc,K:hc,f:ic,P:jc,Q:kc,k:lc,p:mc,q:nc,N:oc,s:pc,w:qc,L:rc,E:sc,aa:tc,_:uc,Z:vc,ca:wc,$:xc,ba:yc,Y:zc,g:Ac,r:Bc,i:Cc,ha:Dc,m:Ec,v:Fc,u:Gc,O:Hc,A:Ic,ka:Jc,C:Kc,D:Lc,fa:Mc,da:Nc,ea:Oc,o:function(a){return a},a:m||x.wasmMemory,G:function(a){Y=a},la:bc,z:function(a,b,c,e){return bc(a,b,c,e)}}; +(function(){function a(f,h){x.asm=f.exports;P.qc.push(x.asm.sb);Ea=x.asm.ub;Ga.unshift(x.asm.Va);wa=h;C||(L--,x.monitorRunDependencies&&x.monitorRunDependencies(L),0==L&&(null!==La&&(clearInterval(La),La=null),M&&(f=M,M=null,f())))}function b(f){a(f.instance,f.module)}function c(f){return Oa().then(function(h){return WebAssembly.instantiate(h,e)}).then(function(h){return h}).then(f,function(h){G("failed to asynchronously prepare wasm: "+h);I(h)})}var e={a:Pc};C||(L++,x.monitorRunDependencies&&x.monitorRunDependencies(L)); +if(x.instantiateWasm)try{return x.instantiateWasm(e,a)}catch(f){return G("Module.instantiateWasm callback failed with error: "+f),!1}(function(){return H||"function"!=typeof WebAssembly.instantiateStreaming||Ma()||O.startsWith("file://")||B||"function"!=typeof fetch?c(b):fetch(O,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,e).then(b,function(h){G("wasm streaming compile failed: "+h);G("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ia); +return{}})();x.___wasm_call_ctors=function(){return(x.___wasm_call_ctors=x.asm.Va).apply(null,arguments)};x._OrtInit=function(){return(x._OrtInit=x.asm.Wa).apply(null,arguments)};x._OrtCreateSessionOptions=function(){return(x._OrtCreateSessionOptions=x.asm.Xa).apply(null,arguments)};x._OrtAppendExecutionProvider=function(){return(x._OrtAppendExecutionProvider=x.asm.Ya).apply(null,arguments)};x._OrtAddSessionConfigEntry=function(){return(x._OrtAddSessionConfigEntry=x.asm.Za).apply(null,arguments)}; +x._OrtReleaseSessionOptions=function(){return(x._OrtReleaseSessionOptions=x.asm._a).apply(null,arguments)};x._OrtCreateSession=function(){return(x._OrtCreateSession=x.asm.$a).apply(null,arguments)};x._OrtReleaseSession=function(){return(x._OrtReleaseSession=x.asm.ab).apply(null,arguments)};x._OrtGetInputCount=function(){return(x._OrtGetInputCount=x.asm.bb).apply(null,arguments)};x._OrtGetOutputCount=function(){return(x._OrtGetOutputCount=x.asm.cb).apply(null,arguments)}; +x._OrtGetInputName=function(){return(x._OrtGetInputName=x.asm.db).apply(null,arguments)};x._OrtGetOutputName=function(){return(x._OrtGetOutputName=x.asm.eb).apply(null,arguments)};x._OrtFree=function(){return(x._OrtFree=x.asm.fb).apply(null,arguments)};x._OrtCreateTensor=function(){return(x._OrtCreateTensor=x.asm.gb).apply(null,arguments)};x._OrtGetTensorData=function(){return(x._OrtGetTensorData=x.asm.hb).apply(null,arguments)}; +x._OrtReleaseTensor=function(){return(x._OrtReleaseTensor=x.asm.ib).apply(null,arguments)};x._OrtCreateRunOptions=function(){return(x._OrtCreateRunOptions=x.asm.jb).apply(null,arguments)};x._OrtAddRunConfigEntry=function(){return(x._OrtAddRunConfigEntry=x.asm.kb).apply(null,arguments)};x._OrtReleaseRunOptions=function(){return(x._OrtReleaseRunOptions=x.asm.lb).apply(null,arguments)};x._OrtRun=function(){return(x._OrtRun=x.asm.mb).apply(null,arguments)}; +x._OrtEndProfiling=function(){return(x._OrtEndProfiling=x.asm.nb).apply(null,arguments)};var $a=x._pthread_self=function(){return($a=x._pthread_self=x.asm.ob).apply(null,arguments)},Fb=x._malloc=function(){return(Fb=x._malloc=x.asm.pb).apply(null,arguments)},kb=x._free=function(){return(kb=x._free=x.asm.qb).apply(null,arguments)},Wa=x._fflush=function(){return(Wa=x._fflush=x.asm.rb).apply(null,arguments)};x.__emscripten_tls_init=function(){return(x.__emscripten_tls_init=x.asm.sb).apply(null,arguments)}; +var Va=x.___funcs_on_exit=function(){return(Va=x.___funcs_on_exit=x.asm.tb).apply(null,arguments)},ec=x.__emscripten_thread_init=function(){return(ec=x.__emscripten_thread_init=x.asm.vb).apply(null,arguments)};x.__emscripten_thread_crashed=function(){return(x.__emscripten_thread_crashed=x.asm.wb).apply(null,arguments)}; +var Lb=x._emscripten_run_in_main_runtime_thread_js=function(){return(Lb=x._emscripten_run_in_main_runtime_thread_js=x.asm.xb).apply(null,arguments)},Ab=x.__emscripten_proxy_execute_task_queue=function(){return(Ab=x.__emscripten_proxy_execute_task_queue=x.asm.yb).apply(null,arguments)},Za=x.__emscripten_thread_free_data=function(){return(Za=x.__emscripten_thread_free_data=x.asm.zb).apply(null,arguments)},eb=x.__emscripten_thread_exit=function(){return(eb=x.__emscripten_thread_exit=x.asm.Ab).apply(null, +arguments)},Z=x._setThrew=function(){return(Z=x._setThrew=x.asm.Bb).apply(null,arguments)},cb=x._emscripten_stack_set_limits=function(){return(cb=x._emscripten_stack_set_limits=x.asm.Cb).apply(null,arguments)},S=x.stackSave=function(){return(S=x.stackSave=x.asm.Db).apply(null,arguments)},U=x.stackRestore=function(){return(U=x.stackRestore=x.asm.Eb).apply(null,arguments)},Kb=x.stackAlloc=function(){return(Kb=x.stackAlloc=x.asm.Fb).apply(null,arguments)},dc=x.___cxa_can_catch=function(){return(dc=x.___cxa_can_catch= +x.asm.Gb).apply(null,arguments)},ib=x.___cxa_is_pointer_type=function(){return(ib=x.___cxa_is_pointer_type=x.asm.Hb).apply(null,arguments)},Qc=x.dynCall_j=function(){return(Qc=x.dynCall_j=x.asm.Ib).apply(null,arguments)},Rc=x.dynCall_iiiiij=function(){return(Rc=x.dynCall_iiiiij=x.asm.Jb).apply(null,arguments)},Sc=x.dynCall_jii=function(){return(Sc=x.dynCall_jii=x.asm.Kb).apply(null,arguments)},Tc=x.dynCall_viiiiij=function(){return(Tc=x.dynCall_viiiiij=x.asm.Lb).apply(null,arguments)},Uc=x.dynCall_vjji= +function(){return(Uc=x.dynCall_vjji=x.asm.Mb).apply(null,arguments)},Vc=x.dynCall_viiijjjii=function(){return(Vc=x.dynCall_viiijjjii=x.asm.Nb).apply(null,arguments)},Wc=x.dynCall_iij=function(){return(Wc=x.dynCall_iij=x.asm.Ob).apply(null,arguments)},Xc=x.dynCall_ji=function(){return(Xc=x.dynCall_ji=x.asm.Pb).apply(null,arguments)},Yc=x.dynCall_iiiiiij=function(){return(Yc=x.dynCall_iiiiiij=x.asm.Qb).apply(null,arguments)},Zc=x.dynCall_iiij=function(){return(Zc=x.dynCall_iiij=x.asm.Rb).apply(null, +arguments)};function ic(a,b){var c=S();try{return V(a)(b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function Bc(a,b){var c=S();try{V(a)(b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function Cc(a,b,c){var e=S();try{V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function lc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function mc(a,b,c,e){var f=S();try{return V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}} +function qc(a,b,c,e,f,h,k){var l=S();try{return V(a)(b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function Ac(a){var b=S();try{V(a)()}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}}function pc(a,b,c,e,f,h){var k=S();try{return V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function nc(a,b,c,e,f){var h=S();try{return V(a)(b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function Ec(a,b,c,e){var f=S();try{V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}} +function Gc(a,b,c,e,f,h){var k=S();try{V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function Fc(a,b,c,e,f){var h=S();try{V(a)(b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function Ic(a,b,c,e,f,h,k,l){var u=S();try{V(a)(b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function kc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function jc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}} +function Jc(a,b,c,e,f,h,k,l,u){var t=S();try{V(a)(b,c,e,f,h,k,l,u)}catch(A){U(t);if(A!==A+0)throw A;Z(1,0)}}function Hc(a,b,c,e,f,h,k){var l=S();try{V(a)(b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function oc(a,b,c,e,f,h){var k=S();try{return V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function rc(a,b,c,e,f,h,k,l){var u=S();try{return V(a)(b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}} +function sc(a,b,c,e,f,h,k,l,u,t,A,K){var J=S();try{return V(a)(b,c,e,f,h,k,l,u,t,A,K)}catch(g){U(J);if(g!==g+0)throw g;Z(1,0)}}function Kc(a,b,c,e,f,h,k,l,u,t,A){var K=S();try{V(a)(b,c,e,f,h,k,l,u,t,A)}catch(J){U(K);if(J!==J+0)throw J;Z(1,0)}}function Lc(a,b,c,e,f,h,k,l,u,t,A,K,J,g,w,z){var N=S();try{V(a)(b,c,e,f,h,k,l,u,t,A,K,J,g,w,z)}catch(T){U(N);if(T!==T+0)throw T;Z(1,0)}}function hc(a){var b=S();try{return V(a)()}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}} +function gc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function fc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function Dc(a,b,c,e){var f=S();try{V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}function Mc(a,b,c,e,f,h,k,l){var u=S();try{Tc(a,b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function Oc(a,b,c,e,f,h){var k=S();try{Uc(a,b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}} +function Nc(a,b,c,e,f,h,k,l,u,t,A,K){var J=S();try{Vc(a,b,c,e,f,h,k,l,u,t,A,K)}catch(g){U(J);if(g!==g+0)throw g;Z(1,0)}}function wc(a,b,c,e){var f=S();try{return Wc(a,b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}function yc(a,b){var c=S();try{return Xc(a,b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function tc(a,b,c,e,f,h,k,l){var u=S();try{return Yc(a,b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function xc(a){var b=S();try{return Qc(a)}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}} +function uc(a,b,c,e,f,h,k){var l=S();try{return Rc(a,b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function vc(a,b,c,e,f){var h=S();try{return Zc(a,b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function zc(a,b,c){var e=S();try{return Sc(a,b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}x.UTF8ToString=Aa;x.stringToUTF8=function(a,b,c){return Ba(a,q(),b,c)};x.lengthBytesUTF8=Ca;x.keepRuntimeAlive=F;x.wasmMemory=m;x.stackSave=S;x.stackRestore=U;x.stackAlloc=Kb;x.ExitStatus=E;x.PThread=P;var $c; +M=function ad(){$c||bd();$c||(M=ad)}; +function bd(){function a(){if(!$c&&($c=!0,x.calledRun=!0,!xa)){C||R(Ga);ha(x);if(x.onRuntimeInitialized)x.onRuntimeInitialized();if(!C){if(x.postRun)for("function"==typeof x.postRun&&(x.postRun=[x.postRun]);x.postRun.length;){var b=x.postRun.shift();Ia.unshift(b)}R(Ia)}}}if(!(0 { + +var __filename = "/index.js"; +var __dirname = "/"; + +var ortWasm = (() => { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + if (true) _scriptDir = _scriptDir || __filename; + return ( +function(ortWasm) { + ortWasm = ortWasm || {}; + + +var d;d||(d=typeof ortWasm !== 'undefined' ? ortWasm : {});var aa,ba;d.ready=new Promise(function(a,b){aa=a;ba=b});var ca=Object.assign({},d),da="./this.program",ea=(a,b)=>{throw b;},fa="object"==typeof window,m="function"==typeof importScripts,p="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,q="",ha,r,v,fs,y,ia; +if(p)q=m?(__webpack_require__(/*! path */ "?75c6").dirname)(q)+"/":__dirname+"/",ia=()=>{y||(fs=__webpack_require__(/*! fs */ "?63c8"),y=__webpack_require__(/*! path */ "?75c6"))},ha=function(a,b){ia();a=y.normalize(a);return fs.readFileSync(a,b?void 0:"utf8")},v=a=>{a=ha(a,!0);a.buffer||(a=new Uint8Array(a));return a},r=(a,b,c)=>{ia();a=y.normalize(a);fs.readFile(a,function(e,f){e?c(e):b(f.buffer)})},1{if(noExitRuntime||0{var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null); +return b.responseText},m&&(v=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),r=(a,b,c)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?b(e.response):c()};e.onerror=c;e.send(null)};var la=d.print||console.log.bind(console),z=d.printErr||console.warn.bind(console);Object.assign(d,ca);ca=null;d.thisProgram&&(da=d.thisProgram);d.quit&&(ea=d.quit); +var A;d.wasmBinary&&(A=d.wasmBinary);var noExitRuntime=d.noExitRuntime||!1;"object"!=typeof WebAssembly&&B("no native wasm support detected");var ma,D=!1,na="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0; +function oa(a,b,c){b>>>=0;var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e}function pa(a,b){return(a>>>=0)?oa(G,a,b):""} +function qa(a,b,c,e){c>>>=0;if(!(0=k){var l=a.charCodeAt(++h);k=65536+((k&1023)<<10)|l&1023}if(127>=k){if(c>=e)break;b[c++>>>0]=k}else{if(2047>=k){if(c+1>=e)break;b[c++>>>0]=192|k>>6}else{if(65535>=k){if(c+2>=e)break;b[c++>>>0]=224|k>>12}else{if(c+3>=e)break;b[c++>>>0]=240|k>>18;b[c++>>>0]=128|k>>12&63}b[c++>>>0]=128|k>>6&63}b[c++>>>0]=128|k&63}}b[c>>>0]=0;return c-f} +function ra(a){for(var b=0,c=0;c=e?b++:2047>=e?b+=2:55296<=e&&57343>=e?(b+=4,++c):b+=3}return b}var sa,H,G,I,J;function ta(){var a=ma.buffer;sa=a;d.HEAP8=H=new Int8Array(a);d.HEAP16=new Int16Array(a);d.HEAP32=I=new Int32Array(a);d.HEAPU8=G=new Uint8Array(a);d.HEAPU16=new Uint16Array(a);d.HEAPU32=J=new Uint32Array(a);d.HEAPF32=new Float32Array(a);d.HEAPF64=new Float64Array(a)}var ua,va=[],wa=[],xa=[],ya=[],ka=0; +function za(){var a=d.preRun.shift();va.unshift(a)}var K=0,Aa=null,L=null;function B(a){if(d.onAbort)d.onAbort(a);a="Aborted("+a+")";z(a);D=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}function Ba(){return N.startsWith("data:application/octet-stream;base64,")}var N;N="ort-wasm.wasm";if(!Ba()){var Ca=N;N=d.locateFile?d.locateFile(Ca,q):q+Ca} +function Da(){var a=N;try{if(a==N&&A)return new Uint8Array(A);if(v)return v(a);throw"both async and sync fetching of the wasm failed";}catch(b){B(b)}} +function Ea(){if(!A&&(fa||m)){if("function"==typeof fetch&&!N.startsWith("file://"))return fetch(N,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+N+"'";return a.arrayBuffer()}).catch(function(){return Da()});if(r)return new Promise(function(a,b){r(N,function(c){a(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return Da()})}function ja(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a} +function O(a){for(;0>2>>>0]=b};this.Eb=function(){return J[this.zb+4>>2>>>0]};this.Sb=function(b){J[this.zb+8>>2>>>0]=b};this.Wb=function(){return J[this.zb+8>>2>>>0]};this.Tb=function(){I[this.zb>>2>>>0]=0};this.Ib=function(b){H[this.zb+12>>0>>>0]=b?1:0};this.Pb=function(){return 0!=H[this.zb+12>>0>>>0]};this.Jb=function(b){H[this.zb+13>>0>>>0]=b?1:0};this.Lb=function(){return 0!=H[this.zb+13>>0>>>0]};this.Rb=function(b,c){this.Fb(0);this.Ub(b);this.Sb(c); +this.Tb();this.Ib(!1);this.Jb(!1)};this.Nb=function(){I[this.zb>>2>>>0]+=1};this.Xb=function(){var b=I[this.zb>>2>>>0];I[this.zb>>2>>>0]=b-1;return 1===b};this.Fb=function(b){J[this.zb+16>>2>>>0]=b};this.Ob=function(){return J[this.zb+16>>2>>>0]};this.Qb=function(){if(Fa(this.Eb()))return J[this.Db>>2>>>0];var b=this.Ob();return 0!==b?b:this.Db}}function Ga(a){return Ha((new S(a)).zb)}var T=[];function U(a){var b=T[a];b||(a>=T.length&&(T.length=a+1),T[a]=b=ua.get(a));return b} +function Ia(a){var b=ra(a)+1,c=Ja(b);c&&qa(a,H,c,b);return c}function Ka(a,b,c){function e(n){return(n=n.toTimeString().match(/\(([A-Za-z ]+)\)$/))?n[1]:"GMT"}var f=(new Date).getFullYear(),h=new Date(f,0,1),k=new Date(f,6,1);f=h.getTimezoneOffset();var l=k.getTimezoneOffset();I[a>>2>>>0]=60*Math.max(f,l);I[b>>2>>>0]=Number(f!=l);a=e(h);b=e(k);a=Ia(a);b=Ia(b);l>2>>>0]=a,J[c+4>>2>>>0]=b):(J[c>>2>>>0]=b,J[c+4>>2>>>0]=a)}function La(a,b,c){La.Vb||(La.Vb=!0,Ka(a,b,c))}var Ma={}; +function Na(){if(!Oa){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:da||"./this.program"},b;for(b in Ma)void 0===Ma[b]?delete a[b]:a[b]=Ma[b];var c=[];for(b in a)c.push(b+"="+a[b]);Oa=c}return Oa}var Oa,Pa=[null,[],[]];function Qa(a,b){var c=Pa[a];0===b||10===b?((1===a?la:z)(oa(c,0)),c.length=0):c.push(b)}var V=0; +function Ra(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(p)try{var b=__webpack_require__(Object(function webpackMissingModule() { var e = new Error("Cannot find module 'crypto'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));return()=>b.randomBytes(1)[0]}catch(c){}return()=>B("randomDevice")}function W(a,b){W.Mb||(W.Mb=Ra());for(var c=0;c>0>>>0]=W.Mb();return 0}function Sa(a){return 0===a%4&&(0!==a%100||0===a%400)}var Ta=[31,29,31,30,31,30,31,31,30,31,30,31],Ua=[31,28,31,30,31,30,31,31,30,31,30,31]; +function Va(a){var b=Array(ra(a)+1);qa(a,b,0,b.length);return b} +function Wa(a,b,c,e){function f(g,u,w){for(g="number"==typeof g?g.toString():g||"";g.lengthM?-1:0F-g.getDate())u-=F-g.getDate()+1,g.setDate(1),11>w?g.setMonth(w+1):(g.setMonth(0),g.setFullYear(g.getFullYear()+1));else{g.setDate(g.getDate()+u);break}}w=new Date(g.getFullYear()+1,0,4);u=l(new Date(g.getFullYear(), +0,4));w=l(w);return 0>=k(u,g)?0>=k(w,g)?g.getFullYear()+1:g.getFullYear():g.getFullYear()-1}var t=I[e+40>>2>>>0];e={$b:I[e>>2>>>0],Zb:I[e+4>>2>>>0],Gb:I[e+8>>2>>>0],Kb:I[e+12>>2>>>0],Hb:I[e+16>>2>>>0],Cb:I[e+20>>2>>>0],Ab:I[e+24>>2>>>0],Bb:I[e+28>>2>>>0],bc:I[e+32>>2>>>0],Yb:I[e+36>>2>>>0],ac:t?pa(t):""};c=pa(c);t={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y", +"%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var x in t)c=c.replace(new RegExp(x,"g"),t[x]);var E="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),C="January February March April May June July August September October November December".split(" ");t={"%a":function(g){return E[g.Ab].substring(0,3)},"%A":function(g){return E[g.Ab]},"%b":function(g){return C[g.Hb].substring(0, +3)},"%B":function(g){return C[g.Hb]},"%C":function(g){return h((g.Cb+1900)/100|0,2)},"%d":function(g){return h(g.Kb,2)},"%e":function(g){return f(g.Kb,2," ")},"%g":function(g){return n(g).toString().substring(2)},"%G":function(g){return n(g)},"%H":function(g){return h(g.Gb,2)},"%I":function(g){g=g.Gb;0==g?g=12:12g.Gb?"AM":"PM"},"%S":function(g){return h(g.$b,2)},"%t":function(){return"\t"},"%u":function(g){return g.Ab||7},"%U":function(g){return h(Math.floor((g.Bb+7-g.Ab)/7),2)},"%V":function(g){var u=Math.floor((g.Bb+7-(g.Ab+6)%7)/7);2>=(g.Ab+371-g.Bb-2)%7&&u++;if(u)53==u&&(w=(g.Ab+371-g.Bb)%7,4==w||3==w&&Sa(g.Cb)||(u=1));else{u=52;var w=(g.Ab+7-g.Bb-1)%7;(4==w||5==w&&Sa(g.Cb%400-1))&&u++}return h(u,2)},"%w":function(g){return g.Ab},"%W":function(g){return h(Math.floor((g.Bb+ +7-(g.Ab+6)%7)/7),2)},"%y":function(g){return(g.Cb+1900).toString().substring(2)},"%Y":function(g){return g.Cb+1900},"%z":function(g){g=g.Yb;var u=0<=g;g=Math.abs(g)/60;return(u?"+":"-")+String("0000"+(g/60*100+g%60)).slice(-4)},"%Z":function(g){return g.ac},"%%":function(){return"%"}};c=c.replace(/%%/g,"\x00\x00");for(x in t)c.includes(x)&&(c=c.replace(new RegExp(x,"g"),t[x](e)));c=c.replace(/\0\0/g,"%");x=Va(c);if(x.length>b)return 0;H.set(x,a>>>0);return x.length-1} +var Jb={a:function(a){return Ja(a+24)+24},m:function(a){a=new S(a);a.Pb()||(a.Ib(!0),Q--);a.Jb(!1);P.push(a);a.Nb();return a.Qb()},ia:function(a){z("Unexpected exception thrown, this is not properly supported - aborting");D=!0;throw a;},w:function(){X(0);var a=P.pop();if(a.Xb()&&!a.Lb()){var b=a.Wb();b&&U(b)(a.Db);Ga(a.Db)}R=0},d:function(){var a=R;if(!a)return V=0;var b=new S(a);b.Fb(a);var c=b.Eb();if(!c)return V=0,a;for(var e=Array.prototype.slice.call(arguments),f=0;f>>2]+4294967296*I[a+4>>>2]));I[b>>2>>>0]=a.getUTCSeconds();I[b+4>>2>>>0]=a.getUTCMinutes();I[b+8>>2>>>0]=a.getUTCHours();I[b+12>>2>>> +0]=a.getUTCDate();I[b+16>>2>>>0]=a.getUTCMonth();I[b+20>>2>>>0]=a.getUTCFullYear()-1900;I[b+24>>2>>>0]=a.getUTCDay();I[b+28>>2>>>0]=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0},Ea:function(a,b){a=new Date(1E3*(J[a>>>2]+4294967296*I[a+4>>>2]));I[b>>2>>>0]=a.getSeconds();I[b+4>>2>>>0]=a.getMinutes();I[b+8>>2>>>0]=a.getHours();I[b+12>>2>>>0]=a.getDate();I[b+16>>2>>>0]=a.getMonth();I[b+20>>2>>>0]=a.getFullYear()-1900;I[b+24>>2>>>0]=a.getDay();var c=new Date(a.getFullYear(),0,1);I[b+ +28>>2>>>0]=(a.getTime()-c.getTime())/864E5|0;I[b+36>>2>>>0]=-(60*a.getTimezoneOffset());var e=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();I[b+32>>2>>>0]=(e!=c&&a.getTimezoneOffset()==Math.min(c,e))|0},Fa:function(a){var b=new Date(I[a+20>>2>>>0]+1900,I[a+16>>2>>>0],I[a+12>>2>>>0],I[a+8>>2>>>0],I[a+4>>2>>>0],I[a>>2>>>0],0),c=I[a+32>>2>>>0],e=b.getTimezoneOffset(),f=new Date(b.getFullYear(),0,1),h=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),k=f.getTimezoneOffset(), +l=Math.min(k,h);0>c?I[a+32>>2>>>0]=Number(h!=k&&l==e):0>2>>>0]=b.getDay();I[a+28>>2>>>0]=(b.getTime()-f.getTime())/864E5|0;I[a>>2>>>0]=b.getSeconds();I[a+4>>2>>>0]=b.getMinutes();I[a+8>>2>>>0]=b.getHours();I[a+12>>2>>>0]=b.getDate();I[a+16>>2>>>0]=b.getMonth();return b.getTime()/1E3|0},sa:function(){return-52},ta:function(){},Ga:La,B:function(){B("")},ma:function(){return 4294901760},I:p?()=>{var a=process.hrtime();return 1E3* +a[0]+a[1]/1E6}:()=>performance.now(),xa:function(a,b,c){G.copyWithin(a>>>0,b>>>0,b+c>>>0)},G:function(a){var b=G.length;a>>>=0;if(4294901760=c;c*=2){var e=b*(1+.2/c);e=Math.min(e,a+100663296);var f=Math;e=Math.max(a,e);f=f.min.call(f,4294901760,e+(65536-e%65536)%65536);a:{try{ma.grow(f-sa.byteLength+65535>>>16);ta();var h=1;break a}catch(k){}h=void 0}if(h)return!0}return!1},va:function(a,b){var c=0;Na().forEach(function(e,f){var h=b+c;f=J[a+4*f>>2>>>0]=h;for(h=0;h> +0>>>0]=e.charCodeAt(h);H[f>>0>>>0]=0;c+=e.length+1});return 0},wa:function(a,b){var c=Na();J[a>>2>>>0]=c.length;var e=0;c.forEach(function(f){e+=f.length+1});J[b>>2>>>0]=e;return 0},ba:function(a){noExitRuntime||0>2>>>0],l=J[b+4>> +2>>>0];b+=8;for(var n=0;n>>0]);f+=l}J[e>>2>>>0]=f;return 0},c:function(){return V},ja:W,ea:$a,fa:ab,J:bb,e:cb,N:db,O:eb,j:fb,o:gb,p:hb,M:ib,r:jb,v:kb,K:lb,D:mb,X:nb,V:ob,U:pb,Z:qb,W:rb,Y:sb,T:tb,f:ub,q:vb,h:wb,da:xb,l:yb,t:zb,u:Ab,x:Bb,z:Cb,ga:Db,A:Eb,C:Fb,aa:Gb,_:Hb,$:Ib,n:function(a){return a},F:function(a){V=a},ha:Wa,y:function(a,b,c,e){return Wa(a,b,c,e)}}; +(function(){function a(f){d.asm=f.exports;ma=d.asm.Ka;ta();ua=d.asm.ib;wa.unshift(d.asm.La);K--;d.monitorRunDependencies&&d.monitorRunDependencies(K);0==K&&(null!==Aa&&(clearInterval(Aa),Aa=null),L&&(f=L,L=null,f()))}function b(f){a(f.instance)}function c(f){return Ea().then(function(h){return WebAssembly.instantiate(h,e)}).then(function(h){return h}).then(f,function(h){z("failed to asynchronously prepare wasm: "+h);B(h)})}var e={a:Jb};K++;d.monitorRunDependencies&&d.monitorRunDependencies(K);if(d.instantiateWasm)try{return d.instantiateWasm(e, +a)}catch(f){return z("Module.instantiateWasm callback failed with error: "+f),!1}(function(){return A||"function"!=typeof WebAssembly.instantiateStreaming||Ba()||N.startsWith("file://")||p||"function"!=typeof fetch?c(b):fetch(N,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,e).then(b,function(h){z("wasm streaming compile failed: "+h);z("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})(); +d.___wasm_call_ctors=function(){return(d.___wasm_call_ctors=d.asm.La).apply(null,arguments)};d._OrtInit=function(){return(d._OrtInit=d.asm.Ma).apply(null,arguments)};d._OrtCreateSessionOptions=function(){return(d._OrtCreateSessionOptions=d.asm.Na).apply(null,arguments)};d._OrtAppendExecutionProvider=function(){return(d._OrtAppendExecutionProvider=d.asm.Oa).apply(null,arguments)};d._OrtAddSessionConfigEntry=function(){return(d._OrtAddSessionConfigEntry=d.asm.Pa).apply(null,arguments)}; +d._OrtReleaseSessionOptions=function(){return(d._OrtReleaseSessionOptions=d.asm.Qa).apply(null,arguments)};d._OrtCreateSession=function(){return(d._OrtCreateSession=d.asm.Ra).apply(null,arguments)};d._OrtReleaseSession=function(){return(d._OrtReleaseSession=d.asm.Sa).apply(null,arguments)};d._OrtGetInputCount=function(){return(d._OrtGetInputCount=d.asm.Ta).apply(null,arguments)};d._OrtGetOutputCount=function(){return(d._OrtGetOutputCount=d.asm.Ua).apply(null,arguments)}; +d._OrtGetInputName=function(){return(d._OrtGetInputName=d.asm.Va).apply(null,arguments)};d._OrtGetOutputName=function(){return(d._OrtGetOutputName=d.asm.Wa).apply(null,arguments)};d._OrtFree=function(){return(d._OrtFree=d.asm.Xa).apply(null,arguments)};d._OrtCreateTensor=function(){return(d._OrtCreateTensor=d.asm.Ya).apply(null,arguments)};d._OrtGetTensorData=function(){return(d._OrtGetTensorData=d.asm.Za).apply(null,arguments)}; +d._OrtReleaseTensor=function(){return(d._OrtReleaseTensor=d.asm._a).apply(null,arguments)};d._OrtCreateRunOptions=function(){return(d._OrtCreateRunOptions=d.asm.$a).apply(null,arguments)};d._OrtAddRunConfigEntry=function(){return(d._OrtAddRunConfigEntry=d.asm.ab).apply(null,arguments)};d._OrtReleaseRunOptions=function(){return(d._OrtReleaseRunOptions=d.asm.bb).apply(null,arguments)};d._OrtRun=function(){return(d._OrtRun=d.asm.cb).apply(null,arguments)}; +d._OrtEndProfiling=function(){return(d._OrtEndProfiling=d.asm.db).apply(null,arguments)}; +var Ja=d._malloc=function(){return(Ja=d._malloc=d.asm.eb).apply(null,arguments)},Ha=d._free=function(){return(Ha=d._free=d.asm.fb).apply(null,arguments)},Za=d._fflush=function(){return(Za=d._fflush=d.asm.gb).apply(null,arguments)},Ya=d.___funcs_on_exit=function(){return(Ya=d.___funcs_on_exit=d.asm.hb).apply(null,arguments)},X=d._setThrew=function(){return(X=d._setThrew=d.asm.jb).apply(null,arguments)},Y=d.stackSave=function(){return(Y=d.stackSave=d.asm.kb).apply(null,arguments)},Z=d.stackRestore= +function(){return(Z=d.stackRestore=d.asm.lb).apply(null,arguments)},Kb=d.stackAlloc=function(){return(Kb=d.stackAlloc=d.asm.mb).apply(null,arguments)},Xa=d.___cxa_can_catch=function(){return(Xa=d.___cxa_can_catch=d.asm.nb).apply(null,arguments)},Fa=d.___cxa_is_pointer_type=function(){return(Fa=d.___cxa_is_pointer_type=d.asm.ob).apply(null,arguments)},Lb=d.dynCall_j=function(){return(Lb=d.dynCall_j=d.asm.pb).apply(null,arguments)},Mb=d.dynCall_iiiiij=function(){return(Mb=d.dynCall_iiiiij=d.asm.qb).apply(null, +arguments)},Nb=d.dynCall_jii=function(){return(Nb=d.dynCall_jii=d.asm.rb).apply(null,arguments)},Ob=d.dynCall_viiiiij=function(){return(Ob=d.dynCall_viiiiij=d.asm.sb).apply(null,arguments)},Pb=d.dynCall_vjji=function(){return(Pb=d.dynCall_vjji=d.asm.tb).apply(null,arguments)},Qb=d.dynCall_viiijjjii=function(){return(Qb=d.dynCall_viiijjjii=d.asm.ub).apply(null,arguments)},Rb=d.dynCall_iij=function(){return(Rb=d.dynCall_iij=d.asm.vb).apply(null,arguments)},Sb=d.dynCall_ji=function(){return(Sb=d.dynCall_ji= +d.asm.wb).apply(null,arguments)},Tb=d.dynCall_iiiiiij=function(){return(Tb=d.dynCall_iiiiiij=d.asm.xb).apply(null,arguments)},Ub=d.dynCall_iiij=function(){return(Ub=d.dynCall_iiij=d.asm.yb).apply(null,arguments)};function cb(a,b){var c=Y();try{return U(a)(b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}}function vb(a,b){var c=Y();try{U(a)(b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}}function wb(a,b,c){var e=Y();try{U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}} +function fb(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function gb(a,b,c,e){var f=Y();try{return U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function kb(a,b,c,e,f,h,k){var l=Y();try{return U(a)(b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}}function ub(a){var b=Y();try{U(a)()}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function jb(a,b,c,e,f,h){var k=Y();try{return U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}} +function hb(a,b,c,e,f){var h=Y();try{return U(a)(b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function yb(a,b,c,e){var f=Y();try{U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function Ab(a,b,c,e,f,h){var k=Y();try{U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}function zb(a,b,c,e,f){var h=Y();try{U(a)(b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function Bb(a,b,c,e,f,h,k){var l=Y();try{U(a)(b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}} +function Cb(a,b,c,e,f,h,k,l){var n=Y();try{U(a)(b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function eb(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function db(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function Db(a,b,c,e,f,h,k,l,n){var t=Y();try{U(a)(b,c,e,f,h,k,l,n)}catch(x){Z(t);if(x!==x+0)throw x;X(1,0)}}function ib(a,b,c,e,f,h){var k=Y();try{return U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}} +function lb(a,b,c,e,f,h,k,l){var n=Y();try{return U(a)(b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function mb(a,b,c,e,f,h,k,l,n,t,x,E){var C=Y();try{return U(a)(b,c,e,f,h,k,l,n,t,x,E)}catch(g){Z(C);if(g!==g+0)throw g;X(1,0)}}function Eb(a,b,c,e,f,h,k,l,n,t,x){var E=Y();try{U(a)(b,c,e,f,h,k,l,n,t,x)}catch(C){Z(E);if(C!==C+0)throw C;X(1,0)}}function Fb(a,b,c,e,f,h,k,l,n,t,x,E,C,g,u,w){var F=Y();try{U(a)(b,c,e,f,h,k,l,n,t,x,E,C,g,u,w)}catch(M){Z(F);if(M!==M+0)throw M;X(1,0)}} +function bb(a){var b=Y();try{return U(a)()}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function ab(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function $a(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function xb(a,b,c,e){var f=Y();try{U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function Gb(a,b,c,e,f,h,k,l){var n=Y();try{Ob(a,b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}} +function Ib(a,b,c,e,f,h){var k=Y();try{Pb(a,b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}function Hb(a,b,c,e,f,h,k,l,n,t,x,E){var C=Y();try{Qb(a,b,c,e,f,h,k,l,n,t,x,E)}catch(g){Z(C);if(g!==g+0)throw g;X(1,0)}}function qb(a,b,c,e){var f=Y();try{return Rb(a,b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function sb(a,b){var c=Y();try{return Sb(a,b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}} +function nb(a,b,c,e,f,h,k,l){var n=Y();try{return Tb(a,b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function rb(a){var b=Y();try{return Lb(a)}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function ob(a,b,c,e,f,h,k){var l=Y();try{return Mb(a,b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}}function pb(a,b,c,e,f){var h=Y();try{return Ub(a,b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function tb(a,b,c){var e=Y();try{return Nb(a,b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}} +d.UTF8ToString=pa;d.stringToUTF8=function(a,b,c){return qa(a,G,b,c)};d.lengthBytesUTF8=ra;d.stackSave=Y;d.stackRestore=Z;d.stackAlloc=Kb;var Vb;L=function Wb(){Vb||Xb();Vb||(L=Wb)}; +function Xb(){function a(){if(!Vb&&(Vb=!0,d.calledRun=!0,!D)){O(wa);aa(d);if(d.onRuntimeInitialized)d.onRuntimeInitialized();if(d.postRun)for("function"==typeof d.postRun&&(d.postRun=[d.postRun]);d.postRun.length;){var b=d.postRun.shift();ya.unshift(b)}O(ya)}}if(!(0 { + +"use strict"; + +module.exports = asPromise; + +/** + * Callback as used by {@link util.asPromise}. + * @typedef asPromiseCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {...*} params Additional arguments + * @returns {undefined} + */ + +/** + * Returns a promise from a node-style callback function. + * @memberof util + * @param {asPromiseCallback} fn Function to call + * @param {*} ctx Function context + * @param {...*} params Function arguments + * @returns {Promise<*>} Promisified function + */ +function asPromise(fn, ctx/*, varargs */) { + var params = new Array(arguments.length - 1), + offset = 0, + index = 2, + pending = true; + while (index < arguments.length) + params[offset++] = arguments[index++]; + return new Promise(function executor(resolve, reject) { + params[offset] = function callback(err/*, varargs */) { + if (pending) { + pending = false; + if (err) + reject(err); + else { + var params = new Array(arguments.length - 1), + offset = 0; + while (offset < params.length) + params[offset++] = arguments[offset]; + resolve.apply(null, params); + } + } + }; + try { + fn.apply(ctx || null, params); + } catch (err) { + if (pending) { + pending = false; + reject(err); + } + } + }); +} + + +/***/ }), + +/***/ "./node_modules/@protobufjs/base64/index.js": +/*!**************************************************!*\ + !*** ./node_modules/@protobufjs/base64/index.js ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + + +/** + * A minimal base64 implementation for number arrays. + * @memberof util + * @namespace + */ +var base64 = exports; + +/** + * Calculates the byte length of a base64 encoded string. + * @param {string} string Base64 encoded string + * @returns {number} Byte length + */ +base64.length = function length(string) { + var p = string.length; + if (!p) + return 0; + var n = 0; + while (--p % 4 > 1 && string.charAt(p) === "=") + ++n; + return Math.ceil(string.length * 3) / 4 - n; +}; + +// Base64 encoding table +var b64 = new Array(64); + +// Base64 decoding table +var s64 = new Array(123); + +// 65..90, 97..122, 48..57, 43, 47 +for (var i = 0; i < 64;) + s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++; + +/** + * Encodes a buffer to a base64 encoded string. + * @param {Uint8Array} buffer Source buffer + * @param {number} start Source start + * @param {number} end Source end + * @returns {string} Base64 encoded string + */ +base64.encode = function encode(buffer, start, end) { + var parts = null, + chunk = []; + var i = 0, // output index + j = 0, // goto index + t; // temporary + while (start < end) { + var b = buffer[start++]; + switch (j) { + case 0: + chunk[i++] = b64[b >> 2]; + t = (b & 3) << 4; + j = 1; + break; + case 1: + chunk[i++] = b64[t | b >> 4]; + t = (b & 15) << 2; + j = 2; + break; + case 2: + chunk[i++] = b64[t | b >> 6]; + chunk[i++] = b64[b & 63]; + j = 0; + break; + } + if (i > 8191) { + (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk)); + i = 0; + } + } + if (j) { + chunk[i++] = b64[t]; + chunk[i++] = 61; + if (j === 1) + chunk[i++] = 61; + } + if (parts) { + if (i) + parts.push(String.fromCharCode.apply(String, chunk.slice(0, i))); + return parts.join(""); + } + return String.fromCharCode.apply(String, chunk.slice(0, i)); +}; + +var invalidEncoding = "invalid encoding"; + +/** + * Decodes a base64 encoded string to a buffer. + * @param {string} string Source string + * @param {Uint8Array} buffer Destination buffer + * @param {number} offset Destination offset + * @returns {number} Number of bytes written + * @throws {Error} If encoding is invalid + */ +base64.decode = function decode(string, buffer, offset) { + var start = offset; + var j = 0, // goto index + t; // temporary + for (var i = 0; i < string.length;) { + var c = string.charCodeAt(i++); + if (c === 61 && j > 1) + break; + if ((c = s64[c]) === undefined) + throw Error(invalidEncoding); + switch (j) { + case 0: + t = c; + j = 1; + break; + case 1: + buffer[offset++] = t << 2 | (c & 48) >> 4; + t = c; + j = 2; + break; + case 2: + buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2; + t = c; + j = 3; + break; + case 3: + buffer[offset++] = (t & 3) << 6 | c; + j = 0; + break; + } + } + if (j === 1) + throw Error(invalidEncoding); + return offset - start; +}; + +/** + * Tests if the specified string appears to be base64 encoded. + * @param {string} string String to test + * @returns {boolean} `true` if probably base64 encoded, otherwise false + */ +base64.test = function test(string) { + return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string); +}; + + +/***/ }), + +/***/ "./node_modules/@protobufjs/eventemitter/index.js": +/*!********************************************************!*\ + !*** ./node_modules/@protobufjs/eventemitter/index.js ***! + \********************************************************/ +/***/ ((module) => { + +"use strict"; + +module.exports = EventEmitter; + +/** + * Constructs a new event emitter instance. + * @classdesc A minimal event emitter. + * @memberof util + * @constructor + */ +function EventEmitter() { + + /** + * Registered listeners. + * @type {Object.} + * @private + */ + this._listeners = {}; +} + +/** + * Registers an event listener. + * @param {string} evt Event name + * @param {function} fn Listener + * @param {*} [ctx] Listener context + * @returns {util.EventEmitter} `this` + */ +EventEmitter.prototype.on = function on(evt, fn, ctx) { + (this._listeners[evt] || (this._listeners[evt] = [])).push({ + fn : fn, + ctx : ctx || this + }); + return this; +}; + +/** + * Removes an event listener or any matching listeners if arguments are omitted. + * @param {string} [evt] Event name. Removes all listeners if omitted. + * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted. + * @returns {util.EventEmitter} `this` + */ +EventEmitter.prototype.off = function off(evt, fn) { + if (evt === undefined) + this._listeners = {}; + else { + if (fn === undefined) + this._listeners[evt] = []; + else { + var listeners = this._listeners[evt]; + for (var i = 0; i < listeners.length;) + if (listeners[i].fn === fn) + listeners.splice(i, 1); + else + ++i; + } + } + return this; +}; + +/** + * Emits an event by calling its listeners with the specified arguments. + * @param {string} evt Event name + * @param {...*} args Arguments + * @returns {util.EventEmitter} `this` + */ +EventEmitter.prototype.emit = function emit(evt) { + var listeners = this._listeners[evt]; + if (listeners) { + var args = [], + i = 1; + for (; i < arguments.length;) + args.push(arguments[i++]); + for (i = 0; i < listeners.length;) + listeners[i].fn.apply(listeners[i++].ctx, args); + } + return this; +}; + + +/***/ }), + +/***/ "./node_modules/@protobufjs/float/index.js": +/*!*************************************************!*\ + !*** ./node_modules/@protobufjs/float/index.js ***! + \*************************************************/ +/***/ ((module) => { + +"use strict"; + + +module.exports = factory(factory); + +/** + * Reads / writes floats / doubles from / to buffers. + * @name util.float + * @namespace + */ + +/** + * Writes a 32 bit float to a buffer using little endian byte order. + * @name util.float.writeFloatLE + * @function + * @param {number} val Value to write + * @param {Uint8Array} buf Target buffer + * @param {number} pos Target buffer offset + * @returns {undefined} + */ + +/** + * Writes a 32 bit float to a buffer using big endian byte order. + * @name util.float.writeFloatBE + * @function + * @param {number} val Value to write + * @param {Uint8Array} buf Target buffer + * @param {number} pos Target buffer offset + * @returns {undefined} + */ + +/** + * Reads a 32 bit float from a buffer using little endian byte order. + * @name util.float.readFloatLE + * @function + * @param {Uint8Array} buf Source buffer + * @param {number} pos Source buffer offset + * @returns {number} Value read + */ + +/** + * Reads a 32 bit float from a buffer using big endian byte order. + * @name util.float.readFloatBE + * @function + * @param {Uint8Array} buf Source buffer + * @param {number} pos Source buffer offset + * @returns {number} Value read + */ + +/** + * Writes a 64 bit double to a buffer using little endian byte order. + * @name util.float.writeDoubleLE + * @function + * @param {number} val Value to write + * @param {Uint8Array} buf Target buffer + * @param {number} pos Target buffer offset + * @returns {undefined} + */ + +/** + * Writes a 64 bit double to a buffer using big endian byte order. + * @name util.float.writeDoubleBE + * @function + * @param {number} val Value to write + * @param {Uint8Array} buf Target buffer + * @param {number} pos Target buffer offset + * @returns {undefined} + */ + +/** + * Reads a 64 bit double from a buffer using little endian byte order. + * @name util.float.readDoubleLE + * @function + * @param {Uint8Array} buf Source buffer + * @param {number} pos Source buffer offset + * @returns {number} Value read + */ + +/** + * Reads a 64 bit double from a buffer using big endian byte order. + * @name util.float.readDoubleBE + * @function + * @param {Uint8Array} buf Source buffer + * @param {number} pos Source buffer offset + * @returns {number} Value read + */ + +// Factory function for the purpose of node-based testing in modified global environments +function factory(exports) { + + // float: typed array + if (typeof Float32Array !== "undefined") (function() { + + var f32 = new Float32Array([ -0 ]), + f8b = new Uint8Array(f32.buffer), + le = f8b[3] === 128; + + function writeFloat_f32_cpy(val, buf, pos) { + f32[0] = val; + buf[pos ] = f8b[0]; + buf[pos + 1] = f8b[1]; + buf[pos + 2] = f8b[2]; + buf[pos + 3] = f8b[3]; + } + + function writeFloat_f32_rev(val, buf, pos) { + f32[0] = val; + buf[pos ] = f8b[3]; + buf[pos + 1] = f8b[2]; + buf[pos + 2] = f8b[1]; + buf[pos + 3] = f8b[0]; + } + + /* istanbul ignore next */ + exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev; + /* istanbul ignore next */ + exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy; + + function readFloat_f32_cpy(buf, pos) { + f8b[0] = buf[pos ]; + f8b[1] = buf[pos + 1]; + f8b[2] = buf[pos + 2]; + f8b[3] = buf[pos + 3]; + return f32[0]; + } + + function readFloat_f32_rev(buf, pos) { + f8b[3] = buf[pos ]; + f8b[2] = buf[pos + 1]; + f8b[1] = buf[pos + 2]; + f8b[0] = buf[pos + 3]; + return f32[0]; + } + + /* istanbul ignore next */ + exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev; + /* istanbul ignore next */ + exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy; + + // float: ieee754 + })(); else (function() { + + function writeFloat_ieee754(writeUint, val, buf, pos) { + var sign = val < 0 ? 1 : 0; + if (sign) + val = -val; + if (val === 0) + writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos); + else if (isNaN(val)) + writeUint(2143289344, buf, pos); + else if (val > 3.4028234663852886e+38) // +-Infinity + writeUint((sign << 31 | 2139095040) >>> 0, buf, pos); + else if (val < 1.1754943508222875e-38) // denormal + writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos); + else { + var exponent = Math.floor(Math.log(val) / Math.LN2), + mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607; + writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos); + } + } + + exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE); + exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE); + + function readFloat_ieee754(readUint, buf, pos) { + var uint = readUint(buf, pos), + sign = (uint >> 31) * 2 + 1, + exponent = uint >>> 23 & 255, + mantissa = uint & 8388607; + return exponent === 255 + ? mantissa + ? NaN + : sign * Infinity + : exponent === 0 // denormal + ? sign * 1.401298464324817e-45 * mantissa + : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608); + } + + exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE); + exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE); + + })(); + + // double: typed array + if (typeof Float64Array !== "undefined") (function() { + + var f64 = new Float64Array([-0]), + f8b = new Uint8Array(f64.buffer), + le = f8b[7] === 128; + + function writeDouble_f64_cpy(val, buf, pos) { + f64[0] = val; + buf[pos ] = f8b[0]; + buf[pos + 1] = f8b[1]; + buf[pos + 2] = f8b[2]; + buf[pos + 3] = f8b[3]; + buf[pos + 4] = f8b[4]; + buf[pos + 5] = f8b[5]; + buf[pos + 6] = f8b[6]; + buf[pos + 7] = f8b[7]; + } + + function writeDouble_f64_rev(val, buf, pos) { + f64[0] = val; + buf[pos ] = f8b[7]; + buf[pos + 1] = f8b[6]; + buf[pos + 2] = f8b[5]; + buf[pos + 3] = f8b[4]; + buf[pos + 4] = f8b[3]; + buf[pos + 5] = f8b[2]; + buf[pos + 6] = f8b[1]; + buf[pos + 7] = f8b[0]; + } + + /* istanbul ignore next */ + exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev; + /* istanbul ignore next */ + exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy; + + function readDouble_f64_cpy(buf, pos) { + f8b[0] = buf[pos ]; + f8b[1] = buf[pos + 1]; + f8b[2] = buf[pos + 2]; + f8b[3] = buf[pos + 3]; + f8b[4] = buf[pos + 4]; + f8b[5] = buf[pos + 5]; + f8b[6] = buf[pos + 6]; + f8b[7] = buf[pos + 7]; + return f64[0]; + } + + function readDouble_f64_rev(buf, pos) { + f8b[7] = buf[pos ]; + f8b[6] = buf[pos + 1]; + f8b[5] = buf[pos + 2]; + f8b[4] = buf[pos + 3]; + f8b[3] = buf[pos + 4]; + f8b[2] = buf[pos + 5]; + f8b[1] = buf[pos + 6]; + f8b[0] = buf[pos + 7]; + return f64[0]; + } + + /* istanbul ignore next */ + exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev; + /* istanbul ignore next */ + exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy; + + // double: ieee754 + })(); else (function() { + + function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) { + var sign = val < 0 ? 1 : 0; + if (sign) + val = -val; + if (val === 0) { + writeUint(0, buf, pos + off0); + writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1); + } else if (isNaN(val)) { + writeUint(0, buf, pos + off0); + writeUint(2146959360, buf, pos + off1); + } else if (val > 1.7976931348623157e+308) { // +-Infinity + writeUint(0, buf, pos + off0); + writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1); + } else { + var mantissa; + if (val < 2.2250738585072014e-308) { // denormal + mantissa = val / 5e-324; + writeUint(mantissa >>> 0, buf, pos + off0); + writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1); + } else { + var exponent = Math.floor(Math.log(val) / Math.LN2); + if (exponent === 1024) + exponent = 1023; + mantissa = val * Math.pow(2, -exponent); + writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0); + writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1); + } + } + } + + exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4); + exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0); + + function readDouble_ieee754(readUint, off0, off1, buf, pos) { + var lo = readUint(buf, pos + off0), + hi = readUint(buf, pos + off1); + var sign = (hi >> 31) * 2 + 1, + exponent = hi >>> 20 & 2047, + mantissa = 4294967296 * (hi & 1048575) + lo; + return exponent === 2047 + ? mantissa + ? NaN + : sign * Infinity + : exponent === 0 // denormal + ? sign * 5e-324 * mantissa + : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496); + } + + exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4); + exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0); + + })(); + + return exports; +} + +// uint helpers + +function writeUintLE(val, buf, pos) { + buf[pos ] = val & 255; + buf[pos + 1] = val >>> 8 & 255; + buf[pos + 2] = val >>> 16 & 255; + buf[pos + 3] = val >>> 24; +} + +function writeUintBE(val, buf, pos) { + buf[pos ] = val >>> 24; + buf[pos + 1] = val >>> 16 & 255; + buf[pos + 2] = val >>> 8 & 255; + buf[pos + 3] = val & 255; +} + +function readUintLE(buf, pos) { + return (buf[pos ] + | buf[pos + 1] << 8 + | buf[pos + 2] << 16 + | buf[pos + 3] << 24) >>> 0; +} + +function readUintBE(buf, pos) { + return (buf[pos ] << 24 + | buf[pos + 1] << 16 + | buf[pos + 2] << 8 + | buf[pos + 3]) >>> 0; +} + + +/***/ }), + +/***/ "./node_modules/@protobufjs/inquire/index.js": +/*!***************************************************!*\ + !*** ./node_modules/@protobufjs/inquire/index.js ***! + \***************************************************/ +/***/ ((module) => { + +"use strict"; + +module.exports = inquire; + +/** + * Requires a module only if available. + * @memberof util + * @param {string} moduleName Module to require + * @returns {?Object} Required module if available and not empty, otherwise `null` + */ +function inquire(moduleName) { + return null; +} + + +/***/ }), + +/***/ "./node_modules/@protobufjs/pool/index.js": +/*!************************************************!*\ + !*** ./node_modules/@protobufjs/pool/index.js ***! + \************************************************/ +/***/ ((module) => { + +"use strict"; + +module.exports = pool; + +/** + * An allocator as used by {@link util.pool}. + * @typedef PoolAllocator + * @type {function} + * @param {number} size Buffer size + * @returns {Uint8Array} Buffer + */ + +/** + * A slicer as used by {@link util.pool}. + * @typedef PoolSlicer + * @type {function} + * @param {number} start Start offset + * @param {number} end End offset + * @returns {Uint8Array} Buffer slice + * @this {Uint8Array} + */ + +/** + * A general purpose buffer pool. + * @memberof util + * @function + * @param {PoolAllocator} alloc Allocator + * @param {PoolSlicer} slice Slicer + * @param {number} [size=8192] Slab size + * @returns {PoolAllocator} Pooled allocator + */ +function pool(alloc, slice, size) { + var SIZE = size || 8192; + var MAX = SIZE >>> 1; + var slab = null; + var offset = SIZE; + return function pool_alloc(size) { + if (size < 1 || size > MAX) + return alloc(size); + if (offset + size > SIZE) { + slab = alloc(SIZE); + offset = 0; + } + var buf = slice.call(slab, offset, offset += size); + if (offset & 7) // align to 32 bit + offset = (offset | 7) + 1; + return buf; + }; +} + + +/***/ }), + +/***/ "./node_modules/@protobufjs/utf8/index.js": +/*!************************************************!*\ + !*** ./node_modules/@protobufjs/utf8/index.js ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + + +/** + * A minimal UTF8 implementation for number arrays. + * @memberof util + * @namespace + */ +var utf8 = exports; + +/** + * Calculates the UTF8 byte length of a string. + * @param {string} string String + * @returns {number} Byte length + */ +utf8.length = function utf8_length(string) { + var len = 0, + c = 0; + for (var i = 0; i < string.length; ++i) { + c = string.charCodeAt(i); + if (c < 128) + len += 1; + else if (c < 2048) + len += 2; + else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) { + ++i; + len += 4; + } else + len += 3; + } + return len; +}; + +/** + * Reads UTF8 bytes as a string. + * @param {Uint8Array} buffer Source buffer + * @param {number} start Source start + * @param {number} end Source end + * @returns {string} String read + */ +utf8.read = function utf8_read(buffer, start, end) { + var len = end - start; + if (len < 1) + return ""; + var parts = null, + chunk = [], + i = 0, // char offset + t; // temporary + while (start < end) { + t = buffer[start++]; + if (t < 128) + chunk[i++] = t; + else if (t > 191 && t < 224) + chunk[i++] = (t & 31) << 6 | buffer[start++] & 63; + else if (t > 239 && t < 365) { + t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000; + chunk[i++] = 0xD800 + (t >> 10); + chunk[i++] = 0xDC00 + (t & 1023); + } else + chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63; + if (i > 8191) { + (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk)); + i = 0; + } + } + if (parts) { + if (i) + parts.push(String.fromCharCode.apply(String, chunk.slice(0, i))); + return parts.join(""); + } + return String.fromCharCode.apply(String, chunk.slice(0, i)); +}; + +/** + * Writes a string as UTF8 bytes. + * @param {string} string Source string + * @param {Uint8Array} buffer Destination buffer + * @param {number} offset Destination offset + * @returns {number} Bytes written + */ +utf8.write = function utf8_write(string, buffer, offset) { + var start = offset, + c1, // character 1 + c2; // character 2 + for (var i = 0; i < string.length; ++i) { + c1 = string.charCodeAt(i); + if (c1 < 128) { + buffer[offset++] = c1; + } else if (c1 < 2048) { + buffer[offset++] = c1 >> 6 | 192; + buffer[offset++] = c1 & 63 | 128; + } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) { + c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF); + ++i; + buffer[offset++] = c1 >> 18 | 240; + buffer[offset++] = c1 >> 12 & 63 | 128; + buffer[offset++] = c1 >> 6 & 63 | 128; + buffer[offset++] = c1 & 63 | 128; + } else { + buffer[offset++] = c1 >> 12 | 224; + buffer[offset++] = c1 >> 6 & 63 | 128; + buffer[offset++] = c1 & 63 | 128; + } + } + return offset - start; +}; + + +/***/ }), + +/***/ "./node_modules/guid-typescript/dist/guid.js": +/*!***************************************************!*\ + !*** ./node_modules/guid-typescript/dist/guid.js ***! + \***************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +exports.__esModule = true; +var Guid = /** @class */ (function () { + function Guid(guid) { + if (!guid) { + throw new TypeError("Invalid argument; `value` has no value."); + } + this.value = Guid.EMPTY; + if (guid && Guid.isGuid(guid)) { + this.value = guid; + } + } + Guid.isGuid = function (guid) { + var value = guid.toString(); + return guid && (guid instanceof Guid || Guid.validator.test(value)); + }; + Guid.create = function () { + return new Guid([Guid.gen(2), Guid.gen(1), Guid.gen(1), Guid.gen(1), Guid.gen(3)].join("-")); + }; + Guid.createEmpty = function () { + return new Guid("emptyguid"); + }; + Guid.parse = function (guid) { + return new Guid(guid); + }; + Guid.raw = function () { + return [Guid.gen(2), Guid.gen(1), Guid.gen(1), Guid.gen(1), Guid.gen(3)].join("-"); + }; + Guid.gen = function (count) { + var out = ""; + for (var i = 0; i < count; i++) { + // tslint:disable-next-line:no-bitwise + out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); + } + return out; + }; + Guid.prototype.equals = function (other) { + // Comparing string `value` against provided `guid` will auto-call + // toString on `guid` for comparison + return Guid.isGuid(other) && this.value === other.toString(); + }; + Guid.prototype.isEmpty = function () { + return this.value === Guid.EMPTY; + }; + Guid.prototype.toString = function () { + return this.value; + }; + Guid.prototype.toJSON = function () { + return { + value: this.value + }; + }; + Guid.validator = new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i"); + Guid.EMPTY = "00000000-0000-0000-0000-000000000000"; + return Guid; +}()); +exports.Guid = Guid; + + +/***/ }), + +/***/ "./node_modules/long/src/long.js": +/*!***************************************!*\ + !*** ./node_modules/long/src/long.js ***! + \***************************************/ +/***/ ((module) => { + +module.exports = Long; + +/** + * wasm optimizations, to do native i64 multiplication and divide + */ +var wasm = null; + +try { + wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 + ])), {}).exports; +} catch (e) { + // no wasm support :( +} + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +function Long(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + */ + this.unsigned = !!unsigned; +} + +// The internal representation of a long is the two given signed, 32-bit values. +// We use 32-bit pieces because these are the size of integers on which +// Javascript performs bit-operations. For operations like addition and +// multiplication, we split each number into 16 bit pieces, which can easily be +// multiplied within Javascript's floating-point representation without overflow +// or change in sign. +// +// In the algorithms below, we frequently reduce the negative case to the +// positive case by negating the input(s) and then post-processing the result. +// Note that we must ALWAYS check specially whether those values are MIN_VALUE +// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +// a positive number, it overflows back into a negative). Not handling this +// case would often result in infinite recursion. +// +// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* +// methods on which they depend. + +/** + * An indicator used to reliably determine if an object is a Long or not. + * @type {boolean} + * @const + * @private + */ +Long.prototype.__isLong__; + +Object.defineProperty(Long.prototype, "__isLong__", { value: true }); + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + */ +function isLong(obj) { + return (obj && obj["__isLong__"]) === true; +} + +/** + * Tests if the specified object is a Long. + * @function + * @param {*} obj Object + * @returns {boolean} + */ +Long.isLong = isLong; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +var INT_CACHE = {}; + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +var UINT_CACHE = {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromInt(value, unsigned) { + var obj, cachedObj, cache; + if (unsigned) { + value >>>= 0; + if (cache = (0 <= value && value < 256)) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); + if (cache) + UINT_CACHE[value] = obj; + return obj; + } else { + value |= 0; + if (cache = (-128 <= value && value < 128)) { + cachedObj = INT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, value < 0 ? -1 : 0, false); + if (cache) + INT_CACHE[value] = obj; + return obj; + } +} + +/** + * Returns a Long representing the given 32 bit integer value. + * @function + * @param {number} value The 32 bit integer in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromInt = fromInt; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromNumber(value, unsigned) { + if (isNaN(value)) + return unsigned ? UZERO : ZERO; + if (unsigned) { + if (value < 0) + return UZERO; + if (value >= TWO_PWR_64_DBL) + return MAX_UNSIGNED_VALUE; + } else { + if (value <= -TWO_PWR_63_DBL) + return MIN_VALUE; + if (value + 1 >= TWO_PWR_63_DBL) + return MAX_VALUE; + } + if (value < 0) + return fromNumber(-value, unsigned).neg(); + return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); +} + +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * @function + * @param {number} value The number in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromNumber = fromNumber; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromBits(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); +} + +/** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @function + * @param {number} lowBits The low 32 bits + * @param {number} highBits The high 32 bits + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromBits = fromBits; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + */ +var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +function fromString(str, unsigned, radix) { + if (str.length === 0) + throw Error('empty string'); + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") + return ZERO; + if (typeof unsigned === 'number') { + // For goog.math.long compatibility + radix = unsigned, + unsigned = false; + } else { + unsigned = !! unsigned; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + + var p; + if ((p = str.indexOf('-')) > 0) + throw Error('interior hyphen'); + else if (p === 0) { + return fromString(str.substring(1), unsigned, radix).neg(); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 8)); + + var result = ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i), + value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = fromNumber(pow_dbl(radix, size)); + result = result.mul(power).add(fromNumber(value)); + } else { + result = result.mul(radixToPower); + result = result.add(fromNumber(value)); + } + } + result.unsigned = unsigned; + return result; +} + +/** + * Returns a Long representation of the given string, written using the specified radix. + * @function + * @param {string} str The textual representation of the Long + * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed + * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 + * @returns {!Long} The corresponding Long value + */ +Long.fromString = fromString; + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromValue(val, unsigned) { + if (typeof val === 'number') + return fromNumber(val, unsigned); + if (typeof val === 'string') + return fromString(val, unsigned); + // Throws for non-objects, converts non-instanceof Long: + return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); +} + +/** + * Converts the specified value to a Long using the appropriate from* function for its type. + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} + */ +Long.fromValue = fromValue; + +// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be +// no runtime penalty for these. + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_16_DBL = 1 << 16; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_24_DBL = 1 << 24; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + +/** + * @type {!Long} + * @const + * @inner + */ +var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); + +/** + * @type {!Long} + * @inner + */ +var ZERO = fromInt(0); + +/** + * Signed zero. + * @type {!Long} + */ +Long.ZERO = ZERO; + +/** + * @type {!Long} + * @inner + */ +var UZERO = fromInt(0, true); + +/** + * Unsigned zero. + * @type {!Long} + */ +Long.UZERO = UZERO; + +/** + * @type {!Long} + * @inner + */ +var ONE = fromInt(1); + +/** + * Signed one. + * @type {!Long} + */ +Long.ONE = ONE; + +/** + * @type {!Long} + * @inner + */ +var UONE = fromInt(1, true); + +/** + * Unsigned one. + * @type {!Long} + */ +Long.UONE = UONE; + +/** + * @type {!Long} + * @inner + */ +var NEG_ONE = fromInt(-1); + +/** + * Signed negative one. + * @type {!Long} + */ +Long.NEG_ONE = NEG_ONE; + +/** + * @type {!Long} + * @inner + */ +var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); + +/** + * Maximum signed value. + * @type {!Long} + */ +Long.MAX_VALUE = MAX_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); + +/** + * Maximum unsigned value. + * @type {!Long} + */ +Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MIN_VALUE = fromBits(0, 0x80000000|0, false); + +/** + * Minimum signed value. + * @type {!Long} + */ +Long.MIN_VALUE = MIN_VALUE; + +/** + * @alias Long.prototype + * @inner + */ +var LongPrototype = Long.prototype; + +/** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @returns {number} + */ +LongPrototype.toInt = function toInt() { + return this.unsigned ? this.low >>> 0 : this.low; +}; + +/** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @returns {number} + */ +LongPrototype.toNumber = function toNumber() { + if (this.unsigned) + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); +}; + +/** + * Converts the Long to a string written in the specified radix. + * @param {number=} radix Radix (2-36), defaults to 10 + * @returns {string} + * @override + * @throws {RangeError} If `radix` is out of range + */ +LongPrototype.toString = function toString(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + if (this.isZero()) + return '0'; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.eq(MIN_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = fromNumber(radix), + div = this.div(radixLong), + rem1 = div.mul(radixLong).sub(this); + return div.toString(radix) + rem1.toInt().toString(radix); + } else + return '-' + this.neg().toString(radix); + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower), + intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, + digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) + return digits + result; + else { + while (digits.length < 6) + digits = '0' + digits; + result = '' + digits + result; + } + } +}; + +/** + * Gets the high 32 bits as a signed integer. + * @returns {number} Signed high bits + */ +LongPrototype.getHighBits = function getHighBits() { + return this.high; +}; + +/** + * Gets the high 32 bits as an unsigned integer. + * @returns {number} Unsigned high bits + */ +LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { + return this.high >>> 0; +}; + +/** + * Gets the low 32 bits as a signed integer. + * @returns {number} Signed low bits + */ +LongPrototype.getLowBits = function getLowBits() { + return this.low; +}; + +/** + * Gets the low 32 bits as an unsigned integer. + * @returns {number} Unsigned low bits + */ +LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { + return this.low >>> 0; +}; + +/** + * Gets the number of bits needed to represent the absolute value of this Long. + * @returns {number} + */ +LongPrototype.getNumBitsAbs = function getNumBitsAbs() { + if (this.isNegative()) // Unsigned Longs are never negative + return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) + if ((val & (1 << bit)) != 0) + break; + return this.high != 0 ? bit + 33 : bit + 1; +}; + +/** + * Tests if this Long's value equals zero. + * @returns {boolean} + */ +LongPrototype.isZero = function isZero() { + return this.high === 0 && this.low === 0; +}; + +/** + * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}. + * @returns {boolean} + */ +LongPrototype.eqz = LongPrototype.isZero; + +/** + * Tests if this Long's value is negative. + * @returns {boolean} + */ +LongPrototype.isNegative = function isNegative() { + return !this.unsigned && this.high < 0; +}; + +/** + * Tests if this Long's value is positive. + * @returns {boolean} + */ +LongPrototype.isPositive = function isPositive() { + return this.unsigned || this.high >= 0; +}; + +/** + * Tests if this Long's value is odd. + * @returns {boolean} + */ +LongPrototype.isOdd = function isOdd() { + return (this.low & 1) === 1; +}; + +/** + * Tests if this Long's value is even. + * @returns {boolean} + */ +LongPrototype.isEven = function isEven() { + return (this.low & 1) === 0; +}; + +/** + * Tests if this Long's value equals the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.equals = function equals(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) + return false; + return this.high === other.high && this.low === other.low; +}; + +/** + * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.eq = LongPrototype.equals; + +/** + * Tests if this Long's value differs from the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.notEquals = function notEquals(other) { + return !this.eq(/* validates */ other); +}; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.neq = LongPrototype.notEquals; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ne = LongPrototype.notEquals; + +/** + * Tests if this Long's value is less than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThan = function lessThan(other) { + return this.comp(/* validates */ other) < 0; +}; + +/** + * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lt = LongPrototype.lessThan; + +/** + * Tests if this Long's value is less than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { + return this.comp(/* validates */ other) <= 0; +}; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lte = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.le = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is greater than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThan = function greaterThan(other) { + return this.comp(/* validates */ other) > 0; +}; + +/** + * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gt = LongPrototype.greaterThan; + +/** + * Tests if this Long's value is greater than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { + return this.comp(/* validates */ other) >= 0; +}; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gte = LongPrototype.greaterThanOrEqual; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ge = LongPrototype.greaterThanOrEqual; + +/** + * Compares this Long's value with the specified's. + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.compare = function compare(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.eq(other)) + return 0; + var thisNeg = this.isNegative(), + otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) + return -1; + if (!thisNeg && otherNeg) + return 1; + // At this point the sign bits are the same + if (!this.unsigned) + return this.sub(other).isNegative() ? -1 : 1; + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; +}; + +/** + * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. + * @function + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.comp = LongPrototype.compare; + +/** + * Negates this Long's value. + * @returns {!Long} Negated Long + */ +LongPrototype.negate = function negate() { + if (!this.unsigned && this.eq(MIN_VALUE)) + return MIN_VALUE; + return this.not().add(ONE); +}; + +/** + * Negates this Long's value. This is an alias of {@link Long#negate}. + * @function + * @returns {!Long} Negated Long + */ +LongPrototype.neg = LongPrototype.negate; + +/** + * Returns the sum of this and the specified Long. + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + */ +LongPrototype.add = function add(addend) { + if (!isLong(addend)) + addend = fromValue(addend); + + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = addend.high >>> 16; + var b32 = addend.high & 0xFFFF; + var b16 = addend.low >>> 16; + var b00 = addend.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the difference of this and the specified Long. + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.subtract = function subtract(subtrahend) { + if (!isLong(subtrahend)) + subtrahend = fromValue(subtrahend); + return this.add(subtrahend.neg()); +}; + +/** + * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. + * @function + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.sub = LongPrototype.subtract; + +/** + * Returns the product of this and the specified Long. + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.multiply = function multiply(multiplier) { + if (this.isZero()) + return ZERO; + if (!isLong(multiplier)) + multiplier = fromValue(multiplier); + + // use wasm support if present + if (wasm) { + var low = wasm.mul(this.low, + this.high, + multiplier.low, + multiplier.high); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (multiplier.isZero()) + return ZERO; + if (this.eq(MIN_VALUE)) + return multiplier.isOdd() ? MIN_VALUE : ZERO; + if (multiplier.eq(MIN_VALUE)) + return this.isOdd() ? MIN_VALUE : ZERO; + + if (this.isNegative()) { + if (multiplier.isNegative()) + return this.neg().mul(multiplier.neg()); + else + return this.neg().mul(multiplier).neg(); + } else if (multiplier.isNegative()) + return this.mul(multiplier.neg()).neg(); + + // If both longs are small, use float multiplication + if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) + return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = multiplier.high >>> 16; + var b32 = multiplier.high & 0xFFFF; + var b16 = multiplier.low >>> 16; + var b00 = multiplier.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. + * @function + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.mul = LongPrototype.multiply; + +/** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.divide = function divide(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + if (divisor.isZero()) + throw Error('division by zero'); + + // use wasm support if present + if (wasm) { + // guard against signed division overflow: the largest + // negative number / -1 would be 1 larger than the largest + // positive number, due to two's complement. + if (!this.unsigned && + this.high === -0x80000000 && + divisor.low === -1 && divisor.high === -1) { + // be consistent with non-wasm code path + return this; + } + var low = (this.unsigned ? wasm.div_u : wasm.div_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (this.isZero()) + return this.unsigned ? UZERO : ZERO; + var approx, rem, res; + if (!this.unsigned) { + // This section is only relevant for signed longs and is derived from the + // closure library as a whole. + if (this.eq(MIN_VALUE)) { + if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) + return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + else if (divisor.eq(MIN_VALUE)) + return ONE; + else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shr(1); + approx = halfThis.div(divisor).shl(1); + if (approx.eq(ZERO)) { + return divisor.isNegative() ? ONE : NEG_ONE; + } else { + rem = this.sub(divisor.mul(approx)); + res = approx.add(rem.div(divisor)); + return res; + } + } + } else if (divisor.eq(MIN_VALUE)) + return this.unsigned ? UZERO : ZERO; + if (this.isNegative()) { + if (divisor.isNegative()) + return this.neg().div(divisor.neg()); + return this.neg().div(divisor).neg(); + } else if (divisor.isNegative()) + return this.div(divisor.neg()).neg(); + res = ZERO; + } else { + // The algorithm below has not been made for unsigned longs. It's therefore + // required to take special care of the MSB prior to running it. + if (!divisor.unsigned) + divisor = divisor.toUnsigned(); + if (divisor.gt(this)) + return UZERO; + if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true + return UONE; + res = UZERO; + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + rem = this; + while (rem.gte(divisor)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2), + delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + approxRes = fromNumber(approx), + approxRem = approxRes.mul(divisor); + while (approxRem.isNegative() || approxRem.gt(rem)) { + approx -= delta; + approxRes = fromNumber(approx, this.unsigned); + approxRem = approxRes.mul(divisor); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) + approxRes = ONE; + + res = res.add(approxRes); + rem = rem.sub(approxRem); + } + return res; +}; + +/** + * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.div = LongPrototype.divide; + +/** + * Returns this Long modulo the specified. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.modulo = function modulo(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + + // use wasm support if present + if (wasm) { + var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + return this.sub(this.div(divisor).mul(divisor)); +}; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.mod = LongPrototype.modulo; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.rem = LongPrototype.modulo; + +/** + * Returns the bitwise NOT of this Long. + * @returns {!Long} + */ +LongPrototype.not = function not() { + return fromBits(~this.low, ~this.high, this.unsigned); +}; + +/** + * Returns the bitwise AND of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.and = function and(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low & other.low, this.high & other.high, this.unsigned); +}; + +/** + * Returns the bitwise OR of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.or = function or(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low | other.low, this.high | other.high, this.unsigned); +}; + +/** + * Returns the bitwise XOR of this Long and the given one. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.xor = function xor(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftLeft = function shiftLeft(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); + else + return fromBits(0, this.low << (numBits - 32), this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shl = LongPrototype.shiftLeft; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRight = function shiftRight(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); + else + return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); +}; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr = LongPrototype.shiftRight; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + numBits &= 63; + if (numBits === 0) + return this; + else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits === 32) + return fromBits(high, 0, this.unsigned); + else + return fromBits(high >>> (numBits - 32), 0, this.unsigned); + } +}; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shru = LongPrototype.shiftRightUnsigned; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr_u = LongPrototype.shiftRightUnsigned; + +/** + * Converts this Long to signed. + * @returns {!Long} Signed long + */ +LongPrototype.toSigned = function toSigned() { + if (!this.unsigned) + return this; + return fromBits(this.low, this.high, false); +}; + +/** + * Converts this Long to unsigned. + * @returns {!Long} Unsigned long + */ +LongPrototype.toUnsigned = function toUnsigned() { + if (this.unsigned) + return this; + return fromBits(this.low, this.high, true); +}; + +/** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {!Array.} Byte representation + */ +LongPrototype.toBytes = function toBytes(le) { + return le ? this.toBytesLE() : this.toBytesBE(); +}; + +/** + * Converts this Long to its little endian byte representation. + * @returns {!Array.} Little endian byte representation + */ +LongPrototype.toBytesLE = function toBytesLE() { + var hi = this.high, + lo = this.low; + return [ + lo & 0xff, + lo >>> 8 & 0xff, + lo >>> 16 & 0xff, + lo >>> 24 , + hi & 0xff, + hi >>> 8 & 0xff, + hi >>> 16 & 0xff, + hi >>> 24 + ]; +}; + +/** + * Converts this Long to its big endian byte representation. + * @returns {!Array.} Big endian byte representation + */ +LongPrototype.toBytesBE = function toBytesBE() { + var hi = this.high, + lo = this.low; + return [ + hi >>> 24 , + hi >>> 16 & 0xff, + hi >>> 8 & 0xff, + hi & 0xff, + lo >>> 24 , + lo >>> 16 & 0xff, + lo >>> 8 & 0xff, + lo & 0xff + ]; +}; + +/** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + */ +Long.fromBytes = function fromBytes(bytes, unsigned, le) { + return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned); +}; + +/** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesLE = function fromBytesLE(bytes, unsigned) { + return new Long( + bytes[0] | + bytes[1] << 8 | + bytes[2] << 16 | + bytes[3] << 24, + bytes[4] | + bytes[5] << 8 | + bytes[6] << 16 | + bytes[7] << 24, + unsigned + ); +}; + +/** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesBE = function fromBytesBE(bytes, unsigned) { + return new Long( + bytes[4] << 24 | + bytes[5] << 16 | + bytes[6] << 8 | + bytes[7], + bytes[0] << 24 | + bytes[1] << 16 | + bytes[2] << 8 | + bytes[3], + unsigned + ); +}; + + +/***/ }), + +/***/ "./node_modules/onnx-proto/dist/onnx.js": +/*!**********************************************!*\ + !*** ./node_modules/onnx-proto/dist/onnx.js ***! + \**********************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; +/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ + + +var $protobuf = __webpack_require__(/*! protobufjs/minimal */ "./node_modules/protobufjs/minimal.js"); + +// Common aliases +var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +$root.onnx = (function() { + + /** + * Namespace onnx. + * @exports onnx + * @namespace + */ + var onnx = {}; + + /** + * Version enum. + * @name onnx.Version + * @enum {string} + * @property {number} _START_VERSION=0 _START_VERSION value + * @property {number} IR_VERSION_2017_10_10=1 IR_VERSION_2017_10_10 value + * @property {number} IR_VERSION_2017_10_30=2 IR_VERSION_2017_10_30 value + * @property {number} IR_VERSION_2017_11_3=3 IR_VERSION_2017_11_3 value + * @property {number} IR_VERSION_2019_1_22=4 IR_VERSION_2019_1_22 value + * @property {number} IR_VERSION=5 IR_VERSION value + */ + onnx.Version = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "_START_VERSION"] = 0; + values[valuesById[1] = "IR_VERSION_2017_10_10"] = 1; + values[valuesById[2] = "IR_VERSION_2017_10_30"] = 2; + values[valuesById[3] = "IR_VERSION_2017_11_3"] = 3; + values[valuesById[4] = "IR_VERSION_2019_1_22"] = 4; + values[valuesById[5] = "IR_VERSION"] = 5; + return values; + })(); + + onnx.AttributeProto = (function() { + + /** + * Properties of an AttributeProto. + * @memberof onnx + * @interface IAttributeProto + * @property {string|null} [name] AttributeProto name + * @property {string|null} [refAttrName] AttributeProto refAttrName + * @property {string|null} [docString] AttributeProto docString + * @property {onnx.AttributeProto.AttributeType|null} [type] AttributeProto type + * @property {number|null} [f] AttributeProto f + * @property {number|Long|null} [i] AttributeProto i + * @property {Uint8Array|null} [s] AttributeProto s + * @property {onnx.ITensorProto|null} [t] AttributeProto t + * @property {onnx.IGraphProto|null} [g] AttributeProto g + * @property {Array.|null} [floats] AttributeProto floats + * @property {Array.|null} [ints] AttributeProto ints + * @property {Array.|null} [strings] AttributeProto strings + * @property {Array.|null} [tensors] AttributeProto tensors + * @property {Array.|null} [graphs] AttributeProto graphs + */ + + /** + * Constructs a new AttributeProto. + * @memberof onnx + * @classdesc Represents an AttributeProto. + * @implements IAttributeProto + * @constructor + * @param {onnx.IAttributeProto=} [properties] Properties to set + */ + function AttributeProto(properties) { + this.floats = []; + this.ints = []; + this.strings = []; + this.tensors = []; + this.graphs = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * AttributeProto name. + * @member {string} name + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.name = ""; + + /** + * AttributeProto refAttrName. + * @member {string} refAttrName + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.refAttrName = ""; + + /** + * AttributeProto docString. + * @member {string} docString + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.docString = ""; + + /** + * AttributeProto type. + * @member {onnx.AttributeProto.AttributeType} type + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.type = 0; + + /** + * AttributeProto f. + * @member {number} f + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.f = 0; + + /** + * AttributeProto i. + * @member {number|Long} i + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.i = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * AttributeProto s. + * @member {Uint8Array} s + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.s = $util.newBuffer([]); + + /** + * AttributeProto t. + * @member {onnx.ITensorProto|null|undefined} t + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.t = null; + + /** + * AttributeProto g. + * @member {onnx.IGraphProto|null|undefined} g + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.g = null; + + /** + * AttributeProto floats. + * @member {Array.} floats + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.floats = $util.emptyArray; + + /** + * AttributeProto ints. + * @member {Array.} ints + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.ints = $util.emptyArray; + + /** + * AttributeProto strings. + * @member {Array.} strings + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.strings = $util.emptyArray; + + /** + * AttributeProto tensors. + * @member {Array.} tensors + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.tensors = $util.emptyArray; + + /** + * AttributeProto graphs. + * @member {Array.} graphs + * @memberof onnx.AttributeProto + * @instance + */ + AttributeProto.prototype.graphs = $util.emptyArray; + + /** + * Creates a new AttributeProto instance using the specified properties. + * @function create + * @memberof onnx.AttributeProto + * @static + * @param {onnx.IAttributeProto=} [properties] Properties to set + * @returns {onnx.AttributeProto} AttributeProto instance + */ + AttributeProto.create = function create(properties) { + return new AttributeProto(properties); + }; + + /** + * Encodes the specified AttributeProto message. Does not implicitly {@link onnx.AttributeProto.verify|verify} messages. + * @function encode + * @memberof onnx.AttributeProto + * @static + * @param {onnx.IAttributeProto} message AttributeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AttributeProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.name != null && message.hasOwnProperty("name")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.name); + if (message.f != null && message.hasOwnProperty("f")) + writer.uint32(/* id 2, wireType 5 =*/21).float(message.f); + if (message.i != null && message.hasOwnProperty("i")) + writer.uint32(/* id 3, wireType 0 =*/24).int64(message.i); + if (message.s != null && message.hasOwnProperty("s")) + writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.s); + if (message.t != null && message.hasOwnProperty("t")) + $root.onnx.TensorProto.encode(message.t, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.g != null && message.hasOwnProperty("g")) + $root.onnx.GraphProto.encode(message.g, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + if (message.floats != null && message.floats.length) { + writer.uint32(/* id 7, wireType 2 =*/58).fork(); + for (var i = 0; i < message.floats.length; ++i) + writer.float(message.floats[i]); + writer.ldelim(); + } + if (message.ints != null && message.ints.length) { + writer.uint32(/* id 8, wireType 2 =*/66).fork(); + for (var i = 0; i < message.ints.length; ++i) + writer.int64(message.ints[i]); + writer.ldelim(); + } + if (message.strings != null && message.strings.length) + for (var i = 0; i < message.strings.length; ++i) + writer.uint32(/* id 9, wireType 2 =*/74).bytes(message.strings[i]); + if (message.tensors != null && message.tensors.length) + for (var i = 0; i < message.tensors.length; ++i) + $root.onnx.TensorProto.encode(message.tensors[i], writer.uint32(/* id 10, wireType 2 =*/82).fork()).ldelim(); + if (message.graphs != null && message.graphs.length) + for (var i = 0; i < message.graphs.length; ++i) + $root.onnx.GraphProto.encode(message.graphs[i], writer.uint32(/* id 11, wireType 2 =*/90).fork()).ldelim(); + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 13, wireType 2 =*/106).string(message.docString); + if (message.type != null && message.hasOwnProperty("type")) + writer.uint32(/* id 20, wireType 0 =*/160).int32(message.type); + if (message.refAttrName != null && message.hasOwnProperty("refAttrName")) + writer.uint32(/* id 21, wireType 2 =*/170).string(message.refAttrName); + return writer; + }; + + /** + * Encodes the specified AttributeProto message, length delimited. Does not implicitly {@link onnx.AttributeProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.AttributeProto + * @static + * @param {onnx.IAttributeProto} message AttributeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AttributeProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an AttributeProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.AttributeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.AttributeProto} AttributeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AttributeProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.AttributeProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + case 21: + message.refAttrName = reader.string(); + break; + case 13: + message.docString = reader.string(); + break; + case 20: + message.type = reader.int32(); + break; + case 2: + message.f = reader.float(); + break; + case 3: + message.i = reader.int64(); + break; + case 4: + message.s = reader.bytes(); + break; + case 5: + message.t = $root.onnx.TensorProto.decode(reader, reader.uint32()); + break; + case 6: + message.g = $root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 7: + if (!(message.floats && message.floats.length)) + message.floats = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.floats.push(reader.float()); + } else + message.floats.push(reader.float()); + break; + case 8: + if (!(message.ints && message.ints.length)) + message.ints = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.ints.push(reader.int64()); + } else + message.ints.push(reader.int64()); + break; + case 9: + if (!(message.strings && message.strings.length)) + message.strings = []; + message.strings.push(reader.bytes()); + break; + case 10: + if (!(message.tensors && message.tensors.length)) + message.tensors = []; + message.tensors.push($root.onnx.TensorProto.decode(reader, reader.uint32())); + break; + case 11: + if (!(message.graphs && message.graphs.length)) + message.graphs = []; + message.graphs.push($root.onnx.GraphProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an AttributeProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.AttributeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.AttributeProto} AttributeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AttributeProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an AttributeProto message. + * @function verify + * @memberof onnx.AttributeProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + AttributeProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + if (message.refAttrName != null && message.hasOwnProperty("refAttrName")) + if (!$util.isString(message.refAttrName)) + return "refAttrName: string expected"; + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + if (message.type != null && message.hasOwnProperty("type")) + switch (message.type) { + default: + return "type: enum value expected"; + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + break; + } + if (message.f != null && message.hasOwnProperty("f")) + if (typeof message.f !== "number") + return "f: number expected"; + if (message.i != null && message.hasOwnProperty("i")) + if (!$util.isInteger(message.i) && !(message.i && $util.isInteger(message.i.low) && $util.isInteger(message.i.high))) + return "i: integer|Long expected"; + if (message.s != null && message.hasOwnProperty("s")) + if (!(message.s && typeof message.s.length === "number" || $util.isString(message.s))) + return "s: buffer expected"; + if (message.t != null && message.hasOwnProperty("t")) { + var error = $root.onnx.TensorProto.verify(message.t); + if (error) + return "t." + error; + } + if (message.g != null && message.hasOwnProperty("g")) { + var error = $root.onnx.GraphProto.verify(message.g); + if (error) + return "g." + error; + } + if (message.floats != null && message.hasOwnProperty("floats")) { + if (!Array.isArray(message.floats)) + return "floats: array expected"; + for (var i = 0; i < message.floats.length; ++i) + if (typeof message.floats[i] !== "number") + return "floats: number[] expected"; + } + if (message.ints != null && message.hasOwnProperty("ints")) { + if (!Array.isArray(message.ints)) + return "ints: array expected"; + for (var i = 0; i < message.ints.length; ++i) + if (!$util.isInteger(message.ints[i]) && !(message.ints[i] && $util.isInteger(message.ints[i].low) && $util.isInteger(message.ints[i].high))) + return "ints: integer|Long[] expected"; + } + if (message.strings != null && message.hasOwnProperty("strings")) { + if (!Array.isArray(message.strings)) + return "strings: array expected"; + for (var i = 0; i < message.strings.length; ++i) + if (!(message.strings[i] && typeof message.strings[i].length === "number" || $util.isString(message.strings[i]))) + return "strings: buffer[] expected"; + } + if (message.tensors != null && message.hasOwnProperty("tensors")) { + if (!Array.isArray(message.tensors)) + return "tensors: array expected"; + for (var i = 0; i < message.tensors.length; ++i) { + var error = $root.onnx.TensorProto.verify(message.tensors[i]); + if (error) + return "tensors." + error; + } + } + if (message.graphs != null && message.hasOwnProperty("graphs")) { + if (!Array.isArray(message.graphs)) + return "graphs: array expected"; + for (var i = 0; i < message.graphs.length; ++i) { + var error = $root.onnx.GraphProto.verify(message.graphs[i]); + if (error) + return "graphs." + error; + } + } + return null; + }; + + /** + * Creates an AttributeProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.AttributeProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.AttributeProto} AttributeProto + */ + AttributeProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.AttributeProto) + return object; + var message = new $root.onnx.AttributeProto(); + if (object.name != null) + message.name = String(object.name); + if (object.refAttrName != null) + message.refAttrName = String(object.refAttrName); + if (object.docString != null) + message.docString = String(object.docString); + switch (object.type) { + case "UNDEFINED": + case 0: + message.type = 0; + break; + case "FLOAT": + case 1: + message.type = 1; + break; + case "INT": + case 2: + message.type = 2; + break; + case "STRING": + case 3: + message.type = 3; + break; + case "TENSOR": + case 4: + message.type = 4; + break; + case "GRAPH": + case 5: + message.type = 5; + break; + case "FLOATS": + case 6: + message.type = 6; + break; + case "INTS": + case 7: + message.type = 7; + break; + case "STRINGS": + case 8: + message.type = 8; + break; + case "TENSORS": + case 9: + message.type = 9; + break; + case "GRAPHS": + case 10: + message.type = 10; + break; + } + if (object.f != null) + message.f = Number(object.f); + if (object.i != null) + if ($util.Long) + (message.i = $util.Long.fromValue(object.i)).unsigned = false; + else if (typeof object.i === "string") + message.i = parseInt(object.i, 10); + else if (typeof object.i === "number") + message.i = object.i; + else if (typeof object.i === "object") + message.i = new $util.LongBits(object.i.low >>> 0, object.i.high >>> 0).toNumber(); + if (object.s != null) + if (typeof object.s === "string") + $util.base64.decode(object.s, message.s = $util.newBuffer($util.base64.length(object.s)), 0); + else if (object.s.length) + message.s = object.s; + if (object.t != null) { + if (typeof object.t !== "object") + throw TypeError(".onnx.AttributeProto.t: object expected"); + message.t = $root.onnx.TensorProto.fromObject(object.t); + } + if (object.g != null) { + if (typeof object.g !== "object") + throw TypeError(".onnx.AttributeProto.g: object expected"); + message.g = $root.onnx.GraphProto.fromObject(object.g); + } + if (object.floats) { + if (!Array.isArray(object.floats)) + throw TypeError(".onnx.AttributeProto.floats: array expected"); + message.floats = []; + for (var i = 0; i < object.floats.length; ++i) + message.floats[i] = Number(object.floats[i]); + } + if (object.ints) { + if (!Array.isArray(object.ints)) + throw TypeError(".onnx.AttributeProto.ints: array expected"); + message.ints = []; + for (var i = 0; i < object.ints.length; ++i) + if ($util.Long) + (message.ints[i] = $util.Long.fromValue(object.ints[i])).unsigned = false; + else if (typeof object.ints[i] === "string") + message.ints[i] = parseInt(object.ints[i], 10); + else if (typeof object.ints[i] === "number") + message.ints[i] = object.ints[i]; + else if (typeof object.ints[i] === "object") + message.ints[i] = new $util.LongBits(object.ints[i].low >>> 0, object.ints[i].high >>> 0).toNumber(); + } + if (object.strings) { + if (!Array.isArray(object.strings)) + throw TypeError(".onnx.AttributeProto.strings: array expected"); + message.strings = []; + for (var i = 0; i < object.strings.length; ++i) + if (typeof object.strings[i] === "string") + $util.base64.decode(object.strings[i], message.strings[i] = $util.newBuffer($util.base64.length(object.strings[i])), 0); + else if (object.strings[i].length) + message.strings[i] = object.strings[i]; + } + if (object.tensors) { + if (!Array.isArray(object.tensors)) + throw TypeError(".onnx.AttributeProto.tensors: array expected"); + message.tensors = []; + for (var i = 0; i < object.tensors.length; ++i) { + if (typeof object.tensors[i] !== "object") + throw TypeError(".onnx.AttributeProto.tensors: object expected"); + message.tensors[i] = $root.onnx.TensorProto.fromObject(object.tensors[i]); + } + } + if (object.graphs) { + if (!Array.isArray(object.graphs)) + throw TypeError(".onnx.AttributeProto.graphs: array expected"); + message.graphs = []; + for (var i = 0; i < object.graphs.length; ++i) { + if (typeof object.graphs[i] !== "object") + throw TypeError(".onnx.AttributeProto.graphs: object expected"); + message.graphs[i] = $root.onnx.GraphProto.fromObject(object.graphs[i]); + } + } + return message; + }; + + /** + * Creates a plain object from an AttributeProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.AttributeProto + * @static + * @param {onnx.AttributeProto} message AttributeProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + AttributeProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.floats = []; + object.ints = []; + object.strings = []; + object.tensors = []; + object.graphs = []; + } + if (options.defaults) { + object.name = ""; + object.f = 0; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.i = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.i = options.longs === String ? "0" : 0; + if (options.bytes === String) + object.s = ""; + else { + object.s = []; + if (options.bytes !== Array) + object.s = $util.newBuffer(object.s); + } + object.t = null; + object.g = null; + object.docString = ""; + object.type = options.enums === String ? "UNDEFINED" : 0; + object.refAttrName = ""; + } + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + if (message.f != null && message.hasOwnProperty("f")) + object.f = options.json && !isFinite(message.f) ? String(message.f) : message.f; + if (message.i != null && message.hasOwnProperty("i")) + if (typeof message.i === "number") + object.i = options.longs === String ? String(message.i) : message.i; + else + object.i = options.longs === String ? $util.Long.prototype.toString.call(message.i) : options.longs === Number ? new $util.LongBits(message.i.low >>> 0, message.i.high >>> 0).toNumber() : message.i; + if (message.s != null && message.hasOwnProperty("s")) + object.s = options.bytes === String ? $util.base64.encode(message.s, 0, message.s.length) : options.bytes === Array ? Array.prototype.slice.call(message.s) : message.s; + if (message.t != null && message.hasOwnProperty("t")) + object.t = $root.onnx.TensorProto.toObject(message.t, options); + if (message.g != null && message.hasOwnProperty("g")) + object.g = $root.onnx.GraphProto.toObject(message.g, options); + if (message.floats && message.floats.length) { + object.floats = []; + for (var j = 0; j < message.floats.length; ++j) + object.floats[j] = options.json && !isFinite(message.floats[j]) ? String(message.floats[j]) : message.floats[j]; + } + if (message.ints && message.ints.length) { + object.ints = []; + for (var j = 0; j < message.ints.length; ++j) + if (typeof message.ints[j] === "number") + object.ints[j] = options.longs === String ? String(message.ints[j]) : message.ints[j]; + else + object.ints[j] = options.longs === String ? $util.Long.prototype.toString.call(message.ints[j]) : options.longs === Number ? new $util.LongBits(message.ints[j].low >>> 0, message.ints[j].high >>> 0).toNumber() : message.ints[j]; + } + if (message.strings && message.strings.length) { + object.strings = []; + for (var j = 0; j < message.strings.length; ++j) + object.strings[j] = options.bytes === String ? $util.base64.encode(message.strings[j], 0, message.strings[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.strings[j]) : message.strings[j]; + } + if (message.tensors && message.tensors.length) { + object.tensors = []; + for (var j = 0; j < message.tensors.length; ++j) + object.tensors[j] = $root.onnx.TensorProto.toObject(message.tensors[j], options); + } + if (message.graphs && message.graphs.length) { + object.graphs = []; + for (var j = 0; j < message.graphs.length; ++j) + object.graphs[j] = $root.onnx.GraphProto.toObject(message.graphs[j], options); + } + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + if (message.type != null && message.hasOwnProperty("type")) + object.type = options.enums === String ? $root.onnx.AttributeProto.AttributeType[message.type] : message.type; + if (message.refAttrName != null && message.hasOwnProperty("refAttrName")) + object.refAttrName = message.refAttrName; + return object; + }; + + /** + * Converts this AttributeProto to JSON. + * @function toJSON + * @memberof onnx.AttributeProto + * @instance + * @returns {Object.} JSON object + */ + AttributeProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * AttributeType enum. + * @name onnx.AttributeProto.AttributeType + * @enum {string} + * @property {number} UNDEFINED=0 UNDEFINED value + * @property {number} FLOAT=1 FLOAT value + * @property {number} INT=2 INT value + * @property {number} STRING=3 STRING value + * @property {number} TENSOR=4 TENSOR value + * @property {number} GRAPH=5 GRAPH value + * @property {number} FLOATS=6 FLOATS value + * @property {number} INTS=7 INTS value + * @property {number} STRINGS=8 STRINGS value + * @property {number} TENSORS=9 TENSORS value + * @property {number} GRAPHS=10 GRAPHS value + */ + AttributeProto.AttributeType = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "UNDEFINED"] = 0; + values[valuesById[1] = "FLOAT"] = 1; + values[valuesById[2] = "INT"] = 2; + values[valuesById[3] = "STRING"] = 3; + values[valuesById[4] = "TENSOR"] = 4; + values[valuesById[5] = "GRAPH"] = 5; + values[valuesById[6] = "FLOATS"] = 6; + values[valuesById[7] = "INTS"] = 7; + values[valuesById[8] = "STRINGS"] = 8; + values[valuesById[9] = "TENSORS"] = 9; + values[valuesById[10] = "GRAPHS"] = 10; + return values; + })(); + + return AttributeProto; + })(); + + onnx.ValueInfoProto = (function() { + + /** + * Properties of a ValueInfoProto. + * @memberof onnx + * @interface IValueInfoProto + * @property {string|null} [name] ValueInfoProto name + * @property {onnx.ITypeProto|null} [type] ValueInfoProto type + * @property {string|null} [docString] ValueInfoProto docString + */ + + /** + * Constructs a new ValueInfoProto. + * @memberof onnx + * @classdesc Represents a ValueInfoProto. + * @implements IValueInfoProto + * @constructor + * @param {onnx.IValueInfoProto=} [properties] Properties to set + */ + function ValueInfoProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ValueInfoProto name. + * @member {string} name + * @memberof onnx.ValueInfoProto + * @instance + */ + ValueInfoProto.prototype.name = ""; + + /** + * ValueInfoProto type. + * @member {onnx.ITypeProto|null|undefined} type + * @memberof onnx.ValueInfoProto + * @instance + */ + ValueInfoProto.prototype.type = null; + + /** + * ValueInfoProto docString. + * @member {string} docString + * @memberof onnx.ValueInfoProto + * @instance + */ + ValueInfoProto.prototype.docString = ""; + + /** + * Creates a new ValueInfoProto instance using the specified properties. + * @function create + * @memberof onnx.ValueInfoProto + * @static + * @param {onnx.IValueInfoProto=} [properties] Properties to set + * @returns {onnx.ValueInfoProto} ValueInfoProto instance + */ + ValueInfoProto.create = function create(properties) { + return new ValueInfoProto(properties); + }; + + /** + * Encodes the specified ValueInfoProto message. Does not implicitly {@link onnx.ValueInfoProto.verify|verify} messages. + * @function encode + * @memberof onnx.ValueInfoProto + * @static + * @param {onnx.IValueInfoProto} message ValueInfoProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ValueInfoProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.name != null && message.hasOwnProperty("name")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.name); + if (message.type != null && message.hasOwnProperty("type")) + $root.onnx.TypeProto.encode(message.type, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.docString); + return writer; + }; + + /** + * Encodes the specified ValueInfoProto message, length delimited. Does not implicitly {@link onnx.ValueInfoProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.ValueInfoProto + * @static + * @param {onnx.IValueInfoProto} message ValueInfoProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ValueInfoProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ValueInfoProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.ValueInfoProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.ValueInfoProto} ValueInfoProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ValueInfoProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.ValueInfoProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + case 2: + message.type = $root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + case 3: + message.docString = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ValueInfoProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.ValueInfoProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.ValueInfoProto} ValueInfoProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ValueInfoProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ValueInfoProto message. + * @function verify + * @memberof onnx.ValueInfoProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ValueInfoProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + if (message.type != null && message.hasOwnProperty("type")) { + var error = $root.onnx.TypeProto.verify(message.type); + if (error) + return "type." + error; + } + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + return null; + }; + + /** + * Creates a ValueInfoProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.ValueInfoProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.ValueInfoProto} ValueInfoProto + */ + ValueInfoProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.ValueInfoProto) + return object; + var message = new $root.onnx.ValueInfoProto(); + if (object.name != null) + message.name = String(object.name); + if (object.type != null) { + if (typeof object.type !== "object") + throw TypeError(".onnx.ValueInfoProto.type: object expected"); + message.type = $root.onnx.TypeProto.fromObject(object.type); + } + if (object.docString != null) + message.docString = String(object.docString); + return message; + }; + + /** + * Creates a plain object from a ValueInfoProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.ValueInfoProto + * @static + * @param {onnx.ValueInfoProto} message ValueInfoProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ValueInfoProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.name = ""; + object.type = null; + object.docString = ""; + } + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + if (message.type != null && message.hasOwnProperty("type")) + object.type = $root.onnx.TypeProto.toObject(message.type, options); + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + return object; + }; + + /** + * Converts this ValueInfoProto to JSON. + * @function toJSON + * @memberof onnx.ValueInfoProto + * @instance + * @returns {Object.} JSON object + */ + ValueInfoProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ValueInfoProto; + })(); + + onnx.NodeProto = (function() { + + /** + * Properties of a NodeProto. + * @memberof onnx + * @interface INodeProto + * @property {Array.|null} [input] NodeProto input + * @property {Array.|null} [output] NodeProto output + * @property {string|null} [name] NodeProto name + * @property {string|null} [opType] NodeProto opType + * @property {string|null} [domain] NodeProto domain + * @property {Array.|null} [attribute] NodeProto attribute + * @property {string|null} [docString] NodeProto docString + */ + + /** + * Constructs a new NodeProto. + * @memberof onnx + * @classdesc Represents a NodeProto. + * @implements INodeProto + * @constructor + * @param {onnx.INodeProto=} [properties] Properties to set + */ + function NodeProto(properties) { + this.input = []; + this.output = []; + this.attribute = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * NodeProto input. + * @member {Array.} input + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.input = $util.emptyArray; + + /** + * NodeProto output. + * @member {Array.} output + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.output = $util.emptyArray; + + /** + * NodeProto name. + * @member {string} name + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.name = ""; + + /** + * NodeProto opType. + * @member {string} opType + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.opType = ""; + + /** + * NodeProto domain. + * @member {string} domain + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.domain = ""; + + /** + * NodeProto attribute. + * @member {Array.} attribute + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.attribute = $util.emptyArray; + + /** + * NodeProto docString. + * @member {string} docString + * @memberof onnx.NodeProto + * @instance + */ + NodeProto.prototype.docString = ""; + + /** + * Creates a new NodeProto instance using the specified properties. + * @function create + * @memberof onnx.NodeProto + * @static + * @param {onnx.INodeProto=} [properties] Properties to set + * @returns {onnx.NodeProto} NodeProto instance + */ + NodeProto.create = function create(properties) { + return new NodeProto(properties); + }; + + /** + * Encodes the specified NodeProto message. Does not implicitly {@link onnx.NodeProto.verify|verify} messages. + * @function encode + * @memberof onnx.NodeProto + * @static + * @param {onnx.INodeProto} message NodeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + NodeProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.input != null && message.input.length) + for (var i = 0; i < message.input.length; ++i) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.input[i]); + if (message.output != null && message.output.length) + for (var i = 0; i < message.output.length; ++i) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.output[i]); + if (message.name != null && message.hasOwnProperty("name")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.name); + if (message.opType != null && message.hasOwnProperty("opType")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.opType); + if (message.attribute != null && message.attribute.length) + for (var i = 0; i < message.attribute.length; ++i) + $root.onnx.AttributeProto.encode(message.attribute[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 6, wireType 2 =*/50).string(message.docString); + if (message.domain != null && message.hasOwnProperty("domain")) + writer.uint32(/* id 7, wireType 2 =*/58).string(message.domain); + return writer; + }; + + /** + * Encodes the specified NodeProto message, length delimited. Does not implicitly {@link onnx.NodeProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.NodeProto + * @static + * @param {onnx.INodeProto} message NodeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + NodeProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a NodeProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.NodeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.NodeProto} NodeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + NodeProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.NodeProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.input && message.input.length)) + message.input = []; + message.input.push(reader.string()); + break; + case 2: + if (!(message.output && message.output.length)) + message.output = []; + message.output.push(reader.string()); + break; + case 3: + message.name = reader.string(); + break; + case 4: + message.opType = reader.string(); + break; + case 7: + message.domain = reader.string(); + break; + case 5: + if (!(message.attribute && message.attribute.length)) + message.attribute = []; + message.attribute.push($root.onnx.AttributeProto.decode(reader, reader.uint32())); + break; + case 6: + message.docString = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a NodeProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.NodeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.NodeProto} NodeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + NodeProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a NodeProto message. + * @function verify + * @memberof onnx.NodeProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + NodeProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.input != null && message.hasOwnProperty("input")) { + if (!Array.isArray(message.input)) + return "input: array expected"; + for (var i = 0; i < message.input.length; ++i) + if (!$util.isString(message.input[i])) + return "input: string[] expected"; + } + if (message.output != null && message.hasOwnProperty("output")) { + if (!Array.isArray(message.output)) + return "output: array expected"; + for (var i = 0; i < message.output.length; ++i) + if (!$util.isString(message.output[i])) + return "output: string[] expected"; + } + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + if (message.opType != null && message.hasOwnProperty("opType")) + if (!$util.isString(message.opType)) + return "opType: string expected"; + if (message.domain != null && message.hasOwnProperty("domain")) + if (!$util.isString(message.domain)) + return "domain: string expected"; + if (message.attribute != null && message.hasOwnProperty("attribute")) { + if (!Array.isArray(message.attribute)) + return "attribute: array expected"; + for (var i = 0; i < message.attribute.length; ++i) { + var error = $root.onnx.AttributeProto.verify(message.attribute[i]); + if (error) + return "attribute." + error; + } + } + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + return null; + }; + + /** + * Creates a NodeProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.NodeProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.NodeProto} NodeProto + */ + NodeProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.NodeProto) + return object; + var message = new $root.onnx.NodeProto(); + if (object.input) { + if (!Array.isArray(object.input)) + throw TypeError(".onnx.NodeProto.input: array expected"); + message.input = []; + for (var i = 0; i < object.input.length; ++i) + message.input[i] = String(object.input[i]); + } + if (object.output) { + if (!Array.isArray(object.output)) + throw TypeError(".onnx.NodeProto.output: array expected"); + message.output = []; + for (var i = 0; i < object.output.length; ++i) + message.output[i] = String(object.output[i]); + } + if (object.name != null) + message.name = String(object.name); + if (object.opType != null) + message.opType = String(object.opType); + if (object.domain != null) + message.domain = String(object.domain); + if (object.attribute) { + if (!Array.isArray(object.attribute)) + throw TypeError(".onnx.NodeProto.attribute: array expected"); + message.attribute = []; + for (var i = 0; i < object.attribute.length; ++i) { + if (typeof object.attribute[i] !== "object") + throw TypeError(".onnx.NodeProto.attribute: object expected"); + message.attribute[i] = $root.onnx.AttributeProto.fromObject(object.attribute[i]); + } + } + if (object.docString != null) + message.docString = String(object.docString); + return message; + }; + + /** + * Creates a plain object from a NodeProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.NodeProto + * @static + * @param {onnx.NodeProto} message NodeProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + NodeProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.input = []; + object.output = []; + object.attribute = []; + } + if (options.defaults) { + object.name = ""; + object.opType = ""; + object.docString = ""; + object.domain = ""; + } + if (message.input && message.input.length) { + object.input = []; + for (var j = 0; j < message.input.length; ++j) + object.input[j] = message.input[j]; + } + if (message.output && message.output.length) { + object.output = []; + for (var j = 0; j < message.output.length; ++j) + object.output[j] = message.output[j]; + } + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + if (message.opType != null && message.hasOwnProperty("opType")) + object.opType = message.opType; + if (message.attribute && message.attribute.length) { + object.attribute = []; + for (var j = 0; j < message.attribute.length; ++j) + object.attribute[j] = $root.onnx.AttributeProto.toObject(message.attribute[j], options); + } + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + if (message.domain != null && message.hasOwnProperty("domain")) + object.domain = message.domain; + return object; + }; + + /** + * Converts this NodeProto to JSON. + * @function toJSON + * @memberof onnx.NodeProto + * @instance + * @returns {Object.} JSON object + */ + NodeProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return NodeProto; + })(); + + onnx.ModelProto = (function() { + + /** + * Properties of a ModelProto. + * @memberof onnx + * @interface IModelProto + * @property {number|Long|null} [irVersion] ModelProto irVersion + * @property {Array.|null} [opsetImport] ModelProto opsetImport + * @property {string|null} [producerName] ModelProto producerName + * @property {string|null} [producerVersion] ModelProto producerVersion + * @property {string|null} [domain] ModelProto domain + * @property {number|Long|null} [modelVersion] ModelProto modelVersion + * @property {string|null} [docString] ModelProto docString + * @property {onnx.IGraphProto|null} [graph] ModelProto graph + * @property {Array.|null} [metadataProps] ModelProto metadataProps + */ + + /** + * Constructs a new ModelProto. + * @memberof onnx + * @classdesc Represents a ModelProto. + * @implements IModelProto + * @constructor + * @param {onnx.IModelProto=} [properties] Properties to set + */ + function ModelProto(properties) { + this.opsetImport = []; + this.metadataProps = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ModelProto irVersion. + * @member {number|Long} irVersion + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.irVersion = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * ModelProto opsetImport. + * @member {Array.} opsetImport + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.opsetImport = $util.emptyArray; + + /** + * ModelProto producerName. + * @member {string} producerName + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.producerName = ""; + + /** + * ModelProto producerVersion. + * @member {string} producerVersion + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.producerVersion = ""; + + /** + * ModelProto domain. + * @member {string} domain + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.domain = ""; + + /** + * ModelProto modelVersion. + * @member {number|Long} modelVersion + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.modelVersion = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * ModelProto docString. + * @member {string} docString + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.docString = ""; + + /** + * ModelProto graph. + * @member {onnx.IGraphProto|null|undefined} graph + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.graph = null; + + /** + * ModelProto metadataProps. + * @member {Array.} metadataProps + * @memberof onnx.ModelProto + * @instance + */ + ModelProto.prototype.metadataProps = $util.emptyArray; + + /** + * Creates a new ModelProto instance using the specified properties. + * @function create + * @memberof onnx.ModelProto + * @static + * @param {onnx.IModelProto=} [properties] Properties to set + * @returns {onnx.ModelProto} ModelProto instance + */ + ModelProto.create = function create(properties) { + return new ModelProto(properties); + }; + + /** + * Encodes the specified ModelProto message. Does not implicitly {@link onnx.ModelProto.verify|verify} messages. + * @function encode + * @memberof onnx.ModelProto + * @static + * @param {onnx.IModelProto} message ModelProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ModelProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.irVersion != null && message.hasOwnProperty("irVersion")) + writer.uint32(/* id 1, wireType 0 =*/8).int64(message.irVersion); + if (message.producerName != null && message.hasOwnProperty("producerName")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.producerName); + if (message.producerVersion != null && message.hasOwnProperty("producerVersion")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.producerVersion); + if (message.domain != null && message.hasOwnProperty("domain")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.domain); + if (message.modelVersion != null && message.hasOwnProperty("modelVersion")) + writer.uint32(/* id 5, wireType 0 =*/40).int64(message.modelVersion); + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 6, wireType 2 =*/50).string(message.docString); + if (message.graph != null && message.hasOwnProperty("graph")) + $root.onnx.GraphProto.encode(message.graph, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); + if (message.opsetImport != null && message.opsetImport.length) + for (var i = 0; i < message.opsetImport.length; ++i) + $root.onnx.OperatorSetIdProto.encode(message.opsetImport[i], writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); + if (message.metadataProps != null && message.metadataProps.length) + for (var i = 0; i < message.metadataProps.length; ++i) + $root.onnx.StringStringEntryProto.encode(message.metadataProps[i], writer.uint32(/* id 14, wireType 2 =*/114).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified ModelProto message, length delimited. Does not implicitly {@link onnx.ModelProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.ModelProto + * @static + * @param {onnx.IModelProto} message ModelProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ModelProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ModelProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.ModelProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.ModelProto} ModelProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ModelProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.ModelProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.irVersion = reader.int64(); + break; + case 8: + if (!(message.opsetImport && message.opsetImport.length)) + message.opsetImport = []; + message.opsetImport.push($root.onnx.OperatorSetIdProto.decode(reader, reader.uint32())); + break; + case 2: + message.producerName = reader.string(); + break; + case 3: + message.producerVersion = reader.string(); + break; + case 4: + message.domain = reader.string(); + break; + case 5: + message.modelVersion = reader.int64(); + break; + case 6: + message.docString = reader.string(); + break; + case 7: + message.graph = $root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 14: + if (!(message.metadataProps && message.metadataProps.length)) + message.metadataProps = []; + message.metadataProps.push($root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ModelProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.ModelProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.ModelProto} ModelProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ModelProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ModelProto message. + * @function verify + * @memberof onnx.ModelProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ModelProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.irVersion != null && message.hasOwnProperty("irVersion")) + if (!$util.isInteger(message.irVersion) && !(message.irVersion && $util.isInteger(message.irVersion.low) && $util.isInteger(message.irVersion.high))) + return "irVersion: integer|Long expected"; + if (message.opsetImport != null && message.hasOwnProperty("opsetImport")) { + if (!Array.isArray(message.opsetImport)) + return "opsetImport: array expected"; + for (var i = 0; i < message.opsetImport.length; ++i) { + var error = $root.onnx.OperatorSetIdProto.verify(message.opsetImport[i]); + if (error) + return "opsetImport." + error; + } + } + if (message.producerName != null && message.hasOwnProperty("producerName")) + if (!$util.isString(message.producerName)) + return "producerName: string expected"; + if (message.producerVersion != null && message.hasOwnProperty("producerVersion")) + if (!$util.isString(message.producerVersion)) + return "producerVersion: string expected"; + if (message.domain != null && message.hasOwnProperty("domain")) + if (!$util.isString(message.domain)) + return "domain: string expected"; + if (message.modelVersion != null && message.hasOwnProperty("modelVersion")) + if (!$util.isInteger(message.modelVersion) && !(message.modelVersion && $util.isInteger(message.modelVersion.low) && $util.isInteger(message.modelVersion.high))) + return "modelVersion: integer|Long expected"; + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + if (message.graph != null && message.hasOwnProperty("graph")) { + var error = $root.onnx.GraphProto.verify(message.graph); + if (error) + return "graph." + error; + } + if (message.metadataProps != null && message.hasOwnProperty("metadataProps")) { + if (!Array.isArray(message.metadataProps)) + return "metadataProps: array expected"; + for (var i = 0; i < message.metadataProps.length; ++i) { + var error = $root.onnx.StringStringEntryProto.verify(message.metadataProps[i]); + if (error) + return "metadataProps." + error; + } + } + return null; + }; + + /** + * Creates a ModelProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.ModelProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.ModelProto} ModelProto + */ + ModelProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.ModelProto) + return object; + var message = new $root.onnx.ModelProto(); + if (object.irVersion != null) + if ($util.Long) + (message.irVersion = $util.Long.fromValue(object.irVersion)).unsigned = false; + else if (typeof object.irVersion === "string") + message.irVersion = parseInt(object.irVersion, 10); + else if (typeof object.irVersion === "number") + message.irVersion = object.irVersion; + else if (typeof object.irVersion === "object") + message.irVersion = new $util.LongBits(object.irVersion.low >>> 0, object.irVersion.high >>> 0).toNumber(); + if (object.opsetImport) { + if (!Array.isArray(object.opsetImport)) + throw TypeError(".onnx.ModelProto.opsetImport: array expected"); + message.opsetImport = []; + for (var i = 0; i < object.opsetImport.length; ++i) { + if (typeof object.opsetImport[i] !== "object") + throw TypeError(".onnx.ModelProto.opsetImport: object expected"); + message.opsetImport[i] = $root.onnx.OperatorSetIdProto.fromObject(object.opsetImport[i]); + } + } + if (object.producerName != null) + message.producerName = String(object.producerName); + if (object.producerVersion != null) + message.producerVersion = String(object.producerVersion); + if (object.domain != null) + message.domain = String(object.domain); + if (object.modelVersion != null) + if ($util.Long) + (message.modelVersion = $util.Long.fromValue(object.modelVersion)).unsigned = false; + else if (typeof object.modelVersion === "string") + message.modelVersion = parseInt(object.modelVersion, 10); + else if (typeof object.modelVersion === "number") + message.modelVersion = object.modelVersion; + else if (typeof object.modelVersion === "object") + message.modelVersion = new $util.LongBits(object.modelVersion.low >>> 0, object.modelVersion.high >>> 0).toNumber(); + if (object.docString != null) + message.docString = String(object.docString); + if (object.graph != null) { + if (typeof object.graph !== "object") + throw TypeError(".onnx.ModelProto.graph: object expected"); + message.graph = $root.onnx.GraphProto.fromObject(object.graph); + } + if (object.metadataProps) { + if (!Array.isArray(object.metadataProps)) + throw TypeError(".onnx.ModelProto.metadataProps: array expected"); + message.metadataProps = []; + for (var i = 0; i < object.metadataProps.length; ++i) { + if (typeof object.metadataProps[i] !== "object") + throw TypeError(".onnx.ModelProto.metadataProps: object expected"); + message.metadataProps[i] = $root.onnx.StringStringEntryProto.fromObject(object.metadataProps[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a ModelProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.ModelProto + * @static + * @param {onnx.ModelProto} message ModelProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ModelProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.opsetImport = []; + object.metadataProps = []; + } + if (options.defaults) { + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.irVersion = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.irVersion = options.longs === String ? "0" : 0; + object.producerName = ""; + object.producerVersion = ""; + object.domain = ""; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.modelVersion = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.modelVersion = options.longs === String ? "0" : 0; + object.docString = ""; + object.graph = null; + } + if (message.irVersion != null && message.hasOwnProperty("irVersion")) + if (typeof message.irVersion === "number") + object.irVersion = options.longs === String ? String(message.irVersion) : message.irVersion; + else + object.irVersion = options.longs === String ? $util.Long.prototype.toString.call(message.irVersion) : options.longs === Number ? new $util.LongBits(message.irVersion.low >>> 0, message.irVersion.high >>> 0).toNumber() : message.irVersion; + if (message.producerName != null && message.hasOwnProperty("producerName")) + object.producerName = message.producerName; + if (message.producerVersion != null && message.hasOwnProperty("producerVersion")) + object.producerVersion = message.producerVersion; + if (message.domain != null && message.hasOwnProperty("domain")) + object.domain = message.domain; + if (message.modelVersion != null && message.hasOwnProperty("modelVersion")) + if (typeof message.modelVersion === "number") + object.modelVersion = options.longs === String ? String(message.modelVersion) : message.modelVersion; + else + object.modelVersion = options.longs === String ? $util.Long.prototype.toString.call(message.modelVersion) : options.longs === Number ? new $util.LongBits(message.modelVersion.low >>> 0, message.modelVersion.high >>> 0).toNumber() : message.modelVersion; + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + if (message.graph != null && message.hasOwnProperty("graph")) + object.graph = $root.onnx.GraphProto.toObject(message.graph, options); + if (message.opsetImport && message.opsetImport.length) { + object.opsetImport = []; + for (var j = 0; j < message.opsetImport.length; ++j) + object.opsetImport[j] = $root.onnx.OperatorSetIdProto.toObject(message.opsetImport[j], options); + } + if (message.metadataProps && message.metadataProps.length) { + object.metadataProps = []; + for (var j = 0; j < message.metadataProps.length; ++j) + object.metadataProps[j] = $root.onnx.StringStringEntryProto.toObject(message.metadataProps[j], options); + } + return object; + }; + + /** + * Converts this ModelProto to JSON. + * @function toJSON + * @memberof onnx.ModelProto + * @instance + * @returns {Object.} JSON object + */ + ModelProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ModelProto; + })(); + + onnx.StringStringEntryProto = (function() { + + /** + * Properties of a StringStringEntryProto. + * @memberof onnx + * @interface IStringStringEntryProto + * @property {string|null} [key] StringStringEntryProto key + * @property {string|null} [value] StringStringEntryProto value + */ + + /** + * Constructs a new StringStringEntryProto. + * @memberof onnx + * @classdesc Represents a StringStringEntryProto. + * @implements IStringStringEntryProto + * @constructor + * @param {onnx.IStringStringEntryProto=} [properties] Properties to set + */ + function StringStringEntryProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * StringStringEntryProto key. + * @member {string} key + * @memberof onnx.StringStringEntryProto + * @instance + */ + StringStringEntryProto.prototype.key = ""; + + /** + * StringStringEntryProto value. + * @member {string} value + * @memberof onnx.StringStringEntryProto + * @instance + */ + StringStringEntryProto.prototype.value = ""; + + /** + * Creates a new StringStringEntryProto instance using the specified properties. + * @function create + * @memberof onnx.StringStringEntryProto + * @static + * @param {onnx.IStringStringEntryProto=} [properties] Properties to set + * @returns {onnx.StringStringEntryProto} StringStringEntryProto instance + */ + StringStringEntryProto.create = function create(properties) { + return new StringStringEntryProto(properties); + }; + + /** + * Encodes the specified StringStringEntryProto message. Does not implicitly {@link onnx.StringStringEntryProto.verify|verify} messages. + * @function encode + * @memberof onnx.StringStringEntryProto + * @static + * @param {onnx.IStringStringEntryProto} message StringStringEntryProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + StringStringEntryProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.key != null && message.hasOwnProperty("key")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.key); + if (message.value != null && message.hasOwnProperty("value")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.value); + return writer; + }; + + /** + * Encodes the specified StringStringEntryProto message, length delimited. Does not implicitly {@link onnx.StringStringEntryProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.StringStringEntryProto + * @static + * @param {onnx.IStringStringEntryProto} message StringStringEntryProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + StringStringEntryProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a StringStringEntryProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.StringStringEntryProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.StringStringEntryProto} StringStringEntryProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + StringStringEntryProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.StringStringEntryProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.string(); + break; + case 2: + message.value = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a StringStringEntryProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.StringStringEntryProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.StringStringEntryProto} StringStringEntryProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + StringStringEntryProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a StringStringEntryProto message. + * @function verify + * @memberof onnx.StringStringEntryProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + StringStringEntryProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.key != null && message.hasOwnProperty("key")) + if (!$util.isString(message.key)) + return "key: string expected"; + if (message.value != null && message.hasOwnProperty("value")) + if (!$util.isString(message.value)) + return "value: string expected"; + return null; + }; + + /** + * Creates a StringStringEntryProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.StringStringEntryProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.StringStringEntryProto} StringStringEntryProto + */ + StringStringEntryProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.StringStringEntryProto) + return object; + var message = new $root.onnx.StringStringEntryProto(); + if (object.key != null) + message.key = String(object.key); + if (object.value != null) + message.value = String(object.value); + return message; + }; + + /** + * Creates a plain object from a StringStringEntryProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.StringStringEntryProto + * @static + * @param {onnx.StringStringEntryProto} message StringStringEntryProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + StringStringEntryProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.key = ""; + object.value = ""; + } + if (message.key != null && message.hasOwnProperty("key")) + object.key = message.key; + if (message.value != null && message.hasOwnProperty("value")) + object.value = message.value; + return object; + }; + + /** + * Converts this StringStringEntryProto to JSON. + * @function toJSON + * @memberof onnx.StringStringEntryProto + * @instance + * @returns {Object.} JSON object + */ + StringStringEntryProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return StringStringEntryProto; + })(); + + onnx.TensorAnnotation = (function() { + + /** + * Properties of a TensorAnnotation. + * @memberof onnx + * @interface ITensorAnnotation + * @property {string|null} [tensorName] TensorAnnotation tensorName + * @property {Array.|null} [quantParameterTensorNames] TensorAnnotation quantParameterTensorNames + */ + + /** + * Constructs a new TensorAnnotation. + * @memberof onnx + * @classdesc Represents a TensorAnnotation. + * @implements ITensorAnnotation + * @constructor + * @param {onnx.ITensorAnnotation=} [properties] Properties to set + */ + function TensorAnnotation(properties) { + this.quantParameterTensorNames = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TensorAnnotation tensorName. + * @member {string} tensorName + * @memberof onnx.TensorAnnotation + * @instance + */ + TensorAnnotation.prototype.tensorName = ""; + + /** + * TensorAnnotation quantParameterTensorNames. + * @member {Array.} quantParameterTensorNames + * @memberof onnx.TensorAnnotation + * @instance + */ + TensorAnnotation.prototype.quantParameterTensorNames = $util.emptyArray; + + /** + * Creates a new TensorAnnotation instance using the specified properties. + * @function create + * @memberof onnx.TensorAnnotation + * @static + * @param {onnx.ITensorAnnotation=} [properties] Properties to set + * @returns {onnx.TensorAnnotation} TensorAnnotation instance + */ + TensorAnnotation.create = function create(properties) { + return new TensorAnnotation(properties); + }; + + /** + * Encodes the specified TensorAnnotation message. Does not implicitly {@link onnx.TensorAnnotation.verify|verify} messages. + * @function encode + * @memberof onnx.TensorAnnotation + * @static + * @param {onnx.ITensorAnnotation} message TensorAnnotation message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorAnnotation.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.tensorName != null && message.hasOwnProperty("tensorName")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.tensorName); + if (message.quantParameterTensorNames != null && message.quantParameterTensorNames.length) + for (var i = 0; i < message.quantParameterTensorNames.length; ++i) + $root.onnx.StringStringEntryProto.encode(message.quantParameterTensorNames[i], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified TensorAnnotation message, length delimited. Does not implicitly {@link onnx.TensorAnnotation.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TensorAnnotation + * @static + * @param {onnx.ITensorAnnotation} message TensorAnnotation message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorAnnotation.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TensorAnnotation message from the specified reader or buffer. + * @function decode + * @memberof onnx.TensorAnnotation + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TensorAnnotation} TensorAnnotation + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorAnnotation.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TensorAnnotation(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.tensorName = reader.string(); + break; + case 2: + if (!(message.quantParameterTensorNames && message.quantParameterTensorNames.length)) + message.quantParameterTensorNames = []; + message.quantParameterTensorNames.push($root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TensorAnnotation message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TensorAnnotation + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TensorAnnotation} TensorAnnotation + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorAnnotation.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TensorAnnotation message. + * @function verify + * @memberof onnx.TensorAnnotation + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TensorAnnotation.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.tensorName != null && message.hasOwnProperty("tensorName")) + if (!$util.isString(message.tensorName)) + return "tensorName: string expected"; + if (message.quantParameterTensorNames != null && message.hasOwnProperty("quantParameterTensorNames")) { + if (!Array.isArray(message.quantParameterTensorNames)) + return "quantParameterTensorNames: array expected"; + for (var i = 0; i < message.quantParameterTensorNames.length; ++i) { + var error = $root.onnx.StringStringEntryProto.verify(message.quantParameterTensorNames[i]); + if (error) + return "quantParameterTensorNames." + error; + } + } + return null; + }; + + /** + * Creates a TensorAnnotation message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TensorAnnotation + * @static + * @param {Object.} object Plain object + * @returns {onnx.TensorAnnotation} TensorAnnotation + */ + TensorAnnotation.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TensorAnnotation) + return object; + var message = new $root.onnx.TensorAnnotation(); + if (object.tensorName != null) + message.tensorName = String(object.tensorName); + if (object.quantParameterTensorNames) { + if (!Array.isArray(object.quantParameterTensorNames)) + throw TypeError(".onnx.TensorAnnotation.quantParameterTensorNames: array expected"); + message.quantParameterTensorNames = []; + for (var i = 0; i < object.quantParameterTensorNames.length; ++i) { + if (typeof object.quantParameterTensorNames[i] !== "object") + throw TypeError(".onnx.TensorAnnotation.quantParameterTensorNames: object expected"); + message.quantParameterTensorNames[i] = $root.onnx.StringStringEntryProto.fromObject(object.quantParameterTensorNames[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a TensorAnnotation message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TensorAnnotation + * @static + * @param {onnx.TensorAnnotation} message TensorAnnotation + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TensorAnnotation.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.quantParameterTensorNames = []; + if (options.defaults) + object.tensorName = ""; + if (message.tensorName != null && message.hasOwnProperty("tensorName")) + object.tensorName = message.tensorName; + if (message.quantParameterTensorNames && message.quantParameterTensorNames.length) { + object.quantParameterTensorNames = []; + for (var j = 0; j < message.quantParameterTensorNames.length; ++j) + object.quantParameterTensorNames[j] = $root.onnx.StringStringEntryProto.toObject(message.quantParameterTensorNames[j], options); + } + return object; + }; + + /** + * Converts this TensorAnnotation to JSON. + * @function toJSON + * @memberof onnx.TensorAnnotation + * @instance + * @returns {Object.} JSON object + */ + TensorAnnotation.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return TensorAnnotation; + })(); + + onnx.GraphProto = (function() { + + /** + * Properties of a GraphProto. + * @memberof onnx + * @interface IGraphProto + * @property {Array.|null} [node] GraphProto node + * @property {string|null} [name] GraphProto name + * @property {Array.|null} [initializer] GraphProto initializer + * @property {string|null} [docString] GraphProto docString + * @property {Array.|null} [input] GraphProto input + * @property {Array.|null} [output] GraphProto output + * @property {Array.|null} [valueInfo] GraphProto valueInfo + * @property {Array.|null} [quantizationAnnotation] GraphProto quantizationAnnotation + */ + + /** + * Constructs a new GraphProto. + * @memberof onnx + * @classdesc Represents a GraphProto. + * @implements IGraphProto + * @constructor + * @param {onnx.IGraphProto=} [properties] Properties to set + */ + function GraphProto(properties) { + this.node = []; + this.initializer = []; + this.input = []; + this.output = []; + this.valueInfo = []; + this.quantizationAnnotation = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * GraphProto node. + * @member {Array.} node + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.node = $util.emptyArray; + + /** + * GraphProto name. + * @member {string} name + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.name = ""; + + /** + * GraphProto initializer. + * @member {Array.} initializer + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.initializer = $util.emptyArray; + + /** + * GraphProto docString. + * @member {string} docString + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.docString = ""; + + /** + * GraphProto input. + * @member {Array.} input + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.input = $util.emptyArray; + + /** + * GraphProto output. + * @member {Array.} output + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.output = $util.emptyArray; + + /** + * GraphProto valueInfo. + * @member {Array.} valueInfo + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.valueInfo = $util.emptyArray; + + /** + * GraphProto quantizationAnnotation. + * @member {Array.} quantizationAnnotation + * @memberof onnx.GraphProto + * @instance + */ + GraphProto.prototype.quantizationAnnotation = $util.emptyArray; + + /** + * Creates a new GraphProto instance using the specified properties. + * @function create + * @memberof onnx.GraphProto + * @static + * @param {onnx.IGraphProto=} [properties] Properties to set + * @returns {onnx.GraphProto} GraphProto instance + */ + GraphProto.create = function create(properties) { + return new GraphProto(properties); + }; + + /** + * Encodes the specified GraphProto message. Does not implicitly {@link onnx.GraphProto.verify|verify} messages. + * @function encode + * @memberof onnx.GraphProto + * @static + * @param {onnx.IGraphProto} message GraphProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + GraphProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.node != null && message.node.length) + for (var i = 0; i < message.node.length; ++i) + $root.onnx.NodeProto.encode(message.node[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.name != null && message.hasOwnProperty("name")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.name); + if (message.initializer != null && message.initializer.length) + for (var i = 0; i < message.initializer.length; ++i) + $root.onnx.TensorProto.encode(message.initializer[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 10, wireType 2 =*/82).string(message.docString); + if (message.input != null && message.input.length) + for (var i = 0; i < message.input.length; ++i) + $root.onnx.ValueInfoProto.encode(message.input[i], writer.uint32(/* id 11, wireType 2 =*/90).fork()).ldelim(); + if (message.output != null && message.output.length) + for (var i = 0; i < message.output.length; ++i) + $root.onnx.ValueInfoProto.encode(message.output[i], writer.uint32(/* id 12, wireType 2 =*/98).fork()).ldelim(); + if (message.valueInfo != null && message.valueInfo.length) + for (var i = 0; i < message.valueInfo.length; ++i) + $root.onnx.ValueInfoProto.encode(message.valueInfo[i], writer.uint32(/* id 13, wireType 2 =*/106).fork()).ldelim(); + if (message.quantizationAnnotation != null && message.quantizationAnnotation.length) + for (var i = 0; i < message.quantizationAnnotation.length; ++i) + $root.onnx.TensorAnnotation.encode(message.quantizationAnnotation[i], writer.uint32(/* id 14, wireType 2 =*/114).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified GraphProto message, length delimited. Does not implicitly {@link onnx.GraphProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.GraphProto + * @static + * @param {onnx.IGraphProto} message GraphProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + GraphProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a GraphProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.GraphProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.GraphProto} GraphProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + GraphProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.GraphProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.node && message.node.length)) + message.node = []; + message.node.push($root.onnx.NodeProto.decode(reader, reader.uint32())); + break; + case 2: + message.name = reader.string(); + break; + case 5: + if (!(message.initializer && message.initializer.length)) + message.initializer = []; + message.initializer.push($root.onnx.TensorProto.decode(reader, reader.uint32())); + break; + case 10: + message.docString = reader.string(); + break; + case 11: + if (!(message.input && message.input.length)) + message.input = []; + message.input.push($root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 12: + if (!(message.output && message.output.length)) + message.output = []; + message.output.push($root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 13: + if (!(message.valueInfo && message.valueInfo.length)) + message.valueInfo = []; + message.valueInfo.push($root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 14: + if (!(message.quantizationAnnotation && message.quantizationAnnotation.length)) + message.quantizationAnnotation = []; + message.quantizationAnnotation.push($root.onnx.TensorAnnotation.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a GraphProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.GraphProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.GraphProto} GraphProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + GraphProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a GraphProto message. + * @function verify + * @memberof onnx.GraphProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + GraphProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.node != null && message.hasOwnProperty("node")) { + if (!Array.isArray(message.node)) + return "node: array expected"; + for (var i = 0; i < message.node.length; ++i) { + var error = $root.onnx.NodeProto.verify(message.node[i]); + if (error) + return "node." + error; + } + } + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + if (message.initializer != null && message.hasOwnProperty("initializer")) { + if (!Array.isArray(message.initializer)) + return "initializer: array expected"; + for (var i = 0; i < message.initializer.length; ++i) { + var error = $root.onnx.TensorProto.verify(message.initializer[i]); + if (error) + return "initializer." + error; + } + } + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + if (message.input != null && message.hasOwnProperty("input")) { + if (!Array.isArray(message.input)) + return "input: array expected"; + for (var i = 0; i < message.input.length; ++i) { + var error = $root.onnx.ValueInfoProto.verify(message.input[i]); + if (error) + return "input." + error; + } + } + if (message.output != null && message.hasOwnProperty("output")) { + if (!Array.isArray(message.output)) + return "output: array expected"; + for (var i = 0; i < message.output.length; ++i) { + var error = $root.onnx.ValueInfoProto.verify(message.output[i]); + if (error) + return "output." + error; + } + } + if (message.valueInfo != null && message.hasOwnProperty("valueInfo")) { + if (!Array.isArray(message.valueInfo)) + return "valueInfo: array expected"; + for (var i = 0; i < message.valueInfo.length; ++i) { + var error = $root.onnx.ValueInfoProto.verify(message.valueInfo[i]); + if (error) + return "valueInfo." + error; + } + } + if (message.quantizationAnnotation != null && message.hasOwnProperty("quantizationAnnotation")) { + if (!Array.isArray(message.quantizationAnnotation)) + return "quantizationAnnotation: array expected"; + for (var i = 0; i < message.quantizationAnnotation.length; ++i) { + var error = $root.onnx.TensorAnnotation.verify(message.quantizationAnnotation[i]); + if (error) + return "quantizationAnnotation." + error; + } + } + return null; + }; + + /** + * Creates a GraphProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.GraphProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.GraphProto} GraphProto + */ + GraphProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.GraphProto) + return object; + var message = new $root.onnx.GraphProto(); + if (object.node) { + if (!Array.isArray(object.node)) + throw TypeError(".onnx.GraphProto.node: array expected"); + message.node = []; + for (var i = 0; i < object.node.length; ++i) { + if (typeof object.node[i] !== "object") + throw TypeError(".onnx.GraphProto.node: object expected"); + message.node[i] = $root.onnx.NodeProto.fromObject(object.node[i]); + } + } + if (object.name != null) + message.name = String(object.name); + if (object.initializer) { + if (!Array.isArray(object.initializer)) + throw TypeError(".onnx.GraphProto.initializer: array expected"); + message.initializer = []; + for (var i = 0; i < object.initializer.length; ++i) { + if (typeof object.initializer[i] !== "object") + throw TypeError(".onnx.GraphProto.initializer: object expected"); + message.initializer[i] = $root.onnx.TensorProto.fromObject(object.initializer[i]); + } + } + if (object.docString != null) + message.docString = String(object.docString); + if (object.input) { + if (!Array.isArray(object.input)) + throw TypeError(".onnx.GraphProto.input: array expected"); + message.input = []; + for (var i = 0; i < object.input.length; ++i) { + if (typeof object.input[i] !== "object") + throw TypeError(".onnx.GraphProto.input: object expected"); + message.input[i] = $root.onnx.ValueInfoProto.fromObject(object.input[i]); + } + } + if (object.output) { + if (!Array.isArray(object.output)) + throw TypeError(".onnx.GraphProto.output: array expected"); + message.output = []; + for (var i = 0; i < object.output.length; ++i) { + if (typeof object.output[i] !== "object") + throw TypeError(".onnx.GraphProto.output: object expected"); + message.output[i] = $root.onnx.ValueInfoProto.fromObject(object.output[i]); + } + } + if (object.valueInfo) { + if (!Array.isArray(object.valueInfo)) + throw TypeError(".onnx.GraphProto.valueInfo: array expected"); + message.valueInfo = []; + for (var i = 0; i < object.valueInfo.length; ++i) { + if (typeof object.valueInfo[i] !== "object") + throw TypeError(".onnx.GraphProto.valueInfo: object expected"); + message.valueInfo[i] = $root.onnx.ValueInfoProto.fromObject(object.valueInfo[i]); + } + } + if (object.quantizationAnnotation) { + if (!Array.isArray(object.quantizationAnnotation)) + throw TypeError(".onnx.GraphProto.quantizationAnnotation: array expected"); + message.quantizationAnnotation = []; + for (var i = 0; i < object.quantizationAnnotation.length; ++i) { + if (typeof object.quantizationAnnotation[i] !== "object") + throw TypeError(".onnx.GraphProto.quantizationAnnotation: object expected"); + message.quantizationAnnotation[i] = $root.onnx.TensorAnnotation.fromObject(object.quantizationAnnotation[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a GraphProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.GraphProto + * @static + * @param {onnx.GraphProto} message GraphProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + GraphProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.node = []; + object.initializer = []; + object.input = []; + object.output = []; + object.valueInfo = []; + object.quantizationAnnotation = []; + } + if (options.defaults) { + object.name = ""; + object.docString = ""; + } + if (message.node && message.node.length) { + object.node = []; + for (var j = 0; j < message.node.length; ++j) + object.node[j] = $root.onnx.NodeProto.toObject(message.node[j], options); + } + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + if (message.initializer && message.initializer.length) { + object.initializer = []; + for (var j = 0; j < message.initializer.length; ++j) + object.initializer[j] = $root.onnx.TensorProto.toObject(message.initializer[j], options); + } + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + if (message.input && message.input.length) { + object.input = []; + for (var j = 0; j < message.input.length; ++j) + object.input[j] = $root.onnx.ValueInfoProto.toObject(message.input[j], options); + } + if (message.output && message.output.length) { + object.output = []; + for (var j = 0; j < message.output.length; ++j) + object.output[j] = $root.onnx.ValueInfoProto.toObject(message.output[j], options); + } + if (message.valueInfo && message.valueInfo.length) { + object.valueInfo = []; + for (var j = 0; j < message.valueInfo.length; ++j) + object.valueInfo[j] = $root.onnx.ValueInfoProto.toObject(message.valueInfo[j], options); + } + if (message.quantizationAnnotation && message.quantizationAnnotation.length) { + object.quantizationAnnotation = []; + for (var j = 0; j < message.quantizationAnnotation.length; ++j) + object.quantizationAnnotation[j] = $root.onnx.TensorAnnotation.toObject(message.quantizationAnnotation[j], options); + } + return object; + }; + + /** + * Converts this GraphProto to JSON. + * @function toJSON + * @memberof onnx.GraphProto + * @instance + * @returns {Object.} JSON object + */ + GraphProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return GraphProto; + })(); + + onnx.TensorProto = (function() { + + /** + * Properties of a TensorProto. + * @memberof onnx + * @interface ITensorProto + * @property {Array.|null} [dims] TensorProto dims + * @property {number|null} [dataType] TensorProto dataType + * @property {onnx.TensorProto.ISegment|null} [segment] TensorProto segment + * @property {Array.|null} [floatData] TensorProto floatData + * @property {Array.|null} [int32Data] TensorProto int32Data + * @property {Array.|null} [stringData] TensorProto stringData + * @property {Array.|null} [int64Data] TensorProto int64Data + * @property {string|null} [name] TensorProto name + * @property {string|null} [docString] TensorProto docString + * @property {Uint8Array|null} [rawData] TensorProto rawData + * @property {Array.|null} [externalData] TensorProto externalData + * @property {onnx.TensorProto.DataLocation|null} [dataLocation] TensorProto dataLocation + * @property {Array.|null} [doubleData] TensorProto doubleData + * @property {Array.|null} [uint64Data] TensorProto uint64Data + */ + + /** + * Constructs a new TensorProto. + * @memberof onnx + * @classdesc Represents a TensorProto. + * @implements ITensorProto + * @constructor + * @param {onnx.ITensorProto=} [properties] Properties to set + */ + function TensorProto(properties) { + this.dims = []; + this.floatData = []; + this.int32Data = []; + this.stringData = []; + this.int64Data = []; + this.externalData = []; + this.doubleData = []; + this.uint64Data = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TensorProto dims. + * @member {Array.} dims + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.dims = $util.emptyArray; + + /** + * TensorProto dataType. + * @member {number} dataType + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.dataType = 0; + + /** + * TensorProto segment. + * @member {onnx.TensorProto.ISegment|null|undefined} segment + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.segment = null; + + /** + * TensorProto floatData. + * @member {Array.} floatData + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.floatData = $util.emptyArray; + + /** + * TensorProto int32Data. + * @member {Array.} int32Data + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.int32Data = $util.emptyArray; + + /** + * TensorProto stringData. + * @member {Array.} stringData + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.stringData = $util.emptyArray; + + /** + * TensorProto int64Data. + * @member {Array.} int64Data + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.int64Data = $util.emptyArray; + + /** + * TensorProto name. + * @member {string} name + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.name = ""; + + /** + * TensorProto docString. + * @member {string} docString + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.docString = ""; + + /** + * TensorProto rawData. + * @member {Uint8Array} rawData + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.rawData = $util.newBuffer([]); + + /** + * TensorProto externalData. + * @member {Array.} externalData + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.externalData = $util.emptyArray; + + /** + * TensorProto dataLocation. + * @member {onnx.TensorProto.DataLocation} dataLocation + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.dataLocation = 0; + + /** + * TensorProto doubleData. + * @member {Array.} doubleData + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.doubleData = $util.emptyArray; + + /** + * TensorProto uint64Data. + * @member {Array.} uint64Data + * @memberof onnx.TensorProto + * @instance + */ + TensorProto.prototype.uint64Data = $util.emptyArray; + + /** + * Creates a new TensorProto instance using the specified properties. + * @function create + * @memberof onnx.TensorProto + * @static + * @param {onnx.ITensorProto=} [properties] Properties to set + * @returns {onnx.TensorProto} TensorProto instance + */ + TensorProto.create = function create(properties) { + return new TensorProto(properties); + }; + + /** + * Encodes the specified TensorProto message. Does not implicitly {@link onnx.TensorProto.verify|verify} messages. + * @function encode + * @memberof onnx.TensorProto + * @static + * @param {onnx.ITensorProto} message TensorProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.dims != null && message.dims.length) { + writer.uint32(/* id 1, wireType 2 =*/10).fork(); + for (var i = 0; i < message.dims.length; ++i) + writer.int64(message.dims[i]); + writer.ldelim(); + } + if (message.dataType != null && message.hasOwnProperty("dataType")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.dataType); + if (message.segment != null && message.hasOwnProperty("segment")) + $root.onnx.TensorProto.Segment.encode(message.segment, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + if (message.floatData != null && message.floatData.length) { + writer.uint32(/* id 4, wireType 2 =*/34).fork(); + for (var i = 0; i < message.floatData.length; ++i) + writer.float(message.floatData[i]); + writer.ldelim(); + } + if (message.int32Data != null && message.int32Data.length) { + writer.uint32(/* id 5, wireType 2 =*/42).fork(); + for (var i = 0; i < message.int32Data.length; ++i) + writer.int32(message.int32Data[i]); + writer.ldelim(); + } + if (message.stringData != null && message.stringData.length) + for (var i = 0; i < message.stringData.length; ++i) + writer.uint32(/* id 6, wireType 2 =*/50).bytes(message.stringData[i]); + if (message.int64Data != null && message.int64Data.length) { + writer.uint32(/* id 7, wireType 2 =*/58).fork(); + for (var i = 0; i < message.int64Data.length; ++i) + writer.int64(message.int64Data[i]); + writer.ldelim(); + } + if (message.name != null && message.hasOwnProperty("name")) + writer.uint32(/* id 8, wireType 2 =*/66).string(message.name); + if (message.rawData != null && message.hasOwnProperty("rawData")) + writer.uint32(/* id 9, wireType 2 =*/74).bytes(message.rawData); + if (message.doubleData != null && message.doubleData.length) { + writer.uint32(/* id 10, wireType 2 =*/82).fork(); + for (var i = 0; i < message.doubleData.length; ++i) + writer.double(message.doubleData[i]); + writer.ldelim(); + } + if (message.uint64Data != null && message.uint64Data.length) { + writer.uint32(/* id 11, wireType 2 =*/90).fork(); + for (var i = 0; i < message.uint64Data.length; ++i) + writer.uint64(message.uint64Data[i]); + writer.ldelim(); + } + if (message.docString != null && message.hasOwnProperty("docString")) + writer.uint32(/* id 12, wireType 2 =*/98).string(message.docString); + if (message.externalData != null && message.externalData.length) + for (var i = 0; i < message.externalData.length; ++i) + $root.onnx.StringStringEntryProto.encode(message.externalData[i], writer.uint32(/* id 13, wireType 2 =*/106).fork()).ldelim(); + if (message.dataLocation != null && message.hasOwnProperty("dataLocation")) + writer.uint32(/* id 14, wireType 0 =*/112).int32(message.dataLocation); + return writer; + }; + + /** + * Encodes the specified TensorProto message, length delimited. Does not implicitly {@link onnx.TensorProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TensorProto + * @static + * @param {onnx.ITensorProto} message TensorProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TensorProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.TensorProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TensorProto} TensorProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TensorProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.dims && message.dims.length)) + message.dims = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.dims.push(reader.int64()); + } else + message.dims.push(reader.int64()); + break; + case 2: + message.dataType = reader.int32(); + break; + case 3: + message.segment = $root.onnx.TensorProto.Segment.decode(reader, reader.uint32()); + break; + case 4: + if (!(message.floatData && message.floatData.length)) + message.floatData = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.floatData.push(reader.float()); + } else + message.floatData.push(reader.float()); + break; + case 5: + if (!(message.int32Data && message.int32Data.length)) + message.int32Data = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.int32Data.push(reader.int32()); + } else + message.int32Data.push(reader.int32()); + break; + case 6: + if (!(message.stringData && message.stringData.length)) + message.stringData = []; + message.stringData.push(reader.bytes()); + break; + case 7: + if (!(message.int64Data && message.int64Data.length)) + message.int64Data = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.int64Data.push(reader.int64()); + } else + message.int64Data.push(reader.int64()); + break; + case 8: + message.name = reader.string(); + break; + case 12: + message.docString = reader.string(); + break; + case 9: + message.rawData = reader.bytes(); + break; + case 13: + if (!(message.externalData && message.externalData.length)) + message.externalData = []; + message.externalData.push($root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + case 14: + message.dataLocation = reader.int32(); + break; + case 10: + if (!(message.doubleData && message.doubleData.length)) + message.doubleData = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.doubleData.push(reader.double()); + } else + message.doubleData.push(reader.double()); + break; + case 11: + if (!(message.uint64Data && message.uint64Data.length)) + message.uint64Data = []; + if ((tag & 7) === 2) { + var end2 = reader.uint32() + reader.pos; + while (reader.pos < end2) + message.uint64Data.push(reader.uint64()); + } else + message.uint64Data.push(reader.uint64()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TensorProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TensorProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TensorProto} TensorProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TensorProto message. + * @function verify + * @memberof onnx.TensorProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TensorProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.dims != null && message.hasOwnProperty("dims")) { + if (!Array.isArray(message.dims)) + return "dims: array expected"; + for (var i = 0; i < message.dims.length; ++i) + if (!$util.isInteger(message.dims[i]) && !(message.dims[i] && $util.isInteger(message.dims[i].low) && $util.isInteger(message.dims[i].high))) + return "dims: integer|Long[] expected"; + } + if (message.dataType != null && message.hasOwnProperty("dataType")) + if (!$util.isInteger(message.dataType)) + return "dataType: integer expected"; + if (message.segment != null && message.hasOwnProperty("segment")) { + var error = $root.onnx.TensorProto.Segment.verify(message.segment); + if (error) + return "segment." + error; + } + if (message.floatData != null && message.hasOwnProperty("floatData")) { + if (!Array.isArray(message.floatData)) + return "floatData: array expected"; + for (var i = 0; i < message.floatData.length; ++i) + if (typeof message.floatData[i] !== "number") + return "floatData: number[] expected"; + } + if (message.int32Data != null && message.hasOwnProperty("int32Data")) { + if (!Array.isArray(message.int32Data)) + return "int32Data: array expected"; + for (var i = 0; i < message.int32Data.length; ++i) + if (!$util.isInteger(message.int32Data[i])) + return "int32Data: integer[] expected"; + } + if (message.stringData != null && message.hasOwnProperty("stringData")) { + if (!Array.isArray(message.stringData)) + return "stringData: array expected"; + for (var i = 0; i < message.stringData.length; ++i) + if (!(message.stringData[i] && typeof message.stringData[i].length === "number" || $util.isString(message.stringData[i]))) + return "stringData: buffer[] expected"; + } + if (message.int64Data != null && message.hasOwnProperty("int64Data")) { + if (!Array.isArray(message.int64Data)) + return "int64Data: array expected"; + for (var i = 0; i < message.int64Data.length; ++i) + if (!$util.isInteger(message.int64Data[i]) && !(message.int64Data[i] && $util.isInteger(message.int64Data[i].low) && $util.isInteger(message.int64Data[i].high))) + return "int64Data: integer|Long[] expected"; + } + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + if (message.docString != null && message.hasOwnProperty("docString")) + if (!$util.isString(message.docString)) + return "docString: string expected"; + if (message.rawData != null && message.hasOwnProperty("rawData")) + if (!(message.rawData && typeof message.rawData.length === "number" || $util.isString(message.rawData))) + return "rawData: buffer expected"; + if (message.externalData != null && message.hasOwnProperty("externalData")) { + if (!Array.isArray(message.externalData)) + return "externalData: array expected"; + for (var i = 0; i < message.externalData.length; ++i) { + var error = $root.onnx.StringStringEntryProto.verify(message.externalData[i]); + if (error) + return "externalData." + error; + } + } + if (message.dataLocation != null && message.hasOwnProperty("dataLocation")) + switch (message.dataLocation) { + default: + return "dataLocation: enum value expected"; + case 0: + case 1: + break; + } + if (message.doubleData != null && message.hasOwnProperty("doubleData")) { + if (!Array.isArray(message.doubleData)) + return "doubleData: array expected"; + for (var i = 0; i < message.doubleData.length; ++i) + if (typeof message.doubleData[i] !== "number") + return "doubleData: number[] expected"; + } + if (message.uint64Data != null && message.hasOwnProperty("uint64Data")) { + if (!Array.isArray(message.uint64Data)) + return "uint64Data: array expected"; + for (var i = 0; i < message.uint64Data.length; ++i) + if (!$util.isInteger(message.uint64Data[i]) && !(message.uint64Data[i] && $util.isInteger(message.uint64Data[i].low) && $util.isInteger(message.uint64Data[i].high))) + return "uint64Data: integer|Long[] expected"; + } + return null; + }; + + /** + * Creates a TensorProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TensorProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.TensorProto} TensorProto + */ + TensorProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TensorProto) + return object; + var message = new $root.onnx.TensorProto(); + if (object.dims) { + if (!Array.isArray(object.dims)) + throw TypeError(".onnx.TensorProto.dims: array expected"); + message.dims = []; + for (var i = 0; i < object.dims.length; ++i) + if ($util.Long) + (message.dims[i] = $util.Long.fromValue(object.dims[i])).unsigned = false; + else if (typeof object.dims[i] === "string") + message.dims[i] = parseInt(object.dims[i], 10); + else if (typeof object.dims[i] === "number") + message.dims[i] = object.dims[i]; + else if (typeof object.dims[i] === "object") + message.dims[i] = new $util.LongBits(object.dims[i].low >>> 0, object.dims[i].high >>> 0).toNumber(); + } + if (object.dataType != null) + message.dataType = object.dataType | 0; + if (object.segment != null) { + if (typeof object.segment !== "object") + throw TypeError(".onnx.TensorProto.segment: object expected"); + message.segment = $root.onnx.TensorProto.Segment.fromObject(object.segment); + } + if (object.floatData) { + if (!Array.isArray(object.floatData)) + throw TypeError(".onnx.TensorProto.floatData: array expected"); + message.floatData = []; + for (var i = 0; i < object.floatData.length; ++i) + message.floatData[i] = Number(object.floatData[i]); + } + if (object.int32Data) { + if (!Array.isArray(object.int32Data)) + throw TypeError(".onnx.TensorProto.int32Data: array expected"); + message.int32Data = []; + for (var i = 0; i < object.int32Data.length; ++i) + message.int32Data[i] = object.int32Data[i] | 0; + } + if (object.stringData) { + if (!Array.isArray(object.stringData)) + throw TypeError(".onnx.TensorProto.stringData: array expected"); + message.stringData = []; + for (var i = 0; i < object.stringData.length; ++i) + if (typeof object.stringData[i] === "string") + $util.base64.decode(object.stringData[i], message.stringData[i] = $util.newBuffer($util.base64.length(object.stringData[i])), 0); + else if (object.stringData[i].length) + message.stringData[i] = object.stringData[i]; + } + if (object.int64Data) { + if (!Array.isArray(object.int64Data)) + throw TypeError(".onnx.TensorProto.int64Data: array expected"); + message.int64Data = []; + for (var i = 0; i < object.int64Data.length; ++i) + if ($util.Long) + (message.int64Data[i] = $util.Long.fromValue(object.int64Data[i])).unsigned = false; + else if (typeof object.int64Data[i] === "string") + message.int64Data[i] = parseInt(object.int64Data[i], 10); + else if (typeof object.int64Data[i] === "number") + message.int64Data[i] = object.int64Data[i]; + else if (typeof object.int64Data[i] === "object") + message.int64Data[i] = new $util.LongBits(object.int64Data[i].low >>> 0, object.int64Data[i].high >>> 0).toNumber(); + } + if (object.name != null) + message.name = String(object.name); + if (object.docString != null) + message.docString = String(object.docString); + if (object.rawData != null) + if (typeof object.rawData === "string") + $util.base64.decode(object.rawData, message.rawData = $util.newBuffer($util.base64.length(object.rawData)), 0); + else if (object.rawData.length) + message.rawData = object.rawData; + if (object.externalData) { + if (!Array.isArray(object.externalData)) + throw TypeError(".onnx.TensorProto.externalData: array expected"); + message.externalData = []; + for (var i = 0; i < object.externalData.length; ++i) { + if (typeof object.externalData[i] !== "object") + throw TypeError(".onnx.TensorProto.externalData: object expected"); + message.externalData[i] = $root.onnx.StringStringEntryProto.fromObject(object.externalData[i]); + } + } + switch (object.dataLocation) { + case "DEFAULT": + case 0: + message.dataLocation = 0; + break; + case "EXTERNAL": + case 1: + message.dataLocation = 1; + break; + } + if (object.doubleData) { + if (!Array.isArray(object.doubleData)) + throw TypeError(".onnx.TensorProto.doubleData: array expected"); + message.doubleData = []; + for (var i = 0; i < object.doubleData.length; ++i) + message.doubleData[i] = Number(object.doubleData[i]); + } + if (object.uint64Data) { + if (!Array.isArray(object.uint64Data)) + throw TypeError(".onnx.TensorProto.uint64Data: array expected"); + message.uint64Data = []; + for (var i = 0; i < object.uint64Data.length; ++i) + if ($util.Long) + (message.uint64Data[i] = $util.Long.fromValue(object.uint64Data[i])).unsigned = true; + else if (typeof object.uint64Data[i] === "string") + message.uint64Data[i] = parseInt(object.uint64Data[i], 10); + else if (typeof object.uint64Data[i] === "number") + message.uint64Data[i] = object.uint64Data[i]; + else if (typeof object.uint64Data[i] === "object") + message.uint64Data[i] = new $util.LongBits(object.uint64Data[i].low >>> 0, object.uint64Data[i].high >>> 0).toNumber(true); + } + return message; + }; + + /** + * Creates a plain object from a TensorProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TensorProto + * @static + * @param {onnx.TensorProto} message TensorProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TensorProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.dims = []; + object.floatData = []; + object.int32Data = []; + object.stringData = []; + object.int64Data = []; + object.doubleData = []; + object.uint64Data = []; + object.externalData = []; + } + if (options.defaults) { + object.dataType = 0; + object.segment = null; + object.name = ""; + if (options.bytes === String) + object.rawData = ""; + else { + object.rawData = []; + if (options.bytes !== Array) + object.rawData = $util.newBuffer(object.rawData); + } + object.docString = ""; + object.dataLocation = options.enums === String ? "DEFAULT" : 0; + } + if (message.dims && message.dims.length) { + object.dims = []; + for (var j = 0; j < message.dims.length; ++j) + if (typeof message.dims[j] === "number") + object.dims[j] = options.longs === String ? String(message.dims[j]) : message.dims[j]; + else + object.dims[j] = options.longs === String ? $util.Long.prototype.toString.call(message.dims[j]) : options.longs === Number ? new $util.LongBits(message.dims[j].low >>> 0, message.dims[j].high >>> 0).toNumber() : message.dims[j]; + } + if (message.dataType != null && message.hasOwnProperty("dataType")) + object.dataType = message.dataType; + if (message.segment != null && message.hasOwnProperty("segment")) + object.segment = $root.onnx.TensorProto.Segment.toObject(message.segment, options); + if (message.floatData && message.floatData.length) { + object.floatData = []; + for (var j = 0; j < message.floatData.length; ++j) + object.floatData[j] = options.json && !isFinite(message.floatData[j]) ? String(message.floatData[j]) : message.floatData[j]; + } + if (message.int32Data && message.int32Data.length) { + object.int32Data = []; + for (var j = 0; j < message.int32Data.length; ++j) + object.int32Data[j] = message.int32Data[j]; + } + if (message.stringData && message.stringData.length) { + object.stringData = []; + for (var j = 0; j < message.stringData.length; ++j) + object.stringData[j] = options.bytes === String ? $util.base64.encode(message.stringData[j], 0, message.stringData[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.stringData[j]) : message.stringData[j]; + } + if (message.int64Data && message.int64Data.length) { + object.int64Data = []; + for (var j = 0; j < message.int64Data.length; ++j) + if (typeof message.int64Data[j] === "number") + object.int64Data[j] = options.longs === String ? String(message.int64Data[j]) : message.int64Data[j]; + else + object.int64Data[j] = options.longs === String ? $util.Long.prototype.toString.call(message.int64Data[j]) : options.longs === Number ? new $util.LongBits(message.int64Data[j].low >>> 0, message.int64Data[j].high >>> 0).toNumber() : message.int64Data[j]; + } + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + if (message.rawData != null && message.hasOwnProperty("rawData")) + object.rawData = options.bytes === String ? $util.base64.encode(message.rawData, 0, message.rawData.length) : options.bytes === Array ? Array.prototype.slice.call(message.rawData) : message.rawData; + if (message.doubleData && message.doubleData.length) { + object.doubleData = []; + for (var j = 0; j < message.doubleData.length; ++j) + object.doubleData[j] = options.json && !isFinite(message.doubleData[j]) ? String(message.doubleData[j]) : message.doubleData[j]; + } + if (message.uint64Data && message.uint64Data.length) { + object.uint64Data = []; + for (var j = 0; j < message.uint64Data.length; ++j) + if (typeof message.uint64Data[j] === "number") + object.uint64Data[j] = options.longs === String ? String(message.uint64Data[j]) : message.uint64Data[j]; + else + object.uint64Data[j] = options.longs === String ? $util.Long.prototype.toString.call(message.uint64Data[j]) : options.longs === Number ? new $util.LongBits(message.uint64Data[j].low >>> 0, message.uint64Data[j].high >>> 0).toNumber(true) : message.uint64Data[j]; + } + if (message.docString != null && message.hasOwnProperty("docString")) + object.docString = message.docString; + if (message.externalData && message.externalData.length) { + object.externalData = []; + for (var j = 0; j < message.externalData.length; ++j) + object.externalData[j] = $root.onnx.StringStringEntryProto.toObject(message.externalData[j], options); + } + if (message.dataLocation != null && message.hasOwnProperty("dataLocation")) + object.dataLocation = options.enums === String ? $root.onnx.TensorProto.DataLocation[message.dataLocation] : message.dataLocation; + return object; + }; + + /** + * Converts this TensorProto to JSON. + * @function toJSON + * @memberof onnx.TensorProto + * @instance + * @returns {Object.} JSON object + */ + TensorProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * DataType enum. + * @name onnx.TensorProto.DataType + * @enum {string} + * @property {number} UNDEFINED=0 UNDEFINED value + * @property {number} FLOAT=1 FLOAT value + * @property {number} UINT8=2 UINT8 value + * @property {number} INT8=3 INT8 value + * @property {number} UINT16=4 UINT16 value + * @property {number} INT16=5 INT16 value + * @property {number} INT32=6 INT32 value + * @property {number} INT64=7 INT64 value + * @property {number} STRING=8 STRING value + * @property {number} BOOL=9 BOOL value + * @property {number} FLOAT16=10 FLOAT16 value + * @property {number} DOUBLE=11 DOUBLE value + * @property {number} UINT32=12 UINT32 value + * @property {number} UINT64=13 UINT64 value + * @property {number} COMPLEX64=14 COMPLEX64 value + * @property {number} COMPLEX128=15 COMPLEX128 value + * @property {number} BFLOAT16=16 BFLOAT16 value + */ + TensorProto.DataType = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "UNDEFINED"] = 0; + values[valuesById[1] = "FLOAT"] = 1; + values[valuesById[2] = "UINT8"] = 2; + values[valuesById[3] = "INT8"] = 3; + values[valuesById[4] = "UINT16"] = 4; + values[valuesById[5] = "INT16"] = 5; + values[valuesById[6] = "INT32"] = 6; + values[valuesById[7] = "INT64"] = 7; + values[valuesById[8] = "STRING"] = 8; + values[valuesById[9] = "BOOL"] = 9; + values[valuesById[10] = "FLOAT16"] = 10; + values[valuesById[11] = "DOUBLE"] = 11; + values[valuesById[12] = "UINT32"] = 12; + values[valuesById[13] = "UINT64"] = 13; + values[valuesById[14] = "COMPLEX64"] = 14; + values[valuesById[15] = "COMPLEX128"] = 15; + values[valuesById[16] = "BFLOAT16"] = 16; + return values; + })(); + + TensorProto.Segment = (function() { + + /** + * Properties of a Segment. + * @memberof onnx.TensorProto + * @interface ISegment + * @property {number|Long|null} [begin] Segment begin + * @property {number|Long|null} [end] Segment end + */ + + /** + * Constructs a new Segment. + * @memberof onnx.TensorProto + * @classdesc Represents a Segment. + * @implements ISegment + * @constructor + * @param {onnx.TensorProto.ISegment=} [properties] Properties to set + */ + function Segment(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Segment begin. + * @member {number|Long} begin + * @memberof onnx.TensorProto.Segment + * @instance + */ + Segment.prototype.begin = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * Segment end. + * @member {number|Long} end + * @memberof onnx.TensorProto.Segment + * @instance + */ + Segment.prototype.end = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * Creates a new Segment instance using the specified properties. + * @function create + * @memberof onnx.TensorProto.Segment + * @static + * @param {onnx.TensorProto.ISegment=} [properties] Properties to set + * @returns {onnx.TensorProto.Segment} Segment instance + */ + Segment.create = function create(properties) { + return new Segment(properties); + }; + + /** + * Encodes the specified Segment message. Does not implicitly {@link onnx.TensorProto.Segment.verify|verify} messages. + * @function encode + * @memberof onnx.TensorProto.Segment + * @static + * @param {onnx.TensorProto.ISegment} message Segment message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Segment.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.begin != null && message.hasOwnProperty("begin")) + writer.uint32(/* id 1, wireType 0 =*/8).int64(message.begin); + if (message.end != null && message.hasOwnProperty("end")) + writer.uint32(/* id 2, wireType 0 =*/16).int64(message.end); + return writer; + }; + + /** + * Encodes the specified Segment message, length delimited. Does not implicitly {@link onnx.TensorProto.Segment.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TensorProto.Segment + * @static + * @param {onnx.TensorProto.ISegment} message Segment message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Segment.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Segment message from the specified reader or buffer. + * @function decode + * @memberof onnx.TensorProto.Segment + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TensorProto.Segment} Segment + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Segment.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TensorProto.Segment(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.begin = reader.int64(); + break; + case 2: + message.end = reader.int64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Segment message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TensorProto.Segment + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TensorProto.Segment} Segment + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Segment.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Segment message. + * @function verify + * @memberof onnx.TensorProto.Segment + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Segment.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.begin != null && message.hasOwnProperty("begin")) + if (!$util.isInteger(message.begin) && !(message.begin && $util.isInteger(message.begin.low) && $util.isInteger(message.begin.high))) + return "begin: integer|Long expected"; + if (message.end != null && message.hasOwnProperty("end")) + if (!$util.isInteger(message.end) && !(message.end && $util.isInteger(message.end.low) && $util.isInteger(message.end.high))) + return "end: integer|Long expected"; + return null; + }; + + /** + * Creates a Segment message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TensorProto.Segment + * @static + * @param {Object.} object Plain object + * @returns {onnx.TensorProto.Segment} Segment + */ + Segment.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TensorProto.Segment) + return object; + var message = new $root.onnx.TensorProto.Segment(); + if (object.begin != null) + if ($util.Long) + (message.begin = $util.Long.fromValue(object.begin)).unsigned = false; + else if (typeof object.begin === "string") + message.begin = parseInt(object.begin, 10); + else if (typeof object.begin === "number") + message.begin = object.begin; + else if (typeof object.begin === "object") + message.begin = new $util.LongBits(object.begin.low >>> 0, object.begin.high >>> 0).toNumber(); + if (object.end != null) + if ($util.Long) + (message.end = $util.Long.fromValue(object.end)).unsigned = false; + else if (typeof object.end === "string") + message.end = parseInt(object.end, 10); + else if (typeof object.end === "number") + message.end = object.end; + else if (typeof object.end === "object") + message.end = new $util.LongBits(object.end.low >>> 0, object.end.high >>> 0).toNumber(); + return message; + }; + + /** + * Creates a plain object from a Segment message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TensorProto.Segment + * @static + * @param {onnx.TensorProto.Segment} message Segment + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Segment.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.begin = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.begin = options.longs === String ? "0" : 0; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.end = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.end = options.longs === String ? "0" : 0; + } + if (message.begin != null && message.hasOwnProperty("begin")) + if (typeof message.begin === "number") + object.begin = options.longs === String ? String(message.begin) : message.begin; + else + object.begin = options.longs === String ? $util.Long.prototype.toString.call(message.begin) : options.longs === Number ? new $util.LongBits(message.begin.low >>> 0, message.begin.high >>> 0).toNumber() : message.begin; + if (message.end != null && message.hasOwnProperty("end")) + if (typeof message.end === "number") + object.end = options.longs === String ? String(message.end) : message.end; + else + object.end = options.longs === String ? $util.Long.prototype.toString.call(message.end) : options.longs === Number ? new $util.LongBits(message.end.low >>> 0, message.end.high >>> 0).toNumber() : message.end; + return object; + }; + + /** + * Converts this Segment to JSON. + * @function toJSON + * @memberof onnx.TensorProto.Segment + * @instance + * @returns {Object.} JSON object + */ + Segment.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Segment; + })(); + + /** + * DataLocation enum. + * @name onnx.TensorProto.DataLocation + * @enum {string} + * @property {number} DEFAULT=0 DEFAULT value + * @property {number} EXTERNAL=1 EXTERNAL value + */ + TensorProto.DataLocation = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "DEFAULT"] = 0; + values[valuesById[1] = "EXTERNAL"] = 1; + return values; + })(); + + return TensorProto; + })(); + + onnx.TensorShapeProto = (function() { + + /** + * Properties of a TensorShapeProto. + * @memberof onnx + * @interface ITensorShapeProto + * @property {Array.|null} [dim] TensorShapeProto dim + */ + + /** + * Constructs a new TensorShapeProto. + * @memberof onnx + * @classdesc Represents a TensorShapeProto. + * @implements ITensorShapeProto + * @constructor + * @param {onnx.ITensorShapeProto=} [properties] Properties to set + */ + function TensorShapeProto(properties) { + this.dim = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TensorShapeProto dim. + * @member {Array.} dim + * @memberof onnx.TensorShapeProto + * @instance + */ + TensorShapeProto.prototype.dim = $util.emptyArray; + + /** + * Creates a new TensorShapeProto instance using the specified properties. + * @function create + * @memberof onnx.TensorShapeProto + * @static + * @param {onnx.ITensorShapeProto=} [properties] Properties to set + * @returns {onnx.TensorShapeProto} TensorShapeProto instance + */ + TensorShapeProto.create = function create(properties) { + return new TensorShapeProto(properties); + }; + + /** + * Encodes the specified TensorShapeProto message. Does not implicitly {@link onnx.TensorShapeProto.verify|verify} messages. + * @function encode + * @memberof onnx.TensorShapeProto + * @static + * @param {onnx.ITensorShapeProto} message TensorShapeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorShapeProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.dim != null && message.dim.length) + for (var i = 0; i < message.dim.length; ++i) + $root.onnx.TensorShapeProto.Dimension.encode(message.dim[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified TensorShapeProto message, length delimited. Does not implicitly {@link onnx.TensorShapeProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TensorShapeProto + * @static + * @param {onnx.ITensorShapeProto} message TensorShapeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TensorShapeProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TensorShapeProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.TensorShapeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TensorShapeProto} TensorShapeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorShapeProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TensorShapeProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.dim && message.dim.length)) + message.dim = []; + message.dim.push($root.onnx.TensorShapeProto.Dimension.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TensorShapeProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TensorShapeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TensorShapeProto} TensorShapeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TensorShapeProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TensorShapeProto message. + * @function verify + * @memberof onnx.TensorShapeProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TensorShapeProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.dim != null && message.hasOwnProperty("dim")) { + if (!Array.isArray(message.dim)) + return "dim: array expected"; + for (var i = 0; i < message.dim.length; ++i) { + var error = $root.onnx.TensorShapeProto.Dimension.verify(message.dim[i]); + if (error) + return "dim." + error; + } + } + return null; + }; + + /** + * Creates a TensorShapeProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TensorShapeProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.TensorShapeProto} TensorShapeProto + */ + TensorShapeProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TensorShapeProto) + return object; + var message = new $root.onnx.TensorShapeProto(); + if (object.dim) { + if (!Array.isArray(object.dim)) + throw TypeError(".onnx.TensorShapeProto.dim: array expected"); + message.dim = []; + for (var i = 0; i < object.dim.length; ++i) { + if (typeof object.dim[i] !== "object") + throw TypeError(".onnx.TensorShapeProto.dim: object expected"); + message.dim[i] = $root.onnx.TensorShapeProto.Dimension.fromObject(object.dim[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a TensorShapeProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TensorShapeProto + * @static + * @param {onnx.TensorShapeProto} message TensorShapeProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TensorShapeProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.dim = []; + if (message.dim && message.dim.length) { + object.dim = []; + for (var j = 0; j < message.dim.length; ++j) + object.dim[j] = $root.onnx.TensorShapeProto.Dimension.toObject(message.dim[j], options); + } + return object; + }; + + /** + * Converts this TensorShapeProto to JSON. + * @function toJSON + * @memberof onnx.TensorShapeProto + * @instance + * @returns {Object.} JSON object + */ + TensorShapeProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + TensorShapeProto.Dimension = (function() { + + /** + * Properties of a Dimension. + * @memberof onnx.TensorShapeProto + * @interface IDimension + * @property {number|Long|null} [dimValue] Dimension dimValue + * @property {string|null} [dimParam] Dimension dimParam + * @property {string|null} [denotation] Dimension denotation + */ + + /** + * Constructs a new Dimension. + * @memberof onnx.TensorShapeProto + * @classdesc Represents a Dimension. + * @implements IDimension + * @constructor + * @param {onnx.TensorShapeProto.IDimension=} [properties] Properties to set + */ + function Dimension(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Dimension dimValue. + * @member {number|Long} dimValue + * @memberof onnx.TensorShapeProto.Dimension + * @instance + */ + Dimension.prototype.dimValue = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * Dimension dimParam. + * @member {string} dimParam + * @memberof onnx.TensorShapeProto.Dimension + * @instance + */ + Dimension.prototype.dimParam = ""; + + /** + * Dimension denotation. + * @member {string} denotation + * @memberof onnx.TensorShapeProto.Dimension + * @instance + */ + Dimension.prototype.denotation = ""; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * Dimension value. + * @member {"dimValue"|"dimParam"|undefined} value + * @memberof onnx.TensorShapeProto.Dimension + * @instance + */ + Object.defineProperty(Dimension.prototype, "value", { + get: $util.oneOfGetter($oneOfFields = ["dimValue", "dimParam"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a new Dimension instance using the specified properties. + * @function create + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {onnx.TensorShapeProto.IDimension=} [properties] Properties to set + * @returns {onnx.TensorShapeProto.Dimension} Dimension instance + */ + Dimension.create = function create(properties) { + return new Dimension(properties); + }; + + /** + * Encodes the specified Dimension message. Does not implicitly {@link onnx.TensorShapeProto.Dimension.verify|verify} messages. + * @function encode + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {onnx.TensorShapeProto.IDimension} message Dimension message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Dimension.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.dimValue != null && message.hasOwnProperty("dimValue")) + writer.uint32(/* id 1, wireType 0 =*/8).int64(message.dimValue); + if (message.dimParam != null && message.hasOwnProperty("dimParam")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.dimParam); + if (message.denotation != null && message.hasOwnProperty("denotation")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.denotation); + return writer; + }; + + /** + * Encodes the specified Dimension message, length delimited. Does not implicitly {@link onnx.TensorShapeProto.Dimension.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {onnx.TensorShapeProto.IDimension} message Dimension message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Dimension.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Dimension message from the specified reader or buffer. + * @function decode + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TensorShapeProto.Dimension} Dimension + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Dimension.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TensorShapeProto.Dimension(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dimValue = reader.int64(); + break; + case 2: + message.dimParam = reader.string(); + break; + case 3: + message.denotation = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Dimension message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TensorShapeProto.Dimension} Dimension + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Dimension.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Dimension message. + * @function verify + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Dimension.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + var properties = {}; + if (message.dimValue != null && message.hasOwnProperty("dimValue")) { + properties.value = 1; + if (!$util.isInteger(message.dimValue) && !(message.dimValue && $util.isInteger(message.dimValue.low) && $util.isInteger(message.dimValue.high))) + return "dimValue: integer|Long expected"; + } + if (message.dimParam != null && message.hasOwnProperty("dimParam")) { + if (properties.value === 1) + return "value: multiple values"; + properties.value = 1; + if (!$util.isString(message.dimParam)) + return "dimParam: string expected"; + } + if (message.denotation != null && message.hasOwnProperty("denotation")) + if (!$util.isString(message.denotation)) + return "denotation: string expected"; + return null; + }; + + /** + * Creates a Dimension message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {Object.} object Plain object + * @returns {onnx.TensorShapeProto.Dimension} Dimension + */ + Dimension.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TensorShapeProto.Dimension) + return object; + var message = new $root.onnx.TensorShapeProto.Dimension(); + if (object.dimValue != null) + if ($util.Long) + (message.dimValue = $util.Long.fromValue(object.dimValue)).unsigned = false; + else if (typeof object.dimValue === "string") + message.dimValue = parseInt(object.dimValue, 10); + else if (typeof object.dimValue === "number") + message.dimValue = object.dimValue; + else if (typeof object.dimValue === "object") + message.dimValue = new $util.LongBits(object.dimValue.low >>> 0, object.dimValue.high >>> 0).toNumber(); + if (object.dimParam != null) + message.dimParam = String(object.dimParam); + if (object.denotation != null) + message.denotation = String(object.denotation); + return message; + }; + + /** + * Creates a plain object from a Dimension message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TensorShapeProto.Dimension + * @static + * @param {onnx.TensorShapeProto.Dimension} message Dimension + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Dimension.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.denotation = ""; + if (message.dimValue != null && message.hasOwnProperty("dimValue")) { + if (typeof message.dimValue === "number") + object.dimValue = options.longs === String ? String(message.dimValue) : message.dimValue; + else + object.dimValue = options.longs === String ? $util.Long.prototype.toString.call(message.dimValue) : options.longs === Number ? new $util.LongBits(message.dimValue.low >>> 0, message.dimValue.high >>> 0).toNumber() : message.dimValue; + if (options.oneofs) + object.value = "dimValue"; + } + if (message.dimParam != null && message.hasOwnProperty("dimParam")) { + object.dimParam = message.dimParam; + if (options.oneofs) + object.value = "dimParam"; + } + if (message.denotation != null && message.hasOwnProperty("denotation")) + object.denotation = message.denotation; + return object; + }; + + /** + * Converts this Dimension to JSON. + * @function toJSON + * @memberof onnx.TensorShapeProto.Dimension + * @instance + * @returns {Object.} JSON object + */ + Dimension.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Dimension; + })(); + + return TensorShapeProto; + })(); + + onnx.TypeProto = (function() { + + /** + * Properties of a TypeProto. + * @memberof onnx + * @interface ITypeProto + * @property {onnx.TypeProto.ITensor|null} [tensorType] TypeProto tensorType + * @property {string|null} [denotation] TypeProto denotation + */ + + /** + * Constructs a new TypeProto. + * @memberof onnx + * @classdesc Represents a TypeProto. + * @implements ITypeProto + * @constructor + * @param {onnx.ITypeProto=} [properties] Properties to set + */ + function TypeProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TypeProto tensorType. + * @member {onnx.TypeProto.ITensor|null|undefined} tensorType + * @memberof onnx.TypeProto + * @instance + */ + TypeProto.prototype.tensorType = null; + + /** + * TypeProto denotation. + * @member {string} denotation + * @memberof onnx.TypeProto + * @instance + */ + TypeProto.prototype.denotation = ""; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * TypeProto value. + * @member {"tensorType"|undefined} value + * @memberof onnx.TypeProto + * @instance + */ + Object.defineProperty(TypeProto.prototype, "value", { + get: $util.oneOfGetter($oneOfFields = ["tensorType"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a new TypeProto instance using the specified properties. + * @function create + * @memberof onnx.TypeProto + * @static + * @param {onnx.ITypeProto=} [properties] Properties to set + * @returns {onnx.TypeProto} TypeProto instance + */ + TypeProto.create = function create(properties) { + return new TypeProto(properties); + }; + + /** + * Encodes the specified TypeProto message. Does not implicitly {@link onnx.TypeProto.verify|verify} messages. + * @function encode + * @memberof onnx.TypeProto + * @static + * @param {onnx.ITypeProto} message TypeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.tensorType != null && message.hasOwnProperty("tensorType")) + $root.onnx.TypeProto.Tensor.encode(message.tensorType, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.denotation != null && message.hasOwnProperty("denotation")) + writer.uint32(/* id 6, wireType 2 =*/50).string(message.denotation); + return writer; + }; + + /** + * Encodes the specified TypeProto message, length delimited. Does not implicitly {@link onnx.TypeProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TypeProto + * @static + * @param {onnx.ITypeProto} message TypeProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TypeProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.TypeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TypeProto} TypeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TypeProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.tensorType = $root.onnx.TypeProto.Tensor.decode(reader, reader.uint32()); + break; + case 6: + message.denotation = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TypeProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TypeProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TypeProto} TypeProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TypeProto message. + * @function verify + * @memberof onnx.TypeProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TypeProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + var properties = {}; + if (message.tensorType != null && message.hasOwnProperty("tensorType")) { + properties.value = 1; + { + var error = $root.onnx.TypeProto.Tensor.verify(message.tensorType); + if (error) + return "tensorType." + error; + } + } + if (message.denotation != null && message.hasOwnProperty("denotation")) + if (!$util.isString(message.denotation)) + return "denotation: string expected"; + return null; + }; + + /** + * Creates a TypeProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TypeProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.TypeProto} TypeProto + */ + TypeProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TypeProto) + return object; + var message = new $root.onnx.TypeProto(); + if (object.tensorType != null) { + if (typeof object.tensorType !== "object") + throw TypeError(".onnx.TypeProto.tensorType: object expected"); + message.tensorType = $root.onnx.TypeProto.Tensor.fromObject(object.tensorType); + } + if (object.denotation != null) + message.denotation = String(object.denotation); + return message; + }; + + /** + * Creates a plain object from a TypeProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TypeProto + * @static + * @param {onnx.TypeProto} message TypeProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TypeProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.denotation = ""; + if (message.tensorType != null && message.hasOwnProperty("tensorType")) { + object.tensorType = $root.onnx.TypeProto.Tensor.toObject(message.tensorType, options); + if (options.oneofs) + object.value = "tensorType"; + } + if (message.denotation != null && message.hasOwnProperty("denotation")) + object.denotation = message.denotation; + return object; + }; + + /** + * Converts this TypeProto to JSON. + * @function toJSON + * @memberof onnx.TypeProto + * @instance + * @returns {Object.} JSON object + */ + TypeProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + TypeProto.Tensor = (function() { + + /** + * Properties of a Tensor. + * @memberof onnx.TypeProto + * @interface ITensor + * @property {number|null} [elemType] Tensor elemType + * @property {onnx.ITensorShapeProto|null} [shape] Tensor shape + */ + + /** + * Constructs a new Tensor. + * @memberof onnx.TypeProto + * @classdesc Represents a Tensor. + * @implements ITensor + * @constructor + * @param {onnx.TypeProto.ITensor=} [properties] Properties to set + */ + function Tensor(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Tensor elemType. + * @member {number} elemType + * @memberof onnx.TypeProto.Tensor + * @instance + */ + Tensor.prototype.elemType = 0; + + /** + * Tensor shape. + * @member {onnx.ITensorShapeProto|null|undefined} shape + * @memberof onnx.TypeProto.Tensor + * @instance + */ + Tensor.prototype.shape = null; + + /** + * Creates a new Tensor instance using the specified properties. + * @function create + * @memberof onnx.TypeProto.Tensor + * @static + * @param {onnx.TypeProto.ITensor=} [properties] Properties to set + * @returns {onnx.TypeProto.Tensor} Tensor instance + */ + Tensor.create = function create(properties) { + return new Tensor(properties); + }; + + /** + * Encodes the specified Tensor message. Does not implicitly {@link onnx.TypeProto.Tensor.verify|verify} messages. + * @function encode + * @memberof onnx.TypeProto.Tensor + * @static + * @param {onnx.TypeProto.ITensor} message Tensor message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Tensor.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.elemType != null && message.hasOwnProperty("elemType")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.elemType); + if (message.shape != null && message.hasOwnProperty("shape")) + $root.onnx.TensorShapeProto.encode(message.shape, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified Tensor message, length delimited. Does not implicitly {@link onnx.TypeProto.Tensor.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.TypeProto.Tensor + * @static + * @param {onnx.TypeProto.ITensor} message Tensor message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Tensor.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Tensor message from the specified reader or buffer. + * @function decode + * @memberof onnx.TypeProto.Tensor + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.TypeProto.Tensor} Tensor + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Tensor.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.TypeProto.Tensor(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.elemType = reader.int32(); + break; + case 2: + message.shape = $root.onnx.TensorShapeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Tensor message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.TypeProto.Tensor + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.TypeProto.Tensor} Tensor + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Tensor.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Tensor message. + * @function verify + * @memberof onnx.TypeProto.Tensor + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Tensor.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.elemType != null && message.hasOwnProperty("elemType")) + if (!$util.isInteger(message.elemType)) + return "elemType: integer expected"; + if (message.shape != null && message.hasOwnProperty("shape")) { + var error = $root.onnx.TensorShapeProto.verify(message.shape); + if (error) + return "shape." + error; + } + return null; + }; + + /** + * Creates a Tensor message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.TypeProto.Tensor + * @static + * @param {Object.} object Plain object + * @returns {onnx.TypeProto.Tensor} Tensor + */ + Tensor.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.TypeProto.Tensor) + return object; + var message = new $root.onnx.TypeProto.Tensor(); + if (object.elemType != null) + message.elemType = object.elemType | 0; + if (object.shape != null) { + if (typeof object.shape !== "object") + throw TypeError(".onnx.TypeProto.Tensor.shape: object expected"); + message.shape = $root.onnx.TensorShapeProto.fromObject(object.shape); + } + return message; + }; + + /** + * Creates a plain object from a Tensor message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.TypeProto.Tensor + * @static + * @param {onnx.TypeProto.Tensor} message Tensor + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Tensor.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.elemType = 0; + object.shape = null; + } + if (message.elemType != null && message.hasOwnProperty("elemType")) + object.elemType = message.elemType; + if (message.shape != null && message.hasOwnProperty("shape")) + object.shape = $root.onnx.TensorShapeProto.toObject(message.shape, options); + return object; + }; + + /** + * Converts this Tensor to JSON. + * @function toJSON + * @memberof onnx.TypeProto.Tensor + * @instance + * @returns {Object.} JSON object + */ + Tensor.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Tensor; + })(); + + return TypeProto; + })(); + + onnx.OperatorSetIdProto = (function() { + + /** + * Properties of an OperatorSetIdProto. + * @memberof onnx + * @interface IOperatorSetIdProto + * @property {string|null} [domain] OperatorSetIdProto domain + * @property {number|Long|null} [version] OperatorSetIdProto version + */ + + /** + * Constructs a new OperatorSetIdProto. + * @memberof onnx + * @classdesc Represents an OperatorSetIdProto. + * @implements IOperatorSetIdProto + * @constructor + * @param {onnx.IOperatorSetIdProto=} [properties] Properties to set + */ + function OperatorSetIdProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * OperatorSetIdProto domain. + * @member {string} domain + * @memberof onnx.OperatorSetIdProto + * @instance + */ + OperatorSetIdProto.prototype.domain = ""; + + /** + * OperatorSetIdProto version. + * @member {number|Long} version + * @memberof onnx.OperatorSetIdProto + * @instance + */ + OperatorSetIdProto.prototype.version = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * Creates a new OperatorSetIdProto instance using the specified properties. + * @function create + * @memberof onnx.OperatorSetIdProto + * @static + * @param {onnx.IOperatorSetIdProto=} [properties] Properties to set + * @returns {onnx.OperatorSetIdProto} OperatorSetIdProto instance + */ + OperatorSetIdProto.create = function create(properties) { + return new OperatorSetIdProto(properties); + }; + + /** + * Encodes the specified OperatorSetIdProto message. Does not implicitly {@link onnx.OperatorSetIdProto.verify|verify} messages. + * @function encode + * @memberof onnx.OperatorSetIdProto + * @static + * @param {onnx.IOperatorSetIdProto} message OperatorSetIdProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + OperatorSetIdProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.domain != null && message.hasOwnProperty("domain")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.domain); + if (message.version != null && message.hasOwnProperty("version")) + writer.uint32(/* id 2, wireType 0 =*/16).int64(message.version); + return writer; + }; + + /** + * Encodes the specified OperatorSetIdProto message, length delimited. Does not implicitly {@link onnx.OperatorSetIdProto.verify|verify} messages. + * @function encodeDelimited + * @memberof onnx.OperatorSetIdProto + * @static + * @param {onnx.IOperatorSetIdProto} message OperatorSetIdProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + OperatorSetIdProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an OperatorSetIdProto message from the specified reader or buffer. + * @function decode + * @memberof onnx.OperatorSetIdProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {onnx.OperatorSetIdProto} OperatorSetIdProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + OperatorSetIdProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.onnx.OperatorSetIdProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.domain = reader.string(); + break; + case 2: + message.version = reader.int64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an OperatorSetIdProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof onnx.OperatorSetIdProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {onnx.OperatorSetIdProto} OperatorSetIdProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + OperatorSetIdProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an OperatorSetIdProto message. + * @function verify + * @memberof onnx.OperatorSetIdProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + OperatorSetIdProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.domain != null && message.hasOwnProperty("domain")) + if (!$util.isString(message.domain)) + return "domain: string expected"; + if (message.version != null && message.hasOwnProperty("version")) + if (!$util.isInteger(message.version) && !(message.version && $util.isInteger(message.version.low) && $util.isInteger(message.version.high))) + return "version: integer|Long expected"; + return null; + }; + + /** + * Creates an OperatorSetIdProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof onnx.OperatorSetIdProto + * @static + * @param {Object.} object Plain object + * @returns {onnx.OperatorSetIdProto} OperatorSetIdProto + */ + OperatorSetIdProto.fromObject = function fromObject(object) { + if (object instanceof $root.onnx.OperatorSetIdProto) + return object; + var message = new $root.onnx.OperatorSetIdProto(); + if (object.domain != null) + message.domain = String(object.domain); + if (object.version != null) + if ($util.Long) + (message.version = $util.Long.fromValue(object.version)).unsigned = false; + else if (typeof object.version === "string") + message.version = parseInt(object.version, 10); + else if (typeof object.version === "number") + message.version = object.version; + else if (typeof object.version === "object") + message.version = new $util.LongBits(object.version.low >>> 0, object.version.high >>> 0).toNumber(); + return message; + }; + + /** + * Creates a plain object from an OperatorSetIdProto message. Also converts values to other types if specified. + * @function toObject + * @memberof onnx.OperatorSetIdProto + * @static + * @param {onnx.OperatorSetIdProto} message OperatorSetIdProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + OperatorSetIdProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.domain = ""; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.version = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.version = options.longs === String ? "0" : 0; + } + if (message.domain != null && message.hasOwnProperty("domain")) + object.domain = message.domain; + if (message.version != null && message.hasOwnProperty("version")) + if (typeof message.version === "number") + object.version = options.longs === String ? String(message.version) : message.version; + else + object.version = options.longs === String ? $util.Long.prototype.toString.call(message.version) : options.longs === Number ? new $util.LongBits(message.version.low >>> 0, message.version.high >>> 0).toNumber() : message.version; + return object; + }; + + /** + * Converts this OperatorSetIdProto to JSON. + * @function toJSON + * @memberof onnx.OperatorSetIdProto + * @instance + * @returns {Object.} JSON object + */ + OperatorSetIdProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return OperatorSetIdProto; + })(); + + return onnx; +})(); + +module.exports = $root; + + +/***/ }), + +/***/ "./node_modules/protobufjs/minimal.js": +/*!********************************************!*\ + !*** ./node_modules/protobufjs/minimal.js ***! + \********************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; +// minimal library entry point. + + +module.exports = __webpack_require__(/*! ./src/index-minimal */ "./node_modules/protobufjs/src/index-minimal.js"); + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/index-minimal.js": +/*!******************************************************!*\ + !*** ./node_modules/protobufjs/src/index-minimal.js ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +var protobuf = exports; + +/** + * Build type, one of `"full"`, `"light"` or `"minimal"`. + * @name build + * @type {string} + * @const + */ +protobuf.build = "minimal"; + +// Serialization +protobuf.Writer = __webpack_require__(/*! ./writer */ "./node_modules/protobufjs/src/writer.js"); +protobuf.BufferWriter = __webpack_require__(/*! ./writer_buffer */ "./node_modules/protobufjs/src/writer_buffer.js"); +protobuf.Reader = __webpack_require__(/*! ./reader */ "./node_modules/protobufjs/src/reader.js"); +protobuf.BufferReader = __webpack_require__(/*! ./reader_buffer */ "./node_modules/protobufjs/src/reader_buffer.js"); + +// Utility +protobuf.util = __webpack_require__(/*! ./util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); +protobuf.rpc = __webpack_require__(/*! ./rpc */ "./node_modules/protobufjs/src/rpc.js"); +protobuf.roots = __webpack_require__(/*! ./roots */ "./node_modules/protobufjs/src/roots.js"); +protobuf.configure = configure; + +/* istanbul ignore next */ +/** + * Reconfigures the library according to the environment. + * @returns {undefined} + */ +function configure() { + protobuf.util._configure(); + protobuf.Writer._configure(protobuf.BufferWriter); + protobuf.Reader._configure(protobuf.BufferReader); +} + +// Set up buffer utility according to the environment +configure(); + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/reader.js": +/*!***********************************************!*\ + !*** ./node_modules/protobufjs/src/reader.js ***! + \***********************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = Reader; + +var util = __webpack_require__(/*! ./util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +var BufferReader; // cyclic + +var LongBits = util.LongBits, + utf8 = util.utf8; + +/* istanbul ignore next */ +function indexOutOfRange(reader, writeLength) { + return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len); +} + +/** + * Constructs a new reader instance using the specified buffer. + * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`. + * @constructor + * @param {Uint8Array} buffer Buffer to read from + */ +function Reader(buffer) { + + /** + * Read buffer. + * @type {Uint8Array} + */ + this.buf = buffer; + + /** + * Read buffer position. + * @type {number} + */ + this.pos = 0; + + /** + * Read buffer length. + * @type {number} + */ + this.len = buffer.length; +} + +var create_array = typeof Uint8Array !== "undefined" + ? function create_typed_array(buffer) { + if (buffer instanceof Uint8Array || Array.isArray(buffer)) + return new Reader(buffer); + throw Error("illegal buffer"); + } + /* istanbul ignore next */ + : function create_array(buffer) { + if (Array.isArray(buffer)) + return new Reader(buffer); + throw Error("illegal buffer"); + }; + +var create = function create() { + return util.Buffer + ? function create_buffer_setup(buffer) { + return (Reader.create = function create_buffer(buffer) { + return util.Buffer.isBuffer(buffer) + ? new BufferReader(buffer) + /* istanbul ignore next */ + : create_array(buffer); + })(buffer); + } + /* istanbul ignore next */ + : create_array; +}; + +/** + * Creates a new reader using the specified buffer. + * @function + * @param {Uint8Array|Buffer} buffer Buffer to read from + * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader} + * @throws {Error} If `buffer` is not a valid buffer + */ +Reader.create = create(); + +Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice; + +/** + * Reads a varint as an unsigned 32 bit value. + * @function + * @returns {number} Value read + */ +Reader.prototype.uint32 = (function read_uint32_setup() { + var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!) + return function read_uint32() { + value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value; + value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value; + value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value; + value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value; + value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value; + + /* istanbul ignore if */ + if ((this.pos += 5) > this.len) { + this.pos = this.len; + throw indexOutOfRange(this, 10); + } + return value; + }; +})(); + +/** + * Reads a varint as a signed 32 bit value. + * @returns {number} Value read + */ +Reader.prototype.int32 = function read_int32() { + return this.uint32() | 0; +}; + +/** + * Reads a zig-zag encoded varint as a signed 32 bit value. + * @returns {number} Value read + */ +Reader.prototype.sint32 = function read_sint32() { + var value = this.uint32(); + return value >>> 1 ^ -(value & 1) | 0; +}; + +/* eslint-disable no-invalid-this */ + +function readLongVarint() { + // tends to deopt with local vars for octet etc. + var bits = new LongBits(0, 0); + var i = 0; + if (this.len - this.pos > 4) { // fast route (lo) + for (; i < 4; ++i) { + // 1st..4th + bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; + if (this.buf[this.pos++] < 128) + return bits; + } + // 5th + bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0; + bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0; + if (this.buf[this.pos++] < 128) + return bits; + i = 0; + } else { + for (; i < 3; ++i) { + /* istanbul ignore if */ + if (this.pos >= this.len) + throw indexOutOfRange(this); + // 1st..3th + bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; + if (this.buf[this.pos++] < 128) + return bits; + } + // 4th + bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0; + return bits; + } + if (this.len - this.pos > 4) { // fast route (hi) + for (; i < 5; ++i) { + // 6th..10th + bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; + if (this.buf[this.pos++] < 128) + return bits; + } + } else { + for (; i < 5; ++i) { + /* istanbul ignore if */ + if (this.pos >= this.len) + throw indexOutOfRange(this); + // 6th..10th + bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; + if (this.buf[this.pos++] < 128) + return bits; + } + } + /* istanbul ignore next */ + throw Error("invalid varint encoding"); +} + +/* eslint-enable no-invalid-this */ + +/** + * Reads a varint as a signed 64 bit value. + * @name Reader#int64 + * @function + * @returns {Long} Value read + */ + +/** + * Reads a varint as an unsigned 64 bit value. + * @name Reader#uint64 + * @function + * @returns {Long} Value read + */ + +/** + * Reads a zig-zag encoded varint as a signed 64 bit value. + * @name Reader#sint64 + * @function + * @returns {Long} Value read + */ + +/** + * Reads a varint as a boolean. + * @returns {boolean} Value read + */ +Reader.prototype.bool = function read_bool() { + return this.uint32() !== 0; +}; + +function readFixed32_end(buf, end) { // note that this uses `end`, not `pos` + return (buf[end - 4] + | buf[end - 3] << 8 + | buf[end - 2] << 16 + | buf[end - 1] << 24) >>> 0; +} + +/** + * Reads fixed 32 bits as an unsigned 32 bit integer. + * @returns {number} Value read + */ +Reader.prototype.fixed32 = function read_fixed32() { + + /* istanbul ignore if */ + if (this.pos + 4 > this.len) + throw indexOutOfRange(this, 4); + + return readFixed32_end(this.buf, this.pos += 4); +}; + +/** + * Reads fixed 32 bits as a signed 32 bit integer. + * @returns {number} Value read + */ +Reader.prototype.sfixed32 = function read_sfixed32() { + + /* istanbul ignore if */ + if (this.pos + 4 > this.len) + throw indexOutOfRange(this, 4); + + return readFixed32_end(this.buf, this.pos += 4) | 0; +}; + +/* eslint-disable no-invalid-this */ + +function readFixed64(/* this: Reader */) { + + /* istanbul ignore if */ + if (this.pos + 8 > this.len) + throw indexOutOfRange(this, 8); + + return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4)); +} + +/* eslint-enable no-invalid-this */ + +/** + * Reads fixed 64 bits. + * @name Reader#fixed64 + * @function + * @returns {Long} Value read + */ + +/** + * Reads zig-zag encoded fixed 64 bits. + * @name Reader#sfixed64 + * @function + * @returns {Long} Value read + */ + +/** + * Reads a float (32 bit) as a number. + * @function + * @returns {number} Value read + */ +Reader.prototype.float = function read_float() { + + /* istanbul ignore if */ + if (this.pos + 4 > this.len) + throw indexOutOfRange(this, 4); + + var value = util.float.readFloatLE(this.buf, this.pos); + this.pos += 4; + return value; +}; + +/** + * Reads a double (64 bit float) as a number. + * @function + * @returns {number} Value read + */ +Reader.prototype.double = function read_double() { + + /* istanbul ignore if */ + if (this.pos + 8 > this.len) + throw indexOutOfRange(this, 4); + + var value = util.float.readDoubleLE(this.buf, this.pos); + this.pos += 8; + return value; +}; + +/** + * Reads a sequence of bytes preceeded by its length as a varint. + * @returns {Uint8Array} Value read + */ +Reader.prototype.bytes = function read_bytes() { + var length = this.uint32(), + start = this.pos, + end = this.pos + length; + + /* istanbul ignore if */ + if (end > this.len) + throw indexOutOfRange(this, length); + + this.pos += length; + if (Array.isArray(this.buf)) // plain array + return this.buf.slice(start, end); + return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1 + ? new this.buf.constructor(0) + : this._slice.call(this.buf, start, end); +}; + +/** + * Reads a string preceeded by its byte length as a varint. + * @returns {string} Value read + */ +Reader.prototype.string = function read_string() { + var bytes = this.bytes(); + return utf8.read(bytes, 0, bytes.length); +}; + +/** + * Skips the specified number of bytes if specified, otherwise skips a varint. + * @param {number} [length] Length if known, otherwise a varint is assumed + * @returns {Reader} `this` + */ +Reader.prototype.skip = function skip(length) { + if (typeof length === "number") { + /* istanbul ignore if */ + if (this.pos + length > this.len) + throw indexOutOfRange(this, length); + this.pos += length; + } else { + do { + /* istanbul ignore if */ + if (this.pos >= this.len) + throw indexOutOfRange(this); + } while (this.buf[this.pos++] & 128); + } + return this; +}; + +/** + * Skips the next element of the specified wire type. + * @param {number} wireType Wire type received + * @returns {Reader} `this` + */ +Reader.prototype.skipType = function(wireType) { + switch (wireType) { + case 0: + this.skip(); + break; + case 1: + this.skip(8); + break; + case 2: + this.skip(this.uint32()); + break; + case 3: + while ((wireType = this.uint32() & 7) !== 4) { + this.skipType(wireType); + } + break; + case 5: + this.skip(4); + break; + + /* istanbul ignore next */ + default: + throw Error("invalid wire type " + wireType + " at offset " + this.pos); + } + return this; +}; + +Reader._configure = function(BufferReader_) { + BufferReader = BufferReader_; + Reader.create = create(); + BufferReader._configure(); + + var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber"; + util.merge(Reader.prototype, { + + int64: function read_int64() { + return readLongVarint.call(this)[fn](false); + }, + + uint64: function read_uint64() { + return readLongVarint.call(this)[fn](true); + }, + + sint64: function read_sint64() { + return readLongVarint.call(this).zzDecode()[fn](false); + }, + + fixed64: function read_fixed64() { + return readFixed64.call(this)[fn](true); + }, + + sfixed64: function read_sfixed64() { + return readFixed64.call(this)[fn](false); + } + + }); +}; + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/reader_buffer.js": +/*!******************************************************!*\ + !*** ./node_modules/protobufjs/src/reader_buffer.js ***! + \******************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = BufferReader; + +// extends Reader +var Reader = __webpack_require__(/*! ./reader */ "./node_modules/protobufjs/src/reader.js"); +(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader; + +var util = __webpack_require__(/*! ./util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +/** + * Constructs a new buffer reader instance. + * @classdesc Wire format reader using node buffers. + * @extends Reader + * @constructor + * @param {Buffer} buffer Buffer to read from + */ +function BufferReader(buffer) { + Reader.call(this, buffer); + + /** + * Read buffer. + * @name BufferReader#buf + * @type {Buffer} + */ +} + +BufferReader._configure = function () { + /* istanbul ignore else */ + if (util.Buffer) + BufferReader.prototype._slice = util.Buffer.prototype.slice; +}; + + +/** + * @override + */ +BufferReader.prototype.string = function read_string_buffer() { + var len = this.uint32(); // modifies pos + return this.buf.utf8Slice + ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len)) + : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len)); +}; + +/** + * Reads a sequence of bytes preceeded by its length as a varint. + * @name BufferReader#bytes + * @function + * @returns {Buffer} Value read + */ + +BufferReader._configure(); + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/roots.js": +/*!**********************************************!*\ + !*** ./node_modules/protobufjs/src/roots.js ***! + \**********************************************/ +/***/ ((module) => { + +"use strict"; + +module.exports = {}; + +/** + * Named roots. + * This is where pbjs stores generated structures (the option `-r, --root` specifies a name). + * Can also be used manually to make roots available accross modules. + * @name roots + * @type {Object.} + * @example + * // pbjs -r myroot -o compiled.js ... + * + * // in another module: + * require("./compiled.js"); + * + * // in any subsequent module: + * var root = protobuf.roots["myroot"]; + */ + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/rpc.js": +/*!********************************************!*\ + !*** ./node_modules/protobufjs/src/rpc.js ***! + \********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + + +/** + * Streaming RPC helpers. + * @namespace + */ +var rpc = exports; + +/** + * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets. + * @typedef RPCImpl + * @type {function} + * @param {Method|rpc.ServiceMethod,Message<{}>>} method Reflected or static method being called + * @param {Uint8Array} requestData Request data + * @param {RPCImplCallback} callback Callback function + * @returns {undefined} + * @example + * function rpcImpl(method, requestData, callback) { + * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code + * throw Error("no such method"); + * asynchronouslyObtainAResponse(requestData, function(err, responseData) { + * callback(err, responseData); + * }); + * } + */ + +/** + * Node-style callback as used by {@link RPCImpl}. + * @typedef RPCImplCallback + * @type {function} + * @param {Error|null} error Error, if any, otherwise `null` + * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error + * @returns {undefined} + */ + +rpc.Service = __webpack_require__(/*! ./rpc/service */ "./node_modules/protobufjs/src/rpc/service.js"); + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/rpc/service.js": +/*!****************************************************!*\ + !*** ./node_modules/protobufjs/src/rpc/service.js ***! + \****************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = Service; + +var util = __webpack_require__(/*! ../util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +// Extends EventEmitter +(Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service; + +/** + * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}. + * + * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`. + * @typedef rpc.ServiceMethodCallback + * @template TRes extends Message + * @type {function} + * @param {Error|null} error Error, if any + * @param {TRes} [response] Response message + * @returns {undefined} + */ + +/** + * A service method part of a {@link rpc.Service} as created by {@link Service.create}. + * @typedef rpc.ServiceMethod + * @template TReq extends Message + * @template TRes extends Message + * @type {function} + * @param {TReq|Properties} request Request message or plain object + * @param {rpc.ServiceMethodCallback} [callback] Node-style callback called with the error, if any, and the response message + * @returns {Promise>} Promise if `callback` has been omitted, otherwise `undefined` + */ + +/** + * Constructs a new RPC service instance. + * @classdesc An RPC service as returned by {@link Service#create}. + * @exports rpc.Service + * @extends util.EventEmitter + * @constructor + * @param {RPCImpl} rpcImpl RPC implementation + * @param {boolean} [requestDelimited=false] Whether requests are length-delimited + * @param {boolean} [responseDelimited=false] Whether responses are length-delimited + */ +function Service(rpcImpl, requestDelimited, responseDelimited) { + + if (typeof rpcImpl !== "function") + throw TypeError("rpcImpl must be a function"); + + util.EventEmitter.call(this); + + /** + * RPC implementation. Becomes `null` once the service is ended. + * @type {RPCImpl|null} + */ + this.rpcImpl = rpcImpl; + + /** + * Whether requests are length-delimited. + * @type {boolean} + */ + this.requestDelimited = Boolean(requestDelimited); + + /** + * Whether responses are length-delimited. + * @type {boolean} + */ + this.responseDelimited = Boolean(responseDelimited); +} + +/** + * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}. + * @param {Method|rpc.ServiceMethod} method Reflected or static method + * @param {Constructor} requestCtor Request constructor + * @param {Constructor} responseCtor Response constructor + * @param {TReq|Properties} request Request message or plain object + * @param {rpc.ServiceMethodCallback} callback Service callback + * @returns {undefined} + * @template TReq extends Message + * @template TRes extends Message + */ +Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) { + + if (!request) + throw TypeError("request must be specified"); + + var self = this; + if (!callback) + return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request); + + if (!self.rpcImpl) { + setTimeout(function() { callback(Error("already ended")); }, 0); + return undefined; + } + + try { + return self.rpcImpl( + method, + requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(), + function rpcCallback(err, response) { + + if (err) { + self.emit("error", err, method); + return callback(err); + } + + if (response === null) { + self.end(/* endedByRPC */ true); + return undefined; + } + + if (!(response instanceof responseCtor)) { + try { + response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response); + } catch (err) { + self.emit("error", err, method); + return callback(err); + } + } + + self.emit("data", response, method); + return callback(null, response); + } + ); + } catch (err) { + self.emit("error", err, method); + setTimeout(function() { callback(err); }, 0); + return undefined; + } +}; + +/** + * Ends this service and emits the `end` event. + * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation. + * @returns {rpc.Service} `this` + */ +Service.prototype.end = function end(endedByRPC) { + if (this.rpcImpl) { + if (!endedByRPC) // signal end to rpcImpl + this.rpcImpl(null, null, null); + this.rpcImpl = null; + this.emit("end").off(); + } + return this; +}; + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/util/longbits.js": +/*!******************************************************!*\ + !*** ./node_modules/protobufjs/src/util/longbits.js ***! + \******************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = LongBits; + +var util = __webpack_require__(/*! ../util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +/** + * Constructs new long bits. + * @classdesc Helper class for working with the low and high bits of a 64 bit value. + * @memberof util + * @constructor + * @param {number} lo Low 32 bits, unsigned + * @param {number} hi High 32 bits, unsigned + */ +function LongBits(lo, hi) { + + // note that the casts below are theoretically unnecessary as of today, but older statically + // generated converter code might still call the ctor with signed 32bits. kept for compat. + + /** + * Low bits. + * @type {number} + */ + this.lo = lo >>> 0; + + /** + * High bits. + * @type {number} + */ + this.hi = hi >>> 0; +} + +/** + * Zero bits. + * @memberof util.LongBits + * @type {util.LongBits} + */ +var zero = LongBits.zero = new LongBits(0, 0); + +zero.toNumber = function() { return 0; }; +zero.zzEncode = zero.zzDecode = function() { return this; }; +zero.length = function() { return 1; }; + +/** + * Zero hash. + * @memberof util.LongBits + * @type {string} + */ +var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0"; + +/** + * Constructs new long bits from the specified number. + * @param {number} value Value + * @returns {util.LongBits} Instance + */ +LongBits.fromNumber = function fromNumber(value) { + if (value === 0) + return zero; + var sign = value < 0; + if (sign) + value = -value; + var lo = value >>> 0, + hi = (value - lo) / 4294967296 >>> 0; + if (sign) { + hi = ~hi >>> 0; + lo = ~lo >>> 0; + if (++lo > 4294967295) { + lo = 0; + if (++hi > 4294967295) + hi = 0; + } + } + return new LongBits(lo, hi); +}; + +/** + * Constructs new long bits from a number, long or string. + * @param {Long|number|string} value Value + * @returns {util.LongBits} Instance + */ +LongBits.from = function from(value) { + if (typeof value === "number") + return LongBits.fromNumber(value); + if (util.isString(value)) { + /* istanbul ignore else */ + if (util.Long) + value = util.Long.fromString(value); + else + return LongBits.fromNumber(parseInt(value, 10)); + } + return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero; +}; + +/** + * Converts this long bits to a possibly unsafe JavaScript number. + * @param {boolean} [unsigned=false] Whether unsigned or not + * @returns {number} Possibly unsafe number + */ +LongBits.prototype.toNumber = function toNumber(unsigned) { + if (!unsigned && this.hi >>> 31) { + var lo = ~this.lo + 1 >>> 0, + hi = ~this.hi >>> 0; + if (!lo) + hi = hi + 1 >>> 0; + return -(lo + hi * 4294967296); + } + return this.lo + this.hi * 4294967296; +}; + +/** + * Converts this long bits to a long. + * @param {boolean} [unsigned=false] Whether unsigned or not + * @returns {Long} Long + */ +LongBits.prototype.toLong = function toLong(unsigned) { + return util.Long + ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned)) + /* istanbul ignore next */ + : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) }; +}; + +var charCodeAt = String.prototype.charCodeAt; + +/** + * Constructs new long bits from the specified 8 characters long hash. + * @param {string} hash Hash + * @returns {util.LongBits} Bits + */ +LongBits.fromHash = function fromHash(hash) { + if (hash === zeroHash) + return zero; + return new LongBits( + ( charCodeAt.call(hash, 0) + | charCodeAt.call(hash, 1) << 8 + | charCodeAt.call(hash, 2) << 16 + | charCodeAt.call(hash, 3) << 24) >>> 0 + , + ( charCodeAt.call(hash, 4) + | charCodeAt.call(hash, 5) << 8 + | charCodeAt.call(hash, 6) << 16 + | charCodeAt.call(hash, 7) << 24) >>> 0 + ); +}; + +/** + * Converts this long bits to a 8 characters long hash. + * @returns {string} Hash + */ +LongBits.prototype.toHash = function toHash() { + return String.fromCharCode( + this.lo & 255, + this.lo >>> 8 & 255, + this.lo >>> 16 & 255, + this.lo >>> 24 , + this.hi & 255, + this.hi >>> 8 & 255, + this.hi >>> 16 & 255, + this.hi >>> 24 + ); +}; + +/** + * Zig-zag encodes this long bits. + * @returns {util.LongBits} `this` + */ +LongBits.prototype.zzEncode = function zzEncode() { + var mask = this.hi >> 31; + this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0; + this.lo = ( this.lo << 1 ^ mask) >>> 0; + return this; +}; + +/** + * Zig-zag decodes this long bits. + * @returns {util.LongBits} `this` + */ +LongBits.prototype.zzDecode = function zzDecode() { + var mask = -(this.lo & 1); + this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0; + this.hi = ( this.hi >>> 1 ^ mask) >>> 0; + return this; +}; + +/** + * Calculates the length of this longbits when encoded as a varint. + * @returns {number} Length + */ +LongBits.prototype.length = function length() { + var part0 = this.lo, + part1 = (this.lo >>> 28 | this.hi << 4) >>> 0, + part2 = this.hi >>> 24; + return part2 === 0 + ? part1 === 0 + ? part0 < 16384 + ? part0 < 128 ? 1 : 2 + : part0 < 2097152 ? 3 : 4 + : part1 < 16384 + ? part1 < 128 ? 5 : 6 + : part1 < 2097152 ? 7 : 8 + : part2 < 128 ? 9 : 10; +}; + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/util/minimal.js": +/*!*****************************************************!*\ + !*** ./node_modules/protobufjs/src/util/minimal.js ***! + \*****************************************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +var util = exports; + +// used to return a Promise where callback is omitted +util.asPromise = __webpack_require__(/*! @protobufjs/aspromise */ "./node_modules/@protobufjs/aspromise/index.js"); + +// converts to / from base64 encoded strings +util.base64 = __webpack_require__(/*! @protobufjs/base64 */ "./node_modules/@protobufjs/base64/index.js"); + +// base class of rpc.Service +util.EventEmitter = __webpack_require__(/*! @protobufjs/eventemitter */ "./node_modules/@protobufjs/eventemitter/index.js"); + +// float handling accross browsers +util.float = __webpack_require__(/*! @protobufjs/float */ "./node_modules/@protobufjs/float/index.js"); + +// requires modules optionally and hides the call from bundlers +util.inquire = __webpack_require__(/*! @protobufjs/inquire */ "./node_modules/@protobufjs/inquire/index.js"); + +// converts to / from utf8 encoded strings +util.utf8 = __webpack_require__(/*! @protobufjs/utf8 */ "./node_modules/@protobufjs/utf8/index.js"); + +// provides a node-like buffer pool in the browser +util.pool = __webpack_require__(/*! @protobufjs/pool */ "./node_modules/@protobufjs/pool/index.js"); + +// utility to work with the low and high bits of a 64 bit value +util.LongBits = __webpack_require__(/*! ./longbits */ "./node_modules/protobufjs/src/util/longbits.js"); + +/** + * Whether running within node or not. + * @memberof util + * @type {boolean} + */ +util.isNode = Boolean(typeof __webpack_require__.g !== "undefined" + && __webpack_require__.g + && __webpack_require__.g.process + && __webpack_require__.g.process.versions + && __webpack_require__.g.process.versions.node); + +/** + * Global object reference. + * @memberof util + * @type {Object} + */ +util.global = util.isNode && __webpack_require__.g + || typeof window !== "undefined" && window + || typeof self !== "undefined" && self + || this; // eslint-disable-line no-invalid-this + +/** + * An immuable empty array. + * @memberof util + * @type {Array.<*>} + * @const + */ +util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes + +/** + * An immutable empty object. + * @type {Object} + * @const + */ +util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes + +/** + * Tests if the specified value is an integer. + * @function + * @param {*} value Value to test + * @returns {boolean} `true` if the value is an integer + */ +util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) { + return typeof value === "number" && isFinite(value) && Math.floor(value) === value; +}; + +/** + * Tests if the specified value is a string. + * @param {*} value Value to test + * @returns {boolean} `true` if the value is a string + */ +util.isString = function isString(value) { + return typeof value === "string" || value instanceof String; +}; + +/** + * Tests if the specified value is a non-null object. + * @param {*} value Value to test + * @returns {boolean} `true` if the value is a non-null object + */ +util.isObject = function isObject(value) { + return value && typeof value === "object"; +}; + +/** + * Checks if a property on a message is considered to be present. + * This is an alias of {@link util.isSet}. + * @function + * @param {Object} obj Plain object or message instance + * @param {string} prop Property name + * @returns {boolean} `true` if considered to be present, otherwise `false` + */ +util.isset = + +/** + * Checks if a property on a message is considered to be present. + * @param {Object} obj Plain object or message instance + * @param {string} prop Property name + * @returns {boolean} `true` if considered to be present, otherwise `false` + */ +util.isSet = function isSet(obj, prop) { + var value = obj[prop]; + if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins + return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0; + return false; +}; + +/** + * Any compatible Buffer instance. + * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings. + * @interface Buffer + * @extends Uint8Array + */ + +/** + * Node's Buffer class if available. + * @type {Constructor} + */ +util.Buffer = (function() { + try { + var Buffer = util.inquire("buffer").Buffer; + // refuse to use non-node buffers if not explicitly assigned (perf reasons): + return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null; + } catch (e) { + /* istanbul ignore next */ + return null; + } +})(); + +// Internal alias of or polyfull for Buffer.from. +util._Buffer_from = null; + +// Internal alias of or polyfill for Buffer.allocUnsafe. +util._Buffer_allocUnsafe = null; + +/** + * Creates a new buffer of whatever type supported by the environment. + * @param {number|number[]} [sizeOrArray=0] Buffer size or number array + * @returns {Uint8Array|Buffer} Buffer + */ +util.newBuffer = function newBuffer(sizeOrArray) { + /* istanbul ignore next */ + return typeof sizeOrArray === "number" + ? util.Buffer + ? util._Buffer_allocUnsafe(sizeOrArray) + : new util.Array(sizeOrArray) + : util.Buffer + ? util._Buffer_from(sizeOrArray) + : typeof Uint8Array === "undefined" + ? sizeOrArray + : new Uint8Array(sizeOrArray); +}; + +/** + * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`. + * @type {Constructor} + */ +util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array; + +/** + * Any compatible Long instance. + * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js. + * @interface Long + * @property {number} low Low bits + * @property {number} high High bits + * @property {boolean} unsigned Whether unsigned or not + */ + +/** + * Long.js's Long class if available. + * @type {Constructor} + */ +util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long + || /* istanbul ignore next */ util.global.Long + || util.inquire("long"); + +/** + * Regular expression used to verify 2 bit (`bool`) map keys. + * @type {RegExp} + * @const + */ +util.key2Re = /^true|false|0|1$/; + +/** + * Regular expression used to verify 32 bit (`int32` etc.) map keys. + * @type {RegExp} + * @const + */ +util.key32Re = /^-?(?:0|[1-9][0-9]*)$/; + +/** + * Regular expression used to verify 64 bit (`int64` etc.) map keys. + * @type {RegExp} + * @const + */ +util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/; + +/** + * Converts a number or long to an 8 characters long hash string. + * @param {Long|number} value Value to convert + * @returns {string} Hash + */ +util.longToHash = function longToHash(value) { + return value + ? util.LongBits.from(value).toHash() + : util.LongBits.zeroHash; +}; + +/** + * Converts an 8 characters long hash string to a long or number. + * @param {string} hash Hash + * @param {boolean} [unsigned=false] Whether unsigned or not + * @returns {Long|number} Original value + */ +util.longFromHash = function longFromHash(hash, unsigned) { + var bits = util.LongBits.fromHash(hash); + if (util.Long) + return util.Long.fromBits(bits.lo, bits.hi, unsigned); + return bits.toNumber(Boolean(unsigned)); +}; + +/** + * Merges the properties of the source object into the destination object. + * @memberof util + * @param {Object.} dst Destination object + * @param {Object.} src Source object + * @param {boolean} [ifNotSet=false] Merges only if the key is not already set + * @returns {Object.} Destination object + */ +function merge(dst, src, ifNotSet) { // used by converters + for (var keys = Object.keys(src), i = 0; i < keys.length; ++i) + if (dst[keys[i]] === undefined || !ifNotSet) + dst[keys[i]] = src[keys[i]]; + return dst; +} + +util.merge = merge; + +/** + * Converts the first character of a string to lower case. + * @param {string} str String to convert + * @returns {string} Converted string + */ +util.lcFirst = function lcFirst(str) { + return str.charAt(0).toLowerCase() + str.substring(1); +}; + +/** + * Creates a custom error constructor. + * @memberof util + * @param {string} name Error name + * @returns {Constructor} Custom error constructor + */ +function newError(name) { + + function CustomError(message, properties) { + + if (!(this instanceof CustomError)) + return new CustomError(message, properties); + + // Error.call(this, message); + // ^ just returns a new error instance because the ctor can be called as a function + + Object.defineProperty(this, "message", { get: function() { return message; } }); + + /* istanbul ignore next */ + if (Error.captureStackTrace) // node + Error.captureStackTrace(this, CustomError); + else + Object.defineProperty(this, "stack", { value: new Error().stack || "" }); + + if (properties) + merge(this, properties); + } + + (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError; + + Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } }); + + CustomError.prototype.toString = function toString() { + return this.name + ": " + this.message; + }; + + return CustomError; +} + +util.newError = newError; + +/** + * Constructs a new protocol error. + * @classdesc Error subclass indicating a protocol specifc error. + * @memberof util + * @extends Error + * @template T extends Message + * @constructor + * @param {string} message Error message + * @param {Object.} [properties] Additional properties + * @example + * try { + * MyMessage.decode(someBuffer); // throws if required fields are missing + * } catch (e) { + * if (e instanceof ProtocolError && e.instance) + * console.log("decoded so far: " + JSON.stringify(e.instance)); + * } + */ +util.ProtocolError = newError("ProtocolError"); + +/** + * So far decoded message instance. + * @name util.ProtocolError#instance + * @type {Message} + */ + +/** + * A OneOf getter as returned by {@link util.oneOfGetter}. + * @typedef OneOfGetter + * @type {function} + * @returns {string|undefined} Set field name, if any + */ + +/** + * Builds a getter for a oneof's present field name. + * @param {string[]} fieldNames Field names + * @returns {OneOfGetter} Unbound getter + */ +util.oneOfGetter = function getOneOf(fieldNames) { + var fieldMap = {}; + for (var i = 0; i < fieldNames.length; ++i) + fieldMap[fieldNames[i]] = 1; + + /** + * @returns {string|undefined} Set field name, if any + * @this Object + * @ignore + */ + return function() { // eslint-disable-line consistent-return + for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i) + if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null) + return keys[i]; + }; +}; + +/** + * A OneOf setter as returned by {@link util.oneOfSetter}. + * @typedef OneOfSetter + * @type {function} + * @param {string|undefined} value Field name + * @returns {undefined} + */ + +/** + * Builds a setter for a oneof's present field name. + * @param {string[]} fieldNames Field names + * @returns {OneOfSetter} Unbound setter + */ +util.oneOfSetter = function setOneOf(fieldNames) { + + /** + * @param {string} name Field name + * @returns {undefined} + * @this Object + * @ignore + */ + return function(name) { + for (var i = 0; i < fieldNames.length; ++i) + if (fieldNames[i] !== name) + delete this[fieldNames[i]]; + }; +}; + +/** + * Default conversion options used for {@link Message#toJSON} implementations. + * + * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely: + * + * - Longs become strings + * - Enums become string keys + * - Bytes become base64 encoded strings + * - (Sub-)Messages become plain objects + * - Maps become plain objects with all string keys + * - Repeated fields become arrays + * - NaN and Infinity for float and double fields become strings + * + * @type {IConversionOptions} + * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json + */ +util.toJSONOptions = { + longs: String, + enums: String, + bytes: String, + json: true +}; + +// Sets up buffer utility according to the environment (called in index-minimal) +util._configure = function() { + var Buffer = util.Buffer; + /* istanbul ignore if */ + if (!Buffer) { + util._Buffer_from = util._Buffer_allocUnsafe = null; + return; + } + // because node 4.x buffers are incompatible & immutable + // see: https://github.com/dcodeIO/protobuf.js/pull/665 + util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from || + /* istanbul ignore next */ + function Buffer_from(value, encoding) { + return new Buffer(value, encoding); + }; + util._Buffer_allocUnsafe = Buffer.allocUnsafe || + /* istanbul ignore next */ + function Buffer_allocUnsafe(size) { + return new Buffer(size); + }; +}; + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/writer.js": +/*!***********************************************!*\ + !*** ./node_modules/protobufjs/src/writer.js ***! + \***********************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = Writer; + +var util = __webpack_require__(/*! ./util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +var BufferWriter; // cyclic + +var LongBits = util.LongBits, + base64 = util.base64, + utf8 = util.utf8; + +/** + * Constructs a new writer operation instance. + * @classdesc Scheduled writer operation. + * @constructor + * @param {function(*, Uint8Array, number)} fn Function to call + * @param {number} len Value byte length + * @param {*} val Value to write + * @ignore + */ +function Op(fn, len, val) { + + /** + * Function to call. + * @type {function(Uint8Array, number, *)} + */ + this.fn = fn; + + /** + * Value byte length. + * @type {number} + */ + this.len = len; + + /** + * Next operation. + * @type {Writer.Op|undefined} + */ + this.next = undefined; + + /** + * Value to write. + * @type {*} + */ + this.val = val; // type varies +} + +/* istanbul ignore next */ +function noop() {} // eslint-disable-line no-empty-function + +/** + * Constructs a new writer state instance. + * @classdesc Copied writer state. + * @memberof Writer + * @constructor + * @param {Writer} writer Writer to copy state from + * @ignore + */ +function State(writer) { + + /** + * Current head. + * @type {Writer.Op} + */ + this.head = writer.head; + + /** + * Current tail. + * @type {Writer.Op} + */ + this.tail = writer.tail; + + /** + * Current buffer length. + * @type {number} + */ + this.len = writer.len; + + /** + * Next state. + * @type {State|null} + */ + this.next = writer.states; +} + +/** + * Constructs a new writer instance. + * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`. + * @constructor + */ +function Writer() { + + /** + * Current length. + * @type {number} + */ + this.len = 0; + + /** + * Operations head. + * @type {Object} + */ + this.head = new Op(noop, 0, 0); + + /** + * Operations tail + * @type {Object} + */ + this.tail = this.head; + + /** + * Linked forked states. + * @type {Object|null} + */ + this.states = null; + + // When a value is written, the writer calculates its byte length and puts it into a linked + // list of operations to perform when finish() is called. This both allows us to allocate + // buffers of the exact required size and reduces the amount of work we have to do compared + // to first calculating over objects and then encoding over objects. In our case, the encoding + // part is just a linked list walk calling operations with already prepared values. +} + +var create = function create() { + return util.Buffer + ? function create_buffer_setup() { + return (Writer.create = function create_buffer() { + return new BufferWriter(); + })(); + } + /* istanbul ignore next */ + : function create_array() { + return new Writer(); + }; +}; + +/** + * Creates a new writer. + * @function + * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer} + */ +Writer.create = create(); + +/** + * Allocates a buffer of the specified size. + * @param {number} size Buffer size + * @returns {Uint8Array} Buffer + */ +Writer.alloc = function alloc(size) { + return new util.Array(size); +}; + +// Use Uint8Array buffer pool in the browser, just like node does with buffers +/* istanbul ignore else */ +if (util.Array !== Array) + Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray); + +/** + * Pushes a new operation to the queue. + * @param {function(Uint8Array, number, *)} fn Function to call + * @param {number} len Value byte length + * @param {number} val Value to write + * @returns {Writer} `this` + * @private + */ +Writer.prototype._push = function push(fn, len, val) { + this.tail = this.tail.next = new Op(fn, len, val); + this.len += len; + return this; +}; + +function writeByte(val, buf, pos) { + buf[pos] = val & 255; +} + +function writeVarint32(val, buf, pos) { + while (val > 127) { + buf[pos++] = val & 127 | 128; + val >>>= 7; + } + buf[pos] = val; +} + +/** + * Constructs a new varint writer operation instance. + * @classdesc Scheduled varint writer operation. + * @extends Op + * @constructor + * @param {number} len Value byte length + * @param {number} val Value to write + * @ignore + */ +function VarintOp(len, val) { + this.len = len; + this.next = undefined; + this.val = val; +} + +VarintOp.prototype = Object.create(Op.prototype); +VarintOp.prototype.fn = writeVarint32; + +/** + * Writes an unsigned 32 bit value as a varint. + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.uint32 = function write_uint32(value) { + // here, the call to this.push has been inlined and a varint specific Op subclass is used. + // uint32 is by far the most frequently used operation and benefits significantly from this. + this.len += (this.tail = this.tail.next = new VarintOp( + (value = value >>> 0) + < 128 ? 1 + : value < 16384 ? 2 + : value < 2097152 ? 3 + : value < 268435456 ? 4 + : 5, + value)).len; + return this; +}; + +/** + * Writes a signed 32 bit value as a varint. + * @function + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.int32 = function write_int32(value) { + return value < 0 + ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec + : this.uint32(value); +}; + +/** + * Writes a 32 bit value as a varint, zig-zag encoded. + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.sint32 = function write_sint32(value) { + return this.uint32((value << 1 ^ value >> 31) >>> 0); +}; + +function writeVarint64(val, buf, pos) { + while (val.hi) { + buf[pos++] = val.lo & 127 | 128; + val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0; + val.hi >>>= 7; + } + while (val.lo > 127) { + buf[pos++] = val.lo & 127 | 128; + val.lo = val.lo >>> 7; + } + buf[pos++] = val.lo; +} + +/** + * Writes an unsigned 64 bit value as a varint. + * @param {Long|number|string} value Value to write + * @returns {Writer} `this` + * @throws {TypeError} If `value` is a string and no long library is present. + */ +Writer.prototype.uint64 = function write_uint64(value) { + var bits = LongBits.from(value); + return this._push(writeVarint64, bits.length(), bits); +}; + +/** + * Writes a signed 64 bit value as a varint. + * @function + * @param {Long|number|string} value Value to write + * @returns {Writer} `this` + * @throws {TypeError} If `value` is a string and no long library is present. + */ +Writer.prototype.int64 = Writer.prototype.uint64; + +/** + * Writes a signed 64 bit value as a varint, zig-zag encoded. + * @param {Long|number|string} value Value to write + * @returns {Writer} `this` + * @throws {TypeError} If `value` is a string and no long library is present. + */ +Writer.prototype.sint64 = function write_sint64(value) { + var bits = LongBits.from(value).zzEncode(); + return this._push(writeVarint64, bits.length(), bits); +}; + +/** + * Writes a boolish value as a varint. + * @param {boolean} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.bool = function write_bool(value) { + return this._push(writeByte, 1, value ? 1 : 0); +}; + +function writeFixed32(val, buf, pos) { + buf[pos ] = val & 255; + buf[pos + 1] = val >>> 8 & 255; + buf[pos + 2] = val >>> 16 & 255; + buf[pos + 3] = val >>> 24; +} + +/** + * Writes an unsigned 32 bit value as fixed 32 bits. + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.fixed32 = function write_fixed32(value) { + return this._push(writeFixed32, 4, value >>> 0); +}; + +/** + * Writes a signed 32 bit value as fixed 32 bits. + * @function + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.sfixed32 = Writer.prototype.fixed32; + +/** + * Writes an unsigned 64 bit value as fixed 64 bits. + * @param {Long|number|string} value Value to write + * @returns {Writer} `this` + * @throws {TypeError} If `value` is a string and no long library is present. + */ +Writer.prototype.fixed64 = function write_fixed64(value) { + var bits = LongBits.from(value); + return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi); +}; + +/** + * Writes a signed 64 bit value as fixed 64 bits. + * @function + * @param {Long|number|string} value Value to write + * @returns {Writer} `this` + * @throws {TypeError} If `value` is a string and no long library is present. + */ +Writer.prototype.sfixed64 = Writer.prototype.fixed64; + +/** + * Writes a float (32 bit). + * @function + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.float = function write_float(value) { + return this._push(util.float.writeFloatLE, 4, value); +}; + +/** + * Writes a double (64 bit float). + * @function + * @param {number} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.double = function write_double(value) { + return this._push(util.float.writeDoubleLE, 8, value); +}; + +var writeBytes = util.Array.prototype.set + ? function writeBytes_set(val, buf, pos) { + buf.set(val, pos); // also works for plain array values + } + /* istanbul ignore next */ + : function writeBytes_for(val, buf, pos) { + for (var i = 0; i < val.length; ++i) + buf[pos + i] = val[i]; + }; + +/** + * Writes a sequence of bytes. + * @param {Uint8Array|string} value Buffer or base64 encoded string to write + * @returns {Writer} `this` + */ +Writer.prototype.bytes = function write_bytes(value) { + var len = value.length >>> 0; + if (!len) + return this._push(writeByte, 1, 0); + if (util.isString(value)) { + var buf = Writer.alloc(len = base64.length(value)); + base64.decode(value, buf, 0); + value = buf; + } + return this.uint32(len)._push(writeBytes, len, value); +}; + +/** + * Writes a string. + * @param {string} value Value to write + * @returns {Writer} `this` + */ +Writer.prototype.string = function write_string(value) { + var len = utf8.length(value); + return len + ? this.uint32(len)._push(utf8.write, len, value) + : this._push(writeByte, 1, 0); +}; + +/** + * Forks this writer's state by pushing it to a stack. + * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state. + * @returns {Writer} `this` + */ +Writer.prototype.fork = function fork() { + this.states = new State(this); + this.head = this.tail = new Op(noop, 0, 0); + this.len = 0; + return this; +}; + +/** + * Resets this instance to the last state. + * @returns {Writer} `this` + */ +Writer.prototype.reset = function reset() { + if (this.states) { + this.head = this.states.head; + this.tail = this.states.tail; + this.len = this.states.len; + this.states = this.states.next; + } else { + this.head = this.tail = new Op(noop, 0, 0); + this.len = 0; + } + return this; +}; + +/** + * Resets to the last state and appends the fork state's current write length as a varint followed by its operations. + * @returns {Writer} `this` + */ +Writer.prototype.ldelim = function ldelim() { + var head = this.head, + tail = this.tail, + len = this.len; + this.reset().uint32(len); + if (len) { + this.tail.next = head.next; // skip noop + this.tail = tail; + this.len += len; + } + return this; +}; + +/** + * Finishes the write operation. + * @returns {Uint8Array} Finished buffer + */ +Writer.prototype.finish = function finish() { + var head = this.head.next, // skip noop + buf = this.constructor.alloc(this.len), + pos = 0; + while (head) { + head.fn(head.val, buf, pos); + pos += head.len; + head = head.next; + } + // this.head = this.tail = null; + return buf; +}; + +Writer._configure = function(BufferWriter_) { + BufferWriter = BufferWriter_; + Writer.create = create(); + BufferWriter._configure(); +}; + + +/***/ }), + +/***/ "./node_modules/protobufjs/src/writer_buffer.js": +/*!******************************************************!*\ + !*** ./node_modules/protobufjs/src/writer_buffer.js ***! + \******************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +module.exports = BufferWriter; + +// extends Writer +var Writer = __webpack_require__(/*! ./writer */ "./node_modules/protobufjs/src/writer.js"); +(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter; + +var util = __webpack_require__(/*! ./util/minimal */ "./node_modules/protobufjs/src/util/minimal.js"); + +/** + * Constructs a new buffer writer instance. + * @classdesc Wire format writer using node buffers. + * @extends Writer + * @constructor + */ +function BufferWriter() { + Writer.call(this); +} + +BufferWriter._configure = function () { + /** + * Allocates a buffer of the specified size. + * @function + * @param {number} size Buffer size + * @returns {Buffer} Buffer + */ + BufferWriter.alloc = util._Buffer_allocUnsafe; + + BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set" + ? function writeBytesBuffer_set(val, buf, pos) { + buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited) + // also works for plain array values + } + /* istanbul ignore next */ + : function writeBytesBuffer_copy(val, buf, pos) { + if (val.copy) // Buffer values + val.copy(buf, pos, 0, val.length); + else for (var i = 0; i < val.length;) // plain array values + buf[pos++] = val[i++]; + }; +}; + + +/** + * @override + */ +BufferWriter.prototype.bytes = function write_bytes_buffer(value) { + if (util.isString(value)) + value = util._Buffer_from(value, "base64"); + var len = value.length >>> 0; + this.uint32(len); + if (len) + this._push(BufferWriter.writeBytesBuffer, len, value); + return this; +}; + +function writeStringBuffer(val, buf, pos) { + if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions) + util.utf8.write(val, buf, pos); + else if (buf.utf8Write) + buf.utf8Write(val, pos); + else + buf.write(val, pos); +} + +/** + * @override + */ +BufferWriter.prototype.string = function write_string_buffer(value) { + var len = util.Buffer.byteLength(value); + this.uint32(len); + if (len) + this._push(writeStringBuffer, len, value); + return this; +}; + + +/** + * Finishes the write operation. + * @name BufferWriter#finish + * @function + * @returns {Buffer} Finished buffer + */ + +BufferWriter._configure(); + + +/***/ }), + +/***/ "./lib/backend-onnxjs.ts": +/*!*******************************!*\ + !*** ./lib/backend-onnxjs.ts ***! + \*******************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.onnxjsBackend = void 0; +const session_1 = __webpack_require__(/*! ./onnxjs/session */ "./lib/onnxjs/session.ts"); +const session_handler_1 = __webpack_require__(/*! ./onnxjs/session-handler */ "./lib/onnxjs/session-handler.ts"); +class OnnxjsBackend { + // eslint-disable-next-line @typescript-eslint/no-empty-function + async init() { } + async createSessionHandler(pathOrBuffer, options) { + // NOTE: Session.Config(from onnx.js) is not compatible with InferenceSession.SessionOptions(from + // onnxruntime-common). + // In future we should remove Session.Config and use InferenceSession.SessionOptions. + // Currently we allow this to happen to make test runner work. + const session = new session_1.Session(options); + // typescript cannot merge method override correctly (so far in 4.2.3). need if-else to call the method. + if (typeof pathOrBuffer === 'string') { + await session.loadModel(pathOrBuffer); + } + else { + await session.loadModel(pathOrBuffer); + } + return new session_handler_1.OnnxjsSessionHandler(session); + } +} +exports.onnxjsBackend = new OnnxjsBackend(); + + +/***/ }), + +/***/ "./lib/backend-wasm.ts": +/*!*****************************!*\ + !*** ./lib/backend-wasm.ts ***! + \*****************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.wasmBackend = exports.initializeFlags = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const os_1 = __webpack_require__(/*! os */ "?0757"); +const proxy_wrapper_1 = __webpack_require__(/*! ./wasm/proxy-wrapper */ "./lib/wasm/proxy-wrapper.ts"); +const session_handler_1 = __webpack_require__(/*! ./wasm/session-handler */ "./lib/wasm/session-handler.ts"); +/** + * This function initializes all flags for WebAssembly. + * + * Those flags are accessible from `ort.env.wasm`. Users are allow to set those flags before the first inference session + * being created, to override default value. + */ +const initializeFlags = () => { + if (typeof onnxruntime_common_1.env.wasm.initTimeout !== 'number' || onnxruntime_common_1.env.wasm.initTimeout < 0) { + onnxruntime_common_1.env.wasm.initTimeout = 0; + } + if (typeof onnxruntime_common_1.env.wasm.simd !== 'boolean') { + onnxruntime_common_1.env.wasm.simd = true; + } + if (typeof onnxruntime_common_1.env.wasm.proxy !== 'boolean') { + onnxruntime_common_1.env.wasm.proxy = false; + } + if (typeof onnxruntime_common_1.env.wasm.numThreads !== 'number' || !Number.isInteger(onnxruntime_common_1.env.wasm.numThreads) || onnxruntime_common_1.env.wasm.numThreads <= 0) { + const numCpuLogicalCores = typeof navigator === 'undefined' ? (0, os_1.cpus)().length : navigator.hardwareConcurrency; + onnxruntime_common_1.env.wasm.numThreads = Math.min(4, Math.ceil((numCpuLogicalCores || 1) / 2)); + } +}; +exports.initializeFlags = initializeFlags; +class OnnxruntimeWebAssemblyBackend { + async init() { + // populate wasm flags + (0, exports.initializeFlags)(); + // init wasm + await (0, proxy_wrapper_1.initWasm)(); + } + async createSessionHandler(pathOrBuffer, options) { + const handler = new session_handler_1.OnnxruntimeWebAssemblySessionHandler(); + await handler.loadModel(pathOrBuffer, options); + return Promise.resolve(handler); + } +} +exports.wasmBackend = new OnnxruntimeWebAssemblyBackend(); + + +/***/ }), + +/***/ "./lib/index.ts": +/*!**********************!*\ + !*** ./lib/index.ts ***! + \**********************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ +// We use "require" instead of "import" here because import statement must be put in top level. Our current code does +// not allow terser to tree-shaking code as expected because some codes are treated as having side effects. +// So we import code inside the if-clause to allow terser remove the code safely. +__exportStar(__webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"), exports); +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +if (true) { + const onnxjsBackend = (__webpack_require__(/*! ./backend-onnxjs */ "./lib/backend-onnxjs.ts").onnxjsBackend); + (0, onnxruntime_common_1.registerBackend)('webgl', onnxjsBackend, -10); +} +if (true) { + const wasmBackend = (__webpack_require__(/*! ./backend-wasm */ "./lib/backend-wasm.ts").wasmBackend); + (0, onnxruntime_common_1.registerBackend)('cpu', wasmBackend, 10); + (0, onnxruntime_common_1.registerBackend)('wasm', wasmBackend, 10); + (0, onnxruntime_common_1.registerBackend)('xnnpack', wasmBackend, 9); +} + + +/***/ }), + +/***/ "./lib/onnxjs/attribute-with-cache-key.ts": +/*!************************************************!*\ + !*** ./lib/onnxjs/attribute-with-cache-key.ts ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createAttributeWithCacheKey = void 0; +class AttributeWithCacheKeyImpl { + constructor(attribute) { + Object.assign(this, attribute); + } + get cacheKey() { + if (!this._cacheKey) { + this._cacheKey = + Object.getOwnPropertyNames(this).sort().map(name => `${this[name]}`).join(';'); + } + return this._cacheKey; + } +} +const createAttributeWithCacheKey = (attribute) => new AttributeWithCacheKeyImpl(attribute); +exports.createAttributeWithCacheKey = createAttributeWithCacheKey; + + +/***/ }), + +/***/ "./lib/onnxjs/attribute.ts": +/*!*********************************!*\ + !*** ./lib/onnxjs/attribute.ts ***! + \*********************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Attribute = void 0; +const onnx_proto_1 = __webpack_require__(/*! onnx-proto */ "./node_modules/onnx-proto/dist/onnx.js"); +const ort_generated_1 = __webpack_require__(/*! ./ort-schema/ort-generated */ "./lib/onnxjs/ort-schema/ort-generated.ts"); +const tensor_1 = __webpack_require__(/*! ./tensor */ "./lib/onnxjs/tensor.ts"); +const util_1 = __webpack_require__(/*! ./util */ "./lib/onnxjs/util.ts"); +var ortFbs = ort_generated_1.onnxruntime.experimental.fbs; +class Attribute { + constructor(attributes) { + this._attributes = new Map(); + if (attributes !== null && attributes !== undefined) { + for (const attr of attributes) { + if (attr instanceof onnx_proto_1.onnx.AttributeProto) { + this._attributes.set(attr.name, [Attribute.getValue(attr), Attribute.getType(attr)]); + } + else if (attr instanceof ortFbs.Attribute) { + this._attributes.set(attr.name(), [Attribute.getValue(attr), Attribute.getType(attr)]); + } + } + if (this._attributes.size < attributes.length) { + throw new Error('duplicated attribute names'); + } + } + } + set(key, type, value) { + this._attributes.set(key, [value, type]); + } + delete(key) { + this._attributes.delete(key); + } + getFloat(key, defaultValue) { + return this.get(key, 'float', defaultValue); + } + getInt(key, defaultValue) { + return this.get(key, 'int', defaultValue); + } + getString(key, defaultValue) { + return this.get(key, 'string', defaultValue); + } + getTensor(key, defaultValue) { + return this.get(key, 'tensor', defaultValue); + } + getFloats(key, defaultValue) { + return this.get(key, 'floats', defaultValue); + } + getInts(key, defaultValue) { + return this.get(key, 'ints', defaultValue); + } + getStrings(key, defaultValue) { + return this.get(key, 'strings', defaultValue); + } + getTensors(key, defaultValue) { + return this.get(key, 'tensors', defaultValue); + } + get(key, type, defaultValue) { + const valueAndType = this._attributes.get(key); + if (valueAndType === undefined) { + if (defaultValue !== undefined) { + return defaultValue; + } + throw new Error(`required attribute not found: ${key}`); + } + if (valueAndType[1] !== type) { + throw new Error(`type mismatch: expected ${type} but got ${valueAndType[1]}`); + } + return valueAndType[0]; + } + static getType(attr) { + const type = attr instanceof onnx_proto_1.onnx.AttributeProto ? (attr).type : attr.type(); + switch (type) { + case onnx_proto_1.onnx.AttributeProto.AttributeType.FLOAT: + return 'float'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.INT: + return 'int'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.STRING: + return 'string'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.TENSOR: + return 'tensor'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.FLOATS: + return 'floats'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.INTS: + return 'ints'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.STRINGS: + return 'strings'; + case onnx_proto_1.onnx.AttributeProto.AttributeType.TENSORS: + return 'tensors'; + default: + throw new Error(`attribute type is not supported yet: ${onnx_proto_1.onnx.AttributeProto.AttributeType[type]}`); + } + } + static getValue(attr) { + const attrType = attr instanceof onnx_proto_1.onnx.AttributeProto ? attr.type : attr.type(); + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.GRAPH || attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.GRAPHS) { + throw new Error('graph attribute is not supported yet'); + } + const value = this.getValueNoCheck(attr); + // cast LONG to number + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.INT && util_1.LongUtil.isLong(value)) { + return util_1.LongUtil.longToNumber(value); + } + // cast LONG[] to number[] + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.INTS) { + const arr = value; + const numberValue = new Array(arr.length); + for (let i = 0; i < arr.length; i++) { + const maybeLong = arr[i]; + numberValue[i] = util_1.LongUtil.longToNumber(maybeLong); + } + return numberValue; + } + // cast onnx.TensorProto to onnxjs.Tensor + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.TENSOR) { + return attr instanceof onnx_proto_1.onnx.AttributeProto ? tensor_1.Tensor.fromProto(value) : + tensor_1.Tensor.fromOrtTensor(value); + } + // cast onnx.TensorProto[] to onnxjs.Tensor[] + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.TENSORS) { + if (attr instanceof onnx_proto_1.onnx.AttributeProto) { + const tensorProtos = value; + return tensorProtos.map(value => tensor_1.Tensor.fromProto(value)); + } + else if (attr instanceof ortFbs.Attribute) { + const tensorProtos = value; + return tensorProtos.map(value => tensor_1.Tensor.fromOrtTensor(value)); + } + } + // cast Uint8Array to string + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.STRING) { + // string in onnx attribute is of uint8array type, so we need to convert it to string below. While in ort format, + // string attributes are returned as string, so no conversion is needed. + if (attr instanceof onnx_proto_1.onnx.AttributeProto) { + const utf8String = value; + return (0, util_1.decodeUtf8String)(utf8String); + } + } + // cast Uint8Array[] to string[] + if (attrType === onnx_proto_1.onnx.AttributeProto.AttributeType.STRINGS) { + // strings in onnx attribute is returned as uint8array[], so we need to convert it to string[] below. While in ort + // format strings attributes are returned as string[], so no conversion is needed. + if (attr instanceof onnx_proto_1.onnx.AttributeProto) { + const utf8Strings = value; + return utf8Strings.map(util_1.decodeUtf8String); + } + } + return value; + } + static getValueNoCheck(attr) { + return attr instanceof (onnx_proto_1.onnx.AttributeProto) ? this.getValueNoCheckFromOnnxFormat(attr) : + this.getValueNoCheckFromOrtFormat(attr); + } + static getValueNoCheckFromOnnxFormat(attr) { + switch (attr.type) { + case onnx_proto_1.onnx.AttributeProto.AttributeType.FLOAT: + return attr.f; + case onnx_proto_1.onnx.AttributeProto.AttributeType.INT: + return attr.i; + case onnx_proto_1.onnx.AttributeProto.AttributeType.STRING: + return attr.s; + case onnx_proto_1.onnx.AttributeProto.AttributeType.TENSOR: + return attr.t; + case onnx_proto_1.onnx.AttributeProto.AttributeType.GRAPH: + return attr.g; + case onnx_proto_1.onnx.AttributeProto.AttributeType.FLOATS: + return attr.floats; + case onnx_proto_1.onnx.AttributeProto.AttributeType.INTS: + return attr.ints; + case onnx_proto_1.onnx.AttributeProto.AttributeType.STRINGS: + return attr.strings; + case onnx_proto_1.onnx.AttributeProto.AttributeType.TENSORS: + return attr.tensors; + case onnx_proto_1.onnx.AttributeProto.AttributeType.GRAPHS: + return attr.graphs; + default: + throw new Error(`unsupported attribute type: ${onnx_proto_1.onnx.AttributeProto.AttributeType[attr.type]}`); + } + } + static getValueNoCheckFromOrtFormat(attr) { + switch (attr.type()) { + case ortFbs.AttributeType.FLOAT: + return attr.f(); + case ortFbs.AttributeType.INT: + return attr.i(); + case ortFbs.AttributeType.STRING: + return attr.s(); + case ortFbs.AttributeType.TENSOR: + return attr.t(); + case ortFbs.AttributeType.GRAPH: + return attr.g(); + case ortFbs.AttributeType.FLOATS: + return attr.floatsArray(); + case ortFbs.AttributeType.INTS: { + const ints = []; + for (let i = 0; i < attr.intsLength(); i++) { + ints.push(attr.ints(i)); + } + return ints; + } + case ortFbs.AttributeType.STRINGS: { + const strings = []; + for (let i = 0; i < attr.stringsLength(); i++) { + strings.push(attr.strings(i)); + } + return strings; + } + case ortFbs.AttributeType.TENSORS: { + const tensors = []; + for (let i = 0; i < attr.tensorsLength(); i++) { + tensors.push(attr.tensors(i)); + } + return tensors; + } + // case ortFbs.AttributeType.GRAPHS: + // TODO: Subgraph not supported yet. + // const graphs = []; + // for (let i = 0; i < attr.graphsLength(); i++) { + // graphs.push(attr.graphs(i)!); + // } + // return graphs; + default: + throw new Error(`unsupported attribute type: ${ortFbs.AttributeType[attr.type()]}`); + } + } +} +exports.Attribute = Attribute; + + +/***/ }), + +/***/ "./lib/onnxjs/backend.ts": +/*!*******************************!*\ + !*** ./lib/onnxjs/backend.ts ***! + \*******************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.resolveBackend = exports.backend = void 0; +const backend_webgl_1 = __webpack_require__(/*! ./backends/backend-webgl */ "./lib/onnxjs/backends/backend-webgl.ts"); +// caches all initialized backend instances +const backendsCache = new Map(); +exports.backend = { + webgl: new backend_webgl_1.WebGLBackend(), +}; +/** + * Resolve a reference to the backend. If a hint is specified, the corresponding + * backend will be used. + */ +async function resolveBackend(hint) { + if (!hint) { + return resolveBackend(['webgl']); + } + else { + const hints = typeof hint === 'string' ? [hint] : hint; + for (const backendHint of hints) { + const cache = backendsCache.get(backendHint); + if (cache) { + return cache; + } + const backend = await tryLoadBackend(backendHint); + if (backend) { + return backend; + } + } + } + throw new Error('no available backend to use'); +} +exports.resolveBackend = resolveBackend; +async function tryLoadBackend(backendHint) { + const backendObj = exports.backend; + if (typeof backendObj[backendHint] !== 'undefined' && isBackend(backendObj[backendHint])) { + const backend = backendObj[backendHint]; + let init = backend.initialize(); + if (typeof init === 'object' && 'then' in init) { + init = await init; + } + if (init) { + backendsCache.set(backendHint, backend); + return backend; + } + } + return undefined; +} +function isBackend(obj) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const o = obj; + // check if an object is a Backend instance + if ('initialize' in o && typeof o.initialize === 'function' && // initialize() + 'createSessionHandler' in o && typeof o.createSessionHandler === 'function' && // createSessionHandler() + 'dispose' in o && typeof o.dispose === 'function' // dispose() + ) { + return true; + } + return false; +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/backend-webgl.ts": +/*!**********************************************!*\ + !*** ./lib/onnxjs/backends/backend-webgl.ts ***! + \**********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.WebGLBackend = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const instrument_1 = __webpack_require__(/*! ../instrument */ "./lib/onnxjs/instrument.ts"); +const session_handler_1 = __webpack_require__(/*! ./webgl/session-handler */ "./lib/onnxjs/backends/webgl/session-handler.ts"); +const webgl_context_factory_1 = __webpack_require__(/*! ./webgl/webgl-context-factory */ "./lib/onnxjs/backends/webgl/webgl-context-factory.ts"); +/** + * WebGLBackend is the entry point for all WebGL opeartions + * When it starts it created the WebGLRenderingContext + * and other main framework components such as Program and Texture Managers + */ +class WebGLBackend { + get contextId() { + return onnxruntime_common_1.env.webgl.contextId; + } + set contextId(value) { + onnxruntime_common_1.env.webgl.contextId = value; + } + get matmulMaxBatchSize() { + return onnxruntime_common_1.env.webgl.matmulMaxBatchSize; + } + set matmulMaxBatchSize(value) { + onnxruntime_common_1.env.webgl.matmulMaxBatchSize = value; + } + get textureCacheMode() { + return onnxruntime_common_1.env.webgl.textureCacheMode; + } + set textureCacheMode(value) { + onnxruntime_common_1.env.webgl.textureCacheMode = value; + } + get pack() { + return onnxruntime_common_1.env.webgl.pack; + } + set pack(value) { + onnxruntime_common_1.env.webgl.pack = value; + } + get async() { + return onnxruntime_common_1.env.webgl.async; + } + set async(value) { + onnxruntime_common_1.env.webgl.async = value; + } + initialize() { + try { + this.glContext = (0, webgl_context_factory_1.createWebGLContext)(this.contextId); + if (typeof this.matmulMaxBatchSize !== 'number') { + this.matmulMaxBatchSize = 16; + } + if (typeof this.textureCacheMode !== 'string') { + this.textureCacheMode = 'full'; + } + if (typeof this.pack !== 'boolean') { + this.pack = false; + } + if (typeof this.async !== 'boolean') { + this.async = false; + } + instrument_1.Logger.setWithEnv(onnxruntime_common_1.env); + instrument_1.Logger.verbose('WebGLBackend', `Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`); + return true; + } + catch (e) { + instrument_1.Logger.warning('WebGLBackend', `Unable to initialize WebGLBackend. ${e}`); + return false; + } + } + createSessionHandler(context) { + return new session_handler_1.WebGLSessionHandler(this, context); + } + dispose() { + this.glContext.dispose(); + } +} +exports.WebGLBackend = WebGLBackend; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-coordinate-lib.ts": +/*!**********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-coordinate-lib.ts ***! + \**********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.CoordsGlslLib = void 0; +const util_1 = __webpack_require__(/*! ../../util */ "./lib/onnxjs/util.ts"); +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +const glsl_source_1 = __webpack_require__(/*! ./glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const texture_layout_strategy_1 = __webpack_require__(/*! ./texture-layout-strategy */ "./lib/onnxjs/backends/webgl/texture-layout-strategy.ts"); +const utils_1 = __webpack_require__(/*! ./utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +/** + * GLSL Library responsible for data types and routines for manipulating + * coordinates and mapping to/from tensor indices + */ +class CoordsGlslLib extends glsl_definitions_1.GlslLib { + constructor(context) { + super(context); + } + getFunctions() { + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.offsetToCoords()), this.coordsToOffset()), this.toVec()), this.valueFrom()), this.getCommonUtilFuncs()), this.getInputsSamplingSnippets()), this.getOutputSamplingSnippet()); + } + getCustomTypes() { + return {}; + } + /** + * Produces a function that can map from + * 2D normalzied coordinates (s,t) to a flat offset + */ + offsetToCoords() { + const funcName = 'offsetToCoords'; + return { + offsetToCoords: new glsl_definitions_1.GlslLibRoutine(` + vec2 ${funcName}(int offset, int width, int height) { + int t = offset / width; + int s = offset - t*width; + vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height); + return coords; + } + `) + }; + } + /** + * Produces a function that can map from + * 2D normalzied coordinates (s,t) to a flat offset + */ + coordsToOffset() { + const funcName = 'coordsToOffset'; + return { + coordsToOffset: new glsl_definitions_1.GlslLibRoutine(` + int ${funcName}(vec2 coords, int width, int height) { + float s = coords.s * float(width); + float t = coords.t * float(height); + int offset = int(t) * width + int(s); + return offset; + } + `) + }; + } + /** + * Generates code for output sampler. + */ + getOutputSamplingSnippet() { + const outputLayout = this.context.outputTextureLayout; + if (outputLayout.isPacked) { + return this.getPackedOutputSamplingSnippet(outputLayout); + } + else { + return this.getUnpackedOutputSamplingSnippet(outputLayout); + } + } + /** + * Generates code for packed output sampler. + */ + getPackedOutputSamplingSnippet(outputLayout) { + const outShape = outputLayout.unpackedShape; + const outTexShape = [outputLayout.width, outputLayout.height]; + const result = {}; + const funcName = 'getOutputCoords'; + switch (outShape.length) { + case 0: + result[funcName] = this.getOutputScalarCoords(); + break; + case 1: + result[funcName] = this.getOutputPacked1DCoords(outShape, outTexShape); + break; + case 2: + result[funcName] = this.getOutputPacked2DCoords(outShape, outTexShape); + break; + case 3: + result[funcName] = + this.getOutputPacked3DCoords(outShape, outTexShape); + break; + default: + result[funcName] = this.getOutputPackedNDCoords(outShape, outTexShape); + } + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + // TODO we need this to properly return a packed vec4 from kernels. + // Replace all '{glsl.output} = result' with 'setOutput(result)' in all kernels. + const floatTextureSetRGBASource = ` + void setOutput(vec4 val) { + ${glsl.output} = val; + } + `; + const floatTextureSetRGBAFuncName = 'floatTextureSetRGBA'; + result[floatTextureSetRGBAFuncName] = new glsl_definitions_1.GlslLibRoutine(floatTextureSetRGBASource); + return result; + } + /** + * Generates code for unpacked output sampler. + */ + getUnpackedOutputSamplingSnippet(outputLayout) { + const outShape = outputLayout.unpackedShape; + const outTexShape = [outputLayout.width, outputLayout.height]; + const result = {}; + const funcName = 'getOutputCoords'; + switch (outShape.length) { + case 0: + result[funcName] = this.getOutputScalarCoords(); + break; + case 1: + result[funcName] = this.getOutputUnpacked1DCoords(outShape, outTexShape); + break; + case 2: + result[funcName] = + this.getOutputUnpacked2DCoords(outShape, outTexShape); + break; + case 3: + result[funcName] = + this.getOutputUnpacked3DCoords(outShape, outTexShape); + break; + case 4: + result[funcName] = this.getOutputUnpacked4DCoords(outShape, outTexShape); + break; + case 5: + result[funcName] = this.getOutputUnpacked5DCoords(outShape, outTexShape); + break; + case 6: + result[funcName] = this.getOutputUnpacked6DCoords(outShape, outTexShape); + break; + default: + throw new Error(`Unsupported output dimensionality: ${outShape.length}`); + } + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + // TODO we need this to properly return a packed vec4 from kernels. + // Replace all '{glsl.output} = result' with 'setOutput(result)' in all kernels. + const floatTextureSetRSource = ` + void setOutput(float val) { + ${glsl.output} = vec4(val, 0, 0, 0); + } + `; + const floatTextureSetRFuncName = 'floatTextureSetR'; + result[floatTextureSetRFuncName] = new glsl_definitions_1.GlslLibRoutine(floatTextureSetRSource); + return result; + } + /** + * Scalar output coordinates. + */ + getOutputScalarCoords() { + return new glsl_definitions_1.GlslLibRoutine(` + int getOutputCoords() { + return 0; + } + `); + } + /** + * 1D packed output coordinates. + */ + getOutputPacked1DCoords(shape, texShape) { + const packedTexShape = texShape; + let source = ''; + if (packedTexShape[0] === 1) { + source = ` + int getOutputCoords() { + return 2 * int(TexCoords.y * ${packedTexShape[1]}.0); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + if (packedTexShape[1] === 1) { + source = ` + int getOutputCoords() { + return 2 * int(TexCoords.x * ${packedTexShape[0]}.0); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + source = ` + int getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${packedTexShape[0]}, ${packedTexShape[1]})); + return 2 * (resTexRC.y * ${packedTexShape[0]} + resTexRC.x); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * 2D packed output coordinates. + */ + getOutputPacked2DCoords(shape, texShape) { + let source = ''; + if (util_1.ArrayUtil.arraysEqual(shape, texShape)) { + source = ` + ivec2 getOutputCoords() { + return 2 * ivec2(TexCoords.xy * vec2(${texShape[0]}, ${texShape[1]})); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + const packedTexShape = texShape; + // texels needed to accommodate a logical row + const texelsInLogicalRow = Math.ceil(shape[1] / 2); + /** + * getOutputCoords + * + * resTexRC: The rows and columns of the texels. If you move over one + * texel to the right in the packed texture, you are moving over one column + * (not two). + * + * index: The texel index + */ + source = ` + ivec2 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${packedTexShape[0]}, ${packedTexShape[1]})); + + int index = resTexRC.y * ${packedTexShape[0]} + resTexRC.x; + + // reverse r and c order for packed texture + int r = imod(index, ${texelsInLogicalRow}) * 2; + int c = 2 * (index / ${texelsInLogicalRow}); + + return ivec2(r, c); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * 3D packed output coordinates. + */ + getOutputPacked3DCoords(shape, texShape) { + const packedTexShape = [texShape[0], texShape[1]]; + const texelsInLogicalRow = Math.ceil(shape[2] / 2); + const texelsInBatch = texelsInLogicalRow * Math.ceil(shape[1] / 2); + const source = ` + ivec3 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${packedTexShape[0]}, ${packedTexShape[1]})); + int index = resTexRC.y * ${packedTexShape[0]} + resTexRC.x; + + int b = index / ${texelsInBatch}; + index -= b * ${texelsInBatch}; + + // reverse r and c order for packed texture + int r = imod(index, ${texelsInLogicalRow}) * 2; + int c = 2 * (index / ${texelsInLogicalRow}); + + return ivec3(b, r, c); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * ND packed output coordinates. + */ + getOutputPackedNDCoords(shape, texShape) { + const packedTexShape = [texShape[0], texShape[1]]; + const texelsInLogicalRow = Math.ceil(shape[shape.length - 1] / 2); + const texelsInBatch = texelsInLogicalRow * Math.ceil(shape[shape.length - 2] / 2); + let texelsInBatchN = texelsInBatch; + let batches = ''; + let coords = 'b, r, c'; + for (let b = 2; b < shape.length - 1; b++) { + texelsInBatchN *= shape[shape.length - b - 1]; + batches = ` + int b${b} = index / ${texelsInBatchN}; + index -= b${b} * ${texelsInBatchN}; + ` + batches; + coords = `b${b}, ` + coords; + } + const source = ` + ivec${shape.length} getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${packedTexShape[0]}, ${packedTexShape[1]})); + int index = resTexRC.y * ${packedTexShape[0]} + resTexRC.x; + + ${batches} + + int b = index / ${texelsInBatch}; + index -= b * ${texelsInBatch}; + + // reverse r and c order for packed texture + int r = imod(index, ${texelsInLogicalRow}) * 2; + int c = 2 * (index / ${texelsInLogicalRow}); + + return ivec${shape.length}(${coords}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 1D output coordinates. + */ + getOutputUnpacked1DCoords(shape, texShape) { + const source = ` + int getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + return resTexRC.y * ${texShape[0]} + resTexRC.x; + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 2D output coordinates. + */ + getOutputUnpacked2DCoords(shape, texShape) { + const source = ` + ivec2 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + int index = resTexRC.y * ${texShape[0]} + resTexRC.x; + int r = index / ${shape[1]}; + int c = index - r * ${shape[1]}; + return ivec2(r, c); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 3D output coordinates. + */ + getOutputUnpacked3DCoords(shape, texShape) { + let source = ''; + const rank = shape.length; + let strides = null; + if (rank < 2) { + strides = []; + } + strides = new Array(rank - 1); + strides[rank - 2] = shape[rank - 1]; + for (let i = rank - 3; i >= 0; --i) { + strides[i] = strides[i + 1] * shape[i + 1]; + } + const coordsToCompute = ['r', 'c', 'd']; + const coordsFromIndexSnippet = strides + .map((stride, i) => { + const line1 = `int ${coordsToCompute[i]} = index / ${stride}`; + const line2 = i === strides.length - 1 ? + `int ${coordsToCompute[i + 1]} = index - ${coordsToCompute[i]} * ${stride}` : + `index -= ${coordsToCompute[i]} * ${stride}`; + return `${line1}; ${line2};`; + }) + .join(''); + source = ` + ivec3 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + int index = resTexRC.y * ${texShape[0]} + resTexRC.x; + ${coordsFromIndexSnippet} + return ivec3(r, c, d); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 4D output coordinates. + */ + getOutputUnpacked4DCoords(shape, texShape) { + let source = ''; + const rank = shape.length; + let strides = null; + if (rank < 2) { + strides = []; + } + strides = new Array(rank - 1); + strides[rank - 2] = shape[rank - 1]; + for (let i = rank - 3; i >= 0; --i) { + strides[i] = strides[i + 1] * shape[i + 1]; + } + const coordsToCompute = ['r', 'c', 'd', 'd2']; + const coordsFromIndexSnippet = strides + .map((stride, i) => { + const line1 = `int ${coordsToCompute[i]} = index / ${stride}`; + const line2 = i === strides.length - 1 ? + `int ${coordsToCompute[i + 1]} = index - ${coordsToCompute[i]} * ${stride}` : + `index -= ${coordsToCompute[i]} * ${stride}`; + return `${line1}; ${line2};`; + }) + .join(''); + source = ` + ivec4 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + int index = resTexRC.y * ${texShape[0]} + resTexRC.x; + ${coordsFromIndexSnippet} + return ivec4(r, c, d, d2); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 5D output coordinates. + */ + getOutputUnpacked5DCoords(shape, texShape) { + let source = ''; + const rank = shape.length; + let strides = null; + if (rank < 2) { + strides = []; + } + strides = new Array(rank - 1); + strides[rank - 2] = shape[rank - 1]; + for (let i = rank - 3; i >= 0; --i) { + strides[i] = strides[i + 1] * shape[i + 1]; + } + const coordsToCompute = ['r', 'c', 'd', 'd2', 'd3']; + const coordsFromIndexSnippet = strides + .map((stride, i) => { + const line1 = `int ${coordsToCompute[i]} = index / ${stride}`; + const line2 = i === strides.length - 1 ? + `int ${coordsToCompute[i + 1]} = index - ${coordsToCompute[i]} * ${stride}` : + `index -= ${coordsToCompute[i]} * ${stride}`; + return `${line1}; ${line2};`; + }) + .join(''); + source = ` + ivec5 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + int index = resTexRC.y * ${texShape[0]} + resTexRC.x; + ${coordsFromIndexSnippet} + return ivec5(r, c, d, d2, d3); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked 6D output coordinates. + */ + getOutputUnpacked6DCoords(shape, texShape) { + let source = ''; + const rank = shape.length; + let strides = null; + if (rank < 2) { + strides = []; + } + strides = new Array(rank - 1); + strides[rank - 2] = shape[rank - 1]; + for (let i = rank - 3; i >= 0; --i) { + strides[i] = strides[i + 1] * shape[i + 1]; + } + const coordsToCompute = ['r', 'c', 'd', 'd2', 'd3', 'd4']; + const coordsFromIndexSnippet = strides + .map((stride, i) => { + const line1 = `int ${coordsToCompute[i]} = index / ${stride}`; + const line2 = i === strides.length - 1 ? + `int ${coordsToCompute[i + 1]} = index - ${coordsToCompute[i]} * ${stride}` : + `index -= ${coordsToCompute[i]} * ${stride}`; + return `${line1}; ${line2};`; + }) + .join(''); + source = ` + ivec6 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${texShape[0]}, ${texShape[1]})); + int index = resTexRC.y * ${texShape[0]} + resTexRC.x; + ${coordsFromIndexSnippet} + return ivec6(r, c, d, d2, d3, d4); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Generates code for common UV coords computation utility functions. + */ + getCommonUtilFuncs() { + const result = {}; + let funcName = 'uvFromFlat'; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(` + vec2 uvFromFlat(int texNumR, int texNumC, int index) { + int texC = index / texNumR; + int texR = index - texC * texNumR; + // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to + // v. + return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC); + } + `); + funcName = 'packedUVfrom1D'; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(` + vec2 packedUVfrom1D(int texNumR, int texNumC, int index) { + int texelIndex = index / 2; + int texR = texelIndex / texNumC; + int texC = texelIndex - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `); + funcName = 'packedUVfrom2D'; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(` + vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) { + int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2); + int texR = texelIndex / texNumC; + int texC = texelIndex - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `); + funcName = 'packedUVfrom3D'; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(` + vec2 packedUVfrom3D(int texNumR, int texNumC, + int texelsInBatch, int texelsInLogicalRow, int b, + int row, int col) { + int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2); + int texR = index / texNumC; + int texC = index - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `); + funcName = 'sampleTexture'; + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + result[funcName] = new glsl_definitions_1.GlslLibRoutine(` + float sampleTexture(sampler2D textureSampler, vec2 uv) { + return ${glsl.texture2D}(textureSampler, uv).r; + }`); + return result; + } + /** + * Constructing snippets for inputs + */ + getInputsSamplingSnippets() { + const result = {}; + const outputLayout = this.context.outputTextureLayout; + this.context.programInfo.inputNames.forEach((samplerName, i) => { + const inputLayout = this.context.inputTextureLayouts[i]; + const funcName = (0, utils_1.generateShaderFuncNameFromInputSamplerName)(samplerName); + if (inputLayout.isPacked) { + result[funcName] = this.getPackedSamplerFromInput(funcName, samplerName, inputLayout); + } + else { + result[funcName] = this.getUnpackedSamplerFromInput(funcName, samplerName, inputLayout); + } + const outCoordFuncName = (0, utils_1.generateShaderFuncNameFromInputSamplerNameAtOutCoords)(samplerName); + if (inputLayout.unpackedShape.length <= outputLayout.unpackedShape.length) { + if (inputLayout.isPacked) { + result[outCoordFuncName] = + this.getPackedSamplerAtOutputCoords(outCoordFuncName, inputLayout, outputLayout, samplerName); + } + else { + result[outCoordFuncName] = + this.getUnpackedSamplerAtOutputCoords(outCoordFuncName, inputLayout, outputLayout, samplerName); + } + } + }); + return result; + } + /** + * Constructing snippets for output coordinates of samplers + */ + getPackedSamplerAtOutputCoords(funcName, inputLayout, outputLayout, name) { + const inShape = inputLayout.unpackedShape; + const outShape = outputLayout.unpackedShape; + const texName = name; + const texFuncSnippet = (0, utils_1.generateShaderFuncNameFromInputSamplerName)(texName); + const inRank = inShape.length; + const outRank = outShape.length; + const broadcastDims = util_1.BroadcastUtil.getBroadcastDims(inShape, outShape); + const type = (0, utils_1.getCoordsDataType)(outRank); + const rankDiff = outRank - inRank; + let coordsSnippet; + const fields = (0, utils_1.getGlChannels)(); + if (inRank === 0) { + coordsSnippet = ''; + } + else if (outRank < 2 && broadcastDims.length >= 1) { + coordsSnippet = 'coords = 0;'; + } + else { + coordsSnippet = broadcastDims.map(d => `coords.${fields[d + rankDiff]} = 0;`).join('\n'); + } + let unpackedCoordsSnippet = ''; + if (outRank < 2 && inRank > 0) { + unpackedCoordsSnippet = 'coords'; + } + else { + unpackedCoordsSnippet = inShape.map((s, i) => `coords.${fields[i + rankDiff]}`).join(', '); + } + let output = 'return outputValue;'; + const inSize = util_1.ShapeUtil.size(inShape); + const isInputScalar = inSize === 1; + const outSize = util_1.ShapeUtil.size(outShape); + const isOutputScalar = outSize === 1; + if (inRank === 1 && !isInputScalar && !isOutputScalar) { + output = ` + return vec4(outputValue.xy, outputValue.xy); + `; + } + else if (isInputScalar && !isOutputScalar) { + if (outRank === 1) { + output = ` + return vec4(outputValue.x, outputValue.x, 0., 0.); + `; + } + else { + output = ` + return vec4(outputValue.x); + `; + } + } + else if (broadcastDims.length) { + const rows = inRank - 2; + const cols = inRank - 1; + if (broadcastDims.indexOf(rows) > -1 && broadcastDims.indexOf(cols) > -1) { + output = 'return vec4(outputValue.x);'; + } + else if (broadcastDims.indexOf(rows) > -1) { + output = 'return vec4(outputValue.x, outputValue.y, ' + + 'outputValue.x, outputValue.y);'; + } + else if (broadcastDims.indexOf(cols) > -1) { + output = 'return vec4(outputValue.xx, outputValue.zz);'; + } + } + const swapLastDimsSnippet = ` + int lastDim = coords.${fields[outRank - 1]}; + coords.${fields[outRank - 1]} = coords.${fields[outRank - 2]}; + coords.${fields[outRank - 2]} = lastDim; + `; + const source = ` + vec4 ${funcName}() { + ${type} coords = getOutputCoords(); + ${swapLastDimsSnippet} + ${coordsSnippet} + vec4 outputValue = ${texFuncSnippet}(${unpackedCoordsSnippet}); + ${output} + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.getOutputCoords']); + } + /** + * Constructing snippets for unpacked output coordinates of samplers + */ + getUnpackedSamplerAtOutputCoords(funcName, inputLayout, outputLayout, name) { + const outTexShape = [outputLayout.width, outputLayout.height]; + const inTexShape = [inputLayout.width, inputLayout.height]; + const inRank = inputLayout.unpackedShape.length; + const outRank = outputLayout.unpackedShape.length; + const inShape = inputLayout.unpackedShape; + const outShape = outputLayout.unpackedShape; + const texFuncSnippet = (0, utils_1.generateShaderFuncNameFromInputSamplerName)(name); + if (inRank === outRank && util_1.ArrayUtil.arraysEqual(inTexShape, outTexShape)) { + const source = ` + float ${funcName}() { + return sampleTexture(${name}, TexCoords); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + const type = (0, utils_1.getCoordsDataType)(outRank); + const broadcastDims = util_1.BroadcastUtil.getBroadcastDims(inShape, outShape); + const rankDiff = outRank - inRank; + let coordsSnippet; + const fields = (0, utils_1.getGlChannels)(); + if (inRank === 0) { + coordsSnippet = ''; + } + else if (outRank < 2 && broadcastDims.length >= 1) { + coordsSnippet = 'coords = 0;'; + } + else { + coordsSnippet = broadcastDims.map(d => `coords.${fields[d + rankDiff]} = 0;`).join('\n'); + } + let unpackedCoordsSnippet = ''; + if (outRank < 2 && inRank > 0) { + unpackedCoordsSnippet = 'coords'; + } + else { + unpackedCoordsSnippet = inputLayout.unpackedShape.map((s, i) => `coords.${fields[i + rankDiff]}`).join(', '); + } + const source = ` + float ${funcName}() { + ${type} coords = getOutputCoords(); + ${coordsSnippet} + return ${texFuncSnippet}(${unpackedCoordsSnippet}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.getOutputCoords']); + } + /** + * Constructing snippets for packed operations. + */ + getPackedSamplerFromInput(funcName, name, inputLayout) { + switch (inputLayout.unpackedShape.length) { + case 0: + return this.getPackedSamplerScalar(funcName, name); + case 1: + return this.getPackedSampler1D(funcName, name, inputLayout); + case 2: + return this.getPackedSampler2D(funcName, name, inputLayout); + case 3: + return this.getPackedSampler3D(funcName, name, inputLayout); + default: + return this.getPackedSamplerND(funcName, name, inputLayout); + } + } + /** + * Constructing snippets for unpacked operations. + */ + getUnpackedSamplerFromInput(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + switch (shape.length) { + case 0: + return this.getUnpackedSamplerScalar(funcName, name, inputLayout); + case 1: + return this.getUnpackedSampler1D(funcName, name, inputLayout); + case 2: + return this.getUnpackedSampler2D(funcName, name, inputLayout); + case 3: + return this.getUnpackedSampler3D(funcName, name, inputLayout); + case 4: + return this.getUnpackedSampler4D(funcName, name, inputLayout); + case 5: + return this.getUnpackedSampler5D(funcName, name, inputLayout); + case 6: + return this.getUnpackedSampler6D(funcName, name, inputLayout); + default: + // TODO support more dimensionalities + throw new Error(`Unsupported dimension ${shape.length}-D`); + } + } + /** + * Packed scalar snippet. + */ + getPackedSamplerScalar(funcName, name) { + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + const source = ` + vec4 ${funcName}() { + return ${glsl.texture2D}(${name}, halfCR); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Packed 1D snippet. + */ + getPackedSampler1D(funcName, name, inputLayout) { + const texShape = [inputLayout.width, inputLayout.height]; + const packedTexShape = [texShape[1], texShape[0]]; + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + const packedSampler = `vec4 ${funcName}(int index) { + vec2 uv = packedUVfrom1D( + ${packedTexShape[0]}, ${packedTexShape[1]}, index); + return ${glsl.texture2D}(${name}, uv); + }`; + const source = packedSampler; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.packedUVfrom1D']); + } + /** + * Packed 2D snippet. + */ + getPackedSampler2D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const texShape = [inputLayout.width, inputLayout.height]; + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + const texNumR = texShape[0]; + const texNumC = texShape[1]; + if (texShape != null && util_1.ArrayUtil.arraysEqual(shape, texShape)) { + const packedSampler = `vec4 ${funcName}(int row, int col) { + vec2 uv = (vec2(col, row) + halfCR) / vec2(${texNumC}.0, ${texNumR}.0); + return ${glsl.texture2D}(${name}, uv); + }`; + return new glsl_definitions_1.GlslLibRoutine(packedSampler); + } + const packedTexShape = texShape; + const valuesPerRow = Math.ceil(shape[1] / 2); + const packedSampler = `vec4 ${funcName}(int row, int col) { + vec2 uv = packedUVfrom2D(${packedTexShape[1]}, ${packedTexShape[0]}, ${valuesPerRow}, row, col); + return ${glsl.texture2D}(${name}, uv); + }`; + const source = packedSampler; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.packedUVfrom2D']); + } + /** + * Packed 3D snippet. + */ + getPackedSampler3D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const texShape = [inputLayout.width, inputLayout.height]; + const packedTexShape = [texShape[0], texShape[1]]; + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + if (shape[0] === 1) { + const squeezedShape = shape.slice(1); + const keptDims = [1, 2]; + const newInputShape = (0, utils_1.squeezeInputShape)(shape, squeezedShape); + const params = ['b', 'row', 'col']; + // Deep copy of input texture layout. + const newInputLayout = JSON.parse(JSON.stringify(inputLayout)); + newInputLayout.unpackedShape = newInputShape; + const samplerRoutine = this.getPackedSamplerFromInput(funcName, name, newInputLayout); + const packedSampler = `${samplerRoutine.routineBody} + vec4 ${funcName}(int b, int row, int col) { + return ${funcName}(${(0, utils_1.getSqueezedParams)(params, keptDims)}); + } `; + const source = packedSampler; + return new glsl_definitions_1.GlslLibRoutine(source, samplerRoutine.dependencies); + } + const texNumR = packedTexShape[0]; + const texNumC = packedTexShape[1]; + const valuesPerRow = Math.ceil(shape[2] / 2); + const texelsInBatch = valuesPerRow * Math.ceil(shape[1] / 2); + const packedSampler = `vec4 ${funcName}(int b, int row, int col) { + vec2 uv = packedUVfrom3D( + ${texNumC}, ${texNumR}, ${texelsInBatch}, ${valuesPerRow}, b, row, col); + return ${glsl.texture2D}(${name}, uv);}`; + const source = packedSampler; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.packedUVfrom3D']); + } + /* + * Packed ND snippet. + */ + getPackedSamplerND(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const rank = shape.length; + const texShape = [inputLayout.width, inputLayout.height]; + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + const packedTexShape = [texShape[0], texShape[1]]; + const texNumR = packedTexShape[1]; + const texNumC = packedTexShape[0]; + const valuesPerRow = Math.ceil(shape[rank - 1] / 2); + let texelsInBatch = valuesPerRow * Math.ceil(shape[rank - 2] / 2); + let params = 'int b, int row, int col'; + let index = `b * ${texelsInBatch} + (row / 2) * ${valuesPerRow} + (col / 2)`; + for (let b = 2; b < rank - 1; b++) { + params = `int b${b}, ` + params; + texelsInBatch *= shape[rank - b - 1]; + index = `b${b} * ${texelsInBatch} + ` + index; + } + const packedSampler = `vec4 ${funcName}(${params}) { + int index = ${index}; + int texR = index / ${texNumC}; + int texC = index - texR * ${texNumC}; + vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${texNumC}, ${texNumR}); + return ${glsl.texture2D}(${name}, uv); + }`; + const source = packedSampler; + return new glsl_definitions_1.GlslLibRoutine(source); + } + /** + * Unpacked scalar snippet. + */ + getUnpackedSamplerScalar(funcName, name, inputLayout) { + const [texNumR, texNumC] = [inputLayout.width, inputLayout.height]; + if (texNumR === 1 && texNumC === 1) { + const source = ` + float ${funcName}() { + return sampleTexture(${name}, halfCR); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + const source = ` + float ${funcName}() { + int offset_${name} = coordsToOffset(TexCoords, ${texNumR}, ${texNumC}); + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, offset_${name}); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + /** + * Unpacked 1D snippet. + */ + getUnpackedSampler1D(funcName, name, inputLayout) { + const tNumR = inputLayout.width; + const tNumC = inputLayout.height; + if (tNumC === 1 && tNumR === 1) { + const source = ` + float ${funcName}(int index) { + return sampleTexture(${name}, halfCR); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + if (tNumC === 1) { + const source = ` + float ${funcName}(int index) { + vec2 uv = vec2((float(index) + 0.5) / ${tNumR}.0, 0.5); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + if (tNumR === 1) { + const source = ` + float ${funcName}(int index) { + vec2 uv = vec2(0.5, (float(index) + 0.5) / ${tNumC}.0); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + const source = ` + float ${funcName}(int index) { + vec2 uv = uvFromFlat(${tNumR}, ${tNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture']); + } + /** + * Unpacked 2D snippet. + */ + getUnpackedSampler2D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + // TODO: modify row/col order for other dimensions. + const texShape = [inputLayout.height, inputLayout.width]; + if (texShape != null && util_1.ArrayUtil.arraysEqual(shape, texShape)) { + const texNumR = texShape[1]; + const texNumC = texShape[0]; + const source = ` + float ${funcName}(int row, int col) { + vec2 uv = (vec2(row, col) + halfCR) / vec2(${texNumR}.0, ${texNumC}.0); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + const { newShape, keptDims } = (0, texture_layout_strategy_1.squeezeShape)(shape); + const squeezedShape = newShape; + if (squeezedShape.length < shape.length) { + const newInputShape = (0, utils_1.squeezeInputShape)(shape, squeezedShape); + // Deep copy of input texture layout. + const newInputLayout = JSON.parse(JSON.stringify(inputLayout)); + newInputLayout.unpackedShape = newInputShape; + const params = ['col', 'row']; + const source = ` + ${this.getUnpackedSamplerFromInput(funcName, name, newInputLayout).routineBody} + float ${funcName}(int row, int col) { + return ${funcName}(${(0, utils_1.getSqueezedParams)(params, keptDims)}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture']); + } + const texNumR = texShape[1]; + const texNumC = texShape[0]; + if (texNumC === 1) { + const source = ` + float ${funcName}(int row, int col) { + int offset_${name} = coordsToOffset(TexCoords, ${texNumR}, ${texNumC}); + float index = dot(vec3(row, col, offset_${name}), vec3(${shape[1]}, 1, 1)); + vec2 uv = vec2(0.5, (index + 0.5) / ${texNumR}.0); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + if (texNumR === 1) { + const source = ` + float ${funcName}(int row, int col) { + int offset_${name} = coordsToOffset(TexCoords, ${texNumR}, ${texNumC}); + float index = dot(vec3(row, col, offset_${name}), vec3(${shape[1]}, 1, 1)); + vec2 uv = vec2((index + 0.5) / ${texNumC}.0, 0.5); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + const source = ` + float ${funcName}(int row, int col) { + int index = col * ${shape[1]} + row; + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + /** + * Unpacked 3D snippet. + */ + getUnpackedSampler3D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const stride0 = shape[1] * shape[2]; + const stride1 = shape[2]; + const { newShape, keptDims } = (0, texture_layout_strategy_1.squeezeShape)(shape); + const squeezedShape = newShape; + if (squeezedShape.length < shape.length) { + const newInputShape = (0, utils_1.squeezeInputShape)(shape, squeezedShape); + const params = ['batch', 'col', 'row']; + // Deep copy of input texture layout. + const newInputLayout = JSON.parse(JSON.stringify(inputLayout)); + newInputLayout.unpackedShape = newInputShape; + const routine = this.getUnpackedSamplerFromInput(funcName, name, newInputLayout); + // TODO: revisit the logic here to make it simpler + const revDims = keptDims.reverse(); + const source = ` + ${routine.routineBody} + float ${funcName}(int batch, int row, int col) { + return ${funcName}(${(0, utils_1.getSqueezedParams)(params, revDims)}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, routine.dependencies); + } + const texNumR = inputLayout.width; + const texNumC = inputLayout.height; + const source = ` + float ${funcName}(int depth, int row, int col) { + // Explicitly use integer operations as dot() only works on floats. + int index = depth * ${stride0} + col * ${stride1} + row; + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + /** + * Unpacked 4D snippet. + */ + getUnpackedSampler4D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const stride2 = shape[3]; + const stride1 = shape[2] * stride2; + const stride0 = shape[1] * stride1; + // + // TODO: re-enable this shortcut once the index calculation bug is fixed. + // + // const {newShape, keptDims} = squeezeShape(shape as number[]); + // if (newShape.length < shape.length) { + // const newInputShape = squeezeInputShape(shape, newShape); + // const params = ['row', 'col', 'depth', 'depth2']; + // // Deep copy of input texture layout. + // const newInputLayout: TextureLayout = JSON.parse(JSON.stringify(inputLayout)); + // newInputLayout.unpackedShape = newInputShape; + // const source = ` + // ${this.getUnpackedSamplerFromInput(funcName, name, newInputLayout).routineBody} + // float ${funcName}(int row, int col, int depth, int depth2) { + // return ${funcName}(${getSqueezedParams(params, keptDims)}); + // } + // `; + // return new GlslLibRoutine( + // source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture', 'coordinates.coordsToOffset']); + // } + const texNumR = inputLayout.width; + const texNumC = inputLayout.height; + const source = ` + float ${funcName}(int row, int col, int depth, int depth2) { + int index = row * ${stride0} + col * ${stride1} + + depth2 * ${stride2} + depth; + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture']); + } + /** + * Unpacked 5D snippet. + */ + getUnpackedSampler5D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const stride3 = shape[4]; + const stride2 = shape[3] * stride3; + const stride1 = shape[2] * stride2; + const stride0 = shape[1] * stride1; + const { newShape, keptDims } = (0, texture_layout_strategy_1.squeezeShape)(shape); + if (newShape.length < shape.length) { + const newInputShape = (0, utils_1.squeezeInputShape)(shape, newShape); + const params = ['row', 'col', 'depth', 'depth2', 'depth3']; + // Deep copy of input texture layout. + const newInputLayout = JSON.parse(JSON.stringify(inputLayout)); + newInputLayout.unpackedShape = newInputShape; + const source = ` + ${this.getUnpackedSamplerFromInput(funcName, name, newInputLayout).routineBody} + float ${funcName}(int row, int col, int depth, int depth2, int depth3) { + return ${funcName}(${(0, utils_1.getSqueezedParams)(params, keptDims)}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture', 'coordinates.uvFromFlat']); + } + const texNumR = inputLayout.width; + const texNumC = inputLayout.height; + const source = ` + float ${funcName}(int row, int col, int depth, int depth2, int depth3) { + int index = row * ${stride0} + col * ${stride1} + depth * ${stride2} + + depth3 * ${stride3} + depth2; + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture', 'coordinates.uvFromFlat']); + } + /** + * Unpacked 6D snippet. + */ + getUnpackedSampler6D(funcName, name, inputLayout) { + const shape = inputLayout.unpackedShape; + const stride4 = shape[5]; + const stride3 = shape[4] * stride4; + const stride2 = shape[3] * stride3; + const stride1 = shape[2] * stride2; + const stride0 = shape[1] * stride1; + const { newShape, keptDims } = (0, texture_layout_strategy_1.squeezeShape)(shape); + if (newShape.length < shape.length) { + const newInputShape = (0, utils_1.squeezeInputShape)(shape, newShape); + const params = ['row', 'col', 'depth', 'depth2', 'depth3', 'depth4']; + // Deep copy of input texture layout. + const newInputLayout = JSON.parse(JSON.stringify(inputLayout)); + newInputLayout.unpackedShape = newInputShape; + const source = ` + ${this.getUnpackedSamplerFromInput(funcName, name, newInputLayout).routineBody} + float ${funcName}(int row, int col, int depth, + int depth2, int depth3, int depth4) { + return ${funcName}(${(0, utils_1.getSqueezedParams)(params, keptDims)}); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.sampleTexture', 'coordinates.uvFromFlat']); + } + const texNumR = inputLayout.width; + const texNumC = inputLayout.height; + const source = ` + float ${funcName}(int row, int col, int depth, + int depth2, int depth3, int depth4) { + int index = row * ${stride0} + col * ${stride1} + depth * ${stride2} + + depth2 * ${stride3} + depth3 * ${stride4} + depth4; + vec2 uv = uvFromFlat(${texNumR}, ${texNumC}, index); + return sampleTexture(${name}, uv); + } + `; + return new glsl_definitions_1.GlslLibRoutine(source, ['coordinates.uvFromFlat', 'coordinates.sampleTexture', 'coordinates.coordsToOffset']); + } + /** + * This is the main function to map from the given texture coordiantes (s,t) + * to logical indices for the output + * There will only be one single variation of this + * Also see coordsToOffset and offsetToIndices for input-specific versions + */ + toVec() { + const output = this.context.outputTextureLayout; + const rank = output.shape.length; + const strides = output.strides; + const xScale = output.width; + const yScale = output.height; + const stridesBlock = []; + for (let i = 0; i < rank - 1; ++i) { + stridesBlock.push(` + c[${i}] = offset / ${strides[i]};`); + stridesBlock.push(` + offset -= c[${i}] * ${strides[i]};`); + } + stridesBlock.push(` + c[${rank - 1}] = offset;`); + const body = ` + void toVec(vec2 texCoords, out int c[${rank}]) { + int offset = coordsToOffset(texCoords, ${xScale}, ${yScale}); + ${stridesBlock.join('')} + } + void toVec(int offset, out int c[${rank}]) { + ${stridesBlock.join('')} + } + `; + return { toVec: new glsl_definitions_1.GlslLibRoutine(body, ['coordinates.coordsToOffset']) }; + } + /** + * These are value getter functions generated for each input + * Each function is hardwired to the name and dimensions of the input + * An '_T' variation is also produced which accesses values as if the + * input was transposed + */ + valueFrom() { + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const layout = this.context.inputTextureLayouts[i]; + const shape = layout.unpackedShape.length > 0 ? layout.unpackedShape : layout.shape; + const rank = shape.length; + let funcName = `_${name}`; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(this.getValueFromSingle(name, rank, layout.width, layout.height, false), [`shapeUtils.indicesToOffset${funcName}`, 'coordinates.offsetToCoords', 'fragcolor.getColorAsFloat']); + funcName = funcName + '_T'; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(this.getValueFromSingle(name, rank, layout.width, layout.height, true), [`shapeUtils.indicesToOffset${funcName}`, 'coordinates.offsetToCoords', 'fragcolor.getColorAsFloat']); + }); + return result; + } + /** + * Produces one value getter function for the name and rank given + * If a transpose is set proper offsetToCoords mapping will be used + * @param name name of the function + * @param rank rank of the input + * @param transpose whether or not should generate a transpose variation + */ + getValueFromSingle(varName, rank, width, height, transpose) { + let name = `_${varName}`; + if (transpose) { + name = name + '_T'; + } + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + return ` + float ${name}(int m[${rank}]) { + int offset = indicesToOffset${name}(m); + vec2 coords = offsetToCoords(offset, ${width}, ${height}); + float value = getColorAsFloat(${glsl.texture2D}(${varName}, coords)); + return value; + } + `; + } + /** + * Produces a packed value getter function for the name and rank given + * If a transpose is set proper offsetToCoords mapping will be used + * @param name name of the function + * @param rank rank of the input + * @param transpose whether or not should generate a transpose variation + */ + getPackedValueFrom(varName, rank, width, height, transpose) { + let name = `_${varName}_Pack`; + if (transpose) { + name = name + '_T'; + } + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + return ` + vec4 ${name}(int m[${rank}]) { + int offset = indicesToOffset_${varName}(m); + vec2 coords = offsetToCoords(offset, ${width}, ${height}); + return ${glsl.texture2D}(${varName}, coords); + } + `; + } +} +exports.CoordsGlslLib = CoordsGlslLib; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-definitions.ts": +/*!*******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-definitions.ts ***! + \*******************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.TopologicalSortGlslRoutines = exports.GlslLibRoutineNode = exports.GlslLibRoutine = exports.GlslLib = exports.GlslContext = exports.FunctionType = void 0; +/* eslint-disable @typescript-eslint/naming-convention */ +var FunctionType; +(function (FunctionType) { + FunctionType[FunctionType["ValueBased"] = 0] = "ValueBased"; + FunctionType[FunctionType["Positional"] = 1] = "Positional"; +})(FunctionType = exports.FunctionType || (exports.FunctionType = {})); +class GlslContext { + constructor(glContext, programInfo, inputTextureLayouts, outputTextureLayout) { + this.glContext = glContext; + this.programInfo = programInfo; + this.inputTextureLayouts = inputTextureLayouts; + this.outputTextureLayout = outputTextureLayout; + } +} +exports.GlslContext = GlslContext; +class GlslLib { + constructor(context) { + this.context = context; + } +} +exports.GlslLib = GlslLib; +// abstraction to represent a GLSL library routine and it's dependencies +class GlslLibRoutine { + constructor(routineBody, dependencies) { + this.routineBody = routineBody; + this.dependencies = dependencies; + } +} +exports.GlslLibRoutine = GlslLibRoutine; +// abstraction to represent a GLSL library routine and it's dependencies AS GRAPH Nodes +// this level of abstraction is used to topologically sort routines before fragment shade inclusion +class GlslLibRoutineNode { + constructor(name, routineBody, dependencies) { + this.name = name; + if (dependencies) { + this.dependencies = dependencies; + } + else { + this.dependencies = []; + } + if (routineBody) { + this.routineBody = routineBody; + } + } + addDependency(node) { + if (node) { + this.dependencies.push(node); + } + } +} +exports.GlslLibRoutineNode = GlslLibRoutineNode; +// topologically sort GLSL library routines (graph nodes abstraction) before shader script inclusion +class TopologicalSortGlslRoutines { + static returnOrderedNodes(nodes) { + if (!nodes || nodes.length === 0) { + return []; + } + if (nodes.length === 1) { + return nodes; + } + const cycleCheck = new Set(); + const alreadyTraversed = new Set(); + const result = new Array(); + this.createOrderedNodes(nodes, cycleCheck, alreadyTraversed, result); + return result; + } + static createOrderedNodes(graphNodes, cycleCheck, alreadyTraversed, result) { + for (let i = 0; i < graphNodes.length; ++i) { + this.dfsTraverse(graphNodes[i], cycleCheck, alreadyTraversed, result); + } + } + static dfsTraverse(root, cycleCheck, alreadyTraversed, result) { + // if this root has already been traversed return + if (!root || alreadyTraversed.has(root.name)) { + return; + } + // cyclic dependency has been detected + if (cycleCheck.has(root.name)) { + throw new Error('Cyclic dependency detected. Can\'t topologically sort routines needed for shader.'); + } + // hold this node to detect cycles if any + cycleCheck.add(root.name); + // traverse children in a dfs fashion + const dependencies = root.dependencies; + if (dependencies && dependencies.length > 0) { + for (let i = 0; i < dependencies.length; ++i) { + this.dfsTraverse(dependencies[i], cycleCheck, alreadyTraversed, result); + } + } + // add to result holder + result.push(root); + // mark this node as traversed so that we don't traverse from this again + alreadyTraversed.add(root.name); + // release the hold + cycleCheck.delete(root.name); + } +} +exports.TopologicalSortGlslRoutines = TopologicalSortGlslRoutines; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-encoding-lib.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-encoding-lib.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.EncodingGlslLib = void 0; +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +/** + * This GLSL library handles routines converting + * float32 to/from Unsigned byte or float 16 + */ +class EncodingGlslLib extends glsl_definitions_1.GlslLib { + constructor(context) { + super(context); + } + getFunctions() { + return Object.assign(Object.assign({}, this.encodeFloat32()), this.decodeFloat32()); + } + getCustomTypes() { + return {}; + } + encodeFloat32() { + return { + encode: new glsl_definitions_1.GlslLibRoutine(`highp vec4 encode(highp float f) { + return vec4(f, 0.0, 0.0, 0.0); + } + `) + }; + } + decodeFloat32() { + return { + decode: new glsl_definitions_1.GlslLibRoutine(`highp float decode(highp vec4 rgba) { + return rgba.r; + } + `) + }; + } + /** + * returns the routine to encode encode a 32bit float to a vec4 (of unsigned bytes) + * @credit: https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float + */ + encodeUint8() { + const endianness = EncodingGlslLib.isLittleEndian() ? 'rgba.rgba=rgba.abgr;' : ''; + return { + encode: new glsl_definitions_1.GlslLibRoutine(` + highp vec4 encode(highp float f) { + highp float F = abs(f); + highp float Sign = step(0.0,-f); + highp float Exponent = floor(log2(F)); + highp float Mantissa = (exp2(- Exponent) * F); + Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa)); + highp vec4 rgba; + rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0)); + rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0); + rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0))); + rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0))); + ${endianness} + rgba = rgba / 255.0; // values need to be normalized to [0,1] + return rgba; + } + `) + }; + } + /** + * returns the routine to encode a vec4 of unsigned bytes to float32 + * @credit: https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float + */ + decodeUint8() { + const endianness = EncodingGlslLib.isLittleEndian() ? 'rgba.rgba=rgba.abgr;' : ''; + return { + decode: new glsl_definitions_1.GlslLibRoutine(` + highp float decode(highp vec4 rgba) { + rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255] + ${endianness} + highp float Sign = 1.0 - step(128.0,rgba[0])*2.0; + highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0; + highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000); + highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 )); + return Result; + } + `) + }; + } + /** + * Determines if the machine is little endian or not + * @credit: https://gist.github.com/TooTallNate/4750953 + */ + static isLittleEndian() { + const b = new ArrayBuffer(4); + const a = new Uint32Array(b); + const c = new Uint8Array(b); + a[0] = 0xdeadbeef; + if (c[0] === 0xef) { + return true; + } + if (c[0] === 0xde) { + return false; + } + throw new Error('unknown endianness'); + } +} +exports.EncodingGlslLib = EncodingGlslLib; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-fragcolor-lib.ts": +/*!*********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-fragcolor-lib.ts ***! + \*********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.FragColorGlslLib = void 0; +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +const glsl_source_1 = __webpack_require__(/*! ./glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +/** + * This GLSL library handles routines around reading a texlet and writing to it + * Reading and writing could be more than just dealing with one channel + * It may require encoding/decoding to/from 4 channels into one + */ +class FragColorGlslLib extends glsl_definitions_1.GlslLib { + constructor(context) { + super(context); + } + getFunctions() { + return Object.assign(Object.assign({}, this.setFragColor()), this.getColorAsFloat()); + } + getCustomTypes() { + return {}; + } + setFragColor() { + const glsl = (0, glsl_source_1.getGlsl)(this.context.glContext.version); + return { + setFragColor: new glsl_definitions_1.GlslLibRoutine(` + void setFragColor(float value) { + ${glsl.output} = encode(value); + } + `, ['encoding.encode']) + }; + } + getColorAsFloat() { + return { + getColorAsFloat: new glsl_definitions_1.GlslLibRoutine(` + float getColorAsFloat(vec4 color) { + return decode(color); + } + `, ['encoding.decode']) + }; + } +} +exports.FragColorGlslLib = FragColorGlslLib; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-function-inliner.ts": +/*!************************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-function-inliner.ts ***! + \************************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.replaceInlines = void 0; +const INLINE_FUNC_DEF_REGEX = /@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm; +const FUNC_CALL_REGEX = '(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;'; +/** + * GLSL preprocessor responsible for resolving @inline directives + */ +function replaceInlines(script) { + const inlineDefs = {}; + let match; + while ((match = INLINE_FUNC_DEF_REGEX.exec(script)) !== null) { + const params = match[3] + .split(',') + .map(s => { + const tokens = s.trim().split(' '); + if (tokens && tokens.length === 2) { + return { type: tokens[0], name: tokens[1] }; + } + return null; + }) + .filter(v => v !== null); + inlineDefs[match[2]] = { params, body: match[4] }; + } + for (const name in inlineDefs) { + const regexString = FUNC_CALL_REGEX.replace('__FUNC__', name); + const regex = new RegExp(regexString, 'gm'); + while ((match = regex.exec(script)) !== null) { + const type = match[1]; + const variable = match[2]; + const params = match[3].split(','); + const declLine = (type) ? `${type} ${variable};` : ''; + let newBody = inlineDefs[name].body; + let paramRedecLine = ''; + inlineDefs[name].params.forEach((v, i) => { + if (v) { + paramRedecLine += `${v.type} ${v.name} = ${params[i]};\n`; + } + }); + newBody = `${paramRedecLine}\n ${newBody}`; + newBody = newBody.replace('return', `${variable} = `); + const replacement = ` + ${declLine} + { + ${newBody} + } + `; + script = script.replace(match[0], replacement); + } + } + script = script.replace(INLINE_FUNC_DEF_REGEX, ''); + return script; +} +exports.replaceInlines = replaceInlines; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-preprocessor.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-preprocessor.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.GlslPreprocessor = void 0; +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +const glsl_function_inliner_1 = __webpack_require__(/*! ./glsl-function-inliner */ "./lib/onnxjs/backends/webgl/glsl-function-inliner.ts"); +const glsl_registered_libs_1 = __webpack_require__(/*! ./glsl-registered-libs */ "./lib/onnxjs/backends/webgl/glsl-registered-libs.ts"); +const glsl_source_1 = __webpack_require__(/*! ./glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +/** + * Preprocessor for the additions to the GLSL language + * It deals with: + * @include directives + * @inline + * Loop unrolling (not implemented) + * Macro resolution (not implemented) + */ +class GlslPreprocessor { + constructor(glContext, programInfo, inputTextureLayouts, outputTextureLayout) { + this.libs = {}; + this.glslLibRoutineDependencyGraph = {}; + this.context = new glsl_definitions_1.GlslContext(glContext, programInfo, inputTextureLayouts, outputTextureLayout); + // construct GlslLibs + Object.keys(glsl_registered_libs_1.glslRegistry).forEach((name) => { + const lib = new glsl_registered_libs_1.glslRegistry[name](this.context); + this.libs[name] = lib; + }); + // construct GlslRoutineDependencyGraph + const map = this.glslLibRoutineDependencyGraph; + for (const libName in this.libs) { + const lib = this.libs[libName]; + const routinesInLib = lib.getFunctions(); + for (const routine in routinesInLib) { + const key = libName + '.' + routine; + let currentNode; + if (map[key]) { + currentNode = map[key]; + currentNode.routineBody = routinesInLib[routine].routineBody; + } + else { + currentNode = new glsl_definitions_1.GlslLibRoutineNode(key, routinesInLib[routine].routineBody); + map[key] = currentNode; + } + const dependencies = routinesInLib[routine].dependencies; + if (dependencies) { + for (let i = 0; i < dependencies.length; ++i) { + if (!map[dependencies[i]]) { + const node = new glsl_definitions_1.GlslLibRoutineNode(dependencies[i]); + map[dependencies[i]] = node; + currentNode.addDependency(node); + } + else { + currentNode.addDependency(map[dependencies[i]]); + } + } + } + } + } + } + preprocess() { + const programInfo = this.context.programInfo; + let source = programInfo.shaderSource; + // append main() function + if (!this.context.programInfo.hasMain) { + source = `${source} + ${(0, glsl_source_1.getDefaultFragShaderMain)(this.context.glContext.version, this.context.outputTextureLayout.shape.length)}`; + } + // replace inlines + source = (0, glsl_function_inliner_1.replaceInlines)(source); + // concat final source string + return `${(0, glsl_source_1.getFragShaderPreamble)(this.context.glContext.version)} + ${this.getUniforms(programInfo.inputNames, programInfo.variables)} + ${this.getImports(source)} + ${source}`; + } + getImports(script) { + const routinesIncluded = this.selectGlslLibRoutinesToBeIncluded(script); + if (routinesIncluded.length === 0) { + return ''; + } + let routines = ''; + for (let i = 0; i < routinesIncluded.length; ++i) { + if (routinesIncluded[i].routineBody) { + routines += routinesIncluded[i].routineBody + '\n'; + } + else { + throw new Error(`Missing body for the Glsl Library routine: ${routinesIncluded[i].name}`); + } + } + return routines; + } + selectGlslLibRoutinesToBeIncluded(script) { + const nodes = []; + Object.keys(this.glslLibRoutineDependencyGraph).forEach(classAndRoutine => { + const routine = classAndRoutine.split('.')[1]; + if (script.indexOf(routine) !== -1) { + nodes.push(this.glslLibRoutineDependencyGraph[classAndRoutine]); + } + }); + return glsl_definitions_1.TopologicalSortGlslRoutines.returnOrderedNodes(nodes); + } + getUniforms(samplers, variables) { + const uniformLines = []; + if (samplers) { + for (const sampler of samplers) { + uniformLines.push(`uniform sampler2D ${sampler};`); + } + } + if (variables) { + for (const variable of variables) { + uniformLines.push(`uniform ${variable.type} ${variable.name}${variable.arrayLength ? `[${variable.arrayLength}]` : ''};`); + } + } + return uniformLines.join('\n'); + } +} +exports.GlslPreprocessor = GlslPreprocessor; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-registered-libs.ts": +/*!***********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-registered-libs.ts ***! + \***********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.glslRegistry = void 0; +const glsl_coordinate_lib_1 = __webpack_require__(/*! ./glsl-coordinate-lib */ "./lib/onnxjs/backends/webgl/glsl-coordinate-lib.ts"); +const glsl_encoding_lib_1 = __webpack_require__(/*! ./glsl-encoding-lib */ "./lib/onnxjs/backends/webgl/glsl-encoding-lib.ts"); +const glsl_fragcolor_lib_1 = __webpack_require__(/*! ./glsl-fragcolor-lib */ "./lib/onnxjs/backends/webgl/glsl-fragcolor-lib.ts"); +const glsl_shape_utils_lib_1 = __webpack_require__(/*! ./glsl-shape-utils-lib */ "./lib/onnxjs/backends/webgl/glsl-shape-utils-lib.ts"); +const glsl_vec_lib_1 = __webpack_require__(/*! ./glsl-vec-lib */ "./lib/onnxjs/backends/webgl/glsl-vec-lib.ts"); +exports.glslRegistry = { + 'encoding': glsl_encoding_lib_1.EncodingGlslLib, + 'fragcolor': glsl_fragcolor_lib_1.FragColorGlslLib, + 'vec': glsl_vec_lib_1.VecGlslLib, + 'shapeUtils': glsl_shape_utils_lib_1.ShapeUtilsGlslLib, + 'coordinates': glsl_coordinate_lib_1.CoordsGlslLib, + // 'arrays': ArrayGlslSLib +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-shape-utils-lib.ts": +/*!***********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-shape-utils-lib.ts ***! + \***********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.ShapeUtilsGlslLib = void 0; +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +/** + * GLSL Library responsible for data types and routines for manipulating + * coordinates and mapping to/from tensor indices + */ +class ShapeUtilsGlslLib extends glsl_definitions_1.GlslLib { + constructor(context) { + super(context); + } + getFunctions() { + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.bcastIndex()), this.bcastMatmulIndex()), this.offsetToIndices()), this.indicesToOffset()), this.incrementIndices()); + } + getCustomTypes() { + return {}; + } + bcastIndex() { + const outputRank = this.context.outputTextureLayout.shape.length; + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const shape = this.context.inputTextureLayouts[i].unpackedShape; + if (shape.length <= outputRank) { + const rank = shape.length; + const dimOffset = outputRank - rank; + const funcName = `bcastIndices_${name}`; + let block = ''; + for (let i = 0; i < rank; ++i) { + block += ` + realIndices[${i}] = int( mod(float(bcastedIndices[${dimOffset + i}]), ${shape[i]}.0) ); + `; + } + const body = ` + void ${funcName} (int bcastedIndices[${outputRank}], out int realIndices[${rank}]) { + ${block} + } + `; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(body); + } + }); + return result; + } + bcastMatmulIndex() { + const outputRank = this.context.outputTextureLayout.shape.length; + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const shape = this.context.inputTextureLayouts[i].shape; + if (!(shape.length < 2 || shape.length > outputRank)) { + const rank = shape.length; + const dimOffset = outputRank - rank; + const funcName = `bcastMatmulIndices_${name}`; + let block = ''; + for (let i = 0; i < rank - 2; ++i) { + block += ` + realIndices[${i}] = int( mod(float(bcastedIndices[${dimOffset + i}]), ${shape[i]}.0) ); + `; + } + const body = ` + void ${funcName}(int bcastedIndices[${outputRank}], out int realIndices[${rank}]) { + ${block} + realIndices[${rank - 1}] = bcastedIndices[${outputRank - 1}]; + realIndices[${rank - 2}] = bcastedIndices[${outputRank - 2}]; + } + `; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(body); + } + }); + return result; + } + indicesToOffset() { + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const shape = this.context.inputTextureLayouts[i].shape; + const strides = this.context.inputTextureLayouts[i].strides; + const rank = shape.length; + let funcName = `indicesToOffset_${name}`; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(ShapeUtilsGlslLib.indexToOffsetSingle(funcName, rank, strides)); + funcName = `indicesToOffset_${name}_T`; + result[funcName] = + new glsl_definitions_1.GlslLibRoutine(ShapeUtilsGlslLib.indexToOffsetSingle(funcName, rank, strides.slice().reverse())); + }); + return result; + } + static indexToOffsetSingle(name, rank, strides) { + let block = ''; + for (let i = rank - 1; i >= 0; --i) { + block += ` + offset += indices[${i}] * ${strides[i]}; + `; + } + return ` + int ${name}(int indices[${rank}]) { + int offset = 0; + ${block} + return offset; + } + `; + } + offsetToIndices() { + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const shape = this.context.inputTextureLayouts[i].shape; + const strides = this.context.inputTextureLayouts[i].strides; + const rank = shape.length; + let funcName = `offsetToIndices_${name}`; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(ShapeUtilsGlslLib.offsetToIndicesSingle(funcName, rank, strides)); + funcName = `offsetToIndices_${name}_T`; + result[funcName] = + new glsl_definitions_1.GlslLibRoutine(ShapeUtilsGlslLib.offsetToIndicesSingle(funcName, rank, strides.slice().reverse())); + }); + return result; + } + static offsetToIndicesSingle(name, rank, strides) { + const stridesBlock = []; + for (let i = 0; i < rank - 1; ++i) { + stridesBlock.push(` + indices[${i}] = offset / ${strides[i]};`); + stridesBlock.push(` + offset -= indices[${i}] * ${strides[i]};`); + } + stridesBlock.push(` + indices[${rank - 1}] = offset;`); + return ` + void ${name}(int offset, out int indices[${rank}]) { + ${stridesBlock.join('')} + } + `; + } + incrementIndices() { + const result = {}; + this.context.programInfo.inputNames.forEach((name, i) => { + const shape = this.context.inputTextureLayouts[i].shape; + const rank = shape.length; + const funcName = `incrementIndices_${name}`; + let shapeInit = ''; + for (let i = 0; i < rank; ++i) { + shapeInit += ` + shape[${i}] = ${shape[i]};`; + } + const body = ` + void ${funcName}(int axis, out int indices[${rank}]) { + int shape[${rank}]; + ${shapeInit}; + for(int i = ${rank} -1 ; i >= 0; --i) { + if(i > axis) continue; + indices[i] += 1; + if(indices[i] < shape[i]) { + break; + } + indices[i] = 0; + } + } + `; + result[funcName] = new glsl_definitions_1.GlslLibRoutine(body); + }); + return result; + } +} +exports.ShapeUtilsGlslLib = ShapeUtilsGlslLib; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-source.ts": +/*!**************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-source.ts ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getDefaultFragShaderMain = exports.getFragShaderPreamble = exports.getVertexShaderSource = exports.getGlsl = void 0; +const GLSL_ES_2_0 = { + version: '', + attribute: 'attribute', + varyingVertex: 'varying', + varyingFrag: 'varying', + texture2D: 'texture2D', + output: 'gl_FragColor', + outputDeclaration: '', +}; +const GLSL_ES_3_0 = { + version: '#version 300 es', + attribute: 'in', + varyingVertex: 'out', + varyingFrag: 'in', + texture2D: 'texture', + output: 'outputColor', + outputDeclaration: 'out vec4 outputColor;', +}; +function getGlsl(version) { + return version === 1 ? GLSL_ES_2_0 : GLSL_ES_3_0; +} +exports.getGlsl = getGlsl; +function getVertexShaderSource(version) { + const glsl = getGlsl(version); + return `${glsl.version} + precision highp float; + ${glsl.attribute} vec3 position; + ${glsl.attribute} vec2 textureCoord; + + ${glsl.varyingVertex} vec2 TexCoords; + + void main() + { + gl_Position = vec4(position, 1.0); + TexCoords = textureCoord; + }`; +} +exports.getVertexShaderSource = getVertexShaderSource; +function getFragShaderPreamble(version) { + const glsl = getGlsl(version); + return `${glsl.version} + precision highp float; + precision highp int; + precision highp sampler2D; + ${glsl.varyingFrag} vec2 TexCoords; + ${glsl.outputDeclaration} + const vec2 halfCR = vec2(0.5, 0.5); + + // Custom vector types to handle higher dimenalities. + struct ivec5 + { + int x; + int y; + int z; + int w; + int u; + }; + + struct ivec6 + { + int x; + int y; + int z; + int w; + int u; + int v; + }; + + int imod(int x, int y) { + return x - y * (x / y); + } + + `; +} +exports.getFragShaderPreamble = getFragShaderPreamble; +function getDefaultFragShaderMain(version, outputShapeLength) { + const glsl = getGlsl(version); + return ` + void main() { + int indices[${outputShapeLength}]; + toVec(TexCoords, indices); + vec4 result = vec4(process(indices)); + ${glsl.output} = result; + } + `; +} +exports.getDefaultFragShaderMain = getDefaultFragShaderMain; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/glsl-vec-lib.ts": +/*!***************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/glsl-vec-lib.ts ***! + \***************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.VecGlslLib = void 0; +const glsl_definitions_1 = __webpack_require__(/*! ./glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +/** + * GLSL Library responsible for vec routines + * Vec is an varible length int array. The length is fixed at the time of + * generating the library functions from the dimensions of the output. + */ +class VecGlslLib extends glsl_definitions_1.GlslLib { + constructor(context) { + super(context); + } + getCustomTypes() { + return {}; + } + getFunctions() { + return Object.assign(Object.assign(Object.assign(Object.assign({}, this.binaryVecFunctions()), this.copyVec()), this.setVecItem()), this.getVecItem()); + } + binaryVecFunctions() { + const outputLayout = this.context.outputTextureLayout; + const rank = outputLayout.shape.length; + const nameOp = { add: '+=', sub: '-=', mul: '*=', div: '/=' }; + const result = {}; + for (const name in nameOp) { + const fname = `${name}Vec`; + let assignmentBlock = ''; + for (let i = 0; i < rank; ++i) { + assignmentBlock += ` + dest[${i}] ${nameOp[name]} src[${i}]; + `; + } + const body = ` + void ${fname}(int src[${rank}], out int dest[${rank}]) { + ${assignmentBlock} + } + `; + result[fname] = new glsl_definitions_1.GlslLibRoutine(body); + } + return result; + } + copyVec() { + const outputLayout = this.context.outputTextureLayout; + const rank = outputLayout.shape.length; + let assignmentBlock = ''; + for (let i = 0; i < rank; ++i) { + assignmentBlock += ` + dest[${i}] = src[${i}]; + `; + } + const body = ` + void copyVec(int src[${rank}], out int dest[${rank}]) { + ${assignmentBlock} + } + `; + return { copyVec: new glsl_definitions_1.GlslLibRoutine(body) }; + } + setVecItem() { + const outputLayout = this.context.outputTextureLayout; + const rank = outputLayout.shape.length; + let block = ` + if(index < 0) + index =${rank} + index; + if (index == 0) + m[0] = value; + `; + for (let i = 1; i < rank - 1; ++i) { + block += ` + else if (index == ${i}) + m[${i}] = value; + `; + } + block += ` + else + m[${rank - 1}] = value; + `; + const body = ` + void setVecItem(out int m[${rank}], int index, int value) { + ${block} + } + `; + return { setVecItem: new glsl_definitions_1.GlslLibRoutine(body) }; + } + getVecItem() { + const outputLayout = this.context.outputTextureLayout; + const rank = outputLayout.shape.length; + let block = ` + if(index < 0) + index = ${rank} + index; + if (index == 0) + return m[0]; + `; + for (let i = 1; i < rank - 1; ++i) { + block += ` + else if (index == ${i}) + return m[${i}]; + `; + } + block += ` + else + return m[${rank - 1}]; + `; + const body = ` + int getVecItem(int m[${rank}], int index) { + ${block} + } + `; + return { getVecItem: new glsl_definitions_1.GlslLibRoutine(body) }; + } +} +exports.VecGlslLib = VecGlslLib; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/inference-handler.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/inference-handler.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.WebGLInferenceHandler = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +const tensor_1 = __webpack_require__(/*! ../../tensor */ "./lib/onnxjs/tensor.ts"); +const util_1 = __webpack_require__(/*! ../../util */ "./lib/onnxjs/util.ts"); +const pack_1 = __webpack_require__(/*! ./ops/pack */ "./lib/onnxjs/backends/webgl/ops/pack.ts"); +const reshape_packed_1 = __webpack_require__(/*! ./ops/reshape-packed */ "./lib/onnxjs/backends/webgl/ops/reshape-packed.ts"); +const uint8_encode_1 = __webpack_require__(/*! ./ops/uint8-encode */ "./lib/onnxjs/backends/webgl/ops/uint8-encode.ts"); +const unpack_1 = __webpack_require__(/*! ./ops/unpack */ "./lib/onnxjs/backends/webgl/ops/unpack.ts"); +const texture_layout_1 = __webpack_require__(/*! ./texture-layout */ "./lib/onnxjs/backends/webgl/texture-layout.ts"); +const types_1 = __webpack_require__(/*! ./types */ "./lib/onnxjs/backends/webgl/types.ts"); +const getProgramInfoUniqueKey = (programInfo, inputTextureDatas) => { + const inputs = inputTextureDatas.map(texture => `${texture.unpackedShape.join(',')};${texture.width}x${texture.height}`) + .join('_'); + let key = programInfo.name; + if (programInfo.cacheHint) { + key += '[' + programInfo.cacheHint + ']'; + } + key += ':' + inputs; + return key; +}; +class WebGLInferenceHandler { + constructor(session) { + this.session = session; + this.packedTextureDataCache = new Map(); + this.unpackedTextureDataCache = new Map(); + } + /** + * @returns [width, height] + */ + calculateTextureWidthAndHeight(shape, textureType) { + return (0, texture_layout_1.calculateTextureWidthAndHeight)(this.session.layoutStrategy, shape, textureType); + } + executeProgram(program, inputs) { + if (inputs.length < program.inputNames.length) { + throw new Error(`Input size mustn't be less than ${program.inputNames.length}.`); + } + if (program.inputNames.length !== program.inputTypes.length) { + throw new Error('input names size does not match input types'); + } + // create texture info for input + const inputTextureDatas = []; + for (let i = 0; i < program.inputNames.length; ++i) { + inputTextureDatas[i] = this.getOrCreateTextureData(inputs[i], program.inputTypes[i]); + } + const key = getProgramInfoUniqueKey(program, inputTextureDatas); + let artifact = this.session.programManager.getArtifact(key); + const programInfo = artifact ? + artifact.programInfo : + (typeof program.get === 'function' ? program.get() : + program); + // create texture info for output + const outputTextureLayout = (0, texture_layout_1.createTextureLayoutFromTextureType)(this.session.layoutStrategy, programInfo.output.dims, programInfo.output.textureType); + const outputTextureData = this.createTextureData(outputTextureLayout, programInfo.output.type); + if (!artifact) { + artifact = this.session.programManager.build(programInfo, inputTextureDatas, outputTextureData); + this.session.programManager.setArtifact(key, artifact); + } + this.runProgram(artifact, inputTextureDatas, outputTextureData); + return outputTextureData; + } + run(program, inputs) { + const outputTextureData = this.executeProgram(program, inputs); + return outputTextureData.tensor; + } + runProgram(artifact, inputs, output) { + // input should match + for (let i = 0; i < inputs.length; ++i) { + if (!!inputs[i].isPacked !== (artifact.programInfo.inputTypes[i] === types_1.TextureType.packed)) { + throw new Error(`input[${i}] property packed inconsistent`); + } + } + // output should match + if (!!output.isPacked !== (artifact.programInfo.output.textureType === types_1.TextureType.packed)) { + throw new Error('output property packed inconsistent'); + } + this.session.programManager.run(artifact, inputs, output); + } + /** + * Create a TextureData object from a tensor. + * Usage = Encoder.Usage.UploadOnly. + * If a related texture data is found in cache, returns it; + * Otherwise: + * Creates a new texture layout if not provided; + * Creates WebGLTexture with the layout; + * Upload tensor data to the texture; + * Creates a texture data object associated with the given tensor. + * @param tensor the tensor with data to upload + */ + getOrCreateTextureData(tensor, textureType) { + let td = this.getTextureData(tensor.dataId, textureType === types_1.TextureType.packed); + if (!td) { + // check if we have texture data in different type + td = this.getTextureData(tensor.dataId, textureType !== types_1.TextureType.packed); + if (td) { + if (textureType === types_1.TextureType.packed) { + return this.pack(td); + } + else { + return this.unpack(td); + } + } + } + if (!td) { + const layout = (0, texture_layout_1.createTextureLayoutFromTextureType)(this.session.layoutStrategy, tensor.dims, textureType); + if (textureType === types_1.TextureType.packedLastDimension) { + const group = 1; + const channels = 4; + const shape = tensor.dims; + if (shape.length === 4) { + // pre-processing for kernel data of Conv. + // + // TODO: currently this is a hacking to overwrite Conv's weight. The correct way to do this should be: + // 1. implement texture based const-folding + // 2. create a WebGL program "preprocessConvWeight" to do the same work as below + // 3. run the program before dotProduct. + // + const adjustedKernelShape = [shape[0], Math.ceil((shape[1] * shape[2] * shape[3]) / channels)]; + const adjustedLayout = (0, texture_layout_1.createTextureLayoutFromTextureType)(this.session.layoutStrategy, adjustedKernelShape, textureType); + let buffer = tensor.numberData; + if (shape[1] * shape[2] * shape[3] % channels !== 0) { + const numFeatureMaps = shape[0]; + const oldRowSize = shape[1] * shape[2] * shape[3]; + const newRowSize = Math.ceil(oldRowSize * group / channels) * channels; + const newSize = numFeatureMaps * newRowSize; + buffer = new Float32Array(newSize); + for (let f = 0; f < numFeatureMaps; ++f) { + const oldOffset = f * oldRowSize; + const newOffset = f * newRowSize + f % group * oldRowSize; + buffer.set(tensor.numberData.subarray(oldOffset, oldOffset + oldRowSize), newOffset); + } + } + return this.createTextureData(adjustedLayout, tensor.type, buffer, tensor, 1 /* Encoder.Usage.UploadOnly */); + } + } + if (textureType === types_1.TextureType.packed) { + const unpackedTextureLayout = (0, texture_layout_1.createTextureLayoutFromShape)(this.session.layoutStrategy, tensor.dims, 1, [], { reverseWH: true }); + const unpackedTextureData = this.createTextureData(unpackedTextureLayout, tensor.type, tensor.numberData, tensor, 1 /* Encoder.Usage.UploadOnly */); + td = this.pack(unpackedTextureData); + } + else { + td = this.createTextureData(layout, tensor.type, tensor.numberData, tensor, 1 /* Encoder.Usage.UploadOnly */); + } + } + return td; + } + /** + * Create a TextureData object using the given data and bind to the given tensor. + * Usage = Encoder.Usage.UploadOnly. + * NOTE: this function is a hack for Conv implementation. should remove this function, after rewriting Conv + * implementation by Graph.Transformer + * @param dataType the tensor data type + * @param data the actual data to upload + * @param tensor the tensor to bind. tensor's data is ignored. + */ + createTextureDataFromLayoutBindTensor(layout, dataType, data, tensor) { + return this.createTextureData(layout, dataType, data, tensor, 1 /* Encoder.Usage.UploadOnly */); + } + createTextureData(layout, dataType, data, tensor, usage) { + instrument_1.Logger.verbose('InferenceHandler', `Creating TextureData: layout:[${JSON.stringify(layout)}]`); + const texture = this.session.textureManager.createTextureFromLayout(dataType, layout, data, usage); + return this.createTextureDataFromTexture(layout, dataType, texture, tensor); + } + reshapeUnpacked(input, reshapedDims) { + const inputTD = this.getOrCreateTextureData(input, types_1.TextureType.unpacked); + const newTextureLayout = { + channels: inputTD.channels, + height: inputTD.height, + width: inputTD.width, + // handle reshaping into scalar Tensors + shape: reshapedDims.length !== 0 ? reshapedDims : [1], + strides: util_1.ShapeUtil.computeStrides(reshapedDims), + unpackedShape: reshapedDims, + }; + const newTextureData = this.createTextureDataFromTexture(newTextureLayout, input.type, inputTD.texture); + return newTextureData.tensor; + } + reshapePacked(input, reshapedDims) { + const inputTD = this.getOrCreateTextureData(input, types_1.TextureType.packed); + // check if the reshape is 'cheap' + if ((0, reshape_packed_1.isReshapeCheap)(input.dims, reshapedDims)) { + const newTextureLayout = { + channels: inputTD.channels, + height: inputTD.height, + width: inputTD.width, + // handle reshaping into scalar Tensors + shape: reshapedDims.length !== 0 ? reshapedDims : [1], + strides: util_1.ShapeUtil.computeStrides(reshapedDims), + unpackedShape: reshapedDims, + isPacked: true + }; + const newTextureData = this.createTextureDataFromTexture(newTextureLayout, input.type, inputTD.texture); + return newTextureData.tensor; + } + const squeezedInputShape = (0, reshape_packed_1.processDims3D)(input.dims); + const squeezedOutputShape = (0, reshape_packed_1.processDims3D)(reshapedDims); + const squeezedInputTensor = this.reshapePacked(input, squeezedInputShape); + const squeezedOutputTensor = this.run((0, reshape_packed_1.createPackedReshape3DProgramInfoLoader)(this, squeezedInputTensor, squeezedOutputShape), [squeezedInputTensor]); + const outputTensor = this.reshapePacked(squeezedOutputTensor, reshapedDims); + return outputTensor; + } + cast(input, type) { + const inputTD = this.getOrCreateTextureData(input, types_1.TextureType.unpacked); + const newTextureData = this.createTextureDataFromTexture(inputTD, type, inputTD.texture); + return newTextureData.tensor; + } + createTextureDataFromTexture(layout, dataType, texture, tensor, tensorId) { + const textureData = Object.assign(Object.assign({}, layout), { tensor: tensor || + new tensor_1.Tensor(layout.unpackedShape, dataType, (_id) => this.readTexture(textureData), async (_id) => this.readTextureAsync(textureData), undefined, tensorId), texture }); + this.setTextureData(textureData.tensor.dataId, textureData, layout.isPacked); + return textureData; + } + getTextureData(tensorId, isPacked = false) { + return this.session.isInitializer(tensorId) ? this.session.getTextureData(tensorId, isPacked) : + isPacked ? this.packedTextureDataCache.get(tensorId) : + this.unpackedTextureDataCache.get(tensorId); + } + setTextureData(tensorId, td, isPacked = false) { + if (this.session.isInitializer(tensorId)) { + this.session.setTextureData(tensorId, td, isPacked); + } + else { + (isPacked ? this.packedTextureDataCache : this.unpackedTextureDataCache).set(tensorId, td); + } + } + isTextureLayoutCached(tensor, isPacked = false) { + return !!this.getTextureData(tensor.dataId, isPacked); + } + dispose() { + this.session.textureManager.clearActiveTextures(); + this.packedTextureDataCache.forEach(td => this.session.textureManager.releaseTexture(td)); + this.packedTextureDataCache = new Map(); + this.unpackedTextureDataCache.forEach(td => this.session.textureManager.releaseTexture(td)); + this.unpackedTextureDataCache = new Map(); + } + readTexture(textureData) { + if (textureData.isPacked) { + return this.readTexture(this.unpack(textureData)); + } + if (!this.session.backend.glContext.isFloat32DownloadSupported) { + return this.session.textureManager.readUint8TextureAsFloat((0, uint8_encode_1.encodeAsUint8)(this, textureData)); + } + return this.session.textureManager.readTexture(textureData, textureData.tensor.type, textureData.channels); + } + async readTextureAsync(textureData) { + if (textureData.isPacked) { + return this.readTextureAsync(this.unpack(textureData)); + } + if (!this.session.backend.glContext.isFloat32DownloadSupported) { + return this.session.textureManager.readUint8TextureAsFloat((0, uint8_encode_1.encodeAsUint8)(this, textureData)); + } + return this.session.textureManager.readTextureAsync(textureData, textureData.tensor.type, textureData.channels); + } + pack(input) { + const outputTextureData = this.executeProgram((0, pack_1.createPackProgramInfoLoader)(this, input.tensor), [input.tensor]); + return outputTextureData; + } + unpack(input) { + const outputTextureData = this.executeProgram((0, unpack_1.createUnpackProgramInfoLoader)(this, input.tensor), [input.tensor]); + return outputTextureData; + } +} +exports.WebGLInferenceHandler = WebGLInferenceHandler; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/op-resolve-rules.ts": +/*!*******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/op-resolve-rules.ts ***! + \*******************************************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.WEBGL_OP_RESOLVE_RULES = void 0; +const batch_normalization_1 = __webpack_require__(/*! ./ops/batch-normalization */ "./lib/onnxjs/backends/webgl/ops/batch-normalization.ts"); +const binaryOps = __importStar(__webpack_require__(/*! ./ops/binary-op */ "./lib/onnxjs/backends/webgl/ops/binary-op.ts")); +const cast_1 = __webpack_require__(/*! ./ops/cast */ "./lib/onnxjs/backends/webgl/ops/cast.ts"); +const concat_1 = __webpack_require__(/*! ./ops/concat */ "./lib/onnxjs/backends/webgl/ops/concat.ts"); +const conv_1 = __webpack_require__(/*! ./ops/conv */ "./lib/onnxjs/backends/webgl/ops/conv.ts"); +const conv_transpose_1 = __webpack_require__(/*! ./ops/conv-transpose */ "./lib/onnxjs/backends/webgl/ops/conv-transpose.ts"); +const depth_to_space_1 = __webpack_require__(/*! ./ops/depth-to-space */ "./lib/onnxjs/backends/webgl/ops/depth-to-space.ts"); +const flatten_1 = __webpack_require__(/*! ./ops/flatten */ "./lib/onnxjs/backends/webgl/ops/flatten.ts"); +const gather_1 = __webpack_require__(/*! ./ops/gather */ "./lib/onnxjs/backends/webgl/ops/gather.ts"); +const gemm_1 = __webpack_require__(/*! ./ops/gemm */ "./lib/onnxjs/backends/webgl/ops/gemm.ts"); +const image_scaler_1 = __webpack_require__(/*! ./ops/image-scaler */ "./lib/onnxjs/backends/webgl/ops/image-scaler.ts"); +const instance_normalization_1 = __webpack_require__(/*! ./ops/instance-normalization */ "./lib/onnxjs/backends/webgl/ops/instance-normalization.ts"); +const matmul_1 = __webpack_require__(/*! ./ops/matmul */ "./lib/onnxjs/backends/webgl/ops/matmul.ts"); +const pad_1 = __webpack_require__(/*! ./ops/pad */ "./lib/onnxjs/backends/webgl/ops/pad.ts"); +const pool_1 = __webpack_require__(/*! ./ops/pool */ "./lib/onnxjs/backends/webgl/ops/pool.ts"); +const reduce_1 = __webpack_require__(/*! ./ops/reduce */ "./lib/onnxjs/backends/webgl/ops/reduce.ts"); +const reshape_1 = __webpack_require__(/*! ./ops/reshape */ "./lib/onnxjs/backends/webgl/ops/reshape.ts"); +const resize_packed_1 = __webpack_require__(/*! ./ops/resize-packed */ "./lib/onnxjs/backends/webgl/ops/resize-packed.ts"); +const shape_1 = __webpack_require__(/*! ./ops/shape */ "./lib/onnxjs/backends/webgl/ops/shape.ts"); +const slice_1 = __webpack_require__(/*! ./ops/slice */ "./lib/onnxjs/backends/webgl/ops/slice.ts"); +const softmax_1 = __webpack_require__(/*! ./ops/softmax */ "./lib/onnxjs/backends/webgl/ops/softmax.ts"); +const split_1 = __webpack_require__(/*! ./ops/split */ "./lib/onnxjs/backends/webgl/ops/split.ts"); +const squeeze_1 = __webpack_require__(/*! ./ops/squeeze */ "./lib/onnxjs/backends/webgl/ops/squeeze.ts"); +const sum_1 = __webpack_require__(/*! ./ops/sum */ "./lib/onnxjs/backends/webgl/ops/sum.ts"); +const tile_1 = __webpack_require__(/*! ./ops/tile */ "./lib/onnxjs/backends/webgl/ops/tile.ts"); +const transpose_1 = __webpack_require__(/*! ./ops/transpose */ "./lib/onnxjs/backends/webgl/ops/transpose.ts"); +const unaryOps = __importStar(__webpack_require__(/*! ./ops/unary-op */ "./lib/onnxjs/backends/webgl/ops/unary-op.ts")); +const unsqueeze_1 = __webpack_require__(/*! ./ops/unsqueeze */ "./lib/onnxjs/backends/webgl/ops/unsqueeze.ts"); +const upsample_1 = __webpack_require__(/*! ./ops/upsample */ "./lib/onnxjs/backends/webgl/ops/upsample.ts"); +exports.WEBGL_OP_RESOLVE_RULES = [ + ['Abs', '', '6+', unaryOps.abs], + ['Acos', '', '7+', unaryOps.acos], + ['Add', '', '7+', binaryOps.add], + ['And', '', '7+', binaryOps.and], + ['Asin', '', '7+', unaryOps.asin], + ['Atan', '', '7+', unaryOps.atan], + // TODO: support new attributes for AveragePool-10 + ['AveragePool', '', '7+', pool_1.averagePool, pool_1.parseAveragePoolAttributes], + ['BatchNormalization', '', '7+', batch_normalization_1.batchNormalization, batch_normalization_1.parseBatchNormalizationAttributes], + ['Cast', '', '6+', cast_1.cast, cast_1.parseCastAttributes], + ['Ceil', '', '6+', unaryOps.ceil], + ['Clip', '', '6-10', unaryOps.clip, unaryOps.parseClipAttributes], + ['Clip', '', '11+', unaryOps.clipV11], + ['Concat', '', '4+', concat_1.concat, concat_1.parseConcatAttributes], + ['Conv', '', '1+', conv_1.conv, conv_1.parseConvAttributes], + ['ConvTranspose', '', '1+', conv_transpose_1.convTranspose, conv_transpose_1.parseConvTransposeAttributes], + ['Cos', '', '7+', unaryOps.cos], + ['Div', '', '7+', binaryOps.div], + ['Dropout', '', '7+', unaryOps.identity], + ['DepthToSpace', '', '1+', depth_to_space_1.depthToSpace, depth_to_space_1.parseDepthToSpaceAttributes], + ['Equal', '', '7+', binaryOps.equal], + ['Elu', '', '6+', unaryOps.elu, unaryOps.parseEluAttributes], + ['Exp', '', '6+', unaryOps.exp], + ['Flatten', '', '1+', flatten_1.flatten, flatten_1.parseFlattenAttributes], + ['Floor', '', '6+', unaryOps.floor], + ['FusedConv', 'com.microsoft', '1+', conv_1.conv, conv_1.parseConvAttributes], + ['Gather', '', '1+', gather_1.gather, gather_1.parseGatherAttributes], + ['Gemm', '', '7-10', gemm_1.gemm, gemm_1.parseGemmAttributesV7], + ['Gemm', '', '11+', gemm_1.gemm, gemm_1.parseGemmAttributesV11], + ['GlobalAveragePool', '', '1+', pool_1.globalAveragePool, pool_1.parseGlobalAveragePoolAttributes], + ['GlobalMaxPool', '', '1+', pool_1.globalMaxPool], + ['Greater', '', '7+', binaryOps.greater], + ['Identity', '', '1+', unaryOps.identity], + ['ImageScaler', '', '1+', image_scaler_1.imageScaler, image_scaler_1.parseImageScalerAttributes], + ['InstanceNormalization', '', '6+', instance_normalization_1.instanceNormalization, instance_normalization_1.parseInstanceNormalizationAttributes], + ['LeakyRelu', '', '6+', unaryOps.leakyRelu, unaryOps.parseLeakyReluAttributes], + ['Less', '', '7+', binaryOps.less], + ['Log', '', '6+', unaryOps.log], + ['MatMul', '', '1+', matmul_1.matMul, matmul_1.parseMatMulAttributes], + // TODO: support new attributes for MaxPool-8 and MaxPool-10 + ['MaxPool', '', '1+', pool_1.maxPool, pool_1.parseMaxPoolAttributes], + ['Mul', '', '7+', binaryOps.mul], + ['Neg', '', '6+', unaryOps.neg], + ['Not', '', '1+', unaryOps.not], + ['Or', '', '7+', binaryOps.or], + ['Pad', '', '2-10', pad_1.padV2, pad_1.parsePadAttributesV2], + ['Pad', '', '11+', pad_1.padV11, pad_1.parsePadAttributesV11], + ['Pow', '', '7+', binaryOps.pow], + ['PRelu', '', '7+', binaryOps.pRelu], + ['ReduceLogSum', '', '1+', reduce_1.reduceLogSum, reduce_1.parseReduceAttributes], + ['ReduceMax', '', '1+', reduce_1.reduceMax, reduce_1.parseReduceAttributes], + ['ReduceMean', '', '1+', reduce_1.reduceMean, reduce_1.parseReduceAttributes], + ['ReduceMin', '', '1+', reduce_1.reduceMin, reduce_1.parseReduceAttributes], + ['ReduceProd', '', '1+', reduce_1.reduceProd, reduce_1.parseReduceAttributes], + ['ReduceSum', '', '1-12', reduce_1.reduceSum, reduce_1.parseReduceAttributes], + ['ReduceSumSquare', '', '1+', reduce_1.reduceLogSumSquare, reduce_1.parseReduceAttributes], + ['Relu', '', '6+', unaryOps.relu], + ['Reshape', '', '5+', reshape_1.reshape], + ['Resize', '', '10', resize_packed_1.resize, resize_packed_1.parseResizeAttributesV10], + ['Resize', '', '11+', resize_packed_1.resize, resize_packed_1.parseResizeAttributesV11], + ['Shape', '', '1+', shape_1.shape], + ['Sigmoid', '', '6+', unaryOps.sigmoid], + ['Sin', '', '7+', unaryOps.sin], + ['Slice', '', '10+', slice_1.sliceV10], + ['Slice', '', '1-9', slice_1.slice, slice_1.parseSliceAttributes], + // The "semantic" meaning of axis has changed in opset-13. + ['Softmax', '', '1-12', softmax_1.softmax, softmax_1.parseSoftmaxAttributes], + ['Softmax', '', '13+', softmax_1.softmaxV13, softmax_1.parseSoftmaxAttributesV13], + // 'Split' operator has an optional attribute 'split' + // this attribute determines how the specified axis of input data is split. + // When the attribute is missing, we need the count of number of outputs + // so that we can determine the 'split' attribute from the runtime input to the Operator + ['Split', '', '2-12', split_1.split, split_1.parseSplitAttributes], + ['Sqrt', '', '6+', unaryOps.sqrt], + ['Squeeze', '', '1-12', squeeze_1.squeeze, squeeze_1.parseSqueezeAttributes], + ['Squeeze', '', '13+', squeeze_1.squeezeV13], + ['Sub', '', '7+', binaryOps.sub], + ['Sum', '', '6+', sum_1.sum], + ['Tan', '', '7+', unaryOps.tan], + ['Tanh', '', '6+', unaryOps.tanh], + ['Tile', '', '6+', tile_1.tile], + ['Transpose', '', '1+', transpose_1.transpose, transpose_1.parseTransposeAttributes], + ['Upsample', '', '7-8', upsample_1.upsample, upsample_1.parseUpsampleAttributesV7], + ['Upsample', '', '9', upsample_1.upsample, upsample_1.parseUpsampleAttributesV9], + ['Unsqueeze', '', '1-12', unsqueeze_1.unsqueeze, unsqueeze_1.parseUnsqueezeAttributes], + ['Unsqueeze', '', '13+', unsqueeze_1.unsqueezeV13], + ['Xor', '', '7+', binaryOps.xor], +]; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/batch-normalization.ts": +/*!**************************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/batch-normalization.ts ***! + \**************************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseBatchNormalizationAttributes = exports.batchNormalization = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const batchNormalizationProgramMetadata = { + name: 'BatchNormalization', + inputNames: ['A', 'Scale', 'B', 'Mean', 'Variance'], + inputTypes: [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked] +}; +const batchNormalization = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, batchNormalizationProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createBatchNormalizationProgramInfo(inferenceHandler, inputs, attributes) }), inputs); + return [output]; +}; +exports.batchNormalization = batchNormalization; +const parseBatchNormalizationAttributes = (node) => { + const epsilon = node.attributes.getFloat('epsilon', 1e-5); + const momentum = node.attributes.getFloat('momentum', 0.9); + const spatial = node.attributes.getInt('spatial', 1); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ epsilon, momentum, spatial }); +}; +exports.parseBatchNormalizationAttributes = parseBatchNormalizationAttributes; +const createBatchNormalizationProgramInfo = (inferenceHandler, inputs, attributes) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const rank = inputs[0].dims.length; + const [scaleWidth, scaleHeight] = inferenceHandler.calculateTextureWidthAndHeight(inputs[1].dims, types_1.TextureType.unpacked); + const shaderSource = ` + float process(int[${rank}] indices) { + vec2 position = offsetToCoords(indices[1], ${scaleWidth}, ${scaleHeight}); + float scale = getColorAsFloat(${glsl.texture2D}(Scale, position)); + float mean = getColorAsFloat(${glsl.texture2D}(Mean, position)); + float variance = getColorAsFloat(${glsl.texture2D}(Variance, position)); + float b = getColorAsFloat(${glsl.texture2D}(B, position)); + + return scale * ( (_A(indices) - mean) / sqrt(variance + float(${attributes.epsilon})) ) + b; + }`; + return Object.assign(Object.assign({}, batchNormalizationProgramMetadata), { output: { dims: inputs[0].dims, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 5) { + throw new Error('BatchNormalization requires 5 inputs.'); + } + const X = inputs[0]; + const scale = inputs[1]; + const B = inputs[2]; + const mean = inputs[3]; + const var_ = inputs[4]; + // input should atleast have three dimensions - N,C,dim1,...,dimn + // other inputs can have only one dimensions + if (X.dims.length < 3 || scale.dims.length !== 1 || B.dims.length !== 1 || mean.dims.length !== 1 || + var_.dims.length !== 1) { + throw new Error('invalid input shape.'); + } + if (scale.dims[0] !== X.dims[1] || B.dims[0] !== X.dims[1] || mean.dims[0] !== X.dims[1] || + var_.dims[0] !== X.dims[1]) { + throw new Error('invalid input shape.'); + } + if ((X.type !== 'float32' && X.type !== 'float64') || (scale.type !== 'float32' && scale.type !== 'float64') || + (B.type !== 'float32' && B.type !== 'float64') || (mean.type !== 'float32' && mean.type !== 'float64') || + (var_.type !== 'float32' && var_.type !== 'float64')) { + throw new Error('invalid input tensor types.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/binary-op.ts": +/*!****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/binary-op.ts ***! + \****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.xor = exports.sub = exports.pRelu = exports.pow = exports.or = exports.mul = exports.less = exports.greater = exports.equal = exports.div = exports.and = exports.add = exports.glslPRelu = exports.glslPow = exports.glslXor = exports.glslOr = exports.glslAnd = exports.glslLess = exports.glslGreater = exports.glslEqual = exports.glslSub = exports.glslMul = exports.glslDiv = exports.glslAdd = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_definitions_1 = __webpack_require__(/*! ../glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +function glslAdd() { + const name = 'add_'; + const body = ` + float ${name}(float a, float b) { + return a + b; + } + vec4 ${name}(vec4 v1, vec4 v2) { + return v1 + v2; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslAdd = glslAdd; +function glslDiv() { + const name = 'div_'; + const body = ` + float ${name}(float a, float b) { + return a / b; + } + vec4 ${name}(vec4 v1, vec4 v2) { + return v1 / v2; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslDiv = glslDiv; +function glslMul() { + const name = 'mul_'; + const body = ` + float ${name}(float a, float b) { + return a * b; + } + vec4 ${name}(vec4 v1, vec4 v2) { + return v1 * v2; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslMul = glslMul; +function glslSub() { + const name = 'sub_'; + const body = ` + float ${name}(float a, float b) { + return a - b; + } + vec4 ${name}(vec4 v1, vec4 v2) { + return v1 - v2; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslSub = glslSub; +function glslEqual() { + const name = 'equal_'; + const body = ` + float ${name}(float a, float b) { + return float(a == b); + } + vec4 ${name}(vec4 v1, vec4 v2) { + return vec4(equal(v1, v2)); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslEqual = glslEqual; +function glslGreater() { + const name = 'greater_'; + const body = ` + float ${name}(float a, float b) { + return float(a > b); + } + vec4 ${name}(vec4 v1, vec4 v2) { + return vec4( v1.r > v2.r , + v1.g > v2.g, + v1.b > v2.b, + v1.a > v2.a ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslGreater = glslGreater; +function glslLess() { + const name = 'less_'; + const body = ` + float ${name}(float a, float b) { + return float(a < b); + } + vec4 ${name}(vec4 v1, vec4 v2) { + return vec4( v1.r < v2.r , + v1.g < v2.g, + v1.b < v2.b, + v1.a < v2.a ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslLess = glslLess; +function glslAnd() { + const name = 'and_'; + const body = ` + float ${name}(float a, float b) { + return float( bool(a) && bool(b) ); + } + vec4 ${name}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r && b2.r , + b1.g && b2.g, + b1.b && b2.b, + b1.a && b2.a ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslAnd = glslAnd; +function glslOr() { + const name = 'or_'; + const body = ` + float ${name}(float a, float b) { + return float( bool(a) || bool(b) ); + } + vec4 ${name}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r || b2.r , + b1.g || b2.g, + b1.b || b2.b, + b1.a || b2.a ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslOr = glslOr; +function glslXor() { + const name = 'xor_'; + const body = ` + float ${name}(float a, float b) { + return float( bool(a) ^^ bool(b) ); + } + vec4 ${name}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r ^^ b2.r , + b1.g ^^ b2.g, + b1.b ^^ b2.b, + b1.a ^^ b2.a ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslXor = glslXor; +function glslPow() { + return glslBuiltinBinary('pow'); +} +exports.glslPow = glslPow; +function glslPRelu() { + const name = 'prelu_'; + const body = ` + float ${name}(float a, float b) { + return a < 0.0 ? a * b: a; + } + vec4 ${name}(vec4 v1, vec4 v2) { + return vec4( + v1.r < 0.0 ? v1.r * v2.r: v1.r, + v1.g < 0.0 ? v1.g * v2.g: v1.g, + v1.b < 0.0 ? v1.b * v2.b: v1.b, + v1.a < 0.0 ? v1.a * v2.a: v1.a + ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslPRelu = glslPRelu; +function glslBuiltinBinary(fname) { + const name = `${fname}_`; + const body = ` + float ${name}(float a, float b) { + return ${fname}(a, b); + } + vec4 ${name}(vec4 v1, vec4 v2) { + return ${fname}(v1, v2); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +const createBinaryProgramInfoLoader = (handler, inputs, glslFunc, outputTensorType = inputs[0].type, cacheKey) => { + const textureType = handler.session.pack ? types_1.TextureType.packed : types_1.TextureType.unpacked; + return { + name: glslFunc.name, + inputNames: ['A', 'B'], + inputTypes: [textureType, textureType], + cacheHint: cacheKey, + get: () => createBinaryProgramInfo(handler, inputs, glslFunc, outputTensorType) + }; +}; +const createBinaryProgramInfo = (handler, inputs, glslFunc, outputTensorType = inputs[0].type) => { + const textureType = handler.session.pack ? types_1.TextureType.packed : types_1.TextureType.unpacked; + const isBroadcast = !util_1.ShapeUtil.areEqual(inputs[0].dims, inputs[1].dims); + let outputShape = inputs[0].dims; + const usePackedTexture = handler.session.pack; + if (isBroadcast) { + const calculatedShape = util_1.BroadcastUtil.calcShape(inputs[0].dims, inputs[1].dims, false); + if (!calculatedShape) { + throw new Error('Can\'t perform binary op on the given tensors'); + } + outputShape = calculatedShape; + const outputRank = outputShape.length; + const aRank = inputs[0].dims.length !== 0 ? inputs[0].dims.length : 1; + const bRank = inputs[1].dims.length !== 0 ? inputs[1].dims.length : 1; + const aBcast = inputs[0].dims.length !== 0 ? 'bcastIndices_A(indices, aindices);' : 'aindices[0] = 0;'; + const bBcast = inputs[1].dims.length !== 0 ? 'bcastIndices_B(indices, bindices);' : 'bindices[0] = 0;'; + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const shaderSource = usePackedTexture ? ` + ${glslFunc.body} + void main() { + vec4 a = getAAtOutCoords(); + vec4 b = getBAtOutCoords(); + vec4 result = ${glslFunc.name}(a, b); + ${glsl.output} = result; + }` : + ` + ${glslFunc.body} + float process(int indices[${outputRank}]) { + int aindices[${aRank}]; + int bindices[${bRank}]; + ${aBcast} + ${bBcast} + return ${glslFunc.name}(_A(aindices), _B(bindices)); + }`; + return { + name: glslFunc.name, + inputNames: ['A', 'B'], + inputTypes: [textureType, textureType], + output: { dims: outputShape, type: outputTensorType, textureType }, + shaderSource, + hasMain: usePackedTexture + }; + } + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const shaderSource = ` + ${glslFunc.body} + void main() { + vec4 v1 = ${glsl.texture2D}(A, TexCoords); + vec4 v2 = ${glsl.texture2D}(B, TexCoords); + vec4 result = ${glslFunc.name}(v1, v2); + ${glsl.output} = result; + } + `; + return { + name: glslFunc.name, + inputNames: ['A', 'B'], + inputTypes: [textureType, textureType], + output: { dims: inputs[0].dims, type: outputTensorType, textureType }, + shaderSource, + hasMain: true + }; +}; +const add = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslAdd()), inputs)]; +exports.add = add; +const and = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslAnd(), 'bool'), inputs)]; +exports.and = and; +const div = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslDiv()), inputs)]; +exports.div = div; +const equal = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslEqual(), 'bool'), inputs)]; +exports.equal = equal; +const greater = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslGreater(), 'bool'), inputs)]; +exports.greater = greater; +const less = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslLess(), 'bool'), inputs)]; +exports.less = less; +const mul = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslMul()), inputs)]; +exports.mul = mul; +const or = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslOr(), 'bool'), inputs)]; +exports.or = or; +const pow = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslPow()), inputs)]; +exports.pow = pow; +const pRelu = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslPRelu()), inputs)]; +exports.pRelu = pRelu; +const sub = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslSub()), inputs)]; +exports.sub = sub; +const xor = (handler, inputs) => [handler.run(createBinaryProgramInfoLoader(handler, inputs, glslXor(), 'bool'), inputs)]; +exports.xor = xor; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/cast.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/cast.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseCastAttributes = exports.cast = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const cast = (handler, inputs, to) => { + validateInputs(inputs); + return [handler.cast(inputs[0], to)]; +}; +exports.cast = cast; +const parseCastAttributes = (node) => util_1.ProtoUtil.tensorDataTypeFromProto(node.attributes.getInt('to')); +exports.parseCastAttributes = parseCastAttributes; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Cast requires 1 input.'); + } + if (inputs[0].type === 'string') { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/concat-packed.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/concat-packed.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createPackedConcatProgramInfoLoader = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const createPackedConcatProgramMetadata = (inputCount, cacheHint) => ({ + name: 'Concat (packed)', + inputNames: Array.from({ length: inputCount }, (v, i) => `X${i}`), + inputTypes: Array(inputCount).fill(types_1.TextureType.packed), + cacheHint +}); +const createPackedConcatProgramInfo = (handler, metadata, inputs, axis) => { + const inputShape = inputs[0].dims.slice(); + if (axis >= inputShape.length || axis < (-1 * inputShape.length)) { + throw new Error('axis specified for concat doesn\'t match input dimensionality'); + } + if (axis < 0) { + axis = inputShape.length + axis; + } + // ensure all of the non-concatenated axes match each other + // calculate the shape of the output tensor while we do that + const outputShape = inputShape.slice(0); + for (let i = 1; i < inputs.length; i++) { + const dataNShape = inputs[i].dims.slice(); + for (let axisIndex = 0; axisIndex < inputShape.length; axisIndex++) { + // add to the placeholder for computing output shape + if (axisIndex === axis) { + outputShape[axis] += dataNShape[axisIndex]; + } + // ensure all non-cancatenated axes match each other + else if (inputShape[axisIndex] !== dataNShape[axisIndex]) { + throw new Error('non concat dimensions must match'); + } + } + } + const rank = outputShape.length; + const coords = (0, packing_utils_1.getChannels)('coords', rank); + const dtype = (0, utils_1.getCoordsDataType)(rank); + const unpackChannel = (0, packing_utils_1.unpackFromChannel)(); + const shapes = inputs.map(i => i.dims); + const channels = (0, utils_1.getGlChannels)(rank); + const offsets = new Array(shapes.length - 1); + offsets[0] = shapes[0][axis]; + for (let i = 1; i < offsets.length; i++) { + offsets[i] = offsets[i - 1] + shapes[i][axis]; + } + const channel = channels[axis]; + const lastChannels = channels.slice(-2); + const allChannels = channels.join(); + let getValueSnippet = `if (${channel} < ${offsets[0]}) { + return getChannel( + getX0(${allChannels}), vec2(${lastChannels.join()})); + }`; + for (let i = 1; i < offsets.length; i++) { + const shift = offsets[i - 1]; + getValueSnippet += ` + if (${channel} < ${offsets[i]} && ${channel} >= ${offsets[i - 1]}) { + return getChannel( + getX${i}(${getShiftedChannelsSnippet(channels, channel, shift)}), + vec2(${getShiftedChannelsSnippet(lastChannels, channel, shift)})); + }`; + } + const lastIndex = offsets.length; + const shift = offsets[offsets.length - 1]; + getValueSnippet += ` + return getChannel( + getX${lastIndex}(${getShiftedChannelsSnippet(channels, channel, shift)}), + vec2(${getShiftedChannelsSnippet(lastChannels, channel, shift)}));`; + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const shaderSource = ` + ${unpackChannel} + float getValue(${channels.map(x => 'int ' + x)}) { + ${getValueSnippet} + } + + void main() { + ${dtype} coords = getOutputCoords(); + int lastDim = coords.${channels[rank - 1]}; + coords.${channels[rank - 1]} = coords.${channels[rank - 2]}; + coords.${channels[rank - 2]} = lastDim; + + vec4 result = vec4(getValue(${coords}), 0., 0., 0.); + + ${coords[rank - 1]} = ${coords[rank - 1]} + 1; + if (${coords[rank - 1]} < ${outputShape[rank - 1]}) { + result.g = getValue(${coords}); + } + + ${coords[rank - 2]} = ${coords[rank - 2]} + 1; + if (${coords[rank - 2]} < ${outputShape[rank - 2]}) { + result.a = getValue(${coords}); + } + + ${coords[rank - 1]} = ${coords[rank - 1]} - 1; + if (${coords[rank - 2]} < ${outputShape[rank - 2]} && + ${coords[rank - 1]} < ${outputShape[rank - 1]}) { + result.b = getValue(${coords}); + } + ${glsl.output} = result; + } + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.packed }, shaderSource, hasMain: true }); +}; +const createPackedConcatProgramInfoLoader = (handler, inputs, attributes) => { + const metadata = createPackedConcatProgramMetadata(inputs.length, attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createPackedConcatProgramInfo(handler, metadata, inputs, attributes.axis) }); +}; +exports.createPackedConcatProgramInfoLoader = createPackedConcatProgramInfoLoader; +const getShiftedChannelsSnippet = (channels, channel, shift) => { + const channelIdx = channels.indexOf(channel); + const res = channels.map((c, idx) => { + if (idx === channelIdx) { + return `${c} - ${shift}`; + } + else { + return c; + } + }); + return res.join(); +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/concat.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/concat.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseConcatAttributes = exports.concat = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const concat_packed_1 = __webpack_require__(/*! ./concat-packed */ "./lib/onnxjs/backends/webgl/ops/concat-packed.ts"); +const concat = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + if (inferenceHandler.session.pack && inputs[0].dims.length > 1) { + const output = inferenceHandler.run((0, concat_packed_1.createPackedConcatProgramInfoLoader)(inferenceHandler, inputs, attributes), inputs); + return [output]; + } + else { + const output = inferenceHandler.run(createUnpackedConcatProgramInfoLoader(inferenceHandler, inputs, attributes), inputs); + return [output]; + } +}; +exports.concat = concat; +const createUnpackedConcatProgramMetadata = (inputCount, cacheHint) => ({ + name: 'Concat', + inputNames: Array.from({ length: inputCount }, (v, i) => `X${i}`), + inputTypes: Array(inputCount).fill(types_1.TextureType.unpacked), + cacheHint +}); +const createUnpackedConcatProgramInfo = (handler, metadata, inputs, axis) => { + const inputShape = inputs[0].dims.slice(); + if (axis >= inputShape.length || axis < (-1 * inputShape.length)) { + throw new Error('axis specified for concat doesn\'t match input dimensionality'); + } + if (axis < 0) { + axis = inputShape.length + axis; + } + // ensure all of the non-concatenated axes match each other + // calculate the shape of the output tensor while we do that + const outputShape = inputShape.slice(0); + for (let i = 1; i < inputs.length; i++) { + const dataNShape = inputs[i].dims.slice(); + for (let axisIndex = 0; axisIndex < inputShape.length; axisIndex++) { + // add to the placeholder for computing output shape + if (axisIndex === axis) { + outputShape[axis] += dataNShape[axisIndex]; + } + // ensure all non-cancatenated axes match each other + else if (inputShape[axisIndex] !== dataNShape[axisIndex]) { + throw new Error('non concat dimensions must match'); + } + } + } + const rank = outputShape.length; + const sizeInConcatAxis = new Array(inputs.length); + let previousSum = 0; + for (let i = 0; i < sizeInConcatAxis.length; ++i) { + previousSum += inputs[i].dims[axis]; + sizeInConcatAxis[i] = previousSum; + } + let getTextureIndexWhereDataResidesMethod = ''; + // in most cases linear search is sufficient, as in most scenarios, only 2 tensors are concatenated + if (inputs.length < 5) { + getTextureIndexWhereDataResidesMethod = getTextureIndexWhereDataResidesLinearSearch(sizeInConcatAxis); + } + else { + getTextureIndexWhereDataResidesMethod = getTextureIndexWhereDataResidesBinarySearch(sizeInConcatAxis); + } + const fetchDataFromCorrectTextureMethod = getFetchDataFromCorrectTextureMethod(inputs.length, rank); + const getSizeInConcatAxisValueFromIndexMethod = getGetSizeInConcatAxisValueFromIndexMethod(sizeInConcatAxis); + const shaderSource = ` + ${fetchDataFromCorrectTextureMethod} + ${getSizeInConcatAxisValueFromIndexMethod} + ${getTextureIndexWhereDataResidesMethod} + float process(int indices[${rank}]) { + int textureIndex = getTextureWhereDataResides (indices[${axis}]); + + if(textureIndex != 0) { + indices[${axis}] = indices[${axis}] - int(getSizeInConcatAxisValueFromIndex(textureIndex-int(1))); + } + + return fetchDataFromCorrectTexture(textureIndex, indices); + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const createUnpackedConcatProgramInfoLoader = (handler, inputs, attributes) => { + const metadata = createUnpackedConcatProgramMetadata(inputs.length, attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createUnpackedConcatProgramInfo(handler, metadata, inputs, attributes.axis) }); +}; +const getTextureIndexWhereDataResidesLinearSearch = (sizeInConcatAxis) => { + const searchAxis = sizeInConcatAxis.map((size, i) => `if(index<${size}) {return ${i};} +`); + return `int getTextureWhereDataResides(int index) { + ${searchAxis.join('')} + }`; +}; +// TODO: Implement BinarySearch in GLSL +const getTextureIndexWhereDataResidesBinarySearch = (sizeInConcatAxis) => getTextureIndexWhereDataResidesLinearSearch(sizeInConcatAxis); +const getFetchDataFromCorrectTextureMethod = (numberOfTensors, tensorRank) => { + const codeLines = [`float fetchDataFromCorrectTexture(int textureIndex, int indices[${tensorRank}]) {`]; + for (let i = 0; i < numberOfTensors; ++i) { + if (i === 0) { + codeLines.push('\t' + + `if (textureIndex == ${i}) { return _X${i}(indices); }`); + } + else if (i === numberOfTensors - 1) { + codeLines.push('\t' + + `else { return _X${i}(indices); }`); + } + else { + codeLines.push('\t' + + `else if (textureIndex == ${i}) { return _X${i}(indices); }`); + } + } + codeLines.push('\t' + + '}'); + return codeLines.join('\n'); +}; +const getGetSizeInConcatAxisValueFromIndexMethod = (sizeInConcatAxis) => { + const codeLines = ['int getSizeInConcatAxisValueFromIndex(int index) {']; + for (let i = 0; i < sizeInConcatAxis.length; ++i) { + if (i === 0) { + codeLines.push('\t' + + `if (index == ${i}) { return ${sizeInConcatAxis[i]}; }`); + } + else if (i === sizeInConcatAxis.length - 1) { + codeLines.push('\t' + + `else { return ${sizeInConcatAxis[i]}; }`); + } + else { + codeLines.push('\t' + + `else if (index == ${i}) { return ${sizeInConcatAxis[i]}; }`); + } + } + codeLines.push('\t' + + '}'); + return codeLines.join('\n'); +}; +const parseConcatAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axis: node.attributes.getInt('axis') }); +exports.parseConcatAttributes = parseConcatAttributes; +const validateInputs = (inputs) => { + if (!inputs || inputs.length < 1) { + throw new Error('too few inputs'); + } + const inputType = inputs[0].type; + const inputDimensionality = inputs[0].dims.length; + // TODO: Support string concat + if (inputType === 'string') { + throw new Error('string tensor is not supported yet'); + } + for (const input of inputs) { + // make sure types of all inputs match + if (input.type !== inputType) { + throw new Error('input tensors should be one type'); + } + // make sure the dimensionality of all inputs are the same + if (input.dims.length !== inputDimensionality) { + throw new Error('input tensors should have the same shape'); + } + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/conv-grouped.ts": +/*!*******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/conv-grouped.ts ***! + \*******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createUnpackedGroupedConvProgramInfoLoader = void 0; +const instrument_1 = __webpack_require__(/*! ../../../instrument */ "./lib/onnxjs/instrument.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const conv_1 = __webpack_require__(/*! ./conv */ "./lib/onnxjs/backends/webgl/ops/conv.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const createUnpackedGroupedConvProgramMetadata = (hasBias, cacheHint) => ({ + name: 'GroupedConv', + inputNames: hasBias ? ['X', 'W', 'Bias'] : ['X', 'W'], + inputTypes: hasBias ? [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked] : + [types_1.TextureType.unpacked, types_1.TextureType.unpacked], + cacheHint +}); +const createUnpackedGroupedConvProgramInfo = (inferenceHandler, inputs, metadata, attributes) => { + const hasBias = inputs.length > 2; + const processBias = hasBias ? 'value += getBias(output_channel);' : ''; + const xShape = inputs[0].dims.slice(); + const wShape = inputs[1].dims.slice(); + const outputChannelsPerGroup = wShape[0] / attributes.group; + instrument_1.Logger.verbose('GroupedConv', `autpPad:${attributes.autoPad}, dilations:${attributes.dilations}, group:${attributes.group}, kernelShape:${attributes.kernelShape}, pads:${attributes.pads}, strides:${attributes.strides}`); + const outputShape = (0, conv_1.calculateOutputShape)(xShape, wShape, attributes.dilations, attributes.pads, attributes.strides); + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const { activationFunction, applyActivation } = (0, fuse_utils_1.getActivationSnippet)(attributes); + const shaderSource = ` + const ivec2 strides = ivec2(${attributes.strides[0]}, ${attributes.strides[1]}); + const ivec2 pads = ivec2(${attributes.pads[0]}, ${attributes.pads[1]}); + ${activationFunction} + void main() { + ivec4 coords = getOutputCoords(); + int batch = coords.x; + int output_channel = coords.y; + ivec2 xRCCorner = coords.zw * strides - pads; + int group_id = output_channel / ${outputChannelsPerGroup}; + + float value = 0.0; + for (int wInChannel = 0; wInChannel < ${wShape[1]}; wInChannel++) { + int input_channel = group_id * ${wShape[1]} + wInChannel; + for (int wHeight = 0; wHeight < ${wShape[2]}; wHeight++) { + int xHeight = xRCCorner.x + wHeight * ${attributes.dilations[0]}; + + if (xHeight < 0 || xHeight >= ${xShape[2]}) { + continue; + } + + for (int wWidth = 0; wWidth < ${wShape[3]}; wWidth++) { + int xWidth = xRCCorner.y + wWidth * ${attributes.dilations[1]}; + if (xWidth < 0 || xWidth >= ${xShape[3]}) { + continue; + } + + float xVal = getX(batch, input_channel, xWidth, xHeight); + float wVal = getW(output_channel, wInChannel, wWidth, wHeight); + value += xVal*wVal; + } + } + } + ${processBias} + ${applyActivation} + ${glsl.output} = vec4(value, .0, .0, .0); + } +`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource, hasMain: true }); +}; +const createUnpackedGroupedConvProgramInfoLoader = (inferenceHandler, inputs, attributes) => { + const metadata = createUnpackedGroupedConvProgramMetadata(inputs.length > 2, attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createUnpackedGroupedConvProgramInfo(inferenceHandler, inputs, metadata, attributes) }); +}; +exports.createUnpackedGroupedConvProgramInfoLoader = createUnpackedGroupedConvProgramInfoLoader; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/conv-pack.ts": +/*!****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/conv-pack.ts ***! + \****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.conv2DPacked = exports.conv2DPackedPointwise = void 0; +const conv_1 = __webpack_require__(/*! ./conv */ "./lib/onnxjs/backends/webgl/ops/conv.ts"); +const im2col_pack_1 = __webpack_require__(/*! ./im2col-pack */ "./lib/onnxjs/backends/webgl/ops/im2col-pack.ts"); +const matmul_pack_1 = __webpack_require__(/*! ./matmul-pack */ "./lib/onnxjs/backends/webgl/ops/matmul-pack.ts"); +const conv2DPackedPointwise = (inferenceHandler, inputs, attributes) => { + const xshape = inputs[0].dims; + const kshape = inputs[1].dims; + const outputShape = (0, conv_1.calculateOutputShape)(xshape, kshape, attributes.dilations, attributes.pads, attributes.strides); + const reshapedX = inferenceHandler.reshapePacked(inputs[0], [xshape[1], xshape[2] * xshape[3]]); + const reshapedK = inferenceHandler.reshapePacked(inputs[1], [kshape[0], kshape[1]]); + const matmulInputs = inputs.length > 2 ? [reshapedK, reshapedX, inputs[2]] : [reshapedK, reshapedX]; + const matmulOutput = inferenceHandler.run((0, matmul_pack_1.createPackedMatmulProgramInfoLoader)(inferenceHandler, matmulInputs, attributes), matmulInputs); + return inferenceHandler.reshapePacked(matmulOutput, outputShape); +}; +exports.conv2DPackedPointwise = conv2DPackedPointwise; +const conv2DPacked = (inferenceHandler, inputs, attributes) => { + const xshape = inputs[0].dims; + const kshape = inputs[1].dims; + const outputShape = (0, conv_1.calculateOutputShape)(xshape, kshape, attributes.dilations, attributes.pads, attributes.strides); + // run im2col + const im2colOutput = inferenceHandler.run((0, im2col_pack_1.createPackedIm2ColProgramInfoLoader)(inferenceHandler, inputs[0], inputs[1], outputShape, attributes), [inputs[0]]); + // reshape kernel + const kernelReshaped = inferenceHandler.reshapePacked(inputs[1], [kshape[0], kshape[1] * kshape[2] * kshape[3]]); + // run matmul + const matmulInputs = (inputs.length === 3) ? [kernelReshaped, im2colOutput, inputs[2]] : [kernelReshaped, im2colOutput]; + const matmulOutput = inferenceHandler.run((0, matmul_pack_1.createPackedMatmulProgramInfoLoader)(inferenceHandler, matmulInputs, attributes), matmulInputs); + // reshape output + const outputReshaped = inferenceHandler.reshapePacked(matmulOutput, outputShape); + return outputReshaped; +}; +exports.conv2DPacked = conv2DPacked; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/conv-transpose.ts": +/*!*********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/conv-transpose.ts ***! + \*********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseConvTransposeAttributes = exports.convTranspose = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const computeTotalPad = (inDim, stride, adj, kernel, dilation, outSize) => (inDim - 1) * stride + adj + (kernel - 1) * dilation + 1 - outSize; +const distributePadding = (totalPad, autoPad, pads, head, tail) => { + const smallPad = Math.floor(totalPad / 2); + if (autoPad === 'SAME_UPPER') { + pads[head] = smallPad; + pads[tail] = totalPad - smallPad; + } + else if (autoPad === 'SAME_LOWER') { + pads[head] = totalPad - smallPad; + pads[tail] = smallPad; + } +}; +const calculateOutputShapeAndPads = (inputShape, kernelShape, dilations, autoPad, pads, strides, outputPadding, outputShape) => { + const spatialRank = inputShape.length - 2; + const updateShape = outputShape.length === 0; + for (let i = 0; i < spatialRank; ++i) { + const outSize = updateShape ? inputShape[i + 2] * strides[i] : outputShape[i]; + const totalPad = computeTotalPad(inputShape[i + 2], strides[i], pads[i], kernelShape[i], dilations[i], outSize); + distributePadding(totalPad, autoPad, pads, i, i + spatialRank); + if (updateShape) { + outputShape.push(strides[i] * (inputShape[i + 2] - 1) + outputPadding[i] + (kernelShape[i] - 1) * dilations[i] + 1 - + pads[i] - pads[i + spatialRank]); + } + } +}; +const convTranspose = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs, attributes); // currently will fail if not convTranspose2D + return convTranspose2d(inferenceHandler, inputs, attributes); +}; +exports.convTranspose = convTranspose; +const convTranspose2d = (inferenceHandler, inputs, attributes) => { + const adjustedAttributes = getAdjustedConvTransposeAttributes(attributes, inputs); + return [convTranspose2DUnpacked(inferenceHandler, inputs, adjustedAttributes)]; +}; +const createConvTransposeProgramMetadata = (hasBias, cacheHint) => ({ + name: 'ConvTranspose', + inputNames: hasBias ? ['X', 'W', 'B'] : ['X', 'W'], + inputTypes: hasBias ? [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked] : + [types_1.TextureType.unpacked, types_1.TextureType.unpacked], + cacheHint +}); +const createUnpackedConvTransposeProgramInfo = (inferenceHandler, inputs, metadata, attributes) => { + const hasBias = inputs.length > 2; + const valueInit = hasBias ? 'getB(output_channel)' : '0.0'; + const xShape = inputs[0].dims; + const wShape = inputs[1].dims; + const outputChannelsPerGroup = wShape[1]; + const inputChannelsPerGroup = wShape[0] / attributes.group; + const outputShape = [inputs[0].dims[0], inputs[1].dims[1] * attributes.group, ...attributes.outputShape]; + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const { activationFunction, applyActivation } = (0, fuse_utils_1.getActivationSnippet)(attributes); + const shaderSource = ` + const ivec2 strides = ivec2(${attributes.strides[0]}, ${attributes.strides[1]}); + const ivec2 pads = ivec2(${attributes.pads[0]}, ${attributes.pads[1]}); + ${activationFunction} + void main() { + ivec4 coords = getOutputCoords(); + int batch = coords.x; + int output_channel = coords.y; + + ivec2 loc = coords.zw + pads; + + int group_id = output_channel / ${outputChannelsPerGroup}; + int wOutChannel = output_channel - group_id * ${outputChannelsPerGroup}; + + float value = ${valueInit}; + for (int inChannelOffset = 0; inChannelOffset < ${inputChannelsPerGroup}; inChannelOffset++) { + int input_channel = group_id * ${inputChannelsPerGroup} + inChannelOffset; + for (int wWOff = 0; wWOff < ${wShape[2]}; wWOff++) { + for (int wHOff = 0; wHOff < ${wShape[3]}; wHOff++) { + ivec2 wOff = ivec2(wWOff * ${attributes.dilations[0]}, wHOff * ${attributes.dilations[1]}); + ivec2 wLoc = loc - wOff; + ivec2 wLocIn = wLoc / strides; + if ( + wLocIn * strides == wLoc && + wLocIn.x >= 0 && wLocIn.x < ${xShape[2]} && + wLocIn.y >= 0 && wLocIn.y < ${xShape[3]} + ) { + float xVal = getX(batch, input_channel, wLocIn.y, wLocIn.x); + float wVal = getW(input_channel, wOutChannel, wHOff, wWOff); + value += xVal * wVal; + } + } + } + } + ${applyActivation} + ${glsl.output} = vec4(value, .0, .0, .0); + } +`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource, hasMain: true }); +}; +const createUnpackedConvTransposeProgramInfoLoader = (inferenceHandler, inputs, attributes) => { + const metadata = createConvTransposeProgramMetadata(inputs.length > 2, attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createUnpackedConvTransposeProgramInfo(inferenceHandler, inputs, metadata, attributes) }); +}; +const convTranspose2DUnpacked = (inferenceHandler, inputs, attributes) => { + const result = inferenceHandler.run(createUnpackedConvTransposeProgramInfoLoader(inferenceHandler, inputs, attributes), inputs); + return result; +}; +const getAdjustedConvTransposeAttributes = (attributes, inputs) => { + const kernelShape = attributes.kernelShape.slice(); + // if kernelShape is not specified in the attributes of this op, infer it from the weight tensor dims + if (attributes.kernelShape.length === 0) { + for (let i = 2; i < inputs[1].dims.length; ++i) { + kernelShape.push(inputs[1].dims[i]); + } + } + const pads = attributes.pads.slice(); + const outputShape = attributes.outputShape.slice(); + const inputShape = inputs[0].dims; + // If outputShape is not specified in the attributes of this op, infer it from the parameters + // Similarly, automatically infer pads if not specified + calculateOutputShapeAndPads(inputShape, kernelShape, attributes.dilations, attributes.autoPad, pads, attributes.strides, attributes.outputPadding, outputShape); + // always return a new object so does not modify the original attributes + const newAttributes = Object.assign({}, attributes); + Object.assign(newAttributes, { kernelShape, pads, outputShape, cacheKey: attributes.cacheKey }); + return newAttributes; +}; +const parseConvTransposeAttributes = (node) => { + const attributes = node.attributes; + const activationAttributes = (0, fuse_utils_1.parseInternalActivationAttributes)(attributes); + // TODO : Make this generic enough to compute default attributes for multi-dimensional conv + const autoPad = attributes.getString('auto_pad', 'NOTSET'); + const dilations = attributes.getInts('dilations', [1, 1]); + const group = attributes.getInt('group', 1); + const kernelShape = attributes.getInts('kernel_shape', []); + const outputPadding = attributes.getInts('output_padding', [0, 0]); + const outputShape = attributes.getInts('output_shape', []); + const pads = attributes.getInts('pads', [0, 0, 0, 0]); + const strides = attributes.getInts('strides', [1, 1]); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)(Object.assign({ autoPad, dilations, group, kernelShape, outputPadding, outputShape, pads, strides }, activationAttributes)); +}; +exports.parseConvTransposeAttributes = parseConvTransposeAttributes; +const validateInputs = (inputs, attributes) => { + // Refer to the below link for all input checks + // https://github.com/onnx/onnx/blob/main/docs/Operators.md#Conv + if (!inputs || (inputs.length !== 2 && inputs.length !== 3)) { + throw new Error('Conv requires 2 or 3 inputs'); + } + // TODO : Need to add support for multi-dimensional conv + if (inputs[0].dims.length !== 4 || inputs[1].dims.length !== 4) { + throw new Error('currently only support 2-dimensional conv'); + } + // FILTER_IN_CHANNEL should be equal to DATA_CHANNEL + const dataChannel = inputs[0].dims[1]; + const filterInChannel = inputs[1].dims[0]; + if (dataChannel !== filterInChannel) { + throw new Error('FILTER_IN_CHANNEL should be equal to DATA_CHANNEL'); + } + const featureMaps = inputs[1].dims[1] * attributes.group; + // if bias is provided it should be 1D and the number of elements should be equal to the number of feature maps + if (inputs.length === 3 && (inputs[2].dims.length !== 1 || inputs[2].dims[0] !== featureMaps)) { + throw new Error('invalid bias'); + } + const spatialRank = inputs[0].dims.length - 2; + // wrong dilations dimension + if (attributes.dilations.length !== spatialRank) { + throw new Error(`dilations should be ${spatialRank}D`); + } + // Wrong strides dimension + if (attributes.strides.length !== spatialRank) { + throw new Error(`strides should be ${spatialRank}D`); + } + // Wrong pads dimension + if (attributes.pads.length !== spatialRank * 2) { + throw new Error(`pads should be ${spatialRank * 2}D`); + } + // Wrong output padding dimension + if (attributes.outputPadding.length !== spatialRank) { + throw new Error(`output_padding should be ${spatialRank}D`); + } + // if kernelShape is specified, it's data length must be 2 less than dims length of the weights tensor + // (the first 2 dims are batch_size and channels) + if (attributes.kernelShape.length !== 0 && attributes.kernelShape.length !== inputs[1].dims.length - 2) { + throw new Error('invalid kernel shape'); + } + // as with kernelShape, must have same number of spatial dims as input + if (attributes.outputShape.length !== 0 && attributes.outputShape.length !== inputs[0].dims.length - 2) { + throw new Error('invalid output shape'); + } + // TODO : Need to add support for float64 + if (inputs[0].type !== 'float32' || inputs[1].type !== 'float32') { + throw new Error('ConvTranspose input(X,W) should be float tensor'); + } + if (inputs.length === 3 && inputs[2].type !== 'float32') { + throw new Error('ConvTranspose input(bias) should be float tensor'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/conv.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/conv.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseConvAttributes = exports.conv = exports.calculateOutputShape = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const conv_grouped_1 = __webpack_require__(/*! ./conv-grouped */ "./lib/onnxjs/backends/webgl/ops/conv-grouped.ts"); +const conv_pack_1 = __webpack_require__(/*! ./conv-pack */ "./lib/onnxjs/backends/webgl/ops/conv-pack.ts"); +const dot_product_1 = __webpack_require__(/*! ./dot-product */ "./lib/onnxjs/backends/webgl/ops/dot-product.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const im2col_1 = __webpack_require__(/*! ./im2col */ "./lib/onnxjs/backends/webgl/ops/im2col.ts"); +const matmul_1 = __webpack_require__(/*! ./matmul */ "./lib/onnxjs/backends/webgl/ops/matmul.ts"); +const calculateOutputShape = (inputShape, kernelShape, dilations, adjustPads, strides) => { + const batchSize = inputShape[0]; + const inputSpatialShape = inputShape.slice(2); + const spatialRank = inputSpatialShape.length; + const outChannels = kernelShape[0]; + const kernelSpatialShape = kernelShape.slice(2); + const dilatedKernelShape = kernelSpatialShape.map((v, i) => v + (v - 1) * (dilations[i] - 1)); + const inputSpatialShapeWithPad = inputSpatialShape.map((v, i) => v + adjustPads[i] + adjustPads[i + spatialRank]); + const outputSpatialShape = inputSpatialShapeWithPad.map((v, i) => Math.floor((v - dilatedKernelShape[i] + strides[i]) / strides[i])); + const outputShape = [batchSize, outChannels].concat(...outputSpatialShape); + return outputShape; +}; +exports.calculateOutputShape = calculateOutputShape; +const conv = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs, attributes); // currently will fail if not conv2D + return conv2d(inferenceHandler, inputs, attributes); +}; +exports.conv = conv; +const conv2d = (inferenceHandler, inputs, attributes) => { + const adjustedAttributes = getAdjustedConvAttributes(attributes, inputs); + const packMode = inferenceHandler.session.pack; + const isPointwise = adjustedAttributes.kernelShape[0] === 1 && adjustedAttributes.kernelShape[1] === 1; + if (adjustedAttributes.group > 1) { + const result = inferenceHandler.run((0, conv_grouped_1.createUnpackedGroupedConvProgramInfoLoader)(inferenceHandler, inputs, adjustedAttributes), inputs); + return [result]; + } + else if (isPointwise && packMode) { + return [conv2DUnpackedPointwise(inferenceHandler, inputs, adjustedAttributes)]; + } + else if (packMode && inputs[0].dims.length === 4 && inputs[0].dims[0] === 1 && !isPointwise) { + return [(0, conv_pack_1.conv2DPacked)(inferenceHandler, inputs, adjustedAttributes)]; + } + else { + return [conv2DUnpacked(inferenceHandler, inputs, adjustedAttributes)]; + } +}; +const conv2DUnpackedPointwise = (inferenceHandler, inputs, attributes) => { + const xshape = inputs[0].dims; + const kshape = inputs[1].dims; + const outputShape = (0, exports.calculateOutputShape)(xshape, kshape, attributes.dilations, attributes.pads, attributes.strides); + const reshapedX = inferenceHandler.reshapeUnpacked(inputs[0], [xshape[1], xshape[2] * xshape[3]]); + const reshapedK = inferenceHandler.reshapeUnpacked(inputs[1], [kshape[0], kshape[1]]); + const matmulInputs = inputs.length > 2 ? [reshapedK, reshapedX, inputs[2]] : [reshapedK, reshapedX]; + const matmulOutput = inferenceHandler.run((0, matmul_1.createMatmulProgramInfoLoader)(matmulInputs, attributes), matmulInputs); + return inferenceHandler.reshapeUnpacked(matmulOutput, outputShape); +}; +const conv2DUnpacked = (inferenceHandler, inputs, attributes) => { + const xshape = inputs[0].dims; + const kshape = inputs[1].dims; + const outputShape = (0, exports.calculateOutputShape)(xshape, kshape, attributes.dilations, attributes.pads, attributes.strides); + const xIm2Col = inferenceHandler.run((0, im2col_1.createIm2ColProgramInfoLoader)(inferenceHandler, inputs[0], inputs[1], outputShape, attributes), [inputs[0]]); + const dotProductInputs = inputs.length === 3 ? [xIm2Col, inputs[1], inputs[2]] : [xIm2Col, inputs[1]]; + const output = inferenceHandler.run((0, dot_product_1.createDotProductProgramInfoLoader)(inferenceHandler, inputs, outputShape, attributes), dotProductInputs); + return output; +}; +const getAdjustedConvAttributes = (attributes, inputs) => { + const kernelShape = attributes.kernelShape.slice(); + // if kernelShape is not specified in the attributes of this op, infer it from the weight tensor dims + if (attributes.kernelShape.length === 0) { + for (let i = 2; i < inputs[1].dims.length; ++i) { + kernelShape.push(inputs[1].dims[i]); + } + } + const pads = attributes.pads.slice(); + util_1.PoolConvUtil.adjustPadsBasedOnAutoPad(inputs[0].dims, attributes.strides, attributes.dilations, kernelShape, pads, attributes.autoPad); + // always return a new object so does not modify the original attributes + const newAttributes = Object.assign({}, attributes); + Object.assign(newAttributes, { kernelShape, pads, cacheKey: attributes.cacheKey }); + return newAttributes; +}; +const parseConvAttributes = (node) => { + const attributes = node.attributes; + const activationAttributes = (0, fuse_utils_1.parseInternalActivationAttributes)(attributes); + // TODO : Make this generic enough to compute default attributes for multi-dimensional conv + const autoPad = attributes.getString('auto_pad', 'NOTSET'); + const dilations = attributes.getInts('dilations', [1, 1]); + const group = attributes.getInt('group', 1); + const kernelShape = attributes.getInts('kernel_shape', []); + const pads = attributes.getInts('pads', [0, 0, 0, 0]); + const strides = attributes.getInts('strides', [1, 1]); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)(Object.assign({ autoPad, dilations, group, kernelShape, pads, strides }, activationAttributes)); +}; +exports.parseConvAttributes = parseConvAttributes; +const validateInputs = (inputs, attributes) => { + // Refer to the below link for all input checks + // https://github.com/onnx/onnx/blob/main/docs/Operators.md#Conv + if (!inputs || (inputs.length !== 2 && inputs.length !== 3)) { + throw new Error('Conv requires 2 or 3 inputs'); + } + // TODO : Need to add support for multi-dimensional conv + if (inputs[0].dims.length !== 4 || inputs[1].dims.length !== 4) { + throw new Error('currently only support 2-dimensional conv'); + } + // FILTER_IN_CHANNEL should be equal to DATA_CHANNEL + const dataChannel = inputs[0].dims[1]; + const filterInChannel = inputs[1].dims[1] * attributes.group; + if (dataChannel !== filterInChannel) { + throw new Error('FILTER_IN_CHANNEL should be equal to DATA_CHANNEL'); + } + // if bias is provided it should be 1D and the number of elements should be equal to the number of feature maps + if (inputs.length === 3 && (inputs[2].dims.length !== 1 || inputs[1].dims[0] !== inputs[2].dims[0])) { + throw new Error('invalid bias'); + } + const spatialRank = inputs[0].dims.length - 2; + // wrong dilations dimension + if (attributes.dilations.length !== spatialRank) { + throw new Error(`dilations should be ${spatialRank}D`); + } + // Wrong strides dimension + if (attributes.strides.length !== spatialRank) { + throw new Error(`strides should be ${spatialRank}D`); + } + // Wrong pads dimension + if (attributes.pads.length !== spatialRank * 2) { + throw new Error(`pads should be ${spatialRank * 2}D`); + } + // if kernelShape is specified, it's data length must be 2 less than dims length of the weights tensor + // (the first 2 dims are batch_size and channels) + if (attributes.kernelShape.length !== 0 && attributes.kernelShape.length !== inputs[1].dims.length - 2) { + throw new Error('invalid kernel shape'); + } + // TODO : Need to add support for float64 + if (inputs[0].type !== 'float32' || inputs[1].type !== 'float32') { + throw new Error('Conv input(X,W) should be float tensor'); + } + if (inputs.length === 3 && inputs[2].type !== 'float32') { + throw new Error('Conv input(bias) should be float tensor'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/depth-to-space.ts": +/*!*********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/depth-to-space.ts ***! + \*********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseDepthToSpaceAttributes = exports.depthToSpace = void 0; +const transpose_1 = __webpack_require__(/*! ./transpose */ "./lib/onnxjs/backends/webgl/ops/transpose.ts"); +const depthToSpace = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const blocksize = attributes.blocksize; + const blocksizeSqr = blocksize * blocksize; + const transposePerm = attributes.mode === 'DCR' ? [0, 3, 4, 1, 5, 2] : [0, 1, 4, 2, 5, 3]; + const firstReshapeShape = attributes.mode === 'DCR' ? + [ + inputs[0].dims[0], blocksize, blocksize, inputs[0].dims[1] / blocksizeSqr, inputs[0].dims[2], + inputs[0].dims[3] + ] : + [ + inputs[0].dims[0], inputs[0].dims[1] / blocksizeSqr, blocksize, blocksize, inputs[0].dims[2], + inputs[0].dims[3] + ]; + // const transpose = new WebGLTranspose(); + // const attributes = new Attribute(undefined); + // attributes.set('perm', 'ints', transposePerm); + // transpose.initialize(attributes); + // First reshape + const firstReshapedTensor = inferenceHandler.reshapeUnpacked(inputs[0], firstReshapeShape); + // transpose + const transposeAttributes = { perm: transposePerm, cacheKey: `${transposePerm}` }; + const [transposeOutput] = (0, transpose_1.transpose)(inferenceHandler, [firstReshapedTensor], transposeAttributes); + // Second reshape + const secondReshapeShape = [ + inputs[0].dims[0], inputs[0].dims[1] / blocksizeSqr, inputs[0].dims[2] * blocksize, + inputs[0].dims[3] * blocksize + ]; + const result = inferenceHandler.reshapeUnpacked(transposeOutput, secondReshapeShape); + return [result]; +}; +exports.depthToSpace = depthToSpace; +const parseDepthToSpaceAttributes = (node) => { + // processing node attributes + const blocksize = node.attributes.getInt('blocksize'); + if (blocksize < 1) { + throw new Error(`blocksize must be >= 1, but got : ${blocksize} for DepthToSpace`); + } + const mode = node.attributes.getString('mode', 'DCR'); + if (mode !== 'DCR' && mode !== 'CRD') { + throw new Error(`unrecognized mode: ${mode} for DepthToSpace`); + } + return { mode, blocksize }; +}; +exports.parseDepthToSpaceAttributes = parseDepthToSpaceAttributes; +const validateInputs = (inputs) => { + if (inputs.length !== 1) { + throw new Error(`DepthToSpace expect 1 inputs, but got ${inputs.length}`); + } + // Input has to be a 4-D tensor + // TODO: Support string depth-to-space. + if (inputs[0].type === 'string' || inputs[0].dims.length !== 4) { + throw new TypeError('DepthToSpace input should be a 4-D numeric tensor'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/dot-product.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/dot-product.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createDotProductProgramInfoLoader = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const im2col_1 = __webpack_require__(/*! ./im2col */ "./lib/onnxjs/backends/webgl/ops/im2col.ts"); +const createDotProductProgramMetadata = (hasBias, attributes) => ({ + name: 'ConvDotProduct', + inputNames: hasBias ? ['Im2Col', 'K', 'B'] : ['Im2Col', 'K'], + inputTypes: hasBias ? [types_1.TextureType.unpacked, types_1.TextureType.packedLastDimension, types_1.TextureType.unpacked] : + [types_1.TextureType.unpacked, types_1.TextureType.packedLastDimension], + cacheKey: attributes.activationCacheKey +}); +const createDotProductProgramInfo = (inferenceHandler, metadata, inputs, outputShape, attributes) => { + const xshape = inputs[0].dims; + const kshape = inputs[1].dims; + const adjustedKernelShape = [kshape[0], Math.ceil((xshape[1] * kshape[2] * kshape[3]) / 4)]; + const im2colShape = (0, im2col_1.calculateIm2ColDims)(xshape, kshape, outputShape); + const [kWidth, kHeight] = inferenceHandler.calculateTextureWidthAndHeight(adjustedKernelShape, types_1.TextureType.packedLastDimension); + const im2colStrides = util_1.ShapeUtil.computeStrides(im2colShape); + const [im2colWidth, im2colHeight] = inferenceHandler.calculateTextureWidthAndHeight(im2colShape, types_1.TextureType.packedLastDimension); + const rank = outputShape.length; + const initValue = (inputs.length < 3) ? '0.0' : '_B(b)'; + const sharedDim = Math.ceil(xshape[1] * kshape[2] * kshape[3] / 4); + const { activationFunction, applyActivation } = (0, fuse_utils_1.getActivationSnippet)(attributes); + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const shaderSource = ` +${activationFunction} +float process(int indices[${rank}]) { + int b[1]; + b[0] = indices[1]; + int im2col[4]; + im2col[0] = indices[0]; + im2col[1] = indices[2]; + im2col[2] = indices[3]; + int im2colOffset = im2col[0] * ${im2colStrides[0]} + im2col[1] * ${im2colStrides[1]} + im2col[2] * ${im2colStrides[2]}; + int kernelOffset = indices[1] * ${adjustedKernelShape[1]}; + float value = ${initValue}; + for (int i = 0; i < ${sharedDim}; ++i) { + vec2 im2colCoords = offsetToCoords(im2colOffset, ${im2colWidth}, ${im2colHeight}); + vec2 kernelCoords = offsetToCoords(kernelOffset, ${kWidth}, ${kHeight}); + value += dot(${glsl.texture2D}(Im2Col, im2colCoords), ${glsl.texture2D}(K, kernelCoords)); + ++im2colOffset; + ++kernelOffset; + } + ${applyActivation} + return value; +}`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const createDotProductProgramInfoLoader = (inferenceHandler, inputs, outputShape, attributes) => { + const metadata = createDotProductProgramMetadata(inputs.length > 2, attributes); + return Object.assign(Object.assign({}, metadata), { get: () => createDotProductProgramInfo(inferenceHandler, metadata, inputs, outputShape, attributes) }); +}; +exports.createDotProductProgramInfoLoader = createDotProductProgramInfoLoader; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/flatten.ts": +/*!**************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/flatten.ts ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseFlattenAttributes = exports.flatten = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const flatten = (inferenceHandler, inputs, axis) => { + validateInputs(inputs, axis); + const outputDims = util_1.ShapeUtil.flattenShape(inputs[0].dims, axis); + return [inferenceHandler.reshapeUnpacked(inputs[0], outputDims)]; +}; +exports.flatten = flatten; +const parseFlattenAttributes = (node) => node.attributes.getInt('axis', 1); // default axis is 1 +exports.parseFlattenAttributes = parseFlattenAttributes; +const validateInputs = (inputs, axis) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Flatten requires 1 input.'); + } + const r = inputs[0].dims.length; + if (r === 0) { + throw new Error('scalar tensor is not supported.'); + } + if (axis < -r || axis > r) { + throw new Error('Invalid axis'); + } + // TODO: Support string type + if (inputs[0].type === 'string') { + throw new Error('string tensor is not supported.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts": +/*!*****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/fuse-utils.ts ***! + \*****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseInternalActivationAttributes = exports.getActivationSnippet = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const unary_op_1 = __webpack_require__(/*! ./unary-op */ "./lib/onnxjs/backends/webgl/ops/unary-op.ts"); +function getActivationSnippet(attributes) { + let func; + switch (attributes.activation) { + case 'Relu': + func = (0, unary_op_1.glslRelu)(); + break; + case 'Sigmoid': + func = (0, unary_op_1.glslSigmoid)(); + break; + case 'Clip': + func = (0, unary_op_1.glslClip)(attributes.clipMin, attributes.clipMax); + break; + // TODO: adding other activations that can be fused. + default: + return { activationFunction: '', applyActivation: '' }; + } + const activationName = func.name; + const activationFunction = func.body; + const applyActivation = `value = ${activationName}_(value);`; + return { activationFunction, applyActivation }; +} +exports.getActivationSnippet = getActivationSnippet; +const parseInternalActivationAttributes = (attributes) => { + const activation = attributes.getString('activation', ''); + if (activation === 'Clip') { + const [clipMin, clipMax] = attributes.getFloats('activation_params', [util_1.MIN_CLIP, util_1.MAX_CLIP]); + return { activation, clipMax, clipMin, activationCacheKey: `${activation}:${clipMin},${clipMax}` }; + } + return { activation, activationCacheKey: activation }; +}; +exports.parseInternalActivationAttributes = parseInternalActivationAttributes; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/gather.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/gather.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseGatherAttributes = exports.gather = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const operators_1 = __webpack_require__(/*! ../../../operators */ "./lib/onnxjs/operators.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const gather = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs, attributes.axis); + const output = inferenceHandler.run(createGatherProgramInfoLoader(inferenceHandler, inputs, attributes), inputs); + return [output]; +}; +exports.gather = gather; +const parseGatherAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axis: node.attributes.getInt('axis', 0) }); +exports.parseGatherAttributes = parseGatherAttributes; +const gatherProgramMetadata = { + name: 'Gather', + inputNames: ['A', 'B'], + inputTypes: [types_1.TextureType.unpacked, types_1.TextureType.unpacked], +}; +const createGatherProgramInfo = (handler, metadata, inputs, axis) => { + const inputShape = inputs[0].dims.slice(); + const indexDataShape = inputs[1].dims.slice(); + const outputShape = new Array(inputShape.length + indexDataShape.length - 1); + axis = util_1.ShapeUtil.normalizeAxis(axis, inputShape.length); + const indexCopyOps = []; + for (let i = 0; i < outputShape.length; i++) { + // outputShape is divided into three parts: A, B, C + // |0 axis| axis + indexDataShape.length | end| + // | A | B | C | + // + // inputIdx: [A, inputs[1][B], C] + if (i < axis) { // A + outputShape[i] = inputShape[i]; + indexCopyOps.push(`inputIdx[${i}] = outputIdx[${i}];`); + } + else { + if (i < axis + indexDataShape.length) { // B + outputShape[i] = indexDataShape[i - axis]; + indexCopyOps.push(`indexDataIdx[${i - axis}] = outputIdx[${i}];`); + } + else { // C + outputShape[i] = inputShape[i - indexDataShape.length + 1]; // skip 1 for axis + indexCopyOps.push(`inputIdx[${i - indexDataShape.length + 1}] = outputIdx[${i}];`); + } + } + } + const orank = outputShape.length || 1; + const irank = inputShape.length; + const iDrank = indexDataShape.length || 1; + const shaderSource = ` + float process(int outputIdx[${orank}]) { + int inputIdx[${irank}]; + int indexDataIdx[${iDrank}]; + indexDataIdx[0] = 0; + ${indexCopyOps.join('\n ')} + int idx = int(_B(indexDataIdx)); + inputIdx[${axis}] = idx < 0 ? idx + ${inputShape[axis]} : idx; + return _A(inputIdx); + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const createGatherProgramInfoLoader = (handler, inputs, attributes) => { + const metadata = Object.assign(Object.assign({}, gatherProgramMetadata), { cacheHint: attributes.cacheKey }); + return Object.assign(Object.assign({}, metadata), { get: () => createGatherProgramInfo(handler, metadata, inputs, attributes.axis) }); +}; +const validateInputs = (inputs, axis) => { + if (!inputs || inputs.length !== 2) { + throw new Error('Gather requires 2 inputs.'); + } + const tensorRank = inputs[0].dims.length; + if (tensorRank < 1) { + throw new Error('Invalid input shape.'); + } + if (axis < -tensorRank || axis > tensorRank - 1) { + throw new Error('Invalid axis.'); + } + if (operators_1.NUMBER_TYPES.indexOf(inputs[0].type) === -1) { + throw new Error('Invaid input type.'); + } + if (inputs[1].type !== 'int32' && inputs[1].type !== 'int16') { + throw new Error('Invaid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/gemm.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/gemm.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseGemmAttributesV11 = exports.parseGemmAttributesV7 = exports.gemm = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const gemm = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs, attributes); + const output = inferenceHandler.run(createGemmProgramInfoLoader(inputs, attributes), inputs); + return [output]; +}; +exports.gemm = gemm; +const parseGemmAttributes = (node, isOptionalC) => { + const transA = node.attributes.getInt('transA', 0) !== 0; + const transB = node.attributes.getInt('transB', 0) !== 0; + const alpha = node.attributes.getFloat('alpha', 1.0); + const beta = node.attributes.getFloat('beta', 1.0); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ transA, transB, alpha, beta, isOptionalC }); +}; +const parseGemmAttributesV7 = (node) => parseGemmAttributes(node, false); +exports.parseGemmAttributesV7 = parseGemmAttributesV7; +const parseGemmAttributesV11 = (node) => parseGemmAttributes(node, true); +exports.parseGemmAttributesV11 = parseGemmAttributesV11; +const createGemmProgramInfoLoader = (inputs, attributes) => { + const metadata = { + name: 'Gemm', + inputNames: inputs.length === 3 ? ['A', 'B', 'C'] : ['A', 'B'], + inputTypes: inputs.length === 3 ? [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked] : + [types_1.TextureType.unpacked, types_1.TextureType.unpacked], + key: attributes.cacheKey + }; + return Object.assign(Object.assign({}, metadata), { get: () => createGemmProgramInfo(metadata, inputs, attributes) }); +}; +const createGemmProgramInfo = (metadata, inputs, attributes) => { + const aShape = inputs[0].dims.slice(); + const bShape = inputs[1].dims.slice(); + const [M, N] = util_1.GemmUtil.getShapeOfGemmResult(aShape, attributes.transA, bShape, attributes.transB, inputs.length === 3 ? inputs[2].dims : undefined); + const outputShape = [M, N]; + if (!outputShape) { + throw new Error('Can\'t use gemm on the given tensors'); + } + let sharedDim = aShape[aShape.length - 1]; + let line = ''; + if (attributes.transA) { + sharedDim = aShape[0]; + } + if (attributes.transA && attributes.transB) { + line = 'value += _A_T(a) * _B_T(b);'; + } + else if (attributes.transA && !attributes.transB) { + line = 'value += _A_T(a) * _B(b);'; + } + else if (!attributes.transA && attributes.transB) { + line = 'value += _A(a) * _B_T(b);'; + } + else if (!attributes.transA && !attributes.transB) { + line = 'value += _A(a) * _B(b);'; + } + const rank = outputShape.length; + const declareC = inputs.length === 3 ? `int c[${inputs[2].dims.length}];` : ''; + const broadcastC = inputs.length === 3 ? 'bcastIndices_C(indices, c);' : ''; + const calculateC = inputs.length === 3 ? 'value += beta * _C(c);' : ''; + const shaderSource = ` + float process(int indices[${rank}]) { + int a[${rank}]; + int b[${rank}]; + ${declareC} + + copyVec(indices, a); + copyVec(indices, b); + ${broadcastC} + + float value = 0.0; + for (int k=0; k<${sharedDim}; ++k) { + a[${rank - 1}] = k; + b[${rank - 2}] = k; + ${line} + } + + value = value * alpha; + ${calculateC} + return value; + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, variables: [ + { name: 'alpha', type: 'float', data: attributes.alpha }, { name: 'beta', type: 'float', data: attributes.beta } + ], shaderSource }); +}; +const validateInputs = (inputs, attributes) => { + if (!inputs) { + throw new Error('Input is missing'); + } + if (attributes.isOptionalC && (inputs.length < 2 || inputs.length > 3)) { + throw new Error('Invaid input shape.'); + } + if (!attributes.isOptionalC && inputs.length !== 3) { + throw new Error('Gemm requires 3 inputs'); + } + // 'C' can be of dimensionality 1 or 2 only + if (inputs.length === 3 && inputs[2].dims.length !== 1 && inputs[2].dims.length !== 2) { + throw new Error('Invalid input shape of C'); + } + if ((inputs[0].type !== 'float32' && inputs[0].type !== 'float64') || + (inputs[1].type !== 'float32' && inputs[1].type !== 'float64') || + (inputs.length === 3 && inputs[2].type !== 'float32' && inputs[2].type !== 'float64')) { + throw new Error('Invalid input type.'); + } + if ((inputs[0].type !== inputs[1].type) || (inputs.length === 3 && inputs[0].type !== inputs[2].type)) { + throw new Error('Input types are mismatched'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/im2col-pack.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/im2col-pack.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createPackedIm2ColProgramInfoLoader = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const createPackedIm2ColProgramMetadata = (cacheHint) => ({ + name: 'Im2Col (packed)', + inputNames: ['A'], + inputTypes: [types_1.TextureType.packed], + cacheHint, +}); +const createPackedIm2ColProgramInfo = (inferenceHandler, metadata, x, w, outputShape, attributes) => { + const xshape = x.dims; + const wshape = w.dims; + const rowDim = 2; + const colDim = 3; + const rank = outputShape.length; + const im2colShape = [wshape[1] * wshape[2] * wshape[3], outputShape[2] * outputShape[3]]; + const kernelSize = wshape[2] * wshape[3]; + const unpackChannel = (0, packing_utils_1.unpackFromChannel)(); + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + let unrolled = ''; + for (let row = 0; row <= 1; row++) { + for (let col = 0; col <= 1; col++) { + unrolled += ` + blockIndex = rc.x + ${col}; + pos = rc.y + ${row}; + + if(blockIndex < ${im2colShape[1]} && pos < ${im2colShape[0]}) { + offsetY = int(blockIndex / (${outputShape[rank - 1]})) * ${attributes.strides[0]} - + ${attributes.pads[0]}; + d0 = offsetY + ${attributes.dilations[0]} * (imod(pos, ${kernelSize}) / ${wshape[2]}); + + if(d0 < ${xshape[rowDim]} && d0 >= 0) { + offsetX = imod(blockIndex, ${outputShape[rank - 1]}) * ${attributes.strides[1]} - + ${attributes.pads[1]}; + d1 = offsetX + ${attributes.dilations[1]} * imod(imod(pos, ${kernelSize}), ${wshape[2]}); + + if(d1 < ${xshape[colDim]} && d1 >= 0) { + + ch = int(float(pos)/ ${kernelSize}.); + innerDims = vec2(d0, d1); + result[${row * 2 + col}] = getChannel( + getA(0, ch, int(innerDims.x), + int(innerDims.y)), innerDims); + } + } + } + + `; + } + } + const shaderSource = ` + ${unpackChannel} + + void main() { + ivec2 rc = getOutputCoords(); + vec4 result = vec4(0.0); + int blockIndex, pos, offsetY, d0, offsetX, d1, ch; + vec2 innerDims; + ${unrolled} + ${glsl.output} = result; + } + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: im2colShape, type: x.type, textureType: types_1.TextureType.packed }, shaderSource, hasMain: true }); +}; +const createPackedIm2ColProgramInfoLoader = (inferenceHandler, x, w, outputShape, attributes) => { + const metadata = createPackedIm2ColProgramMetadata(attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createPackedIm2ColProgramInfo(inferenceHandler, metadata, x, w, outputShape, attributes) }); +}; +exports.createPackedIm2ColProgramInfoLoader = createPackedIm2ColProgramInfoLoader; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/im2col.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/im2col.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.calculateIm2ColDims = exports.createIm2ColProgramInfoLoader = void 0; +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const createIm2ColProgramMetadata = (cacheHint) => ({ + name: 'Im2Col', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked], + cacheHint, +}); +const createIm2ColProgramInfo = (inferenceHandler, metadata, x, w, outputShape, attributes) => { + const xshape = x.dims; + const wshape = w.dims; + const rank = outputShape.length; + const im2colDims = (0, exports.calculateIm2ColDims)(xshape, wshape, outputShape, 4); + const shaderSource = ` + const int XC = ${xshape[1]}; + const int XH = ${xshape[2]}; + const int XW = ${xshape[3]}; + const int KH = ${attributes.kernelShape[0]}; + const int KW = ${attributes.kernelShape[1]}; + const int dilationH = ${attributes.dilations[0]}; + const int dilationW = ${attributes.dilations[1]}; + const int strideH = ${attributes.strides[0]}; + const int strideW = ${attributes.strides[1]}; + const int padH = ${attributes.pads[0]}; + const int padW = ${attributes.pads[1]}; + const int KHKW = KH*KW; + const int XCKHKW = XC * KHKW; + const int outputChannels = 4; + vec4 process(int indices[${rank}]) { + int b = indices[0]; // batch size + int oh = indices[1] * strideH - padH; //output height + int ow = indices[2] * strideW - padW; //output width + int p = indices[3] * outputChannels; //patch + vec4 value = vec4(0.0); + for(int i=0; i < outputChannels; ++i) { + if(p < XCKHKW) { + int patchC = p / KHKW; + int patchH = (p - patchC*KHKW) / KW; + int patchW = (p - patchC*KHKW) - patchH * KW; + int xh2 = oh + patchH * dilationH; + int xw2 = ow + patchW * dilationW; + int x[${xshape.length}]; + x[0] = b; + x[1] = patchC; + x[2] = xh2; + x[3] = xw2; + if(xh2 >= 0 && + xh2 < XH && + xw2 >= 0 && + xw2 < XW) { + value[i] = _X(x); + } + } + ++p; + } + return value; + } + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: im2colDims, type: x.type, textureType: types_1.TextureType.packedLastDimension }, shaderSource }); +}; +const createIm2ColProgramInfoLoader = (inferenceHandler, x, w, outputShape, attributes) => { + const metadata = createIm2ColProgramMetadata(attributes.cacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createIm2ColProgramInfo(inferenceHandler, metadata, x, w, outputShape, attributes) }); +}; +exports.createIm2ColProgramInfoLoader = createIm2ColProgramInfoLoader; +const calculateIm2ColDims = (inputShape, kernelShape, outputShape, channels = 4) => [outputShape[0], outputShape[2], outputShape[3], + Math.ceil(inputShape[1] * kernelShape[2] * kernelShape[3] / channels)]; +exports.calculateIm2ColDims = calculateIm2ColDims; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/image-scaler.ts": +/*!*******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/image-scaler.ts ***! + \*******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseImageScalerAttributes = exports.imageScaler = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const imageScaler = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const output = inferenceHandler.run(createImageScalerProgramInfoLoader(inferenceHandler, inputs, attributes), inputs); + return [output]; +}; +exports.imageScaler = imageScaler; +const parseImageScalerAttributes = (node) => { + const scale = node.attributes.getFloat('scale'); + const bias = node.attributes.getFloats('bias'); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ scale, bias }); +}; +exports.parseImageScalerAttributes = parseImageScalerAttributes; +const imageScalerProgramMetadata = { + name: 'ImageScaler', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked], +}; +const createImageScalerProgramInfo = (handler, metadata, inputs, attributes) => { + const outputShape = inputs[0].dims.slice(); + const rank = outputShape.length; + const getBiasMethod = createGetBiasMethod(attributes.bias.length); + const shaderSource = ` + ${getBiasMethod} + float process(int indices[${rank}]) { + return _X(indices) * scale + getBias(bias, indices[1]); + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, variables: [ + { name: 'bias', type: 'float', arrayLength: attributes.bias.length, data: attributes.bias }, + { name: 'scale', type: 'float', data: attributes.scale } + ], shaderSource }); +}; +const createImageScalerProgramInfoLoader = (handler, inputs, attributes) => { + const metadata = Object.assign(Object.assign({}, imageScalerProgramMetadata), { cacheHint: attributes.cacheKey }); + return Object.assign(Object.assign({}, metadata), { get: () => createImageScalerProgramInfo(handler, metadata, inputs, attributes) }); +}; +const createGetBiasMethod = (numChannels) => { + const codeLines = [`float getBias(float bias[${numChannels}], int channel) {`]; + for (let i = 0; i < numChannels; ++i) { + if (i === 0) { + codeLines.push('\t' + + `if (channel == ${i}) { return bias[${i}]; }`); + } + else if (i === numChannels - 1) { + codeLines.push('\t' + + `else { return bias[${i}]; }`); + } + else { + codeLines.push('\t' + + `else if (channel == ${i}) { return bias[${i}]; }`); + } + } + codeLines.push('\t' + + '}'); + return codeLines.join('\n'); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('ImageScaler requires 1 input.'); + } + if (inputs[0].dims.length !== 4) { + throw new Error('Invalid input shape.'); + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/instance-normalization.ts": +/*!*****************************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/instance-normalization.ts ***! + \*****************************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseInstanceNormalizationAttributes = exports.instanceNormalization = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const instanceNormalization = (inferenceHandler, inputs, epsilon) => { + validateInputs(inputs); + const meanAndVariance = inferenceHandler.run(createMeanAndVarianceProgramInfoLoader(inputs[0]), inputs); + const output = inferenceHandler.run(createComputeOutputProgramInfoLoader(inferenceHandler, inputs[0], epsilon, meanAndVariance.dims), [inputs[0], meanAndVariance, inputs[1], inputs[2]]); + return [output]; +}; +exports.instanceNormalization = instanceNormalization; +const parseInstanceNormalizationAttributes = (node) => node.attributes.getFloat('epsilon', 1e-5); +exports.parseInstanceNormalizationAttributes = parseInstanceNormalizationAttributes; +const meanAndVarianceProgramMetadata = { + name: 'InstanceNormalization_MeanAndVariance', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked], +}; +const createMeanAndVarianceProgramInfo = (metadata, input) => { + const xDims = input.dims.slice(); + const channel = xDims[1]; + const channelSize = xDims[2] * xDims[3]; + const outputShape = [xDims[0], channel]; + const shaderSource = ` + vec4 process(int[2] indices) { + vec4 v = vec4(0.0); + int a[4]; + a[0] = indices[0]; + a[1] = indices[1]; + float temp = 0.0; + for(int a2=0; a2<${xDims[2]}; a2++) { + a[2] = a2; + for(int a3=0; a3<${xDims[3]}; a3++) { + a[3] = a3; + float x = _X(a); + temp += x; + } + } + float mean = temp / float(${channelSize}); + temp = 0.0; + for(int a2=0; a2<${xDims[2]}; a2++) { + a[2] = a2; + for(int a3=0; a3<${xDims[3]}; a3++) { + a[3] = a3; + float x = _X(a); + temp += (x - mean) * (x - mean); + } + } + v.r = mean; + v.g = temp / float(${channelSize}); + + return v; + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.packedLastDimension }, shaderSource }); +}; +const createMeanAndVarianceProgramInfoLoader = (input) => (Object.assign(Object.assign({}, meanAndVarianceProgramMetadata), { get: () => createMeanAndVarianceProgramInfo(meanAndVarianceProgramMetadata, input) })); +const computeOutputProgramMetadata = { + name: 'InstanceNormalization_ComputeOutput', + inputNames: ['X', 'MeanAndVariance', 'Scale', 'B'], + inputTypes: [types_1.TextureType.unpacked, types_1.TextureType.packedLastDimension, types_1.TextureType.unpacked, types_1.TextureType.unpacked], +}; +const createComputeOutputProgramInfo = (inferenceHandler, metadata, input, epsilon, meanAndVarianceShape) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const [textureWidth, textureHeight] = inferenceHandler.calculateTextureWidthAndHeight(meanAndVarianceShape, types_1.TextureType.packedLastDimension); + const [meanAndVarianceWidth, meanAndVarianceHeight] = [textureWidth / 4, textureHeight]; + const shaderSource = ` + vec4 get_MeanAndVariance(int[2] mv) { + int offset = indicesToOffset_MeanAndVariance(mv); + vec2 coords = offsetToCoords(offset, ${meanAndVarianceWidth}, ${meanAndVarianceHeight}); + return ${glsl.texture2D}(MeanAndVariance, coords); + } + + float process(int[4] indices) { + int mv[2]; + mv[0] = indices[0]; + mv[1] = indices[1]; + vec4 mean_and_variance = get_MeanAndVariance(mv); + float mean = mean_and_variance.r; + float variance = mean_and_variance.g; + + int sb[1]; + sb[0] = indices[1]; + float scale = _Scale(sb); + float b = _B(sb); + + return scale * (_X(indices) - mean) / sqrt(variance + epsilon) + b; + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: input.dims, type: input.type, textureType: types_1.TextureType.unpacked }, variables: [{ name: 'epsilon', type: 'float', data: epsilon }], shaderSource }); +}; +const createComputeOutputProgramInfoLoader = (inferenceHandler, input, epsilon, meanAndVarianceShape) => { + const metadata = Object.assign(Object.assign({}, computeOutputProgramMetadata), { cacheHint: `${epsilon}` }); + return Object.assign(Object.assign({}, metadata), { get: () => createComputeOutputProgramInfo(inferenceHandler, metadata, input, epsilon, meanAndVarianceShape) }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 3) { + throw new Error('InstanceNormalization requires 3 inputs.'); + } + const X = inputs[0]; + const scale = inputs[1]; + const B = inputs[2]; + // input should at least have three dimensions - N,C,dim1,...,dimn + // other inputs can have only one dimensions + if (X.dims.length < 3 || scale.dims.length !== 1 || B.dims.length !== 1) { + throw new Error('Invalid input shape.'); + } + if (scale.dims[0] !== X.dims[1] || B.dims[0] !== X.dims[1]) { + throw new Error('Input shapes are mismatched.'); + } + if ((X.type !== 'float32' && X.type !== 'float64') || (scale.type !== 'float32' && scale.type !== 'float64') || + (B.type !== 'float32' && B.type !== 'float64')) { + throw new Error('Invalid input type.'); + } + if (inputs[0].dims.length !== 4) { + throw new Error('Only support 4-D input shape.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/matmul-pack.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/matmul-pack.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createPackedMatmulProgramInfoLoader = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const matmul_1 = __webpack_require__(/*! ./matmul */ "./lib/onnxjs/backends/webgl/ops/matmul.ts"); +const createPackedMatmulProgramMetadata = (hasBias, cacheHint) => ({ + name: 'MatMul (packed)', + inputNames: hasBias ? ['A', 'B', 'Bias'] : ['A', 'B'], + inputTypes: hasBias ? [types_1.TextureType.packed, types_1.TextureType.packed, types_1.TextureType.packed] : + [types_1.TextureType.packed, types_1.TextureType.packed], + cacheHint +}); +const createPackedMatmulProgramInfo = (inferenceHandler, metadata, inputs, activationAttributes) => { + const hasBias = inputs.length > 2; + const processBias = hasBias ? 'value += getBiasForMatmul();' : ''; + const aShape = inputs[0].dims; + const bShape = inputs[1].dims; + const outputShape = util_1.BroadcastUtil.calcShape(aShape, bShape, true); + const isBroadcast = !util_1.ShapeUtil.areEqual(inputs[0].dims, inputs[1].dims); + if (!outputShape) { + throw new Error('Can\'t use matmul on the given tensors'); + } + const sharedDim = aShape[aShape.length - 1]; + const sharedDimIndex = Math.ceil(sharedDim / 2); + const aRank = aShape.length; + const bRank = bShape.length; + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const coordsDataType = (0, utils_1.getCoordsDataType)(outputShape.length); + const outRank = outputShape.length; + const allGlChannels = (0, utils_1.getGlChannels)(); + const { activationFunction, applyActivation } = (0, fuse_utils_1.getActivationSnippet)(activationAttributes); + const getBiasForMatmulSnippet = hasBias ? `${(0, matmul_1.getBiasForMatmul)(coordsDataType, allGlChannels, inputs[2].dims, outputShape, true)}` : ''; + const getBcastedSamplerForMatmulSnippet = isBroadcast ? `${getBcastSamplerForMatmul(coordsDataType, allGlChannels, inputs, outputShape)}` : ''; + const getSamplerAInLoopSnippet = isBroadcast ? 'getAAtOutCoordsMatmul(i)' : `getA(${getA(allGlChannels, aRank)})`; + const getSamplerBInLoopSnippet = isBroadcast ? 'getBAtOutCoordsMatmul(i)' : `getB(${getB(allGlChannels, bRank)})`; + const getOutputCoordsSnippet = isBroadcast ? '' : `${coordsDataType} rc = + getOutputCoords(); int lastDim = rc.${allGlChannels[outRank - 1]}; rc.${allGlChannels[outRank - 1]} = + rc.${allGlChannels[outRank - 2]}; rc.${allGlChannels[outRank - 2]} = lastDim; + `; + const shaderSource = ` + ${getBcastedSamplerForMatmulSnippet} + ${getBiasForMatmulSnippet} + ${activationFunction} + void main() { + ${getOutputCoordsSnippet} + + vec4 value = vec4(0); + for (int i = 0; i < ${sharedDimIndex}; i++) { + vec4 a = ${getSamplerAInLoopSnippet}; + vec4 b = ${getSamplerBInLoopSnippet}; + + value += (a.rrbb * b.rgrg); + value += (a.ggaa * b.baba); + } + ${processBias} + ${applyActivation} + ${glsl.output} = value; + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.packed }, shaderSource, hasMain: true }); +}; +const createPackedMatmulProgramInfoLoader = (inferenceHandler, inputs, activationAttributes) => { + const metadata = createPackedMatmulProgramMetadata(inputs.length > 2, activationAttributes.activationCacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createPackedMatmulProgramInfo(inferenceHandler, metadata, inputs, activationAttributes) }); +}; +exports.createPackedMatmulProgramInfoLoader = createPackedMatmulProgramInfoLoader; +function getBcastSamplerForMatmul(coordsDataType, allGlChannels, inputs, outShape) { + let unpackedACoordsSnippet = []; + let unpackedBCoordsSnippet = []; + const inAShape = inputs[0].dims; + const inBShape = inputs[1].dims; + const inARank = inAShape.length; + const inBRank = inBShape.length; + const outRank = outShape.length; + const rankADiff = outRank - inARank; + const rankBDiff = outRank - inBRank; + unpackedACoordsSnippet = inAShape.map((s, i) => `coords.${allGlChannels[i + rankADiff]}`); + unpackedACoordsSnippet[inARank - 1] = 'i*2'; + unpackedACoordsSnippet.join(', '); + unpackedBCoordsSnippet = inBShape.map((s, i) => `coords.${allGlChannels[i + rankBDiff]}`); + unpackedBCoordsSnippet[inBRank - 2] = 'i*2'; + unpackedBCoordsSnippet.join(', '); + const broadcastADims = util_1.BroadcastUtil.getBroadcastDims(inAShape, outShape); + const broadcastBDims = util_1.BroadcastUtil.getBroadcastDims(inBShape, outShape); + const coordsASnippet = broadcastADims.map(d => `coords.${allGlChannels[d + rankADiff]} = 0;`).join('\n'); + const coordsBSnippet = broadcastBDims.map(d => `coords.${allGlChannels[d + rankBDiff]} = 0;`).join('\n'); + const swapDimSnippet = `int lastDim = coords.${allGlChannels[outRank - 1]}; + coords.${allGlChannels[outRank - 1]} = coords.${allGlChannels[outRank - 2]}; + coords.${allGlChannels[outRank - 2]} = lastDim;`; + const getBcastSamplerMatmulSource = ` +vec4 getAAtOutCoordsMatmul(int i) { + ${coordsDataType} coords = getOutputCoords(); + ${swapDimSnippet} + ${coordsASnippet} + vec4 outputValue = getA(${unpackedACoordsSnippet}); + return outputValue; +} + +vec4 getBAtOutCoordsMatmul(int i) { + ${coordsDataType} coords = getOutputCoords(); + ${swapDimSnippet} + ${coordsBSnippet} + vec4 outputValue = getB(${unpackedBCoordsSnippet}); + return outputValue; +}`; + return getBcastSamplerMatmulSource; +} +function getA(allGlChannels, rank) { + let res = ''; + for (let i = 0; i < rank - 2; i++) { + res += `rc.${allGlChannels[i]}, `; + } + res += `rc.${allGlChannels[rank - 2]}, ` + + 'i*2'; + return res; +} +function getB(allGlChannels, rank) { + let res = ''; + for (let i = 0; i < rank - 2; i++) { + res += `rc.${allGlChannels[i]}, `; + } + res += 'i*2, ' + + `rc.${allGlChannels[rank - 1]}`; + return res; +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/matmul.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/matmul.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getBiasForMatmul = exports.createMatmulProgramInfoLoader = exports.parseMatMulAttributes = exports.matMul = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const fuse_utils_1 = __webpack_require__(/*! ./fuse-utils */ "./lib/onnxjs/backends/webgl/ops/fuse-utils.ts"); +const matmul_pack_1 = __webpack_require__(/*! ./matmul-pack */ "./lib/onnxjs/backends/webgl/ops/matmul-pack.ts"); +const matMul = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + if (inferenceHandler.session.pack) { + return [inferenceHandler.run((0, matmul_pack_1.createPackedMatmulProgramInfoLoader)(inferenceHandler, inputs, attributes), inputs)]; + } + else { + return [inferenceHandler.run(createMatmulProgramInfoLoader(inputs, attributes), inputs)]; + } +}; +exports.matMul = matMul; +const parseMatMulAttributes = (node) => (0, fuse_utils_1.parseInternalActivationAttributes)(node.attributes); +exports.parseMatMulAttributes = parseMatMulAttributes; +const createMatmulProgramMetadata = (hasBias, cacheHint) => ({ + name: 'MatMul', + inputNames: hasBias ? ['A', 'B', 'Bias'] : ['A', 'B'], + inputTypes: hasBias ? [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked] : + [types_1.TextureType.unpacked, types_1.TextureType.unpacked], + cacheHint +}); +function createMatmulProgramInfo(metadata, inputs, activationAttributes) { + const aShape = inputs[0].dims; + const bShape = inputs[1].dims; + const outputShape = util_1.BroadcastUtil.calcShape(aShape, bShape, true); + if (!outputShape) { + throw new Error('Can\'t use matmul on the given tensors'); + } + const coordsDataType = (0, utils_1.getCoordsDataType)(outputShape.length); + const allGlChannels = (0, utils_1.getGlChannels)(); + const { activationFunction, applyActivation } = (0, fuse_utils_1.getActivationSnippet)(activationAttributes); + const hasBias = inputs.length > 2; + const processBias = hasBias ? 'value += getBiasForMatmul();' : ''; + const getBiasForMatmulSnippet = hasBias ? `${getBiasForMatmul(coordsDataType, allGlChannels, inputs[2].dims, outputShape, false)}` : ''; + const rank = outputShape.length; + const arank = aShape.length; + const brank = bShape.length; + const sharedDim = aShape[aShape.length - 1]; + const shaderSource = ` + ${activationFunction} + ${getBiasForMatmulSnippet} + float process(int indices[${rank}]) { + int a[${arank}]; + int b[${brank}]; + bcastMatmulIndices_A(indices, a); + bcastMatmulIndices_B(indices, b); + + float value; + for (int k=0; k<${sharedDim}; ++k) { + a[${arank - 1}] = k; + b[${brank - 2}] = k; + value += _A(a) * _B(b); + } + ${processBias} + ${applyActivation} + return value; + }`; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +} +function createMatmulProgramInfoLoader(inputs, activationAttributes) { + const metadata = createMatmulProgramMetadata(inputs.length > 2, activationAttributes.activationCacheKey); + return Object.assign(Object.assign({}, metadata), { get: () => createMatmulProgramInfo(metadata, inputs, activationAttributes) }); +} +exports.createMatmulProgramInfoLoader = createMatmulProgramInfoLoader; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 2) { + throw new Error('MatMul requires 2 inputs.'); + } + if (inputs[0].dims[inputs[0].dims.length - 1] !== inputs[1].dims[inputs[1].dims.length - 2]) { + throw new Error('shared dimension does not match.'); + } + if ((inputs[0].type !== 'float32' && inputs[0].type !== 'float64') || + (inputs[1].type !== 'float32' && inputs[1].type !== 'float64')) { + throw new Error('inputs should be float type'); + } + if (inputs[0].type !== inputs[1].type) { + throw new Error('inputs types should match'); + } +}; +function getBiasForMatmul(coordsDataType, allGlChannels, inShape, outShape, isPacked) { + let unpackedCoordsSnippet = ''; + const inRank = inShape.length; + const outRank = outShape.length; + const rankDiff = outRank - inRank; + if (outRank < 2 && inRank > 0) { + unpackedCoordsSnippet = 'coords'; + } + else { + unpackedCoordsSnippet = inShape.map((s, i) => `coords.${allGlChannels[i + rankDiff]}`).join(', '); + } + const broadcastDims = util_1.BroadcastUtil.getBroadcastDims(inShape, outShape); + const coordsSnippet = broadcastDims.map(d => `coords.${allGlChannels[d + rankDiff]} = 0;`).join('\n'); + const inSize = util_1.ShapeUtil.size(inShape); + const isInputScalar = inSize === 1; + let output = 'vec4(outputValue.xx, outputValue.yy)'; + if (isInputScalar) { + output = 'vec4(outputValue.x)'; + } + const getBiasForMatmulSource = isPacked ? ` +vec4 getBiasForMatmul() { + ${coordsDataType} coords = getOutputCoords(); + ${coordsSnippet} + vec4 outputValue = getBias(${unpackedCoordsSnippet}); + return ${output}; +}` : + ` +float getBiasForMatmul() { + ${coordsDataType} coords = getOutputCoords(); + ${coordsSnippet} + return getBias(coords.x); +}`; + return getBiasForMatmulSource; +} +exports.getBiasForMatmul = getBiasForMatmul; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/pack.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/pack.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createPackProgramInfoLoader = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const packProgramMetadata = { + name: 'pack', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpackedReversed] +}; +const createPackProgramInfo = (handler, input) => { + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const inputShape = input.dims; + const inputRank = inputShape.length; + // createTextureLayoutFromShape won't change output rank. Need to verify by running tests + const outputRank = input.dims.length; + const coordsDataType = (0, utils_1.getCoordsDataType)(outputRank); + const channels = (0, packing_utils_1.getChannels)('rc', outputRank); + const setup = getSetup(outputRank, channels, inputShape[inputShape.length - 2], inputShape[inputShape.length - 1]); + let reversedInputWH; + if (inputRank === 0) { + reversedInputWH = [1, 1]; + } + else if (inputRank === 1) { + reversedInputWH = [inputShape[0], 1]; + } + else { + reversedInputWH = [inputShape[outputRank - 1], inputShape[outputRank - 2]]; + } + const outOfBoundsCondition = getOutOfBoundsCondition(outputRank, reversedInputWH, channels); + const output = getOutput(inputShape, channels); + const shaderSource = ` + void main() { + ${coordsDataType} rc = getOutputCoords(); + + if(${outOfBoundsCondition}) { + ${glsl.output} = vec4(0); + } else { + ${setup} + + ${glsl.output} = vec4(${output}); + } + } + `; + return Object.assign(Object.assign({}, packProgramMetadata), { hasMain: true, output: { dims: input.dims, type: input.type, textureType: types_1.TextureType.packed }, shaderSource }); +}; +const createPackProgramInfoLoader = (handler, input) => (Object.assign(Object.assign({}, packProgramMetadata), { get: () => createPackProgramInfo(handler, input) })); +exports.createPackProgramInfoLoader = createPackProgramInfoLoader; +/** + * check output coordinate location and return false if it is outside input's width/height boundary + */ +function getOutOfBoundsCondition(rank, shape, dims) { + if (rank === 0) { + return 'false'; + } + if (rank === 1) { + return `rc > ${shape[0]}`; + } + let cond = ''; + for (let i = rank - 2; i < rank; i++) { + cond += `${dims[i]} >= ${shape[i - rank + 2]}`; + if (i < rank - 1) { + cond += '||'; + } + } + return cond; +} +/** + * code snippet to sample input texture with output coordiantes + */ +function getOutput(shape, dims) { + const rank = shape.length; + if (rank === 0) { + return 'getA(), 0, 0, 0'; + } + if (rank === 1) { + return `getA(rc), + rc + 1 >= ${shape[0]} ? 0. : getA(rc + 1), + 0, 0`; + } + const coord00 = 'r, c'; + const coord01 = 'r, cp1'; + const coord10 = 'rp1, c'; + const coord11 = 'rp1, cp1'; + let D = ''; + if (rank > 2) { + for (let i = 0; i < rank - 2; ++i) { + D = D + `${dims[i]},`; + } + } + return `getA(${D}${coord00}), + rEdge ? 0. : getA(${D}${coord10}), + cEdge ? 0. : getA(${D}${coord01}), + rEdge || cEdge ? 0. : getA(${D}${coord11})`; +} +/** + * code snippet to setup 4 coordinates and edge conditions + */ +function getSetup(rank, dims, rows, cols) { + if (rank === 0 || rank === 1) { + return ''; + } + // rank >= 2 for width+height pack. + else { + const setup = ` + int r = ${dims[rank - 2]}; + int c = ${dims[rank - 1]}; + int rp1 = ${dims[rank - 2]} + 1; + int cp1 = ${dims[rank - 1]} + 1; + bool rEdge = rp1 >= ${cols}; + bool cEdge = cp1 >= ${rows}; + `; + return setup; + } +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/packing-utils.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.unpackFromChannel = exports.getChannels = exports.getVecChannels = void 0; +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +function getVecChannels(name, rank) { + return (0, utils_1.getGlChannels)(rank).map(d => `${name}.${d}`); +} +exports.getVecChannels = getVecChannels; +function getChannels(name, rank) { + if (rank === 1) { + return [name]; + } + return getVecChannels(name, rank); +} +exports.getChannels = getChannels; +function unpackFromChannel() { + return ` + float getChannel(vec4 frag, int dim) { + int modCoord = imod(dim, 2); + return modCoord == 0 ? frag.r : frag.g; + } + + float getChannel(vec4 frag, vec2 innerDims) { + vec2 modCoord = mod(innerDims, 2.); + return modCoord.x == 0. ? + (modCoord.y == 0. ? frag.r : frag.g) : + (modCoord.y == 0. ? frag.b : frag.a); + } + `; +} +exports.unpackFromChannel = unpackFromChannel; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/pad.ts": +/*!**********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/pad.ts ***! + \**********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parsePadAttributesV11 = exports.padV11 = exports.parsePadAttributesV2 = exports.padV2 = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const padProgramMetadata = { + name: 'Pad', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], +}; +const padV2 = (inferenceHandler, inputs, attributes) => { + validateInputsV2(inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, padProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createPadProgramInfo(inferenceHandler, inputs[0], attributes) }), inputs); + return [output]; +}; +exports.padV2 = padV2; +const parsePadAttributesV2 = (node) => { + const mode = node.attributes.getString('mode', 'constant'); + const value = node.attributes.getFloat('value', 0.0); + const pads = node.attributes.getInts('pads'); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ mode, value, pads }); +}; +exports.parsePadAttributesV2 = parsePadAttributesV2; +const padV11 = (inferenceHandler, inputs, mode) => { + validateInputsV11(inputs); + const attrubutes = generatePadAttributesFromInputs(inferenceHandler, inputs, mode); + return (0, exports.padV2)(inferenceHandler, [inputs[0]], attrubutes); +}; +exports.padV11 = padV11; +const parsePadAttributesV11 = (node) => node.attributes.getString('mode', 'constant'); +exports.parsePadAttributesV11 = parsePadAttributesV11; +const generatePadAttributesFromInputs = (inferenceHandler, inputs, mode) => { + if (!inferenceHandler.session.isInitializer(inputs[1].dataId) || + (inputs.length >= 3 && !inferenceHandler.session.isInitializer(inputs[2].dataId))) { + throw new Error('dynamic pad attributes are not allowed'); + } + const pads = Array.from(inputs[1].integerData); + const value = (inputs.length >= 3) ? inputs[2].floatData[0] : 0.0; + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ mode, pads, value }); +}; +const createPadProgramInfo = (inferenceHandler, input, attributes) => { + const outputShape = util_1.ShapeUtil.padShape(input.dims.slice(), attributes.pads); + const rank = outputShape.length; + const padFunction = getPadFunction(inferenceHandler, input, attributes); + const shaderSource = ` + ${padFunction} + float process(int[${rank}] indices) { + return padA(indices); + }`; + return { + name: 'Pad', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], + output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.unpacked }, + shaderSource + }; +}; +const validateInputsV2 = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Pad requires 1 input'); + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('Invalid input type.'); + } +}; +const validateInputsV11 = (inputs) => { + if (!inputs || (inputs.length !== 2 && inputs.length !== 3)) { + throw new Error('Pad requires 2 or 3 inputs'); + } + if (inputs[1].type !== 'int32') { + throw new Error('Invalid input type.'); + } + if (inputs.length >= 3 && inputs[2].type === 'string') { + throw new Error('Invalid input type.'); + } +}; +const getPadFunction = (inferenceHandler, input, attributes) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const [width, height] = inferenceHandler.calculateTextureWidthAndHeight(input.dims, types_1.TextureType.unpacked); + const strides = util_1.ShapeUtil.computeStrides(input.dims); + switch (attributes.mode) { + case 'constant': + return getPadConstant(glsl, input.dims, strides, width, height, attributes.pads, attributes.value); + case 'reflect': + return getPadReflect(glsl, input.dims, strides, width, height, attributes.pads); + case 'edge': + return getPadEdge(glsl, input.dims, strides, width, height, attributes.pads); + default: + throw new Error('Invalid mode'); + } +}; +const getPadConstant = (glsl, shape, strides, width, height, pads, value) => { + const rank = shape.length; + let block = ''; + for (let i = rank - 1; i >= 0; --i) { + block += ` + k = m[${i}] - ${pads[i]}; + if (k < 0) return constant; + if (k >= ${shape[i]}) return constant; + offset += k * ${strides[i]}; + `; + } + return ` + float padA(int m[${rank}]) { + const float constant = float(${value}); + int offset = 0; + int k = 0; + ${block} + vec2 coords = offsetToCoords(offset, ${width}, ${height}); + float value = getColorAsFloat(${glsl.texture2D}(A, coords)); + return value; + } + `; +}; +const getPadReflect = (glsl, shape, strides, width, height, pads) => { + const rank = shape.length; + let block = ''; + for (let i = rank - 1; i >= 0; --i) { + block += ` + k = m[${i}] - ${pads[i]}; + if (k < 0) { k = -k; } + { + const int _2n_1 = ${2 * (shape[i] - 1)}; + k = int( mod( float(k), float(_2n_1) ) ) ; + if(k >= ${shape[i]}) { k = _2n_1 - k; } + } + offset += k * ${strides[i]}; + `; + } + return ` + float padA(int m[${rank}]) { + int offset = 0; + int k = 0; + ${block} + vec2 coords = offsetToCoords(offset, ${width}, ${height}); + float value = getColorAsFloat(${glsl.texture2D}(A, coords)); + return value; + } + `; +}; +const getPadEdge = (glsl, shape, strides, width, height, pads) => { + const rank = shape.length; + let block = ''; + for (let i = rank - 1; i >= 0; --i) { + block += ` + k = m[${i}] - ${pads[i]}; + if (k < 0) k = 0; + if (k >= ${shape[i]}) k = ${shape[i] - 1}; + offset += k * ${strides[i]}; + `; + } + return ` + float padA(int m[${rank}]) { + int offset = 0; + int k = 0; + ${block} + vec2 coords = offsetToCoords(offset, ${width}, ${height}); + float value = getColorAsFloat(${glsl.texture2D}(A, coords)); + return value; + } + `; +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/pool.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/pool.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.globalMaxPool = exports.parseMaxPoolAttributes = exports.maxPool = exports.parseGlobalAveragePoolAttributes = exports.globalAveragePool = exports.parseAveragePoolAttributes = exports.averagePool = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const averagePool = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const metadata = { name: 'AveragePool', inputNames: ['X'], inputTypes: [types_1.TextureType.unpacked], cacheHint: attributes.cacheKey }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, metadata), { get: () => createAveragePoolProgramInfo(inputs, metadata, false, attributes) }), inputs); + return [output]; +}; +exports.averagePool = averagePool; +const parseAveragePoolAttributes = (node) => { + const autoPad = node.attributes.getString('auto_pad', 'NOTSET'); + const ceilMode = node.attributes.getInt('ceil_mode', 0); + const countIncludePad = (node.attributes.getInt('count_include_pad', 0) === 0 ? false : true); + const kernelShape = node.attributes.getInts('kernel_shape'); + const strides = node.attributes.getInts('strides', []); + const pads = node.attributes.getInts('pads', []); + // TODO: support attribute 'ceil_mode' + if (ceilMode !== 0) { + throw new Error('using ceil() in shape computation is not yet supported for AveragePool'); + } + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ autoPad, ceilMode, countIncludePad, kernelShape, strides, pads }); +}; +exports.parseAveragePoolAttributes = parseAveragePoolAttributes; +const createAveragePoolProgramInfo = (inputs, metadata, isGlobalOperator, attributes) => { + const [adjustedAttributes, outputShape] = getAdjustedPoolAttributesAndOutputShape(inputs, attributes, isGlobalOperator); + const kernelSize = util_1.ShapeUtil.size(adjustedAttributes.kernelShape); + const op1 = 'value += _X(x);'; + let op2 = ''; + if (adjustedAttributes.countIncludePad) { + op2 += `value /= float(${kernelSize});`; + } + else { + op2 += `value /= float(${kernelSize} - pad);`; + } + const poolingCode = generatePoolingCode(inputs[0].dims, adjustedAttributes, op1, op2, '0.0'); + const shaderSource = ` + ${poolingCode} + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const globalAveragePool = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const metadata = { + name: 'GlobalAveragePool', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked], + cacheHint: `${attributes.countIncludePad}` + }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, metadata), { get: () => createAveragePoolProgramInfo(inputs, metadata, true, attributes) }), inputs); + return [output]; +}; +exports.globalAveragePool = globalAveragePool; +const parseGlobalAveragePoolAttributes = (node) => { + const countIncludePad = (node.attributes.getInt('count_include_pad', 0) === 0 ? false : true); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ autoPad: '', ceilMode: 0, countIncludePad, kernelShape: [], strides: [], pads: [] }); +}; +exports.parseGlobalAveragePoolAttributes = parseGlobalAveragePoolAttributes; +const maxPool = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const metadata = { name: 'MaxPool', inputNames: ['X'], inputTypes: [types_1.TextureType.unpacked], cacheHint: attributes.cacheKey }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, metadata), { get: () => createMaxPoolProgramInfo(inputs, metadata, false, attributes) }), inputs); + return [output]; +}; +exports.maxPool = maxPool; +const parseMaxPoolAttributes = (node) => { + const autoPad = node.attributes.getString('auto_pad', 'NOTSET'); + const ceilMode = node.attributes.getInt('ceil_mode', 0); + const kernelShape = node.attributes.getInts('kernel_shape'); + const strides = node.attributes.getInts('strides', []); + const pads = node.attributes.getInts('pads', []); + const storageOrder = node.attributes.getInt('storage_order', 0); + const dilations = node.attributes.getInts('dilations', []); + // TODO: support attribute 'ceil_mode' and 'storage_order' + if (storageOrder !== 0) { + throw new Error('column major storage order is not yet supported for MaxPool'); + } + if (ceilMode !== 0) { + throw new Error('using ceil() in shape computation is not yet supported for MaxPool'); + } + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ autoPad, ceilMode, countIncludePad: false, kernelShape, strides, pads, storageOrder, dilations }); +}; +exports.parseMaxPoolAttributes = parseMaxPoolAttributes; +const createMaxPoolProgramInfo = (inputs, metadata, isGlobalOperator, attributes) => { + const [adjustedAttributes, outputShape] = getAdjustedPoolAttributesAndOutputShape(inputs, attributes, isGlobalOperator); + const op1 = ` + value = max(_X(x), value); + `; + const op2 = ''; + const poolingCode = generatePoolingCode(inputs[0].dims, adjustedAttributes, op1, op2, '-1e5'); + const shaderSource = ` + ${poolingCode} + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const getAdjustedPoolAttributesAndOutputShape = (inputs, attributes, isGlobalOperator) => { + const inputShape = inputs[0].dims.slice(); + const hasDilations = Object.hasOwnProperty.call(attributes, 'dilations'); + const kernelShape = attributes.kernelShape.slice(); + const strides = attributes.strides.slice(); + const dilations = hasDilations ? attributes.dilations.slice() : []; + const pads = attributes.pads.slice(); + util_1.PoolConvUtil.adjustPoolAttributes(isGlobalOperator, inputShape, kernelShape, strides, dilations, pads); + const outputShape = util_1.PoolConvUtil.computePoolOutputShape(isGlobalOperator, inputShape, strides, dilations, kernelShape, pads, attributes.autoPad); + const newAttributes = Object.assign({}, attributes); + if (hasDilations) { + Object.assign(newAttributes, { kernelShape, strides, pads, dilations, cacheKey: attributes.cacheKey }); + } + else { + Object.assign(newAttributes, { kernelShape, strides, pads, cacheKey: attributes.cacheKey }); + } + return [newAttributes, outputShape]; +}; +const globalMaxPoolAttributes = { + autoPad: '', + ceilMode: 0, + countIncludePad: false, + kernelShape: [], + strides: [], + pads: [], + storageOrder: 0, + dilations: [], + cacheKey: '' +}; +const globalMaxPoolMetadata = { + name: 'GlobalMaxPool', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked] +}; +const globalMaxPool = (inferenceHandler, inputs) => { + validateInputs(inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, globalMaxPoolMetadata), { get: () => createMaxPoolProgramInfo(inputs, globalMaxPoolMetadata, true, globalMaxPoolAttributes) }), inputs); + return [output]; +}; +exports.globalMaxPool = globalMaxPool; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Pool ops requires 1 input.'); + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('Invalid input type.'); + } +}; +const generatePoolingCode = (inputDims, attributes, op1, op2, start) => { + const rank = inputDims.length; + if (attributes.kernelShape.length <= 2) { + const kw = attributes.kernelShape[attributes.kernelShape.length - 1]; + const sw = attributes.strides[attributes.strides.length - 1]; + const pwStart = attributes.pads[attributes.pads.length / 2 - 1]; + const pwEnd = attributes.pads[attributes.pads.length - 1]; + const dimW = inputDims[rank - 1]; + let codeW = ''; + let codeH = ''; + let codeHEnd = ''; + if (pwStart + pwEnd !== 0) { + codeW = ` + for (int i = 0; i < ${kw}; i++) { + x[${rank} - 1] = indices[${rank} - 1] * ${sw} - ${pwStart} + i; + if (x[${rank} - 1] < 0 || x[${rank} - 1] >= ${dimW}) { + pad++; + continue; + } + ${op1} + }`; + } + else { + codeW = ` + for (int i = 0; i < ${kw}; i++) { + x[${rank} - 1] = indices[${rank} - 1] * ${sw} - ${pwStart} + i; + ${op1} + }`; + } + if (attributes.kernelShape.length === 2) { + const kh = attributes.kernelShape[attributes.kernelShape.length - 2]; + const sh = attributes.strides[attributes.strides.length - 2]; + const phStart = attributes.pads[attributes.pads.length / 2 - 2]; + const phEnd = attributes.pads[attributes.pads.length - 2]; + const dimH = inputDims[rank - 2]; + if (phStart + phEnd !== 0) { + codeH = ` + for (int j = 0; j < ${kh}; j++) { + x[${rank} - 2] = indices[${rank} - 2] * ${sh} - ${phStart} + j; + if (x[${rank} - 2] < 0 || x[${rank} - 2] >= ${dimH}) { + pad+= ${kw}; + continue; + } + `; + } + else { + codeH = ` + for (int j = 0; j < ${kh}; j++) { + x[${rank} - 2] = indices[${rank} - 2] * ${sh} - ${phStart} + j; + `; + } + codeHEnd = ` + } + `; + } + const poolingCode = ` + float process(int indices[${rank}]) { + int x[${rank}]; + copyVec(indices, x); + + float value = ${start}; + int pad = 0; + ${codeH} + ${codeW} + ${codeHEnd} + ${op2} + return value; + } + `; + return poolingCode; + } + else { + const kernelSize = util_1.ShapeUtil.size(attributes.kernelShape); + const kernelStrides = util_1.ShapeUtil.computeStrides(attributes.kernelShape); + const stridesRank = kernelStrides.length; + const padsRank = attributes.pads.length; + const offsetToIndicesFunction = offsetToIndices(stridesRank); + const copyInputDims = copyArray(inputDims, 'inputDims'); + const copyPads = copyArray(attributes.pads, 'pads'); + const copyKernelStrides = copyArray(kernelStrides, 'kernelStrides'); + const copyStrides = copyArray(attributes.strides, 'strides'); + const hasPads = attributes.pads.reduce((sum, cur) => sum + cur); + let padCode = ''; + if (hasPads) { + padCode = ` + if (x[j] >= inputDims[j] || x[j] < 0) { + pad++; + isPad = true; + break; + } + } + if (!isPad) { + ${op1} + }`; + } + else { + padCode = ` + } + ${op1} + `; + } + const poolingCode = ` + ${offsetToIndicesFunction} + float process(int indices[${rank}]) { + int x[${rank}]; + copyVec(indices, x); + int offset[${stridesRank}]; + int pads[${padsRank}]; + int inputDims[${rank}]; + int kernelStrides[${stridesRank}]; + int strides[${stridesRank}]; + ${copyPads} + ${copyInputDims} + ${copyStrides} + ${copyKernelStrides} + + float value = ${start}; + int pad = 0; + bool isPad = false; + for (int i = 0; i < ${kernelSize}; i++) { + offsetToIndices(i, kernelStrides, offset); + isPad = false; + for (int j = ${rank} - ${stridesRank}; j < ${rank}; j++) { + x[j] = indices[j] * strides[j - ${rank} + ${stridesRank}] + + offset[j - ${rank} + ${stridesRank}] - pads[j - 2]; + ${padCode} + } + ${op2} + + return value; + } + `; + return poolingCode; + } +}; +const copyArray = (array, arrayName) => { + let block = ''; + for (let i = 0; i < array.length; i++) { + block += ` + ${arrayName}[${i}] = ${array[i]}; + `; + } + return block; +}; +const offsetToIndices = (rank) => ` + void offsetToIndices(int offset, int[${rank}] strides, out int[${rank}] indices) { + if (${rank} == 0) { + return; + } + for (int i = 0; i < ${rank} - 1; ++i) { + indices[i] = offset / strides[i]; + offset -= indices[i] * strides[i]; + } + indices[${rank} - 1] = offset; + }`; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/reduce.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/reduce.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.reduceLogSumSquare = exports.reduceLogSum = exports.reduceProd = exports.reduceMin = exports.reduceMax = exports.reduceMean = exports.reduceSum = exports.parseReduceAttributes = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const operators_1 = __webpack_require__(/*! ../../../operators */ "./lib/onnxjs/operators.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const reduce = (inferenceHandler, inputs, attributes, name, reduceOp) => { + validateInputs(inputs); + const reduceProgramMetadata = { + name, + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], + }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, reduceProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createReduceProgramInfo(inferenceHandler, inputs, attributes, name, reduceOp, reduceProgramMetadata) }), inputs); + return [output]; +}; +const parseReduceAttributes = (node) => { + const axes = node.attributes.getInts('axes', []); + const keepDims = node.attributes.getInt('keepdims', 1) === 1; + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axes, keepDims }); +}; +exports.parseReduceAttributes = parseReduceAttributes; +const createReduceProgramInfo = (handler, inputs, attributes, name, reduceOp, reduceProgramMetadata) => { + const outputShape = []; + const iRank = inputs[0].dims.length || 1; + const idxCopy = []; // copy output indexes to input indexes + const axes = util_1.ShapeUtil.normalizeAxes(attributes.axes, inputs[0].dims.length); + const ops = reduceOp(inputs, axes); + let reduceOps = ops[1]; + for (let k = 0; k < inputs[0].dims.length; k++) { + // if this axis is reduced + if (axes.indexOf(k) >= 0 || axes.length === 0) { + if (attributes.keepDims) { + outputShape.push(1); + } // else { remove the axis from outputShape; } + // loop over the d-th axis + reduceOps = ` + for(int j${k} = 0; j${k} < ${inputs[0].dims[k]}; j${k}++) { + inputIdx[${k}] = j${k}; + ${reduceOps} + }`; + } + else { + idxCopy.push(`inputIdx[${k}] = outputIdx[${outputShape.length}];`); + outputShape.push(inputs[0].dims[k]); + } + } + const oRank = outputShape.length || 1; + const shaderSource = ` + float process(int outputIdx[${oRank}]) { + float value; // final result + int inputIdx[${iRank}]; // addressing input data + ${idxCopy.join('\n')} + ${ops[0]} // init ops for reduce max/min + ${reduceOps} + ${ops[2]} // final computation for reduce mean + return value; + }`; + return Object.assign(Object.assign({}, reduceProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Reduce op requires 1 input.'); + } + if (operators_1.NUMBER_TYPES.indexOf(inputs[0].type) === -1) { + throw new Error('Invalid input type.'); + } +}; +const reduceSum = (inferenceHandler, inputs, attributes) => { + const reduceOp = () => ['value = 0.0;', 'value += _A(inputIdx);', '']; + return reduce(inferenceHandler, inputs, attributes, 'ReduceSum', reduceOp); +}; +exports.reduceSum = reduceSum; +const reduceMean = (inferenceHandler, inputs, attributes) => { + const reduceOp = (inputs, axes) => { + let size = 1.0; + for (let k = 0; k < inputs[0].dims.length; k++) { + if (axes.indexOf(k) >= 0 || axes.length === 0) { + size *= inputs[0].dims[k]; + } + } + return ['value = 0.0;', 'value += _A(inputIdx);', `value /= ${size}.;`]; // ensure real number with `.` + }; + return reduce(inferenceHandler, inputs, attributes, 'ReduceMean', reduceOp); +}; +exports.reduceMean = reduceMean; +const reduceMax = (inferenceHandler, inputs, attributes) => { + const reduceOp = (inputs, axes) => { + const idxZero = []; + for (let k = 0; k < inputs[0].dims.length; k++) { + if (axes.indexOf(k) >= 0 || axes.length === 0) { + idxZero.push(`inputIdx[${k}] = 0;`); // first element + } + } + return [`${idxZero.join('\n')}\nvalue = _A(inputIdx);`, 'value = max(value, _A(inputIdx));', '']; + }; + return reduce(inferenceHandler, inputs, attributes, 'ReduceMax', reduceOp); +}; +exports.reduceMax = reduceMax; +const reduceMin = (inferenceHandler, inputs, attributes) => { + const reduceOp = (inputs, axes) => { + const idxZero = []; + for (let k = 0; k < inputs[0].dims.length; k++) { + if (axes.indexOf(k) >= 0 || axes.length === 0) { + idxZero.push(`inputIdx[${k}] = 0;`); // first element + } + } + return [`${idxZero.join('\n')}\nvalue = _A(inputIdx);`, 'value = min(value, _A(inputIdx));', '']; + }; + return reduce(inferenceHandler, inputs, attributes, 'ReduceMin', reduceOp); +}; +exports.reduceMin = reduceMin; +const reduceProd = (inferenceHandler, inputs, attributes) => { + const reduceOp = () => ['value = 1.0;', 'value *= _A(inputIdx);', '']; + return reduce(inferenceHandler, inputs, attributes, 'ReduceProd', reduceOp); +}; +exports.reduceProd = reduceProd; +const reduceLogSum = (inferenceHandler, inputs, attributes) => { + const reduceOp = () => ['value = 0.0;', 'value += _A(inputIdx);', 'value = log(value);']; + return reduce(inferenceHandler, inputs, attributes, 'ReduceLogSum', reduceOp); +}; +exports.reduceLogSum = reduceLogSum; +const reduceLogSumSquare = (inferenceHandler, inputs, attributes) => { + const reduceOp = () => ['float t; value = 0.0;', 't = _A(inputIdx); value += t * t;', '']; + return reduce(inferenceHandler, inputs, attributes, 'ReduceLogSumSquare', reduceOp); +}; +exports.reduceLogSumSquare = reduceLogSumSquare; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/reshape-packed.ts": +/*!*********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/reshape-packed.ts ***! + \*********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isReshapeCheap = exports.processDims3D = exports.createPackedReshape3DProgramInfoLoader = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const createPackedReshape3DProgramMetadata = (outputShape3D) => ({ name: 'Reshape (packed)', inputTypes: [types_1.TextureType.packed], inputNames: ['A'], cacheHint: `${outputShape3D}` }); +const createPackedReshape3DProgramInfo = (handler, input3D, metadata, outputShape3D) => { + const inputShape3D = input3D.dims; + const squeezedOutputShape = outputShape3D; + let mainLoop = ''; + for (let i = 0; i < 4; i++) { + let outputCoords = ''; + switch (i) { + case 0: + outputCoords = 'outputCoords = rc;'; + break; + case 1: + outputCoords = 'outputCoords = ivec3(rc.x, rc.y+1, rc.z);'; + break; + case 2: + outputCoords = 'outputCoords = ivec3(rc.x, rc.y, rc.z+1);'; + break; + case 3: + outputCoords = 'outputCoords = ivec3(rc.x, rc.y+1, rc.z+1);'; + break; + default: + throw new Error(); + } + mainLoop += ` + ${outputCoords} + ${i > 0 ? 'if(outputCoords.y < rows && outputCoords.z < cols){' : ''} + int flattenedIndex = getFlattenedIndex(outputCoords); + + ivec3 inputRC = inputCoordsFromReshapedOutCoords(flattenedIndex); + vec2 innerDims = vec2(float(inputRC.y),float(inputRC.z)); + + result[${i}] = getChannel(getA(inputRC.x, inputRC.y, inputRC.z), innerDims); + + ${i > 0 ? '}' : ''} + `; + } + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const shaderSource = ` + ${getReshapedInputCoords(inputShape3D)} + ${getFlattenedIndexFrom3D(squeezedOutputShape)} + ${(0, packing_utils_1.unpackFromChannel)()} + + void main() { + ivec3 rc = getOutputCoords(); + + vec4 result = vec4(0.0); + + ivec3 outputCoords; + int rows = ${squeezedOutputShape[2]}; + int cols = ${squeezedOutputShape[1]}; + + ${mainLoop} + ${glsl.output} = result; + } + `; + return Object.assign(Object.assign({}, metadata), { output: { dims: squeezedOutputShape, type: input3D.type, textureType: types_1.TextureType.packed }, shaderSource, hasMain: true }); +}; +const createPackedReshape3DProgramInfoLoader = (handler, input3D, outputShape3D) => { + const metadata = createPackedReshape3DProgramMetadata(outputShape3D); + return Object.assign(Object.assign({}, metadata), { get: () => createPackedReshape3DProgramInfo(handler, input3D, metadata, outputShape3D) }); +}; +exports.createPackedReshape3DProgramInfoLoader = createPackedReshape3DProgramInfoLoader; +function processDims3D(shape) { + if (shape.length === 0) { + return [1, 1, 1]; + } + // TODO: squeeze other shapes to 2D case + let batch = 1; + for (let i = 0; i < shape.length - 2; ++i) { + batch *= shape[i]; + } + return [batch, shape.length > 1 ? shape[shape.length - 2] : 1, shape[shape.length - 1]]; +} +exports.processDims3D = processDims3D; +// For packed reshape, we need to re-arrange texel data for output shape. +// Our pack is designed to pack a 2x2 tile in last h and w dimension, so +// for the reshaped new tensor, we just need to re-arrange the last h and +// w dimension. For any shape that is not in 3D, i.e. [batch, W, H], we +// first convert it to 3D by collapsing other dimension to batch dim, then +// process with the last two dimensions. +// Note: we only need the shape tensor to calculate output shape, so the +// content in shape tensor is never uploaded to GPU. It is always kept in CPU. +// TODO: optimize the algorithm -- in some cases, if the last two dims are +// the same between input shape and output shape, the packed reshape can be +// treated as no-op. +function isReshapeCheap(dims, reshapedDims) { + let isCheapReshape = false; + if (dims.length === 0 || reshapedDims.length === 0) { // scalar + isCheapReshape = true; + } + else if (dims.length < 2 || reshapedDims.length < 2) { // 1D + isCheapReshape = dims[dims.length - 1] === reshapedDims[reshapedDims.length - 1]; + } + else { // 2D + + isCheapReshape = dims[dims.length - 1] === reshapedDims[reshapedDims.length - 1] && + dims[dims.length - 2] === reshapedDims[reshapedDims.length - 2]; + } + return isCheapReshape; +} +exports.isReshapeCheap = isReshapeCheap; +function getReshapedInputCoords(shape) { + const strides = util_1.ShapeUtil.computeStrides(shape); + const coords = ['b', 'r', 'c']; + const index = 'index'; + const coordsFromIndexSnippet = strides + .map((stride, i) => { + const line1 = `int ${coords[i]} = ${index} / ${stride}`; + const line2 = i === strides.length - 1 ? + `int ${coords[i + 1]} = ${index} - ${coords[i]} * ${stride}` : + `index -= ${coords[i]} * ${stride}`; + return `${line1}; ${line2};`; + }) + .join(''); + return ` + ivec3 inputCoordsFromReshapedOutCoords(int index) { + ${coordsFromIndexSnippet} + return ivec3(b, r, c); + } + `; +} +function getFlattenedIndexFrom3D(shape) { + const strides = util_1.ShapeUtil.computeStrides(shape); + return ` + int getFlattenedIndex(ivec3 coords) { + // reverse y, z order + return coords.x * ${strides[0]} + coords.z * ${strides[1]} + coords.y; + } +`; +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/reshape.ts": +/*!**************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/reshape.ts ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.reshape = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const reshape = (handler, inputs) => { + const reshapedDims = util_1.ShapeUtil.calculateReshapedDims(inputs[0].dims, inputs[1].integerData); + if (handler.session.pack) { + return [handler.reshapePacked(inputs[0], reshapedDims)]; + } + else { + return [handler.reshapeUnpacked(inputs[0], reshapedDims)]; + } +}; +exports.reshape = reshape; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/resize-packed.ts": +/*!********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/resize-packed.ts ***! + \********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseResizeAttributesV11 = exports.parseResizeAttributesV10 = exports.resize = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const upsample_1 = __webpack_require__(/*! ./upsample */ "./lib/onnxjs/backends/webgl/ops/upsample.ts"); +const resizeProgramMetadata = { + name: 'Resize', + inputNames: ['A'], + inputTypes: [types_1.TextureType.packed] +}; +const resize = (inferenceHandler, inputs, attributes) => { + (0, upsample_1.validateInputs)(inputs, attributes); + const output = inferenceHandler.run(Object.assign(Object.assign({}, resizeProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createPackedResizeProgramInfo(inferenceHandler, inputs, attributes) }), inputs); + return [output]; +}; +exports.resize = resize; +const parseResizeAttributesV10 = (node) => (0, upsample_1.parseUpsampleAttributes)(node, 10); +exports.parseResizeAttributesV10 = parseResizeAttributesV10; +const parseResizeAttributesV11 = (node) => (0, upsample_1.parseUpsampleAttributes)(node, 11); +exports.parseResizeAttributesV11 = parseResizeAttributesV11; +const createPackedResizeProgramInfo = (inferenceHandler, inputs, attributes) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const [scales, outputShape] = prepareInputs(inputs, attributes); + const isSame = scales.every((s) => s === 1) && attributes.coordinateTransformMode !== 'tf_crop_and_resize'; + if (isSame) { + return Object.assign(Object.assign({}, resizeProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.packed }, hasMain: true, shaderSource: `void main() { + vec4 v = ${glsl.texture2D}(X, TexCoords); + ${glsl.output} = v; + }` }); + } + const dim = outputShape.length; + if (dim < 2) { + throw new Error(`output dimension should be at least 2, but got ${dim}`); + } + const outputHeight = outputShape[dim - 2]; + const outputWidth = outputShape[dim - 1]; + const inputShape = inputs[0].dims; + if (dim !== inputShape.length) { + throw new Error(`output dimension should match input ${inputShape.length}, but got ${dim}`); + } + const inputHeight = inputShape[dim - 2]; + const inputWidth = inputShape[dim - 1]; + const scalesHeight = scales[dim - 2]; + const scalesWidth = scales[dim - 1]; + let getSourceFracIndex = ''; + if (attributes.mode !== 'linear') { + // TODO: support other modes + throw new Error(`resize (packed) does not support mode: '${attributes.mode}'`); + } + switch (attributes.coordinateTransformMode) { + case 'asymmetric': + getSourceFracIndex = ` + vec4 getSourceFracIndex(ivec4 coords) { + return vec4(coords) / scaleWHWH; + } + `; + break; + case 'half_pixel': + getSourceFracIndex = ` + vec4 getSourceFracIndex(ivec4 coords) { + return (vec4(coords) + 0.5) / scaleWHWH - 0.5; + } + `; + break; + case 'pytorch_half_pixel': + getSourceFracIndex = ` + vec4 getSourceFracIndex(ivec4 coords) { + vec4 fcoords = vec4(coords); + return vec4( + ${outputWidth}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0, + ${outputHeight}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0, + ${outputWidth}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0, + ${outputHeight}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0 + ); + } + `; + break; + case 'align_corners': + getSourceFracIndex = ` + vec4 getSourceFracIndex(ivec4 coords) { + vec4 resized = vec4(${outputWidth}.0 - 1.0, ${outputHeight}.0 - 1.0, ${outputWidth}.0 - 1.0, + ${outputHeight}.0 - 1.0); + vec4 original = vec4(${inputWidth}.0 - 1.0, ${inputHeight}.0 - 1.0, ${inputWidth}.0 - 1.0, + ${inputHeight}.0 - 1.0); + vec4 new_scale = original / resized; + return vec4(coords) * new_scale; + } + `; + break; + default: + // TODO:supporting other coordinateTransformModes + throw new Error(`resize (packed) does not support coordinateTransformMode: \ + '${attributes.coordinateTransformMode}'`); + } + const coordsDataType = (0, utils_1.getCoordsDataType)(dim); + const unpackChannel = (0, packing_utils_1.unpackFromChannel)(); + const shaderSource = ` + const vec2 inputWH = vec2(${inputHeight}.0, ${inputWidth}.0); + const vec4 scaleWHWH = vec4(float(${scalesHeight}), float(${scalesWidth}), float(${scalesHeight}), float(${scalesWidth})); + ${unpackChannel} + ${getSourceFracIndex} + float getAValue(int x10, int r, int c, int d) { + return getChannel(getA(x10, r, c, d), vec2(c, d)); + } + void main() { + ${coordsDataType} rc = getOutputCoords(); + + int batch = rc[0]; + int depth = rc[1]; + + // retrieve the 4 coordinates that is used in the 4 packed output values. + ivec4 coords = ivec4(rc.wz, rc.w + 1, rc.z + 1); + + // calculate the source index in fraction + vec4 sourceFrac = getSourceFracIndex(coords); + + // get the lower and upper bound of the 4 values that will be packed into one texel. + ivec4 x00 = ivec4(max(sourceFrac.xy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xy))); + ivec4 x01 = ivec4(max(sourceFrac.xw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xw))); + ivec4 x10 = ivec4(max(sourceFrac.zy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zy))); + ivec4 x11 = ivec4(max(sourceFrac.zw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zw))); + + bool hasNextRow = rc.w < ${outputHeight - 1}; + bool hasNextCol = rc.z < ${outputWidth - 1}; + + // pack x00, x01, x10, x11's top-left corner into one vec4 structure + vec4 topLeft = vec4( + getAValue(batch, depth, x00.x, x00.y), + hasNextCol ? getAValue(batch, depth, x01.x, x01.y) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.x, x10.y) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.y) : 0.0); + + // pack x00, x01, x10, x11's top-right corner into one vec4 structure + vec4 topRight = vec4( + getAValue(batch, depth, x00.x, x00.w), + hasNextCol ? getAValue(batch, depth, x01.x, x01.w) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.x, x10.w) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.w) : 0.0); + + // pack x00, x01, x10, x11's bottom-left corner into one vec4 structure + vec4 bottomLeft = vec4( + getAValue(batch, depth, x00.z, x00.y), + hasNextCol ? getAValue(batch, depth, x01.z, x01.y) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.z, x10.y) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.y) : 0.0); + + // pack x00, x01, x10, x11's bottom-right corner into one vec4 structure + vec4 bottomRight = vec4( + getAValue(batch, depth, x00.z, x00.w), + hasNextCol ? getAValue(batch, depth, x01.z, x01.w) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.z, x10.w) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.w) : 0.0); + + // calculate the interpolation fraction on u and v direction + vec4 frac = vec4(sourceFrac) - floor(sourceFrac); + vec4 clampFrac = clamp(frac, vec4(0.0), vec4(1.0)); + + vec4 top = mix(topLeft, topRight, clampFrac.ywyw); + vec4 bottom = mix(bottomLeft, bottomRight, clampFrac.ywyw); + vec4 newValue = mix(top, bottom, clampFrac.xxzz); + + ${glsl.output} = vec4(newValue); + } + `; + return Object.assign(Object.assign({}, resizeProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.packed }, hasMain: true, shaderSource }); +}; +const prepareInputs = (inputs, attributes) => { + const x = inputs[0]; + const xDims = x.dims; + let scales = attributes.scales; + let outputSizes; + if (scales.length === 0) { + const scalesTensor = inputs[attributes.scalesInputIdx]; + if (scalesTensor && scalesTensor.size !== 0) { + if (inputs[attributes.sizesInputIdx]) { + throw new Error('Only one of scales or sizes must be provided as input.'); + } + scales = parseScalesData(scalesTensor, attributes.mode, attributes.isResize); + } + else { + const sizesTensor = inputs[attributes.sizesInputIdx]; + if (!sizesTensor || sizesTensor.size === 0) { + throw new Error('Either scales or sizes MUST be provided as input.'); + } + outputSizes = Array.from(sizesTensor.integerData); + scales = parseScalesDataFromOutputSize(outputSizes, xDims, attributes.mode, attributes.isResize); + } + } + else { + if (inputs[attributes.sizesInputIdx]) { + throw new Error('Only one of scales or sizes must be provided as input.'); + } + } + const yDims = outputSizes || (xDims.map((dim, i) => Math.floor(dim * scales[i]))); + return [scales, yDims]; +}; +const parseScalesData = (scale, mode, isResize) => { + const scales = Array.from(scale.floatData); + (0, upsample_1.scalesValidation)(scales, mode, isResize); + return scales; +}; +const parseScalesDataFromOutputSize = (yDims, xDims, mode, isResize) => { + const length = xDims.length; + const scales = new Array(length); + for (let i = 0, end = length; i < end; i++) { + if (xDims[i] === 0) { + if (yDims[i] !== 0) { + throw new Error('Input dim is zero but required output dim is non-zero.'); + } + scales[i] = 1; + } + else { + scales[i] = yDims[i] / xDims[i]; + } + } + (0, upsample_1.scalesValidation)(scales, mode, isResize); + return scales; +}; +// roi data is not used yet. but leave here for future usage. +// const getRoi = (inputs: Tensor[], attributes: UpsampleAttributes) : number[] => { +// let roi: number[] = []; +// if (attributes.needRoiInput) { +// if (attributes.roiInputIdx <= 0) { +// throw new Error('Invalid roi input index.'); +// } +// const roiTensor = inputs[attributes.roiInputIdx]; +// roi = roiTensor.size > 0 ? Array.from(roiTensor.floatData) : []; +// } else { +// roi = new Array(inputs[0].dims.length * 2).fill(0); +// } +// return roi; +// }; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/shape.ts": +/*!************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/shape.ts ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.shape = void 0; +const tensor_1 = __webpack_require__(/*! ../../../tensor */ "./lib/onnxjs/tensor.ts"); +const shape = (inferenceHandler, inputs) => { + validateInputs(inputs); + return [new tensor_1.Tensor([inputs[0].dims.length], 'int32', undefined, undefined, new Int32Array(inputs[0].dims))]; +}; +exports.shape = shape; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Shape requires 1 input.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/slice.ts": +/*!************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/slice.ts ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.sliceV10 = exports.parseSliceAttributes = exports.slice = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const operators_1 = __webpack_require__(/*! ../../../operators */ "./lib/onnxjs/operators.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const sliceProgramMetadata = { + name: 'Slice', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked] +}; +const slice = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, sliceProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createSliceProgramInfo(inferenceHandler, inputs[0], attributes) }), inputs); + return [output]; +}; +exports.slice = slice; +const parseSliceAttributes = (node) => { + const starts = node.attributes.getInts('starts'); + const ends = node.attributes.getInts('ends'); + const axes = node.attributes.getInts('axes', []); + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ starts, ends, axes }); +}; +exports.parseSliceAttributes = parseSliceAttributes; +const createSliceProgramInfo = (inferenceHandler, input, attributes) => { + const axes = (attributes.axes.length === 0) ? input.dims.slice(0).map((val, i) => i) : attributes.axes; + const normalizedAxes = util_1.ShapeUtil.normalizeAxes(axes, input.dims.length); + const starts = attributes.starts.map((start, i) => { + if (start > input.dims[normalizedAxes[i]] - 1) { + return input.dims[normalizedAxes[i]]; + } + return util_1.ShapeUtil.normalizeAxis(start, input.dims[normalizedAxes[i]]); + }); + const ends = attributes.ends.map((end, i) => { + if (end > input.dims[normalizedAxes[i]] - 1) { + return input.dims[normalizedAxes[i]]; + } + return util_1.ShapeUtil.normalizeAxis(end, input.dims[normalizedAxes[i]]); + }); + const outputShape = input.dims.slice(); + const sliceOps = []; + for (let i = 0; i < normalizedAxes.length; i++) { + outputShape[normalizedAxes[i]] = ends[i] - starts[i]; + if (starts[i] > 0) { + sliceOps.push(`outputIdx[${normalizedAxes[i]}] += ${starts[i]};`); + } // else { sliceOps.push(`outputIdx[${normalizedAxes[i]}] += 0;`); } + } + const rank = outputShape.length; + const shaderSource = ` + float process(int outputIdx[${rank}]) { + ${sliceOps.join('\n ')} + return _A(outputIdx); + }`; + return Object.assign(Object.assign({}, sliceProgramMetadata), { output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Slice requires 1 input.'); + } + if (operators_1.NUMBER_TYPES.indexOf(inputs[0].type) === -1) { + throw new Error('Invalid input type.'); + } +}; +const sliceV10 = (inferenceHandler, inputs) => { + validateInputsV10(inputs); + const attributes = generateSliceAttributesFromInputs(inferenceHandler, inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, sliceProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createSliceProgramInfo(inferenceHandler, inputs[0], attributes) }), [inputs[0]]); + return [output]; +}; +exports.sliceV10 = sliceV10; +const generateSliceAttributesFromInputs = (inferenceHandler, inputs) => { + if (!inferenceHandler.session.isInitializer(inputs[1].dataId) || + !inferenceHandler.session.isInitializer(inputs[2].dataId) || + (inputs.length >= 4 && !inferenceHandler.session.isInitializer(inputs[3].dataId)) || + (inputs.length >= 5 && !inferenceHandler.session.isInitializer(inputs[4].dataId))) { + throw new Error('dynamic slice attributes are not allowed'); + } + if (inputs.length >= 5 && inputs[4].integerData.some((i) => i !== 1)) { + throw new Error('currently non-1 steps is not supported for Slice'); + } + const starts = Array.from(inputs[1].integerData); + const ends = Array.from(inputs[2].integerData); + const axes = inputs.length >= 4 ? Array.from(inputs[3].integerData) : []; + const cacheKey = `${axes};${starts};${ends}`; + return { starts, ends, axes, cacheKey }; +}; +const validateInputsV10 = (inputs) => { + if (!inputs || inputs.length < 3 || inputs.length > 5) { + throw new Error('Invalid input number.'); + } + if (inputs[1].type !== 'int32' || inputs[1].dims.length !== 1) { + throw new Error('Invalid input type.'); + } + if (inputs[2].type !== 'int32' || inputs[2].dims.length !== 1) { + throw new Error('Invalid input type.'); + } + if (inputs.length >= 4 && (inputs[3].type !== 'int32' || inputs[3].dims.length !== 1)) { + throw new Error('Invalid input type.'); + } + if (inputs.length >= 5 && (inputs[4].type !== 'int32' || inputs[4].dims.length !== 1)) { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/softmax.ts": +/*!**************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/softmax.ts ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.softmaxV13 = exports.parseSoftmaxAttributesV13 = exports.parseSoftmaxAttributes = exports.softmax = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const transpose_1 = __webpack_require__(/*! ./transpose */ "./lib/onnxjs/backends/webgl/ops/transpose.ts"); +const softmaxComputeMaxProgramMetadata = { + name: 'SoftmaxComputeMax', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], +}; +const softmaxComputeScaleProgramMetadata = { + name: 'SoftmaxComputeScale', + inputNames: ['A', 'Max'], + inputTypes: [types_1.TextureType.unpacked, types_1.TextureType.unpacked], +}; +const softmaxProgramMetadata = { + name: 'SoftMax', + inputNames: ['A', 'Max', 'Norm'], + inputTypes: [types_1.TextureType.unpacked, types_1.TextureType.unpacked, types_1.TextureType.unpacked], +}; +const softmax = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const inputShape = inputs[0].dims.slice(); + const axis = util_1.ShapeUtil.normalizeAxis(attributes.axis, inputShape.length); + const logicalRowCount = util_1.ShapeUtil.sizeToDimension(inputShape, axis); + const featureCount = util_1.ShapeUtil.sizeFromDimension(inputShape, axis); + const output = computeSoftmax(inferenceHandler, inputs, attributes, logicalRowCount, featureCount); + return output; +}; +exports.softmax = softmax; +const parseSoftmaxAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axis: node.attributes.getInt('axis', 1) }); +exports.parseSoftmaxAttributes = parseSoftmaxAttributes; +const parseSoftmaxAttributesV13 = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axis: node.attributes.getInt('axis', -1) }); +exports.parseSoftmaxAttributesV13 = parseSoftmaxAttributesV13; +// The "semantic" meaning of axis has changed in opset-13. +// Please compare: https://github.com/onnx/onnx/blob/main/docs/Operators.md#Softmax +// with https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Softmax-11 for detailed explanations +// To account for the opset-13 behavior, our plan will be to transpose the "axis" dim to the innermost dim +// and perform softmax and then reverse the transpose. We can skip the transposing aspect if the axis is already +// the innermost dim +const softmaxV13 = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const inputShape = inputs[0].dims.slice(); + const axis = util_1.ShapeUtil.normalizeAxis(attributes.axis, inputShape.length); + const rank = inputShape.length; + const isTransposeRequired = (axis !== rank - 1) ? true : false; + const transposedInputShape = []; + let perm = []; + let transposedInputs = []; + let transposeAttribute; + if (isTransposeRequired) { + perm = Array.from({ length: rank }).map((_, i) => i); + // swap the innermost dim with the dim corresponding to axis + perm[axis] = rank - 1; + perm[rank - 1] = axis; + perm.map(p => transposedInputShape.push(inputShape[p])); + transposeAttribute = (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ perm }); + transposedInputs = (0, transpose_1.transpose)(inferenceHandler, inputs, transposeAttribute); + } + const logicalRowCount = isTransposeRequired ? util_1.ShapeUtil.sizeToDimension(transposedInputShape, rank - 1) : + util_1.ShapeUtil.sizeToDimension(inputShape, rank - 1); + const featureCount = isTransposeRequired ? util_1.ShapeUtil.sizeFromDimension(transposedInputShape, rank - 1) : + util_1.ShapeUtil.sizeFromDimension(inputShape, rank - 1); + const output = computeSoftmax(inferenceHandler, isTransposeRequired ? transposedInputs : inputs, attributes, logicalRowCount, featureCount); + if (isTransposeRequired) { + const reversedOutput = (0, transpose_1.transpose)(inferenceHandler, output, transposeAttribute); + return reversedOutput; + } + else { + return output; + } +}; +exports.softmaxV13 = softmaxV13; +const computeSoftmax = (inferenceHandler, inputs, attributes, logicalRowCount, featureCount) => { + const computeMaxProgramInfo = createComputeMaxProgramInfo(inferenceHandler, inputs[0], logicalRowCount, featureCount, [logicalRowCount]); + const max = inferenceHandler.run(Object.assign(Object.assign({}, softmaxComputeMaxProgramMetadata), { cacheHint: attributes.cacheKey, get: () => computeMaxProgramInfo }), inputs); + const computeScaleProgramInfo = createComputScaleProgramInfo(inferenceHandler, inputs[0], logicalRowCount, featureCount, computeMaxProgramInfo.output.dims, [logicalRowCount]); + const scale = inferenceHandler.run(Object.assign(Object.assign({}, softmaxComputeScaleProgramMetadata), { cacheHint: attributes.cacheKey, get: () => computeScaleProgramInfo }), [inputs[0], max]); + const softMaxProgramInfo = createSoftMaxProgramInfo(inferenceHandler, inputs[0], logicalRowCount, featureCount, computeMaxProgramInfo.output.dims, computeScaleProgramInfo.output.dims); + const output = inferenceHandler.run(Object.assign(Object.assign({}, softmaxProgramMetadata), { cacheHint: attributes.cacheKey, get: () => softMaxProgramInfo }), [inputs[0], max, scale]); + return [output]; +}; +/** + * Create a texture that contains the maximum value of each of the 'N' rows + */ +const createComputeMaxProgramInfo = (inferenceHandler, input, logicalRowCount, featureCount, outputShape) => { + const [textureWidth, textureHeight] = inferenceHandler.calculateTextureWidthAndHeight(input.dims, types_1.TextureType.unpacked); + const rank = outputShape.length; + if (logicalRowCount < 1 || featureCount < 1) { + throw new Error('Logical row count N and feature count D must be greater than or equal to 1'); + } + if (outputShape.length !== 1) { + throw new Error('Dimensionality of the output should be 1'); + } + if (outputShape[0] !== logicalRowCount) { + throw new Error('Shape of the output should be equal to logical row count'); + } + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const shaderSource = ` + float process(int[${rank}] indices) { + int logical_row_start_offset = indices[0] * ${featureCount}; + + float max = getColorAsFloat(${glsl.texture2D}(A, offsetToCoords(logical_row_start_offset, ${textureWidth}, + ${textureHeight} ))); + for(int i=1; i<${featureCount}; ++i) + { + float current = getColorAsFloat(${glsl.texture2D}(A, offsetToCoords(logical_row_start_offset + i, + ${textureWidth}, ${textureHeight}))); + if(current > max) + max = current; + } + + return max; + }`; + return Object.assign(Object.assign({}, softmaxComputeMaxProgramMetadata), { output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +/** + * Create a texture that contains the normalization factor for each of the 'N' rows + */ +const createComputScaleProgramInfo = (inferenceHandler, input, logicalRowCount, featureCount, maxElementPerLogicalRow, outputShape) => { + const [textureWidth, textureHeight] = inferenceHandler.calculateTextureWidthAndHeight(input.dims, types_1.TextureType.unpacked); + const rank = outputShape.length; + if (logicalRowCount < 1 || featureCount < 1) { + throw new Error('Logical row count N and feature count D must be greater than or equal to 1'); + } + if (outputShape.length !== 1) { + throw new Error('Dimensionality of the output should be 1'); + } + if (outputShape[0] !== logicalRowCount) { + throw new Error('Shape of the output should be equal to logical row count'); + } + if (maxElementPerLogicalRow.length !== 1) { + throw new Error('Dimensionality of the intermediate results should be 1'); + } + if (maxElementPerLogicalRow[0] !== logicalRowCount) { + throw new Error('Shape of the intermediate results should be equal to logical row count'); + } + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const shaderSource = ` + float process(int[${rank}] indices) { + int logical_row_start_offset = indices[0] * ${featureCount}; + + float norm_factor = 0.0; + float max = _Max(indices); + for(int i=0; i<${featureCount}; ++i) + { + norm_factor += exp(getColorAsFloat(${glsl.texture2D}(A, offsetToCoords(logical_row_start_offset + i, + ${textureWidth}, ${textureHeight}))) - max); + } + + return norm_factor; + }`; + return Object.assign(Object.assign({}, softmaxComputeScaleProgramMetadata), { output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const createSoftMaxProgramInfo = (inferenceHandler, input, logicalRowCount, featureCount, maxElementPerLogicalRow, normalizationPerLogicalRow) => { + const [textureWidth, textureHeight] = inferenceHandler.calculateTextureWidthAndHeight(input.dims, types_1.TextureType.unpacked); + const rank = input.dims.length; + if (logicalRowCount < 1 || featureCount < 1) { + throw new Error('Logical row count N and feature count D must be greater than or equal to 1'); + } + if (maxElementPerLogicalRow.length !== 1 || normalizationPerLogicalRow.length !== 1) { + throw new Error('Dimensionality of the intermediate results should be 1'); + } + if (maxElementPerLogicalRow[0] !== logicalRowCount || normalizationPerLogicalRow[0] !== logicalRowCount) { + throw new Error('Shape of the intermediate results should be equal to logical row count'); + } + const shaderSource = ` + float process(int[${rank}] indices) { + + // get offset of current logical tensor index from the 2-D texture coordinates (TexCoords) + int offset = coordsToOffset(TexCoords, ${textureWidth}, ${textureHeight}); + + //determine the logical row for this index + int logical_row_index[1]; + logical_row_index[0] = offset / ${featureCount}; + + float norm_factor = _Norm(logical_row_index); + + // avoid possible division by 0 + // if norm_facor is 0, all elements are zero + // if so, return 0 + if(norm_factor == 0.0) + return 0.0; + + return exp(_A(indices) - _Max(logical_row_index)) / norm_factor; + }`; + return Object.assign(Object.assign({}, softmaxProgramMetadata), { output: { dims: input.dims, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Softmax requires 1 input.'); + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('Invalid input type'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/split.ts": +/*!************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/split.ts ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseSplitAttributes = exports.split = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const splitProgramMetadata = { + name: 'Split', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], +}; +const split = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const axis = util_1.ShapeUtil.normalizeAxis(attributes.axis, inputs[0].dims.length); + const count = getProgramCount(inferenceHandler, inputs, axis, attributes); + const output = []; + for (let i = 0; i < count; ++i) { + output.push(inferenceHandler.run(Object.assign(Object.assign({}, splitProgramMetadata), { cacheHint: `${attributes.cacheKey};${i}`, get: () => createSplitProgramInfo(inferenceHandler, inputs[0], attributes, axis, i) }), inputs)); + } + return output; +}; +exports.split = split; +const parseSplitAttributes = (node) => { + const axis = node.attributes.getInt('axis', 0); + const split = node.attributes.getInts('split', []); + const numOutputs = node.outputs.length; + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ axis, split, numOutputs }); +}; +exports.parseSplitAttributes = parseSplitAttributes; +const getProgramCount = (inferenceHandler, inputs, axis, attributes) => { + const [, offsets] = util_1.SplitUtil.splitShape(inputs[0].dims, axis, attributes.split, attributes.numOutputs); + return offsets.length; +}; +const createSplitProgramInfo = (inferenceHandler, input, attributes, axis, index) => { + const [shapes, offsets] = util_1.SplitUtil.splitShape(input.dims, axis, attributes.split, attributes.numOutputs); + const offset = offsets[index]; + const outputShape = shapes[index]; + const rank = outputShape.length; + const shaderSource = ` + float process(int indices[${rank}]) { + indices[${axis}] += ${offset}; + return _A(indices); + } + `; + return Object.assign(Object.assign({}, splitProgramMetadata), { cacheHint: `${attributes.cacheKey}:${index}`, output: { dims: outputShape, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Split requires one input.'); + } + if (inputs[0].type !== 'int8' && inputs[0].type !== 'uint8' && inputs[0].type !== 'int16' && + inputs[0].type !== 'uint16' && inputs[0].type !== 'int32' && inputs[0].type !== 'uint32' && + inputs[0].type !== 'float32' && inputs[0].type !== 'float64' && inputs[0].type !== 'bool') { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/squeeze.ts": +/*!**************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/squeeze.ts ***! + \**************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseSqueezeAttributes = exports.squeezeV13 = exports.squeeze = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const squeeze = (inferenceHandler, inputs, axes) => { + validateInputs(inputs); + const outputShape = util_1.ShapeUtil.squeezeShape(inputs[0].dims, axes); + const output = inferenceHandler.reshapeUnpacked(inputs[0], outputShape); + return [output]; +}; +exports.squeeze = squeeze; +const squeezeV13 = (inferenceHandler, inputs) => { + validateInputsV13(inputs); + return (0, exports.squeeze)(inferenceHandler, [inputs[0]], Array.from(inputs[1].integerData)); +}; +exports.squeezeV13 = squeezeV13; +const parseSqueezeAttributes = (node) => node.attributes.getInts('axes'); +exports.parseSqueezeAttributes = parseSqueezeAttributes; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Squeeze requires 1 input.'); + } + if (inputs[0].type === 'string') { + throw new Error('invalid input tensor types.'); + } +}; +const validateInputsV13 = (inputs) => { + if (!inputs || inputs.length !== 2) { + throw new Error('Squeeze requires 2 inputs.'); + } + if (inputs[1].type !== 'int32') { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/sum.ts": +/*!**********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/sum.ts ***! + \**********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.sum = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const sum = (inferenceHandler, inputs) => { + validateInputs(inputs); + const sumProgramMetadata = { + name: 'Sum', + inputNames: inputs.map((v, i) => `X${i}`), + inputTypes: new Array(inputs.length).fill(types_1.TextureType.unpacked) + }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, sumProgramMetadata), { get: () => createSumProgramInfo(inferenceHandler, inputs, sumProgramMetadata) }), inputs); + return [output]; +}; +exports.sum = sum; +const createSumProgramInfo = (inferenceHandler, inputs, sumProgramMetadata) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const outputShape = inputs[0].dims.slice(); + const sumLine = inputs.map((v, i) => `${glsl.texture2D}(X${i},TexCoords)`).join(' + '); + const shaderSource = ` + void main() { + vec4 result = ${sumLine}; + ${glsl.output} = result; + } + `; + return Object.assign(Object.assign({}, sumProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, hasMain: true, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length === 0) { + throw new Error('Sum requires inputs.'); + } + const length = inputs[0].dims.length; + for (let i = 1; i < inputs.length; i++) { + if (length !== inputs[i].dims.length) { + throw new Error('Input shapes are mismatched.'); + } + for (let j = 0; j < length; j++) { + if (inputs[0].dims[j] !== inputs[i].dims[j]) { + throw new Error('Input shapes are not matched.'); + } + } + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('Invalid input type.'); + } + for (let i = 1; i < inputs.length; i++) { + if (inputs[0].type !== inputs[i].type) { + throw new Error('Input types are not matched.'); + } + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/tile.ts": +/*!***********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/tile.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.tile = void 0; +const operators_1 = __webpack_require__(/*! ../../../operators */ "./lib/onnxjs/operators.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const tile = (inferenceHandler, inputs) => { + validateInputs(inputs); + const tileProgramMetadata = { + name: 'Tile', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked], + }; + const output = inferenceHandler.run(Object.assign(Object.assign({}, tileProgramMetadata), { get: () => createTileProgramInfo(inferenceHandler, inputs, tileProgramMetadata) }), inputs); + return [output]; +}; +exports.tile = tile; +const createTileProgramInfo = (handler, inputs, tileProgramMetadata) => { + const inputShape = inputs[0].dims.slice(); + const outputShape = new Array(inputShape.length); + const tileOps = []; + for (let i = 0; i < inputShape.length; i++) { + outputShape[i] = inputShape[i] * inputs[1].numberData[i]; + tileOps.push(`inputIdx[${i}] = int(mod(float(outputIdx[${i}]), ${inputShape[i]}.));`); + } + const rank = outputShape.length; + const shaderSource = ` + float process(int outputIdx[${rank}]) { + int inputIdx[${rank}]; + ${tileOps.join('\n')} + return _A(inputIdx); + } + `; + return Object.assign(Object.assign({}, tileProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 2) { + throw new Error('Tile requires 2 input.'); + } + if (inputs[1].dims.length !== 1) { + throw new Error('The second input shape must 1 dimension.'); + } + if (inputs[1].dims[0] !== inputs[0].dims.length) { + throw new Error('Invalid input shape.'); + } + if (operators_1.NUMBER_TYPES.indexOf(inputs[0].type) === -1) { + throw new Error('Invalid input type.'); + } + if (inputs[1].type !== 'int32' && inputs[1].type !== 'int16') { + throw new Error('Invalid repeat type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/transpose.ts": +/*!****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/transpose.ts ***! + \****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseTransposeAttributes = exports.transpose = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const transposeProgramMetadata = { + name: 'Transpose', + inputNames: ['A'], + inputTypes: [types_1.TextureType.unpacked] +}; +const transpose = (inferenceHandler, inputs, attributes) => { + validateInputs(inputs); + const output = inferenceHandler.run(Object.assign(Object.assign({}, transposeProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createTransposeProgramInfo(inferenceHandler, inputs[0], attributes.perm) }), inputs); + return [output]; +}; +exports.transpose = transpose; +const parseTransposeAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ perm: node.attributes.getInts('perm', []) }); +exports.parseTransposeAttributes = parseTransposeAttributes; +const createTransposeProgramInfo = (inferenceHandler, input, perm) => { + const inputShape = input.dims; + perm = getAdjustedPerm(inputShape, perm); + const unpackedOutputShape = getOutputShape(inputShape, perm); + const rank = inputShape.length; + // A dims=[${inputs[0].dims.toString()}] + // out Dims=[${unpackedOutputShape.toString()}] + // based on perm=[${perm.toString()}] + const shaderSource = ` + ${getPermFunctionBody('perm', perm, rank)} + float process(int indices[${rank}]) { + int a[${rank}]; + perm(a, indices); + return _A(a); + }`; + return Object.assign(Object.assign({}, transposeProgramMetadata), { output: { dims: unpackedOutputShape, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +const getAdjustedPerm = (inputShape, perm) => { + if (perm && perm.length !== inputShape.length) { + perm = [...(inputShape.keys())].reverse(); + } + return perm; +}; +const getOutputShape = (inputShape, perm) => { + perm = getAdjustedPerm(inputShape, perm); + return util_1.ShapeUtil.sortBasedOnPerm(inputShape, perm); +}; +const getPermFunctionBody = (name, perm, rank) => { + const reverseFunc = []; + reverseFunc.push(`void ${name}(out int a[${rank}], int src[${rank}]) {`); + for (let i = 0; i < rank; ++i) { + reverseFunc.push(`\ta[${perm[i]}]=src[${i}];`); + } + reverseFunc.push('\t}'); + return reverseFunc.join('\n'); +}; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Transpose requires 1 input.'); + } + if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { + throw new Error('input should be float tensor'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/uint8-encode.ts": +/*!*******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/uint8-encode.ts ***! + \*******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.encodeAsUint8 = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const encodeAsUint8 = (inferenceHandler, input) => { + const outputShape = input.shape; + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + /** + * https://github.com/tensorflow/tfjs-core/blob/master/src/kernels/webgl/encode_float_gpu.ts + */ + const shaderSource = ` + const float FLOAT_MAX = 1.70141184e38; + const float FLOAT_MIN = 1.17549435e-38; + + bool isNaN(float val) { + return (val < 1.0 || 0.0 < val || val == 0.0) ? false : true; + } + + highp vec4 encodeAsUint8(highp float v) { + if (isNaN(v)) { + return vec4(255, 255, 255, 255); + } + + highp float av = abs(v); + + if(av < FLOAT_MIN) { + return vec4(0.0, 0.0, 0.0, 0.0); + } else if(v > FLOAT_MAX) { + return vec4(0.0, 0.0, 128.0, 127.0) / 255.0; + } else if(v < -FLOAT_MAX) { + return vec4(0.0, 0.0, 128.0, 255.0) / 255.0; + } + + highp vec4 c = vec4(0,0,0,0); + + highp float e = floor(log2(av)); + highp float m = exp2(fract(log2(av))) - 1.0; + + c[2] = floor(128.0 * m); + m -= c[2] / 128.0; + c[1] = floor(32768.0 * m); + m -= c[1] / 32768.0; + c[0] = floor(8388608.0 * m); + + highp float ebias = e + 127.0; + c[3] = floor(ebias / 2.0); + ebias -= c[3] * 2.0; + c[2] += floor(ebias) * 128.0; + + c[3] += 128.0 * step(0.0, -v); + + return c / 255.0; + } + + void main() { + float value = ${glsl.texture2D}(X,TexCoords).r; + ${glsl.output} = encodeAsUint8(value); + }`; + const programInfo = { + name: 'Uint8Encode', + inputTypes: [types_1.TextureType.unpacked], + inputNames: ['X'], + output: { dims: outputShape, type: input.tensor.type, textureType: types_1.TextureType.downloadUint8AsFloat }, + shaderSource, + hasMain: true + }; + return inferenceHandler.executeProgram(programInfo, [input.tensor]); +}; +exports.encodeAsUint8 = encodeAsUint8; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/unary-op.ts": +/*!***************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/unary-op.ts ***! + \***************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.tanh = exports.tan = exports.sqrt = exports.sin = exports.sigmoid = exports.relu = exports.not = exports.neg = exports.log = exports.parseLeakyReluAttributes = exports.leakyRelu = exports.identity = exports.floor = exports.exp = exports.parseEluAttributes = exports.elu = exports.cos = exports.ceil = exports.clipV11 = exports.parseClipAttributes = exports.clip = exports.atan = exports.asin = exports.acos = exports.abs = exports.glslTanh = exports.glslTan = exports.glslSqrt = exports.glslSigmoid = exports.glslRelu = exports.glslSin = exports.glslNot = exports.glslNeg = exports.glslLog = exports.glslLeakyRelu = exports.glslIdentity = exports.glslClip = exports.glslFloor = exports.glslExp = exports.glslElu = exports.glslCos = exports.glslCeil = exports.glslAtan = exports.glslAsin = exports.glslAcos = exports.glslAbs = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const glsl_definitions_1 = __webpack_require__(/*! ../glsl-definitions */ "./lib/onnxjs/backends/webgl/glsl-definitions.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +function glslAbs() { + return glslBuiltinUnary('abs'); +} +exports.glslAbs = glslAbs; +function glslAcos() { + return glslBuiltinUnary('acos'); +} +exports.glslAcos = glslAcos; +function glslAsin() { + return glslBuiltinUnary('asin'); +} +exports.glslAsin = glslAsin; +function glslAtan() { + return glslBuiltinUnary('atan'); +} +exports.glslAtan = glslAtan; +function glslCeil() { + return glslBuiltinUnary('ceil'); +} +exports.glslCeil = glslCeil; +function glslCos() { + return glslBuiltinUnary('cos'); +} +exports.glslCos = glslCos; +function glslElu(alpha) { + const name = 'elu'; + const body = ` + const float alpha = float(${alpha}); + + float ${name}_(float a) { + return a >= 0.0 ? a: (exp(a) - 1.0) * alpha; + } + vec4 ${name}_(vec4 v) { + return vec4(${name}_(v.x), ${name}_(v.y), ${name}_(v.z), ${name}_(v.w)); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslElu = glslElu; +function glslExp() { + return glslBuiltinUnary('exp'); +} +exports.glslExp = glslExp; +function glslFloor() { + return glslBuiltinUnary('floor'); +} +exports.glslFloor = glslFloor; +function glslClip(min, max) { + const name = 'clip'; + const body = ` + const float min = float(${min}); + const float max = float(${max}); + + float ${name}_(float a) { + return clamp(a, min, max); + } + vec4 ${name}_(vec4 v) { + return clamp(v, min, max); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslClip = glslClip; +function glslIdentity() { + const name = 'indentity'; + const body = ` + float ${name}_(float a) { + return a; + } + vec4 ${name}_(vec4 v) { + return v; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslIdentity = glslIdentity; +function glslLeakyRelu(alpha) { + const name = 'leakyRelu'; + const body = ` + const float alpha = float(${alpha}); + + float ${name}_(float a) { + return a < 0.0 ? a * alpha : a; + } + vec4 ${name}_(vec4 v) { + return vec4(${name}_(v.x), ${name}_(v.y), ${name}_(v.z), ${name}_(v.w)); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslLeakyRelu = glslLeakyRelu; +function glslLog() { + return glslBuiltinUnary('log'); +} +exports.glslLog = glslLog; +function glslNeg() { + const name = 'neg'; + const body = ` + float ${name}_(float a) { + return -a; + } + vec4 ${name}_(vec4 v) { + return -v; + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslNeg = glslNeg; +function glslNot() { + const name = 'not'; + const body = ` + float ${name}_(float a) { + return float( ! bool(a) ); + } + bool ${name}_(bool a) { + return !a; + } + vec4 ${name}_(vec4 v) { + return vec4(!bool(v.x), !bool(v.y), !bool(v.z), !bool(v.w)); + } + bvec4 ${name}_(bvec4 v) { + return bvec4(!v.x, !v.y, !v.z, !v.w); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslNot = glslNot; +function glslSin() { + return glslBuiltinUnary('sin'); +} +exports.glslSin = glslSin; +function glslRelu() { + const name = 'relu'; + const body = ` + float ${name}_(float a) { + return max( a, 0.0 ); + } + vec4 ${name}_(vec4 v) { + return max( v, 0.0 ); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslRelu = glslRelu; +function glslSigmoid() { + const name = 'sigmoid'; + const body = ` + float ${name}_(float a) { + return 1.0 / (1.0 + exp(-a)); + } + vec4 ${name}_(vec4 v) { + return 1.0 / (1.0 + exp(-v)); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslSigmoid = glslSigmoid; +function glslSqrt() { + return glslBuiltinUnary('sqrt'); +} +exports.glslSqrt = glslSqrt; +function glslTan() { + return glslBuiltinUnary('tan'); +} +exports.glslTan = glslTan; +function glslTanh() { + const name = 'tanh'; + const body = ` + float ${name}_(float a) { + a = clamp(a, -10., 10.); + a = exp(2.*a); + return (a - 1.) / (a + 1.); + } + vec4 ${name}_(vec4 v) { + v = clamp(v, -10., 10.); + v = exp(2.*v); + return (v - 1.) / (v + 1.); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +exports.glslTanh = glslTanh; +function glslBuiltinUnary(name) { + const body = ` + float ${name}_(float a) { + return ${name}(a); + } + vec4 ${name}_(vec4 v) { + return ${name}(v); + } + `; + return { body, name, type: glsl_definitions_1.FunctionType.ValueBased }; +} +///// +///// +///// +const createElementwiseProgramInfo = (handler, metadata, input, glslFunc) => { + const textureType = handler.session.pack ? types_1.TextureType.packed : types_1.TextureType.unpacked; + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + return Object.assign(Object.assign({}, metadata), { output: { dims: input.dims, type: input.type, textureType }, shaderSource: ` + ${glslFunc.body} + void main() { + vec4 v = ${glsl.texture2D}(A, TexCoords); + v = ${glslFunc.name}_(v); + ${glsl.output} = v; + } + `, hasMain: true }); +}; +const createElementwiseProgramInfoLoader = (handler, input, glslFunc, cacheKey) => { + const textureType = handler.session.pack ? types_1.TextureType.packed : types_1.TextureType.unpacked; + const metadata = { name: glslFunc.name, inputTypes: [textureType], inputNames: ['A'], cacheHint: cacheKey }; + return Object.assign(Object.assign({}, metadata), { get: () => createElementwiseProgramInfo(handler, metadata, input, glslFunc) }); +}; +const abs = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslAbs()), inputs)]; +exports.abs = abs; +const acos = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslAcos()), inputs)]; +exports.acos = acos; +const asin = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslAsin()), inputs)]; +exports.asin = asin; +const atan = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslAtan()), inputs)]; +exports.atan = atan; +const clip = (handler, inputs, attributes) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslClip(attributes.min, attributes.max), attributes.cacheKey), inputs)]; +exports.clip = clip; +const parseClipAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ min: node.attributes.getFloat('min', util_1.MIN_CLIP), max: node.attributes.getFloat('max', util_1.MAX_CLIP) }); +exports.parseClipAttributes = parseClipAttributes; +const clipV11 = (handler, inputs) => { + const attributes = generateClipAttributesFromInputs(handler, inputs); + return (0, exports.clip)(handler, [inputs[0]], attributes); +}; +exports.clipV11 = clipV11; +const generateClipAttributesFromInputs = (handler, inputs) => { + if (inputs.length >= 3 && + (!handler.session.isInitializer(inputs[1].dataId) || !handler.session.isInitializer(inputs[2].dataId))) { + throw new Error('dynamic clip attributes are not allowed'); + } + const min = (inputs.length >= 3) ? inputs[1].numberData[0] : util_1.MIN_CLIP; + const max = (inputs.length >= 3) ? inputs[2].numberData[0] : util_1.MAX_CLIP; + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ min, max }); +}; +const ceil = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslCeil()), inputs)]; +exports.ceil = ceil; +const cos = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslCos()), inputs)]; +exports.cos = cos; +const elu = (handler, inputs, attributes) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslElu(attributes.alpha), attributes.cacheKey), inputs)]; +exports.elu = elu; +const parseEluAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ alpha: node.attributes.getFloat('alpha', 1.0) }); +exports.parseEluAttributes = parseEluAttributes; +const exp = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslExp()), inputs)]; +exports.exp = exp; +const floor = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslFloor()), inputs)]; +exports.floor = floor; +const identity = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslIdentity()), inputs)]; +exports.identity = identity; +const leakyRelu = (handler, inputs, attributes) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslLeakyRelu(attributes.alpha), attributes.cacheKey), inputs)]; +exports.leakyRelu = leakyRelu; +const parseLeakyReluAttributes = (node) => (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ alpha: node.attributes.getFloat('alpha', 0.01) }); +exports.parseLeakyReluAttributes = parseLeakyReluAttributes; +const log = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslLog()), inputs)]; +exports.log = log; +const neg = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslNeg()), inputs)]; +exports.neg = neg; +const not = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslNot()), inputs)]; +exports.not = not; +const relu = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslRelu()), inputs)]; +exports.relu = relu; +const sigmoid = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslSigmoid()), inputs)]; +exports.sigmoid = sigmoid; +const sin = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslSin()), inputs)]; +exports.sin = sin; +const sqrt = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslSqrt()), inputs)]; +exports.sqrt = sqrt; +const tan = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslTan()), inputs)]; +exports.tan = tan; +const tanh = (handler, inputs) => [handler.run(createElementwiseProgramInfoLoader(handler, inputs[0], glslTanh()), inputs)]; +exports.tanh = tanh; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/unpack.ts": +/*!*************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/unpack.ts ***! + \*************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createUnpackProgramInfoLoader = exports.createUnpackProgramInfo = void 0; +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const utils_1 = __webpack_require__(/*! ../utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +const packing_utils_1 = __webpack_require__(/*! ./packing-utils */ "./lib/onnxjs/backends/webgl/ops/packing-utils.ts"); +const unpackProgramMetadata = { + name: 'unpack', + inputNames: ['A'], + inputTypes: [types_1.TextureType.packed] +}; +const createUnpackProgramInfo = (handler, input) => { + const rank = input.dims.length; + const channels = (0, packing_utils_1.getChannels)('rc', rank); + const innerDims = channels.slice(-2); + const coordsDataType = (0, utils_1.getCoordsDataType)(rank); + const unpackChannel = (0, packing_utils_1.unpackFromChannel)(); + const isScalar = (input.dims.length === 0); + const sourceCoords = isScalar ? '' : getSourceCoords(rank, channels); + const coords = rank <= 1 ? 'rc' : `vec2(${innerDims.join(',')})`; + const glsl = (0, glsl_source_1.getGlsl)(handler.session.backend.glContext.version); + const shaderSource = ` + ${unpackChannel} + void main() { + ${coordsDataType} rc = getOutputCoords(); + + // Sample the texture with the coords to get the rgba channel value. + vec4 packedInput = getA(${sourceCoords}); + + ${glsl.output} = vec4(getChannel(packedInput, ${coords}), 0, 0, 0); + } + `; + return Object.assign(Object.assign({}, unpackProgramMetadata), { hasMain: true, output: { dims: input.dims, type: input.type, textureType: types_1.TextureType.unpacked }, shaderSource }); +}; +exports.createUnpackProgramInfo = createUnpackProgramInfo; +const createUnpackProgramInfoLoader = (handler, input) => (Object.assign(Object.assign({}, unpackProgramMetadata), { get: () => (0, exports.createUnpackProgramInfo)(handler, input) })); +exports.createUnpackProgramInfoLoader = createUnpackProgramInfoLoader; +function getSourceCoords(rank, dims) { + if (rank === 1) { + return 'rc'; + } + let coords = ''; + for (let i = 0; i < rank; i++) { + coords += dims[i]; + if (i < rank - 1) { + coords += ','; + } + } + return coords; +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/unsqueeze.ts": +/*!****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/unsqueeze.ts ***! + \****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseUnsqueezeAttributes = exports.unsqueezeV13 = exports.unsqueeze = void 0; +const util_1 = __webpack_require__(/*! ../../../util */ "./lib/onnxjs/util.ts"); +const unsqueeze = (inferenceHandler, inputs, axes) => { + validateInputs(inputs); + const outputShape = util_1.ShapeUtil.unsqueezeShape(inputs[0].dims, axes); + const output = inferenceHandler.reshapeUnpacked(inputs[0], outputShape); + return [output]; +}; +exports.unsqueeze = unsqueeze; +const unsqueezeV13 = (inferenceHandler, inputs) => { + validateInputsV13(inputs); + return (0, exports.unsqueeze)(inferenceHandler, [inputs[0]], Array.from(inputs[1].integerData)); +}; +exports.unsqueezeV13 = unsqueezeV13; +const parseUnsqueezeAttributes = (node) => node.attributes.getInts('axes'); +exports.parseUnsqueezeAttributes = parseUnsqueezeAttributes; +const validateInputs = (inputs) => { + if (!inputs || inputs.length !== 1) { + throw new Error('Unsqueeze requires 1 input.'); + } + if (inputs[0].type === 'string') { + throw new Error('invalid input tensor types.'); + } +}; +const validateInputsV13 = (inputs) => { + if (!inputs || inputs.length !== 2) { + throw new Error('Unsqueeze requires 2 inputs.'); + } + if (inputs[1].type !== 'int32') { + throw new Error('Invalid input type.'); + } +}; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/ops/upsample.ts": +/*!***************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/ops/upsample.ts ***! + \***************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.scalesValidation = exports.validateInputs = exports.parseUpsampleAttributes = exports.parseUpsampleAttributesV9 = exports.parseUpsampleAttributesV7 = exports.upsample = void 0; +const attribute_with_cache_key_1 = __webpack_require__(/*! ../../../attribute-with-cache-key */ "./lib/onnxjs/attribute-with-cache-key.ts"); +const glsl_source_1 = __webpack_require__(/*! ../glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +const types_1 = __webpack_require__(/*! ../types */ "./lib/onnxjs/backends/webgl/types.ts"); +const upsampleProgramMetadata = { + name: 'Upsample', + inputNames: ['X'], + inputTypes: [types_1.TextureType.unpacked], +}; +const upsample = (inferenceHandler, inputs, attributes) => { + (0, exports.validateInputs)(inputs, attributes); + const output = inferenceHandler.run(Object.assign(Object.assign({}, upsampleProgramMetadata), { cacheHint: attributes.cacheKey, get: () => createUpsampleProgramInfo(inferenceHandler, inputs, attributes) }), inputs); + return [output]; +}; +exports.upsample = upsample; +const parseUpsampleAttributesV7 = (node) => (0, exports.parseUpsampleAttributes)(node, 7); +exports.parseUpsampleAttributesV7 = parseUpsampleAttributesV7; +const parseUpsampleAttributesV9 = (node) => (0, exports.parseUpsampleAttributes)(node, 9); +exports.parseUpsampleAttributesV9 = parseUpsampleAttributesV9; +const parseUpsampleAttributes = (node, opset) => { + const isResize = (opset >= 10); + // processing node attributes + const mode = node.attributes.getString('mode', 'nearest'); + if (mode !== 'nearest' && mode !== 'linear' && (opset < 11 || mode !== 'cubic')) { + throw new Error(`unrecognized mode: ${mode}`); + } + let scales = []; + if (opset < 9) { + scales = node.attributes.getFloats('scales'); + (0, exports.scalesValidation)(scales, mode, isResize); + } + const extrapolationValue = node.attributes.getFloat('extrapolation_value', 0.0); + const coordinateTransformMode = opset > 10 ? node.attributes.getString('coordinate_transformation_mode', 'half_pixel') : 'asymmetric'; + if ([ + 'asymmetric', 'pytorch_half_pixel', 'tf_half_pixel_for_nn', 'align_corners', 'tf_crop_and_resize', 'half_pixel' + ].indexOf(coordinateTransformMode) === -1) { + throw new Error(`coordinate_transform_mode '${coordinateTransformMode}' is not supported`); + } + const needRoiInput = (coordinateTransformMode === 'tf_crop_and_resize'); + const useExtrapolation = needRoiInput; + const nearestMode = (mode === 'nearest' && opset >= 11) ? node.attributes.getString('nearest_mode', 'round_prefer_floor') : ''; + if (['round_prefer_floor', 'round_prefer_ceil', 'floor', 'ceil', ''].indexOf(nearestMode) === -1) { + throw new Error(`nearest_mode '${nearestMode}' is not supported`); + } + const cubicCoefficientA = node.attributes.getFloat('cubic_coeff_a', -0.75); + const excludeOutside = node.attributes.getInt('exclude_outside', 0) !== 0; + if (excludeOutside && mode !== 'cubic') { + throw new Error('exclude_outside can be set to 1 only when mode is CUBIC.'); + } + const useNearest2xOptimization = (opset < 11) ? true : (mode === 'nearest' && coordinateTransformMode === 'asymmetric' && nearestMode === 'floor'); + let roiInputIdx = 0; + let scalesInputIdx = 0; + let sizesInputIdx = 0; + if (opset > 10) { + // handle when roiInput is not given + if (node.inputs.length > 2) { + roiInputIdx = 1; + scalesInputIdx = 2; + sizesInputIdx = 3; + } + else { + scalesInputIdx = 1; + sizesInputIdx = 2; + } + } + else if (opset === 9) { + scalesInputIdx = 1; + } + return (0, attribute_with_cache_key_1.createAttributeWithCacheKey)({ + opset, + isResize, + mode, + scales, + extrapolationValue, + coordinateTransformMode, + useExtrapolation, + needRoiInput, + nearestMode, + cubicCoefficientA, + excludeOutside, + useNearest2xOptimization, + roiInputIdx, + scalesInputIdx, + sizesInputIdx + }); +}; +exports.parseUpsampleAttributes = parseUpsampleAttributes; +const createUpsampleProgramInfo = (inferenceHandler, inputs, attributes) => { + const glsl = (0, glsl_source_1.getGlsl)(inferenceHandler.session.backend.glContext.version); + const [inputWidth, inputHeight] = inferenceHandler.calculateTextureWidthAndHeight(inputs[0].dims, types_1.TextureType.unpacked); + const outputShape = inputs[0].dims.map((dim, i) => Math.floor(dim * attributes.scales[i])); + const [outputWidth, outputHeight] = inferenceHandler.calculateTextureWidthAndHeight(outputShape, types_1.TextureType.unpacked); + const dim = outputShape.length; + const outputPitches = new Array(dim); + const inputPitches = new Array(dim); + let precalculatedPitches = ` + int output_pitches[${dim}]; + int input_pitches[${dim}]; + `; + for (let d = dim - 1; d >= 0; d--) { + outputPitches[d] = (d === dim - 1) ? 1 : outputPitches[d + 1] * outputShape[d + 1]; + inputPitches[d] = (d === dim - 1) ? 1 : inputPitches[d + 1] * inputs[0].dims[d + 1]; + precalculatedPitches += ` + output_pitches[${d}] = ${outputPitches[d]}; + input_pitches[${d}] = ${inputPitches[d]}; + `; + } + const getInputFloatFunction = ` + float getInputFloat(int index) { + vec2 coords = offsetToCoords(index, ${inputWidth}, ${inputHeight}); + float value = getColorAsFloat(${glsl.texture2D}(X, coords)); + return value; + } + `; + const shaderSource = attributes.mode === 'nearest' ? + // nearest + ` + ${getInputFloatFunction} + float process(int indices[${dim}]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${outputWidth}, ${outputHeight}); + + ${precalculatedPitches} + + int d, m; + for (int dim = 0; dim < ${dim}; ++dim) { + d = output_index / output_pitches[dim]; + m = output_index - d * output_pitches[dim]; + output_index = m; + + if (scales[dim] != 1 && d > 0) { + int d2 = d / scales[dim]; + m = d - d2 * scales[dim]; + d = d2; + } + input_index += input_pitches[dim] * d; + } + + return getInputFloat(input_index); + }` : + dim === 4 ? + // bilinear 4D + ` + ${getInputFloatFunction} + float process(int indices[4]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${outputWidth}, ${outputHeight}); + + ${precalculatedPitches} + + int m; + int index_of_dim0, index_of_dim1, index_of_dim2, index_of_dim3; + index_of_dim0 = output_index / output_pitches[0]; + m = output_index - index_of_dim0 * output_pitches[0]; + index_of_dim1 = m / output_pitches[1]; + m = m - index_of_dim1 * output_pitches[1]; + index_of_dim2 = m / output_pitches[2]; + m = m - index_of_dim2 * output_pitches[2]; + index_of_dim3 = m; + + int index_of_input_dim2, index_of_input_dim3, x_offset, y_offset; + index_of_input_dim2 = index_of_dim2 / scales[2]; + y_offset = index_of_dim2 - index_of_input_dim2 * scales[2]; + index_of_input_dim3 = index_of_dim3 / scales[3]; + x_offset = index_of_dim3 - index_of_input_dim3 * scales[3]; + + input_index = index_of_dim0 * input_pitches[0] + + index_of_dim1 * input_pitches[1] + + index_of_input_dim2 * input_pitches[2] + + index_of_input_dim3; + + float x00 = getInputFloat(input_index); + float x10, x01, x11; + + bool end_of_dim2 = false; + if (index_of_input_dim2 == (${inputs[0].dims[2]} - 1)) { + // It's the end in dimension 2 + x01 = x00; + end_of_dim2 = true; + } else { + x01 = getInputFloat(input_index + input_pitches[2]); + } + + if (index_of_input_dim3 == (input_pitches[2] - 1)) { + // It's the end in dimension 3 + x10 = x00; + x11 = x01; + } + else { + x10 = getInputFloat(input_index + 1); + x11 = end_of_dim2 ? x10 : getInputFloat(input_index + input_pitches[2] + 1); + } + + float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[2]); + float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[2]); + return y0 + float(x_offset) * (y1 - y0) / float(scales[3]); + }` : + // bilinear 2D + ` + ${getInputFloatFunction} + float process(int indices[2]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${outputWidth}, ${outputHeight}); + + ${precalculatedPitches} + + int m; + int index_of_dim0, index_of_dim1; + index_of_dim0 = output_index / output_pitches[0]; + m = output_index - index_of_dim0 * output_pitches[0]; + index_of_dim1 = m; + + int index_of_input_dim0, index_of_input_dim1, x_offset, y_offset; + index_of_input_dim0 = index_of_dim0 / scales[0]; + y_offset = index_of_dim0 - index_of_input_dim0 * scales[0]; + index_of_input_dim1 = index_of_dim1 / scales[1]; + x_offset = index_of_dim1 - index_of_input_dim1 * scales[1]; + + input_index = index_of_input_dim0 * input_pitches[0] + index_of_input_dim1; + + float x00 = getInputFloat(input_index); + float x10, x01, x11; + + bool end_of_dim0 = false; + if (index_of_input_dim0 == (${inputs[0].dims[0]} - 1)) { + // It's the end in dimension 0 + x01 = x00; + end_of_dim0 = true; + } else { + x01 = getInputFloat(input_index + input_pitches[0]); + } + + if (index_of_input_dim1 == (input_pitches[0] - 1)) { + // It's the end in dimension 1 + x10 = x00; + x11 = x01; + } + else { + x10 = getInputFloat(input_index + 1); + x11 = end_of_dim0 ? x10 : getInputFloat(input_index + input_pitches[0] + 1); + } + + float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[0]); + float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[0]); + return y0 + float(x_offset) * (y1 - y0) / float(scales[1]); + }`; + return Object.assign(Object.assign({}, upsampleProgramMetadata), { output: { dims: outputShape, type: inputs[0].type, textureType: types_1.TextureType.unpacked }, shaderSource, variables: [{ + name: 'scales', + type: 'int', + arrayLength: attributes.scales.length, + data: attributes.scales.map(x => Math.ceil(x)) + }] }); +}; +const validateInputs = (inputs, attribute) => { + if (!inputs || (attribute.opset < 9 && inputs.length !== 1) || + (attribute.opset >= 9 && attribute.opset < 11 && inputs.length !== 2) || + (attribute.opset >= 11 && inputs.length < 2)) { + throw new Error('invalid inputs.'); + } + if (attribute.scales.length > 0 && inputs[0].dims.length !== attribute.scales.length) { + throw new Error('Invalid input shape.'); + } + if (inputs[0].type === 'string') { + throw new Error('Invalid input tensor types.'); + } +}; +exports.validateInputs = validateInputs; +const scalesValidation = (scales, mode, isResize) => { + if (!isResize) { + for (const scale of scales) { + if (scale < 1) { + throw new Error('Scale value should be greater than or equal to 1.'); + } + } + } + else { + for (const scale of scales) { + if (scale <= 0) { + throw new Error('Scale value should be greater than 0.'); + } + } + } + if (mode === 'linear' || mode === 'cubic') { + if (scales.length !== 2 && (scales.length !== 4 || scales[0] !== 1 || scales[1] !== 1)) { + throw new Error(`'Linear' mode and 'Cubic' mode only support 2-D inputs ('Bilinear', 'Bicubic') \ + or 4-D inputs with the corresponding outermost 2 scale values being 1 \ + in the ${isResize ? 'Resize' : 'Upsample'} opeartor.`); + } + } +}; +exports.scalesValidation = scalesValidation; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/program-manager.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/program-manager.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.ProgramManager = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +const glsl_preprocessor_1 = __webpack_require__(/*! ./glsl-preprocessor */ "./lib/onnxjs/backends/webgl/glsl-preprocessor.ts"); +const glsl_source_1 = __webpack_require__(/*! ./glsl-source */ "./lib/onnxjs/backends/webgl/glsl-source.ts"); +/** + * ProgramManager is the main class behind running computations + * It builds ProgramInfo's into Artifacts + * It compiles given ProgramInfo's into WebGL Prorams (cached as Artifacts) + * Uses the artifact to run the computation by calling Draw on + * the WebGL drawing buffer + * ProgramManager automatically maps (binds) input variables to their + * corresponding Location's in the binary program + */ +class ProgramManager { + constructor(profiler, glContext, textureLayoutStrategy) { + this.profiler = profiler; + this.glContext = glContext; + this.textureLayoutStrategy = textureLayoutStrategy; + this.repo = new Map(); + this.attributesBound = false; + } + getArtifact(key) { + return this.repo.get(key); + } + setArtifact(key, artifact) { + this.repo.set(key, artifact); + } + run(buildArtifact, inputs, output) { + var _a; + this.profiler.event('op', `ProgramManager.run ${(_a = buildArtifact.programInfo.name) !== null && _a !== void 0 ? _a : 'unknown kernel'}`, () => { + var _a; + const gl = this.glContext.gl; + const program = buildArtifact.program; + gl.useProgram(program); + try { + this.bindOutput(output); + if (!this.attributesBound) { + this.bindAttributes(buildArtifact.attribLocations); + } + this.bindUniforms(buildArtifact.uniformLocations, (_a = buildArtifact.programInfo.variables) !== null && _a !== void 0 ? _a : [], inputs); + } + catch (err) { + instrument_1.Logger.error('ProgramManager', buildArtifact.programInfo.shaderSource); + throw err; + } + this.profiler.event('backend', 'GlContext.draw()', () => { + this.glContext.draw(); + }); + }, this.glContext); + } + dispose() { + if (this.vertexShader) { + this.glContext.deleteShader(this.vertexShader); + } + this.repo.forEach(a => this.glContext.deleteProgram(a.program)); + } + build(programInfo, inputTextureLayouts, outputTextureLayout) { + return this.profiler.event('backend', 'ProgramManager.build', () => { + const preprocessor = new glsl_preprocessor_1.GlslPreprocessor(this.glContext, programInfo, inputTextureLayouts, outputTextureLayout); + const fragScript = preprocessor.preprocess(); + const program = this.compile(fragScript); + const artifact = { + programInfo, + program, + uniformLocations: this.getUniformLocations(program, preprocessor.context.programInfo.inputNames, preprocessor.context.programInfo.variables), + attribLocations: this.getAttribLocations(program) + }; + return artifact; + }); + } + compile(fragShaderScript) { + if (!this.vertexShader) { + instrument_1.Logger.verbose('ProrgramManager', 'Compiling and caching Vertex shader for the first time'); + const vertexShaderScript = (0, glsl_source_1.getVertexShaderSource)(this.glContext.version); + this.vertexShader = this.glContext.compileShader(vertexShaderScript, this.glContext.gl.VERTEX_SHADER); + } + if (onnxruntime_common_1.env.debug) { + instrument_1.Logger.verbose('ProrgramManager', `FragShader: +${fragShaderScript} +`); + } + const fragShader = this.glContext.compileShader(fragShaderScript, this.glContext.gl.FRAGMENT_SHADER); + const program = this.glContext.createProgram(this.vertexShader, fragShader); + this.glContext.deleteShader(fragShader); + return program; + } + bindOutput(td) { + const width = td.width; + const height = td.height; + instrument_1.Logger.verbose('ProrgramManager', `Binding output texture to Framebuffer: w/h=${width}/${height}, shape=${td.shape}, type=${td.tensor.type}`); + this.glContext.attachFramebuffer(td.texture, width, height); + } + bindAttributes(attribLocations) { + const positionHandle = attribLocations.position; + const textureCoordHandle = attribLocations.textureCoord; + this.glContext.setVertexAttributes(positionHandle, textureCoordHandle); + this.attributesBound = true; + } + bindUniforms(uniformLocations, variables, textures) { + var _a; + const gl = this.glContext.gl; + let texturePosition = 0; + for (const { name, type, location, arrayLength } of uniformLocations) { + const value = (_a = variables.find(v => v.name === name)) === null || _a === void 0 ? void 0 : _a.data; + if (type !== 'sampler2D' && !value) { + throw new Error(`variable '${name}' does not have data defined in program info`); + } + switch (type) { + case 'sampler2D': + this.bindTexture(textures[texturePosition], location, texturePosition); + texturePosition++; + break; + case 'float': + if (arrayLength) { + gl.uniform1fv(location, value); + } + else { + gl.uniform1f(location, value); + } + break; + case 'int': + if (arrayLength) { + gl.uniform1iv(location, value); + } + else { + gl.uniform1i(location, value); + } + break; + default: + throw new Error(`Uniform not implemented: ${type}`); + } + } + } + bindTexture(td, uniformHandle, position) { + this.glContext.bindTextureToUniform(td.texture, position, uniformHandle); + } + getAttribLocations(program) { + return { + position: this.getAttribLocation(program, 'position'), + textureCoord: this.getAttribLocation(program, 'textureCoord') + }; + } + getUniformLocations(program, samplers, variables) { + const uniformLocations = []; + if (samplers) { + for (const sampler of samplers) { + uniformLocations.push({ name: sampler, type: 'sampler2D', location: this.getUniformLocation(program, sampler) }); + } + } + if (variables) { + for (const variable of variables) { + uniformLocations.push(Object.assign(Object.assign({}, variable), { location: this.getUniformLocation(program, variable.name) })); + } + } + return uniformLocations; + } + getUniformLocation(program, name) { + const gl = this.glContext.gl; + const reference = gl.getUniformLocation(program, name); + if (reference === null) { + throw new Error(`Uniform ${name} not found.`); + } + return reference; + } + getAttribLocation(program, name) { + const gl = this.glContext.gl; + const attributeLocation = gl.getAttribLocation(program, name); + return attributeLocation; + } +} +exports.ProgramManager = ProgramManager; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/session-handler.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/session-handler.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.WebGLSessionHandler = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +const opset_1 = __webpack_require__(/*! ../../opset */ "./lib/onnxjs/opset.ts"); +const inference_handler_1 = __webpack_require__(/*! ./inference-handler */ "./lib/onnxjs/backends/webgl/inference-handler.ts"); +const op_resolve_rules_1 = __webpack_require__(/*! ./op-resolve-rules */ "./lib/onnxjs/backends/webgl/op-resolve-rules.ts"); +const program_manager_1 = __webpack_require__(/*! ./program-manager */ "./lib/onnxjs/backends/webgl/program-manager.ts"); +const texture_layout_strategy_1 = __webpack_require__(/*! ./texture-layout-strategy */ "./lib/onnxjs/backends/webgl/texture-layout-strategy.ts"); +const texture_manager_1 = __webpack_require__(/*! ./texture-manager */ "./lib/onnxjs/backends/webgl/texture-manager.ts"); +class WebGLSessionHandler { + constructor(backend, context) { + this.backend = backend; + this.context = context; + this.layoutStrategy = new texture_layout_strategy_1.PreferLogicalStrategy(backend.glContext.maxTextureSize); + this.programManager = new program_manager_1.ProgramManager(this.context.profiler, backend.glContext, this.layoutStrategy); + this.textureManager = new texture_manager_1.TextureManager(backend.glContext, this.layoutStrategy, this.context.profiler, { reuseTextures: backend.textureCacheMode === 'full' }); + this.packedTextureDataCache = new Map(); + this.unpackedTextureDataCache = new Map(); + this.pack = backend.pack; + this.pack2unpackMap = new Map(); + this.unpack2packMap = new Map(); + } + createInferenceHandler() { + return new inference_handler_1.WebGLInferenceHandler(this); + } + onGraphInitialized(graph) { + const initializers = graph.getValues().filter(v => v.from === -1 && v.tensor).map(v => v.tensor.dataId); + this.initializers = new Set(initializers); + } + isInitializer(tensorId) { + return this.initializers ? this.initializers.has(tensorId) : false; + } + addInitializer(tensorId) { + this.initializers.add(tensorId); + } + getTextureData(tensorId, isPacked) { + if (isPacked) { + return this.packedTextureDataCache.get(tensorId); + } + else { + return this.unpackedTextureDataCache.get(tensorId); + } + } + setTextureData(tensorId, textureData, isPacked = false) { + instrument_1.Logger.verbose('WebGLSessionHandler', 'Storing Texture data in cache'); + if (isPacked) { + this.packedTextureDataCache.set(tensorId, textureData); + } + else { + this.unpackedTextureDataCache.set(tensorId, textureData); + } + } + dispose() { + this.programManager.dispose(); + this.textureManager.clearActiveTextures(); + this.packedTextureDataCache.forEach(td => this.textureManager.releaseTexture(td, true)); + this.packedTextureDataCache = new Map(); + this.unpackedTextureDataCache.forEach(td => this.textureManager.releaseTexture(td, true)); + this.unpackedTextureDataCache = new Map(); + } + resolve(node, opsets, graph) { + const op = (0, opset_1.resolveOperator)(node, opsets, op_resolve_rules_1.WEBGL_OP_RESOLVE_RULES); + return { impl: op.opImpl, context: op.opInit ? op.opInit(node, graph) : node }; + } +} +exports.WebGLSessionHandler = WebGLSessionHandler; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/texture-data-encoder.ts": +/*!***********************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/texture-data-encoder.ts ***! + \***********************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Uint8DataEncoder = exports.RGBAFloatDataEncoder = exports.RedFloat32DataEncoder = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +/** + * WebGL2 data encoder + * Uses R32F as the format for texlet + */ +class RedFloat32DataEncoder { + constructor(gl, channels = 1) { + if (channels === 1) { + this.internalFormat = gl.R32F; + this.format = gl.RED; + this.textureType = gl.FLOAT; + this.channelSize = channels; + } + else if (channels === 4) { + this.internalFormat = gl.RGBA32F; + this.format = gl.RGBA; + this.textureType = gl.FLOAT; + this.channelSize = channels; + } + else { + throw new Error(`Invalid number of channels: ${channels}`); + } + } + encode(src, textureSize) { + let result; + let source; + if (src.constructor !== Float32Array) { + instrument_1.Logger.warning('Encoder', 'data was not of type Float32; creating new Float32Array'); + source = new Float32Array(src); + } + if (textureSize * this.channelSize > src.length) { + instrument_1.Logger.warning('Encoder', 'Source data too small. Allocating larger array'); + source = src; + result = this.allocate(textureSize * this.channelSize); + source.forEach((v, i) => result[i] = v); + } + else { + source = src; + result = source; + } + return result; + } + allocate(size) { + return new Float32Array(size * 4); + } + decode(buffer, dataSize) { + if (this.channelSize === 1) { + const filteredData = buffer.filter((value, index) => index % 4 === 0).subarray(0, dataSize); + return filteredData; + } + return buffer.subarray(0, dataSize); + } +} +exports.RedFloat32DataEncoder = RedFloat32DataEncoder; +/** + * Data encoder for WebGL 1 with support for floating point texture + */ +class RGBAFloatDataEncoder { + constructor(gl, channels = 1, textureType) { + if (channels !== 1 && channels !== 4) { + throw new Error(`Invalid number of channels: ${channels}`); + } + this.internalFormat = gl.RGBA; + this.format = gl.RGBA; + this.channelSize = channels; + this.textureType = textureType || gl.FLOAT; + } + encode(src, textureSize) { + let dest = src; + if (this.channelSize === 1) { + instrument_1.Logger.verbose('Encoder', 'Exploding into a larger array'); + dest = this.allocate(textureSize); + src.forEach((v, i) => dest[i * 4] = v); + } + return dest; + } + allocate(size) { + return new Float32Array(size * 4); + } + decode(buffer, dataSize) { + if (this.channelSize === 1) { + const filteredData = buffer.filter((value, index) => index % 4 === 0).subarray(0, dataSize); + return filteredData; + } + return buffer.subarray(0, dataSize); + } +} +exports.RGBAFloatDataEncoder = RGBAFloatDataEncoder; +class Uint8DataEncoder { + constructor(gl, channels = 1) { + this.channelSize = 4; + if (channels === 1) { + this.internalFormat = gl.ALPHA; + this.format = gl.ALPHA; // not tested + this.textureType = gl.UNSIGNED_BYTE; + this.channelSize = channels; + } + else if (channels === 4) { + this.internalFormat = gl.RGBA; + this.format = gl.RGBA; + this.textureType = gl.UNSIGNED_BYTE; + this.channelSize = channels; + } + else { + throw new Error(`Invalid number of channels: ${channels}`); + } + } + encode(src, _textureSize) { + return new Uint8Array(src.buffer, src.byteOffset, src.byteLength); + } + allocate(size) { + return new Uint8Array(size * this.channelSize); + } + decode(buffer, dataSize) { + if (buffer instanceof Uint8Array) { + return buffer.subarray(0, dataSize); + } + throw new Error(`Invalid array type: ${buffer.constructor}`); + } +} +exports.Uint8DataEncoder = Uint8DataEncoder; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/texture-layout-strategy.ts": +/*!**************************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/texture-layout-strategy.ts ***! + \**************************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getBatchDim = exports.sizeToSquarishShape = exports.getRowsCols = exports.sizeFromShape = exports.isInt = exports.parseAxisParam = exports.squeezeShape = exports.PreferLogicalStrategy = exports.AlwaysKeepOriginalSizeStrategy = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +const util_1 = __webpack_require__(/*! ../../util */ "./lib/onnxjs/util.ts"); +/** + * This strategy try to find the minimal max(W,H) that fulfills (W * H == totalSize) + */ +class AlwaysKeepOriginalSizeStrategy { + constructor(maxTextureSize) { + this.maxTextureSize = maxTextureSize; + } + computeTextureWH(shape, prefs) { + // scalar tensor + if (shape.length === 0) { + return [1, 1]; + } + const maxTextureSize = this.maxTextureSize; + if (prefs && prefs.breakAxis !== undefined) { + // check to see if dims fit + const wsize = prefs.breakAxis >= shape.length ? 1 : shape.slice(prefs.breakAxis).reduce((a, b) => a * b); + const hsize = prefs.breakAxis <= 0 ? 1 : shape.slice(0, prefs.breakAxis).reduce((a, b) => a * b); + if (wsize > maxTextureSize || hsize > maxTextureSize) { + // ignore preferences + // continue with default layout + instrument_1.Logger.verbose('TextureLayout', `Given width/height preferences were unattainable: shape:${shape}, breakAxis:${prefs.breakAxis}`); + } + else { + return [wsize, hsize]; + } + } + const totalSize = shape.reduce((a, b) => a * b); + let width = Math.floor(Math.sqrt(totalSize)); + for (; width < maxTextureSize && width < totalSize; width++) { + if (totalSize % width === 0) { + break; + } + } + if (width >= maxTextureSize || totalSize % width !== 0) { + throw new Error(`The given dimensions are outside this GPU's boundaries: ${shape}`); + } + return [width, totalSize / width]; + } +} +exports.AlwaysKeepOriginalSizeStrategy = AlwaysKeepOriginalSizeStrategy; +class PreferLogicalStrategy { + constructor(maxTextureSize) { + this.maxTextureSize = maxTextureSize; + } + computeTextureWH(shape, prefs) { + const wh = this.computeTexture(shape, prefs); + if (prefs && prefs.isPacked) { + wh[0] /= 2; + wh[1] /= 2; + } + if (prefs && prefs.reverseWH) { + return [wh[1], wh[0]]; + } + return wh; + } + computeTexture(shape, prefs) { + const isPacked = prefs && prefs.isPacked; + // scalar tensor + if (shape.length === 0) { + return isPacked ? [2, 2] : [1, 1]; + } + let maxTextureSize = this.maxTextureSize; + if (prefs && prefs.breakAxis !== undefined) { + // check to see if dims fit + const wsize = prefs.breakAxis >= shape.length ? 1 : shape.slice(prefs.breakAxis).reduce((a, b) => a * b); + const hsize = prefs.breakAxis <= 0 ? 1 : shape.slice(0, prefs.breakAxis).reduce((a, b) => a * b); + if (wsize > maxTextureSize || hsize > maxTextureSize) { + // ignore preferences + // continue with default layout + instrument_1.Logger.verbose('TextureLayout', `Given width/height preferences were unattainable: shape:${shape}, breakAxis:${prefs.breakAxis}`); + } + else { + return [wsize, hsize]; + } + } + let logShape = shape.slice(0); + if (isPacked) { + maxTextureSize = maxTextureSize * 2; + // This logic ensures we accurately count the number of packed texels needed + // to accommodate the tensor. We can only pack values in the same texel if + // they are from adjacent pairs of rows/cols within the same batch. So if a + // tensor has 3 rows, we pretend it has 4 rows in order to account for the + // fact that the texels containing the third row are half empty. + logShape = logShape.map((d, i) => i >= logShape.length - 2 ? (logShape[i] % 2 === 0 ? logShape[i] : logShape[i] + 1) : logShape[i]); + // Packed texture height is at least 2 (the channel height of a single + // texel). + if (logShape.length === 1) { + logShape = [2, logShape[0]]; + } + } + // If logical shape is 2, we don't squeeze, since we want to match physical. + if (logShape.length !== 2) { + const squeezeResult = squeezeShape(logShape); + logShape = squeezeResult.newShape; + } + const size = sizeFromShape(logShape); + if (logShape.length <= 1 && size <= maxTextureSize) { + return [1, size]; + } + else if (logShape.length === 2 && logShape[0] <= maxTextureSize && logShape[1] <= maxTextureSize) { + return logShape; + } + else if (logShape.length === 3 && logShape[0] * logShape[1] <= maxTextureSize && logShape[2] <= maxTextureSize) { + return [logShape[0] * logShape[1], logShape[2]]; + } + else if (logShape.length === 3 && logShape[0] <= maxTextureSize && logShape[1] * logShape[2] <= maxTextureSize) { + return [logShape[0], logShape[1] * logShape[2]]; + } + else if (logShape.length === 4 && logShape[0] * logShape[1] * logShape[2] <= maxTextureSize && + logShape[3] <= maxTextureSize) { + return [logShape[0] * logShape[1] * logShape[2], logShape[3]]; + } + else if (logShape.length === 4 && logShape[0] <= maxTextureSize && + logShape[1] * logShape[2] * logShape[3] <= maxTextureSize) { + return [logShape[0], logShape[1] * logShape[2] * logShape[3]]; + } + else { + if (isPacked) { + // For packed textures size equals the number of channels required to + // accommodate the texture data. However in order to squarify such that + // inner dimensions stay even, we rewrite size to equal the number of + // texels. Then in the return statement we rehydrate the squarified + // dimensions to channel units. + return sizeToSquarishShape(size / 4).map(d => d * 2); + } + return sizeToSquarishShape(size); + } + } +} +exports.PreferLogicalStrategy = PreferLogicalStrategy; +function squeezeShape(shape, axis) { + const newShape = []; + const keptDims = []; + const isEmptyArray = axis != null && Array.isArray(axis) && axis.length === 0; + const axes = (axis == null || isEmptyArray) ? null : parseAxisParam(axis, shape).sort(); + let j = 0; + for (let i = 0; i < shape.length; ++i) { + if (axes != null) { + if (axes[j] === i && shape[i] !== 1) { + throw new Error(`Can't squeeze axis ${i} since its dim '${shape[i]}' is not 1`); + } + if ((axes[j] == null || axes[j] > i) && shape[i] === 1) { + newShape.push(shape[i]); + keptDims.push(i); + } + if (axes[j] <= i) { + j++; + } + } + if (shape[i] !== 1) { + newShape.push(shape[i]); + keptDims.push(i); + } + } + return { newShape, keptDims }; +} +exports.squeezeShape = squeezeShape; +function parseAxisParam(axis, shape) { + const rank = shape.length; + // Normalize input + axis = axis == null ? shape.map((s, i) => i) : [].concat(axis); + // Check for valid range + (0, util_1.assert)(axis.every(ax => ax >= -rank && ax < rank), () => `All values in axis param must be in range [-${rank}, ${rank}) but ` + + `got axis ${axis}`); + // Check for only integers + (0, util_1.assert)(axis.every(isInt), () => 'All values in axis param must be integers but ' + + `got axis ${axis}`); + // Handle negative axis. + return axis.map(a => a < 0 ? rank + a : a); +} +exports.parseAxisParam = parseAxisParam; +function isInt(a) { + return a % 1 === 0; +} +exports.isInt = isInt; +function sizeFromShape(shape) { + if (shape.length === 0) { + // Scalar. + return 1; + } + let size = shape[0]; + for (let i = 1; i < shape.length; i++) { + size *= shape[i]; + } + return size; +} +exports.sizeFromShape = sizeFromShape; +function getRowsCols(shape) { + if (shape.length === 0) { + throw Error('Cannot get rows and columns of an empty shape array.'); + } + return [shape.length > 1 ? shape[shape.length - 2] : 1, shape[shape.length - 1]]; +} +exports.getRowsCols = getRowsCols; +function sizeToSquarishShape(size) { + const width = Math.ceil(Math.sqrt(size)); + return [width, Math.ceil(size / width)]; +} +exports.sizeToSquarishShape = sizeToSquarishShape; +function getBatchDim(shape, dimsToSkip = 2) { + return sizeFromShape(shape.slice(0, shape.length - dimsToSkip)); +} +exports.getBatchDim = getBatchDim; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/texture-layout.ts": +/*!*****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/texture-layout.ts ***! + \*****************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createTextureLayoutFromShape = exports.calculateTextureWidthAndHeight = exports.createTextureLayoutFromTextureType = void 0; +const util_1 = __webpack_require__(/*! ../../util */ "./lib/onnxjs/util.ts"); +const types_1 = __webpack_require__(/*! ./types */ "./lib/onnxjs/backends/webgl/types.ts"); +const createTextureLayoutFromTextureType = (textureLayoutStrategy, shape, textureType) => { + const channel = (textureType === types_1.TextureType.unpacked || textureType === types_1.TextureType.unpackedReversed) ? 1 : 4; + const isPacked = textureType === types_1.TextureType.packed; + const reverseWH = (textureType === types_1.TextureType.unpackedReversed || textureType === types_1.TextureType.packed); + const breakAxis = textureType === types_1.TextureType.packedLastDimension ? shape.length - 1 : undefined; + const unpackedShape = textureType === types_1.TextureType.packedLastDimension ? + shape.map((d, i) => i === shape.length - 1 ? d * 4 : d) : + undefined; + return (0, exports.createTextureLayoutFromShape)(textureLayoutStrategy, shape, channel, unpackedShape, { isPacked, reverseWH, breakAxis }); +}; +exports.createTextureLayoutFromTextureType = createTextureLayoutFromTextureType; +const calculateTextureWidthAndHeight = (textureLayoutStrategy, shape, textureType) => { + const layout = (0, exports.createTextureLayoutFromTextureType)(textureLayoutStrategy, shape, textureType); + return [layout.width, layout.height]; +}; +exports.calculateTextureWidthAndHeight = calculateTextureWidthAndHeight; +/** + * Create a TextureLayout object from shape. + */ +const createTextureLayoutFromShape = (textureLayoutStrategy, shape, channels = 1, unpackedShape, prefs) => { + const isPacked = !!(prefs && prefs.isPacked); + const [width, height] = textureLayoutStrategy.computeTextureWH(isPacked ? unpackedShape || shape : shape, prefs); + const rank = shape.length; + let inferredDims = shape.slice(0); + if (rank === 0) { + inferredDims = [1]; + } + if (channels === 1) { + // unpackedShape will take `shape` and not `inferredDims` so as to create a scalar Tensor if need be + unpackedShape = shape; + } + else if (isPacked) { + if (channels !== 4) { + throw new Error('a packed texture must be 4-channel'); + } + unpackedShape = shape; + if (rank > 0) { + inferredDims[rank - 1] = Math.ceil(inferredDims[rank - 1] / 2); + } + if (rank > 1) { + inferredDims[rank - 2] = Math.ceil(inferredDims[rank - 2] / 2); + } + } + else if (!unpackedShape) { + throw new Error('Unpacked shape is needed when using channels > 1'); + } + return { + width, + height, + channels, + isPacked, + shape: inferredDims, + strides: util_1.ShapeUtil.computeStrides(inferredDims), + unpackedShape, + reversedWH: (prefs && prefs.reverseWH) + }; +}; +exports.createTextureLayoutFromShape = createTextureLayoutFromShape; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/texture-manager.ts": +/*!******************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/texture-manager.ts ***! + \******************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.TextureManager = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +/** + * TextureManager is the mainly responsible for caching Textures + * Textures are cached in 2 levels: + * 1. the texures which are associated with a dataId (from Tensor) + * Caching these is crucial to performance. These are In-use Textures + * 2. textures which are not in use by any current ProgramInfo/Tensor + * These are called Free Textures + * TextureManager is also used to help creating textures. For this it + * uses WebGLContext and TextureLayoutStrategy + */ +class TextureManager { + constructor(glContext, layoutStrategy, profiler, config) { + this.glContext = glContext; + this.layoutStrategy = layoutStrategy; + this.profiler = profiler; + this.config = config; + this.pendingRead = new Map(); + if (config.reuseTextures) { + this.inUseTextures = new Map(); + this.idleTextures = new Map(); + this.textureLookup = new Map(); + } + } + createTextureFromLayout(dataType, layout, data, usage) { + const textureDataType = this.toEncoderType(dataType); + const encoder = this.glContext.getEncoder(textureDataType, layout.channels || 1, usage); + if (layout.isPacked && usage === 1 /* Encoder.Usage.UploadOnly */) { + throw new Error('not implemented'); + } + const width = layout.width; + const height = layout.height; + let key; + let inUseTextures; + if (this.config.reuseTextures) { + key = `${width}x${height}_${encoder.format}_${encoder.internalFormat}_${encoder.textureType}`; + inUseTextures = this.inUseTextures.get(key); + if (!inUseTextures) { + inUseTextures = []; + this.inUseTextures.set(key, inUseTextures); + } + const idleTextures = this.idleTextures.get(key); + if (idleTextures && idleTextures.length > 0) { + const texture = idleTextures.pop(); + inUseTextures.push(texture); + if (usage === 1 /* Encoder.Usage.UploadOnly */) { + this.glContext.updateTexture(texture, width, height, encoder, this.toTextureData(dataType, data)); + } + return texture; + } + } + instrument_1.Logger.verbose('TextureManager', `Creating new texture of size ${layout.width}x${layout.height}`); + const texture = this.glContext.allocateTexture(width, height, encoder, this.toTextureData(dataType, data)); + if (this.config.reuseTextures) { + inUseTextures.push(texture); + this.textureLookup.set(texture, key); + } + return texture; + } + readTexture(td, dataType, channels) { + if (!channels) { + channels = 1; + } + return this.profiler.event('backend', 'TextureManager.readTexture', () => { + const dataSize = td.shape.reduce((a, b) => a * b) * channels; + const data = this.glContext.readTexture(td.texture, td.width, td.height, dataSize, this.toEncoderType(dataType), channels); + return this.toTensorData(dataType, data); + }); + } + async readTextureAsync(td, dataType, channels) { + const dataId = td.tensor.dataId; + if (!channels) { + channels = 1; + } + if (this.pendingRead.has(dataId)) { + const subscribers = this.pendingRead.get(dataId); + return new Promise(resolve => subscribers === null || subscribers === void 0 ? void 0 : subscribers.push(resolve)); + } + return this.profiler.event('backend', 'TextureManager.readTextureAsync', async () => { + this.pendingRead.set(dataId, []); + const dataSize = td.shape.reduce((a, b) => a * b) * channels; + // add a fence waiting for the data to be ready + await this.glContext.createAndWaitForFence(); + const data = this.glContext.readTexture(td.texture, td.width, td.height, dataSize, this.toEncoderType(dataType), channels); + const tensorData = this.toTensorData(dataType, data); + const subscribers = this.pendingRead.get(dataId); + this.pendingRead.delete(dataId); + subscribers === null || subscribers === void 0 ? void 0 : subscribers.forEach(resolve => resolve(tensorData)); + return tensorData; + }); + } + readUint8TextureAsFloat(td) { + return this.profiler.event('backend', 'TextureManager.readUint8TextureAsFloat', () => { + const dataSize = td.shape.reduce((a, b) => a * b); + const data = this.glContext.readTexture(td.texture, td.width, td.height, dataSize * 4, 'byte', 4); + return new Float32Array(data.buffer, data.byteOffset, dataSize); + }); + } + releaseTexture(textureData, deleteTexture) { + let key; + if (this.config.reuseTextures) { + key = this.textureLookup.get(textureData.texture); + if (key) { + if (deleteTexture) { + this.textureLookup.delete(key); + } + const inUseTextures = this.inUseTextures.get(key); + if (inUseTextures) { + const index = inUseTextures.indexOf(textureData.texture); + if (index !== -1) { + inUseTextures.splice(index, 1); + let idleTextures = this.idleTextures.get(key); + if (!idleTextures) { + idleTextures = []; + this.idleTextures.set(key, idleTextures); + } + idleTextures.push(textureData.texture); + } + } + } + } + if (!key || deleteTexture) { + instrument_1.Logger.verbose('TextureManager', `Deleting texture of size ${textureData.width}x${textureData.height}`); + this.glContext.deleteTexture(textureData.texture); + } + } + toTensorData(dataType, data) { + switch (dataType) { + case 'int16': + return data instanceof Int16Array ? data : Int16Array.from(data); + case 'int32': + return data instanceof Int32Array ? data : Int32Array.from(data); + case 'int8': + return data instanceof Int8Array ? data : Int8Array.from(data); + case 'uint16': + return data instanceof Uint16Array ? data : Uint16Array.from(data); + case 'uint32': + return data instanceof Uint32Array ? data : Uint32Array.from(data); + case 'uint8': + case 'bool': + return data instanceof Uint8Array ? data : Uint8Array.from(data); + case 'float32': + return data instanceof Float32Array ? data : Float32Array.from(data); + case 'float64': + return data instanceof Float64Array ? data : Float64Array.from(data); + default: + throw new Error(`TensorData type ${dataType} is not supported`); + } + } + toTextureData(dataType, data) { + if (!data) { + return undefined; + } + return (data instanceof Float32Array) ? data : new Float32Array(data); + /* + switch (dataType) { + case 'int16': + case 'int32': + case 'uint16': + case 'uint32': + return (data.constructor === Uint32Array) ? data as Uint32Array : new Uint32Array(data); + case 'int8': + case 'uint8': + case 'bool': + return (data.constructor === Uint8Array) ? data as Uint8Array : new Uint8Array(data); + case 'float32': + case 'float64': + return (data.constructor === Float32Array) ? data as Float32Array : new Float32Array(data); + default: + throw new Error(`TensorData type ${dataType} is not supported`); + } + */ + } + toEncoderType(_dataType) { + return 'float'; + // switch (dataType) { + // case 'int16': + // case 'int32': + // case 'uint16': + // case 'uint32': + // return 'int'; + // case 'uint8': + // case 'bool': + // return 'byte'; + // case 'float32': + // case 'float64': + // return 'float'; + // default: + // throw new Error(`TensorData type ${dataType} is not supported`); + // } + } + clearActiveTextures() { + this.glContext.clearActiveTextures(); + } +} +exports.TextureManager = TextureManager; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/types.ts": +/*!********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/types.ts ***! + \********************************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.TextureType = void 0; +var TextureType; +(function (TextureType) { + TextureType[TextureType["unpacked"] = 0] = "unpacked"; + TextureType[TextureType["unpackedReversed"] = 1] = "unpackedReversed"; + TextureType[TextureType["packed"] = 2] = "packed"; + TextureType[TextureType["downloadUint8AsFloat"] = 3] = "downloadUint8AsFloat"; + TextureType[TextureType["packedLastDimension"] = 4] = "packedLastDimension"; // <-- ONLY used in old ONNX.js Conv implementation for input W (deprecated) +})(TextureType = exports.TextureType || (exports.TextureType = {})); + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/utils.ts": +/*!********************************************!*\ + !*** ./lib/onnxjs/backends/webgl/utils.ts ***! + \********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getGlChannels = exports.getCoordsDataType = exports.getSqueezedParams = exports.squeezeInputShape = exports.generateShaderFuncNameFromInputSamplerNameAtOutCoords = exports.generateShaderFuncNameFromInputSamplerName = exports.repeatedTry = exports.getPackedShape = void 0; +const util_1 = __webpack_require__(/*! ../../util */ "./lib/onnxjs/util.ts"); +/** + * Given a non RGBA shape calculate the R version + * It is assumed that the dimensions are multiples of given channels + * NOTE: it is always the last dim that gets packed. + * @param unpackedShape original shape to create a packed version from + */ +function getPackedShape(unpackedShape) { + const len = unpackedShape.length; + return unpackedShape.slice(0, len - 1).concat(unpackedShape[len - 1] / 4); +} +exports.getPackedShape = getPackedShape; +async function repeatedTry(checkFn, delayFn = (_counter) => 0, maxCounter) { + return new Promise((resolve, reject) => { + let tryCount = 0; + const tryFn = () => { + if (checkFn()) { + resolve(); + return; + } + tryCount++; + const nextBackoff = delayFn(tryCount); + if (maxCounter != null && tryCount >= maxCounter) { + reject(); + return; + } + setTimeout(tryFn, nextBackoff); + }; + tryFn(); + }); +} +exports.repeatedTry = repeatedTry; +/** + * Generates the function name from an input sampler name. + * @param samplerName Name of the sampler. + */ +function generateShaderFuncNameFromInputSamplerName(samplerName) { + (0, util_1.assert)(typeof samplerName !== 'undefined' && samplerName.length !== 0, () => 'empty string found for sampler name'); + return 'get' + samplerName.charAt(0).toUpperCase() + samplerName.slice(1); +} +exports.generateShaderFuncNameFromInputSamplerName = generateShaderFuncNameFromInputSamplerName; +/** + * Generates the function name from an input sampler name at output coordinates. + * @param samplerName Name of the sampler. + */ +function generateShaderFuncNameFromInputSamplerNameAtOutCoords(samplerName) { + (0, util_1.assert)(typeof samplerName !== 'undefined' && samplerName.length !== 0, () => 'empty string found for sampler name'); + return 'get' + samplerName.charAt(0).toUpperCase() + samplerName.slice(1) + 'AtOutCoords'; +} +exports.generateShaderFuncNameFromInputSamplerNameAtOutCoords = generateShaderFuncNameFromInputSamplerNameAtOutCoords; +/** Returns a new input shape (a copy) that has a squeezed logical shape. */ +function squeezeInputShape(inputShape, squeezedShape) { + // Deep copy. + let newInputShape = JSON.parse(JSON.stringify(inputShape)); + newInputShape = squeezedShape; + return newInputShape; +} +exports.squeezeInputShape = squeezeInputShape; +/** Returns a list of squeezed parameters for shader functions */ +function getSqueezedParams(params, keptDims) { + return keptDims.map(d => params[d]).join(', '); +} +exports.getSqueezedParams = getSqueezedParams; +/** Returns the data type for different ranks. */ +function getCoordsDataType(rank) { + if (rank <= 1) { + return 'int'; + } + else if (rank === 2) { + return 'ivec2'; + } + else if (rank === 3) { + return 'ivec3'; + } + else if (rank === 4) { + return 'ivec4'; + } + else if (rank === 5) { + return 'ivec5'; + } + else if (rank === 6) { + return 'ivec6'; + } + else { + throw Error(`GPU for rank ${rank} is not yet supported`); + } +} +exports.getCoordsDataType = getCoordsDataType; +function getGlChannels(rank = 6) { + return ['x', 'y', 'z', 'w', 'u', 'v'].slice(0, rank); +} +exports.getGlChannels = getGlChannels; + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/webgl-context-factory.ts": +/*!************************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/webgl-context-factory.ts ***! + \************************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createNewWebGLContext = exports.createWebGLContext = void 0; +const instrument_1 = __webpack_require__(/*! ../../instrument */ "./lib/onnxjs/instrument.ts"); +const webgl_context_1 = __webpack_require__(/*! ./webgl-context */ "./lib/onnxjs/backends/webgl/webgl-context.ts"); +const cache = {}; +/** + * This factory function creates proper WebGLRenderingContext based on + * the current browsers capabilities + * The order is from higher/most recent versions to most basic + */ +function createWebGLContext(contextId) { + let context; + if ((!contextId || contextId === 'webgl2') && 'webgl2' in cache) { + context = cache.webgl2; + } + else if ((!contextId || contextId === 'webgl') && 'webgl' in cache) { + context = cache.webgl; + } + context = context || createNewWebGLContext(contextId); + contextId = contextId || context.version === 1 ? 'webgl' : 'webgl2'; + const gl = context.gl; + cache[contextId] = context; + if (gl.isContextLost()) { + delete cache[contextId]; + return createWebGLContext(contextId); + } + gl.disable(gl.DEPTH_TEST); + gl.disable(gl.STENCIL_TEST); + gl.disable(gl.BLEND); + gl.disable(gl.DITHER); + gl.disable(gl.POLYGON_OFFSET_FILL); + gl.disable(gl.SAMPLE_COVERAGE); + gl.enable(gl.SCISSOR_TEST); + gl.enable(gl.CULL_FACE); + gl.cullFace(gl.BACK); + return context; +} +exports.createWebGLContext = createWebGLContext; +function createNewWebGLContext(contextId) { + const canvas = createCanvas(); + const contextAttributes = { + alpha: false, + depth: false, + antialias: false, + stencil: false, + preserveDrawingBuffer: false, + premultipliedAlpha: false, + failIfMajorPerformanceCaveat: false + }; + let gl; + const ca = contextAttributes; + if (!contextId || contextId === 'webgl2') { + gl = canvas.getContext('webgl2', ca); + if (gl) { + try { + return new webgl_context_1.WebGLContext(gl, 2); + } + catch (err) { + instrument_1.Logger.warning('GlContextFactory', `failed to create WebGLContext using contextId 'webgl2'. Error: ${err}`); + } + } + } + if (!contextId || contextId === 'webgl') { + gl = canvas.getContext('webgl', ca) || canvas.getContext('experimental-webgl', ca); + if (gl) { + try { + return new webgl_context_1.WebGLContext(gl, 1); + } + catch (err) { + instrument_1.Logger.warning('GlContextFactory', `failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${err}`); + } + } + } + throw new Error('WebGL is not supported'); +} +exports.createNewWebGLContext = createNewWebGLContext; +function createCanvas() { + if (typeof document === 'undefined') { + if (typeof OffscreenCanvas === 'undefined') { + throw new TypeError('failed to create canvas: OffscreenCanvas is not supported'); + } + return new OffscreenCanvas(1, 1); + } + const canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + return canvas; +} + + +/***/ }), + +/***/ "./lib/onnxjs/backends/webgl/webgl-context.ts": +/*!****************************************************!*\ + !*** ./lib/onnxjs/backends/webgl/webgl-context.ts ***! + \****************************************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.WebGLContext = exports.linearSearchLastTrue = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const DataEncoders = __importStar(__webpack_require__(/*! ./texture-data-encoder */ "./lib/onnxjs/backends/webgl/texture-data-encoder.ts")); +const utils_1 = __webpack_require__(/*! ./utils */ "./lib/onnxjs/backends/webgl/utils.ts"); +function linearSearchLastTrue(arr) { + let i = 0; + for (; i < arr.length; ++i) { + const isDone = arr[i](); + if (!isDone) { + break; + } + } + return i - 1; +} +exports.linearSearchLastTrue = linearSearchLastTrue; +/** + * Abstraction and wrapper around WebGLRenderingContext and its operations + */ +class WebGLContext { + constructor(gl, version) { + this.frameBufferBound = false; + this.itemsToPoll = []; + this.gl = gl; + this.version = version; + this.getExtensions(); + this.vertexbuffer = this.createVertexbuffer(); + this.framebuffer = this.createFramebuffer(); + this.queryVitalParameters(); + } + allocateTexture(width, height, encoder, data) { + const gl = this.gl; + // create the texture + const texture = gl.createTexture(); + // bind the texture so the following methods effect this texture. + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + const buffer = data ? encoder.encode(data, width * height) : null; + gl.texImage2D(gl.TEXTURE_2D, 0, // Level of detail. + encoder.internalFormat, width, height, 0, // Always 0 in OpenGL ES. + encoder.format, encoder.textureType, buffer); + this.checkError(); + return texture; + } + updateTexture(texture, width, height, encoder, data) { + const gl = this.gl; + gl.bindTexture(gl.TEXTURE_2D, texture); + const buffer = encoder.encode(data, width * height); + gl.texSubImage2D(gl.TEXTURE_2D, 0, // level + 0, // xoffset + 0, // yoffset + width, height, encoder.format, encoder.textureType, buffer); + this.checkError(); + } + attachFramebuffer(texture, width, height) { + const gl = this.gl; + // Make it the target for framebuffer operations - including rendering. + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); // 0, we aren't using MIPMAPs + this.checkError(); + gl.viewport(0, 0, width, height); + gl.scissor(0, 0, width, height); + } + readTexture(texture, width, height, dataSize, dataType, channels) { + const gl = this.gl; + if (!channels) { + channels = 1; + } + if (!this.frameBufferBound) { + this.attachFramebuffer(texture, width, height); + } + const encoder = this.getEncoder(dataType, channels); + const buffer = encoder.allocate(width * height); + // bind texture to framebuffer + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); // 0, we aren't using MIPMAPs + // TODO: Check if framebuffer is ready + gl.readPixels(0, 0, width, height, gl.RGBA, encoder.textureType, buffer); + this.checkError(); + // unbind FB + return encoder.decode(buffer, dataSize); + } + isFramebufferReady() { + // TODO: Implement logic to check if the framebuffer is ready + return true; + } + getActiveTexture() { + const gl = this.gl; + const n = gl.getParameter(this.gl.ACTIVE_TEXTURE); + return `TEXTURE${(n - gl.TEXTURE0)}`; + } + getTextureBinding() { + return this.gl.getParameter(this.gl.TEXTURE_BINDING_2D); + } + getFramebufferBinding() { + return this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING); + } + setVertexAttributes(positionHandle, textureCoordHandle) { + const gl = this.gl; + gl.vertexAttribPointer(positionHandle, 3, gl.FLOAT, false, 20, 0); + gl.enableVertexAttribArray(positionHandle); + if (textureCoordHandle !== -1) { + gl.vertexAttribPointer(textureCoordHandle, 2, gl.FLOAT, false, 20, 12); + gl.enableVertexAttribArray(textureCoordHandle); + } + this.checkError(); + } + createProgram(vertexShader, fragShader) { + const gl = this.gl; + const program = gl.createProgram(); + // the program consists of our shaders + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragShader); + gl.linkProgram(program); + return program; + } + compileShader(shaderSource, shaderType) { + const gl = this.gl; + const shader = gl.createShader(shaderType); + if (!shader) { + throw new Error(`createShader() returned null with type ${shaderType}`); + } + gl.shaderSource(shader, shaderSource); + gl.compileShader(shader); + if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) === false) { + throw new Error(`Failed to compile shader: ${gl.getShaderInfoLog(shader)} +Shader source: +${shaderSource}`); + } + return shader; + } + deleteShader(shader) { + this.gl.deleteShader(shader); + } + bindTextureToUniform(texture, position, uniformHandle) { + const gl = this.gl; + gl.activeTexture(gl.TEXTURE0 + position); + this.checkError(); + gl.bindTexture(gl.TEXTURE_2D, texture); + this.checkError(); + gl.uniform1i(uniformHandle, position); + this.checkError(); + } + draw() { + this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4); + this.checkError(); + } + checkError() { + if (onnxruntime_common_1.env.debug) { + const gl = this.gl; + const error = gl.getError(); + let label = ''; + switch (error) { + case (gl.NO_ERROR): + return; + case (gl.INVALID_ENUM): + label = 'INVALID_ENUM'; + break; + case (gl.INVALID_VALUE): + label = 'INVALID_VALUE'; + break; + case (gl.INVALID_OPERATION): + label = 'INVALID_OPERATION'; + break; + case (gl.INVALID_FRAMEBUFFER_OPERATION): + label = 'INVALID_FRAMEBUFFER_OPERATION'; + break; + case (gl.OUT_OF_MEMORY): + label = 'OUT_OF_MEMORY'; + break; + case (gl.CONTEXT_LOST_WEBGL): + label = 'CONTEXT_LOST_WEBGL'; + break; + default: + label = `Unknown WebGL Error: ${error.toString(16)}`; + } + throw new Error(label); + } + } + deleteTexture(texture) { + this.gl.deleteTexture(texture); + } + deleteProgram(program) { + this.gl.deleteProgram(program); + } + getEncoder(dataType, channels, usage = 0 /* Encoder.Usage.Default */) { + if (this.version === 2) { + return new DataEncoders.RedFloat32DataEncoder(this.gl, channels); + } + switch (dataType) { + case 'float': + if (usage === 1 /* Encoder.Usage.UploadOnly */ || this.isRenderFloat32Supported) { + return new DataEncoders.RGBAFloatDataEncoder(this.gl, channels); + } + else { + return new DataEncoders.RGBAFloatDataEncoder(this.gl, channels, this.textureHalfFloatExtension.HALF_FLOAT_OES); + } + case 'int': + throw new Error('not implemented'); + case 'byte': + return new DataEncoders.Uint8DataEncoder(this.gl, channels); + default: + throw new Error(`Invalid dataType: ${dataType}`); + } + } + clearActiveTextures() { + const gl = this.gl; + for (let unit = 0; unit < this.maxTextureImageUnits; ++unit) { + gl.activeTexture(gl.TEXTURE0 + unit); + gl.bindTexture(gl.TEXTURE_2D, null); + } + } + dispose() { + if (this.disposed) { + return; + } + const gl = this.gl; + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + gl.deleteFramebuffer(this.framebuffer); + gl.bindBuffer(gl.ARRAY_BUFFER, null); + gl.deleteBuffer(this.vertexbuffer); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); + gl.finish(); + this.disposed = true; + } + createDefaultGeometry() { + // Sets of x,y,z(=0),s,t coordinates. + return new Float32Array([ + -1.0, 1.0, 0.0, 0.0, 1.0, + -1.0, -1.0, 0.0, 0.0, 0.0, + 1.0, 1.0, 0.0, 1.0, 1.0, + 1.0, -1.0, 0.0, 1.0, 0.0 // lower right + ]); + } + createVertexbuffer() { + const gl = this.gl; + const buffer = gl.createBuffer(); + if (!buffer) { + throw new Error('createBuffer() returned null'); + } + const geometry = this.createDefaultGeometry(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.bufferData(gl.ARRAY_BUFFER, geometry, gl.STATIC_DRAW); + this.checkError(); + return buffer; + } + createFramebuffer() { + const fb = this.gl.createFramebuffer(); + if (!fb) { + throw new Error('createFramebuffer returned null'); + } + return fb; + } + queryVitalParameters() { + const gl = this.gl; + this.isFloatTextureAttachableToFrameBuffer = this.checkFloatTextureAttachableToFrameBuffer(); + this.isRenderFloat32Supported = this.checkRenderFloat32(); + this.isFloat32DownloadSupported = this.checkFloat32Download(); + if (this.version === 1 && !this.textureHalfFloatExtension && !this.isRenderFloat32Supported) { + throw new Error('both float32 and float16 TextureType are not supported'); + } + this.isBlendSupported = !this.isRenderFloat32Supported || this.checkFloat32Blend(); + // this.maxCombinedTextureImageUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); + this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); + this.maxTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); + // this.maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); + // this.shadingLanguageVersion = gl.getParameter(gl.SHADING_LANGUAGE_VERSION); + // this.webglVendor = gl.getParameter(gl.VENDOR); + // this.webglVersion = gl.getParameter(gl.VERSION); + if (this.version === 2) { + // this.max3DTextureSize = gl.getParameter(WebGL2RenderingContext.MAX_3D_TEXTURE_SIZE); + // this.maxArrayTextureLayers = gl.getParameter(WebGL2RenderingContext.MAX_ARRAY_TEXTURE_LAYERS); + // this.maxColorAttachments = gl.getParameter(WebGL2RenderingContext.MAX_COLOR_ATTACHMENTS); + // this.maxDrawBuffers = gl.getParameter(WebGL2RenderingContext.MAX_DRAW_BUFFERS); + } + } + getExtensions() { + if (this.version === 2) { + this.colorBufferFloatExtension = this.gl.getExtension('EXT_color_buffer_float'); + this.disjointTimerQueryWebgl2Extension = this.gl.getExtension('EXT_disjoint_timer_query_webgl2'); + } + else { + this.textureFloatExtension = this.gl.getExtension('OES_texture_float'); + this.textureHalfFloatExtension = this.gl.getExtension('OES_texture_half_float'); + } + } + checkFloatTextureAttachableToFrameBuffer() { + // test whether Float32 texture is supported: + // STEP.1 create a float texture + const gl = this.gl; + const texture = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture); + // eslint-disable-next-line @typescript-eslint/naming-convention + const internalFormat = this.version === 2 ? gl.RGBA32F : gl.RGBA; + gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null); + // STEP.2 bind a frame buffer + const frameBuffer = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); + // STEP.3 attach texture to framebuffer + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); + // STEP.4 test whether framebuffer is complete + const isComplete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE; + gl.bindTexture(gl.TEXTURE_2D, null); + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + gl.deleteTexture(texture); + gl.deleteFramebuffer(frameBuffer); + return isComplete; + } + checkRenderFloat32() { + if (this.version === 2) { + if (!this.colorBufferFloatExtension) { + return false; + } + } + else { + if (!this.textureFloatExtension) { + return false; + } + } + return this.isFloatTextureAttachableToFrameBuffer; + } + checkFloat32Download() { + if (this.version === 2) { + if (!this.colorBufferFloatExtension) { + return false; + } + } + else { + if (!this.textureFloatExtension) { + return false; + } + if (!this.gl.getExtension('WEBGL_color_buffer_float')) { + return false; + } + } + return this.isFloatTextureAttachableToFrameBuffer; + } + /** + * Check whether GL_BLEND is supported + */ + checkFloat32Blend() { + // it looks like currently (2019-05-08) there is no easy way to detect whether BLEND is supported + // https://github.com/microsoft/onnxjs/issues/145 + const gl = this.gl; + let texture; + let frameBuffer; + let vertexShader; + let fragmentShader; + let program; + try { + texture = gl.createTexture(); + frameBuffer = gl.createFramebuffer(); + gl.bindTexture(gl.TEXTURE_2D, texture); + // eslint-disable-next-line @typescript-eslint/naming-convention + const internalFormat = this.version === 2 ? gl.RGBA32F : gl.RGBA; + gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null); + gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); + gl.enable(gl.BLEND); + vertexShader = gl.createShader(gl.VERTEX_SHADER); + if (!vertexShader) { + return false; + } + gl.shaderSource(vertexShader, 'void main(){}'); + gl.compileShader(vertexShader); + fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + if (!fragmentShader) { + return false; + } + gl.shaderSource(fragmentShader, 'precision highp float;void main(){gl_FragColor=vec4(0.5);}'); + gl.compileShader(fragmentShader); + program = gl.createProgram(); + if (!program) { + return false; + } + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragmentShader); + gl.linkProgram(program); + gl.useProgram(program); + gl.drawArrays(gl.POINTS, 0, 1); + return gl.getError() === gl.NO_ERROR; + } + finally { + gl.disable(gl.BLEND); + if (program) { + gl.deleteProgram(program); + } + if (vertexShader) { + gl.deleteShader(vertexShader); + } + if (fragmentShader) { + gl.deleteShader(fragmentShader); + } + if (frameBuffer) { + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + gl.deleteFramebuffer(frameBuffer); + } + if (texture) { + gl.bindTexture(gl.TEXTURE_2D, null); + gl.deleteTexture(texture); + } + } + } + beginTimer() { + if (this.version === 2 && this.disjointTimerQueryWebgl2Extension) { + const gl2 = this.gl; + const ext = this.disjointTimerQueryWebgl2Extension; + const query = gl2.createQuery(); + gl2.beginQuery(ext.TIME_ELAPSED_EXT, query); + return query; + } + else { + // TODO: add webgl 1 handling. + throw new Error('WebGL1 profiling currently not supported.'); + } + } + endTimer() { + if (this.version === 2 && this.disjointTimerQueryWebgl2Extension) { + const gl2 = this.gl; + const ext = this.disjointTimerQueryWebgl2Extension; + gl2.endQuery(ext.TIME_ELAPSED_EXT); + return; + } + else { + // TODO: add webgl 1 handling. + throw new Error('WebGL1 profiling currently not supported'); + } + } + isTimerResultAvailable(query) { + let available = false, disjoint = false; + if (this.version === 2 && this.disjointTimerQueryWebgl2Extension) { + const gl2 = this.gl; + const ext = this.disjointTimerQueryWebgl2Extension; + available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE); + disjoint = gl2.getParameter(ext.GPU_DISJOINT_EXT); + } + else { + // TODO: add webgl 1 handling. + throw new Error('WebGL1 profiling currently not supported'); + } + return available && !disjoint; + } + getTimerResult(query) { + let timeElapsed = 0; + if (this.version === 2) { + const gl2 = this.gl; + timeElapsed = gl2.getQueryParameter(query, gl2.QUERY_RESULT); + gl2.deleteQuery(query); + } + else { + // TODO: add webgl 1 handling. + throw new Error('WebGL1 profiling currently not supported'); + } + // return miliseconds + return timeElapsed / 1000000; + } + async waitForQueryAndGetTime(query) { + await (0, utils_1.repeatedTry)(() => this.isTimerResultAvailable(query)); + return this.getTimerResult(query); + } + async createAndWaitForFence() { + const fenceContext = this.createFence(this.gl); + return this.pollFence(fenceContext); + } + createFence(gl) { + let isFencePassed; + const gl2 = gl; + const query = gl2.fenceSync(gl2.SYNC_GPU_COMMANDS_COMPLETE, 0); + gl.flush(); + if (query === null) { + isFencePassed = () => true; + } + else { + isFencePassed = () => { + const status = gl2.clientWaitSync(query, 0, 0); + return status === gl2.ALREADY_SIGNALED || status === gl2.CONDITION_SATISFIED; + }; + } + return { query, isFencePassed }; + } + async pollFence(fenceContext) { + return new Promise(resolve => { + void this.addItemToPoll(() => fenceContext.isFencePassed(), () => resolve()); + }); + } + pollItems() { + // Find the last query that has finished. + const index = linearSearchLastTrue(this.itemsToPoll.map(x => x.isDoneFn)); + for (let i = 0; i <= index; ++i) { + const { resolveFn } = this.itemsToPoll[i]; + resolveFn(); + } + this.itemsToPoll = this.itemsToPoll.slice(index + 1); + } + async addItemToPoll(isDoneFn, resolveFn) { + this.itemsToPoll.push({ isDoneFn, resolveFn }); + if (this.itemsToPoll.length > 1) { + // We already have a running loop that polls. + return; + } + // Start a new loop that polls. + await (0, utils_1.repeatedTry)(() => { + this.pollItems(); + // End the loop if no more items to poll. + return this.itemsToPoll.length === 0; + }); + } +} +exports.WebGLContext = WebGLContext; + + +/***/ }), + +/***/ "./lib/onnxjs/execution-plan.ts": +/*!**************************************!*\ + !*** ./lib/onnxjs/execution-plan.ts ***! + \**************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.ExecutionPlan = void 0; +const instrument_1 = __webpack_require__(/*! ./instrument */ "./lib/onnxjs/instrument.ts"); +class KernelOp { + constructor(op, node) { + this.op = op; + this.node = node; + } +} +class ExecutionPlan { + constructor(graph, ops, profiler) { + this.graph = graph; + this.profiler = profiler; + this.initialize(ops); + } + initialize(ops) { + this.profiler.event('session', 'ExecutionPlan.initialize', () => { + const graphNodes = this.graph.getNodes(); + if (graphNodes.length !== ops.length) { + throw new Error('The size of nodes and OPs do not match.'); + } + this._ops = ops.map((op, i) => new KernelOp(op, graphNodes[i])); + this.reset(); + // look for starter node(s) + this._starter = []; + this._ops.forEach((op, i) => { + let resolved = true; + for (const input of op.node.inputs) { + if (!this._values[input] // not an initialized input + && this.graph.getInputIndices().indexOf(input) === -1 // not model input + ) { + resolved = false; + break; + } + } + if (resolved) { + this._starter.push(i); + } + }); + }); + } + reset() { + this._values = this.graph.getValues().map(i => i.tensor); + } + async execute(sessionHandler, modelInputs) { + return this.profiler.event('session', 'ExecutionPlan.execute', async () => { + // reset mediem result + this.reset(); + // create inference handler + const inferenceHandler = sessionHandler.createInferenceHandler(); + // populate inputs value + const graphInputs = this.graph.getInputIndices(); + if (modelInputs.length !== graphInputs.length) { + throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${modelInputs.length} expected: ${graphInputs.length}`); + } + modelInputs.forEach((input, i) => { + const index = graphInputs[i]; + this._values[index] = input; + }); + // prepare running sequence + const sequence = this._starter.slice(0); + // execution iterations + const graphValues = this.graph.getValues(); + const graphNodes = this.graph.getNodes(); + let rear = 0; + while (rear < sequence.length) { + const thisOpIndex = sequence[rear++]; + const thisOp = this._ops[thisOpIndex]; + // check input + const inputList = thisOp.node.inputs.map(i => this._values[i]); + if (inputList.indexOf(undefined) !== -1) { + throw new Error(`unresolved input detected: op: ${thisOp.node}`); + } + // run + const inputTensors = inputList; + instrument_1.Logger.verbose('ExecPlan', `Runing op:${thisOp.node.name} (${inputTensors.map((t, i) => `'${thisOp.node.inputs[i]}': ${t.type}[${t.dims.join(',')}]`).join(', ')})`); + const outputList = await this.profiler.event('node', thisOp.node.name, async () => thisOp.op.impl(inferenceHandler, inputTensors, thisOp.op.context)); + // check output + if (outputList.length !== thisOp.node.outputs.length) { + throw new Error('the size of output does not match model definition.'); + } + // fill value + outputList.forEach((output, i) => { + const j = thisOp.node.outputs[i]; + if (this._values[j]) { + throw new Error(`output [${j}] already has value: op:${thisOp.node.name}`); + } + this._values[j] = output; + }); + // resolve downstream nodes + const downstreamNodes = new Set(); + outputList.forEach((output, i) => { + const j = thisOp.node.outputs[i]; + for (const currentDownstreamNodeIndex of graphValues[j].to) { + const currentDownstreamNode = graphNodes[currentDownstreamNodeIndex]; + let resolved = true; + for (const k of currentDownstreamNode.inputs) { + if (!this._values[k]) { + resolved = false; + break; + } + } + if (resolved) { + downstreamNodes.add(currentDownstreamNodeIndex); + } + } + }); + sequence.push(...downstreamNodes); + } + const output = []; + for (let i = 0; i < this.graph.getOutputIndices().length; i++) { + const outputIndex = this.graph.getOutputIndices()[i]; + const outputTensor = this._values[outputIndex]; + if (outputTensor === undefined) { + throw new Error(`required output [${outputIndex}] does not have value`); + } + if (outputIndex === 0) { + await outputTensor.getData(); + } + else { + // eslint-disable-next-line no-unused-expressions + outputTensor.data; + } + output.push(outputTensor); + } + instrument_1.Logger.verbose('ExecPlan', 'disposing of inferenceHandler'); + inferenceHandler.dispose(); + return output; + }); + } +} +exports.ExecutionPlan = ExecutionPlan; + + +/***/ }), + +/***/ "./lib/onnxjs/graph.ts": +/*!*****************************!*\ + !*** ./lib/onnxjs/graph.ts ***! + \*****************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Graph = void 0; +const onnx_proto_1 = __webpack_require__(/*! onnx-proto */ "./node_modules/onnx-proto/dist/onnx.js"); +const attribute_1 = __webpack_require__(/*! ./attribute */ "./lib/onnxjs/attribute.ts"); +const ort_generated_1 = __webpack_require__(/*! ./ort-schema/ort-generated */ "./lib/onnxjs/ort-schema/ort-generated.ts"); +const tensor_1 = __webpack_require__(/*! ./tensor */ "./lib/onnxjs/tensor.ts"); +const util_1 = __webpack_require__(/*! ./util */ "./lib/onnxjs/util.ts"); +var ortFbs = ort_generated_1.onnxruntime.experimental.fbs; +// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-redeclare +exports.Graph = { + /** + * construct a graph from a graph protobuf type + */ + from: (graphProto, initializer) => new GraphImpl(graphProto, initializer), +}; +class Value { + constructor(valueInfo) { + this._from = undefined; + this._to = []; + this.tensor = undefined; + this.type = undefined; + if (valueInfo) { + this.type = util_1.ProtoUtil.tensorValueTypeFromProto(valueInfo.type.tensorType); + } + } + get from() { + return this._from; + } + get to() { + return this._to; + } +} +class Node { + constructor(_nodeProto, name) { + if (_nodeProto instanceof onnx_proto_1.onnx.NodeProto) { + this.name = _nodeProto.name; + this.opType = _nodeProto.opType; + this.attributes = new attribute_1.Attribute(_nodeProto.attribute); + } + else if (_nodeProto instanceof ortFbs.Node) { + this.name = name !== null && name !== void 0 ? name : _nodeProto.name(); + this.opType = _nodeProto.opType(); + this.attributes = new attribute_1.Attribute(util_1.ProtoUtil.tensorAttributesFromORTFormat(_nodeProto)); + } + this.inputs = []; + this.outputs = []; + this.executeNode = true; + } +} +class GraphImpl { + constructor(graph, graphInitializer) { + if (!graph) { + throw new TypeError('graph is empty'); + } + // build the graph - will throw exceptions if something fatal is detected + this.buildGraph(graph); + // execute any transformation logic for the graph (if applicable) + this.transformGraph(graphInitializer); + // check for cycles and other inconsistencies - will throw exceptions if something fatal is detected + this.checkIsAcyclic(); + } + getInputIndices() { + return this._allInputIndices; + } + getInputNames() { + return this._allInputNames; + } + getOutputIndices() { + return this._allOutputIndices; + } + getOutputNames() { + return this._allOutputNames; + } + getValues() { + return this._allData; + } + getNodes() { + return this._nodes; + } + buildGraph(graph) { + // build the graph - will throw exceptions if something fatal is detected + if (graph instanceof onnx_proto_1.onnx.GraphProto) { + this.buildGraphFromOnnxFormat(graph); + } + else if (graph instanceof ortFbs.Graph) { + this.buildGraphFromOrtFormat(graph); + } + else { + throw new TypeError('Graph type is not supported.'); + } + } + buildGraphFromOnnxFormat(graph) { + const dataIndices = new Map(); + this._allData = []; + this._allInputIndices = []; + this._allInputNames = []; + this._allOutputIndices = []; + this._allOutputNames = []; + this._nodes = []; + const nodesIndices = new Map(); + // scan all inputs + if (!graph.input) { + throw new Error('missing information in graph: input'); + } + const inputValueNames = []; + for (const i of graph.input) { + if (dataIndices.has(i.name)) { + throw new Error(`duplicated input name: ${i.name}`); + } + const currentIndex = this._allData.push(new Value(i)) - 1; + dataIndices.set(i.name, currentIndex); + inputValueNames.push(i.name); + } + // scan all initializers + if (!graph.initializer) { + throw new Error('missing information in graph: initializer'); + } + for (const i of graph.initializer) { + let index = dataIndices.get(i.name); + if (index === undefined) { + const value = new Value(); + value.type = { + shape: { dims: util_1.ProtoUtil.tensorDimsFromProto(i.dims) }, + tensorType: util_1.ProtoUtil.tensorDataTypeFromProto(i.dataType) + }; + index = this._allData.push(value) - 1; + dataIndices.set(i.name, index); + } + this._allData[index]._from = -1; + this._allData[index].tensor = tensor_1.Tensor.fromProto(i); + } + // filter out input indices + for (let i = 0; i < this._allData.length; i++) { + if (!this._allData[i].tensor) { + this._allInputIndices.push(i); + this._allInputNames.push(inputValueNames[i]); + } + } + // scan all outputs + if (!graph.output) { + throw new Error('missing information in graph: output'); + } + for (const i of graph.output) { + if (dataIndices.has(i.name)) { + throw new Error(`duplicated output name: ${i.name}`); + } + const currentIndex = this._allData.push(new Value(i)) - 1; + dataIndices.set(i.name, currentIndex); + this._allOutputIndices.push(currentIndex); + this._allOutputNames.push(i.name); + } + // scan all nodes + if (!graph.node) { + throw new Error('missing information in graph: node'); + } + for (const nodeProto of graph.node) { + if (!nodeProto.name) { + // assign a name to the node if it doesn't have one + for (let pick = 0;; pick++) { + const name = `unnamed_${nodeProto.opType}_${pick}`; + if (!nodesIndices.has(name)) { + nodeProto.name = name; + break; + } + } + } + if (nodesIndices.has(nodeProto.name)) { + throw new Error(`duplicated node name: ${nodeProto.name}`); + } + const currentIndex = this._nodes.push(new Node(nodeProto)) - 1; + nodesIndices.set(nodeProto.name, currentIndex); + } + // scan node's outputs + for (let i = 0; i < this._nodes.length; i++) { + const node = this._nodes[i]; + const nodeProto = graph.node[i]; + if (!nodeProto.output) { + throw new Error(`missing output for node: ${nodeProto.name}`); + } + for (const output of nodeProto.output) { + let dataIndex = dataIndices.get(output); + if (typeof dataIndex === 'undefined') { + dataIndex = this._allData.push(new Value()) - 1; + dataIndices.set(output, dataIndex); + } + node.outputs.push(dataIndex); + if (this._allData[dataIndex]._from !== undefined) { + throw new Error(`multiple nodes output to one data value: ${dataIndex}`); + } + this._allData[dataIndex]._from = i; + // for the 'Constant' operator, just create a new edge in the graph corresponding to the 'output' of the + // operator and ignore the node from the graph + if (nodeProto.opType === 'Constant') { + if (!nodeProto.attribute || nodeProto.attribute.length !== 1 || !nodeProto.attribute[0].t) { + throw new Error('missing attributes or missing tensor value in attributes for this Constant operator'); + } + if (!nodeProto.output || nodeProto.output.length !== 1) { + throw new Error('missing output or incorrect number of outputs for this Constant operator'); + } + node.outputs.pop(); + node.executeNode = false; + this._allData[dataIndex]._from = -1; + this._allData[dataIndex].tensor = tensor_1.Tensor.fromProto(nodeProto.attribute[0].t); + } + } + } + // scan node's inputs + for (let i = 0; i < this._nodes.length; i++) { + const node = this._nodes[i]; + const nodeProto = graph.node[i]; + if (!nodeProto.input) { + throw new Error(`missing input for node: ${nodeProto.name}`); + } + for (const input of nodeProto.input) { + const dataIndex = dataIndices.get(input); + if (typeof dataIndex === 'undefined') { + // handle exception when opset > 9 and roi not given + if (input === '' && nodeProto.input.length === 3 && nodeProto.opType === 'Resize') { + continue; + } + throw new Error(`unrecognized input '${input}' for node: ${nodeProto.name}`); + } + node.inputs.push(dataIndex); + this._allData[dataIndex]._to.push(i); + } + } + return true; + } + buildGraphFromOrtFormat(graph) { + var _a, _b, _c; + const dataIndices = new Map(); + this._allData = []; + this._allInputIndices = []; + this._allInputNames = []; + this._allOutputIndices = []; + this._allOutputNames = []; + this._nodes = []; + const nodesIndices = new Map(); + // scan all inputs + const inputValueNames = []; + for (let i = 0; i < graph.inputsLength(); i++) { + const inputName = graph.inputs(i); + if (dataIndices.has(inputName)) { + throw new Error(`duplicated input name: ${inputName}`); + } + // Find the input typeInfo from nodeargs + for (let j = 0; j < graph.nodeArgsLength(); j++) { + if (((_a = graph.nodeArgs(j)) === null || _a === void 0 ? void 0 : _a.name()) === inputName) { + const value = new Value(); + const valueType = (_c = (_b = graph.nodeArgs(j)) === null || _b === void 0 ? void 0 : _b.type()) === null || _c === void 0 ? void 0 : _c.valueType(); + if (valueType !== ortFbs.TypeInfoValue.tensor_type) { + throw new Error('Unexpected value type for the nodeArg.'); + } + const valueInfo = graph.nodeArgs(j).type().value(new ortFbs.TensorTypeAndShape()); + const type = util_1.ProtoUtil.tensorDataTypeFromProto(valueInfo.elemType()); + const shape = valueInfo.shape(); + const dims = []; + for (let k = 0; k < shape.dimLength(); k++) { + dims.push(util_1.LongUtil.longToNumber(shape.dim(k).value().dimValue())); + } + value.type = { shape: { dims }, tensorType: type }; + const currentIndex = this._allData.push(value) - 1; + dataIndices.set(inputName, currentIndex); + inputValueNames.push(inputName); + } + } + } + // check initializers + for (let i = 0; i < graph.initializersLength(); i++) { + const initializer = graph.initializers(i); + let index = dataIndices.get(initializer.name()); + if (index === undefined) { + const value = new Value(); + const dims = util_1.ProtoUtil.tensorDimsFromORTFormat(initializer); + const type = util_1.ProtoUtil.tensorDataTypeFromProto(initializer.dataType()); + value.type = { shape: { dims }, tensorType: type }; + index = this._allData.push(value) - 1; + dataIndices.set(initializer.name(), index); + } + this._allData[index]._from = -1; + this._allData[index].tensor = tensor_1.Tensor.fromOrtTensor(initializer); + } + // filter out input indices + for (let i = 0; i < this._allData.length; i++) { + if (!this._allData[i].tensor) { + this._allInputIndices.push(i); + this._allInputNames.push(inputValueNames[i]); + } + } + // scan all outputs + for (let i = 0; i < graph.outputsLength(); i++) { + const outputName = graph.outputs(i); + if (dataIndices.has(outputName)) { + throw new Error(`duplicated output name: ${outputName}`); + } + const currentIndex = this._allData.push(new Value()) - 1; + dataIndices.set(outputName, currentIndex); + this._allOutputIndices.push(currentIndex); + this._allOutputNames.push(outputName); + } + // scan all nodes + if (!graph.nodes) { + throw new Error('missing information in graph: node'); + } + for (let i = 0; i < graph.nodesLength(); i++) { + const nodeProto = graph.nodes(i); + let name = nodeProto.name(); + if (!name) { + // assign a name to the node if it doesn't have one + for (let pick = 0;; pick++) { + name = `unnamed_${nodeProto.opType()}_${pick}`; + if (!nodesIndices.has(name)) { + // an unique name is found. break. + break; + } + } + } + if (nodesIndices.has(name)) { + throw new Error(`duplicated node name: ${name}`); + } + const currentIndex = this._nodes.push(new Node(nodeProto, name)) - 1; + nodesIndices.set(name, currentIndex); + } + // scan node's outputs + for (let i = 0; i < this._nodes.length; i++) { + const node = this._nodes[i]; + const nodeProto = graph.nodes(i); + if (nodeProto == null) { + throw new Error(`No node exists at index ${i}`); + } + if ((nodeProto === null || nodeProto === void 0 ? void 0 : nodeProto.outputsLength()) === 0) { + throw new Error(`missing output for node: ${nodeProto.name}`); + } + for (let j = 0; j < (nodeProto === null || nodeProto === void 0 ? void 0 : nodeProto.outputsLength()); j++) { + const output = nodeProto === null || nodeProto === void 0 ? void 0 : nodeProto.outputs(j); + let dataIndex = dataIndices.get(output); + if (typeof dataIndex === 'undefined') { + dataIndex = this._allData.push(new Value()) - 1; + dataIndices.set(output, dataIndex); + } + node.outputs.push(dataIndex); + if (this._allData[dataIndex]._from !== undefined) { + throw new Error(`multiple nodes output to one data value: ${dataIndex}`); + } + this._allData[dataIndex]._from = i; + // for the 'Constant' operator, just create a new edge in the graph corresponding to the 'output' of the + // operator and ignore the node from the graph + if (nodeProto.opType() === 'Constant') { + if (nodeProto.attributesLength() !== 1 || !nodeProto.attributes(0).t()) { + throw new Error('missing attributes or missing tensor value in attributes for this Constant operator'); + } + if (nodeProto.outputsLength() !== 1) { + throw new Error('missing output or incorrect number of outputs for this Constant operator'); + } + node.outputs.pop(); + node.executeNode = false; + this._allData[dataIndex]._from = -1; + this._allData[dataIndex].tensor = tensor_1.Tensor.fromOrtTensor(nodeProto.attributes(0).t()); + } + } + } + // scan node's inputs + for (let i = 0; i < this._nodes.length; i++) { + const node = this._nodes[i]; + const nodeProto = graph.nodes(i); + if (nodeProto.inputsLength() === 0) { + throw new Error(`missing input for node: ${nodeProto.name}`); + } + for (let j = 0; j < nodeProto.inputsLength(); j++) { + const input = nodeProto.inputs(j); + const dataIndex = dataIndices.get(input); + if (typeof dataIndex === 'undefined') { + throw new Error(`unrecognized input '${input}' for node: ${nodeProto.name()}`); + } + node.inputs.push(dataIndex); + this._allData[dataIndex]._to.push(i); + } + } + } + checkIsAcyclic() { + // go through the graph and check for cycles or other fatal inconsistencies + const starters = new Set(); + this._allInputIndices.forEach(i => { + const data = this._allData[i]; + data._to.forEach(j => { + starters.add(j); + }); + }); + // Iterative DFS to check for cycles + const nodesStack = Array.from(starters); + const nodesState = new Array(this._nodes.length).fill('white'); + while (nodesStack.length > 0) { + const nodeIndex = nodesStack.pop(); + // this node has now been processed completely. Mark this node 'black' to denote this. + if (nodesState[nodeIndex] === 'gray') { + nodesState[nodeIndex] = 'black'; + } + else { + // this node is under processing stage. mark this node 'gray' to denote this. + nodesStack.push(nodeIndex); + nodesState[nodeIndex] = 'gray'; + this._nodes[nodeIndex].outputs.forEach((outgoingEdgeIndex) => { + const data = this._allData[outgoingEdgeIndex]; + if (typeof data.tensor !== 'undefined') { + throw new Error('node outputs should not be initialized'); + } + if (data._from !== nodeIndex) { + throw new Error('from property of the Value object doesn\'t match index of Node being processed'); + } + data._to.forEach((downstreamNodeIndex) => { + // back edge found - cyclic + if (nodesState[downstreamNodeIndex] === 'gray') { + throw new Error('model graph is cyclic'); + } + // tree edge found - continue processing by adding it to stack + else if (nodesState[downstreamNodeIndex] === 'white') { + nodesStack.push(downstreamNodeIndex); + } + }); + }); + } + } + } + transformGraph(graphInitializer) { + // apply common transform + this.removeAllIdentityNodes(); + this.removeAllDropoutNodes(); + this.fuseConvActivationNodes(); + // apply initializer specific transform + if (graphInitializer) { + graphInitializer.transformGraph(this); + } + // finalize graph + this.finalizeGraph(); + } + /** + * finalize the graph. + * + * this function should be called after all the transformation completed. + * this function removes all unnecessary nodes and values from the graph + */ + finalizeGraph() { + let offset = 0; + // delete all nodes that are not being executed + for (let i = 0; i < this._nodes.length; i++) { + if (!this._nodes[i].executeNode) { + // delete this node and shift all subsequent nodes up + offset++; + // delete all output values + this._nodes[i].outputs.forEach(ind => { + this._allData[ind]._from = -2; + }); + this._nodes.splice(i, 1); + i--; + continue; + } + if (offset > 0) { + // update the value table + this._nodes[i].inputs.forEach(value => { + const ind = this._allData[value]._to.indexOf(i + offset); + if (ind !== -1) { + this._allData[value]._to[ind] = i; + } + }); + this._nodes[i].outputs.forEach(value => { + if (this._allData[value]._from && this._allData[value]._from === i + offset) { + this._allData[value]._from = i; + } + }); + } + } + offset = 0; + // delete all values that are not being referenced + for (let i = 0; i < this._allData.length; i++) { + // if current value is neither linked to next node, nor an output value, remove it. + if (this._allData[i].from === -2 && this._allOutputIndices.indexOf(i + offset) === -1) { + offset++; + this._allData.splice(i, 1); + i--; + continue; + } + if (offset > 0) { + let ind = -1; + // if current value is neither an input value nor an initializer, find the node it's + // coming from and update the corresponding node output + if (this._allData[i].from !== undefined && this._allData[i].from !== -1) { + ind = this._nodes[this._allData[i].from].outputs.indexOf(i + offset); + if (ind !== -1) { + this._nodes[this._allData[i].from].outputs[ind] = i; + } + } + else { + // if current value is an input value, update its reference in inputIndices + ind = this._allInputIndices.indexOf(i + offset); + if (ind !== -1) { + this._allInputIndices[ind] = i; + } + } + // find the node that the current value is linking to and update its input reference + this._allData[i].to.forEach(node => { + ind = this._nodes[node].inputs.indexOf(i + offset); + if (ind !== -1) { + this._nodes[node].inputs[ind] = i; + } + }); + if (this._allData[i].to.length === 0) { + // if current value is a graph output, update its reference in outputIndices + ind = this._allOutputIndices.indexOf(i + offset); + if (ind !== -1) { + this._allOutputIndices[ind] = i; + } + } + } + } + } + /** + * Delete the specifed node. Assume the node has one incoming input and the first output connected to other nodes. + * An input validation must be done before calling this function. + * @param nodeIndex The index of node to be deleted + */ + deleteNode(nodeIndex) { + const node = this._nodes[nodeIndex]; + if (node.outputs.length > 1) { + for (let i = 1; i < node.outputs.length; i++) { + if (this._allData[node.outputs[i]].to.length > 0) { + throw new Error('Node deletion with more than one output connected to other nodes is not supported. '); + } + } + } + // this node wil not be executed + node.executeNode = false; + const inputValueIndex = node.inputs[0]; + const outputValueIndex = node.outputs[0]; + const nodesConsumingOutput = this._allData[outputValueIndex].to; + // remove this node from the to property of the input Value + const delIndex = this._allData[inputValueIndex].to.indexOf(nodeIndex); + // should not happen + if (delIndex === -1) { + throw new Error('The Value object doesn\'t have the current Node in it\'s \'to\' property '); + } + this._allData[inputValueIndex].to.splice(delIndex, 1); + // clear node indices consuming this output Value + this._allData[outputValueIndex]._to = []; + // if the output of this node is a graph output, adjust the index appropriately + const index = this._allOutputIndices.indexOf(outputValueIndex); + if (index !== -1) { + this._allOutputIndices[index] = inputValueIndex; + } + // override the inputs for nodes consuming this node's output with the input to this node + if (nodesConsumingOutput && nodesConsumingOutput.length > 0) { + for (const nodeIndex of nodesConsumingOutput) { + const replaceIndex = this._nodes[nodeIndex].inputs.indexOf(outputValueIndex); + // should not happen + if (replaceIndex === -1) { + throw new Error('The Node object doesn\'t have the output Value in it\'s \'inputs\' property '); + } + this._nodes[nodeIndex].inputs[replaceIndex] = inputValueIndex; + this._allData[inputValueIndex].to.push(nodeIndex); + } + } + } + removeAllDropoutNodes() { + let nodeIndex = 0; + for (const node of this._nodes) { + // weed out 'Dropout' nodes so that no time is wasted in execution + if (node.opType === 'Dropout') { + // the node should have exactly 1 input and 1 or 2 outputs + if (node.inputs.length !== 1) { + throw new Error('Dropout nodes should only contain one input. '); + } + if (node.outputs.length !== 1 && node.outputs.length !== 2) { + throw new Error('Dropout nodes should contain either 1 or 2 output(s)'); + } + // the second output should not be referenced by any other node + if (node.outputs.length === 2 && this._allData[node.outputs[1]]._to.length !== 0) { + throw new Error('Dropout nodes\'s second output should not be referenced by other nodes'); + } + this.deleteNode(nodeIndex); + } + nodeIndex++; + } + } + removeAllIdentityNodes() { + let nodeIndex = 0; + for (const node of this._nodes) { + // weed out 'Identity' nodes so that no time is wasted in execution + if (node.opType === 'Identity') { + this.deleteNode(nodeIndex); + } + nodeIndex++; + } + } + isActivation(n) { + switch (n.opType) { + // TODO: add other activation methods + case 'Relu': + case 'Sigmoid': + case 'Clip': + return true; + default: + return false; + } + } + fuseConvActivationNodes() { + for (const node of this._nodes) { + if (node.opType === 'Conv') { + const next = this._allData[node.outputs[0]]._to; + if (next.length === 1 && this.isActivation(this._nodes[next[0]])) { + const child = this._nodes[next[0]]; + if (child.opType === 'Clip') { + if (child.inputs.length === 1) { + try { + node.attributes.set('activation_params', 'floats', [child.attributes.getFloat('min'), child.attributes.getFloat('max')]); + } + catch (e) { + node.attributes.set('activation_params', 'floats', [util_1.MIN_CLIP, util_1.MAX_CLIP]); + } + } + else if (child.inputs.length >= 3 && this._allData[child.inputs[1]].tensor !== undefined && + this._allData[child.inputs[2]].tensor !== undefined) { + node.attributes.set('activation_params', 'floats', [ + this._allData[child.inputs[1]].tensor.floatData[0], this._allData[child.inputs[2]].tensor.floatData[0] + ]); + } + else { + // Skip fusion with clip node since clip min and clip max are not coming from initializer + continue; + } + } + node.attributes.set('activation', 'string', (child.opType)); + this.deleteNode(next[0]); + } + } + } + } +} + + +/***/ }), + +/***/ "./lib/onnxjs/instrument.ts": +/*!**********************************!*\ + !*** ./lib/onnxjs/instrument.ts ***! + \**********************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.now = exports.Profiler = exports.Logger = void 0; +class NoOpLoggerProvider { + log(_severity, _content, _category) { + // do nothing + } +} +class ConsoleLoggerProvider { + log(severity, content, category) { + // eslint-disable-next-line no-console + console.log(`${this.color(severity)} ${category ? '\x1b[35m' + category + '\x1b[0m ' : ''}${content}`); + } + color(severity) { + switch (severity) { + case 'verbose': + return '\x1b[34;40mv\x1b[0m'; + case 'info': + return '\x1b[32mi\x1b[0m'; + case 'warning': + return '\x1b[30;43mw\x1b[0m'; + case 'error': + return '\x1b[31;40me\x1b[0m'; + case 'fatal': + return '\x1b[101mf\x1b[0m'; + default: + throw new Error(`unsupported severity: ${severity}`); + } + } +} +const SEVERITY_VALUE = { + verbose: 1000, + info: 2000, + warning: 4000, + error: 5000, + fatal: 6000 +}; +const LOGGER_PROVIDER_MAP = { + ['none']: new NoOpLoggerProvider(), + ['console']: new ConsoleLoggerProvider() +}; +const LOGGER_DEFAULT_CONFIG = { + provider: 'console', + minimalSeverity: 'warning', + logDateTime: true, + logSourceLocation: false +}; +let LOGGER_CONFIG_MAP = { ['']: LOGGER_DEFAULT_CONFIG }; +function log(arg0, arg1, arg2, arg3) { + if (arg1 === undefined) { + // log(category: string): Logger.CategorizedLogger; + return createCategorizedLogger(arg0); + } + else if (arg2 === undefined) { + // log(severity, content); + logInternal(arg0, arg1, 1); + } + else if (typeof arg2 === 'number' && arg3 === undefined) { + // log(severity, content, stack) + logInternal(arg0, arg1, arg2); + } + else if (typeof arg2 === 'string' && arg3 === undefined) { + // log(severity, category, content) + logInternal(arg0, arg2, 1, arg1); + } + else if (typeof arg2 === 'string' && typeof arg3 === 'number') { + // log(severity, category, content, stack) + logInternal(arg0, arg2, arg3, arg1); + } + else { + throw new TypeError('input is valid'); + } +} +function createCategorizedLogger(category) { + return { + verbose: log.verbose.bind(null, category), + info: log.info.bind(null, category), + warning: log.warning.bind(null, category), + error: log.error.bind(null, category), + fatal: log.fatal.bind(null, category) + }; +} +// NOTE: argument 'category' is put the last parameter beacause typescript +// doesn't allow optional argument put in front of required argument. This +// order is different from a usual logging API. +function logInternal(severity, content, stack, category) { + const config = LOGGER_CONFIG_MAP[category || ''] || LOGGER_CONFIG_MAP['']; + if (SEVERITY_VALUE[severity] < SEVERITY_VALUE[config.minimalSeverity]) { + return; + } + if (config.logDateTime) { + content = `${new Date().toISOString()}|${content}`; + } + if (config.logSourceLocation) { + // TODO: calculate source location from 'stack' + } + LOGGER_PROVIDER_MAP[config.provider].log(severity, content, category); +} +// eslint-disable-next-line @typescript-eslint/no-namespace +(function (log) { + function verbose(arg0, arg1) { + log('verbose', arg0, arg1); + } + log.verbose = verbose; + function info(arg0, arg1) { + log('info', arg0, arg1); + } + log.info = info; + function warning(arg0, arg1) { + log('warning', arg0, arg1); + } + log.warning = warning; + function error(arg0, arg1) { + log('error', arg0, arg1); + } + log.error = error; + function fatal(arg0, arg1) { + log('fatal', arg0, arg1); + } + log.fatal = fatal; + function reset(config) { + LOGGER_CONFIG_MAP = {}; + set('', config || {}); + } + log.reset = reset; + function set(category, config) { + if (category === '*') { + reset(config); + } + else { + const previousConfig = LOGGER_CONFIG_MAP[category] || LOGGER_DEFAULT_CONFIG; + LOGGER_CONFIG_MAP[category] = { + provider: config.provider || previousConfig.provider, + minimalSeverity: config.minimalSeverity || previousConfig.minimalSeverity, + logDateTime: (config.logDateTime === undefined) ? previousConfig.logDateTime : config.logDateTime, + logSourceLocation: (config.logSourceLocation === undefined) ? previousConfig.logSourceLocation : + config.logSourceLocation + }; + } + // TODO: we want to support wildcard or regex? + } + log.set = set; + function setWithEnv(env) { + const config = {}; + if (env.logLevel) { + config.minimalSeverity = env.logLevel; + } + set('', config); + } + log.setWithEnv = setWithEnv; +})(log || (log = {})); +// eslint-disable-next-line @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention +exports.Logger = log; +// TODO +// class WebGLEvent implements Profiler.Event {} +class Event { + constructor(category, name, startTime, endCallback, timer, ctx) { + this.category = category; + this.name = name; + this.startTime = startTime; + this.endCallback = endCallback; + this.timer = timer; + this.ctx = ctx; + } + end() { + return this.endCallback(this); + } + async checkTimer() { + if (this.ctx === undefined || this.timer === undefined) { + throw new Error('No webgl timer found'); + } + else { + this.ctx.endTimer(); + return this.ctx.waitForQueryAndGetTime(this.timer); + } + } +} +class EventRecord { + constructor(category, name, startTime, endTime) { + this.category = category; + this.name = name; + this.startTime = startTime; + this.endTime = endTime; + } +} +class Profiler { + static create(config) { + if (config === undefined) { + return new this(); + } + return new this(config.maxNumberEvents, config.flushBatchSize, config.flushIntervalInMilliseconds); + } + constructor(maxNumberEvents, flushBatchSize, flushIntervalInMilliseconds) { + this._started = false; + this._flushPointer = 0; + this._started = false; + this._maxNumberEvents = maxNumberEvents === undefined ? 10000 : maxNumberEvents; + this._flushBatchSize = flushBatchSize === undefined ? 10 : flushBatchSize; + this._flushIntervalInMilliseconds = flushIntervalInMilliseconds === undefined ? 5000 : flushIntervalInMilliseconds; + } + // start profiling + start() { + this._started = true; + this._timingEvents = []; + this._flushTime = (0, exports.now)(); + this._flushPointer = 0; + } + // stop profiling + stop() { + this._started = false; + for (; this._flushPointer < this._timingEvents.length; this._flushPointer++) { + this.logOneEvent(this._timingEvents[this._flushPointer]); + } + } + event(category, name, func, ctx) { + const event = this._started ? this.begin(category, name, ctx) : undefined; + let isPromise = false; + const res = func(); + // we consider a then-able object is a promise + if (res && typeof res.then === 'function') { + isPromise = true; + return new Promise((resolve, reject) => { + res + .then(async (value) => { + if (event) { + await event.end(); + } + resolve(value); + }, async (reason) => { + if (event) { + await event.end(); + } + reject(reason); + }); + }); + } + if (!isPromise && event) { + const eventRes = event.end(); + if (eventRes && typeof eventRes.then === 'function') { + return new Promise((resolve, reject) => { + (eventRes).then(() => { + resolve(res); + }, (reason) => { + reject(reason); + }); + }); + } + } + return res; + } + // begin an event + begin(category, name, ctx) { + if (!this._started) { + throw new Error('profiler is not started yet'); + } + if (ctx === undefined) { + const startTime = (0, exports.now)(); + this.flush(startTime); + return new Event(category, name, startTime, e => this.endSync(e)); + } + else { + const timer = ctx.beginTimer(); + return new Event(category, name, 0, async (e) => this.end(e), timer, ctx); + } + } + // end the specific event + async end(event) { + const endTime = await event.checkTimer(); + if (this._timingEvents.length < this._maxNumberEvents) { + this._timingEvents.push(new EventRecord(event.category, event.name, event.startTime, endTime)); + this.flush(endTime); + } + } + endSync(event) { + const endTime = (0, exports.now)(); + if (this._timingEvents.length < this._maxNumberEvents) { + this._timingEvents.push(new EventRecord(event.category, event.name, event.startTime, endTime)); + this.flush(endTime); + } + } + logOneEvent(event) { + exports.Logger.verbose(`Profiler.${event.category}`, `${(event.endTime - event.startTime).toFixed(2)}ms on event '${event.name}' at ${event.endTime.toFixed(2)}`); + } + flush(currentTime) { + if (this._timingEvents.length - this._flushPointer >= this._flushBatchSize || + currentTime - this._flushTime >= this._flushIntervalInMilliseconds) { + // should flush when either batch size accumlated or interval elepsed + for (const previousPointer = this._flushPointer; this._flushPointer < previousPointer + this._flushBatchSize && + this._flushPointer < this._timingEvents.length; this._flushPointer++) { + this.logOneEvent(this._timingEvents[this._flushPointer]); + } + this._flushTime = (0, exports.now)(); + } + } + get started() { + return this._started; + } +} +exports.Profiler = Profiler; +/** + * returns a number to represent the current timestamp in a resolution as high as possible. + */ +exports.now = (typeof performance !== 'undefined' && performance.now) ? () => performance.now() : Date.now; + + +/***/ }), + +/***/ "./lib/onnxjs/model.ts": +/*!*****************************!*\ + !*** ./lib/onnxjs/model.ts ***! + \*****************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Model = void 0; +const flatbuffers_1 = __webpack_require__(/*! flatbuffers */ "./node_modules/flatbuffers/js/flatbuffers.mjs"); +const onnx_proto_1 = __webpack_require__(/*! onnx-proto */ "./node_modules/onnx-proto/dist/onnx.js"); +const graph_1 = __webpack_require__(/*! ./graph */ "./lib/onnxjs/graph.ts"); +const ort_generated_1 = __webpack_require__(/*! ./ort-schema/ort-generated */ "./lib/onnxjs/ort-schema/ort-generated.ts"); +const util_1 = __webpack_require__(/*! ./util */ "./lib/onnxjs/util.ts"); +var ortFbs = ort_generated_1.onnxruntime.experimental.fbs; +class Model { + // empty model + constructor() { } + load(buf, graphInitializer, isOrtFormat) { + if (!isOrtFormat) { + // isOrtFormat === false || isOrtFormat === undefined + try { + this.loadFromOnnxFormat(buf, graphInitializer); + return; + } + catch (e) { + if (isOrtFormat !== undefined) { + throw e; + } + } + } + this.loadFromOrtFormat(buf, graphInitializer); + } + loadFromOnnxFormat(buf, graphInitializer) { + const modelProto = onnx_proto_1.onnx.ModelProto.decode(buf); + const irVersion = util_1.LongUtil.longToNumber(modelProto.irVersion); + if (irVersion < 3) { + throw new Error('only support ONNX model with IR_VERSION>=3'); + } + this._opsets = + modelProto.opsetImport.map(i => ({ domain: i.domain, version: util_1.LongUtil.longToNumber(i.version) })); + this._graph = graph_1.Graph.from(modelProto.graph, graphInitializer); + } + loadFromOrtFormat(buf, graphInitializer) { + const fb = new flatbuffers_1.flatbuffers.ByteBuffer(buf); + const ortModel = ortFbs.InferenceSession.getRootAsInferenceSession(fb).model(); + const irVersion = util_1.LongUtil.longToNumber(ortModel.irVersion()); + if (irVersion < 3) { + throw new Error('only support ONNX model with IR_VERSION>=3'); + } + this._opsets = []; + for (let i = 0; i < ortModel.opsetImportLength(); i++) { + const opsetId = ortModel.opsetImport(i); + this._opsets.push({ domain: opsetId === null || opsetId === void 0 ? void 0 : opsetId.domain(), version: util_1.LongUtil.longToNumber(opsetId.version()) }); + } + this._graph = graph_1.Graph.from(ortModel.graph(), graphInitializer); + } + get graph() { + return this._graph; + } + get opsets() { + return this._opsets; + } +} +exports.Model = Model; + + +/***/ }), + +/***/ "./lib/onnxjs/operators.ts": +/*!*********************************!*\ + !*** ./lib/onnxjs/operators.ts ***! + \*********************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.FLOAT_TYPES = exports.INT_TYPES = exports.NUMBER_TYPES = void 0; +exports.NUMBER_TYPES = ['float32', 'float64', 'int32', 'int16', 'int8', 'uint16', 'uint32', 'uint8']; +exports.INT_TYPES = ['int32', 'int16', 'int8', 'uint16', 'uint32', 'uint8']; +exports.FLOAT_TYPES = ['float32', 'float64']; + + +/***/ }), + +/***/ "./lib/onnxjs/opset.ts": +/*!*****************************!*\ + !*** ./lib/onnxjs/opset.ts ***! + \*****************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.resolveOperator = void 0; +function resolveOperator(node, opsets, rules) { + for (const rule of rules) { + const opType = rule[0]; + const domain = rule[1]; + const versionSelector = rule[2]; + const opImpl = rule[3]; + const opInit = rule[4]; + if (node.opType === opType) { // operator type matches + for (const opset of opsets) { + // opset '' and 'ai.onnx' are considered the same. + if (opset.domain === domain || (opset.domain === 'ai.onnx' && domain === '')) { // opset domain found + if (matchSelector(opset.version, versionSelector)) { + return { opImpl, opInit }; + } + } + } + } + } + throw new TypeError(`cannot resolve operator '${node.opType}' with opsets: ${opsets.map(set => `${set.domain || 'ai.onnx'} v${set.version}`).join(', ')}`); +} +exports.resolveOperator = resolveOperator; +function matchSelector(version, selector) { + if (selector.endsWith('+')) { + // minimum version match ('7+' expects version>=7) + const rangeStart = Number.parseInt(selector.substring(0, selector.length - 1), 10); + return !isNaN(rangeStart) && rangeStart <= version; + } + else if (selector.split('-').length === 2) { + // range match ('6-8' expects 6<=version<=8) + const pair = selector.split('-'); + const rangeStart = Number.parseInt(pair[0], 10); + const rangeEnd = Number.parseInt(pair[1], 10); + return !isNaN(rangeStart) && !isNaN(rangeEnd) && rangeStart <= version && version <= rangeEnd; + } + else { + // exact match ('7' expects version===7) + return Number.parseInt(selector, 10) === version; + } +} + + +/***/ }), + +/***/ "./lib/onnxjs/ort-schema/ort-generated.ts": +/*!************************************************!*\ + !*** ./lib/onnxjs/ort-schema/ort-generated.ts ***! + \************************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable */ +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.onnxruntime = void 0; +const flatbuffers_1 = __webpack_require__(/*! flatbuffers */ "./node_modules/flatbuffers/js/flatbuffers.mjs"); +/** + * @enum {number} + */ +var onnxruntime; +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + let AttributeType; + (function (AttributeType) { + AttributeType[AttributeType["UNDEFINED"] = 0] = "UNDEFINED"; + AttributeType[AttributeType["FLOAT"] = 1] = "FLOAT"; + AttributeType[AttributeType["INT"] = 2] = "INT"; + AttributeType[AttributeType["STRING"] = 3] = "STRING"; + AttributeType[AttributeType["TENSOR"] = 4] = "TENSOR"; + AttributeType[AttributeType["GRAPH"] = 5] = "GRAPH"; + AttributeType[AttributeType["FLOATS"] = 6] = "FLOATS"; + AttributeType[AttributeType["INTS"] = 7] = "INTS"; + AttributeType[AttributeType["STRINGS"] = 8] = "STRINGS"; + AttributeType[AttributeType["TENSORS"] = 9] = "TENSORS"; + AttributeType[AttributeType["GRAPHS"] = 10] = "GRAPHS"; + AttributeType[AttributeType["SPARSE_TENSOR"] = 11] = "SPARSE_TENSOR"; + AttributeType[AttributeType["SPARSE_TENSORS"] = 12] = "SPARSE_TENSORS"; + })(AttributeType = fbs.AttributeType || (fbs.AttributeType = {})); + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @enum {number} + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + let DimensionValueType; + (function (DimensionValueType) { + DimensionValueType[DimensionValueType["UNKNOWN"] = 0] = "UNKNOWN"; + DimensionValueType[DimensionValueType["VALUE"] = 1] = "VALUE"; + DimensionValueType[DimensionValueType["PARAM"] = 2] = "PARAM"; + })(DimensionValueType = fbs.DimensionValueType || (fbs.DimensionValueType = {})); + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @enum {number} + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + let TensorDataType; + (function (TensorDataType) { + TensorDataType[TensorDataType["UNDEFINED"] = 0] = "UNDEFINED"; + TensorDataType[TensorDataType["FLOAT"] = 1] = "FLOAT"; + TensorDataType[TensorDataType["UINT8"] = 2] = "UINT8"; + TensorDataType[TensorDataType["INT8"] = 3] = "INT8"; + TensorDataType[TensorDataType["UINT16"] = 4] = "UINT16"; + TensorDataType[TensorDataType["INT16"] = 5] = "INT16"; + TensorDataType[TensorDataType["INT32"] = 6] = "INT32"; + TensorDataType[TensorDataType["INT64"] = 7] = "INT64"; + TensorDataType[TensorDataType["STRING"] = 8] = "STRING"; + TensorDataType[TensorDataType["BOOL"] = 9] = "BOOL"; + TensorDataType[TensorDataType["FLOAT16"] = 10] = "FLOAT16"; + TensorDataType[TensorDataType["DOUBLE"] = 11] = "DOUBLE"; + TensorDataType[TensorDataType["UINT32"] = 12] = "UINT32"; + TensorDataType[TensorDataType["UINT64"] = 13] = "UINT64"; + TensorDataType[TensorDataType["COMPLEX64"] = 14] = "COMPLEX64"; + TensorDataType[TensorDataType["COMPLEX128"] = 15] = "COMPLEX128"; + TensorDataType[TensorDataType["BFLOAT16"] = 16] = "BFLOAT16"; + })(TensorDataType = fbs.TensorDataType || (fbs.TensorDataType = {})); + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @enum {number} + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + let NodeType; + (function (NodeType) { + NodeType[NodeType["Primitive"] = 0] = "Primitive"; + NodeType[NodeType["Fused"] = 1] = "Fused"; + })(NodeType = fbs.NodeType || (fbs.NodeType = {})); + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @enum {number} + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + let TypeInfoValue; + (function (TypeInfoValue) { + TypeInfoValue[TypeInfoValue["NONE"] = 0] = "NONE"; + TypeInfoValue[TypeInfoValue["tensor_type"] = 1] = "tensor_type"; + TypeInfoValue[TypeInfoValue["sequence_type"] = 2] = "sequence_type"; + TypeInfoValue[TypeInfoValue["map_type"] = 3] = "map_type"; + })(TypeInfoValue = fbs.TypeInfoValue || (fbs.TypeInfoValue = {})); + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Shape { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Shape + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Shape= obj + * @returns Shape + */ + static getRootAsShape(bb, obj) { + return (obj || new Shape()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Shape= obj + * @returns Shape + */ + static getSizePrefixedRootAsShape(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Shape()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Dimension= obj + * @returns onnxruntime.experimental.fbs.Dimension + */ + dim(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.Dimension()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + dimLength() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startShape(builder) { + builder.startObject(1); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset dimOffset + */ + static addDim(builder, dimOffset) { + builder.addFieldOffset(0, dimOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createDimVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startDimVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endShape(builder) { + let offset = builder.endObject(); + return offset; + } + static createShape(builder, dimOffset) { + Shape.startShape(builder); + Shape.addDim(builder, dimOffset); + return Shape.endShape(builder); + } + } + fbs.Shape = Shape; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Dimension { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Dimension + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Dimension= obj + * @returns Dimension + */ + static getRootAsDimension(bb, obj) { + return (obj || new Dimension()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Dimension= obj + * @returns Dimension + */ + static getSizePrefixedRootAsDimension(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Dimension()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param onnxruntime.experimental.fbs.DimensionValue= obj + * @returns onnxruntime.experimental.fbs.DimensionValue|null + */ + value(obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.DimensionValue()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + denotation(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param flatbuffers.Builder builder + */ + static startDimension(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset valueOffset + */ + static addValue(builder, valueOffset) { + builder.addFieldOffset(0, valueOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset denotationOffset + */ + static addDenotation(builder, denotationOffset) { + builder.addFieldOffset(1, denotationOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endDimension(builder) { + let offset = builder.endObject(); + return offset; + } + static createDimension(builder, valueOffset, denotationOffset) { + Dimension.startDimension(builder); + Dimension.addValue(builder, valueOffset); + Dimension.addDenotation(builder, denotationOffset); + return Dimension.endDimension(builder); + } + } + fbs.Dimension = Dimension; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class DimensionValue { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns DimensionValue + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param DimensionValue= obj + * @returns DimensionValue + */ + static getRootAsDimensionValue(bb, obj) { + return (obj || new DimensionValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param DimensionValue= obj + * @returns DimensionValue + */ + static getSizePrefixedRootAsDimensionValue(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new DimensionValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @returns onnxruntime.experimental.fbs.DimensionValueType + */ + dimType() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? /** */ (this.bb.readInt8(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.DimensionValueType.UNKNOWN; + } + /** + * @returns flatbuffers.Long + */ + dimValue() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0); + } + dimParam(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param flatbuffers.Builder builder + */ + static startDimensionValue(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.DimensionValueType dimType + */ + static addDimType(builder, dimType) { + builder.addFieldInt8(0, dimType, onnxruntime.experimental.fbs.DimensionValueType.UNKNOWN); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Long dimValue + */ + static addDimValue(builder, dimValue) { + builder.addFieldInt64(1, dimValue, builder.createLong(0, 0)); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset dimParamOffset + */ + static addDimParam(builder, dimParamOffset) { + builder.addFieldOffset(2, dimParamOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endDimensionValue(builder) { + let offset = builder.endObject(); + return offset; + } + static createDimensionValue(builder, dimType, dimValue, dimParamOffset) { + DimensionValue.startDimensionValue(builder); + DimensionValue.addDimType(builder, dimType); + DimensionValue.addDimValue(builder, dimValue); + DimensionValue.addDimParam(builder, dimParamOffset); + return DimensionValue.endDimensionValue(builder); + } + } + fbs.DimensionValue = DimensionValue; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class TensorTypeAndShape { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns TensorTypeAndShape + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param TensorTypeAndShape= obj + * @returns TensorTypeAndShape + */ + static getRootAsTensorTypeAndShape(bb, obj) { + return (obj || new TensorTypeAndShape()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param TensorTypeAndShape= obj + * @returns TensorTypeAndShape + */ + static getSizePrefixedRootAsTensorTypeAndShape(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TensorTypeAndShape()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @returns onnxruntime.experimental.fbs.TensorDataType + */ + elemType() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? /** */ (this.bb.readInt32(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.TensorDataType.UNDEFINED; + } + /** + * @param onnxruntime.experimental.fbs.Shape= obj + * @returns onnxruntime.experimental.fbs.Shape|null + */ + shape(obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.Shape()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startTensorTypeAndShape(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.TensorDataType elemType + */ + static addElemType(builder, elemType) { + builder.addFieldInt32(0, elemType, onnxruntime.experimental.fbs.TensorDataType.UNDEFINED); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset shapeOffset + */ + static addShape(builder, shapeOffset) { + builder.addFieldOffset(1, shapeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endTensorTypeAndShape(builder) { + let offset = builder.endObject(); + return offset; + } + static createTensorTypeAndShape(builder, elemType, shapeOffset) { + TensorTypeAndShape.startTensorTypeAndShape(builder); + TensorTypeAndShape.addElemType(builder, elemType); + TensorTypeAndShape.addShape(builder, shapeOffset); + return TensorTypeAndShape.endTensorTypeAndShape(builder); + } + } + fbs.TensorTypeAndShape = TensorTypeAndShape; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class MapType { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns MapType + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param MapType= obj + * @returns MapType + */ + static getRootAsMapType(bb, obj) { + return (obj || new MapType()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param MapType= obj + * @returns MapType + */ + static getSizePrefixedRootAsMapType(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MapType()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @returns onnxruntime.experimental.fbs.TensorDataType + */ + keyType() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? /** */ (this.bb.readInt32(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.TensorDataType.UNDEFINED; + } + /** + * @param onnxruntime.experimental.fbs.TypeInfo= obj + * @returns onnxruntime.experimental.fbs.TypeInfo|null + */ + valueType(obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.TypeInfo()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startMapType(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.TensorDataType keyType + */ + static addKeyType(builder, keyType) { + builder.addFieldInt32(0, keyType, onnxruntime.experimental.fbs.TensorDataType.UNDEFINED); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset valueTypeOffset + */ + static addValueType(builder, valueTypeOffset) { + builder.addFieldOffset(1, valueTypeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endMapType(builder) { + let offset = builder.endObject(); + return offset; + } + static createMapType(builder, keyType, valueTypeOffset) { + MapType.startMapType(builder); + MapType.addKeyType(builder, keyType); + MapType.addValueType(builder, valueTypeOffset); + return MapType.endMapType(builder); + } + } + fbs.MapType = MapType; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class SequenceType { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns SequenceType + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SequenceType= obj + * @returns SequenceType + */ + static getRootAsSequenceType(bb, obj) { + return (obj || new SequenceType()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SequenceType= obj + * @returns SequenceType + */ + static getSizePrefixedRootAsSequenceType(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SequenceType()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param onnxruntime.experimental.fbs.TypeInfo= obj + * @returns onnxruntime.experimental.fbs.TypeInfo|null + */ + elemType(obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.TypeInfo()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startSequenceType(builder) { + builder.startObject(1); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset elemTypeOffset + */ + static addElemType(builder, elemTypeOffset) { + builder.addFieldOffset(0, elemTypeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endSequenceType(builder) { + let offset = builder.endObject(); + return offset; + } + static createSequenceType(builder, elemTypeOffset) { + SequenceType.startSequenceType(builder); + SequenceType.addElemType(builder, elemTypeOffset); + return SequenceType.endSequenceType(builder); + } + } + fbs.SequenceType = SequenceType; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class EdgeEnd { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns EdgeEnd + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @returns number + */ + nodeIndex() { + return this.bb.readUint32(this.bb_pos); + } + /** + * @returns number + */ + srcArgIndex() { + return this.bb.readInt32(this.bb_pos + 4); + } + /** + * @returns number + */ + dstArgIndex() { + return this.bb.readInt32(this.bb_pos + 8); + } + /** + * @param flatbuffers.Builder builder + * @param number node_index + * @param number src_arg_index + * @param number dst_arg_index + * @returns flatbuffers.Offset + */ + static createEdgeEnd(builder, node_index, src_arg_index, dst_arg_index) { + builder.prep(4, 12); + builder.writeInt32(dst_arg_index); + builder.writeInt32(src_arg_index); + builder.writeInt32(node_index); + return builder.offset(); + } + } + fbs.EdgeEnd = EdgeEnd; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class NodeEdge { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns NodeEdge + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param NodeEdge= obj + * @returns NodeEdge + */ + static getRootAsNodeEdge(bb, obj) { + return (obj || new NodeEdge()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param NodeEdge= obj + * @returns NodeEdge + */ + static getSizePrefixedRootAsNodeEdge(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new NodeEdge()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @returns number + */ + nodeIndex() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.EdgeEnd= obj + * @returns onnxruntime.experimental.fbs.EdgeEnd + */ + inputEdges(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.EdgeEnd()) + .__init(this.bb.__vector(this.bb_pos + offset) + index * 12, this.bb) : + null; + } + /** + * @returns number + */ + inputEdgesLength() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.EdgeEnd= obj + * @returns onnxruntime.experimental.fbs.EdgeEnd + */ + outputEdges(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new onnxruntime.experimental.fbs.EdgeEnd()) + .__init(this.bb.__vector(this.bb_pos + offset) + index * 12, this.bb) : + null; + } + /** + * @returns number + */ + outputEdgesLength() { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startNodeEdge(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param number nodeIndex + */ + static addNodeIndex(builder, nodeIndex) { + builder.addFieldInt32(0, nodeIndex, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset inputEdgesOffset + */ + static addInputEdges(builder, inputEdgesOffset) { + builder.addFieldOffset(1, inputEdgesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startInputEdgesVector(builder, numElems) { + builder.startVector(12, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset outputEdgesOffset + */ + static addOutputEdges(builder, outputEdgesOffset) { + builder.addFieldOffset(2, outputEdgesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startOutputEdgesVector(builder, numElems) { + builder.startVector(12, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endNodeEdge(builder) { + let offset = builder.endObject(); + return offset; + } + static createNodeEdge(builder, nodeIndex, inputEdgesOffset, outputEdgesOffset) { + NodeEdge.startNodeEdge(builder); + NodeEdge.addNodeIndex(builder, nodeIndex); + NodeEdge.addInputEdges(builder, inputEdgesOffset); + NodeEdge.addOutputEdges(builder, outputEdgesOffset); + return NodeEdge.endNodeEdge(builder); + } + } + fbs.NodeEdge = NodeEdge; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Node { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Node + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Node= obj + * @returns Node + */ + static getRootAsNode(bb, obj) { + return (obj || new Node()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Node= obj + * @returns Node + */ + static getSizePrefixedRootAsNode(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Node()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + docString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + domain(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns number + */ + sinceVersion() { + let offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + /** + * @returns number + */ + index() { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + opType(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns onnxruntime.experimental.fbs.NodeType + */ + type() { + let offset = this.bb.__offset(this.bb_pos, 16); + return offset ? /** */ (this.bb.readInt32(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.NodeType.Primitive; + } + executionProviderType(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + inputs(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + inputsLength() { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + outputs(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + outputsLength() { + let offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Attribute= obj + * @returns onnxruntime.experimental.fbs.Attribute + */ + attributes(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 24); + return offset ? (obj || new onnxruntime.experimental.fbs.Attribute()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + attributesLength() { + let offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @returns number + */ + inputArgCounts(index) { + let offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.readInt32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; + } + /** + * @returns number + */ + inputArgCountsLength() { + let offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns Int32Array + */ + inputArgCountsArray() { + let offset = this.bb.__offset(this.bb_pos, 26); + return offset ? + new Int32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : + null; + } + implicitInputs(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 28); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + implicitInputsLength() { + let offset = this.bb.__offset(this.bb_pos, 28); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startNode(builder) { + builder.startObject(13); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nameOffset + */ + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset docStringOffset + */ + static addDocString(builder, docStringOffset) { + builder.addFieldOffset(1, docStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset domainOffset + */ + static addDomain(builder, domainOffset) { + builder.addFieldOffset(2, domainOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param number sinceVersion + */ + static addSinceVersion(builder, sinceVersion) { + builder.addFieldInt32(3, sinceVersion, 0); + } + /** + * @param flatbuffers.Builder builder + * @param number index + */ + static addIndex(builder, index) { + builder.addFieldInt32(4, index, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset opTypeOffset + */ + static addOpType(builder, opTypeOffset) { + builder.addFieldOffset(5, opTypeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.NodeType type + */ + static addType(builder, type) { + builder.addFieldInt32(6, type, onnxruntime.experimental.fbs.NodeType.Primitive); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset executionProviderTypeOffset + */ + static addExecutionProviderType(builder, executionProviderTypeOffset) { + builder.addFieldOffset(7, executionProviderTypeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset inputsOffset + */ + static addInputs(builder, inputsOffset) { + builder.addFieldOffset(8, inputsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createInputsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startInputsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset outputsOffset + */ + static addOutputs(builder, outputsOffset) { + builder.addFieldOffset(9, outputsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createOutputsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startOutputsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset attributesOffset + */ + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(10, attributesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset inputArgCountsOffset + */ + static addInputArgCounts(builder, inputArgCountsOffset) { + builder.addFieldOffset(11, inputArgCountsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createInputArgCountsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startInputArgCountsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset implicitInputsOffset + */ + static addImplicitInputs(builder, implicitInputsOffset) { + builder.addFieldOffset(12, implicitInputsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createImplicitInputsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startImplicitInputsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endNode(builder) { + let offset = builder.endObject(); + return offset; + } + static createNode(builder, nameOffset, docStringOffset, domainOffset, sinceVersion, index, opTypeOffset, type, executionProviderTypeOffset, inputsOffset, outputsOffset, attributesOffset, inputArgCountsOffset, implicitInputsOffset) { + Node.startNode(builder); + Node.addName(builder, nameOffset); + Node.addDocString(builder, docStringOffset); + Node.addDomain(builder, domainOffset); + Node.addSinceVersion(builder, sinceVersion); + Node.addIndex(builder, index); + Node.addOpType(builder, opTypeOffset); + Node.addType(builder, type); + Node.addExecutionProviderType(builder, executionProviderTypeOffset); + Node.addInputs(builder, inputsOffset); + Node.addOutputs(builder, outputsOffset); + Node.addAttributes(builder, attributesOffset); + Node.addInputArgCounts(builder, inputArgCountsOffset); + Node.addImplicitInputs(builder, implicitInputsOffset); + return Node.endNode(builder); + } + } + fbs.Node = Node; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class ValueInfo { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns ValueInfo + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param ValueInfo= obj + * @returns ValueInfo + */ + static getRootAsValueInfo(bb, obj) { + return (obj || new ValueInfo()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param ValueInfo= obj + * @returns ValueInfo + */ + static getSizePrefixedRootAsValueInfo(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ValueInfo()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + docString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param onnxruntime.experimental.fbs.TypeInfo= obj + * @returns onnxruntime.experimental.fbs.TypeInfo|null + */ + type(obj) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new onnxruntime.experimental.fbs.TypeInfo()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startValueInfo(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nameOffset + */ + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset docStringOffset + */ + static addDocString(builder, docStringOffset) { + builder.addFieldOffset(1, docStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset typeOffset + */ + static addType(builder, typeOffset) { + builder.addFieldOffset(2, typeOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endValueInfo(builder) { + let offset = builder.endObject(); + return offset; + } + static createValueInfo(builder, nameOffset, docStringOffset, typeOffset) { + ValueInfo.startValueInfo(builder); + ValueInfo.addName(builder, nameOffset); + ValueInfo.addDocString(builder, docStringOffset); + ValueInfo.addType(builder, typeOffset); + return ValueInfo.endValueInfo(builder); + } + } + fbs.ValueInfo = ValueInfo; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class TypeInfo { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns TypeInfo + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param TypeInfo= obj + * @returns TypeInfo + */ + static getRootAsTypeInfo(bb, obj) { + return (obj || new TypeInfo()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param TypeInfo= obj + * @returns TypeInfo + */ + static getSizePrefixedRootAsTypeInfo(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TypeInfo()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + denotation(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns onnxruntime.experimental.fbs.TypeInfoValue + */ + valueType() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? /** */ (this.bb.readUint8(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.TypeInfoValue.NONE; + } + /** + * @param flatbuffers.Table obj + * @returns ?flatbuffers.Table + */ + value(obj) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; + } + /** + * @param flatbuffers.Builder builder + */ + static startTypeInfo(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset denotationOffset + */ + static addDenotation(builder, denotationOffset) { + builder.addFieldOffset(0, denotationOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.TypeInfoValue valueType + */ + static addValueType(builder, valueType) { + builder.addFieldInt8(1, valueType, onnxruntime.experimental.fbs.TypeInfoValue.NONE); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset valueOffset + */ + static addValue(builder, valueOffset) { + builder.addFieldOffset(2, valueOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endTypeInfo(builder) { + let offset = builder.endObject(); + return offset; + } + static createTypeInfo(builder, denotationOffset, valueType, valueOffset) { + TypeInfo.startTypeInfo(builder); + TypeInfo.addDenotation(builder, denotationOffset); + TypeInfo.addValueType(builder, valueType); + TypeInfo.addValue(builder, valueOffset); + return TypeInfo.endTypeInfo(builder); + } + } + fbs.TypeInfo = TypeInfo; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class OperatorSetId { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns OperatorSetId + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param OperatorSetId= obj + * @returns OperatorSetId + */ + static getRootAsOperatorSetId(bb, obj) { + return (obj || new OperatorSetId()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param OperatorSetId= obj + * @returns OperatorSetId + */ + static getSizePrefixedRootAsOperatorSetId(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new OperatorSetId()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + domain(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns flatbuffers.Long + */ + version() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0); + } + /** + * @param flatbuffers.Builder builder + */ + static startOperatorSetId(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset domainOffset + */ + static addDomain(builder, domainOffset) { + builder.addFieldOffset(0, domainOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Long version + */ + static addVersion(builder, version) { + builder.addFieldInt64(1, version, builder.createLong(0, 0)); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endOperatorSetId(builder) { + let offset = builder.endObject(); + return offset; + } + static createOperatorSetId(builder, domainOffset, version) { + OperatorSetId.startOperatorSetId(builder); + OperatorSetId.addDomain(builder, domainOffset); + OperatorSetId.addVersion(builder, version); + return OperatorSetId.endOperatorSetId(builder); + } + } + fbs.OperatorSetId = OperatorSetId; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Tensor { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Tensor + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Tensor= obj + * @returns Tensor + */ + static getRootAsTensor(bb, obj) { + return (obj || new Tensor()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Tensor= obj + * @returns Tensor + */ + static getSizePrefixedRootAsTensor(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Tensor()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + docString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param number index + * @returns flatbuffers.Long + */ + dims(index) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : + this.bb.createLong(0, 0); + } + /** + * @returns number + */ + dimsLength() { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns onnxruntime.experimental.fbs.TensorDataType + */ + dataType() { + let offset = this.bb.__offset(this.bb_pos, 10); + return offset ? /** */ (this.bb.readInt32(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.TensorDataType.UNDEFINED; + } + /** + * @param number index + * @returns number + */ + rawData(index) { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + } + /** + * @returns number + */ + rawDataLength() { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns Uint8Array + */ + rawDataArray() { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? + new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : + null; + } + stringData(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + stringDataLength() { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startTensor(builder) { + builder.startObject(6); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nameOffset + */ + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset docStringOffset + */ + static addDocString(builder, docStringOffset) { + builder.addFieldOffset(1, docStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset dimsOffset + */ + static addDims(builder, dimsOffset) { + builder.addFieldOffset(2, dimsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createDimsVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startDimsVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.TensorDataType dataType + */ + static addDataType(builder, dataType) { + builder.addFieldInt32(3, dataType, onnxruntime.experimental.fbs.TensorDataType.UNDEFINED); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset rawDataOffset + */ + static addRawData(builder, rawDataOffset) { + builder.addFieldOffset(4, rawDataOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createRawDataVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startRawDataVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset stringDataOffset + */ + static addStringData(builder, stringDataOffset) { + builder.addFieldOffset(5, stringDataOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createStringDataVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startStringDataVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endTensor(builder) { + let offset = builder.endObject(); + return offset; + } + static createTensor(builder, nameOffset, docStringOffset, dimsOffset, dataType, rawDataOffset, stringDataOffset) { + Tensor.startTensor(builder); + Tensor.addName(builder, nameOffset); + Tensor.addDocString(builder, docStringOffset); + Tensor.addDims(builder, dimsOffset); + Tensor.addDataType(builder, dataType); + Tensor.addRawData(builder, rawDataOffset); + Tensor.addStringData(builder, stringDataOffset); + return Tensor.endTensor(builder); + } + } + fbs.Tensor = Tensor; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class SparseTensor { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns SparseTensor + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SparseTensor= obj + * @returns SparseTensor + */ + static getRootAsSparseTensor(bb, obj) { + return (obj || new SparseTensor()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SparseTensor= obj + * @returns SparseTensor + */ + static getSizePrefixedRootAsSparseTensor(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SparseTensor()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param onnxruntime.experimental.fbs.Tensor= obj + * @returns onnxruntime.experimental.fbs.Tensor|null + */ + values(obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.Tensor()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param onnxruntime.experimental.fbs.Tensor= obj + * @returns onnxruntime.experimental.fbs.Tensor|null + */ + indices(obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.Tensor()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param number index + * @returns flatbuffers.Long + */ + dims(index) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : + this.bb.createLong(0, 0); + } + /** + * @returns number + */ + dimsLength() { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startSparseTensor(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset valuesOffset + */ + static addValues(builder, valuesOffset) { + builder.addFieldOffset(0, valuesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset indicesOffset + */ + static addIndices(builder, indicesOffset) { + builder.addFieldOffset(1, indicesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset dimsOffset + */ + static addDims(builder, dimsOffset) { + builder.addFieldOffset(2, dimsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createDimsVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startDimsVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endSparseTensor(builder) { + let offset = builder.endObject(); + return offset; + } + static createSparseTensor(builder, valuesOffset, indicesOffset, dimsOffset) { + SparseTensor.startSparseTensor(builder); + SparseTensor.addValues(builder, valuesOffset); + SparseTensor.addIndices(builder, indicesOffset); + SparseTensor.addDims(builder, dimsOffset); + return SparseTensor.endSparseTensor(builder); + } + } + fbs.SparseTensor = SparseTensor; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Attribute { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Attribute + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Attribute= obj + * @returns Attribute + */ + static getRootAsAttribute(bb, obj) { + return (obj || new Attribute()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Attribute= obj + * @returns Attribute + */ + static getSizePrefixedRootAsAttribute(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Attribute()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + docString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns onnxruntime.experimental.fbs.AttributeType + */ + type() { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? /** */ (this.bb.readInt32(this.bb_pos + offset)) : + onnxruntime.experimental.fbs.AttributeType.UNDEFINED; + } + /** + * @returns number + */ + f() { + let offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; + } + /** + * @returns flatbuffers.Long + */ + i() { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0); + } + s(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param onnxruntime.experimental.fbs.Tensor= obj + * @returns onnxruntime.experimental.fbs.Tensor|null + */ + t(obj) { + let offset = this.bb.__offset(this.bb_pos, 16); + return offset ? (obj || new onnxruntime.experimental.fbs.Tensor()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param onnxruntime.experimental.fbs.Graph= obj + * @returns onnxruntime.experimental.fbs.Graph|null + */ + g(obj) { + let offset = this.bb.__offset(this.bb_pos, 18); + return offset ? (obj || new onnxruntime.experimental.fbs.Graph()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param number index + * @returns number + */ + floats(index) { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; + } + /** + * @returns number + */ + floatsLength() { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns Float32Array + */ + floatsArray() { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? + new Float32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : + null; + } + /** + * @param number index + * @returns flatbuffers.Long + */ + ints(index) { + let offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : + this.bb.createLong(0, 0); + } + /** + * @returns number + */ + intsLength() { + let offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + strings(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + stringsLength() { + let offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Tensor= obj + * @returns onnxruntime.experimental.fbs.Tensor + */ + tensors(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 26); + return offset ? (obj || new onnxruntime.experimental.fbs.Tensor()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + tensorsLength() { + let offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Graph= obj + * @returns onnxruntime.experimental.fbs.Graph + */ + graphs(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 28); + return offset ? (obj || new onnxruntime.experimental.fbs.Graph()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + graphsLength() { + let offset = this.bb.__offset(this.bb_pos, 28); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startAttribute(builder) { + builder.startObject(13); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nameOffset + */ + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset docStringOffset + */ + static addDocString(builder, docStringOffset) { + builder.addFieldOffset(1, docStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param onnxruntime.experimental.fbs.AttributeType type + */ + static addType(builder, type) { + builder.addFieldInt32(2, type, onnxruntime.experimental.fbs.AttributeType.UNDEFINED); + } + /** + * @param flatbuffers.Builder builder + * @param number f + */ + static addF(builder, f) { + builder.addFieldFloat32(3, f, 0.0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Long i + */ + static addI(builder, i) { + builder.addFieldInt64(4, i, builder.createLong(0, 0)); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset sOffset + */ + static addS(builder, sOffset) { + builder.addFieldOffset(5, sOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset tOffset + */ + static addT(builder, tOffset) { + builder.addFieldOffset(6, tOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset gOffset + */ + static addG(builder, gOffset) { + builder.addFieldOffset(7, gOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset floatsOffset + */ + static addFloats(builder, floatsOffset) { + builder.addFieldOffset(8, floatsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createFloatsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat32(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startFloatsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset intsOffset + */ + static addInts(builder, intsOffset) { + builder.addFieldOffset(9, intsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createIntsVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startIntsVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset stringsOffset + */ + static addStrings(builder, stringsOffset) { + builder.addFieldOffset(10, stringsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createStringsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startStringsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset tensorsOffset + */ + static addTensors(builder, tensorsOffset) { + builder.addFieldOffset(11, tensorsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createTensorsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startTensorsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset graphsOffset + */ + static addGraphs(builder, graphsOffset) { + builder.addFieldOffset(12, graphsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createGraphsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startGraphsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endAttribute(builder) { + let offset = builder.endObject(); + return offset; + } + static createAttribute(builder, nameOffset, docStringOffset, type, f, i, sOffset, tOffset, gOffset, floatsOffset, intsOffset, stringsOffset, tensorsOffset, graphsOffset) { + Attribute.startAttribute(builder); + Attribute.addName(builder, nameOffset); + Attribute.addDocString(builder, docStringOffset); + Attribute.addType(builder, type); + Attribute.addF(builder, f); + Attribute.addI(builder, i); + Attribute.addS(builder, sOffset); + Attribute.addT(builder, tOffset); + Attribute.addG(builder, gOffset); + Attribute.addFloats(builder, floatsOffset); + Attribute.addInts(builder, intsOffset); + Attribute.addStrings(builder, stringsOffset); + Attribute.addTensors(builder, tensorsOffset); + Attribute.addGraphs(builder, graphsOffset); + return Attribute.endAttribute(builder); + } + } + fbs.Attribute = Attribute; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Graph { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Graph + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Graph= obj + * @returns Graph + */ + static getRootAsGraph(bb, obj) { + return (obj || new Graph()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Graph= obj + * @returns Graph + */ + static getSizePrefixedRootAsGraph(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Graph()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Tensor= obj + * @returns onnxruntime.experimental.fbs.Tensor + */ + initializers(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.Tensor()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + initializersLength() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.ValueInfo= obj + * @returns onnxruntime.experimental.fbs.ValueInfo + */ + nodeArgs(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.ValueInfo()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + nodeArgsLength() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.Node= obj + * @returns onnxruntime.experimental.fbs.Node + */ + nodes(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new onnxruntime.experimental.fbs.Node()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + nodesLength() { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns number + */ + maxNodeIndex() { + let offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.NodeEdge= obj + * @returns onnxruntime.experimental.fbs.NodeEdge + */ + nodeEdges(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? (obj || new onnxruntime.experimental.fbs.NodeEdge()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + nodeEdgesLength() { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + inputs(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + inputsLength() { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + outputs(index, optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + /** + * @returns number + */ + outputsLength() { + let offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.SparseTensor= obj + * @returns onnxruntime.experimental.fbs.SparseTensor + */ + sparseInitializers(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 18); + return offset ? (obj || new onnxruntime.experimental.fbs.SparseTensor()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + sparseInitializersLength() { + let offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startGraph(builder) { + builder.startObject(8); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset initializersOffset + */ + static addInitializers(builder, initializersOffset) { + builder.addFieldOffset(0, initializersOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createInitializersVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startInitializersVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nodeArgsOffset + */ + static addNodeArgs(builder, nodeArgsOffset) { + builder.addFieldOffset(1, nodeArgsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createNodeArgsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startNodeArgsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nodesOffset + */ + static addNodes(builder, nodesOffset) { + builder.addFieldOffset(2, nodesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createNodesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startNodesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param number maxNodeIndex + */ + static addMaxNodeIndex(builder, maxNodeIndex) { + builder.addFieldInt32(3, maxNodeIndex, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nodeEdgesOffset + */ + static addNodeEdges(builder, nodeEdgesOffset) { + builder.addFieldOffset(4, nodeEdgesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createNodeEdgesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startNodeEdgesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset inputsOffset + */ + static addInputs(builder, inputsOffset) { + builder.addFieldOffset(5, inputsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createInputsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startInputsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset outputsOffset + */ + static addOutputs(builder, outputsOffset) { + builder.addFieldOffset(6, outputsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createOutputsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startOutputsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset sparseInitializersOffset + */ + static addSparseInitializers(builder, sparseInitializersOffset) { + builder.addFieldOffset(7, sparseInitializersOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createSparseInitializersVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startSparseInitializersVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endGraph(builder) { + let offset = builder.endObject(); + return offset; + } + static createGraph(builder, initializersOffset, nodeArgsOffset, nodesOffset, maxNodeIndex, nodeEdgesOffset, inputsOffset, outputsOffset, sparseInitializersOffset) { + Graph.startGraph(builder); + Graph.addInitializers(builder, initializersOffset); + Graph.addNodeArgs(builder, nodeArgsOffset); + Graph.addNodes(builder, nodesOffset); + Graph.addMaxNodeIndex(builder, maxNodeIndex); + Graph.addNodeEdges(builder, nodeEdgesOffset); + Graph.addInputs(builder, inputsOffset); + Graph.addOutputs(builder, outputsOffset); + Graph.addSparseInitializers(builder, sparseInitializersOffset); + return Graph.endGraph(builder); + } + } + fbs.Graph = Graph; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class Model { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Model + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Model= obj + * @returns Model + */ + static getRootAsModel(bb, obj) { + return (obj || new Model()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param Model= obj + * @returns Model + */ + static getSizePrefixedRootAsModel(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Model()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @returns flatbuffers.Long + */ + irVersion() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0); + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.OperatorSetId= obj + * @returns onnxruntime.experimental.fbs.OperatorSetId + */ + opsetImport(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.OperatorSetId()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + opsetImportLength() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + producerName(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + producerVersion(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + domain(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @returns flatbuffers.Long + */ + modelVersion() { + let offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0); + } + docString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param onnxruntime.experimental.fbs.Graph= obj + * @returns onnxruntime.experimental.fbs.Graph|null + */ + graph(obj) { + let offset = this.bb.__offset(this.bb_pos, 18); + return offset ? (obj || new onnxruntime.experimental.fbs.Graph()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + graphDocString(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param flatbuffers.Builder builder + */ + static startModel(builder) { + builder.startObject(9); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Long irVersion + */ + static addIrVersion(builder, irVersion) { + builder.addFieldInt64(0, irVersion, builder.createLong(0, 0)); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset opsetImportOffset + */ + static addOpsetImport(builder, opsetImportOffset) { + builder.addFieldOffset(1, opsetImportOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createOpsetImportVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startOpsetImportVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset producerNameOffset + */ + static addProducerName(builder, producerNameOffset) { + builder.addFieldOffset(2, producerNameOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset producerVersionOffset + */ + static addProducerVersion(builder, producerVersionOffset) { + builder.addFieldOffset(3, producerVersionOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset domainOffset + */ + static addDomain(builder, domainOffset) { + builder.addFieldOffset(4, domainOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Long modelVersion + */ + static addModelVersion(builder, modelVersion) { + builder.addFieldInt64(5, modelVersion, builder.createLong(0, 0)); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset docStringOffset + */ + static addDocString(builder, docStringOffset) { + builder.addFieldOffset(6, docStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset graphOffset + */ + static addGraph(builder, graphOffset) { + builder.addFieldOffset(7, graphOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset graphDocStringOffset + */ + static addGraphDocString(builder, graphDocStringOffset) { + builder.addFieldOffset(8, graphDocStringOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endModel(builder) { + let offset = builder.endObject(); + return offset; + } + static createModel(builder, irVersion, opsetImportOffset, producerNameOffset, producerVersionOffset, domainOffset, modelVersion, docStringOffset, graphOffset, graphDocStringOffset) { + Model.startModel(builder); + Model.addIrVersion(builder, irVersion); + Model.addOpsetImport(builder, opsetImportOffset); + Model.addProducerName(builder, producerNameOffset); + Model.addProducerVersion(builder, producerVersionOffset); + Model.addDomain(builder, domainOffset); + Model.addModelVersion(builder, modelVersion); + Model.addDocString(builder, docStringOffset); + Model.addGraph(builder, graphOffset); + Model.addGraphDocString(builder, graphDocStringOffset); + return Model.endModel(builder); + } + } + fbs.Model = Model; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class KernelCreateInfos { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns KernelCreateInfos + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param KernelCreateInfos= obj + * @returns KernelCreateInfos + */ + static getRootAsKernelCreateInfos(bb, obj) { + return (obj || new KernelCreateInfos()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param KernelCreateInfos= obj + * @returns KernelCreateInfos + */ + static getSizePrefixedRootAsKernelCreateInfos(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new KernelCreateInfos()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param number index + * @returns number + */ + nodeIndices(index) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; + } + /** + * @returns number + */ + nodeIndicesLength() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @returns Uint32Array + */ + nodeIndicesArray() { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? + new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : + null; + } + /** + * @param number index + * @returns flatbuffers.Long + */ + kernelDefHashes(index) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : + this.bb.createLong(0, 0); + } + /** + * @returns number + */ + kernelDefHashesLength() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startKernelCreateInfos(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset nodeIndicesOffset + */ + static addNodeIndices(builder, nodeIndicesOffset) { + builder.addFieldOffset(0, nodeIndicesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createNodeIndicesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startNodeIndicesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset kernelDefHashesOffset + */ + static addKernelDefHashes(builder, kernelDefHashesOffset) { + builder.addFieldOffset(1, kernelDefHashesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createKernelDefHashesVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startKernelDefHashesVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endKernelCreateInfos(builder) { + let offset = builder.endObject(); + return offset; + } + static createKernelCreateInfos(builder, nodeIndicesOffset, kernelDefHashesOffset) { + KernelCreateInfos.startKernelCreateInfos(builder); + KernelCreateInfos.addNodeIndices(builder, nodeIndicesOffset); + KernelCreateInfos.addKernelDefHashes(builder, kernelDefHashesOffset); + return KernelCreateInfos.endKernelCreateInfos(builder); + } + } + fbs.KernelCreateInfos = KernelCreateInfos; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class SubGraphSessionState { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns SubGraphSessionState + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SubGraphSessionState= obj + * @returns SubGraphSessionState + */ + static getRootAsSubGraphSessionState(bb, obj) { + return (obj || new SubGraphSessionState()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SubGraphSessionState= obj + * @returns SubGraphSessionState + */ + static getSizePrefixedRootAsSubGraphSessionState(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SubGraphSessionState()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + graphId(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param onnxruntime.experimental.fbs.SessionState= obj + * @returns onnxruntime.experimental.fbs.SessionState|null + */ + sessionState(obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.SessionState()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startSubGraphSessionState(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset graphIdOffset + */ + static addGraphId(builder, graphIdOffset) { + builder.addFieldOffset(0, graphIdOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset sessionStateOffset + */ + static addSessionState(builder, sessionStateOffset) { + builder.addFieldOffset(1, sessionStateOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endSubGraphSessionState(builder) { + let offset = builder.endObject(); + builder.requiredField(offset, 4); // graph_id + return offset; + } + static createSubGraphSessionState(builder, graphIdOffset, sessionStateOffset) { + SubGraphSessionState.startSubGraphSessionState(builder); + SubGraphSessionState.addGraphId(builder, graphIdOffset); + SubGraphSessionState.addSessionState(builder, sessionStateOffset); + return SubGraphSessionState.endSubGraphSessionState(builder); + } + } + fbs.SubGraphSessionState = SubGraphSessionState; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class SessionState { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns SessionState + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SessionState= obj + * @returns SessionState + */ + static getRootAsSessionState(bb, obj) { + return (obj || new SessionState()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param SessionState= obj + * @returns SessionState + */ + static getSizePrefixedRootAsSessionState(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SessionState()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param onnxruntime.experimental.fbs.KernelCreateInfos= obj + * @returns onnxruntime.experimental.fbs.KernelCreateInfos|null + */ + kernels(obj) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new onnxruntime.experimental.fbs.KernelCreateInfos()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param number index + * @param onnxruntime.experimental.fbs.SubGraphSessionState= obj + * @returns onnxruntime.experimental.fbs.SubGraphSessionState + */ + subGraphSessionStates(index, obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.SubGraphSessionState()) + .__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : + null; + } + /** + * @returns number + */ + subGraphSessionStatesLength() { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + /** + * @param flatbuffers.Builder builder + */ + static startSessionState(builder) { + builder.startObject(2); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset kernelsOffset + */ + static addKernels(builder, kernelsOffset) { + builder.addFieldOffset(0, kernelsOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset subGraphSessionStatesOffset + */ + static addSubGraphSessionStates(builder, subGraphSessionStatesOffset) { + builder.addFieldOffset(1, subGraphSessionStatesOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param Array. data + * @returns flatbuffers.Offset + */ + static createSubGraphSessionStatesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + /** + * @param flatbuffers.Builder builder + * @param number numElems + */ + static startSubGraphSessionStatesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endSessionState(builder) { + let offset = builder.endObject(); + return offset; + } + static createSessionState(builder, kernelsOffset, subGraphSessionStatesOffset) { + SessionState.startSessionState(builder); + SessionState.addKernels(builder, kernelsOffset); + SessionState.addSubGraphSessionStates(builder, subGraphSessionStatesOffset); + return SessionState.endSessionState(builder); + } + } + fbs.SessionState = SessionState; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); +/** + * @constructor + */ +(function (onnxruntime) { + var experimental; + (function (experimental) { + var fbs; + (function (fbs) { + class InferenceSession { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + /** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns InferenceSession + */ + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + /** + * @param flatbuffers.ByteBuffer bb + * @param InferenceSession= obj + * @returns InferenceSession + */ + static getRootAsInferenceSession(bb, obj) { + return (obj || new InferenceSession()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @param InferenceSession= obj + * @returns InferenceSession + */ + static getSizePrefixedRootAsInferenceSession(bb, obj) { + bb.setPosition(bb.position() + flatbuffers_1.flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new InferenceSession()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + /** + * @param flatbuffers.ByteBuffer bb + * @returns boolean + */ + static bufferHasIdentifier(bb) { + return bb.__has_identifier('ORTM'); + } + ortVersion(optionalEncoding) { + let offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + /** + * @param onnxruntime.experimental.fbs.Model= obj + * @returns onnxruntime.experimental.fbs.Model|null + */ + model(obj) { + let offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new onnxruntime.experimental.fbs.Model()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param onnxruntime.experimental.fbs.SessionState= obj + * @returns onnxruntime.experimental.fbs.SessionState|null + */ + sessionState(obj) { + let offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new onnxruntime.experimental.fbs.SessionState()) + .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : + null; + } + /** + * @param flatbuffers.Builder builder + */ + static startInferenceSession(builder) { + builder.startObject(3); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset ortVersionOffset + */ + static addOrtVersion(builder, ortVersionOffset) { + builder.addFieldOffset(0, ortVersionOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset modelOffset + */ + static addModel(builder, modelOffset) { + builder.addFieldOffset(1, modelOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset sessionStateOffset + */ + static addSessionState(builder, sessionStateOffset) { + builder.addFieldOffset(2, sessionStateOffset, 0); + } + /** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ + static endInferenceSession(builder) { + let offset = builder.endObject(); + return offset; + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset offset + */ + static finishInferenceSessionBuffer(builder, offset) { + builder.finish(offset, 'ORTM'); + } + /** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset offset + */ + static finishSizePrefixedInferenceSessionBuffer(builder, offset) { + builder.finish(offset, 'ORTM', true); + } + static createInferenceSession(builder, ortVersionOffset, modelOffset, sessionStateOffset) { + InferenceSession.startInferenceSession(builder); + InferenceSession.addOrtVersion(builder, ortVersionOffset); + InferenceSession.addModel(builder, modelOffset); + InferenceSession.addSessionState(builder, sessionStateOffset); + return InferenceSession.endInferenceSession(builder); + } + } + fbs.InferenceSession = InferenceSession; + })(fbs = experimental.fbs || (experimental.fbs = {})); + })(experimental = onnxruntime.experimental || (onnxruntime.experimental = {})); +})(onnxruntime = exports.onnxruntime || (exports.onnxruntime = {})); + + +/***/ }), + +/***/ "./lib/onnxjs/session-handler.ts": +/*!***************************************!*\ + !*** ./lib/onnxjs/session-handler.ts ***! + \***************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.OnnxjsSessionHandler = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const tensor_1 = __webpack_require__(/*! ./tensor */ "./lib/onnxjs/tensor.ts"); +class OnnxjsSessionHandler { + constructor(session) { + this.session = session; + this.inputNames = this.session.inputNames; + this.outputNames = this.session.outputNames; + } + async dispose() { } + async run(feeds, _fetches, _options) { + const inputMap = new Map(); + for (const name in feeds) { + if (Object.hasOwnProperty.call(feeds, name)) { + const feed = feeds[name]; + inputMap.set(name, new tensor_1.Tensor(feed.dims, feed.type, undefined, undefined, feed.data)); + } + } + const outputMap = await this.session.run(inputMap); + const output = {}; + outputMap.forEach((tensor, name) => { + output[name] = new onnxruntime_common_1.Tensor(tensor.type, tensor.data, tensor.dims); + }); + return output; + } + startProfiling() { + this.session.startProfiling(); + } + endProfiling() { + this.session.endProfiling(); + } +} +exports.OnnxjsSessionHandler = OnnxjsSessionHandler; + + +/***/ }), + +/***/ "./lib/onnxjs/session.ts": +/*!*******************************!*\ + !*** ./lib/onnxjs/session.ts ***! + \*******************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Session = void 0; +const fs_1 = __webpack_require__(/*! fs */ "?6c45"); +const util_1 = __webpack_require__(/*! util */ "?b3a2"); +const backend_1 = __webpack_require__(/*! ./backend */ "./lib/onnxjs/backend.ts"); +const execution_plan_1 = __webpack_require__(/*! ./execution-plan */ "./lib/onnxjs/execution-plan.ts"); +const instrument_1 = __webpack_require__(/*! ./instrument */ "./lib/onnxjs/instrument.ts"); +const model_1 = __webpack_require__(/*! ./model */ "./lib/onnxjs/model.ts"); +class Session { + constructor(config = {}) { + this._initialized = false; + this.backendHint = config.backendHint; + this.profiler = instrument_1.Profiler.create(config.profiler); + this.context = { profiler: this.profiler, graphInputTypes: [], graphInputDims: [] }; + } + get inputNames() { + return this._model.graph.getInputNames(); + } + get outputNames() { + return this._model.graph.getOutputNames(); + } + startProfiling() { + this.profiler.start(); + } + endProfiling() { + this.profiler.stop(); + } + async loadModel(arg, byteOffset, length) { + await this.profiler.event('session', 'Session.loadModel', async () => { + // resolve backend and session handler + const backend = await (0, backend_1.resolveBackend)(this.backendHint); + this.sessionHandler = backend.createSessionHandler(this.context); + this._model = new model_1.Model(); + if (typeof arg === 'string') { + const isOrtFormat = arg.endsWith('.ort'); + if (typeof fetch === 'undefined') { + // node + const buf = await (0, util_1.promisify)(fs_1.readFile)(arg); + this.initialize(buf, isOrtFormat); + } + else { + // browser + const response = await fetch(arg); + const buf = await response.arrayBuffer(); + this.initialize(new Uint8Array(buf), isOrtFormat); + } + } + else if (!ArrayBuffer.isView(arg)) { + // load model from ArrayBuffer + const arr = new Uint8Array(arg, byteOffset || 0, length || arg.byteLength); + this.initialize(arr); + } + else { + // load model from Uint8array + this.initialize(arg); + } + }); + } + initialize(modelProtoBlob, isOrtFormat) { + if (this._initialized) { + throw new Error('already initialized'); + } + this.profiler.event('session', 'Session.initialize', () => { + // load graph + const graphInitializer = this.sessionHandler.transformGraph ? this.sessionHandler : undefined; + this._model.load(modelProtoBlob, graphInitializer, isOrtFormat); + // graph is completely initialzied at this stage , let the interested handlers know + if (this.sessionHandler.onGraphInitialized) { + this.sessionHandler.onGraphInitialized(this._model.graph); + } + // initialize each operator in the graph + this.initializeOps(this._model.graph); + // instantiate an ExecutionPlan object to be used by the Session object + this._executionPlan = new execution_plan_1.ExecutionPlan(this._model.graph, this._ops, this.profiler); + }); + this._initialized = true; + } + async run(inputs) { + if (!this._initialized) { + throw new Error('session not initialized yet'); + } + return this.profiler.event('session', 'Session.run', async () => { + const inputTensors = this.normalizeAndValidateInputs(inputs); + const outputTensors = await this._executionPlan.execute(this.sessionHandler, inputTensors); + return this.createOutput(outputTensors); + }); + } + normalizeAndValidateInputs(inputs) { + const modelInputNames = this._model.graph.getInputNames(); + // normalize inputs + // inputs: Tensor[] + if (Array.isArray(inputs)) { + if (inputs.length !== modelInputNames.length) { + throw new Error(`incorrect input array length: expected ${modelInputNames.length} but got ${inputs.length}`); + } + } + // convert map to array + // inputs: Map + else { + if (inputs.size !== modelInputNames.length) { + throw new Error(`incorrect input map size: expected ${modelInputNames.length} but got ${inputs.size}`); + } + const sortedInputs = new Array(inputs.size); + let sortedInputsIndex = 0; + for (let i = 0; i < modelInputNames.length; ++i) { + const tensor = inputs.get(modelInputNames[i]); + if (!tensor) { + throw new Error(`missing input tensor for: '${name}'`); + } + sortedInputs[sortedInputsIndex++] = tensor; + } + inputs = sortedInputs; + } + // validate dims requirements + // First session run - graph input data is not cached for the session + if (!this.context.graphInputTypes || this.context.graphInputTypes.length === 0 || !this.context.graphInputDims || + this.context.graphInputDims.length === 0) { + const modelInputIndices = this._model.graph.getInputIndices(); + const modelValues = this._model.graph.getValues(); + const graphInputDims = new Array(modelInputIndices.length); + for (let i = 0; i < modelInputIndices.length; ++i) { + const graphInput = modelValues[modelInputIndices[i]]; + graphInputDims[i] = graphInput.type.shape.dims; + // cached for second and subsequent runs. + // Some parts of the framework works on the assumption that the graph and types and shapes are static + this.context.graphInputTypes.push(graphInput.type.tensorType); + this.context.graphInputDims.push(inputs[i].dims); + } + this.validateInputTensorDims(graphInputDims, inputs, true); + } + // Second and subsequent session runs - graph input data is cached for the session + else { + this.validateInputTensorDims(this.context.graphInputDims, inputs, false); + } + // validate types requirement + this.validateInputTensorTypes(this.context.graphInputTypes, inputs); + return inputs; + } + validateInputTensorTypes(graphInputTypes, givenInputs) { + for (let i = 0; i < givenInputs.length; i++) { + const expectedType = graphInputTypes[i]; + const actualType = givenInputs[i].type; + if (expectedType !== actualType) { + throw new Error(`input tensor[${i}] check failed: expected type '${expectedType}' but got ${actualType}`); + } + } + } + validateInputTensorDims(graphInputDims, givenInputs, noneDimSupported) { + for (let i = 0; i < givenInputs.length; i++) { + const expectedDims = graphInputDims[i]; + const actualDims = givenInputs[i].dims; + if (!this.compareTensorDims(expectedDims, actualDims, noneDimSupported)) { + throw new Error(`input tensor[${i}] check failed: expected shape '[${expectedDims.join(',')}]' but got [${actualDims.join(',')}]`); + } + } + } + compareTensorDims(expectedDims, actualDims, noneDimSupported) { + if (expectedDims.length !== actualDims.length) { + return false; + } + for (let i = 0; i < expectedDims.length; ++i) { + if (expectedDims[i] !== actualDims[i] && (!noneDimSupported || expectedDims[i] !== 0)) { + // data shape mis-match AND not a 'None' dimension. + return false; + } + } + return true; + } + createOutput(outputTensors) { + const modelOutputNames = this._model.graph.getOutputNames(); + if (outputTensors.length !== modelOutputNames.length) { + throw new Error('expected number of outputs do not match number of generated outputs'); + } + const output = new Map(); + for (let i = 0; i < modelOutputNames.length; ++i) { + output.set(modelOutputNames[i], outputTensors[i]); + } + return output; + } + initializeOps(graph) { + const nodes = graph.getNodes(); + this._ops = new Array(nodes.length); + for (let i = 0; i < nodes.length; i++) { + this._ops[i] = this.sessionHandler.resolve(nodes[i], this._model.opsets, graph); + } + } +} +exports.Session = Session; + + +/***/ }), + +/***/ "./lib/onnxjs/tensor.ts": +/*!******************************!*\ + !*** ./lib/onnxjs/tensor.ts ***! + \******************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Tensor = void 0; +const guid_typescript_1 = __webpack_require__(/*! guid-typescript */ "./node_modules/guid-typescript/dist/guid.js"); +const long_1 = __importDefault(__webpack_require__(/*! long */ "./node_modules/long/src/long.js")); +const onnx_proto_1 = __webpack_require__(/*! onnx-proto */ "./node_modules/onnx-proto/dist/onnx.js"); +const ort_generated_1 = __webpack_require__(/*! ./ort-schema/ort-generated */ "./lib/onnxjs/ort-schema/ort-generated.ts"); +const util_1 = __webpack_require__(/*! ./util */ "./lib/onnxjs/util.ts"); +var ortFbs = ort_generated_1.onnxruntime.experimental.fbs; +class Tensor { + /** + * get the underlying tensor data + */ + get data() { + if (this.cache === undefined) { + const data = this.dataProvider(this.dataId); + if (data.length !== this.size) { + throw new Error('Length of data provided by the Data Provider is inconsistent with the dims of this Tensor.'); + } + this.cache = data; + } + return this.cache; + } + /** + * get the underlying string tensor data. Should only use when type is STRING + */ + get stringData() { + if (this.type !== 'string') { + throw new TypeError('data type is not string'); + } + return this.data; + } + /** + * get the underlying integer tensor data. Should only use when type is one of the following: (UINT8, INT8, UINT16, + * INT16, INT32, UINT32, BOOL) + */ + get integerData() { + switch (this.type) { + case 'uint8': + case 'int8': + case 'uint16': + case 'int16': + case 'int32': + case 'uint32': + case 'bool': + return this.data; + default: + throw new TypeError('data type is not integer (uint8, int8, uint16, int16, int32, uint32, bool)'); + } + } + /** + * get the underlying float tensor data. Should only use when type is one of the following: (FLOAT, DOUBLE) + */ + get floatData() { + switch (this.type) { + case 'float32': + case 'float64': + return this.data; + default: + throw new TypeError('data type is not float (float32, float64)'); + } + } + /** + * get the underlying number tensor data. Should only use when type is one of the following: (UINT8, INT8, UINT16, + * INT16, INT32, UINT32, BOOL, FLOAT, DOUBLE) + */ + get numberData() { + if (this.type !== 'string') { + return this.data; + } + throw new TypeError('type cannot be non-number (string)'); + } + /** + * get value of an element at the given indices + */ + get(indices) { + return this.data[util_1.ShapeUtil.indicesToOffset(indices, this.strides)]; + } + /** + * set value of an element at the given indices + */ + set(indices, value) { + this.data[util_1.ShapeUtil.indicesToOffset(indices, this.strides)] = value; + } + /** + * get the underlying tensor data asynchronously + */ + async getData() { + if (this.cache === undefined) { + this.cache = await this.asyncDataProvider(this.dataId); + } + return this.cache; + } + /** + * get the strides for each dimension + */ + get strides() { + if (!this._strides) { + this._strides = util_1.ShapeUtil.computeStrides(this.dims); + } + return this._strides; + } + constructor( + /** + * get the dimensions of the tensor + */ + dims, + /** + * get the type of the tensor + */ + type, dataProvider, asyncDataProvider, cache, + /** + * get the data ID that used to map to a tensor data + */ + dataId = guid_typescript_1.Guid.create()) { + this.dims = dims; + this.type = type; + this.dataProvider = dataProvider; + this.asyncDataProvider = asyncDataProvider; + this.cache = cache; + this.dataId = dataId; + this.size = util_1.ShapeUtil.validateDimsAndCalcSize(dims); + const size = this.size; + const empty = (dataProvider === undefined && asyncDataProvider === undefined && cache === undefined); + if (cache !== undefined) { + if (cache.length !== size) { + throw new RangeError('Input dims doesn\'t match data length.'); + } + } + if (type === 'string') { + if (cache !== undefined && (!Array.isArray(cache) || !cache.every(i => typeof i === 'string'))) { + throw new TypeError('cache should be a string array'); + } + if (empty) { + this.cache = new Array(size); + } + } + else { + if (cache !== undefined) { + const constructor = dataviewConstructor(type); + if (!(cache instanceof constructor)) { + throw new TypeError(`cache should be type ${constructor.name}`); + } + } + if (empty) { + const buf = new ArrayBuffer(size * sizeof(type)); + this.cache = createView(buf, type); + } + } + } + /** + * Construct new Tensor from a ONNX Tensor object + * @param tensorProto the ONNX Tensor + */ + static fromProto(tensorProto) { + if (!tensorProto) { + throw new Error('cannot construct Value from an empty tensor'); + } + const type = util_1.ProtoUtil.tensorDataTypeFromProto(tensorProto.dataType); + const dims = util_1.ProtoUtil.tensorDimsFromProto(tensorProto.dims); + const value = new Tensor(dims, type); + if (type === 'string') { + // When it's STRING type, the value should always be stored in field + // 'stringData' + tensorProto.stringData.forEach((str, i) => { + value.data[i] = (0, util_1.decodeUtf8String)(str); + }); + } + else if (tensorProto.rawData && typeof tensorProto.rawData.byteLength === 'number' && + tensorProto.rawData.byteLength > 0) { + // NOT considering segment for now (IMPORTANT) + // populate value from rawData + const dataDest = value.data; + const dataSource = new DataView(tensorProto.rawData.buffer, tensorProto.rawData.byteOffset, tensorProto.rawData.byteLength); + const elementSize = sizeofProto(tensorProto.dataType); + const length = tensorProto.rawData.byteLength / elementSize; + if (tensorProto.rawData.byteLength % elementSize !== 0) { + throw new Error('invalid buffer length'); + } + if (dataDest.length !== length) { + throw new Error('buffer length mismatch'); + } + for (let i = 0; i < length; i++) { + const n = readProto(dataSource, tensorProto.dataType, i * elementSize); + dataDest[i] = n; + } + } + else { + // populate value from array + let array; + switch (tensorProto.dataType) { + case onnx_proto_1.onnx.TensorProto.DataType.FLOAT: + array = tensorProto.floatData; + break; + case onnx_proto_1.onnx.TensorProto.DataType.INT32: + case onnx_proto_1.onnx.TensorProto.DataType.INT16: + case onnx_proto_1.onnx.TensorProto.DataType.UINT16: + case onnx_proto_1.onnx.TensorProto.DataType.INT8: + case onnx_proto_1.onnx.TensorProto.DataType.UINT8: + case onnx_proto_1.onnx.TensorProto.DataType.BOOL: + array = tensorProto.int32Data; + break; + case onnx_proto_1.onnx.TensorProto.DataType.INT64: + array = tensorProto.int64Data; + break; + case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE: + array = tensorProto.doubleData; + break; + case onnx_proto_1.onnx.TensorProto.DataType.UINT32: + case onnx_proto_1.onnx.TensorProto.DataType.UINT64: + array = tensorProto.uint64Data; + break; + default: + // should never run here + throw new Error('unspecific error'); + } + if (array === null || array === undefined) { + throw new Error('failed to populate data from a tensorproto value'); + } + const data = value.data; + if (data.length !== array.length) { + throw new Error('array length mismatch'); + } + for (let i = 0; i < array.length; i++) { + const element = array[i]; + if (long_1.default.isLong(element)) { + data[i] = longToNumber(element, tensorProto.dataType); + } + else { + data[i] = element; + } + } + } + return value; + } + /** + * Construct new Tensor from raw data + * @param data the raw data object. Should be a string array for 'string' tensor, and the corresponding typed array + * for other types of tensor. + * @param dims the dimensions of the tensor + * @param type the type of the tensor + */ + static fromData(data, dims, type) { + return new Tensor(dims, type, undefined, undefined, data); + } + static fromOrtTensor(ortTensor) { + if (!ortTensor) { + throw new Error('cannot construct Value from an empty tensor'); + } + const dims = util_1.ProtoUtil.tensorDimsFromORTFormat(ortTensor); + const type = util_1.ProtoUtil.tensorDataTypeFromProto(ortTensor.dataType()); + const value = new Tensor(dims, type); + if (type === 'string') { + // When it's STRING type, the value should always be stored in field + // 'stringData' + for (let i = 0; i < ortTensor.stringDataLength(); i++) { + value.data[i] = ortTensor.stringData(i); + } + } + else if (ortTensor.rawDataArray() && typeof ortTensor.rawDataLength() === 'number' && ortTensor.rawDataLength() > 0) { + // NOT considering segment for now (IMPORTANT) + // populate value from rawData + const dataDest = value.data; + const dataSource = new DataView(ortTensor.rawDataArray().buffer, ortTensor.rawDataArray().byteOffset, ortTensor.rawDataLength()); + const elementSize = sizeofProto(ortTensor.dataType()); + const length = ortTensor.rawDataLength() / elementSize; + if (ortTensor.rawDataLength() % elementSize !== 0) { + throw new Error('invalid buffer length'); + } + if (dataDest.length !== length) { + throw new Error('buffer length mismatch'); + } + for (let i = 0; i < length; i++) { + const n = readProto(dataSource, ortTensor.dataType(), i * elementSize); + dataDest[i] = n; + } + } + return value; + } +} +exports.Tensor = Tensor; +function sizeof(type) { + switch (type) { + case 'bool': + case 'int8': + case 'uint8': + return 1; + case 'int16': + case 'uint16': + return 2; + case 'int32': + case 'uint32': + case 'float32': + return 4; + case 'float64': + return 8; + default: + throw new Error(`cannot calculate sizeof() on type ${type}`); + } +} +function sizeofProto(type) { + switch (type) { + case onnx_proto_1.onnx.TensorProto.DataType.UINT8: + case onnx_proto_1.onnx.TensorProto.DataType.INT8: + case onnx_proto_1.onnx.TensorProto.DataType.BOOL: + return 1; + case onnx_proto_1.onnx.TensorProto.DataType.UINT16: + case onnx_proto_1.onnx.TensorProto.DataType.INT16: + return 2; + case onnx_proto_1.onnx.TensorProto.DataType.FLOAT: + case onnx_proto_1.onnx.TensorProto.DataType.INT32: + case onnx_proto_1.onnx.TensorProto.DataType.UINT32: + return 4; + case onnx_proto_1.onnx.TensorProto.DataType.INT64: + case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE: + case onnx_proto_1.onnx.TensorProto.DataType.UINT64: + return 8; + default: + throw new Error(`cannot calculate sizeof() on type ${onnx_proto_1.onnx.TensorProto.DataType[type]}`); + } +} +function createView(dataBuffer, type) { + return new (dataviewConstructor(type))(dataBuffer); +} +function dataviewConstructor(type) { + switch (type) { + case 'bool': + case 'uint8': + return Uint8Array; + case 'int8': + return Int8Array; + case 'int16': + return Int16Array; + case 'uint16': + return Uint16Array; + case 'int32': + return Int32Array; + case 'uint32': + return Uint32Array; + case 'float32': + return Float32Array; + case 'float64': + return Float64Array; + default: + // should never run to here + throw new Error('unspecified error'); + } +} +// convert a long number to a 32-bit integer (cast-down) +function longToNumber(i, type) { + // INT64, UINT32, UINT64 + if (type === onnx_proto_1.onnx.TensorProto.DataType.INT64 || type === ortFbs.TensorDataType.INT64) { + if (i.greaterThanOrEqual(2147483648) || i.lessThan(-2147483648)) { + throw new TypeError('int64 is not supported'); + } + } + else if (type === onnx_proto_1.onnx.TensorProto.DataType.UINT32 || type === ortFbs.TensorDataType.UINT32 || + type === onnx_proto_1.onnx.TensorProto.DataType.UINT64 || type === ortFbs.TensorDataType.UINT64) { + if (i.greaterThanOrEqual(4294967296) || i.lessThan(0)) { + throw new TypeError('uint64 is not supported'); + } + } + else { + throw new TypeError(`not a LONG type: ${onnx_proto_1.onnx.TensorProto.DataType[type]}`); + } + return i.toNumber(); +} +// read one value from TensorProto +function readProto(view, type, byteOffset) { + switch (type) { + case onnx_proto_1.onnx.TensorProto.DataType.BOOL: + case onnx_proto_1.onnx.TensorProto.DataType.UINT8: + return view.getUint8(byteOffset); + case onnx_proto_1.onnx.TensorProto.DataType.INT8: + return view.getInt8(byteOffset); + case onnx_proto_1.onnx.TensorProto.DataType.UINT16: + return view.getUint16(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.INT16: + return view.getInt16(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.FLOAT: + return view.getFloat32(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.INT32: + return view.getInt32(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.UINT32: + return view.getUint32(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.INT64: + return longToNumber(long_1.default.fromBits(view.getUint32(byteOffset, true), view.getUint32(byteOffset + 4, true), false), type); + case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE: + return view.getFloat64(byteOffset, true); + case onnx_proto_1.onnx.TensorProto.DataType.UINT64: + return longToNumber(long_1.default.fromBits(view.getUint32(byteOffset, true), view.getUint32(byteOffset + 4, true), true), type); + default: + throw new Error(`cannot read from DataView for type ${onnx_proto_1.onnx.TensorProto.DataType[type]}`); + } +} + + +/***/ }), + +/***/ "./lib/onnxjs/util.ts": +/*!****************************!*\ + !*** ./lib/onnxjs/util.ts ***! + \****************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.decodeUtf8String = exports.MAX_CLIP = exports.MIN_CLIP = exports.PoolConvUtil = exports.ReduceUtil = exports.SplitUtil = exports.MathUtil = exports.ShapeUtil = exports.LongUtil = exports.ProtoUtil = exports.GemmUtil = exports.arrayCopyHelper = exports.BroadcastUtil = exports.MatMulUtil = exports.ArrayUtil = exports.assert = exports.checkInputsShape = void 0; +const flatbuffers_1 = __webpack_require__(/*! flatbuffers */ "./node_modules/flatbuffers/js/flatbuffers.mjs"); +const long_1 = __importDefault(__webpack_require__(/*! long */ "./node_modules/long/src/long.js")); +const onnx_proto_1 = __webpack_require__(/*! onnx-proto */ "./node_modules/onnx-proto/dist/onnx.js"); +const tensor_1 = __webpack_require__(/*! ./tensor */ "./lib/onnxjs/tensor.ts"); +// check the inputs shape before running an OP. +// return true when the inputs pass the check +// return false when the inputs do not fit the requirement +// throw exception when fatal error or not implemented +function checkInputsShape(inputs, ...expectedDimensions) { + if (!inputs || inputs.length !== expectedDimensions.length) { + return false; + } + for (let i = 0; i < inputs.length; i++) { + if (!inputs[i].dims || inputs[i].dims.length !== expectedDimensions[i]) { + return false; + } + } + return true; +} +exports.checkInputsShape = checkInputsShape; +// Evaluates the given expression and asserts error message if condition is unmet. +function assert(expr, msg) { + if (!expr) { + throw new Error(typeof msg === 'string' ? msg : msg()); + } +} +exports.assert = assert; +class ArrayUtil { + /** + * Verifies if 2 input arrays contain the same elements. + * @param n1 Array 1 + * @param n2 Array 2 + * @returns Whether these 2 are equal + */ + static arraysEqual(n1, n2) { + if (n1.length !== n2.length) { + return false; + } + for (let i = 0; i < n1.length; i++) { + if (n1[i] !== n2[i]) { + return false; + } + } + return true; + } +} +exports.ArrayUtil = ArrayUtil; +class MatMulUtil { + /** + * Fix the input shapes for MatMul operation if they need fixing + * @param dimsA The shape of tensor A. Should be an array of positive integers + * @param dimsB The shape of tensor B. Should be an array of positive integers + * @returns A tuple containing the preprocessed input shapes as required by ONNX specifications + */ + static preprocessInputShapes(dimsA, dimsB) { + // If the first argument is 1-D, it is promoted to a matrix by prepending + // a 1 to its dimensions. After matrix multiplication the prepended 1 is + // removed. + const a = (dimsA.length === 1) ? [1, dimsA[0]] : dimsA; + // If the second argument is 1-D, it is promoted to a matrix by appending + // a 1 to its dimensions. After matrix multiplication the appended 1 is + // removed. + const b = (dimsB.length === 1) ? [dimsB[0], 1] : dimsB; + return [a, b]; + } + /** + * Fix the output shape computed for MatMul operation if it needs fixing + * @param outputShape The computed outputShape. Should be an array (atleast of length 2) of positive integers. + * This will be mutated. + * @param aRank The rank of tensor A. + * @param bRank The rank of tensor B. + */ + static postprocessOutputShape(outputShape, aRank, bRank) { + // Remove prepended dimension if first input is 1d + if (aRank === 1) { + // outputShape = outputShape.slice(0, outputShape.length - 2).concat(outputShape.slice(outputShape.length - 1)); + outputShape.splice(outputShape.length - 2, 1); + } + // Remove appended dimension if second input is 1d + if (bRank === 1) { + outputShape.pop(); + } + } + /** + * Calculate the expected shape when matrix multiplication + * @param a The shape of tensor A. Should be a tuple of 2 positive integers + * @param b The shape of tensor B. Should be a tuple of 2 positive integers + * @returns The expected shape of the result, or undefined if N/A + */ + static calcMatMulShape(a, b) { + return (a[1] !== b[0]) ? undefined : [a[0], b[1]]; + } +} +exports.MatMulUtil = MatMulUtil; +class BroadcastUtil { + /** + * Calculate the expected shape when broadcasting 2 tensors + * @param a The shape of tensor A. Should be an array of positive integers + * @param b The shape of tensor B. Should be an array of positive integers + * @param isMatMul Whether the operation is MatMul + * @returns The expected shape of the result, or undefined if N/A + */ + static calcShape(adims, bdims, isMatMul = false) { + const arank = adims.length; + const brank = bdims.length; + if (arank === 0) { + return bdims; + } + if (brank === 0) { + return adims; + } + const crank = Math.max(adims.length, bdims.length); + const cdims = new Array(crank); + // calculate the last 2 dimension if it is MatMul + if (isMatMul) { + if (arank < 2 || brank < 2) { + return undefined; + } + const cShapeMatMul = MatMulUtil.calcMatMulShape([adims[arank - 2], adims[arank - 1]], [bdims[brank - 2], bdims[brank - 1]]); + if (cShapeMatMul === undefined) { + return undefined; + } + [cdims[crank - 2], cdims[crank - 1]] = cShapeMatMul; + } + for (let i = isMatMul ? 3 : 1; i <= crank; i++) { + const aLen = arank - i < 0 ? 1 : adims[arank - i]; + const bLen = brank - i < 0 ? 1 : bdims[brank - i]; + if (aLen !== bLen && aLen > 1 && bLen > 1) { + return undefined; + } + cdims[crank - i] = Math.max(aLen, bLen); + } + return cdims; + } + /** + * Given the indices of a broadcasted tensor, calculate the original indices + * @param broadcastedIndices The given indices of the broadcasted tensor. + * @param originalShape The original shape of the tensor before broadcas + * @returns The calculated indices that maps to the original tensor. + */ + static index(broadcastedIndices, originalShape) { + // NOTE 1: we assume the parameter broadcastedIndices is valid. ie. it should have the same + // length as the broadcasted shape, and for each dimension the index should + // not be out of range. + const originalIndices = new Array(originalShape.length); + BroadcastUtil.fillIndex(broadcastedIndices, originalShape, originalIndices); + return originalIndices; + } + /** + * Given the indices of a broadcasted tensor, calculate the original indices + * @param broadcastedIndices The given indices of the broadcasted tensor. + * @param originalShape The original shape of the tensor before broadcast + * @param originalIndices The mapping of broadcastedIndices to the originalIndices (output parameter - will be + * mutated). + */ + static fillIndex(broadcastedIndices, originalShape, originalIndices) { + // NOTE 1: we assume the parameter broadcastedIndices is valid. ie. it should have the same length as the + // broadcasted shape, and for each dimension the index should not be out of range. + // NOTE 2: we assume the parameter originalIndices has the same length as the originalShape + const dimOffset = broadcastedIndices.length - originalShape.length; + for (let i = 0; i < originalShape.length; i++) { + originalIndices[i] = broadcastedIndices[dimOffset + i] % originalShape[i]; + } + } + /** + * Perform the broadcasting operation on the specific operator + * @param a The input tensor A + * @param b The input tensor B + * @param op The operator lambda function + * @param inplace Whether to write the result back to A. + * @returns The result tensor, or undefined if input not broadcastable. + */ + static calc(a, b, op, inplace, resultType) { + const outputShape = BroadcastUtil.calcShape(a.dims, b.dims); + if (outputShape) { + if (inplace && !ShapeUtil.areEqual(outputShape, a.dims)) { + // B is not broadcastable to A, failed to calculate inplace. + return undefined; + } + const size = ShapeUtil.size(outputShape); + const c = inplace ? a : new tensor_1.Tensor(outputShape, resultType || a.type); + // both inputs are scalars + if (outputShape.length === 0) { + c.set([], op(a.get([]), b.get([]))); + } + // atleast one input is a non-scalar + else { + const outputIndices = new Array(outputShape.length); + const originalIndicesA = new Array(a.dims.length); + const originalIndicesB = new Array(b.dims.length); + let valA = 0; + let valB = 0; + let isAScalar = false; + let isBScalar = false; + if (a.dims.length === 0) { + valA = a.get([]); + isAScalar = true; + } + if (b.dims.length === 0) { + valB = b.get([]); + isBScalar = true; + } + let rest; + for (let i = 0; i < size; i++) { + // traversal indices + rest = i; + for (let j = outputShape.length - 1; j >= 0; j--) { + outputIndices[j] = rest % outputShape[j]; + rest = Math.floor(rest / outputShape[j]); + } + if (!isAScalar) { + // map outputIndices (which is actually broadcasted) to the originalIndices + BroadcastUtil.fillIndex(outputIndices, a.dims, originalIndicesA); + valA = a.get(originalIndicesA); + } + if (!isBScalar) { + BroadcastUtil.fillIndex(outputIndices, b.dims, originalIndicesB); + valB = b.get(originalIndicesB); + } + c.set(outputIndices, op(valA, valB)); + } + } + return c; + } + return undefined; + } + /** + * Determine if a shape is unidirectional broadcastable to another shape + * @param shape The input shape + * @param finalShape The desired shape after broadcasting + */ + static isValidBroadcast(shape, finalShape) { + // align shape to the right + const inputRank = shape.length; + const finalRank = finalShape.length; + if (inputRank > finalRank) { + return false; + } + for (let i = 1; i <= inputRank; i++) { + if (shape[inputRank - i] !== 1 && shape[inputRank - i] !== finalShape[finalRank - i]) { + return false; + } + } + return true; + } + /** + * Determine the broadcasted dims in input shape based on the given output shape. + * Note that this function only returns the broadcasted dims. + * @param inputShape The input shape + * @param outputShape The output shape + * @returns The broadcasted dims in input shape. + */ + static getBroadcastDims(inputShape, outputShape) { + const inRank = inputShape.length; + const dims = []; + for (let i = 0; i < inRank; i++) { + const dim = inRank - 1 - i; + const a = inputShape[dim] || 1; + const b = outputShape[outputShape.length - 1 - i] || 1; + if (b > 1 && a === 1) { + dims.unshift(dim); + } + } + return dims; + } +} +exports.BroadcastUtil = BroadcastUtil; +// copy array helper +// mimics memcpy as much as possible +function arrayCopyHelper(target, source, targetIndex, sourceIndex, blockSize) { + if (sourceIndex < 0 || sourceIndex >= source.length) { + throw new Error('sourceIndex out of bounds'); + } + if (targetIndex < 0 || targetIndex >= target.length) { + throw new Error('targetIndex out of bounds'); + } + if (sourceIndex + blockSize > source.length) { + throw new Error('source indices to be copied are outside bounds'); + } + if (targetIndex + blockSize > target.length) { + throw new Error('target array is too small to hold result'); + } + for (let offset = 0; offset < blockSize; offset++) { + target[targetIndex + offset] = source[sourceIndex + offset]; + } +} +exports.arrayCopyHelper = arrayCopyHelper; +class GemmUtil { + // will make sure input shapes are compatible for this op + // and return back the shape of the output in the form of a tuple + // will throw exception if the input shapes are not compatible + static getShapeOfGemmResult(leftShape, transLeft, rightShape, transRight, biasShape) { + if (leftShape.length !== 2 || rightShape.length !== 2) { + throw new Error('shape need to be of size 2'); + } + let M; + let K; + let N; + if (transLeft) { + M = leftShape[1]; + K = leftShape[0]; + } + else { + M = leftShape[0]; + K = leftShape[1]; + } + let kDim = -1; + if (transRight) { + N = rightShape[0]; + kDim = 1; + } + else { + N = rightShape[1]; + kDim = 0; + } + if (rightShape[kDim] !== K) { + throw new Error('dimension mismatch'); + } + if (M <= 0 || N <= 0 || K <= 0) { + throw new Error('invalid shape specified'); + } + if (biasShape && !BroadcastUtil.isValidBroadcast(biasShape, [M, N])) { + throw new Error('gemm: invalid bias shape for broadcast'); + } + return [M, N, K]; + } +} +exports.GemmUtil = GemmUtil; +class ProtoUtil { + static tensorDataTypeFromProto(typeProto) { + switch (typeProto) { + case onnx_proto_1.onnx.TensorProto.DataType.INT8: + return 'int8'; + case onnx_proto_1.onnx.TensorProto.DataType.UINT8: + return 'uint8'; + case onnx_proto_1.onnx.TensorProto.DataType.BOOL: + return 'bool'; + case onnx_proto_1.onnx.TensorProto.DataType.INT16: + return 'int16'; + case onnx_proto_1.onnx.TensorProto.DataType.UINT16: + return 'uint16'; + case onnx_proto_1.onnx.TensorProto.DataType.INT32: + return 'int32'; + case onnx_proto_1.onnx.TensorProto.DataType.UINT32: + return 'uint32'; + case onnx_proto_1.onnx.TensorProto.DataType.FLOAT: + return 'float32'; + case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE: + return 'float64'; + case onnx_proto_1.onnx.TensorProto.DataType.STRING: + return 'string'; + // For INT64/UINT64, reduce their value to 32-bits. + // Should throw exception when overflow + case onnx_proto_1.onnx.TensorProto.DataType.INT64: + return 'int32'; + case onnx_proto_1.onnx.TensorProto.DataType.UINT64: + return 'uint32'; + default: + throw new Error(`unsupported data type: ${onnx_proto_1.onnx.TensorProto.DataType[typeProto]}`); + } + } + static tensorDataTypeStringToEnum(type) { + switch (type) { + case 'int8': + return onnx_proto_1.onnx.TensorProto.DataType.INT8; + case 'uint8': + return onnx_proto_1.onnx.TensorProto.DataType.UINT8; + case 'bool': + return onnx_proto_1.onnx.TensorProto.DataType.BOOL; + case 'int16': + return onnx_proto_1.onnx.TensorProto.DataType.INT16; + case 'uint16': + return onnx_proto_1.onnx.TensorProto.DataType.UINT16; + case 'int32': + return onnx_proto_1.onnx.TensorProto.DataType.INT32; + case 'uint32': + return onnx_proto_1.onnx.TensorProto.DataType.UINT32; + case 'float32': + return onnx_proto_1.onnx.TensorProto.DataType.FLOAT; + case 'float64': + return onnx_proto_1.onnx.TensorProto.DataType.DOUBLE; + case 'string': + return onnx_proto_1.onnx.TensorProto.DataType.STRING; + case 'int64': + return onnx_proto_1.onnx.TensorProto.DataType.INT64; + case 'uint64': + return onnx_proto_1.onnx.TensorProto.DataType.UINT64; + default: + throw new Error(`unsupported data type: ${type}`); + } + } + static tensorDimsFromProto(dims) { + // get rid of Long type for dims + return dims.map(d => long_1.default.isLong(d) ? d.toNumber() : d); + } + static tensorValueTypeFromProto(valueType) { + return { + tensorType: ProtoUtil.tensorDataTypeFromProto(valueType.elemType), + shape: { dims: ProtoUtil.tensorDimsFromProto(valueType.shape.dim.map(d => d.dimValue)) } + }; + } + static tensorDimsFromORTFormat(tensor) { + const dims = []; + for (let i = 0; i < tensor.dimsLength(); i++) { + dims.push(LongUtil.longToNumber(tensor.dims(i))); + } + return dims; + } + static tensorAttributesFromORTFormat(node) { + const attributes = []; + for (let i = 0; i < node.attributesLength(); i++) { + attributes.push(node.attributes(i)); + } + return attributes; + } +} +exports.ProtoUtil = ProtoUtil; +class LongUtil { + // This function is called to get a number from long type of data for attribute, dim, and ir version, + // which values are signed integers. + // To make it more generic, add an optional paramter to convert to a unsigned number. + static longToNumber(n, unsigned) { + if (long_1.default.isLong(n)) { + return n.toNumber(); + } + else if (n instanceof flatbuffers_1.flatbuffers.Long) { + return long_1.default.fromValue({ low: n.low, high: n.high, unsigned: unsigned !== null && unsigned !== void 0 ? unsigned : false }).toNumber(); + } + return n; + } + static isLong(n) { + return long_1.default.isLong(n) || n instanceof flatbuffers_1.flatbuffers.Long; + } +} +exports.LongUtil = LongUtil; +class ShapeUtil { + static size(dims) { + return ShapeUtil.getSizeFromDimensionRange(dims, 0, dims.length); + } + // `axis` inclusive + static sizeFromDimension(dims, axis) { + if (axis < 0 || axis > dims.length) { + throw new Error(`invalid dimension of ${axis} for sizeFromDimension as Tensor has ${dims.length} dimensions.`); + } + return ShapeUtil.getSizeFromDimensionRange(dims, axis, dims.length); + } + // `axis` exclusive + static sizeToDimension(dims, axis) { + if (axis < 0 || axis > dims.length) { + throw new Error(`invalid dimension of ${axis} for sizeToDimension as Tensor has ${dims.length} dimensions.`); + } + return ShapeUtil.getSizeFromDimensionRange(dims, 0, axis); + } + static getSizeFromDimensionRange(dims, start, end) { + let size = 1; + for (let i = start; i < end; i++) { + // safety check as this method is called by multiple other methods requiring size. + // size cannot be 0 or negative. + if (dims[i] <= 0) { + throw new Error( + // eslint-disable-next-line max-len + 'cannot get valid size from specified dimension range. Most likely the range contains 0 or negative values in them.'); + } + size *= dims[i]; + } + return size; + } + static computeStrides(dims) { + const rank = dims.length; + if (rank === 0) { + return []; + } + else if (rank === 1) { + return [1]; + } + const strides = new Array(rank); + strides[rank - 1] = 1; + strides[rank - 2] = dims[rank - 1]; + for (let i = rank - 3; i >= 0; --i) { + strides[i] = strides[i + 1] * dims[i + 1]; + } + return strides; + } + static transpose(dims) { + const copy = dims.slice(); + return copy.reverse(); + } + static indicesToOffset(indices, strides, axis) { + if (axis === undefined) { + axis = indices.length; + } + let offset = 0; + for (let i = 0; i < axis; ++i) { + offset += strides[i] * indices[i]; + } + return offset; + } + static offsetToIndices(offset, strides) { + const rank = strides.length; + if (rank === 0) { + return []; + } + else if (rank === 1) { + return [offset * strides[0]]; + } + const indices = new Array(strides.length); + for (let i = 0; i < indices.length - 1; ++i) { + indices[i] = Math.floor(offset / strides[i]); + offset -= indices[i] * strides[i]; + } + indices[indices.length - 1] = offset; + return indices; + } + /** + * normailze axis of range [-r, r) into [0, r). + */ + static normalizeAxis(axis, tensorRank) { + if (axis < -tensorRank && axis >= tensorRank) { + throw new Error('unsupported axis for this operation.'); + } + return axis < 0 ? axis + tensorRank : axis; + } + static normalizeAxes(axes, tensorRank) { + return axes.map(x => this.normalizeAxis(x, tensorRank)); + } + // Increment an index into a tensor (in lexicographic + // ordering), wrapping around the specified upper_bound. + /** + * Increment an index into a tensor (in lexicographic ordering), wrapping around the specified upper_bound. + * @param index Given index to increment (Will be mutated) + * @param dims The dimensions of the tensor for which the given index corresponds to + * @param axisToIncrementOn The 1-indexed axis to increment on. If undefined, axisToIncrementOn == rank + */ + static incrementIndex(index, dims, axisToIncrementOn) { + if (dims.length === 0 || index.length === 0) { + throw new Error('Index incrementing unsupported for scalar Tensor'); + } + if (axisToIncrementOn === undefined) { + axisToIncrementOn = dims.length; + } + else { + if (axisToIncrementOn <= 0 || axisToIncrementOn > dims.length) { + throw new Error('Incorrect axis to increment on'); + } + } + for (let k = axisToIncrementOn - 1; k >= 0; --k) { + index[k]++; + if (index[k] < dims[k]) { + break; + } + index[k] = 0; + } + } + /** + * Produces a new dimensions array based on the values in the 'originalDimensions' and 'shape' array + * Used in Reshape + * @param originalDims Original Shape array + * @param shapeHints array containing values to compute the new dimensions + * For example: + * originalDims = [2,2] and shapeHints = [0,-1] will return [2,2] + * originalDims = [2,2] and shapeHints = [4] will return [4] + * originalDims = [2,2] and shapeHints = [5] will throw an exception + * https://github.com/onnx/onnx/blob/main/docs/Operators.md#Reshape + */ + static calculateReshapedDims(originalDims, shapeHints) { + // reshape to a Scalar Tensor + if (shapeHints.length === 0) { + if (originalDims.length === 0 || ShapeUtil.size(originalDims) === 1) { + return []; + } + else { + throw new Error('cannot reshape to a scalar Tensor'); + } + } + const nDims = shapeHints.length; + const reshapedDims = new Array(nDims); + let unknownDimension = -1; + let newTensorSize = 1; + for (let i = 0; i < nDims; i++) { + if (shapeHints[i] < -1) { + throw new Error('a dimension in shape hints cannot be less than -1'); + } + if (shapeHints[i] === -1) { + if (unknownDimension !== -1) { + throw new Error('at most one dimension in shape hints can be -1'); + } + unknownDimension = i; + } + else { + if (shapeHints[i] === 0) { + if (i >= originalDims.length) { + throw new Error('the dimension with value zero exceeds the dimension size of the input tensor'); + } + reshapedDims[i] = originalDims[i]; + } + else { + reshapedDims[i] = shapeHints[i]; + } + newTensorSize *= reshapedDims[i]; + } + } + const oldTensorSize = ShapeUtil.size(originalDims); + if (unknownDimension !== -1) { + if (oldTensorSize % newTensorSize !== 0) { + throw new Error(`the input tensor cannot be reshaped to the requested shape. Input shape: [${originalDims}] Output shape: [${shapeHints}]`); + } + reshapedDims[unknownDimension] = oldTensorSize / newTensorSize; + } + // validate sizes from originalDims and reshapedDims match + else { + if (newTensorSize !== oldTensorSize) { + throw new Error('reshapedDims and originalDims don\'t have matching sizes'); + } + } + return reshapedDims; + } + /** + * Sorts a given array based on the indices in the Perm array + * Used in Transpose + * @param a Array to be sorted such as dims or strides + * @param perm Perm given; if null a will be reversed + */ + static sortBasedOnPerm(a, perm) { + if (perm) { + return perm.map((v) => a[v]); + } + else { + return a.slice().reverse(); + } + } + /** + * Pads a given shape according to the padding values + * @param dims shape of the Tensor to be padded + * @param pad pad values + */ + static padShape(dims, pad) { + const rank = dims.length; + return dims.map((v, i) => v + pad[i] + pad[i + rank]); + } + /** + * Determines if the two shapes are identical + * @param shape1 + * @param shape2 + */ + static areEqual(shape1, shape2) { + if (shape1.length !== shape2.length) { + return false; + } + return shape1.every((v, i) => v === shape2[i]); + } + /** + * Validates if the given `dims` or `shape` is valid in ONNX.js context and returns data size + * @param dims - input `dims` that needs to be checked + */ + static validateDimsAndCalcSize(dims) { + if (dims.length > 6) { + throw new TypeError('Only rank 0 to 6 is supported for tensor shape.'); + } + let size = 1; + for (const n of dims) { + if (!Number.isInteger(n)) { + throw new TypeError(`Invalid shape: ${n} is not an integer`); + } + if (n < 0 || n > 2147483647) { + throw new TypeError(`Invalid shape: length ${n} is not allowed`); + } + size *= n; + } + return size; + } + /** + * Determines the shape of output tensor y = flatten(x, axis) + * @param dims - shape of input tensor + * @param axis - flatten axis, in the range [-r, r] + */ + static flattenShape(dims, axis) { + if (axis < 0) { + axis += dims.length; + } + const total = dims.reduce((x, y) => x * y, 1); + const right = dims.slice(axis).reduce((x, y) => x * y, 1); + const outputDims = [total / right, right]; + return outputDims; + } + /** + * Determines the shape of output tensor y = squeeze(x, axes) + * @param dims - shape of input tensor + * @param axes - squeeze axes + */ + static squeezeShape(dims, axes) { + const outputDims = new Array(); + // sanity check + axes = ShapeUtil.normalizeAxes(axes, dims.length); + for (let i = 0; i < dims.length; i++) { + const inSqueezeList = axes.indexOf(i) >= 0; + if (inSqueezeList && dims[i] !== 1) { + throw new Error('squeeze an axis of size different than 1'); + } + if ((axes.length === 0 && dims[i] > 1) || (axes.length > 0 && !inSqueezeList)) { + outputDims.push(dims[i]); + } + } + return outputDims; + } + /** + * Determines the shape of output tensor y = unsqueeze(x, axes) + * @param dims - shape of input tensor + * @param axes - unsqueeze axes + */ + static unsqueezeShape(dims, axes) { + const outputDims = new Array(dims.length + axes.length); + // initialize the array elements to 0 + outputDims.fill(0); + // set all axes indices to 1 in outputDims and check for duplicates + for (let i = 0; i < axes.length; i++) { + const axis = ShapeUtil.normalizeAxis(axes[i], outputDims.length); + if (axis >= outputDims.length) { + throw new Error('\'axes\' has an out of range axis'); + } + if (outputDims[axis] !== 0) { + throw new Error('\'axes\' has a duplicate axis'); + } + outputDims[axis] = 1; + } + // fill in the zero entries of outputDims with the input tensor's shape + let inputDimsIterator = 0; + for (let i = 0; i < outputDims.length; i++) { + if (outputDims[i] === 0) { + outputDims[i] = dims[inputDimsIterator++]; + } + } + // sanity check assertion. 'inputDimsIterator' + // should be equal to the length of 'dims' + if (inputDimsIterator !== dims.length) { + throw new Error('the unsqueezed dimension could not be established'); + } + return outputDims; + } +} +exports.ShapeUtil = ShapeUtil; +// bunch of helper methods that do a variety of math operations +class MathUtil { + // y = (x*x) + y + static sqr(target, source, targetIndex, sourceIndex, blockSize) { + if (sourceIndex < 0 || sourceIndex >= source.length) { + throw new Error('sourceIndex out of bounds'); + } + if (targetIndex < 0 || targetIndex >= target.length) { + throw new Error('targetIndex out of bounds'); + } + if (sourceIndex + blockSize > source.length) { + throw new Error('source indices to be copied are outside bounds'); + } + if (targetIndex + blockSize > target.length) { + throw new Error('target array is too small to hold result'); + } + for (let offset = 0; offset < blockSize; offset++) { + target[targetIndex + offset] += Math.pow(source[sourceIndex + offset], 2); + } + } + // y = ax + y + static axpy(target, source, targetIndex, sourceIndex, blockSize, alpha) { + if (sourceIndex < 0 || sourceIndex >= source.length) { + throw new Error('sourceIndex out of bounds'); + } + if (targetIndex < 0 || targetIndex >= target.length) { + throw new Error('targetIndex out of bounds'); + } + if (sourceIndex + blockSize > source.length) { + throw new Error('source indices to be copied are outside bounds'); + } + if (targetIndex + blockSize > target.length) { + throw new Error('target array is too small to hold result'); + } + for (let offset = 0; offset < blockSize; offset++) { + target[targetIndex + offset] += (alpha * source[sourceIndex + offset]); + } + } + // y = pow(x, b) + static powx(target, source, targetIndex, sourceIndex, blockSize, b) { + if (sourceIndex < 0 || sourceIndex >= source.length) { + throw new Error('sourceIndex out of bounds'); + } + if (targetIndex < 0 || targetIndex >= target.length) { + throw new Error('targetIndex out of bounds'); + } + if (sourceIndex + blockSize > source.length) { + throw new Error('source indices to be copied are outside bounds'); + } + if (targetIndex + blockSize > target.length) { + throw new Error('target array is too small to hold result'); + } + for (let offset = 0; offset < blockSize; offset++) { + target[targetIndex + offset] = Math.pow(source[sourceIndex + offset], b); + } + } + // y = x * y + static mul(target, source, targetIndex, sourceIndex, blockSize) { + if (sourceIndex < 0 || sourceIndex >= source.length) { + throw new Error('sourceIndex out of bounds'); + } + if (targetIndex < 0 || targetIndex >= target.length) { + throw new Error('targetIndex out of bounds'); + } + if (sourceIndex + blockSize > source.length) { + throw new Error('source indices to be copied are outside bounds'); + } + if (targetIndex + blockSize > target.length) { + throw new Error('target array is too small to hold result'); + } + for (let offset = 0; offset < blockSize; offset++) { + target[targetIndex + offset] = (source[sourceIndex + offset] * target[targetIndex + offset]); + } + } +} +exports.MathUtil = MathUtil; +class SplitUtil { + /** + * Calculates new Shapes from existing one and the splits given along the axis provides + * @param dims Shape of the Tensor to be splitted into two or more Shapes + * @param axis The dimension along which the Tensor will be split + * @param splits Offsets for the start of each split + */ + static splitShape(dims, axis, split, numOutputs) { + if (split.length === 0) { + if (!numOutputs) { + throw new Error('need to know number of outputs when the \'split\' attribute is not specified'); + } + SplitUtil.determineSplit(dims[axis], numOutputs, split); + } + const shapes = []; + const offsets = [0]; + for (let i = 0; i < split.length; ++i) { + if (i !== 0) { + offsets.push(offsets[i - 1] + split[i - 1]); + } + const shape = dims.slice(); + shape[axis] = split[i]; + shapes.push(shape); + } + return [shapes, offsets]; + } + static determineSplit(numElementsAlongAxis, numOutputs, split) { + // If 'split' is not specified by the user, we need to partition the number of elements equally among the outputs + if (numElementsAlongAxis % numOutputs !== 0) { + throw new Error('cannot split tensor to equal sized parts'); + } + for (let i = 0; i < numOutputs; ++i) { + split.push(numElementsAlongAxis / numOutputs); + } + } +} +exports.SplitUtil = SplitUtil; +class ReduceUtil { + /** + * Perform reduce operations on the specific operator + * @param a Input tensor data + * @param axes The dimensions along which the Tensor will be reduced + * @param keepdims If set to true, the axes which are reduced are left in the + * result as dimensions with size one. + * @param op1 The operation to be performed on each element in the tensor + * @param op2 The operation to be performed between elements in the tensor + */ + static calcReduce(a, axes, keepdims, op1, op2) { + const dims = a.dims.slice(0); + // if axes is not set, perform reduce on all axes + if (axes.length === 0) { + dims.forEach((d, ind) => axes.push(ind)); + } + // get a temporary broadcastable output shape + const outputDims = ReduceUtil.calcReduceShape(dims, axes, true); + // loop through the output and calculate result one by one + const size = ShapeUtil.size(outputDims); + const y = new tensor_1.Tensor(outputDims, a.type); + const strides = ShapeUtil.computeStrides(outputDims); + const inputStrides = ShapeUtil.computeStrides(dims); + const indicesY = new Array(dims.length); + for (let i = 0; i < size; i++) { + const indices = ShapeUtil.offsetToIndices(i, strides); + // map index + BroadcastUtil.fillIndex(indices, dims, indicesY); + y.set(indices, ReduceUtil.calcReduceByAxis(a.numberData, axes, dims, 0, ShapeUtil.indicesToOffset(indicesY, inputStrides), op1, op2)); + } + if (keepdims) { + return y; + } + else { + // keepdims == 0, calculate the expected shape + return new tensor_1.Tensor(ReduceUtil.calcReduceShape(dims, axes, keepdims), y.type, undefined, undefined, y.data, y.dataId); + } + } + /** + * Perform reduce operations on the specific operator on specific axes + * @param a Input tensor data + * @param axes The dimensions along which the Tensor will be reduced + * @param dims The input dimension. + * @param curAxisInd Index in axes specifying the current dimension along + * which the tensor will be reduced + * @param pos The current index of element to perform operation + * @param op1 The operation to be performed on each element in the tensor + * @param op2 The operation to be performed between elements in the tensor + */ + static calcReduceByAxis(input, axes, dims, curAxisInd, pos, op1, op2) { + let res = 0; + if (curAxisInd >= axes.length) { + return op1(input[pos]); + } + const axis = axes[curAxisInd]; + const step = axis >= dims.length ? 1 : ShapeUtil.size(dims.slice(axis + 1)); + for (let i = 0; i < dims[axis]; i++) { + res = i === 0 ? ReduceUtil.calcReduceByAxis(input, axes, dims, curAxisInd + 1, pos, op1, op2) : + op2(res, ReduceUtil.calcReduceByAxis(input, axes, dims, curAxisInd + 1, pos, op1, op2)); + pos += step; + } + return res; + } + /** + * Calculate the expected shape of a reduce operation + * @param dims The input tensor dimension + * @param axes The dimensions along which the Tensor will be reduced + * @param keepdims If set to true, the axes which are reduced are left in the + * result as dimensions with size one. + */ + static calcReduceShape(dims, axes, keepDims) { + const outputDims = dims.slice(); + for (let i = 0; i < axes.length; i++) { + if (keepDims) { + outputDims[axes[i]] = 1; + } + else { + outputDims[axes[i]] = 0; + } + } + return outputDims.filter(dim => dim !== 0); + } +} +exports.ReduceUtil = ReduceUtil; +class PoolConvUtil { + /** + * Adjust the kernel, strides, pads to correct rank. Set to default value if not present + * @param isGlobalOperator If true, perform global pooling. + * @param inputDims The input tensor dimension. + * @param kernelShape The size of the kernel along each axis. + * @param strides Stride along each axis. + * @param dilations Dilation along each axis. + * @param pads Padding for the beginning and ending along each axis. + */ + static adjustPoolAttributes(isGlobalOperator, inputDims, kernelShape, strides, dilations, pads) { + if (!isGlobalOperator && kernelShape.length !== inputDims.length - 2) { + throw new Error('length of specified kernel shapes should be 2 less than length of input dimensions'); + } + if (isGlobalOperator) { + // adjust kernel shape to cover the input dims + for (let dim = 0; dim < inputDims.length - 2; dim++) { + if (dim >= kernelShape.length) { + kernelShape.push(inputDims[dim + 2]); + } + else { + kernelShape[dim] = inputDims[dim + 2]; + } + } + } + // adjust strides length to match kernel shape length + for (let dim = 0; dim < kernelShape.length; dim++) { + if (dim < strides.length) { + if (strides[dim] < 0) { + throw new Error('strides should be greater than or equal to 1'); + } + } + else { + strides.push(1); + } + } + // adjust dilation value + for (let dim = 0; dim < kernelShape.length; dim++) { + if (dim < dilations.length) { + if (dilations[dim] < 0) { + throw new Error('dilations should be greater than or equal to 1'); + } + } + else { + dilations.push(1); + } + } + // adjust pads length to match 2 * kernel shape length + for (let dim = 0; dim < kernelShape.length * 2; dim++) { + if (dim < pads.length) { + if (pads[dim] < 0) { + throw new Error('pad should be greater than or equal to 1'); + } + } + else { + pads.push(0); + } + } + // sanity checks for values in kernel shapes and pads + for (let dim = 0; dim < kernelShape.length; dim++) { + if (kernelShape[dim] <= 0) { + throw new Error('kernel shapes need to be greater than 0'); + } + if (pads[dim] >= kernelShape[dim] || pads[dim + kernelShape.length] >= kernelShape[dim]) { + throw new Error('pads should be smaller than kernel'); + } + } + } + // adjust pad values based on 'autoPad' attribute + static adjustPadsBasedOnAutoPad(inputDims, strides, dilations, kernelShape, pads, autoPad) { + if (!autoPad) { + return; + } + if (pads.length !== 2 * (inputDims.length - 2)) { + throw new Error('length of pads should be twice the length of data dimensions'); + } + if (strides.length !== (inputDims.length - 2)) { + throw new Error('length of strides should be the length of data dimensions'); + } + if (kernelShape.length !== (inputDims.length - 2)) { + throw new Error('length of kernel shapes should be the length of data dimensions'); + } + for (let dim = 0; dim < inputDims.length - 2; dim++) { + PoolConvUtil.adjustPadAndReturnShape(inputDims[dim + 2], strides[dim], dilations[dim], kernelShape[dim], pads, dim, dim + inputDims.length - 2, autoPad); + } + } + /** + * Calculate the output shape for Pool ops based on input attributes. (Should be used only for Pool ops) + * @param isGlobalOperator If true, perform global pooling. + * @param inputDims The input tensor dimension. (inputs[0].dims) + * @param strides Stride along each axis. + * @param dilations Dilation along each axis. + * @param kernelShape The size of the kernel along each axis. + * @param pads Padding for the beginning and ending along each axis. + * @param autoPad DEPRECATED attribute supported for legacy models. Specifies how to implicitly calculate pads in each + * dimension. Can take values NOTSET, SAME_UPPER, SAME_LOWER, or VALID. + */ + static computePoolOutputShape(isGlobalOperator, inputDims, strides, dilations, kernelShape, pads, autoPad) { + if (inputDims.length <= 0) { + throw new Error('input shape must be of size greater than 0'); + } + // Add batch size and number of channels of output + const outputDims = [inputDims[0], inputDims[1]]; + PoolConvUtil.computeShapeHelper(isGlobalOperator, inputDims, outputDims, strides, dilations, kernelShape, pads, autoPad); + return outputDims; + } + /** + * Calculate the output shape for Conv op based on input attributes. (Should be used only for Conv op) + * @param inputDims The input tensor dimension. (inputs[0].dims) + * @param filterDims The filter tensor dimension. (inputs[1].dims) + * @param strides Stride along each axis. + * @param kernelShape The size of the kernel along each axis. + * @param pads Padding for the beginning and ending along each axis. + * @param autoPad DEPRECATED attribute supported for legacy models. Specifies how to implicitly calculate pads in each + * dimension. Can take values NOTSET, SAME_UPPER, SAME_LOWER, or VALID. + */ + static computeConvOutputShape(inputDims, filterDims, strides, dilations, kernelShape, pads, autoPad) { + if (inputDims.length <= 0 || filterDims.length <= 0) { + throw new Error('invalid input tensor dims or invalid filter tensor dims'); + } + // Add batch size and number of channels of output + const outputDims = [inputDims[0], filterDims[0]]; + PoolConvUtil.computeShapeHelper(false, inputDims, outputDims, strides, dilations, kernelShape, pads, autoPad); + return outputDims; + } + // will compute output shapes for data dimensions ONLY (i.e.) no batch size and channels + // called by computePoolOutputShape() and computeConvOutputShape() + // adjust pads based on 'autoPad' attribute prior to shape computation + static computeShapeHelper(isGlobalOperator, inputDims, outputDims, strides, dilations, kernelShape, pads, autoPad) { + if (isGlobalOperator) { + for (let dim = 0; dim < inputDims.length - 2; dim++) { + outputDims.push(1); + } + } + else { + for (let dim = 0; dim < inputDims.length - 2; dim++) { + outputDims.push(PoolConvUtil.adjustPadAndReturnShape(inputDims[dim + 2], strides[dim], dilations[dim], kernelShape[dim], pads, dim, dim + inputDims.length - 2, autoPad)); + } + } + } + // helper for computeShapeHelper() and adjustPadsBasedOnAutoPad() + // adjusts pad value for given 'autoPad' string and computes output shape along a particular dimension + static adjustPadAndReturnShape(inSize, stride, dilation, kernel, pads, padHeadIndex, padTailIndex, autoPad) { + const dkernel = dilation * (kernel - 1) + 1; + if (autoPad && autoPad !== 'NOTSET') { + switch (autoPad) { + case 'VALID': + pads[padHeadIndex] = 0; + pads[padTailIndex] = 0; + return Math.floor(((inSize - dkernel) / stride) + 1); + case 'SAME_LOWER': + case 'SAME_UPPER': + if (dilation !== 1) { + throw new Error('Dilation not supported for SAME_UPPER or SAME_LOWER'); + } + else { + const legacyTargetSize = (inSize + stride - 1) / stride; + const padNeeded = (legacyTargetSize - 1) * stride + kernel - inSize; + pads[padHeadIndex] = + (autoPad === 'SAME_LOWER') ? Math.floor((padNeeded + 1) / 2) : Math.floor(padNeeded / 2); + pads[padTailIndex] = padNeeded - pads[padHeadIndex]; + return Math.floor(((inSize + padNeeded - kernel) / stride) + 1); + } + default: + throw new Error('Unsupported AutoPad type'); + } + } + else { + return Math.floor(((inSize + pads[padHeadIndex] + pads[padTailIndex] - dkernel) / stride) + 1); + } + } +} +exports.PoolConvUtil = PoolConvUtil; +exports.MIN_CLIP = -3.4028234663852886e+38; +exports.MAX_CLIP = 3.4028234663852886e+38; +function decodeUtf8String(buffer) { + return new TextDecoder().decode(buffer); +} +exports.decodeUtf8String = decodeUtf8String; + + +/***/ }), + +/***/ "./lib/wasm/options-utils.ts": +/*!***********************************!*\ + !*** ./lib/wasm/options-utils.ts ***! + \***********************************/ +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.iterateExtraOptions = void 0; +const iterateExtraOptions = (options, prefix, seen, handler) => { + if (typeof options == 'object' && options !== null) { + if (seen.has(options)) { + throw new Error('Circular reference in options'); + } + else { + seen.add(options); + } + } + Object.entries(options).forEach(([key, value]) => { + const name = (prefix) ? prefix + key : key; + if (typeof value === 'object') { + (0, exports.iterateExtraOptions)(value, name + '.', seen, handler); + } + else if (typeof value === 'string' || typeof value === 'number') { + handler(name, value.toString()); + } + else if (typeof value === 'boolean') { + handler(name, (value) ? '1' : '0'); + } + else { + throw new Error(`Can't handle extra config type: ${typeof value}`); + } + }); +}; +exports.iterateExtraOptions = iterateExtraOptions; + + +/***/ }), + +/***/ "./lib/wasm/proxy-wrapper.ts": +/*!***********************************!*\ + !*** ./lib/wasm/proxy-wrapper.ts ***! + \***********************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var _a; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.endProfiling = exports.run = exports.releaseSession = exports.createSession = exports.createSessionFinalize = exports.createSessionAllocate = exports.initOrt = exports.initWasm = void 0; +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const core = __importStar(__webpack_require__(/*! ./wasm-core-impl */ "./lib/wasm/wasm-core-impl.ts")); +const wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ "./lib/wasm/wasm-factory.ts"); +const isProxy = () => !!onnxruntime_common_1.env.wasm.proxy && typeof document !== 'undefined'; +let proxyWorker; +let initializing = false; +let initialized = false; +let aborted = false; +let initWasmCallbacks; +let initOrtCallbacks; +const createSessionAllocateCallbacks = []; +const createSessionFinalizeCallbacks = []; +const createSessionCallbacks = []; +const releaseSessionCallbacks = []; +const runCallbacks = []; +const endProfilingCallbacks = []; +const ensureWorker = () => { + if (initializing || !initialized || aborted || !proxyWorker) { + throw new Error('worker not ready'); + } +}; +const onProxyWorkerMessage = (ev) => { + switch (ev.data.type) { + case 'init-wasm': + initializing = false; + if (ev.data.err) { + aborted = true; + initWasmCallbacks[1](ev.data.err); + } + else { + initialized = true; + initWasmCallbacks[0](); + } + break; + case 'init-ort': + if (ev.data.err) { + initOrtCallbacks[1](ev.data.err); + } + else { + initOrtCallbacks[0](); + } + break; + case 'create_allocate': + if (ev.data.err) { + createSessionAllocateCallbacks.shift()[1](ev.data.err); + } + else { + createSessionAllocateCallbacks.shift()[0](ev.data.out); + } + break; + case 'create_finalize': + if (ev.data.err) { + createSessionFinalizeCallbacks.shift()[1](ev.data.err); + } + else { + createSessionFinalizeCallbacks.shift()[0](ev.data.out); + } + break; + case 'create': + if (ev.data.err) { + createSessionCallbacks.shift()[1](ev.data.err); + } + else { + createSessionCallbacks.shift()[0](ev.data.out); + } + break; + case 'release': + if (ev.data.err) { + releaseSessionCallbacks.shift()[1](ev.data.err); + } + else { + releaseSessionCallbacks.shift()[0](); + } + break; + case 'run': + if (ev.data.err) { + runCallbacks.shift()[1](ev.data.err); + } + else { + runCallbacks.shift()[0](ev.data.out); + } + break; + case 'end-profiling': + if (ev.data.err) { + endProfilingCallbacks.shift()[1](ev.data.err); + } + else { + endProfilingCallbacks.shift()[0](); + } + break; + default: + } +}; +const scriptSrc = typeof document !== 'undefined' ? (_a = document === null || document === void 0 ? void 0 : document.currentScript) === null || _a === void 0 ? void 0 : _a.src : undefined; +const initWasm = async () => { + if ( true && isProxy()) { + if (initialized) { + return; + } + if (initializing) { + throw new Error('multiple calls to \'initWasm()\' detected.'); + } + if (aborted) { + throw new Error('previous call to \'initWasm()\' failed.'); + } + initializing = true; + // overwrite wasm filepaths + if (onnxruntime_common_1.env.wasm.wasmPaths === undefined) { + if (scriptSrc && scriptSrc.indexOf('blob:') !== 0) { + onnxruntime_common_1.env.wasm.wasmPaths = scriptSrc.substr(0, +(scriptSrc).lastIndexOf('/') + 1); + } + } + return new Promise((resolve, reject) => { + proxyWorker === null || proxyWorker === void 0 ? void 0 : proxyWorker.terminate(); + // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports + proxyWorker = (__webpack_require__(/*! worker-loader?inline=no-fallback!./proxy-worker/main */ "./node_modules/worker-loader/dist/cjs.js?inline=no-fallback!./lib/wasm/proxy-worker/main.ts")["default"])(); + proxyWorker.onmessage = onProxyWorkerMessage; + initWasmCallbacks = [resolve, reject]; + const message = { type: 'init-wasm', in: onnxruntime_common_1.env.wasm }; + proxyWorker.postMessage(message); + }); + } + else { + return (0, wasm_factory_1.initializeWebAssembly)(onnxruntime_common_1.env.wasm); + } +}; +exports.initWasm = initWasm; +const initOrt = async (numThreads, loggingLevel) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + initOrtCallbacks = [resolve, reject]; + const message = { type: 'init-ort', in: { numThreads, loggingLevel } }; + proxyWorker.postMessage(message); + }); + } + else { + core.initOrt(numThreads, loggingLevel); + } +}; +exports.initOrt = initOrt; +const createSessionAllocate = async (model) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + createSessionAllocateCallbacks.push([resolve, reject]); + const message = { type: 'create_allocate', in: { model } }; + proxyWorker.postMessage(message, [model.buffer]); + }); + } + else { + return core.createSessionAllocate(model); + } +}; +exports.createSessionAllocate = createSessionAllocate; +const createSessionFinalize = async (modeldata, options) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + createSessionFinalizeCallbacks.push([resolve, reject]); + const message = { type: 'create_finalize', in: { modeldata, options } }; + proxyWorker.postMessage(message); + }); + } + else { + return core.createSessionFinalize(modeldata, options); + } +}; +exports.createSessionFinalize = createSessionFinalize; +const createSession = async (model, options) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + createSessionCallbacks.push([resolve, reject]); + const message = { type: 'create', in: { model, options } }; + proxyWorker.postMessage(message, [model.buffer]); + }); + } + else { + return core.createSession(model, options); + } +}; +exports.createSession = createSession; +const releaseSession = async (sessionId) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + releaseSessionCallbacks.push([resolve, reject]); + const message = { type: 'release', in: sessionId }; + proxyWorker.postMessage(message); + }); + } + else { + core.releaseSession(sessionId); + } +}; +exports.releaseSession = releaseSession; +const run = async (sessionId, inputIndices, inputs, outputIndices, options) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + runCallbacks.push([resolve, reject]); + const message = { type: 'run', in: { sessionId, inputIndices, inputs, outputIndices, options } }; + proxyWorker.postMessage(message, core.extractTransferableBuffers(inputs)); + }); + } + else { + return core.run(sessionId, inputIndices, inputs, outputIndices, options); + } +}; +exports.run = run; +const endProfiling = async (sessionId) => { + if ( true && isProxy()) { + ensureWorker(); + return new Promise((resolve, reject) => { + endProfilingCallbacks.push([resolve, reject]); + const message = { type: 'end-profiling', in: sessionId }; + proxyWorker.postMessage(message); + }); + } + else { + core.endProfiling(sessionId); + } +}; +exports.endProfiling = endProfiling; + + +/***/ }), + +/***/ "./lib/wasm/run-options.ts": +/*!*********************************!*\ + !*** ./lib/wasm/run-options.ts ***! + \*********************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.setRunOptions = void 0; +const options_utils_1 = __webpack_require__(/*! ./options-utils */ "./lib/wasm/options-utils.ts"); +const string_utils_1 = __webpack_require__(/*! ./string-utils */ "./lib/wasm/string-utils.ts"); +const wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ "./lib/wasm/wasm-factory.ts"); +const setRunOptions = (options) => { + const wasm = (0, wasm_factory_1.getInstance)(); + let runOptionsHandle = 0; + const allocs = []; + const runOptions = options || {}; + try { + if ((options === null || options === void 0 ? void 0 : options.logSeverityLevel) === undefined) { + runOptions.logSeverityLevel = 2; // Default to warning + } + else if (typeof options.logSeverityLevel !== 'number' || !Number.isInteger(options.logSeverityLevel) || + options.logSeverityLevel < 0 || options.logSeverityLevel > 4) { + throw new Error(`log serverity level is not valid: ${options.logSeverityLevel}`); + } + if ((options === null || options === void 0 ? void 0 : options.logVerbosityLevel) === undefined) { + runOptions.logVerbosityLevel = 0; // Default to 0 + } + else if (typeof options.logVerbosityLevel !== 'number' || !Number.isInteger(options.logVerbosityLevel)) { + throw new Error(`log verbosity level is not valid: ${options.logVerbosityLevel}`); + } + if ((options === null || options === void 0 ? void 0 : options.terminate) === undefined) { + runOptions.terminate = false; + } + let tagDataOffset = 0; + if ((options === null || options === void 0 ? void 0 : options.tag) !== undefined) { + tagDataOffset = (0, string_utils_1.allocWasmString)(options.tag, allocs); + } + runOptionsHandle = wasm._OrtCreateRunOptions(runOptions.logSeverityLevel, runOptions.logVerbosityLevel, !!runOptions.terminate, tagDataOffset); + if (runOptionsHandle === 0) { + throw new Error('Can\'t create run options'); + } + if ((options === null || options === void 0 ? void 0 : options.extra) !== undefined) { + (0, options_utils_1.iterateExtraOptions)(options.extra, '', new WeakSet(), (key, value) => { + const keyDataOffset = (0, string_utils_1.allocWasmString)(key, allocs); + const valueDataOffset = (0, string_utils_1.allocWasmString)(value, allocs); + if (wasm._OrtAddRunConfigEntry(runOptionsHandle, keyDataOffset, valueDataOffset) !== 0) { + throw new Error(`Can't set a run config entry: ${key} - ${value}`); + } + }); + } + return [runOptionsHandle, allocs]; + } + catch (e) { + if (runOptionsHandle !== 0) { + wasm._OrtReleaseRunOptions(runOptionsHandle); + } + allocs.forEach(wasm._free); + throw e; + } +}; +exports.setRunOptions = setRunOptions; + + +/***/ }), + +/***/ "./lib/wasm/session-handler.ts": +/*!*************************************!*\ + !*** ./lib/wasm/session-handler.ts ***! + \*************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.OnnxruntimeWebAssemblySessionHandler = void 0; +const fs_1 = __webpack_require__(/*! fs */ "?295d"); +const onnxruntime_common_1 = __webpack_require__(/*! onnxruntime-common */ "../common/dist/lib/index.js"); +const util_1 = __webpack_require__(/*! util */ "?cf98"); +const proxy_wrapper_1 = __webpack_require__(/*! ./proxy-wrapper */ "./lib/wasm/proxy-wrapper.ts"); +let ortInit; +const getLogLevel = (logLevel) => { + switch (logLevel) { + case 'verbose': + return 0; + case 'info': + return 1; + case 'warning': + return 2; + case 'error': + return 3; + case 'fatal': + return 4; + default: + throw new Error(`unsupported logging level: ${logLevel}`); + } +}; +class OnnxruntimeWebAssemblySessionHandler { + async createSessionAllocate(path) { + // fetch model from url and move to wasm heap. The arraybufffer that held the http + // response is freed once we return + const response = await fetch(path); + const arrayBuffer = await response.arrayBuffer(); + return (0, proxy_wrapper_1.createSessionAllocate)(new Uint8Array(arrayBuffer)); + } + async loadModel(pathOrBuffer, options) { + if (!ortInit) { + await (0, proxy_wrapper_1.initOrt)(onnxruntime_common_1.env.wasm.numThreads, getLogLevel(onnxruntime_common_1.env.logLevel)); + ortInit = true; + } + if (typeof pathOrBuffer === 'string') { + if (typeof fetch === 'undefined') { + // node + const model = await (0, util_1.promisify)(fs_1.readFile)(pathOrBuffer); + [this.sessionId, this.inputNames, this.outputNames] = await (0, proxy_wrapper_1.createSession)(model, options); + } + else { + // browser + // fetch model and move to wasm heap. + const modelData = await this.createSessionAllocate(pathOrBuffer); + // create the session + [this.sessionId, this.inputNames, this.outputNames] = await (0, proxy_wrapper_1.createSessionFinalize)(modelData, options); + } + } + else { + [this.sessionId, this.inputNames, this.outputNames] = await (0, proxy_wrapper_1.createSession)(pathOrBuffer, options); + } + } + async dispose() { + return (0, proxy_wrapper_1.releaseSession)(this.sessionId); + } + async run(feeds, fetches, options) { + const inputArray = []; + const inputIndices = []; + Object.entries(feeds).forEach(kvp => { + const name = kvp[0]; + const tensor = kvp[1]; + const index = this.inputNames.indexOf(name); + if (index === -1) { + throw new Error(`invalid input '${name}'`); + } + inputArray.push(tensor); + inputIndices.push(index); + }); + const outputIndices = []; + Object.entries(fetches).forEach(kvp => { + const name = kvp[0]; + // TODO: support pre-allocated output + const index = this.outputNames.indexOf(name); + if (index === -1) { + throw new Error(`invalid output '${name}'`); + } + outputIndices.push(index); + }); + const outputs = await (0, proxy_wrapper_1.run)(this.sessionId, inputIndices, inputArray.map(t => [t.type, t.dims, t.data]), outputIndices, options); + const result = {}; + for (let i = 0; i < outputs.length; i++) { + result[this.outputNames[outputIndices[i]]] = new onnxruntime_common_1.Tensor(outputs[i][0], outputs[i][2], outputs[i][1]); + } + return result; + } + startProfiling() { + // TODO: implement profiling + } + endProfiling() { + void (0, proxy_wrapper_1.endProfiling)(this.sessionId); + } +} +exports.OnnxruntimeWebAssemblySessionHandler = OnnxruntimeWebAssemblySessionHandler; + + +/***/ }), + +/***/ "./lib/wasm/session-options.ts": +/*!*************************************!*\ + !*** ./lib/wasm/session-options.ts ***! + \*************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.setSessionOptions = void 0; +const options_utils_1 = __webpack_require__(/*! ./options-utils */ "./lib/wasm/options-utils.ts"); +const string_utils_1 = __webpack_require__(/*! ./string-utils */ "./lib/wasm/string-utils.ts"); +const wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ "./lib/wasm/wasm-factory.ts"); +const getGraphOptimzationLevel = (graphOptimizationLevel) => { + switch (graphOptimizationLevel) { + case 'disabled': + return 0; + case 'basic': + return 1; + case 'extended': + return 2; + case 'all': + return 99; + default: + throw new Error(`unsupported graph optimization level: ${graphOptimizationLevel}`); + } +}; +const getExecutionMode = (executionMode) => { + switch (executionMode) { + case 'sequential': + return 0; + case 'parallel': + return 1; + default: + throw new Error(`unsupported execution mode: ${executionMode}`); + } +}; +const appendDefaultOptions = (options) => { + if (!options.extra) { + options.extra = {}; + } + if (!options.extra.session) { + options.extra.session = {}; + } + const session = options.extra.session; + if (!session.use_ort_model_bytes_directly) { + // eslint-disable-next-line camelcase + session.use_ort_model_bytes_directly = '1'; + } +}; +const setExecutionProviders = (sessionOptionsHandle, executionProviders, allocs) => { + for (const ep of executionProviders) { + let epName = typeof ep === 'string' ? ep : ep.name; + // check EP name + switch (epName) { + case 'xnnpack': + epName = 'XNNPACK'; + break; + case 'wasm': + case 'cpu': + continue; + default: + throw new Error(`not supported EP: ${epName}`); + } + const epNameDataOffset = (0, string_utils_1.allocWasmString)(epName, allocs); + if ((0, wasm_factory_1.getInstance)()._OrtAppendExecutionProvider(sessionOptionsHandle, epNameDataOffset) !== 0) { + throw new Error(`Can't append execution provider: ${epName}`); + } + } +}; +const setSessionOptions = (options) => { + const wasm = (0, wasm_factory_1.getInstance)(); + let sessionOptionsHandle = 0; + const allocs = []; + const sessionOptions = options || {}; + appendDefaultOptions(sessionOptions); + try { + if ((options === null || options === void 0 ? void 0 : options.graphOptimizationLevel) === undefined) { + sessionOptions.graphOptimizationLevel = 'all'; + } + const graphOptimizationLevel = getGraphOptimzationLevel(sessionOptions.graphOptimizationLevel); + if ((options === null || options === void 0 ? void 0 : options.enableCpuMemArena) === undefined) { + sessionOptions.enableCpuMemArena = true; + } + if ((options === null || options === void 0 ? void 0 : options.enableMemPattern) === undefined) { + sessionOptions.enableMemPattern = true; + } + if ((options === null || options === void 0 ? void 0 : options.executionMode) === undefined) { + sessionOptions.executionMode = 'sequential'; + } + const executionMode = getExecutionMode(sessionOptions.executionMode); + let logIdDataOffset = 0; + if ((options === null || options === void 0 ? void 0 : options.logId) !== undefined) { + logIdDataOffset = (0, string_utils_1.allocWasmString)(options.logId, allocs); + } + if ((options === null || options === void 0 ? void 0 : options.logSeverityLevel) === undefined) { + sessionOptions.logSeverityLevel = 2; // Default to warning + } + else if (typeof options.logSeverityLevel !== 'number' || !Number.isInteger(options.logSeverityLevel) || + options.logSeverityLevel < 0 || options.logSeverityLevel > 4) { + throw new Error(`log serverity level is not valid: ${options.logSeverityLevel}`); + } + if ((options === null || options === void 0 ? void 0 : options.logVerbosityLevel) === undefined) { + sessionOptions.logVerbosityLevel = 0; // Default to 0 + } + else if (typeof options.logVerbosityLevel !== 'number' || !Number.isInteger(options.logVerbosityLevel)) { + throw new Error(`log verbosity level is not valid: ${options.logVerbosityLevel}`); + } + if ((options === null || options === void 0 ? void 0 : options.enableProfiling) === undefined) { + sessionOptions.enableProfiling = false; + } + sessionOptionsHandle = wasm._OrtCreateSessionOptions(graphOptimizationLevel, !!sessionOptions.enableCpuMemArena, !!sessionOptions.enableMemPattern, executionMode, !!sessionOptions.enableProfiling, 0, logIdDataOffset, sessionOptions.logSeverityLevel, sessionOptions.logVerbosityLevel); + if (sessionOptionsHandle === 0) { + throw new Error('Can\'t create session options'); + } + if (options === null || options === void 0 ? void 0 : options.executionProviders) { + setExecutionProviders(sessionOptionsHandle, options.executionProviders, allocs); + } + if ((options === null || options === void 0 ? void 0 : options.extra) !== undefined) { + (0, options_utils_1.iterateExtraOptions)(options.extra, '', new WeakSet(), (key, value) => { + const keyDataOffset = (0, string_utils_1.allocWasmString)(key, allocs); + const valueDataOffset = (0, string_utils_1.allocWasmString)(value, allocs); + if (wasm._OrtAddSessionConfigEntry(sessionOptionsHandle, keyDataOffset, valueDataOffset) !== 0) { + throw new Error(`Can't set a session config entry: ${key} - ${value}`); + } + }); + } + return [sessionOptionsHandle, allocs]; + } + catch (e) { + if (sessionOptionsHandle !== 0) { + wasm._OrtReleaseSessionOptions(sessionOptionsHandle); + } + allocs.forEach(wasm._free); + throw e; + } +}; +exports.setSessionOptions = setSessionOptions; + + +/***/ }), + +/***/ "./lib/wasm/string-utils.ts": +/*!**********************************!*\ + !*** ./lib/wasm/string-utils.ts ***! + \**********************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.allocWasmString = void 0; +const wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ "./lib/wasm/wasm-factory.ts"); +const allocWasmString = (data, allocs) => { + const wasm = (0, wasm_factory_1.getInstance)(); + const dataLength = wasm.lengthBytesUTF8(data) + 1; + const dataOffset = wasm._malloc(dataLength); + wasm.stringToUTF8(data, dataOffset, dataLength); + allocs.push(dataOffset); + return dataOffset; +}; +exports.allocWasmString = allocWasmString; + + +/***/ }), + +/***/ "./lib/wasm/wasm-core-impl.ts": +/*!************************************!*\ + !*** ./lib/wasm/wasm-core-impl.ts ***! + \************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + +"use strict"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.extractTransferableBuffers = exports.endProfiling = exports.run = exports.releaseSession = exports.createSession = exports.createSessionFinalize = exports.createSessionAllocate = exports.initOrt = void 0; +const run_options_1 = __webpack_require__(/*! ./run-options */ "./lib/wasm/run-options.ts"); +const session_options_1 = __webpack_require__(/*! ./session-options */ "./lib/wasm/session-options.ts"); +const string_utils_1 = __webpack_require__(/*! ./string-utils */ "./lib/wasm/string-utils.ts"); +const wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ "./lib/wasm/wasm-factory.ts"); +/** + * initialize ORT environment. + * @param numThreads SetGlobalIntraOpNumThreads(numThreads) + * @param loggingLevel CreateEnv(static_cast(logging_level)) + */ +const initOrt = (numThreads, loggingLevel) => { + const errorCode = (0, wasm_factory_1.getInstance)()._OrtInit(numThreads, loggingLevel); + if (errorCode !== 0) { + throw new Error(`Can't initialize onnxruntime. error code = ${errorCode}`); + } +}; +exports.initOrt = initOrt; +const activeSessions = new Map(); +/** + * create an instance of InferenceSession. + * @returns the metadata of InferenceSession. 0-value handle for failure. + */ +const createSessionAllocate = (model) => { + const wasm = (0, wasm_factory_1.getInstance)(); + const modelDataOffset = wasm._malloc(model.byteLength); + wasm.HEAPU8.set(model, modelDataOffset); + return [modelDataOffset, model.byteLength]; +}; +exports.createSessionAllocate = createSessionAllocate; +const createSessionFinalize = (modelData, options) => { + const wasm = (0, wasm_factory_1.getInstance)(); + let sessionHandle = 0; + let sessionOptionsHandle = 0; + let allocs = []; + try { + [sessionOptionsHandle, allocs] = (0, session_options_1.setSessionOptions)(options); + sessionHandle = wasm._OrtCreateSession(modelData[0], modelData[1], sessionOptionsHandle); + if (sessionHandle === 0) { + throw new Error('Can\'t create a session'); + } + } + finally { + wasm._free(modelData[0]); + wasm._OrtReleaseSessionOptions(sessionOptionsHandle); + allocs.forEach(wasm._free); + } + const inputCount = wasm._OrtGetInputCount(sessionHandle); + const outputCount = wasm._OrtGetOutputCount(sessionHandle); + const inputNames = []; + const inputNamesUTF8Encoded = []; + const outputNames = []; + const outputNamesUTF8Encoded = []; + for (let i = 0; i < inputCount; i++) { + const name = wasm._OrtGetInputName(sessionHandle, i); + if (name === 0) { + throw new Error('Can\'t get an input name'); + } + inputNamesUTF8Encoded.push(name); + inputNames.push(wasm.UTF8ToString(name)); + } + for (let i = 0; i < outputCount; i++) { + const name = wasm._OrtGetOutputName(sessionHandle, i); + if (name === 0) { + throw new Error('Can\'t get an output name'); + } + outputNamesUTF8Encoded.push(name); + outputNames.push(wasm.UTF8ToString(name)); + } + activeSessions.set(sessionHandle, [sessionHandle, inputNamesUTF8Encoded, outputNamesUTF8Encoded]); + return [sessionHandle, inputNames, outputNames]; +}; +exports.createSessionFinalize = createSessionFinalize; +/** + * create an instance of InferenceSession. + * @returns the metadata of InferenceSession. 0-value handle for failure. + */ +const createSession = (model, options) => { + const modelData = (0, exports.createSessionAllocate)(model); + return (0, exports.createSessionFinalize)(modelData, options); +}; +exports.createSession = createSession; +const releaseSession = (sessionId) => { + const wasm = (0, wasm_factory_1.getInstance)(); + const session = activeSessions.get(sessionId); + if (!session) { + throw new Error('invalid session id'); + } + const sessionHandle = session[0]; + const inputNamesUTF8Encoded = session[1]; + const outputNamesUTF8Encoded = session[2]; + inputNamesUTF8Encoded.forEach(wasm._OrtFree); + outputNamesUTF8Encoded.forEach(wasm._OrtFree); + wasm._OrtReleaseSession(sessionHandle); + activeSessions.delete(sessionId); +}; +exports.releaseSession = releaseSession; +const tensorDataTypeStringToEnum = (type) => { + switch (type) { + case 'int8': + return 3 /* DataType.int8 */; + case 'uint8': + return 2 /* DataType.uint8 */; + case 'bool': + return 9 /* DataType.bool */; + case 'int16': + return 5 /* DataType.int16 */; + case 'uint16': + return 4 /* DataType.uint16 */; + case 'int32': + return 6 /* DataType.int32 */; + case 'uint32': + return 12 /* DataType.uint32 */; + case 'float32': + return 1 /* DataType.float */; + case 'float64': + return 11 /* DataType.double */; + case 'string': + return 8 /* DataType.string */; + case 'int64': + return 7 /* DataType.int64 */; + case 'uint64': + return 13 /* DataType.uint64 */; + default: + throw new Error(`unsupported data type: ${type}`); + } +}; +const tensorDataTypeEnumToString = (typeProto) => { + switch (typeProto) { + case 3 /* DataType.int8 */: + return 'int8'; + case 2 /* DataType.uint8 */: + return 'uint8'; + case 9 /* DataType.bool */: + return 'bool'; + case 5 /* DataType.int16 */: + return 'int16'; + case 4 /* DataType.uint16 */: + return 'uint16'; + case 6 /* DataType.int32 */: + return 'int32'; + case 12 /* DataType.uint32 */: + return 'uint32'; + case 1 /* DataType.float */: + return 'float32'; + case 11 /* DataType.double */: + return 'float64'; + case 8 /* DataType.string */: + return 'string'; + case 7 /* DataType.int64 */: + return 'int64'; + case 13 /* DataType.uint64 */: + return 'uint64'; + default: + throw new Error(`unsupported data type: ${typeProto}`); + } +}; +const numericTensorTypeToTypedArray = (type) => { + switch (type) { + case 'float32': + return Float32Array; + case 'uint8': + return Uint8Array; + case 'int8': + return Int8Array; + case 'uint16': + return Uint16Array; + case 'int16': + return Int16Array; + case 'int32': + return Int32Array; + case 'bool': + return Uint8Array; + case 'float64': + return Float64Array; + case 'uint32': + return Uint32Array; + case 'int64': + return BigInt64Array; + case 'uint64': + return BigUint64Array; + default: + throw new Error(`unsupported type: ${type}`); + } +}; +/** + * perform inference run + */ +const run = (sessionId, inputIndices, inputs, outputIndices, options) => { + const wasm = (0, wasm_factory_1.getInstance)(); + const session = activeSessions.get(sessionId); + if (!session) { + throw new Error('invalid session id'); + } + const sessionHandle = session[0]; + const inputNamesUTF8Encoded = session[1]; + const outputNamesUTF8Encoded = session[2]; + const inputCount = inputIndices.length; + const outputCount = outputIndices.length; + let runOptionsHandle = 0; + let runOptionsAllocs = []; + const inputValues = []; + const inputAllocs = []; + try { + [runOptionsHandle, runOptionsAllocs] = (0, run_options_1.setRunOptions)(options); + // create input tensors + for (let i = 0; i < inputCount; i++) { + const dataType = inputs[i][0]; + const dims = inputs[i][1]; + const data = inputs[i][2]; + let dataOffset; + let dataByteLength; + if (Array.isArray(data)) { + // string tensor + dataByteLength = 4 * data.length; + dataOffset = wasm._malloc(dataByteLength); + inputAllocs.push(dataOffset); + let dataIndex = dataOffset / 4; + for (let i = 0; i < data.length; i++) { + if (typeof data[i] !== 'string') { + throw new TypeError(`tensor data at index ${i} is not a string`); + } + wasm.HEAPU32[dataIndex++] = (0, string_utils_1.allocWasmString)(data[i], inputAllocs); + } + } + else { + dataByteLength = data.byteLength; + dataOffset = wasm._malloc(dataByteLength); + inputAllocs.push(dataOffset); + wasm.HEAPU8.set(new Uint8Array(data.buffer, data.byteOffset, dataByteLength), dataOffset); + } + const stack = wasm.stackSave(); + const dimsOffset = wasm.stackAlloc(4 * dims.length); + try { + let dimIndex = dimsOffset / 4; + dims.forEach(d => wasm.HEAP32[dimIndex++] = d); + const tensor = wasm._OrtCreateTensor(tensorDataTypeStringToEnum(dataType), dataOffset, dataByteLength, dimsOffset, dims.length); + if (tensor === 0) { + throw new Error('Can\'t create a tensor'); + } + inputValues.push(tensor); + } + finally { + wasm.stackRestore(stack); + } + } + const beforeRunStack = wasm.stackSave(); + const inputValuesOffset = wasm.stackAlloc(inputCount * 4); + const inputNamesOffset = wasm.stackAlloc(inputCount * 4); + const outputValuesOffset = wasm.stackAlloc(outputCount * 4); + const outputNamesOffset = wasm.stackAlloc(outputCount * 4); + try { + let inputValuesIndex = inputValuesOffset / 4; + let inputNamesIndex = inputNamesOffset / 4; + let outputValuesIndex = outputValuesOffset / 4; + let outputNamesIndex = outputNamesOffset / 4; + for (let i = 0; i < inputCount; i++) { + wasm.HEAPU32[inputValuesIndex++] = inputValues[i]; + wasm.HEAPU32[inputNamesIndex++] = inputNamesUTF8Encoded[inputIndices[i]]; + } + for (let i = 0; i < outputCount; i++) { + wasm.HEAPU32[outputValuesIndex++] = 0; + wasm.HEAPU32[outputNamesIndex++] = outputNamesUTF8Encoded[outputIndices[i]]; + } + // support RunOptions + let errorCode = wasm._OrtRun(sessionHandle, inputNamesOffset, inputValuesOffset, inputCount, outputNamesOffset, outputCount, outputValuesOffset, runOptionsHandle); + const output = []; + if (errorCode === 0) { + for (let i = 0; i < outputCount; i++) { + const tensor = wasm.HEAPU32[outputValuesOffset / 4 + i]; + const beforeGetTensorDataStack = wasm.stackSave(); + // stack allocate 4 pointer value + const tensorDataOffset = wasm.stackAlloc(4 * 4); + let type, dataOffset = 0; + try { + errorCode = wasm._OrtGetTensorData(tensor, tensorDataOffset, tensorDataOffset + 4, tensorDataOffset + 8, tensorDataOffset + 12); + if (errorCode !== 0) { + throw new Error(`Can't access output tensor data. error code = ${errorCode}`); + } + let tensorDataIndex = tensorDataOffset / 4; + const dataType = wasm.HEAPU32[tensorDataIndex++]; + dataOffset = wasm.HEAPU32[tensorDataIndex++]; + const dimsOffset = wasm.HEAPU32[tensorDataIndex++]; + const dimsLength = wasm.HEAPU32[tensorDataIndex++]; + const dims = []; + for (let i = 0; i < dimsLength; i++) { + dims.push(wasm.HEAPU32[dimsOffset / 4 + i]); + } + wasm._OrtFree(dimsOffset); + const size = dims.length === 0 ? 1 : dims.reduce((a, b) => a * b); + type = tensorDataTypeEnumToString(dataType); + if (type === 'string') { + const stringData = []; + let dataIndex = dataOffset / 4; + for (let i = 0; i < size; i++) { + const offset = wasm.HEAPU32[dataIndex++]; + const maxBytesToRead = i === size - 1 ? undefined : wasm.HEAPU32[dataIndex] - offset; + stringData.push(wasm.UTF8ToString(offset, maxBytesToRead)); + } + output.push([type, dims, stringData]); + } + else { + const typedArrayConstructor = numericTensorTypeToTypedArray(type); + const data = new typedArrayConstructor(size); + new Uint8Array(data.buffer, data.byteOffset, data.byteLength) + .set(wasm.HEAPU8.subarray(dataOffset, dataOffset + data.byteLength)); + output.push([type, dims, data]); + } + } + finally { + wasm.stackRestore(beforeGetTensorDataStack); + if (type === 'string' && dataOffset) { + wasm._free(dataOffset); + } + wasm._OrtReleaseTensor(tensor); + } + } + } + if (errorCode === 0) { + return output; + } + else { + throw new Error(`failed to call OrtRun(). error code = ${errorCode}.`); + } + } + finally { + wasm.stackRestore(beforeRunStack); + } + } + finally { + inputValues.forEach(wasm._OrtReleaseTensor); + inputAllocs.forEach(wasm._free); + wasm._OrtReleaseRunOptions(runOptionsHandle); + runOptionsAllocs.forEach(wasm._free); + } +}; +exports.run = run; +/** + * end profiling + */ +const endProfiling = (sessionId) => { + const wasm = (0, wasm_factory_1.getInstance)(); + const session = activeSessions.get(sessionId); + if (!session) { + throw new Error('invalid session id'); + } + const sessionHandle = session[0]; + // profile file name is not used yet, but it must be freed. + const profileFileName = wasm._OrtEndProfiling(sessionHandle); + if (profileFileName === 0) { + throw new Error('Can\'t get an profile file name'); + } + wasm._OrtFree(profileFileName); +}; +exports.endProfiling = endProfiling; +const extractTransferableBuffers = (tensors) => { + const buffers = []; + for (const tensor of tensors) { + const data = tensor[2]; + if (!Array.isArray(data) && data.buffer) { + buffers.push(data.buffer); + } + } + return buffers; +}; +exports.extractTransferableBuffers = extractTransferableBuffers; + + +/***/ }), + +/***/ "./lib/wasm/wasm-factory.ts": +/*!**********************************!*\ + !*** ./lib/wasm/wasm-factory.ts ***! + \**********************************/ +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; +var __dirname = "/"; + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.dispose = exports.getInstance = exports.initializeWebAssembly = void 0; +const path = __importStar(__webpack_require__(/*! path */ "?7aa5")); +const ort_wasm_js_1 = __importDefault(__webpack_require__(/*! ./binding/ort-wasm.js */ "./lib/wasm/binding/ort-wasm.js")); +const ortWasmFactoryThreaded = +// eslint-disable-next-line @typescript-eslint/no-require-imports + true ? __webpack_require__(/*! ./binding/ort-wasm-threaded.js */ "./lib/wasm/binding/ort-wasm-threaded.js") : 0; +let wasm; +let initialized = false; +let initializing = false; +let aborted = false; +const isMultiThreadSupported = () => { + try { + // If 'SharedArrayBuffer' is not available, WebAssembly threads will not work. + if (typeof SharedArrayBuffer === 'undefined') { + return false; + } + // Test for transferability of SABs (for browsers. needed for Firefox) + // https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ + if (typeof MessageChannel !== 'undefined') { + new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)); + } + // Test for WebAssembly threads capability (for both browsers and Node.js) + // This typed array is a WebAssembly program containing threaded instructions. + return WebAssembly.validate(new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 5, + 4, 1, 3, 1, 1, 10, 11, 1, 9, 0, 65, 0, 254, 16, 2, 0, 26, 11 + ])); + } + catch (e) { + return false; + } +}; +const isSimdSupported = () => { + try { + // Test for WebAssembly SIMD capability (for both browsers and Node.js) + // This typed array is a WebAssembly program containing SIMD instructions. + // The binary data is generated from the following code by wat2wasm: + // + // (module + // (type $t0 (func)) + // (func $f0 (type $t0) + // (drop + // (i32x4.dot_i16x8_s + // (i8x16.splat + // (i32.const 0)) + // (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))))) + return WebAssembly.validate(new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 30, 1, 28, 0, 65, 0, + 253, 15, 253, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 253, 186, 1, 26, 11 + ])); + } + catch (e) { + return false; + } +}; +const getWasmFileName = (useSimd, useThreads) => { + if (useThreads) { + return useSimd ? 'ort-wasm-simd-threaded.wasm' : 'ort-wasm-threaded.wasm'; + } + else { + return useSimd ? 'ort-wasm-simd.wasm' : 'ort-wasm.wasm'; + } +}; +const initializeWebAssembly = async (flags) => { + if (initialized) { + return Promise.resolve(); + } + if (initializing) { + throw new Error('multiple calls to \'initializeWebAssembly()\' detected.'); + } + if (aborted) { + throw new Error('previous call to \'initializeWebAssembly()\' failed.'); + } + initializing = true; + // wasm flags are already initialized + const timeout = flags.initTimeout; + const numThreads = flags.numThreads; + const simd = flags.simd; + const useThreads = numThreads > 1 && isMultiThreadSupported(); + const useSimd = simd && isSimdSupported(); + const wasmPrefixOverride = typeof flags.wasmPaths === 'string' ? flags.wasmPaths : undefined; + const wasmFileName = getWasmFileName(false, useThreads); + const wasmOverrideFileName = getWasmFileName(useSimd, useThreads); + const wasmPathOverride = typeof flags.wasmPaths === 'object' ? flags.wasmPaths[wasmOverrideFileName] : undefined; + let isTimeout = false; + const tasks = []; + // promise for timeout + if (timeout > 0) { + tasks.push(new Promise((resolve) => { + setTimeout(() => { + isTimeout = true; + resolve(); + }, timeout); + })); + } + // promise for module initialization + tasks.push(new Promise((resolve, reject) => { + const factory = useThreads ? ortWasmFactoryThreaded : ort_wasm_js_1.default; + const config = { + locateFile: (fileName, scriptDirectory) => { + if ( true && useThreads && fileName.endsWith('.worker.js') && + typeof Blob !== 'undefined') { + return URL.createObjectURL(new Blob([ + // This require() function is handled by webpack to load file content of the corresponding .worker.js + // eslint-disable-next-line @typescript-eslint/no-require-imports + __webpack_require__(/*! ./binding/ort-wasm-threaded.worker.js */ "./lib/wasm/binding/ort-wasm-threaded.worker.js") + ], { type: 'text/javascript' })); + } + if (fileName === wasmFileName) { + const prefix = wasmPrefixOverride !== null && wasmPrefixOverride !== void 0 ? wasmPrefixOverride : scriptDirectory; + return wasmPathOverride !== null && wasmPathOverride !== void 0 ? wasmPathOverride : prefix + wasmOverrideFileName; + } + return scriptDirectory + fileName; + } + }; + if ( true && useThreads) { + if (typeof Blob === 'undefined') { + config.mainScriptUrlOrBlob = path.join(__dirname, 'ort-wasm-threaded.js'); + } + else { + const scriptSourceCode = `var ortWasmThreaded=(function(){var _scriptDir;return ${factory.toString()}})();`; + config.mainScriptUrlOrBlob = new Blob([scriptSourceCode], { type: 'text/javascript' }); + } + } + factory(config).then( + // wasm module initialized successfully + module => { + initializing = false; + initialized = true; + wasm = module; + resolve(); + }, + // wasm module failed to initialize + (what) => { + initializing = false; + aborted = true; + reject(what); + }); + })); + await Promise.race(tasks); + if (isTimeout) { + throw new Error(`WebAssembly backend initializing failed due to timeout: ${timeout}ms`); + } +}; +exports.initializeWebAssembly = initializeWebAssembly; +const getInstance = () => { + if (initialized && wasm) { + return wasm; + } + throw new Error('WebAssembly is not initialized yet.'); +}; +exports.getInstance = getInstance; +const dispose = () => { + var _a; + if (initialized && !initializing && !aborted) { + initializing = true; + (_a = wasm.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads(); + wasm = undefined; + initializing = false; + initialized = false; + aborted = true; + } +}; +exports.dispose = dispose; + + +/***/ }), + +/***/ "./node_modules/worker-loader/dist/cjs.js?inline=no-fallback!./lib/wasm/proxy-worker/main.ts": +/*!***************************************************************************************************!*\ + !*** ./node_modules/worker-loader/dist/cjs.js?inline=no-fallback!./lib/wasm/proxy-worker/main.ts ***! + \***************************************************************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ Worker_fn) +/* harmony export */ }); +/* harmony import */ var _node_modules_worker_loader_dist_runtime_inline_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! !!../../../node_modules/worker-loader/dist/runtime/inline.js */ "./node_modules/worker-loader/dist/runtime/inline.js"); +/* harmony import */ var _node_modules_worker_loader_dist_runtime_inline_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_worker_loader_dist_runtime_inline_js__WEBPACK_IMPORTED_MODULE_0__); + + + +function Worker_fn() { + return _node_modules_worker_loader_dist_runtime_inline_js__WEBPACK_IMPORTED_MODULE_0___default()("/*!\n* ONNX Runtime Web v1.14.0\n* Copyright (c) Microsoft Corporation. All rights reserved.\n* Licensed under the MIT License.\n*/\n/******/ (() => { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ \"./lib/wasm/binding/ort-wasm-threaded.js\":\n/*!***********************************************!*\\\n !*** ./lib/wasm/binding/ort-wasm-threaded.js ***!\n \\***********************************************/\n/***/ ((module, __unused_webpack_exports, __webpack_require__) => {\n\nvar __filename = \"/index.js\";\nvar __dirname = \"/\";\n\r\nvar ortWasmThreaded = (() => {\r\n var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;\r\n if (true) _scriptDir = _scriptDir || __filename;\r\n return (\r\nfunction(ortWasmThreaded) {\r\n ortWasmThreaded = ortWasmThreaded || {};\r\n\r\n\r\nfunction d(){m.buffer!=n&&p(m.buffer);return aa}function q(){m.buffer!=n&&p(m.buffer);return ba}function r(){m.buffer!=n&&p(m.buffer);return ca}function v(){m.buffer!=n&&p(m.buffer);return da}function ea(){m.buffer!=n&&p(m.buffer);return fa}var x;x||(x=typeof ortWasmThreaded !== 'undefined' ? ortWasmThreaded : {});var ha,ia;x.ready=new Promise(function(a,b){ha=a;ia=b});\r\nvar ja=Object.assign({},x),ka=\"./this.program\",la=(a,b)=>{throw b;},ma=\"object\"==typeof window,y=\"function\"==typeof importScripts,B=\"object\"==typeof process&&\"object\"==typeof process.versions&&\"string\"==typeof process.versions.node,C=x.ENVIRONMENT_IS_PTHREAD||!1,D=\"\";function na(a){return x.locateFile?x.locateFile(a,D):D+a}var oa,pa,qa,fs,ra,sa;\r\nif(B){D=y?(__webpack_require__(/*! path */ \"?75c6\").dirname)(D)+\"/\":__dirname+\"/\";sa=()=>{ra||(fs=__webpack_require__(/*! fs */ \"?63c8\"),ra=__webpack_require__(/*! path */ \"?75c6\"))};oa=function(b,c){sa();b=ra.normalize(b);return fs.readFileSync(b,c?void 0:\"utf8\")};qa=b=>{b=oa(b,!0);b.buffer||(b=new Uint8Array(b));return b};pa=(b,c,e)=>{sa();b=ra.normalize(b);fs.readFile(b,function(f,h){f?e(f):c(h.buffer)})};1{if(F())throw process.exitCode=b,c;c instanceof E||G(\"exiting due to exception: \"+c);process.exit(b)};x.inspect=function(){return\"[Emscripten Module object]\"};let a;try{a=__webpack_require__(/*! worker_threads */ \"?c6f7\")}catch(b){throw console.error('The \"worker_threads\" module is not supported in this node.js build - perhaps a newer version is needed?'),b;}__webpack_require__.g.Worker=a.Worker}else if(ma||y)y?D=self.location.href:\"undefined\"!=typeof document&&document.currentScript&&(D=document.currentScript.src),\r\n_scriptDir&&(D=_scriptDir),0!==D.indexOf(\"blob:\")?D=D.substr(0,D.replace(/[?#].*/,\"\").lastIndexOf(\"/\")+1):D=\"\",B||(oa=a=>{var b=new XMLHttpRequest;b.open(\"GET\",a,!1);b.send(null);return b.responseText},y&&(qa=a=>{var b=new XMLHttpRequest;b.open(\"GET\",a,!1);b.responseType=\"arraybuffer\";b.send(null);return new Uint8Array(b.response)}),pa=(a,b,c)=>{var e=new XMLHttpRequest;e.open(\"GET\",a,!0);e.responseType=\"arraybuffer\";e.onload=()=>{200==e.status||0==e.status&&e.response?b(e.response):c()};e.onerror=\r\nc;e.send(null)});B&&\"undefined\"==typeof performance&&(__webpack_require__.g.performance=(__webpack_require__(/*! perf_hooks */ \"?674f\").performance));var ta=console.log.bind(console),ua=console.warn.bind(console);B&&(sa(),ta=a=>fs.writeSync(1,a+\"\\n\"),ua=a=>fs.writeSync(2,a+\"\\n\"));var va=x.print||ta,G=x.printErr||ua;Object.assign(x,ja);ja=null;x.thisProgram&&(ka=x.thisProgram);x.quit&&(la=x.quit);var H;x.wasmBinary&&(H=x.wasmBinary);var noExitRuntime=x.noExitRuntime||!1;\"object\"!=typeof WebAssembly&&I(\"no native wasm support detected\");\r\nvar m,wa,xa=!1,ya=\"undefined\"!=typeof TextDecoder?new TextDecoder(\"utf8\"):void 0;\r\nfunction za(a,b,c){b>>>=0;var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e}\r\nfunction Aa(a,b){return(a>>>=0)?za(q(),a,b):\"\"}\r\nfunction Ba(a,b,c,e){c>>>=0;if(!(0=k){var l=a.charCodeAt(++h);k=65536+((k&1023)<<10)|l&1023}if(127>=k){if(c>=e)break;b[c++>>>0]=k}else{if(2047>=k){if(c+1>=e)break;b[c++>>>0]=192|k>>6}else{if(65535>=k){if(c+2>=e)break;b[c++>>>0]=224|k>>12}else{if(c+3>=e)break;b[c++>>>0]=240|k>>18;b[c++>>>0]=128|k>>12&63}b[c++>>>0]=128|k>>6&63}b[c++>>>0]=128|k&63}}b[c>>>0]=0;return c-f}\r\nfunction Ca(a){for(var b=0,c=0;c=e?b++:2047>=e?b+=2:55296<=e&&57343>=e?(b+=4,++c):b+=3}return b}var n,aa,ba,ca,da,fa;C&&(n=x.buffer);function p(a){n=a;x.HEAP8=aa=new Int8Array(a);x.HEAP16=new Int16Array(a);x.HEAP32=ca=new Int32Array(a);x.HEAPU8=ba=new Uint8Array(a);x.HEAPU16=new Uint16Array(a);x.HEAPU32=da=new Uint32Array(a);x.HEAPF32=new Float32Array(a);x.HEAPF64=fa=new Float64Array(a)}var Da=x.INITIAL_MEMORY||16777216;\r\nif(C)m=x.wasmMemory,n=x.buffer;else if(x.wasmMemory)m=x.wasmMemory;else if(m=new WebAssembly.Memory({initial:Da/65536,maximum:65536,shared:!0}),!(m.buffer instanceof SharedArrayBuffer))throw G(\"requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag\"),B&&console.log(\"(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)\"),\r\nError(\"bad memory\");m&&(n=m.buffer);Da=n.byteLength;p(n);var Ea,Fa=[],Ga=[],Ha=[],Ia=[],Ja=0;function F(){return noExitRuntime||0{c.time=performance.now();b.postMessage(c,a.Nc)};b.loaded&&(b.$b(),delete b.$b);return 0}function Sa(a){if(C)return Q(1,1,a);if(!F()){P.oc();if(x.onExit)x.onExit(a);xa=!0}la(a,new E(a))}\r\nfunction Ta(a,b){if(!b&&C)throw Ua(a),\"unwind\";F()||C||(Va(),R(Ha),Wa(0),Xa[1].length&&Ya(1,10),Xa[2].length&&Ya(2,10),P.oc());Sa(a)}\r\nvar P={Yb:[],ac:[],qc:[],Vb:{},fc:function(){C&&P.Ec()},Pc:function(){},Ec:function(){P.receiveObjectTransfer=P.Gc;P.threadInitTLS=P.pc;P.setExitStatus=P.nc;noExitRuntime=!1},nc:function(){},oc:function(){for(var a of Object.values(P.Vb))P.mc(a);for(a of P.Yb)a.terminate();P.Yb=[]},mc:function(a){var b=a.Ub;delete P.Vb[b];P.Yb.push(a);P.ac.splice(P.ac.indexOf(a),1);a.Ub=0;Za(b)},Gc:function(){},pc:function(){P.qc.forEach(a=>a())},Fc:function(a,b){a.onmessage=c=>{c=c.data;var e=c.cmd;a.Ub&&(P.Bc=a.Ub);\r\nif(c.targetThread&&c.targetThread!=$a()){var f=P.Vb[c.Qc];f?f.postMessage(c,c.transferList):G('Internal error! Worker sent a message \"'+e+'\" to target pthread '+c.targetThread+\", but that thread no longer exists!\")}else if(\"processProxyingQueue\"===e)ab(c.queue);else if(\"spawnThread\"===e)Ra(c);else if(\"cleanupThread\"===e)Qa(c.thread);else if(\"killThread\"===e)c=c.thread,e=P.Vb[c],delete P.Vb[c],e.terminate(),Za(c),P.ac.splice(P.ac.indexOf(e),1),e.Ub=0;else if(\"cancelThread\"===e)P.Vb[c.thread].postMessage({cmd:\"cancel\"});\r\nelse if(\"loaded\"===e)a.loaded=!0,b&&b(a),a.$b&&(a.$b(),delete a.$b);else if(\"print\"===e)va(\"Thread \"+c.threadId+\": \"+c.text);else if(\"printErr\"===e)G(\"Thread \"+c.threadId+\": \"+c.text);else if(\"alert\"===e)alert(\"Thread \"+c.threadId+\": \"+c.text);else if(\"setimmediate\"===c.target)a.postMessage(c);else if(\"onAbort\"===e){if(x.onAbort)x.onAbort(c.arg)}else e&&G(\"worker sent an unknown command \"+e);P.Bc=void 0};a.onerror=c=>{G(\"worker sent an error! \"+c.filename+\":\"+c.lineno+\": \"+c.message);throw c;};B&&\r\n(a.on(\"message\",function(c){a.onmessage({data:c})}),a.on(\"error\",function(c){a.onerror(c)}),a.on(\"detachedExit\",function(){}));a.postMessage({cmd:\"load\",urlOrBlob:x.mainScriptUrlOrBlob||_scriptDir,wasmMemory:m,wasmModule:wa})},yc:function(){var a=na(\"ort-wasm-threaded.worker.js\");P.Yb.push(new Worker(a))},Cc:function(){0==P.Yb.length&&(P.yc(),P.Fc(P.Yb[0]));return P.Yb.pop()}};x.PThread=P;function R(a){for(;0>2>>>0];a=r()[a+48>>2>>>0];cb(b,b-a);U(b)};function Ua(a){if(C)return Q(2,0,a);try{Ta(a)}catch(b){b instanceof E||\"unwind\"==b||la(1,b)}}var db=[];function V(a){var b=db[a];b||(a>=db.length&&(db.length=a+1),db[a]=b=Ea.get(a));return b}x.invokeEntryPoint=function(a,b){a=V(a)(b);F()?P.nc(a):eb(a)};function fb(a,b){d().set(a,b>>>0)}var gb=[],hb=0,W=0;\r\nfunction X(a){this.Zb=a;this.Sb=a-24;this.xc=function(b){v()[this.Sb+4>>2>>>0]=b};this.bc=function(){return v()[this.Sb+4>>2>>>0]};this.wc=function(b){v()[this.Sb+8>>2>>>0]=b};this.Dc=function(){return v()[this.Sb+8>>2>>>0]};this.rc=function(){r()[this.Sb>>2>>>0]=0};this.hc=function(b){b=b?1:0;d()[this.Sb+12>>0>>>0]=b};this.uc=function(){return 0!=d()[this.Sb+12>>0>>>0]};this.ic=function(b){b=b?1:0;d()[this.Sb+13>>0>>>0]=b};this.kc=function(){return 0!=d()[this.Sb+13>>0>>>0]};this.fc=function(b,c){this.cc(0);\r\nthis.xc(b);this.wc(c);this.rc();this.hc(!1);this.ic(!1)};this.sc=function(){Atomics.add(r(),this.Sb>>2,1)};this.Hc=function(){return 1===Atomics.sub(r(),this.Sb>>2,1)};this.cc=function(b){v()[this.Sb+16>>2>>>0]=b};this.tc=function(){return v()[this.Sb+16>>2>>>0]};this.vc=function(){if(ib(this.bc()))return v()[this.Zb>>2>>>0];var b=this.tc();return 0!==b?b:this.Zb}}function jb(a){return kb((new X(a)).Sb)}function lb(a,b,c,e){return C?Q(3,1,a,b,c,e):mb(a,b,c,e)}\r\nfunction mb(a,b,c,e){if(\"undefined\"==typeof SharedArrayBuffer)return G(\"Current environment does not support SharedArrayBuffer, pthreads are not available!\"),6;var f=[];if(C&&0===f.length)return lb(a,b,c,e);a={Ic:c,Ub:a,zc:e,Nc:f};return C?(a.Oc=\"spawnThread\",postMessage(a,f),0):Ra(a)}function nb(a,b,c){return C?Q(4,1,a,b,c):0}function ob(a,b){if(C)return Q(5,1,a,b)}function pb(a,b){if(C)return Q(6,1,a,b)}function qb(a,b,c){if(C)return Q(7,1,a,b,c)}function rb(a,b,c){return C?Q(8,1,a,b,c):0}\r\nfunction sb(a,b){if(C)return Q(9,1,a,b)}function tb(a,b,c){if(C)return Q(10,1,a,b,c)}function ub(a,b,c,e){if(C)return Q(11,1,a,b,c,e)}function vb(a,b,c,e){if(C)return Q(12,1,a,b,c,e)}function wb(a,b,c,e){if(C)return Q(13,1,a,b,c,e)}function xb(a){if(C)return Q(14,1,a)}function yb(a,b){if(C)return Q(15,1,a,b)}function zb(a,b,c){if(C)return Q(16,1,a,b,c)}function ab(a){Atomics.store(r(),a>>2,1);$a()&&Ab(a);Atomics.compareExchange(r(),a>>2,1,0)}x.executeNotifiedProxyingQueue=ab;\r\nfunction Bb(a){return v()[a>>>2]+4294967296*r()[a+4>>>2]}function Cb(a,b,c,e,f,h){return C?Q(17,1,a,b,c,e,f,h):-52}function Db(a,b,c,e,f,h){if(C)return Q(18,1,a,b,c,e,f,h)}function Eb(a){var b=Ca(a)+1,c=Fb(b);c&&Ba(a,d(),c,b);return c}\r\nfunction Gb(a,b,c){function e(t){return(t=t.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?t[1]:\"GMT\"}if(C)return Q(19,1,a,b,c);var f=(new Date).getFullYear(),h=new Date(f,0,1),k=new Date(f,6,1);f=h.getTimezoneOffset();var l=k.getTimezoneOffset(),u=Math.max(f,l);r()[a>>2>>>0]=60*u;r()[b>>2>>>0]=Number(f!=l);a=e(h);b=e(k);a=Eb(a);b=Eb(b);l>2>>>0]=a,v()[c+4>>2>>>0]=b):(v()[c>>2>>>0]=b,v()[c+4>>2>>>0]=a)}function Hb(a,b,c){Hb.Ac||(Hb.Ac=!0,Gb(a,b,c))}var Ib,Jb;\r\nJb=B?()=>{var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:C?()=>performance.now()-x.__performance_now_clock_drift:()=>performance.now();function Q(a,b){var c=arguments.length-2,e=arguments;return bb(()=>{for(var f=Kb(8*c),h=f>>3,k=0;k>>0]=l}return Lb(a,c,f,b)})}var Mb=[],Nb={};\r\nfunction Ob(){if(!Pb){var a={USER:\"web_user\",LOGNAME:\"web_user\",PATH:\"/\",PWD:\"/\",HOME:\"/home/web_user\",LANG:(\"object\"==typeof navigator&&navigator.languages&&navigator.languages[0]||\"C\").replace(\"-\",\"_\")+\".UTF-8\",_:ka||\"./this.program\"},b;for(b in Nb)void 0===Nb[b]?delete a[b]:a[b]=Nb[b];var c=[];for(b in a)c.push(b+\"=\"+a[b]);Pb=c}return Pb}var Pb;\r\nfunction Qb(a,b){if(C)return Q(20,1,a,b);var c=0;Ob().forEach(function(e,f){var h=b+c;f=v()[a+4*f>>2>>>0]=h;for(h=0;h>0>>>0]=e.charCodeAt(h);d()[f>>0>>>0]=0;c+=e.length+1});return 0}function Rb(a,b){if(C)return Q(21,1,a,b);var c=Ob();v()[a>>2>>>0]=c.length;var e=0;c.forEach(function(f){e+=f.length+1});v()[b>>2>>>0]=e;return 0}function Sb(a){return C?Q(22,1,a):52}function Tb(a,b,c,e){return C?Q(23,1,a,b,c,e):52}function Ub(a,b,c,e,f){return C?Q(24,1,a,b,c,e,f):70}\r\nvar Xa=[null,[],[]];function Ya(a,b){var c=Xa[a];0===b||10===b?((1===a?va:G)(za(c,0)),c.length=0):c.push(b)}function Vb(a,b,c,e){if(C)return Q(25,1,a,b,c,e);for(var f=0,h=0;h>2>>>0],l=v()[b+4>>2>>>0];b+=8;for(var u=0;u>>0]);f+=l}v()[e>>2>>>0]=f;return 0}var Y=0;\r\nfunction Wb(){if(\"object\"==typeof crypto&&\"function\"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(B)try{var b=__webpack_require__(Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'crypto'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));return()=>b.randomBytes(1)[0]}catch(c){}return()=>I(\"randomDevice\")}function Xb(a,b){Xb.lc||(Xb.lc=Wb());for(var c=0;c>0>>>0]=Xb.lc();return 0}function Yb(a){return 0===a%4&&(0!==a%100||0===a%400)}var Zb=[31,29,31,30,31,30,31,31,30,31,30,31],$b=[31,28,31,30,31,30,31,31,30,31,30,31];\r\nfunction ac(a){var b=Array(Ca(a)+1);Ba(a,b,0,b.length);return b}\r\nfunction bc(a,b,c,e){function f(g,w,z){for(g=\"number\"==typeof g?g.toString():g||\"\";g.lengthT?-1:0N-g.getDate())w-=N-g.getDate()+1,g.setDate(1),11>z?g.setMonth(z+1):(g.setMonth(0),g.setFullYear(g.getFullYear()+1));else{g.setDate(g.getDate()+w);break}}z=new Date(g.getFullYear()+1,0,4);w=l(new Date(g.getFullYear(),\r\n0,4));z=l(z);return 0>=k(w,g)?0>=k(z,g)?g.getFullYear()+1:g.getFullYear():g.getFullYear()-1}var t=r()[e+40>>2>>>0];e={Lc:r()[e>>2>>>0],Kc:r()[e+4>>2>>>0],dc:r()[e+8>>2>>>0],jc:r()[e+12>>2>>>0],ec:r()[e+16>>2>>>0],Xb:r()[e+20>>2>>>0],Tb:r()[e+24>>2>>>0],Wb:r()[e+28>>2>>>0],Rc:r()[e+32>>2>>>0],Jc:r()[e+36>>2>>>0],Mc:t?Aa(t):\"\"};c=Aa(c);t={\"%c\":\"%a %b %d %H:%M:%S %Y\",\"%D\":\"%m/%d/%y\",\"%F\":\"%Y-%m-%d\",\"%h\":\"%b\",\"%r\":\"%I:%M:%S %p\",\"%R\":\"%H:%M\",\"%T\":\"%H:%M:%S\",\"%x\":\"%m/%d/%y\",\"%X\":\"%H:%M:%S\",\"%Ec\":\"%c\",\"%EC\":\"%C\",\r\n\"%Ex\":\"%m/%d/%y\",\"%EX\":\"%H:%M:%S\",\"%Ey\":\"%y\",\"%EY\":\"%Y\",\"%Od\":\"%d\",\"%Oe\":\"%e\",\"%OH\":\"%H\",\"%OI\":\"%I\",\"%Om\":\"%m\",\"%OM\":\"%M\",\"%OS\":\"%S\",\"%Ou\":\"%u\",\"%OU\":\"%U\",\"%OV\":\"%V\",\"%Ow\":\"%w\",\"%OW\":\"%W\",\"%Oy\":\"%y\"};for(var A in t)c=c.replace(new RegExp(A,\"g\"),t[A]);var K=\"Sunday Monday Tuesday Wednesday Thursday Friday Saturday\".split(\" \"),J=\"January February March April May June July August September October November December\".split(\" \");t={\"%a\":function(g){return K[g.Tb].substring(0,3)},\"%A\":function(g){return K[g.Tb]},\r\n\"%b\":function(g){return J[g.ec].substring(0,3)},\"%B\":function(g){return J[g.ec]},\"%C\":function(g){return h((g.Xb+1900)/100|0,2)},\"%d\":function(g){return h(g.jc,2)},\"%e\":function(g){return f(g.jc,2,\" \")},\"%g\":function(g){return u(g).toString().substring(2)},\"%G\":function(g){return u(g)},\"%H\":function(g){return h(g.dc,2)},\"%I\":function(g){g=g.dc;0==g?g=12:12g.dc?\"AM\":\"PM\"},\"%S\":function(g){return h(g.Lc,2)},\"%t\":function(){return\"\\t\"},\"%u\":function(g){return g.Tb||7},\"%U\":function(g){return h(Math.floor((g.Wb+7-g.Tb)/7),2)},\"%V\":function(g){var w=Math.floor((g.Wb+7-(g.Tb+6)%7)/7);2>=(g.Tb+371-g.Wb-2)%7&&w++;if(w)53==w&&(z=(g.Tb+371-g.Wb)%7,4==z||3==z&&Yb(g.Xb)||(w=1));else{w=52;var z=(g.Tb+7-g.Wb-1)%7;(4==z||5==z&&Yb(g.Xb%400-1))&&w++}return h(w,\r\n2)},\"%w\":function(g){return g.Tb},\"%W\":function(g){return h(Math.floor((g.Wb+7-(g.Tb+6)%7)/7),2)},\"%y\":function(g){return(g.Xb+1900).toString().substring(2)},\"%Y\":function(g){return g.Xb+1900},\"%z\":function(g){g=g.Jc;var w=0<=g;g=Math.abs(g)/60;return(w?\"+\":\"-\")+String(\"0000\"+(g/60*100+g%60)).slice(-4)},\"%Z\":function(g){return g.Mc},\"%%\":function(){return\"%\"}};c=c.replace(/%%/g,\"\\x00\\x00\");for(A in t)c.includes(A)&&(c=c.replace(new RegExp(A,\"g\"),t[A](e)));c=c.replace(/\\0\\0/g,\"%\");A=ac(c);if(A.length>\r\nb)return 0;fb(A,a);return A.length-1}P.fc();\r\nvar cc=[null,Sa,Ua,lb,nb,ob,pb,qb,rb,sb,tb,ub,vb,wb,xb,yb,zb,Cb,Db,Gb,Qb,Rb,Sb,Tb,Ub,Vb],Pc={b:function(a){return Fb(a+24)+24},n:function(a){a=new X(a);a.uc()||(a.hc(!0),hb--);a.ic(!1);gb.push(a);a.sc();return a.vc()},ma:function(a){G(\"Unexpected exception thrown, this is not properly supported - aborting\");xa=!0;throw a;},x:function(){Z(0);var a=gb.pop();if(a.Hc()&&!a.kc()){var b=a.Dc();b&&V(b)(a.Zb);jb(a.Zb)}W=0},e:function(){var a=W;if(!a)return Y=0;var b=new X(a);b.cc(a);var c=b.bc();if(!c)return Y=\r\n0,a;for(var e=Array.prototype.slice.call(arguments),f=0;fab(e));else if(C)postMessage({targetThread:a,cmd:\"processProxyingQueue\",\r\nqueue:e});else{a=P.Vb[a];if(!a)return;a.postMessage({cmd:\"processProxyingQueue\",queue:e})}return 1},Ea:function(){return-1},Pa:function(a,b){a=new Date(1E3*Bb(a));r()[b>>2>>>0]=a.getUTCSeconds();r()[b+4>>2>>>0]=a.getUTCMinutes();r()[b+8>>2>>>0]=a.getUTCHours();r()[b+12>>2>>>0]=a.getUTCDate();r()[b+16>>2>>>0]=a.getUTCMonth();r()[b+20>>2>>>0]=a.getUTCFullYear()-1900;r()[b+24>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;r()[b+28>>2>>>0]=a},Qa:function(a,b){a=\r\nnew Date(1E3*Bb(a));r()[b>>2>>>0]=a.getSeconds();r()[b+4>>2>>>0]=a.getMinutes();r()[b+8>>2>>>0]=a.getHours();r()[b+12>>2>>>0]=a.getDate();r()[b+16>>2>>>0]=a.getMonth();r()[b+20>>2>>>0]=a.getFullYear()-1900;r()[b+24>>2>>>0]=a.getDay();var c=new Date(a.getFullYear(),0,1),e=(a.getTime()-c.getTime())/864E5|0;r()[b+28>>2>>>0]=e;r()[b+36>>2>>>0]=-(60*a.getTimezoneOffset());e=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();a=(e!=c&&a.getTimezoneOffset()==Math.min(c,e))|0;r()[b+\r\n32>>2>>>0]=a},Ra:function(a){var b=new Date(r()[a+20>>2>>>0]+1900,r()[a+16>>2>>>0],r()[a+12>>2>>>0],r()[a+8>>2>>>0],r()[a+4>>2>>>0],r()[a>>2>>>0],0),c=r()[a+32>>2>>>0],e=b.getTimezoneOffset(),f=new Date(b.getFullYear(),0,1),h=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),k=f.getTimezoneOffset(),l=Math.min(k,h);0>c?r()[a+32>>2>>>0]=Number(h!=k&&l==e):0>2>>>0]=b.getDay();c=(b.getTime()-f.getTime())/864E5|0;r()[a+28>>\r\n2>>>0]=c;r()[a>>2>>>0]=b.getSeconds();r()[a+4>>2>>>0]=b.getMinutes();r()[a+8>>2>>>0]=b.getHours();r()[a+12>>2>>>0]=b.getDate();r()[a+16>>2>>>0]=b.getMonth();return b.getTime()/1E3|0},Aa:Cb,Ba:Db,Sa:Hb,y:function(){I(\"\")},U:function(){if(!B&&!y){var a=\"Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread\";Ib||(Ib={});Ib[a]||(Ib[a]=1,B&&(a=\"warning: \"+a),G(a))}},ra:function(){return 4294901760},B:Jb,Ia:function(a,b,\r\nc){q().copyWithin(a>>>0,b>>>0,b+c>>>0)},F:function(){return B?(__webpack_require__(/*! os */ \"?aedb\").cpus)().length:navigator.hardwareConcurrency},Da:function(a,b,c){Mb.length=b;c>>=3;for(var e=0;e>>0];return(0>a?Pa[-a-1]:cc[a]).apply(null,Mb)},qa:function(a){var b=q().length;a>>>=0;if(a<=b||4294901760=c;c*=2){var e=b*(1+.2/c);e=Math.min(e,a+100663296);var f=Math;e=Math.max(a,e);f=f.min.call(f,4294901760,e+(65536-e%65536)%65536);a:{try{m.grow(f-n.byteLength+65535>>>16);p(m.buffer);\r\nvar h=1;break a}catch(k){}h=void 0}if(h)return!0}return!1},Na:function(){throw\"unwind\";},Ga:Qb,Ha:Rb,J:Ta,I:Sb,S:Tb,ga:Ub,R:Vb,d:function(){return Y},na:Xb,ia:fc,ja:gc,K:hc,f:ic,P:jc,Q:kc,k:lc,p:mc,q:nc,N:oc,s:pc,w:qc,L:rc,E:sc,aa:tc,_:uc,Z:vc,ca:wc,$:xc,ba:yc,Y:zc,g:Ac,r:Bc,i:Cc,ha:Dc,m:Ec,v:Fc,u:Gc,O:Hc,A:Ic,ka:Jc,C:Kc,D:Lc,fa:Mc,da:Nc,ea:Oc,o:function(a){return a},a:m||x.wasmMemory,G:function(a){Y=a},la:bc,z:function(a,b,c,e){return bc(a,b,c,e)}};\r\n(function(){function a(f,h){x.asm=f.exports;P.qc.push(x.asm.sb);Ea=x.asm.ub;Ga.unshift(x.asm.Va);wa=h;C||(L--,x.monitorRunDependencies&&x.monitorRunDependencies(L),0==L&&(null!==La&&(clearInterval(La),La=null),M&&(f=M,M=null,f())))}function b(f){a(f.instance,f.module)}function c(f){return Oa().then(function(h){return WebAssembly.instantiate(h,e)}).then(function(h){return h}).then(f,function(h){G(\"failed to asynchronously prepare wasm: \"+h);I(h)})}var e={a:Pc};C||(L++,x.monitorRunDependencies&&x.monitorRunDependencies(L));\r\nif(x.instantiateWasm)try{return x.instantiateWasm(e,a)}catch(f){return G(\"Module.instantiateWasm callback failed with error: \"+f),!1}(function(){return H||\"function\"!=typeof WebAssembly.instantiateStreaming||Ma()||O.startsWith(\"file://\")||B||\"function\"!=typeof fetch?c(b):fetch(O,{credentials:\"same-origin\"}).then(function(f){return WebAssembly.instantiateStreaming(f,e).then(b,function(h){G(\"wasm streaming compile failed: \"+h);G(\"falling back to ArrayBuffer instantiation\");return c(b)})})})().catch(ia);\r\nreturn{}})();x.___wasm_call_ctors=function(){return(x.___wasm_call_ctors=x.asm.Va).apply(null,arguments)};x._OrtInit=function(){return(x._OrtInit=x.asm.Wa).apply(null,arguments)};x._OrtCreateSessionOptions=function(){return(x._OrtCreateSessionOptions=x.asm.Xa).apply(null,arguments)};x._OrtAppendExecutionProvider=function(){return(x._OrtAppendExecutionProvider=x.asm.Ya).apply(null,arguments)};x._OrtAddSessionConfigEntry=function(){return(x._OrtAddSessionConfigEntry=x.asm.Za).apply(null,arguments)};\r\nx._OrtReleaseSessionOptions=function(){return(x._OrtReleaseSessionOptions=x.asm._a).apply(null,arguments)};x._OrtCreateSession=function(){return(x._OrtCreateSession=x.asm.$a).apply(null,arguments)};x._OrtReleaseSession=function(){return(x._OrtReleaseSession=x.asm.ab).apply(null,arguments)};x._OrtGetInputCount=function(){return(x._OrtGetInputCount=x.asm.bb).apply(null,arguments)};x._OrtGetOutputCount=function(){return(x._OrtGetOutputCount=x.asm.cb).apply(null,arguments)};\r\nx._OrtGetInputName=function(){return(x._OrtGetInputName=x.asm.db).apply(null,arguments)};x._OrtGetOutputName=function(){return(x._OrtGetOutputName=x.asm.eb).apply(null,arguments)};x._OrtFree=function(){return(x._OrtFree=x.asm.fb).apply(null,arguments)};x._OrtCreateTensor=function(){return(x._OrtCreateTensor=x.asm.gb).apply(null,arguments)};x._OrtGetTensorData=function(){return(x._OrtGetTensorData=x.asm.hb).apply(null,arguments)};\r\nx._OrtReleaseTensor=function(){return(x._OrtReleaseTensor=x.asm.ib).apply(null,arguments)};x._OrtCreateRunOptions=function(){return(x._OrtCreateRunOptions=x.asm.jb).apply(null,arguments)};x._OrtAddRunConfigEntry=function(){return(x._OrtAddRunConfigEntry=x.asm.kb).apply(null,arguments)};x._OrtReleaseRunOptions=function(){return(x._OrtReleaseRunOptions=x.asm.lb).apply(null,arguments)};x._OrtRun=function(){return(x._OrtRun=x.asm.mb).apply(null,arguments)};\r\nx._OrtEndProfiling=function(){return(x._OrtEndProfiling=x.asm.nb).apply(null,arguments)};var $a=x._pthread_self=function(){return($a=x._pthread_self=x.asm.ob).apply(null,arguments)},Fb=x._malloc=function(){return(Fb=x._malloc=x.asm.pb).apply(null,arguments)},kb=x._free=function(){return(kb=x._free=x.asm.qb).apply(null,arguments)},Wa=x._fflush=function(){return(Wa=x._fflush=x.asm.rb).apply(null,arguments)};x.__emscripten_tls_init=function(){return(x.__emscripten_tls_init=x.asm.sb).apply(null,arguments)};\r\nvar Va=x.___funcs_on_exit=function(){return(Va=x.___funcs_on_exit=x.asm.tb).apply(null,arguments)},ec=x.__emscripten_thread_init=function(){return(ec=x.__emscripten_thread_init=x.asm.vb).apply(null,arguments)};x.__emscripten_thread_crashed=function(){return(x.__emscripten_thread_crashed=x.asm.wb).apply(null,arguments)};\r\nvar Lb=x._emscripten_run_in_main_runtime_thread_js=function(){return(Lb=x._emscripten_run_in_main_runtime_thread_js=x.asm.xb).apply(null,arguments)},Ab=x.__emscripten_proxy_execute_task_queue=function(){return(Ab=x.__emscripten_proxy_execute_task_queue=x.asm.yb).apply(null,arguments)},Za=x.__emscripten_thread_free_data=function(){return(Za=x.__emscripten_thread_free_data=x.asm.zb).apply(null,arguments)},eb=x.__emscripten_thread_exit=function(){return(eb=x.__emscripten_thread_exit=x.asm.Ab).apply(null,\r\narguments)},Z=x._setThrew=function(){return(Z=x._setThrew=x.asm.Bb).apply(null,arguments)},cb=x._emscripten_stack_set_limits=function(){return(cb=x._emscripten_stack_set_limits=x.asm.Cb).apply(null,arguments)},S=x.stackSave=function(){return(S=x.stackSave=x.asm.Db).apply(null,arguments)},U=x.stackRestore=function(){return(U=x.stackRestore=x.asm.Eb).apply(null,arguments)},Kb=x.stackAlloc=function(){return(Kb=x.stackAlloc=x.asm.Fb).apply(null,arguments)},dc=x.___cxa_can_catch=function(){return(dc=x.___cxa_can_catch=\r\nx.asm.Gb).apply(null,arguments)},ib=x.___cxa_is_pointer_type=function(){return(ib=x.___cxa_is_pointer_type=x.asm.Hb).apply(null,arguments)},Qc=x.dynCall_j=function(){return(Qc=x.dynCall_j=x.asm.Ib).apply(null,arguments)},Rc=x.dynCall_iiiiij=function(){return(Rc=x.dynCall_iiiiij=x.asm.Jb).apply(null,arguments)},Sc=x.dynCall_jii=function(){return(Sc=x.dynCall_jii=x.asm.Kb).apply(null,arguments)},Tc=x.dynCall_viiiiij=function(){return(Tc=x.dynCall_viiiiij=x.asm.Lb).apply(null,arguments)},Uc=x.dynCall_vjji=\r\nfunction(){return(Uc=x.dynCall_vjji=x.asm.Mb).apply(null,arguments)},Vc=x.dynCall_viiijjjii=function(){return(Vc=x.dynCall_viiijjjii=x.asm.Nb).apply(null,arguments)},Wc=x.dynCall_iij=function(){return(Wc=x.dynCall_iij=x.asm.Ob).apply(null,arguments)},Xc=x.dynCall_ji=function(){return(Xc=x.dynCall_ji=x.asm.Pb).apply(null,arguments)},Yc=x.dynCall_iiiiiij=function(){return(Yc=x.dynCall_iiiiiij=x.asm.Qb).apply(null,arguments)},Zc=x.dynCall_iiij=function(){return(Zc=x.dynCall_iiij=x.asm.Rb).apply(null,\r\narguments)};function ic(a,b){var c=S();try{return V(a)(b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function Bc(a,b){var c=S();try{V(a)(b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function Cc(a,b,c){var e=S();try{V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function lc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function mc(a,b,c,e){var f=S();try{return V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}\r\nfunction qc(a,b,c,e,f,h,k){var l=S();try{return V(a)(b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function Ac(a){var b=S();try{V(a)()}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}}function pc(a,b,c,e,f,h){var k=S();try{return V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function nc(a,b,c,e,f){var h=S();try{return V(a)(b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function Ec(a,b,c,e){var f=S();try{V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}\r\nfunction Gc(a,b,c,e,f,h){var k=S();try{V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function Fc(a,b,c,e,f){var h=S();try{V(a)(b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function Ic(a,b,c,e,f,h,k,l){var u=S();try{V(a)(b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function kc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function jc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}\r\nfunction Jc(a,b,c,e,f,h,k,l,u){var t=S();try{V(a)(b,c,e,f,h,k,l,u)}catch(A){U(t);if(A!==A+0)throw A;Z(1,0)}}function Hc(a,b,c,e,f,h,k){var l=S();try{V(a)(b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function oc(a,b,c,e,f,h){var k=S();try{return V(a)(b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}function rc(a,b,c,e,f,h,k,l){var u=S();try{return V(a)(b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}\r\nfunction sc(a,b,c,e,f,h,k,l,u,t,A,K){var J=S();try{return V(a)(b,c,e,f,h,k,l,u,t,A,K)}catch(g){U(J);if(g!==g+0)throw g;Z(1,0)}}function Kc(a,b,c,e,f,h,k,l,u,t,A){var K=S();try{V(a)(b,c,e,f,h,k,l,u,t,A)}catch(J){U(K);if(J!==J+0)throw J;Z(1,0)}}function Lc(a,b,c,e,f,h,k,l,u,t,A,K,J,g,w,z){var N=S();try{V(a)(b,c,e,f,h,k,l,u,t,A,K,J,g,w,z)}catch(T){U(N);if(T!==T+0)throw T;Z(1,0)}}function hc(a){var b=S();try{return V(a)()}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}}\r\nfunction gc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function fc(a,b,c){var e=S();try{return V(a)(b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}function Dc(a,b,c,e){var f=S();try{V(a)(b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}function Mc(a,b,c,e,f,h,k,l){var u=S();try{Tc(a,b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function Oc(a,b,c,e,f,h){var k=S();try{Uc(a,b,c,e,f,h)}catch(l){U(k);if(l!==l+0)throw l;Z(1,0)}}\r\nfunction Nc(a,b,c,e,f,h,k,l,u,t,A,K){var J=S();try{Vc(a,b,c,e,f,h,k,l,u,t,A,K)}catch(g){U(J);if(g!==g+0)throw g;Z(1,0)}}function wc(a,b,c,e){var f=S();try{return Wc(a,b,c,e)}catch(h){U(f);if(h!==h+0)throw h;Z(1,0)}}function yc(a,b){var c=S();try{return Xc(a,b)}catch(e){U(c);if(e!==e+0)throw e;Z(1,0)}}function tc(a,b,c,e,f,h,k,l){var u=S();try{return Yc(a,b,c,e,f,h,k,l)}catch(t){U(u);if(t!==t+0)throw t;Z(1,0)}}function xc(a){var b=S();try{return Qc(a)}catch(c){U(b);if(c!==c+0)throw c;Z(1,0)}}\r\nfunction uc(a,b,c,e,f,h,k){var l=S();try{return Rc(a,b,c,e,f,h,k)}catch(u){U(l);if(u!==u+0)throw u;Z(1,0)}}function vc(a,b,c,e,f){var h=S();try{return Zc(a,b,c,e,f)}catch(k){U(h);if(k!==k+0)throw k;Z(1,0)}}function zc(a,b,c){var e=S();try{return Sc(a,b,c)}catch(f){U(e);if(f!==f+0)throw f;Z(1,0)}}x.UTF8ToString=Aa;x.stringToUTF8=function(a,b,c){return Ba(a,q(),b,c)};x.lengthBytesUTF8=Ca;x.keepRuntimeAlive=F;x.wasmMemory=m;x.stackSave=S;x.stackRestore=U;x.stackAlloc=Kb;x.ExitStatus=E;x.PThread=P;var $c;\r\nM=function ad(){$c||bd();$c||(M=ad)};\r\nfunction bd(){function a(){if(!$c&&($c=!0,x.calledRun=!0,!xa)){C||R(Ga);ha(x);if(x.onRuntimeInitialized)x.onRuntimeInitialized();if(!C){if(x.postRun)for(\"function\"==typeof x.postRun&&(x.postRun=[x.postRun]);x.postRun.length;){var b=x.postRun.shift();Ia.unshift(b)}R(Ia)}}}if(!(0 {\n\nvar __filename = \"/index.js\";\nvar __dirname = \"/\";\n\r\nvar ortWasm = (() => {\r\n var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;\r\n if (true) _scriptDir = _scriptDir || __filename;\r\n return (\r\nfunction(ortWasm) {\r\n ortWasm = ortWasm || {};\r\n\r\n\r\nvar d;d||(d=typeof ortWasm !== 'undefined' ? ortWasm : {});var aa,ba;d.ready=new Promise(function(a,b){aa=a;ba=b});var ca=Object.assign({},d),da=\"./this.program\",ea=(a,b)=>{throw b;},fa=\"object\"==typeof window,m=\"function\"==typeof importScripts,p=\"object\"==typeof process&&\"object\"==typeof process.versions&&\"string\"==typeof process.versions.node,q=\"\",ha,r,v,fs,y,ia;\r\nif(p)q=m?(__webpack_require__(/*! path */ \"?75c6\").dirname)(q)+\"/\":__dirname+\"/\",ia=()=>{y||(fs=__webpack_require__(/*! fs */ \"?63c8\"),y=__webpack_require__(/*! path */ \"?75c6\"))},ha=function(a,b){ia();a=y.normalize(a);return fs.readFileSync(a,b?void 0:\"utf8\")},v=a=>{a=ha(a,!0);a.buffer||(a=new Uint8Array(a));return a},r=(a,b,c)=>{ia();a=y.normalize(a);fs.readFile(a,function(e,f){e?c(e):b(f.buffer)})},1{if(noExitRuntime||0{var b=new XMLHttpRequest;b.open(\"GET\",a,!1);b.send(null);\r\nreturn b.responseText},m&&(v=a=>{var b=new XMLHttpRequest;b.open(\"GET\",a,!1);b.responseType=\"arraybuffer\";b.send(null);return new Uint8Array(b.response)}),r=(a,b,c)=>{var e=new XMLHttpRequest;e.open(\"GET\",a,!0);e.responseType=\"arraybuffer\";e.onload=()=>{200==e.status||0==e.status&&e.response?b(e.response):c()};e.onerror=c;e.send(null)};var la=d.print||console.log.bind(console),z=d.printErr||console.warn.bind(console);Object.assign(d,ca);ca=null;d.thisProgram&&(da=d.thisProgram);d.quit&&(ea=d.quit);\r\nvar A;d.wasmBinary&&(A=d.wasmBinary);var noExitRuntime=d.noExitRuntime||!1;\"object\"!=typeof WebAssembly&&B(\"no native wasm support detected\");var ma,D=!1,na=\"undefined\"!=typeof TextDecoder?new TextDecoder(\"utf8\"):void 0;\r\nfunction oa(a,b,c){b>>>=0;var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e}function pa(a,b){return(a>>>=0)?oa(G,a,b):\"\"}\r\nfunction qa(a,b,c,e){c>>>=0;if(!(0=k){var l=a.charCodeAt(++h);k=65536+((k&1023)<<10)|l&1023}if(127>=k){if(c>=e)break;b[c++>>>0]=k}else{if(2047>=k){if(c+1>=e)break;b[c++>>>0]=192|k>>6}else{if(65535>=k){if(c+2>=e)break;b[c++>>>0]=224|k>>12}else{if(c+3>=e)break;b[c++>>>0]=240|k>>18;b[c++>>>0]=128|k>>12&63}b[c++>>>0]=128|k>>6&63}b[c++>>>0]=128|k&63}}b[c>>>0]=0;return c-f}\r\nfunction ra(a){for(var b=0,c=0;c=e?b++:2047>=e?b+=2:55296<=e&&57343>=e?(b+=4,++c):b+=3}return b}var sa,H,G,I,J;function ta(){var a=ma.buffer;sa=a;d.HEAP8=H=new Int8Array(a);d.HEAP16=new Int16Array(a);d.HEAP32=I=new Int32Array(a);d.HEAPU8=G=new Uint8Array(a);d.HEAPU16=new Uint16Array(a);d.HEAPU32=J=new Uint32Array(a);d.HEAPF32=new Float32Array(a);d.HEAPF64=new Float64Array(a)}var ua,va=[],wa=[],xa=[],ya=[],ka=0;\r\nfunction za(){var a=d.preRun.shift();va.unshift(a)}var K=0,Aa=null,L=null;function B(a){if(d.onAbort)d.onAbort(a);a=\"Aborted(\"+a+\")\";z(a);D=!0;a=new WebAssembly.RuntimeError(a+\". Build with -sASSERTIONS for more info.\");ba(a);throw a;}function Ba(){return N.startsWith(\"data:application/octet-stream;base64,\")}var N;N=\"ort-wasm.wasm\";if(!Ba()){var Ca=N;N=d.locateFile?d.locateFile(Ca,q):q+Ca}\r\nfunction Da(){var a=N;try{if(a==N&&A)return new Uint8Array(A);if(v)return v(a);throw\"both async and sync fetching of the wasm failed\";}catch(b){B(b)}}\r\nfunction Ea(){if(!A&&(fa||m)){if(\"function\"==typeof fetch&&!N.startsWith(\"file://\"))return fetch(N,{credentials:\"same-origin\"}).then(function(a){if(!a.ok)throw\"failed to load wasm binary file at '\"+N+\"'\";return a.arrayBuffer()}).catch(function(){return Da()});if(r)return new Promise(function(a,b){r(N,function(c){a(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return Da()})}function ja(a){this.name=\"ExitStatus\";this.message=\"Program terminated with exit(\"+a+\")\";this.status=a}\r\nfunction O(a){for(;0>2>>>0]=b};this.Eb=function(){return J[this.zb+4>>2>>>0]};this.Sb=function(b){J[this.zb+8>>2>>>0]=b};this.Wb=function(){return J[this.zb+8>>2>>>0]};this.Tb=function(){I[this.zb>>2>>>0]=0};this.Ib=function(b){H[this.zb+12>>0>>>0]=b?1:0};this.Pb=function(){return 0!=H[this.zb+12>>0>>>0]};this.Jb=function(b){H[this.zb+13>>0>>>0]=b?1:0};this.Lb=function(){return 0!=H[this.zb+13>>0>>>0]};this.Rb=function(b,c){this.Fb(0);this.Ub(b);this.Sb(c);\r\nthis.Tb();this.Ib(!1);this.Jb(!1)};this.Nb=function(){I[this.zb>>2>>>0]+=1};this.Xb=function(){var b=I[this.zb>>2>>>0];I[this.zb>>2>>>0]=b-1;return 1===b};this.Fb=function(b){J[this.zb+16>>2>>>0]=b};this.Ob=function(){return J[this.zb+16>>2>>>0]};this.Qb=function(){if(Fa(this.Eb()))return J[this.Db>>2>>>0];var b=this.Ob();return 0!==b?b:this.Db}}function Ga(a){return Ha((new S(a)).zb)}var T=[];function U(a){var b=T[a];b||(a>=T.length&&(T.length=a+1),T[a]=b=ua.get(a));return b}\r\nfunction Ia(a){var b=ra(a)+1,c=Ja(b);c&&qa(a,H,c,b);return c}function Ka(a,b,c){function e(n){return(n=n.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?n[1]:\"GMT\"}var f=(new Date).getFullYear(),h=new Date(f,0,1),k=new Date(f,6,1);f=h.getTimezoneOffset();var l=k.getTimezoneOffset();I[a>>2>>>0]=60*Math.max(f,l);I[b>>2>>>0]=Number(f!=l);a=e(h);b=e(k);a=Ia(a);b=Ia(b);l>2>>>0]=a,J[c+4>>2>>>0]=b):(J[c>>2>>>0]=b,J[c+4>>2>>>0]=a)}function La(a,b,c){La.Vb||(La.Vb=!0,Ka(a,b,c))}var Ma={};\r\nfunction Na(){if(!Oa){var a={USER:\"web_user\",LOGNAME:\"web_user\",PATH:\"/\",PWD:\"/\",HOME:\"/home/web_user\",LANG:(\"object\"==typeof navigator&&navigator.languages&&navigator.languages[0]||\"C\").replace(\"-\",\"_\")+\".UTF-8\",_:da||\"./this.program\"},b;for(b in Ma)void 0===Ma[b]?delete a[b]:a[b]=Ma[b];var c=[];for(b in a)c.push(b+\"=\"+a[b]);Oa=c}return Oa}var Oa,Pa=[null,[],[]];function Qa(a,b){var c=Pa[a];0===b||10===b?((1===a?la:z)(oa(c,0)),c.length=0):c.push(b)}var V=0;\r\nfunction Ra(){if(\"object\"==typeof crypto&&\"function\"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(p)try{var b=__webpack_require__(Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'crypto'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));return()=>b.randomBytes(1)[0]}catch(c){}return()=>B(\"randomDevice\")}function W(a,b){W.Mb||(W.Mb=Ra());for(var c=0;c>0>>>0]=W.Mb();return 0}function Sa(a){return 0===a%4&&(0!==a%100||0===a%400)}var Ta=[31,29,31,30,31,30,31,31,30,31,30,31],Ua=[31,28,31,30,31,30,31,31,30,31,30,31];\r\nfunction Va(a){var b=Array(ra(a)+1);qa(a,b,0,b.length);return b}\r\nfunction Wa(a,b,c,e){function f(g,u,w){for(g=\"number\"==typeof g?g.toString():g||\"\";g.lengthM?-1:0F-g.getDate())u-=F-g.getDate()+1,g.setDate(1),11>w?g.setMonth(w+1):(g.setMonth(0),g.setFullYear(g.getFullYear()+1));else{g.setDate(g.getDate()+u);break}}w=new Date(g.getFullYear()+1,0,4);u=l(new Date(g.getFullYear(),\r\n0,4));w=l(w);return 0>=k(u,g)?0>=k(w,g)?g.getFullYear()+1:g.getFullYear():g.getFullYear()-1}var t=I[e+40>>2>>>0];e={$b:I[e>>2>>>0],Zb:I[e+4>>2>>>0],Gb:I[e+8>>2>>>0],Kb:I[e+12>>2>>>0],Hb:I[e+16>>2>>>0],Cb:I[e+20>>2>>>0],Ab:I[e+24>>2>>>0],Bb:I[e+28>>2>>>0],bc:I[e+32>>2>>>0],Yb:I[e+36>>2>>>0],ac:t?pa(t):\"\"};c=pa(c);t={\"%c\":\"%a %b %d %H:%M:%S %Y\",\"%D\":\"%m/%d/%y\",\"%F\":\"%Y-%m-%d\",\"%h\":\"%b\",\"%r\":\"%I:%M:%S %p\",\"%R\":\"%H:%M\",\"%T\":\"%H:%M:%S\",\"%x\":\"%m/%d/%y\",\"%X\":\"%H:%M:%S\",\"%Ec\":\"%c\",\"%EC\":\"%C\",\"%Ex\":\"%m/%d/%y\",\r\n\"%EX\":\"%H:%M:%S\",\"%Ey\":\"%y\",\"%EY\":\"%Y\",\"%Od\":\"%d\",\"%Oe\":\"%e\",\"%OH\":\"%H\",\"%OI\":\"%I\",\"%Om\":\"%m\",\"%OM\":\"%M\",\"%OS\":\"%S\",\"%Ou\":\"%u\",\"%OU\":\"%U\",\"%OV\":\"%V\",\"%Ow\":\"%w\",\"%OW\":\"%W\",\"%Oy\":\"%y\"};for(var x in t)c=c.replace(new RegExp(x,\"g\"),t[x]);var E=\"Sunday Monday Tuesday Wednesday Thursday Friday Saturday\".split(\" \"),C=\"January February March April May June July August September October November December\".split(\" \");t={\"%a\":function(g){return E[g.Ab].substring(0,3)},\"%A\":function(g){return E[g.Ab]},\"%b\":function(g){return C[g.Hb].substring(0,\r\n3)},\"%B\":function(g){return C[g.Hb]},\"%C\":function(g){return h((g.Cb+1900)/100|0,2)},\"%d\":function(g){return h(g.Kb,2)},\"%e\":function(g){return f(g.Kb,2,\" \")},\"%g\":function(g){return n(g).toString().substring(2)},\"%G\":function(g){return n(g)},\"%H\":function(g){return h(g.Gb,2)},\"%I\":function(g){g=g.Gb;0==g?g=12:12g.Gb?\"AM\":\"PM\"},\"%S\":function(g){return h(g.$b,2)},\"%t\":function(){return\"\\t\"},\"%u\":function(g){return g.Ab||7},\"%U\":function(g){return h(Math.floor((g.Bb+7-g.Ab)/7),2)},\"%V\":function(g){var u=Math.floor((g.Bb+7-(g.Ab+6)%7)/7);2>=(g.Ab+371-g.Bb-2)%7&&u++;if(u)53==u&&(w=(g.Ab+371-g.Bb)%7,4==w||3==w&&Sa(g.Cb)||(u=1));else{u=52;var w=(g.Ab+7-g.Bb-1)%7;(4==w||5==w&&Sa(g.Cb%400-1))&&u++}return h(u,2)},\"%w\":function(g){return g.Ab},\"%W\":function(g){return h(Math.floor((g.Bb+\r\n7-(g.Ab+6)%7)/7),2)},\"%y\":function(g){return(g.Cb+1900).toString().substring(2)},\"%Y\":function(g){return g.Cb+1900},\"%z\":function(g){g=g.Yb;var u=0<=g;g=Math.abs(g)/60;return(u?\"+\":\"-\")+String(\"0000\"+(g/60*100+g%60)).slice(-4)},\"%Z\":function(g){return g.ac},\"%%\":function(){return\"%\"}};c=c.replace(/%%/g,\"\\x00\\x00\");for(x in t)c.includes(x)&&(c=c.replace(new RegExp(x,\"g\"),t[x](e)));c=c.replace(/\\0\\0/g,\"%\");x=Va(c);if(x.length>b)return 0;H.set(x,a>>>0);return x.length-1}\r\nvar Jb={a:function(a){return Ja(a+24)+24},m:function(a){a=new S(a);a.Pb()||(a.Ib(!0),Q--);a.Jb(!1);P.push(a);a.Nb();return a.Qb()},ia:function(a){z(\"Unexpected exception thrown, this is not properly supported - aborting\");D=!0;throw a;},w:function(){X(0);var a=P.pop();if(a.Xb()&&!a.Lb()){var b=a.Wb();b&&U(b)(a.Db);Ga(a.Db)}R=0},d:function(){var a=R;if(!a)return V=0;var b=new S(a);b.Fb(a);var c=b.Eb();if(!c)return V=0,a;for(var e=Array.prototype.slice.call(arguments),f=0;f>>2]+4294967296*I[a+4>>>2]));I[b>>2>>>0]=a.getUTCSeconds();I[b+4>>2>>>0]=a.getUTCMinutes();I[b+8>>2>>>0]=a.getUTCHours();I[b+12>>2>>>\r\n0]=a.getUTCDate();I[b+16>>2>>>0]=a.getUTCMonth();I[b+20>>2>>>0]=a.getUTCFullYear()-1900;I[b+24>>2>>>0]=a.getUTCDay();I[b+28>>2>>>0]=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0},Ea:function(a,b){a=new Date(1E3*(J[a>>>2]+4294967296*I[a+4>>>2]));I[b>>2>>>0]=a.getSeconds();I[b+4>>2>>>0]=a.getMinutes();I[b+8>>2>>>0]=a.getHours();I[b+12>>2>>>0]=a.getDate();I[b+16>>2>>>0]=a.getMonth();I[b+20>>2>>>0]=a.getFullYear()-1900;I[b+24>>2>>>0]=a.getDay();var c=new Date(a.getFullYear(),0,1);I[b+\r\n28>>2>>>0]=(a.getTime()-c.getTime())/864E5|0;I[b+36>>2>>>0]=-(60*a.getTimezoneOffset());var e=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();I[b+32>>2>>>0]=(e!=c&&a.getTimezoneOffset()==Math.min(c,e))|0},Fa:function(a){var b=new Date(I[a+20>>2>>>0]+1900,I[a+16>>2>>>0],I[a+12>>2>>>0],I[a+8>>2>>>0],I[a+4>>2>>>0],I[a>>2>>>0],0),c=I[a+32>>2>>>0],e=b.getTimezoneOffset(),f=new Date(b.getFullYear(),0,1),h=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),k=f.getTimezoneOffset(),\r\nl=Math.min(k,h);0>c?I[a+32>>2>>>0]=Number(h!=k&&l==e):0>2>>>0]=b.getDay();I[a+28>>2>>>0]=(b.getTime()-f.getTime())/864E5|0;I[a>>2>>>0]=b.getSeconds();I[a+4>>2>>>0]=b.getMinutes();I[a+8>>2>>>0]=b.getHours();I[a+12>>2>>>0]=b.getDate();I[a+16>>2>>>0]=b.getMonth();return b.getTime()/1E3|0},sa:function(){return-52},ta:function(){},Ga:La,B:function(){B(\"\")},ma:function(){return 4294901760},I:p?()=>{var a=process.hrtime();return 1E3*\r\na[0]+a[1]/1E6}:()=>performance.now(),xa:function(a,b,c){G.copyWithin(a>>>0,b>>>0,b+c>>>0)},G:function(a){var b=G.length;a>>>=0;if(4294901760=c;c*=2){var e=b*(1+.2/c);e=Math.min(e,a+100663296);var f=Math;e=Math.max(a,e);f=f.min.call(f,4294901760,e+(65536-e%65536)%65536);a:{try{ma.grow(f-sa.byteLength+65535>>>16);ta();var h=1;break a}catch(k){}h=void 0}if(h)return!0}return!1},va:function(a,b){var c=0;Na().forEach(function(e,f){var h=b+c;f=J[a+4*f>>2>>>0]=h;for(h=0;h>\r\n0>>>0]=e.charCodeAt(h);H[f>>0>>>0]=0;c+=e.length+1});return 0},wa:function(a,b){var c=Na();J[a>>2>>>0]=c.length;var e=0;c.forEach(function(f){e+=f.length+1});J[b>>2>>>0]=e;return 0},ba:function(a){noExitRuntime||0>2>>>0],l=J[b+4>>\r\n2>>>0];b+=8;for(var n=0;n>>0]);f+=l}J[e>>2>>>0]=f;return 0},c:function(){return V},ja:W,ea:$a,fa:ab,J:bb,e:cb,N:db,O:eb,j:fb,o:gb,p:hb,M:ib,r:jb,v:kb,K:lb,D:mb,X:nb,V:ob,U:pb,Z:qb,W:rb,Y:sb,T:tb,f:ub,q:vb,h:wb,da:xb,l:yb,t:zb,u:Ab,x:Bb,z:Cb,ga:Db,A:Eb,C:Fb,aa:Gb,_:Hb,$:Ib,n:function(a){return a},F:function(a){V=a},ha:Wa,y:function(a,b,c,e){return Wa(a,b,c,e)}};\r\n(function(){function a(f){d.asm=f.exports;ma=d.asm.Ka;ta();ua=d.asm.ib;wa.unshift(d.asm.La);K--;d.monitorRunDependencies&&d.monitorRunDependencies(K);0==K&&(null!==Aa&&(clearInterval(Aa),Aa=null),L&&(f=L,L=null,f()))}function b(f){a(f.instance)}function c(f){return Ea().then(function(h){return WebAssembly.instantiate(h,e)}).then(function(h){return h}).then(f,function(h){z(\"failed to asynchronously prepare wasm: \"+h);B(h)})}var e={a:Jb};K++;d.monitorRunDependencies&&d.monitorRunDependencies(K);if(d.instantiateWasm)try{return d.instantiateWasm(e,\r\na)}catch(f){return z(\"Module.instantiateWasm callback failed with error: \"+f),!1}(function(){return A||\"function\"!=typeof WebAssembly.instantiateStreaming||Ba()||N.startsWith(\"file://\")||p||\"function\"!=typeof fetch?c(b):fetch(N,{credentials:\"same-origin\"}).then(function(f){return WebAssembly.instantiateStreaming(f,e).then(b,function(h){z(\"wasm streaming compile failed: \"+h);z(\"falling back to ArrayBuffer instantiation\");return c(b)})})})().catch(ba);return{}})();\r\nd.___wasm_call_ctors=function(){return(d.___wasm_call_ctors=d.asm.La).apply(null,arguments)};d._OrtInit=function(){return(d._OrtInit=d.asm.Ma).apply(null,arguments)};d._OrtCreateSessionOptions=function(){return(d._OrtCreateSessionOptions=d.asm.Na).apply(null,arguments)};d._OrtAppendExecutionProvider=function(){return(d._OrtAppendExecutionProvider=d.asm.Oa).apply(null,arguments)};d._OrtAddSessionConfigEntry=function(){return(d._OrtAddSessionConfigEntry=d.asm.Pa).apply(null,arguments)};\r\nd._OrtReleaseSessionOptions=function(){return(d._OrtReleaseSessionOptions=d.asm.Qa).apply(null,arguments)};d._OrtCreateSession=function(){return(d._OrtCreateSession=d.asm.Ra).apply(null,arguments)};d._OrtReleaseSession=function(){return(d._OrtReleaseSession=d.asm.Sa).apply(null,arguments)};d._OrtGetInputCount=function(){return(d._OrtGetInputCount=d.asm.Ta).apply(null,arguments)};d._OrtGetOutputCount=function(){return(d._OrtGetOutputCount=d.asm.Ua).apply(null,arguments)};\r\nd._OrtGetInputName=function(){return(d._OrtGetInputName=d.asm.Va).apply(null,arguments)};d._OrtGetOutputName=function(){return(d._OrtGetOutputName=d.asm.Wa).apply(null,arguments)};d._OrtFree=function(){return(d._OrtFree=d.asm.Xa).apply(null,arguments)};d._OrtCreateTensor=function(){return(d._OrtCreateTensor=d.asm.Ya).apply(null,arguments)};d._OrtGetTensorData=function(){return(d._OrtGetTensorData=d.asm.Za).apply(null,arguments)};\r\nd._OrtReleaseTensor=function(){return(d._OrtReleaseTensor=d.asm._a).apply(null,arguments)};d._OrtCreateRunOptions=function(){return(d._OrtCreateRunOptions=d.asm.$a).apply(null,arguments)};d._OrtAddRunConfigEntry=function(){return(d._OrtAddRunConfigEntry=d.asm.ab).apply(null,arguments)};d._OrtReleaseRunOptions=function(){return(d._OrtReleaseRunOptions=d.asm.bb).apply(null,arguments)};d._OrtRun=function(){return(d._OrtRun=d.asm.cb).apply(null,arguments)};\r\nd._OrtEndProfiling=function(){return(d._OrtEndProfiling=d.asm.db).apply(null,arguments)};\r\nvar Ja=d._malloc=function(){return(Ja=d._malloc=d.asm.eb).apply(null,arguments)},Ha=d._free=function(){return(Ha=d._free=d.asm.fb).apply(null,arguments)},Za=d._fflush=function(){return(Za=d._fflush=d.asm.gb).apply(null,arguments)},Ya=d.___funcs_on_exit=function(){return(Ya=d.___funcs_on_exit=d.asm.hb).apply(null,arguments)},X=d._setThrew=function(){return(X=d._setThrew=d.asm.jb).apply(null,arguments)},Y=d.stackSave=function(){return(Y=d.stackSave=d.asm.kb).apply(null,arguments)},Z=d.stackRestore=\r\nfunction(){return(Z=d.stackRestore=d.asm.lb).apply(null,arguments)},Kb=d.stackAlloc=function(){return(Kb=d.stackAlloc=d.asm.mb).apply(null,arguments)},Xa=d.___cxa_can_catch=function(){return(Xa=d.___cxa_can_catch=d.asm.nb).apply(null,arguments)},Fa=d.___cxa_is_pointer_type=function(){return(Fa=d.___cxa_is_pointer_type=d.asm.ob).apply(null,arguments)},Lb=d.dynCall_j=function(){return(Lb=d.dynCall_j=d.asm.pb).apply(null,arguments)},Mb=d.dynCall_iiiiij=function(){return(Mb=d.dynCall_iiiiij=d.asm.qb).apply(null,\r\narguments)},Nb=d.dynCall_jii=function(){return(Nb=d.dynCall_jii=d.asm.rb).apply(null,arguments)},Ob=d.dynCall_viiiiij=function(){return(Ob=d.dynCall_viiiiij=d.asm.sb).apply(null,arguments)},Pb=d.dynCall_vjji=function(){return(Pb=d.dynCall_vjji=d.asm.tb).apply(null,arguments)},Qb=d.dynCall_viiijjjii=function(){return(Qb=d.dynCall_viiijjjii=d.asm.ub).apply(null,arguments)},Rb=d.dynCall_iij=function(){return(Rb=d.dynCall_iij=d.asm.vb).apply(null,arguments)},Sb=d.dynCall_ji=function(){return(Sb=d.dynCall_ji=\r\nd.asm.wb).apply(null,arguments)},Tb=d.dynCall_iiiiiij=function(){return(Tb=d.dynCall_iiiiiij=d.asm.xb).apply(null,arguments)},Ub=d.dynCall_iiij=function(){return(Ub=d.dynCall_iiij=d.asm.yb).apply(null,arguments)};function cb(a,b){var c=Y();try{return U(a)(b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}}function vb(a,b){var c=Y();try{U(a)(b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}}function wb(a,b,c){var e=Y();try{U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}\r\nfunction fb(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function gb(a,b,c,e){var f=Y();try{return U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function kb(a,b,c,e,f,h,k){var l=Y();try{return U(a)(b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}}function ub(a){var b=Y();try{U(a)()}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function jb(a,b,c,e,f,h){var k=Y();try{return U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}\r\nfunction hb(a,b,c,e,f){var h=Y();try{return U(a)(b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function yb(a,b,c,e){var f=Y();try{U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function Ab(a,b,c,e,f,h){var k=Y();try{U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}function zb(a,b,c,e,f){var h=Y();try{U(a)(b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function Bb(a,b,c,e,f,h,k){var l=Y();try{U(a)(b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}}\r\nfunction Cb(a,b,c,e,f,h,k,l){var n=Y();try{U(a)(b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function eb(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function db(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function Db(a,b,c,e,f,h,k,l,n){var t=Y();try{U(a)(b,c,e,f,h,k,l,n)}catch(x){Z(t);if(x!==x+0)throw x;X(1,0)}}function ib(a,b,c,e,f,h){var k=Y();try{return U(a)(b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}\r\nfunction lb(a,b,c,e,f,h,k,l){var n=Y();try{return U(a)(b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function mb(a,b,c,e,f,h,k,l,n,t,x,E){var C=Y();try{return U(a)(b,c,e,f,h,k,l,n,t,x,E)}catch(g){Z(C);if(g!==g+0)throw g;X(1,0)}}function Eb(a,b,c,e,f,h,k,l,n,t,x){var E=Y();try{U(a)(b,c,e,f,h,k,l,n,t,x)}catch(C){Z(E);if(C!==C+0)throw C;X(1,0)}}function Fb(a,b,c,e,f,h,k,l,n,t,x,E,C,g,u,w){var F=Y();try{U(a)(b,c,e,f,h,k,l,n,t,x,E,C,g,u,w)}catch(M){Z(F);if(M!==M+0)throw M;X(1,0)}}\r\nfunction bb(a){var b=Y();try{return U(a)()}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function ab(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function $a(a,b,c){var e=Y();try{return U(a)(b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}function xb(a,b,c,e){var f=Y();try{U(a)(b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function Gb(a,b,c,e,f,h,k,l){var n=Y();try{Ob(a,b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}\r\nfunction Ib(a,b,c,e,f,h){var k=Y();try{Pb(a,b,c,e,f,h)}catch(l){Z(k);if(l!==l+0)throw l;X(1,0)}}function Hb(a,b,c,e,f,h,k,l,n,t,x,E){var C=Y();try{Qb(a,b,c,e,f,h,k,l,n,t,x,E)}catch(g){Z(C);if(g!==g+0)throw g;X(1,0)}}function qb(a,b,c,e){var f=Y();try{return Rb(a,b,c,e)}catch(h){Z(f);if(h!==h+0)throw h;X(1,0)}}function sb(a,b){var c=Y();try{return Sb(a,b)}catch(e){Z(c);if(e!==e+0)throw e;X(1,0)}}\r\nfunction nb(a,b,c,e,f,h,k,l){var n=Y();try{return Tb(a,b,c,e,f,h,k,l)}catch(t){Z(n);if(t!==t+0)throw t;X(1,0)}}function rb(a){var b=Y();try{return Lb(a)}catch(c){Z(b);if(c!==c+0)throw c;X(1,0)}}function ob(a,b,c,e,f,h,k){var l=Y();try{return Mb(a,b,c,e,f,h,k)}catch(n){Z(l);if(n!==n+0)throw n;X(1,0)}}function pb(a,b,c,e,f){var h=Y();try{return Ub(a,b,c,e,f)}catch(k){Z(h);if(k!==k+0)throw k;X(1,0)}}function tb(a,b,c){var e=Y();try{return Nb(a,b,c)}catch(f){Z(e);if(f!==f+0)throw f;X(1,0)}}\r\nd.UTF8ToString=pa;d.stringToUTF8=function(a,b,c){return qa(a,G,b,c)};d.lengthBytesUTF8=ra;d.stackSave=Y;d.stackRestore=Z;d.stackAlloc=Kb;var Vb;L=function Wb(){Vb||Xb();Vb||(L=Wb)};\r\nfunction Xb(){function a(){if(!Vb&&(Vb=!0,d.calledRun=!0,!D)){O(wa);aa(d);if(d.onRuntimeInitialized)d.onRuntimeInitialized();if(d.postRun)for(\"function\"==typeof d.postRun&&(d.postRun=[d.postRun]);d.postRun.length;){var b=d.postRun.shift();ya.unshift(b)}O(ya)}}if(!(0 {\n\n\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.iterateExtraOptions = void 0;\nconst iterateExtraOptions = (options, prefix, seen, handler) => {\n if (typeof options == 'object' && options !== null) {\n if (seen.has(options)) {\n throw new Error('Circular reference in options');\n }\n else {\n seen.add(options);\n }\n }\n Object.entries(options).forEach(([key, value]) => {\n const name = (prefix) ? prefix + key : key;\n if (typeof value === 'object') {\n (0, exports.iterateExtraOptions)(value, name + '.', seen, handler);\n }\n else if (typeof value === 'string' || typeof value === 'number') {\n handler(name, value.toString());\n }\n else if (typeof value === 'boolean') {\n handler(name, (value) ? '1' : '0');\n }\n else {\n throw new Error(`Can't handle extra config type: ${typeof value}`);\n }\n });\n};\nexports.iterateExtraOptions = iterateExtraOptions;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/run-options.ts\":\n/*!*********************************!*\\\n !*** ./lib/wasm/run-options.ts ***!\n \\*********************************/\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.setRunOptions = void 0;\nconst options_utils_1 = __webpack_require__(/*! ./options-utils */ \"./lib/wasm/options-utils.ts\");\nconst string_utils_1 = __webpack_require__(/*! ./string-utils */ \"./lib/wasm/string-utils.ts\");\nconst wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ \"./lib/wasm/wasm-factory.ts\");\nconst setRunOptions = (options) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n let runOptionsHandle = 0;\n const allocs = [];\n const runOptions = options || {};\n try {\n if ((options === null || options === void 0 ? void 0 : options.logSeverityLevel) === undefined) {\n runOptions.logSeverityLevel = 2; // Default to warning\n }\n else if (typeof options.logSeverityLevel !== 'number' || !Number.isInteger(options.logSeverityLevel) ||\n options.logSeverityLevel < 0 || options.logSeverityLevel > 4) {\n throw new Error(`log serverity level is not valid: ${options.logSeverityLevel}`);\n }\n if ((options === null || options === void 0 ? void 0 : options.logVerbosityLevel) === undefined) {\n runOptions.logVerbosityLevel = 0; // Default to 0\n }\n else if (typeof options.logVerbosityLevel !== 'number' || !Number.isInteger(options.logVerbosityLevel)) {\n throw new Error(`log verbosity level is not valid: ${options.logVerbosityLevel}`);\n }\n if ((options === null || options === void 0 ? void 0 : options.terminate) === undefined) {\n runOptions.terminate = false;\n }\n let tagDataOffset = 0;\n if ((options === null || options === void 0 ? void 0 : options.tag) !== undefined) {\n tagDataOffset = (0, string_utils_1.allocWasmString)(options.tag, allocs);\n }\n runOptionsHandle = wasm._OrtCreateRunOptions(runOptions.logSeverityLevel, runOptions.logVerbosityLevel, !!runOptions.terminate, tagDataOffset);\n if (runOptionsHandle === 0) {\n throw new Error('Can\\'t create run options');\n }\n if ((options === null || options === void 0 ? void 0 : options.extra) !== undefined) {\n (0, options_utils_1.iterateExtraOptions)(options.extra, '', new WeakSet(), (key, value) => {\n const keyDataOffset = (0, string_utils_1.allocWasmString)(key, allocs);\n const valueDataOffset = (0, string_utils_1.allocWasmString)(value, allocs);\n if (wasm._OrtAddRunConfigEntry(runOptionsHandle, keyDataOffset, valueDataOffset) !== 0) {\n throw new Error(`Can't set a run config entry: ${key} - ${value}`);\n }\n });\n }\n return [runOptionsHandle, allocs];\n }\n catch (e) {\n if (runOptionsHandle !== 0) {\n wasm._OrtReleaseRunOptions(runOptionsHandle);\n }\n allocs.forEach(wasm._free);\n throw e;\n }\n};\nexports.setRunOptions = setRunOptions;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/session-options.ts\":\n/*!*************************************!*\\\n !*** ./lib/wasm/session-options.ts ***!\n \\*************************************/\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.setSessionOptions = void 0;\nconst options_utils_1 = __webpack_require__(/*! ./options-utils */ \"./lib/wasm/options-utils.ts\");\nconst string_utils_1 = __webpack_require__(/*! ./string-utils */ \"./lib/wasm/string-utils.ts\");\nconst wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ \"./lib/wasm/wasm-factory.ts\");\nconst getGraphOptimzationLevel = (graphOptimizationLevel) => {\n switch (graphOptimizationLevel) {\n case 'disabled':\n return 0;\n case 'basic':\n return 1;\n case 'extended':\n return 2;\n case 'all':\n return 99;\n default:\n throw new Error(`unsupported graph optimization level: ${graphOptimizationLevel}`);\n }\n};\nconst getExecutionMode = (executionMode) => {\n switch (executionMode) {\n case 'sequential':\n return 0;\n case 'parallel':\n return 1;\n default:\n throw new Error(`unsupported execution mode: ${executionMode}`);\n }\n};\nconst appendDefaultOptions = (options) => {\n if (!options.extra) {\n options.extra = {};\n }\n if (!options.extra.session) {\n options.extra.session = {};\n }\n const session = options.extra.session;\n if (!session.use_ort_model_bytes_directly) {\n // eslint-disable-next-line camelcase\n session.use_ort_model_bytes_directly = '1';\n }\n};\nconst setExecutionProviders = (sessionOptionsHandle, executionProviders, allocs) => {\n for (const ep of executionProviders) {\n let epName = typeof ep === 'string' ? ep : ep.name;\n // check EP name\n switch (epName) {\n case 'xnnpack':\n epName = 'XNNPACK';\n break;\n case 'wasm':\n case 'cpu':\n continue;\n default:\n throw new Error(`not supported EP: ${epName}`);\n }\n const epNameDataOffset = (0, string_utils_1.allocWasmString)(epName, allocs);\n if ((0, wasm_factory_1.getInstance)()._OrtAppendExecutionProvider(sessionOptionsHandle, epNameDataOffset) !== 0) {\n throw new Error(`Can't append execution provider: ${epName}`);\n }\n }\n};\nconst setSessionOptions = (options) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n let sessionOptionsHandle = 0;\n const allocs = [];\n const sessionOptions = options || {};\n appendDefaultOptions(sessionOptions);\n try {\n if ((options === null || options === void 0 ? void 0 : options.graphOptimizationLevel) === undefined) {\n sessionOptions.graphOptimizationLevel = 'all';\n }\n const graphOptimizationLevel = getGraphOptimzationLevel(sessionOptions.graphOptimizationLevel);\n if ((options === null || options === void 0 ? void 0 : options.enableCpuMemArena) === undefined) {\n sessionOptions.enableCpuMemArena = true;\n }\n if ((options === null || options === void 0 ? void 0 : options.enableMemPattern) === undefined) {\n sessionOptions.enableMemPattern = true;\n }\n if ((options === null || options === void 0 ? void 0 : options.executionMode) === undefined) {\n sessionOptions.executionMode = 'sequential';\n }\n const executionMode = getExecutionMode(sessionOptions.executionMode);\n let logIdDataOffset = 0;\n if ((options === null || options === void 0 ? void 0 : options.logId) !== undefined) {\n logIdDataOffset = (0, string_utils_1.allocWasmString)(options.logId, allocs);\n }\n if ((options === null || options === void 0 ? void 0 : options.logSeverityLevel) === undefined) {\n sessionOptions.logSeverityLevel = 2; // Default to warning\n }\n else if (typeof options.logSeverityLevel !== 'number' || !Number.isInteger(options.logSeverityLevel) ||\n options.logSeverityLevel < 0 || options.logSeverityLevel > 4) {\n throw new Error(`log serverity level is not valid: ${options.logSeverityLevel}`);\n }\n if ((options === null || options === void 0 ? void 0 : options.logVerbosityLevel) === undefined) {\n sessionOptions.logVerbosityLevel = 0; // Default to 0\n }\n else if (typeof options.logVerbosityLevel !== 'number' || !Number.isInteger(options.logVerbosityLevel)) {\n throw new Error(`log verbosity level is not valid: ${options.logVerbosityLevel}`);\n }\n if ((options === null || options === void 0 ? void 0 : options.enableProfiling) === undefined) {\n sessionOptions.enableProfiling = false;\n }\n sessionOptionsHandle = wasm._OrtCreateSessionOptions(graphOptimizationLevel, !!sessionOptions.enableCpuMemArena, !!sessionOptions.enableMemPattern, executionMode, !!sessionOptions.enableProfiling, 0, logIdDataOffset, sessionOptions.logSeverityLevel, sessionOptions.logVerbosityLevel);\n if (sessionOptionsHandle === 0) {\n throw new Error('Can\\'t create session options');\n }\n if (options === null || options === void 0 ? void 0 : options.executionProviders) {\n setExecutionProviders(sessionOptionsHandle, options.executionProviders, allocs);\n }\n if ((options === null || options === void 0 ? void 0 : options.extra) !== undefined) {\n (0, options_utils_1.iterateExtraOptions)(options.extra, '', new WeakSet(), (key, value) => {\n const keyDataOffset = (0, string_utils_1.allocWasmString)(key, allocs);\n const valueDataOffset = (0, string_utils_1.allocWasmString)(value, allocs);\n if (wasm._OrtAddSessionConfigEntry(sessionOptionsHandle, keyDataOffset, valueDataOffset) !== 0) {\n throw new Error(`Can't set a session config entry: ${key} - ${value}`);\n }\n });\n }\n return [sessionOptionsHandle, allocs];\n }\n catch (e) {\n if (sessionOptionsHandle !== 0) {\n wasm._OrtReleaseSessionOptions(sessionOptionsHandle);\n }\n allocs.forEach(wasm._free);\n throw e;\n }\n};\nexports.setSessionOptions = setSessionOptions;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/string-utils.ts\":\n/*!**********************************!*\\\n !*** ./lib/wasm/string-utils.ts ***!\n \\**********************************/\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.allocWasmString = void 0;\nconst wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ \"./lib/wasm/wasm-factory.ts\");\nconst allocWasmString = (data, allocs) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n const dataLength = wasm.lengthBytesUTF8(data) + 1;\n const dataOffset = wasm._malloc(dataLength);\n wasm.stringToUTF8(data, dataOffset, dataLength);\n allocs.push(dataOffset);\n return dataOffset;\n};\nexports.allocWasmString = allocWasmString;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/wasm-core-impl.ts\":\n/*!************************************!*\\\n !*** ./lib/wasm/wasm-core-impl.ts ***!\n \\************************************/\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.extractTransferableBuffers = exports.endProfiling = exports.run = exports.releaseSession = exports.createSession = exports.createSessionFinalize = exports.createSessionAllocate = exports.initOrt = void 0;\nconst run_options_1 = __webpack_require__(/*! ./run-options */ \"./lib/wasm/run-options.ts\");\nconst session_options_1 = __webpack_require__(/*! ./session-options */ \"./lib/wasm/session-options.ts\");\nconst string_utils_1 = __webpack_require__(/*! ./string-utils */ \"./lib/wasm/string-utils.ts\");\nconst wasm_factory_1 = __webpack_require__(/*! ./wasm-factory */ \"./lib/wasm/wasm-factory.ts\");\n/**\n * initialize ORT environment.\n * @param numThreads SetGlobalIntraOpNumThreads(numThreads)\n * @param loggingLevel CreateEnv(static_cast(logging_level))\n */\nconst initOrt = (numThreads, loggingLevel) => {\n const errorCode = (0, wasm_factory_1.getInstance)()._OrtInit(numThreads, loggingLevel);\n if (errorCode !== 0) {\n throw new Error(`Can't initialize onnxruntime. error code = ${errorCode}`);\n }\n};\nexports.initOrt = initOrt;\nconst activeSessions = new Map();\n/**\n * create an instance of InferenceSession.\n * @returns the metadata of InferenceSession. 0-value handle for failure.\n */\nconst createSessionAllocate = (model) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n const modelDataOffset = wasm._malloc(model.byteLength);\n wasm.HEAPU8.set(model, modelDataOffset);\n return [modelDataOffset, model.byteLength];\n};\nexports.createSessionAllocate = createSessionAllocate;\nconst createSessionFinalize = (modelData, options) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n let sessionHandle = 0;\n let sessionOptionsHandle = 0;\n let allocs = [];\n try {\n [sessionOptionsHandle, allocs] = (0, session_options_1.setSessionOptions)(options);\n sessionHandle = wasm._OrtCreateSession(modelData[0], modelData[1], sessionOptionsHandle);\n if (sessionHandle === 0) {\n throw new Error('Can\\'t create a session');\n }\n }\n finally {\n wasm._free(modelData[0]);\n wasm._OrtReleaseSessionOptions(sessionOptionsHandle);\n allocs.forEach(wasm._free);\n }\n const inputCount = wasm._OrtGetInputCount(sessionHandle);\n const outputCount = wasm._OrtGetOutputCount(sessionHandle);\n const inputNames = [];\n const inputNamesUTF8Encoded = [];\n const outputNames = [];\n const outputNamesUTF8Encoded = [];\n for (let i = 0; i < inputCount; i++) {\n const name = wasm._OrtGetInputName(sessionHandle, i);\n if (name === 0) {\n throw new Error('Can\\'t get an input name');\n }\n inputNamesUTF8Encoded.push(name);\n inputNames.push(wasm.UTF8ToString(name));\n }\n for (let i = 0; i < outputCount; i++) {\n const name = wasm._OrtGetOutputName(sessionHandle, i);\n if (name === 0) {\n throw new Error('Can\\'t get an output name');\n }\n outputNamesUTF8Encoded.push(name);\n outputNames.push(wasm.UTF8ToString(name));\n }\n activeSessions.set(sessionHandle, [sessionHandle, inputNamesUTF8Encoded, outputNamesUTF8Encoded]);\n return [sessionHandle, inputNames, outputNames];\n};\nexports.createSessionFinalize = createSessionFinalize;\n/**\n * create an instance of InferenceSession.\n * @returns the metadata of InferenceSession. 0-value handle for failure.\n */\nconst createSession = (model, options) => {\n const modelData = (0, exports.createSessionAllocate)(model);\n return (0, exports.createSessionFinalize)(modelData, options);\n};\nexports.createSession = createSession;\nconst releaseSession = (sessionId) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n const session = activeSessions.get(sessionId);\n if (!session) {\n throw new Error('invalid session id');\n }\n const sessionHandle = session[0];\n const inputNamesUTF8Encoded = session[1];\n const outputNamesUTF8Encoded = session[2];\n inputNamesUTF8Encoded.forEach(wasm._OrtFree);\n outputNamesUTF8Encoded.forEach(wasm._OrtFree);\n wasm._OrtReleaseSession(sessionHandle);\n activeSessions.delete(sessionId);\n};\nexports.releaseSession = releaseSession;\nconst tensorDataTypeStringToEnum = (type) => {\n switch (type) {\n case 'int8':\n return 3 /* DataType.int8 */;\n case 'uint8':\n return 2 /* DataType.uint8 */;\n case 'bool':\n return 9 /* DataType.bool */;\n case 'int16':\n return 5 /* DataType.int16 */;\n case 'uint16':\n return 4 /* DataType.uint16 */;\n case 'int32':\n return 6 /* DataType.int32 */;\n case 'uint32':\n return 12 /* DataType.uint32 */;\n case 'float32':\n return 1 /* DataType.float */;\n case 'float64':\n return 11 /* DataType.double */;\n case 'string':\n return 8 /* DataType.string */;\n case 'int64':\n return 7 /* DataType.int64 */;\n case 'uint64':\n return 13 /* DataType.uint64 */;\n default:\n throw new Error(`unsupported data type: ${type}`);\n }\n};\nconst tensorDataTypeEnumToString = (typeProto) => {\n switch (typeProto) {\n case 3 /* DataType.int8 */:\n return 'int8';\n case 2 /* DataType.uint8 */:\n return 'uint8';\n case 9 /* DataType.bool */:\n return 'bool';\n case 5 /* DataType.int16 */:\n return 'int16';\n case 4 /* DataType.uint16 */:\n return 'uint16';\n case 6 /* DataType.int32 */:\n return 'int32';\n case 12 /* DataType.uint32 */:\n return 'uint32';\n case 1 /* DataType.float */:\n return 'float32';\n case 11 /* DataType.double */:\n return 'float64';\n case 8 /* DataType.string */:\n return 'string';\n case 7 /* DataType.int64 */:\n return 'int64';\n case 13 /* DataType.uint64 */:\n return 'uint64';\n default:\n throw new Error(`unsupported data type: ${typeProto}`);\n }\n};\nconst numericTensorTypeToTypedArray = (type) => {\n switch (type) {\n case 'float32':\n return Float32Array;\n case 'uint8':\n return Uint8Array;\n case 'int8':\n return Int8Array;\n case 'uint16':\n return Uint16Array;\n case 'int16':\n return Int16Array;\n case 'int32':\n return Int32Array;\n case 'bool':\n return Uint8Array;\n case 'float64':\n return Float64Array;\n case 'uint32':\n return Uint32Array;\n case 'int64':\n return BigInt64Array;\n case 'uint64':\n return BigUint64Array;\n default:\n throw new Error(`unsupported type: ${type}`);\n }\n};\n/**\n * perform inference run\n */\nconst run = (sessionId, inputIndices, inputs, outputIndices, options) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n const session = activeSessions.get(sessionId);\n if (!session) {\n throw new Error('invalid session id');\n }\n const sessionHandle = session[0];\n const inputNamesUTF8Encoded = session[1];\n const outputNamesUTF8Encoded = session[2];\n const inputCount = inputIndices.length;\n const outputCount = outputIndices.length;\n let runOptionsHandle = 0;\n let runOptionsAllocs = [];\n const inputValues = [];\n const inputAllocs = [];\n try {\n [runOptionsHandle, runOptionsAllocs] = (0, run_options_1.setRunOptions)(options);\n // create input tensors\n for (let i = 0; i < inputCount; i++) {\n const dataType = inputs[i][0];\n const dims = inputs[i][1];\n const data = inputs[i][2];\n let dataOffset;\n let dataByteLength;\n if (Array.isArray(data)) {\n // string tensor\n dataByteLength = 4 * data.length;\n dataOffset = wasm._malloc(dataByteLength);\n inputAllocs.push(dataOffset);\n let dataIndex = dataOffset / 4;\n for (let i = 0; i < data.length; i++) {\n if (typeof data[i] !== 'string') {\n throw new TypeError(`tensor data at index ${i} is not a string`);\n }\n wasm.HEAPU32[dataIndex++] = (0, string_utils_1.allocWasmString)(data[i], inputAllocs);\n }\n }\n else {\n dataByteLength = data.byteLength;\n dataOffset = wasm._malloc(dataByteLength);\n inputAllocs.push(dataOffset);\n wasm.HEAPU8.set(new Uint8Array(data.buffer, data.byteOffset, dataByteLength), dataOffset);\n }\n const stack = wasm.stackSave();\n const dimsOffset = wasm.stackAlloc(4 * dims.length);\n try {\n let dimIndex = dimsOffset / 4;\n dims.forEach(d => wasm.HEAP32[dimIndex++] = d);\n const tensor = wasm._OrtCreateTensor(tensorDataTypeStringToEnum(dataType), dataOffset, dataByteLength, dimsOffset, dims.length);\n if (tensor === 0) {\n throw new Error('Can\\'t create a tensor');\n }\n inputValues.push(tensor);\n }\n finally {\n wasm.stackRestore(stack);\n }\n }\n const beforeRunStack = wasm.stackSave();\n const inputValuesOffset = wasm.stackAlloc(inputCount * 4);\n const inputNamesOffset = wasm.stackAlloc(inputCount * 4);\n const outputValuesOffset = wasm.stackAlloc(outputCount * 4);\n const outputNamesOffset = wasm.stackAlloc(outputCount * 4);\n try {\n let inputValuesIndex = inputValuesOffset / 4;\n let inputNamesIndex = inputNamesOffset / 4;\n let outputValuesIndex = outputValuesOffset / 4;\n let outputNamesIndex = outputNamesOffset / 4;\n for (let i = 0; i < inputCount; i++) {\n wasm.HEAPU32[inputValuesIndex++] = inputValues[i];\n wasm.HEAPU32[inputNamesIndex++] = inputNamesUTF8Encoded[inputIndices[i]];\n }\n for (let i = 0; i < outputCount; i++) {\n wasm.HEAPU32[outputValuesIndex++] = 0;\n wasm.HEAPU32[outputNamesIndex++] = outputNamesUTF8Encoded[outputIndices[i]];\n }\n // support RunOptions\n let errorCode = wasm._OrtRun(sessionHandle, inputNamesOffset, inputValuesOffset, inputCount, outputNamesOffset, outputCount, outputValuesOffset, runOptionsHandle);\n const output = [];\n if (errorCode === 0) {\n for (let i = 0; i < outputCount; i++) {\n const tensor = wasm.HEAPU32[outputValuesOffset / 4 + i];\n const beforeGetTensorDataStack = wasm.stackSave();\n // stack allocate 4 pointer value\n const tensorDataOffset = wasm.stackAlloc(4 * 4);\n let type, dataOffset = 0;\n try {\n errorCode = wasm._OrtGetTensorData(tensor, tensorDataOffset, tensorDataOffset + 4, tensorDataOffset + 8, tensorDataOffset + 12);\n if (errorCode !== 0) {\n throw new Error(`Can't access output tensor data. error code = ${errorCode}`);\n }\n let tensorDataIndex = tensorDataOffset / 4;\n const dataType = wasm.HEAPU32[tensorDataIndex++];\n dataOffset = wasm.HEAPU32[tensorDataIndex++];\n const dimsOffset = wasm.HEAPU32[tensorDataIndex++];\n const dimsLength = wasm.HEAPU32[tensorDataIndex++];\n const dims = [];\n for (let i = 0; i < dimsLength; i++) {\n dims.push(wasm.HEAPU32[dimsOffset / 4 + i]);\n }\n wasm._OrtFree(dimsOffset);\n const size = dims.length === 0 ? 1 : dims.reduce((a, b) => a * b);\n type = tensorDataTypeEnumToString(dataType);\n if (type === 'string') {\n const stringData = [];\n let dataIndex = dataOffset / 4;\n for (let i = 0; i < size; i++) {\n const offset = wasm.HEAPU32[dataIndex++];\n const maxBytesToRead = i === size - 1 ? undefined : wasm.HEAPU32[dataIndex] - offset;\n stringData.push(wasm.UTF8ToString(offset, maxBytesToRead));\n }\n output.push([type, dims, stringData]);\n }\n else {\n const typedArrayConstructor = numericTensorTypeToTypedArray(type);\n const data = new typedArrayConstructor(size);\n new Uint8Array(data.buffer, data.byteOffset, data.byteLength)\n .set(wasm.HEAPU8.subarray(dataOffset, dataOffset + data.byteLength));\n output.push([type, dims, data]);\n }\n }\n finally {\n wasm.stackRestore(beforeGetTensorDataStack);\n if (type === 'string' && dataOffset) {\n wasm._free(dataOffset);\n }\n wasm._OrtReleaseTensor(tensor);\n }\n }\n }\n if (errorCode === 0) {\n return output;\n }\n else {\n throw new Error(`failed to call OrtRun(). error code = ${errorCode}.`);\n }\n }\n finally {\n wasm.stackRestore(beforeRunStack);\n }\n }\n finally {\n inputValues.forEach(wasm._OrtReleaseTensor);\n inputAllocs.forEach(wasm._free);\n wasm._OrtReleaseRunOptions(runOptionsHandle);\n runOptionsAllocs.forEach(wasm._free);\n }\n};\nexports.run = run;\n/**\n * end profiling\n */\nconst endProfiling = (sessionId) => {\n const wasm = (0, wasm_factory_1.getInstance)();\n const session = activeSessions.get(sessionId);\n if (!session) {\n throw new Error('invalid session id');\n }\n const sessionHandle = session[0];\n // profile file name is not used yet, but it must be freed.\n const profileFileName = wasm._OrtEndProfiling(sessionHandle);\n if (profileFileName === 0) {\n throw new Error('Can\\'t get an profile file name');\n }\n wasm._OrtFree(profileFileName);\n};\nexports.endProfiling = endProfiling;\nconst extractTransferableBuffers = (tensors) => {\n const buffers = [];\n for (const tensor of tensors) {\n const data = tensor[2];\n if (!Array.isArray(data) && data.buffer) {\n buffers.push(data.buffer);\n }\n }\n return buffers;\n};\nexports.extractTransferableBuffers = extractTransferableBuffers;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/wasm-factory.ts\":\n/*!**********************************!*\\\n !*** ./lib/wasm/wasm-factory.ts ***!\n \\**********************************/\n/***/ (function(__unused_webpack_module, exports, __webpack_require__) {\n\n\"use strict\";\nvar __dirname = \"/\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.dispose = exports.getInstance = exports.initializeWebAssembly = void 0;\nconst path = __importStar(__webpack_require__(/*! path */ \"?7aa5\"));\nconst ort_wasm_js_1 = __importDefault(__webpack_require__(/*! ./binding/ort-wasm.js */ \"./lib/wasm/binding/ort-wasm.js\"));\nconst ortWasmFactoryThreaded = \n// eslint-disable-next-line @typescript-eslint/no-require-imports\n true ? __webpack_require__(/*! ./binding/ort-wasm-threaded.js */ \"./lib/wasm/binding/ort-wasm-threaded.js\") : 0;\nlet wasm;\nlet initialized = false;\nlet initializing = false;\nlet aborted = false;\nconst isMultiThreadSupported = () => {\n try {\n // If 'SharedArrayBuffer' is not available, WebAssembly threads will not work.\n if (typeof SharedArrayBuffer === 'undefined') {\n return false;\n }\n // Test for transferability of SABs (for browsers. needed for Firefox)\n // https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ\n if (typeof MessageChannel !== 'undefined') {\n new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));\n }\n // Test for WebAssembly threads capability (for both browsers and Node.js)\n // This typed array is a WebAssembly program containing threaded instructions.\n return WebAssembly.validate(new Uint8Array([\n 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 5,\n 4, 1, 3, 1, 1, 10, 11, 1, 9, 0, 65, 0, 254, 16, 2, 0, 26, 11\n ]));\n }\n catch (e) {\n return false;\n }\n};\nconst isSimdSupported = () => {\n try {\n // Test for WebAssembly SIMD capability (for both browsers and Node.js)\n // This typed array is a WebAssembly program containing SIMD instructions.\n // The binary data is generated from the following code by wat2wasm:\n //\n // (module\n // (type $t0 (func))\n // (func $f0 (type $t0)\n // (drop\n // (i32x4.dot_i16x8_s\n // (i8x16.splat\n // (i32.const 0))\n // (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)))))\n return WebAssembly.validate(new Uint8Array([\n 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 30, 1, 28, 0, 65, 0,\n 253, 15, 253, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 253, 186, 1, 26, 11\n ]));\n }\n catch (e) {\n return false;\n }\n};\nconst getWasmFileName = (useSimd, useThreads) => {\n if (useThreads) {\n return useSimd ? 'ort-wasm-simd-threaded.wasm' : 'ort-wasm-threaded.wasm';\n }\n else {\n return useSimd ? 'ort-wasm-simd.wasm' : 'ort-wasm.wasm';\n }\n};\nconst initializeWebAssembly = async (flags) => {\n if (initialized) {\n return Promise.resolve();\n }\n if (initializing) {\n throw new Error('multiple calls to \\'initializeWebAssembly()\\' detected.');\n }\n if (aborted) {\n throw new Error('previous call to \\'initializeWebAssembly()\\' failed.');\n }\n initializing = true;\n // wasm flags are already initialized\n const timeout = flags.initTimeout;\n const numThreads = flags.numThreads;\n const simd = flags.simd;\n const useThreads = numThreads > 1 && isMultiThreadSupported();\n const useSimd = simd && isSimdSupported();\n const wasmPrefixOverride = typeof flags.wasmPaths === 'string' ? flags.wasmPaths : undefined;\n const wasmFileName = getWasmFileName(false, useThreads);\n const wasmOverrideFileName = getWasmFileName(useSimd, useThreads);\n const wasmPathOverride = typeof flags.wasmPaths === 'object' ? flags.wasmPaths[wasmOverrideFileName] : undefined;\n let isTimeout = false;\n const tasks = [];\n // promise for timeout\n if (timeout > 0) {\n tasks.push(new Promise((resolve) => {\n setTimeout(() => {\n isTimeout = true;\n resolve();\n }, timeout);\n }));\n }\n // promise for module initialization\n tasks.push(new Promise((resolve, reject) => {\n const factory = useThreads ? ortWasmFactoryThreaded : ort_wasm_js_1.default;\n const config = {\n locateFile: (fileName, scriptDirectory) => {\n if ( true && useThreads && fileName.endsWith('.worker.js') &&\n typeof Blob !== 'undefined') {\n return URL.createObjectURL(new Blob([\n // This require() function is handled by webpack to load file content of the corresponding .worker.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n __webpack_require__(/*! ./binding/ort-wasm-threaded.worker.js */ \"./lib/wasm/binding/ort-wasm-threaded.worker.js\")\n ], { type: 'text/javascript' }));\n }\n if (fileName === wasmFileName) {\n const prefix = wasmPrefixOverride !== null && wasmPrefixOverride !== void 0 ? wasmPrefixOverride : scriptDirectory;\n return wasmPathOverride !== null && wasmPathOverride !== void 0 ? wasmPathOverride : prefix + wasmOverrideFileName;\n }\n return scriptDirectory + fileName;\n }\n };\n if ( true && useThreads) {\n if (typeof Blob === 'undefined') {\n config.mainScriptUrlOrBlob = path.join(__dirname, 'ort-wasm-threaded.js');\n }\n else {\n const scriptSourceCode = `var ortWasmThreaded=(function(){var _scriptDir;return ${factory.toString()}})();`;\n config.mainScriptUrlOrBlob = new Blob([scriptSourceCode], { type: 'text/javascript' });\n }\n }\n factory(config).then(\n // wasm module initialized successfully\n module => {\n initializing = false;\n initialized = true;\n wasm = module;\n resolve();\n }, \n // wasm module failed to initialize\n (what) => {\n initializing = false;\n aborted = true;\n reject(what);\n });\n }));\n await Promise.race(tasks);\n if (isTimeout) {\n throw new Error(`WebAssembly backend initializing failed due to timeout: ${timeout}ms`);\n }\n};\nexports.initializeWebAssembly = initializeWebAssembly;\nconst getInstance = () => {\n if (initialized && wasm) {\n return wasm;\n }\n throw new Error('WebAssembly is not initialized yet.');\n};\nexports.getInstance = getInstance;\nconst dispose = () => {\n var _a;\n if (initialized && !initializing && !aborted) {\n initializing = true;\n (_a = wasm.PThread) === null || _a === void 0 ? void 0 : _a.terminateAllThreads();\n wasm = undefined;\n initializing = false;\n initialized = false;\n aborted = true;\n }\n};\nexports.dispose = dispose;\n\n\n/***/ }),\n\n/***/ \"./lib/wasm/binding/ort-wasm-threaded.worker.js\":\n/*!******************************************************!*\\\n !*** ./lib/wasm/binding/ort-wasm-threaded.worker.js ***!\n \\******************************************************/\n/***/ ((module) => {\n\n\"use strict\";\nmodule.exports = \"\\\"use strict\\\";var Module={};var ENVIRONMENT_IS_NODE=typeof process==\\\"object\\\"&&typeof process.versions==\\\"object\\\"&&typeof process.versions.node==\\\"string\\\";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require(\\\"worker_threads\\\");var parentPort=nodeWorkerThreads.parentPort;parentPort.on(\\\"message\\\",data=>onmessage({data:data}));var fs=require(\\\"fs\\\");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(fs.readFileSync(f,\\\"utf8\\\"))},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;var pendingNotifiedProxyingQueues=[];function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(\\\" \\\");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+\\\"\\\\n\\\");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(\\\" \\\");postMessage({cmd:\\\"alert\\\",text:text,threadId:Module[\\\"_pthread_self\\\"]()})}var err=threadPrintErr;self.alert=threadAlert;Module[\\\"instantiateWasm\\\"]=(info,receiveInstance)=>{var instance=new WebAssembly.Instance(Module[\\\"wasmModule\\\"],info);receiveInstance(instance);Module[\\\"wasmModule\\\"]=null;return instance.exports};self.onunhandledrejection=e=>{throw e.reason??e};self.onmessage=e=>{try{if(e.data.cmd===\\\"load\\\"){Module[\\\"wasmModule\\\"]=e.data.wasmModule;Module[\\\"wasmMemory\\\"]=e.data.wasmMemory;Module[\\\"buffer\\\"]=Module[\\\"wasmMemory\\\"].buffer;Module[\\\"ENVIRONMENT_IS_PTHREAD\\\"]=true;if(typeof e.data.urlOrBlob==\\\"string\\\"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}ortWasmThreaded(Module).then(function(instance){Module=instance})}else if(e.data.cmd===\\\"run\\\"){Module[\\\"__performance_now_clock_drift\\\"]=performance.now()-e.data.time;Module[\\\"__emscripten_thread_init\\\"](e.data.pthread_ptr,/*isMainBrowserThread=*/0,/*isMainRuntimeThread=*/0,/*canBlock=*/1);Module[\\\"establishStackSpace\\\"]();Module[\\\"PThread\\\"].receiveObjectTransfer(e.data);Module[\\\"PThread\\\"].threadInitTLS();if(!initializedJS){pendingNotifiedProxyingQueues.forEach(queue=>{Module[\\\"executeNotifiedProxyingQueue\\\"](queue)});pendingNotifiedProxyingQueues=[];initializedJS=true}try{Module[\\\"invokeEntryPoint\\\"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!=\\\"unwind\\\"){if(ex instanceof Module[\\\"ExitStatus\\\"]){if(Module[\\\"keepRuntimeAlive\\\"]()){}else{Module[\\\"__emscripten_thread_exit\\\"](ex.status)}}else{throw ex}}}}else if(e.data.cmd===\\\"cancel\\\"){if(Module[\\\"_pthread_self\\\"]()){Module[\\\"__emscripten_thread_exit\\\"](-1)}}else if(e.data.target===\\\"setimmediate\\\"){}else if(e.data.cmd===\\\"processProxyingQueue\\\"){if(initializedJS){Module[\\\"executeNotifiedProxyingQueue\\\"](e.data.queue)}else{pendingNotifiedProxyingQueues.push(e.data.queue)}}else{err(\\\"worker.js received unknown command \\\"+e.data.cmd);err(e.data)}}catch(ex){err(\\\"worker.js onmessage() captured an uncaught exception: \\\"+ex);if(ex&&ex.stack)err(ex.stack);if(Module[\\\"__emscripten_thread_crashed\\\"]){Module[\\\"__emscripten_thread_crashed\\\"]()}throw ex}};\\r\\n\";\n\n/***/ }),\n\n/***/ \"?63c8\":\n/*!********************!*\\\n !*** fs (ignored) ***!\n \\********************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ }),\n\n/***/ \"?aedb\":\n/*!********************!*\\\n !*** os (ignored) ***!\n \\********************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ }),\n\n/***/ \"?75c6\":\n/*!**********************!*\\\n !*** path (ignored) ***!\n \\**********************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ }),\n\n/***/ \"?674f\":\n/*!****************************!*\\\n !*** perf_hooks (ignored) ***!\n \\****************************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ }),\n\n/***/ \"?c6f7\":\n/*!********************************!*\\\n !*** worker_threads (ignored) ***!\n \\********************************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ }),\n\n/***/ \"?7aa5\":\n/*!**********************!*\\\n !*** path (ignored) ***!\n \\**********************/\n/***/ (() => {\n\n/* (ignored) */\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tvar cachedModule = __webpack_module_cache__[moduleId];\n/******/ \t\tif (cachedModule !== undefined) {\n/******/ \t\t\treturn cachedModule.exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/global */\n/******/ \t(() => {\n/******/ \t\t__webpack_require__.g = (function() {\n/******/ \t\t\tif (typeof globalThis === 'object') return globalThis;\n/******/ \t\t\ttry {\n/******/ \t\t\t\treturn this || new Function('return this')();\n/******/ \t\t\t} catch (e) {\n/******/ \t\t\t\tif (typeof window === 'object') return window;\n/******/ \t\t\t}\n/******/ \t\t})();\n/******/ \t})();\n/******/ \t\n/************************************************************************/\nvar __webpack_exports__ = {};\n// This entry need to be wrapped in an IIFE because it need to be in strict mode.\n(() => {\n\"use strict\";\nvar exports = __webpack_exports__;\n/*!*****************************************************************************************************!*\\\n !*** ./node_modules/ts-loader/index.js??ruleSet[1].rules[0].use[0]!./lib/wasm/proxy-worker/main.ts ***!\n \\*****************************************************************************************************/\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License.\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst wasm_core_impl_1 = __webpack_require__(/*! ../wasm-core-impl */ \"./lib/wasm/wasm-core-impl.ts\");\nconst wasm_factory_1 = __webpack_require__(/*! ../wasm-factory */ \"./lib/wasm/wasm-factory.ts\");\nself.onmessage = (ev) => {\n switch (ev.data.type) {\n case 'init-wasm':\n (0, wasm_factory_1.initializeWebAssembly)(ev.data.in)\n .then(() => postMessage({ type: 'init-wasm' }), err => postMessage({ type: 'init-wasm', err }));\n break;\n case 'init-ort':\n try {\n const { numThreads, loggingLevel } = ev.data.in;\n (0, wasm_core_impl_1.initOrt)(numThreads, loggingLevel);\n postMessage({ type: 'init-ort' });\n }\n catch (err) {\n postMessage({ type: 'init-ort', err });\n }\n break;\n case 'create_allocate':\n try {\n const { model } = ev.data.in;\n const modeldata = (0, wasm_core_impl_1.createSessionAllocate)(model);\n postMessage({ type: 'create_allocate', out: modeldata });\n }\n catch (err) {\n postMessage({ type: 'create_allocate', err });\n }\n break;\n case 'create_finalize':\n try {\n const { modeldata, options } = ev.data.in;\n const sessionMetadata = (0, wasm_core_impl_1.createSessionFinalize)(modeldata, options);\n postMessage({ type: 'create_finalize', out: sessionMetadata });\n }\n catch (err) {\n postMessage({ type: 'create_finalize', err });\n }\n break;\n case 'create':\n try {\n const { model, options } = ev.data.in;\n const sessionMetadata = (0, wasm_core_impl_1.createSession)(model, options);\n postMessage({ type: 'create', out: sessionMetadata });\n }\n catch (err) {\n postMessage({ type: 'create', err });\n }\n break;\n case 'release':\n try {\n const handler = ev.data.in;\n (0, wasm_core_impl_1.releaseSession)(handler);\n postMessage({ type: 'release' });\n }\n catch (err) {\n postMessage({ type: 'release', err });\n }\n break;\n case 'run':\n try {\n const { sessionId, inputIndices, inputs, outputIndices, options } = ev.data.in;\n const outputs = (0, wasm_core_impl_1.run)(sessionId, inputIndices, inputs, outputIndices, options);\n postMessage({ type: 'run', out: outputs }, (0, wasm_core_impl_1.extractTransferableBuffers)(outputs));\n }\n catch (err) {\n postMessage({ type: 'run', err });\n }\n break;\n case 'end-profiling':\n try {\n const handler = ev.data.in;\n (0, wasm_core_impl_1.endProfiling)(handler);\n postMessage({ type: 'end-profiling' });\n }\n catch (err) {\n postMessage({ type: 'end-profiling', err });\n }\n break;\n default:\n }\n};\n\n})();\n\n/******/ })()\n;\n", "Worker", undefined, undefined); +} + + +/***/ }), + +/***/ "./node_modules/worker-loader/dist/runtime/inline.js": +/*!***********************************************************!*\ + !*** ./node_modules/worker-loader/dist/runtime/inline.js ***! + \***********************************************************/ +/***/ ((module) => { + +"use strict"; + + +/* eslint-env browser */ + +/* eslint-disable no-undef, no-use-before-define, new-cap */ +module.exports = function (content, workerConstructor, workerOptions, url) { + var globalScope = self || window; + + try { + try { + var blob; + + try { + // New API + blob = new globalScope.Blob([content]); + } catch (e) { + // BlobBuilder = Deprecated, but widely implemented + var BlobBuilder = globalScope.BlobBuilder || globalScope.WebKitBlobBuilder || globalScope.MozBlobBuilder || globalScope.MSBlobBuilder; + blob = new BlobBuilder(); + blob.append(content); + blob = blob.getBlob(); + } + + var URL = globalScope.URL || globalScope.webkitURL; + var objectURL = URL.createObjectURL(blob); + var worker = new globalScope[workerConstructor](objectURL, workerOptions); + URL.revokeObjectURL(objectURL); + return worker; + } catch (e) { + return new globalScope[workerConstructor]("data:application/javascript,".concat(encodeURIComponent(content)), workerOptions); + } + } catch (e) { + if (!url) { + throw Error("Inline worker is not supported"); + } + + return new globalScope[workerConstructor](url, workerOptions); + } +}; + +/***/ }), + +/***/ "./lib/wasm/binding/ort-wasm-threaded.worker.js": +/*!******************************************************!*\ + !*** ./lib/wasm/binding/ort-wasm-threaded.worker.js ***! + \******************************************************/ +/***/ ((module) => { + +"use strict"; +module.exports = "\"use strict\";var Module={};var ENVIRONMENT_IS_NODE=typeof process==\"object\"&&typeof process.versions==\"object\"&&typeof process.versions.node==\"string\";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require(\"worker_threads\");var parentPort=nodeWorkerThreads.parentPort;parentPort.on(\"message\",data=>onmessage({data:data}));var fs=require(\"fs\");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(fs.readFileSync(f,\"utf8\"))},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;var pendingNotifiedProxyingQueues=[];function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(\" \");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+\"\\n\");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(\" \");postMessage({cmd:\"alert\",text:text,threadId:Module[\"_pthread_self\"]()})}var err=threadPrintErr;self.alert=threadAlert;Module[\"instantiateWasm\"]=(info,receiveInstance)=>{var instance=new WebAssembly.Instance(Module[\"wasmModule\"],info);receiveInstance(instance);Module[\"wasmModule\"]=null;return instance.exports};self.onunhandledrejection=e=>{throw e.reason??e};self.onmessage=e=>{try{if(e.data.cmd===\"load\"){Module[\"wasmModule\"]=e.data.wasmModule;Module[\"wasmMemory\"]=e.data.wasmMemory;Module[\"buffer\"]=Module[\"wasmMemory\"].buffer;Module[\"ENVIRONMENT_IS_PTHREAD\"]=true;if(typeof e.data.urlOrBlob==\"string\"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}ortWasmThreaded(Module).then(function(instance){Module=instance})}else if(e.data.cmd===\"run\"){Module[\"__performance_now_clock_drift\"]=performance.now()-e.data.time;Module[\"__emscripten_thread_init\"](e.data.pthread_ptr,/*isMainBrowserThread=*/0,/*isMainRuntimeThread=*/0,/*canBlock=*/1);Module[\"establishStackSpace\"]();Module[\"PThread\"].receiveObjectTransfer(e.data);Module[\"PThread\"].threadInitTLS();if(!initializedJS){pendingNotifiedProxyingQueues.forEach(queue=>{Module[\"executeNotifiedProxyingQueue\"](queue)});pendingNotifiedProxyingQueues=[];initializedJS=true}try{Module[\"invokeEntryPoint\"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!=\"unwind\"){if(ex instanceof Module[\"ExitStatus\"]){if(Module[\"keepRuntimeAlive\"]()){}else{Module[\"__emscripten_thread_exit\"](ex.status)}}else{throw ex}}}}else if(e.data.cmd===\"cancel\"){if(Module[\"_pthread_self\"]()){Module[\"__emscripten_thread_exit\"](-1)}}else if(e.data.target===\"setimmediate\"){}else if(e.data.cmd===\"processProxyingQueue\"){if(initializedJS){Module[\"executeNotifiedProxyingQueue\"](e.data.queue)}else{pendingNotifiedProxyingQueues.push(e.data.queue)}}else{err(\"worker.js received unknown command \"+e.data.cmd);err(e.data)}}catch(ex){err(\"worker.js onmessage() captured an uncaught exception: \"+ex);if(ex&&ex.stack)err(ex.stack);if(Module[\"__emscripten_thread_crashed\"]){Module[\"__emscripten_thread_crashed\"]()}throw ex}};\r\n"; + +/***/ }), + +/***/ "?6c45": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?b3a2": +/*!**********************!*\ + !*** util (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?63c8": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?aedb": +/*!********************!*\ + !*** os (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?75c6": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?674f": +/*!****************************!*\ + !*** perf_hooks (ignored) ***! + \****************************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?c6f7": +/*!********************************!*\ + !*** worker_threads (ignored) ***! + \********************************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?295d": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?7aa5": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?cf98": +/*!**********************!*\ + !*** util (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?0757": +/*!********************!*\ + !*** os (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "./node_modules/flatbuffers/js/flatbuffers.mjs": +/*!*****************************************************!*\ + !*** ./node_modules/flatbuffers/js/flatbuffers.mjs ***! + \*****************************************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "flatbuffers": () => (/* binding */ flatbuffers) +/* harmony export */ }); +/// @file +/// @addtogroup flatbuffers_javascript_api +/// @{ +/// @cond FLATBUFFERS_INTERNAL + +/** + * @fileoverview + * + * Need to suppress 'global this' error so the Node.js export line doesn't cause + * closure compile to error out. + * @suppress {globalThis} + */ + +/** + * @const + * @namespace + */ +var flatbuffers = {}; + +/** + * @typedef {number} + */ +flatbuffers.Offset; + +/** + * @typedef {{ + * bb: flatbuffers.ByteBuffer, + * bb_pos: number + * }} + */ +flatbuffers.Table; + +/** + * @type {number} + * @const + */ +flatbuffers.SIZEOF_SHORT = 2; + +/** + * @type {number} + * @const + */ +flatbuffers.SIZEOF_INT = 4; + +/** + * @type {number} + * @const + */ +flatbuffers.FILE_IDENTIFIER_LENGTH = 4; + +/** + * @type {number} + * @const + */ +flatbuffers.SIZE_PREFIX_LENGTH = 4; + +/** + * @enum {number} + */ +flatbuffers.Encoding = { + UTF8_BYTES: 1, + UTF16_STRING: 2 +}; + +/** + * @type {Int32Array} + * @const + */ +flatbuffers.int32 = new Int32Array(2); + +/** + * @type {Float32Array} + * @const + */ +flatbuffers.float32 = new Float32Array(flatbuffers.int32.buffer); + +/** + * @type {Float64Array} + * @const + */ +flatbuffers.float64 = new Float64Array(flatbuffers.int32.buffer); + +/** + * @type {boolean} + * @const + */ +flatbuffers.isLittleEndian = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @constructor + * @param {number} low + * @param {number} high + */ +flatbuffers.Long = function(low, high) { + /** + * @type {number} + * @const + */ + this.low = low | 0; + + /** + * @type {number} + * @const + */ + this.high = high | 0; +}; + +/** + * @param {number} low + * @param {number} high + * @returns {!flatbuffers.Long} + */ +flatbuffers.Long.create = function(low, high) { + // Special-case zero to avoid GC overhead for default values + return low == 0 && high == 0 ? flatbuffers.Long.ZERO : new flatbuffers.Long(low, high); +}; + +/** + * @returns {number} + */ +flatbuffers.Long.prototype.toFloat64 = function() { + return (this.low >>> 0) + this.high * 0x100000000; +}; + +/** + * @param {flatbuffers.Long} other + * @returns {boolean} + */ +flatbuffers.Long.prototype.equals = function(other) { + return this.low == other.low && this.high == other.high; +}; + +/** + * @type {!flatbuffers.Long} + * @const + */ +flatbuffers.Long.ZERO = new flatbuffers.Long(0, 0); + +/// @endcond +//////////////////////////////////////////////////////////////////////////////// +/** + * Create a FlatBufferBuilder. + * + * @constructor + * @param {number=} opt_initial_size + */ +flatbuffers.Builder = function(opt_initial_size) { + if (!opt_initial_size) { + var initial_size = 1024; + } else { + var initial_size = opt_initial_size; + } + + /** + * @type {flatbuffers.ByteBuffer} + * @private + */ + this.bb = flatbuffers.ByteBuffer.allocate(initial_size); + + /** + * Remaining space in the ByteBuffer. + * + * @type {number} + * @private + */ + this.space = initial_size; + + /** + * Minimum alignment encountered so far. + * + * @type {number} + * @private + */ + this.minalign = 1; + + /** + * The vtable for the current table. + * + * @type {Array.} + * @private + */ + this.vtable = null; + + /** + * The amount of fields we're actually using. + * + * @type {number} + * @private + */ + this.vtable_in_use = 0; + + /** + * Whether we are currently serializing a table. + * + * @type {boolean} + * @private + */ + this.isNested = false; + + /** + * Starting offset of the current struct/table. + * + * @type {number} + * @private + */ + this.object_start = 0; + + /** + * List of offsets of all vtables. + * + * @type {Array.} + * @private + */ + this.vtables = []; + + /** + * For the current vector being built. + * + * @type {number} + * @private + */ + this.vector_num_elems = 0; + + /** + * False omits default values from the serialized data + * + * @type {boolean} + * @private + */ + this.force_defaults = false; +}; + +flatbuffers.Builder.prototype.clear = function() { + this.bb.clear(); + this.space = this.bb.capacity(); + this.minalign = 1; + this.vtable = null; + this.vtable_in_use = 0; + this.isNested = false; + this.object_start = 0; + this.vtables = []; + this.vector_num_elems = 0; + this.force_defaults = false; +}; + +/** + * In order to save space, fields that are set to their default value + * don't get serialized into the buffer. Forcing defaults provides a + * way to manually disable this optimization. + * + * @param {boolean} forceDefaults true always serializes default values + */ +flatbuffers.Builder.prototype.forceDefaults = function(forceDefaults) { + this.force_defaults = forceDefaults; +}; + +/** + * Get the ByteBuffer representing the FlatBuffer. Only call this after you've + * called finish(). The actual data starts at the ByteBuffer's current position, + * not necessarily at 0. + * + * @returns {flatbuffers.ByteBuffer} + */ +flatbuffers.Builder.prototype.dataBuffer = function() { + return this.bb; +}; + +/** + * Get the bytes representing the FlatBuffer. Only call this after you've + * called finish(). + * + * @returns {!Uint8Array} + */ +flatbuffers.Builder.prototype.asUint8Array = function() { + return this.bb.bytes().subarray(this.bb.position(), this.bb.position() + this.offset()); +}; + +/// @cond FLATBUFFERS_INTERNAL +/** + * Prepare to write an element of `size` after `additional_bytes` have been + * written, e.g. if you write a string, you need to align such the int length + * field is aligned to 4 bytes, and the string data follows it directly. If all + * you need to do is alignment, `additional_bytes` will be 0. + * + * @param {number} size This is the of the new element to write + * @param {number} additional_bytes The padding size + */ +flatbuffers.Builder.prototype.prep = function(size, additional_bytes) { + // Track the biggest thing we've ever aligned to. + if (size > this.minalign) { + this.minalign = size; + } + + // Find the amount of alignment needed such that `size` is properly + // aligned after `additional_bytes` + var align_size = ((~(this.bb.capacity() - this.space + additional_bytes)) + 1) & (size - 1); + + // Reallocate the buffer if needed. + while (this.space < align_size + size + additional_bytes) { + var old_buf_size = this.bb.capacity(); + this.bb = flatbuffers.Builder.growByteBuffer(this.bb); + this.space += this.bb.capacity() - old_buf_size; + } + + this.pad(align_size); +}; + +/** + * @param {number} byte_size + */ +flatbuffers.Builder.prototype.pad = function(byte_size) { + for (var i = 0; i < byte_size; i++) { + this.bb.writeInt8(--this.space, 0); + } +}; + +/** + * @param {number} value + */ +flatbuffers.Builder.prototype.writeInt8 = function(value) { + this.bb.writeInt8(this.space -= 1, value); +}; + +/** + * @param {number} value + */ +flatbuffers.Builder.prototype.writeInt16 = function(value) { + this.bb.writeInt16(this.space -= 2, value); +}; + +/** + * @param {number} value + */ +flatbuffers.Builder.prototype.writeInt32 = function(value) { + this.bb.writeInt32(this.space -= 4, value); +}; + +/** + * @param {flatbuffers.Long} value + */ +flatbuffers.Builder.prototype.writeInt64 = function(value) { + this.bb.writeInt64(this.space -= 8, value); +}; + +/** + * @param {number} value + */ +flatbuffers.Builder.prototype.writeFloat32 = function(value) { + this.bb.writeFloat32(this.space -= 4, value); +}; + +/** + * @param {number} value + */ +flatbuffers.Builder.prototype.writeFloat64 = function(value) { + this.bb.writeFloat64(this.space -= 8, value); +}; +/// @endcond + +/** + * Add an `int8` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {number} value The `int8` to add the the buffer. + */ +flatbuffers.Builder.prototype.addInt8 = function(value) { + this.prep(1, 0); + this.writeInt8(value); +}; + +/** + * Add an `int16` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {number} value The `int16` to add the the buffer. + */ +flatbuffers.Builder.prototype.addInt16 = function(value) { + this.prep(2, 0); + this.writeInt16(value); +}; + +/** + * Add an `int32` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {number} value The `int32` to add the the buffer. + */ +flatbuffers.Builder.prototype.addInt32 = function(value) { + this.prep(4, 0); + this.writeInt32(value); +}; + +/** + * Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {flatbuffers.Long} value The `int64` to add the the buffer. + */ +flatbuffers.Builder.prototype.addInt64 = function(value) { + this.prep(8, 0); + this.writeInt64(value); +}; + +/** + * Add a `float32` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {number} value The `float32` to add the the buffer. + */ +flatbuffers.Builder.prototype.addFloat32 = function(value) { + this.prep(4, 0); + this.writeFloat32(value); +}; + +/** + * Add a `float64` to the buffer, properly aligned, and grows the buffer (if necessary). + * @param {number} value The `float64` to add the the buffer. + */ +flatbuffers.Builder.prototype.addFloat64 = function(value) { + this.prep(8, 0); + this.writeFloat64(value); +}; + +/// @cond FLATBUFFERS_INTERNAL +/** + * @param {number} voffset + * @param {number} value + * @param {number} defaultValue + */ +flatbuffers.Builder.prototype.addFieldInt8 = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addInt8(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {number} value + * @param {number} defaultValue + */ +flatbuffers.Builder.prototype.addFieldInt16 = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addInt16(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {number} value + * @param {number} defaultValue + */ +flatbuffers.Builder.prototype.addFieldInt32 = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addInt32(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {flatbuffers.Long} value + * @param {flatbuffers.Long} defaultValue + */ +flatbuffers.Builder.prototype.addFieldInt64 = function(voffset, value, defaultValue) { + if (this.force_defaults || !value.equals(defaultValue)) { + this.addInt64(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {number} value + * @param {number} defaultValue + */ +flatbuffers.Builder.prototype.addFieldFloat32 = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addFloat32(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {number} value + * @param {number} defaultValue + */ +flatbuffers.Builder.prototype.addFieldFloat64 = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addFloat64(value); + this.slot(voffset); + } +}; + +/** + * @param {number} voffset + * @param {flatbuffers.Offset} value + * @param {flatbuffers.Offset} defaultValue + */ +flatbuffers.Builder.prototype.addFieldOffset = function(voffset, value, defaultValue) { + if (this.force_defaults || value != defaultValue) { + this.addOffset(value); + this.slot(voffset); + } +}; + +/** + * Structs are stored inline, so nothing additional is being added. `d` is always 0. + * + * @param {number} voffset + * @param {flatbuffers.Offset} value + * @param {flatbuffers.Offset} defaultValue + */ +flatbuffers.Builder.prototype.addFieldStruct = function(voffset, value, defaultValue) { + if (value != defaultValue) { + this.nested(value); + this.slot(voffset); + } +}; + +/** + * Structures are always stored inline, they need to be created right + * where they're used. You'll get this assertion failure if you + * created it elsewhere. + * + * @param {flatbuffers.Offset} obj The offset of the created object + */ +flatbuffers.Builder.prototype.nested = function(obj) { + if (obj != this.offset()) { + throw new Error('FlatBuffers: struct must be serialized inline.'); + } +}; + +/** + * Should not be creating any other object, string or vector + * while an object is being constructed + */ +flatbuffers.Builder.prototype.notNested = function() { + if (this.isNested) { + throw new Error('FlatBuffers: object serialization must not be nested.'); + } +}; + +/** + * Set the current vtable at `voffset` to the current location in the buffer. + * + * @param {number} voffset + */ +flatbuffers.Builder.prototype.slot = function(voffset) { + this.vtable[voffset] = this.offset(); +}; + +/** + * @returns {flatbuffers.Offset} Offset relative to the end of the buffer. + */ +flatbuffers.Builder.prototype.offset = function() { + return this.bb.capacity() - this.space; +}; + +/** + * Doubles the size of the backing ByteBuffer and copies the old data towards + * the end of the new buffer (since we build the buffer backwards). + * + * @param {flatbuffers.ByteBuffer} bb The current buffer with the existing data + * @returns {!flatbuffers.ByteBuffer} A new byte buffer with the old data copied + * to it. The data is located at the end of the buffer. + * + * uint8Array.set() formally takes {Array|ArrayBufferView}, so to pass + * it a uint8Array we need to suppress the type check: + * @suppress {checkTypes} + */ +flatbuffers.Builder.growByteBuffer = function(bb) { + var old_buf_size = bb.capacity(); + + // Ensure we don't grow beyond what fits in an int. + if (old_buf_size & 0xC0000000) { + throw new Error('FlatBuffers: cannot grow buffer beyond 2 gigabytes.'); + } + + var new_buf_size = old_buf_size << 1; + var nbb = flatbuffers.ByteBuffer.allocate(new_buf_size); + nbb.setPosition(new_buf_size - old_buf_size); + nbb.bytes().set(bb.bytes(), new_buf_size - old_buf_size); + return nbb; +}; +/// @endcond + +/** + * Adds on offset, relative to where it will be written. + * + * @param {flatbuffers.Offset} offset The offset to add. + */ +flatbuffers.Builder.prototype.addOffset = function(offset) { + this.prep(flatbuffers.SIZEOF_INT, 0); // Ensure alignment is already done. + this.writeInt32(this.offset() - offset + flatbuffers.SIZEOF_INT); +}; + +/// @cond FLATBUFFERS_INTERNAL +/** + * Start encoding a new object in the buffer. Users will not usually need to + * call this directly. The FlatBuffers compiler will generate helper methods + * that call this method internally. + * + * @param {number} numfields + */ +flatbuffers.Builder.prototype.startObject = function(numfields) { + this.notNested(); + if (this.vtable == null) { + this.vtable = []; + } + this.vtable_in_use = numfields; + for (var i = 0; i < numfields; i++) { + this.vtable[i] = 0; // This will push additional elements as needed + } + this.isNested = true; + this.object_start = this.offset(); +}; + +/** + * Finish off writing the object that is under construction. + * + * @returns {flatbuffers.Offset} The offset to the object inside `dataBuffer` + */ +flatbuffers.Builder.prototype.endObject = function() { + if (this.vtable == null || !this.isNested) { + throw new Error('FlatBuffers: endObject called without startObject'); + } + + this.addInt32(0); + var vtableloc = this.offset(); + + // Trim trailing zeroes. + var i = this.vtable_in_use - 1; + for (; i >= 0 && this.vtable[i] == 0; i--) {} + var trimmed_size = i + 1; + + // Write out the current vtable. + for (; i >= 0; i--) { + // Offset relative to the start of the table. + this.addInt16(this.vtable[i] != 0 ? vtableloc - this.vtable[i] : 0); + } + + var standard_fields = 2; // The fields below: + this.addInt16(vtableloc - this.object_start); + var len = (trimmed_size + standard_fields) * flatbuffers.SIZEOF_SHORT; + this.addInt16(len); + + // Search for an existing vtable that matches the current one. + var existing_vtable = 0; + var vt1 = this.space; +outer_loop: + for (i = 0; i < this.vtables.length; i++) { + var vt2 = this.bb.capacity() - this.vtables[i]; + if (len == this.bb.readInt16(vt2)) { + for (var j = flatbuffers.SIZEOF_SHORT; j < len; j += flatbuffers.SIZEOF_SHORT) { + if (this.bb.readInt16(vt1 + j) != this.bb.readInt16(vt2 + j)) { + continue outer_loop; + } + } + existing_vtable = this.vtables[i]; + break; + } + } + + if (existing_vtable) { + // Found a match: + // Remove the current vtable. + this.space = this.bb.capacity() - vtableloc; + + // Point table to existing vtable. + this.bb.writeInt32(this.space, existing_vtable - vtableloc); + } else { + // No match: + // Add the location of the current vtable to the list of vtables. + this.vtables.push(this.offset()); + + // Point table to current vtable. + this.bb.writeInt32(this.bb.capacity() - vtableloc, this.offset() - vtableloc); + } + + this.isNested = false; + return vtableloc; +}; +/// @endcond + +/** + * Finalize a buffer, poiting to the given `root_table`. + * + * @param {flatbuffers.Offset} root_table + * @param {string=} opt_file_identifier + * @param {boolean=} opt_size_prefix + */ +flatbuffers.Builder.prototype.finish = function(root_table, opt_file_identifier, opt_size_prefix) { + var size_prefix = opt_size_prefix ? flatbuffers.SIZE_PREFIX_LENGTH : 0; + if (opt_file_identifier) { + var file_identifier = opt_file_identifier; + this.prep(this.minalign, flatbuffers.SIZEOF_INT + + flatbuffers.FILE_IDENTIFIER_LENGTH + size_prefix); + if (file_identifier.length != flatbuffers.FILE_IDENTIFIER_LENGTH) { + throw new Error('FlatBuffers: file identifier must be length ' + + flatbuffers.FILE_IDENTIFIER_LENGTH); + } + for (var i = flatbuffers.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { + this.writeInt8(file_identifier.charCodeAt(i)); + } + } + this.prep(this.minalign, flatbuffers.SIZEOF_INT + size_prefix); + this.addOffset(root_table); + if (size_prefix) { + this.addInt32(this.bb.capacity() - this.space); + } + this.bb.setPosition(this.space); +}; + +/** + * Finalize a size prefixed buffer, pointing to the given `root_table`. + * + * @param {flatbuffers.Offset} root_table + * @param {string=} opt_file_identifier + */ +flatbuffers.Builder.prototype.finishSizePrefixed = function (root_table, opt_file_identifier) { + this.finish(root_table, opt_file_identifier, true); +}; + +/// @cond FLATBUFFERS_INTERNAL +/** + * This checks a required field has been set in a given table that has + * just been constructed. + * + * @param {flatbuffers.Offset} table + * @param {number} field + */ +flatbuffers.Builder.prototype.requiredField = function(table, field) { + var table_start = this.bb.capacity() - table; + var vtable_start = table_start - this.bb.readInt32(table_start); + var ok = this.bb.readInt16(vtable_start + field) != 0; + + // If this fails, the caller will show what field needs to be set. + if (!ok) { + throw new Error('FlatBuffers: field ' + field + ' must be set'); + } +}; + +/** + * Start a new array/vector of objects. Users usually will not call + * this directly. The FlatBuffers compiler will create a start/end + * method for vector types in generated code. + * + * @param {number} elem_size The size of each element in the array + * @param {number} num_elems The number of elements in the array + * @param {number} alignment The alignment of the array + */ +flatbuffers.Builder.prototype.startVector = function(elem_size, num_elems, alignment) { + this.notNested(); + this.vector_num_elems = num_elems; + this.prep(flatbuffers.SIZEOF_INT, elem_size * num_elems); + this.prep(alignment, elem_size * num_elems); // Just in case alignment > int. +}; + +/** + * Finish off the creation of an array and all its elements. The array must be + * created with `startVector`. + * + * @returns {flatbuffers.Offset} The offset at which the newly created array + * starts. + */ +flatbuffers.Builder.prototype.endVector = function() { + this.writeInt32(this.vector_num_elems); + return this.offset(); +}; +/// @endcond + +/** + * Encode the string `s` in the buffer using UTF-8. If a Uint8Array is passed + * instead of a string, it is assumed to contain valid UTF-8 encoded data. + * + * @param {string|Uint8Array} s The string to encode + * @return {flatbuffers.Offset} The offset in the buffer where the encoded string starts + */ +flatbuffers.Builder.prototype.createString = function(s) { + if (s instanceof Uint8Array) { + var utf8 = s; + } else { + var utf8 = []; + var i = 0; + + while (i < s.length) { + var codePoint; + + // Decode UTF-16 + var a = s.charCodeAt(i++); + if (a < 0xD800 || a >= 0xDC00) { + codePoint = a; + } else { + var b = s.charCodeAt(i++); + codePoint = (a << 10) + b + (0x10000 - (0xD800 << 10) - 0xDC00); + } + + // Encode UTF-8 + if (codePoint < 0x80) { + utf8.push(codePoint); + } else { + if (codePoint < 0x800) { + utf8.push(((codePoint >> 6) & 0x1F) | 0xC0); + } else { + if (codePoint < 0x10000) { + utf8.push(((codePoint >> 12) & 0x0F) | 0xE0); + } else { + utf8.push( + ((codePoint >> 18) & 0x07) | 0xF0, + ((codePoint >> 12) & 0x3F) | 0x80); + } + utf8.push(((codePoint >> 6) & 0x3F) | 0x80); + } + utf8.push((codePoint & 0x3F) | 0x80); + } + } + } + + this.addInt8(0); + this.startVector(1, utf8.length, 1); + this.bb.setPosition(this.space -= utf8.length); + for (var i = 0, offset = this.space, bytes = this.bb.bytes(); i < utf8.length; i++) { + bytes[offset++] = utf8[i]; + } + return this.endVector(); +}; + +/** + * A helper function to avoid generated code depending on this file directly. + * + * @param {number} low + * @param {number} high + * @returns {!flatbuffers.Long} + */ +flatbuffers.Builder.prototype.createLong = function(low, high) { + return flatbuffers.Long.create(low, high); +}; +//////////////////////////////////////////////////////////////////////////////// +/// @cond FLATBUFFERS_INTERNAL +/** + * Create a new ByteBuffer with a given array of bytes (`Uint8Array`). + * + * @constructor + * @param {Uint8Array} bytes + */ +flatbuffers.ByteBuffer = function(bytes) { + /** + * @type {Uint8Array} + * @private + */ + this.bytes_ = bytes; + + /** + * @type {number} + * @private + */ + this.position_ = 0; +}; + +/** + * Create and allocate a new ByteBuffer with a given size. + * + * @param {number} byte_size + * @returns {!flatbuffers.ByteBuffer} + */ +flatbuffers.ByteBuffer.allocate = function(byte_size) { + return new flatbuffers.ByteBuffer(new Uint8Array(byte_size)); +}; + +flatbuffers.ByteBuffer.prototype.clear = function() { + this.position_ = 0; +}; + +/** + * Get the underlying `Uint8Array`. + * + * @returns {Uint8Array} + */ +flatbuffers.ByteBuffer.prototype.bytes = function() { + return this.bytes_; +}; + +/** + * Get the buffer's position. + * + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.position = function() { + return this.position_; +}; + +/** + * Set the buffer's position. + * + * @param {number} position + */ +flatbuffers.ByteBuffer.prototype.setPosition = function(position) { + this.position_ = position; +}; + +/** + * Get the buffer's capacity. + * + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.capacity = function() { + return this.bytes_.length; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readInt8 = function(offset) { + return this.readUint8(offset) << 24 >> 24; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readUint8 = function(offset) { + return this.bytes_[offset]; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readInt16 = function(offset) { + return this.readUint16(offset) << 16 >> 16; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readUint16 = function(offset) { + return this.bytes_[offset] | this.bytes_[offset + 1] << 8; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readInt32 = function(offset) { + return this.bytes_[offset] | this.bytes_[offset + 1] << 8 | this.bytes_[offset + 2] << 16 | this.bytes_[offset + 3] << 24; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readUint32 = function(offset) { + return this.readInt32(offset) >>> 0; +}; + +/** + * @param {number} offset + * @returns {!flatbuffers.Long} + */ +flatbuffers.ByteBuffer.prototype.readInt64 = function(offset) { + return new flatbuffers.Long(this.readInt32(offset), this.readInt32(offset + 4)); +}; + +/** + * @param {number} offset + * @returns {!flatbuffers.Long} + */ +flatbuffers.ByteBuffer.prototype.readUint64 = function(offset) { + return new flatbuffers.Long(this.readUint32(offset), this.readUint32(offset + 4)); +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readFloat32 = function(offset) { + flatbuffers.int32[0] = this.readInt32(offset); + return flatbuffers.float32[0]; +}; + +/** + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.readFloat64 = function(offset) { + flatbuffers.int32[flatbuffers.isLittleEndian ? 0 : 1] = this.readInt32(offset); + flatbuffers.int32[flatbuffers.isLittleEndian ? 1 : 0] = this.readInt32(offset + 4); + return flatbuffers.float64[0]; +}; + +/** + * @param {number} offset + * @param {number|boolean} value + */ +flatbuffers.ByteBuffer.prototype.writeInt8 = function(offset, value) { + this.bytes_[offset] = /** @type {number} */(value); +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeUint8 = function(offset, value) { + this.bytes_[offset] = value; +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeInt16 = function(offset, value) { + this.bytes_[offset] = value; + this.bytes_[offset + 1] = value >> 8; +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeUint16 = function(offset, value) { + this.bytes_[offset] = value; + this.bytes_[offset + 1] = value >> 8; +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeInt32 = function(offset, value) { + this.bytes_[offset] = value; + this.bytes_[offset + 1] = value >> 8; + this.bytes_[offset + 2] = value >> 16; + this.bytes_[offset + 3] = value >> 24; +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeUint32 = function(offset, value) { + this.bytes_[offset] = value; + this.bytes_[offset + 1] = value >> 8; + this.bytes_[offset + 2] = value >> 16; + this.bytes_[offset + 3] = value >> 24; +}; + +/** + * @param {number} offset + * @param {flatbuffers.Long} value + */ +flatbuffers.ByteBuffer.prototype.writeInt64 = function(offset, value) { + this.writeInt32(offset, value.low); + this.writeInt32(offset + 4, value.high); +}; + +/** + * @param {number} offset + * @param {flatbuffers.Long} value + */ +flatbuffers.ByteBuffer.prototype.writeUint64 = function(offset, value) { + this.writeUint32(offset, value.low); + this.writeUint32(offset + 4, value.high); +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeFloat32 = function(offset, value) { + flatbuffers.float32[0] = value; + this.writeInt32(offset, flatbuffers.int32[0]); +}; + +/** + * @param {number} offset + * @param {number} value + */ +flatbuffers.ByteBuffer.prototype.writeFloat64 = function(offset, value) { + flatbuffers.float64[0] = value; + this.writeInt32(offset, flatbuffers.int32[flatbuffers.isLittleEndian ? 0 : 1]); + this.writeInt32(offset + 4, flatbuffers.int32[flatbuffers.isLittleEndian ? 1 : 0]); +}; + +/** + * Return the file identifier. Behavior is undefined for FlatBuffers whose + * schema does not include a file_identifier (likely points at padding or the + * start of a the root vtable). + * @returns {string} + */ +flatbuffers.ByteBuffer.prototype.getBufferIdentifier = function() { + if (this.bytes_.length < this.position_ + flatbuffers.SIZEOF_INT + + flatbuffers.FILE_IDENTIFIER_LENGTH) { + throw new Error( + 'FlatBuffers: ByteBuffer is too short to contain an identifier.'); + } + var result = ""; + for (var i = 0; i < flatbuffers.FILE_IDENTIFIER_LENGTH; i++) { + result += String.fromCharCode( + this.readInt8(this.position_ + flatbuffers.SIZEOF_INT + i)); + } + return result; +}; + +/** + * Look up a field in the vtable, return an offset into the object, or 0 if the + * field is not present. + * + * @param {number} bb_pos + * @param {number} vtable_offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.__offset = function(bb_pos, vtable_offset) { + var vtable = bb_pos - this.readInt32(bb_pos); + return vtable_offset < this.readInt16(vtable) ? this.readInt16(vtable + vtable_offset) : 0; +}; + +/** + * Initialize any Table-derived type to point to the union at the given offset. + * + * @param {flatbuffers.Table} t + * @param {number} offset + * @returns {flatbuffers.Table} + */ +flatbuffers.ByteBuffer.prototype.__union = function(t, offset) { + t.bb_pos = offset + this.readInt32(offset); + t.bb = this; + return t; +}; + +/** + * Create a JavaScript string from UTF-8 data stored inside the FlatBuffer. + * This allocates a new string and converts to wide chars upon each access. + * + * To avoid the conversion to UTF-16, pass flatbuffers.Encoding.UTF8_BYTES as + * the "optionalEncoding" argument. This is useful for avoiding conversion to + * and from UTF-16 when the data will just be packaged back up in another + * FlatBuffer later on. + * + * @param {number} offset + * @param {flatbuffers.Encoding=} opt_encoding Defaults to UTF16_STRING + * @returns {string|!Uint8Array} + */ +flatbuffers.ByteBuffer.prototype.__string = function(offset, opt_encoding) { + offset += this.readInt32(offset); + + var length = this.readInt32(offset); + var result = ''; + var i = 0; + + offset += flatbuffers.SIZEOF_INT; + + if (opt_encoding === flatbuffers.Encoding.UTF8_BYTES) { + return this.bytes_.subarray(offset, offset + length); + } + + while (i < length) { + var codePoint; + + // Decode UTF-8 + var a = this.readUint8(offset + i++); + if (a < 0xC0) { + codePoint = a; + } else { + var b = this.readUint8(offset + i++); + if (a < 0xE0) { + codePoint = + ((a & 0x1F) << 6) | + (b & 0x3F); + } else { + var c = this.readUint8(offset + i++); + if (a < 0xF0) { + codePoint = + ((a & 0x0F) << 12) | + ((b & 0x3F) << 6) | + (c & 0x3F); + } else { + var d = this.readUint8(offset + i++); + codePoint = + ((a & 0x07) << 18) | + ((b & 0x3F) << 12) | + ((c & 0x3F) << 6) | + (d & 0x3F); + } + } + } + + // Encode UTF-16 + if (codePoint < 0x10000) { + result += String.fromCharCode(codePoint); + } else { + codePoint -= 0x10000; + result += String.fromCharCode( + (codePoint >> 10) + 0xD800, + (codePoint & ((1 << 10) - 1)) + 0xDC00); + } + } + + return result; +}; + +/** + * Retrieve the relative offset stored at "offset" + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.__indirect = function(offset) { + return offset + this.readInt32(offset); +}; + +/** + * Get the start of data of a vector whose offset is stored at "offset" in this object. + * + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.__vector = function(offset) { + return offset + this.readInt32(offset) + flatbuffers.SIZEOF_INT; // data starts after the length +}; + +/** + * Get the length of a vector whose offset is stored at "offset" in this object. + * + * @param {number} offset + * @returns {number} + */ +flatbuffers.ByteBuffer.prototype.__vector_len = function(offset) { + return this.readInt32(offset + this.readInt32(offset)); +}; + +/** + * @param {string} ident + * @returns {boolean} + */ +flatbuffers.ByteBuffer.prototype.__has_identifier = function(ident) { + if (ident.length != flatbuffers.FILE_IDENTIFIER_LENGTH) { + throw new Error('FlatBuffers: file identifier must be length ' + + flatbuffers.FILE_IDENTIFIER_LENGTH); + } + for (var i = 0; i < flatbuffers.FILE_IDENTIFIER_LENGTH; i++) { + if (ident.charCodeAt(i) != this.readInt8(this.position_ + flatbuffers.SIZEOF_INT + i)) { + return false; + } + } + return true; +}; + +/** + * A helper function to avoid generated code depending on this file directly. + * + * @param {number} low + * @param {number} high + * @returns {!flatbuffers.Long} + */ +flatbuffers.ByteBuffer.prototype.createLong = function(low, high) { + return flatbuffers.Long.create(low, high); +}; + +// Exports for Node.js and RequireJS + + +/// @endcond +/// @} + + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/global */ +/******/ (() => { +/******/ __webpack_require__.g = (function() { +/******/ if (typeof globalThis === 'object') return globalThis; +/******/ try { +/******/ return this || new Function('return this')(); +/******/ } catch (e) { +/******/ if (typeof window === 'object') return window; +/******/ } +/******/ })(); +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __webpack_require__("./lib/index.ts"); +/******/ +/******/ return __webpack_exports__; +/******/ })() +; +}); diff --git a/toolkit/components/ml/vendor/ort.js b/toolkit/components/ml/vendor/ort.js new file mode 100644 index 0000000000..965abd5e2d --- /dev/null +++ b/toolkit/components/ml/vendor/ort.js @@ -0,0 +1,7 @@ +/*! +* ONNX Runtime Web v1.14.0 +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. +*/ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ort=e():t.ort=e()}(self,(()=>(()=>{var __webpack_modules__={8453:(t,e,n)=>{"use strict";n.r(e),n.d(e,{InferenceSession:()=>h,Tensor:()=>f,env:()=>a,registerBackend:()=>o});const r={},i=[],o=(t,e,n)=>{if(!e||"function"!=typeof e.init||"function"!=typeof e.createSessionHandler)throw new TypeError("not a valid backend");{const o=r[t];if(void 0===o)r[t]={backend:e,priority:n};else{if(o.priority>n)return;if(o.priority===n&&o.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${n}`)}if(n>=0){const e=i.indexOf(t);-1!==e&&i.splice(e,1);for(let e=0;e{let e=1;for(let n=0;n{const i=document.createElement("canvas"),o=i.getContext("2d");if(!t||!o)return r();const a=new Image;a.crossOrigin="Anonymous",a.src=t,a.onload=()=>{i.width=a.width,i.height=a.height,o.drawImage(a,0,0,i.width,i.height);const t=o.getImageData(0,0,i.width,i.height);if(void 0!==e){if(void 0!==e.height&&e.height!==i.height)throw new Error("Image input config height doesn't match ImageBitmap height");if(s.height=i.height,void 0!==e.width&&e.width!==i.width)throw new Error("Image input config width doesn't match ImageBitmap width");s.width=i.width}else s.height=i.height,s.width=i.width;n(p.bufferToTensor(t.data,s))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{const n="RGBA";let r,i;if(void 0!==e&&void 0!==e.resizedWidth&&void 0!==e.resizedHeight?(r=e.resizedHeight,i=e.resizedWidth):(r=t.height,i=t.width),void 0!==e){if(s=e,void 0!==e.bitmapFormat&&e.bitmapFormat!==n)throw new Error("Image input config format must be RGBA for ImageData");s.bitmapFormat="RGBA"}else s.bitmapFormat="RGBA";if(s.height=r,s.width=i,void 0!==e){const e=document.createElement("canvas");e.width=i,e.height=r;const n=e.getContext("2d");if(null==n)throw new Error("Can not access image data");n.putImageData(t,0,0),a=n.getImageData(0,0,i,r).data}else a=t.data}}if(void 0!==a)return p.bufferToTensor(a,s);throw new Error("Input data provided is not supported - aborted tensor creation")}toImageData(t){var e,n;const r=document.createElement("canvas").getContext("2d");let i;if(null==r)throw new Error("Can not access image data");{const o=this.dims[3],a=this.dims[2],s=this.dims[1],u=void 0!==t&&void 0!==t.format?t.format:"RGB",c=void 0!==t&&void 0!==(null===(e=t.norm)||void 0===e?void 0:e.mean)?t.norm.mean:255,l=void 0!==t&&void 0!==(null===(n=t.norm)||void 0===n?void 0:n.bias)?t.norm.bias:0,p=a*o;if(void 0!==t){if(void 0!==t.height&&t.height!==a)throw new Error("Image output config height doesn't match tensor height");if(void 0!==t.width&&t.width!==o)throw new Error("Image output config width doesn't match tensor width");if(void 0!==t.format&&4===s&&"RGBA"!==t.format||3===s&&"RGB"!==t.format&&"BGR"!==t.format)throw new Error("Tensor format doesn't match input tensor dims")}const f=4;let d=0,h=1,g=2,b=3,m=0,y=p,_=2*p,v=-1;"RGBA"===u?(m=0,y=p,_=2*p,v=3*p):"RGB"===u?(m=0,y=p,_=2*p):"RBG"===u&&(m=0,_=p,y=2*p),i=r.createImageData(o,a);for(let t=0;t=r.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${r.byteLength}).`);if(u=t.byteLength-i,"number"==typeof n){if(u=n,!Number.isSafeInteger(u))throw new RangeError("'byteLength' must be an integer.");if(u<=0||i+u>r.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${r.byteLength-i}].`);if("object"==typeof o&&null!==o)s=o;else if(void 0!==o)throw new TypeError("'options' must be an object.")}else if(void 0!==n)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==e)throw new TypeError("'options' must be an object.");a=new Uint8Array(r,i,u)}}const u=(s.executionProviders||[]).map((t=>"string"==typeof t?t:t.name)),c=await(async t=>{const e=0===t.length?i:t,n=[];for(const t of e){const e=r[t];if(e){if(e.initialized)return e.backend;if(e.aborted)continue;const r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init()),await e.initPromise,e.initialized=!0,e.backend}catch(i){r||n.push({name:t,err:i}),e.aborted=!0}finally{delete e.initPromise}}}throw new Error(`no available backend found. ERR: ${n.map((t=>`[${t.name}] ${t.err}`)).join(", ")}`)})(u),l=await c.createSessionHandler(a,s);return new d(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}const h=d},3474:(t,e,n)=>{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){function e(){return $.buffer!=C&&H($.buffer),F}function r(){return $.buffer!=C&&H($.buffer),N}function i(){return $.buffer!=C&&H($.buffer),R}function o(){return $.buffer!=C&&H($.buffer),L}function a(){return $.buffer!=C&&H($.buffer),j}var s,u,c;t=t||{},s||(s=void 0!==t?t:{}),s.ready=new Promise((function(t,e){u=t,c=e}));var l,p,f,d,h,g,b=Object.assign({},s),m="./this.program",y=(t,e)=>{throw e},_="object"==typeof window,v="function"==typeof importScripts,w="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,x=s.ENVIRONMENT_IS_PTHREAD||!1,T="";function S(t){return s.locateFile?s.locateFile(t,T):T+t}if(w){let e;T=v?n(908).dirname(T)+"/":"//",g=()=>{h||(d=n(1384),h=n(908))},l=function(t,e){return g(),t=h.normalize(t),d.readFileSync(t,e?void 0:"utf8")},f=t=>((t=l(t,!0)).buffer||(t=new Uint8Array(t)),t),p=(t,e,n)=>{g(),t=h.normalize(t),d.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(J())throw process.exitCode=t,e;e instanceof ut||P("exiting due to exception: "+e),process.exit(t)},s.inspect=function(){return"[Emscripten Module object]"};try{e=n(9925)}catch(t){throw console.error('The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?'),t}n.g.Worker=e.Worker}else(_||v)&&(v?T=self.location.href:"undefined"!=typeof document&&document.currentScript&&(T=document.currentScript.src),_scriptDir&&(T=_scriptDir),T=0!==T.indexOf("blob:")?T.substr(0,T.replace(/[?#].*/,"").lastIndexOf("/")+1):"",w||(l=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},v&&(f=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),p=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)}));w&&"undefined"==typeof performance&&(n.g.performance=n(6953).performance);var O=console.log.bind(console),A=console.warn.bind(console);w&&(g(),O=t=>d.writeSync(1,t+"\n"),A=t=>d.writeSync(2,t+"\n"));var E,I=s.print||O,P=s.printErr||A;Object.assign(s,b),b=null,s.thisProgram&&(m=s.thisProgram),s.quit&&(y=s.quit),s.wasmBinary&&(E=s.wasmBinary);var D=s.noExitRuntime||!1;"object"!=typeof WebAssembly&&it("no native wasm support detected");var $,k,C,F,N,R,L,j,M=!1,U="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function V(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(i=224==(240&i)?(15&i)<<12|o<<6|a:(7&i)<<18|o<<12|a<<6|63&t[e++])?r+=String.fromCharCode(i):(i-=65536,r+=String.fromCharCode(55296|i>>10,56320|1023&i))}}else r+=String.fromCharCode(i)}return r}function B(t,e){return(t>>>=0)?V(r(),t,e):""}function z(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var o=0;o=a&&(a=65536+((1023&a)<<10)|1023&t.charCodeAt(++o)),127>=a){if(n>=r)break;e[n++>>>0]=a}else{if(2047>=a){if(n+1>=r)break;e[n++>>>0]=192|a>>6}else{if(65535>=a){if(n+2>=r)break;e[n++>>>0]=224|a>>12}else{if(n+3>=r)break;e[n++>>>0]=240|a>>18,e[n++>>>0]=128|a>>12&63}e[n++>>>0]=128|a>>6&63}e[n++>>>0]=128|63&a}}return e[n>>>0]=0,n-i}function G(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function H(t){C=t,s.HEAP8=F=new Int8Array(t),s.HEAP16=new Int16Array(t),s.HEAP32=R=new Int32Array(t),s.HEAPU8=N=new Uint8Array(t),s.HEAPU16=new Uint16Array(t),s.HEAPU32=L=new Uint32Array(t),s.HEAPF32=new Float32Array(t),s.HEAPF64=j=new Float64Array(t)}x&&(C=s.buffer);var W=s.INITIAL_MEMORY||16777216;if(x)$=s.wasmMemory,C=s.buffer;else if(s.wasmMemory)$=s.wasmMemory;else if(!(($=new WebAssembly.Memory({initial:W/65536,maximum:65536,shared:!0})).buffer instanceof SharedArrayBuffer))throw P("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),w&&console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)"),Error("bad memory");$&&(C=$.buffer),W=C.byteLength,H(C);var q,X=[],Y=[],K=[],Z=[];function J(){return D||!1}function Q(){var t=s.preRun.shift();X.unshift(t)}var tt,et=0,nt=null,rt=null;function it(t){throw x?postMessage({cmd:"onAbort",arg:t}):s.onAbort&&s.onAbort(t),P(t="Aborted("+t+")"),M=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),c(t),t}function ot(){return tt.startsWith("data:application/octet-stream;base64,")}function at(){var t=tt;try{if(t==tt&&E)return new Uint8Array(E);if(f)return f(t);throw"both async and sync fetching of the wasm failed"}catch(t){it(t)}}tt="ort-wasm-threaded.wasm",ot()||(tt=S(tt));var st={};function ut(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function ct(t){(t=dt.Vb[t])||it(),dt.mc(t)}function lt(t){var e=dt.Cc();if(!e)return 6;dt.ac.push(e),dt.Vb[t.Ub]=e,e.Ub=t.Ub;var n={cmd:"run",start_routine:t.Ic,arg:t.zc,pthread_ptr:t.Ub};return e.$b=()=>{n.time=performance.now(),e.postMessage(n,t.Nc)},e.loaded&&(e.$b(),delete e.$b),0}function pt(t){if(x)return qt(1,1,t);J()||(dt.oc(),s.onExit&&s.onExit(t),M=!0),y(t,new ut(t))}function ft(t,e){if(!e&&x)throw bt(t),"unwind";J()||x||(me(),ht(K),be(0),re[1].length&&ie(1,10),re[2].length&&ie(2,10),dt.oc()),pt(t)}var dt={Yb:[],ac:[],qc:[],Vb:{},fc:function(){x&&dt.Ec()},Pc:function(){},Ec:function(){dt.receiveObjectTransfer=dt.Gc,dt.threadInitTLS=dt.pc,dt.setExitStatus=dt.nc,D=!1},nc:function(){},oc:function(){for(var t of Object.values(dt.Vb))dt.mc(t);for(t of dt.Yb)t.terminate();dt.Yb=[]},mc:function(t){var e=t.Ub;delete dt.Vb[e],dt.Yb.push(t),dt.ac.splice(dt.ac.indexOf(t),1),t.Ub=0,xe(e)},Gc:function(){},pc:function(){dt.qc.forEach((t=>t()))},Fc:function(t,e){t.onmessage=n=>{var r=(n=n.data).cmd;if(t.Ub&&(dt.Bc=t.Ub),n.targetThread&&n.targetThread!=de()){var i=dt.Vb[n.Qc];i?i.postMessage(n,n.transferList):P('Internal error! Worker sent a message "'+r+'" to target pthread '+n.targetThread+", but that thread no longer exists!")}else"processProxyingQueue"===r?Vt(n.queue):"spawnThread"===r?lt(n):"cleanupThread"===r?ct(n.thread):"killThread"===r?(n=n.thread,r=dt.Vb[n],delete dt.Vb[n],r.terminate(),xe(n),dt.ac.splice(dt.ac.indexOf(r),1),r.Ub=0):"cancelThread"===r?dt.Vb[n.thread].postMessage({cmd:"cancel"}):"loaded"===r?(t.loaded=!0,e&&e(t),t.$b&&(t.$b(),delete t.$b)):"print"===r?I("Thread "+n.threadId+": "+n.text):"printErr"===r?P("Thread "+n.threadId+": "+n.text):"alert"===r?alert("Thread "+n.threadId+": "+n.text):"setimmediate"===n.target?t.postMessage(n):"onAbort"===r?s.onAbort&&s.onAbort(n.arg):r&&P("worker sent an unknown command "+r);dt.Bc=void 0},t.onerror=t=>{throw P("worker sent an error! "+t.filename+":"+t.lineno+": "+t.message),t},w&&(t.on("message",(function(e){t.onmessage({data:e})})),t.on("error",(function(e){t.onerror(e)})),t.on("detachedExit",(function(){}))),t.postMessage({cmd:"load",urlOrBlob:s.mainScriptUrlOrBlob||_scriptDir,wasmMemory:$,wasmModule:k})},yc:function(){var t=S("ort-wasm-threaded.worker.js");dt.Yb.push(new Worker(t))},Cc:function(){return 0==dt.Yb.length&&(dt.yc(),dt.Fc(dt.Yb[0])),dt.Yb.pop()}};function ht(t){for(;0>2>>>0];t=i()[t+48>>2>>>0],Oe(e,e-t),Ee(e)};var mt=[];function yt(t){var e=mt[t];return e||(t>=mt.length&&(mt.length=t+1),mt[t]=e=q.get(t)),e}s.invokeEntryPoint=function(t,e){t=yt(t)(e),J()?dt.nc(t):Te(t)};var _t,vt,wt=[],xt=0,Tt=0;function St(t){this.Zb=t,this.Sb=t-24,this.xc=function(t){o()[this.Sb+4>>2>>>0]=t},this.bc=function(){return o()[this.Sb+4>>2>>>0]},this.wc=function(t){o()[this.Sb+8>>2>>>0]=t},this.Dc=function(){return o()[this.Sb+8>>2>>>0]},this.rc=function(){i()[this.Sb>>2>>>0]=0},this.hc=function(t){t=t?1:0,e()[this.Sb+12>>0>>>0]=t},this.uc=function(){return 0!=e()[this.Sb+12>>0>>>0]},this.ic=function(t){t=t?1:0,e()[this.Sb+13>>0>>>0]=t},this.kc=function(){return 0!=e()[this.Sb+13>>0>>>0]},this.fc=function(t,e){this.cc(0),this.xc(t),this.wc(e),this.rc(),this.hc(!1),this.ic(!1)},this.sc=function(){Atomics.add(i(),this.Sb>>2,1)},this.Hc=function(){return 1===Atomics.sub(i(),this.Sb>>2,1)},this.cc=function(t){o()[this.Sb+16>>2>>>0]=t},this.tc=function(){return o()[this.Sb+16>>2>>>0]},this.vc=function(){if(De(this.bc()))return o()[this.Zb>>2>>>0];var t=this.tc();return 0!==t?t:this.Zb}}function Ot(t){return ge(new St(t).Sb)}function At(t,e,n,r){return x?qt(3,1,t,e,n,r):Et(t,e,n,r)}function Et(t,e,n,r){if("undefined"==typeof SharedArrayBuffer)return P("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var i=[];return x&&0===i.length?At(t,e,n,r):(t={Ic:n,Ub:t,zc:r,Nc:i},x?(t.Oc="spawnThread",postMessage(t,i),0):lt(t))}function It(t,e,n){return x?qt(4,1,t,e,n):0}function Pt(t,e){if(x)return qt(5,1,t,e)}function Dt(t,e){if(x)return qt(6,1,t,e)}function $t(t,e,n){if(x)return qt(7,1,t,e,n)}function kt(t,e,n){return x?qt(8,1,t,e,n):0}function Ct(t,e){if(x)return qt(9,1,t,e)}function Ft(t,e,n){if(x)return qt(10,1,t,e,n)}function Nt(t,e,n,r){if(x)return qt(11,1,t,e,n,r)}function Rt(t,e,n,r){if(x)return qt(12,1,t,e,n,r)}function Lt(t,e,n,r){if(x)return qt(13,1,t,e,n,r)}function jt(t){if(x)return qt(14,1,t)}function Mt(t,e){if(x)return qt(15,1,t,e)}function Ut(t,e,n){if(x)return qt(16,1,t,e,n)}function Vt(t){Atomics.store(i(),t>>2,1),de()&&we(t),Atomics.compareExchange(i(),t>>2,1,0)}function Bt(t){return o()[t>>>2]+4294967296*i()[t+4>>>2]}function zt(t,e,n,r,i,o){return x?qt(17,1,t,e,n,r,i,o):-52}function Gt(t,e,n,r,i,o){if(x)return qt(18,1,t,e,n,r,i,o)}function Ht(t){var n=G(t)+1,r=he(n);return r&&z(t,e(),r,n),r}function Wt(t,e,n){function r(t){return(t=t.toTimeString().match(/\(([A-Za-z ]+)\)$/))?t[1]:"GMT"}if(x)return qt(19,1,t,e,n);var a=(new Date).getFullYear(),s=new Date(a,0,1),u=new Date(a,6,1);a=s.getTimezoneOffset();var c=u.getTimezoneOffset(),l=Math.max(a,c);i()[t>>2>>>0]=60*l,i()[e>>2>>>0]=Number(a!=c),t=r(s),e=r(u),t=Ht(t),e=Ht(e),c>2>>>0]=t,o()[n+4>>2>>>0]=e):(o()[n>>2>>>0]=e,o()[n+4>>2>>>0]=t)}function qt(t,e){var n=arguments.length-2,r=arguments;return gt((()=>{for(var i=Ie(8*n),o=i>>3,s=0;s>>0]=u}return ve(t,n,i,e)}))}s.executeNotifiedProxyingQueue=Vt,vt=w?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:x?()=>performance.now()-s.__performance_now_clock_drift:()=>performance.now();var Xt,Yt=[],Kt={};function Zt(){if(!Xt){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:m||"./this.program"};for(t in Kt)void 0===Kt[t]?delete e[t]:e[t]=Kt[t];var n=[];for(t in e)n.push(t+"="+e[t]);Xt=n}return Xt}function Jt(t,n){if(x)return qt(20,1,t,n);var r=0;return Zt().forEach((function(i,a){var s=n+r;for(a=o()[t+4*a>>2>>>0]=s,s=0;s>0>>>0]=i.charCodeAt(s);e()[a>>0>>>0]=0,r+=i.length+1})),0}function Qt(t,e){if(x)return qt(21,1,t,e);var n=Zt();o()[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),o()[e>>2>>>0]=r,0}function te(t){return x?qt(22,1,t):52}function ee(t,e,n,r){return x?qt(23,1,t,e,n,r):52}function ne(t,e,n,r,i){return x?qt(24,1,t,e,n,r,i):70}var re=[null,[],[]];function ie(t,e){var n=re[t];0===e||10===e?((1===t?I:P)(V(n,0)),n.length=0):n.push(e)}function oe(t,e,n,i){if(x)return qt(25,1,t,e,n,i);for(var a=0,s=0;s>2>>>0],c=o()[e+4>>2>>>0];e+=8;for(var l=0;l>>0]);a+=c}return o()[i>>2>>>0]=a,0}var ae=0;function se(t){return 0==t%4&&(0!=t%100||0==t%400)}var ue=[31,29,31,30,31,30,31,31,30,31,30,31],ce=[31,28,31,30,31,30,31,31,30,31,30,31];function le(t,n,r,o){function a(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=c(new Date(t.getFullYear(),0,4)),n=c(n),0>=u(e,t)?0>=u(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var p=i()[o+40>>2>>>0];for(var f in o={Lc:i()[o>>2>>>0],Kc:i()[o+4>>2>>>0],dc:i()[o+8>>2>>>0],jc:i()[o+12>>2>>>0],ec:i()[o+16>>2>>>0],Xb:i()[o+20>>2>>>0],Tb:i()[o+24>>2>>>0],Wb:i()[o+28>>2>>>0],Rc:i()[o+32>>2>>>0],Jc:i()[o+36>>2>>>0],Mc:p?B(p):""},r=B(r),p={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})r=r.replace(new RegExp(f,"g"),p[f]);var d="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),h="January February March April May June July August September October November December".split(" ");for(f in p={"%a":function(t){return d[t.Tb].substring(0,3)},"%A":function(t){return d[t.Tb]},"%b":function(t){return h[t.ec].substring(0,3)},"%B":function(t){return h[t.ec]},"%C":function(t){return s((t.Xb+1900)/100|0,2)},"%d":function(t){return s(t.jc,2)},"%e":function(t){return a(t.jc,2," ")},"%g":function(t){return l(t).toString().substring(2)},"%G":function(t){return l(t)},"%H":function(t){return s(t.dc,2)},"%I":function(t){return 0==(t=t.dc)?t=12:12t.dc?"AM":"PM"},"%S":function(t){return s(t.Lc,2)},"%t":function(){return"\t"},"%u":function(t){return t.Tb||7},"%U":function(t){return s(Math.floor((t.Wb+7-t.Tb)/7),2)},"%V":function(t){var e=Math.floor((t.Wb+7-(t.Tb+6)%7)/7);if(2>=(t.Tb+371-t.Wb-2)%7&&e++,e)53==e&&(4==(n=(t.Tb+371-t.Wb)%7)||3==n&&se(t.Xb)||(e=1));else{e=52;var n=(t.Tb+7-t.Wb-1)%7;(4==n||5==n&&se(t.Xb%400-1))&&e++}return s(e,2)},"%w":function(t){return t.Tb},"%W":function(t){return s(Math.floor((t.Wb+7-(t.Tb+6)%7)/7),2)},"%y":function(t){return(t.Xb+1900).toString().substring(2)},"%Y":function(t){return t.Xb+1900},"%z":function(t){var e=0<=(t=t.Jc);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.Mc},"%%":function(){return"%"}},r=r.replace(/%%/g,"\0\0"),p)r.includes(f)&&(r=r.replace(new RegExp(f,"g"),p[f](o)));return f=function(t){var e=Array(G(t)+1);return z(t,e,0,e.length),e}(r=r.replace(/\0\0/g,"%")),f.length>n?0:(function(t,n){e().set(t,n>>>0)}(f,t),f.length-1)}dt.fc();var pe=[null,pt,bt,At,It,Pt,Dt,$t,kt,Ct,Ft,Nt,Rt,Lt,jt,Mt,Ut,zt,Gt,Wt,Jt,Qt,te,ee,ne,oe],fe={b:function(t){return he(t+24)+24},n:function(t){return(t=new St(t)).uc()||(t.hc(!0),xt--),t.ic(!1),wt.push(t),t.sc(),t.vc()},ma:function(t){throw P("Unexpected exception thrown, this is not properly supported - aborting"),M=!0,t},x:function(){Se(0);var t=wt.pop();if(t.Hc()&&!t.kc()){var e=t.Dc();e&&yt(e)(t.Zb),Ot(t.Zb)}Tt=0},e:function(){var t=Tt;if(!t)return ae=0;var e=new St(t);e.cc(t);var n=e.bc();if(!n)return ae=0,t;for(var r=Array.prototype.slice.call(arguments),i=0;iVt(r)));else if(x)postMessage({targetThread:t,cmd:"processProxyingQueue",queue:r});else{if(!(t=dt.Vb[t]))return;t.postMessage({cmd:"processProxyingQueue",queue:r})}return 1},Ea:function(){return-1},Pa:function(t,e){t=new Date(1e3*Bt(t)),i()[e>>2>>>0]=t.getUTCSeconds(),i()[e+4>>2>>>0]=t.getUTCMinutes(),i()[e+8>>2>>>0]=t.getUTCHours(),i()[e+12>>2>>>0]=t.getUTCDate(),i()[e+16>>2>>>0]=t.getUTCMonth(),i()[e+20>>2>>>0]=t.getUTCFullYear()-1900,i()[e+24>>2>>>0]=t.getUTCDay(),t=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,i()[e+28>>2>>>0]=t},Qa:function(t,e){t=new Date(1e3*Bt(t)),i()[e>>2>>>0]=t.getSeconds(),i()[e+4>>2>>>0]=t.getMinutes(),i()[e+8>>2>>>0]=t.getHours(),i()[e+12>>2>>>0]=t.getDate(),i()[e+16>>2>>>0]=t.getMonth(),i()[e+20>>2>>>0]=t.getFullYear()-1900,i()[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1),r=(t.getTime()-n.getTime())/864e5|0;i()[e+28>>2>>>0]=r,i()[e+36>>2>>>0]=-60*t.getTimezoneOffset(),r=new Date(t.getFullYear(),6,1).getTimezoneOffset(),t=0|(r!=(n=n.getTimezoneOffset())&&t.getTimezoneOffset()==Math.min(n,r)),i()[e+32>>2>>>0]=t},Ra:function(t){var e=new Date(i()[t+20>>2>>>0]+1900,i()[t+16>>2>>>0],i()[t+12>>2>>>0],i()[t+8>>2>>>0],i()[t+4>>2>>>0],i()[t>>2>>>0],0),n=i()[t+32>>2>>>0],r=e.getTimezoneOffset(),o=new Date(e.getFullYear(),0,1),a=new Date(e.getFullYear(),6,1).getTimezoneOffset(),s=o.getTimezoneOffset(),u=Math.min(s,a);return 0>n?i()[t+32>>2>>>0]=Number(a!=s&&u==r):0>2>>>0]=e.getDay(),n=(e.getTime()-o.getTime())/864e5|0,i()[t+28>>2>>>0]=n,i()[t>>2>>>0]=e.getSeconds(),i()[t+4>>2>>>0]=e.getMinutes(),i()[t+8>>2>>>0]=e.getHours(),i()[t+12>>2>>>0]=e.getDate(),i()[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},Aa:zt,Ba:Gt,Sa:function t(e,n,r){t.Ac||(t.Ac=!0,Wt(e,n,r))},y:function(){it("")},U:function(){if(!w&&!v){var t="Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread";_t||(_t={}),_t[t]||(_t[t]=1,w&&(t="warning: "+t),P(t))}},ra:function(){return 4294901760},B:vt,Ia:function(t,e,n){r().copyWithin(t>>>0,e>>>0,e+n>>>0)},F:function(){return w?n(3993).cpus().length:navigator.hardwareConcurrency},Da:function(t,e,n){Yt.length=e,n>>=3;for(var r=0;r>>0];return(0>t?st[-t-1]:pe[t]).apply(null,Yt)},qa:function(t){var e=r().length;if((t>>>=0)<=e||4294901760=n;n*=2){var i=e*(1+.2/n);i=Math.min(i,t+100663296);var o=Math;i=Math.max(t,i),o=o.min.call(o,4294901760,i+(65536-i%65536)%65536);t:{try{$.grow(o-C.byteLength+65535>>>16),H($.buffer);var a=1;break t}catch(t){}a=void 0}if(a)return!0}return!1},Na:function(){throw"unwind"},Ga:Jt,Ha:Qt,J:ft,I:te,S:ee,ga:ne,R:oe,d:function(){return ae},na:function t(r,i){t.lc||(t.lc=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(w)try{var e=n(Object(function(){var t=new Error("Cannot find module 'crypto'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>it("randomDevice")}());for(var o=0;o>0>>>0]=t.lc();return 0},ia:function(t,e,n){var r=Ae();try{return yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},ja:function(t,e,n){var r=Ae();try{return yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},K:function(t){var e=Ae();try{return yt(t)()}catch(t){if(Ee(e),t!==t+0)throw t;Se(1,0)}},f:function(t,e){var n=Ae();try{return yt(t)(e)}catch(t){if(Ee(n),t!==t+0)throw t;Se(1,0)}},P:function(t,e,n){var r=Ae();try{return yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},Q:function(t,e,n){var r=Ae();try{return yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},k:function(t,e,n){var r=Ae();try{return yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},p:function(t,e,n,r){var i=Ae();try{return yt(t)(e,n,r)}catch(t){if(Ee(i),t!==t+0)throw t;Se(1,0)}},q:function(t,e,n,r,i){var o=Ae();try{return yt(t)(e,n,r,i)}catch(t){if(Ee(o),t!==t+0)throw t;Se(1,0)}},N:function(t,e,n,r,i,o){var a=Ae();try{return yt(t)(e,n,r,i,o)}catch(t){if(Ee(a),t!==t+0)throw t;Se(1,0)}},s:function(t,e,n,r,i,o){var a=Ae();try{return yt(t)(e,n,r,i,o)}catch(t){if(Ee(a),t!==t+0)throw t;Se(1,0)}},w:function(t,e,n,r,i,o,a){var s=Ae();try{return yt(t)(e,n,r,i,o,a)}catch(t){if(Ee(s),t!==t+0)throw t;Se(1,0)}},L:function(t,e,n,r,i,o,a,s){var u=Ae();try{return yt(t)(e,n,r,i,o,a,s)}catch(t){if(Ee(u),t!==t+0)throw t;Se(1,0)}},E:function(t,e,n,r,i,o,a,s,u,c,l,p){var f=Ae();try{return yt(t)(e,n,r,i,o,a,s,u,c,l,p)}catch(t){if(Ee(f),t!==t+0)throw t;Se(1,0)}},aa:function(t,e,n,r,i,o,a,s){var u=Ae();try{return Me(t,e,n,r,i,o,a,s)}catch(t){if(Ee(u),t!==t+0)throw t;Se(1,0)}},_:function(t,e,n,r,i,o,a){var s=Ae();try{return ke(t,e,n,r,i,o,a)}catch(t){if(Ee(s),t!==t+0)throw t;Se(1,0)}},Z:function(t,e,n,r,i){var o=Ae();try{return Ue(t,e,n,r,i)}catch(t){if(Ee(o),t!==t+0)throw t;Se(1,0)}},ca:function(t,e,n,r){var i=Ae();try{return Le(t,e,n,r)}catch(t){if(Ee(i),t!==t+0)throw t;Se(1,0)}},$:function(t){var e=Ae();try{return $e(t)}catch(t){if(Ee(e),t!==t+0)throw t;Se(1,0)}},ba:function(t,e){var n=Ae();try{return je(t,e)}catch(t){if(Ee(n),t!==t+0)throw t;Se(1,0)}},Y:function(t,e,n){var r=Ae();try{return Ce(t,e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},g:function(t){var e=Ae();try{yt(t)()}catch(t){if(Ee(e),t!==t+0)throw t;Se(1,0)}},r:function(t,e){var n=Ae();try{yt(t)(e)}catch(t){if(Ee(n),t!==t+0)throw t;Se(1,0)}},i:function(t,e,n){var r=Ae();try{yt(t)(e,n)}catch(t){if(Ee(r),t!==t+0)throw t;Se(1,0)}},ha:function(t,e,n,r){var i=Ae();try{yt(t)(e,n,r)}catch(t){if(Ee(i),t!==t+0)throw t;Se(1,0)}},m:function(t,e,n,r){var i=Ae();try{yt(t)(e,n,r)}catch(t){if(Ee(i),t!==t+0)throw t;Se(1,0)}},v:function(t,e,n,r,i){var o=Ae();try{yt(t)(e,n,r,i)}catch(t){if(Ee(o),t!==t+0)throw t;Se(1,0)}},u:function(t,e,n,r,i,o){var a=Ae();try{yt(t)(e,n,r,i,o)}catch(t){if(Ee(a),t!==t+0)throw t;Se(1,0)}},O:function(t,e,n,r,i,o,a){var s=Ae();try{yt(t)(e,n,r,i,o,a)}catch(t){if(Ee(s),t!==t+0)throw t;Se(1,0)}},A:function(t,e,n,r,i,o,a,s){var u=Ae();try{yt(t)(e,n,r,i,o,a,s)}catch(t){if(Ee(u),t!==t+0)throw t;Se(1,0)}},ka:function(t,e,n,r,i,o,a,s,u){var c=Ae();try{yt(t)(e,n,r,i,o,a,s,u)}catch(t){if(Ee(c),t!==t+0)throw t;Se(1,0)}},C:function(t,e,n,r,i,o,a,s,u,c,l){var p=Ae();try{yt(t)(e,n,r,i,o,a,s,u,c,l)}catch(t){if(Ee(p),t!==t+0)throw t;Se(1,0)}},D:function(t,e,n,r,i,o,a,s,u,c,l,p,f,d,h,g){var b=Ae();try{yt(t)(e,n,r,i,o,a,s,u,c,l,p,f,d,h,g)}catch(t){if(Ee(b),t!==t+0)throw t;Se(1,0)}},fa:function(t,e,n,r,i,o,a,s){var u=Ae();try{Fe(t,e,n,r,i,o,a,s)}catch(t){if(Ee(u),t!==t+0)throw t;Se(1,0)}},da:function(t,e,n,r,i,o,a,s,u,c,l,p){var f=Ae();try{Re(t,e,n,r,i,o,a,s,u,c,l,p)}catch(t){if(Ee(f),t!==t+0)throw t;Se(1,0)}},ea:function(t,e,n,r,i,o){var a=Ae();try{Ne(t,e,n,r,i,o)}catch(t){if(Ee(a),t!==t+0)throw t;Se(1,0)}},o:function(t){return t},a:$||s.wasmMemory,G:function(t){ae=t},la:le,z:function(t,e,n,r){return le(t,e,n,r)}};!function(){function t(t,e){s.asm=t.exports,dt.qc.push(s.asm.sb),q=s.asm.ub,Y.unshift(s.asm.Va),k=e,x||(et--,s.monitorRunDependencies&&s.monitorRunDependencies(et),0==et&&(null!==nt&&(clearInterval(nt),nt=null),rt&&(t=rt,rt=null,t())))}function e(e){t(e.instance,e.module)}function n(t){return function(){if(!E&&(_||v)){if("function"==typeof fetch&&!tt.startsWith("file://"))return fetch(tt,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at '"+tt+"'";return t.arrayBuffer()})).catch((function(){return at()}));if(p)return new Promise((function(t,e){p(tt,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return at()}))}().then((function(t){return WebAssembly.instantiate(t,r)})).then((function(t){return t})).then(t,(function(t){P("failed to asynchronously prepare wasm: "+t),it(t)}))}var r={a:fe};if(x||(et++,s.monitorRunDependencies&&s.monitorRunDependencies(et)),s.instantiateWasm)try{return s.instantiateWasm(r,t)}catch(t){return P("Module.instantiateWasm callback failed with error: "+t),!1}(E||"function"!=typeof WebAssembly.instantiateStreaming||ot()||tt.startsWith("file://")||w||"function"!=typeof fetch?n(e):fetch(tt,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(e,(function(t){return P("wasm streaming compile failed: "+t),P("falling back to ArrayBuffer instantiation"),n(e)}))}))).catch(c)}(),s.___wasm_call_ctors=function(){return(s.___wasm_call_ctors=s.asm.Va).apply(null,arguments)},s._OrtInit=function(){return(s._OrtInit=s.asm.Wa).apply(null,arguments)},s._OrtCreateSessionOptions=function(){return(s._OrtCreateSessionOptions=s.asm.Xa).apply(null,arguments)},s._OrtAppendExecutionProvider=function(){return(s._OrtAppendExecutionProvider=s.asm.Ya).apply(null,arguments)},s._OrtAddSessionConfigEntry=function(){return(s._OrtAddSessionConfigEntry=s.asm.Za).apply(null,arguments)},s._OrtReleaseSessionOptions=function(){return(s._OrtReleaseSessionOptions=s.asm._a).apply(null,arguments)},s._OrtCreateSession=function(){return(s._OrtCreateSession=s.asm.$a).apply(null,arguments)},s._OrtReleaseSession=function(){return(s._OrtReleaseSession=s.asm.ab).apply(null,arguments)},s._OrtGetInputCount=function(){return(s._OrtGetInputCount=s.asm.bb).apply(null,arguments)},s._OrtGetOutputCount=function(){return(s._OrtGetOutputCount=s.asm.cb).apply(null,arguments)},s._OrtGetInputName=function(){return(s._OrtGetInputName=s.asm.db).apply(null,arguments)},s._OrtGetOutputName=function(){return(s._OrtGetOutputName=s.asm.eb).apply(null,arguments)},s._OrtFree=function(){return(s._OrtFree=s.asm.fb).apply(null,arguments)},s._OrtCreateTensor=function(){return(s._OrtCreateTensor=s.asm.gb).apply(null,arguments)},s._OrtGetTensorData=function(){return(s._OrtGetTensorData=s.asm.hb).apply(null,arguments)},s._OrtReleaseTensor=function(){return(s._OrtReleaseTensor=s.asm.ib).apply(null,arguments)},s._OrtCreateRunOptions=function(){return(s._OrtCreateRunOptions=s.asm.jb).apply(null,arguments)},s._OrtAddRunConfigEntry=function(){return(s._OrtAddRunConfigEntry=s.asm.kb).apply(null,arguments)},s._OrtReleaseRunOptions=function(){return(s._OrtReleaseRunOptions=s.asm.lb).apply(null,arguments)},s._OrtRun=function(){return(s._OrtRun=s.asm.mb).apply(null,arguments)},s._OrtEndProfiling=function(){return(s._OrtEndProfiling=s.asm.nb).apply(null,arguments)};var de=s._pthread_self=function(){return(de=s._pthread_self=s.asm.ob).apply(null,arguments)},he=s._malloc=function(){return(he=s._malloc=s.asm.pb).apply(null,arguments)},ge=s._free=function(){return(ge=s._free=s.asm.qb).apply(null,arguments)},be=s._fflush=function(){return(be=s._fflush=s.asm.rb).apply(null,arguments)};s.__emscripten_tls_init=function(){return(s.__emscripten_tls_init=s.asm.sb).apply(null,arguments)};var me=s.___funcs_on_exit=function(){return(me=s.___funcs_on_exit=s.asm.tb).apply(null,arguments)},ye=s.__emscripten_thread_init=function(){return(ye=s.__emscripten_thread_init=s.asm.vb).apply(null,arguments)};s.__emscripten_thread_crashed=function(){return(s.__emscripten_thread_crashed=s.asm.wb).apply(null,arguments)};var _e,ve=s._emscripten_run_in_main_runtime_thread_js=function(){return(ve=s._emscripten_run_in_main_runtime_thread_js=s.asm.xb).apply(null,arguments)},we=s.__emscripten_proxy_execute_task_queue=function(){return(we=s.__emscripten_proxy_execute_task_queue=s.asm.yb).apply(null,arguments)},xe=s.__emscripten_thread_free_data=function(){return(xe=s.__emscripten_thread_free_data=s.asm.zb).apply(null,arguments)},Te=s.__emscripten_thread_exit=function(){return(Te=s.__emscripten_thread_exit=s.asm.Ab).apply(null,arguments)},Se=s._setThrew=function(){return(Se=s._setThrew=s.asm.Bb).apply(null,arguments)},Oe=s._emscripten_stack_set_limits=function(){return(Oe=s._emscripten_stack_set_limits=s.asm.Cb).apply(null,arguments)},Ae=s.stackSave=function(){return(Ae=s.stackSave=s.asm.Db).apply(null,arguments)},Ee=s.stackRestore=function(){return(Ee=s.stackRestore=s.asm.Eb).apply(null,arguments)},Ie=s.stackAlloc=function(){return(Ie=s.stackAlloc=s.asm.Fb).apply(null,arguments)},Pe=s.___cxa_can_catch=function(){return(Pe=s.___cxa_can_catch=s.asm.Gb).apply(null,arguments)},De=s.___cxa_is_pointer_type=function(){return(De=s.___cxa_is_pointer_type=s.asm.Hb).apply(null,arguments)},$e=s.dynCall_j=function(){return($e=s.dynCall_j=s.asm.Ib).apply(null,arguments)},ke=s.dynCall_iiiiij=function(){return(ke=s.dynCall_iiiiij=s.asm.Jb).apply(null,arguments)},Ce=s.dynCall_jii=function(){return(Ce=s.dynCall_jii=s.asm.Kb).apply(null,arguments)},Fe=s.dynCall_viiiiij=function(){return(Fe=s.dynCall_viiiiij=s.asm.Lb).apply(null,arguments)},Ne=s.dynCall_vjji=function(){return(Ne=s.dynCall_vjji=s.asm.Mb).apply(null,arguments)},Re=s.dynCall_viiijjjii=function(){return(Re=s.dynCall_viiijjjii=s.asm.Nb).apply(null,arguments)},Le=s.dynCall_iij=function(){return(Le=s.dynCall_iij=s.asm.Ob).apply(null,arguments)},je=s.dynCall_ji=function(){return(je=s.dynCall_ji=s.asm.Pb).apply(null,arguments)},Me=s.dynCall_iiiiiij=function(){return(Me=s.dynCall_iiiiiij=s.asm.Qb).apply(null,arguments)},Ue=s.dynCall_iiij=function(){return(Ue=s.dynCall_iiij=s.asm.Rb).apply(null,arguments)};function Ve(){function t(){if(!_e&&(_e=!0,s.calledRun=!0,!M)&&(x||ht(Y),u(s),s.onRuntimeInitialized&&s.onRuntimeInitialized(),!x)){if(s.postRun)for("function"==typeof s.postRun&&(s.postRun=[s.postRun]);s.postRun.length;){var t=s.postRun.shift();Z.unshift(t)}ht(Z)}}if(!(0{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){var e,r,i;t=t||{},e||(e=void 0!==t?t:{}),e.ready=new Promise((function(t,e){r=t,i=e}));var o,a,s,u,c,l,p=Object.assign({},e),f="./this.program",d=(t,e)=>{throw e},h="object"==typeof window,g="function"==typeof importScripts,b="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,m="";b?(m=g?n(908).dirname(m)+"/":"//",l=()=>{c||(u=n(1384),c=n(908))},o=function(t,e){return l(),t=c.normalize(t),u.readFileSync(t,e?void 0:"utf8")},s=t=>((t=o(t,!0)).buffer||(t=new Uint8Array(t)),t),a=(t,e,n)=>{l(),t=c.normalize(t),u.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(w||0{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},g&&(s=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),a=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)});var y,_=e.print||console.log.bind(console),v=e.printErr||console.warn.bind(console);Object.assign(e,p),p=null,e.thisProgram&&(f=e.thisProgram),e.quit&&(d=e.quit),e.wasmBinary&&(y=e.wasmBinary);var w=e.noExitRuntime||!1;"object"!=typeof WebAssembly&&W("no native wasm support detected");var x,T,S,O,A,E,I=!1,P="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function D(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(i=224==(240&i)?(15&i)<<12|o<<6|a:(7&i)<<18|o<<12|a<<6|63&t[e++])?r+=String.fromCharCode(i):(i-=65536,r+=String.fromCharCode(55296|i>>10,56320|1023&i))}}else r+=String.fromCharCode(i)}return r}function $(t,e){return(t>>>=0)?D(O,t,e):""}function k(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var o=0;o=a&&(a=65536+((1023&a)<<10)|1023&t.charCodeAt(++o)),127>=a){if(n>=r)break;e[n++>>>0]=a}else{if(2047>=a){if(n+1>=r)break;e[n++>>>0]=192|a>>6}else{if(65535>=a){if(n+2>=r)break;e[n++>>>0]=224|a>>12}else{if(n+3>=r)break;e[n++>>>0]=240|a>>18,e[n++>>>0]=128|a>>12&63}e[n++>>>0]=128|a>>6&63}e[n++>>>0]=128|63&a}}return e[n>>>0]=0,n-i}function C(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function F(){var t=x.buffer;T=t,e.HEAP8=S=new Int8Array(t),e.HEAP16=new Int16Array(t),e.HEAP32=A=new Int32Array(t),e.HEAPU8=O=new Uint8Array(t),e.HEAPU16=new Uint16Array(t),e.HEAPU32=E=new Uint32Array(t),e.HEAPF32=new Float32Array(t),e.HEAPF64=new Float64Array(t)}var N,R=[],L=[],j=[],M=[],U=0;function V(){var t=e.preRun.shift();R.unshift(t)}var B,z=0,G=null,H=null;function W(t){throw e.onAbort&&e.onAbort(t),v(t="Aborted("+t+")"),I=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),i(t),t}function q(){return B.startsWith("data:application/octet-stream;base64,")}if(B="ort-wasm.wasm",!q()){var X=B;B=e.locateFile?e.locateFile(X,m):m+X}function Y(){var t=B;try{if(t==B&&y)return new Uint8Array(y);if(s)return s(t);throw"both async and sync fetching of the wasm failed"}catch(t){W(t)}}function K(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function Z(t){for(;0>2>>>0]=t},this.Eb=function(){return E[this.zb+4>>2>>>0]},this.Sb=function(t){E[this.zb+8>>2>>>0]=t},this.Wb=function(){return E[this.zb+8>>2>>>0]},this.Tb=function(){A[this.zb>>2>>>0]=0},this.Ib=function(t){S[this.zb+12>>0>>>0]=t?1:0},this.Pb=function(){return 0!=S[this.zb+12>>0>>>0]},this.Jb=function(t){S[this.zb+13>>0>>>0]=t?1:0},this.Lb=function(){return 0!=S[this.zb+13>>0>>>0]},this.Rb=function(t,e){this.Fb(0),this.Ub(t),this.Sb(e),this.Tb(),this.Ib(!1),this.Jb(!1)},this.Nb=function(){A[this.zb>>2>>>0]+=1},this.Xb=function(){var t=A[this.zb>>2>>>0];return A[this.zb>>2>>>0]=t-1,1===t},this.Fb=function(t){E[this.zb+16>>2>>>0]=t},this.Ob=function(){return E[this.zb+16>>2>>>0]},this.Qb=function(){if(Et(this.Eb()))return E[this.Db>>2>>>0];var t=this.Ob();return 0!==t?t:this.Db}}function nt(t){return _t(new et(t).zb)}var rt=[];function it(t){var e=rt[t];return e||(t>=rt.length&&(rt.length=t+1),rt[t]=e=N.get(t)),e}function ot(t){var e=C(t)+1,n=yt(e);return n&&k(t,S,n,e),n}var at={};function st(){if(!ut){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:f||"./this.program"};for(t in at)void 0===at[t]?delete e[t]:e[t]=at[t];var n=[];for(t in e)n.push(t+"="+e[t]);ut=n}return ut}var ut,ct=[null,[],[]];function lt(t,e){var n=ct[t];0===e||10===e?((1===t?_:v)(D(n,0)),n.length=0):n.push(e)}var pt=0;function ft(t){return 0==t%4&&(0!=t%100||0==t%400)}var dt=[31,29,31,30,31,30,31,31,30,31,30,31],ht=[31,28,31,30,31,30,31,31,30,31,30,31];function gt(t,e,n,r){function i(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=s(new Date(t.getFullYear(),0,4)),n=s(n),0>=a(e,t)?0>=a(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var c=A[r+40>>2>>>0];for(var l in r={$b:A[r>>2>>>0],Zb:A[r+4>>2>>>0],Gb:A[r+8>>2>>>0],Kb:A[r+12>>2>>>0],Hb:A[r+16>>2>>>0],Cb:A[r+20>>2>>>0],Ab:A[r+24>>2>>>0],Bb:A[r+28>>2>>>0],bc:A[r+32>>2>>>0],Yb:A[r+36>>2>>>0],ac:c?$(c):""},n=$(n),c={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})n=n.replace(new RegExp(l,"g"),c[l]);var p="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),f="January February March April May June July August September October November December".split(" ");for(l in c={"%a":function(t){return p[t.Ab].substring(0,3)},"%A":function(t){return p[t.Ab]},"%b":function(t){return f[t.Hb].substring(0,3)},"%B":function(t){return f[t.Hb]},"%C":function(t){return o((t.Cb+1900)/100|0,2)},"%d":function(t){return o(t.Kb,2)},"%e":function(t){return i(t.Kb,2," ")},"%g":function(t){return u(t).toString().substring(2)},"%G":function(t){return u(t)},"%H":function(t){return o(t.Gb,2)},"%I":function(t){return 0==(t=t.Gb)?t=12:12t.Gb?"AM":"PM"},"%S":function(t){return o(t.$b,2)},"%t":function(){return"\t"},"%u":function(t){return t.Ab||7},"%U":function(t){return o(Math.floor((t.Bb+7-t.Ab)/7),2)},"%V":function(t){var e=Math.floor((t.Bb+7-(t.Ab+6)%7)/7);if(2>=(t.Ab+371-t.Bb-2)%7&&e++,e)53==e&&(4==(n=(t.Ab+371-t.Bb)%7)||3==n&&ft(t.Cb)||(e=1));else{e=52;var n=(t.Ab+7-t.Bb-1)%7;(4==n||5==n&&ft(t.Cb%400-1))&&e++}return o(e,2)},"%w":function(t){return t.Ab},"%W":function(t){return o(Math.floor((t.Bb+7-(t.Ab+6)%7)/7),2)},"%y":function(t){return(t.Cb+1900).toString().substring(2)},"%Y":function(t){return t.Cb+1900},"%z":function(t){var e=0<=(t=t.Yb);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.ac},"%%":function(){return"%"}},n=n.replace(/%%/g,"\0\0"),c)n.includes(l)&&(n=n.replace(new RegExp(l,"g"),c[l](r)));return l=function(t){var e=Array(C(t)+1);return k(t,e,0,e.length),e}(n=n.replace(/\0\0/g,"%")),l.length>e?0:(S.set(l,t>>>0),l.length-1)}var bt={a:function(t){return yt(t+24)+24},m:function(t){return(t=new et(t)).Pb()||(t.Ib(!0),Q--),t.Jb(!1),J.push(t),t.Nb(),t.Qb()},ia:function(t){throw v("Unexpected exception thrown, this is not properly supported - aborting"),I=!0,t},w:function(){xt(0);var t=J.pop();if(t.Xb()&&!t.Lb()){var e=t.Wb();e&&it(e)(t.Db),nt(t.Db)}tt=0},d:function(){var t=tt;if(!t)return pt=0;var e=new et(t);e.Fb(t);var n=e.Eb();if(!n)return pt=0,t;for(var r=Array.prototype.slice.call(arguments),i=0;i>>2]+4294967296*A[t+4>>>2])),A[e>>2>>>0]=t.getUTCSeconds(),A[e+4>>2>>>0]=t.getUTCMinutes(),A[e+8>>2>>>0]=t.getUTCHours(),A[e+12>>2>>>0]=t.getUTCDate(),A[e+16>>2>>>0]=t.getUTCMonth(),A[e+20>>2>>>0]=t.getUTCFullYear()-1900,A[e+24>>2>>>0]=t.getUTCDay(),A[e+28>>2>>>0]=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},Ea:function(t,e){t=new Date(1e3*(E[t>>>2]+4294967296*A[t+4>>>2])),A[e>>2>>>0]=t.getSeconds(),A[e+4>>2>>>0]=t.getMinutes(),A[e+8>>2>>>0]=t.getHours(),A[e+12>>2>>>0]=t.getDate(),A[e+16>>2>>>0]=t.getMonth(),A[e+20>>2>>>0]=t.getFullYear()-1900,A[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1);A[e+28>>2>>>0]=(t.getTime()-n.getTime())/864e5|0,A[e+36>>2>>>0]=-60*t.getTimezoneOffset();var r=new Date(t.getFullYear(),6,1).getTimezoneOffset();n=n.getTimezoneOffset(),A[e+32>>2>>>0]=0|(r!=n&&t.getTimezoneOffset()==Math.min(n,r))},Fa:function(t){var e=new Date(A[t+20>>2>>>0]+1900,A[t+16>>2>>>0],A[t+12>>2>>>0],A[t+8>>2>>>0],A[t+4>>2>>>0],A[t>>2>>>0],0),n=A[t+32>>2>>>0],r=e.getTimezoneOffset(),i=new Date(e.getFullYear(),0,1),o=new Date(e.getFullYear(),6,1).getTimezoneOffset(),a=i.getTimezoneOffset(),s=Math.min(a,o);return 0>n?A[t+32>>2>>>0]=Number(o!=a&&s==r):0>2>>>0]=e.getDay(),A[t+28>>2>>>0]=(e.getTime()-i.getTime())/864e5|0,A[t>>2>>>0]=e.getSeconds(),A[t+4>>2>>>0]=e.getMinutes(),A[t+8>>2>>>0]=e.getHours(),A[t+12>>2>>>0]=e.getDate(),A[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},sa:function(){return-52},ta:function(){},Ga:function t(e,n,r){t.Vb||(t.Vb=!0,function(t,e,n){function r(t){return(t=t.toTimeString().match(/\(([A-Za-z ]+)\)$/))?t[1]:"GMT"}var i=(new Date).getFullYear(),o=new Date(i,0,1),a=new Date(i,6,1);i=o.getTimezoneOffset();var s=a.getTimezoneOffset();A[t>>2>>>0]=60*Math.max(i,s),A[e>>2>>>0]=Number(i!=s),t=r(o),e=r(a),t=ot(t),e=ot(e),s>2>>>0]=t,E[n+4>>2>>>0]=e):(E[n>>2>>>0]=e,E[n+4>>2>>>0]=t)}(e,n,r))},B:function(){W("")},ma:function(){return 4294901760},I:b?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:()=>performance.now(),xa:function(t,e,n){O.copyWithin(t>>>0,e>>>0,e+n>>>0)},G:function(t){var e=O.length;if(4294901760<(t>>>=0))return!1;for(var n=1;4>=n;n*=2){var r=e*(1+.2/n);r=Math.min(r,t+100663296);var i=Math;r=Math.max(t,r),i=i.min.call(i,4294901760,r+(65536-r%65536)%65536);t:{try{x.grow(i-T.byteLength+65535>>>16),F();var o=1;break t}catch(t){}o=void 0}if(o)return!0}return!1},va:function(t,e){var n=0;return st().forEach((function(r,i){var o=e+n;for(i=E[t+4*i>>2>>>0]=o,o=0;o>0>>>0]=r.charCodeAt(o);S[i>>0>>>0]=0,n+=r.length+1})),0},wa:function(t,e){var n=st();E[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),E[e>>2>>>0]=r,0},ba:function(t){w||0>2>>>0],s=E[e+4>>2>>>0];e+=8;for(var u=0;u>>0]);i+=s}return E[r>>2>>>0]=i,0},c:function(){return pt},ja:function t(e,r){t.Mb||(t.Mb=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(b)try{var e=n(Object(function(){var t=new Error("Cannot find module 'crypto'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>W("randomDevice")}());for(var i=0;i>0>>>0]=t.Mb();return 0},ea:function(t,e,n){var r=Tt();try{return it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},fa:function(t,e,n){var r=Tt();try{return it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},J:function(t){var e=Tt();try{return it(t)()}catch(t){if(St(e),t!==t+0)throw t;xt(1,0)}},e:function(t,e){var n=Tt();try{return it(t)(e)}catch(t){if(St(n),t!==t+0)throw t;xt(1,0)}},N:function(t,e,n){var r=Tt();try{return it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},O:function(t,e,n){var r=Tt();try{return it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},j:function(t,e,n){var r=Tt();try{return it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},o:function(t,e,n,r){var i=Tt();try{return it(t)(e,n,r)}catch(t){if(St(i),t!==t+0)throw t;xt(1,0)}},p:function(t,e,n,r,i){var o=Tt();try{return it(t)(e,n,r,i)}catch(t){if(St(o),t!==t+0)throw t;xt(1,0)}},M:function(t,e,n,r,i,o){var a=Tt();try{return it(t)(e,n,r,i,o)}catch(t){if(St(a),t!==t+0)throw t;xt(1,0)}},r:function(t,e,n,r,i,o){var a=Tt();try{return it(t)(e,n,r,i,o)}catch(t){if(St(a),t!==t+0)throw t;xt(1,0)}},v:function(t,e,n,r,i,o,a){var s=Tt();try{return it(t)(e,n,r,i,o,a)}catch(t){if(St(s),t!==t+0)throw t;xt(1,0)}},K:function(t,e,n,r,i,o,a,s){var u=Tt();try{return it(t)(e,n,r,i,o,a,s)}catch(t){if(St(u),t!==t+0)throw t;xt(1,0)}},D:function(t,e,n,r,i,o,a,s,u,c,l,p){var f=Tt();try{return it(t)(e,n,r,i,o,a,s,u,c,l,p)}catch(t){if(St(f),t!==t+0)throw t;xt(1,0)}},X:function(t,e,n,r,i,o,a,s){var u=Tt();try{return Rt(t,e,n,r,i,o,a,s)}catch(t){if(St(u),t!==t+0)throw t;xt(1,0)}},V:function(t,e,n,r,i,o,a){var s=Tt();try{return Pt(t,e,n,r,i,o,a)}catch(t){if(St(s),t!==t+0)throw t;xt(1,0)}},U:function(t,e,n,r,i){var o=Tt();try{return Lt(t,e,n,r,i)}catch(t){if(St(o),t!==t+0)throw t;xt(1,0)}},Z:function(t,e,n,r){var i=Tt();try{return Ft(t,e,n,r)}catch(t){if(St(i),t!==t+0)throw t;xt(1,0)}},W:function(t){var e=Tt();try{return It(t)}catch(t){if(St(e),t!==t+0)throw t;xt(1,0)}},Y:function(t,e){var n=Tt();try{return Nt(t,e)}catch(t){if(St(n),t!==t+0)throw t;xt(1,0)}},T:function(t,e,n){var r=Tt();try{return Dt(t,e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},f:function(t){var e=Tt();try{it(t)()}catch(t){if(St(e),t!==t+0)throw t;xt(1,0)}},q:function(t,e){var n=Tt();try{it(t)(e)}catch(t){if(St(n),t!==t+0)throw t;xt(1,0)}},h:function(t,e,n){var r=Tt();try{it(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;xt(1,0)}},da:function(t,e,n,r){var i=Tt();try{it(t)(e,n,r)}catch(t){if(St(i),t!==t+0)throw t;xt(1,0)}},l:function(t,e,n,r){var i=Tt();try{it(t)(e,n,r)}catch(t){if(St(i),t!==t+0)throw t;xt(1,0)}},t:function(t,e,n,r,i){var o=Tt();try{it(t)(e,n,r,i)}catch(t){if(St(o),t!==t+0)throw t;xt(1,0)}},u:function(t,e,n,r,i,o){var a=Tt();try{it(t)(e,n,r,i,o)}catch(t){if(St(a),t!==t+0)throw t;xt(1,0)}},x:function(t,e,n,r,i,o,a){var s=Tt();try{it(t)(e,n,r,i,o,a)}catch(t){if(St(s),t!==t+0)throw t;xt(1,0)}},z:function(t,e,n,r,i,o,a,s){var u=Tt();try{it(t)(e,n,r,i,o,a,s)}catch(t){if(St(u),t!==t+0)throw t;xt(1,0)}},ga:function(t,e,n,r,i,o,a,s,u){var c=Tt();try{it(t)(e,n,r,i,o,a,s,u)}catch(t){if(St(c),t!==t+0)throw t;xt(1,0)}},A:function(t,e,n,r,i,o,a,s,u,c,l){var p=Tt();try{it(t)(e,n,r,i,o,a,s,u,c,l)}catch(t){if(St(p),t!==t+0)throw t;xt(1,0)}},C:function(t,e,n,r,i,o,a,s,u,c,l,p,f,d,h,g){var b=Tt();try{it(t)(e,n,r,i,o,a,s,u,c,l,p,f,d,h,g)}catch(t){if(St(b),t!==t+0)throw t;xt(1,0)}},aa:function(t,e,n,r,i,o,a,s){var u=Tt();try{$t(t,e,n,r,i,o,a,s)}catch(t){if(St(u),t!==t+0)throw t;xt(1,0)}},_:function(t,e,n,r,i,o,a,s,u,c,l,p){var f=Tt();try{Ct(t,e,n,r,i,o,a,s,u,c,l,p)}catch(t){if(St(f),t!==t+0)throw t;xt(1,0)}},$:function(t,e,n,r,i,o){var a=Tt();try{kt(t,e,n,r,i,o)}catch(t){if(St(a),t!==t+0)throw t;xt(1,0)}},n:function(t){return t},F:function(t){pt=t},ha:gt,y:function(t,e,n,r){return gt(t,e,n,r)}};!function(){function t(t){e.asm=t.exports,x=e.asm.Ka,F(),N=e.asm.ib,L.unshift(e.asm.La),z--,e.monitorRunDependencies&&e.monitorRunDependencies(z),0==z&&(null!==G&&(clearInterval(G),G=null),H&&(t=H,H=null,t()))}function n(e){t(e.instance)}function r(t){return function(){if(!y&&(h||g)){if("function"==typeof fetch&&!B.startsWith("file://"))return fetch(B,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at '"+B+"'";return t.arrayBuffer()})).catch((function(){return Y()}));if(a)return new Promise((function(t,e){a(B,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return Y()}))}().then((function(t){return WebAssembly.instantiate(t,o)})).then((function(t){return t})).then(t,(function(t){v("failed to asynchronously prepare wasm: "+t),W(t)}))}var o={a:bt};if(z++,e.monitorRunDependencies&&e.monitorRunDependencies(z),e.instantiateWasm)try{return e.instantiateWasm(o,t)}catch(t){return v("Module.instantiateWasm callback failed with error: "+t),!1}(y||"function"!=typeof WebAssembly.instantiateStreaming||q()||B.startsWith("file://")||b||"function"!=typeof fetch?r(n):fetch(B,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,o).then(n,(function(t){return v("wasm streaming compile failed: "+t),v("falling back to ArrayBuffer instantiation"),r(n)}))}))).catch(i)}(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.La).apply(null,arguments)},e._OrtInit=function(){return(e._OrtInit=e.asm.Ma).apply(null,arguments)},e._OrtCreateSessionOptions=function(){return(e._OrtCreateSessionOptions=e.asm.Na).apply(null,arguments)},e._OrtAppendExecutionProvider=function(){return(e._OrtAppendExecutionProvider=e.asm.Oa).apply(null,arguments)},e._OrtAddSessionConfigEntry=function(){return(e._OrtAddSessionConfigEntry=e.asm.Pa).apply(null,arguments)},e._OrtReleaseSessionOptions=function(){return(e._OrtReleaseSessionOptions=e.asm.Qa).apply(null,arguments)},e._OrtCreateSession=function(){return(e._OrtCreateSession=e.asm.Ra).apply(null,arguments)},e._OrtReleaseSession=function(){return(e._OrtReleaseSession=e.asm.Sa).apply(null,arguments)},e._OrtGetInputCount=function(){return(e._OrtGetInputCount=e.asm.Ta).apply(null,arguments)},e._OrtGetOutputCount=function(){return(e._OrtGetOutputCount=e.asm.Ua).apply(null,arguments)},e._OrtGetInputName=function(){return(e._OrtGetInputName=e.asm.Va).apply(null,arguments)},e._OrtGetOutputName=function(){return(e._OrtGetOutputName=e.asm.Wa).apply(null,arguments)},e._OrtFree=function(){return(e._OrtFree=e.asm.Xa).apply(null,arguments)},e._OrtCreateTensor=function(){return(e._OrtCreateTensor=e.asm.Ya).apply(null,arguments)},e._OrtGetTensorData=function(){return(e._OrtGetTensorData=e.asm.Za).apply(null,arguments)},e._OrtReleaseTensor=function(){return(e._OrtReleaseTensor=e.asm._a).apply(null,arguments)},e._OrtCreateRunOptions=function(){return(e._OrtCreateRunOptions=e.asm.$a).apply(null,arguments)},e._OrtAddRunConfigEntry=function(){return(e._OrtAddRunConfigEntry=e.asm.ab).apply(null,arguments)},e._OrtReleaseRunOptions=function(){return(e._OrtReleaseRunOptions=e.asm.bb).apply(null,arguments)},e._OrtRun=function(){return(e._OrtRun=e.asm.cb).apply(null,arguments)},e._OrtEndProfiling=function(){return(e._OrtEndProfiling=e.asm.db).apply(null,arguments)};var mt,yt=e._malloc=function(){return(yt=e._malloc=e.asm.eb).apply(null,arguments)},_t=e._free=function(){return(_t=e._free=e.asm.fb).apply(null,arguments)},vt=e._fflush=function(){return(vt=e._fflush=e.asm.gb).apply(null,arguments)},wt=e.___funcs_on_exit=function(){return(wt=e.___funcs_on_exit=e.asm.hb).apply(null,arguments)},xt=e._setThrew=function(){return(xt=e._setThrew=e.asm.jb).apply(null,arguments)},Tt=e.stackSave=function(){return(Tt=e.stackSave=e.asm.kb).apply(null,arguments)},St=e.stackRestore=function(){return(St=e.stackRestore=e.asm.lb).apply(null,arguments)},Ot=e.stackAlloc=function(){return(Ot=e.stackAlloc=e.asm.mb).apply(null,arguments)},At=e.___cxa_can_catch=function(){return(At=e.___cxa_can_catch=e.asm.nb).apply(null,arguments)},Et=e.___cxa_is_pointer_type=function(){return(Et=e.___cxa_is_pointer_type=e.asm.ob).apply(null,arguments)},It=e.dynCall_j=function(){return(It=e.dynCall_j=e.asm.pb).apply(null,arguments)},Pt=e.dynCall_iiiiij=function(){return(Pt=e.dynCall_iiiiij=e.asm.qb).apply(null,arguments)},Dt=e.dynCall_jii=function(){return(Dt=e.dynCall_jii=e.asm.rb).apply(null,arguments)},$t=e.dynCall_viiiiij=function(){return($t=e.dynCall_viiiiij=e.asm.sb).apply(null,arguments)},kt=e.dynCall_vjji=function(){return(kt=e.dynCall_vjji=e.asm.tb).apply(null,arguments)},Ct=e.dynCall_viiijjjii=function(){return(Ct=e.dynCall_viiijjjii=e.asm.ub).apply(null,arguments)},Ft=e.dynCall_iij=function(){return(Ft=e.dynCall_iij=e.asm.vb).apply(null,arguments)},Nt=e.dynCall_ji=function(){return(Nt=e.dynCall_ji=e.asm.wb).apply(null,arguments)},Rt=e.dynCall_iiiiiij=function(){return(Rt=e.dynCall_iiiiiij=e.asm.xb).apply(null,arguments)},Lt=e.dynCall_iiij=function(){return(Lt=e.dynCall_iiij=e.asm.yb).apply(null,arguments)};function jt(){function t(){if(!mt&&(mt=!0,e.calledRun=!0,!I)){if(Z(L),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var t=e.postRun.shift();M.unshift(t)}Z(M)}}if(!(0{"use strict";t.exports=function(t,e){for(var n=new Array(arguments.length-1),r=0,i=2,o=!0;i{"use strict";var n=e;n.length=function(t){var e=t.length;if(!e)return 0;for(var n=0;--e%4>1&&"="===t.charAt(e);)++n;return Math.ceil(3*t.length)/4-n};for(var r=new Array(64),i=new Array(123),o=0;o<64;)i[r[o]=o<26?o+65:o<52?o+71:o<62?o-4:o-59|43]=o++;n.encode=function(t,e,n){for(var i,o=null,a=[],s=0,u=0;e>2],i=(3&c)<<4,u=1;break;case 1:a[s++]=r[i|c>>4],i=(15&c)<<2,u=2;break;case 2:a[s++]=r[i|c>>6],a[s++]=r[63&c],u=0}s>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,a)),s=0)}return u&&(a[s++]=r[i],a[s++]=61,1===u&&(a[s++]=61)),o?(s&&o.push(String.fromCharCode.apply(String,a.slice(0,s))),o.join("")):String.fromCharCode.apply(String,a.slice(0,s))};var a="invalid encoding";n.decode=function(t,e,n){for(var r,o=n,s=0,u=0;u1)break;if(void 0===(c=i[c]))throw Error(a);switch(s){case 0:r=c,s=1;break;case 1:e[n++]=r<<2|(48&c)>>4,r=c,s=2;break;case 2:e[n++]=(15&r)<<4|(60&c)>>2,r=c,s=3;break;case 3:e[n++]=(3&r)<<6|c,s=0}}if(1===s)throw Error(a);return n-o},n.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},9211:t=>{"use strict";function e(){this._listeners={}}t.exports=e,e.prototype.on=function(t,e,n){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:n||this}),this},e.prototype.off=function(t,e){if(void 0===t)this._listeners={};else if(void 0===e)this._listeners[t]=[];else for(var n=this._listeners[t],r=0;r{"use strict";function e(t){return"undefined"!=typeof Float32Array?function(){var e=new Float32Array([-0]),n=new Uint8Array(e.buffer),r=128===n[3];function i(t,r,i){e[0]=t,r[i]=n[0],r[i+1]=n[1],r[i+2]=n[2],r[i+3]=n[3]}function o(t,r,i){e[0]=t,r[i]=n[3],r[i+1]=n[2],r[i+2]=n[1],r[i+3]=n[0]}function a(t,r){return n[0]=t[r],n[1]=t[r+1],n[2]=t[r+2],n[3]=t[r+3],e[0]}function s(t,r){return n[3]=t[r],n[2]=t[r+1],n[1]=t[r+2],n[0]=t[r+3],e[0]}t.writeFloatLE=r?i:o,t.writeFloatBE=r?o:i,t.readFloatLE=r?a:s,t.readFloatBE=r?s:a}():function(){function e(t,e,n,r){var i=e<0?1:0;if(i&&(e=-e),0===e)t(1/e>0?0:2147483648,n,r);else if(isNaN(e))t(2143289344,n,r);else if(e>34028234663852886e22)t((i<<31|2139095040)>>>0,n,r);else if(e<11754943508222875e-54)t((i<<31|Math.round(e/1401298464324817e-60))>>>0,n,r);else{var o=Math.floor(Math.log(e)/Math.LN2);t((i<<31|o+127<<23|8388607&Math.round(e*Math.pow(2,-o)*8388608))>>>0,n,r)}}function a(t,e,n){var r=t(e,n),i=2*(r>>31)+1,o=r>>>23&255,a=8388607&r;return 255===o?a?NaN:i*(1/0):0===o?1401298464324817e-60*i*a:i*Math.pow(2,o-150)*(a+8388608)}t.writeFloatLE=e.bind(null,n),t.writeFloatBE=e.bind(null,r),t.readFloatLE=a.bind(null,i),t.readFloatBE=a.bind(null,o)}(),"undefined"!=typeof Float64Array?function(){var e=new Float64Array([-0]),n=new Uint8Array(e.buffer),r=128===n[7];function i(t,r,i){e[0]=t,r[i]=n[0],r[i+1]=n[1],r[i+2]=n[2],r[i+3]=n[3],r[i+4]=n[4],r[i+5]=n[5],r[i+6]=n[6],r[i+7]=n[7]}function o(t,r,i){e[0]=t,r[i]=n[7],r[i+1]=n[6],r[i+2]=n[5],r[i+3]=n[4],r[i+4]=n[3],r[i+5]=n[2],r[i+6]=n[1],r[i+7]=n[0]}function a(t,r){return n[0]=t[r],n[1]=t[r+1],n[2]=t[r+2],n[3]=t[r+3],n[4]=t[r+4],n[5]=t[r+5],n[6]=t[r+6],n[7]=t[r+7],e[0]}function s(t,r){return n[7]=t[r],n[6]=t[r+1],n[5]=t[r+2],n[4]=t[r+3],n[3]=t[r+4],n[2]=t[r+5],n[1]=t[r+6],n[0]=t[r+7],e[0]}t.writeDoubleLE=r?i:o,t.writeDoubleBE=r?o:i,t.readDoubleLE=r?a:s,t.readDoubleBE=r?s:a}():function(){function e(t,e,n,r,i,o){var a=r<0?1:0;if(a&&(r=-r),0===r)t(0,i,o+e),t(1/r>0?0:2147483648,i,o+n);else if(isNaN(r))t(0,i,o+e),t(2146959360,i,o+n);else if(r>17976931348623157e292)t(0,i,o+e),t((a<<31|2146435072)>>>0,i,o+n);else{var s;if(r<22250738585072014e-324)t((s=r/5e-324)>>>0,i,o+e),t((a<<31|s/4294967296)>>>0,i,o+n);else{var u=Math.floor(Math.log(r)/Math.LN2);1024===u&&(u=1023),t(4503599627370496*(s=r*Math.pow(2,-u))>>>0,i,o+e),t((a<<31|u+1023<<20|1048576*s&1048575)>>>0,i,o+n)}}}function a(t,e,n,r,i){var o=t(r,i+e),a=t(r,i+n),s=2*(a>>31)+1,u=a>>>20&2047,c=4294967296*(1048575&a)+o;return 2047===u?c?NaN:s*(1/0):0===u?5e-324*s*c:s*Math.pow(2,u-1075)*(c+4503599627370496)}t.writeDoubleLE=e.bind(null,n,0,4),t.writeDoubleBE=e.bind(null,r,4,0),t.readDoubleLE=a.bind(null,i,0,4),t.readDoubleBE=a.bind(null,o,4,0)}(),t}function n(t,e,n){e[n]=255&t,e[n+1]=t>>>8&255,e[n+2]=t>>>16&255,e[n+3]=t>>>24}function r(t,e,n){e[n]=t>>>24,e[n+1]=t>>>16&255,e[n+2]=t>>>8&255,e[n+3]=255&t}function i(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}function o(t,e){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}t.exports=e(e)},7199:module=>{"use strict";function inquire(moduleName){return null}module.exports=inquire},6662:t=>{"use strict";t.exports=function(t,e,n){var r=n||8192,i=r>>>1,o=null,a=r;return function(n){if(n<1||n>i)return t(n);a+n>r&&(o=t(r),a=0);var s=e.call(o,a,a+=n);return 7&a&&(a=1+(7|a)),s}}},4997:(t,e)=>{"use strict";var n=e;n.length=function(t){for(var e=0,n=0,r=0;r191&&r<224?o[a++]=(31&r)<<6|63&t[e++]:r>239&&r<365?(r=((7&r)<<18|(63&t[e++])<<12|(63&t[e++])<<6|63&t[e++])-65536,o[a++]=55296+(r>>10),o[a++]=56320+(1023&r)):o[a++]=(15&r)<<12|(63&t[e++])<<6|63&t[e++],a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,o)),a=0);return i?(a&&i.push(String.fromCharCode.apply(String,o.slice(0,a))),i.join("")):String.fromCharCode.apply(String,o.slice(0,a))},n.write=function(t,e,n){for(var r,i,o=n,a=0;a>6|192,e[n++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=t.charCodeAt(a+1)))?(r=65536+((1023&r)<<10)+(1023&i),++a,e[n++]=r>>18|240,e[n++]=r>>12&63|128,e[n++]=r>>6&63|128,e[n++]=63&r|128):(e[n++]=r>>12|224,e[n++]=r>>6&63|128,e[n++]=63&r|128);return n-o}},3442:(t,e)=>{"use strict";e.__esModule=!0;var n=function(){function t(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=t.EMPTY,e&&t.isGuid(e)&&(this.value=e)}return t.isGuid=function(e){var n=e.toString();return e&&(e instanceof t||t.validator.test(n))},t.create=function(){return new t([t.gen(2),t.gen(1),t.gen(1),t.gen(1),t.gen(3)].join("-"))},t.createEmpty=function(){return new t("emptyguid")},t.parse=function(e){return new t(e)},t.raw=function(){return[t.gen(2),t.gen(1),t.gen(1),t.gen(1),t.gen(3)].join("-")},t.gen=function(t){for(var e="",n=0;n{t.exports=n;var e=null;try{e=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(t){}function n(t,e,n){this.low=0|t,this.high=0|e,this.unsigned=!!n}function r(t){return!0===(t&&t.__isLong__)}n.prototype.__isLong__,Object.defineProperty(n.prototype,"__isLong__",{value:!0}),n.isLong=r;var i={},o={};function a(t,e){var n,r,a;return e?(a=0<=(t>>>=0)&&t<256)&&(r=o[t])?r:(n=u(t,(0|t)<0?-1:0,!0),a&&(o[t]=n),n):(a=-128<=(t|=0)&&t<128)&&(r=i[t])?r:(n=u(t,t<0?-1:0,!1),a&&(i[t]=n),n)}function s(t,e){if(isNaN(t))return e?m:b;if(e){if(t<0)return m;if(t>=d)return x}else{if(t<=-h)return T;if(t+1>=h)return w}return t<0?s(-t,e).neg():u(t%f|0,t/f|0,e)}function u(t,e,r){return new n(t,e,r)}n.fromInt=a,n.fromNumber=s,n.fromBits=u;var c=Math.pow;function l(t,e,n){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return b;if("number"==typeof e?(n=e,e=!1):e=!!e,(n=n||10)<2||360)throw Error("interior hyphen");if(0===r)return l(t.substring(1),e,n).neg();for(var i=s(c(n,8)),o=b,a=0;a>>0:this.low},S.toNumber=function(){return this.unsigned?(this.high>>>0)*f+(this.low>>>0):this.high*f+(this.low>>>0)},S.toString=function(t){if((t=t||10)<2||36>>0).toString(t);if((o=u).isZero())return l+a;for(;l.length<6;)l="0"+l;a=""+l+a}},S.getHighBits=function(){return this.high},S.getHighBitsUnsigned=function(){return this.high>>>0},S.getLowBits=function(){return this.low},S.getLowBitsUnsigned=function(){return this.low>>>0},S.getNumBitsAbs=function(){if(this.isNegative())return this.eq(T)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,e=31;e>0&&0==(t&1<=0},S.isOdd=function(){return 1==(1&this.low)},S.isEven=function(){return 0==(1&this.low)},S.equals=function(t){return r(t)||(t=p(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&this.high===t.high&&this.low===t.low},S.eq=S.equals,S.notEquals=function(t){return!this.eq(t)},S.neq=S.notEquals,S.ne=S.notEquals,S.lessThan=function(t){return this.comp(t)<0},S.lt=S.lessThan,S.lessThanOrEqual=function(t){return this.comp(t)<=0},S.lte=S.lessThanOrEqual,S.le=S.lessThanOrEqual,S.greaterThan=function(t){return this.comp(t)>0},S.gt=S.greaterThan,S.greaterThanOrEqual=function(t){return this.comp(t)>=0},S.gte=S.greaterThanOrEqual,S.ge=S.greaterThanOrEqual,S.compare=function(t){if(r(t)||(t=p(t)),this.eq(t))return 0;var e=this.isNegative(),n=t.isNegative();return e&&!n?-1:!e&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},S.comp=S.compare,S.negate=function(){return!this.unsigned&&this.eq(T)?T:this.not().add(y)},S.neg=S.negate,S.add=function(t){r(t)||(t=p(t));var e=this.high>>>16,n=65535&this.high,i=this.low>>>16,o=65535&this.low,a=t.high>>>16,s=65535&t.high,c=t.low>>>16,l=0,f=0,d=0,h=0;return d+=(h+=o+(65535&t.low))>>>16,f+=(d+=i+c)>>>16,l+=(f+=n+s)>>>16,l+=e+a,u((d&=65535)<<16|(h&=65535),(l&=65535)<<16|(f&=65535),this.unsigned)},S.subtract=function(t){return r(t)||(t=p(t)),this.add(t.neg())},S.sub=S.subtract,S.multiply=function(t){if(this.isZero())return b;if(r(t)||(t=p(t)),e)return u(e.mul(this.low,this.high,t.low,t.high),e.get_high(),this.unsigned);if(t.isZero())return b;if(this.eq(T))return t.isOdd()?T:b;if(t.eq(T))return this.isOdd()?T:b;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(g)&&t.lt(g))return s(this.toNumber()*t.toNumber(),this.unsigned);var n=this.high>>>16,i=65535&this.high,o=this.low>>>16,a=65535&this.low,c=t.high>>>16,l=65535&t.high,f=t.low>>>16,d=65535&t.low,h=0,m=0,y=0,_=0;return y+=(_+=a*d)>>>16,m+=(y+=o*d)>>>16,y&=65535,m+=(y+=a*f)>>>16,h+=(m+=i*d)>>>16,m&=65535,h+=(m+=o*f)>>>16,m&=65535,h+=(m+=a*l)>>>16,h+=n*d+i*f+o*l+a*c,u((y&=65535)<<16|(_&=65535),(h&=65535)<<16|(m&=65535),this.unsigned)},S.mul=S.multiply,S.divide=function(t){if(r(t)||(t=p(t)),t.isZero())throw Error("division by zero");var n,i,o;if(e)return this.unsigned||-2147483648!==this.high||-1!==t.low||-1!==t.high?u((this.unsigned?e.div_u:e.div_s)(this.low,this.high,t.low,t.high),e.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?m:b;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return m;if(t.gt(this.shru(1)))return _;o=m}else{if(this.eq(T))return t.eq(y)||t.eq(v)?T:t.eq(T)?y:(n=this.shr(1).div(t).shl(1)).eq(b)?t.isNegative()?y:v:(i=this.sub(t.mul(n)),o=n.add(i.div(t)));if(t.eq(T))return this.unsigned?m:b;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();o=b}for(i=this;i.gte(t);){n=Math.max(1,Math.floor(i.toNumber()/t.toNumber()));for(var a=Math.ceil(Math.log(n)/Math.LN2),l=a<=48?1:c(2,a-48),f=s(n),d=f.mul(t);d.isNegative()||d.gt(i);)d=(f=s(n-=l,this.unsigned)).mul(t);f.isZero()&&(f=y),o=o.add(f),i=i.sub(d)}return o},S.div=S.divide,S.modulo=function(t){return r(t)||(t=p(t)),e?u((this.unsigned?e.rem_u:e.rem_s)(this.low,this.high,t.low,t.high),e.get_high(),this.unsigned):this.sub(this.div(t).mul(t))},S.mod=S.modulo,S.rem=S.modulo,S.not=function(){return u(~this.low,~this.high,this.unsigned)},S.and=function(t){return r(t)||(t=p(t)),u(this.low&t.low,this.high&t.high,this.unsigned)},S.or=function(t){return r(t)||(t=p(t)),u(this.low|t.low,this.high|t.high,this.unsigned)},S.xor=function(t){return r(t)||(t=p(t)),u(this.low^t.low,this.high^t.high,this.unsigned)},S.shiftLeft=function(t){return r(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?u(this.low<>>32-t,this.unsigned):u(0,this.low<>>t|this.high<<32-t,this.high>>t,this.unsigned):u(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},S.shr=S.shiftRight,S.shiftRightUnsigned=function(t){if(r(t)&&(t=t.toInt()),0==(t&=63))return this;var e=this.high;return t<32?u(this.low>>>t|e<<32-t,e>>>t,this.unsigned):u(32===t?e:e>>>t-32,0,this.unsigned)},S.shru=S.shiftRightUnsigned,S.shr_u=S.shiftRightUnsigned,S.toSigned=function(){return this.unsigned?u(this.low,this.high,!1):this},S.toUnsigned=function(){return this.unsigned?this:u(this.low,this.high,!0)},S.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},S.toBytesLE=function(){var t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},S.toBytesBE=function(){var t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]},n.fromBytes=function(t,e,r){return r?n.fromBytesLE(t,e):n.fromBytesBE(t,e)},n.fromBytesLE=function(t,e){return new n(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)},n.fromBytesBE=function(t,e){return new n(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)}},1446:(t,e,n)=>{"use strict";var r,i,o,a=n(2100),s=a.Reader,u=a.Writer,c=a.util,l=a.roots.default||(a.roots.default={});l.onnx=((o={}).Version=(r={},(i=Object.create(r))[r[0]="_START_VERSION"]=0,i[r[1]="IR_VERSION_2017_10_10"]=1,i[r[2]="IR_VERSION_2017_10_30"]=2,i[r[3]="IR_VERSION_2017_11_3"]=3,i[r[4]="IR_VERSION_2019_1_22"]=4,i[r[5]="IR_VERSION"]=5,i),o.AttributeProto=function(){function t(t){if(this.floats=[],this.ints=[],this.strings=[],this.tensors=[],this.graphs=[],t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.name=t.string();break;case 21:r.refAttrName=t.string();break;case 13:r.docString=t.string();break;case 20:r.type=t.int32();break;case 2:r.f=t.float();break;case 3:r.i=t.int64();break;case 4:r.s=t.bytes();break;case 5:r.t=l.onnx.TensorProto.decode(t,t.uint32());break;case 6:r.g=l.onnx.GraphProto.decode(t,t.uint32());break;case 7:if(r.floats&&r.floats.length||(r.floats=[]),2==(7&i))for(var o=t.uint32()+t.pos;t.pos>>0,t.i.high>>>0).toNumber())),null!=t.s&&("string"==typeof t.s?c.base64.decode(t.s,e.s=c.newBuffer(c.base64.length(t.s)),0):t.s.length&&(e.s=t.s)),null!=t.t){if("object"!=typeof t.t)throw TypeError(".onnx.AttributeProto.t: object expected");e.t=l.onnx.TensorProto.fromObject(t.t)}if(null!=t.g){if("object"!=typeof t.g)throw TypeError(".onnx.AttributeProto.g: object expected");e.g=l.onnx.GraphProto.fromObject(t.g)}if(t.floats){if(!Array.isArray(t.floats))throw TypeError(".onnx.AttributeProto.floats: array expected");e.floats=[];for(var n=0;n>>0,t.ints[n].high>>>0).toNumber())}if(t.strings){if(!Array.isArray(t.strings))throw TypeError(".onnx.AttributeProto.strings: array expected");for(e.strings=[],n=0;n>>0,t.i.high>>>0).toNumber():t.i),null!=t.s&&t.hasOwnProperty("s")&&(n.s=e.bytes===String?c.base64.encode(t.s,0,t.s.length):e.bytes===Array?Array.prototype.slice.call(t.s):t.s),null!=t.t&&t.hasOwnProperty("t")&&(n.t=l.onnx.TensorProto.toObject(t.t,e)),null!=t.g&&t.hasOwnProperty("g")&&(n.g=l.onnx.GraphProto.toObject(t.g,e)),t.floats&&t.floats.length){n.floats=[];for(var i=0;i>>0,t.ints[i].high>>>0).toNumber():t.ints[i];if(t.strings&&t.strings.length)for(n.strings=[],i=0;i>>3){case 1:r.name=t.string();break;case 2:r.type=l.onnx.TypeProto.decode(t,t.uint32());break;case 3:r.docString=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.name&&t.hasOwnProperty("name")&&!c.isString(t.name))return"name: string expected";if(null!=t.type&&t.hasOwnProperty("type")){var e=l.onnx.TypeProto.verify(t.type);if(e)return"type."+e}return null!=t.docString&&t.hasOwnProperty("docString")&&!c.isString(t.docString)?"docString: string expected":null},t.fromObject=function(t){if(t instanceof l.onnx.ValueInfoProto)return t;var e=new l.onnx.ValueInfoProto;if(null!=t.name&&(e.name=String(t.name)),null!=t.type){if("object"!=typeof t.type)throw TypeError(".onnx.ValueInfoProto.type: object expected");e.type=l.onnx.TypeProto.fromObject(t.type)}return null!=t.docString&&(e.docString=String(t.docString)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.name="",n.type=null,n.docString=""),null!=t.name&&t.hasOwnProperty("name")&&(n.name=t.name),null!=t.type&&t.hasOwnProperty("type")&&(n.type=l.onnx.TypeProto.toObject(t.type,e)),null!=t.docString&&t.hasOwnProperty("docString")&&(n.docString=t.docString),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),o.NodeProto=function(){function t(t){if(this.input=[],this.output=[],this.attribute=[],t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.input&&r.input.length||(r.input=[]),r.input.push(t.string());break;case 2:r.output&&r.output.length||(r.output=[]),r.output.push(t.string());break;case 3:r.name=t.string();break;case 4:r.opType=t.string();break;case 7:r.domain=t.string();break;case 5:r.attribute&&r.attribute.length||(r.attribute=[]),r.attribute.push(l.onnx.AttributeProto.decode(t,t.uint32()));break;case 6:r.docString=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.input&&t.hasOwnProperty("input")){if(!Array.isArray(t.input))return"input: array expected";for(var e=0;e>>3){case 1:r.irVersion=t.int64();break;case 8:r.opsetImport&&r.opsetImport.length||(r.opsetImport=[]),r.opsetImport.push(l.onnx.OperatorSetIdProto.decode(t,t.uint32()));break;case 2:r.producerName=t.string();break;case 3:r.producerVersion=t.string();break;case 4:r.domain=t.string();break;case 5:r.modelVersion=t.int64();break;case 6:r.docString=t.string();break;case 7:r.graph=l.onnx.GraphProto.decode(t,t.uint32());break;case 14:r.metadataProps&&r.metadataProps.length||(r.metadataProps=[]),r.metadataProps.push(l.onnx.StringStringEntryProto.decode(t,t.uint32()));break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.irVersion&&t.hasOwnProperty("irVersion")&&!(c.isInteger(t.irVersion)||t.irVersion&&c.isInteger(t.irVersion.low)&&c.isInteger(t.irVersion.high)))return"irVersion: integer|Long expected";if(null!=t.opsetImport&&t.hasOwnProperty("opsetImport")){if(!Array.isArray(t.opsetImport))return"opsetImport: array expected";for(var e=0;e>>0,t.irVersion.high>>>0).toNumber())),t.opsetImport){if(!Array.isArray(t.opsetImport))throw TypeError(".onnx.ModelProto.opsetImport: array expected");e.opsetImport=[];for(var n=0;n>>0,t.modelVersion.high>>>0).toNumber())),null!=t.docString&&(e.docString=String(t.docString)),null!=t.graph){if("object"!=typeof t.graph)throw TypeError(".onnx.ModelProto.graph: object expected");e.graph=l.onnx.GraphProto.fromObject(t.graph)}if(t.metadataProps){if(!Array.isArray(t.metadataProps))throw TypeError(".onnx.ModelProto.metadataProps: array expected");for(e.metadataProps=[],n=0;n>>0,t.irVersion.high>>>0).toNumber():t.irVersion),null!=t.producerName&&t.hasOwnProperty("producerName")&&(n.producerName=t.producerName),null!=t.producerVersion&&t.hasOwnProperty("producerVersion")&&(n.producerVersion=t.producerVersion),null!=t.domain&&t.hasOwnProperty("domain")&&(n.domain=t.domain),null!=t.modelVersion&&t.hasOwnProperty("modelVersion")&&("number"==typeof t.modelVersion?n.modelVersion=e.longs===String?String(t.modelVersion):t.modelVersion:n.modelVersion=e.longs===String?c.Long.prototype.toString.call(t.modelVersion):e.longs===Number?new c.LongBits(t.modelVersion.low>>>0,t.modelVersion.high>>>0).toNumber():t.modelVersion),null!=t.docString&&t.hasOwnProperty("docString")&&(n.docString=t.docString),null!=t.graph&&t.hasOwnProperty("graph")&&(n.graph=l.onnx.GraphProto.toObject(t.graph,e)),t.opsetImport&&t.opsetImport.length){n.opsetImport=[];for(var i=0;i>>3){case 1:r.key=t.string();break;case 2:r.value=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.key&&t.hasOwnProperty("key")&&!c.isString(t.key)?"key: string expected":null!=t.value&&t.hasOwnProperty("value")&&!c.isString(t.value)?"value: string expected":null},t.fromObject=function(t){if(t instanceof l.onnx.StringStringEntryProto)return t;var e=new l.onnx.StringStringEntryProto;return null!=t.key&&(e.key=String(t.key)),null!=t.value&&(e.value=String(t.value)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.key="",n.value=""),null!=t.key&&t.hasOwnProperty("key")&&(n.key=t.key),null!=t.value&&t.hasOwnProperty("value")&&(n.value=t.value),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),o.TensorAnnotation=function(){function t(t){if(this.quantParameterTensorNames=[],t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.tensorName=t.string();break;case 2:r.quantParameterTensorNames&&r.quantParameterTensorNames.length||(r.quantParameterTensorNames=[]),r.quantParameterTensorNames.push(l.onnx.StringStringEntryProto.decode(t,t.uint32()));break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.tensorName&&t.hasOwnProperty("tensorName")&&!c.isString(t.tensorName))return"tensorName: string expected";if(null!=t.quantParameterTensorNames&&t.hasOwnProperty("quantParameterTensorNames")){if(!Array.isArray(t.quantParameterTensorNames))return"quantParameterTensorNames: array expected";for(var e=0;e>>3){case 1:r.node&&r.node.length||(r.node=[]),r.node.push(l.onnx.NodeProto.decode(t,t.uint32()));break;case 2:r.name=t.string();break;case 5:r.initializer&&r.initializer.length||(r.initializer=[]),r.initializer.push(l.onnx.TensorProto.decode(t,t.uint32()));break;case 10:r.docString=t.string();break;case 11:r.input&&r.input.length||(r.input=[]),r.input.push(l.onnx.ValueInfoProto.decode(t,t.uint32()));break;case 12:r.output&&r.output.length||(r.output=[]),r.output.push(l.onnx.ValueInfoProto.decode(t,t.uint32()));break;case 13:r.valueInfo&&r.valueInfo.length||(r.valueInfo=[]),r.valueInfo.push(l.onnx.ValueInfoProto.decode(t,t.uint32()));break;case 14:r.quantizationAnnotation&&r.quantizationAnnotation.length||(r.quantizationAnnotation=[]),r.quantizationAnnotation.push(l.onnx.TensorAnnotation.decode(t,t.uint32()));break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.node&&t.hasOwnProperty("node")){if(!Array.isArray(t.node))return"node: array expected";for(var e=0;e>>3){case 1:if(r.dims&&r.dims.length||(r.dims=[]),2==(7&i))for(var o=t.uint32()+t.pos;t.pos>>0,t.dims[n].high>>>0).toNumber())}if(null!=t.dataType&&(e.dataType=0|t.dataType),null!=t.segment){if("object"!=typeof t.segment)throw TypeError(".onnx.TensorProto.segment: object expected");e.segment=l.onnx.TensorProto.Segment.fromObject(t.segment)}if(t.floatData){if(!Array.isArray(t.floatData))throw TypeError(".onnx.TensorProto.floatData: array expected");for(e.floatData=[],n=0;n>>0,t.int64Data[n].high>>>0).toNumber())}if(null!=t.name&&(e.name=String(t.name)),null!=t.docString&&(e.docString=String(t.docString)),null!=t.rawData&&("string"==typeof t.rawData?c.base64.decode(t.rawData,e.rawData=c.newBuffer(c.base64.length(t.rawData)),0):t.rawData.length&&(e.rawData=t.rawData)),t.externalData){if(!Array.isArray(t.externalData))throw TypeError(".onnx.TensorProto.externalData: array expected");for(e.externalData=[],n=0;n>>0,t.uint64Data[n].high>>>0).toNumber(!0))}return e},t.toObject=function(t,e){e||(e={});var n={};if((e.arrays||e.defaults)&&(n.dims=[],n.floatData=[],n.int32Data=[],n.stringData=[],n.int64Data=[],n.doubleData=[],n.uint64Data=[],n.externalData=[]),e.defaults&&(n.dataType=0,n.segment=null,n.name="",e.bytes===String?n.rawData="":(n.rawData=[],e.bytes!==Array&&(n.rawData=c.newBuffer(n.rawData))),n.docString="",n.dataLocation=e.enums===String?"DEFAULT":0),t.dims&&t.dims.length){n.dims=[];for(var r=0;r>>0,t.dims[r].high>>>0).toNumber():t.dims[r]}if(null!=t.dataType&&t.hasOwnProperty("dataType")&&(n.dataType=t.dataType),null!=t.segment&&t.hasOwnProperty("segment")&&(n.segment=l.onnx.TensorProto.Segment.toObject(t.segment,e)),t.floatData&&t.floatData.length)for(n.floatData=[],r=0;r>>0,t.int64Data[r].high>>>0).toNumber():t.int64Data[r];if(null!=t.name&&t.hasOwnProperty("name")&&(n.name=t.name),null!=t.rawData&&t.hasOwnProperty("rawData")&&(n.rawData=e.bytes===String?c.base64.encode(t.rawData,0,t.rawData.length):e.bytes===Array?Array.prototype.slice.call(t.rawData):t.rawData),t.doubleData&&t.doubleData.length)for(n.doubleData=[],r=0;r>>0,t.uint64Data[r].high>>>0).toNumber(!0):t.uint64Data[r];if(null!=t.docString&&t.hasOwnProperty("docString")&&(n.docString=t.docString),t.externalData&&t.externalData.length)for(n.externalData=[],r=0;r>>3){case 1:r.begin=t.int64();break;case 2:r.end=t.int64();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.begin&&t.hasOwnProperty("begin")&&!(c.isInteger(t.begin)||t.begin&&c.isInteger(t.begin.low)&&c.isInteger(t.begin.high))?"begin: integer|Long expected":null!=t.end&&t.hasOwnProperty("end")&&!(c.isInteger(t.end)||t.end&&c.isInteger(t.end.low)&&c.isInteger(t.end.high))?"end: integer|Long expected":null},t.fromObject=function(t){if(t instanceof l.onnx.TensorProto.Segment)return t;var e=new l.onnx.TensorProto.Segment;return null!=t.begin&&(c.Long?(e.begin=c.Long.fromValue(t.begin)).unsigned=!1:"string"==typeof t.begin?e.begin=parseInt(t.begin,10):"number"==typeof t.begin?e.begin=t.begin:"object"==typeof t.begin&&(e.begin=new c.LongBits(t.begin.low>>>0,t.begin.high>>>0).toNumber())),null!=t.end&&(c.Long?(e.end=c.Long.fromValue(t.end)).unsigned=!1:"string"==typeof t.end?e.end=parseInt(t.end,10):"number"==typeof t.end?e.end=t.end:"object"==typeof t.end&&(e.end=new c.LongBits(t.end.low>>>0,t.end.high>>>0).toNumber())),e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults){if(c.Long){var r=new c.Long(0,0,!1);n.begin=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.begin=e.longs===String?"0":0;c.Long?(r=new c.Long(0,0,!1),n.end=e.longs===String?r.toString():e.longs===Number?r.toNumber():r):n.end=e.longs===String?"0":0}return null!=t.begin&&t.hasOwnProperty("begin")&&("number"==typeof t.begin?n.begin=e.longs===String?String(t.begin):t.begin:n.begin=e.longs===String?c.Long.prototype.toString.call(t.begin):e.longs===Number?new c.LongBits(t.begin.low>>>0,t.begin.high>>>0).toNumber():t.begin),null!=t.end&&t.hasOwnProperty("end")&&("number"==typeof t.end?n.end=e.longs===String?String(t.end):t.end:n.end=e.longs===String?c.Long.prototype.toString.call(t.end):e.longs===Number?new c.LongBits(t.end.low>>>0,t.end.high>>>0).toNumber():t.end),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),t.DataLocation=function(){var t={},e=Object.create(t);return e[t[0]="DEFAULT"]=0,e[t[1]="EXTERNAL"]=1,e}(),t}(),o.TensorShapeProto=function(){function t(t){if(this.dim=[],t)for(var e=Object.keys(t),n=0;n>>3==1?(r.dim&&r.dim.length||(r.dim=[]),r.dim.push(l.onnx.TensorShapeProto.Dimension.decode(t,t.uint32()))):t.skipType(7&i)}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.dim&&t.hasOwnProperty("dim")){if(!Array.isArray(t.dim))return"dim: array expected";for(var e=0;e>>3){case 1:r.dimValue=t.int64();break;case 2:r.dimParam=t.string();break;case 3:r.denotation=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";var e={};if(null!=t.dimValue&&t.hasOwnProperty("dimValue")&&(e.value=1,!(c.isInteger(t.dimValue)||t.dimValue&&c.isInteger(t.dimValue.low)&&c.isInteger(t.dimValue.high))))return"dimValue: integer|Long expected";if(null!=t.dimParam&&t.hasOwnProperty("dimParam")){if(1===e.value)return"value: multiple values";if(e.value=1,!c.isString(t.dimParam))return"dimParam: string expected"}return null!=t.denotation&&t.hasOwnProperty("denotation")&&!c.isString(t.denotation)?"denotation: string expected":null},t.fromObject=function(t){if(t instanceof l.onnx.TensorShapeProto.Dimension)return t;var e=new l.onnx.TensorShapeProto.Dimension;return null!=t.dimValue&&(c.Long?(e.dimValue=c.Long.fromValue(t.dimValue)).unsigned=!1:"string"==typeof t.dimValue?e.dimValue=parseInt(t.dimValue,10):"number"==typeof t.dimValue?e.dimValue=t.dimValue:"object"==typeof t.dimValue&&(e.dimValue=new c.LongBits(t.dimValue.low>>>0,t.dimValue.high>>>0).toNumber())),null!=t.dimParam&&(e.dimParam=String(t.dimParam)),null!=t.denotation&&(e.denotation=String(t.denotation)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.denotation=""),null!=t.dimValue&&t.hasOwnProperty("dimValue")&&("number"==typeof t.dimValue?n.dimValue=e.longs===String?String(t.dimValue):t.dimValue:n.dimValue=e.longs===String?c.Long.prototype.toString.call(t.dimValue):e.longs===Number?new c.LongBits(t.dimValue.low>>>0,t.dimValue.high>>>0).toNumber():t.dimValue,e.oneofs&&(n.value="dimValue")),null!=t.dimParam&&t.hasOwnProperty("dimParam")&&(n.dimParam=t.dimParam,e.oneofs&&(n.value="dimParam")),null!=t.denotation&&t.hasOwnProperty("denotation")&&(n.denotation=t.denotation),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),t}(),o.TypeProto=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.tensorType=l.onnx.TypeProto.Tensor.decode(t,t.uint32());break;case 6:r.denotation=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.tensorType&&t.hasOwnProperty("tensorType")){var e=l.onnx.TypeProto.Tensor.verify(t.tensorType);if(e)return"tensorType."+e}return null!=t.denotation&&t.hasOwnProperty("denotation")&&!c.isString(t.denotation)?"denotation: string expected":null},t.fromObject=function(t){if(t instanceof l.onnx.TypeProto)return t;var e=new l.onnx.TypeProto;if(null!=t.tensorType){if("object"!=typeof t.tensorType)throw TypeError(".onnx.TypeProto.tensorType: object expected");e.tensorType=l.onnx.TypeProto.Tensor.fromObject(t.tensorType)}return null!=t.denotation&&(e.denotation=String(t.denotation)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.denotation=""),null!=t.tensorType&&t.hasOwnProperty("tensorType")&&(n.tensorType=l.onnx.TypeProto.Tensor.toObject(t.tensorType,e),e.oneofs&&(n.value="tensorType")),null!=t.denotation&&t.hasOwnProperty("denotation")&&(n.denotation=t.denotation),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t.Tensor=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.elemType=t.int32();break;case 2:r.shape=l.onnx.TensorShapeProto.decode(t,t.uint32());break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.elemType&&t.hasOwnProperty("elemType")&&!c.isInteger(t.elemType))return"elemType: integer expected";if(null!=t.shape&&t.hasOwnProperty("shape")){var e=l.onnx.TensorShapeProto.verify(t.shape);if(e)return"shape."+e}return null},t.fromObject=function(t){if(t instanceof l.onnx.TypeProto.Tensor)return t;var e=new l.onnx.TypeProto.Tensor;if(null!=t.elemType&&(e.elemType=0|t.elemType),null!=t.shape){if("object"!=typeof t.shape)throw TypeError(".onnx.TypeProto.Tensor.shape: object expected");e.shape=l.onnx.TensorShapeProto.fromObject(t.shape)}return e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.elemType=0,n.shape=null),null!=t.elemType&&t.hasOwnProperty("elemType")&&(n.elemType=t.elemType),null!=t.shape&&t.hasOwnProperty("shape")&&(n.shape=l.onnx.TensorShapeProto.toObject(t.shape,e)),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),t}(),o.OperatorSetIdProto=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.domain=t.string();break;case 2:r.version=t.int64();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.domain&&t.hasOwnProperty("domain")&&!c.isString(t.domain)?"domain: string expected":null!=t.version&&t.hasOwnProperty("version")&&!(c.isInteger(t.version)||t.version&&c.isInteger(t.version.low)&&c.isInteger(t.version.high))?"version: integer|Long expected":null},t.fromObject=function(t){if(t instanceof l.onnx.OperatorSetIdProto)return t;var e=new l.onnx.OperatorSetIdProto;return null!=t.domain&&(e.domain=String(t.domain)),null!=t.version&&(c.Long?(e.version=c.Long.fromValue(t.version)).unsigned=!1:"string"==typeof t.version?e.version=parseInt(t.version,10):"number"==typeof t.version?e.version=t.version:"object"==typeof t.version&&(e.version=new c.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber())),e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults)if(n.domain="",c.Long){var r=new c.Long(0,0,!1);n.version=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.version=e.longs===String?"0":0;return null!=t.domain&&t.hasOwnProperty("domain")&&(n.domain=t.domain),null!=t.version&&t.hasOwnProperty("version")&&("number"==typeof t.version?n.version=e.longs===String?String(t.version):t.version:n.version=e.longs===String?c.Long.prototype.toString.call(t.version):e.longs===Number?new c.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber():t.version),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,a.util.toJSONOptions)},t}(),o),t.exports=l},2100:(t,e,n)=>{"use strict";t.exports=n(9482)},9482:(t,e,n)=>{"use strict";var r=e;function i(){r.util._configure(),r.Writer._configure(r.BufferWriter),r.Reader._configure(r.BufferReader)}r.build="minimal",r.Writer=n(1173),r.BufferWriter=n(3155),r.Reader=n(1408),r.BufferReader=n(593),r.util=n(9693),r.rpc=n(5994),r.roots=n(5054),r.configure=i,i()},1408:(t,e,n)=>{"use strict";t.exports=u;var r,i=n(9693),o=i.LongBits,a=i.utf8;function s(t,e){return RangeError("index out of range: "+t.pos+" + "+(e||1)+" > "+t.len)}function u(t){this.buf=t,this.pos=0,this.len=t.length}var c,l="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new u(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new u(t);throw Error("illegal buffer")},p=function(){return i.Buffer?function(t){return(u.create=function(t){return i.Buffer.isBuffer(t)?new r(t):l(t)})(t)}:l};function f(){var t=new o(0,0),e=0;if(!(this.len-this.pos>4)){for(;e<3;++e){if(this.pos>=this.len)throw s(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*e)>>>0,t}for(;e<4;++e)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(e=0,this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw s(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function d(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}function h(){if(this.pos+8>this.len)throw s(this,8);return new o(d(this.buf,this.pos+=4),d(this.buf,this.pos+=4))}u.create=p(),u.prototype._slice=i.Array.prototype.subarray||i.Array.prototype.slice,u.prototype.uint32=(c=4294967295,function(){if(c=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return c;if((this.pos+=5)>this.len)throw this.pos=this.len,s(this,10);return c}),u.prototype.int32=function(){return 0|this.uint32()},u.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)|0},u.prototype.bool=function(){return 0!==this.uint32()},u.prototype.fixed32=function(){if(this.pos+4>this.len)throw s(this,4);return d(this.buf,this.pos+=4)},u.prototype.sfixed32=function(){if(this.pos+4>this.len)throw s(this,4);return 0|d(this.buf,this.pos+=4)},u.prototype.float=function(){if(this.pos+4>this.len)throw s(this,4);var t=i.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},u.prototype.double=function(){if(this.pos+8>this.len)throw s(this,4);var t=i.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},u.prototype.bytes=function(){var t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw s(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,n):e===n?new this.buf.constructor(0):this._slice.call(this.buf,e,n)},u.prototype.string=function(){var t=this.bytes();return a.read(t,0,t.length)},u.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw s(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw s(this)}while(128&this.buf[this.pos++]);return this},u.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},u._configure=function(t){r=t,u.create=p(),r._configure();var e=i.Long?"toLong":"toNumber";i.merge(u.prototype,{int64:function(){return f.call(this)[e](!1)},uint64:function(){return f.call(this)[e](!0)},sint64:function(){return f.call(this).zzDecode()[e](!1)},fixed64:function(){return h.call(this)[e](!0)},sfixed64:function(){return h.call(this)[e](!1)}})}},593:(t,e,n)=>{"use strict";t.exports=o;var r=n(1408);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(9693);function o(t){r.call(this,t)}o._configure=function(){i.Buffer&&(o.prototype._slice=i.Buffer.prototype.slice)},o.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))},o._configure()},5054:t=>{"use strict";t.exports={}},5994:(t,e,n)=>{"use strict";e.Service=n(7948)},7948:(t,e,n)=>{"use strict";t.exports=i;var r=n(9693);function i(t,e,n){if("function"!=typeof t)throw TypeError("rpcImpl must be a function");r.EventEmitter.call(this),this.rpcImpl=t,this.requestDelimited=Boolean(e),this.responseDelimited=Boolean(n)}(i.prototype=Object.create(r.EventEmitter.prototype)).constructor=i,i.prototype.rpcCall=function t(e,n,i,o,a){if(!o)throw TypeError("request must be specified");var s=this;if(!a)return r.asPromise(t,s,e,n,i,o);if(s.rpcImpl)try{return s.rpcImpl(e,n[s.requestDelimited?"encodeDelimited":"encode"](o).finish(),(function(t,n){if(t)return s.emit("error",t,e),a(t);if(null!==n){if(!(n instanceof i))try{n=i[s.responseDelimited?"decodeDelimited":"decode"](n)}catch(t){return s.emit("error",t,e),a(t)}return s.emit("data",n,e),a(null,n)}s.end(!0)}))}catch(t){return s.emit("error",t,e),void setTimeout((function(){a(t)}),0)}else setTimeout((function(){a(Error("already ended"))}),0)},i.prototype.end=function(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},1945:(t,e,n)=>{"use strict";t.exports=i;var r=n(9693);function i(t,e){this.lo=t>>>0,this.hi=e>>>0}var o=i.zero=new i(0,0);o.toNumber=function(){return 0},o.zzEncode=o.zzDecode=function(){return this},o.length=function(){return 1};var a=i.zeroHash="\0\0\0\0\0\0\0\0";i.fromNumber=function(t){if(0===t)return o;var e=t<0;e&&(t=-t);var n=t>>>0,r=(t-n)/4294967296>>>0;return e&&(r=~r>>>0,n=~n>>>0,++n>4294967295&&(n=0,++r>4294967295&&(r=0))),new i(n,r)},i.from=function(t){if("number"==typeof t)return i.fromNumber(t);if(r.isString(t)){if(!r.Long)return i.fromNumber(parseInt(t,10));t=r.Long.fromString(t)}return t.low||t.high?new i(t.low>>>0,t.high>>>0):o},i.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var e=1+~this.lo>>>0,n=~this.hi>>>0;return e||(n=n+1>>>0),-(e+4294967296*n)}return this.lo+4294967296*this.hi},i.prototype.toLong=function(t){return r.Long?new r.Long(0|this.lo,0|this.hi,Boolean(t)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(t)}};var s=String.prototype.charCodeAt;i.fromHash=function(t){return t===a?o:new i((s.call(t,0)|s.call(t,1)<<8|s.call(t,2)<<16|s.call(t,3)<<24)>>>0,(s.call(t,4)|s.call(t,5)<<8|s.call(t,6)<<16|s.call(t,7)<<24)>>>0)},i.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},i.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this},i.prototype.zzDecode=function(){var t=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this},i.prototype.length=function(){var t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return 0===n?0===e?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}},9693:function(t,e,n){"use strict";var r=e;function i(t,e,n){for(var r=Object.keys(e),i=0;i0)},r.Buffer=function(){try{var t=r.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(t){return"number"==typeof t?r.Buffer?r._Buffer_allocUnsafe(t):new r.Array(t):r.Buffer?r._Buffer_from(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(t){return t?r.LongBits.from(t).toHash():r.LongBits.zeroHash},r.longFromHash=function(t,e){var n=r.LongBits.fromHash(t);return r.Long?r.Long.fromBits(n.lo,n.hi,e):n.toNumber(Boolean(e))},r.merge=i,r.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)},r.newError=o,r.ProtocolError=o("ProtocolError"),r.oneOfGetter=function(t){for(var e={},n=0;n-1;--n)if(1===e[t[n]]&&void 0!==this[t[n]]&&null!==this[t[n]])return t[n]}},r.oneOfSetter=function(t){return function(e){for(var n=0;n{"use strict";t.exports=p;var r,i=n(9693),o=i.LongBits,a=i.base64,s=i.utf8;function u(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}function c(){}function l(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function p(){this.len=0,this.head=new u(c,0,0),this.tail=this.head,this.states=null}var f=function(){return i.Buffer?function(){return(p.create=function(){return new r})()}:function(){return new p}};function d(t,e,n){e[n]=255&t}function h(t,e){this.len=t,this.next=void 0,this.val=e}function g(t,e,n){for(;t.hi;)e[n++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[n++]=127&t.lo|128,t.lo=t.lo>>>7;e[n++]=t.lo}function b(t,e,n){e[n]=255&t,e[n+1]=t>>>8&255,e[n+2]=t>>>16&255,e[n+3]=t>>>24}p.create=f(),p.alloc=function(t){return new i.Array(t)},i.Array!==Array&&(p.alloc=i.pool(p.alloc,i.Array.prototype.subarray)),p.prototype._push=function(t,e,n){return this.tail=this.tail.next=new u(t,e,n),this.len+=e,this},h.prototype=Object.create(u.prototype),h.prototype.fn=function(t,e,n){for(;t>127;)e[n++]=127&t|128,t>>>=7;e[n]=t},p.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new h((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},p.prototype.int32=function(t){return t<0?this._push(g,10,o.fromNumber(t)):this.uint32(t)},p.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},p.prototype.uint64=function(t){var e=o.from(t);return this._push(g,e.length(),e)},p.prototype.int64=p.prototype.uint64,p.prototype.sint64=function(t){var e=o.from(t).zzEncode();return this._push(g,e.length(),e)},p.prototype.bool=function(t){return this._push(d,1,t?1:0)},p.prototype.fixed32=function(t){return this._push(b,4,t>>>0)},p.prototype.sfixed32=p.prototype.fixed32,p.prototype.fixed64=function(t){var e=o.from(t);return this._push(b,4,e.lo)._push(b,4,e.hi)},p.prototype.sfixed64=p.prototype.fixed64,p.prototype.float=function(t){return this._push(i.float.writeFloatLE,4,t)},p.prototype.double=function(t){return this._push(i.float.writeDoubleLE,8,t)};var m=i.Array.prototype.set?function(t,e,n){e.set(t,n)}:function(t,e,n){for(var r=0;r>>0;if(!e)return this._push(d,1,0);if(i.isString(t)){var n=p.alloc(e=a.length(t));a.decode(t,n,0),t=n}return this.uint32(e)._push(m,e,t)},p.prototype.string=function(t){var e=s.length(t);return e?this.uint32(e)._push(s.write,e,t):this._push(d,1,0)},p.prototype.fork=function(){return this.states=new l(this),this.head=this.tail=new u(c,0,0),this.len=0,this},p.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new u(c,0,0),this.len=0),this},p.prototype.ldelim=function(){var t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=t.next,this.tail=e,this.len+=n),this},p.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),n=0;t;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e},p._configure=function(t){r=t,p.create=f(),r._configure()}},3155:(t,e,n)=>{"use strict";t.exports=o;var r=n(1173);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(9693);function o(){r.call(this)}function a(t,e,n){t.length<40?i.utf8.write(t,e,n):e.utf8Write?e.utf8Write(t,n):e.write(t,n)}o._configure=function(){o.alloc=i._Buffer_allocUnsafe,o.writeBytesBuffer=i.Buffer&&i.Buffer.prototype instanceof Uint8Array&&"set"===i.Buffer.prototype.set.name?function(t,e,n){e.set(t,n)}:function(t,e,n){if(t.copy)t.copy(e,n,0,t.length);else for(var r=0;r>>0;return this.uint32(e),e&&this._push(o.writeBytesBuffer,e,t),this},o.prototype.string=function(t){var e=i.Buffer.byteLength(t);return this.uint32(e),e&&this._push(a,e,t),this},o._configure()},7714:(t,e,n)=>{"use strict";e.R=void 0;const r=n(6919),i=n(7448);e.R=new class{async init(){}async createSessionHandler(t,e){const n=new r.Session(e);return await n.loadModel(t),new i.OnnxjsSessionHandler(n)}}},4200:(t,e,n)=>{"use strict";e.c8=e.rX=void 0;const r=n(8453),i=n(5381),o=n(2157),a=n(2306);e.rX=()=>{if(("number"!=typeof r.env.wasm.initTimeout||r.env.wasm.initTimeout<0)&&(r.env.wasm.initTimeout=0),"boolean"!=typeof r.env.wasm.simd&&(r.env.wasm.simd=!0),"boolean"!=typeof r.env.wasm.proxy&&(r.env.wasm.proxy=!1),"number"!=typeof r.env.wasm.numThreads||!Number.isInteger(r.env.wasm.numThreads)||r.env.wasm.numThreads<=0){const t="undefined"==typeof navigator?(0,i.cpus)().length:navigator.hardwareConcurrency;r.env.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},e.c8=new class{async init(){(0,e.rX)(),await(0,o.initWasm)()}async createSessionHandler(t,e){const n=new a.OnnxruntimeWebAssemblySessionHandler;return await n.loadModel(t,e),Promise.resolve(n)}}},6018:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),i(n(8453),e);const o=n(8453);{const t=n(7714).R;(0,o.registerBackend)("webgl",t,-10)}{const t=n(4200).c8;(0,o.registerBackend)("cpu",t,10),(0,o.registerBackend)("wasm",t,10),(0,o.registerBackend)("xnnpack",t,9)}},246:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createAttributeWithCacheKey=void 0;class n{constructor(t){Object.assign(this,t)}get cacheKey(){return this._cacheKey||(this._cacheKey=Object.getOwnPropertyNames(this).sort().map((t=>`${this[t]}`)).join(";")),this._cacheKey}}e.createAttributeWithCacheKey=t=>new n(t)},7778:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Attribute=void 0;const r=n(1446),i=n(9395),o=n(9162),a=n(2517);var s=i.onnxruntime.experimental.fbs;class u{constructor(t){if(this._attributes=new Map,null!=t){for(const e of t)e instanceof r.onnx.AttributeProto?this._attributes.set(e.name,[u.getValue(e),u.getType(e)]):e instanceof s.Attribute&&this._attributes.set(e.name(),[u.getValue(e),u.getType(e)]);if(this._attributes.sizeo.Tensor.fromProto(t)));if(t instanceof s.Attribute)return n.map((t=>o.Tensor.fromOrtTensor(t)))}if(e===r.onnx.AttributeProto.AttributeType.STRING&&t instanceof r.onnx.AttributeProto){const t=n;return(0,a.decodeUtf8String)(t)}return e===r.onnx.AttributeProto.AttributeType.STRINGS&&t instanceof r.onnx.AttributeProto?n.map(a.decodeUtf8String):n}static getValueNoCheck(t){return t instanceof r.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(t):this.getValueNoCheckFromOrtFormat(t)}static getValueNoCheckFromOnnxFormat(t){switch(t.type){case r.onnx.AttributeProto.AttributeType.FLOAT:return t.f;case r.onnx.AttributeProto.AttributeType.INT:return t.i;case r.onnx.AttributeProto.AttributeType.STRING:return t.s;case r.onnx.AttributeProto.AttributeType.TENSOR:return t.t;case r.onnx.AttributeProto.AttributeType.GRAPH:return t.g;case r.onnx.AttributeProto.AttributeType.FLOATS:return t.floats;case r.onnx.AttributeProto.AttributeType.INTS:return t.ints;case r.onnx.AttributeProto.AttributeType.STRINGS:return t.strings;case r.onnx.AttributeProto.AttributeType.TENSORS:return t.tensors;case r.onnx.AttributeProto.AttributeType.GRAPHS:return t.graphs;default:throw new Error(`unsupported attribute type: ${r.onnx.AttributeProto.AttributeType[t.type]}`)}}static getValueNoCheckFromOrtFormat(t){switch(t.type()){case s.AttributeType.FLOAT:return t.f();case s.AttributeType.INT:return t.i();case s.AttributeType.STRING:return t.s();case s.AttributeType.TENSOR:return t.t();case s.AttributeType.GRAPH:return t.g();case s.AttributeType.FLOATS:return t.floatsArray();case s.AttributeType.INTS:{const e=[];for(let n=0;n{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.resolveBackend=e.backend=void 0;const r=n(5038),i=new Map;async function o(t){const n=e.backend;if(void 0!==n[t]&&function(t){const e=t;return"initialize"in e&&"function"==typeof e.initialize&&"createSessionHandler"in e&&"function"==typeof e.createSessionHandler&&"dispose"in e&&"function"==typeof e.dispose}(n[t])){const e=n[t];let r=e.initialize();if("object"==typeof r&&"then"in r&&(r=await r),r)return i.set(t,e),e}}e.backend={webgl:new r.WebGLBackend},e.resolveBackend=async function t(e){if(!e)return t(["webgl"]);{const t="string"==typeof e?[e]:e;for(const e of t){const t=i.get(e);if(t)return t;const n=await o(e);if(n)return n}}throw new Error("no available backend to use")}},5038:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLBackend=void 0;const r=n(8453),i=n(6231),o=n(6416),a=n(7305);e.WebGLBackend=class{get contextId(){return r.env.webgl.contextId}set contextId(t){r.env.webgl.contextId=t}get matmulMaxBatchSize(){return r.env.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(t){r.env.webgl.matmulMaxBatchSize=t}get textureCacheMode(){return r.env.webgl.textureCacheMode}set textureCacheMode(t){r.env.webgl.textureCacheMode=t}get pack(){return r.env.webgl.pack}set pack(t){r.env.webgl.pack=t}get async(){return r.env.webgl.async}set async(t){r.env.webgl.async=t}initialize(){try{return this.glContext=(0,a.createWebGLContext)(this.contextId),"number"!=typeof this.matmulMaxBatchSize&&(this.matmulMaxBatchSize=16),"string"!=typeof this.textureCacheMode&&(this.textureCacheMode="full"),"boolean"!=typeof this.pack&&(this.pack=!1),"boolean"!=typeof this.async&&(this.async=!1),i.Logger.setWithEnv(r.env),i.Logger.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(t){return i.Logger.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${t}`),!1}}createSessionHandler(t){return new o.WebGLSessionHandler(this,t)}dispose(){this.glContext.dispose()}}},5107:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CoordsGlslLib=void 0;const r=n(2517),i=n(8520),o=n(5060),a=n(7859),s=n(9390);class u extends i.GlslLib{constructor(t){super(t)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.offsetToCoords()),this.coordsToOffset()),this.toVec()),this.valueFrom()),this.getCommonUtilFuncs()),this.getInputsSamplingSnippets()),this.getOutputSamplingSnippet())}getCustomTypes(){return{}}offsetToCoords(){return{offsetToCoords:new i.GlslLibRoutine("\n vec2 offsetToCoords(int offset, int width, int height) {\n int t = offset / width;\n int s = offset - t*width;\n vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height);\n return coords;\n }\n ")}}coordsToOffset(){return{coordsToOffset:new i.GlslLibRoutine("\n int coordsToOffset(vec2 coords, int width, int height) {\n float s = coords.s * float(width);\n float t = coords.t * float(height);\n int offset = int(t) * width + int(s);\n return offset;\n }\n ")}}getOutputSamplingSnippet(){const t=this.context.outputTextureLayout;return t.isPacked?this.getPackedOutputSamplingSnippet(t):this.getUnpackedOutputSamplingSnippet(t)}getPackedOutputSamplingSnippet(t){const e=t.unpackedShape,n=[t.width,t.height],r={},a="getOutputCoords";switch(e.length){case 0:r[a]=this.getOutputScalarCoords();break;case 1:r[a]=this.getOutputPacked1DCoords(e,n);break;case 2:r[a]=this.getOutputPacked2DCoords(e,n);break;case 3:r[a]=this.getOutputPacked3DCoords(e,n);break;default:r[a]=this.getOutputPackedNDCoords(e,n)}const s=`\n void setOutput(vec4 val) {\n ${(0,o.getGlsl)(this.context.glContext.version).output} = val;\n }\n `;return r.floatTextureSetRGBA=new i.GlslLibRoutine(s),r}getUnpackedOutputSamplingSnippet(t){const e=t.unpackedShape,n=[t.width,t.height],r={},a="getOutputCoords";switch(e.length){case 0:r[a]=this.getOutputScalarCoords();break;case 1:r[a]=this.getOutputUnpacked1DCoords(e,n);break;case 2:r[a]=this.getOutputUnpacked2DCoords(e,n);break;case 3:r[a]=this.getOutputUnpacked3DCoords(e,n);break;case 4:r[a]=this.getOutputUnpacked4DCoords(e,n);break;case 5:r[a]=this.getOutputUnpacked5DCoords(e,n);break;case 6:r[a]=this.getOutputUnpacked6DCoords(e,n);break;default:throw new Error(`Unsupported output dimensionality: ${e.length}`)}const s=`\n void setOutput(float val) {\n ${(0,o.getGlsl)(this.context.glContext.version).output} = vec4(val, 0, 0, 0);\n }\n `;return r.floatTextureSetR=new i.GlslLibRoutine(s),r}getOutputScalarCoords(){return new i.GlslLibRoutine("\n int getOutputCoords() {\n return 0;\n }\n ")}getOutputPacked1DCoords(t,e){const n=e;let r="";return 1===n[0]?(r=`\n int getOutputCoords() {\n return 2 * int(TexCoords.y * ${n[1]}.0);\n }\n `,new i.GlslLibRoutine(r)):1===n[1]?(r=`\n int getOutputCoords() {\n return 2 * int(TexCoords.x * ${n[0]}.0);\n }\n `,new i.GlslLibRoutine(r)):(r=`\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${n[0]}, ${n[1]}));\n return 2 * (resTexRC.y * ${n[0]} + resTexRC.x);\n }\n `,new i.GlslLibRoutine(r))}getOutputPacked2DCoords(t,e){let n="";if(r.ArrayUtil.arraysEqual(t,e))return n=`\n ivec2 getOutputCoords() {\n return 2 * ivec2(TexCoords.xy * vec2(${e[0]}, ${e[1]}));\n }\n `,new i.GlslLibRoutine(n);const o=e,a=Math.ceil(t[1]/2);return n=`\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${o[0]}, ${o[1]}));\n\n int index = resTexRC.y * ${o[0]} + resTexRC.x;\n\n // reverse r and c order for packed texture\n int r = imod(index, ${a}) * 2;\n int c = 2 * (index / ${a});\n\n return ivec2(r, c);\n }\n `,new i.GlslLibRoutine(n)}getOutputPacked3DCoords(t,e){const n=[e[0],e[1]],r=Math.ceil(t[2]/2),o=r*Math.ceil(t[1]/2),a=`\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${n[0]}, ${n[1]}));\n int index = resTexRC.y * ${n[0]} + resTexRC.x;\n\n int b = index / ${o};\n index -= b * ${o};\n\n // reverse r and c order for packed texture\n int r = imod(index, ${r}) * 2;\n int c = 2 * (index / ${r});\n\n return ivec3(b, r, c);\n }\n `;return new i.GlslLibRoutine(a)}getOutputPackedNDCoords(t,e){const n=[e[0],e[1]],r=Math.ceil(t[t.length-1]/2),o=r*Math.ceil(t[t.length-2]/2);let a=o,s="",u="b, r, c";for(let e=2;e=0;--e)o[e]=o[e+1]*t[e+1];const a=["r","c","d"],s=o.map(((t,e)=>`int ${a[e]} = index / ${t}; ${e===o.length-1?`int ${a[e+1]} = index - ${a[e]} * ${t}`:`index -= ${a[e]} * ${t}`};`)).join("");return n=`\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${e[0]}, ${e[1]}));\n int index = resTexRC.y * ${e[0]} + resTexRC.x;\n ${s}\n return ivec3(r, c, d);\n }\n `,new i.GlslLibRoutine(n)}getOutputUnpacked4DCoords(t,e){let n="";const r=t.length;let o=null;r<2&&(o=[]),o=new Array(r-1),o[r-2]=t[r-1];for(let e=r-3;e>=0;--e)o[e]=o[e+1]*t[e+1];const a=["r","c","d","d2"],s=o.map(((t,e)=>`int ${a[e]} = index / ${t}; ${e===o.length-1?`int ${a[e+1]} = index - ${a[e]} * ${t}`:`index -= ${a[e]} * ${t}`};`)).join("");return n=`\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${e[0]}, ${e[1]}));\n int index = resTexRC.y * ${e[0]} + resTexRC.x;\n ${s}\n return ivec4(r, c, d, d2);\n }\n `,new i.GlslLibRoutine(n)}getOutputUnpacked5DCoords(t,e){let n="";const r=t.length;let o=null;r<2&&(o=[]),o=new Array(r-1),o[r-2]=t[r-1];for(let e=r-3;e>=0;--e)o[e]=o[e+1]*t[e+1];const a=["r","c","d","d2","d3"],s=o.map(((t,e)=>`int ${a[e]} = index / ${t}; ${e===o.length-1?`int ${a[e+1]} = index - ${a[e]} * ${t}`:`index -= ${a[e]} * ${t}`};`)).join("");return n=`\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${e[0]}, ${e[1]}));\n int index = resTexRC.y * ${e[0]} + resTexRC.x;\n ${s}\n return ivec5(r, c, d, d2, d3);\n }\n `,new i.GlslLibRoutine(n)}getOutputUnpacked6DCoords(t,e){let n="";const r=t.length;let o=null;r<2&&(o=[]),o=new Array(r-1),o[r-2]=t[r-1];for(let e=r-3;e>=0;--e)o[e]=o[e+1]*t[e+1];const a=["r","c","d","d2","d3","d4"],s=o.map(((t,e)=>`int ${a[e]} = index / ${t}; ${e===o.length-1?`int ${a[e+1]} = index - ${a[e]} * ${t}`:`index -= ${a[e]} * ${t}`};`)).join("");return n=`\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${e[0]}, ${e[1]}));\n int index = resTexRC.y * ${e[0]} + resTexRC.x;\n ${s}\n return ivec6(r, c, d, d2, d3, d4);\n }\n `,new i.GlslLibRoutine(n)}getCommonUtilFuncs(){const t={};let e="uvFromFlat";t[e]=new i.GlslLibRoutine("\n vec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texC = index / texNumR;\n int texR = index - texC * texNumR;\n // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to\n // v.\n return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC);\n }\n "),e="packedUVfrom1D",t[e]=new i.GlslLibRoutine("\n vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),e="packedUVfrom2D",t[e]=new i.GlslLibRoutine("\n vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),e="packedUVfrom3D",t[e]=new i.GlslLibRoutine("\n vec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),e="sampleTexture";const n=(0,o.getGlsl)(this.context.glContext.version);return t[e]=new i.GlslLibRoutine(`\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return ${n.texture2D}(textureSampler, uv).r;\n }`),t}getInputsSamplingSnippets(){const t={},e=this.context.outputTextureLayout;return this.context.programInfo.inputNames.forEach(((n,r)=>{const i=this.context.inputTextureLayouts[r],o=(0,s.generateShaderFuncNameFromInputSamplerName)(n);i.isPacked?t[o]=this.getPackedSamplerFromInput(o,n,i):t[o]=this.getUnpackedSamplerFromInput(o,n,i);const a=(0,s.generateShaderFuncNameFromInputSamplerNameAtOutCoords)(n);i.unpackedShape.length<=e.unpackedShape.length&&(i.isPacked?t[a]=this.getPackedSamplerAtOutputCoords(a,i,e,n):t[a]=this.getUnpackedSamplerAtOutputCoords(a,i,e,n))})),t}getPackedSamplerAtOutputCoords(t,e,n,o){const a=e.unpackedShape,u=n.unpackedShape,c=o,l=(0,s.generateShaderFuncNameFromInputSamplerName)(c),p=a.length,f=u.length,d=r.BroadcastUtil.getBroadcastDims(a,u),h=(0,s.getCoordsDataType)(f),g=f-p;let b;const m=(0,s.getGlChannels)();b=0===p?"":f<2&&d.length>=1?"coords = 0;":d.map((t=>`coords.${m[t+g]} = 0;`)).join("\n");let y="";y=f<2&&p>0?"coords":a.map(((t,e)=>`coords.${m[e+g]}`)).join(", ");let _="return outputValue;";const v=1===r.ShapeUtil.size(a),w=1===r.ShapeUtil.size(u);if(1!==p||v||w){if(v&&!w)_=1===f?"\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n ":"\n return vec4(outputValue.x);\n ";else if(d.length){const t=p-2,e=p-1;d.indexOf(t)>-1&&d.indexOf(e)>-1?_="return vec4(outputValue.x);":d.indexOf(t)>-1?_="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":d.indexOf(e)>-1&&(_="return vec4(outputValue.xx, outputValue.zz);")}}else _="\n return vec4(outputValue.xy, outputValue.xy);\n ";const x=`\n vec4 ${t}() {\n ${h} coords = getOutputCoords();\n \n int lastDim = coords.${m[f-1]};\n coords.${m[f-1]} = coords.${m[f-2]};\n coords.${m[f-2]} = lastDim;\n \n ${b}\n vec4 outputValue = ${l}(${y});\n ${_}\n }\n `;return new i.GlslLibRoutine(x,["coordinates.getOutputCoords"])}getUnpackedSamplerAtOutputCoords(t,e,n,o){const a=[n.width,n.height],u=[e.width,e.height],c=e.unpackedShape.length,l=n.unpackedShape.length,p=e.unpackedShape,f=n.unpackedShape,d=(0,s.generateShaderFuncNameFromInputSamplerName)(o);if(c===l&&r.ArrayUtil.arraysEqual(u,a)){const e=`\n float ${t}() {\n return sampleTexture(${o}, TexCoords);\n }\n `;return new i.GlslLibRoutine(e,["coordinates.sampleTexture"])}const h=(0,s.getCoordsDataType)(l),g=r.BroadcastUtil.getBroadcastDims(p,f),b=l-c;let m;const y=(0,s.getGlChannels)();m=0===c?"":l<2&&g.length>=1?"coords = 0;":g.map((t=>`coords.${y[t+b]} = 0;`)).join("\n");let _="";_=l<2&&c>0?"coords":e.unpackedShape.map(((t,e)=>`coords.${y[e+b]}`)).join(", ");const v=`\n float ${t}() {\n ${h} coords = getOutputCoords();\n ${m}\n return ${d}(${_});\n }\n `;return new i.GlslLibRoutine(v,["coordinates.getOutputCoords"])}getPackedSamplerFromInput(t,e,n){switch(n.unpackedShape.length){case 0:return this.getPackedSamplerScalar(t,e);case 1:return this.getPackedSampler1D(t,e,n);case 2:return this.getPackedSampler2D(t,e,n);case 3:return this.getPackedSampler3D(t,e,n);default:return this.getPackedSamplerND(t,e,n)}}getUnpackedSamplerFromInput(t,e,n){const r=n.unpackedShape;switch(r.length){case 0:return this.getUnpackedSamplerScalar(t,e,n);case 1:return this.getUnpackedSampler1D(t,e,n);case 2:return this.getUnpackedSampler2D(t,e,n);case 3:return this.getUnpackedSampler3D(t,e,n);case 4:return this.getUnpackedSampler4D(t,e,n);case 5:return this.getUnpackedSampler5D(t,e,n);case 6:return this.getUnpackedSampler6D(t,e,n);default:throw new Error(`Unsupported dimension ${r.length}-D`)}}getPackedSamplerScalar(t,e){const n=`\n vec4 ${t}() {\n return ${(0,o.getGlsl)(this.context.glContext.version).texture2D}(${e}, halfCR);\n }\n `;return new i.GlslLibRoutine(n)}getPackedSampler1D(t,e,n){const r=[n.width,n.height],a=[r[1],r[0]],s=(0,o.getGlsl)(this.context.glContext.version),u=`vec4 ${t}(int index) {\n vec2 uv = packedUVfrom1D(\n ${a[0]}, ${a[1]}, index);\n return ${s.texture2D}(${e}, uv);\n }`;return new i.GlslLibRoutine(u,["coordinates.packedUVfrom1D"])}getPackedSampler2D(t,e,n){const a=n.unpackedShape,s=[n.width,n.height],u=(0,o.getGlsl)(this.context.glContext.version),c=s[0],l=s[1];if(null!=s&&r.ArrayUtil.arraysEqual(a,s)){const n=`vec4 ${t}(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(${l}.0, ${c}.0);\n return ${u.texture2D}(${e}, uv);\n }`;return new i.GlslLibRoutine(n)}const p=s,f=Math.ceil(a[1]/2),d=`vec4 ${t}(int row, int col) {\n vec2 uv = packedUVfrom2D(${p[1]}, ${p[0]}, ${f}, row, col);\n return ${u.texture2D}(${e}, uv);\n }`;return new i.GlslLibRoutine(d,["coordinates.packedUVfrom2D"])}getPackedSampler3D(t,e,n){const r=n.unpackedShape,a=[n.width,n.height],u=[a[0],a[1]],c=(0,o.getGlsl)(this.context.glContext.version);if(1===r[0]){const o=r.slice(1),a=[1,2],u=(0,s.squeezeInputShape)(r,o),c=["b","row","col"],l=JSON.parse(JSON.stringify(n));l.unpackedShape=u;const p=this.getPackedSamplerFromInput(t,e,l),f=`${p.routineBody}\n vec4 ${t}(int b, int row, int col) {\n return ${t}(${(0,s.getSqueezedParams)(c,a)});\n } `;return new i.GlslLibRoutine(f,p.dependencies)}const l=u[0],p=u[1],f=Math.ceil(r[2]/2),d=`vec4 ${t}(int b, int row, int col) {\n vec2 uv = packedUVfrom3D(\n ${p}, ${l}, ${f*Math.ceil(r[1]/2)}, ${f}, b, row, col);\n return ${c.texture2D}(${e}, uv);}`;return new i.GlslLibRoutine(d,["coordinates.packedUVfrom3D"])}getPackedSamplerND(t,e,n){const r=n.unpackedShape,a=r.length,s=[n.width,n.height],u=(0,o.getGlsl)(this.context.glContext.version),c=[s[0],s[1]],l=c[1],p=c[0],f=Math.ceil(r[a-1]/2);let d=f*Math.ceil(r[a-2]/2),h="int b, int row, int col",g=`b * ${d} + (row / 2) * ${f} + (col / 2)`;for(let t=2;t{const r=this.context.inputTextureLayouts[n],o=(r.unpackedShape.length>0?r.unpackedShape:r.shape).length;let a=`_${e}`;t[a]=new i.GlslLibRoutine(this.getValueFromSingle(e,o,r.width,r.height,!1),[`shapeUtils.indicesToOffset${a}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"]),a+="_T",t[a]=new i.GlslLibRoutine(this.getValueFromSingle(e,o,r.width,r.height,!0),[`shapeUtils.indicesToOffset${a}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"])})),t}getValueFromSingle(t,e,n,r,i){let a=`_${t}`;return i&&(a+="_T"),`\n float ${a}(int m[${e}]) {\n int offset = indicesToOffset${a}(m);\n vec2 coords = offsetToCoords(offset, ${n}, ${r});\n float value = getColorAsFloat(${(0,o.getGlsl)(this.context.glContext.version).texture2D}(${t}, coords));\n return value;\n }\n `}getPackedValueFrom(t,e,n,r,i){let a=`_${t}_Pack`;return i&&(a+="_T"),`\n vec4 ${a}(int m[${e}]) {\n int offset = indicesToOffset_${t}(m);\n vec2 coords = offsetToCoords(offset, ${n}, ${r});\n return ${(0,o.getGlsl)(this.context.glContext.version).texture2D}(${t}, coords);\n }\n `}}e.CoordsGlslLib=u},8520:(t,e)=>{"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.TopologicalSortGlslRoutines=e.GlslLibRoutineNode=e.GlslLibRoutine=e.GlslLib=e.GlslContext=e.FunctionType=void 0,(n=e.FunctionType||(e.FunctionType={}))[n.ValueBased=0]="ValueBased",n[n.Positional=1]="Positional",e.GlslContext=class{constructor(t,e,n,r){this.glContext=t,this.programInfo=e,this.inputTextureLayouts=n,this.outputTextureLayout=r}},e.GlslLib=class{constructor(t){this.context=t}},e.GlslLibRoutine=class{constructor(t,e){this.routineBody=t,this.dependencies=e}},e.GlslLibRoutineNode=class{constructor(t,e,n){this.name=t,this.dependencies=n||[],e&&(this.routineBody=e)}addDependency(t){t&&this.dependencies.push(t)}},e.TopologicalSortGlslRoutines=class{static returnOrderedNodes(t){if(!t||0===t.length)return[];if(1===t.length)return t;const e=new Set,n=new Set,r=new Array;return this.createOrderedNodes(t,e,n,r),r}static createOrderedNodes(t,e,n,r){for(let i=0;i0)for(let t=0;t{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.EncodingGlslLib=void 0;const r=n(8520);class i extends r.GlslLib{constructor(t){super(t)}getFunctions(){return Object.assign(Object.assign({},this.encodeFloat32()),this.decodeFloat32())}getCustomTypes(){return{}}encodeFloat32(){return{encode:new r.GlslLibRoutine("highp vec4 encode(highp float f) {\n return vec4(f, 0.0, 0.0, 0.0);\n }\n ")}}decodeFloat32(){return{decode:new r.GlslLibRoutine("highp float decode(highp vec4 rgba) {\n return rgba.r;\n }\n ")}}encodeUint8(){const t=i.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{encode:new r.GlslLibRoutine(`\n highp vec4 encode(highp float f) {\n highp float F = abs(f);\n highp float Sign = step(0.0,-f);\n highp float Exponent = floor(log2(F));\n highp float Mantissa = (exp2(- Exponent) * F);\n Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa));\n highp vec4 rgba;\n rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0));\n rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0);\n rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0)));\n rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0)));\n ${t}\n rgba = rgba / 255.0; // values need to be normalized to [0,1]\n return rgba;\n }\n `)}}decodeUint8(){const t=i.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{decode:new r.GlslLibRoutine(`\n highp float decode(highp vec4 rgba) {\n rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255]\n ${t}\n highp float Sign = 1.0 - step(128.0,rgba[0])*2.0;\n highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0;\n highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000);\n highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));\n return Result;\n }\n `)}}static isLittleEndian(){const t=new ArrayBuffer(4),e=new Uint32Array(t),n=new Uint8Array(t);if(e[0]=3735928559,239===n[0])return!0;if(222===n[0])return!1;throw new Error("unknown endianness")}}e.EncodingGlslLib=i},9894:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.FragColorGlslLib=void 0;const r=n(8520),i=n(5060);class o extends r.GlslLib{constructor(t){super(t)}getFunctions(){return Object.assign(Object.assign({},this.setFragColor()),this.getColorAsFloat())}getCustomTypes(){return{}}setFragColor(){const t=(0,i.getGlsl)(this.context.glContext.version);return{setFragColor:new r.GlslLibRoutine(`\n void setFragColor(float value) {\n ${t.output} = encode(value);\n }\n `,["encoding.encode"])}}getColorAsFloat(){return{getColorAsFloat:new r.GlslLibRoutine("\n float getColorAsFloat(vec4 color) {\n return decode(color);\n }\n ",["encoding.decode"])}}}e.FragColorGlslLib=o},2848:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.replaceInlines=void 0;const n=/@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm;e.replaceInlines=function(t){const e={};let r;for(;null!==(r=n.exec(t));){const t=r[3].split(",").map((t=>{const e=t.trim().split(" ");return e&&2===e.length?{type:e[0],name:e[1]}:null})).filter((t=>null!==t));e[r[2]]={params:t,body:r[4]}}for(const n in e){const i="(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;".replace("__FUNC__",n),o=new RegExp(i,"gm");for(;null!==(r=o.exec(t));){const i=r[1],o=r[2],a=r[3].split(","),s=i?`${i} ${o};`:"";let u=e[n].body,c="";e[n].params.forEach(((t,e)=>{t&&(c+=`${t.type} ${t.name} = ${a[e]};\n`)})),u=`${c}\n ${u}`,u=u.replace("return",`${o} = `);const l=`\n ${s}\n {\n ${u}\n }\n `;t=t.replace(r[0],l)}}return t.replace(n,"")}},8879:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.GlslPreprocessor=void 0;const r=n(8520),i=n(2848),o=n(5483),a=n(5060);e.GlslPreprocessor=class{constructor(t,e,n,i){this.libs={},this.glslLibRoutineDependencyGraph={},this.context=new r.GlslContext(t,e,n,i),Object.keys(o.glslRegistry).forEach((t=>{const e=new o.glslRegistry[t](this.context);this.libs[t]=e}));const a=this.glslLibRoutineDependencyGraph;for(const t in this.libs){const e=this.libs[t].getFunctions();for(const n in e){const i=t+"."+n;let o;a[i]?(o=a[i],o.routineBody=e[n].routineBody):(o=new r.GlslLibRoutineNode(i,e[n].routineBody),a[i]=o);const s=e[n].dependencies;if(s)for(let t=0;t{const r=n.split(".")[1];-1!==t.indexOf(r)&&e.push(this.glslLibRoutineDependencyGraph[n])})),r.TopologicalSortGlslRoutines.returnOrderedNodes(e)}getUniforms(t,e){const n=[];if(t)for(const e of t)n.push(`uniform sampler2D ${e};`);if(e)for(const t of e)n.push(`uniform ${t.type} ${t.name}${t.arrayLength?`[${t.arrayLength}]`:""};`);return n.join("\n")}}},5483:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.glslRegistry=void 0;const r=n(5107),i=n(7341),o=n(9894),a=n(2655),s=n(3891);e.glslRegistry={encoding:i.EncodingGlslLib,fragcolor:o.FragColorGlslLib,vec:s.VecGlslLib,shapeUtils:a.ShapeUtilsGlslLib,coordinates:r.CoordsGlslLib}},2655:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ShapeUtilsGlslLib=void 0;const r=n(8520);class i extends r.GlslLib{constructor(t){super(t)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.bcastIndex()),this.bcastMatmulIndex()),this.offsetToIndices()),this.indicesToOffset()),this.incrementIndices())}getCustomTypes(){return{}}bcastIndex(){const t=this.context.outputTextureLayout.shape.length,e={};return this.context.programInfo.inputNames.forEach(((n,i)=>{const o=this.context.inputTextureLayouts[i].unpackedShape;if(o.length<=t){const i=o.length,a=t-i,s=`bcastIndices_${n}`;let u="";for(let t=0;t{const o=this.context.inputTextureLayouts[i].shape;if(!(o.length<2||o.length>t)){const i=o.length,a=t-i,s=`bcastMatmulIndices_${n}`;let u="";for(let t=0;t{const o=this.context.inputTextureLayouts[n].shape,a=this.context.inputTextureLayouts[n].strides,s=o.length;let u=`indicesToOffset_${e}`;t[u]=new r.GlslLibRoutine(i.indexToOffsetSingle(u,s,a)),u=`indicesToOffset_${e}_T`,t[u]=new r.GlslLibRoutine(i.indexToOffsetSingle(u,s,a.slice().reverse()))})),t}static indexToOffsetSingle(t,e,n){let r="";for(let t=e-1;t>=0;--t)r+=`\n offset += indices[${t}] * ${n[t]};\n `;return`\n int ${t}(int indices[${e}]) {\n int offset = 0;\n ${r}\n return offset;\n }\n `}offsetToIndices(){const t={};return this.context.programInfo.inputNames.forEach(((e,n)=>{const o=this.context.inputTextureLayouts[n].shape,a=this.context.inputTextureLayouts[n].strides,s=o.length;let u=`offsetToIndices_${e}`;t[u]=new r.GlslLibRoutine(i.offsetToIndicesSingle(u,s,a)),u=`offsetToIndices_${e}_T`,t[u]=new r.GlslLibRoutine(i.offsetToIndicesSingle(u,s,a.slice().reverse()))})),t}static offsetToIndicesSingle(t,e,n){const r=[];for(let t=0;t{const i=this.context.inputTextureLayouts[n].shape,o=i.length,a=`incrementIndices_${e}`;let s="";for(let t=0;t= 0; --i) {\n if(i > axis) continue;\n indices[i] += 1;\n if(indices[i] < shape[i]) {\n break;\n }\n indices[i] = 0;\n }\n }\n `;t[a]=new r.GlslLibRoutine(u)})),t}}e.ShapeUtilsGlslLib=i},5060:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getDefaultFragShaderMain=e.getFragShaderPreamble=e.getVertexShaderSource=e.getGlsl=void 0;const n={version:"",attribute:"attribute",varyingVertex:"varying",varyingFrag:"varying",texture2D:"texture2D",output:"gl_FragColor",outputDeclaration:""},r={version:"#version 300 es",attribute:"in",varyingVertex:"out",varyingFrag:"in",texture2D:"texture",output:"outputColor",outputDeclaration:"out vec4 outputColor;"};function i(t){return 1===t?n:r}e.getGlsl=i,e.getVertexShaderSource=function(t){const e=i(t);return`${e.version}\n precision highp float;\n ${e.attribute} vec3 position;\n ${e.attribute} vec2 textureCoord;\n\n ${e.varyingVertex} vec2 TexCoords;\n\n void main()\n {\n gl_Position = vec4(position, 1.0);\n TexCoords = textureCoord;\n }`},e.getFragShaderPreamble=function(t){const e=i(t);return`${e.version}\n precision highp float;\n precision highp int;\n precision highp sampler2D;\n ${e.varyingFrag} vec2 TexCoords;\n ${e.outputDeclaration}\n const vec2 halfCR = vec2(0.5, 0.5);\n\n // Custom vector types to handle higher dimenalities.\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n `},e.getDefaultFragShaderMain=function(t,e){return`\n void main() {\n int indices[${e}];\n toVec(TexCoords, indices);\n vec4 result = vec4(process(indices));\n ${i(t).output} = result;\n }\n `}},3891:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.VecGlslLib=void 0;const r=n(8520);class i extends r.GlslLib{constructor(t){super(t)}getCustomTypes(){return{}}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign({},this.binaryVecFunctions()),this.copyVec()),this.setVecItem()),this.getVecItem())}binaryVecFunctions(){const t=this.context.outputTextureLayout.shape.length,e={add:"+=",sub:"-=",mul:"*=",div:"/="},n={};for(const i in e){const o=`${i}Vec`;let a="";for(let n=0;n{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLInferenceHandler=void 0;const r=n(6231),i=n(9162),o=n(2517),a=n(2403),s=n(7019),u=n(8710),c=n(5611),l=n(4057),p=n(2039);e.WebGLInferenceHandler=class{constructor(t){this.session=t,this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map}calculateTextureWidthAndHeight(t,e){return(0,l.calculateTextureWidthAndHeight)(this.session.layoutStrategy,t,e)}executeProgram(t,e){if(e.length{const n=e.map((t=>`${t.unpackedShape.join(",")};${t.width}x${t.height}`)).join("_");let r=t.name;return t.cacheHint&&(r+="["+t.cacheHint+"]"),r+=":"+n,r})(t,n);let i=this.session.programManager.getArtifact(r);const o=i?i.programInfo:"function"==typeof t.get?t.get():t,a=(0,l.createTextureLayoutFromTextureType)(this.session.layoutStrategy,o.output.dims,o.output.textureType),s=this.createTextureData(a,o.output.type);return i||(i=this.session.programManager.build(o,n,s),this.session.programManager.setArtifact(r,i)),this.runProgram(i,n,s),s}run(t,e){return this.executeProgram(t,e).tensor}runProgram(t,e,n){for(let n=0;nthis.readTexture(a)),(async t=>this.readTextureAsync(a)),void 0,o),texture:n});return this.setTextureData(a.tensor.dataId,a,t.isPacked),a}getTextureData(t,e=!1){return this.session.isInitializer(t)?this.session.getTextureData(t,e):e?this.packedTextureDataCache.get(t):this.unpackedTextureDataCache.get(t)}setTextureData(t,e,n=!1){this.session.isInitializer(t)?this.session.setTextureData(t,e,n):(n?this.packedTextureDataCache:this.unpackedTextureDataCache).set(t,e)}isTextureLayoutCached(t,e=!1){return!!this.getTextureData(t.dataId,e)}dispose(){this.session.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach((t=>this.session.textureManager.releaseTexture(t))),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach((t=>this.session.textureManager.releaseTexture(t))),this.unpackedTextureDataCache=new Map}readTexture(t){return t.isPacked?this.readTexture(this.unpack(t)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTexture(t,t.tensor.type,t.channels):this.session.textureManager.readUint8TextureAsFloat((0,u.encodeAsUint8)(this,t))}async readTextureAsync(t){return t.isPacked?this.readTextureAsync(this.unpack(t)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTextureAsync(t,t.tensor.type,t.channels):this.session.textureManager.readUint8TextureAsFloat((0,u.encodeAsUint8)(this,t))}pack(t){return this.executeProgram((0,a.createPackProgramInfoLoader)(this,t.tensor),[t.tensor])}unpack(t){return this.executeProgram((0,c.createUnpackProgramInfoLoader)(this,t.tensor),[t.tensor])}}},1640:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.WEBGL_OP_RESOLVE_RULES=void 0;const a=n(2898),s=o(n(7839)),u=n(4196),c=n(2069),l=n(8138),p=n(9663),f=n(5193),d=n(7992),h=n(1253),g=n(4776),b=n(6572),m=n(3346),y=n(5623),_=n(2870),v=n(2143),w=n(4939),x=n(718),T=n(2268),S=n(8117),O=n(2278),A=n(5524),E=n(5975),I=n(3933),P=n(6558),D=n(5723),$=n(3738),k=o(n(4909)),C=n(8428),F=n(9793);e.WEBGL_OP_RESOLVE_RULES=[["Abs","","6+",k.abs],["Acos","","7+",k.acos],["Add","","7+",s.add],["And","","7+",s.and],["Asin","","7+",k.asin],["Atan","","7+",k.atan],["AveragePool","","7+",v.averagePool,v.parseAveragePoolAttributes],["BatchNormalization","","7+",a.batchNormalization,a.parseBatchNormalizationAttributes],["Cast","","6+",u.cast,u.parseCastAttributes],["Ceil","","6+",k.ceil],["Clip","","6-10",k.clip,k.parseClipAttributes],["Clip","","11+",k.clipV11],["Concat","","4+",c.concat,c.parseConcatAttributes],["Conv","","1+",l.conv,l.parseConvAttributes],["ConvTranspose","","1+",p.convTranspose,p.parseConvTransposeAttributes],["Cos","","7+",k.cos],["Div","","7+",s.div],["Dropout","","7+",k.identity],["DepthToSpace","","1+",f.depthToSpace,f.parseDepthToSpaceAttributes],["Equal","","7+",s.equal],["Elu","","6+",k.elu,k.parseEluAttributes],["Exp","","6+",k.exp],["Flatten","","1+",d.flatten,d.parseFlattenAttributes],["Floor","","6+",k.floor],["FusedConv","com.microsoft","1+",l.conv,l.parseConvAttributes],["Gather","","1+",h.gather,h.parseGatherAttributes],["Gemm","","7-10",g.gemm,g.parseGemmAttributesV7],["Gemm","","11+",g.gemm,g.parseGemmAttributesV11],["GlobalAveragePool","","1+",v.globalAveragePool,v.parseGlobalAveragePoolAttributes],["GlobalMaxPool","","1+",v.globalMaxPool],["Greater","","7+",s.greater],["Identity","","1+",k.identity],["ImageScaler","","1+",b.imageScaler,b.parseImageScalerAttributes],["InstanceNormalization","","6+",m.instanceNormalization,m.parseInstanceNormalizationAttributes],["LeakyRelu","","6+",k.leakyRelu,k.parseLeakyReluAttributes],["Less","","7+",s.less],["Log","","6+",k.log],["MatMul","","1+",y.matMul,y.parseMatMulAttributes],["MaxPool","","1+",v.maxPool,v.parseMaxPoolAttributes],["Mul","","7+",s.mul],["Neg","","6+",k.neg],["Not","","1+",k.not],["Or","","7+",s.or],["Pad","","2-10",_.padV2,_.parsePadAttributesV2],["Pad","","11+",_.padV11,_.parsePadAttributesV11],["Pow","","7+",s.pow],["PRelu","","7+",s.pRelu],["ReduceLogSum","","1+",w.reduceLogSum,w.parseReduceAttributes],["ReduceMax","","1+",w.reduceMax,w.parseReduceAttributes],["ReduceMean","","1+",w.reduceMean,w.parseReduceAttributes],["ReduceMin","","1+",w.reduceMin,w.parseReduceAttributes],["ReduceProd","","1+",w.reduceProd,w.parseReduceAttributes],["ReduceSum","","1-12",w.reduceSum,w.parseReduceAttributes],["ReduceSumSquare","","1+",w.reduceLogSumSquare,w.parseReduceAttributes],["Relu","","6+",k.relu],["Reshape","","5+",x.reshape],["Resize","","10",T.resize,T.parseResizeAttributesV10],["Resize","","11+",T.resize,T.parseResizeAttributesV11],["Shape","","1+",S.shape],["Sigmoid","","6+",k.sigmoid],["Sin","","7+",k.sin],["Slice","","10+",O.sliceV10],["Slice","","1-9",O.slice,O.parseSliceAttributes],["Softmax","","1-12",A.softmax,A.parseSoftmaxAttributes],["Softmax","","13+",A.softmaxV13,A.parseSoftmaxAttributesV13],["Split","","2-12",E.split,E.parseSplitAttributes],["Sqrt","","6+",k.sqrt],["Squeeze","","1-12",I.squeeze,I.parseSqueezeAttributes],["Squeeze","","13+",I.squeezeV13],["Sub","","7+",s.sub],["Sum","","6+",P.sum],["Tan","","7+",k.tan],["Tanh","","6+",k.tanh],["Tile","","6+",D.tile],["Transpose","","1+",$.transpose,$.parseTransposeAttributes],["Upsample","","7-8",F.upsample,F.parseUpsampleAttributesV7],["Upsample","","9",F.upsample,F.parseUpsampleAttributesV9],["Unsqueeze","","1-12",C.unsqueeze,C.parseUnsqueezeAttributes],["Unsqueeze","","13+",C.unsqueezeV13],["Xor","","7+",s.xor]]},2898:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseBatchNormalizationAttributes=e.batchNormalization=void 0;const r=n(246),i=n(5060),o=n(2039),a={name:"BatchNormalization",inputNames:["A","Scale","B","Mean","Variance"],inputTypes:[o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked]};e.batchNormalization=(t,e,n)=>(u(e),[t.run(Object.assign(Object.assign({},a),{cacheHint:n.cacheKey,get:()=>s(t,e,n)}),e)]),e.parseBatchNormalizationAttributes=t=>{const e=t.attributes.getFloat("epsilon",1e-5),n=t.attributes.getFloat("momentum",.9),i=t.attributes.getInt("spatial",1);return(0,r.createAttributeWithCacheKey)({epsilon:e,momentum:n,spatial:i})};const s=(t,e,n)=>{const r=(0,i.getGlsl)(t.session.backend.glContext.version),s=e[0].dims.length,[u,c]=t.calculateTextureWidthAndHeight(e[1].dims,o.TextureType.unpacked),l=`\n float process(int[${s}] indices) {\n vec2 position = offsetToCoords(indices[1], ${u}, ${c});\n float scale = getColorAsFloat(${r.texture2D}(Scale, position));\n float mean = getColorAsFloat(${r.texture2D}(Mean, position));\n float variance = getColorAsFloat(${r.texture2D}(Variance, position));\n float b = getColorAsFloat(${r.texture2D}(B, position));\n\n return scale * ( (_A(indices) - mean) / sqrt(variance + float(${n.epsilon})) ) + b;\n }`;return Object.assign(Object.assign({},a),{output:{dims:e[0].dims,type:e[0].type,textureType:o.TextureType.unpacked},shaderSource:l})},u=t=>{if(!t||5!==t.length)throw new Error("BatchNormalization requires 5 inputs.");const e=t[0],n=t[1],r=t[2],i=t[3],o=t[4];if(e.dims.length<3||1!==n.dims.length||1!==r.dims.length||1!==i.dims.length||1!==o.dims.length)throw new Error("invalid input shape.");if(n.dims[0]!==e.dims[1]||r.dims[0]!==e.dims[1]||i.dims[0]!==e.dims[1]||o.dims[0]!==e.dims[1])throw new Error("invalid input shape.");if("float32"!==e.type&&"float64"!==e.type||"float32"!==n.type&&"float64"!==n.type||"float32"!==r.type&&"float64"!==r.type||"float32"!==i.type&&"float64"!==i.type||"float32"!==o.type&&"float64"!==o.type)throw new Error("invalid input tensor types.")}},7839:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.xor=e.sub=e.pRelu=e.pow=e.or=e.mul=e.less=e.greater=e.equal=e.div=e.and=e.add=e.glslPRelu=e.glslPow=e.glslXor=e.glslOr=e.glslAnd=e.glslLess=e.glslGreater=e.glslEqual=e.glslSub=e.glslMul=e.glslDiv=e.glslAdd=void 0;const r=n(2517),i=n(8520),o=n(5060),a=n(2039);function s(){const t="add_";return{body:`\n float ${t}(float a, float b) {\n return a + b;\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return v1 + v2;\n }\n `,name:t,type:i.FunctionType.ValueBased}}function u(){const t="div_";return{body:`\n float ${t}(float a, float b) {\n return a / b;\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return v1 / v2;\n }\n `,name:t,type:i.FunctionType.ValueBased}}function c(){const t="mul_";return{body:`\n float ${t}(float a, float b) {\n return a * b;\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return v1 * v2;\n }\n `,name:t,type:i.FunctionType.ValueBased}}function l(){const t="sub_";return{body:`\n float ${t}(float a, float b) {\n return a - b;\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return v1 - v2;\n }\n `,name:t,type:i.FunctionType.ValueBased}}function p(){const t="equal_";return{body:`\n float ${t}(float a, float b) {\n return float(a == b);\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return vec4(equal(v1, v2));\n }\n `,name:t,type:i.FunctionType.ValueBased}}function f(){const t="greater_";return{body:`\n float ${t}(float a, float b) {\n return float(a > b);\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return vec4( v1.r > v2.r ,\n v1.g > v2.g,\n v1.b > v2.b,\n v1.a > v2.a );\n }\n `,name:t,type:i.FunctionType.ValueBased}}function d(){const t="less_";return{body:`\n float ${t}(float a, float b) {\n return float(a < b);\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return vec4( v1.r < v2.r ,\n v1.g < v2.g,\n v1.b < v2.b,\n v1.a < v2.a );\n }\n `,name:t,type:i.FunctionType.ValueBased}}function h(){const t="and_";return{body:`\n float ${t}(float a, float b) {\n return float( bool(a) && bool(b) );\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n bvec4 b1 = bvec4(v1);\n bvec4 b2 = bvec4(v2);\n return vec4( b1.r && b2.r ,\n b1.g && b2.g,\n b1.b && b2.b,\n b1.a && b2.a );\n }\n `,name:t,type:i.FunctionType.ValueBased}}function g(){const t="or_";return{body:`\n float ${t}(float a, float b) {\n return float( bool(a) || bool(b) );\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n bvec4 b1 = bvec4(v1);\n bvec4 b2 = bvec4(v2);\n return vec4( b1.r || b2.r ,\n b1.g || b2.g,\n b1.b || b2.b,\n b1.a || b2.a );\n }\n `,name:t,type:i.FunctionType.ValueBased}}function b(){const t="xor_";return{body:`\n float ${t}(float a, float b) {\n return float( bool(a) ^^ bool(b) );\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n bvec4 b1 = bvec4(v1);\n bvec4 b2 = bvec4(v2);\n return vec4( b1.r ^^ b2.r ,\n b1.g ^^ b2.g,\n b1.b ^^ b2.b,\n b1.a ^^ b2.a );\n }\n `,name:t,type:i.FunctionType.ValueBased}}function m(){return function(t){const e=`${t}_`;return{body:`\n float ${e}(float a, float b) {\n return ${t}(a, b);\n }\n vec4 ${e}(vec4 v1, vec4 v2) {\n return ${t}(v1, v2);\n }\n `,name:e,type:i.FunctionType.ValueBased}}("pow")}function y(){const t="prelu_";return{body:`\n float ${t}(float a, float b) {\n return a < 0.0 ? a * b: a;\n }\n vec4 ${t}(vec4 v1, vec4 v2) {\n return vec4(\n v1.r < 0.0 ? v1.r * v2.r: v1.r,\n v1.g < 0.0 ? v1.g * v2.g: v1.g,\n v1.b < 0.0 ? v1.b * v2.b: v1.b,\n v1.a < 0.0 ? v1.a * v2.a: v1.a\n );\n }\n `,name:t,type:i.FunctionType.ValueBased}}e.glslAdd=s,e.glslDiv=u,e.glslMul=c,e.glslSub=l,e.glslEqual=p,e.glslGreater=f,e.glslLess=d,e.glslAnd=h,e.glslOr=g,e.glslXor=b,e.glslPow=m,e.glslPRelu=y;const _=(t,e,n,r=e[0].type,i)=>{const o=t.session.pack?a.TextureType.packed:a.TextureType.unpacked;return{name:n.name,inputNames:["A","B"],inputTypes:[o,o],cacheHint:i,get:()=>v(t,e,n,r)}},v=(t,e,n,i=e[0].type)=>{const s=t.session.pack?a.TextureType.packed:a.TextureType.unpacked,u=!r.ShapeUtil.areEqual(e[0].dims,e[1].dims);let c=e[0].dims;const l=t.session.pack;if(u){const a=r.BroadcastUtil.calcShape(e[0].dims,e[1].dims,!1);if(!a)throw new Error("Can't perform binary op on the given tensors");c=a;const u=c.length,p=0!==e[0].dims.length?e[0].dims.length:1,f=0!==e[1].dims.length?e[1].dims.length:1,d=0!==e[0].dims.length?"bcastIndices_A(indices, aindices);":"aindices[0] = 0;",h=0!==e[1].dims.length?"bcastIndices_B(indices, bindices);":"bindices[0] = 0;",g=(0,o.getGlsl)(t.session.backend.glContext.version),b=l?`\n ${n.body}\n void main() {\n vec4 a = getAAtOutCoords();\n vec4 b = getBAtOutCoords();\n vec4 result = ${n.name}(a, b);\n ${g.output} = result;\n }`:`\n ${n.body}\n float process(int indices[${u}]) {\n int aindices[${p}];\n int bindices[${f}];\n ${d}\n ${h}\n return ${n.name}(_A(aindices), _B(bindices));\n }`;return{name:n.name,inputNames:["A","B"],inputTypes:[s,s],output:{dims:c,type:i,textureType:s},shaderSource:b,hasMain:l}}const p=(0,o.getGlsl)(t.session.backend.glContext.version),f=`\n ${n.body}\n void main() {\n vec4 v1 = ${p.texture2D}(A, TexCoords);\n vec4 v2 = ${p.texture2D}(B, TexCoords);\n vec4 result = ${n.name}(v1, v2);\n ${p.output} = result;\n }\n `;return{name:n.name,inputNames:["A","B"],inputTypes:[s,s],output:{dims:e[0].dims,type:i,textureType:s},shaderSource:f,hasMain:!0}};e.add=(t,e)=>[t.run(_(t,e,s()),e)],e.and=(t,e)=>[t.run(_(t,e,h(),"bool"),e)],e.div=(t,e)=>[t.run(_(t,e,u()),e)],e.equal=(t,e)=>[t.run(_(t,e,p(),"bool"),e)],e.greater=(t,e)=>[t.run(_(t,e,f(),"bool"),e)],e.less=(t,e)=>[t.run(_(t,e,d(),"bool"),e)],e.mul=(t,e)=>[t.run(_(t,e,c()),e)],e.or=(t,e)=>[t.run(_(t,e,g(),"bool"),e)],e.pow=(t,e)=>[t.run(_(t,e,m()),e)],e.pRelu=(t,e)=>[t.run(_(t,e,y()),e)],e.sub=(t,e)=>[t.run(_(t,e,l()),e)],e.xor=(t,e)=>[t.run(_(t,e,b(),"bool"),e)]},4196:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseCastAttributes=e.cast=void 0;const r=n(2517);e.cast=(t,e,n)=>(i(e),[t.cast(e[0],n)]),e.parseCastAttributes=t=>r.ProtoUtil.tensorDataTypeFromProto(t.attributes.getInt("to"));const i=t=>{if(!t||1!==t.length)throw new Error("Cast requires 1 input.");if("string"===t[0].type)throw new Error("Invalid input type.")}},1163:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedConcatProgramInfoLoader=void 0;const r=n(5060),i=n(2039),o=n(9390),a=n(2827);e.createPackedConcatProgramInfoLoader=(t,e,n)=>{const u=(c=e.length,l=n.cacheKey,{name:"Concat (packed)",inputNames:Array.from({length:c},((t,e)=>`X${e}`)),inputTypes:Array(c).fill(i.TextureType.packed),cacheHint:l});var c,l;return Object.assign(Object.assign({},u),{get:()=>((t,e,n,u)=>{const c=n[0].dims.slice();if(u>=c.length||u<-1*c.length)throw new Error("axis specified for concat doesn't match input dimensionality");u<0&&(u=c.length+u);const l=c.slice(0);for(let t=1;tt.dims)),b=(0,o.getGlChannels)(p),m=new Array(g.length-1);m[0]=g[0][u];for(let t=1;t= ${m[t-1]}) {\n return getChannel(\n getX${t}(${s(b,y,e)}),\n vec2(${s(_,y,e)}));\n }`}const x=m.length,T=m[m.length-1];w+=`\n return getChannel(\n getX${x}(${s(b,y,T)}),\n vec2(${s(_,y,T)}));`;const S=(0,r.getGlsl)(t.session.backend.glContext.version),O=`\n ${h}\n float getValue(${b.map((t=>"int "+t))}) {\n ${w}\n }\n\n void main() {\n ${d} coords = getOutputCoords();\n int lastDim = coords.${b[p-1]};\n coords.${b[p-1]} = coords.${b[p-2]};\n coords.${b[p-2]} = lastDim;\n\n vec4 result = vec4(getValue(${f}), 0., 0., 0.);\n\n ${f[p-1]} = ${f[p-1]} + 1;\n if (${f[p-1]} < ${l[p-1]}) {\n result.g = getValue(${f});\n }\n\n ${f[p-2]} = ${f[p-2]} + 1;\n if (${f[p-2]} < ${l[p-2]}) {\n result.a = getValue(${f});\n }\n\n ${f[p-1]} = ${f[p-1]} - 1;\n if (${f[p-2]} < ${l[p-2]} &&\n ${f[p-1]} < ${l[p-1]}) {\n result.b = getValue(${f});\n }\n ${S.output} = result;\n }\n `;return Object.assign(Object.assign({},e),{output:{dims:l,type:n[0].type,textureType:i.TextureType.packed},shaderSource:O,hasMain:!0})})(t,u,e,n.axis)})};const s=(t,e,n)=>{const r=t.indexOf(e);return t.map(((t,e)=>e===r?`${t} - ${n}`:t)).join()}},2069:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseConcatAttributes=e.concat=void 0;const r=n(246),i=n(2039),o=n(1163);e.concat=(t,e,n)=>(p(e),t.session.pack&&e[0].dims.length>1?[t.run((0,o.createPackedConcatProgramInfoLoader)(t,e,n),e)]:[t.run(a(t,e,n),e)]);const a=(t,e,n)=>{const r=(o=e.length,a=n.cacheKey,{name:"Concat",inputNames:Array.from({length:o},((t,e)=>`X${e}`)),inputTypes:Array(o).fill(i.TextureType.unpacked),cacheHint:a});var o,a;return Object.assign(Object.assign({},r),{get:()=>((t,e,n,r)=>{const o=n[0].dims.slice();if(r>=o.length||r<-1*o.length)throw new Error("axis specified for concat doesn't match input dimensionality");r<0&&(r=o.length+r);const a=o.slice(0);for(let t=1;t`int getTextureWhereDataResides(int index) {\n ${t.map(((t,e)=>`if(index<${t}) {return ${e};}\n`)).join("")}\n }`,u=t=>s(t),c=(t,e)=>{const n=[`float fetchDataFromCorrectTexture(int textureIndex, int indices[${e}]) {`];for(let e=0;e{const e=["int getSizeInConcatAxisValueFromIndex(int index) {"];for(let n=0;n(0,r.createAttributeWithCacheKey)({axis:t.attributes.getInt("axis")});const p=t=>{if(!t||t.length<1)throw new Error("too few inputs");const e=t[0].type,n=t[0].dims.length;if("string"===e)throw new Error("string tensor is not supported yet");for(const r of t){if(r.type!==e)throw new Error("input tensors should be one type");if(r.dims.length!==n)throw new Error("input tensors should have the same shape")}}},4770:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createUnpackedGroupedConvProgramInfoLoader=void 0;const r=n(6231),i=n(5060),o=n(2039),a=n(8138),s=n(2823);e.createUnpackedGroupedConvProgramInfoLoader=(t,e,n)=>{const u=(c=e.length>2,l=n.cacheKey,{name:"GroupedConv",inputNames:c?["X","W","Bias"]:["X","W"],inputTypes:c?[o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked]:[o.TextureType.unpacked,o.TextureType.unpacked],cacheHint:l});var c,l;return Object.assign(Object.assign({},u),{get:()=>((t,e,n,u)=>{const c=e.length>2?"value += getBias(output_channel);":"",l=e[0].dims.slice(),p=e[1].dims.slice(),f=p[0]/u.group;r.Logger.verbose("GroupedConv",`autpPad:${u.autoPad}, dilations:${u.dilations}, group:${u.group}, kernelShape:${u.kernelShape}, pads:${u.pads}, strides:${u.strides}`);const d=(0,a.calculateOutputShape)(l,p,u.dilations,u.pads,u.strides),h=(0,i.getGlsl)(t.session.backend.glContext.version),{activationFunction:g,applyActivation:b}=(0,s.getActivationSnippet)(u),m=`\n const ivec2 strides = ivec2(${u.strides[0]}, ${u.strides[1]});\n const ivec2 pads = ivec2(${u.pads[0]}, ${u.pads[1]});\n ${g}\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n int output_channel = coords.y;\n ivec2 xRCCorner = coords.zw * strides - pads;\n int group_id = output_channel / ${f};\n\n float value = 0.0;\n for (int wInChannel = 0; wInChannel < ${p[1]}; wInChannel++) {\n int input_channel = group_id * ${p[1]} + wInChannel;\n for (int wHeight = 0; wHeight < ${p[2]}; wHeight++) {\n int xHeight = xRCCorner.x + wHeight * ${u.dilations[0]};\n\n if (xHeight < 0 || xHeight >= ${l[2]}) {\n continue;\n }\n\n for (int wWidth = 0; wWidth < ${p[3]}; wWidth++) {\n int xWidth = xRCCorner.y + wWidth * ${u.dilations[1]};\n if (xWidth < 0 || xWidth >= ${l[3]}) {\n continue;\n }\n\n float xVal = getX(batch, input_channel, xWidth, xHeight);\n float wVal = getW(output_channel, wInChannel, wWidth, wHeight);\n value += xVal*wVal;\n }\n }\n }\n ${c}\n ${b}\n ${h.output} = vec4(value, .0, .0, .0);\n }\n`;return Object.assign(Object.assign({},n),{output:{dims:d,type:e[0].type,textureType:o.TextureType.unpacked},shaderSource:m,hasMain:!0})})(t,e,u,n)})}},1386:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.conv2DPacked=e.conv2DPackedPointwise=void 0;const r=n(8138),i=n(8555),o=n(708);e.conv2DPackedPointwise=(t,e,n)=>{const i=e[0].dims,a=e[1].dims,s=(0,r.calculateOutputShape)(i,a,n.dilations,n.pads,n.strides),u=t.reshapePacked(e[0],[i[1],i[2]*i[3]]),c=t.reshapePacked(e[1],[a[0],a[1]]),l=e.length>2?[c,u,e[2]]:[c,u],p=t.run((0,o.createPackedMatmulProgramInfoLoader)(t,l,n),l);return t.reshapePacked(p,s)},e.conv2DPacked=(t,e,n)=>{const a=e[0].dims,s=e[1].dims,u=(0,r.calculateOutputShape)(a,s,n.dilations,n.pads,n.strides),c=t.run((0,i.createPackedIm2ColProgramInfoLoader)(t,e[0],e[1],u,n),[e[0]]),l=t.reshapePacked(e[1],[s[0],s[1]*s[2]*s[3]]),p=3===e.length?[l,c,e[2]]:[l,c],f=t.run((0,o.createPackedMatmulProgramInfoLoader)(t,p,n),p);return t.reshapePacked(f,u)}},9663:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseConvTransposeAttributes=e.convTranspose=void 0;const r=n(246),i=n(5060),o=n(2039),a=n(2823),s=(t,e,n,r,i,o)=>(t-1)*e+n+(r-1)*i+1-o,u=(t,e,n,r,i)=>{const o=Math.floor(t/2);"SAME_UPPER"===e?(n[r]=o,n[i]=t-o):"SAME_LOWER"===e&&(n[r]=t-o,n[i]=o)};e.convTranspose=(t,e,n)=>(f(e,n),c(t,e,n));const c=(t,e,n)=>{const r=p(n,e);return[l(t,e,r)]},l=(t,e,n)=>t.run(((t,e,n)=>{const r=(s=e.length>2,u=n.cacheKey,{name:"ConvTranspose",inputNames:s?["X","W","B"]:["X","W"],inputTypes:s?[o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked]:[o.TextureType.unpacked,o.TextureType.unpacked],cacheHint:u});var s,u;return Object.assign(Object.assign({},r),{get:()=>((t,e,n,r)=>{const s=e.length>2?"getB(output_channel)":"0.0",u=e[0].dims,c=e[1].dims,l=c[1],p=c[0]/r.group,f=[e[0].dims[0],e[1].dims[1]*r.group,...r.outputShape],d=(0,i.getGlsl)(t.session.backend.glContext.version),{activationFunction:h,applyActivation:g}=(0,a.getActivationSnippet)(r),b=`\n const ivec2 strides = ivec2(${r.strides[0]}, ${r.strides[1]});\n const ivec2 pads = ivec2(${r.pads[0]}, ${r.pads[1]});\n ${h}\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n int output_channel = coords.y;\n\n ivec2 loc = coords.zw + pads;\n\n int group_id = output_channel / ${l};\n int wOutChannel = output_channel - group_id * ${l};\n\n float value = ${s};\n for (int inChannelOffset = 0; inChannelOffset < ${p}; inChannelOffset++) {\n int input_channel = group_id * ${p} + inChannelOffset;\n for (int wWOff = 0; wWOff < ${c[2]}; wWOff++) {\n for (int wHOff = 0; wHOff < ${c[3]}; wHOff++) {\n ivec2 wOff = ivec2(wWOff * ${r.dilations[0]}, wHOff * ${r.dilations[1]});\n ivec2 wLoc = loc - wOff;\n ivec2 wLocIn = wLoc / strides;\n if (\n wLocIn * strides == wLoc &&\n wLocIn.x >= 0 && wLocIn.x < ${u[2]} &&\n wLocIn.y >= 0 && wLocIn.y < ${u[3]}\n ) {\n float xVal = getX(batch, input_channel, wLocIn.y, wLocIn.x);\n float wVal = getW(input_channel, wOutChannel, wHOff, wWOff);\n value += xVal * wVal;\n }\n }\n }\n }\n ${g}\n ${d.output} = vec4(value, .0, .0, .0);\n }\n`;return Object.assign(Object.assign({},n),{output:{dims:f,type:e[0].type,textureType:o.TextureType.unpacked},shaderSource:b,hasMain:!0})})(t,e,r,n)})})(t,e,n),e),p=(t,e)=>{const n=t.kernelShape.slice();if(0===t.kernelShape.length)for(let t=2;t{const l=t.length-2,p=0===c.length;for(let f=0;f{const e=t.attributes,n=(0,a.parseInternalActivationAttributes)(e),i=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),s=e.getInt("group",1),u=e.getInts("kernel_shape",[]),c=e.getInts("output_padding",[0,0]),l=e.getInts("output_shape",[]),p=e.getInts("pads",[0,0,0,0]),f=e.getInts("strides",[1,1]);return(0,r.createAttributeWithCacheKey)(Object.assign({autoPad:i,dilations:o,group:s,kernelShape:u,outputPadding:c,outputShape:l,pads:p,strides:f},n))};const f=(t,e)=>{if(!t||2!==t.length&&3!==t.length)throw new Error("Conv requires 2 or 3 inputs");if(4!==t[0].dims.length||4!==t[1].dims.length)throw new Error("currently only support 2-dimensional conv");if(t[0].dims[1]!==t[1].dims[0])throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");const n=t[1].dims[1]*e.group;if(3===t.length&&(1!==t[2].dims.length||t[2].dims[0]!==n))throw new Error("invalid bias");const r=t[0].dims.length-2;if(e.dilations.length!==r)throw new Error(`dilations should be ${r}D`);if(e.strides.length!==r)throw new Error(`strides should be ${r}D`);if(e.pads.length!==2*r)throw new Error(`pads should be ${2*r}D`);if(e.outputPadding.length!==r)throw new Error(`output_padding should be ${r}D`);if(0!==e.kernelShape.length&&e.kernelShape.length!==t[1].dims.length-2)throw new Error("invalid kernel shape");if(0!==e.outputShape.length&&e.outputShape.length!==t[0].dims.length-2)throw new Error("invalid output shape");if("float32"!==t[0].type||"float32"!==t[1].type)throw new Error("ConvTranspose input(X,W) should be float tensor");if(3===t.length&&"float32"!==t[2].type)throw new Error("ConvTranspose input(bias) should be float tensor")}},8138:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseConvAttributes=e.conv=e.calculateOutputShape=void 0;const r=n(246),i=n(2517),o=n(4770),a=n(1386),s=n(9828),u=n(2823),c=n(3248),l=n(5623);e.calculateOutputShape=(t,e,n,r,i)=>{const o=t[0],a=t.slice(2),s=a.length,u=e[0],c=e.slice(2).map(((t,e)=>t+(t-1)*(n[e]-1))),l=a.map(((t,e)=>t+r[e]+r[e+s])).map(((t,e)=>Math.floor((t-c[e]+i[e])/i[e])));return[o,u].concat(...l)},e.conv=(t,e,n)=>(g(e,n),p(t,e,n));const p=(t,e,n)=>{const r=h(n,e),i=t.session.pack,s=1===r.kernelShape[0]&&1===r.kernelShape[1];return r.group>1?[t.run((0,o.createUnpackedGroupedConvProgramInfoLoader)(t,e,r),e)]:s&&i?[f(t,e,r)]:i&&4===e[0].dims.length&&1===e[0].dims[0]&&!s?[(0,a.conv2DPacked)(t,e,r)]:[d(t,e,r)]},f=(t,n,r)=>{const i=n[0].dims,o=n[1].dims,a=(0,e.calculateOutputShape)(i,o,r.dilations,r.pads,r.strides),s=t.reshapeUnpacked(n[0],[i[1],i[2]*i[3]]),u=t.reshapeUnpacked(n[1],[o[0],o[1]]),c=n.length>2?[u,s,n[2]]:[u,s],p=t.run((0,l.createMatmulProgramInfoLoader)(c,r),c);return t.reshapeUnpacked(p,a)},d=(t,n,r)=>{const i=n[0].dims,o=n[1].dims,a=(0,e.calculateOutputShape)(i,o,r.dilations,r.pads,r.strides),u=t.run((0,c.createIm2ColProgramInfoLoader)(t,n[0],n[1],a,r),[n[0]]),l=3===n.length?[u,n[1],n[2]]:[u,n[1]];return t.run((0,s.createDotProductProgramInfoLoader)(t,n,a,r),l)},h=(t,e)=>{const n=t.kernelShape.slice();if(0===t.kernelShape.length)for(let t=2;t{const e=t.attributes,n=(0,u.parseInternalActivationAttributes)(e),i=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),a=e.getInt("group",1),s=e.getInts("kernel_shape",[]),c=e.getInts("pads",[0,0,0,0]),l=e.getInts("strides",[1,1]);return(0,r.createAttributeWithCacheKey)(Object.assign({autoPad:i,dilations:o,group:a,kernelShape:s,pads:c,strides:l},n))};const g=(t,e)=>{if(!t||2!==t.length&&3!==t.length)throw new Error("Conv requires 2 or 3 inputs");if(4!==t[0].dims.length||4!==t[1].dims.length)throw new Error("currently only support 2-dimensional conv");if(t[0].dims[1]!==t[1].dims[1]*e.group)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(3===t.length&&(1!==t[2].dims.length||t[1].dims[0]!==t[2].dims[0]))throw new Error("invalid bias");const n=t[0].dims.length-2;if(e.dilations.length!==n)throw new Error(`dilations should be ${n}D`);if(e.strides.length!==n)throw new Error(`strides should be ${n}D`);if(e.pads.length!==2*n)throw new Error(`pads should be ${2*n}D`);if(0!==e.kernelShape.length&&e.kernelShape.length!==t[1].dims.length-2)throw new Error("invalid kernel shape");if("float32"!==t[0].type||"float32"!==t[1].type)throw new Error("Conv input(X,W) should be float tensor");if(3===t.length&&"float32"!==t[2].type)throw new Error("Conv input(bias) should be float tensor")}},5193:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseDepthToSpaceAttributes=e.depthToSpace=void 0;const r=n(3738);e.depthToSpace=(t,e,n)=>{i(e);const o=n.blocksize,a=o*o,s="DCR"===n.mode?[0,3,4,1,5,2]:[0,1,4,2,5,3],u="DCR"===n.mode?[e[0].dims[0],o,o,e[0].dims[1]/a,e[0].dims[2],e[0].dims[3]]:[e[0].dims[0],e[0].dims[1]/a,o,o,e[0].dims[2],e[0].dims[3]],c=t.reshapeUnpacked(e[0],u),l={perm:s,cacheKey:`${s}`},[p]=(0,r.transpose)(t,[c],l),f=[e[0].dims[0],e[0].dims[1]/a,e[0].dims[2]*o,e[0].dims[3]*o];return[t.reshapeUnpacked(p,f)]},e.parseDepthToSpaceAttributes=t=>{const e=t.attributes.getInt("blocksize");if(e<1)throw new Error(`blocksize must be >= 1, but got : ${e} for DepthToSpace`);const n=t.attributes.getString("mode","DCR");if("DCR"!==n&&"CRD"!==n)throw new Error(`unrecognized mode: ${n} for DepthToSpace`);return{mode:n,blocksize:e}};const i=t=>{if(1!==t.length)throw new Error(`DepthToSpace expect 1 inputs, but got ${t.length}`);if("string"===t[0].type||4!==t[0].dims.length)throw new TypeError("DepthToSpace input should be a 4-D numeric tensor")}},9828:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createDotProductProgramInfoLoader=void 0;const r=n(2517),i=n(5060),o=n(2039),a=n(2823),s=n(3248);e.createDotProductProgramInfoLoader=(t,e,n,u)=>{const c=((t,e)=>({name:"ConvDotProduct",inputNames:t?["Im2Col","K","B"]:["Im2Col","K"],inputTypes:t?[o.TextureType.unpacked,o.TextureType.packedLastDimension,o.TextureType.unpacked]:[o.TextureType.unpacked,o.TextureType.packedLastDimension],cacheKey:e.activationCacheKey}))(e.length>2,u);return Object.assign(Object.assign({},c),{get:()=>((t,e,n,u,c)=>{const l=n[0].dims,p=n[1].dims,f=[p[0],Math.ceil(l[1]*p[2]*p[3]/4)],d=(0,s.calculateIm2ColDims)(l,p,u),[h,g]=t.calculateTextureWidthAndHeight(f,o.TextureType.packedLastDimension),b=r.ShapeUtil.computeStrides(d),[m,y]=t.calculateTextureWidthAndHeight(d,o.TextureType.packedLastDimension),_=u.length,v=n.length<3?"0.0":"_B(b)",w=Math.ceil(l[1]*p[2]*p[3]/4),{activationFunction:x,applyActivation:T}=(0,a.getActivationSnippet)(c),S=(0,i.getGlsl)(t.session.backend.glContext.version),O=`\n${x}\nfloat process(int indices[${_}]) {\n int b[1];\n b[0] = indices[1];\n int im2col[4];\n im2col[0] = indices[0];\n im2col[1] = indices[2];\n im2col[2] = indices[3];\n int im2colOffset = im2col[0] * ${b[0]} + im2col[1] * ${b[1]} + im2col[2] * ${b[2]};\n int kernelOffset = indices[1] * ${f[1]};\n float value = ${v};\n for (int i = 0; i < ${w}; ++i) {\n vec2 im2colCoords = offsetToCoords(im2colOffset, ${m}, ${y});\n vec2 kernelCoords = offsetToCoords(kernelOffset, ${h}, ${g});\n value += dot(${S.texture2D}(Im2Col, im2colCoords), ${S.texture2D}(K, kernelCoords));\n ++im2colOffset;\n ++kernelOffset;\n }\n ${T}\n return value;\n}`;return Object.assign(Object.assign({},e),{output:{dims:u,type:n[0].type,textureType:o.TextureType.unpacked},shaderSource:O})})(t,c,e,n,u)})}},7992:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseFlattenAttributes=e.flatten=void 0;const r=n(2517);e.flatten=(t,e,n)=>{i(e,n);const o=r.ShapeUtil.flattenShape(e[0].dims,n);return[t.reshapeUnpacked(e[0],o)]},e.parseFlattenAttributes=t=>t.attributes.getInt("axis",1);const i=(t,e)=>{if(!t||1!==t.length)throw new Error("Flatten requires 1 input.");const n=t[0].dims.length;if(0===n)throw new Error("scalar tensor is not supported.");if(e<-n||e>n)throw new Error("Invalid axis");if("string"===t[0].type)throw new Error("string tensor is not supported.")}},2823:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseInternalActivationAttributes=e.getActivationSnippet=void 0;const r=n(2517),i=n(4909);e.getActivationSnippet=function(t){let e;switch(t.activation){case"Relu":e=(0,i.glslRelu)();break;case"Sigmoid":e=(0,i.glslSigmoid)();break;case"Clip":e=(0,i.glslClip)(t.clipMin,t.clipMax);break;default:return{activationFunction:"",applyActivation:""}}const n=e.name;return{activationFunction:e.body,applyActivation:`value = ${n}_(value);`}},e.parseInternalActivationAttributes=t=>{const e=t.getString("activation","");if("Clip"===e){const[n,i]=t.getFloats("activation_params",[r.MIN_CLIP,r.MAX_CLIP]);return{activation:e,clipMax:i,clipMin:n,activationCacheKey:`${e}:${n},${i}`}}return{activation:e,activationCacheKey:e}}},1253:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseGatherAttributes=e.gather=void 0;const r=n(246),i=n(782),o=n(2517),a=n(2039);e.gather=(t,e,n)=>(c(e,n.axis),[t.run(u(t,e,n),e)]),e.parseGatherAttributes=t=>(0,r.createAttributeWithCacheKey)({axis:t.attributes.getInt("axis",0)});const s={name:"Gather",inputNames:["A","B"],inputTypes:[a.TextureType.unpacked,a.TextureType.unpacked]},u=(t,e,n)=>{const r=Object.assign(Object.assign({},s),{cacheHint:n.cacheKey});return Object.assign(Object.assign({},r),{get:()=>((t,e,n,r)=>{const i=n[0].dims.slice(),s=n[1].dims.slice(),u=new Array(i.length+s.length-1);r=o.ShapeUtil.normalizeAxis(r,i.length);const c=[];for(let t=0;t{if(!t||2!==t.length)throw new Error("Gather requires 2 inputs.");const n=t[0].dims.length;if(n<1)throw new Error("Invalid input shape.");if(e<-n||e>n-1)throw new Error("Invalid axis.");if(-1===i.NUMBER_TYPES.indexOf(t[0].type))throw new Error("Invaid input type.");if("int32"!==t[1].type&&"int16"!==t[1].type)throw new Error("Invaid input type.")}},4776:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseGemmAttributesV11=e.parseGemmAttributesV7=e.gemm=void 0;const r=n(246),i=n(2517),o=n(2039);e.gemm=(t,e,n)=>(c(e,n),[t.run(s(e,n),e)]);const a=(t,e)=>{const n=0!==t.attributes.getInt("transA",0),i=0!==t.attributes.getInt("transB",0),o=t.attributes.getFloat("alpha",1),a=t.attributes.getFloat("beta",1);return(0,r.createAttributeWithCacheKey)({transA:n,transB:i,alpha:o,beta:a,isOptionalC:e})};e.parseGemmAttributesV7=t=>a(t,!1),e.parseGemmAttributesV11=t=>a(t,!0);const s=(t,e)=>{const n={name:"Gemm",inputNames:3===t.length?["A","B","C"]:["A","B"],inputTypes:3===t.length?[o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked]:[o.TextureType.unpacked,o.TextureType.unpacked],key:e.cacheKey};return Object.assign(Object.assign({},n),{get:()=>u(n,t,e)})},u=(t,e,n)=>{const r=e[0].dims.slice(),a=e[1].dims.slice(),[s,u]=i.GemmUtil.getShapeOfGemmResult(r,n.transA,a,n.transB,3===e.length?e[2].dims:void 0),c=[s,u];if(!c)throw new Error("Can't use gemm on the given tensors");let l=r[r.length-1],p="";n.transA&&(l=r[0]),n.transA&&n.transB?p="value += _A_T(a) * _B_T(b);":n.transA&&!n.transB?p="value += _A_T(a) * _B(b);":!n.transA&&n.transB?p="value += _A(a) * _B_T(b);":n.transA||n.transB||(p="value += _A(a) * _B(b);");const f=c.length,d=`\n float process(int indices[${f}]) {\n int a[${f}];\n int b[${f}];\n ${3===e.length?`int c[${e[2].dims.length}];`:""}\n\n copyVec(indices, a);\n copyVec(indices, b);\n ${3===e.length?"bcastIndices_C(indices, c);":""}\n\n float value = 0.0;\n for (int k=0; k<${l}; ++k) {\n a[${f-1}] = k;\n b[${f-2}] = k;\n ${p}\n }\n\n value = value * alpha;\n ${3===e.length?"value += beta * _C(c);":""}\n return value;\n }`;return Object.assign(Object.assign({},t),{output:{dims:c,type:e[0].type,textureType:o.TextureType.unpacked},variables:[{name:"alpha",type:"float",data:n.alpha},{name:"beta",type:"float",data:n.beta}],shaderSource:d})},c=(t,e)=>{if(!t)throw new Error("Input is missing");if(e.isOptionalC&&(t.length<2||t.length>3))throw new Error("Invaid input shape.");if(!e.isOptionalC&&3!==t.length)throw new Error("Gemm requires 3 inputs");if(3===t.length&&1!==t[2].dims.length&&2!==t[2].dims.length)throw new Error("Invalid input shape of C");if("float32"!==t[0].type&&"float64"!==t[0].type||"float32"!==t[1].type&&"float64"!==t[1].type||3===t.length&&"float32"!==t[2].type&&"float64"!==t[2].type)throw new Error("Invalid input type.");if(t[0].type!==t[1].type||3===t.length&&t[0].type!==t[2].type)throw new Error("Input types are mismatched")}},8555:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedIm2ColProgramInfoLoader=void 0;const r=n(5060),i=n(2039),o=n(2827);e.createPackedIm2ColProgramInfoLoader=(t,e,n,a,s)=>{const u=(c=s.cacheKey,{name:"Im2Col (packed)",inputNames:["A"],inputTypes:[i.TextureType.packed],cacheHint:c});var c;return Object.assign(Object.assign({},u),{get:()=>((t,e,n,a,s,u)=>{const c=n.dims,l=a.dims,p=s.length,f=[l[1]*l[2]*l[3],s[2]*s[3]],d=l[2]*l[3],h=(0,o.unpackFromChannel)(),g=(0,r.getGlsl)(t.session.backend.glContext.version);let b="";for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)b+=`\n blockIndex = rc.x + ${e};\n pos = rc.y + ${t};\n\n if(blockIndex < ${f[1]} && pos < ${f[0]}) {\n offsetY = int(blockIndex / (${s[p-1]})) * ${u.strides[0]} -\n ${u.pads[0]};\n d0 = offsetY + ${u.dilations[0]} * (imod(pos, ${d}) / ${l[2]});\n\n if(d0 < ${c[2]} && d0 >= 0) {\n offsetX = imod(blockIndex, ${s[p-1]}) * ${u.strides[1]} -\n ${u.pads[1]};\n d1 = offsetX + ${u.dilations[1]} * imod(imod(pos, ${d}), ${l[2]});\n\n if(d1 < ${c[3]} && d1 >= 0) {\n\n ch = int(float(pos)/ ${d}.);\n innerDims = vec2(d0, d1);\n result[${2*t+e}] = getChannel(\n getA(0, ch, int(innerDims.x),\n int(innerDims.y)), innerDims);\n }\n }\n }\n\n `;const m=`\n ${h}\n\n void main() {\n ivec2 rc = getOutputCoords();\n vec4 result = vec4(0.0);\n int blockIndex, pos, offsetY, d0, offsetX, d1, ch;\n vec2 innerDims;\n ${b}\n ${g.output} = result;\n }\n `;return Object.assign(Object.assign({},e),{output:{dims:f,type:n.type,textureType:i.TextureType.packed},shaderSource:m,hasMain:!0})})(t,u,e,n,a,s)})}},3248:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.calculateIm2ColDims=e.createIm2ColProgramInfoLoader=void 0;const r=n(2039);e.createIm2ColProgramInfoLoader=(t,n,i,o,a)=>{const s=(u=a.cacheKey,{name:"Im2Col",inputNames:["X"],inputTypes:[r.TextureType.unpacked],cacheHint:u});var u;return Object.assign(Object.assign({},s),{get:()=>((t,n,i,o,a,s)=>{const u=i.dims,c=o.dims,l=a.length,p=(0,e.calculateIm2ColDims)(u,c,a,4),f=`\n const int XC = ${u[1]};\n const int XH = ${u[2]};\n const int XW = ${u[3]};\n const int KH = ${s.kernelShape[0]};\n const int KW = ${s.kernelShape[1]};\n const int dilationH = ${s.dilations[0]};\n const int dilationW = ${s.dilations[1]};\n const int strideH = ${s.strides[0]};\n const int strideW = ${s.strides[1]};\n const int padH = ${s.pads[0]};\n const int padW = ${s.pads[1]};\n const int KHKW = KH*KW;\n const int XCKHKW = XC * KHKW;\n const int outputChannels = 4;\n vec4 process(int indices[${l}]) {\n int b = indices[0]; // batch size\n int oh = indices[1] * strideH - padH; //output height\n int ow = indices[2] * strideW - padW; //output width\n int p = indices[3] * outputChannels; //patch\n vec4 value = vec4(0.0);\n for(int i=0; i < outputChannels; ++i) {\n if(p < XCKHKW) {\n int patchC = p / KHKW;\n int patchH = (p - patchC*KHKW) / KW;\n int patchW = (p - patchC*KHKW) - patchH * KW;\n int xh2 = oh + patchH * dilationH;\n int xw2 = ow + patchW * dilationW;\n int x[${u.length}];\n x[0] = b;\n x[1] = patchC;\n x[2] = xh2;\n x[3] = xw2;\n if(xh2 >= 0 &&\n xh2 < XH &&\n xw2 >= 0 &&\n xw2 < XW) {\n value[i] = _X(x);\n }\n }\n ++p;\n }\n return value;\n }\n `;return Object.assign(Object.assign({},n),{output:{dims:p,type:i.type,textureType:r.TextureType.packedLastDimension},shaderSource:f})})(0,s,n,i,o,a)})},e.calculateIm2ColDims=(t,e,n,r=4)=>[n[0],n[2],n[3],Math.ceil(t[1]*e[2]*e[3]/r)]},6572:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseImageScalerAttributes=e.imageScaler=void 0;const r=n(246),i=n(2039);e.imageScaler=(t,e,n)=>(u(e),[t.run(a(t,e,n),e)]),e.parseImageScalerAttributes=t=>{const e=t.attributes.getFloat("scale"),n=t.attributes.getFloats("bias");return(0,r.createAttributeWithCacheKey)({scale:e,bias:n})};const o={name:"ImageScaler",inputNames:["X"],inputTypes:[i.TextureType.unpacked]},a=(t,e,n)=>{const r=Object.assign(Object.assign({},o),{cacheHint:n.cacheKey});return Object.assign(Object.assign({},r),{get:()=>((t,e,n,r)=>{const o=n[0].dims.slice(),a=o.length,u=`\n ${s(r.bias.length)}\n float process(int indices[${a}]) {\n return _X(indices) * scale + getBias(bias, indices[1]);\n }`;return Object.assign(Object.assign({},e),{output:{dims:o,type:n[0].type,textureType:i.TextureType.unpacked},variables:[{name:"bias",type:"float",arrayLength:r.bias.length,data:r.bias},{name:"scale",type:"float",data:r.scale}],shaderSource:u})})(0,r,e,n)})},s=t=>{const e=[`float getBias(float bias[${t}], int channel) {`];for(let n=0;n{if(!t||1!==t.length)throw new Error("ImageScaler requires 1 input.");if(4!==t[0].dims.length)throw new Error("Invalid input shape.");if("float32"!==t[0].type&&"float64"!==t[0].type)throw new Error("Invalid input type.")}},3346:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseInstanceNormalizationAttributes=e.instanceNormalization=void 0;const r=n(5060),i=n(2039);e.instanceNormalization=(t,e,n)=>{c(e);const r=t.run(a(e[0]),e);return[t.run(u(t,e[0],n,r.dims),[e[0],r,e[1],e[2]])]},e.parseInstanceNormalizationAttributes=t=>t.attributes.getFloat("epsilon",1e-5);const o={name:"InstanceNormalization_MeanAndVariance",inputNames:["X"],inputTypes:[i.TextureType.unpacked]},a=t=>Object.assign(Object.assign({},o),{get:()=>((t,e)=>{const n=e.dims.slice(),r=n[1],o=n[2]*n[3],a=[n[0],r],s=`\n vec4 process(int[2] indices) {\n vec4 v = vec4(0.0);\n int a[4];\n a[0] = indices[0];\n a[1] = indices[1];\n float temp = 0.0;\n for(int a2=0; a2<${n[2]}; a2++) {\n a[2] = a2;\n for(int a3=0; a3<${n[3]}; a3++) {\n a[3] = a3;\n float x = _X(a);\n temp += x;\n }\n }\n float mean = temp / float(${o});\n temp = 0.0;\n for(int a2=0; a2<${n[2]}; a2++) {\n a[2] = a2;\n for(int a3=0; a3<${n[3]}; a3++) {\n a[3] = a3;\n float x = _X(a);\n temp += (x - mean) * (x - mean);\n }\n }\n v.r = mean;\n v.g = temp / float(${o});\n\n return v;\n }`;return Object.assign(Object.assign({},t),{output:{dims:a,type:e.type,textureType:i.TextureType.packedLastDimension},shaderSource:s})})(o,t)}),s={name:"InstanceNormalization_ComputeOutput",inputNames:["X","MeanAndVariance","Scale","B"],inputTypes:[i.TextureType.unpacked,i.TextureType.packedLastDimension,i.TextureType.unpacked,i.TextureType.unpacked]},u=(t,e,n,o)=>{const a=Object.assign(Object.assign({},s),{cacheHint:`${n}`});return Object.assign(Object.assign({},a),{get:()=>((t,e,n,o,a)=>{const s=(0,r.getGlsl)(t.session.backend.glContext.version),[u,c]=t.calculateTextureWidthAndHeight(a,i.TextureType.packedLastDimension),[l,p]=[u/4,c],f=`\n vec4 get_MeanAndVariance(int[2] mv) {\n int offset = indicesToOffset_MeanAndVariance(mv);\n vec2 coords = offsetToCoords(offset, ${l}, ${p});\n return ${s.texture2D}(MeanAndVariance, coords);\n }\n\n float process(int[4] indices) {\n int mv[2];\n mv[0] = indices[0];\n mv[1] = indices[1];\n vec4 mean_and_variance = get_MeanAndVariance(mv);\n float mean = mean_and_variance.r;\n float variance = mean_and_variance.g;\n\n int sb[1];\n sb[0] = indices[1];\n float scale = _Scale(sb);\n float b = _B(sb);\n\n return scale * (_X(indices) - mean) / sqrt(variance + epsilon) + b;\n }`;return Object.assign(Object.assign({},e),{output:{dims:n.dims,type:n.type,textureType:i.TextureType.unpacked},variables:[{name:"epsilon",type:"float",data:o}],shaderSource:f})})(t,a,e,n,o)})},c=t=>{if(!t||3!==t.length)throw new Error("InstanceNormalization requires 3 inputs.");const e=t[0],n=t[1],r=t[2];if(e.dims.length<3||1!==n.dims.length||1!==r.dims.length)throw new Error("Invalid input shape.");if(n.dims[0]!==e.dims[1]||r.dims[0]!==e.dims[1])throw new Error("Input shapes are mismatched.");if("float32"!==e.type&&"float64"!==e.type||"float32"!==n.type&&"float64"!==n.type||"float32"!==r.type&&"float64"!==r.type)throw new Error("Invalid input type.");if(4!==t[0].dims.length)throw new Error("Only support 4-D input shape.")}},708:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedMatmulProgramInfoLoader=void 0;const r=n(2517),i=n(5060),o=n(2039),a=n(9390),s=n(2823),u=n(5623);e.createPackedMatmulProgramInfoLoader=(t,e,n)=>{const c=(l=e.length>2,p=n.activationCacheKey,{name:"MatMul (packed)",inputNames:l?["A","B","Bias"]:["A","B"],inputTypes:l?[o.TextureType.packed,o.TextureType.packed,o.TextureType.packed]:[o.TextureType.packed,o.TextureType.packed],cacheHint:p});var l,p;return Object.assign(Object.assign({},c),{get:()=>((t,e,n,c)=>{const l=n.length>2,p=l?"value += getBiasForMatmul();":"",f=n[0].dims,d=n[1].dims,h=r.BroadcastUtil.calcShape(f,d,!0),g=!r.ShapeUtil.areEqual(n[0].dims,n[1].dims);if(!h)throw new Error("Can't use matmul on the given tensors");const b=f[f.length-1],m=Math.ceil(b/2),y=f.length,_=d.length,v=(0,i.getGlsl)(t.session.backend.glContext.version),w=(0,a.getCoordsDataType)(h.length),x=h.length,T=(0,a.getGlChannels)(),{activationFunction:S,applyActivation:O}=(0,s.getActivationSnippet)(c),A=l?`${(0,u.getBiasForMatmul)(w,T,n[2].dims,h,!0)}`:"",E=g?`${function(t,e,n,i){let o=[],a=[];const s=n[0].dims,u=n[1].dims,c=s.length,l=u.length,p=i.length,f=p-c,d=p-l;o=s.map(((t,n)=>`coords.${e[n+f]}`)),o[c-1]="i*2",o.join(", "),a=u.map(((t,n)=>`coords.${e[n+d]}`)),a[l-2]="i*2",a.join(", ");const h=r.BroadcastUtil.getBroadcastDims(s,i),g=r.BroadcastUtil.getBroadcastDims(u,i),b=h.map((t=>`coords.${e[t+f]} = 0;`)).join("\n"),m=g.map((t=>`coords.${e[t+d]} = 0;`)).join("\n"),y=`int lastDim = coords.${e[p-1]};\n coords.${e[p-1]} = coords.${e[p-2]};\n coords.${e[p-2]} = lastDim;`;return`\nvec4 getAAtOutCoordsMatmul(int i) {\n ${t} coords = getOutputCoords();\n ${y}\n ${b}\n vec4 outputValue = getA(${o});\n return outputValue;\n}\n\nvec4 getBAtOutCoordsMatmul(int i) {\n ${t} coords = getOutputCoords();\n ${y}\n ${m}\n vec4 outputValue = getB(${a});\n return outputValue;\n}`}(w,T,n,h)}`:"",I=g?"getAAtOutCoordsMatmul(i)":`getA(${function(t,e){let n="";for(let r=0;r{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getBiasForMatmul=e.createMatmulProgramInfoLoader=e.parseMatMulAttributes=e.matMul=void 0;const r=n(2517),i=n(2039),o=n(9390),a=n(2823),s=n(708);function u(t,e){const n=(s=t.length>2,u=e.activationCacheKey,{name:"MatMul",inputNames:s?["A","B","Bias"]:["A","B"],inputTypes:s?[i.TextureType.unpacked,i.TextureType.unpacked,i.TextureType.unpacked]:[i.TextureType.unpacked,i.TextureType.unpacked],cacheHint:u});var s,u;return Object.assign(Object.assign({},n),{get:()=>function(t,e,n){const s=e[0].dims,u=e[1].dims,c=r.BroadcastUtil.calcShape(s,u,!0);if(!c)throw new Error("Can't use matmul on the given tensors");const p=(0,o.getCoordsDataType)(c.length),f=(0,o.getGlChannels)(),{activationFunction:d,applyActivation:h}=(0,a.getActivationSnippet)(n),g=e.length>2,b=g?"value += getBiasForMatmul();":"",m=g?`${l(p,f,e[2].dims,c,!1)}`:"",y=c.length,_=s.length,v=u.length,w=`\n ${d}\n ${m}\n float process(int indices[${y}]) {\n int a[${_}];\n int b[${v}];\n bcastMatmulIndices_A(indices, a);\n bcastMatmulIndices_B(indices, b);\n\n float value;\n for (int k=0; k<${s[s.length-1]}; ++k) {\n a[${_-1}] = k;\n b[${v-2}] = k;\n value += _A(a) * _B(b);\n }\n ${b}\n ${h}\n return value;\n }`;return Object.assign(Object.assign({},t),{output:{dims:c,type:e[0].type,textureType:i.TextureType.unpacked},shaderSource:w})}(n,t,e)})}e.matMul=(t,e,n)=>(c(e),t.session.pack?[t.run((0,s.createPackedMatmulProgramInfoLoader)(t,e,n),e)]:[t.run(u(e,n),e)]),e.parseMatMulAttributes=t=>(0,a.parseInternalActivationAttributes)(t.attributes),e.createMatmulProgramInfoLoader=u;const c=t=>{if(!t||2!==t.length)throw new Error("MatMul requires 2 inputs.");if(t[0].dims[t[0].dims.length-1]!==t[1].dims[t[1].dims.length-2])throw new Error("shared dimension does not match.");if("float32"!==t[0].type&&"float64"!==t[0].type||"float32"!==t[1].type&&"float64"!==t[1].type)throw new Error("inputs should be float type");if(t[0].type!==t[1].type)throw new Error("inputs types should match")};function l(t,e,n,i,o){let a="";const s=n.length,u=i.length,c=u-s;a=u<2&&s>0?"coords":n.map(((t,n)=>`coords.${e[n+c]}`)).join(", ");const l=r.BroadcastUtil.getBroadcastDims(n,i).map((t=>`coords.${e[t+c]} = 0;`)).join("\n");let p="vec4(outputValue.xx, outputValue.yy)";return 1===r.ShapeUtil.size(n)&&(p="vec4(outputValue.x)"),o?`\nvec4 getBiasForMatmul() {\n ${t} coords = getOutputCoords();\n ${l}\n vec4 outputValue = getBias(${a});\n return ${p};\n}`:`\nfloat getBiasForMatmul() {\n ${t} coords = getOutputCoords();\n ${l}\n return getBias(coords.x);\n}`}e.getBiasForMatmul=l},2403:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createPackProgramInfoLoader=void 0;const r=n(5060),i=n(2039),o=n(9390),a=n(2827),s={name:"pack",inputNames:["A"],inputTypes:[i.TextureType.unpackedReversed]};e.createPackProgramInfoLoader=(t,e)=>Object.assign(Object.assign({},s),{get:()=>((t,e)=>{const n=(0,r.getGlsl)(t.session.backend.glContext.version),u=e.dims,c=u.length,l=e.dims.length,p=(0,o.getCoordsDataType)(l),f=(0,a.getChannels)("rc",l),d=(h=l,g=f,b=u[u.length-2],m=u[u.length-1],0===h||1===h?"":`\n int r = ${g[h-2]};\n int c = ${g[h-1]};\n int rp1 = ${g[h-2]} + 1;\n int cp1 = ${g[h-1]} + 1;\n bool rEdge = rp1 >= ${m};\n bool cEdge = cp1 >= ${b};\n `);var h,g,b,m;let y;y=0===c?[1,1]:1===c?[u[0],1]:[u[l-1],u[l-2]];const _=function(t,e,n){if(0===t)return"false";if(1===t)return`rc > ${e[0]}`;let r="";for(let i=t-2;i= ${e[i-t+2]}`,i= ${t[0]} ? 0. : getA(rc + 1),\n 0, 0`;let r="";if(n>2)for(let t=0;t{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.unpackFromChannel=e.getChannels=e.getVecChannels=void 0;const r=n(9390);function i(t,e){return(0,r.getGlChannels)(e).map((e=>`${t}.${e}`))}e.getVecChannels=i,e.getChannels=function(t,e){return 1===e?[t]:i(t,e)},e.unpackFromChannel=function(){return"\n float getChannel(vec4 frag, int dim) {\n int modCoord = imod(dim, 2);\n return modCoord == 0 ? frag.r : frag.g;\n }\n\n float getChannel(vec4 frag, vec2 innerDims) {\n vec2 modCoord = mod(innerDims, 2.);\n return modCoord.x == 0. ?\n (modCoord.y == 0. ? frag.r : frag.g) :\n (modCoord.y == 0. ? frag.b : frag.a);\n }\n "}},2870:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parsePadAttributesV11=e.padV11=e.parsePadAttributesV2=e.padV2=void 0;const r=n(246),i=n(2517),o=n(5060),a=n(2039),s={name:"Pad",inputNames:["A"],inputTypes:[a.TextureType.unpacked]};e.padV2=(t,e,n)=>(l(e),[t.run(Object.assign(Object.assign({},s),{cacheHint:n.cacheKey,get:()=>c(t,e[0],n)}),e)]),e.parsePadAttributesV2=t=>{const e=t.attributes.getString("mode","constant"),n=t.attributes.getFloat("value",0),i=t.attributes.getInts("pads");return(0,r.createAttributeWithCacheKey)({mode:e,value:n,pads:i})},e.padV11=(t,n,r)=>{p(n);const i=u(t,n,r);return(0,e.padV2)(t,[n[0]],i)},e.parsePadAttributesV11=t=>t.attributes.getString("mode","constant");const u=(t,e,n)=>{if(!t.session.isInitializer(e[1].dataId)||e.length>=3&&!t.session.isInitializer(e[2].dataId))throw new Error("dynamic pad attributes are not allowed");const i=Array.from(e[1].integerData),o=e.length>=3?e[2].floatData[0]:0;return(0,r.createAttributeWithCacheKey)({mode:n,pads:i,value:o})},c=(t,e,n)=>{const r=i.ShapeUtil.padShape(e.dims.slice(),n.pads),o=r.length,s=`\n ${f(t,e,n)}\n float process(int[${o}] indices) {\n return padA(indices);\n }`;return{name:"Pad",inputNames:["A"],inputTypes:[a.TextureType.unpacked],output:{dims:r,type:e.type,textureType:a.TextureType.unpacked},shaderSource:s}},l=t=>{if(!t||1!==t.length)throw new Error("Pad requires 1 input");if("float32"!==t[0].type&&"float64"!==t[0].type)throw new Error("Invalid input type.")},p=t=>{if(!t||2!==t.length&&3!==t.length)throw new Error("Pad requires 2 or 3 inputs");if("int32"!==t[1].type)throw new Error("Invalid input type.");if(t.length>=3&&"string"===t[2].type)throw new Error("Invalid input type.")},f=(t,e,n)=>{const r=(0,o.getGlsl)(t.session.backend.glContext.version),[s,u]=t.calculateTextureWidthAndHeight(e.dims,a.TextureType.unpacked),c=i.ShapeUtil.computeStrides(e.dims);switch(n.mode){case"constant":return d(r,e.dims,c,s,u,n.pads,n.value);case"reflect":return h(r,e.dims,c,s,u,n.pads);case"edge":return g(r,e.dims,c,s,u,n.pads);default:throw new Error("Invalid mode")}},d=(t,e,n,r,i,o,a)=>{const s=e.length;let u="";for(let t=s-1;t>=0;--t)u+=`\n k = m[${t}] - ${o[t]};\n if (k < 0) return constant;\n if (k >= ${e[t]}) return constant;\n offset += k * ${n[t]};\n `;return`\n float padA(int m[${s}]) {\n const float constant = float(${a});\n int offset = 0;\n int k = 0;\n ${u}\n vec2 coords = offsetToCoords(offset, ${r}, ${i});\n float value = getColorAsFloat(${t.texture2D}(A, coords));\n return value;\n }\n `},h=(t,e,n,r,i,o)=>{const a=e.length;let s="";for(let t=a-1;t>=0;--t)s+=`\n k = m[${t}] - ${o[t]};\n if (k < 0) { k = -k; }\n {\n const int _2n_1 = ${2*(e[t]-1)};\n k = int( mod( float(k), float(_2n_1) ) ) ;\n if(k >= ${e[t]}) { k = _2n_1 - k; }\n }\n offset += k * ${n[t]};\n `;return`\n float padA(int m[${a}]) {\n int offset = 0;\n int k = 0;\n ${s}\n vec2 coords = offsetToCoords(offset, ${r}, ${i});\n float value = getColorAsFloat(${t.texture2D}(A, coords));\n return value;\n }\n `},g=(t,e,n,r,i,o)=>{const a=e.length;let s="";for(let t=a-1;t>=0;--t)s+=`\n k = m[${t}] - ${o[t]};\n if (k < 0) k = 0;\n if (k >= ${e[t]}) k = ${e[t]-1};\n offset += k * ${n[t]};\n `;return`\n float padA(int m[${a}]) {\n int offset = 0;\n int k = 0;\n ${s}\n vec2 coords = offsetToCoords(offset, ${r}, ${i});\n float value = getColorAsFloat(${t.texture2D}(A, coords));\n return value;\n }\n `}},2143:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.globalMaxPool=e.parseMaxPoolAttributes=e.maxPool=e.parseGlobalAveragePoolAttributes=e.globalAveragePool=e.parseAveragePoolAttributes=e.averagePool=void 0;const r=n(246),i=n(2517),o=n(2039);e.averagePool=(t,e,n)=>{p(e);const r={name:"AveragePool",inputNames:["X"],inputTypes:[o.TextureType.unpacked],cacheHint:n.cacheKey};return[t.run(Object.assign(Object.assign({},r),{get:()=>a(e,r,!1,n)}),e)]},e.parseAveragePoolAttributes=t=>{const e=t.attributes.getString("auto_pad","NOTSET"),n=t.attributes.getInt("ceil_mode",0),i=0!==t.attributes.getInt("count_include_pad",0),o=t.attributes.getInts("kernel_shape"),a=t.attributes.getInts("strides",[]),s=t.attributes.getInts("pads",[]);if(0!==n)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");return(0,r.createAttributeWithCacheKey)({autoPad:e,ceilMode:n,countIncludePad:i,kernelShape:o,strides:a,pads:s})};const a=(t,e,n,r)=>{const[a,s]=u(t,r,n),c=i.ShapeUtil.size(a.kernelShape);let l="";a.countIncludePad?l+=`value /= float(${c});`:l+=`value /= float(${c} - pad);`;const p=`\n ${f(t[0].dims,a,"value += _X(x);",l,"0.0")}\n `;return Object.assign(Object.assign({},e),{output:{dims:s,type:t[0].type,textureType:o.TextureType.unpacked},shaderSource:p})};e.globalAveragePool=(t,e,n)=>{p(e);const r={name:"GlobalAveragePool",inputNames:["X"],inputTypes:[o.TextureType.unpacked],cacheHint:`${n.countIncludePad}`};return[t.run(Object.assign(Object.assign({},r),{get:()=>a(e,r,!0,n)}),e)]},e.parseGlobalAveragePoolAttributes=t=>{const e=0!==t.attributes.getInt("count_include_pad",0);return(0,r.createAttributeWithCacheKey)({autoPad:"",ceilMode:0,countIncludePad:e,kernelShape:[],strides:[],pads:[]})},e.maxPool=(t,e,n)=>{p(e);const r={name:"MaxPool",inputNames:["X"],inputTypes:[o.TextureType.unpacked],cacheHint:n.cacheKey};return[t.run(Object.assign(Object.assign({},r),{get:()=>s(e,r,!1,n)}),e)]},e.parseMaxPoolAttributes=t=>{const e=t.attributes.getString("auto_pad","NOTSET"),n=t.attributes.getInt("ceil_mode",0),i=t.attributes.getInts("kernel_shape"),o=t.attributes.getInts("strides",[]),a=t.attributes.getInts("pads",[]),s=t.attributes.getInt("storage_order",0),u=t.attributes.getInts("dilations",[]);if(0!==s)throw new Error("column major storage order is not yet supported for MaxPool");if(0!==n)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");return(0,r.createAttributeWithCacheKey)({autoPad:e,ceilMode:n,countIncludePad:!1,kernelShape:i,strides:o,pads:a,storageOrder:s,dilations:u})};const s=(t,e,n,r)=>{const[i,a]=u(t,r,n),s=`\n ${f(t[0].dims,i,"\n value = max(_X(x), value);\n ","","-1e5")}\n `;return Object.assign(Object.assign({},e),{output:{dims:a,type:t[0].type,textureType:o.TextureType.unpacked},shaderSource:s})},u=(t,e,n)=>{const r=t[0].dims.slice(),o=Object.hasOwnProperty.call(e,"dilations"),a=e.kernelShape.slice(),s=e.strides.slice(),u=o?e.dilations.slice():[],c=e.pads.slice();i.PoolConvUtil.adjustPoolAttributes(n,r,a,s,u,c);const l=i.PoolConvUtil.computePoolOutputShape(n,r,s,u,a,c,e.autoPad),p=Object.assign({},e);return o?Object.assign(p,{kernelShape:a,strides:s,pads:c,dilations:u,cacheKey:e.cacheKey}):Object.assign(p,{kernelShape:a,strides:s,pads:c,cacheKey:e.cacheKey}),[p,l]},c={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[],cacheKey:""},l={name:"GlobalMaxPool",inputNames:["X"],inputTypes:[o.TextureType.unpacked]};e.globalMaxPool=(t,e)=>(p(e),[t.run(Object.assign(Object.assign({},l),{get:()=>s(e,l,!0,c)}),e)]);const p=t=>{if(!t||1!==t.length)throw new Error("Pool ops requires 1 input.");if("float32"!==t[0].type&&"float64"!==t[0].type)throw new Error("Invalid input type.")},f=(t,e,n,r,o)=>{const a=t.length;if(e.kernelShape.length<=2){const i=e.kernelShape[e.kernelShape.length-1],s=e.strides[e.strides.length-1],u=e.pads[e.pads.length/2-1],c=e.pads[e.pads.length-1],l=t[a-1];let p="",f="",d="";if(p=u+c!==0?`\n for (int i = 0; i < ${i}; i++) {\n x[${a} - 1] = indices[${a} - 1] * ${s} - ${u} + i;\n if (x[${a} - 1] < 0 || x[${a} - 1] >= ${l}) {\n pad++;\n continue;\n }\n ${n}\n }`:`\n for (int i = 0; i < ${i}; i++) {\n x[${a} - 1] = indices[${a} - 1] * ${s} - ${u} + i;\n ${n}\n }`,2===e.kernelShape.length){const n=e.kernelShape[e.kernelShape.length-2],r=e.strides[e.strides.length-2],o=e.pads[e.pads.length/2-2],s=e.pads[e.pads.length-2],u=t[a-2];f=o+s!==0?`\n for (int j = 0; j < ${n}; j++) {\n x[${a} - 2] = indices[${a} - 2] * ${r} - ${o} + j;\n if (x[${a} - 2] < 0 || x[${a} - 2] >= ${u}) {\n pad+= ${i};\n continue;\n }\n `:`\n for (int j = 0; j < ${n}; j++) {\n x[${a} - 2] = indices[${a} - 2] * ${r} - ${o} + j;\n `,d="\n }\n "}return`\n float process(int indices[${a}]) {\n int x[${a}];\n copyVec(indices, x);\n\n float value = ${o};\n int pad = 0;\n ${f}\n ${p}\n ${d}\n ${r}\n return value;\n }\n `}{const s=i.ShapeUtil.size(e.kernelShape),u=i.ShapeUtil.computeStrides(e.kernelShape),c=u.length,l=e.pads.length,p=h(c),f=d(t,"inputDims"),g=d(e.pads,"pads"),b=d(u,"kernelStrides"),m=d(e.strides,"strides");let y="";return y=e.pads.reduce(((t,e)=>t+e))?`\n if (x[j] >= inputDims[j] || x[j] < 0) {\n pad++;\n isPad = true;\n break;\n }\n }\n if (!isPad) {\n ${n}\n }`:`\n }\n ${n}\n `,`\n ${p}\n float process(int indices[${a}]) {\n int x[${a}];\n copyVec(indices, x);\n int offset[${c}];\n int pads[${l}];\n int inputDims[${a}];\n int kernelStrides[${c}];\n int strides[${c}];\n ${g}\n ${f}\n ${m}\n ${b}\n\n float value = ${o};\n int pad = 0;\n bool isPad = false;\n for (int i = 0; i < ${s}; i++) {\n offsetToIndices(i, kernelStrides, offset);\n isPad = false;\n for (int j = ${a} - ${c}; j < ${a}; j++) {\n x[j] = indices[j] * strides[j - ${a} + ${c}]\n + offset[j - ${a} + ${c}] - pads[j - 2];\n ${y}\n }\n ${r}\n\n return value;\n }\n `}},d=(t,e)=>{let n="";for(let r=0;r`\n void offsetToIndices(int offset, int[${t}] strides, out int[${t}] indices) {\n if (${t} == 0) {\n return;\n }\n for (int i = 0; i < ${t} - 1; ++i) {\n indices[i] = offset / strides[i];\n offset -= indices[i] * strides[i];\n }\n indices[${t} - 1] = offset;\n }`},4939:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.reduceLogSumSquare=e.reduceLogSum=e.reduceProd=e.reduceMin=e.reduceMax=e.reduceMean=e.reduceSum=e.parseReduceAttributes=void 0;const r=n(246),i=n(782),o=n(2517),a=n(2039),s=(t,e,n,r,i)=>{c(e);const o={name:r,inputNames:["A"],inputTypes:[a.TextureType.unpacked]};return[t.run(Object.assign(Object.assign({},o),{cacheHint:n.cacheKey,get:()=>u(t,e,n,r,i,o)}),e)]};e.parseReduceAttributes=t=>{const e=t.attributes.getInts("axes",[]),n=1===t.attributes.getInt("keepdims",1);return(0,r.createAttributeWithCacheKey)({axes:e,keepDims:n})};const u=(t,e,n,r,i,s)=>{const u=[],c=e[0].dims.length||1,l=[],p=o.ShapeUtil.normalizeAxes(n.axes,e[0].dims.length),f=i(e,p);let d=f[1];for(let t=0;t=0||0===p.length?(n.keepDims&&u.push(1),d=`\n for(int j${t} = 0; j${t} < ${e[0].dims[t]}; j${t}++) {\n inputIdx[${t}] = j${t};\n ${d}\n }`):(l.push(`inputIdx[${t}] = outputIdx[${u.length}];`),u.push(e[0].dims[t]));const h=`\n float process(int outputIdx[${u.length||1}]) {\n float value; // final result\n int inputIdx[${c}]; // addressing input data\n ${l.join("\n")}\n ${f[0]} // init ops for reduce max/min\n ${d}\n ${f[2]} // final computation for reduce mean\n return value;\n }`;return Object.assign(Object.assign({},s),{output:{dims:u,type:e[0].type,textureType:a.TextureType.unpacked},shaderSource:h})},c=t=>{if(!t||1!==t.length)throw new Error("Reduce op requires 1 input.");if(-1===i.NUMBER_TYPES.indexOf(t[0].type))throw new Error("Invalid input type.")};e.reduceSum=(t,e,n)=>s(t,e,n,"ReduceSum",(()=>["value = 0.0;","value += _A(inputIdx);",""])),e.reduceMean=(t,e,n)=>s(t,e,n,"ReduceMean",((t,e)=>{let n=1;for(let r=0;r=0||0===e.length)&&(n*=t[0].dims[r]);return["value = 0.0;","value += _A(inputIdx);",`value /= ${n}.;`]})),e.reduceMax=(t,e,n)=>s(t,e,n,"ReduceMax",((t,e)=>{const n=[];for(let r=0;r=0||0===e.length)&&n.push(`inputIdx[${r}] = 0;`);return[`${n.join("\n")}\nvalue = _A(inputIdx);`,"value = max(value, _A(inputIdx));",""]})),e.reduceMin=(t,e,n)=>s(t,e,n,"ReduceMin",((t,e)=>{const n=[];for(let r=0;r=0||0===e.length)&&n.push(`inputIdx[${r}] = 0;`);return[`${n.join("\n")}\nvalue = _A(inputIdx);`,"value = min(value, _A(inputIdx));",""]})),e.reduceProd=(t,e,n)=>s(t,e,n,"ReduceProd",(()=>["value = 1.0;","value *= _A(inputIdx);",""])),e.reduceLogSum=(t,e,n)=>s(t,e,n,"ReduceLogSum",(()=>["value = 0.0;","value += _A(inputIdx);","value = log(value);"])),e.reduceLogSumSquare=(t,e,n)=>s(t,e,n,"ReduceLogSumSquare",(()=>["float t; value = 0.0;","t = _A(inputIdx); value += t * t;",""]))},7019:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isReshapeCheap=e.processDims3D=e.createPackedReshape3DProgramInfoLoader=void 0;const r=n(2517),i=n(5060),o=n(2039),a=n(2827);e.createPackedReshape3DProgramInfoLoader=(t,e,n)=>{const s=(t=>({name:"Reshape (packed)",inputTypes:[o.TextureType.packed],inputNames:["A"],cacheHint:`${t}`}))(n);return Object.assign(Object.assign({},s),{get:()=>((t,e,n,s)=>{const u=e.dims,c=s;let l="";for(let t=0;t<4;t++){let e="";switch(t){case 0:e="outputCoords = rc;";break;case 1:e="outputCoords = ivec3(rc.x, rc.y+1, rc.z);";break;case 2:e="outputCoords = ivec3(rc.x, rc.y, rc.z+1);";break;case 3:e="outputCoords = ivec3(rc.x, rc.y+1, rc.z+1);";break;default:throw new Error}l+=`\n ${e}\n ${t>0?"if(outputCoords.y < rows && outputCoords.z < cols){":""}\n int flattenedIndex = getFlattenedIndex(outputCoords);\n\n ivec3 inputRC = inputCoordsFromReshapedOutCoords(flattenedIndex);\n vec2 innerDims = vec2(float(inputRC.y),float(inputRC.z));\n\n result[${t}] = getChannel(getA(inputRC.x, inputRC.y, inputRC.z), innerDims);\n\n ${t>0?"}":""}\n `}const p=(0,i.getGlsl)(t.session.backend.glContext.version),f=`\n ${function(t){const e=r.ShapeUtil.computeStrides(t),n=["b","r","c"],i="index";return`\n ivec3 inputCoordsFromReshapedOutCoords(int index) {\n ${e.map(((t,r)=>`int ${n[r]} = ${i} / ${t}; ${r===e.length-1?`int ${n[r+1]} = ${i} - ${n[r]} * ${t}`:`index -= ${n[r]} * ${t}`};`)).join("")}\n return ivec3(b, r, c);\n }\n `}(u)}\n ${function(t){const e=r.ShapeUtil.computeStrides(t);return`\n int getFlattenedIndex(ivec3 coords) {\n // reverse y, z order\n return coords.x * ${e[0]} + coords.z * ${e[1]} + coords.y;\n }\n`}(c)}\n ${(0,a.unpackFromChannel)()}\n\n void main() {\n ivec3 rc = getOutputCoords();\n\n vec4 result = vec4(0.0);\n\n ivec3 outputCoords;\n int rows = ${c[2]};\n int cols = ${c[1]};\n\n ${l}\n ${p.output} = result;\n }\n `;return Object.assign(Object.assign({},n),{output:{dims:c,type:e.type,textureType:o.TextureType.packed},shaderSource:f,hasMain:!0})})(t,e,s,n)})},e.processDims3D=function(t){if(0===t.length)return[1,1,1];let e=1;for(let n=0;n1?t[t.length-2]:1,t[t.length-1]]},e.isReshapeCheap=function(t,e){let n=!1;return n=0===t.length||0===e.length||(t.length<2||e.length<2?t[t.length-1]===e[e.length-1]:t[t.length-1]===e[e.length-1]&&t[t.length-2]===e[e.length-2]),n}},718:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.reshape=void 0;const r=n(2517);e.reshape=(t,e)=>{const n=r.ShapeUtil.calculateReshapedDims(e[0].dims,e[1].integerData);return t.session.pack?[t.reshapePacked(e[0],n)]:[t.reshapeUnpacked(e[0],n)]}},2268:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseResizeAttributesV11=e.parseResizeAttributesV10=e.resize=void 0;const r=n(5060),i=n(2039),o=n(9390),a=n(2827),s=n(9793),u={name:"Resize",inputNames:["A"],inputTypes:[i.TextureType.packed]};e.resize=(t,e,n)=>((0,s.validateInputs)(e,n),[t.run(Object.assign(Object.assign({},u),{cacheHint:n.cacheKey,get:()=>c(t,e,n)}),e)]),e.parseResizeAttributesV10=t=>(0,s.parseUpsampleAttributes)(t,10),e.parseResizeAttributesV11=t=>(0,s.parseUpsampleAttributes)(t,11);const c=(t,e,n)=>{const s=(0,r.getGlsl)(t.session.backend.glContext.version),[c,p]=l(e,n);if(c.every((t=>1===t))&&"tf_crop_and_resize"!==n.coordinateTransformMode)return Object.assign(Object.assign({},u),{output:{dims:p,type:e[0].type,textureType:i.TextureType.packed},hasMain:!0,shaderSource:`void main() {\n vec4 v = ${s.texture2D}(X, TexCoords);\n ${s.output} = v;\n }`});const f=p.length;if(f<2)throw new Error(`output dimension should be at least 2, but got ${f}`);const d=p[f-2],h=p[f-1],g=e[0].dims;if(f!==g.length)throw new Error(`output dimension should match input ${g.length}, but got ${f}`);const b=g[f-2],m=g[f-1],y=c[f-2],_=c[f-1];let v="";if("linear"!==n.mode)throw new Error(`resize (packed) does not support mode: '${n.mode}'`);switch(n.coordinateTransformMode){case"asymmetric":v="\n vec4 getSourceFracIndex(ivec4 coords) {\n return vec4(coords) / scaleWHWH;\n }\n ";break;case"half_pixel":v="\n vec4 getSourceFracIndex(ivec4 coords) {\n return (vec4(coords) + 0.5) / scaleWHWH - 0.5;\n }\n ";break;case"pytorch_half_pixel":v=`\n vec4 getSourceFracIndex(ivec4 coords) {\n vec4 fcoords = vec4(coords);\n return vec4(\n ${h}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0,\n ${d}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0,\n ${h}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0,\n ${d}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0\n );\n }\n `;break;case"align_corners":v=`\n vec4 getSourceFracIndex(ivec4 coords) {\n vec4 resized = vec4(${h}.0 - 1.0, ${d}.0 - 1.0, ${h}.0 - 1.0,\n ${d}.0 - 1.0);\n vec4 original = vec4(${m}.0 - 1.0, ${b}.0 - 1.0, ${m}.0 - 1.0,\n ${b}.0 - 1.0);\n vec4 new_scale = original / resized;\n return vec4(coords) * new_scale;\n }\n `;break;default:throw new Error(`resize (packed) does not support coordinateTransformMode: '${n.coordinateTransformMode}'`)}const w=(0,o.getCoordsDataType)(f),x=`\n const vec2 inputWH = vec2(${b}.0, ${m}.0);\n const vec4 scaleWHWH = vec4(float(${y}), float(${_}), float(${y}), float(${_}));\n ${(0,a.unpackFromChannel)()}\n ${v}\n float getAValue(int x10, int r, int c, int d) {\n return getChannel(getA(x10, r, c, d), vec2(c, d));\n }\n void main() {\n ${w} rc = getOutputCoords();\n\n int batch = rc[0];\n int depth = rc[1];\n\n // retrieve the 4 coordinates that is used in the 4 packed output values.\n ivec4 coords = ivec4(rc.wz, rc.w + 1, rc.z + 1);\n\n // calculate the source index in fraction\n vec4 sourceFrac = getSourceFracIndex(coords);\n\n // get the lower and upper bound of the 4 values that will be packed into one texel.\n ivec4 x00 = ivec4(max(sourceFrac.xy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xy)));\n ivec4 x01 = ivec4(max(sourceFrac.xw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xw)));\n ivec4 x10 = ivec4(max(sourceFrac.zy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zy)));\n ivec4 x11 = ivec4(max(sourceFrac.zw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zw)));\n\n bool hasNextRow = rc.w < ${d-1};\n bool hasNextCol = rc.z < ${h-1};\n\n // pack x00, x01, x10, x11's top-left corner into one vec4 structure\n vec4 topLeft = vec4(\n getAValue(batch, depth, x00.x, x00.y),\n hasNextCol ? getAValue(batch, depth, x01.x, x01.y) : 0.0,\n hasNextRow ? getAValue(batch, depth, x10.x, x10.y) : 0.0,\n (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.y) : 0.0);\n\n // pack x00, x01, x10, x11's top-right corner into one vec4 structure\n vec4 topRight = vec4(\n getAValue(batch, depth, x00.x, x00.w),\n hasNextCol ? getAValue(batch, depth, x01.x, x01.w) : 0.0,\n hasNextRow ? getAValue(batch, depth, x10.x, x10.w) : 0.0,\n (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.w) : 0.0);\n\n // pack x00, x01, x10, x11's bottom-left corner into one vec4 structure\n vec4 bottomLeft = vec4(\n getAValue(batch, depth, x00.z, x00.y),\n hasNextCol ? getAValue(batch, depth, x01.z, x01.y) : 0.0,\n hasNextRow ? getAValue(batch, depth, x10.z, x10.y) : 0.0,\n (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.y) : 0.0);\n\n // pack x00, x01, x10, x11's bottom-right corner into one vec4 structure\n vec4 bottomRight = vec4(\n getAValue(batch, depth, x00.z, x00.w),\n hasNextCol ? getAValue(batch, depth, x01.z, x01.w) : 0.0,\n hasNextRow ? getAValue(batch, depth, x10.z, x10.w) : 0.0,\n (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.w) : 0.0);\n\n // calculate the interpolation fraction on u and v direction\n vec4 frac = vec4(sourceFrac) - floor(sourceFrac);\n vec4 clampFrac = clamp(frac, vec4(0.0), vec4(1.0));\n\n vec4 top = mix(topLeft, topRight, clampFrac.ywyw);\n vec4 bottom = mix(bottomLeft, bottomRight, clampFrac.ywyw);\n vec4 newValue = mix(top, bottom, clampFrac.xxzz);\n\n ${s.output} = vec4(newValue);\n }\n `;return Object.assign(Object.assign({},u),{output:{dims:p,type:e[0].type,textureType:i.TextureType.packed},hasMain:!0,shaderSource:x})},l=(t,e)=>{const n=t[0].dims;let r,i=e.scales;if(0===i.length){const o=t[e.scalesInputIdx];if(o&&0!==o.size){if(t[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");i=p(o,e.mode,e.isResize)}else{const o=t[e.sizesInputIdx];if(!o||0===o.size)throw new Error("Either scales or sizes MUST be provided as input.");r=Array.from(o.integerData),i=f(r,n,e.mode,e.isResize)}}else if(t[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");const o=r||n.map(((t,e)=>Math.floor(t*i[e])));return[i,o]},p=(t,e,n)=>{const r=Array.from(t.floatData);return(0,s.scalesValidation)(r,e,n),r},f=(t,e,n,r)=>{const i=e.length,o=new Array(i);for(let n=0,r=i;n{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.shape=void 0;const r=n(9162);e.shape=(t,e)=>(i(e),[new r.Tensor([e[0].dims.length],"int32",void 0,void 0,new Int32Array(e[0].dims))]);const i=t=>{if(!t||1!==t.length)throw new Error("Shape requires 1 input.")}},2278:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sliceV10=e.parseSliceAttributes=e.slice=void 0;const r=n(246),i=n(782),o=n(2517),a=n(2039),s={name:"Slice",inputNames:["A"],inputTypes:[a.TextureType.unpacked]};e.slice=(t,e,n)=>(c(e),[t.run(Object.assign(Object.assign({},s),{cacheHint:n.cacheKey,get:()=>u(t,e[0],n)}),e)]),e.parseSliceAttributes=t=>{const e=t.attributes.getInts("starts"),n=t.attributes.getInts("ends"),i=t.attributes.getInts("axes",[]);return(0,r.createAttributeWithCacheKey)({starts:e,ends:n,axes:i})};const u=(t,e,n)=>{const r=0===n.axes.length?e.dims.slice(0).map(((t,e)=>e)):n.axes,i=o.ShapeUtil.normalizeAxes(r,e.dims.length),u=n.starts.map(((t,n)=>t>e.dims[i[n]]-1?e.dims[i[n]]:o.ShapeUtil.normalizeAxis(t,e.dims[i[n]]))),c=n.ends.map(((t,n)=>t>e.dims[i[n]]-1?e.dims[i[n]]:o.ShapeUtil.normalizeAxis(t,e.dims[i[n]]))),l=e.dims.slice(),p=[];for(let t=0;t0&&p.push(`outputIdx[${i[t]}] += ${u[t]};`);const f=`\n float process(int outputIdx[${l.length}]) {\n ${p.join("\n ")}\n return _A(outputIdx);\n }`;return Object.assign(Object.assign({},s),{output:{dims:l,type:e.type,textureType:a.TextureType.unpacked},shaderSource:f})},c=t=>{if(!t||1!==t.length)throw new Error("Slice requires 1 input.");if(-1===i.NUMBER_TYPES.indexOf(t[0].type))throw new Error("Invalid input type.")};e.sliceV10=(t,e)=>{p(e);const n=l(t,e);return[t.run(Object.assign(Object.assign({},s),{cacheHint:n.cacheKey,get:()=>u(t,e[0],n)}),[e[0]])]};const l=(t,e)=>{if(!t.session.isInitializer(e[1].dataId)||!t.session.isInitializer(e[2].dataId)||e.length>=4&&!t.session.isInitializer(e[3].dataId)||e.length>=5&&!t.session.isInitializer(e[4].dataId))throw new Error("dynamic slice attributes are not allowed");if(e.length>=5&&e[4].integerData.some((t=>1!==t)))throw new Error("currently non-1 steps is not supported for Slice");const n=Array.from(e[1].integerData),r=Array.from(e[2].integerData),i=e.length>=4?Array.from(e[3].integerData):[];return{starts:n,ends:r,axes:i,cacheKey:`${i};${n};${r}`}},p=t=>{if(!t||t.length<3||t.length>5)throw new Error("Invalid input number.");if("int32"!==t[1].type||1!==t[1].dims.length)throw new Error("Invalid input type.");if("int32"!==t[2].type||1!==t[2].dims.length)throw new Error("Invalid input type.");if(t.length>=4&&("int32"!==t[3].type||1!==t[3].dims.length))throw new Error("Invalid input type.");if(t.length>=5&&("int32"!==t[4].type||1!==t[4].dims.length))throw new Error("Invalid input type.")}},5524:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.softmaxV13=e.parseSoftmaxAttributesV13=e.parseSoftmaxAttributes=e.softmax=void 0;const r=n(246),i=n(2517),o=n(5060),a=n(2039),s=n(3738),u={name:"SoftmaxComputeMax",inputNames:["A"],inputTypes:[a.TextureType.unpacked]},c={name:"SoftmaxComputeScale",inputNames:["A","Max"],inputTypes:[a.TextureType.unpacked,a.TextureType.unpacked]},l={name:"SoftMax",inputNames:["A","Max","Norm"],inputTypes:[a.TextureType.unpacked,a.TextureType.unpacked,a.TextureType.unpacked]};e.softmax=(t,e,n)=>{g(e);const r=e[0].dims.slice(),o=i.ShapeUtil.normalizeAxis(n.axis,r.length),a=i.ShapeUtil.sizeToDimension(r,o),s=i.ShapeUtil.sizeFromDimension(r,o);return p(t,e,n,a,s)},e.parseSoftmaxAttributes=t=>(0,r.createAttributeWithCacheKey)({axis:t.attributes.getInt("axis",1)}),e.parseSoftmaxAttributesV13=t=>(0,r.createAttributeWithCacheKey)({axis:t.attributes.getInt("axis",-1)}),e.softmaxV13=(t,e,n)=>{g(e);const o=e[0].dims.slice(),a=i.ShapeUtil.normalizeAxis(n.axis,o.length),u=o.length,c=a!==u-1,l=[];let f,d=[],h=[];c&&(d=Array.from({length:u}).map(((t,e)=>e)),d[a]=u-1,d[u-1]=a,d.map((t=>l.push(o[t]))),f=(0,r.createAttributeWithCacheKey)({perm:d}),h=(0,s.transpose)(t,e,f));const b=c?i.ShapeUtil.sizeToDimension(l,u-1):i.ShapeUtil.sizeToDimension(o,u-1),m=c?i.ShapeUtil.sizeFromDimension(l,u-1):i.ShapeUtil.sizeFromDimension(o,u-1),y=p(t,c?h:e,n,b,m);return c?(0,s.transpose)(t,y,f):y};const p=(t,e,n,r,i)=>{const o=f(t,e[0],r,i,[r]),a=t.run(Object.assign(Object.assign({},u),{cacheHint:n.cacheKey,get:()=>o}),e),s=d(t,e[0],r,i,o.output.dims,[r]),p=t.run(Object.assign(Object.assign({},c),{cacheHint:n.cacheKey,get:()=>s}),[e[0],a]),g=h(t,e[0],r,i,o.output.dims,s.output.dims);return[t.run(Object.assign(Object.assign({},l),{cacheHint:n.cacheKey,get:()=>g}),[e[0],a,p])]},f=(t,e,n,r,i)=>{const[s,c]=t.calculateTextureWidthAndHeight(e.dims,a.TextureType.unpacked),l=i.length;if(n<1||r<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(1!==i.length)throw new Error("Dimensionality of the output should be 1");if(i[0]!==n)throw new Error("Shape of the output should be equal to logical row count");const p=(0,o.getGlsl)(t.session.backend.glContext.version),f=`\n float process(int[${l}] indices) {\n int logical_row_start_offset = indices[0] * ${r};\n\n float max = getColorAsFloat(${p.texture2D}(A, offsetToCoords(logical_row_start_offset, ${s},\n ${c} )));\n for(int i=1; i<${r}; ++i)\n {\n float current = getColorAsFloat(${p.texture2D}(A, offsetToCoords(logical_row_start_offset + i,\n ${s}, ${c})));\n if(current > max)\n max = current;\n }\n\n return max;\n }`;return Object.assign(Object.assign({},u),{output:{dims:i,type:e.type,textureType:a.TextureType.unpacked},shaderSource:f})},d=(t,e,n,r,i,s)=>{const[u,l]=t.calculateTextureWidthAndHeight(e.dims,a.TextureType.unpacked),p=s.length;if(n<1||r<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(1!==s.length)throw new Error("Dimensionality of the output should be 1");if(s[0]!==n)throw new Error("Shape of the output should be equal to logical row count");if(1!==i.length)throw new Error("Dimensionality of the intermediate results should be 1");if(i[0]!==n)throw new Error("Shape of the intermediate results should be equal to logical row count");const f=`\n float process(int[${p}] indices) {\n int logical_row_start_offset = indices[0] * ${r};\n\n float norm_factor = 0.0;\n float max = _Max(indices);\n for(int i=0; i<${r}; ++i)\n {\n norm_factor += exp(getColorAsFloat(${(0,o.getGlsl)(t.session.backend.glContext.version).texture2D}(A, offsetToCoords(logical_row_start_offset + i,\n ${u}, ${l}))) - max);\n }\n\n return norm_factor;\n }`;return Object.assign(Object.assign({},c),{output:{dims:s,type:e.type,textureType:a.TextureType.unpacked},shaderSource:f})},h=(t,e,n,r,i,o)=>{const[s,u]=t.calculateTextureWidthAndHeight(e.dims,a.TextureType.unpacked),c=e.dims.length;if(n<1||r<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(1!==i.length||1!==o.length)throw new Error("Dimensionality of the intermediate results should be 1");if(i[0]!==n||o[0]!==n)throw new Error("Shape of the intermediate results should be equal to logical row count");const p=`\n float process(int[${c}] indices) {\n\n // get offset of current logical tensor index from the 2-D texture coordinates (TexCoords)\n int offset = coordsToOffset(TexCoords, ${s}, ${u});\n\n //determine the logical row for this index\n int logical_row_index[1];\n logical_row_index[0] = offset / ${r};\n\n float norm_factor = _Norm(logical_row_index);\n\n // avoid possible division by 0\n // if norm_facor is 0, all elements are zero\n // if so, return 0\n if(norm_factor == 0.0)\n return 0.0;\n\n return exp(_A(indices) - _Max(logical_row_index)) / norm_factor;\n }`;return Object.assign(Object.assign({},l),{output:{dims:e.dims,type:e.type,textureType:a.TextureType.unpacked},shaderSource:p})},g=t=>{if(!t||1!==t.length)throw new Error("Softmax requires 1 input.");if("float32"!==t[0].type&&"float64"!==t[0].type)throw new Error("Invalid input type")}},5975:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseSplitAttributes=e.split=void 0;const r=n(246),i=n(2517),o=n(2039),a={name:"Split",inputNames:["A"],inputTypes:[o.TextureType.unpacked]};e.split=(t,e,n)=>{c(e);const r=i.ShapeUtil.normalizeAxis(n.axis,e[0].dims.length),o=s(t,e,r,n),l=[];for(let i=0;iu(t,e[0],n,r,i)}),e));return l},e.parseSplitAttributes=t=>{const e=t.attributes.getInt("axis",0),n=t.attributes.getInts("split",[]),i=t.outputs.length;return(0,r.createAttributeWithCacheKey)({axis:e,split:n,numOutputs:i})};const s=(t,e,n,r)=>{const[,o]=i.SplitUtil.splitShape(e[0].dims,n,r.split,r.numOutputs);return o.length},u=(t,e,n,r,s)=>{const[u,c]=i.SplitUtil.splitShape(e.dims,r,n.split,n.numOutputs),l=c[s],p=u[s],f=`\n float process(int indices[${p.length}]) {\n indices[${r}] += ${l};\n return _A(indices);\n }\n `;return Object.assign(Object.assign({},a),{cacheHint:`${n.cacheKey}:${s}`,output:{dims:p,type:e.type,textureType:o.TextureType.unpacked},shaderSource:f})},c=t=>{if(!t||1!==t.length)throw new Error("Split requires one input.");if("int8"!==t[0].type&&"uint8"!==t[0].type&&"int16"!==t[0].type&&"uint16"!==t[0].type&&"int32"!==t[0].type&&"uint32"!==t[0].type&&"float32"!==t[0].type&&"float64"!==t[0].type&&"bool"!==t[0].type)throw new Error("Invalid input type.")}},3933:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseSqueezeAttributes=e.squeezeV13=e.squeeze=void 0;const r=n(2517);e.squeeze=(t,e,n)=>{i(e);const o=r.ShapeUtil.squeezeShape(e[0].dims,n);return[t.reshapeUnpacked(e[0],o)]},e.squeezeV13=(t,n)=>(o(n),(0,e.squeeze)(t,[n[0]],Array.from(n[1].integerData))),e.parseSqueezeAttributes=t=>t.attributes.getInts("axes");const i=t=>{if(!t||1!==t.length)throw new Error("Squeeze requires 1 input.");if("string"===t[0].type)throw new Error("invalid input tensor types.")},o=t=>{if(!t||2!==t.length)throw new Error("Squeeze requires 2 inputs.");if("int32"!==t[1].type)throw new Error("Invalid input type.")}},6558:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sum=void 0;const r=n(5060),i=n(2039);e.sum=(t,e)=>{a(e);const n={name:"Sum",inputNames:e.map(((t,e)=>`X${e}`)),inputTypes:new Array(e.length).fill(i.TextureType.unpacked)};return[t.run(Object.assign(Object.assign({},n),{get:()=>o(t,e,n)}),e)]};const o=(t,e,n)=>{const o=(0,r.getGlsl)(t.session.backend.glContext.version),a=e[0].dims.slice(),s=`\n void main() {\n vec4 result = ${e.map(((t,e)=>`${o.texture2D}(X${e},TexCoords)`)).join(" + ")};\n ${o.output} = result;\n }\n `;return Object.assign(Object.assign({},n),{output:{dims:a,type:e[0].type,textureType:i.TextureType.unpacked},hasMain:!0,shaderSource:s})},a=t=>{if(!t||0===t.length)throw new Error("Sum requires inputs.");const e=t[0].dims.length;for(let n=1;n{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.tile=void 0;const r=n(782),i=n(2039);e.tile=(t,e)=>{a(e);const n={name:"Tile",inputNames:["A"],inputTypes:[i.TextureType.unpacked]};return[t.run(Object.assign(Object.assign({},n),{get:()=>o(t,e,n)}),e)]};const o=(t,e,n)=>{const r=e[0].dims.slice(),o=new Array(r.length),a=[];for(let t=0;t{if(!t||2!==t.length)throw new Error("Tile requires 2 input.");if(1!==t[1].dims.length)throw new Error("The second input shape must 1 dimension.");if(t[1].dims[0]!==t[0].dims.length)throw new Error("Invalid input shape.");if(-1===r.NUMBER_TYPES.indexOf(t[0].type))throw new Error("Invalid input type.");if("int32"!==t[1].type&&"int16"!==t[1].type)throw new Error("Invalid repeat type.")}},3738:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseTransposeAttributes=e.transpose=void 0;const r=n(246),i=n(2517),o=n(2039),a={name:"Transpose",inputNames:["A"],inputTypes:[o.TextureType.unpacked]};e.transpose=(t,e,n)=>(p(e),[t.run(Object.assign(Object.assign({},a),{cacheHint:n.cacheKey,get:()=>s(t,e[0],n.perm)}),e)]),e.parseTransposeAttributes=t=>(0,r.createAttributeWithCacheKey)({perm:t.attributes.getInts("perm",[])});const s=(t,e,n)=>{const r=e.dims;n=u(r,n);const i=c(r,n),s=r.length,p=`\n ${l("perm",n,s)}\n float process(int indices[${s}]) {\n int a[${s}];\n perm(a, indices);\n return _A(a);\n }`;return Object.assign(Object.assign({},a),{output:{dims:i,type:e.type,textureType:o.TextureType.unpacked},shaderSource:p})},u=(t,e)=>(e&&e.length!==t.length&&(e=[...t.keys()].reverse()),e),c=(t,e)=>(e=u(t,e),i.ShapeUtil.sortBasedOnPerm(t,e)),l=(t,e,n)=>{const r=[];r.push(`void ${t}(out int a[${n}], int src[${n}]) {`);for(let t=0;t{if(!t||1!==t.length)throw new Error("Transpose requires 1 input.");if("float32"!==t[0].type&&"float64"!==t[0].type)throw new Error("input should be float tensor")}},8710:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.encodeAsUint8=void 0;const r=n(5060),i=n(2039);e.encodeAsUint8=(t,e)=>{const n=e.shape,o=(0,r.getGlsl)(t.session.backend.glContext.version),a=`\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n bool isNaN(float val) {\n return (val < 1.0 || 0.0 < val || val == 0.0) ? false : true;\n }\n\n highp vec4 encodeAsUint8(highp float v) {\n if (isNaN(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n\n void main() {\n float value = ${o.texture2D}(X,TexCoords).r;\n ${o.output} = encodeAsUint8(value);\n }`,s={name:"Uint8Encode",inputTypes:[i.TextureType.unpacked],inputNames:["X"],output:{dims:n,type:e.tensor.type,textureType:i.TextureType.downloadUint8AsFloat},shaderSource:a,hasMain:!0};return t.executeProgram(s,[e.tensor])}},4909:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.tanh=e.tan=e.sqrt=e.sin=e.sigmoid=e.relu=e.not=e.neg=e.log=e.parseLeakyReluAttributes=e.leakyRelu=e.identity=e.floor=e.exp=e.parseEluAttributes=e.elu=e.cos=e.ceil=e.clipV11=e.parseClipAttributes=e.clip=e.atan=e.asin=e.acos=e.abs=e.glslTanh=e.glslTan=e.glslSqrt=e.glslSigmoid=e.glslRelu=e.glslSin=e.glslNot=e.glslNeg=e.glslLog=e.glslLeakyRelu=e.glslIdentity=e.glslClip=e.glslFloor=e.glslExp=e.glslElu=e.glslCos=e.glslCeil=e.glslAtan=e.glslAsin=e.glslAcos=e.glslAbs=void 0;const r=n(246),i=n(2517),o=n(8520),a=n(5060),s=n(2039);function u(){return P("abs")}function c(){return P("acos")}function l(){return P("asin")}function p(){return P("atan")}function f(){return P("ceil")}function d(){return P("cos")}function h(t){const e="elu";return{body:`\n const float alpha = float(${t});\n\n float ${e}_(float a) {\n return a >= 0.0 ? a: (exp(a) - 1.0) * alpha;\n }\n vec4 ${e}_(vec4 v) {\n return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w));\n }\n `,name:e,type:o.FunctionType.ValueBased}}function g(){return P("exp")}function b(){return P("floor")}function m(t,e){const n="clip";return{body:`\n const float min = float(${t});\n const float max = float(${e});\n\n float ${n}_(float a) {\n return clamp(a, min, max);\n }\n vec4 ${n}_(vec4 v) {\n return clamp(v, min, max);\n }\n `,name:n,type:o.FunctionType.ValueBased}}function y(){const t="indentity";return{body:`\n float ${t}_(float a) {\n return a;\n }\n vec4 ${t}_(vec4 v) {\n return v;\n }\n `,name:t,type:o.FunctionType.ValueBased}}function _(t){const e="leakyRelu";return{body:`\n const float alpha = float(${t});\n\n float ${e}_(float a) {\n return a < 0.0 ? a * alpha : a;\n }\n vec4 ${e}_(vec4 v) {\n return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w));\n }\n `,name:e,type:o.FunctionType.ValueBased}}function v(){return P("log")}function w(){const t="neg";return{body:`\n float ${t}_(float a) {\n return -a;\n }\n vec4 ${t}_(vec4 v) {\n return -v;\n }\n `,name:t,type:o.FunctionType.ValueBased}}function x(){const t="not";return{body:`\n float ${t}_(float a) {\n return float( ! bool(a) );\n }\n bool ${t}_(bool a) {\n return !a;\n }\n vec4 ${t}_(vec4 v) {\n return vec4(!bool(v.x), !bool(v.y), !bool(v.z), !bool(v.w));\n }\n bvec4 ${t}_(bvec4 v) {\n return bvec4(!v.x, !v.y, !v.z, !v.w);\n }\n `,name:t,type:o.FunctionType.ValueBased}}function T(){return P("sin")}function S(){const t="relu";return{body:`\n float ${t}_(float a) {\n return max( a, 0.0 );\n }\n vec4 ${t}_(vec4 v) {\n return max( v, 0.0 );\n }\n `,name:t,type:o.FunctionType.ValueBased}}function O(){const t="sigmoid";return{body:`\n float ${t}_(float a) {\n return 1.0 / (1.0 + exp(-a));\n }\n vec4 ${t}_(vec4 v) {\n return 1.0 / (1.0 + exp(-v));\n }\n `,name:t,type:o.FunctionType.ValueBased}}function A(){return P("sqrt")}function E(){return P("tan")}function I(){const t="tanh";return{body:`\n float ${t}_(float a) {\n a = clamp(a, -10., 10.);\n a = exp(2.*a);\n return (a - 1.) / (a + 1.);\n }\n vec4 ${t}_(vec4 v) {\n v = clamp(v, -10., 10.);\n v = exp(2.*v);\n return (v - 1.) / (v + 1.);\n }\n `,name:t,type:o.FunctionType.ValueBased}}function P(t){return{body:`\n float ${t}_(float a) {\n return ${t}(a);\n }\n vec4 ${t}_(vec4 v) {\n return ${t}(v);\n }\n `,name:t,type:o.FunctionType.ValueBased}}e.glslAbs=u,e.glslAcos=c,e.glslAsin=l,e.glslAtan=p,e.glslCeil=f,e.glslCos=d,e.glslElu=h,e.glslExp=g,e.glslFloor=b,e.glslClip=m,e.glslIdentity=y,e.glslLeakyRelu=_,e.glslLog=v,e.glslNeg=w,e.glslNot=x,e.glslSin=T,e.glslRelu=S,e.glslSigmoid=O,e.glslSqrt=A,e.glslTan=E,e.glslTanh=I;const D=(t,e,n,r)=>{const i=t.session.pack?s.TextureType.packed:s.TextureType.unpacked,o={name:n.name,inputTypes:[i],inputNames:["A"],cacheHint:r};return Object.assign(Object.assign({},o),{get:()=>((t,e,n,r)=>{const i=t.session.pack?s.TextureType.packed:s.TextureType.unpacked,o=(0,a.getGlsl)(t.session.backend.glContext.version);return Object.assign(Object.assign({},e),{output:{dims:n.dims,type:n.type,textureType:i},shaderSource:`\n ${r.body}\n void main() {\n vec4 v = ${o.texture2D}(A, TexCoords);\n v = ${r.name}_(v);\n ${o.output} = v;\n }\n `,hasMain:!0})})(t,o,e,n)})};e.abs=(t,e)=>[t.run(D(t,e[0],u()),e)],e.acos=(t,e)=>[t.run(D(t,e[0],c()),e)],e.asin=(t,e)=>[t.run(D(t,e[0],l()),e)],e.atan=(t,e)=>[t.run(D(t,e[0],p()),e)],e.clip=(t,e,n)=>[t.run(D(t,e[0],m(n.min,n.max),n.cacheKey),e)],e.parseClipAttributes=t=>(0,r.createAttributeWithCacheKey)({min:t.attributes.getFloat("min",i.MIN_CLIP),max:t.attributes.getFloat("max",i.MAX_CLIP)}),e.clipV11=(t,n)=>{const r=$(t,n);return(0,e.clip)(t,[n[0]],r)};const $=(t,e)=>{if(e.length>=3&&(!t.session.isInitializer(e[1].dataId)||!t.session.isInitializer(e[2].dataId)))throw new Error("dynamic clip attributes are not allowed");const n=e.length>=3?e[1].numberData[0]:i.MIN_CLIP,o=e.length>=3?e[2].numberData[0]:i.MAX_CLIP;return(0,r.createAttributeWithCacheKey)({min:n,max:o})};e.ceil=(t,e)=>[t.run(D(t,e[0],f()),e)],e.cos=(t,e)=>[t.run(D(t,e[0],d()),e)],e.elu=(t,e,n)=>[t.run(D(t,e[0],h(n.alpha),n.cacheKey),e)],e.parseEluAttributes=t=>(0,r.createAttributeWithCacheKey)({alpha:t.attributes.getFloat("alpha",1)}),e.exp=(t,e)=>[t.run(D(t,e[0],g()),e)],e.floor=(t,e)=>[t.run(D(t,e[0],b()),e)],e.identity=(t,e)=>[t.run(D(t,e[0],y()),e)],e.leakyRelu=(t,e,n)=>[t.run(D(t,e[0],_(n.alpha),n.cacheKey),e)],e.parseLeakyReluAttributes=t=>(0,r.createAttributeWithCacheKey)({alpha:t.attributes.getFloat("alpha",.01)}),e.log=(t,e)=>[t.run(D(t,e[0],v()),e)],e.neg=(t,e)=>[t.run(D(t,e[0],w()),e)],e.not=(t,e)=>[t.run(D(t,e[0],x()),e)],e.relu=(t,e)=>[t.run(D(t,e[0],S()),e)],e.sigmoid=(t,e)=>[t.run(D(t,e[0],O()),e)],e.sin=(t,e)=>[t.run(D(t,e[0],T()),e)],e.sqrt=(t,e)=>[t.run(D(t,e[0],A()),e)],e.tan=(t,e)=>[t.run(D(t,e[0],E()),e)],e.tanh=(t,e)=>[t.run(D(t,e[0],I()),e)]},5611:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createUnpackProgramInfoLoader=e.createUnpackProgramInfo=void 0;const r=n(5060),i=n(2039),o=n(9390),a=n(2827),s={name:"unpack",inputNames:["A"],inputTypes:[i.TextureType.packed]};e.createUnpackProgramInfo=(t,e)=>{const n=e.dims.length,u=(0,a.getChannels)("rc",n),c=u.slice(-2),l=(0,o.getCoordsDataType)(n),p=(0,a.unpackFromChannel)(),f=0===e.dims.length?"":function(t,e){if(1===t)return"rc";let n="";for(let r=0;rObject.assign(Object.assign({},s),{get:()=>(0,e.createUnpackProgramInfo)(t,n)})},8428:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.parseUnsqueezeAttributes=e.unsqueezeV13=e.unsqueeze=void 0;const r=n(2517);e.unsqueeze=(t,e,n)=>{i(e);const o=r.ShapeUtil.unsqueezeShape(e[0].dims,n);return[t.reshapeUnpacked(e[0],o)]},e.unsqueezeV13=(t,n)=>(o(n),(0,e.unsqueeze)(t,[n[0]],Array.from(n[1].integerData))),e.parseUnsqueezeAttributes=t=>t.attributes.getInts("axes");const i=t=>{if(!t||1!==t.length)throw new Error("Unsqueeze requires 1 input.");if("string"===t[0].type)throw new Error("invalid input tensor types.")},o=t=>{if(!t||2!==t.length)throw new Error("Unsqueeze requires 2 inputs.");if("int32"!==t[1].type)throw new Error("Invalid input type.")}},9793:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.scalesValidation=e.validateInputs=e.parseUpsampleAttributes=e.parseUpsampleAttributesV9=e.parseUpsampleAttributesV7=e.upsample=void 0;const r=n(246),i=n(5060),o=n(2039),a={name:"Upsample",inputNames:["X"],inputTypes:[o.TextureType.unpacked]};e.upsample=(t,n,r)=>((0,e.validateInputs)(n,r),[t.run(Object.assign(Object.assign({},a),{cacheHint:r.cacheKey,get:()=>s(t,n,r)}),n)]),e.parseUpsampleAttributesV7=t=>(0,e.parseUpsampleAttributes)(t,7),e.parseUpsampleAttributesV9=t=>(0,e.parseUpsampleAttributes)(t,9),e.parseUpsampleAttributes=(t,n)=>{const i=n>=10,o=t.attributes.getString("mode","nearest");if("nearest"!==o&&"linear"!==o&&(n<11||"cubic"!==o))throw new Error(`unrecognized mode: ${o}`);let a=[];n<9&&(a=t.attributes.getFloats("scales"),(0,e.scalesValidation)(a,o,i));const s=t.attributes.getFloat("extrapolation_value",0),u=n>10?t.attributes.getString("coordinate_transformation_mode","half_pixel"):"asymmetric";if(-1===["asymmetric","pytorch_half_pixel","tf_half_pixel_for_nn","align_corners","tf_crop_and_resize","half_pixel"].indexOf(u))throw new Error(`coordinate_transform_mode '${u}' is not supported`);const c="tf_crop_and_resize"===u,l=c,p="nearest"===o&&n>=11?t.attributes.getString("nearest_mode","round_prefer_floor"):"";if(-1===["round_prefer_floor","round_prefer_ceil","floor","ceil",""].indexOf(p))throw new Error(`nearest_mode '${p}' is not supported`);const f=t.attributes.getFloat("cubic_coeff_a",-.75),d=0!==t.attributes.getInt("exclude_outside",0);if(d&&"cubic"!==o)throw new Error("exclude_outside can be set to 1 only when mode is CUBIC.");const h=n<11||"nearest"===o&&"asymmetric"===u&&"floor"===p;let g=0,b=0,m=0;return n>10?t.inputs.length>2?(g=1,b=2,m=3):(b=1,m=2):9===n&&(b=1),(0,r.createAttributeWithCacheKey)({opset:n,isResize:i,mode:o,scales:a,extrapolationValue:s,coordinateTransformMode:u,useExtrapolation:l,needRoiInput:c,nearestMode:p,cubicCoefficientA:f,excludeOutside:d,useNearest2xOptimization:h,roiInputIdx:g,scalesInputIdx:b,sizesInputIdx:m})};const s=(t,e,n)=>{const r=(0,i.getGlsl)(t.session.backend.glContext.version),[s,u]=t.calculateTextureWidthAndHeight(e[0].dims,o.TextureType.unpacked),c=e[0].dims.map(((t,e)=>Math.floor(t*n.scales[e]))),[l,p]=t.calculateTextureWidthAndHeight(c,o.TextureType.unpacked),f=c.length,d=new Array(f),h=new Array(f);let g=`\n int output_pitches[${f}];\n int input_pitches[${f}];\n `;for(let t=f-1;t>=0;t--)d[t]=t===f-1?1:d[t+1]*c[t+1],h[t]=t===f-1?1:h[t+1]*e[0].dims[t+1],g+=`\n output_pitches[${t}] = ${d[t]};\n input_pitches[${t}] = ${h[t]};\n `;const b=`\n float getInputFloat(int index) {\n vec2 coords = offsetToCoords(index, ${s}, ${u});\n float value = getColorAsFloat(${r.texture2D}(X, coords));\n return value;\n }\n `,m="nearest"===n.mode?`\n ${b}\n float process(int indices[${f}]) {\n int input_index = 0;\n int output_index = coordsToOffset(TexCoords, ${l}, ${p});\n\n ${g}\n\n int d, m;\n for (int dim = 0; dim < ${f}; ++dim) {\n d = output_index / output_pitches[dim];\n m = output_index - d * output_pitches[dim];\n output_index = m;\n\n if (scales[dim] != 1 && d > 0) {\n int d2 = d / scales[dim];\n m = d - d2 * scales[dim];\n d = d2;\n }\n input_index += input_pitches[dim] * d;\n }\n\n return getInputFloat(input_index);\n }`:4===f?`\n ${b}\n float process(int indices[4]) {\n int input_index = 0;\n int output_index = coordsToOffset(TexCoords, ${l}, ${p});\n\n ${g}\n\n int m;\n int index_of_dim0, index_of_dim1, index_of_dim2, index_of_dim3;\n index_of_dim0 = output_index / output_pitches[0];\n m = output_index - index_of_dim0 * output_pitches[0];\n index_of_dim1 = m / output_pitches[1];\n m = m - index_of_dim1 * output_pitches[1];\n index_of_dim2 = m / output_pitches[2];\n m = m - index_of_dim2 * output_pitches[2];\n index_of_dim3 = m;\n\n int index_of_input_dim2, index_of_input_dim3, x_offset, y_offset;\n index_of_input_dim2 = index_of_dim2 / scales[2];\n y_offset = index_of_dim2 - index_of_input_dim2 * scales[2];\n index_of_input_dim3 = index_of_dim3 / scales[3];\n x_offset = index_of_dim3 - index_of_input_dim3 * scales[3];\n\n input_index = index_of_dim0 * input_pitches[0] +\n index_of_dim1 * input_pitches[1] +\n index_of_input_dim2 * input_pitches[2] +\n index_of_input_dim3;\n\n float x00 = getInputFloat(input_index);\n float x10, x01, x11;\n\n bool end_of_dim2 = false;\n if (index_of_input_dim2 == (${e[0].dims[2]} - 1)) {\n // It's the end in dimension 2\n x01 = x00;\n end_of_dim2 = true;\n } else {\n x01 = getInputFloat(input_index + input_pitches[2]);\n }\n\n if (index_of_input_dim3 == (input_pitches[2] - 1)) {\n // It's the end in dimension 3\n x10 = x00;\n x11 = x01;\n }\n else {\n x10 = getInputFloat(input_index + 1);\n x11 = end_of_dim2 ? x10 : getInputFloat(input_index + input_pitches[2] + 1);\n }\n\n float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[2]);\n float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[2]);\n return y0 + float(x_offset) * (y1 - y0) / float(scales[3]);\n }`:`\n ${b}\n float process(int indices[2]) {\n int input_index = 0;\n int output_index = coordsToOffset(TexCoords, ${l}, ${p});\n\n ${g}\n\n int m;\n int index_of_dim0, index_of_dim1;\n index_of_dim0 = output_index / output_pitches[0];\n m = output_index - index_of_dim0 * output_pitches[0];\n index_of_dim1 = m;\n\n int index_of_input_dim0, index_of_input_dim1, x_offset, y_offset;\n index_of_input_dim0 = index_of_dim0 / scales[0];\n y_offset = index_of_dim0 - index_of_input_dim0 * scales[0];\n index_of_input_dim1 = index_of_dim1 / scales[1];\n x_offset = index_of_dim1 - index_of_input_dim1 * scales[1];\n\n input_index = index_of_input_dim0 * input_pitches[0] + index_of_input_dim1;\n\n float x00 = getInputFloat(input_index);\n float x10, x01, x11;\n\n bool end_of_dim0 = false;\n if (index_of_input_dim0 == (${e[0].dims[0]} - 1)) {\n // It's the end in dimension 0\n x01 = x00;\n end_of_dim0 = true;\n } else {\n x01 = getInputFloat(input_index + input_pitches[0]);\n }\n\n if (index_of_input_dim1 == (input_pitches[0] - 1)) {\n // It's the end in dimension 1\n x10 = x00;\n x11 = x01;\n }\n else {\n x10 = getInputFloat(input_index + 1);\n x11 = end_of_dim0 ? x10 : getInputFloat(input_index + input_pitches[0] + 1);\n }\n\n float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[0]);\n float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[0]);\n return y0 + float(x_offset) * (y1 - y0) / float(scales[1]);\n }`;return Object.assign(Object.assign({},a),{output:{dims:c,type:e[0].type,textureType:o.TextureType.unpacked},shaderSource:m,variables:[{name:"scales",type:"int",arrayLength:n.scales.length,data:n.scales.map((t=>Math.ceil(t)))}]})};e.validateInputs=(t,e)=>{if(!t||e.opset<9&&1!==t.length||e.opset>=9&&e.opset<11&&2!==t.length||e.opset>=11&&t.length<2)throw new Error("invalid inputs.");if(e.scales.length>0&&t[0].dims.length!==e.scales.length)throw new Error("Invalid input shape.");if("string"===t[0].type)throw new Error("Invalid input tensor types.")},e.scalesValidation=(t,e,n)=>{if(n){for(const e of t)if(e<=0)throw new Error("Scale value should be greater than 0.")}else for(const e of t)if(e<1)throw new Error("Scale value should be greater than or equal to 1.");if(!("linear"!==e&&"cubic"!==e||2===t.length||4===t.length&&1===t[0]&&1===t[1]))throw new Error(`'Linear' mode and 'Cubic' mode only support 2-D inputs ('Bilinear', 'Bicubic') or 4-D inputs with the corresponding outermost 2 scale values being 1 in the ${n?"Resize":"Upsample"} opeartor.`)}},1958:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ProgramManager=void 0;const r=n(8453),i=n(6231),o=n(8879),a=n(5060);e.ProgramManager=class{constructor(t,e,n){this.profiler=t,this.glContext=e,this.textureLayoutStrategy=n,this.repo=new Map,this.attributesBound=!1}getArtifact(t){return this.repo.get(t)}setArtifact(t,e){this.repo.set(t,e)}run(t,e,n){var r;this.profiler.event("op",`ProgramManager.run ${null!==(r=t.programInfo.name)&&void 0!==r?r:"unknown kernel"}`,(()=>{var r;const o=this.glContext.gl,a=t.program;o.useProgram(a);try{this.bindOutput(n),this.attributesBound||this.bindAttributes(t.attribLocations),this.bindUniforms(t.uniformLocations,null!==(r=t.programInfo.variables)&&void 0!==r?r:[],e)}catch(e){throw i.Logger.error("ProgramManager",t.programInfo.shaderSource),e}this.profiler.event("backend","GlContext.draw()",(()=>{this.glContext.draw()}))}),this.glContext)}dispose(){this.vertexShader&&this.glContext.deleteShader(this.vertexShader),this.repo.forEach((t=>this.glContext.deleteProgram(t.program)))}build(t,e,n){return this.profiler.event("backend","ProgramManager.build",(()=>{const r=new o.GlslPreprocessor(this.glContext,t,e,n),i=r.preprocess(),a=this.compile(i);return{programInfo:t,program:a,uniformLocations:this.getUniformLocations(a,r.context.programInfo.inputNames,r.context.programInfo.variables),attribLocations:this.getAttribLocations(a)}}))}compile(t){if(!this.vertexShader){i.Logger.verbose("ProrgramManager","Compiling and caching Vertex shader for the first time");const t=(0,a.getVertexShaderSource)(this.glContext.version);this.vertexShader=this.glContext.compileShader(t,this.glContext.gl.VERTEX_SHADER)}r.env.debug&&i.Logger.verbose("ProrgramManager",`FragShader:\n${t}\n`);const e=this.glContext.compileShader(t,this.glContext.gl.FRAGMENT_SHADER),n=this.glContext.createProgram(this.vertexShader,e);return this.glContext.deleteShader(e),n}bindOutput(t){const e=t.width,n=t.height;i.Logger.verbose("ProrgramManager",`Binding output texture to Framebuffer: w/h=${e}/${n}, shape=${t.shape}, type=${t.tensor.type}`),this.glContext.attachFramebuffer(t.texture,e,n)}bindAttributes(t){const e=t.position,n=t.textureCoord;this.glContext.setVertexAttributes(e,n),this.attributesBound=!0}bindUniforms(t,e,n){var r;const i=this.glContext.gl;let o=0;for(const{name:a,type:s,location:u,arrayLength:c}of t){const t=null===(r=e.find((t=>t.name===a)))||void 0===r?void 0:r.data;if("sampler2D"!==s&&!t)throw new Error(`variable '${a}' does not have data defined in program info`);switch(s){case"sampler2D":this.bindTexture(n[o],u,o),o++;break;case"float":c?i.uniform1fv(u,t):i.uniform1f(u,t);break;case"int":c?i.uniform1iv(u,t):i.uniform1i(u,t);break;default:throw new Error(`Uniform not implemented: ${s}`)}}}bindTexture(t,e,n){this.glContext.bindTextureToUniform(t.texture,n,e)}getAttribLocations(t){return{position:this.getAttribLocation(t,"position"),textureCoord:this.getAttribLocation(t,"textureCoord")}}getUniformLocations(t,e,n){const r=[];if(e)for(const n of e)r.push({name:n,type:"sampler2D",location:this.getUniformLocation(t,n)});if(n)for(const e of n)r.push(Object.assign(Object.assign({},e),{location:this.getUniformLocation(t,e.name)}));return r}getUniformLocation(t,e){const n=this.glContext.gl.getUniformLocation(t,e);if(null===n)throw new Error(`Uniform ${e} not found.`);return n}getAttribLocation(t,e){return this.glContext.gl.getAttribLocation(t,e)}}},6416:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLSessionHandler=void 0;const r=n(6231),i=n(1047),o=n(8316),a=n(1640),s=n(1958),u=n(7859),c=n(5702);e.WebGLSessionHandler=class{constructor(t,e){this.backend=t,this.context=e,this.layoutStrategy=new u.PreferLogicalStrategy(t.glContext.maxTextureSize),this.programManager=new s.ProgramManager(this.context.profiler,t.glContext,this.layoutStrategy),this.textureManager=new c.TextureManager(t.glContext,this.layoutStrategy,this.context.profiler,{reuseTextures:"full"===t.textureCacheMode}),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map,this.pack=t.pack,this.pack2unpackMap=new Map,this.unpack2packMap=new Map}createInferenceHandler(){return new o.WebGLInferenceHandler(this)}onGraphInitialized(t){const e=t.getValues().filter((t=>-1===t.from&&t.tensor)).map((t=>t.tensor.dataId));this.initializers=new Set(e)}isInitializer(t){return!!this.initializers&&this.initializers.has(t)}addInitializer(t){this.initializers.add(t)}getTextureData(t,e){return e?this.packedTextureDataCache.get(t):this.unpackedTextureDataCache.get(t)}setTextureData(t,e,n=!1){r.Logger.verbose("WebGLSessionHandler","Storing Texture data in cache"),n?this.packedTextureDataCache.set(t,e):this.unpackedTextureDataCache.set(t,e)}dispose(){this.programManager.dispose(),this.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach((t=>this.textureManager.releaseTexture(t,!0))),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach((t=>this.textureManager.releaseTexture(t,!0))),this.unpackedTextureDataCache=new Map}resolve(t,e,n){const r=(0,i.resolveOperator)(t,e,a.WEBGL_OP_RESOLVE_RULES);return{impl:r.opImpl,context:r.opInit?r.opInit(t,n):t}}}},7769:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Uint8DataEncoder=e.RGBAFloatDataEncoder=e.RedFloat32DataEncoder=void 0;const r=n(6231);e.RedFloat32DataEncoder=class{constructor(t,e=1){if(1===e)this.internalFormat=t.R32F,this.format=t.RED,this.textureType=t.FLOAT,this.channelSize=e;else{if(4!==e)throw new Error(`Invalid number of channels: ${e}`);this.internalFormat=t.RGBA32F,this.format=t.RGBA,this.textureType=t.FLOAT,this.channelSize=e}}encode(t,e){let n,i;return t.constructor!==Float32Array&&(r.Logger.warning("Encoder","data was not of type Float32; creating new Float32Array"),i=new Float32Array(t)),e*this.channelSize>t.length?(r.Logger.warning("Encoder","Source data too small. Allocating larger array"),i=t,n=this.allocate(e*this.channelSize),i.forEach(((t,e)=>n[e]=t))):(i=t,n=i),n}allocate(t){return new Float32Array(4*t)}decode(t,e){return 1===this.channelSize?t.filter(((t,e)=>e%4==0)).subarray(0,e):t.subarray(0,e)}},e.RGBAFloatDataEncoder=class{constructor(t,e=1,n){if(1!==e&&4!==e)throw new Error(`Invalid number of channels: ${e}`);this.internalFormat=t.RGBA,this.format=t.RGBA,this.channelSize=e,this.textureType=n||t.FLOAT}encode(t,e){let n=t;return 1===this.channelSize&&(r.Logger.verbose("Encoder","Exploding into a larger array"),n=this.allocate(e),t.forEach(((t,e)=>n[4*e]=t))),n}allocate(t){return new Float32Array(4*t)}decode(t,e){return 1===this.channelSize?t.filter(((t,e)=>e%4==0)).subarray(0,e):t.subarray(0,e)}},e.Uint8DataEncoder=class{constructor(t,e=1){if(this.channelSize=4,1===e)this.internalFormat=t.ALPHA,this.format=t.ALPHA,this.textureType=t.UNSIGNED_BYTE,this.channelSize=e;else{if(4!==e)throw new Error(`Invalid number of channels: ${e}`);this.internalFormat=t.RGBA,this.format=t.RGBA,this.textureType=t.UNSIGNED_BYTE,this.channelSize=e}}encode(t,e){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}allocate(t){return new Uint8Array(t*this.channelSize)}decode(t,e){if(t instanceof Uint8Array)return t.subarray(0,e);throw new Error(`Invalid array type: ${t.constructor}`)}}},7859:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getBatchDim=e.sizeToSquarishShape=e.getRowsCols=e.sizeFromShape=e.isInt=e.parseAxisParam=e.squeezeShape=e.PreferLogicalStrategy=e.AlwaysKeepOriginalSizeStrategy=void 0;const r=n(6231),i=n(2517);function o(t,e){const n=[],r=[],i=null!=e&&Array.isArray(e)&&0===e.length,o=null==e||i?null:a(e,t).sort();let s=0;for(let e=0;ee)&&1===t[e]&&(n.push(t[e]),r.push(e)),o[s]<=e&&s++}1!==t[e]&&(n.push(t[e]),r.push(e))}return{newShape:n,keptDims:r}}function a(t,e){const n=e.length;return t=null==t?e.map(((t,e)=>e)):[].concat(t),(0,i.assert)(t.every((t=>t>=-n&&t`All values in axis param must be in range [-${n}, ${n}) but got axis ${t}`)),(0,i.assert)(t.every(s),(()=>`All values in axis param must be integers but got axis ${t}`)),t.map((t=>t<0?n+t:t))}function s(t){return t%1==0}function u(t){if(0===t.length)return 1;let e=t[0];for(let n=1;n=t.length?1:t.slice(e.breakAxis).reduce(((t,e)=>t*e)),o=e.breakAxis<=0?1:t.slice(0,e.breakAxis).reduce(((t,e)=>t*e));if(!(i>n||o>n))return[i,o];r.Logger.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${t}, breakAxis:${e.breakAxis}`)}const i=t.reduce(((t,e)=>t*e));let o=Math.floor(Math.sqrt(i));for(;o=n||i%o!=0)throw new Error(`The given dimensions are outside this GPU's boundaries: ${t}`);return[o,i/o]}},e.PreferLogicalStrategy=class{constructor(t){this.maxTextureSize=t}computeTextureWH(t,e){const n=this.computeTexture(t,e);return e&&e.isPacked&&(n[0]/=2,n[1]/=2),e&&e.reverseWH?[n[1],n[0]]:n}computeTexture(t,e){const n=e&&e.isPacked;if(0===t.length)return n?[2,2]:[1,1];let i=this.maxTextureSize;if(e&&void 0!==e.breakAxis){const n=e.breakAxis>=t.length?1:t.slice(e.breakAxis).reduce(((t,e)=>t*e)),o=e.breakAxis<=0?1:t.slice(0,e.breakAxis).reduce(((t,e)=>t*e));if(!(n>i||o>i))return[n,o];r.Logger.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${t}, breakAxis:${e.breakAxis}`)}let a=t.slice(0);if(n&&(i*=2,a=a.map(((t,e)=>e>=a.length-2?a[e]%2==0?a[e]:a[e]+1:a[e])),1===a.length&&(a=[2,a[0]])),2!==a.length){const t=o(a);a=t.newShape}const s=u(a);return a.length<=1&&s<=i?[1,s]:2===a.length&&a[0]<=i&&a[1]<=i?a:3===a.length&&a[0]*a[1]<=i&&a[2]<=i?[a[0]*a[1],a[2]]:3===a.length&&a[0]<=i&&a[1]*a[2]<=i?[a[0],a[1]*a[2]]:4===a.length&&a[0]*a[1]*a[2]<=i&&a[3]<=i?[a[0]*a[1]*a[2],a[3]]:4===a.length&&a[0]<=i&&a[1]*a[2]*a[3]<=i?[a[0],a[1]*a[2]*a[3]]:n?c(s/4).map((t=>2*t)):c(s)}},e.squeezeShape=o,e.parseAxisParam=a,e.isInt=s,e.sizeFromShape=u,e.getRowsCols=function(t){if(0===t.length)throw Error("Cannot get rows and columns of an empty shape array.");return[t.length>1?t[t.length-2]:1,t[t.length-1]]},e.sizeToSquarishShape=c,e.getBatchDim=function(t,e=2){return u(t.slice(0,t.length-e))}},4057:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createTextureLayoutFromShape=e.calculateTextureWidthAndHeight=e.createTextureLayoutFromTextureType=void 0;const r=n(2517),i=n(2039);e.createTextureLayoutFromTextureType=(t,n,r)=>{const o=r===i.TextureType.unpacked||r===i.TextureType.unpackedReversed?1:4,a=r===i.TextureType.packed,s=r===i.TextureType.unpackedReversed||r===i.TextureType.packed,u=r===i.TextureType.packedLastDimension?n.length-1:void 0,c=r===i.TextureType.packedLastDimension?n.map(((t,e)=>e===n.length-1?4*t:t)):void 0;return(0,e.createTextureLayoutFromShape)(t,n,o,c,{isPacked:a,reverseWH:s,breakAxis:u})},e.calculateTextureWidthAndHeight=(t,n,r)=>{const i=(0,e.createTextureLayoutFromTextureType)(t,n,r);return[i.width,i.height]},e.createTextureLayoutFromShape=(t,e,n=1,i,o)=>{const a=!(!o||!o.isPacked),[s,u]=t.computeTextureWH(a&&i||e,o),c=e.length;let l=e.slice(0);if(0===c&&(l=[1]),1===n)i=e;else if(a){if(4!==n)throw new Error("a packed texture must be 4-channel");i=e,c>0&&(l[c-1]=Math.ceil(l[c-1]/2)),c>1&&(l[c-2]=Math.ceil(l[c-2]/2))}else if(!i)throw new Error("Unpacked shape is needed when using channels > 1");return{width:s,height:u,channels:n,isPacked:a,shape:l,strides:r.ShapeUtil.computeStrides(l),unpackedShape:i,reversedWH:o&&o.reverseWH}}},5702:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.TextureManager=void 0;const r=n(6231);e.TextureManager=class{constructor(t,e,n,r){this.glContext=t,this.layoutStrategy=e,this.profiler=n,this.config=r,this.pendingRead=new Map,r.reuseTextures&&(this.inUseTextures=new Map,this.idleTextures=new Map,this.textureLookup=new Map)}createTextureFromLayout(t,e,n,i){const o=this.toEncoderType(t),a=this.glContext.getEncoder(o,e.channels||1,i);if(e.isPacked&&1===i)throw new Error("not implemented");const s=e.width,u=e.height;let c,l;if(this.config.reuseTextures){c=`${s}x${u}_${a.format}_${a.internalFormat}_${a.textureType}`,l=this.inUseTextures.get(c),l||(l=[],this.inUseTextures.set(c,l));const e=this.idleTextures.get(c);if(e&&e.length>0){const r=e.pop();return l.push(r),1===i&&this.glContext.updateTexture(r,s,u,a,this.toTextureData(t,n)),r}}r.Logger.verbose("TextureManager",`Creating new texture of size ${e.width}x${e.height}`);const p=this.glContext.allocateTexture(s,u,a,this.toTextureData(t,n));return this.config.reuseTextures&&(l.push(p),this.textureLookup.set(p,c)),p}readTexture(t,e,n){return n||(n=1),this.profiler.event("backend","TextureManager.readTexture",(()=>{const r=t.shape.reduce(((t,e)=>t*e))*n,i=this.glContext.readTexture(t.texture,t.width,t.height,r,this.toEncoderType(e),n);return this.toTensorData(e,i)}))}async readTextureAsync(t,e,n){const r=t.tensor.dataId;if(n||(n=1),this.pendingRead.has(r)){const t=this.pendingRead.get(r);return new Promise((e=>null==t?void 0:t.push(e)))}return this.profiler.event("backend","TextureManager.readTextureAsync",(async()=>{this.pendingRead.set(r,[]);const i=t.shape.reduce(((t,e)=>t*e))*n;await this.glContext.createAndWaitForFence();const o=this.glContext.readTexture(t.texture,t.width,t.height,i,this.toEncoderType(e),n),a=this.toTensorData(e,o),s=this.pendingRead.get(r);return this.pendingRead.delete(r),null==s||s.forEach((t=>t(a))),a}))}readUint8TextureAsFloat(t){return this.profiler.event("backend","TextureManager.readUint8TextureAsFloat",(()=>{const e=t.shape.reduce(((t,e)=>t*e)),n=this.glContext.readTexture(t.texture,t.width,t.height,4*e,"byte",4);return new Float32Array(n.buffer,n.byteOffset,e)}))}releaseTexture(t,e){let n;if(this.config.reuseTextures&&(n=this.textureLookup.get(t.texture),n)){e&&this.textureLookup.delete(n);const r=this.inUseTextures.get(n);if(r){const e=r.indexOf(t.texture);if(-1!==e){r.splice(e,1);let i=this.idleTextures.get(n);i||(i=[],this.idleTextures.set(n,i)),i.push(t.texture)}}}n&&!e||(r.Logger.verbose("TextureManager",`Deleting texture of size ${t.width}x${t.height}`),this.glContext.deleteTexture(t.texture))}toTensorData(t,e){switch(t){case"int16":return e instanceof Int16Array?e:Int16Array.from(e);case"int32":return e instanceof Int32Array?e:Int32Array.from(e);case"int8":return e instanceof Int8Array?e:Int8Array.from(e);case"uint16":return e instanceof Uint16Array?e:Uint16Array.from(e);case"uint32":return e instanceof Uint32Array?e:Uint32Array.from(e);case"uint8":case"bool":return e instanceof Uint8Array?e:Uint8Array.from(e);case"float32":return e instanceof Float32Array?e:Float32Array.from(e);case"float64":return e instanceof Float64Array?e:Float64Array.from(e);default:throw new Error(`TensorData type ${t} is not supported`)}}toTextureData(t,e){if(e)return e instanceof Float32Array?e:new Float32Array(e)}toEncoderType(t){return"float"}clearActiveTextures(){this.glContext.clearActiveTextures()}}},2039:(t,e)=>{"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.TextureType=void 0,(n=e.TextureType||(e.TextureType={}))[n.unpacked=0]="unpacked",n[n.unpackedReversed=1]="unpackedReversed",n[n.packed=2]="packed",n[n.downloadUint8AsFloat=3]="downloadUint8AsFloat",n[n.packedLastDimension=4]="packedLastDimension"},9390:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getGlChannels=e.getCoordsDataType=e.getSqueezedParams=e.squeezeInputShape=e.generateShaderFuncNameFromInputSamplerNameAtOutCoords=e.generateShaderFuncNameFromInputSamplerName=e.repeatedTry=e.getPackedShape=void 0;const r=n(2517);e.getPackedShape=function(t){const e=t.length;return t.slice(0,e-1).concat(t[e-1]/4)},e.repeatedTry=async function(t,e=(t=>0),n){return new Promise(((r,i)=>{let o=0;const a=()=>{if(t())return void r();o++;const s=e(o);null!=n&&o>=n?i():setTimeout(a,s)};a()}))},e.generateShaderFuncNameFromInputSamplerName=function(t){return(0,r.assert)(void 0!==t&&0!==t.length,(()=>"empty string found for sampler name")),"get"+t.charAt(0).toUpperCase()+t.slice(1)},e.generateShaderFuncNameFromInputSamplerNameAtOutCoords=function(t){return(0,r.assert)(void 0!==t&&0!==t.length,(()=>"empty string found for sampler name")),"get"+t.charAt(0).toUpperCase()+t.slice(1)+"AtOutCoords"},e.squeezeInputShape=function(t,e){let n=JSON.parse(JSON.stringify(t));return n=e,n},e.getSqueezedParams=function(t,e){return e.map((e=>t[e])).join(", ")},e.getCoordsDataType=function(t){if(t<=1)return"int";if(2===t)return"ivec2";if(3===t)return"ivec3";if(4===t)return"ivec4";if(5===t)return"ivec5";if(6===t)return"ivec6";throw Error(`GPU for rank ${t} is not yet supported`)},e.getGlChannels=function(t=6){return["x","y","z","w","u","v"].slice(0,t)}},7305:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createNewWebGLContext=e.createWebGLContext=void 0;const r=n(6231),i=n(1713),o={};function a(t){const e=function(){if("undefined"==typeof document){if("undefined"==typeof OffscreenCanvas)throw new TypeError("failed to create canvas: OffscreenCanvas is not supported");return new OffscreenCanvas(1,1)}const t=document.createElement("canvas");return t.width=1,t.height=1,t}();let n;const o={alpha:!1,depth:!1,antialias:!1,stencil:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1,failIfMajorPerformanceCaveat:!1};if((!t||"webgl2"===t)&&(n=e.getContext("webgl2",o),n))try{return new i.WebGLContext(n,2)}catch(t){r.Logger.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl2'. Error: ${t}`)}if((!t||"webgl"===t)&&(n=e.getContext("webgl",o)||e.getContext("experimental-webgl",o),n))try{return new i.WebGLContext(n,1)}catch(t){r.Logger.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${t}`)}throw new Error("WebGL is not supported")}e.createWebGLContext=function t(e){let n;e&&"webgl2"!==e||!("webgl2"in o)?e&&"webgl"!==e||!("webgl"in o)||(n=o.webgl):n=o.webgl2,n=n||a(e),e=e||1===n.version?"webgl":"webgl2";const r=n.gl;return o[e]=n,r.isContextLost()?(delete o[e],t(e)):(r.disable(r.DEPTH_TEST),r.disable(r.STENCIL_TEST),r.disable(r.BLEND),r.disable(r.DITHER),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SAMPLE_COVERAGE),r.enable(r.SCISSOR_TEST),r.enable(r.CULL_FACE),r.cullFace(r.BACK),n)},e.createNewWebGLContext=a},1713:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLContext=e.linearSearchLastTrue=void 0;const a=n(8453),s=o(n(7769)),u=n(9390);function c(t){let e=0;for(;ethis.isTimerResultAvailable(t))),this.getTimerResult(t)}async createAndWaitForFence(){const t=this.createFence(this.gl);return this.pollFence(t)}createFence(t){let e;const n=t,r=n.fenceSync(n.SYNC_GPU_COMMANDS_COMPLETE,0);return t.flush(),e=null===r?()=>!0:()=>{const t=n.clientWaitSync(r,0,0);return t===n.ALREADY_SIGNALED||t===n.CONDITION_SATISFIED},{query:r,isFencePassed:e}}async pollFence(t){return new Promise((e=>{this.addItemToPoll((()=>t.isFencePassed()),(()=>e()))}))}pollItems(){const t=c(this.itemsToPoll.map((t=>t.isDoneFn)));for(let e=0;e<=t;++e){const{resolveFn:t}=this.itemsToPoll[e];t()}this.itemsToPoll=this.itemsToPoll.slice(t+1)}async addItemToPoll(t,e){this.itemsToPoll.push({isDoneFn:t,resolveFn:e}),this.itemsToPoll.length>1||await(0,u.repeatedTry)((()=>(this.pollItems(),0===this.itemsToPoll.length)))}}},1036:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ExecutionPlan=void 0;const r=n(6231);class i{constructor(t,e){this.op=t,this.node=e}}e.ExecutionPlan=class{constructor(t,e,n){this.graph=t,this.profiler=n,this.initialize(e)}initialize(t){this.profiler.event("session","ExecutionPlan.initialize",(()=>{const e=this.graph.getNodes();if(e.length!==t.length)throw new Error("The size of nodes and OPs do not match.");this._ops=t.map(((t,n)=>new i(t,e[n]))),this.reset(),this._starter=[],this._ops.forEach(((t,e)=>{let n=!0;for(const e of t.node.inputs)if(!this._values[e]&&-1===this.graph.getInputIndices().indexOf(e)){n=!1;break}n&&this._starter.push(e)}))}))}reset(){this._values=this.graph.getValues().map((t=>t.tensor))}async execute(t,e){return this.profiler.event("session","ExecutionPlan.execute",(async()=>{this.reset();const n=t.createInferenceHandler(),i=this.graph.getInputIndices();if(e.length!==i.length)throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${e.length} expected: ${i.length}`);e.forEach(((t,e)=>{const n=i[e];this._values[n]=t}));const o=this._starter.slice(0),a=this.graph.getValues(),s=this.graph.getNodes();let u=0;for(;uthis._values[t]));if(-1!==i.indexOf(void 0))throw new Error(`unresolved input detected: op: ${e.node}`);const c=i;r.Logger.verbose("ExecPlan",`Runing op:${e.node.name} (${c.map(((t,n)=>`'${e.node.inputs[n]}': ${t.type}[${t.dims.join(",")}]`)).join(", ")})`);const l=await this.profiler.event("node",e.node.name,(async()=>e.op.impl(n,c,e.op.context)));if(l.length!==e.node.outputs.length)throw new Error("the size of output does not match model definition.");l.forEach(((t,n)=>{const r=e.node.outputs[n];if(this._values[r])throw new Error(`output [${r}] already has value: op:${e.node.name}`);this._values[r]=t}));const p=new Set;l.forEach(((t,n)=>{const r=e.node.outputs[n];for(const t of a[r].to){const e=s[t];let n=!0;for(const t of e.inputs)if(!this._values[t]){n=!1;break}n&&p.add(t)}})),o.push(...p)}const c=[];for(let t=0;t{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Graph=void 0;const r=n(1446),i=n(7778),o=n(9395),a=n(9162),s=n(2517);var u=o.onnxruntime.experimental.fbs;e.Graph={from:(t,e)=>new p(t,e)};class c{constructor(t){this._from=void 0,this._to=[],this.tensor=void 0,this.type=void 0,t&&(this.type=s.ProtoUtil.tensorValueTypeFromProto(t.type.tensorType))}get from(){return this._from}get to(){return this._to}}class l{constructor(t,e){t instanceof r.onnx.NodeProto?(this.name=t.name,this.opType=t.opType,this.attributes=new i.Attribute(t.attribute)):t instanceof u.Node&&(this.name=null!=e?e:t.name(),this.opType=t.opType(),this.attributes=new i.Attribute(s.ProtoUtil.tensorAttributesFromORTFormat(t))),this.inputs=[],this.outputs=[],this.executeNode=!0}}class p{constructor(t,e){if(!t)throw new TypeError("graph is empty");this.buildGraph(t),this.transformGraph(e),this.checkIsAcyclic()}getInputIndices(){return this._allInputIndices}getInputNames(){return this._allInputNames}getOutputIndices(){return this._allOutputIndices}getOutputNames(){return this._allOutputNames}getValues(){return this._allData}getNodes(){return this._nodes}buildGraph(t){if(t instanceof r.onnx.GraphProto)this.buildGraphFromOnnxFormat(t);else{if(!(t instanceof u.Graph))throw new TypeError("Graph type is not supported.");this.buildGraphFromOrtFormat(t)}}buildGraphFromOnnxFormat(t){const e=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];const n=new Map;if(!t.input)throw new Error("missing information in graph: input");const r=[];for(const n of t.input){if(e.has(n.name))throw new Error(`duplicated input name: ${n.name}`);const t=this._allData.push(new c(n))-1;e.set(n.name,t),r.push(n.name)}if(!t.initializer)throw new Error("missing information in graph: initializer");for(const n of t.initializer){let t=e.get(n.name);if(void 0===t){const r=new c;r.type={shape:{dims:s.ProtoUtil.tensorDimsFromProto(n.dims)},tensorType:s.ProtoUtil.tensorDataTypeFromProto(n.dataType)},t=this._allData.push(r)-1,e.set(n.name,t)}this._allData[t]._from=-1,this._allData[t].tensor=a.Tensor.fromProto(n)}for(let t=0;t{this._allData[e]._to.forEach((e=>{t.add(e)}))}));const e=Array.from(t),n=new Array(this._nodes.length).fill("white");for(;e.length>0;){const t=e.pop();"gray"===n[t]?n[t]="black":(e.push(t),n[t]="gray",this._nodes[t].outputs.forEach((r=>{const i=this._allData[r];if(void 0!==i.tensor)throw new Error("node outputs should not be initialized");if(i._from!==t)throw new Error("from property of the Value object doesn't match index of Node being processed");i._to.forEach((t=>{if("gray"===n[t])throw new Error("model graph is cyclic");"white"===n[t]&&e.push(t)}))})))}}transformGraph(t){this.removeAllIdentityNodes(),this.removeAllDropoutNodes(),this.fuseConvActivationNodes(),t&&t.transformGraph(this),this.finalizeGraph()}finalizeGraph(){let t=0;for(let e=0;e0&&(this._nodes[e].inputs.forEach((n=>{const r=this._allData[n]._to.indexOf(e+t);-1!==r&&(this._allData[n]._to[r]=e)})),this._nodes[e].outputs.forEach((n=>{this._allData[n]._from&&this._allData[n]._from===e+t&&(this._allData[n]._from=e)}))):(t++,this._nodes[e].outputs.forEach((t=>{this._allData[t]._from=-2})),this._nodes.splice(e,1),e--);t=0;for(let e=0;e0){let n=-1;void 0!==this._allData[e].from&&-1!==this._allData[e].from?(n=this._nodes[this._allData[e].from].outputs.indexOf(e+t),-1!==n&&(this._nodes[this._allData[e].from].outputs[n]=e)):(n=this._allInputIndices.indexOf(e+t),-1!==n&&(this._allInputIndices[n]=e)),this._allData[e].to.forEach((r=>{n=this._nodes[r].inputs.indexOf(e+t),-1!==n&&(this._nodes[r].inputs[n]=e)})),0===this._allData[e].to.length&&(n=this._allOutputIndices.indexOf(e+t),-1!==n&&(this._allOutputIndices[n]=e))}}else t++,this._allData.splice(e,1),e--}deleteNode(t){const e=this._nodes[t];if(e.outputs.length>1)for(let t=1;t0)throw new Error("Node deletion with more than one output connected to other nodes is not supported. ");e.executeNode=!1;const n=e.inputs[0],r=e.outputs[0],i=this._allData[r].to,o=this._allData[n].to.indexOf(t);if(-1===o)throw new Error("The Value object doesn't have the current Node in it's 'to' property ");this._allData[n].to.splice(o,1),this._allData[r]._to=[];const a=this._allOutputIndices.indexOf(r);if(-1!==a&&(this._allOutputIndices[a]=n),i&&i.length>0)for(const t of i){const e=this._nodes[t].inputs.indexOf(r);if(-1===e)throw new Error("The Node object doesn't have the output Value in it's 'inputs' property ");this._nodes[t].inputs[e]=n,this._allData[n].to.push(t)}}removeAllDropoutNodes(){let t=0;for(const e of this._nodes){if("Dropout"===e.opType){if(1!==e.inputs.length)throw new Error("Dropout nodes should only contain one input. ");if(1!==e.outputs.length&&2!==e.outputs.length)throw new Error("Dropout nodes should contain either 1 or 2 output(s)");if(2===e.outputs.length&&0!==this._allData[e.outputs[1]]._to.length)throw new Error("Dropout nodes's second output should not be referenced by other nodes");this.deleteNode(t)}t++}}removeAllIdentityNodes(){let t=0;for(const e of this._nodes)"Identity"===e.opType&&this.deleteNode(t),t++}isActivation(t){switch(t.opType){case"Relu":case"Sigmoid":case"Clip":return!0;default:return!1}}fuseConvActivationNodes(){for(const t of this._nodes)if("Conv"===t.opType){const e=this._allData[t.outputs[0]]._to;if(1===e.length&&this.isActivation(this._nodes[e[0]])){const n=this._nodes[e[0]];if("Clip"===n.opType)if(1===n.inputs.length)try{t.attributes.set("activation_params","floats",[n.attributes.getFloat("min"),n.attributes.getFloat("max")])}catch(e){t.attributes.set("activation_params","floats",[s.MIN_CLIP,s.MAX_CLIP])}else{if(!(n.inputs.length>=3&&void 0!==this._allData[n.inputs[1]].tensor&&void 0!==this._allData[n.inputs[2]].tensor))continue;t.attributes.set("activation_params","floats",[this._allData[n.inputs[1]].tensor.floatData[0],this._allData[n.inputs[2]].tensor.floatData[0]])}t.attributes.set("activation","string",n.opType),this.deleteNode(e[0])}}}}},6231:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.now=e.Profiler=e.Logger=void 0;const n={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},r={none:new class{log(t,e,n){}},console:new class{log(t,e,n){console.log(`${this.color(t)} ${n?""+n+" ":""}${e}`)}color(t){switch(t){case"verbose":return"v";case"info":return"i";case"warning":return"w";case"error":return"e";case"fatal":return"f";default:throw new Error(`unsupported severity: ${t}`)}}}},i={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1};let o={"":i};function a(t,e,n,r){if(void 0===e)return i=t,{verbose:a.verbose.bind(null,i),info:a.info.bind(null,i),warning:a.warning.bind(null,i),error:a.error.bind(null,i),fatal:a.fatal.bind(null,i)};if(void 0===n)s(t,e);else if("number"==typeof n&&void 0===r)s(t,e);else if("string"==typeof n&&void 0===r)s(t,n,0,e);else{if("string"!=typeof n||"number"!=typeof r)throw new TypeError("input is valid");s(t,n,0,e)}var i}function s(t,e,i,a){const s=o[a||""]||o[""];n[t]{a.then((async e=>{i&&await i.end(),t(e)}),(async t=>{i&&await i.end(),e(t)}))}));if(!o&&i){const t=i.end();if(t&&"function"==typeof t.then)return new Promise(((e,n)=>{t.then((()=>{e(a)}),(t=>{n(t)}))}))}return a}begin(t,n,r){if(!this._started)throw new Error("profiler is not started yet");if(void 0===r){const r=(0,e.now)();return this.flush(r),new u(t,n,r,(t=>this.endSync(t)))}{const e=r.beginTimer();return new u(t,n,0,(async t=>this.end(t)),e,r)}}async end(t){const e=await t.checkTimer();this._timingEvents.length=this._flushBatchSize||t-this._flushTime>=this._flushIntervalInMilliseconds){for(const t=this._flushPointer;this._flushPointerperformance.now():Date.now},2644:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Model=void 0;const r=n(5686),i=n(1446),o=n(7070),a=n(9395),s=n(2517);var u=a.onnxruntime.experimental.fbs;e.Model=class{constructor(){}load(t,e,n){if(!n)try{return void this.loadFromOnnxFormat(t,e)}catch(t){if(void 0!==n)throw t}this.loadFromOrtFormat(t,e)}loadFromOnnxFormat(t,e){const n=i.onnx.ModelProto.decode(t);if(s.LongUtil.longToNumber(n.irVersion)<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=n.opsetImport.map((t=>({domain:t.domain,version:s.LongUtil.longToNumber(t.version)}))),this._graph=o.Graph.from(n.graph,e)}loadFromOrtFormat(t,e){const n=new r.flatbuffers.ByteBuffer(t),i=u.InferenceSession.getRootAsInferenceSession(n).model();if(s.LongUtil.longToNumber(i.irVersion())<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=[];for(let t=0;t{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.FLOAT_TYPES=e.INT_TYPES=e.NUMBER_TYPES=void 0,e.NUMBER_TYPES=["float32","float64","int32","int16","int8","uint16","uint32","uint8"],e.INT_TYPES=["int32","int16","int8","uint16","uint32","uint8"],e.FLOAT_TYPES=["float32","float64"]},1047:(t,e)=>{"use strict";function n(t,e){if(e.endsWith("+")){const n=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(n)&&n<=t}if(2===e.split("-").length){const n=e.split("-"),r=Number.parseInt(n[0],10),i=Number.parseInt(n[1],10);return!isNaN(r)&&!isNaN(i)&&r<=t&&t<=i}return Number.parseInt(e,10)===t}Object.defineProperty(e,"__esModule",{value:!0}),e.resolveOperator=void 0,e.resolveOperator=function(t,e,r){for(const i of r){const r=i[0],o=i[1],a=i[2],s=i[3],u=i[4];if(t.opType===r)for(const t of e)if((t.domain===o||"ai.onnx"===t.domain&&""===o)&&n(t.version,a))return{opImpl:s,opInit:u}}throw new TypeError(`cannot resolve operator '${t.opType}' with opsets: ${e.map((t=>`${t.domain||"ai.onnx"} v${t.version}`)).join(", ")}`)}},9395:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.onnxruntime=void 0;const r=n(5686);var i,o;i=e.onnxruntime||(e.onnxruntime={}),function(t){let e;!function(t){t[t.UNDEFINED=0]="UNDEFINED",t[t.FLOAT=1]="FLOAT",t[t.INT=2]="INT",t[t.STRING=3]="STRING",t[t.TENSOR=4]="TENSOR",t[t.GRAPH=5]="GRAPH",t[t.FLOATS=6]="FLOATS",t[t.INTS=7]="INTS",t[t.STRINGS=8]="STRINGS",t[t.TENSORS=9]="TENSORS",t[t.GRAPHS=10]="GRAPHS",t[t.SPARSE_TENSOR=11]="SPARSE_TENSOR",t[t.SPARSE_TENSORS=12]="SPARSE_TENSORS"}(e=t.AttributeType||(t.AttributeType={}))}((o=i.experimental||(i.experimental={})).fbs||(o.fbs={})),function(t){!function(t){!function(t){let e;!function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.VALUE=1]="VALUE",t[t.PARAM=2]="PARAM"}(e=t.DimensionValueType||(t.DimensionValueType={}))}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){!function(t){let e;!function(t){t[t.UNDEFINED=0]="UNDEFINED",t[t.FLOAT=1]="FLOAT",t[t.UINT8=2]="UINT8",t[t.INT8=3]="INT8",t[t.UINT16=4]="UINT16",t[t.INT16=5]="INT16",t[t.INT32=6]="INT32",t[t.INT64=7]="INT64",t[t.STRING=8]="STRING",t[t.BOOL=9]="BOOL",t[t.FLOAT16=10]="FLOAT16",t[t.DOUBLE=11]="DOUBLE",t[t.UINT32=12]="UINT32",t[t.UINT64=13]="UINT64",t[t.COMPLEX64=14]="COMPLEX64",t[t.COMPLEX128=15]="COMPLEX128",t[t.BFLOAT16=16]="BFLOAT16"}(e=t.TensorDataType||(t.TensorDataType={}))}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){!function(t){let e;!function(t){t[t.Primitive=0]="Primitive",t[t.Fused=1]="Fused"}(e=t.NodeType||(t.NodeType={}))}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){!function(t){let e;!function(t){t[t.NONE=0]="NONE",t[t.tensor_type=1]="tensor_type",t[t.sequence_type=2]="sequence_type",t[t.map_type=3]="map_type"}(e=t.TypeInfoValue||(t.TypeInfoValue={}))}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsShape(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsShape(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}dim(e,n){let r=this.bb.__offset(this.bb_pos,4);return r?(n||new t.experimental.fbs.Dimension).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}dimLength(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startShape(t){t.startObject(1)}static addDim(t,e){t.addFieldOffset(0,e,0)}static createDimVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startDimVector(t,e){t.startVector(4,e,4)}static endShape(t){return t.endObject()}static createShape(t,e){return n.startShape(t),n.addDim(t,e),n.endShape(t)}}e.Shape=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsDimension(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsDimension(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}value(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new t.experimental.fbs.DimensionValue).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}denotation(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}static startDimension(t){t.startObject(2)}static addValue(t,e){t.addFieldOffset(0,e,0)}static addDenotation(t,e){t.addFieldOffset(1,e,0)}static endDimension(t){return t.endObject()}static createDimension(t,e,r){return n.startDimension(t),n.addValue(t,e),n.addDenotation(t,r),n.endDimension(t)}}e.Dimension=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsDimensionValue(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsDimensionValue(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}dimType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt8(this.bb_pos+e):t.experimental.fbs.DimensionValueType.UNKNOWN}dimValue(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt64(this.bb_pos+t):this.bb.createLong(0,0)}dimParam(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}static startDimensionValue(t){t.startObject(3)}static addDimType(e,n){e.addFieldInt8(0,n,t.experimental.fbs.DimensionValueType.UNKNOWN)}static addDimValue(t,e){t.addFieldInt64(1,e,t.createLong(0,0))}static addDimParam(t,e){t.addFieldOffset(2,e,0)}static endDimensionValue(t){return t.endObject()}static createDimensionValue(t,e,r,i){return n.startDimensionValue(t),n.addDimType(t,e),n.addDimValue(t,r),n.addDimParam(t,i),n.endDimensionValue(t)}}e.DimensionValue=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTensorTypeAndShape(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTensorTypeAndShape(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}elemType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):t.experimental.fbs.TensorDataType.UNDEFINED}shape(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new t.experimental.fbs.Shape).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startTensorTypeAndShape(t){t.startObject(2)}static addElemType(e,n){e.addFieldInt32(0,n,t.experimental.fbs.TensorDataType.UNDEFINED)}static addShape(t,e){t.addFieldOffset(1,e,0)}static endTensorTypeAndShape(t){return t.endObject()}static createTensorTypeAndShape(t,e,r){return n.startTensorTypeAndShape(t),n.addElemType(t,e),n.addShape(t,r),n.endTensorTypeAndShape(t)}}e.TensorTypeAndShape=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMapType(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMapType(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}keyType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):t.experimental.fbs.TensorDataType.UNDEFINED}valueType(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new t.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startMapType(t){t.startObject(2)}static addKeyType(e,n){e.addFieldInt32(0,n,t.experimental.fbs.TensorDataType.UNDEFINED)}static addValueType(t,e){t.addFieldOffset(1,e,0)}static endMapType(t){return t.endObject()}static createMapType(t,e,r){return n.startMapType(t),n.addKeyType(t,e),n.addValueType(t,r),n.endMapType(t)}}e.MapType=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSequenceType(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSequenceType(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}elemType(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new t.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startSequenceType(t){t.startObject(1)}static addElemType(t,e){t.addFieldOffset(0,e,0)}static endSequenceType(t){return t.endObject()}static createSequenceType(t,e){return n.startSequenceType(t),n.addElemType(t,e),n.endSequenceType(t)}}e.SequenceType=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){(t.fbs||(t.fbs={})).EdgeEnd=class{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}nodeIndex(){return this.bb.readUint32(this.bb_pos)}srcArgIndex(){return this.bb.readInt32(this.bb_pos+4)}dstArgIndex(){return this.bb.readInt32(this.bb_pos+8)}static createEdgeEnd(t,e,n,r){return t.prep(4,12),t.writeInt32(r),t.writeInt32(n),t.writeInt32(e),t.offset()}}}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsNodeEdge(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNodeEdge(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}nodeIndex(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):0}inputEdges(e,n){let r=this.bb.__offset(this.bb_pos,6);return r?(n||new t.experimental.fbs.EdgeEnd).__init(this.bb.__vector(this.bb_pos+r)+12*e,this.bb):null}inputEdgesLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}outputEdges(e,n){let r=this.bb.__offset(this.bb_pos,8);return r?(n||new t.experimental.fbs.EdgeEnd).__init(this.bb.__vector(this.bb_pos+r)+12*e,this.bb):null}outputEdgesLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startNodeEdge(t){t.startObject(3)}static addNodeIndex(t,e){t.addFieldInt32(0,e,0)}static addInputEdges(t,e){t.addFieldOffset(1,e,0)}static startInputEdgesVector(t,e){t.startVector(12,e,4)}static addOutputEdges(t,e){t.addFieldOffset(2,e,0)}static startOutputEdgesVector(t,e){t.startVector(12,e,4)}static endNodeEdge(t){return t.endObject()}static createNodeEdge(t,e,r,i){return n.startNodeEdge(t),n.addNodeIndex(t,e),n.addInputEdges(t,r),n.addOutputEdges(t,i),n.endNodeEdge(t)}}e.NodeEdge=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsNode(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNode(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}name(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}docString(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}domain(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}sinceVersion(){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readInt32(this.bb_pos+t):0}index(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.readUint32(this.bb_pos+t):0}opType(t){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__string(this.bb_pos+e,t):null}type(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readInt32(this.bb_pos+e):t.experimental.fbs.NodeType.Primitive}executionProviderType(t){let e=this.bb.__offset(this.bb_pos,18);return e?this.bb.__string(this.bb_pos+e,t):null}inputs(t,e){let n=this.bb.__offset(this.bb_pos,20);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}inputsLength(){let t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__vector_len(this.bb_pos+t):0}outputs(t,e){let n=this.bb.__offset(this.bb_pos,22);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}outputsLength(){let t=this.bb.__offset(this.bb_pos,22);return t?this.bb.__vector_len(this.bb_pos+t):0}attributes(e,n){let r=this.bb.__offset(this.bb_pos,24);return r?(n||new t.experimental.fbs.Attribute).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}attributesLength(){let t=this.bb.__offset(this.bb_pos,24);return t?this.bb.__vector_len(this.bb_pos+t):0}inputArgCounts(t){let e=this.bb.__offset(this.bb_pos,26);return e?this.bb.readInt32(this.bb.__vector(this.bb_pos+e)+4*t):0}inputArgCountsLength(){let t=this.bb.__offset(this.bb_pos,26);return t?this.bb.__vector_len(this.bb_pos+t):0}inputArgCountsArray(){let t=this.bb.__offset(this.bb_pos,26);return t?new Int32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}implicitInputs(t,e){let n=this.bb.__offset(this.bb_pos,28);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}implicitInputsLength(){let t=this.bb.__offset(this.bb_pos,28);return t?this.bb.__vector_len(this.bb_pos+t):0}static startNode(t){t.startObject(13)}static addName(t,e){t.addFieldOffset(0,e,0)}static addDocString(t,e){t.addFieldOffset(1,e,0)}static addDomain(t,e){t.addFieldOffset(2,e,0)}static addSinceVersion(t,e){t.addFieldInt32(3,e,0)}static addIndex(t,e){t.addFieldInt32(4,e,0)}static addOpType(t,e){t.addFieldOffset(5,e,0)}static addType(e,n){e.addFieldInt32(6,n,t.experimental.fbs.NodeType.Primitive)}static addExecutionProviderType(t,e){t.addFieldOffset(7,e,0)}static addInputs(t,e){t.addFieldOffset(8,e,0)}static createInputsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startInputsVector(t,e){t.startVector(4,e,4)}static addOutputs(t,e){t.addFieldOffset(9,e,0)}static createOutputsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startOutputsVector(t,e){t.startVector(4,e,4)}static addAttributes(t,e){t.addFieldOffset(10,e,0)}static createAttributesVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startAttributesVector(t,e){t.startVector(4,e,4)}static addInputArgCounts(t,e){t.addFieldOffset(11,e,0)}static createInputArgCountsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addInt32(e[n]);return t.endVector()}static startInputArgCountsVector(t,e){t.startVector(4,e,4)}static addImplicitInputs(t,e){t.addFieldOffset(12,e,0)}static createImplicitInputsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startImplicitInputsVector(t,e){t.startVector(4,e,4)}static endNode(t){return t.endObject()}static createNode(t,e,r,i,o,a,s,u,c,l,p,f,d,h){return n.startNode(t),n.addName(t,e),n.addDocString(t,r),n.addDomain(t,i),n.addSinceVersion(t,o),n.addIndex(t,a),n.addOpType(t,s),n.addType(t,u),n.addExecutionProviderType(t,c),n.addInputs(t,l),n.addOutputs(t,p),n.addAttributes(t,f),n.addInputArgCounts(t,d),n.addImplicitInputs(t,h),n.endNode(t)}}e.Node=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsValueInfo(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsValueInfo(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}name(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}docString(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}type(e){let n=this.bb.__offset(this.bb_pos,8);return n?(e||new t.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startValueInfo(t){t.startObject(3)}static addName(t,e){t.addFieldOffset(0,e,0)}static addDocString(t,e){t.addFieldOffset(1,e,0)}static addType(t,e){t.addFieldOffset(2,e,0)}static endValueInfo(t){return t.endObject()}static createValueInfo(t,e,r,i){return n.startValueInfo(t),n.addName(t,e),n.addDocString(t,r),n.addType(t,i),n.endValueInfo(t)}}e.ValueInfo=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTypeInfo(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTypeInfo(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}denotation(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}valueType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):t.experimental.fbs.TypeInfoValue.NONE}value(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__union(t,this.bb_pos+e):null}static startTypeInfo(t){t.startObject(3)}static addDenotation(t,e){t.addFieldOffset(0,e,0)}static addValueType(e,n){e.addFieldInt8(1,n,t.experimental.fbs.TypeInfoValue.NONE)}static addValue(t,e){t.addFieldOffset(2,e,0)}static endTypeInfo(t){return t.endObject()}static createTypeInfo(t,e,r,i){return n.startTypeInfo(t),n.addDenotation(t,e),n.addValueType(t,r),n.addValue(t,i),n.endTypeInfo(t)}}e.TypeInfo=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){!function(t){class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsOperatorSetId(t,n){return(n||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsOperatorSetId(t,n){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new e).__init(t.readInt32(t.position())+t.position(),t)}domain(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}version(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt64(this.bb_pos+t):this.bb.createLong(0,0)}static startOperatorSetId(t){t.startObject(2)}static addDomain(t,e){t.addFieldOffset(0,e,0)}static addVersion(t,e){t.addFieldInt64(1,e,t.createLong(0,0))}static endOperatorSetId(t){return t.endObject()}static createOperatorSetId(t,n,r){return e.startOperatorSetId(t),e.addDomain(t,n),e.addVersion(t,r),e.endOperatorSetId(t)}}t.OperatorSetId=e}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTensor(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTensor(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}name(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}docString(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}dims(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt64(this.bb.__vector(this.bb_pos+e)+8*t):this.bb.createLong(0,0)}dimsLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}dataType(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt32(this.bb_pos+e):t.experimental.fbs.TensorDataType.UNDEFINED}rawData(t){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}rawDataLength(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}rawDataArray(){let t=this.bb.__offset(this.bb_pos,12);return t?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}stringData(t,e){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}stringDataLength(){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTensor(t){t.startObject(6)}static addName(t,e){t.addFieldOffset(0,e,0)}static addDocString(t,e){t.addFieldOffset(1,e,0)}static addDims(t,e){t.addFieldOffset(2,e,0)}static createDimsVector(t,e){t.startVector(8,e.length,8);for(let n=e.length-1;n>=0;n--)t.addInt64(e[n]);return t.endVector()}static startDimsVector(t,e){t.startVector(8,e,8)}static addDataType(e,n){e.addFieldInt32(3,n,t.experimental.fbs.TensorDataType.UNDEFINED)}static addRawData(t,e){t.addFieldOffset(4,e,0)}static createRawDataVector(t,e){t.startVector(1,e.length,1);for(let n=e.length-1;n>=0;n--)t.addInt8(e[n]);return t.endVector()}static startRawDataVector(t,e){t.startVector(1,e,1)}static addStringData(t,e){t.addFieldOffset(5,e,0)}static createStringDataVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startStringDataVector(t,e){t.startVector(4,e,4)}static endTensor(t){return t.endObject()}static createTensor(t,e,r,i,o,a,s){return n.startTensor(t),n.addName(t,e),n.addDocString(t,r),n.addDims(t,i),n.addDataType(t,o),n.addRawData(t,a),n.addStringData(t,s),n.endTensor(t)}}e.Tensor=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSparseTensor(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSparseTensor(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}values(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new t.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}indices(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new t.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}dims(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt64(this.bb.__vector(this.bb_pos+e)+8*t):this.bb.createLong(0,0)}dimsLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startSparseTensor(t){t.startObject(3)}static addValues(t,e){t.addFieldOffset(0,e,0)}static addIndices(t,e){t.addFieldOffset(1,e,0)}static addDims(t,e){t.addFieldOffset(2,e,0)}static createDimsVector(t,e){t.startVector(8,e.length,8);for(let n=e.length-1;n>=0;n--)t.addInt64(e[n]);return t.endVector()}static startDimsVector(t,e){t.startVector(8,e,8)}static endSparseTensor(t){return t.endObject()}static createSparseTensor(t,e,r,i){return n.startSparseTensor(t),n.addValues(t,e),n.addIndices(t,r),n.addDims(t,i),n.endSparseTensor(t)}}e.SparseTensor=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsAttribute(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsAttribute(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}name(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}docString(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}type(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt32(this.bb_pos+e):t.experimental.fbs.AttributeType.UNDEFINED}f(){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readFloat32(this.bb_pos+t):0}i(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.readInt64(this.bb_pos+t):this.bb.createLong(0,0)}s(t){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__string(this.bb_pos+e,t):null}t(e){let n=this.bb.__offset(this.bb_pos,16);return n?(e||new t.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}g(e){let n=this.bb.__offset(this.bb_pos,18);return n?(e||new t.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}floats(t){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.readFloat32(this.bb.__vector(this.bb_pos+e)+4*t):0}floatsLength(){let t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__vector_len(this.bb_pos+t):0}floatsArray(){let t=this.bb.__offset(this.bb_pos,20);return t?new Float32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}ints(t){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.readInt64(this.bb.__vector(this.bb_pos+e)+8*t):this.bb.createLong(0,0)}intsLength(){let t=this.bb.__offset(this.bb_pos,22);return t?this.bb.__vector_len(this.bb_pos+t):0}strings(t,e){let n=this.bb.__offset(this.bb_pos,24);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}stringsLength(){let t=this.bb.__offset(this.bb_pos,24);return t?this.bb.__vector_len(this.bb_pos+t):0}tensors(e,n){let r=this.bb.__offset(this.bb_pos,26);return r?(n||new t.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}tensorsLength(){let t=this.bb.__offset(this.bb_pos,26);return t?this.bb.__vector_len(this.bb_pos+t):0}graphs(e,n){let r=this.bb.__offset(this.bb_pos,28);return r?(n||new t.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}graphsLength(){let t=this.bb.__offset(this.bb_pos,28);return t?this.bb.__vector_len(this.bb_pos+t):0}static startAttribute(t){t.startObject(13)}static addName(t,e){t.addFieldOffset(0,e,0)}static addDocString(t,e){t.addFieldOffset(1,e,0)}static addType(e,n){e.addFieldInt32(2,n,t.experimental.fbs.AttributeType.UNDEFINED)}static addF(t,e){t.addFieldFloat32(3,e,0)}static addI(t,e){t.addFieldInt64(4,e,t.createLong(0,0))}static addS(t,e){t.addFieldOffset(5,e,0)}static addT(t,e){t.addFieldOffset(6,e,0)}static addG(t,e){t.addFieldOffset(7,e,0)}static addFloats(t,e){t.addFieldOffset(8,e,0)}static createFloatsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addFloat32(e[n]);return t.endVector()}static startFloatsVector(t,e){t.startVector(4,e,4)}static addInts(t,e){t.addFieldOffset(9,e,0)}static createIntsVector(t,e){t.startVector(8,e.length,8);for(let n=e.length-1;n>=0;n--)t.addInt64(e[n]);return t.endVector()}static startIntsVector(t,e){t.startVector(8,e,8)}static addStrings(t,e){t.addFieldOffset(10,e,0)}static createStringsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startStringsVector(t,e){t.startVector(4,e,4)}static addTensors(t,e){t.addFieldOffset(11,e,0)}static createTensorsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startTensorsVector(t,e){t.startVector(4,e,4)}static addGraphs(t,e){t.addFieldOffset(12,e,0)}static createGraphsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startGraphsVector(t,e){t.startVector(4,e,4)}static endAttribute(t){return t.endObject()}static createAttribute(t,e,r,i,o,a,s,u,c,l,p,f,d,h){return n.startAttribute(t),n.addName(t,e),n.addDocString(t,r),n.addType(t,i),n.addF(t,o),n.addI(t,a),n.addS(t,s),n.addT(t,u),n.addG(t,c),n.addFloats(t,l),n.addInts(t,p),n.addStrings(t,f),n.addTensors(t,d),n.addGraphs(t,h),n.endAttribute(t)}}e.Attribute=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGraph(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGraph(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}initializers(e,n){let r=this.bb.__offset(this.bb_pos,4);return r?(n||new t.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}initializersLength(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}nodeArgs(e,n){let r=this.bb.__offset(this.bb_pos,6);return r?(n||new t.experimental.fbs.ValueInfo).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}nodeArgsLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}nodes(e,n){let r=this.bb.__offset(this.bb_pos,8);return r?(n||new t.experimental.fbs.Node).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}nodesLength(){let t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}maxNodeIndex(){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readUint32(this.bb_pos+t):0}nodeEdges(e,n){let r=this.bb.__offset(this.bb_pos,12);return r?(n||new t.experimental.fbs.NodeEdge).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}nodeEdgesLength(){let t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}inputs(t,e){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}inputsLength(){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__vector_len(this.bb_pos+t):0}outputs(t,e){let n=this.bb.__offset(this.bb_pos,16);return n?this.bb.__string(this.bb.__vector(this.bb_pos+n)+4*t,e):null}outputsLength(){let t=this.bb.__offset(this.bb_pos,16);return t?this.bb.__vector_len(this.bb_pos+t):0}sparseInitializers(e,n){let r=this.bb.__offset(this.bb_pos,18);return r?(n||new t.experimental.fbs.SparseTensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}sparseInitializersLength(){let t=this.bb.__offset(this.bb_pos,18);return t?this.bb.__vector_len(this.bb_pos+t):0}static startGraph(t){t.startObject(8)}static addInitializers(t,e){t.addFieldOffset(0,e,0)}static createInitializersVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startInitializersVector(t,e){t.startVector(4,e,4)}static addNodeArgs(t,e){t.addFieldOffset(1,e,0)}static createNodeArgsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startNodeArgsVector(t,e){t.startVector(4,e,4)}static addNodes(t,e){t.addFieldOffset(2,e,0)}static createNodesVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startNodesVector(t,e){t.startVector(4,e,4)}static addMaxNodeIndex(t,e){t.addFieldInt32(3,e,0)}static addNodeEdges(t,e){t.addFieldOffset(4,e,0)}static createNodeEdgesVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startNodeEdgesVector(t,e){t.startVector(4,e,4)}static addInputs(t,e){t.addFieldOffset(5,e,0)}static createInputsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startInputsVector(t,e){t.startVector(4,e,4)}static addOutputs(t,e){t.addFieldOffset(6,e,0)}static createOutputsVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startOutputsVector(t,e){t.startVector(4,e,4)}static addSparseInitializers(t,e){t.addFieldOffset(7,e,0)}static createSparseInitializersVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startSparseInitializersVector(t,e){t.startVector(4,e,4)}static endGraph(t){return t.endObject()}static createGraph(t,e,r,i,o,a,s,u,c){return n.startGraph(t),n.addInitializers(t,e),n.addNodeArgs(t,r),n.addNodes(t,i),n.addMaxNodeIndex(t,o),n.addNodeEdges(t,a),n.addInputs(t,s),n.addOutputs(t,u),n.addSparseInitializers(t,c),n.endGraph(t)}}e.Graph=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsModel(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsModel(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}irVersion(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readInt64(this.bb_pos+t):this.bb.createLong(0,0)}opsetImport(e,n){let r=this.bb.__offset(this.bb_pos,6);return r?(n||new t.experimental.fbs.OperatorSetId).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}opsetImportLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}producerName(t){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}producerVersion(t){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.__string(this.bb_pos+e,t):null}domain(t){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__string(this.bb_pos+e,t):null}modelVersion(){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.readInt64(this.bb_pos+t):this.bb.createLong(0,0)}docString(t){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.__string(this.bb_pos+e,t):null}graph(e){let n=this.bb.__offset(this.bb_pos,18);return n?(e||new t.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}graphDocString(t){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.__string(this.bb_pos+e,t):null}static startModel(t){t.startObject(9)}static addIrVersion(t,e){t.addFieldInt64(0,e,t.createLong(0,0))}static addOpsetImport(t,e){t.addFieldOffset(1,e,0)}static createOpsetImportVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startOpsetImportVector(t,e){t.startVector(4,e,4)}static addProducerName(t,e){t.addFieldOffset(2,e,0)}static addProducerVersion(t,e){t.addFieldOffset(3,e,0)}static addDomain(t,e){t.addFieldOffset(4,e,0)}static addModelVersion(t,e){t.addFieldInt64(5,e,t.createLong(0,0))}static addDocString(t,e){t.addFieldOffset(6,e,0)}static addGraph(t,e){t.addFieldOffset(7,e,0)}static addGraphDocString(t,e){t.addFieldOffset(8,e,0)}static endModel(t){return t.endObject()}static createModel(t,e,r,i,o,a,s,u,c,l){return n.startModel(t),n.addIrVersion(t,e),n.addOpsetImport(t,r),n.addProducerName(t,i),n.addProducerVersion(t,o),n.addDomain(t,a),n.addModelVersion(t,s),n.addDocString(t,u),n.addGraph(t,c),n.addGraphDocString(t,l),n.endModel(t)}}e.Model=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(t){!function(t){class e{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsKernelCreateInfos(t,n){return(n||new e).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKernelCreateInfos(t,n){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new e).__init(t.readInt32(t.position())+t.position(),t)}nodeIndices(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}nodeIndicesLength(){let t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}nodeIndicesArray(){let t=this.bb.__offset(this.bb_pos,4);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}kernelDefHashes(t){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint64(this.bb.__vector(this.bb_pos+e)+8*t):this.bb.createLong(0,0)}kernelDefHashesLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}static startKernelCreateInfos(t){t.startObject(2)}static addNodeIndices(t,e){t.addFieldOffset(0,e,0)}static createNodeIndicesVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addInt32(e[n]);return t.endVector()}static startNodeIndicesVector(t,e){t.startVector(4,e,4)}static addKernelDefHashes(t,e){t.addFieldOffset(1,e,0)}static createKernelDefHashesVector(t,e){t.startVector(8,e.length,8);for(let n=e.length-1;n>=0;n--)t.addInt64(e[n]);return t.endVector()}static startKernelDefHashesVector(t,e){t.startVector(8,e,8)}static endKernelCreateInfos(t){return t.endObject()}static createKernelCreateInfos(t,n,r){return e.startKernelCreateInfos(t),e.addNodeIndices(t,n),e.addKernelDefHashes(t,r),e.endKernelCreateInfos(t)}}t.KernelCreateInfos=e}(t.fbs||(t.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubGraphSessionState(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubGraphSessionState(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}graphId(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}sessionState(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new t.experimental.fbs.SessionState).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startSubGraphSessionState(t){t.startObject(2)}static addGraphId(t,e){t.addFieldOffset(0,e,0)}static addSessionState(t,e){t.addFieldOffset(1,e,0)}static endSubGraphSessionState(t){let e=t.endObject();return t.requiredField(e,4),e}static createSubGraphSessionState(t,e,r){return n.startSubGraphSessionState(t),n.addGraphId(t,e),n.addSessionState(t,r),n.endSubGraphSessionState(t)}}e.SubGraphSessionState=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSessionState(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSessionState(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}kernels(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new t.experimental.fbs.KernelCreateInfos).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}subGraphSessionStates(e,n){let r=this.bb.__offset(this.bb_pos,6);return r?(n||new t.experimental.fbs.SubGraphSessionState).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+r)+4*e),this.bb):null}subGraphSessionStatesLength(){let t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}static startSessionState(t){t.startObject(2)}static addKernels(t,e){t.addFieldOffset(0,e,0)}static addSubGraphSessionStates(t,e){t.addFieldOffset(1,e,0)}static createSubGraphSessionStatesVector(t,e){t.startVector(4,e.length,4);for(let n=e.length-1;n>=0;n--)t.addOffset(e[n]);return t.endVector()}static startSubGraphSessionStatesVector(t,e){t.startVector(4,e,4)}static endSessionState(t){return t.endObject()}static createSessionState(t,e,r){return n.startSessionState(t),n.addKernels(t,e),n.addSubGraphSessionStates(t,r),n.endSessionState(t)}}e.SessionState=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(t){!function(e){!function(e){class n{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsInferenceSession(t,e){return(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsInferenceSession(t,e){return t.setPosition(t.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(e||new n).__init(t.readInt32(t.position())+t.position(),t)}static bufferHasIdentifier(t){return t.__has_identifier("ORTM")}ortVersion(t){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}model(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new t.experimental.fbs.Model).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}sessionState(e){let n=this.bb.__offset(this.bb_pos,8);return n?(e||new t.experimental.fbs.SessionState).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startInferenceSession(t){t.startObject(3)}static addOrtVersion(t,e){t.addFieldOffset(0,e,0)}static addModel(t,e){t.addFieldOffset(1,e,0)}static addSessionState(t,e){t.addFieldOffset(2,e,0)}static endInferenceSession(t){return t.endObject()}static finishInferenceSessionBuffer(t,e){t.finish(e,"ORTM")}static finishSizePrefixedInferenceSessionBuffer(t,e){t.finish(e,"ORTM",!0)}static createInferenceSession(t,e,r,i){return n.startInferenceSession(t),n.addOrtVersion(t,e),n.addModel(t,r),n.addSessionState(t,i),n.endInferenceSession(t)}}e.InferenceSession=n}(e.fbs||(e.fbs={}))}(t.experimental||(t.experimental={}))}(e.onnxruntime||(e.onnxruntime={}))},7448:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.OnnxjsSessionHandler=void 0;const r=n(8453),i=n(9162);e.OnnxjsSessionHandler=class{constructor(t){this.session=t,this.inputNames=this.session.inputNames,this.outputNames=this.session.outputNames}async dispose(){}async run(t,e,n){const o=new Map;for(const e in t)if(Object.hasOwnProperty.call(t,e)){const n=t[e];o.set(e,new i.Tensor(n.dims,n.type,void 0,void 0,n.data))}const a=await this.session.run(o),s={};return a.forEach(((t,e)=>{s[e]=new r.Tensor(t.type,t.data,t.dims)})),s}startProfiling(){this.session.startProfiling()}endProfiling(){this.session.endProfiling()}}},6919:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Session=void 0;const r=n(7067),i=n(1296),o=n(7091),a=n(1036),s=n(6231),u=n(2644);e.Session=class{constructor(t={}){this._initialized=!1,this.backendHint=t.backendHint,this.profiler=s.Profiler.create(t.profiler),this.context={profiler:this.profiler,graphInputTypes:[],graphInputDims:[]}}get inputNames(){return this._model.graph.getInputNames()}get outputNames(){return this._model.graph.getOutputNames()}startProfiling(){this.profiler.start()}endProfiling(){this.profiler.stop()}async loadModel(t,e,n){await this.profiler.event("session","Session.loadModel",(async()=>{const a=await(0,o.resolveBackend)(this.backendHint);if(this.sessionHandler=a.createSessionHandler(this.context),this._model=new u.Model,"string"==typeof t){const e=t.endsWith(".ort");if("undefined"==typeof fetch){const n=await(0,i.promisify)(r.readFile)(t);this.initialize(n,e)}else{const n=await fetch(t),r=await n.arrayBuffer();this.initialize(new Uint8Array(r),e)}}else if(ArrayBuffer.isView(t))this.initialize(t);else{const r=new Uint8Array(t,e||0,n||t.byteLength);this.initialize(r)}}))}initialize(t,e){if(this._initialized)throw new Error("already initialized");this.profiler.event("session","Session.initialize",(()=>{const n=this.sessionHandler.transformGraph?this.sessionHandler:void 0;this._model.load(t,n,e),this.sessionHandler.onGraphInitialized&&this.sessionHandler.onGraphInitialized(this._model.graph),this.initializeOps(this._model.graph),this._executionPlan=new a.ExecutionPlan(this._model.graph,this._ops,this.profiler)})),this._initialized=!0}async run(t){if(!this._initialized)throw new Error("session not initialized yet");return this.profiler.event("session","Session.run",(async()=>{const e=this.normalizeAndValidateInputs(t),n=await this._executionPlan.execute(this.sessionHandler,e);return this.createOutput(n)}))}normalizeAndValidateInputs(t){const e=this._model.graph.getInputNames();if(Array.isArray(t)){if(t.length!==e.length)throw new Error(`incorrect input array length: expected ${e.length} but got ${t.length}`)}else{if(t.size!==e.length)throw new Error(`incorrect input map size: expected ${e.length} but got ${t.size}`);const n=new Array(t.size);let r=0;for(let i=0;i"string"==typeof t))))throw new TypeError("cache should be a string array");c&&(this.cache=new Array(s))}else{if(void 0!==o){const t=f(e);if(!(o instanceof t))throw new TypeError(`cache should be type ${t.name}`)}if(c){const t=new ArrayBuffer(s*function(t){switch(t){case"bool":case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"float64":return 8;default:throw new Error(`cannot calculate sizeof() on type ${t}`)}}(e));this.cache=function(t,e){return new(f(e))(t)}(t,e)}}}static fromProto(t){if(!t)throw new Error("cannot construct Value from an empty tensor");const e=u.ProtoUtil.tensorDataTypeFromProto(t.dataType),n=u.ProtoUtil.tensorDimsFromProto(t.dims),r=new l(n,e);if("string"===e)t.stringData.forEach(((t,e)=>{r.data[e]=(0,u.decodeUtf8String)(t)}));else if(t.rawData&&"number"==typeof t.rawData.byteLength&&t.rawData.byteLength>0){const e=r.data,n=new DataView(t.rawData.buffer,t.rawData.byteOffset,t.rawData.byteLength),i=p(t.dataType),o=t.rawData.byteLength/i;if(t.rawData.byteLength%i!=0)throw new Error("invalid buffer length");if(e.length!==o)throw new Error("buffer length mismatch");for(let r=0;r0){const e=r.data,n=new DataView(t.rawDataArray().buffer,t.rawDataArray().byteOffset,t.rawDataLength()),i=p(t.dataType()),o=t.rawDataLength()/i;if(t.rawDataLength()%i!=0)throw new Error("invalid buffer length");if(e.length!==o)throw new Error("buffer length mismatch");for(let r=0;r1&&u>1)return;a[o-s]=Math.max(n,u)}return a}static index(t,e){const n=new Array(e.length);return c.fillIndex(t,e,n),n}static fillIndex(t,e,n){const r=t.length-e.length;for(let i=0;i=0;t--)r[t]=l%o[t],l=Math.floor(l/o[t]);d||(c.fillIndex(r,t.dims,i),p=t.get(i)),h||(c.fillIndex(r,e.dims,s),f=e.get(s)),u.set(r,n(p,f))}}return u}}static isValidBroadcast(t,e){const n=t.length,r=e.length;if(n>r)return!1;for(let i=1;i<=n;i++)if(1!==t[n-i]&&t[n-i]!==e[r-i])return!1;return!0}static getBroadcastDims(t,e){const n=t.length,r=[];for(let i=0;i1&&1===a&&r.unshift(o)}return r}}e.BroadcastUtil=c,e.arrayCopyHelper=function(t,e,n,r,i){if(r<0||r>=e.length)throw new Error("sourceIndex out of bounds");if(n<0||n>=t.length)throw new Error("targetIndex out of bounds");if(r+i>e.length)throw new Error("source indices to be copied are outside bounds");if(n+i>t.length)throw new Error("target array is too small to hold result");for(let o=0;oo.default.isLong(t)?t.toNumber():t))}static tensorValueTypeFromProto(t){return{tensorType:l.tensorDataTypeFromProto(t.elemType),shape:{dims:l.tensorDimsFromProto(t.shape.dim.map((t=>t.dimValue)))}}}static tensorDimsFromORTFormat(t){const e=[];for(let n=0;nt.length)throw new Error(`invalid dimension of ${e} for sizeFromDimension as Tensor has ${t.length} dimensions.`);return f.getSizeFromDimensionRange(t,e,t.length)}static sizeToDimension(t,e){if(e<0||e>t.length)throw new Error(`invalid dimension of ${e} for sizeToDimension as Tensor has ${t.length} dimensions.`);return f.getSizeFromDimensionRange(t,0,e)}static getSizeFromDimensionRange(t,e,n){let r=1;for(let i=e;i=0;--r)n[r]=n[r+1]*t[r+1];return n}static transpose(t){return t.slice().reverse()}static indicesToOffset(t,e,n){void 0===n&&(n=t.length);let r=0;for(let i=0;i=e)throw new Error("unsupported axis for this operation.");return t<0?t+e:t}static normalizeAxes(t,e){return t.map((t=>this.normalizeAxis(t,e)))}static incrementIndex(t,e,n){if(0===e.length||0===t.length)throw new Error("Index incrementing unsupported for scalar Tensor");if(void 0===n)n=e.length;else if(n<=0||n>e.length)throw new Error("Incorrect axis to increment on");for(let r=n-1;r>=0&&(t[r]++,!(t[r]=t.length)throw new Error("the dimension with value zero exceeds the dimension size of the input tensor");r[a]=t[a]}else r[a]=e[a];o*=r[a]}}const a=f.size(t);if(-1!==i){if(a%o!=0)throw new Error(`the input tensor cannot be reshaped to the requested shape. Input shape: [${t}] Output shape: [${e}]`);r[i]=a/o}else if(o!==a)throw new Error("reshapedDims and originalDims don't have matching sizes");return r}static sortBasedOnPerm(t,e){return e?e.map((e=>t[e])):t.slice().reverse()}static padShape(t,e){const n=t.length;return t.map(((t,r)=>t+e[r]+e[r+n]))}static areEqual(t,e){return t.length===e.length&&t.every(((t,n)=>t===e[n]))}static validateDimsAndCalcSize(t){if(t.length>6)throw new TypeError("Only rank 0 to 6 is supported for tensor shape.");let e=1;for(const n of t){if(!Number.isInteger(n))throw new TypeError(`Invalid shape: ${n} is not an integer`);if(n<0||n>2147483647)throw new TypeError(`Invalid shape: length ${n} is not allowed`);e*=n}return e}static flattenShape(t,e){e<0&&(e+=t.length);const n=t.reduce(((t,e)=>t*e),1),r=t.slice(e).reduce(((t,e)=>t*e),1);return[n/r,r]}static squeezeShape(t,e){const n=new Array;e=f.normalizeAxes(e,t.length);for(let r=0;r=0;if(i&&1!==t[r])throw new Error("squeeze an axis of size different than 1");(0===e.length&&t[r]>1||e.length>0&&!i)&&n.push(t[r])}return n}static unsqueezeShape(t,e){const n=new Array(t.length+e.length);n.fill(0);for(let t=0;t=n.length)throw new Error("'axes' has an out of range axis");if(0!==n[r])throw new Error("'axes' has a duplicate axis");n[r]=1}let r=0;for(let e=0;e=e.length)throw new Error("sourceIndex out of bounds");if(n<0||n>=t.length)throw new Error("targetIndex out of bounds");if(r+i>e.length)throw new Error("source indices to be copied are outside bounds");if(n+i>t.length)throw new Error("target array is too small to hold result");for(let o=0;o=e.length)throw new Error("sourceIndex out of bounds");if(n<0||n>=t.length)throw new Error("targetIndex out of bounds");if(r+i>e.length)throw new Error("source indices to be copied are outside bounds");if(n+i>t.length)throw new Error("target array is too small to hold result");for(let a=0;a=e.length)throw new Error("sourceIndex out of bounds");if(n<0||n>=t.length)throw new Error("targetIndex out of bounds");if(r+i>e.length)throw new Error("source indices to be copied are outside bounds");if(n+i>t.length)throw new Error("target array is too small to hold result");for(let a=0;a=e.length)throw new Error("sourceIndex out of bounds");if(n<0||n>=t.length)throw new Error("targetIndex out of bounds");if(r+i>e.length)throw new Error("source indices to be copied are outside bounds");if(n+i>t.length)throw new Error("target array is too small to hold result");for(let o=0;oe.push(n)));const a=h.calcReduceShape(o,e,!0),u=f.size(a),l=new s.Tensor(a,t.type),p=f.computeStrides(a),d=f.computeStrides(o),g=new Array(o.length);for(let n=0;n=e.length)return o(t[i]);const u=e[r],c=u>=n.length?1:f.size(n.slice(u+1));for(let l=0;l0!==t))}}e.ReduceUtil=h;class g{static adjustPoolAttributes(t,e,n,r,i,o){if(!t&&n.length!==e.length-2)throw new Error("length of specified kernel shapes should be 2 less than length of input dimensions");if(t)for(let t=0;t=n.length?n.push(e[t+2]):n[t]=e[t+2];for(let t=0;t=n[t]||o[t+n.length]>=n[t])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(t,e,n,r,i,o){if(o){if(i.length!==2*(t.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(e.length!==t.length-2)throw new Error("length of strides should be the length of data dimensions");if(r.length!==t.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let a=0;a{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.iterateExtraOptions=void 0,e.iterateExtraOptions=(t,n,r,i)=>{if("object"==typeof t&&null!==t){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach((([t,o])=>{const a=n?n+t:t;if("object"==typeof o)(0,e.iterateExtraOptions)(o,a+".",r,i);else if("string"==typeof o||"number"==typeof o)i(a,o.toString());else{if("boolean"!=typeof o)throw new Error("Can't handle extra config type: "+typeof o);i(a,o?"1":"0")}}))}},2157:function(t,e,n){"use strict";var r,i=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&i(e,t,n);return o(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=e.initWasm=void 0;const s=n(8453),u=a(n(349)),c=n(6361),l=()=>!!s.env.wasm.proxy&&"undefined"!=typeof document;let p,f,d,h=!1,g=!1,b=!1;const m=[],y=[],_=[],v=[],w=[],x=[],T=()=>{if(h||!g||b||!p)throw new Error("worker not ready")},S=t=>{switch(t.data.type){case"init-wasm":h=!1,t.data.err?(b=!0,f[1](t.data.err)):(g=!0,f[0]());break;case"init-ort":t.data.err?d[1](t.data.err):d[0]();break;case"create_allocate":t.data.err?m.shift()[1](t.data.err):m.shift()[0](t.data.out);break;case"create_finalize":t.data.err?y.shift()[1](t.data.err):y.shift()[0](t.data.out);break;case"create":t.data.err?_.shift()[1](t.data.err):_.shift()[0](t.data.out);break;case"release":t.data.err?v.shift()[1](t.data.err):v.shift()[0]();break;case"run":t.data.err?w.shift()[1](t.data.err):w.shift()[0](t.data.out);break;case"end-profiling":t.data.err?x.shift()[1](t.data.err):x.shift()[0]()}},O="undefined"!=typeof document?null===(r=null===document||void 0===document?void 0:document.currentScript)||void 0===r?void 0:r.src:void 0;e.initWasm=async()=>{if(l()){if(g)return;if(h)throw new Error("multiple calls to 'initWasm()' detected.");if(b)throw new Error("previous call to 'initWasm()' failed.");return h=!0,void 0===s.env.wasm.wasmPaths&&O&&0!==O.indexOf("blob:")&&(s.env.wasm.wasmPaths=O.substr(0,+O.lastIndexOf("/")+1)),new Promise(((t,e)=>{null==p||p.terminate(),p=n(9710).Z(),p.onmessage=S,f=[t,e];const r={type:"init-wasm",in:s.env.wasm};p.postMessage(r)}))}return(0,c.initializeWebAssembly)(s.env.wasm)},e.initOrt=async(t,e)=>{if(l())return T(),new Promise(((n,r)=>{d=[n,r];const i={type:"init-ort",in:{numThreads:t,loggingLevel:e}};p.postMessage(i)}));u.initOrt(t,e)},e.createSessionAllocate=async t=>l()?(T(),new Promise(((e,n)=>{m.push([e,n]);const r={type:"create_allocate",in:{model:t}};p.postMessage(r,[t.buffer])}))):u.createSessionAllocate(t),e.createSessionFinalize=async(t,e)=>l()?(T(),new Promise(((n,r)=>{y.push([n,r]);const i={type:"create_finalize",in:{modeldata:t,options:e}};p.postMessage(i)}))):u.createSessionFinalize(t,e),e.createSession=async(t,e)=>l()?(T(),new Promise(((n,r)=>{_.push([n,r]);const i={type:"create",in:{model:t,options:e}};p.postMessage(i,[t.buffer])}))):u.createSession(t,e),e.releaseSession=async t=>{if(l())return T(),new Promise(((e,n)=>{v.push([e,n]);const r={type:"release",in:t};p.postMessage(r)}));u.releaseSession(t)},e.run=async(t,e,n,r,i)=>l()?(T(),new Promise(((o,a)=>{w.push([o,a]);const s={type:"run",in:{sessionId:t,inputIndices:e,inputs:n,outputIndices:r,options:i}};p.postMessage(s,u.extractTransferableBuffers(n))}))):u.run(t,e,n,r,i),e.endProfiling=async t=>{if(l())return T(),new Promise(((e,n)=>{x.push([e,n]);const r={type:"end-profiling",in:t};p.postMessage(r)}));u.endProfiling(t)}},586:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setRunOptions=void 0;const r=n(7967),i=n(4983),o=n(6361);e.setRunOptions=t=>{const e=(0,o.getInstance)();let n=0;const a=[],s=t||{};try{if(void 0===(null==t?void 0:t.logSeverityLevel))s.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))s.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);void 0===(null==t?void 0:t.terminate)&&(s.terminate=!1);let o=0;if(void 0!==(null==t?void 0:t.tag)&&(o=(0,i.allocWasmString)(t.tag,a)),n=e._OrtCreateRunOptions(s.logSeverityLevel,s.logVerbosityLevel,!!s.terminate,o),0===n)throw new Error("Can't create run options");return void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const o=(0,i.allocWasmString)(t,a),s=(0,i.allocWasmString)(r,a);if(0!==e._OrtAddRunConfigEntry(n,o,s))throw new Error(`Can't set a run config entry: ${t} - ${r}`)})),[n,a]}catch(t){throw 0!==n&&e._OrtReleaseRunOptions(n),a.forEach(e._free),t}}},2306:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.OnnxruntimeWebAssemblySessionHandler=void 0;const r=n(2806),i=n(8453),o=n(2850),a=n(2157);let s;e.OnnxruntimeWebAssemblySessionHandler=class{async createSessionAllocate(t){const e=await fetch(t),n=await e.arrayBuffer();return(0,a.createSessionAllocate)(new Uint8Array(n))}async loadModel(t,e){if(s||(await(0,a.initOrt)(i.env.wasm.numThreads,(t=>{switch(t){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${t}`)}})(i.env.logLevel)),s=!0),"string"==typeof t)if("undefined"==typeof fetch){const n=await(0,o.promisify)(r.readFile)(t);[this.sessionId,this.inputNames,this.outputNames]=await(0,a.createSession)(n,e)}else{const n=await this.createSessionAllocate(t);[this.sessionId,this.inputNames,this.outputNames]=await(0,a.createSessionFinalize)(n,e)}else[this.sessionId,this.inputNames,this.outputNames]=await(0,a.createSession)(t,e)}async dispose(){return(0,a.releaseSession)(this.sessionId)}async run(t,e,n){const r=[],o=[];Object.entries(t).forEach((t=>{const e=t[0],n=t[1],i=this.inputNames.indexOf(e);if(-1===i)throw new Error(`invalid input '${e}'`);r.push(n),o.push(i)}));const s=[];Object.entries(e).forEach((t=>{const e=t[0],n=this.outputNames.indexOf(e);if(-1===n)throw new Error(`invalid output '${e}'`);s.push(n)}));const u=await(0,a.run)(this.sessionId,o,r.map((t=>[t.type,t.dims,t.data])),s,n),c={};for(let t=0;t{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setSessionOptions=void 0;const r=n(7967),i=n(4983),o=n(6361);e.setSessionOptions=t=>{const e=(0,o.getInstance)();let n=0;const a=[],s=t||{};(t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});const e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1")})(s);try{void 0===(null==t?void 0:t.graphOptimizationLevel)&&(s.graphOptimizationLevel="all");const u=(t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}})(s.graphOptimizationLevel);void 0===(null==t?void 0:t.enableCpuMemArena)&&(s.enableCpuMemArena=!0),void 0===(null==t?void 0:t.enableMemPattern)&&(s.enableMemPattern=!0),void 0===(null==t?void 0:t.executionMode)&&(s.executionMode="sequential");const c=(t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}})(s.executionMode);let l=0;if(void 0!==(null==t?void 0:t.logId)&&(l=(0,i.allocWasmString)(t.logId,a)),void 0===(null==t?void 0:t.logSeverityLevel))s.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))s.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);if(void 0===(null==t?void 0:t.enableProfiling)&&(s.enableProfiling=!1),n=e._OrtCreateSessionOptions(u,!!s.enableCpuMemArena,!!s.enableMemPattern,c,!!s.enableProfiling,0,l,s.logSeverityLevel,s.logVerbosityLevel),0===n)throw new Error("Can't create session options");return(null==t?void 0:t.executionProviders)&&((t,e,n)=>{for(const r of e){let e="string"==typeof r?r:r.name;switch(e){case"xnnpack":e="XNNPACK";break;case"wasm":case"cpu":continue;default:throw new Error(`not supported EP: ${e}`)}const a=(0,i.allocWasmString)(e,n);if(0!==(0,o.getInstance)()._OrtAppendExecutionProvider(t,a))throw new Error(`Can't append execution provider: ${e}`)}})(n,t.executionProviders,a),void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const o=(0,i.allocWasmString)(t,a),s=(0,i.allocWasmString)(r,a);if(0!==e._OrtAddSessionConfigEntry(n,o,s))throw new Error(`Can't set a session config entry: ${t} - ${r}`)})),[n,a]}catch(t){throw 0!==n&&e._OrtReleaseSessionOptions(n),a.forEach(e._free),t}}},4983:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.allocWasmString=void 0;const r=n(6361);e.allocWasmString=(t,e)=>{const n=(0,r.getInstance)(),i=n.lengthBytesUTF8(t)+1,o=n._malloc(i);return n.stringToUTF8(t,o,i),e.push(o),o}},349:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.extractTransferableBuffers=e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=void 0;const r=n(586),i=n(4919),o=n(4983),a=n(6361);e.initOrt=(t,e)=>{const n=(0,a.getInstance)()._OrtInit(t,e);if(0!==n)throw new Error(`Can't initialize onnxruntime. error code = ${n}`)};const s=new Map;e.createSessionAllocate=t=>{const e=(0,a.getInstance)(),n=e._malloc(t.byteLength);return e.HEAPU8.set(t,n),[n,t.byteLength]},e.createSessionFinalize=(t,e)=>{const n=(0,a.getInstance)();let r=0,o=0,u=[];try{if([o,u]=(0,i.setSessionOptions)(e),r=n._OrtCreateSession(t[0],t[1],o),0===r)throw new Error("Can't create a session")}finally{n._free(t[0]),n._OrtReleaseSessionOptions(o),u.forEach(n._free)}const c=n._OrtGetInputCount(r),l=n._OrtGetOutputCount(r),p=[],f=[],d=[],h=[];for(let t=0;t{const r=(0,e.createSessionAllocate)(t);return(0,e.createSessionFinalize)(r,n)},e.releaseSession=t=>{const e=(0,a.getInstance)(),n=s.get(t);if(!n)throw new Error("invalid session id");const r=n[0],i=n[1],o=n[2];i.forEach(e._OrtFree),o.forEach(e._OrtFree),e._OrtReleaseSession(r),s.delete(t)};const u=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${t}`)}},c=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${t}`)}},l=t=>{switch(t){case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${t}`)}};e.run=(t,e,n,i,p)=>{const f=(0,a.getInstance)(),d=s.get(t);if(!d)throw new Error("invalid session id");const h=d[0],g=d[1],b=d[2],m=e.length,y=i.length;let _=0,v=[];const w=[],x=[];try{[_,v]=(0,r.setRunOptions)(p);for(let t=0;tf.HEAP32[t++]=e));const n=f._OrtCreateTensor(u(e),a,s,l,r.length);if(0===n)throw new Error("Can't create a tensor");w.push(n)}finally{f.stackRestore(c)}}const t=f.stackSave(),a=f.stackAlloc(4*m),s=f.stackAlloc(4*m),d=f.stackAlloc(4*y),T=f.stackAlloc(4*y);try{let n=a/4,r=s/4,o=d/4,u=T/4;for(let t=0;tt*e));if(i=c(a),"string"===i){const t=[];let e=o/4;for(let n=0;n{const e=(0,a.getInstance)(),n=s.get(t);if(!n)throw new Error("invalid session id");const r=n[0],i=e._OrtEndProfiling(r);if(0===i)throw new Error("Can't get an profile file name");e._OrtFree(i)},e.extractTransferableBuffers=t=>{const e=[];for(const n of t){const t=n[2];!Array.isArray(t)&&t.buffer&&e.push(t.buffer)}return e}},6361:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return i(e,t),e},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.dispose=e.getInstance=e.initializeWebAssembly=void 0;const s=o(n(6449)),u=a(n(932)),c=n(3474);let l,p=!1,f=!1,d=!1;const h=(t,e)=>e?t?"ort-wasm-simd-threaded.wasm":"ort-wasm-threaded.wasm":t?"ort-wasm-simd.wasm":"ort-wasm.wasm";e.initializeWebAssembly=async t=>{if(p)return Promise.resolve();if(f)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(d)throw new Error("previous call to 'initializeWebAssembly()' failed.");f=!0;const e=t.initTimeout,r=t.numThreads,i=t.simd,o=r>1&&(()=>{try{return"undefined"!=typeof SharedArrayBuffer&&("undefined"!=typeof MessageChannel&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11])))}catch(t){return!1}})(),a=i&&(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch(t){return!1}})(),g="string"==typeof t.wasmPaths?t.wasmPaths:void 0,b=h(!1,o),m=h(a,o),y="object"==typeof t.wasmPaths?t.wasmPaths[m]:void 0;let _=!1;const v=[];if(e>0&&v.push(new Promise((t=>{setTimeout((()=>{_=!0,t()}),e)}))),v.push(new Promise(((t,e)=>{const r=o?c:u.default,i={locateFile:(t,e)=>o&&t.endsWith(".worker.js")&&"undefined"!=typeof Blob?URL.createObjectURL(new Blob([n(4154)],{type:"text/javascript"})):t===b?null!=y?y:(null!=g?g:e)+m:e+t};if(o)if("undefined"==typeof Blob)i.mainScriptUrlOrBlob=s.join("/","ort-wasm-threaded.js");else{const t=`var ortWasmThreaded=(function(){var _scriptDir;return ${r.toString()}})();`;i.mainScriptUrlOrBlob=new Blob([t],{type:"text/javascript"})}r(i).then((e=>{f=!1,p=!0,l=e,t()}),(t=>{f=!1,d=!0,e(t)}))}))),await Promise.race(v),_)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},e.getInstance=()=>{if(p&&l)return l;throw new Error("WebAssembly is not initialized yet.")},e.dispose=()=>{var t;!p||f||d||(f=!0,null===(t=l.PThread)||void 0===t||t.terminateAllThreads(),l=void 0,f=!1,p=!1,d=!0)}},9710:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(477),i=n.n(r);function o(){return i()('/*!\n* ONNX Runtime Web v1.14.0\n* Copyright (c) Microsoft Corporation. All rights reserved.\n* Licensed under the MIT License.\n*/\n(()=>{var t={474:(t,e,n)=>{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){function e(){return j.buffer!=D&&N(j.buffer),P}function r(){return j.buffer!=D&&N(j.buffer),U}function a(){return j.buffer!=D&&N(j.buffer),F}function i(){return j.buffer!=D&&N(j.buffer),I}function o(){return j.buffer!=D&&N(j.buffer),W}var u,c,s;t=t||{},u||(u=void 0!==t?t:{}),u.ready=new Promise((function(t,e){c=t,s=e}));var l,f,p,h,d,y,b=Object.assign({},u),m="./this.program",g=(t,e)=>{throw e},v="object"==typeof window,w="function"==typeof importScripts,_="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,O=u.ENVIRONMENT_IS_PTHREAD||!1,A="";function S(t){return u.locateFile?u.locateFile(t,A):A+t}if(_){let e;A=w?n(908).dirname(A)+"/":"//",y=()=>{d||(h=n(384),d=n(908))},l=function(t,e){return y(),t=d.normalize(t),h.readFileSync(t,e?void 0:"utf8")},p=t=>((t=l(t,!0)).buffer||(t=new Uint8Array(t)),t),f=(t,e,n)=>{y(),t=d.normalize(t),h.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(Q())throw process.exitCode=t,e;e instanceof ct||x("exiting due to exception: "+e),process.exit(t)},u.inspect=function(){return"[Emscripten Module object]"};try{e=n(925)}catch(t){throw console.error(\'The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?\'),t}n.g.Worker=e.Worker}else(v||w)&&(w?A=self.location.href:"undefined"!=typeof document&&document.currentScript&&(A=document.currentScript.src),_scriptDir&&(A=_scriptDir),A=0!==A.indexOf("blob:")?A.substr(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1):"",_||(l=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},w&&(p=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),f=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)}));_&&"undefined"==typeof performance&&(n.g.performance=n(953).performance);var T=console.log.bind(console),E=console.warn.bind(console);_&&(y(),T=t=>h.writeSync(1,t+"\\n"),E=t=>h.writeSync(2,t+"\\n"));var M,C=u.print||T,x=u.printErr||E;Object.assign(u,b),b=null,u.thisProgram&&(m=u.thisProgram),u.quit&&(g=u.quit),u.wasmBinary&&(M=u.wasmBinary);var R=u.noExitRuntime||!1;"object"!=typeof WebAssembly&&at("no native wasm support detected");var j,k,D,P,U,F,I,W,H=!1,L="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function z(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&t[e++])?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else r+=String.fromCharCode(a)}return r}function Y(t,e){return(t>>>=0)?z(r(),t,e):""}function B(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var i=0;i=o&&(o=65536+((1023&o)<<10)|1023&t.charCodeAt(++i)),127>=o){if(n>=r)break;e[n++>>>0]=o}else{if(2047>=o){if(n+1>=r)break;e[n++>>>0]=192|o>>6}else{if(65535>=o){if(n+2>=r)break;e[n++>>>0]=224|o>>12}else{if(n+3>=r)break;e[n++>>>0]=240|o>>18,e[n++>>>0]=128|o>>12&63}e[n++>>>0]=128|o>>6&63}e[n++>>>0]=128|63&o}}return e[n>>>0]=0,n-a}function G(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function N(t){D=t,u.HEAP8=P=new Int8Array(t),u.HEAP16=new Int16Array(t),u.HEAP32=F=new Int32Array(t),u.HEAPU8=U=new Uint8Array(t),u.HEAPU16=new Uint16Array(t),u.HEAPU32=I=new Uint32Array(t),u.HEAPF32=new Float32Array(t),u.HEAPF64=W=new Float64Array(t)}O&&(D=u.buffer);var V=u.INITIAL_MEMORY||16777216;if(O)j=u.wasmMemory,D=u.buffer;else if(u.wasmMemory)j=u.wasmMemory;else if(!((j=new WebAssembly.Memory({initial:V/65536,maximum:65536,shared:!0})).buffer instanceof SharedArrayBuffer))throw x("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),_&&console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)"),Error("bad memory");j&&(D=j.buffer),V=D.byteLength,N(D);var $,q=[],X=[],J=[],Z=[];function Q(){return R||!1}function K(){var t=u.preRun.shift();q.unshift(t)}var tt,et=0,nt=null,rt=null;function at(t){throw O?postMessage({cmd:"onAbort",arg:t}):u.onAbort&&u.onAbort(t),x(t="Aborted("+t+")"),H=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),s(t),t}function it(){return tt.startsWith("data:application/octet-stream;base64,")}function ot(){var t=tt;try{if(t==tt&&M)return new Uint8Array(M);if(p)return p(t);throw"both async and sync fetching of the wasm failed"}catch(t){at(t)}}tt="ort-wasm-threaded.wasm",it()||(tt=S(tt));var ut={};function ct(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function st(t){(t=ht.Vb[t])||at(),ht.mc(t)}function lt(t){var e=ht.Cc();if(!e)return 6;ht.ac.push(e),ht.Vb[t.Ub]=e,e.Ub=t.Ub;var n={cmd:"run",start_routine:t.Ic,arg:t.zc,pthread_ptr:t.Ub};return e.$b=()=>{n.time=performance.now(),e.postMessage(n,t.Nc)},e.loaded&&(e.$b(),delete e.$b),0}function ft(t){if(O)return $t(1,1,t);Q()||(ht.oc(),u.onExit&&u.onExit(t),H=!0),g(t,new ct(t))}function pt(t,e){if(!e&&O)throw bt(t),"unwind";Q()||O||(me(),dt(J),be(0),re[1].length&&ae(1,10),re[2].length&&ae(2,10),ht.oc()),ft(t)}var ht={Yb:[],ac:[],qc:[],Vb:{},fc:function(){O&&ht.Ec()},Pc:function(){},Ec:function(){ht.receiveObjectTransfer=ht.Gc,ht.threadInitTLS=ht.pc,ht.setExitStatus=ht.nc,R=!1},nc:function(){},oc:function(){for(var t of Object.values(ht.Vb))ht.mc(t);for(t of ht.Yb)t.terminate();ht.Yb=[]},mc:function(t){var e=t.Ub;delete ht.Vb[e],ht.Yb.push(t),ht.ac.splice(ht.ac.indexOf(t),1),t.Ub=0,Oe(e)},Gc:function(){},pc:function(){ht.qc.forEach((t=>t()))},Fc:function(t,e){t.onmessage=n=>{var r=(n=n.data).cmd;if(t.Ub&&(ht.Bc=t.Ub),n.targetThread&&n.targetThread!=he()){var a=ht.Vb[n.Qc];a?a.postMessage(n,n.transferList):x(\'Internal error! Worker sent a message "\'+r+\'" to target pthread \'+n.targetThread+", but that thread no longer exists!")}else"processProxyingQueue"===r?zt(n.queue):"spawnThread"===r?lt(n):"cleanupThread"===r?st(n.thread):"killThread"===r?(n=n.thread,r=ht.Vb[n],delete ht.Vb[n],r.terminate(),Oe(n),ht.ac.splice(ht.ac.indexOf(r),1),r.Ub=0):"cancelThread"===r?ht.Vb[n.thread].postMessage({cmd:"cancel"}):"loaded"===r?(t.loaded=!0,e&&e(t),t.$b&&(t.$b(),delete t.$b)):"print"===r?C("Thread "+n.threadId+": "+n.text):"printErr"===r?x("Thread "+n.threadId+": "+n.text):"alert"===r?alert("Thread "+n.threadId+": "+n.text):"setimmediate"===n.target?t.postMessage(n):"onAbort"===r?u.onAbort&&u.onAbort(n.arg):r&&x("worker sent an unknown command "+r);ht.Bc=void 0},t.onerror=t=>{throw x("worker sent an error! "+t.filename+":"+t.lineno+": "+t.message),t},_&&(t.on("message",(function(e){t.onmessage({data:e})})),t.on("error",(function(e){t.onerror(e)})),t.on("detachedExit",(function(){}))),t.postMessage({cmd:"load",urlOrBlob:u.mainScriptUrlOrBlob||_scriptDir,wasmMemory:j,wasmModule:k})},yc:function(){var t=S("ort-wasm-threaded.worker.js");ht.Yb.push(new Worker(t))},Cc:function(){return 0==ht.Yb.length&&(ht.yc(),ht.Fc(ht.Yb[0])),ht.Yb.pop()}};function dt(t){for(;0>2>>>0];t=a()[t+48>>2>>>0],Te(e,e-t),Me(e)};var mt=[];function gt(t){var e=mt[t];return e||(t>=mt.length&&(mt.length=t+1),mt[t]=e=$.get(t)),e}u.invokeEntryPoint=function(t,e){t=gt(t)(e),Q()?ht.nc(t):Ae(t)};var vt,wt,_t=[],Ot=0,At=0;function St(t){this.Zb=t,this.Sb=t-24,this.xc=function(t){i()[this.Sb+4>>2>>>0]=t},this.bc=function(){return i()[this.Sb+4>>2>>>0]},this.wc=function(t){i()[this.Sb+8>>2>>>0]=t},this.Dc=function(){return i()[this.Sb+8>>2>>>0]},this.rc=function(){a()[this.Sb>>2>>>0]=0},this.hc=function(t){t=t?1:0,e()[this.Sb+12>>0>>>0]=t},this.uc=function(){return 0!=e()[this.Sb+12>>0>>>0]},this.ic=function(t){t=t?1:0,e()[this.Sb+13>>0>>>0]=t},this.kc=function(){return 0!=e()[this.Sb+13>>0>>>0]},this.fc=function(t,e){this.cc(0),this.xc(t),this.wc(e),this.rc(),this.hc(!1),this.ic(!1)},this.sc=function(){Atomics.add(a(),this.Sb>>2,1)},this.Hc=function(){return 1===Atomics.sub(a(),this.Sb>>2,1)},this.cc=function(t){i()[this.Sb+16>>2>>>0]=t},this.tc=function(){return i()[this.Sb+16>>2>>>0]},this.vc=function(){if(Re(this.bc()))return i()[this.Zb>>2>>>0];var t=this.tc();return 0!==t?t:this.Zb}}function Tt(t){return ye(new St(t).Sb)}function Et(t,e,n,r){return O?$t(3,1,t,e,n,r):Mt(t,e,n,r)}function Mt(t,e,n,r){if("undefined"==typeof SharedArrayBuffer)return x("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var a=[];return O&&0===a.length?Et(t,e,n,r):(t={Ic:n,Ub:t,zc:r,Nc:a},O?(t.Oc="spawnThread",postMessage(t,a),0):lt(t))}function Ct(t,e,n){return O?$t(4,1,t,e,n):0}function xt(t,e){if(O)return $t(5,1,t,e)}function Rt(t,e){if(O)return $t(6,1,t,e)}function jt(t,e,n){if(O)return $t(7,1,t,e,n)}function kt(t,e,n){return O?$t(8,1,t,e,n):0}function Dt(t,e){if(O)return $t(9,1,t,e)}function Pt(t,e,n){if(O)return $t(10,1,t,e,n)}function Ut(t,e,n,r){if(O)return $t(11,1,t,e,n,r)}function Ft(t,e,n,r){if(O)return $t(12,1,t,e,n,r)}function It(t,e,n,r){if(O)return $t(13,1,t,e,n,r)}function Wt(t){if(O)return $t(14,1,t)}function Ht(t,e){if(O)return $t(15,1,t,e)}function Lt(t,e,n){if(O)return $t(16,1,t,e,n)}function zt(t){Atomics.store(a(),t>>2,1),he()&&_e(t),Atomics.compareExchange(a(),t>>2,1,0)}function Yt(t){return i()[t>>>2]+4294967296*a()[t+4>>>2]}function Bt(t,e,n,r,a,i){return O?$t(17,1,t,e,n,r,a,i):-52}function Gt(t,e,n,r,a,i){if(O)return $t(18,1,t,e,n,r,a,i)}function Nt(t){var n=G(t)+1,r=de(n);return r&&B(t,e(),r,n),r}function Vt(t,e,n){function r(t){return(t=t.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?t[1]:"GMT"}if(O)return $t(19,1,t,e,n);var o=(new Date).getFullYear(),u=new Date(o,0,1),c=new Date(o,6,1);o=u.getTimezoneOffset();var s=c.getTimezoneOffset(),l=Math.max(o,s);a()[t>>2>>>0]=60*l,a()[e>>2>>>0]=Number(o!=s),t=r(u),e=r(c),t=Nt(t),e=Nt(e),s>2>>>0]=t,i()[n+4>>2>>>0]=e):(i()[n>>2>>>0]=e,i()[n+4>>2>>>0]=t)}function $t(t,e){var n=arguments.length-2,r=arguments;return yt((()=>{for(var a=Ce(8*n),i=a>>3,u=0;u>>0]=c}return we(t,n,a,e)}))}u.executeNotifiedProxyingQueue=zt,wt=_?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:O?()=>performance.now()-u.__performance_now_clock_drift:()=>performance.now();var qt,Xt=[],Jt={};function Zt(){if(!qt){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:m||"./this.program"};for(t in Jt)void 0===Jt[t]?delete e[t]:e[t]=Jt[t];var n=[];for(t in e)n.push(t+"="+e[t]);qt=n}return qt}function Qt(t,n){if(O)return $t(20,1,t,n);var r=0;return Zt().forEach((function(a,o){var u=n+r;for(o=i()[t+4*o>>2>>>0]=u,u=0;u>0>>>0]=a.charCodeAt(u);e()[o>>0>>>0]=0,r+=a.length+1})),0}function Kt(t,e){if(O)return $t(21,1,t,e);var n=Zt();i()[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),i()[e>>2>>>0]=r,0}function te(t){return O?$t(22,1,t):52}function ee(t,e,n,r){return O?$t(23,1,t,e,n,r):52}function ne(t,e,n,r,a){return O?$t(24,1,t,e,n,r,a):70}var re=[null,[],[]];function ae(t,e){var n=re[t];0===e||10===e?((1===t?C:x)(z(n,0)),n.length=0):n.push(e)}function ie(t,e,n,a){if(O)return $t(25,1,t,e,n,a);for(var o=0,u=0;u>2>>>0],s=i()[e+4>>2>>>0];e+=8;for(var l=0;l>>0]);o+=s}return i()[a>>2>>>0]=o,0}var oe=0;function ue(t){return 0==t%4&&(0!=t%100||0==t%400)}var ce=[31,29,31,30,31,30,31,31,30,31,30,31],se=[31,28,31,30,31,30,31,31,30,31,30,31];function le(t,n,r,i){function o(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=s(new Date(t.getFullYear(),0,4)),n=s(n),0>=c(e,t)?0>=c(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var f=a()[i+40>>2>>>0];for(var p in i={Lc:a()[i>>2>>>0],Kc:a()[i+4>>2>>>0],dc:a()[i+8>>2>>>0],jc:a()[i+12>>2>>>0],ec:a()[i+16>>2>>>0],Xb:a()[i+20>>2>>>0],Tb:a()[i+24>>2>>>0],Wb:a()[i+28>>2>>>0],Rc:a()[i+32>>2>>>0],Jc:a()[i+36>>2>>>0],Mc:f?Y(f):""},r=Y(r),f={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})r=r.replace(new RegExp(p,"g"),f[p]);var h="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),d="January February March April May June July August September October November December".split(" ");for(p in f={"%a":function(t){return h[t.Tb].substring(0,3)},"%A":function(t){return h[t.Tb]},"%b":function(t){return d[t.ec].substring(0,3)},"%B":function(t){return d[t.ec]},"%C":function(t){return u((t.Xb+1900)/100|0,2)},"%d":function(t){return u(t.jc,2)},"%e":function(t){return o(t.jc,2," ")},"%g":function(t){return l(t).toString().substring(2)},"%G":function(t){return l(t)},"%H":function(t){return u(t.dc,2)},"%I":function(t){return 0==(t=t.dc)?t=12:12t.dc?"AM":"PM"},"%S":function(t){return u(t.Lc,2)},"%t":function(){return"\\t"},"%u":function(t){return t.Tb||7},"%U":function(t){return u(Math.floor((t.Wb+7-t.Tb)/7),2)},"%V":function(t){var e=Math.floor((t.Wb+7-(t.Tb+6)%7)/7);if(2>=(t.Tb+371-t.Wb-2)%7&&e++,e)53==e&&(4==(n=(t.Tb+371-t.Wb)%7)||3==n&&ue(t.Xb)||(e=1));else{e=52;var n=(t.Tb+7-t.Wb-1)%7;(4==n||5==n&&ue(t.Xb%400-1))&&e++}return u(e,2)},"%w":function(t){return t.Tb},"%W":function(t){return u(Math.floor((t.Wb+7-(t.Tb+6)%7)/7),2)},"%y":function(t){return(t.Xb+1900).toString().substring(2)},"%Y":function(t){return t.Xb+1900},"%z":function(t){var e=0<=(t=t.Jc);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.Mc},"%%":function(){return"%"}},r=r.replace(/%%/g,"\\0\\0"),f)r.includes(p)&&(r=r.replace(new RegExp(p,"g"),f[p](i)));return p=function(t){var e=Array(G(t)+1);return B(t,e,0,e.length),e}(r=r.replace(/\\0\\0/g,"%")),p.length>n?0:(function(t,n){e().set(t,n>>>0)}(p,t),p.length-1)}ht.fc();var fe=[null,ft,bt,Et,Ct,xt,Rt,jt,kt,Dt,Pt,Ut,Ft,It,Wt,Ht,Lt,Bt,Gt,Vt,Qt,Kt,te,ee,ne,ie],pe={b:function(t){return de(t+24)+24},n:function(t){return(t=new St(t)).uc()||(t.hc(!0),Ot--),t.ic(!1),_t.push(t),t.sc(),t.vc()},ma:function(t){throw x("Unexpected exception thrown, this is not properly supported - aborting"),H=!0,t},x:function(){Se(0);var t=_t.pop();if(t.Hc()&&!t.kc()){var e=t.Dc();e&>(e)(t.Zb),Tt(t.Zb)}At=0},e:function(){var t=At;if(!t)return oe=0;var e=new St(t);e.cc(t);var n=e.bc();if(!n)return oe=0,t;for(var r=Array.prototype.slice.call(arguments),a=0;azt(r)));else if(O)postMessage({targetThread:t,cmd:"processProxyingQueue",queue:r});else{if(!(t=ht.Vb[t]))return;t.postMessage({cmd:"processProxyingQueue",queue:r})}return 1},Ea:function(){return-1},Pa:function(t,e){t=new Date(1e3*Yt(t)),a()[e>>2>>>0]=t.getUTCSeconds(),a()[e+4>>2>>>0]=t.getUTCMinutes(),a()[e+8>>2>>>0]=t.getUTCHours(),a()[e+12>>2>>>0]=t.getUTCDate(),a()[e+16>>2>>>0]=t.getUTCMonth(),a()[e+20>>2>>>0]=t.getUTCFullYear()-1900,a()[e+24>>2>>>0]=t.getUTCDay(),t=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,a()[e+28>>2>>>0]=t},Qa:function(t,e){t=new Date(1e3*Yt(t)),a()[e>>2>>>0]=t.getSeconds(),a()[e+4>>2>>>0]=t.getMinutes(),a()[e+8>>2>>>0]=t.getHours(),a()[e+12>>2>>>0]=t.getDate(),a()[e+16>>2>>>0]=t.getMonth(),a()[e+20>>2>>>0]=t.getFullYear()-1900,a()[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1),r=(t.getTime()-n.getTime())/864e5|0;a()[e+28>>2>>>0]=r,a()[e+36>>2>>>0]=-60*t.getTimezoneOffset(),r=new Date(t.getFullYear(),6,1).getTimezoneOffset(),t=0|(r!=(n=n.getTimezoneOffset())&&t.getTimezoneOffset()==Math.min(n,r)),a()[e+32>>2>>>0]=t},Ra:function(t){var e=new Date(a()[t+20>>2>>>0]+1900,a()[t+16>>2>>>0],a()[t+12>>2>>>0],a()[t+8>>2>>>0],a()[t+4>>2>>>0],a()[t>>2>>>0],0),n=a()[t+32>>2>>>0],r=e.getTimezoneOffset(),i=new Date(e.getFullYear(),0,1),o=new Date(e.getFullYear(),6,1).getTimezoneOffset(),u=i.getTimezoneOffset(),c=Math.min(u,o);return 0>n?a()[t+32>>2>>>0]=Number(o!=u&&c==r):0>2>>>0]=e.getDay(),n=(e.getTime()-i.getTime())/864e5|0,a()[t+28>>2>>>0]=n,a()[t>>2>>>0]=e.getSeconds(),a()[t+4>>2>>>0]=e.getMinutes(),a()[t+8>>2>>>0]=e.getHours(),a()[t+12>>2>>>0]=e.getDate(),a()[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},Aa:Bt,Ba:Gt,Sa:function t(e,n,r){t.Ac||(t.Ac=!0,Vt(e,n,r))},y:function(){at("")},U:function(){if(!_&&!w){var t="Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread";vt||(vt={}),vt[t]||(vt[t]=1,_&&(t="warning: "+t),x(t))}},ra:function(){return 4294901760},B:wt,Ia:function(t,e,n){r().copyWithin(t>>>0,e>>>0,e+n>>>0)},F:function(){return _?n(993).cpus().length:navigator.hardwareConcurrency},Da:function(t,e,n){Xt.length=e,n>>=3;for(var r=0;r>>0];return(0>t?ut[-t-1]:fe[t]).apply(null,Xt)},qa:function(t){var e=r().length;if((t>>>=0)<=e||4294901760=n;n*=2){var a=e*(1+.2/n);a=Math.min(a,t+100663296);var i=Math;a=Math.max(t,a),i=i.min.call(i,4294901760,a+(65536-a%65536)%65536);t:{try{j.grow(i-D.byteLength+65535>>>16),N(j.buffer);var o=1;break t}catch(t){}o=void 0}if(o)return!0}return!1},Na:function(){throw"unwind"},Ga:Qt,Ha:Kt,J:pt,I:te,S:ee,ga:ne,R:ie,d:function(){return oe},na:function t(r,a){t.lc||(t.lc=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(_)try{var e=n(Object(function(){var t=new Error("Cannot find module \'crypto\'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>at("randomDevice")}());for(var i=0;i>0>>>0]=t.lc();return 0},ia:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},ja:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},K:function(t){var e=Ee();try{return gt(t)()}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},f:function(t,e){var n=Ee();try{return gt(t)(e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},P:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},Q:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},k:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},p:function(t,e,n,r){var a=Ee();try{return gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},q:function(t,e,n,r,a){var i=Ee();try{return gt(t)(e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},N:function(t,e,n,r,a,i){var o=Ee();try{return gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},s:function(t,e,n,r,a,i){var o=Ee();try{return gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},w:function(t,e,n,r,a,i,o){var u=Ee();try{return gt(t)(e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},L:function(t,e,n,r,a,i,o,u){var c=Ee();try{return gt(t)(e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},E:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=Ee();try{return gt(t)(e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(Me(p),t!==t+0)throw t;Se(1,0)}},aa:function(t,e,n,r,a,i,o,u){var c=Ee();try{return He(t,e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},_:function(t,e,n,r,a,i,o){var u=Ee();try{return ke(t,e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},Z:function(t,e,n,r,a){var i=Ee();try{return Le(t,e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},ca:function(t,e,n,r){var a=Ee();try{return Ie(t,e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},$:function(t){var e=Ee();try{return je(t)}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},ba:function(t,e){var n=Ee();try{return We(t,e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},Y:function(t,e,n){var r=Ee();try{return De(t,e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},g:function(t){var e=Ee();try{gt(t)()}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},r:function(t,e){var n=Ee();try{gt(t)(e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},i:function(t,e,n){var r=Ee();try{gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},ha:function(t,e,n,r){var a=Ee();try{gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},m:function(t,e,n,r){var a=Ee();try{gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},v:function(t,e,n,r,a){var i=Ee();try{gt(t)(e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},u:function(t,e,n,r,a,i){var o=Ee();try{gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},O:function(t,e,n,r,a,i,o){var u=Ee();try{gt(t)(e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},A:function(t,e,n,r,a,i,o,u){var c=Ee();try{gt(t)(e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},ka:function(t,e,n,r,a,i,o,u,c){var s=Ee();try{gt(t)(e,n,r,a,i,o,u,c)}catch(t){if(Me(s),t!==t+0)throw t;Se(1,0)}},C:function(t,e,n,r,a,i,o,u,c,s,l){var f=Ee();try{gt(t)(e,n,r,a,i,o,u,c,s,l)}catch(t){if(Me(f),t!==t+0)throw t;Se(1,0)}},D:function(t,e,n,r,a,i,o,u,c,s,l,f,p,h,d,y){var b=Ee();try{gt(t)(e,n,r,a,i,o,u,c,s,l,f,p,h,d,y)}catch(t){if(Me(b),t!==t+0)throw t;Se(1,0)}},fa:function(t,e,n,r,a,i,o,u){var c=Ee();try{Pe(t,e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},da:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=Ee();try{Fe(t,e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(Me(p),t!==t+0)throw t;Se(1,0)}},ea:function(t,e,n,r,a,i){var o=Ee();try{Ue(t,e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},o:function(t){return t},a:j||u.wasmMemory,G:function(t){oe=t},la:le,z:function(t,e,n,r){return le(t,e,n,r)}};!function(){function t(t,e){u.asm=t.exports,ht.qc.push(u.asm.sb),$=u.asm.ub,X.unshift(u.asm.Va),k=e,O||(et--,u.monitorRunDependencies&&u.monitorRunDependencies(et),0==et&&(null!==nt&&(clearInterval(nt),nt=null),rt&&(t=rt,rt=null,t())))}function e(e){t(e.instance,e.module)}function n(t){return function(){if(!M&&(v||w)){if("function"==typeof fetch&&!tt.startsWith("file://"))return fetch(tt,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at \'"+tt+"\'";return t.arrayBuffer()})).catch((function(){return ot()}));if(f)return new Promise((function(t,e){f(tt,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return ot()}))}().then((function(t){return WebAssembly.instantiate(t,r)})).then((function(t){return t})).then(t,(function(t){x("failed to asynchronously prepare wasm: "+t),at(t)}))}var r={a:pe};if(O||(et++,u.monitorRunDependencies&&u.monitorRunDependencies(et)),u.instantiateWasm)try{return u.instantiateWasm(r,t)}catch(t){return x("Module.instantiateWasm callback failed with error: "+t),!1}(M||"function"!=typeof WebAssembly.instantiateStreaming||it()||tt.startsWith("file://")||_||"function"!=typeof fetch?n(e):fetch(tt,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(e,(function(t){return x("wasm streaming compile failed: "+t),x("falling back to ArrayBuffer instantiation"),n(e)}))}))).catch(s)}(),u.___wasm_call_ctors=function(){return(u.___wasm_call_ctors=u.asm.Va).apply(null,arguments)},u._OrtInit=function(){return(u._OrtInit=u.asm.Wa).apply(null,arguments)},u._OrtCreateSessionOptions=function(){return(u._OrtCreateSessionOptions=u.asm.Xa).apply(null,arguments)},u._OrtAppendExecutionProvider=function(){return(u._OrtAppendExecutionProvider=u.asm.Ya).apply(null,arguments)},u._OrtAddSessionConfigEntry=function(){return(u._OrtAddSessionConfigEntry=u.asm.Za).apply(null,arguments)},u._OrtReleaseSessionOptions=function(){return(u._OrtReleaseSessionOptions=u.asm._a).apply(null,arguments)},u._OrtCreateSession=function(){return(u._OrtCreateSession=u.asm.$a).apply(null,arguments)},u._OrtReleaseSession=function(){return(u._OrtReleaseSession=u.asm.ab).apply(null,arguments)},u._OrtGetInputCount=function(){return(u._OrtGetInputCount=u.asm.bb).apply(null,arguments)},u._OrtGetOutputCount=function(){return(u._OrtGetOutputCount=u.asm.cb).apply(null,arguments)},u._OrtGetInputName=function(){return(u._OrtGetInputName=u.asm.db).apply(null,arguments)},u._OrtGetOutputName=function(){return(u._OrtGetOutputName=u.asm.eb).apply(null,arguments)},u._OrtFree=function(){return(u._OrtFree=u.asm.fb).apply(null,arguments)},u._OrtCreateTensor=function(){return(u._OrtCreateTensor=u.asm.gb).apply(null,arguments)},u._OrtGetTensorData=function(){return(u._OrtGetTensorData=u.asm.hb).apply(null,arguments)},u._OrtReleaseTensor=function(){return(u._OrtReleaseTensor=u.asm.ib).apply(null,arguments)},u._OrtCreateRunOptions=function(){return(u._OrtCreateRunOptions=u.asm.jb).apply(null,arguments)},u._OrtAddRunConfigEntry=function(){return(u._OrtAddRunConfigEntry=u.asm.kb).apply(null,arguments)},u._OrtReleaseRunOptions=function(){return(u._OrtReleaseRunOptions=u.asm.lb).apply(null,arguments)},u._OrtRun=function(){return(u._OrtRun=u.asm.mb).apply(null,arguments)},u._OrtEndProfiling=function(){return(u._OrtEndProfiling=u.asm.nb).apply(null,arguments)};var he=u._pthread_self=function(){return(he=u._pthread_self=u.asm.ob).apply(null,arguments)},de=u._malloc=function(){return(de=u._malloc=u.asm.pb).apply(null,arguments)},ye=u._free=function(){return(ye=u._free=u.asm.qb).apply(null,arguments)},be=u._fflush=function(){return(be=u._fflush=u.asm.rb).apply(null,arguments)};u.__emscripten_tls_init=function(){return(u.__emscripten_tls_init=u.asm.sb).apply(null,arguments)};var me=u.___funcs_on_exit=function(){return(me=u.___funcs_on_exit=u.asm.tb).apply(null,arguments)},ge=u.__emscripten_thread_init=function(){return(ge=u.__emscripten_thread_init=u.asm.vb).apply(null,arguments)};u.__emscripten_thread_crashed=function(){return(u.__emscripten_thread_crashed=u.asm.wb).apply(null,arguments)};var ve,we=u._emscripten_run_in_main_runtime_thread_js=function(){return(we=u._emscripten_run_in_main_runtime_thread_js=u.asm.xb).apply(null,arguments)},_e=u.__emscripten_proxy_execute_task_queue=function(){return(_e=u.__emscripten_proxy_execute_task_queue=u.asm.yb).apply(null,arguments)},Oe=u.__emscripten_thread_free_data=function(){return(Oe=u.__emscripten_thread_free_data=u.asm.zb).apply(null,arguments)},Ae=u.__emscripten_thread_exit=function(){return(Ae=u.__emscripten_thread_exit=u.asm.Ab).apply(null,arguments)},Se=u._setThrew=function(){return(Se=u._setThrew=u.asm.Bb).apply(null,arguments)},Te=u._emscripten_stack_set_limits=function(){return(Te=u._emscripten_stack_set_limits=u.asm.Cb).apply(null,arguments)},Ee=u.stackSave=function(){return(Ee=u.stackSave=u.asm.Db).apply(null,arguments)},Me=u.stackRestore=function(){return(Me=u.stackRestore=u.asm.Eb).apply(null,arguments)},Ce=u.stackAlloc=function(){return(Ce=u.stackAlloc=u.asm.Fb).apply(null,arguments)},xe=u.___cxa_can_catch=function(){return(xe=u.___cxa_can_catch=u.asm.Gb).apply(null,arguments)},Re=u.___cxa_is_pointer_type=function(){return(Re=u.___cxa_is_pointer_type=u.asm.Hb).apply(null,arguments)},je=u.dynCall_j=function(){return(je=u.dynCall_j=u.asm.Ib).apply(null,arguments)},ke=u.dynCall_iiiiij=function(){return(ke=u.dynCall_iiiiij=u.asm.Jb).apply(null,arguments)},De=u.dynCall_jii=function(){return(De=u.dynCall_jii=u.asm.Kb).apply(null,arguments)},Pe=u.dynCall_viiiiij=function(){return(Pe=u.dynCall_viiiiij=u.asm.Lb).apply(null,arguments)},Ue=u.dynCall_vjji=function(){return(Ue=u.dynCall_vjji=u.asm.Mb).apply(null,arguments)},Fe=u.dynCall_viiijjjii=function(){return(Fe=u.dynCall_viiijjjii=u.asm.Nb).apply(null,arguments)},Ie=u.dynCall_iij=function(){return(Ie=u.dynCall_iij=u.asm.Ob).apply(null,arguments)},We=u.dynCall_ji=function(){return(We=u.dynCall_ji=u.asm.Pb).apply(null,arguments)},He=u.dynCall_iiiiiij=function(){return(He=u.dynCall_iiiiiij=u.asm.Qb).apply(null,arguments)},Le=u.dynCall_iiij=function(){return(Le=u.dynCall_iiij=u.asm.Rb).apply(null,arguments)};function ze(){function t(){if(!ve&&(ve=!0,u.calledRun=!0,!H)&&(O||dt(X),c(u),u.onRuntimeInitialized&&u.onRuntimeInitialized(),!O)){if(u.postRun)for("function"==typeof u.postRun&&(u.postRun=[u.postRun]);u.postRun.length;){var t=u.postRun.shift();Z.unshift(t)}dt(Z)}}if(!(0{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){var e,r,a;t=t||{},e||(e=void 0!==t?t:{}),e.ready=new Promise((function(t,e){r=t,a=e}));var i,o,u,c,s,l,f=Object.assign({},e),p="./this.program",h=(t,e)=>{throw e},d="object"==typeof window,y="function"==typeof importScripts,b="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,m="";b?(m=y?n(908).dirname(m)+"/":"//",l=()=>{s||(c=n(384),s=n(908))},i=function(t,e){return l(),t=s.normalize(t),c.readFileSync(t,e?void 0:"utf8")},u=t=>((t=i(t,!0)).buffer||(t=new Uint8Array(t)),t),o=(t,e,n)=>{l(),t=s.normalize(t),c.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(_||0{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},y&&(u=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),o=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)});var g,v=e.print||console.log.bind(console),w=e.printErr||console.warn.bind(console);Object.assign(e,f),f=null,e.thisProgram&&(p=e.thisProgram),e.quit&&(h=e.quit),e.wasmBinary&&(g=e.wasmBinary);var _=e.noExitRuntime||!1;"object"!=typeof WebAssembly&&V("no native wasm support detected");var O,A,S,T,E,M,C=!1,x="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function R(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&t[e++])?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else r+=String.fromCharCode(a)}return r}function j(t,e){return(t>>>=0)?R(T,t,e):""}function k(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var i=0;i=o&&(o=65536+((1023&o)<<10)|1023&t.charCodeAt(++i)),127>=o){if(n>=r)break;e[n++>>>0]=o}else{if(2047>=o){if(n+1>=r)break;e[n++>>>0]=192|o>>6}else{if(65535>=o){if(n+2>=r)break;e[n++>>>0]=224|o>>12}else{if(n+3>=r)break;e[n++>>>0]=240|o>>18,e[n++>>>0]=128|o>>12&63}e[n++>>>0]=128|o>>6&63}e[n++>>>0]=128|63&o}}return e[n>>>0]=0,n-a}function D(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function P(){var t=O.buffer;A=t,e.HEAP8=S=new Int8Array(t),e.HEAP16=new Int16Array(t),e.HEAP32=E=new Int32Array(t),e.HEAPU8=T=new Uint8Array(t),e.HEAPU16=new Uint16Array(t),e.HEAPU32=M=new Uint32Array(t),e.HEAPF32=new Float32Array(t),e.HEAPF64=new Float64Array(t)}var U,F=[],I=[],W=[],H=[],L=0;function z(){var t=e.preRun.shift();F.unshift(t)}var Y,B=0,G=null,N=null;function V(t){throw e.onAbort&&e.onAbort(t),w(t="Aborted("+t+")"),C=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),a(t),t}function $(){return Y.startsWith("data:application/octet-stream;base64,")}if(Y="ort-wasm.wasm",!$()){var q=Y;Y=e.locateFile?e.locateFile(q,m):m+q}function X(){var t=Y;try{if(t==Y&&g)return new Uint8Array(g);if(u)return u(t);throw"both async and sync fetching of the wasm failed"}catch(t){V(t)}}function J(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function Z(t){for(;0>2>>>0]=t},this.Eb=function(){return M[this.zb+4>>2>>>0]},this.Sb=function(t){M[this.zb+8>>2>>>0]=t},this.Wb=function(){return M[this.zb+8>>2>>>0]},this.Tb=function(){E[this.zb>>2>>>0]=0},this.Ib=function(t){S[this.zb+12>>0>>>0]=t?1:0},this.Pb=function(){return 0!=S[this.zb+12>>0>>>0]},this.Jb=function(t){S[this.zb+13>>0>>>0]=t?1:0},this.Lb=function(){return 0!=S[this.zb+13>>0>>>0]},this.Rb=function(t,e){this.Fb(0),this.Ub(t),this.Sb(e),this.Tb(),this.Ib(!1),this.Jb(!1)},this.Nb=function(){E[this.zb>>2>>>0]+=1},this.Xb=function(){var t=E[this.zb>>2>>>0];return E[this.zb>>2>>>0]=t-1,1===t},this.Fb=function(t){M[this.zb+16>>2>>>0]=t},this.Ob=function(){return M[this.zb+16>>2>>>0]},this.Qb=function(){if(Mt(this.Eb()))return M[this.Db>>2>>>0];var t=this.Ob();return 0!==t?t:this.Db}}function nt(t){return vt(new et(t).zb)}var rt=[];function at(t){var e=rt[t];return e||(t>=rt.length&&(rt.length=t+1),rt[t]=e=U.get(t)),e}function it(t){var e=D(t)+1,n=gt(e);return n&&k(t,S,n,e),n}var ot={};function ut(){if(!ct){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:p||"./this.program"};for(t in ot)void 0===ot[t]?delete e[t]:e[t]=ot[t];var n=[];for(t in e)n.push(t+"="+e[t]);ct=n}return ct}var ct,st=[null,[],[]];function lt(t,e){var n=st[t];0===e||10===e?((1===t?v:w)(R(n,0)),n.length=0):n.push(e)}var ft=0;function pt(t){return 0==t%4&&(0!=t%100||0==t%400)}var ht=[31,29,31,30,31,30,31,31,30,31,30,31],dt=[31,28,31,30,31,30,31,31,30,31,30,31];function yt(t,e,n,r){function a(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=u(new Date(t.getFullYear(),0,4)),n=u(n),0>=o(e,t)?0>=o(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var s=E[r+40>>2>>>0];for(var l in r={$b:E[r>>2>>>0],Zb:E[r+4>>2>>>0],Gb:E[r+8>>2>>>0],Kb:E[r+12>>2>>>0],Hb:E[r+16>>2>>>0],Cb:E[r+20>>2>>>0],Ab:E[r+24>>2>>>0],Bb:E[r+28>>2>>>0],bc:E[r+32>>2>>>0],Yb:E[r+36>>2>>>0],ac:s?j(s):""},n=j(n),s={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})n=n.replace(new RegExp(l,"g"),s[l]);var f="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),p="January February March April May June July August September October November December".split(" ");for(l in s={"%a":function(t){return f[t.Ab].substring(0,3)},"%A":function(t){return f[t.Ab]},"%b":function(t){return p[t.Hb].substring(0,3)},"%B":function(t){return p[t.Hb]},"%C":function(t){return i((t.Cb+1900)/100|0,2)},"%d":function(t){return i(t.Kb,2)},"%e":function(t){return a(t.Kb,2," ")},"%g":function(t){return c(t).toString().substring(2)},"%G":function(t){return c(t)},"%H":function(t){return i(t.Gb,2)},"%I":function(t){return 0==(t=t.Gb)?t=12:12t.Gb?"AM":"PM"},"%S":function(t){return i(t.$b,2)},"%t":function(){return"\\t"},"%u":function(t){return t.Ab||7},"%U":function(t){return i(Math.floor((t.Bb+7-t.Ab)/7),2)},"%V":function(t){var e=Math.floor((t.Bb+7-(t.Ab+6)%7)/7);if(2>=(t.Ab+371-t.Bb-2)%7&&e++,e)53==e&&(4==(n=(t.Ab+371-t.Bb)%7)||3==n&&pt(t.Cb)||(e=1));else{e=52;var n=(t.Ab+7-t.Bb-1)%7;(4==n||5==n&&pt(t.Cb%400-1))&&e++}return i(e,2)},"%w":function(t){return t.Ab},"%W":function(t){return i(Math.floor((t.Bb+7-(t.Ab+6)%7)/7),2)},"%y":function(t){return(t.Cb+1900).toString().substring(2)},"%Y":function(t){return t.Cb+1900},"%z":function(t){var e=0<=(t=t.Yb);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.ac},"%%":function(){return"%"}},n=n.replace(/%%/g,"\\0\\0"),s)n.includes(l)&&(n=n.replace(new RegExp(l,"g"),s[l](r)));return l=function(t){var e=Array(D(t)+1);return k(t,e,0,e.length),e}(n=n.replace(/\\0\\0/g,"%")),l.length>e?0:(S.set(l,t>>>0),l.length-1)}var bt={a:function(t){return gt(t+24)+24},m:function(t){return(t=new et(t)).Pb()||(t.Ib(!0),K--),t.Jb(!1),Q.push(t),t.Nb(),t.Qb()},ia:function(t){throw w("Unexpected exception thrown, this is not properly supported - aborting"),C=!0,t},w:function(){Ot(0);var t=Q.pop();if(t.Xb()&&!t.Lb()){var e=t.Wb();e&&at(e)(t.Db),nt(t.Db)}tt=0},d:function(){var t=tt;if(!t)return ft=0;var e=new et(t);e.Fb(t);var n=e.Eb();if(!n)return ft=0,t;for(var r=Array.prototype.slice.call(arguments),a=0;a>>2]+4294967296*E[t+4>>>2])),E[e>>2>>>0]=t.getUTCSeconds(),E[e+4>>2>>>0]=t.getUTCMinutes(),E[e+8>>2>>>0]=t.getUTCHours(),E[e+12>>2>>>0]=t.getUTCDate(),E[e+16>>2>>>0]=t.getUTCMonth(),E[e+20>>2>>>0]=t.getUTCFullYear()-1900,E[e+24>>2>>>0]=t.getUTCDay(),E[e+28>>2>>>0]=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},Ea:function(t,e){t=new Date(1e3*(M[t>>>2]+4294967296*E[t+4>>>2])),E[e>>2>>>0]=t.getSeconds(),E[e+4>>2>>>0]=t.getMinutes(),E[e+8>>2>>>0]=t.getHours(),E[e+12>>2>>>0]=t.getDate(),E[e+16>>2>>>0]=t.getMonth(),E[e+20>>2>>>0]=t.getFullYear()-1900,E[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1);E[e+28>>2>>>0]=(t.getTime()-n.getTime())/864e5|0,E[e+36>>2>>>0]=-60*t.getTimezoneOffset();var r=new Date(t.getFullYear(),6,1).getTimezoneOffset();n=n.getTimezoneOffset(),E[e+32>>2>>>0]=0|(r!=n&&t.getTimezoneOffset()==Math.min(n,r))},Fa:function(t){var e=new Date(E[t+20>>2>>>0]+1900,E[t+16>>2>>>0],E[t+12>>2>>>0],E[t+8>>2>>>0],E[t+4>>2>>>0],E[t>>2>>>0],0),n=E[t+32>>2>>>0],r=e.getTimezoneOffset(),a=new Date(e.getFullYear(),0,1),i=new Date(e.getFullYear(),6,1).getTimezoneOffset(),o=a.getTimezoneOffset(),u=Math.min(o,i);return 0>n?E[t+32>>2>>>0]=Number(i!=o&&u==r):0>2>>>0]=e.getDay(),E[t+28>>2>>>0]=(e.getTime()-a.getTime())/864e5|0,E[t>>2>>>0]=e.getSeconds(),E[t+4>>2>>>0]=e.getMinutes(),E[t+8>>2>>>0]=e.getHours(),E[t+12>>2>>>0]=e.getDate(),E[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},sa:function(){return-52},ta:function(){},Ga:function t(e,n,r){t.Vb||(t.Vb=!0,function(t,e,n){function r(t){return(t=t.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?t[1]:"GMT"}var a=(new Date).getFullYear(),i=new Date(a,0,1),o=new Date(a,6,1);a=i.getTimezoneOffset();var u=o.getTimezoneOffset();E[t>>2>>>0]=60*Math.max(a,u),E[e>>2>>>0]=Number(a!=u),t=r(i),e=r(o),t=it(t),e=it(e),u>2>>>0]=t,M[n+4>>2>>>0]=e):(M[n>>2>>>0]=e,M[n+4>>2>>>0]=t)}(e,n,r))},B:function(){V("")},ma:function(){return 4294901760},I:b?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:()=>performance.now(),xa:function(t,e,n){T.copyWithin(t>>>0,e>>>0,e+n>>>0)},G:function(t){var e=T.length;if(4294901760<(t>>>=0))return!1;for(var n=1;4>=n;n*=2){var r=e*(1+.2/n);r=Math.min(r,t+100663296);var a=Math;r=Math.max(t,r),a=a.min.call(a,4294901760,r+(65536-r%65536)%65536);t:{try{O.grow(a-A.byteLength+65535>>>16),P();var i=1;break t}catch(t){}i=void 0}if(i)return!0}return!1},va:function(t,e){var n=0;return ut().forEach((function(r,a){var i=e+n;for(a=M[t+4*a>>2>>>0]=i,i=0;i>0>>>0]=r.charCodeAt(i);S[a>>0>>>0]=0,n+=r.length+1})),0},wa:function(t,e){var n=ut();M[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),M[e>>2>>>0]=r,0},ba:function(t){_||0>2>>>0],u=M[e+4>>2>>>0];e+=8;for(var c=0;c>>0]);a+=u}return M[r>>2>>>0]=a,0},c:function(){return ft},ja:function t(e,r){t.Mb||(t.Mb=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(b)try{var e=n(Object(function(){var t=new Error("Cannot find module \'crypto\'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>V("randomDevice")}());for(var a=0;a>0>>>0]=t.Mb();return 0},ea:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},fa:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},J:function(t){var e=At();try{return at(t)()}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},e:function(t,e){var n=At();try{return at(t)(e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},N:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},O:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},j:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},o:function(t,e,n,r){var a=At();try{return at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},p:function(t,e,n,r,a){var i=At();try{return at(t)(e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},M:function(t,e,n,r,a,i){var o=At();try{return at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},r:function(t,e,n,r,a,i){var o=At();try{return at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},v:function(t,e,n,r,a,i,o){var u=At();try{return at(t)(e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},K:function(t,e,n,r,a,i,o,u){var c=At();try{return at(t)(e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},D:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=At();try{return at(t)(e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(St(p),t!==t+0)throw t;Ot(1,0)}},X:function(t,e,n,r,a,i,o,u){var c=At();try{return Ft(t,e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},V:function(t,e,n,r,a,i,o){var u=At();try{return xt(t,e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},U:function(t,e,n,r,a){var i=At();try{return It(t,e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},Z:function(t,e,n,r){var a=At();try{return Pt(t,e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},W:function(t){var e=At();try{return Ct(t)}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},Y:function(t,e){var n=At();try{return Ut(t,e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},T:function(t,e,n){var r=At();try{return Rt(t,e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},f:function(t){var e=At();try{at(t)()}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},q:function(t,e){var n=At();try{at(t)(e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},h:function(t,e,n){var r=At();try{at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},da:function(t,e,n,r){var a=At();try{at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},l:function(t,e,n,r){var a=At();try{at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},t:function(t,e,n,r,a){var i=At();try{at(t)(e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},u:function(t,e,n,r,a,i){var o=At();try{at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},x:function(t,e,n,r,a,i,o){var u=At();try{at(t)(e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},z:function(t,e,n,r,a,i,o,u){var c=At();try{at(t)(e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},ga:function(t,e,n,r,a,i,o,u,c){var s=At();try{at(t)(e,n,r,a,i,o,u,c)}catch(t){if(St(s),t!==t+0)throw t;Ot(1,0)}},A:function(t,e,n,r,a,i,o,u,c,s,l){var f=At();try{at(t)(e,n,r,a,i,o,u,c,s,l)}catch(t){if(St(f),t!==t+0)throw t;Ot(1,0)}},C:function(t,e,n,r,a,i,o,u,c,s,l,f,p,h,d,y){var b=At();try{at(t)(e,n,r,a,i,o,u,c,s,l,f,p,h,d,y)}catch(t){if(St(b),t!==t+0)throw t;Ot(1,0)}},aa:function(t,e,n,r,a,i,o,u){var c=At();try{jt(t,e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},_:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=At();try{Dt(t,e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(St(p),t!==t+0)throw t;Ot(1,0)}},$:function(t,e,n,r,a,i){var o=At();try{kt(t,e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},n:function(t){return t},F:function(t){ft=t},ha:yt,y:function(t,e,n,r){return yt(t,e,n,r)}};!function(){function t(t){e.asm=t.exports,O=e.asm.Ka,P(),U=e.asm.ib,I.unshift(e.asm.La),B--,e.monitorRunDependencies&&e.monitorRunDependencies(B),0==B&&(null!==G&&(clearInterval(G),G=null),N&&(t=N,N=null,t()))}function n(e){t(e.instance)}function r(t){return function(){if(!g&&(d||y)){if("function"==typeof fetch&&!Y.startsWith("file://"))return fetch(Y,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at \'"+Y+"\'";return t.arrayBuffer()})).catch((function(){return X()}));if(o)return new Promise((function(t,e){o(Y,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return X()}))}().then((function(t){return WebAssembly.instantiate(t,i)})).then((function(t){return t})).then(t,(function(t){w("failed to asynchronously prepare wasm: "+t),V(t)}))}var i={a:bt};if(B++,e.monitorRunDependencies&&e.monitorRunDependencies(B),e.instantiateWasm)try{return e.instantiateWasm(i,t)}catch(t){return w("Module.instantiateWasm callback failed with error: "+t),!1}(g||"function"!=typeof WebAssembly.instantiateStreaming||$()||Y.startsWith("file://")||b||"function"!=typeof fetch?r(n):fetch(Y,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,i).then(n,(function(t){return w("wasm streaming compile failed: "+t),w("falling back to ArrayBuffer instantiation"),r(n)}))}))).catch(a)}(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.La).apply(null,arguments)},e._OrtInit=function(){return(e._OrtInit=e.asm.Ma).apply(null,arguments)},e._OrtCreateSessionOptions=function(){return(e._OrtCreateSessionOptions=e.asm.Na).apply(null,arguments)},e._OrtAppendExecutionProvider=function(){return(e._OrtAppendExecutionProvider=e.asm.Oa).apply(null,arguments)},e._OrtAddSessionConfigEntry=function(){return(e._OrtAddSessionConfigEntry=e.asm.Pa).apply(null,arguments)},e._OrtReleaseSessionOptions=function(){return(e._OrtReleaseSessionOptions=e.asm.Qa).apply(null,arguments)},e._OrtCreateSession=function(){return(e._OrtCreateSession=e.asm.Ra).apply(null,arguments)},e._OrtReleaseSession=function(){return(e._OrtReleaseSession=e.asm.Sa).apply(null,arguments)},e._OrtGetInputCount=function(){return(e._OrtGetInputCount=e.asm.Ta).apply(null,arguments)},e._OrtGetOutputCount=function(){return(e._OrtGetOutputCount=e.asm.Ua).apply(null,arguments)},e._OrtGetInputName=function(){return(e._OrtGetInputName=e.asm.Va).apply(null,arguments)},e._OrtGetOutputName=function(){return(e._OrtGetOutputName=e.asm.Wa).apply(null,arguments)},e._OrtFree=function(){return(e._OrtFree=e.asm.Xa).apply(null,arguments)},e._OrtCreateTensor=function(){return(e._OrtCreateTensor=e.asm.Ya).apply(null,arguments)},e._OrtGetTensorData=function(){return(e._OrtGetTensorData=e.asm.Za).apply(null,arguments)},e._OrtReleaseTensor=function(){return(e._OrtReleaseTensor=e.asm._a).apply(null,arguments)},e._OrtCreateRunOptions=function(){return(e._OrtCreateRunOptions=e.asm.$a).apply(null,arguments)},e._OrtAddRunConfigEntry=function(){return(e._OrtAddRunConfigEntry=e.asm.ab).apply(null,arguments)},e._OrtReleaseRunOptions=function(){return(e._OrtReleaseRunOptions=e.asm.bb).apply(null,arguments)},e._OrtRun=function(){return(e._OrtRun=e.asm.cb).apply(null,arguments)},e._OrtEndProfiling=function(){return(e._OrtEndProfiling=e.asm.db).apply(null,arguments)};var mt,gt=e._malloc=function(){return(gt=e._malloc=e.asm.eb).apply(null,arguments)},vt=e._free=function(){return(vt=e._free=e.asm.fb).apply(null,arguments)},wt=e._fflush=function(){return(wt=e._fflush=e.asm.gb).apply(null,arguments)},_t=e.___funcs_on_exit=function(){return(_t=e.___funcs_on_exit=e.asm.hb).apply(null,arguments)},Ot=e._setThrew=function(){return(Ot=e._setThrew=e.asm.jb).apply(null,arguments)},At=e.stackSave=function(){return(At=e.stackSave=e.asm.kb).apply(null,arguments)},St=e.stackRestore=function(){return(St=e.stackRestore=e.asm.lb).apply(null,arguments)},Tt=e.stackAlloc=function(){return(Tt=e.stackAlloc=e.asm.mb).apply(null,arguments)},Et=e.___cxa_can_catch=function(){return(Et=e.___cxa_can_catch=e.asm.nb).apply(null,arguments)},Mt=e.___cxa_is_pointer_type=function(){return(Mt=e.___cxa_is_pointer_type=e.asm.ob).apply(null,arguments)},Ct=e.dynCall_j=function(){return(Ct=e.dynCall_j=e.asm.pb).apply(null,arguments)},xt=e.dynCall_iiiiij=function(){return(xt=e.dynCall_iiiiij=e.asm.qb).apply(null,arguments)},Rt=e.dynCall_jii=function(){return(Rt=e.dynCall_jii=e.asm.rb).apply(null,arguments)},jt=e.dynCall_viiiiij=function(){return(jt=e.dynCall_viiiiij=e.asm.sb).apply(null,arguments)},kt=e.dynCall_vjji=function(){return(kt=e.dynCall_vjji=e.asm.tb).apply(null,arguments)},Dt=e.dynCall_viiijjjii=function(){return(Dt=e.dynCall_viiijjjii=e.asm.ub).apply(null,arguments)},Pt=e.dynCall_iij=function(){return(Pt=e.dynCall_iij=e.asm.vb).apply(null,arguments)},Ut=e.dynCall_ji=function(){return(Ut=e.dynCall_ji=e.asm.wb).apply(null,arguments)},Ft=e.dynCall_iiiiiij=function(){return(Ft=e.dynCall_iiiiiij=e.asm.xb).apply(null,arguments)},It=e.dynCall_iiij=function(){return(It=e.dynCall_iiij=e.asm.yb).apply(null,arguments)};function Wt(){function t(){if(!mt&&(mt=!0,e.calledRun=!0,!C)){if(Z(I),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var t=e.postRun.shift();H.unshift(t)}Z(H)}}if(!(0{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.iterateExtraOptions=void 0,e.iterateExtraOptions=(t,n,r,a)=>{if("object"==typeof t&&null!==t){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach((([t,i])=>{const o=n?n+t:t;if("object"==typeof i)(0,e.iterateExtraOptions)(i,o+".",r,a);else if("string"==typeof i||"number"==typeof i)a(o,i.toString());else{if("boolean"!=typeof i)throw new Error("Can\'t handle extra config type: "+typeof i);a(o,i?"1":"0")}}))}},586:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setRunOptions=void 0;const r=n(967),a=n(983),i=n(361);e.setRunOptions=t=>{const e=(0,i.getInstance)();let n=0;const o=[],u=t||{};try{if(void 0===(null==t?void 0:t.logSeverityLevel))u.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))u.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);void 0===(null==t?void 0:t.terminate)&&(u.terminate=!1);let i=0;if(void 0!==(null==t?void 0:t.tag)&&(i=(0,a.allocWasmString)(t.tag,o)),n=e._OrtCreateRunOptions(u.logSeverityLevel,u.logVerbosityLevel,!!u.terminate,i),0===n)throw new Error("Can\'t create run options");return void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const i=(0,a.allocWasmString)(t,o),u=(0,a.allocWasmString)(r,o);if(0!==e._OrtAddRunConfigEntry(n,i,u))throw new Error(`Can\'t set a run config entry: ${t} - ${r}`)})),[n,o]}catch(t){throw 0!==n&&e._OrtReleaseRunOptions(n),o.forEach(e._free),t}}},919:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setSessionOptions=void 0;const r=n(967),a=n(983),i=n(361);e.setSessionOptions=t=>{const e=(0,i.getInstance)();let n=0;const o=[],u=t||{};(t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});const e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1")})(u);try{void 0===(null==t?void 0:t.graphOptimizationLevel)&&(u.graphOptimizationLevel="all");const c=(t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}})(u.graphOptimizationLevel);void 0===(null==t?void 0:t.enableCpuMemArena)&&(u.enableCpuMemArena=!0),void 0===(null==t?void 0:t.enableMemPattern)&&(u.enableMemPattern=!0),void 0===(null==t?void 0:t.executionMode)&&(u.executionMode="sequential");const s=(t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}})(u.executionMode);let l=0;if(void 0!==(null==t?void 0:t.logId)&&(l=(0,a.allocWasmString)(t.logId,o)),void 0===(null==t?void 0:t.logSeverityLevel))u.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))u.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);if(void 0===(null==t?void 0:t.enableProfiling)&&(u.enableProfiling=!1),n=e._OrtCreateSessionOptions(c,!!u.enableCpuMemArena,!!u.enableMemPattern,s,!!u.enableProfiling,0,l,u.logSeverityLevel,u.logVerbosityLevel),0===n)throw new Error("Can\'t create session options");return(null==t?void 0:t.executionProviders)&&((t,e,n)=>{for(const r of e){let e="string"==typeof r?r:r.name;switch(e){case"xnnpack":e="XNNPACK";break;case"wasm":case"cpu":continue;default:throw new Error(`not supported EP: ${e}`)}const o=(0,a.allocWasmString)(e,n);if(0!==(0,i.getInstance)()._OrtAppendExecutionProvider(t,o))throw new Error(`Can\'t append execution provider: ${e}`)}})(n,t.executionProviders,o),void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const i=(0,a.allocWasmString)(t,o),u=(0,a.allocWasmString)(r,o);if(0!==e._OrtAddSessionConfigEntry(n,i,u))throw new Error(`Can\'t set a session config entry: ${t} - ${r}`)})),[n,o]}catch(t){throw 0!==n&&e._OrtReleaseSessionOptions(n),o.forEach(e._free),t}}},983:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.allocWasmString=void 0;const r=n(361);e.allocWasmString=(t,e)=>{const n=(0,r.getInstance)(),a=n.lengthBytesUTF8(t)+1,i=n._malloc(a);return n.stringToUTF8(t,i,a),e.push(i),i}},349:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.extractTransferableBuffers=e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=void 0;const r=n(586),a=n(919),i=n(983),o=n(361);e.initOrt=(t,e)=>{const n=(0,o.getInstance)()._OrtInit(t,e);if(0!==n)throw new Error(`Can\'t initialize onnxruntime. error code = ${n}`)};const u=new Map;e.createSessionAllocate=t=>{const e=(0,o.getInstance)(),n=e._malloc(t.byteLength);return e.HEAPU8.set(t,n),[n,t.byteLength]},e.createSessionFinalize=(t,e)=>{const n=(0,o.getInstance)();let r=0,i=0,c=[];try{if([i,c]=(0,a.setSessionOptions)(e),r=n._OrtCreateSession(t[0],t[1],i),0===r)throw new Error("Can\'t create a session")}finally{n._free(t[0]),n._OrtReleaseSessionOptions(i),c.forEach(n._free)}const s=n._OrtGetInputCount(r),l=n._OrtGetOutputCount(r),f=[],p=[],h=[],d=[];for(let t=0;t{const r=(0,e.createSessionAllocate)(t);return(0,e.createSessionFinalize)(r,n)},e.releaseSession=t=>{const e=(0,o.getInstance)(),n=u.get(t);if(!n)throw new Error("invalid session id");const r=n[0],a=n[1],i=n[2];a.forEach(e._OrtFree),i.forEach(e._OrtFree),e._OrtReleaseSession(r),u.delete(t)};const c=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${t}`)}},s=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${t}`)}},l=t=>{switch(t){case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${t}`)}};e.run=(t,e,n,a,f)=>{const p=(0,o.getInstance)(),h=u.get(t);if(!h)throw new Error("invalid session id");const d=h[0],y=h[1],b=h[2],m=e.length,g=a.length;let v=0,w=[];const _=[],O=[];try{[v,w]=(0,r.setRunOptions)(f);for(let t=0;tp.HEAP32[t++]=e));const n=p._OrtCreateTensor(c(e),o,u,l,r.length);if(0===n)throw new Error("Can\'t create a tensor");_.push(n)}finally{p.stackRestore(s)}}const t=p.stackSave(),o=p.stackAlloc(4*m),u=p.stackAlloc(4*m),h=p.stackAlloc(4*g),A=p.stackAlloc(4*g);try{let n=o/4,r=u/4,i=h/4,c=A/4;for(let t=0;tt*e));if(a=s(o),"string"===a){const t=[];let e=i/4;for(let n=0;n{const e=(0,o.getInstance)(),n=u.get(t);if(!n)throw new Error("invalid session id");const r=n[0],a=e._OrtEndProfiling(r);if(0===a)throw new Error("Can\'t get an profile file name");e._OrtFree(a)},e.extractTransferableBuffers=t=>{const e=[];for(const n of t){const t=n[2];!Array.isArray(t)&&t.buffer&&e.push(t.buffer)}return e}},361:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(e,n);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,a)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),a=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return a(e,t),e},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.dispose=e.getInstance=e.initializeWebAssembly=void 0;const u=i(n(449)),c=o(n(932)),s=n(474);let l,f=!1,p=!1,h=!1;const d=(t,e)=>e?t?"ort-wasm-simd-threaded.wasm":"ort-wasm-threaded.wasm":t?"ort-wasm-simd.wasm":"ort-wasm.wasm";e.initializeWebAssembly=async t=>{if(f)return Promise.resolve();if(p)throw new Error("multiple calls to \'initializeWebAssembly()\' detected.");if(h)throw new Error("previous call to \'initializeWebAssembly()\' failed.");p=!0;const e=t.initTimeout,r=t.numThreads,a=t.simd,i=r>1&&(()=>{try{return"undefined"!=typeof SharedArrayBuffer&&("undefined"!=typeof MessageChannel&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11])))}catch(t){return!1}})(),o=a&&(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch(t){return!1}})(),y="string"==typeof t.wasmPaths?t.wasmPaths:void 0,b=d(!1,i),m=d(o,i),g="object"==typeof t.wasmPaths?t.wasmPaths[m]:void 0;let v=!1;const w=[];if(e>0&&w.push(new Promise((t=>{setTimeout((()=>{v=!0,t()}),e)}))),w.push(new Promise(((t,e)=>{const r=i?s:c.default,a={locateFile:(t,e)=>i&&t.endsWith(".worker.js")&&"undefined"!=typeof Blob?URL.createObjectURL(new Blob([n(154)],{type:"text/javascript"})):t===b?null!=g?g:(null!=y?y:e)+m:e+t};if(i)if("undefined"==typeof Blob)a.mainScriptUrlOrBlob=u.join("/","ort-wasm-threaded.js");else{const t=`var ortWasmThreaded=(function(){var _scriptDir;return ${r.toString()}})();`;a.mainScriptUrlOrBlob=new Blob([t],{type:"text/javascript"})}r(a).then((e=>{p=!1,f=!0,l=e,t()}),(t=>{p=!1,h=!0,e(t)}))}))),await Promise.race(w),v)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},e.getInstance=()=>{if(f&&l)return l;throw new Error("WebAssembly is not initialized yet.")},e.dispose=()=>{var t;!f||p||h||(p=!0,null===(t=l.PThread)||void 0===t||t.terminateAllThreads(),l=void 0,p=!1,f=!1,h=!0)}},154:t=>{"use strict";t.exports=\'"use strict";var e={},t="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node;if(t){var r=require("worker_threads"),a=r.parentPort;a.on("message",(e=>onmessage({data:e})));var o=require("fs");Object.assign(global,{self:global,require:require,Module:e,location:{href:__filename},Worker:r.Worker,importScripts:function(e){(0,eval)(o.readFileSync(e,"utf8"))},postMessage:function(e){a.postMessage(e)},performance:global.performance||{now:function(){return Date.now()}}})}var s=!1,n=[],i=function(){var e=Array.prototype.slice.call(arguments).join(" ");t?o.writeSync(2,e+"\\\\n"):console.error(e)};self.alert=function(){var t=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:t,threadId:e._pthread_self()})},e.instantiateWasm=(t,r)=>{var a=new WebAssembly.Instance(e.wasmModule,t);return r(a),e.wasmModule=null,a.exports},self.onunhandledrejection=e=>{throw e.reason??e},self.onmessage=t=>{try{if("load"===t.data.cmd){if(e.wasmModule=t.data.wasmModule,e.wasmMemory=t.data.wasmMemory,e.buffer=e.wasmMemory.buffer,e.ENVIRONMENT_IS_PTHREAD=!0,"string"==typeof t.data.urlOrBlob)importScripts(t.data.urlOrBlob);else{var r=URL.createObjectURL(t.data.urlOrBlob);importScripts(r),URL.revokeObjectURL(r)}ortWasmThreaded(e).then((function(t){e=t}))}else if("run"===t.data.cmd){e.__performance_now_clock_drift=performance.now()-t.data.time,e.__emscripten_thread_init(t.data.pthread_ptr,0,0,1),e.establishStackSpace(),e.PThread.receiveObjectTransfer(t.data),e.PThread.threadInitTLS(),s||(n.forEach((t=>{e.executeNotifiedProxyingQueue(t)})),n=[],s=!0);try{e.invokeEntryPoint(t.data.start_routine,t.data.arg)}catch(t){if("unwind"!=t){if(!(t instanceof e.ExitStatus))throw t;e.keepRuntimeAlive()||e.__emscripten_thread_exit(t.status)}}}else"cancel"===t.data.cmd?e._pthread_self()&&e.__emscripten_thread_exit(-1):"setimmediate"===t.data.target||("processProxyingQueue"===t.data.cmd?s?e.executeNotifiedProxyingQueue(t.data.queue):n.push(t.data.queue):(i("worker.js received unknown command "+t.data.cmd),i(t.data)))}catch(t){throw i("worker.js onmessage() captured an uncaught exception: "+t),t&&t.stack&&i(t.stack),e.__emscripten_thread_crashed&&e.__emscripten_thread_crashed(),t}};\\n\'},384:()=>{},993:()=>{},908:()=>{},953:()=>{},925:()=>{},449:()=>{}},e={};function n(r){var a=e[r];if(void 0!==a)return a.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),(()=>{"use strict";const t=n(349),e=n(361);self.onmessage=n=>{switch(n.data.type){case"init-wasm":(0,e.initializeWebAssembly)(n.data.in).then((()=>postMessage({type:"init-wasm"})),(t=>postMessage({type:"init-wasm",err:t})));break;case"init-ort":try{const{numThreads:e,loggingLevel:r}=n.data.in;(0,t.initOrt)(e,r),postMessage({type:"init-ort"})}catch(t){postMessage({type:"init-ort",err:t})}break;case"create_allocate":try{const{model:e}=n.data.in,r=(0,t.createSessionAllocate)(e);postMessage({type:"create_allocate",out:r})}catch(t){postMessage({type:"create_allocate",err:t})}break;case"create_finalize":try{const{modeldata:e,options:r}=n.data.in,a=(0,t.createSessionFinalize)(e,r);postMessage({type:"create_finalize",out:a})}catch(t){postMessage({type:"create_finalize",err:t})}break;case"create":try{const{model:e,options:r}=n.data.in,a=(0,t.createSession)(e,r);postMessage({type:"create",out:a})}catch(t){postMessage({type:"create",err:t})}break;case"release":try{const e=n.data.in;(0,t.releaseSession)(e),postMessage({type:"release"})}catch(t){postMessage({type:"release",err:t})}break;case"run":try{const{sessionId:e,inputIndices:r,inputs:a,outputIndices:i,options:o}=n.data.in,u=(0,t.run)(e,r,a,i,o);postMessage({type:"run",out:u},(0,t.extractTransferableBuffers)(u))}catch(t){postMessage({type:"run",err:t})}break;case"end-profiling":try{const e=n.data.in;(0,t.endProfiling)(e),postMessage({type:"end-profiling"})}catch(t){postMessage({type:"end-profiling",err:t})}}}})()})();\n',"Worker",void 0,void 0)}},477:t=>{"use strict";t.exports=function(t,e,n,r){var i=self||window;try{try{var o;try{o=new i.Blob([t])}catch(e){(o=new(i.BlobBuilder||i.WebKitBlobBuilder||i.MozBlobBuilder||i.MSBlobBuilder)).append(t),o=o.getBlob()}var a=i.URL||i.webkitURL,s=a.createObjectURL(o),u=new i[e](s,n);return a.revokeObjectURL(s),u}catch(r){return new i[e]("data:application/javascript,".concat(encodeURIComponent(t)),n)}}catch(t){if(!r)throw Error("Inline worker is not supported");return new i[e](r,n)}}},4154:t=>{"use strict";t.exports='"use strict";var e={},t="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node;if(t){var r=require("worker_threads"),a=r.parentPort;a.on("message",(e=>onmessage({data:e})));var o=require("fs");Object.assign(global,{self:global,require:require,Module:e,location:{href:__filename},Worker:r.Worker,importScripts:function(e){(0,eval)(o.readFileSync(e,"utf8"))},postMessage:function(e){a.postMessage(e)},performance:global.performance||{now:function(){return Date.now()}}})}var s=!1,n=[],i=function(){var e=Array.prototype.slice.call(arguments).join(" ");t?o.writeSync(2,e+"\\n"):console.error(e)};self.alert=function(){var t=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:t,threadId:e._pthread_self()})},e.instantiateWasm=(t,r)=>{var a=new WebAssembly.Instance(e.wasmModule,t);return r(a),e.wasmModule=null,a.exports},self.onunhandledrejection=e=>{throw e.reason??e},self.onmessage=t=>{try{if("load"===t.data.cmd){if(e.wasmModule=t.data.wasmModule,e.wasmMemory=t.data.wasmMemory,e.buffer=e.wasmMemory.buffer,e.ENVIRONMENT_IS_PTHREAD=!0,"string"==typeof t.data.urlOrBlob)importScripts(t.data.urlOrBlob);else{var r=URL.createObjectURL(t.data.urlOrBlob);importScripts(r),URL.revokeObjectURL(r)}ortWasmThreaded(e).then((function(t){e=t}))}else if("run"===t.data.cmd){e.__performance_now_clock_drift=performance.now()-t.data.time,e.__emscripten_thread_init(t.data.pthread_ptr,0,0,1),e.establishStackSpace(),e.PThread.receiveObjectTransfer(t.data),e.PThread.threadInitTLS(),s||(n.forEach((t=>{e.executeNotifiedProxyingQueue(t)})),n=[],s=!0);try{e.invokeEntryPoint(t.data.start_routine,t.data.arg)}catch(t){if("unwind"!=t){if(!(t instanceof e.ExitStatus))throw t;e.keepRuntimeAlive()||e.__emscripten_thread_exit(t.status)}}}else"cancel"===t.data.cmd?e._pthread_self()&&e.__emscripten_thread_exit(-1):"setimmediate"===t.data.target||("processProxyingQueue"===t.data.cmd?s?e.executeNotifiedProxyingQueue(t.data.queue):n.push(t.data.queue):(i("worker.js received unknown command "+t.data.cmd),i(t.data)))}catch(t){throw i("worker.js onmessage() captured an uncaught exception: "+t),t&&t.stack&&i(t.stack),e.__emscripten_thread_crashed&&e.__emscripten_thread_crashed(),t}};\n'},7067:()=>{},1296:()=>{},1384:()=>{},3993:()=>{},908:()=>{},6953:()=>{},9925:()=>{},2806:()=>{},6449:()=>{},2850:()=>{},5381:()=>{},5686:(t,e,n)=>{"use strict";n.r(e),n.d(e,{flatbuffers:()=>r});var r={};r.Offset,r.Table,r.SIZEOF_SHORT=2,r.SIZEOF_INT=4,r.FILE_IDENTIFIER_LENGTH=4,r.SIZE_PREFIX_LENGTH=4,r.Encoding={UTF8_BYTES:1,UTF16_STRING:2},r.int32=new Int32Array(2),r.float32=new Float32Array(r.int32.buffer),r.float64=new Float64Array(r.int32.buffer),r.isLittleEndian=1===new Uint16Array(new Uint8Array([1,0]).buffer)[0],r.Long=function(t,e){this.low=0|t,this.high=0|e},r.Long.create=function(t,e){return 0==t&&0==e?r.Long.ZERO:new r.Long(t,e)},r.Long.prototype.toFloat64=function(){return(this.low>>>0)+4294967296*this.high},r.Long.prototype.equals=function(t){return this.low==t.low&&this.high==t.high},r.Long.ZERO=new r.Long(0,0),r.Builder=function(t){if(t)e=t;else var e=1024;this.bb=r.ByteBuffer.allocate(e),this.space=e,this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1},r.Builder.prototype.clear=function(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1},r.Builder.prototype.forceDefaults=function(t){this.force_defaults=t},r.Builder.prototype.dataBuffer=function(){return this.bb},r.Builder.prototype.asUint8Array=function(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())},r.Builder.prototype.prep=function(t,e){t>this.minalign&&(this.minalign=t);for(var n=1+~(this.bb.capacity()-this.space+e)&t-1;this.space=0&&0==this.vtable[e];e--);for(var n=e+1;e>=0;e--)this.addInt16(0!=this.vtable[e]?t-this.vtable[e]:0);this.addInt16(t-this.object_start);var i=(n+2)*r.SIZEOF_SHORT;this.addInt16(i);var o=0,a=this.space;t:for(e=0;e=0;a--)this.writeInt8(o.charCodeAt(a))}this.prep(this.minalign,r.SIZEOF_INT+i),this.addOffset(t),i&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)},r.Builder.prototype.finishSizePrefixed=function(t,e){this.finish(t,e,!0)},r.Builder.prototype.requiredField=function(t,e){var n=this.bb.capacity()-t,r=n-this.bb.readInt32(n);if(0==this.bb.readInt16(r+e))throw new Error("FlatBuffers: field "+e+" must be set")},r.Builder.prototype.startVector=function(t,e,n){this.notNested(),this.vector_num_elems=e,this.prep(r.SIZEOF_INT,t*e),this.prep(n,t*e)},r.Builder.prototype.endVector=function(){return this.writeInt32(this.vector_num_elems),this.offset()},r.Builder.prototype.createString=function(t){if(t instanceof Uint8Array)var e=t;else{e=[];for(var n=0;n=56320?i:(i<<10)+t.charCodeAt(n++)+-56613888)<128?e.push(r):(r<2048?e.push(r>>6&31|192):(r<65536?e.push(r>>12&15|224):e.push(r>>18&7|240,r>>12&63|128),e.push(r>>6&63|128)),e.push(63&r|128))}}this.addInt8(0),this.startVector(1,e.length,1),this.bb.setPosition(this.space-=e.length),n=0;for(var o=this.space,a=this.bb.bytes();n>24},r.ByteBuffer.prototype.readUint8=function(t){return this.bytes_[t]},r.ByteBuffer.prototype.readInt16=function(t){return this.readUint16(t)<<16>>16},r.ByteBuffer.prototype.readUint16=function(t){return this.bytes_[t]|this.bytes_[t+1]<<8},r.ByteBuffer.prototype.readInt32=function(t){return this.bytes_[t]|this.bytes_[t+1]<<8|this.bytes_[t+2]<<16|this.bytes_[t+3]<<24},r.ByteBuffer.prototype.readUint32=function(t){return this.readInt32(t)>>>0},r.ByteBuffer.prototype.readInt64=function(t){return new r.Long(this.readInt32(t),this.readInt32(t+4))},r.ByteBuffer.prototype.readUint64=function(t){return new r.Long(this.readUint32(t),this.readUint32(t+4))},r.ByteBuffer.prototype.readFloat32=function(t){return r.int32[0]=this.readInt32(t),r.float32[0]},r.ByteBuffer.prototype.readFloat64=function(t){return r.int32[r.isLittleEndian?0:1]=this.readInt32(t),r.int32[r.isLittleEndian?1:0]=this.readInt32(t+4),r.float64[0]},r.ByteBuffer.prototype.writeInt8=function(t,e){this.bytes_[t]=e},r.ByteBuffer.prototype.writeUint8=function(t,e){this.bytes_[t]=e},r.ByteBuffer.prototype.writeInt16=function(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8},r.ByteBuffer.prototype.writeUint16=function(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8},r.ByteBuffer.prototype.writeInt32=function(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8,this.bytes_[t+2]=e>>16,this.bytes_[t+3]=e>>24},r.ByteBuffer.prototype.writeUint32=function(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8,this.bytes_[t+2]=e>>16,this.bytes_[t+3]=e>>24},r.ByteBuffer.prototype.writeInt64=function(t,e){this.writeInt32(t,e.low),this.writeInt32(t+4,e.high)},r.ByteBuffer.prototype.writeUint64=function(t,e){this.writeUint32(t,e.low),this.writeUint32(t+4,e.high)},r.ByteBuffer.prototype.writeFloat32=function(t,e){r.float32[0]=e,this.writeInt32(t,r.int32[0])},r.ByteBuffer.prototype.writeFloat64=function(t,e){r.float64[0]=e,this.writeInt32(t,r.int32[r.isLittleEndian?0:1]),this.writeInt32(t+4,r.int32[r.isLittleEndian?1:0])},r.ByteBuffer.prototype.getBufferIdentifier=function(){if(this.bytes_.length>10),56320+(1023&a)))}return i},r.ByteBuffer.prototype.__indirect=function(t){return t+this.readInt32(t)},r.ByteBuffer.prototype.__vector=function(t){return t+this.readInt32(t)+r.SIZEOF_INT},r.ByteBuffer.prototype.__vector_len=function(t){return this.readInt32(t+this.readInt32(t))},r.ByteBuffer.prototype.__has_identifier=function(t){if(t.length!=r.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: file identifier must be length "+r.FILE_IDENTIFIER_LENGTH);for(var e=0;e{var e=t&&t.__esModule?()=>t.default:()=>t;return __webpack_require__.d(e,{a:e}),e},__webpack_require__.d=(t,e)=>{for(var n in e)__webpack_require__.o(e,n)&&!__webpack_require__.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),__webpack_require__.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),__webpack_require__.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__(6018);return __webpack_exports__})())); +//# sourceMappingURL=ort.min.js.map \ No newline at end of file diff --git a/toolkit/components/ml/vendor/transformers-dev.js b/toolkit/components/ml/vendor/transformers-dev.js new file mode 100644 index 0000000000..23e4ba18d1 --- /dev/null +++ b/toolkit/components/ml/vendor/transformers-dev.js @@ -0,0 +1,25483 @@ +import * as __WEBPACK_EXTERNAL_MODULE_chrome_global_content_ml_ort_dev_js_1378f1ef__ from "chrome://global/content/ml/ort-dev.js"; +/******/ var __webpack_modules__ = ({ + +/***/ "onnxruntime-web": +/*!********************************************************!*\ + !*** external "chrome://global/content/ml/ort-dev.js" ***! + \********************************************************/ +/***/ ((module) => { + +var x = y => { var x = {}; __webpack_require__.d(x, y); return x; } +var y = x => () => x +module.exports = __WEBPACK_EXTERNAL_MODULE_chrome_global_content_ml_ort_dev_js_1378f1ef__; + +/***/ }), + +/***/ "?7a2c": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?a42a": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?2b25": +/*!***********************!*\ + !*** sharp (ignored) ***! + \***********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?e65c": +/*!****************************!*\ + !*** stream/web (ignored) ***! + \****************************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?569f": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?3f59": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "?154a": +/*!*********************!*\ + !*** url (ignored) ***! + \*********************/ +/***/ (() => { + +/* (ignored) */ + +/***/ }), + +/***/ "./node_modules/@huggingface/jinja/dist/index.js": +/*!*******************************************************!*\ + !*** ./node_modules/@huggingface/jinja/dist/index.js ***! + \*******************************************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "Environment": () => (/* binding */ Environment), +/* harmony export */ "Interpreter": () => (/* binding */ Interpreter), +/* harmony export */ "Template": () => (/* binding */ Template), +/* harmony export */ "parse": () => (/* binding */ parse), +/* harmony export */ "tokenize": () => (/* binding */ tokenize) +/* harmony export */ }); +// src/lexer.ts +var TOKEN_TYPES = Object.freeze({ + Text: "Text", + // The text between Jinja statements or expressions + NumericLiteral: "NumericLiteral", + // e.g., 123 + BooleanLiteral: "BooleanLiteral", + // true or false + StringLiteral: "StringLiteral", + // 'string' + Identifier: "Identifier", + // Variables, functions, etc. + Equals: "Equals", + // = + OpenParen: "OpenParen", + // ( + CloseParen: "CloseParen", + // ) + OpenStatement: "OpenStatement", + // {% + CloseStatement: "CloseStatement", + // %} + OpenExpression: "OpenExpression", + // {{ + CloseExpression: "CloseExpression", + // }} + OpenSquareBracket: "OpenSquareBracket", + // [ + CloseSquareBracket: "CloseSquareBracket", + // ] + OpenCurlyBracket: "OpenCurlyBracket", + // { + CloseCurlyBracket: "CloseCurlyBracket", + // } + Comma: "Comma", + // , + Dot: "Dot", + // . + Colon: "Colon", + // : + Pipe: "Pipe", + // | + CallOperator: "CallOperator", + // () + AdditiveBinaryOperator: "AdditiveBinaryOperator", + // + - + MultiplicativeBinaryOperator: "MultiplicativeBinaryOperator", + // * / % + ComparisonBinaryOperator: "ComparisonBinaryOperator", + // < > <= >= == != + UnaryOperator: "UnaryOperator", + // ! - + + // Keywords + Set: "Set", + If: "If", + For: "For", + In: "In", + Is: "Is", + NotIn: "NotIn", + Else: "Else", + EndIf: "EndIf", + ElseIf: "ElseIf", + EndFor: "EndFor", + And: "And", + Or: "Or", + Not: "UnaryOperator" +}); +var KEYWORDS = Object.freeze({ + set: TOKEN_TYPES.Set, + for: TOKEN_TYPES.For, + in: TOKEN_TYPES.In, + is: TOKEN_TYPES.Is, + if: TOKEN_TYPES.If, + else: TOKEN_TYPES.Else, + endif: TOKEN_TYPES.EndIf, + elif: TOKEN_TYPES.ElseIf, + endfor: TOKEN_TYPES.EndFor, + and: TOKEN_TYPES.And, + or: TOKEN_TYPES.Or, + not: TOKEN_TYPES.Not, + "not in": TOKEN_TYPES.NotIn, + // Literals + true: TOKEN_TYPES.BooleanLiteral, + false: TOKEN_TYPES.BooleanLiteral +}); +var Token = class { + /** + * Constructs a new Token. + * @param {string} value The raw value as seen inside the source code. + * @param {TokenType} type The type of token. + */ + constructor(value, type) { + this.value = value; + this.type = type; + } +}; +function isWord(char) { + return /\w/.test(char); +} +function isInteger(char) { + return /[0-9]/.test(char); +} +var ORDERED_MAPPING_TABLE = [ + // Control sequences + ["{%", TOKEN_TYPES.OpenStatement], + ["%}", TOKEN_TYPES.CloseStatement], + ["{{", TOKEN_TYPES.OpenExpression], + ["}}", TOKEN_TYPES.CloseExpression], + // Single character tokens + ["(", TOKEN_TYPES.OpenParen], + [")", TOKEN_TYPES.CloseParen], + ["{", TOKEN_TYPES.OpenCurlyBracket], + ["}", TOKEN_TYPES.CloseCurlyBracket], + ["[", TOKEN_TYPES.OpenSquareBracket], + ["]", TOKEN_TYPES.CloseSquareBracket], + [",", TOKEN_TYPES.Comma], + [".", TOKEN_TYPES.Dot], + [":", TOKEN_TYPES.Colon], + ["|", TOKEN_TYPES.Pipe], + // Comparison operators + ["<=", TOKEN_TYPES.ComparisonBinaryOperator], + [">=", TOKEN_TYPES.ComparisonBinaryOperator], + ["==", TOKEN_TYPES.ComparisonBinaryOperator], + ["!=", TOKEN_TYPES.ComparisonBinaryOperator], + ["<", TOKEN_TYPES.ComparisonBinaryOperator], + [">", TOKEN_TYPES.ComparisonBinaryOperator], + // Arithmetic operators + ["+", TOKEN_TYPES.AdditiveBinaryOperator], + ["-", TOKEN_TYPES.AdditiveBinaryOperator], + ["*", TOKEN_TYPES.MultiplicativeBinaryOperator], + ["/", TOKEN_TYPES.MultiplicativeBinaryOperator], + ["%", TOKEN_TYPES.MultiplicativeBinaryOperator], + // Assignment operator + ["=", TOKEN_TYPES.Equals] +]; +var ESCAPE_CHARACTERS = /* @__PURE__ */ new Map([ + ["n", "\n"], + // New line + ["t", " "], + // Horizontal tab + ["r", "\r"], + // Carriage return + ["b", "\b"], + // Backspace + ["f", "\f"], + // Form feed + ["v", "\v"], + // Vertical tab + ["'", "'"], + // Single quote + ['"', '"'], + // Double quote + ["\\", "\\"] + // Backslash +]); +function preprocess(template, options = {}) { + if (template.endsWith("\n")) { + template = template.slice(0, -1); + } + template = template.replace(/{#.*?#}/gs, "{##}"); + if (options.lstrip_blocks) { + template = template.replace(/^[ \t]*({[#%])/gm, "$1"); + } + if (options.trim_blocks) { + template = template.replace(/([#%]})\n/g, "$1"); + } + return template.replace(/{##}/g, "").replace(/-%}\s*/g, "%}").replace(/\s*{%-/g, "{%").replace(/-}}\s*/g, "}}").replace(/\s*{{-/g, "{{"); +} +function tokenize(source, options = {}) { + const tokens = []; + const src = preprocess(source, options); + let cursorPosition = 0; + const consumeWhile = (predicate) => { + let str = ""; + while (predicate(src[cursorPosition])) { + if (src[cursorPosition] === "\\") { + ++cursorPosition; + if (cursorPosition >= src.length) + throw new SyntaxError("Unexpected end of input"); + const escaped = src[cursorPosition++]; + const unescaped = ESCAPE_CHARACTERS.get(escaped); + if (unescaped === void 0) { + throw new SyntaxError(`Unexpected escaped character: ${escaped}`); + } + str += unescaped; + continue; + } + str += src[cursorPosition++]; + if (cursorPosition >= src.length) + throw new SyntaxError("Unexpected end of input"); + } + return str; + }; + main: + while (cursorPosition < src.length) { + const lastTokenType = tokens.at(-1)?.type; + if (lastTokenType === void 0 || lastTokenType === TOKEN_TYPES.CloseStatement || lastTokenType === TOKEN_TYPES.CloseExpression) { + let text = ""; + while (cursorPosition < src.length && // Keep going until we hit the next Jinja statement or expression + !(src[cursorPosition] === "{" && (src[cursorPosition + 1] === "%" || src[cursorPosition + 1] === "{"))) { + text += src[cursorPosition++]; + } + if (text.length > 0) { + tokens.push(new Token(text, TOKEN_TYPES.Text)); + continue; + } + } + consumeWhile((char2) => /\s/.test(char2)); + const char = src[cursorPosition]; + if (char === "-" || char === "+") { + const lastTokenType2 = tokens.at(-1)?.type; + if (lastTokenType2 === TOKEN_TYPES.Text || lastTokenType2 === void 0) { + throw new SyntaxError(`Unexpected character: ${char}`); + } + switch (lastTokenType2) { + case TOKEN_TYPES.Identifier: + case TOKEN_TYPES.NumericLiteral: + case TOKEN_TYPES.BooleanLiteral: + case TOKEN_TYPES.StringLiteral: + case TOKEN_TYPES.CloseParen: + case TOKEN_TYPES.CloseSquareBracket: + break; + default: { + ++cursorPosition; + const num = consumeWhile(isInteger); + tokens.push( + new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator) + ); + continue; + } + } + } + for (const [char2, token] of ORDERED_MAPPING_TABLE) { + const slice2 = src.slice(cursorPosition, cursorPosition + char2.length); + if (slice2 === char2) { + tokens.push(new Token(char2, token)); + cursorPosition += char2.length; + continue main; + } + } + if (char === "'" || char === '"') { + ++cursorPosition; + const str = consumeWhile((c) => c !== char); + tokens.push(new Token(str, TOKEN_TYPES.StringLiteral)); + ++cursorPosition; + continue; + } + if (isInteger(char)) { + const num = consumeWhile(isInteger); + tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral)); + continue; + } + if (isWord(char)) { + const word = consumeWhile(isWord); + const type = Object.hasOwn(KEYWORDS, word) ? KEYWORDS[word] : TOKEN_TYPES.Identifier; + if (type === TOKEN_TYPES.In && tokens.at(-1)?.type === TOKEN_TYPES.Not) { + tokens.pop(); + tokens.push(new Token("not in", TOKEN_TYPES.NotIn)); + } else { + tokens.push(new Token(word, type)); + } + continue; + } + throw new SyntaxError(`Unexpected character: ${char}`); + } + return tokens; +} + +// src/ast.ts +var Statement = class { + type = "Statement"; +}; +var Program = class extends Statement { + constructor(body) { + super(); + this.body = body; + } + type = "Program"; +}; +var If = class extends Statement { + constructor(test, body, alternate) { + super(); + this.test = test; + this.body = body; + this.alternate = alternate; + } + type = "If"; +}; +var For = class extends Statement { + constructor(loopvar, iterable, body) { + super(); + this.loopvar = loopvar; + this.iterable = iterable; + this.body = body; + } + type = "For"; +}; +var SetStatement = class extends Statement { + constructor(assignee, value) { + super(); + this.assignee = assignee; + this.value = value; + } + type = "Set"; +}; +var Expression = class extends Statement { + type = "Expression"; +}; +var MemberExpression = class extends Expression { + constructor(object, property, computed) { + super(); + this.object = object; + this.property = property; + this.computed = computed; + } + type = "MemberExpression"; +}; +var CallExpression = class extends Expression { + constructor(callee, args) { + super(); + this.callee = callee; + this.args = args; + } + type = "CallExpression"; +}; +var Identifier = class extends Expression { + /** + * @param {string} value The name of the identifier + */ + constructor(value) { + super(); + this.value = value; + } + type = "Identifier"; +}; +var Literal = class extends Expression { + constructor(value) { + super(); + this.value = value; + } + type = "Literal"; +}; +var NumericLiteral = class extends Literal { + type = "NumericLiteral"; +}; +var StringLiteral = class extends Literal { + type = "StringLiteral"; +}; +var BooleanLiteral = class extends Literal { + type = "BooleanLiteral"; +}; +var ArrayLiteral = class extends Literal { + type = "ArrayLiteral"; +}; +var TupleLiteral = class extends Literal { + type = "TupleLiteral"; +}; +var ObjectLiteral = class extends Literal { + type = "ObjectLiteral"; +}; +var BinaryExpression = class extends Expression { + constructor(operator, left, right) { + super(); + this.operator = operator; + this.left = left; + this.right = right; + } + type = "BinaryExpression"; +}; +var FilterExpression = class extends Expression { + constructor(operand, filter) { + super(); + this.operand = operand; + this.filter = filter; + } + type = "FilterExpression"; +}; +var TestExpression = class extends Expression { + constructor(operand, negate, test) { + super(); + this.operand = operand; + this.negate = negate; + this.test = test; + } + type = "TestExpression"; +}; +var UnaryExpression = class extends Expression { + constructor(operator, argument) { + super(); + this.operator = operator; + this.argument = argument; + } + type = "UnaryExpression"; +}; +var SliceExpression = class extends Expression { + constructor(start = void 0, stop = void 0, step = void 0) { + super(); + this.start = start; + this.stop = stop; + this.step = step; + } + type = "SliceExpression"; +}; +var KeywordArgumentExpression = class extends Expression { + constructor(key, value) { + super(); + this.key = key; + this.value = value; + } + type = "KeywordArgumentExpression"; +}; + +// src/parser.ts +function parse(tokens) { + const program = new Program([]); + let current = 0; + function expect(type, error) { + const prev = tokens[current++]; + if (!prev || prev.type !== type) { + throw new Error(`Parser Error: ${error}. ${prev.type} !== ${type}.`); + } + return prev; + } + function parseAny() { + switch (tokens[current].type) { + case TOKEN_TYPES.Text: + return parseText(); + case TOKEN_TYPES.OpenStatement: + return parseJinjaStatement(); + case TOKEN_TYPES.OpenExpression: + return parseJinjaExpression(); + default: + throw new SyntaxError(`Unexpected token type: ${tokens[current].type}`); + } + } + function not(...types) { + return current + types.length <= tokens.length && types.some((type, i) => type !== tokens[current + i].type); + } + function is(...types) { + return current + types.length <= tokens.length && types.every((type, i) => type === tokens[current + i].type); + } + function parseText() { + return new StringLiteral(expect(TOKEN_TYPES.Text, "Expected text token").value); + } + function parseJinjaStatement() { + expect(TOKEN_TYPES.OpenStatement, "Expected opening statement token"); + let result; + switch (tokens[current].type) { + case TOKEN_TYPES.Set: + ++current; + result = parseSetStatement(); + expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token"); + break; + case TOKEN_TYPES.If: + ++current; + result = parseIfStatement(); + expect(TOKEN_TYPES.OpenStatement, "Expected {% token"); + expect(TOKEN_TYPES.EndIf, "Expected endif token"); + expect(TOKEN_TYPES.CloseStatement, "Expected %} token"); + break; + case TOKEN_TYPES.For: + ++current; + result = parseForStatement(); + expect(TOKEN_TYPES.OpenStatement, "Expected {% token"); + expect(TOKEN_TYPES.EndFor, "Expected endfor token"); + expect(TOKEN_TYPES.CloseStatement, "Expected %} token"); + break; + default: + throw new SyntaxError(`Unknown statement type: ${tokens[current].type}`); + } + return result; + } + function parseJinjaExpression() { + expect(TOKEN_TYPES.OpenExpression, "Expected opening expression token"); + const result = parseExpression(); + expect(TOKEN_TYPES.CloseExpression, "Expected closing expression token"); + return result; + } + function parseSetStatement() { + const left = parseExpression(); + if (is(TOKEN_TYPES.Equals)) { + ++current; + const value = parseSetStatement(); + return new SetStatement(left, value); + } + return left; + } + function parseIfStatement() { + const test = parseExpression(); + expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token"); + const body = []; + const alternate = []; + while (!(tokens[current]?.type === TOKEN_TYPES.OpenStatement && (tokens[current + 1]?.type === TOKEN_TYPES.ElseIf || tokens[current + 1]?.type === TOKEN_TYPES.Else || tokens[current + 1]?.type === TOKEN_TYPES.EndIf))) { + body.push(parseAny()); + } + if (tokens[current]?.type === TOKEN_TYPES.OpenStatement && tokens[current + 1]?.type !== TOKEN_TYPES.EndIf) { + ++current; + if (is(TOKEN_TYPES.ElseIf)) { + expect(TOKEN_TYPES.ElseIf, "Expected elseif token"); + alternate.push(parseIfStatement()); + } else { + expect(TOKEN_TYPES.Else, "Expected else token"); + expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token"); + while (!(tokens[current]?.type === TOKEN_TYPES.OpenStatement && tokens[current + 1]?.type === TOKEN_TYPES.EndIf)) { + alternate.push(parseAny()); + } + } + } + return new If(test, body, alternate); + } + function parseExpressionSequence(primary = false) { + const fn = primary ? parsePrimaryExpression : parseExpression; + const expressions = [fn()]; + const isTuple = is(TOKEN_TYPES.Comma); + while (isTuple) { + ++current; + expressions.push(fn()); + if (!is(TOKEN_TYPES.Comma)) { + break; + } + } + return isTuple ? new TupleLiteral(expressions) : expressions[0]; + } + function parseForStatement() { + const loopVariable = parseExpressionSequence(true); + if (!(loopVariable instanceof Identifier || loopVariable instanceof TupleLiteral)) { + throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${loopVariable.type} instead`); + } + expect(TOKEN_TYPES.In, "Expected `in` keyword following loop variable"); + const iterable = parseExpression(); + expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token"); + const body = []; + while (not(TOKEN_TYPES.OpenStatement, TOKEN_TYPES.EndFor)) { + body.push(parseAny()); + } + return new For(loopVariable, iterable, body); + } + function parseExpression() { + return parseTernaryExpression(); + } + function parseTernaryExpression() { + const a = parseLogicalOrExpression(); + if (is(TOKEN_TYPES.If)) { + ++current; + const predicate = parseLogicalOrExpression(); + expect(TOKEN_TYPES.Else, "Expected else token"); + const b = parseLogicalOrExpression(); + return new If(predicate, [a], [b]); + } + return a; + } + function parseLogicalOrExpression() { + let left = parseLogicalAndExpression(); + while (is(TOKEN_TYPES.Or)) { + const operator = tokens[current]; + ++current; + const right = parseLogicalAndExpression(); + left = new BinaryExpression(operator, left, right); + } + return left; + } + function parseLogicalAndExpression() { + let left = parseLogicalNegationExpression(); + while (is(TOKEN_TYPES.And)) { + const operator = tokens[current]; + ++current; + const right = parseLogicalNegationExpression(); + left = new BinaryExpression(operator, left, right); + } + return left; + } + function parseLogicalNegationExpression() { + let right; + while (is(TOKEN_TYPES.Not)) { + const operator = tokens[current]; + ++current; + const arg = parseLogicalNegationExpression(); + right = new UnaryExpression(operator, arg); + } + return right ?? parseComparisonExpression(); + } + function parseComparisonExpression() { + let left = parseAdditiveExpression(); + while (is(TOKEN_TYPES.ComparisonBinaryOperator) || is(TOKEN_TYPES.In) || is(TOKEN_TYPES.NotIn)) { + const operator = tokens[current]; + ++current; + const right = parseAdditiveExpression(); + left = new BinaryExpression(operator, left, right); + } + return left; + } + function parseAdditiveExpression() { + let left = parseMultiplicativeExpression(); + while (is(TOKEN_TYPES.AdditiveBinaryOperator)) { + const operator = tokens[current]; + ++current; + const right = parseMultiplicativeExpression(); + left = new BinaryExpression(operator, left, right); + } + return left; + } + function parseCallMemberExpression() { + const member = parseMemberExpression(); + if (is(TOKEN_TYPES.OpenParen)) { + return parseCallExpression(member); + } + return member; + } + function parseCallExpression(callee) { + let callExpression = new CallExpression(callee, parseArgs()); + if (is(TOKEN_TYPES.OpenParen)) { + callExpression = parseCallExpression(callExpression); + } + return callExpression; + } + function parseArgs() { + expect(TOKEN_TYPES.OpenParen, "Expected opening parenthesis for arguments list"); + const args = parseArgumentsList(); + expect(TOKEN_TYPES.CloseParen, "Expected closing parenthesis for arguments list"); + return args; + } + function parseArgumentsList() { + const args = []; + while (!is(TOKEN_TYPES.CloseParen)) { + let argument = parseExpression(); + if (is(TOKEN_TYPES.Equals)) { + ++current; + if (!(argument instanceof Identifier)) { + throw new SyntaxError(`Expected identifier for keyword argument`); + } + const value = parseExpression(); + argument = new KeywordArgumentExpression(argument, value); + } + args.push(argument); + if (is(TOKEN_TYPES.Comma)) { + ++current; + } + } + return args; + } + function parseMemberExpressionArgumentsList() { + const slices = []; + let isSlice = false; + while (!is(TOKEN_TYPES.CloseSquareBracket)) { + if (is(TOKEN_TYPES.Colon)) { + slices.push(void 0); + ++current; + isSlice = true; + } else { + slices.push(parseExpression()); + if (is(TOKEN_TYPES.Colon)) { + ++current; + isSlice = true; + } + } + } + if (slices.length === 0) { + throw new SyntaxError(`Expected at least one argument for member/slice expression`); + } + if (isSlice) { + if (slices.length > 3) { + throw new SyntaxError(`Expected 0-3 arguments for slice expression`); + } + return new SliceExpression(...slices); + } + return slices[0]; + } + function parseMemberExpression() { + let object = parsePrimaryExpression(); + while (is(TOKEN_TYPES.Dot) || is(TOKEN_TYPES.OpenSquareBracket)) { + const operator = tokens[current]; + ++current; + let property; + const computed = operator.type !== TOKEN_TYPES.Dot; + if (computed) { + property = parseMemberExpressionArgumentsList(); + expect(TOKEN_TYPES.CloseSquareBracket, "Expected closing square bracket"); + } else { + property = parsePrimaryExpression(); + if (property.type !== "Identifier") { + throw new SyntaxError(`Expected identifier following dot operator`); + } + } + object = new MemberExpression(object, property, computed); + } + return object; + } + function parseMultiplicativeExpression() { + let left = parseTestExpression(); + while (is(TOKEN_TYPES.MultiplicativeBinaryOperator)) { + const operator = tokens[current]; + ++current; + const right = parseTestExpression(); + left = new BinaryExpression(operator, left, right); + } + return left; + } + function parseTestExpression() { + let operand = parseFilterExpression(); + while (is(TOKEN_TYPES.Is)) { + ++current; + const negate = is(TOKEN_TYPES.Not); + if (negate) { + ++current; + } + let filter = parsePrimaryExpression(); + if (filter instanceof BooleanLiteral) { + filter = new Identifier(filter.value.toString()); + } + if (!(filter instanceof Identifier)) { + throw new SyntaxError(`Expected identifier for the test`); + } + operand = new TestExpression(operand, negate, filter); + } + return operand; + } + function parseFilterExpression() { + let operand = parseCallMemberExpression(); + while (is(TOKEN_TYPES.Pipe)) { + ++current; + let filter = parsePrimaryExpression(); + if (!(filter instanceof Identifier)) { + throw new SyntaxError(`Expected identifier for the filter`); + } + if (is(TOKEN_TYPES.OpenParen)) { + filter = parseCallExpression(filter); + } + operand = new FilterExpression(operand, filter); + } + return operand; + } + function parsePrimaryExpression() { + const token = tokens[current]; + switch (token.type) { + case TOKEN_TYPES.NumericLiteral: + ++current; + return new NumericLiteral(Number(token.value)); + case TOKEN_TYPES.StringLiteral: + ++current; + return new StringLiteral(token.value); + case TOKEN_TYPES.BooleanLiteral: + ++current; + return new BooleanLiteral(token.value === "true"); + case TOKEN_TYPES.Identifier: + ++current; + return new Identifier(token.value); + case TOKEN_TYPES.OpenParen: { + ++current; + const expression = parseExpressionSequence(); + if (tokens[current].type !== TOKEN_TYPES.CloseParen) { + throw new SyntaxError(`Expected closing parenthesis, got ${tokens[current].type} instead`); + } + ++current; + return expression; + } + case TOKEN_TYPES.OpenSquareBracket: { + ++current; + const values = []; + while (!is(TOKEN_TYPES.CloseSquareBracket)) { + values.push(parseExpression()); + if (is(TOKEN_TYPES.Comma)) { + ++current; + } + } + ++current; + return new ArrayLiteral(values); + } + case TOKEN_TYPES.OpenCurlyBracket: { + ++current; + const values = /* @__PURE__ */ new Map(); + while (!is(TOKEN_TYPES.CloseCurlyBracket)) { + const key = parseExpression(); + expect(TOKEN_TYPES.Colon, "Expected colon between key and value in object literal"); + const value = parseExpression(); + values.set(key, value); + if (is(TOKEN_TYPES.Comma)) { + ++current; + } + } + ++current; + return new ObjectLiteral(values); + } + default: + throw new SyntaxError(`Unexpected token: ${token.type}`); + } + } + while (current < tokens.length) { + program.body.push(parseAny()); + } + return program; +} + +// src/utils.ts +function range(start, stop, step = 1) { + if (stop === void 0) { + stop = start; + start = 0; + } + const result = []; + for (let i = start; i < stop; i += step) { + result.push(i); + } + return result; +} +function slice(array, start, stop, step = 1) { + const direction = Math.sign(step); + if (direction >= 0) { + start = (start ??= 0) < 0 ? Math.max(array.length + start, 0) : Math.min(start, array.length); + stop = (stop ??= array.length) < 0 ? Math.max(array.length + stop, 0) : Math.min(stop, array.length); + } else { + start = (start ??= array.length - 1) < 0 ? Math.max(array.length + start, -1) : Math.min(start, array.length - 1); + stop = (stop ??= -1) < -1 ? Math.max(array.length + stop, -1) : Math.min(stop, array.length - 1); + } + const result = []; + for (let i = start; direction * i < direction * stop; i += step) { + result.push(array[i]); + } + return result; +} +function titleCase(value) { + return value.replace(/\b\w/g, (c) => c.toUpperCase()); +} + +// src/runtime.ts +var RuntimeValue = class { + type = "RuntimeValue"; + value; + /** + * A collection of built-in functions for this type. + */ + builtins = /* @__PURE__ */ new Map(); + /** + * Creates a new RuntimeValue. + */ + constructor(value = void 0) { + this.value = value; + } + /** + * Determines truthiness or falsiness of the runtime value. + * This function should be overridden by subclasses if it has custom truthiness criteria. + * @returns {BooleanValue} BooleanValue(true) if the value is truthy, BooleanValue(false) otherwise. + */ + __bool__() { + return new BooleanValue(!!this.value); + } +}; +var NumericValue = class extends RuntimeValue { + type = "NumericValue"; +}; +var StringValue = class extends RuntimeValue { + type = "StringValue"; + builtins = /* @__PURE__ */ new Map([ + [ + "upper", + new FunctionValue(() => { + return new StringValue(this.value.toUpperCase()); + }) + ], + [ + "lower", + new FunctionValue(() => { + return new StringValue(this.value.toLowerCase()); + }) + ], + [ + "strip", + new FunctionValue(() => { + return new StringValue(this.value.trim()); + }) + ], + [ + "title", + new FunctionValue(() => { + return new StringValue(titleCase(this.value)); + }) + ], + ["length", new NumericValue(this.value.length)] + ]); +}; +var BooleanValue = class extends RuntimeValue { + type = "BooleanValue"; +}; +var ObjectValue = class extends RuntimeValue { + type = "ObjectValue"; + /** + * NOTE: necessary to override since all JavaScript arrays are considered truthy, + * while only non-empty Python arrays are consider truthy. + * + * e.g., + * - JavaScript: {} && 5 -> 5 + * - Python: {} and 5 -> {} + */ + __bool__() { + return new BooleanValue(this.value.size > 0); + } + builtins = /* @__PURE__ */ new Map([ + [ + "get", + new FunctionValue(([key, defaultValue]) => { + if (!(key instanceof StringValue)) { + throw new Error(`Object key must be a string: got ${key.type}`); + } + return this.value.get(key.value) ?? defaultValue ?? new NullValue(); + }) + ], + [ + "items", + new FunctionValue(() => { + return new ArrayValue( + Array.from(this.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])) + ); + }) + ] + ]); +}; +var ArrayValue = class extends RuntimeValue { + type = "ArrayValue"; + builtins = /* @__PURE__ */ new Map([["length", new NumericValue(this.value.length)]]); + /** + * NOTE: necessary to override since all JavaScript arrays are considered truthy, + * while only non-empty Python arrays are consider truthy. + * + * e.g., + * - JavaScript: [] && 5 -> 5 + * - Python: [] and 5 -> [] + */ + __bool__() { + return new BooleanValue(this.value.length > 0); + } +}; +var TupleValue = class extends ArrayValue { + type = "TupleValue"; +}; +var FunctionValue = class extends RuntimeValue { + type = "FunctionValue"; +}; +var NullValue = class extends RuntimeValue { + type = "NullValue"; +}; +var UndefinedValue = class extends RuntimeValue { + type = "UndefinedValue"; +}; +var Environment = class { + constructor(parent) { + this.parent = parent; + } + /** + * The variables declared in this environment. + */ + variables = /* @__PURE__ */ new Map([ + [ + "namespace", + new FunctionValue((args) => { + if (args.length === 0) { + return new ObjectValue(/* @__PURE__ */ new Map()); + } + if (args.length !== 1 || !(args[0] instanceof ObjectValue)) { + throw new Error("`namespace` expects either zero arguments or a single object argument"); + } + return args[0]; + }) + ] + ]); + /** + * The tests available in this environment. + */ + tests = /* @__PURE__ */ new Map([ + ["boolean", (operand) => operand.type === "BooleanValue"], + ["callable", (operand) => operand instanceof FunctionValue], + [ + "odd", + (operand) => { + if (operand.type !== "NumericValue") { + throw new Error(`Cannot apply test "odd" to type: ${operand.type}`); + } + return operand.value % 2 !== 0; + } + ], + [ + "even", + (operand) => { + if (operand.type !== "NumericValue") { + throw new Error(`Cannot apply test "even" to type: ${operand.type}`); + } + return operand.value % 2 === 0; + } + ], + ["false", (operand) => operand.type === "BooleanValue" && !operand.value], + ["true", (operand) => operand.type === "BooleanValue" && operand.value], + ["number", (operand) => operand.type === "NumericValue"], + ["integer", (operand) => operand.type === "NumericValue" && Number.isInteger(operand.value)], + ["iterable", (operand) => operand instanceof ArrayValue || operand instanceof StringValue], + [ + "lower", + (operand) => { + const str = operand.value; + return operand.type === "StringValue" && str === str.toLowerCase(); + } + ], + [ + "upper", + (operand) => { + const str = operand.value; + return operand.type === "StringValue" && str === str.toUpperCase(); + } + ], + ["none", (operand) => operand.type === "NullValue"], + ["defined", (operand) => operand.type !== "UndefinedValue"], + ["undefined", (operand) => operand.type === "UndefinedValue"], + ["equalto", (a, b) => a.value === b.value] + ]); + /** + * Set the value of a variable in the current environment. + */ + set(name, value) { + return this.declareVariable(name, convertToRuntimeValues(value)); + } + declareVariable(name, value) { + if (this.variables.has(name)) { + throw new SyntaxError(`Variable already declared: ${name}`); + } + this.variables.set(name, value); + return value; + } + // private assignVariable(name: string, value: AnyRuntimeValue): AnyRuntimeValue { + // const env = this.resolve(name); + // env.variables.set(name, value); + // return value; + // } + /** + * Set variable in the current scope. + * See https://jinja.palletsprojects.com/en/3.0.x/templates/#assignments for more information. + */ + setVariable(name, value) { + this.variables.set(name, value); + return value; + } + /** + * Resolve the environment in which the variable is declared. + * @param {string} name The name of the variable. + * @returns {Environment} The environment in which the variable is declared. + */ + resolve(name) { + if (this.variables.has(name)) { + return this; + } + if (this.parent) { + return this.parent.resolve(name); + } + throw new Error(`Unknown variable: ${name}`); + } + lookupVariable(name) { + try { + return this.resolve(name).variables.get(name) ?? new UndefinedValue(); + } catch { + return new UndefinedValue(); + } + } +}; +var Interpreter = class { + global; + constructor(env) { + this.global = env ?? new Environment(); + } + /** + * Run the program. + */ + run(program) { + return this.evaluate(program, this.global); + } + /** + * Evaluates expressions following the binary operation type. + */ + evaluateBinaryExpression(node, environment) { + const left = this.evaluate(node.left, environment); + switch (node.operator.value) { + case "and": + return left.__bool__().value ? this.evaluate(node.right, environment) : left; + case "or": + return left.__bool__().value ? left : this.evaluate(node.right, environment); + } + const right = this.evaluate(node.right, environment); + switch (node.operator.value) { + case "==": + return new BooleanValue(left.value == right.value); + case "!=": + return new BooleanValue(left.value != right.value); + } + if (left instanceof UndefinedValue || right instanceof UndefinedValue) { + throw new Error("Cannot perform operation on undefined values"); + } else if (left instanceof NullValue || right instanceof NullValue) { + throw new Error("Cannot perform operation on null values"); + } else if (left instanceof NumericValue && right instanceof NumericValue) { + switch (node.operator.value) { + case "+": + return new NumericValue(left.value + right.value); + case "-": + return new NumericValue(left.value - right.value); + case "*": + return new NumericValue(left.value * right.value); + case "/": + return new NumericValue(left.value / right.value); + case "%": + return new NumericValue(left.value % right.value); + case "<": + return new BooleanValue(left.value < right.value); + case ">": + return new BooleanValue(left.value > right.value); + case ">=": + return new BooleanValue(left.value >= right.value); + case "<=": + return new BooleanValue(left.value <= right.value); + } + } else if (left instanceof ArrayValue && right instanceof ArrayValue) { + switch (node.operator.value) { + case "+": + return new ArrayValue(left.value.concat(right.value)); + } + } else if (right instanceof ArrayValue) { + const member = right.value.find((x) => x.value === left.value) !== void 0; + switch (node.operator.value) { + case "in": + return new BooleanValue(member); + case "not in": + return new BooleanValue(!member); + } + } + if (left instanceof StringValue || right instanceof StringValue) { + switch (node.operator.value) { + case "+": + return new StringValue(left.value.toString() + right.value.toString()); + } + } + if (left instanceof StringValue && right instanceof StringValue) { + switch (node.operator.value) { + case "in": + return new BooleanValue(right.value.includes(left.value)); + case "not in": + return new BooleanValue(!right.value.includes(left.value)); + } + } + if (left instanceof StringValue && right instanceof ObjectValue) { + switch (node.operator.value) { + case "in": + return new BooleanValue(right.value.has(left.value)); + case "not in": + return new BooleanValue(!right.value.has(left.value)); + } + } + throw new SyntaxError(`Unknown operator "${node.operator.value}" between ${left.type} and ${right.type}`); + } + /** + * Evaluates expressions following the filter operation type. + */ + evaluateFilterExpression(node, environment) { + const operand = this.evaluate(node.operand, environment); + if (node.filter.type === "Identifier") { + const filter = node.filter; + if (operand instanceof ArrayValue) { + switch (filter.value) { + case "list": + return operand; + case "first": + return operand.value[0]; + case "last": + return operand.value[operand.value.length - 1]; + case "length": + return new NumericValue(operand.value.length); + case "reverse": + return new ArrayValue(operand.value.reverse()); + case "sort": + return new ArrayValue( + operand.value.sort((a, b) => { + if (a.type !== b.type) { + throw new Error(`Cannot compare different types: ${a.type} and ${b.type}`); + } + switch (a.type) { + case "NumericValue": + return a.value - b.value; + case "StringValue": + return a.value.localeCompare(b.value); + default: + throw new Error(`Cannot compare type: ${a.type}`); + } + }) + ); + default: + throw new Error(`Unknown ArrayValue filter: ${filter.value}`); + } + } else if (operand instanceof StringValue) { + switch (filter.value) { + case "length": + return new NumericValue(operand.value.length); + case "upper": + return new StringValue(operand.value.toUpperCase()); + case "lower": + return new StringValue(operand.value.toLowerCase()); + case "title": + return new StringValue(titleCase(operand.value)); + case "capitalize": + return new StringValue(operand.value.charAt(0).toUpperCase() + operand.value.slice(1)); + case "trim": + return new StringValue(operand.value.trim()); + default: + throw new Error(`Unknown StringValue filter: ${filter.value}`); + } + } else if (operand instanceof NumericValue) { + switch (filter.value) { + case "abs": + return new NumericValue(Math.abs(operand.value)); + default: + throw new Error(`Unknown NumericValue filter: ${filter.value}`); + } + } else if (operand instanceof ObjectValue) { + switch (filter.value) { + case "items": + return new ArrayValue( + Array.from(operand.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])) + ); + case "length": + return new NumericValue(operand.value.size); + default: + throw new Error(`Unknown ObjectValue filter: ${filter.value}`); + } + } + throw new Error(`Cannot apply filter "${filter.value}" to type: ${operand.type}`); + } else if (node.filter.type === "CallExpression") { + const filter = node.filter; + if (filter.callee.type !== "Identifier") { + throw new Error(`Unknown filter: ${filter.callee.type}`); + } + const filterName = filter.callee.value; + if (operand instanceof ArrayValue) { + switch (filterName) { + case "selectattr": { + if (operand.value.some((x) => !(x instanceof ObjectValue))) { + throw new Error("`selectattr` can only be applied to array of objects"); + } + if (filter.args.some((x) => x.type !== "StringLiteral")) { + throw new Error("arguments of `selectattr` must be strings"); + } + const [attr, testName, value] = filter.args.map((x) => this.evaluate(x, environment)); + let testFunction; + if (testName) { + const test = environment.tests.get(testName.value); + if (!test) { + throw new Error(`Unknown test: ${testName.value}`); + } + testFunction = test; + } else { + testFunction = (...x) => x[0].__bool__().value; + } + const filtered = operand.value.filter((item) => { + const a = item.value.get(attr.value); + if (a) { + return testFunction(a, value); + } + return false; + }); + return new ArrayValue(filtered); + } + } + throw new Error(`Unknown ArrayValue filter: ${filterName}`); + } else { + throw new Error(`Cannot apply filter "${filterName}" to type: ${operand.type}`); + } + } + throw new Error(`Unknown filter: ${node.filter.type}`); + } + /** + * Evaluates expressions following the test operation type. + */ + evaluateTestExpression(node, environment) { + const operand = this.evaluate(node.operand, environment); + const test = environment.tests.get(node.test.value); + if (!test) { + throw new Error(`Unknown test: ${node.test.value}`); + } + const result = test(operand); + return new BooleanValue(node.negate ? !result : result); + } + /** + * Evaluates expressions following the unary operation type. + */ + evaluateUnaryExpression(node, environment) { + const argument = this.evaluate(node.argument, environment); + switch (node.operator.value) { + case "not": + return new BooleanValue(!argument.value); + default: + throw new SyntaxError(`Unknown operator: ${node.operator.value}`); + } + } + evalProgram(program, environment) { + return this.evaluateBlock(program.body, environment); + } + evaluateBlock(statements, environment) { + let result = ""; + for (const statement of statements) { + const lastEvaluated = this.evaluate(statement, environment); + if (lastEvaluated.type !== "NullValue" && lastEvaluated.type !== "UndefinedValue") { + result += lastEvaluated.value; + } + } + return new StringValue(result); + } + evaluateIdentifier(node, environment) { + return environment.lookupVariable(node.value); + } + evaluateCallExpression(expr, environment) { + const args = []; + const kwargs = /* @__PURE__ */ new Map(); + for (const argument of expr.args) { + if (argument.type === "KeywordArgumentExpression") { + const kwarg = argument; + kwargs.set(kwarg.key.value, this.evaluate(kwarg.value, environment)); + } else { + args.push(this.evaluate(argument, environment)); + } + } + if (kwargs.size > 0) { + args.push(new ObjectValue(kwargs)); + } + const fn = this.evaluate(expr.callee, environment); + if (fn.type !== "FunctionValue") { + throw new Error(`Cannot call something that is not a function: got ${fn.type}`); + } + return fn.value(args, environment); + } + evaluateSliceExpression(object, expr, environment) { + if (!(object instanceof ArrayValue || object instanceof StringValue)) { + throw new Error("Slice object must be an array or string"); + } + const start = this.evaluate(expr.start, environment); + const stop = this.evaluate(expr.stop, environment); + const step = this.evaluate(expr.step, environment); + if (!(start instanceof NumericValue || start instanceof UndefinedValue)) { + throw new Error("Slice start must be numeric or undefined"); + } + if (!(stop instanceof NumericValue || stop instanceof UndefinedValue)) { + throw new Error("Slice stop must be numeric or undefined"); + } + if (!(step instanceof NumericValue || step instanceof UndefinedValue)) { + throw new Error("Slice step must be numeric or undefined"); + } + if (object instanceof ArrayValue) { + return new ArrayValue(slice(object.value, start.value, stop.value, step.value)); + } else { + return new StringValue(slice(Array.from(object.value), start.value, stop.value, step.value).join("")); + } + } + evaluateMemberExpression(expr, environment) { + const object = this.evaluate(expr.object, environment); + let property; + if (expr.computed) { + if (expr.property.type === "SliceExpression") { + return this.evaluateSliceExpression(object, expr.property, environment); + } else { + property = this.evaluate(expr.property, environment); + } + } else { + property = new StringValue(expr.property.value); + } + let value; + if (object instanceof ObjectValue) { + if (!(property instanceof StringValue)) { + throw new Error(`Cannot access property with non-string: got ${property.type}`); + } + value = object.value.get(property.value) ?? object.builtins.get(property.value); + } else if (object instanceof ArrayValue || object instanceof StringValue) { + if (property instanceof NumericValue) { + value = object.value.at(property.value); + if (object instanceof StringValue) { + value = new StringValue(object.value.at(property.value)); + } + } else if (property instanceof StringValue) { + value = object.builtins.get(property.value); + } else { + throw new Error(`Cannot access property with non-string/non-number: got ${property.type}`); + } + } else { + if (!(property instanceof StringValue)) { + throw new Error(`Cannot access property with non-string: got ${property.type}`); + } + value = object.builtins.get(property.value); + } + return value instanceof RuntimeValue ? value : new UndefinedValue(); + } + evaluateSet(node, environment) { + const rhs = this.evaluate(node.value, environment); + if (node.assignee.type === "Identifier") { + const variableName = node.assignee.value; + environment.setVariable(variableName, rhs); + } else if (node.assignee.type === "MemberExpression") { + const member = node.assignee; + const object = this.evaluate(member.object, environment); + if (!(object instanceof ObjectValue)) { + throw new Error("Cannot assign to member of non-object"); + } + if (member.property.type !== "Identifier") { + throw new Error("Cannot assign to member with non-identifier property"); + } + object.value.set(member.property.value, rhs); + } else { + throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(node.assignee)}`); + } + return new NullValue(); + } + evaluateIf(node, environment) { + const test = this.evaluate(node.test, environment); + return this.evaluateBlock(test.__bool__().value ? node.body : node.alternate, environment); + } + evaluateFor(node, environment) { + const scope = new Environment(environment); + const iterable = this.evaluate(node.iterable, scope); + if (!(iterable instanceof ArrayValue)) { + throw new Error(`Expected iterable type in for loop: got ${iterable.type}`); + } + let result = ""; + for (let i = 0; i < iterable.value.length; ++i) { + const loop = /* @__PURE__ */ new Map([ + ["index", new NumericValue(i + 1)], + ["index0", new NumericValue(i)], + ["revindex", new NumericValue(iterable.value.length - i)], + ["revindex0", new NumericValue(iterable.value.length - i - 1)], + ["first", new BooleanValue(i === 0)], + ["last", new BooleanValue(i === iterable.value.length - 1)], + ["length", new NumericValue(iterable.value.length)], + ["previtem", i > 0 ? iterable.value[i - 1] : new UndefinedValue()], + ["nextitem", i < iterable.value.length - 1 ? iterable.value[i + 1] : new UndefinedValue()] + ]); + scope.setVariable("loop", new ObjectValue(loop)); + const current = iterable.value[i]; + if (node.loopvar.type === "Identifier") { + scope.setVariable(node.loopvar.value, current); + } else if (node.loopvar.type === "TupleLiteral") { + const loopvar = node.loopvar; + if (current.type !== "ArrayValue") { + throw new Error(`Cannot unpack non-iterable type: ${current.type}`); + } + const c = current; + if (loopvar.value.length !== c.value.length) { + throw new Error(`Too ${loopvar.value.length > c.value.length ? "few" : "many"} items to unpack`); + } + for (let j = 0; j < loopvar.value.length; ++j) { + if (loopvar.value[j].type !== "Identifier") { + throw new Error(`Cannot unpack non-identifier type: ${loopvar.value[j].type}`); + } + scope.setVariable(loopvar.value[j].value, c.value[j]); + } + } + const evaluated = this.evaluateBlock(node.body, scope); + result += evaluated.value; + } + return new StringValue(result); + } + evaluate(statement, environment) { + if (statement === void 0) + return new UndefinedValue(); + switch (statement.type) { + case "Program": + return this.evalProgram(statement, environment); + case "Set": + return this.evaluateSet(statement, environment); + case "If": + return this.evaluateIf(statement, environment); + case "For": + return this.evaluateFor(statement, environment); + case "NumericLiteral": + return new NumericValue(Number(statement.value)); + case "StringLiteral": + return new StringValue(statement.value); + case "BooleanLiteral": + return new BooleanValue(statement.value); + case "ArrayLiteral": + return new ArrayValue(statement.value.map((x) => this.evaluate(x, environment))); + case "TupleLiteral": + return new TupleValue(statement.value.map((x) => this.evaluate(x, environment))); + case "ObjectLiteral": { + const mapping = /* @__PURE__ */ new Map(); + for (const [key, value] of statement.value) { + const evaluatedKey = this.evaluate(key, environment); + if (!(evaluatedKey instanceof StringValue)) { + throw new Error(`Object keys must be strings: got ${evaluatedKey.type}`); + } + mapping.set(evaluatedKey.value, this.evaluate(value, environment)); + } + return new ObjectValue(mapping); + } + case "Identifier": + return this.evaluateIdentifier(statement, environment); + case "CallExpression": + return this.evaluateCallExpression(statement, environment); + case "MemberExpression": + return this.evaluateMemberExpression(statement, environment); + case "UnaryExpression": + return this.evaluateUnaryExpression(statement, environment); + case "BinaryExpression": + return this.evaluateBinaryExpression(statement, environment); + case "FilterExpression": + return this.evaluateFilterExpression(statement, environment); + case "TestExpression": + return this.evaluateTestExpression(statement, environment); + default: + throw new SyntaxError(`Unknown node type: ${statement.type}`); + } + } +}; +function convertToRuntimeValues(input) { + switch (typeof input) { + case "number": + return new NumericValue(input); + case "string": + return new StringValue(input); + case "boolean": + return new BooleanValue(input); + case "object": + if (input === null) { + return new NullValue(); + } else if (Array.isArray(input)) { + return new ArrayValue(input.map(convertToRuntimeValues)); + } else { + return new ObjectValue( + new Map(Object.entries(input).map(([key, value]) => [key, convertToRuntimeValues(value)])) + ); + } + case "function": + return new FunctionValue((args, _scope) => { + const result = input(...args.map((x) => x.value)) ?? null; + return convertToRuntimeValues(result); + }); + default: + throw new Error(`Cannot convert to runtime value: ${input}`); + } +} + +// src/index.ts +var Template = class { + parsed; + /** + * @param {string} template The template string + */ + constructor(template) { + const tokens = tokenize(template, { + lstrip_blocks: true, + trim_blocks: true + }); + this.parsed = parse(tokens); + } + render(items) { + const env = new Environment(); + env.set("false", false); + env.set("true", true); + env.set("raise_exception", (args) => { + throw new Error(args); + }); + env.set("range", range); + for (const [key, value] of Object.entries(items)) { + env.set(key, value); + } + const interpreter = new Interpreter(env); + const result = interpreter.run(this.parsed); + return result.value; + } +}; + + + +/***/ }), + +/***/ "./src/backends/onnx.js": +/*!******************************!*\ + !*** ./src/backends/onnx.js ***! + \******************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "ONNX": () => (/* binding */ ONNX), +/* harmony export */ "executionProviders": () => (/* binding */ executionProviders) +/* harmony export */ }); +/* harmony import */ var onnxruntime_web__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! onnxruntime-web */ "onnxruntime-web"); +/** + * @file Handler file for choosing the correct version of ONNX Runtime, based on the environment. + * Ideally, we could import the `onnxruntime-web` and `onnxruntime-node` packages only when needed, + * but dynamic imports don't seem to work with the current webpack version and/or configuration. + * This is possibly due to the experimental nature of top-level await statements. + * So, we just import both packages, and use the appropriate one based on the environment: + * - When running in node, we use `onnxruntime-node`. + * - When running in the browser, we use `onnxruntime-web` (`onnxruntime-node` is not bundled). + * + * This module is not directly exported, but can be accessed through the environment variables: + * ```javascript + * import { env } from '@xenova/transformers'; + * console.log(env.backends.onnx); + * ``` + * + * @module backends/onnx + */ + +// NOTE: Import order matters here. We need to import `onnxruntime-node` before `onnxruntime-web`. +// In either case, we select the default export if it exists, otherwise we use the named export. +//import * as ONNX_NODE from 'onnxruntime-node'; +//import * as ONNX_WEB from 'onnxruntime-web'; + + +const ONNX_WEB = ort; + + +/** @type {import('onnxruntime-web')} The ONNX runtime module. */ +let ONNX; + +const executionProviders = [ + // 'webgpu', + 'wasm' +]; + +if (typeof process !== 'undefined' && process?.release?.name === 'node') { + // Running in a node-like environment. + ONNX = ONNX_NODE.default ?? ONNX_NODE; + + // Add `cpu` execution provider, with higher precedence that `wasm`. + executionProviders.unshift('cpu'); + +} else { + // Running in a browser-environment + ONNX = ONNX_WEB.default ?? ONNX_WEB; + + // SIMD for WebAssembly does not operate correctly in some recent versions of iOS (16.4.x). + // As a temporary fix, we disable it for now. + // For more information, see: https://github.com/microsoft/onnxruntime/issues/15644 + const isIOS = typeof navigator !== 'undefined' && /iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent); + if (isIOS) { + ONNX.env.wasm.simd = false; + } +} + + +/***/ }), + +/***/ "./src/configs.js": +/*!************************!*\ + !*** ./src/configs.js ***! + \************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "AutoConfig": () => (/* binding */ AutoConfig), +/* harmony export */ "PretrainedConfig": () => (/* binding */ PretrainedConfig) +/* harmony export */ }); +/* harmony import */ var _utils_hub_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/hub.js */ "./src/utils/hub.js"); + +/** + * @file Helper module for using model configs. For more information, see the corresponding + * [Python documentation](https://huggingface.co/docs/transformers/main/en/model_doc/auto#transformers.AutoConfig). + * + * **Example:** Load an `AutoConfig`. + * + * ```javascript + * import { AutoConfig } from '@xenova/transformers'; + * let config = await AutoConfig.from_pretrained('bert-base-uncased'); + * console.log(config); + * // PretrainedConfig { + * // "model_type": "bert", + * // "is_encoder_decoder": false, + * // "architectures": [ + * // "BertForMaskedLM" + * // ], + * // "vocab_size": 30522 + * // "num_attention_heads": 12, + * // "num_hidden_layers": 12, + * // "hidden_size": 768, + * // "max_position_embeddings": 512, + * // ... + * // } + * ``` + * + * @module configs + */ + + + +/** + * @typedef {import('./utils/hub.js').PretrainedOptions} PretrainedOptions + */ + + +/** + * Loads a config from the specified path. + * @param {string} pretrained_model_name_or_path The path to the config directory. + * @param {PretrainedOptions} options Additional options for loading the config. + * @returns {Promise} A promise that resolves with information about the loaded config. + */ +async function loadConfig(pretrained_model_name_or_path, options) { + let info = await (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_0__.getModelJSON)(pretrained_model_name_or_path, 'config.json', true, options); + return info; +} + +/** + * Base class for all configuration classes. For more information, see the corresponding + * [Python documentation](https://huggingface.co/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig). + */ +class PretrainedConfig { + // NOTE: Typo in original + + /** + * Create a new PreTrainedTokenizer instance. + * @param {Object} configJSON The JSON of the config. + */ + constructor(configJSON) { + this.model_type = null; + this.is_encoder_decoder = false; + + Object.assign(this, configJSON); + } + + /** + * Loads a pre-trained config from the given `pretrained_model_name_or_path`. + * + * @param {string} pretrained_model_name_or_path The path to the pre-trained config. + * @param {PretrainedOptions} options Additional options for loading the config. + * @throws {Error} Throws an error if the config.json is not found in the `pretrained_model_name_or_path`. + * + * @returns {Promise} A new instance of the `PretrainedConfig` class. + */ + static async from_pretrained(pretrained_model_name_or_path, { + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + } = {}) { + + let data = config ?? await loadConfig(pretrained_model_name_or_path, { + progress_callback, + config, + cache_dir, + local_files_only, + revision, + }) + return new this(data); + } +} + +/** + * Helper class which is used to instantiate pretrained configs with the `from_pretrained` function. + * + * @example + * let config = await AutoConfig.from_pretrained('bert-base-uncased'); + */ +class AutoConfig { + /** @type {PretrainedConfig.from_pretrained} */ + static async from_pretrained(...args) { + return PretrainedConfig.from_pretrained(...args); + } +} + + +/***/ }), + +/***/ "./src/env.js": +/*!********************!*\ + !*** ./src/env.js ***! + \********************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "env": () => (/* binding */ env) +/* harmony export */ }); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "?569f"); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "?3f59"); +/* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "?154a"); +/* harmony import */ var _backends_onnx_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./backends/onnx.js */ "./src/backends/onnx.js"); +/** + * @file Module used to configure Transformers.js. + * + * **Example:** Disable remote models. + * ```javascript + * import { env } from '@xenova/transformers'; + * env.allowRemoteModels = false; + * ``` + * + * **Example:** Set local model path. + * ```javascript + * import { env } from '@xenova/transformers'; + * env.localModelPath = '/path/to/local/models/'; + * ``` + * + * **Example:** Set cache directory. + * ```javascript + * import { env } from '@xenova/transformers'; + * env.cacheDir = '/path/to/cache/directory/'; + * ``` + * + * @module env + */ + + + + + + +const { env: onnx_env } = _backends_onnx_js__WEBPACK_IMPORTED_MODULE_3__.ONNX; + +const VERSION = '2.16.1'; + +// Check if various APIs are available (depends on environment) +const WEB_CACHE_AVAILABLE = typeof self !== 'undefined' && 'caches' in self; +const FS_AVAILABLE = !isEmpty(fs__WEBPACK_IMPORTED_MODULE_0__); // check if file system is available +const PATH_AVAILABLE = !isEmpty(path__WEBPACK_IMPORTED_MODULE_1__); // check if path is available + +const RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE; + +const __dirname = RUNNING_LOCALLY + ? path__WEBPACK_IMPORTED_MODULE_1__.dirname(path__WEBPACK_IMPORTED_MODULE_1__.dirname(url__WEBPACK_IMPORTED_MODULE_2__.fileURLToPath("file:///Users/tarekziade/Dev/mozilla-central/toolkit/components/ml/vendor/tmp/transformers.js/src/env.js"))) + : './'; + +// Only used for environments with access to file system +const DEFAULT_CACHE_DIR = RUNNING_LOCALLY + ? path__WEBPACK_IMPORTED_MODULE_1__.join(__dirname, '/.cache/') + : null; + +// Set local model path, based on available APIs +const DEFAULT_LOCAL_MODEL_PATH = '/models/'; +const localModelPath = RUNNING_LOCALLY + ? path__WEBPACK_IMPORTED_MODULE_1__.join(__dirname, DEFAULT_LOCAL_MODEL_PATH) + : DEFAULT_LOCAL_MODEL_PATH; + +if (onnx_env?.wasm) { + // Set path to wasm files. This is needed when running in a web worker. + // https://onnxruntime.ai/docs/api/js/interfaces/Env.WebAssemblyFlags.html#wasmPaths + // We use remote wasm files by default to make it easier for newer users. + // In practice, users should probably self-host the necessary .wasm files. + onnx_env.wasm.wasmPaths = RUNNING_LOCALLY + ? path__WEBPACK_IMPORTED_MODULE_1__.join(__dirname, '/dist/') + : `https://cdn.jsdelivr.net/npm/@xenova/transformers@${VERSION}/dist/`; +} + +/** + * Global variable used to control execution. This provides users a simple way to configure Transformers.js. + * @property {Object} backends Expose environment variables of different backends, + * allowing users to set these variables if they want to. + * @property {string} __dirname Directory name of module. Useful for resolving local paths. + * @property {string} version This version of Transformers.js. + * @property {boolean} allowRemoteModels Whether to allow loading of remote files, defaults to `true`. + * If set to `false`, it will have the same effect as setting `local_files_only=true` when loading pipelines, models, tokenizers, processors, etc. + * @property {string} remoteHost Host URL to load models from. Defaults to the Hugging Face Hub. + * @property {string} remotePathTemplate Path template to fill in and append to `remoteHost` when loading models. + * @property {boolean} allowLocalModels Whether to allow loading of local files, defaults to `true`. + * If set to `false`, it will skip the local file check and try to load the model from the remote host. + * @property {string} localModelPath Path to load local models from. Defaults to `/models/`. + * @property {boolean} useFS Whether to use the file system to load files. By default, it is `true` if available. + * @property {boolean} useBrowserCache Whether to use Cache API to cache models. By default, it is `true` if available. + * @property {boolean} useFSCache Whether to use the file system to cache files. By default, it is `true` if available. + * @property {string} cacheDir The directory to use for caching files with the file system. By default, it is `./.cache`. + * @property {boolean} useCustomCache Whether to use a custom cache system (defined by `customCache`), defaults to `false`. + * @property {Object} customCache The custom cache to use. Defaults to `null`. Note: this must be an object which + * implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache + */ +const env = { + /////////////////// Backends settings /////////////////// + backends: { + // onnxruntime-web/onnxruntime-node + onnx: onnx_env, + + // TensorFlow.js + tfjs: {}, + }, + + __dirname, + version: VERSION, + + /////////////////// Model settings /////////////////// + allowRemoteModels: true, + remoteHost: 'https://huggingface.co/', + remotePathTemplate: '{model}/resolve/{revision}/', + + allowLocalModels: true, + localModelPath: localModelPath, + useFS: FS_AVAILABLE, + + /////////////////// Cache settings /////////////////// + useBrowserCache: WEB_CACHE_AVAILABLE, + + useFSCache: FS_AVAILABLE, + cacheDir: DEFAULT_CACHE_DIR, + + useCustomCache: false, + customCache: null, + ////////////////////////////////////////////////////// +} + + +/** + * @param {Object} obj + * @private + */ +function isEmpty(obj) { + return Object.keys(obj).length === 0; +} + + + +/***/ }), + +/***/ "./src/models.js": +/*!***********************!*\ + !*** ./src/models.js ***! + \***********************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "ASTForAudioClassification": () => (/* binding */ ASTForAudioClassification), +/* harmony export */ "ASTModel": () => (/* binding */ ASTModel), +/* harmony export */ "ASTPreTrainedModel": () => (/* binding */ ASTPreTrainedModel), +/* harmony export */ "AlbertForMaskedLM": () => (/* binding */ AlbertForMaskedLM), +/* harmony export */ "AlbertForQuestionAnswering": () => (/* binding */ AlbertForQuestionAnswering), +/* harmony export */ "AlbertForSequenceClassification": () => (/* binding */ AlbertForSequenceClassification), +/* harmony export */ "AlbertModel": () => (/* binding */ AlbertModel), +/* harmony export */ "AlbertPreTrainedModel": () => (/* binding */ AlbertPreTrainedModel), +/* harmony export */ "AutoModel": () => (/* binding */ AutoModel), +/* harmony export */ "AutoModelForAudioClassification": () => (/* binding */ AutoModelForAudioClassification), +/* harmony export */ "AutoModelForAudioFrameClassification": () => (/* binding */ AutoModelForAudioFrameClassification), +/* harmony export */ "AutoModelForCTC": () => (/* binding */ AutoModelForCTC), +/* harmony export */ "AutoModelForCausalLM": () => (/* binding */ AutoModelForCausalLM), +/* harmony export */ "AutoModelForDepthEstimation": () => (/* binding */ AutoModelForDepthEstimation), +/* harmony export */ "AutoModelForDocumentQuestionAnswering": () => (/* binding */ AutoModelForDocumentQuestionAnswering), +/* harmony export */ "AutoModelForImageClassification": () => (/* binding */ AutoModelForImageClassification), +/* harmony export */ "AutoModelForImageFeatureExtraction": () => (/* binding */ AutoModelForImageFeatureExtraction), +/* harmony export */ "AutoModelForImageMatting": () => (/* binding */ AutoModelForImageMatting), +/* harmony export */ "AutoModelForImageSegmentation": () => (/* binding */ AutoModelForImageSegmentation), +/* harmony export */ "AutoModelForImageToImage": () => (/* binding */ AutoModelForImageToImage), +/* harmony export */ "AutoModelForMaskGeneration": () => (/* binding */ AutoModelForMaskGeneration), +/* harmony export */ "AutoModelForMaskedLM": () => (/* binding */ AutoModelForMaskedLM), +/* harmony export */ "AutoModelForObjectDetection": () => (/* binding */ AutoModelForObjectDetection), +/* harmony export */ "AutoModelForQuestionAnswering": () => (/* binding */ AutoModelForQuestionAnswering), +/* harmony export */ "AutoModelForSemanticSegmentation": () => (/* binding */ AutoModelForSemanticSegmentation), +/* harmony export */ "AutoModelForSeq2SeqLM": () => (/* binding */ AutoModelForSeq2SeqLM), +/* harmony export */ "AutoModelForSequenceClassification": () => (/* binding */ AutoModelForSequenceClassification), +/* harmony export */ "AutoModelForSpeechSeq2Seq": () => (/* binding */ AutoModelForSpeechSeq2Seq), +/* harmony export */ "AutoModelForTextToSpectrogram": () => (/* binding */ AutoModelForTextToSpectrogram), +/* harmony export */ "AutoModelForTextToWaveform": () => (/* binding */ AutoModelForTextToWaveform), +/* harmony export */ "AutoModelForTokenClassification": () => (/* binding */ AutoModelForTokenClassification), +/* harmony export */ "AutoModelForVision2Seq": () => (/* binding */ AutoModelForVision2Seq), +/* harmony export */ "AutoModelForXVector": () => (/* binding */ AutoModelForXVector), +/* harmony export */ "AutoModelForZeroShotObjectDetection": () => (/* binding */ AutoModelForZeroShotObjectDetection), +/* harmony export */ "BartForConditionalGeneration": () => (/* binding */ BartForConditionalGeneration), +/* harmony export */ "BartForSequenceClassification": () => (/* binding */ BartForSequenceClassification), +/* harmony export */ "BartModel": () => (/* binding */ BartModel), +/* harmony export */ "BartPretrainedModel": () => (/* binding */ BartPretrainedModel), +/* harmony export */ "BaseModelOutput": () => (/* binding */ BaseModelOutput), +/* harmony export */ "BeitForImageClassification": () => (/* binding */ BeitForImageClassification), +/* harmony export */ "BeitModel": () => (/* binding */ BeitModel), +/* harmony export */ "BeitPreTrainedModel": () => (/* binding */ BeitPreTrainedModel), +/* harmony export */ "BertForMaskedLM": () => (/* binding */ BertForMaskedLM), +/* harmony export */ "BertForQuestionAnswering": () => (/* binding */ BertForQuestionAnswering), +/* harmony export */ "BertForSequenceClassification": () => (/* binding */ BertForSequenceClassification), +/* harmony export */ "BertForTokenClassification": () => (/* binding */ BertForTokenClassification), +/* harmony export */ "BertModel": () => (/* binding */ BertModel), +/* harmony export */ "BertPreTrainedModel": () => (/* binding */ BertPreTrainedModel), +/* harmony export */ "BlenderbotForConditionalGeneration": () => (/* binding */ BlenderbotForConditionalGeneration), +/* harmony export */ "BlenderbotModel": () => (/* binding */ BlenderbotModel), +/* harmony export */ "BlenderbotPreTrainedModel": () => (/* binding */ BlenderbotPreTrainedModel), +/* harmony export */ "BlenderbotSmallForConditionalGeneration": () => (/* binding */ BlenderbotSmallForConditionalGeneration), +/* harmony export */ "BlenderbotSmallModel": () => (/* binding */ BlenderbotSmallModel), +/* harmony export */ "BlenderbotSmallPreTrainedModel": () => (/* binding */ BlenderbotSmallPreTrainedModel), +/* harmony export */ "BloomForCausalLM": () => (/* binding */ BloomForCausalLM), +/* harmony export */ "BloomModel": () => (/* binding */ BloomModel), +/* harmony export */ "BloomPreTrainedModel": () => (/* binding */ BloomPreTrainedModel), +/* harmony export */ "CLIPModel": () => (/* binding */ CLIPModel), +/* harmony export */ "CLIPPreTrainedModel": () => (/* binding */ CLIPPreTrainedModel), +/* harmony export */ "CLIPSegForImageSegmentation": () => (/* binding */ CLIPSegForImageSegmentation), +/* harmony export */ "CLIPSegModel": () => (/* binding */ CLIPSegModel), +/* harmony export */ "CLIPSegPreTrainedModel": () => (/* binding */ CLIPSegPreTrainedModel), +/* harmony export */ "CLIPTextModelWithProjection": () => (/* binding */ CLIPTextModelWithProjection), +/* harmony export */ "CLIPVisionModelWithProjection": () => (/* binding */ CLIPVisionModelWithProjection), +/* harmony export */ "CamembertForMaskedLM": () => (/* binding */ CamembertForMaskedLM), +/* harmony export */ "CamembertForQuestionAnswering": () => (/* binding */ CamembertForQuestionAnswering), +/* harmony export */ "CamembertForSequenceClassification": () => (/* binding */ CamembertForSequenceClassification), +/* harmony export */ "CamembertForTokenClassification": () => (/* binding */ CamembertForTokenClassification), +/* harmony export */ "CamembertModel": () => (/* binding */ CamembertModel), +/* harmony export */ "CamembertPreTrainedModel": () => (/* binding */ CamembertPreTrainedModel), +/* harmony export */ "CausalLMOutput": () => (/* binding */ CausalLMOutput), +/* harmony export */ "CausalLMOutputWithPast": () => (/* binding */ CausalLMOutputWithPast), +/* harmony export */ "ChineseCLIPModel": () => (/* binding */ ChineseCLIPModel), +/* harmony export */ "ChineseCLIPPreTrainedModel": () => (/* binding */ ChineseCLIPPreTrainedModel), +/* harmony export */ "ClapAudioModelWithProjection": () => (/* binding */ ClapAudioModelWithProjection), +/* harmony export */ "ClapModel": () => (/* binding */ ClapModel), +/* harmony export */ "ClapPreTrainedModel": () => (/* binding */ ClapPreTrainedModel), +/* harmony export */ "ClapTextModelWithProjection": () => (/* binding */ ClapTextModelWithProjection), +/* harmony export */ "CodeGenForCausalLM": () => (/* binding */ CodeGenForCausalLM), +/* harmony export */ "CodeGenModel": () => (/* binding */ CodeGenModel), +/* harmony export */ "CodeGenPreTrainedModel": () => (/* binding */ CodeGenPreTrainedModel), +/* harmony export */ "ConvBertForMaskedLM": () => (/* binding */ ConvBertForMaskedLM), +/* harmony export */ "ConvBertForQuestionAnswering": () => (/* binding */ ConvBertForQuestionAnswering), +/* harmony export */ "ConvBertForSequenceClassification": () => (/* binding */ ConvBertForSequenceClassification), +/* harmony export */ "ConvBertForTokenClassification": () => (/* binding */ ConvBertForTokenClassification), +/* harmony export */ "ConvBertModel": () => (/* binding */ ConvBertModel), +/* harmony export */ "ConvBertPreTrainedModel": () => (/* binding */ ConvBertPreTrainedModel), +/* harmony export */ "ConvNextForImageClassification": () => (/* binding */ ConvNextForImageClassification), +/* harmony export */ "ConvNextModel": () => (/* binding */ ConvNextModel), +/* harmony export */ "ConvNextPreTrainedModel": () => (/* binding */ ConvNextPreTrainedModel), +/* harmony export */ "ConvNextV2ForImageClassification": () => (/* binding */ ConvNextV2ForImageClassification), +/* harmony export */ "ConvNextV2Model": () => (/* binding */ ConvNextV2Model), +/* harmony export */ "ConvNextV2PreTrainedModel": () => (/* binding */ ConvNextV2PreTrainedModel), +/* harmony export */ "DPTForDepthEstimation": () => (/* binding */ DPTForDepthEstimation), +/* harmony export */ "DPTModel": () => (/* binding */ DPTModel), +/* harmony export */ "DPTPreTrainedModel": () => (/* binding */ DPTPreTrainedModel), +/* harmony export */ "DebertaForMaskedLM": () => (/* binding */ DebertaForMaskedLM), +/* harmony export */ "DebertaForQuestionAnswering": () => (/* binding */ DebertaForQuestionAnswering), +/* harmony export */ "DebertaForSequenceClassification": () => (/* binding */ DebertaForSequenceClassification), +/* harmony export */ "DebertaForTokenClassification": () => (/* binding */ DebertaForTokenClassification), +/* harmony export */ "DebertaModel": () => (/* binding */ DebertaModel), +/* harmony export */ "DebertaPreTrainedModel": () => (/* binding */ DebertaPreTrainedModel), +/* harmony export */ "DebertaV2ForMaskedLM": () => (/* binding */ DebertaV2ForMaskedLM), +/* harmony export */ "DebertaV2ForQuestionAnswering": () => (/* binding */ DebertaV2ForQuestionAnswering), +/* harmony export */ "DebertaV2ForSequenceClassification": () => (/* binding */ DebertaV2ForSequenceClassification), +/* harmony export */ "DebertaV2ForTokenClassification": () => (/* binding */ DebertaV2ForTokenClassification), +/* harmony export */ "DebertaV2Model": () => (/* binding */ DebertaV2Model), +/* harmony export */ "DebertaV2PreTrainedModel": () => (/* binding */ DebertaV2PreTrainedModel), +/* harmony export */ "DeiTForImageClassification": () => (/* binding */ DeiTForImageClassification), +/* harmony export */ "DeiTModel": () => (/* binding */ DeiTModel), +/* harmony export */ "DeiTPreTrainedModel": () => (/* binding */ DeiTPreTrainedModel), +/* harmony export */ "DepthAnythingForDepthEstimation": () => (/* binding */ DepthAnythingForDepthEstimation), +/* harmony export */ "DepthAnythingPreTrainedModel": () => (/* binding */ DepthAnythingPreTrainedModel), +/* harmony export */ "DetrForObjectDetection": () => (/* binding */ DetrForObjectDetection), +/* harmony export */ "DetrForSegmentation": () => (/* binding */ DetrForSegmentation), +/* harmony export */ "DetrModel": () => (/* binding */ DetrModel), +/* harmony export */ "DetrObjectDetectionOutput": () => (/* binding */ DetrObjectDetectionOutput), +/* harmony export */ "DetrPreTrainedModel": () => (/* binding */ DetrPreTrainedModel), +/* harmony export */ "DetrSegmentationOutput": () => (/* binding */ DetrSegmentationOutput), +/* harmony export */ "Dinov2ForImageClassification": () => (/* binding */ Dinov2ForImageClassification), +/* harmony export */ "Dinov2Model": () => (/* binding */ Dinov2Model), +/* harmony export */ "Dinov2PreTrainedModel": () => (/* binding */ Dinov2PreTrainedModel), +/* harmony export */ "DistilBertForMaskedLM": () => (/* binding */ DistilBertForMaskedLM), +/* harmony export */ "DistilBertForQuestionAnswering": () => (/* binding */ DistilBertForQuestionAnswering), +/* harmony export */ "DistilBertForSequenceClassification": () => (/* binding */ DistilBertForSequenceClassification), +/* harmony export */ "DistilBertForTokenClassification": () => (/* binding */ DistilBertForTokenClassification), +/* harmony export */ "DistilBertModel": () => (/* binding */ DistilBertModel), +/* harmony export */ "DistilBertPreTrainedModel": () => (/* binding */ DistilBertPreTrainedModel), +/* harmony export */ "DonutSwinModel": () => (/* binding */ DonutSwinModel), +/* harmony export */ "DonutSwinPreTrainedModel": () => (/* binding */ DonutSwinPreTrainedModel), +/* harmony export */ "EfficientNetForImageClassification": () => (/* binding */ EfficientNetForImageClassification), +/* harmony export */ "EfficientNetModel": () => (/* binding */ EfficientNetModel), +/* harmony export */ "EfficientNetPreTrainedModel": () => (/* binding */ EfficientNetPreTrainedModel), +/* harmony export */ "ElectraForMaskedLM": () => (/* binding */ ElectraForMaskedLM), +/* harmony export */ "ElectraForQuestionAnswering": () => (/* binding */ ElectraForQuestionAnswering), +/* harmony export */ "ElectraForSequenceClassification": () => (/* binding */ ElectraForSequenceClassification), +/* harmony export */ "ElectraForTokenClassification": () => (/* binding */ ElectraForTokenClassification), +/* harmony export */ "ElectraModel": () => (/* binding */ ElectraModel), +/* harmony export */ "ElectraPreTrainedModel": () => (/* binding */ ElectraPreTrainedModel), +/* harmony export */ "EsmForMaskedLM": () => (/* binding */ EsmForMaskedLM), +/* harmony export */ "EsmForSequenceClassification": () => (/* binding */ EsmForSequenceClassification), +/* harmony export */ "EsmForTokenClassification": () => (/* binding */ EsmForTokenClassification), +/* harmony export */ "EsmModel": () => (/* binding */ EsmModel), +/* harmony export */ "EsmPreTrainedModel": () => (/* binding */ EsmPreTrainedModel), +/* harmony export */ "FalconForCausalLM": () => (/* binding */ FalconForCausalLM), +/* harmony export */ "FalconModel": () => (/* binding */ FalconModel), +/* harmony export */ "FalconPreTrainedModel": () => (/* binding */ FalconPreTrainedModel), +/* harmony export */ "GLPNForDepthEstimation": () => (/* binding */ GLPNForDepthEstimation), +/* harmony export */ "GLPNModel": () => (/* binding */ GLPNModel), +/* harmony export */ "GLPNPreTrainedModel": () => (/* binding */ GLPNPreTrainedModel), +/* harmony export */ "GPT2LMHeadModel": () => (/* binding */ GPT2LMHeadModel), +/* harmony export */ "GPT2Model": () => (/* binding */ GPT2Model), +/* harmony export */ "GPT2PreTrainedModel": () => (/* binding */ GPT2PreTrainedModel), +/* harmony export */ "GPTBigCodeForCausalLM": () => (/* binding */ GPTBigCodeForCausalLM), +/* harmony export */ "GPTBigCodeModel": () => (/* binding */ GPTBigCodeModel), +/* harmony export */ "GPTBigCodePreTrainedModel": () => (/* binding */ GPTBigCodePreTrainedModel), +/* harmony export */ "GPTJForCausalLM": () => (/* binding */ GPTJForCausalLM), +/* harmony export */ "GPTJModel": () => (/* binding */ GPTJModel), +/* harmony export */ "GPTJPreTrainedModel": () => (/* binding */ GPTJPreTrainedModel), +/* harmony export */ "GPTNeoForCausalLM": () => (/* binding */ GPTNeoForCausalLM), +/* harmony export */ "GPTNeoModel": () => (/* binding */ GPTNeoModel), +/* harmony export */ "GPTNeoPreTrainedModel": () => (/* binding */ GPTNeoPreTrainedModel), +/* harmony export */ "GPTNeoXForCausalLM": () => (/* binding */ GPTNeoXForCausalLM), +/* harmony export */ "GPTNeoXModel": () => (/* binding */ GPTNeoXModel), +/* harmony export */ "GPTNeoXPreTrainedModel": () => (/* binding */ GPTNeoXPreTrainedModel), +/* harmony export */ "HubertForCTC": () => (/* binding */ HubertForCTC), +/* harmony export */ "HubertForSequenceClassification": () => (/* binding */ HubertForSequenceClassification), +/* harmony export */ "HubertModel": () => (/* binding */ HubertModel), +/* harmony export */ "HubertPreTrainedModel": () => (/* binding */ HubertPreTrainedModel), +/* harmony export */ "ImageMattingOutput": () => (/* binding */ ImageMattingOutput), +/* harmony export */ "LlamaForCausalLM": () => (/* binding */ LlamaForCausalLM), +/* harmony export */ "LlamaModel": () => (/* binding */ LlamaModel), +/* harmony export */ "LlamaPreTrainedModel": () => (/* binding */ LlamaPreTrainedModel), +/* harmony export */ "LongT5ForConditionalGeneration": () => (/* binding */ LongT5ForConditionalGeneration), +/* harmony export */ "LongT5Model": () => (/* binding */ LongT5Model), +/* harmony export */ "LongT5PreTrainedModel": () => (/* binding */ LongT5PreTrainedModel), +/* harmony export */ "M2M100ForConditionalGeneration": () => (/* binding */ M2M100ForConditionalGeneration), +/* harmony export */ "M2M100Model": () => (/* binding */ M2M100Model), +/* harmony export */ "M2M100PreTrainedModel": () => (/* binding */ M2M100PreTrainedModel), +/* harmony export */ "MBartForCausalLM": () => (/* binding */ MBartForCausalLM), +/* harmony export */ "MBartForConditionalGeneration": () => (/* binding */ MBartForConditionalGeneration), +/* harmony export */ "MBartForSequenceClassification": () => (/* binding */ MBartForSequenceClassification), +/* harmony export */ "MBartModel": () => (/* binding */ MBartModel), +/* harmony export */ "MBartPreTrainedModel": () => (/* binding */ MBartPreTrainedModel), +/* harmony export */ "MPNetForMaskedLM": () => (/* binding */ MPNetForMaskedLM), +/* harmony export */ "MPNetForQuestionAnswering": () => (/* binding */ MPNetForQuestionAnswering), +/* harmony export */ "MPNetForSequenceClassification": () => (/* binding */ MPNetForSequenceClassification), +/* harmony export */ "MPNetForTokenClassification": () => (/* binding */ MPNetForTokenClassification), +/* harmony export */ "MPNetModel": () => (/* binding */ MPNetModel), +/* harmony export */ "MPNetPreTrainedModel": () => (/* binding */ MPNetPreTrainedModel), +/* harmony export */ "MT5ForConditionalGeneration": () => (/* binding */ MT5ForConditionalGeneration), +/* harmony export */ "MT5Model": () => (/* binding */ MT5Model), +/* harmony export */ "MT5PreTrainedModel": () => (/* binding */ MT5PreTrainedModel), +/* harmony export */ "MarianMTModel": () => (/* binding */ MarianMTModel), +/* harmony export */ "MarianModel": () => (/* binding */ MarianModel), +/* harmony export */ "MarianPreTrainedModel": () => (/* binding */ MarianPreTrainedModel), +/* harmony export */ "MaskedLMOutput": () => (/* binding */ MaskedLMOutput), +/* harmony export */ "MistralForCausalLM": () => (/* binding */ MistralForCausalLM), +/* harmony export */ "MistralModel": () => (/* binding */ MistralModel), +/* harmony export */ "MistralPreTrainedModel": () => (/* binding */ MistralPreTrainedModel), +/* harmony export */ "MobileBertForMaskedLM": () => (/* binding */ MobileBertForMaskedLM), +/* harmony export */ "MobileBertForQuestionAnswering": () => (/* binding */ MobileBertForQuestionAnswering), +/* harmony export */ "MobileBertForSequenceClassification": () => (/* binding */ MobileBertForSequenceClassification), +/* harmony export */ "MobileBertModel": () => (/* binding */ MobileBertModel), +/* harmony export */ "MobileBertPreTrainedModel": () => (/* binding */ MobileBertPreTrainedModel), +/* harmony export */ "MobileViTForImageClassification": () => (/* binding */ MobileViTForImageClassification), +/* harmony export */ "MobileViTModel": () => (/* binding */ MobileViTModel), +/* harmony export */ "MobileViTPreTrainedModel": () => (/* binding */ MobileViTPreTrainedModel), +/* harmony export */ "ModelOutput": () => (/* binding */ ModelOutput), +/* harmony export */ "MptForCausalLM": () => (/* binding */ MptForCausalLM), +/* harmony export */ "MptModel": () => (/* binding */ MptModel), +/* harmony export */ "MptPreTrainedModel": () => (/* binding */ MptPreTrainedModel), +/* harmony export */ "NomicBertModel": () => (/* binding */ NomicBertModel), +/* harmony export */ "NomicBertPreTrainedModel": () => (/* binding */ NomicBertPreTrainedModel), +/* harmony export */ "OPTForCausalLM": () => (/* binding */ OPTForCausalLM), +/* harmony export */ "OPTModel": () => (/* binding */ OPTModel), +/* harmony export */ "OPTPreTrainedModel": () => (/* binding */ OPTPreTrainedModel), +/* harmony export */ "OwlViTForObjectDetection": () => (/* binding */ OwlViTForObjectDetection), +/* harmony export */ "OwlViTModel": () => (/* binding */ OwlViTModel), +/* harmony export */ "OwlViTPreTrainedModel": () => (/* binding */ OwlViTPreTrainedModel), +/* harmony export */ "Owlv2ForObjectDetection": () => (/* binding */ Owlv2ForObjectDetection), +/* harmony export */ "Owlv2Model": () => (/* binding */ Owlv2Model), +/* harmony export */ "Owlv2PreTrainedModel": () => (/* binding */ Owlv2PreTrainedModel), +/* harmony export */ "PhiForCausalLM": () => (/* binding */ PhiForCausalLM), +/* harmony export */ "PhiModel": () => (/* binding */ PhiModel), +/* harmony export */ "PhiPreTrainedModel": () => (/* binding */ PhiPreTrainedModel), +/* harmony export */ "PreTrainedModel": () => (/* binding */ PreTrainedModel), +/* harmony export */ "PretrainedMixin": () => (/* binding */ PretrainedMixin), +/* harmony export */ "QuestionAnsweringModelOutput": () => (/* binding */ QuestionAnsweringModelOutput), +/* harmony export */ "Qwen2ForCausalLM": () => (/* binding */ Qwen2ForCausalLM), +/* harmony export */ "Qwen2Model": () => (/* binding */ Qwen2Model), +/* harmony export */ "Qwen2PreTrainedModel": () => (/* binding */ Qwen2PreTrainedModel), +/* harmony export */ "ResNetForImageClassification": () => (/* binding */ ResNetForImageClassification), +/* harmony export */ "ResNetModel": () => (/* binding */ ResNetModel), +/* harmony export */ "ResNetPreTrainedModel": () => (/* binding */ ResNetPreTrainedModel), +/* harmony export */ "RoFormerForMaskedLM": () => (/* binding */ RoFormerForMaskedLM), +/* harmony export */ "RoFormerForQuestionAnswering": () => (/* binding */ RoFormerForQuestionAnswering), +/* harmony export */ "RoFormerForSequenceClassification": () => (/* binding */ RoFormerForSequenceClassification), +/* harmony export */ "RoFormerForTokenClassification": () => (/* binding */ RoFormerForTokenClassification), +/* harmony export */ "RoFormerModel": () => (/* binding */ RoFormerModel), +/* harmony export */ "RoFormerPreTrainedModel": () => (/* binding */ RoFormerPreTrainedModel), +/* harmony export */ "RobertaForMaskedLM": () => (/* binding */ RobertaForMaskedLM), +/* harmony export */ "RobertaForQuestionAnswering": () => (/* binding */ RobertaForQuestionAnswering), +/* harmony export */ "RobertaForSequenceClassification": () => (/* binding */ RobertaForSequenceClassification), +/* harmony export */ "RobertaForTokenClassification": () => (/* binding */ RobertaForTokenClassification), +/* harmony export */ "RobertaModel": () => (/* binding */ RobertaModel), +/* harmony export */ "RobertaPreTrainedModel": () => (/* binding */ RobertaPreTrainedModel), +/* harmony export */ "SamImageSegmentationOutput": () => (/* binding */ SamImageSegmentationOutput), +/* harmony export */ "SamModel": () => (/* binding */ SamModel), +/* harmony export */ "SamPreTrainedModel": () => (/* binding */ SamPreTrainedModel), +/* harmony export */ "SegformerForImageClassification": () => (/* binding */ SegformerForImageClassification), +/* harmony export */ "SegformerForSemanticSegmentation": () => (/* binding */ SegformerForSemanticSegmentation), +/* harmony export */ "SegformerModel": () => (/* binding */ SegformerModel), +/* harmony export */ "SegformerPreTrainedModel": () => (/* binding */ SegformerPreTrainedModel), +/* harmony export */ "Seq2SeqLMOutput": () => (/* binding */ Seq2SeqLMOutput), +/* harmony export */ "SequenceClassifierOutput": () => (/* binding */ SequenceClassifierOutput), +/* harmony export */ "SiglipModel": () => (/* binding */ SiglipModel), +/* harmony export */ "SiglipPreTrainedModel": () => (/* binding */ SiglipPreTrainedModel), +/* harmony export */ "SiglipTextModel": () => (/* binding */ SiglipTextModel), +/* harmony export */ "SiglipVisionModel": () => (/* binding */ SiglipVisionModel), +/* harmony export */ "SpeechT5ForSpeechToText": () => (/* binding */ SpeechT5ForSpeechToText), +/* harmony export */ "SpeechT5ForTextToSpeech": () => (/* binding */ SpeechT5ForTextToSpeech), +/* harmony export */ "SpeechT5HifiGan": () => (/* binding */ SpeechT5HifiGan), +/* harmony export */ "SpeechT5Model": () => (/* binding */ SpeechT5Model), +/* harmony export */ "SpeechT5PreTrainedModel": () => (/* binding */ SpeechT5PreTrainedModel), +/* harmony export */ "SqueezeBertForMaskedLM": () => (/* binding */ SqueezeBertForMaskedLM), +/* harmony export */ "SqueezeBertForQuestionAnswering": () => (/* binding */ SqueezeBertForQuestionAnswering), +/* harmony export */ "SqueezeBertForSequenceClassification": () => (/* binding */ SqueezeBertForSequenceClassification), +/* harmony export */ "SqueezeBertModel": () => (/* binding */ SqueezeBertModel), +/* harmony export */ "SqueezeBertPreTrainedModel": () => (/* binding */ SqueezeBertPreTrainedModel), +/* harmony export */ "StableLmForCausalLM": () => (/* binding */ StableLmForCausalLM), +/* harmony export */ "StableLmModel": () => (/* binding */ StableLmModel), +/* harmony export */ "StableLmPreTrainedModel": () => (/* binding */ StableLmPreTrainedModel), +/* harmony export */ "Starcoder2ForCausalLM": () => (/* binding */ Starcoder2ForCausalLM), +/* harmony export */ "Starcoder2Model": () => (/* binding */ Starcoder2Model), +/* harmony export */ "Starcoder2PreTrainedModel": () => (/* binding */ Starcoder2PreTrainedModel), +/* harmony export */ "Swin2SRForImageSuperResolution": () => (/* binding */ Swin2SRForImageSuperResolution), +/* harmony export */ "Swin2SRModel": () => (/* binding */ Swin2SRModel), +/* harmony export */ "Swin2SRPreTrainedModel": () => (/* binding */ Swin2SRPreTrainedModel), +/* harmony export */ "SwinForImageClassification": () => (/* binding */ SwinForImageClassification), +/* harmony export */ "SwinModel": () => (/* binding */ SwinModel), +/* harmony export */ "SwinPreTrainedModel": () => (/* binding */ SwinPreTrainedModel), +/* harmony export */ "T5ForConditionalGeneration": () => (/* binding */ T5ForConditionalGeneration), +/* harmony export */ "T5Model": () => (/* binding */ T5Model), +/* harmony export */ "T5PreTrainedModel": () => (/* binding */ T5PreTrainedModel), +/* harmony export */ "TableTransformerForObjectDetection": () => (/* binding */ TableTransformerForObjectDetection), +/* harmony export */ "TableTransformerModel": () => (/* binding */ TableTransformerModel), +/* harmony export */ "TableTransformerObjectDetectionOutput": () => (/* binding */ TableTransformerObjectDetectionOutput), +/* harmony export */ "TableTransformerPreTrainedModel": () => (/* binding */ TableTransformerPreTrainedModel), +/* harmony export */ "TokenClassifierOutput": () => (/* binding */ TokenClassifierOutput), +/* harmony export */ "TrOCRForCausalLM": () => (/* binding */ TrOCRForCausalLM), +/* harmony export */ "TrOCRPreTrainedModel": () => (/* binding */ TrOCRPreTrainedModel), +/* harmony export */ "UniSpeechForCTC": () => (/* binding */ UniSpeechForCTC), +/* harmony export */ "UniSpeechForSequenceClassification": () => (/* binding */ UniSpeechForSequenceClassification), +/* harmony export */ "UniSpeechModel": () => (/* binding */ UniSpeechModel), +/* harmony export */ "UniSpeechPreTrainedModel": () => (/* binding */ UniSpeechPreTrainedModel), +/* harmony export */ "UniSpeechSatForAudioFrameClassification": () => (/* binding */ UniSpeechSatForAudioFrameClassification), +/* harmony export */ "UniSpeechSatForCTC": () => (/* binding */ UniSpeechSatForCTC), +/* harmony export */ "UniSpeechSatForSequenceClassification": () => (/* binding */ UniSpeechSatForSequenceClassification), +/* harmony export */ "UniSpeechSatModel": () => (/* binding */ UniSpeechSatModel), +/* harmony export */ "UniSpeechSatPreTrainedModel": () => (/* binding */ UniSpeechSatPreTrainedModel), +/* harmony export */ "ViTForImageClassification": () => (/* binding */ ViTForImageClassification), +/* harmony export */ "ViTModel": () => (/* binding */ ViTModel), +/* harmony export */ "ViTPreTrainedModel": () => (/* binding */ ViTPreTrainedModel), +/* harmony export */ "VisionEncoderDecoderModel": () => (/* binding */ VisionEncoderDecoderModel), +/* harmony export */ "VitMatteForImageMatting": () => (/* binding */ VitMatteForImageMatting), +/* harmony export */ "VitMattePreTrainedModel": () => (/* binding */ VitMattePreTrainedModel), +/* harmony export */ "VitsModel": () => (/* binding */ VitsModel), +/* harmony export */ "VitsModelOutput": () => (/* binding */ VitsModelOutput), +/* harmony export */ "VitsPreTrainedModel": () => (/* binding */ VitsPreTrainedModel), +/* harmony export */ "Wav2Vec2BertForCTC": () => (/* binding */ Wav2Vec2BertForCTC), +/* harmony export */ "Wav2Vec2BertForSequenceClassification": () => (/* binding */ Wav2Vec2BertForSequenceClassification), +/* harmony export */ "Wav2Vec2BertModel": () => (/* binding */ Wav2Vec2BertModel), +/* harmony export */ "Wav2Vec2BertPreTrainedModel": () => (/* binding */ Wav2Vec2BertPreTrainedModel), +/* harmony export */ "Wav2Vec2ForAudioFrameClassification": () => (/* binding */ Wav2Vec2ForAudioFrameClassification), +/* harmony export */ "Wav2Vec2ForCTC": () => (/* binding */ Wav2Vec2ForCTC), +/* harmony export */ "Wav2Vec2ForSequenceClassification": () => (/* binding */ Wav2Vec2ForSequenceClassification), +/* harmony export */ "Wav2Vec2Model": () => (/* binding */ Wav2Vec2Model), +/* harmony export */ "Wav2Vec2PreTrainedModel": () => (/* binding */ Wav2Vec2PreTrainedModel), +/* harmony export */ "WavLMForAudioFrameClassification": () => (/* binding */ WavLMForAudioFrameClassification), +/* harmony export */ "WavLMForCTC": () => (/* binding */ WavLMForCTC), +/* harmony export */ "WavLMForSequenceClassification": () => (/* binding */ WavLMForSequenceClassification), +/* harmony export */ "WavLMForXVector": () => (/* binding */ WavLMForXVector), +/* harmony export */ "WavLMModel": () => (/* binding */ WavLMModel), +/* harmony export */ "WavLMPreTrainedModel": () => (/* binding */ WavLMPreTrainedModel), +/* harmony export */ "WhisperForConditionalGeneration": () => (/* binding */ WhisperForConditionalGeneration), +/* harmony export */ "WhisperModel": () => (/* binding */ WhisperModel), +/* harmony export */ "WhisperPreTrainedModel": () => (/* binding */ WhisperPreTrainedModel), +/* harmony export */ "XLMForQuestionAnswering": () => (/* binding */ XLMForQuestionAnswering), +/* harmony export */ "XLMForSequenceClassification": () => (/* binding */ XLMForSequenceClassification), +/* harmony export */ "XLMForTokenClassification": () => (/* binding */ XLMForTokenClassification), +/* harmony export */ "XLMModel": () => (/* binding */ XLMModel), +/* harmony export */ "XLMPreTrainedModel": () => (/* binding */ XLMPreTrainedModel), +/* harmony export */ "XLMRobertaForMaskedLM": () => (/* binding */ XLMRobertaForMaskedLM), +/* harmony export */ "XLMRobertaForQuestionAnswering": () => (/* binding */ XLMRobertaForQuestionAnswering), +/* harmony export */ "XLMRobertaForSequenceClassification": () => (/* binding */ XLMRobertaForSequenceClassification), +/* harmony export */ "XLMRobertaForTokenClassification": () => (/* binding */ XLMRobertaForTokenClassification), +/* harmony export */ "XLMRobertaModel": () => (/* binding */ XLMRobertaModel), +/* harmony export */ "XLMRobertaPreTrainedModel": () => (/* binding */ XLMRobertaPreTrainedModel), +/* harmony export */ "XLMWithLMHeadModel": () => (/* binding */ XLMWithLMHeadModel), +/* harmony export */ "XVectorOutput": () => (/* binding */ XVectorOutput), +/* harmony export */ "YolosForObjectDetection": () => (/* binding */ YolosForObjectDetection), +/* harmony export */ "YolosModel": () => (/* binding */ YolosModel), +/* harmony export */ "YolosObjectDetectionOutput": () => (/* binding */ YolosObjectDetectionOutput), +/* harmony export */ "YolosPreTrainedModel": () => (/* binding */ YolosPreTrainedModel) +/* harmony export */ }); +/* harmony import */ var _configs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./configs.js */ "./src/configs.js"); +/* harmony import */ var _utils_core_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/core.js */ "./src/utils/core.js"); +/* harmony import */ var _utils_hub_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/hub.js */ "./src/utils/hub.js"); +/* harmony import */ var _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils/generation.js */ "./src/utils/generation.js"); +/* harmony import */ var _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _backends_onnx_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./backends/onnx.js */ "./src/backends/onnx.js"); +/* harmony import */ var _transformers_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./transformers.js */ "./src/transformers.js"); + +/** + * @file Definitions of all models available in Transformers.js. + * + * **Example:** Load and run an `AutoModel`. + * + * ```javascript + * import { AutoModel, AutoTokenizer } from '@xenova/transformers'; + * + * let tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased'); + * let model = await AutoModel.from_pretrained('Xenova/bert-base-uncased'); + * + * let inputs = await tokenizer('I love transformers!'); + * let { logits } = await model(inputs); + * // Tensor { + * // data: Float32Array(183132) [-7.117443084716797, -7.107812881469727, -7.092104911804199, ...] + * // dims: (3) [1, 6, 30522], + * // type: "float32", + * // size: 183132, + * // } + * ``` + * + * We also provide other `AutoModel`s (listed below), which you can use in the same way as the Python library. For example: + * + * **Example:** Load and run an `AutoModelForSeq2SeqLM`. + * ```javascript + * import { AutoModelForSeq2SeqLM, AutoTokenizer } from '@xenova/transformers'; + * + * let tokenizer = await AutoTokenizer.from_pretrained('Xenova/t5-small'); + * let model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small'); + * + * let { input_ids } = await tokenizer('translate English to German: I love transformers!'); + * let outputs = await model.generate(input_ids); + * let decoded = tokenizer.decode(outputs[0], { skip_special_tokens: true }); + * // 'Ich liebe Transformatoren!' + * ``` + * + * @module models + */ + + + + + + + + + + + + + +const { InferenceSession, Tensor: ONNXTensor, env } = _backends_onnx_js__WEBPACK_IMPORTED_MODULE_5__.ONNX; + +/** @typedef {import('onnxruntime-web').InferenceSession} InferenceSession */ + +////////////////////////////////////////////////// +// Model types: used internally +const MODEL_TYPES = { + EncoderOnly: 0, + EncoderDecoder: 1, + Seq2Seq: 2, + Vision2Seq: 3, + DecoderOnly: 4, + MaskGeneration: 5, +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Helper functions + +// NOTE: These will be populated fully later +const MODEL_TYPE_MAPPING = new Map(); +const MODEL_NAME_TO_CLASS_MAPPING = new Map(); +const MODEL_CLASS_TO_NAME_MAPPING = new Map(); + + +/** + * Constructs an InferenceSession using a model file located at the specified path. + * @param {string} pretrained_model_name_or_path The path to the directory containing the model file. + * @param {string} fileName The name of the model file. + * @param {import('./utils/hub.js').PretrainedOptions} options Additional options for loading the model. + * @returns {Promise} A Promise that resolves to an InferenceSession object. + * @private + */ +async function constructSession(pretrained_model_name_or_path, fileName, options) { + // TODO add option for user to force specify their desired execution provider + let modelFileName = `onnx/${fileName}${options.quantized ? '_quantized' : ''}.onnx`; + let buffer = await (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_2__.getModelFile)(pretrained_model_name_or_path, modelFileName, true, options); + + try { + return await InferenceSession.create(buffer, { + executionProviders: _backends_onnx_js__WEBPACK_IMPORTED_MODULE_5__.executionProviders, + }); + } catch (err) { + // If the execution provided was only wasm, throw the error + if (_backends_onnx_js__WEBPACK_IMPORTED_MODULE_5__.executionProviders.length === 1 && _backends_onnx_js__WEBPACK_IMPORTED_MODULE_5__.executionProviders[0] === 'wasm') { + throw err; + } + + console.warn(err); + console.warn( + 'Something went wrong during model construction (most likely a missing operation). ' + + 'Using `wasm` as a fallback. ' + ) + return await InferenceSession.create(buffer, { + executionProviders: ['wasm'] + }); + } +} + +/** + * Validate model inputs + * @param {InferenceSession} session The InferenceSession object that will be run. + * @param {Record} inputs The inputs to check. + * @returns {Record} The checked inputs. + * @throws {Error} If any inputs are missing. + * @private + */ +function validateInputs(session, inputs) { + /** + * NOTE: Create either a shallow or deep copy based on `onnx.wasm.proxy` + * @type {Record} + */ + const checkedInputs = Object.create(null); + const missingInputs = []; + for (const inputName of session.inputNames) { + const tensor = inputs[inputName]; + // Rare case where one of the model's input names corresponds to a built-in + // object name (e.g., toString), which would cause a simple (!tensor) check to fail, + // because it's not undefined but a function. + if (!(tensor instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor)) { + missingInputs.push(inputName); + continue; + } + // NOTE: When `env.wasm.proxy is true` the tensor is moved across the Worker + // boundary, transferring ownership to the worker and invalidating the tensor. + // So, in this case, we simply sacrifice a clone for it. + checkedInputs[inputName] = env.wasm.proxy ? tensor.clone() : tensor; + } + if (missingInputs.length > 0) { + throw new Error( + `An error occurred during model execution: "Missing the following inputs: ${missingInputs.join(', ')}.`); + } + + const numInputsProvided = Object.keys(inputs).length; + const numInputsNeeded = session.inputNames.length; + if (numInputsProvided > numInputsNeeded) { + // No missing inputs, but too many inputs were provided. + // Warn the user and ignore the extra inputs. + let ignored = Object.keys(inputs).filter(inputName => !session.inputNames.includes(inputName)); + console.warn(`WARNING: Too many inputs were provided (${numInputsProvided} > ${numInputsNeeded}). The following inputs will be ignored: "${ignored.join(', ')}".`); + } + + return checkedInputs; +} + +/** + * Executes an InferenceSession using the specified inputs. + * NOTE: `inputs` must contain at least the input names of the model. + * - If additional inputs are passed, they will be ignored. + * - If inputs are missing, an error will be thrown. + * + * @param {InferenceSession} session The InferenceSession object to run. + * @param {Object} inputs An object that maps input names to input tensors. + * @returns {Promise} A Promise that resolves to an object that maps output names to output tensors. + * @private + */ +async function sessionRun(session, inputs) { + const checkedInputs = validateInputs(session, inputs); + try { + // @ts-ignore + let output = await session.run(checkedInputs); + output = replaceTensors(output); + return output; + } catch (e) { + // This usually occurs when the inputs are of the wrong type. + console.error(`An error occurred during model execution: "${e}".`); + console.error('Inputs given to model:', checkedInputs); + throw e; + } +} + +/** + * Replaces ONNX Tensor objects with custom Tensor objects to support additional functions. + * @param {Object} obj The object to replace tensor objects in. + * @returns {Object} The object with tensor objects replaced by custom Tensor objects. + * @private + */ +function replaceTensors(obj) { + for (let prop in obj) { + if (obj[prop] instanceof ONNXTensor) { + obj[prop] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor(obj[prop]); + } else if (typeof obj[prop] === 'object') { + replaceTensors(obj[prop]); + } + } + return obj; +} + + +/** + * Converts an array or Tensor of integers to an int64 Tensor. + * @param {Array|Tensor} items The input integers to be converted. + * @returns {Tensor} The int64 Tensor with the converted values. + * @throws {Error} If the input array is empty or the input is a batched Tensor and not all sequences have the same length. + * @private + */ +function toI64Tensor(items) { + if (items instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor) { + return items; + } + // items is an array + if (items.length === 0) { + throw Error("items must be non-empty"); + } + + if (Array.isArray(items[0])) { + // batched + if (items.some(x => x.length !== items[0].length)) { + throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.") + } + + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('int64', + BigInt64Array.from(items.flat().map(x => BigInt(x))), + [items.length, items[0].length] + ); + } else { + //flat + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('int64', + BigInt64Array.from(items.map(x => BigInt(x))), + [1, items.length] + ); + } +} + +/** + * Prepares an attention mask for a sequence of tokens based on configuration options. + * @param {Object} self The calling object instance. + * @param {Tensor} tokens The input tokens. + * @returns {Tensor} The attention mask tensor. + * @private + */ +function prepareAttentionMask(self, tokens) { + + // Prepare attention mask + let pad_token_id = self.config.pad_token_id ?? null; + let eos_token_id = self.config.eos_token_id ?? null; + if ((0,_utils_core_js__WEBPACK_IMPORTED_MODULE_1__.isIntegralNumber)(eos_token_id)) { + eos_token_id = [eos_token_id]; + } + + let is_pad_token_in_inputs = tokens.indexOf(pad_token_id) !== -1; + let is_pad_token_not_equal_to_eos_token_id = (eos_token_id === null) || !eos_token_id.includes(pad_token_id) + + if (is_pad_token_in_inputs && is_pad_token_not_equal_to_eos_token_id) { + let data = BigInt64Array.from( + // Note: != so that int matches bigint + // @ts-ignore + tokens.data.map(x => x != pad_token_id) + ) + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('int64', data, tokens.dims) + } else { + return (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.ones_like)(tokens); + } +} + +/** + * Add position IDs to the feeds object. + * @param {Object} session The inference session. + * @param {Object} feeds The input to the model. + * @param {boolean} use_cache_branch Whether to use the cache branch of the model. + * @returns {void} + * @private + */ +function preparePositionIds(session, feeds, use_cache_branch) { + if (!session.inputNames.includes('position_ids')) return; + + const data = new BigInt64Array(feeds.attention_mask.data.length); + + // Compute cumulative sum of the attention mask along the sequence length dimension + for (let i = 0; i < feeds.attention_mask.dims[0]; ++i) { + let start = i * feeds.attention_mask.dims[1]; + let sum = BigInt(0); + for (let j = 0; j < feeds.attention_mask.dims[1]; ++j) { + const index = start + j; + if (feeds.attention_mask.data[index] === 0n) { + data[index] = BigInt(1); + } else { // === 1n + data[index] = sum; + sum += feeds.attention_mask.data[index]; + } + } + } + + feeds.position_ids = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('int64', data, feeds.attention_mask.dims); + + if (use_cache_branch) { + feeds.position_ids = feeds.position_ids.slice(null, -1).unsqueeze_(-1); + } +} + +/** + * Creates a boolean tensor with a single value. + * @param {boolean} value The value of the tensor. + * @returns {Tensor} The boolean tensor. + * @private + */ +function boolTensor(value) { + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('bool', [value], [1]); +} + +// JS doesn't support mixins, so we define some reused functions here, and allow "this" to be passed in +/** + * Perform forward pass on the seq2seq model (both encoder and decoder). + * @param {Object} self The seq2seq model object. + * @param {Object} model_inputs The input object for the model containing encoder and decoder inputs. + * @returns {Promise} Promise that resolves with the output of the seq2seq model. + * @private + */ +async function seq2seqForward(self, model_inputs) { + + let { encoder_outputs, past_key_values } = model_inputs; + + if (!encoder_outputs) { + // Encoder outputs are not given, so we must compute them. + encoder_outputs = (await encoderForward(self, model_inputs)).last_hidden_state; + } + let decoderFeeds = { + input_ids: model_inputs.decoder_input_ids, + encoder_hidden_states: encoder_outputs, + }; + const use_cache_branch = !!past_key_values; + + if (self.decoder_merged_session.inputNames.includes('use_cache_branch')) { + decoderFeeds.use_cache_branch = boolTensor(use_cache_branch); + } + + if (self.decoder_merged_session.inputNames.includes('encoder_attention_mask')) { + decoderFeeds.encoder_attention_mask = model_inputs.attention_mask + } + + preparePositionIds(self.decoder_merged_session, decoderFeeds, use_cache_branch); + self.addPastKeyValues(decoderFeeds, past_key_values); + + const decoderResults = await sessionRun(self.decoder_merged_session, decoderFeeds); + let logits = decoderResults.logits; + past_key_values = self.getPastKeyValues(decoderResults, past_key_values); + + // Get cross attention and/or decoder attentions if they are present + const attns = self.getAttentions(decoderResults); + + return new Seq2SeqLMOutput({ logits, past_key_values, encoder_outputs, ...attns }); +} + +/** + * Start the beam search process for the seq2seq model. + * @param {PreTrainedModel} self The seq2seq model object. + * @param {Tensor} inputTokenIds Array of input token ids for each input sequence. + * @param {Object} generation_config The generation config. + * @param {number} numOutputTokens The maximum number of output tokens for the model. + * @returns {Object[]} Array of beam search objects. + * @private + */ +function seq2seqStartBeams(self, inputTokenIds, generation_config, numOutputTokens) { + let beams = []; + let beamId = 0; + + // @ts-ignore + const requires_attention_mask = self.requires_attention_mask ?? true; + + // decoder_input_ids == output_token_ids + let decoder_input_ids = + generation_config.decoder_input_ids + ?? generation_config.decoder_start_token_id + ?? generation_config.bos_token_id + ?? generation_config.eos_token_id; + + // Support input as tensor or list + // TODO support batched decoder_input_ids + if (decoder_input_ids instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor) { + decoder_input_ids = decoder_input_ids.tolist().flat(); + } else if (!Array.isArray(decoder_input_ids)) { + decoder_input_ids = [decoder_input_ids]; + } + + for (let tokens of inputTokenIds) { + // TODO: Improve + // Currently, just add back batch dimension. + // In future, allow for true parallel execution + tokens.dims = [1, ...tokens.dims] + + // Create beam + let start = { + inputs: tokens, + encoder_outputs: null, + prev_model_outputs: null, + + output_token_ids: decoder_input_ids, + done: false, + score: 0, + id: beamId++ // assign unique id to beams + } + + if (requires_attention_mask) { + start.attention_mask = prepareAttentionMask(self, tokens); + } + + beams.push(start); + } + + return beams; +} + +/** + * Run beam search on the seq2seq model for a single beam. + * @param {PreTrainedModel} self The seq2seq model object. + * @param {Object} beam The beam search object for which to run the model. + * @param {Object} options options + * @param {string} [options.input_name='input_ids'] The name of the input tensor for the encoder. + * @returns {Promise} Promise that resolves with the output of the seq2seq model for the given beam. + * @private + */ +async function seq2seqRunBeam(self, beam) { + const input_name = self.main_input_name; + + let decoder_input_ids = beam.output_token_ids; + if (beam.prev_model_outputs) { + // After the first step, `prev_model_outputs` won't be null. + // So, we cut decoder_input_ids if past is used + decoder_input_ids = decoder_input_ids.slice(-1); + } + + // 1. Prepare + let model_inputs = { + [input_name]: beam.inputs, + decoder_input_ids: toI64Tensor(decoder_input_ids), + encoder_outputs: beam.encoder_outputs, + past_key_values: beam.prev_model_outputs?.past_key_values, + } + if (beam.attention_mask) { + model_inputs.attention_mask = beam.attention_mask + } + + // 2. Run + let output = await self.forward(model_inputs); + + // 3. Update + beam.prev_model_outputs = output; + beam.encoder_outputs = output.encoder_outputs; + + return output; +} + +/** + * Update a beam with a new token ID. + * @param {Object} beam The beam to update. + * @param {number} newTokenId The new token ID to add to the beam's output. + * @private + */ +function seq2seqUpdatebeam(beam, newTokenId) { + beam.output_token_ids = [...beam.output_token_ids, newTokenId]; +} + +/** + * Forward pass of an encoder model. + * @param {Object} self The encoder model. + * @param {Object} model_inputs The input data to be used for the forward pass. + * @returns {Promise} Promise that resolves with an object containing the model's outputs. + * @private + */ +async function encoderForward(self, model_inputs) { + const encoderFeeds = Object.create(null); + for (const key of self.session.inputNames) { + encoderFeeds[key] = model_inputs[key]; + } + if (self.session.inputNames.includes('token_type_ids') && !encoderFeeds.token_type_ids) { + // Assign default `token_type_ids` (all zeroes) to the `encoderFeeds` if the model expects it, + // but they weren't created by the tokenizer. + encoderFeeds.token_type_ids = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor( + 'int64', + new BigInt64Array(encoderFeeds.input_ids.data.length), + encoderFeeds.input_ids.dims + ) + } + return await sessionRun(self.session, encoderFeeds); +} + + +/** + * Forward pass of a decoder model. + * @param {Object} self The decoder model. + * @param {Object} model_inputs The input data to be used for the forward pass. + * @returns {Promise} Promise that resolves with an object containing the logits and past key values. + * @private + */ +async function decoderForward(self, model_inputs) { + let { input_ids, past_key_values, attention_mask } = model_inputs; + let decoderFeeds = { + input_ids: input_ids, + attention_mask: attention_mask ?? prepareAttentionMask(self, input_ids), + } + const use_cache_branch = !!past_key_values; + + if (self.session.inputNames.includes('use_cache_branch')) { + decoderFeeds.use_cache_branch = boolTensor(use_cache_branch); + } + + preparePositionIds(self.session, decoderFeeds, use_cache_branch); + + self.addPastKeyValues(decoderFeeds, past_key_values); + + let decoderResults = await sessionRun(self.session, decoderFeeds); + + let logits = decoderResults.logits; + + past_key_values = self.getPastKeyValues(decoderResults, past_key_values); + return { logits, past_key_values }; +} + +/** + * Starts the generation of text by initializing the beams for the given input token IDs. + * @param {Object} self The text generation model object. + * @param {Tensor} inputTokenIds An tensor of input token IDs to generate text from. + * @param {Object} generation_config The generation config. + * @param {number} numOutputTokens The maximum number of tokens to generate for each beam. + * @param {Tensor} [inputs_attention_mask] The attention mask tensor for the input token IDs. + * @returns {Object[]} An array of beams initialized with the given inputs and parameters. + * @private + */ +function decoderStartBeams(self, inputTokenIds, generation_config, numOutputTokens, inputs_attention_mask) { + let beams = []; + + let beamId = 0; + for (let tokens of inputTokenIds) { + let output_token_ids = tokens.tolist().map(Number); + + // TODO: Improve + // Currently, just add back batch dimension. + // In future, allow for true parallel execution + tokens.dims = [1, ...tokens.dims] + + let attn_mask; + if (inputs_attention_mask) { + attn_mask = inputs_attention_mask[beamId]; + attn_mask.dims = [1, ...attn_mask.dims] + + } else { + attn_mask = prepareAttentionMask(self, tokens) + } + + let start = { + input: tokens, + model_input_ids: tokens, + attention_mask: attn_mask, + prev_model_outputs: null, + + output_token_ids: output_token_ids, + num_output_tokens: numOutputTokens, + + done: false, + score: 0, + id: beamId++ // assign unique id to beams + } + + beams.push(start); + } + return beams; +} + +/** + * Runs a single step of the text generation process for a given beam. + * + * @param {Object} self The decoder object. + * @param {Object} beam The beam to run. + * @param {Tensor} beam.input The input tensor. + * @param {Tensor} beam.model_input_ids The input ids to the model. + * @param {Tensor} beam.attention_mask The attention mask. + * @param {Object} beam.prev_model_outputs The past key values. + * @param {number[]} beam.output_token_ids The output token ids. + * @returns {Promise} The output of the generation step. + * @private + */ +async function decoderRunBeam(self, beam) { + let attnMaskData = new BigInt64Array(beam.output_token_ids.length).fill(1n) + + // 1. Prepare + let model_inputs = { + input_ids: beam.model_input_ids, + attention_mask: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor( + 'int64', + attnMaskData, + [1, attnMaskData.length] + ), + past_key_values: beam.prev_model_outputs?.past_key_values, + } + + // 2. Run + let output = await self.forward(model_inputs); + + // 3. Update + beam.prev_model_outputs = output; + + return output; +} + +/** + * Update a beam with a new token ID. + * @param {Object} beam The beam to update. + * @param {number} newTokenId The new token ID to add to the beam's output. + * @private + */ +function decoderUpdatebeam(beam, newTokenId) { + beam.output_token_ids = [...beam.output_token_ids, newTokenId]; + beam.model_input_ids = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('int64', [BigInt(newTokenId)], [1, 1]); +} + +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +/** + * A base class for pre-trained models that provides the model configuration and an ONNX session. + */ +class PreTrainedModel extends _utils_core_js__WEBPACK_IMPORTED_MODULE_1__.Callable { + main_input_name = 'input_ids'; + + /** + * Creates a new instance of the `PreTrainedModel` class. + * @param {Object} config The model configuration. + * @param {any} session session for the model. + */ + constructor(config, session) { + super(); + + this.config = config; + this.session = session; + + const modelName = MODEL_CLASS_TO_NAME_MAPPING.get(this.constructor); + const modelType = MODEL_TYPE_MAPPING.get(modelName); + + this.can_generate = false; + this._runBeam = null; + this._getStartBeams = null; + this._updateBeam = null; + this._forward = null; + if (modelType === MODEL_TYPES.DecoderOnly) { + this.can_generate = true; + + this._runBeam = decoderRunBeam; + this._getStartBeams = decoderStartBeams; + this._updateBeam = decoderUpdatebeam; + this._forward = decoderForward; + + } else if (modelType === MODEL_TYPES.Seq2Seq || modelType === MODEL_TYPES.Vision2Seq) { + this.can_generate = true; + + this._runBeam = seq2seqRunBeam; + this._getStartBeams = seq2seqStartBeams; + this._updateBeam = seq2seqUpdatebeam; + this._forward = seq2seqForward; + + } else if (modelType === MODEL_TYPES.EncoderDecoder) { + this._forward = encoderForward; + + } else { // should be MODEL_TYPES.EncoderOnly + this._forward = encoderForward; + } + } + + /** + * Disposes of all the ONNX sessions that were created during inference. + * @returns {Promise} An array of promises, one for each ONNX session that is being disposed. + * @todo Use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry + */ + async dispose() { + const promises = []; + for (let key of Object.keys(this)) { + const item = this[key]; + // @ts-ignore + if (item instanceof InferenceSession) { + promises.push(item.handler.dispose()) + } + } + return await Promise.all(promises); + } + + /** + * Instantiate one of the model classes of the library from a pretrained model. + * + * The model class to instantiate is selected based on the `model_type` property of the config object + * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) + * + * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: + * - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co. + * Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a + * user or organization name, like `dbmdz/bert-base-german-cased`. + * - A path to a *directory* containing model weights, e.g., `./my_model_directory/`. + * @param {import('./utils/hub.js').PretrainedOptions} options Additional options for loading the model. + * + * @returns {Promise} A new instance of the `PreTrainedModel` class. + */ + static async from_pretrained(pretrained_model_name_or_path, { + quantized = true, + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + model_file_name = null, + } = {}) { + + let options = { + quantized, + progress_callback, + config, + cache_dir, + local_files_only, + revision, + model_file_name, + } + + const modelName = MODEL_CLASS_TO_NAME_MAPPING.get(this); + const modelType = MODEL_TYPE_MAPPING.get(modelName); + + let info; + if (modelType === MODEL_TYPES.DecoderOnly) { + info = await Promise.all([ + _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options), + constructSession(pretrained_model_name_or_path, options.model_file_name ?? 'decoder_model_merged', options), + (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_2__.getModelJSON)(pretrained_model_name_or_path, 'generation_config.json', false, options), + ]); + + } else if (modelType === MODEL_TYPES.Seq2Seq || modelType === MODEL_TYPES.Vision2Seq) { + info = await Promise.all([ + _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options), + constructSession(pretrained_model_name_or_path, 'encoder_model', options), + constructSession(pretrained_model_name_or_path, 'decoder_model_merged', options), + (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_2__.getModelJSON)(pretrained_model_name_or_path, 'generation_config.json', false, options), + ]); + + } else if (modelType === MODEL_TYPES.MaskGeneration) { + info = await Promise.all([ + _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options), + constructSession(pretrained_model_name_or_path, 'vision_encoder', options), + constructSession(pretrained_model_name_or_path, 'prompt_encoder_mask_decoder', options), + ]); + + } else if (modelType === MODEL_TYPES.EncoderDecoder) { + info = await Promise.all([ + _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options), + constructSession(pretrained_model_name_or_path, 'encoder_model', options), + constructSession(pretrained_model_name_or_path, 'decoder_model_merged', options), + ]); + + } else { // should be MODEL_TYPES.EncoderOnly + if (modelType !== MODEL_TYPES.EncoderOnly) { + console.warn(`Model type for '${modelName ?? config?.model_type}' not found, assuming encoder-only architecture. Please report this at https://github.com/xenova/transformers.js/issues/new/choose.`) + } + info = await Promise.all([ + _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options), + constructSession(pretrained_model_name_or_path, options.model_file_name ?? 'model', options) + ]); + } + + // @ts-ignore + return new this(...info); + } + + /** + * Runs the model with the provided inputs + * @param {Object} model_inputs Object containing input tensors + * @returns {Promise} Object containing output tensors + */ + async _call(model_inputs) { + return await this.forward(model_inputs); + } + + /** + * Forward method for a pretrained model. If not overridden by a subclass, the correct forward method + * will be chosen based on the model type. + * @param {Object} model_inputs The input data to the model in the format specified in the ONNX model. + * @returns {Promise} The output data from the model in the format specified in the ONNX model. + * @throws {Error} This method must be implemented in subclasses. + */ + async forward(model_inputs) { + return await this._forward(this, model_inputs); + } + + /** + * @param {import('./utils/generation.js').GenerationConfigType} generation_config + * @param {number} input_ids_seq_length The starting sequence length for the input ids. + * @returns {LogitsProcessorList} + * @private + */ + _get_logits_processor( + generation_config, + input_ids_seq_length, + // encoder_input_ids, TODO + // prefix_allowed_tokens_fn, TODO + logits_processor = null + ) { + const processors = new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.LogitsProcessorList(); + + // if (generation_config.diversity_penalty !== null && generation_config.diversity_penalty > 0.0) { + // processors.push(new HammingDiversityLogitsProcessor( + // generation_config.diversity_penalty, + // generation_config.num_beams, + // generation_config.num_beam_groups + // )); + // } + + // if (generation_config.encoder_repetition_penalty !== null && generation_config.encoder_repetition_penalty !== 1.0) { + // processors.push(new EncoderRepetitionPenaltyLogitsProcessor( + // generation_config.encoder_repetition_penalty, + // encoder_input_ids + // )); + // } + + if (generation_config.repetition_penalty !== null && generation_config.repetition_penalty !== 1.0) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.RepetitionPenaltyLogitsProcessor(generation_config.repetition_penalty)); + } + + if (generation_config.no_repeat_ngram_size !== null && generation_config.no_repeat_ngram_size > 0) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.NoRepeatNGramLogitsProcessor(generation_config.no_repeat_ngram_size)); + } + + // if (generation_config.encoder_no_repeat_ngram_size !== null && generation_config.encoder_no_repeat_ngram_size > 0) { + // if (this.config.is_encoder_decoder) { + // processors.push(new EncoderNoRepeatNGramLogitsProcessor( + // generation_config.encoder_no_repeat_ngram_size, + // encoder_input_ids + // )); + // } else { + // throw new Error("It's impossible to use `encoder_no_repeat_ngram_size` with decoder-only architecture"); + // } + // } + + if (generation_config.bad_words_ids !== null) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.NoBadWordsLogitsProcessor(generation_config.bad_words_ids, generation_config.eos_token_id)); + } + + if (generation_config.min_length !== null && generation_config.eos_token_id !== null && generation_config.min_length > 0) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.MinLengthLogitsProcessor(generation_config.min_length, generation_config.eos_token_id)); + } + + if (generation_config.min_new_tokens !== null && generation_config.eos_token_id !== null && generation_config.min_new_tokens > 0) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.MinNewTokensLengthLogitsProcessor( + input_ids_seq_length, + generation_config.min_new_tokens, + generation_config.eos_token_id + )); + } + + // if (prefix_allowed_tokens_fn !== null) { + // processors.push(new PrefixConstrainedLogitsProcessor( + // prefix_allowed_tokens_fn, + // generation_config.num_beams / generation_config.num_beam_groups + // )); + // } + + + if (generation_config.forced_bos_token_id !== null) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.ForcedBOSTokenLogitsProcessor(generation_config.forced_bos_token_id)); + } + + if (generation_config.forced_eos_token_id !== null) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.ForcedEOSTokenLogitsProcessor( + generation_config.max_length, + generation_config.forced_eos_token_id + )); + } + + // if (generation_config.remove_invalid_values === true) { + // processors.push(new InfNanRemoveLogitsProcessor()); + // } + + // if (generation_config.exponential_decay_length_penalty !== null) { + // processors.push(new ExponentialDecayLengthPenalty( + // generation_config.exponential_decay_length_penalty, + // generation_config.eos_token_id, + // input_ids_seq_length + // )); + // } + + // if (generation_config.suppress_tokens !== null) { + // processors.push(new SuppressTokensLogitsProcessor(generation_config.suppress_tokens)); + // } + + if (generation_config.begin_suppress_tokens !== null) { + let begin_index = (input_ids_seq_length > 1 || generation_config.forced_bos_token_id === null) + ? input_ids_seq_length + : input_ids_seq_length + 1; + + if (generation_config.forced_decoder_ids !== null) { + // generation starts after the last token that is forced + begin_index += generation_config.forced_decoder_ids[generation_config.forced_decoder_ids.length - 1][0]; + } + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.SuppressTokensAtBeginLogitsProcessor(generation_config.begin_suppress_tokens, begin_index)); + } + + if (generation_config.forced_decoder_ids !== null) { + processors.push(new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.ForceTokensLogitsProcessor(generation_config.forced_decoder_ids)); + } + + if (logits_processor !== null) { + processors.extend(logits_processor) + } + + // `LogitNormalization` should always be the last logit processor, when present + // if (generation_config.renormalize_logits === true) { + // processors.push(new LogitNormalization()); + // } + + return processors; + } + + /** + * This function merges multiple generation configs together to form a final generation config to be used by the model for text generation. + * It first creates an empty `GenerationConfig` object, then it applies the model's own `generation_config` property to it. Finally, if a `generation_config` object was passed in the arguments, it overwrites the corresponding properties in the final config with those of the passed config object. + * @param {import('./utils/generation.js').GenerationConfigType} generation_config A `GenerationConfig` object containing generation parameters. + * @returns {import('./utils/generation.js').GenerationConfigType} The final generation config object to be used by the model for text generation. + */ + _get_generation_config(generation_config) { + // Create empty generation config (contains defaults) + // We pass `this.config` so that if `eos_token_id` or `bos_token_id` exist in the model's config, we will use them + let gen_config = new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.GenerationConfig(this.config); + + // Apply model's generation config, if it exists + if ('generation_config' in this) { + Object.assign(gen_config, this.generation_config); + } + + // Finally, use any generation config specified by the user + // when calling `generate` + if (generation_config !== null) { + Object.assign(gen_config, generation_config); + } + return gen_config; + } + + /** + * @typedef {import('./utils/maths.js').TypedArray} TypedArray + */ + + /** + * @typedef {{ sequences: Tensor, decoder_attentions: Tensor, cross_attentions: Tensor }} EncoderDecoderOutput + * @typedef {Object} DecoderOutput + * + * Generates text based on the given inputs and generation configuration using the model. + * @param {Tensor|Array|TypedArray} inputs An array of input token IDs. + * @param {Object|GenerationConfig|null} generation_config The generation configuration to use. If null, default configuration will be used. + * @param {Object|null} logits_processor An optional logits processor to use. If null, a new LogitsProcessorList instance will be created. + * @param {Object} options options + * @param {Object} [options.inputs_attention_mask=null] An optional attention mask for the inputs. + * @returns {Promise} An array of generated output sequences, where each sequence is an array of token IDs. + * @throws {Error} Throws an error if the inputs array is empty. + */ + async generate( + inputs, + generation_config = null, + logits_processor = null, + { + inputs_attention_mask = null + } = {}, + ) { + if (!this.can_generate) { + const modelName = MODEL_CLASS_TO_NAME_MAPPING.get(this.constructor); + let errorMessage = `The current model class (${modelName}) is not compatible with \`.generate()\`, as it doesn't have a language model head.` + + const modelType = this.config.model_type; + const possibleInfo = + MODEL_WITH_LM_HEAD_MAPPING_NAMES.get(modelType) + ?? MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES.get(modelType) + ?? MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES.get(modelType) + // ?? MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES.get(modelType) // TODO + ?? MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES.get(modelType); + + if (possibleInfo) { + // TODO: support multiple possible classes + errorMessage += ` Please use the following class instead: '${possibleInfo[0]}'`; + } + throw Error(errorMessage); + } + + if (!(inputs instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor) && !(0,_utils_core_js__WEBPACK_IMPORTED_MODULE_1__.isTypedArray)(inputs) && !Array.isArray(inputs)) { + throw Error(`\`inputs\` must be a Tensor, TypedArray, or Array, but is "${inputs.constructor.name}".`); + } + + let input_ids_seq_length; + + // Prepare `input_ids` which will be used for auto-regressive generation + // TODO: Update to align with HF transformers' implementation + if (this.config.is_encoder_decoder) { + // Generating from the encoder outputs + input_ids_seq_length = 0; + + } else { + input_ids_seq_length = inputs instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor ? inputs.dims.at(-1) : inputs.length; + + // decoder-only + if (input_ids_seq_length === 0) { + throw Error("Must supply a non-empty array of input token ids.") + } + } + + // Update generation config with defaults + generation_config = this._get_generation_config(generation_config); + + logits_processor = logits_processor ?? new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.LogitsProcessorList() + + // Update logits processor + logits_processor = this._get_logits_processor( + generation_config, + input_ids_seq_length, + logits_processor + ) + + /** @type {number[]} */ + let eos_token_ids = generation_config.eos_token_id; + if (eos_token_ids !== null && !Array.isArray(eos_token_ids)) { + eos_token_ids = [eos_token_ids]; + } + + // TODO implement early_stopping + // https://huggingface.co/blog/how-to-generate + + let numOutputTokens = 1; + const maxOutputTokens = numOutputTokens + (generation_config.max_new_tokens ?? Infinity); + + // Only use max length if max_new_tokens is not provided + const useMaxLength = Number.isInteger(generation_config.max_length) && (generation_config.max_new_tokens ?? null) === null; + let sampler = _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.Sampler.getSampler(generation_config); + + // @ts-ignore + let beams = this.getStartBeams(inputs, generation_config, numOutputTokens, inputs_attention_mask); + + while (beams.some(x => !x.done) && numOutputTokens < maxOutputTokens) { + let newest_beams = []; + for (let beam of beams) { + if (beam.done) { + // Add this beam back into the pool + newest_beams.push(beam); + continue + } + if (useMaxLength && beam.output_token_ids.length >= generation_config.max_length) { + // Set this beam to done and add it back into the pool + beam.done = true; + newest_beams.push(beam); + continue + } + + // @ts-ignore + let output = await this.runBeam(beam); + + // add attentions/scores to beam only if user requested + if (generation_config.output_attentions) { + this.addAttentionsToBeam(beam, output); + } + if (generation_config.output_scores) { + // TODO add + } + + // Logits are of the form [batch_size, out_seq_length, vocab_size] + // In most cases, this will be [batch_size, 1, vocab_size] + // So, we select the last token's logits: + // (equivalent to `logits = outputs.logits[:, -1, :]`) + let logits = output.logits.slice(null, -1, null); + + // Apply logits processor + logits_processor(beam.output_token_ids, logits); + + let sampledTokens = sampler(logits); + for (let [newTokenId, logProb] of sampledTokens) { + // use previous beam as a starting point + let newBeam = { ...beam }; + + // update new beam + // @ts-ignore + this.updateBeam(newBeam, newTokenId); + + newBeam.score += logProb; + + if (eos_token_ids && eos_token_ids.includes(newTokenId)) { + newBeam.done = true; + } + + newest_beams.push(newBeam); + } + } + ++numOutputTokens; + + // Next, we get the best beams, per ID + newest_beams = this.groupBeams(newest_beams).map( + group => group + .sort((a, b) => b.score - a.score) // sort by score + .slice(0, generation_config.num_beams) // remove outside beam width + ); + + // Flatten beams + beams = newest_beams.flat(); + + // Run callback + if (generation_config.callback_function) { + generation_config.callback_function(beams); + } + } + + // TODO: Ensure that we can return non-batched outputs + + const groupedBeams = this.groupBeams(beams); + + const getFlattened = (key) => groupedBeams.map( + batch => { + if (generation_config.num_return_sequences > 1) { + return batch.slice(0, generation_config.num_return_sequences).map(x => x[key]); + } else { + return [batch[0][key]]; + } + } + ).flat(); // Flatten across batches (depth=1) + + const sequences = getFlattened('output_token_ids'); // [1, seqLength] + + if (generation_config.return_dict_in_generate) { + // NOTE: `decoder_attentions` and `cross_attentions` should be: + // list (one element for each generated token) + // of list (one element for each layer of the decoder) + // of torch.FloatTensor of shape (batch_size, num_heads, generated_length, sequence_length) + // However, since we are only generating one batch at a time, they are of the form: + // list (batches) + // of list (one element for each generated token) + // of list (one element for each layer of the decoder) + // of torch.FloatTensor of shape (1, num_heads, generated_length, sequence_length) + // + // TODO: In future (when true parallelism, we should be able to return the correct shape) + + const decoder_attentions = getFlattened('decoder_attentions'); + const cross_attentions = getFlattened('cross_attentions'); + + return { + sequences, + + decoder_attentions, + cross_attentions, + } + } else { + return sequences; + } + } + + /** + * Helper function to add attentions to beam + * @param {Object} beam + * @param {Object} output + * @private + */ + addAttentionsToBeam(beam, output) { + if (this.config.is_encoder_decoder) { + if (!output.cross_attentions || output.cross_attentions.length === 0) { + throw Error( + "`output_attentions` is true, but the model did not produce cross-attentions. " + + "This is most likely because the model was not exported with `output_attentions=True`." + ) + } + if (!beam.cross_attentions) { + beam.cross_attentions = []; + } + beam.cross_attentions.push(output.cross_attentions); + } + + if (!output.decoder_attentions || output.decoder_attentions.length === 0) { + throw Error( + "`output_attentions` is true, but the model did not produce decoder-attentions. " + + "This is most likely because the model was not exported with `output_attentions=True`." + ) + } + if (!beam.decoder_attentions) { + beam.decoder_attentions = []; + } + beam.decoder_attentions.push(output.decoder_attentions); + } + + /** + * Groups an array of beam objects by their ids. + * + * @param {Array} beams The array of beam objects to group. + * @returns {Array} An array of arrays, where each inner array contains beam objects with the same id. + */ + groupBeams(beams) { + // Group beams by their ids + const groups = Object.create(null); + for (const obj of beams) { + if (groups[obj.id] === undefined) { + groups[obj.id] = [obj]; + } else { + groups[obj.id].push(obj); + } + } + + return Object.values(groups); + } + + /** + * Returns an object containing past key values from the given decoder results object. + * + * @param {Object} decoderResults The decoder results object. + * @param {Object} pastKeyValues The previous past key values. + * @returns {Object} An object containing past key values. + */ + getPastKeyValues(decoderResults, pastKeyValues) { + + const pkvs = Object.create(null); + + for (const name in decoderResults) { + if (name.startsWith('present')) { + let newName = name.replace('present', 'past_key_values'); + + if (pastKeyValues && name.includes('encoder')) { + // Optimization introduced by optimum to reuse past key values. So, we just replace the constant + // outputs with the previous past key values. + // https://github.com/huggingface/optimum/blob/0bf2c05fb7e1182b52d21b703cfc95fd9e4ea3dc/optimum/onnxruntime/base.py#L677-L704 + pkvs[newName] = pastKeyValues[newName]; + } else { + pkvs[newName] = decoderResults[name]; + } + } + } + return pkvs; + } + + /** + * Returns an object containing attentions from the given decoder results object. + * + * @param {Object} decoderResults The decoder results object. + * @returns {Object} An object containing attentions. + */ + getAttentions(decoderResults) { + const attns = Object.create(null); + + for (const attnName of ['cross_attentions', 'decoder_attentions']) { + const result = []; + for (const name in decoderResults) { + if (name.startsWith(attnName)) { + const index = name.split('.').pop() + result[index] = decoderResults[name]; + } + } + attns[attnName] = result; + } + return attns; + } + + /** + * Adds past key values to the decoder feeds object. If pastKeyValues is null, creates new tensors for past key values. + * + * @param {Object} decoderFeeds The decoder feeds object to add past key values to. + * @param {Object} pastKeyValues An object containing past key values. + */ + addPastKeyValues(decoderFeeds, pastKeyValues) { + if (pastKeyValues) { + Object.assign(decoderFeeds, pastKeyValues) + } else { + // TODO support batches (i.e., batch_size > 1) + const batch_size = 1; + + // @ts-ignore + if (this.config.is_encoder_decoder && (this.add_encoder_pkv ?? true)) { + // @ts-ignore + let encoder_dims = [batch_size, this.num_encoder_heads, 0, this.encoder_dim_kv]; + // @ts-ignore + let decoder_dims = [batch_size, this.num_decoder_heads, 0, this.decoder_dim_kv]; + // @ts-ignore + for (let i = 0; i < this.num_decoder_layers; ++i) { + decoderFeeds[`past_key_values.${i}.encoder.key`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], encoder_dims) + decoderFeeds[`past_key_values.${i}.encoder.value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], encoder_dims) + decoderFeeds[`past_key_values.${i}.decoder.key`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], decoder_dims) + decoderFeeds[`past_key_values.${i}.decoder.value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], decoder_dims) + } + } else if (this.config.model_type === 'falcon') { + // NOTE: Custom implementation for Falcon + // @ts-ignore + let dims = [batch_size * this.num_heads, 0, this.dim_kv] + // @ts-ignore + for (let i = 0; i < this.num_layers; ++i) { + decoderFeeds[`past_key_values.${i}.key`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], dims) + decoderFeeds[`past_key_values.${i}.value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], dims) + } + } else if (this.config.multi_query) { // e.g., for `gpt_bigcode` + // @ts-ignore + let dims = [batch_size * this.num_heads, 0, 2 * this.dim_kv] + // @ts-ignore + for (let i = 0; i < this.num_layers; ++i) { + decoderFeeds[`past_key_values.${i}.key_value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], dims) + } + } else if (this.config.model_type === 'bloom') { + // NOTE: Custom implementation for Bloom + + // @ts-ignore + let keyDims = [batch_size * this.num_heads, this.dim_kv, 0] // [batch_size x num_heads,64,past_sequence_length] + // @ts-ignore + let valueDims = [batch_size * this.num_heads, 0, this.dim_kv] // [batch_size x num_heads,past_sequence_length,64] + // @ts-ignore + for (let i = 0; i < this.num_layers; ++i) { + decoderFeeds[`past_key_values.${i}.key`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], keyDims) + decoderFeeds[`past_key_values.${i}.value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], valueDims) + } + } else { // Decoder-only + // @ts-ignore + let dims = [batch_size, this.num_heads, 0, this.dim_kv] + // @ts-ignore + for (let i = 0; i < this.num_layers; ++i) { + decoderFeeds[`past_key_values.${i}.key`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], dims) + decoderFeeds[`past_key_values.${i}.value`] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor('float32', [], dims) + } + } + } + } + + /** + * Initializes and returns the beam for text generation task + * @param {Tensor} inputTokenIds The input token ids. + * @param {Object} generation_config The generation config. + * @param {number} numOutputTokens The number of tokens to be generated. + * @param {Tensor} inputs_attention_mask Optional input attention mask. + * @returns {any} A Beam object representing the initialized beam. + * @private + */ + getStartBeams(inputTokenIds, generation_config, numOutputTokens, inputs_attention_mask) { + return this._getStartBeams(this, inputTokenIds, generation_config, numOutputTokens, inputs_attention_mask) + } + + /** + * Runs a single step of the beam search generation algorithm. + * @param {any} beam The current beam being generated. + * @returns {Promise} The updated beam after a single generation step. + * @private + */ + async runBeam(beam) { + return await this._runBeam(this, beam); + } + + /** + * Update a beam with a new token ID. + * @param {Object} beam The beam to update. + * @param {number} newTokenId The new token ID to add to the beam's output. + * @private + */ + updateBeam(beam, newTokenId) { + return this._updateBeam(beam, newTokenId); + } +} + +////////////////////////////////////////////////// +// Base model output class +class ModelOutput { } + +/** + * Base class for model's outputs, with potential hidden states and attentions. + */ +class BaseModelOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.last_hidden_state Sequence of hidden-states at the output of the last layer of the model. + * @param {Tensor} [output.hidden_states] Hidden-states of the model at the output of each layer plus the optional initial embedding outputs. + * @param {Tensor} [output.attentions] Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads. + */ + constructor({ last_hidden_state, hidden_states = null, attentions = null }) { + super(); + this.last_hidden_state = last_hidden_state; + this.hidden_states = hidden_states; + this.attentions = attentions; + } +} +////////////////////////////////////////////////// +// Bert models +class BertPreTrainedModel extends PreTrainedModel { } +class BertModel extends BertPreTrainedModel { } + +/** + * BertForMaskedLM is a class representing a BERT model for masked language modeling. + */ +class BertForMaskedLM extends BertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * BertForSequenceClassification is a class representing a BERT model for sequence classification. + */ +class BertForSequenceClassification extends BertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * BertForTokenClassification is a class representing a BERT model for token classification. + */ +class BertForTokenClassification extends BertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * BertForQuestionAnswering is a class representing a BERT model for question answering. + */ +class BertForQuestionAnswering extends BertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// NomicBert models +class NomicBertPreTrainedModel extends PreTrainedModel { } +class NomicBertModel extends NomicBertPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// RoFormer models +class RoFormerPreTrainedModel extends PreTrainedModel { } + +/** + * The bare RoFormer Model transformer outputting raw hidden-states without any specific head on top. + */ +class RoFormerModel extends RoFormerPreTrainedModel { } + +/** + * RoFormer Model with a `language modeling` head on top. + */ +class RoFormerForMaskedLM extends RoFormerPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * RoFormer Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class RoFormerForSequenceClassification extends RoFormerPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * RoFormer Model with a token classification head on top (a linear layer on top of the hidden-states output) + * e.g. for Named-Entity-Recognition (NER) tasks. + */ +class RoFormerForTokenClassification extends RoFormerPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * RoFormer Model with a span classification head on top for extractive question-answering tasks like SQuAD + * (a linear layers on top of the hidden-states output to compute `span start logits` and `span end logits`). + */ +class RoFormerForQuestionAnswering extends RoFormerPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +// TODO: Add RoFormerForCausalLM and RoFormerForMultipleChoice +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// ConvBert models +class ConvBertPreTrainedModel extends PreTrainedModel { } + +/** + * The bare ConvBERT Model transformer outputting raw hidden-states without any specific head on top. + */ +class ConvBertModel extends ConvBertPreTrainedModel { } + +/** + * ConvBERT Model with a language modeling head on top. + */ +class ConvBertForMaskedLM extends ConvBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * ConvBERT Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class ConvBertForSequenceClassification extends ConvBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * ConvBERT Model with a token classification head on top (a linear layer on top of the hidden-states output) + * e.g. for Named-Entity-Recognition (NER) tasks. + */ +class ConvBertForTokenClassification extends ConvBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * ConvBERT Model with a span classification head on top for extractive question-answering tasks like SQuAD + * (a linear layers on top of the hidden-states output to compute `span start logits` and `span end logits`) + */ +class ConvBertForQuestionAnswering extends ConvBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Electra models +class ElectraPreTrainedModel extends PreTrainedModel { } + +/** + * The bare Electra Model transformer outputting raw hidden-states without any specific head on top. + * Identical to the BERT model except that it uses an additional linear layer between the embedding + * layer and the encoder if the hidden size and embedding size are different. + */ +class ElectraModel extends ElectraPreTrainedModel { } +// TODO add ElectraForPreTraining +/** + * Electra model with a language modeling head on top. + */ +class ElectraForMaskedLM extends ElectraPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * ELECTRA Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class ElectraForSequenceClassification extends ElectraPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * Electra model with a token classification head on top. + */ +class ElectraForTokenClassification extends ElectraPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * LECTRA Model with a span classification head on top for extractive question-answering tasks like SQuAD + * (a linear layers on top of the hidden-states output to compute `span start logits` and `span end logits`). + */ +class ElectraForQuestionAnswering extends ElectraPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// CamemBERT models +class CamembertPreTrainedModel extends PreTrainedModel { } + +/** + * The bare CamemBERT Model transformer outputting raw hidden-states without any specific head on top. + */ +class CamembertModel extends CamembertPreTrainedModel { } + +/** + * CamemBERT Model with a `language modeling` head on top. + */ +class CamembertForMaskedLM extends CamembertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * CamemBERT Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) e.g. for GLUE tasks. + */ +class CamembertForSequenceClassification extends CamembertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * CamemBERT Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks. + */ +class CamembertForTokenClassification extends CamembertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * CamemBERT Model with a span classification head on top for extractive question-answering tasks + */ +class CamembertForQuestionAnswering extends CamembertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// DeBERTa models +class DebertaPreTrainedModel extends PreTrainedModel { } + +/** + * The bare DeBERTa Model transformer outputting raw hidden-states without any specific head on top. + */ +class DebertaModel extends DebertaPreTrainedModel { } + +/** + * DeBERTa Model with a `language modeling` head on top. + */ +class DebertaForMaskedLM extends DebertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class DebertaForSequenceClassification extends DebertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks. + */ +class DebertaForTokenClassification extends DebertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear + * layers on top of the hidden-states output to compute `span start logits` and `span end logits`). + */ +class DebertaForQuestionAnswering extends DebertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// DeBERTa-v2 models +class DebertaV2PreTrainedModel extends PreTrainedModel { } + +/** + * The bare DeBERTa-V2 Model transformer outputting raw hidden-states without any specific head on top. + */ +class DebertaV2Model extends DebertaV2PreTrainedModel { } + +/** + * DeBERTa-V2 Model with a `language modeling` head on top. + */ +class DebertaV2ForMaskedLM extends DebertaV2PreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa-V2 Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class DebertaV2ForSequenceClassification extends DebertaV2PreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa-V2 Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks. + */ +class DebertaV2ForTokenClassification extends DebertaV2PreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * DeBERTa-V2 Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear + * layers on top of the hidden-states output to compute `span start logits` and `span end logits`). + */ +class DebertaV2ForQuestionAnswering extends DebertaV2PreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// DistilBert models +class DistilBertPreTrainedModel extends PreTrainedModel { } +class DistilBertModel extends DistilBertPreTrainedModel { } + +/** + * DistilBertForSequenceClassification is a class representing a DistilBERT model for sequence classification. + */ +class DistilBertForSequenceClassification extends DistilBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * DistilBertForTokenClassification is a class representing a DistilBERT model for token classification. + */ +class DistilBertForTokenClassification extends DistilBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + + +/** + * DistilBertForQuestionAnswering is a class representing a DistilBERT model for question answering. + */ +class DistilBertForQuestionAnswering extends DistilBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} + +/** + * DistilBertForMaskedLM is a class representing a DistilBERT model for masking task. + */ +class DistilBertForMaskedLM extends DistilBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// ESM models +class EsmPreTrainedModel extends PreTrainedModel { } + +/** + * The bare ESM Model transformer outputting raw hidden-states without any specific head on top. + */ +class EsmModel extends EsmPreTrainedModel { } + +/** + * ESM Model with a `language modeling` head on top. + */ +class EsmForMaskedLM extends EsmPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * ESM Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class EsmForSequenceClassification extends EsmPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * ESM Model with a token classification head on top (a linear layer on top of the hidden-states output) + * e.g. for Named-Entity-Recognition (NER) tasks. + */ +class EsmForTokenClassification extends EsmPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// MobileBert models +class MobileBertPreTrainedModel extends PreTrainedModel { } +class MobileBertModel extends MobileBertPreTrainedModel { } + +/** + * MobileBertForMaskedLM is a class representing a MobileBERT model for masking task. + */ +class MobileBertForMaskedLM extends MobileBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * MobileBert Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class MobileBertForSequenceClassification extends MobileBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * MobileBert Model with a span classification head on top for extractive question-answering tasks + */ +class MobileBertForQuestionAnswering extends MobileBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// MPNet models +class MPNetPreTrainedModel extends PreTrainedModel { } + +/** + * The bare MPNet Model transformer outputting raw hidden-states without any specific head on top. + */ +class MPNetModel extends MPNetPreTrainedModel { } + +/** + * MPNetForMaskedLM is a class representing a MPNet model for masked language modeling. + */ +class MPNetForMaskedLM extends MPNetPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for masked language modeling. + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * MPNetForSequenceClassification is a class representing a MPNet model for sequence classification. + */ +class MPNetForSequenceClassification extends MPNetPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * MPNetForTokenClassification is a class representing a MPNet model for token classification. + */ +class MPNetForTokenClassification extends MPNetPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * MPNetForQuestionAnswering is a class representing a MPNet model for question answering. + */ +class MPNetForQuestionAnswering extends MPNetPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for question answering. + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// SqueezeBert models +class SqueezeBertPreTrainedModel extends PreTrainedModel { } +class SqueezeBertModel extends SqueezeBertPreTrainedModel { } +class SqueezeBertForMaskedLM extends SqueezeBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} +class SqueezeBertForSequenceClassification extends SqueezeBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +class SqueezeBertForQuestionAnswering extends SqueezeBertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Albert models +class AlbertPreTrainedModel extends PreTrainedModel { } +class AlbertModel extends AlbertPreTrainedModel { } +class AlbertForSequenceClassification extends AlbertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +class AlbertForQuestionAnswering extends AlbertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +class AlbertForMaskedLM extends AlbertPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// T5 models +class T5PreTrainedModel extends PreTrainedModel { }; + +class T5Model extends T5PreTrainedModel { } + +/** + * T5Model is a class representing a T5 model for conditional generation. + */ +class T5ForConditionalGeneration extends T5PreTrainedModel { + + /** + * Creates a new instance of the `T5ForConditionalGeneration` class. + * @param {Object} config The model configuration. + * @param {any} session session for the model. + * @param {any} decoder_merged_session session for the decoder. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.num_decoder_layers; + this.num_decoder_heads = this.config.num_heads; + this.decoder_dim_kv = this.config.d_kv; + + this.num_encoder_layers = this.config.num_layers; + this.num_encoder_heads = this.config.num_heads; + this.encoder_dim_kv = this.config.d_kv; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// LONGT5 models +/** + * An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. + */ +class LongT5PreTrainedModel extends PreTrainedModel { }; + +/** + * The bare LONGT5 Model transformer outputting raw hidden-states without any specific head on top. + */ +class LongT5Model extends LongT5PreTrainedModel { } + +/** + * LONGT5 Model with a `language modeling` head on top. + */ +class LongT5ForConditionalGeneration extends LongT5PreTrainedModel { + /** + * Creates a new instance of the `LongT5ForConditionalGeneration` class. + * @param {Object} config The model configuration. + * @param {any} session session for the model. + * @param {any} decoder_merged_session session for the decoder. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.num_decoder_layers; + this.num_decoder_heads = this.config.num_heads; + this.decoder_dim_kv = this.config.d_kv; + + this.num_encoder_layers = this.config.num_layers; + this.num_encoder_heads = this.config.num_heads; + this.encoder_dim_kv = this.config.d_kv; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// MT5 models +class MT5PreTrainedModel extends PreTrainedModel { }; + +class MT5Model extends MT5PreTrainedModel { } + +/** + * A class representing a conditional sequence-to-sequence model based on the MT5 architecture. + */ +class MT5ForConditionalGeneration extends MT5PreTrainedModel { + + /** + * Creates a new instance of the `MT5ForConditionalGeneration` class. + * @param {any} config The model configuration. + * @param {any} session The ONNX session containing the encoder weights. + * @param {any} decoder_merged_session The ONNX session containing the merged decoder weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.num_decoder_layers; + this.num_decoder_heads = this.config.num_heads; + this.decoder_dim_kv = this.config.d_kv; + + this.num_encoder_layers = this.config.num_layers; + this.num_encoder_heads = this.config.num_heads; + this.encoder_dim_kv = this.config.d_kv; + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Bart models +class BartPretrainedModel extends PreTrainedModel { }; + +/** + * The bare BART Model outputting raw hidden-states without any specific head on top. + */ +class BartModel extends BartPretrainedModel { } + +/** + * The BART Model with a language modeling head. Can be used for summarization. + */ +class BartForConditionalGeneration extends BartPretrainedModel { + + /** + * Creates a new instance of the `BartForConditionalGeneration` class. + * @param {Object} config The configuration object for the Bart model. + * @param {Object} session The ONNX session used to execute the model. + * @param {Object} decoder_merged_session The ONNX session used to execute the decoder. + * @param {Object} generation_config The generation configuration object. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } + +} + +/** + * Bart model with a sequence classification/head on top (a linear layer on top of the pooled output) + */ +class BartForSequenceClassification extends BartPretrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// MBart models +class MBartPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare MBART Model outputting raw hidden-states without any specific head on top. + */ +class MBartModel extends MBartPreTrainedModel { } + +/** + * The MBART Model with a language modeling head. Can be used for summarization, after fine-tuning the pretrained models. + */ +class MBartForConditionalGeneration extends MBartPreTrainedModel { + + /** + * Creates a new instance of the `MBartForConditionalGeneration` class. + * @param {Object} config The configuration object for the Bart model. + * @param {Object} session The ONNX session used to execute the model. + * @param {Object} decoder_merged_session The ONNX session used to execute the decoder. + * @param {Object} generation_config The generation configuration object. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } + +} + +/** + * MBart model with a sequence classification/head on top (a linear layer on top of the pooled output). + */ +class MBartForSequenceClassification extends MBartPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + + +class MBartForCausalLM extends MBartPreTrainedModel { + /** + * Creates a new instance of the `MBartForCausalLM` class. + * @param {Object} config Configuration object for the model. + * @param {Object} decoder_merged_session ONNX Session object for the decoder. + * @param {Object} generation_config Configuration object for the generation process. + */ + constructor(config, decoder_merged_session, generation_config) { + super(config, decoder_merged_session); + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Blenderbot models +class BlenderbotPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare Blenderbot Model outputting raw hidden-states without any specific head on top. + */ +class BlenderbotModel extends BlenderbotPreTrainedModel { } + +/** + * The Blenderbot Model with a language modeling head. Can be used for summarization. + */ +class BlenderbotForConditionalGeneration extends BlenderbotPreTrainedModel { + + /** + * Creates a new instance of the `BlenderbotForConditionalGeneration` class. + * @param {any} config The model configuration. + * @param {any} session The ONNX session containing the encoder weights. + * @param {any} decoder_merged_session The ONNX session containing the merged decoder weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Blenderbot models +class BlenderbotSmallPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare BlenderbotSmall Model outputting raw hidden-states without any specific head on top. + */ +class BlenderbotSmallModel extends BlenderbotSmallPreTrainedModel { } + +/** + * The BlenderbotSmall Model with a language modeling head. Can be used for summarization. + */ +class BlenderbotSmallForConditionalGeneration extends BlenderbotSmallPreTrainedModel { + + /** + * Creates a new instance of the `BlenderbotForConditionalGeneration` class. + * @param {any} config The model configuration. + * @param {any} session The ONNX session containing the encoder weights. + * @param {any} decoder_merged_session The ONNX session containing the merged decoder weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Roberta models +class RobertaPreTrainedModel extends PreTrainedModel { } +class RobertaModel extends RobertaPreTrainedModel { } + +/** + * RobertaForMaskedLM class for performing masked language modeling on Roberta models. + */ +class RobertaForMaskedLM extends RobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * RobertaForSequenceClassification class for performing sequence classification on Roberta models. + */ +class RobertaForSequenceClassification extends RobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * RobertaForTokenClassification class for performing token classification on Roberta models. + */ +class RobertaForTokenClassification extends RobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * RobertaForQuestionAnswering class for performing question answering on Roberta models. + */ +class RobertaForQuestionAnswering extends RobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// XLM models +/** + * An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. + */ +class XLMPreTrainedModel extends PreTrainedModel { } + +/** + * The bare XLM Model transformer outputting raw hidden-states without any specific head on top. + */ +class XLMModel extends XLMPreTrainedModel { } + +/** + * The XLM Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). + */ +class XLMWithLMHeadModel extends XLMPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * XLM Model with a sequence classification/regression head on top (a linear layer on top of the pooled output) + */ +class XLMForSequenceClassification extends XLMPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * XLM Model with a token classification head on top (a linear layer on top of the hidden-states output) + */ +class XLMForTokenClassification extends XLMPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * XLM Model with a span classification head on top for extractive question-answering tasks + */ +class XLMForQuestionAnswering extends XLMPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// XLMRoberta models +class XLMRobertaPreTrainedModel extends PreTrainedModel { } +class XLMRobertaModel extends XLMRobertaPreTrainedModel { } + +/** + * XLMRobertaForMaskedLM class for performing masked language modeling on XLMRoberta models. + */ +class XLMRobertaForMaskedLM extends XLMRobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new MaskedLMOutput(await super._call(model_inputs)); + } +} + +/** + * XLMRobertaForSequenceClassification class for performing sequence classification on XLMRoberta models. + */ +class XLMRobertaForSequenceClassification extends XLMRobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * XLMRobertaForTokenClassification class for performing token classification on XLMRoberta models. + */ +class XLMRobertaForTokenClassification extends XLMRobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for token classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * XLMRobertaForQuestionAnswering class for performing question answering on XLMRoberta models. + */ +class XLMRobertaForQuestionAnswering extends XLMRobertaPreTrainedModel { + /** + * Calls the model on new inputs. + * + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} returned object + */ + async _call(model_inputs) { + return new QuestionAnsweringModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Audio Spectrogram Transformer (AST) models +class ASTPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare AST Model transformer outputting raw hidden-states without any specific head on top. + */ +class ASTModel extends ASTPreTrainedModel { } + +/** + * Audio Spectrogram Transformer model with an audio classification head on top + * (a linear layer on top of the pooled output) e.g. for datasets like AudioSet, Speech Commands v2. + */ +class ASTForAudioClassification extends ASTPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Whisper models +class WhisperPreTrainedModel extends PreTrainedModel { }; + +/** + * WhisperModel class for training Whisper models without a language model head. + */ +class WhisperModel extends WhisperPreTrainedModel { } + +/** + * WhisperForConditionalGeneration class for generating conditional outputs from Whisper models. + */ +class WhisperForConditionalGeneration extends WhisperPreTrainedModel { + + requires_attention_mask = false; + main_input_name = 'input_features'; + + /** + * Creates a new instance of the `WhisperForConditionalGeneration` class. + * @param {Object} config Configuration object for the model. + * @param {Object} session ONNX Session object for the model. + * @param {Object} decoder_merged_session ONNX Session object for the decoder. + * @param {Object} generation_config Configuration object for the generation process. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } + + /** + * @typedef {Object} WhisperGenerationConfig + * @extends GenerationConfig + * @property {boolean} [return_timestamps=null] Whether to return the timestamps with the text. This enables the `WhisperTimestampsLogitsProcessor`. + * @property {boolean} [return_token_timestamps=null] Whether to return token-level timestamps + * with the text. This can be used with or without the `return_timestamps` option. To get word-level + * timestamps, use the tokenizer to group the tokens into words. + * @property {number} [num_frames=null] The number of audio frames available in this chunk. This is only used generating word-level timestamps. + */ + + /** + * Generates outputs based on input and generation configuration. + * @param {Object} inputs Input data for the model. + * @param {WhisperGenerationConfig} generation_config Configuration object for the generation process. + * @param {Object} logits_processor Optional logits processor object. + * @returns {Promise} Promise object represents the generated outputs. + */ + async generate( + inputs, + generation_config = null, + logits_processor = null, + // { + // return_timestamps = null, + // return_token_timestamps = null, + // language = null, + // task = null, + // } = {}, + ) { + // Create generation config object + generation_config = this._get_generation_config(generation_config); + + + // Whisper has additional options for returning timestamps + generation_config.return_timestamps ??= false; + + // TODO add language and task + + if (generation_config.return_timestamps) { + logits_processor = [new _utils_generation_js__WEBPACK_IMPORTED_MODULE_3__.WhisperTimeStampLogitsProcessor(generation_config)] + } + + if (generation_config.return_token_timestamps) { + generation_config.output_attentions = true; + generation_config.return_dict_in_generate = true; + + if (generation_config.task === 'translate') { + console.warn("Token-level timestamps may not be reliable for task 'translate'.") + } + + if (!generation_config.alignment_heads) { + throw new Error( + "Model generation config has no `alignment_heads`, token-level timestamps not available. " + + "See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config." + ) + } + } + + const outputs = await super.generate(inputs, generation_config, logits_processor); + + if (generation_config.return_token_timestamps && generation_config.alignment_heads) { + outputs["token_timestamps"] = this._extract_token_timestamps( + outputs, + generation_config.alignment_heads, + generation_config.num_frames, + ) + } + + return outputs + } + + /** + * Calculates token-level timestamps using the encoder-decoder cross-attentions and + * dynamic time-warping (DTW) to map each output token to a position in the input audio. + * @param {Object} generate_outputs Outputs generated by the model + * @param {Tensor[][][]} generate_outputs.cross_attentions The cross attentions output by the model + * @param {Tensor[][][]} generate_outputs.decoder_attentions The decoder attentions output by the model + * @param {number[][]} generate_outputs.sequences The sequences output by the model + * @param {number[][]} alignment_heads Alignment heads of the model + * @param {number} [num_frames=null] Number of frames in the input audio. + * @param {number} [time_precision=0.02] Precision of the timestamps in seconds + * @returns {Tensor} tensor containing the timestamps in seconds for each predicted token + */ + _extract_token_timestamps(generate_outputs, alignment_heads, num_frames = null, time_precision = 0.02) { + if (!generate_outputs.cross_attentions) { + throw new Error( + "Model outputs must contain cross attentions to extract timestamps. " + + "This is most likely because the model was not exported with `output_attentions=True`." + ) + } + + let median_filter_width = this.config.median_filter_width; + if (median_filter_width === undefined) { + console.warn("Model config has no `median_filter_width`, using default value of 7.") + median_filter_width = 7; + } + + const batchedMatrices = generate_outputs.cross_attentions.map(batch => { + // Create a list with `decoder_layers` elements, each a tensor of shape + // (batch size, attention_heads, output length, input length). + let cross_attentions = Array.from({ length: this.config.decoder_layers }, + (_, i) => (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.cat)(batch.map(x => x[i]), 2) + ); + + let weights = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.stack)(alignment_heads.map(([l, h]) => { + return num_frames + ? cross_attentions[l].slice(null, h, null, [0, num_frames]) + : cross_attentions[l].slice(null, h); + })); + weights = weights.transpose(1, 0, 2, 3) + + let [std, calculatedMean] = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.std_mean)(weights, -2, 0, true); + + // Normalize and smoothen the weights. + let smoothedWeights = weights.clone(); // [1, 8, seqLength, 1500] + + for (let a = 0; a < smoothedWeights.dims[0]; ++a) { + let aTensor = smoothedWeights[a]; // [8, seqLength, 1500] + + for (let b = 0; b < aTensor.dims[0]; ++b) { + let bTensor = aTensor[b]; // [seqLength, 1500] + + const stdTensor = std[a][b][0]; // [1500] + const meanTensor = calculatedMean[a][b][0]; // [1500] + + for (let c = 0; c < bTensor.dims[0]; ++c) { + + let cTensor = bTensor[c]; // [1500] + for (let d = 0; d < cTensor.data.length; ++d) { + cTensor.data[d] = (cTensor.data[d] - meanTensor.data[d]) / stdTensor.data[d] + } + + // Apply median filter. + cTensor.data.set((0,_transformers_js__WEBPACK_IMPORTED_MODULE_6__.medianFilter)(cTensor.data, median_filter_width)) + } + } + } + + // Average the different cross-attention heads. + const matrix = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.mean)(smoothedWeights, 1); + return matrix; + }); + + const timestampsShape = [generate_outputs.sequences.length, generate_outputs.sequences[0].length]; + + const timestamps = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor( + 'float32', + new Float32Array(timestampsShape[0] * timestampsShape[1]), + timestampsShape + ); + + // Perform dynamic time warping on each element of the batch. + for (let batch_idx = 0; batch_idx < timestampsShape[0]; ++batch_idx) { + // NOTE: Since we run only one batch at a time, we can squeeze to get the same dimensions + // as the python implementation + const matrix = batchedMatrices[batch_idx].neg().squeeze_(0); + let [text_indices, time_indices] = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.dynamicTimeWarping)(matrix); + + let diffs = Array.from({ length: text_indices.length - 1 }, (v, i) => text_indices[i + 1] - text_indices[i]); + let jumps = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_1__.mergeArrays)([1], diffs).map(x => !!x); // convert to boolean + + let jump_times = []; + for (let i = 0; i < jumps.length; ++i) { + if (jumps[i]) { + jump_times.push(time_indices[i] * time_precision); + // NOTE: No point in rounding here, since we set to Float32Array later + } + } + timestamps[batch_idx].data.set(jump_times, 1) + } + + return timestamps; + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +/** + * Vision Encoder-Decoder model based on OpenAI's GPT architecture for image captioning and other vision tasks + */ +class VisionEncoderDecoderModel extends PreTrainedModel { + main_input_name = 'pixel_values'; + + /** + * Creates a new instance of the `VisionEncoderDecoderModel` class. + * @param {Object} config The configuration object specifying the hyperparameters and other model settings. + * @param {Object} session The ONNX session containing the encoder model. + * @param {any} decoder_merged_session The ONNX session containing the merged decoder model. + * @param {Object} generation_config Configuration object for the generation process. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + // Extract configs + const encoderConfig = this.config.encoder; + const decoderConfig = this.config.decoder; + + // Validate encoder + const encoderModelType = encoderConfig.model_type; + const encoderModel = + MODEL_MAPPING_NAMES_ENCODER_ONLY.get(encoderModelType) + ?? MODEL_MAPPING_NAMES_ENCODER_DECODER.get(encoderModelType); + if (!encoderModel) { + console.warn(`Model type for encoder '${encoderModelType}' not found, assuming encoder-only architecture. Please report this at https://github.com/xenova/transformers.js/issues/new/choose.`); + } + + // Validate decoder + const decoderModel = MODEL_WITH_LM_HEAD_MAPPING_NAMES.get(decoderConfig.model_type); + if (!decoderModel) { + throw new Error(`Unable to construct \`VisionEncoderDecoder\` due to unsupported decoder: "${this.config.decoder.model_type}"`); + } + + // @ts-ignore + const decoderModelClass = decoderModel[1]; + // @ts-ignore + const decoder = new decoderModelClass(decoderConfig, decoder_merged_session, generation_config); + + this.add_encoder_pkv = 'num_decoder_layers' in decoder; + if (this.add_encoder_pkv) { + // Decoder is part of an encoder-decoder model + this.num_decoder_layers = decoder.num_decoder_layers; + this.num_decoder_heads = decoder.num_decoder_heads; + this.decoder_dim_kv = decoder.decoder_dim_kv; + + this.num_encoder_layers = decoder.num_encoder_layers; + this.num_encoder_heads = decoder.num_encoder_heads; + this.encoder_dim_kv = decoder.encoder_dim_kv; + + } else { + // Decoder is a decoder-only model + this.num_layers = decoder.num_layers; + this.num_heads = decoder.num_heads; + this.dim_kv = decoder.dim_kv; + } + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// CLIP models +class CLIPPreTrainedModel extends PreTrainedModel { } + +/** + * CLIP Text and Vision Model with a projection layers on top + * + * **Example:** Perform zero-shot image classification with a `CLIPModel`. + * + * ```javascript + * import { AutoTokenizer, AutoProcessor, CLIPModel, RawImage } from '@xenova/transformers'; + * + * // Load tokenizer, processor, and model + * let tokenizer = await AutoTokenizer.from_pretrained('Xenova/clip-vit-base-patch16'); + * let processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16'); + * let model = await CLIPModel.from_pretrained('Xenova/clip-vit-base-patch16'); + * + * // Run tokenization + * let texts = ['a photo of a car', 'a photo of a football match'] + * let text_inputs = tokenizer(texts, { padding: true, truncation: true }); + * + * // Read image and run processor + * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'); + * let image_inputs = await processor(image); + * + * // Run model with both text and pixel inputs + * let output = await model({ ...text_inputs, ...image_inputs }); + * // { + * // logits_per_image: Tensor { + * // dims: [ 1, 2 ], + * // data: Float32Array(2) [ 18.579734802246094, 24.31830596923828 ], + * // }, + * // logits_per_text: Tensor { + * // dims: [ 2, 1 ], + * // data: Float32Array(2) [ 18.579734802246094, 24.31830596923828 ], + * // }, + * // text_embeds: Tensor { + * // dims: [ 2, 512 ], + * // data: Float32Array(1024) [ ... ], + * // }, + * // image_embeds: Tensor { + * // dims: [ 1, 512 ], + * // data: Float32Array(512) [ ... ], + * // } + * // } + * ``` + */ +class CLIPModel extends CLIPPreTrainedModel { } + +/** + * CLIP Text Model with a projection layer on top (a linear layer on top of the pooled output) + * + * **Example:** Compute text embeddings with `CLIPTextModelWithProjection`. + * + * ```javascript + * import { AutoTokenizer, CLIPTextModelWithProjection } from '@xenova/transformers'; + * + * // Load tokenizer and text model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clip-vit-base-patch16'); + * const text_model = await CLIPTextModelWithProjection.from_pretrained('Xenova/clip-vit-base-patch16'); + * + * // Run tokenization + * let texts = ['a photo of a car', 'a photo of a football match']; + * let text_inputs = tokenizer(texts, { padding: true, truncation: true }); + * + * // Compute embeddings + * const { text_embeds } = await text_model(text_inputs); + * // Tensor { + * // dims: [ 2, 512 ], + * // type: 'float32', + * // data: Float32Array(1024) [ ... ], + * // size: 1024 + * // } + * ``` + */ +class CLIPTextModelWithProjection extends CLIPPreTrainedModel { + + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'text_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} + +/** + * CLIP Vision Model with a projection layer on top (a linear layer on top of the pooled output) + * + * **Example:** Compute vision embeddings with `CLIPVisionModelWithProjection`. + * + * ```javascript + * import { AutoProcessor, CLIPVisionModelWithProjection, RawImage} from '@xenova/transformers'; + * + * // Load processor and vision model + * const processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16'); + * const vision_model = await CLIPVisionModelWithProjection.from_pretrained('Xenova/clip-vit-base-patch16'); + * + * // Read image and run processor + * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'); + * let image_inputs = await processor(image); + * + * // Compute embeddings + * const { image_embeds } = await vision_model(image_inputs); + * // Tensor { + * // dims: [ 1, 512 ], + * // type: 'float32', + * // data: Float32Array(512) [ ... ], + * // size: 512 + * // } + * ``` + */ +class CLIPVisionModelWithProjection extends CLIPPreTrainedModel { + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'vision_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// SigLIP models +class SiglipPreTrainedModel extends PreTrainedModel { } + +/** + * SigLIP Text and Vision Model with a projection layers on top + * + * **Example:** Perform zero-shot image classification with a `SiglipModel`. + * + * ```javascript + * import { AutoTokenizer, AutoProcessor, SiglipModel, RawImage } from '@xenova/transformers'; + * + * // Load tokenizer, processor, and model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/siglip-base-patch16-224'); + * const processor = await AutoProcessor.from_pretrained('Xenova/siglip-base-patch16-224'); + * const model = await SiglipModel.from_pretrained('Xenova/siglip-base-patch16-224'); + * + * // Run tokenization + * const texts = ['a photo of 2 cats', 'a photo of 2 dogs']; + * const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true }); + * + * // Read image and run processor + * const image = await RawImage.read('http://images.cocodataset.org/val2017/000000039769.jpg'); + * const image_inputs = await processor(image); + * + * // Run model with both text and pixel inputs + * const output = await model({ ...text_inputs, ...image_inputs }); + * // { + * // logits_per_image: Tensor { + * // dims: [ 1, 2 ], + * // data: Float32Array(2) [ -1.6019744873046875, -10.720091819763184 ], + * // }, + * // logits_per_text: Tensor { + * // dims: [ 2, 1 ], + * // data: Float32Array(2) [ -1.6019744873046875, -10.720091819763184 ], + * // }, + * // text_embeds: Tensor { + * // dims: [ 2, 768 ], + * // data: Float32Array(1536) [ ... ], + * // }, + * // image_embeds: Tensor { + * // dims: [ 1, 768 ], + * // data: Float32Array(768) [ ... ], + * // } + * // } + * ``` + */ +class SiglipModel extends SiglipPreTrainedModel { } + +/** + * The text model from SigLIP without any head or projection on top. + * + * **Example:** Compute text embeddings with `SiglipTextModel`. + * + * ```javascript + * import { AutoTokenizer, SiglipTextModel } from '@xenova/transformers'; + * + * // Load tokenizer and text model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/siglip-base-patch16-224'); + * const text_model = await SiglipTextModel.from_pretrained('Xenova/siglip-base-patch16-224'); + * + * // Run tokenization + * const texts = ['a photo of 2 cats', 'a photo of 2 dogs']; + * const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true }); + * + * // Compute embeddings + * const { pooler_output } = await text_model(text_inputs); + * // Tensor { + * // dims: [ 2, 768 ], + * // type: 'float32', + * // data: Float32Array(1536) [ ... ], + * // size: 1536 + * // } + * ``` + */ +class SiglipTextModel extends SiglipPreTrainedModel { + + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'text_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} + +/** + * The vision model from SigLIP without any head or projection on top. + * + * **Example:** Compute vision embeddings with `SiglipVisionModel`. + * + * ```javascript + * import { AutoProcessor, SiglipVisionModel, RawImage} from '@xenova/transformers'; + * + * // Load processor and vision model + * const processor = await AutoProcessor.from_pretrained('Xenova/siglip-base-patch16-224'); + * const vision_model = await SiglipVisionModel.from_pretrained('Xenova/siglip-base-patch16-224'); + * + * // Read image and run processor + * const image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'); + * const image_inputs = await processor(image); + * + * // Compute embeddings + * const { pooler_output } = await vision_model(image_inputs); + * // Tensor { + * // dims: [ 1, 768 ], + * // type: 'float32', + * // data: Float32Array(768) [ ... ], + * // size: 768 + * // } + * ``` + */ +class SiglipVisionModel extends CLIPPreTrainedModel { + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'vision_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} +////////////////////////////////////////////////// +// ChineseCLIP models +class ChineseCLIPPreTrainedModel extends PreTrainedModel { } + +class ChineseCLIPModel extends ChineseCLIPPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// CLIPSeg models +class CLIPSegPreTrainedModel extends PreTrainedModel { } + +class CLIPSegModel extends CLIPSegPreTrainedModel { } + +/** + * CLIPSeg model with a Transformer-based decoder on top for zero-shot and one-shot image segmentation. + * + * **Example:** Perform zero-shot image segmentation with a `CLIPSegForImageSegmentation` model. + * + * ```javascript + * import { AutoTokenizer, AutoProcessor, CLIPSegForImageSegmentation, RawImage } from '@xenova/transformers'; + * + * // Load tokenizer, processor, and model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clipseg-rd64-refined'); + * const processor = await AutoProcessor.from_pretrained('Xenova/clipseg-rd64-refined'); + * const model = await CLIPSegForImageSegmentation.from_pretrained('Xenova/clipseg-rd64-refined'); + * + * // Run tokenization + * const texts = ['a glass', 'something to fill', 'wood', 'a jar']; + * const text_inputs = tokenizer(texts, { padding: true, truncation: true }); + * + * // Read image and run processor + * const image = await RawImage.read('https://github.com/timojl/clipseg/blob/master/example_image.jpg?raw=true'); + * const image_inputs = await processor(image); + * + * // Run model with both text and pixel inputs + * const { logits } = await model({ ...text_inputs, ...image_inputs }); + * // logits: Tensor { + * // dims: [4, 352, 352], + * // type: 'float32', + * // data: Float32Array(495616) [ ... ], + * // size: 495616 + * // } + * ``` + * + * You can visualize the predictions as follows: + * ```javascript + * const preds = logits + * .unsqueeze_(1) + * .sigmoid_() + * .mul_(255) + * .round_() + * .to('uint8'); + * + * for (let i = 0; i < preds.dims[0]; ++i) { + * const img = RawImage.fromTensor(preds[i]); + * img.save(`prediction_${i}.png`); + * } + * ``` + */ +class CLIPSegForImageSegmentation extends CLIPSegPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// GPT2 models +class GPT2PreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `GPT2PreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_head + this.num_layers = this.config.n_layer + this.dim_kv = this.config.n_embd / this.num_heads; + } +} + +class GPT2Model extends GPT2PreTrainedModel { } + +/** + * GPT-2 language model head on top of the GPT-2 base model. This model is suitable for text generation tasks. + */ +class GPT2LMHeadModel extends GPT2PreTrainedModel { } +// export class GPT2ForSequenceClassification extends GPT2PreTrainedModel { +// TODO +// } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// GPTNeo models +class GPTNeoPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `GPTNeoPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_heads; + this.num_layers = this.config.num_layers; + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} +class GPTNeoModel extends GPTNeoPreTrainedModel { } + +class GPTNeoForCausalLM extends GPTNeoPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// GPTNeoX models +class GPTNeoXPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `GPTNeoXPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_attention_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} +class GPTNeoXModel extends GPTNeoXPreTrainedModel { } + +class GPTNeoXForCausalLM extends GPTNeoXPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// GPT-J models +class GPTJPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `GPTJPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_head + this.num_layers = this.config.n_layer + this.dim_kv = this.config.n_embd / this.num_heads; + } +} + +class GPTJModel extends GPTJPreTrainedModel { } + +class GPTJForCausalLM extends GPTJPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// GPTBigCode models +class GPTBigCodePreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `GPTBigCodePreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_head + this.num_layers = this.config.n_layer + this.dim_kv = this.config.n_embd / this.num_heads; + } +} + +class GPTBigCodeModel extends GPTBigCodePreTrainedModel { } + +class GPTBigCodeForCausalLM extends GPTBigCodePreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// CodeGen models +class CodeGenPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `CodeGenPreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_head + this.num_layers = this.config.n_layer + this.dim_kv = this.config.n_embd / this.num_heads; + } +} +/** + * CodeGenModel is a class representing a code generation model without a language model head. + */ +class CodeGenModel extends CodeGenPreTrainedModel { } + +/** + * CodeGenForCausalLM is a class that represents a code generation model based on the GPT-2 architecture. It extends the `CodeGenPreTrainedModel` class. + */ +class CodeGenForCausalLM extends CodeGenPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// LLama models + +/** + * The bare LLama Model outputting raw hidden-states without any specific head on top. + */ +class LlamaPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `LlamaPreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_key_value_heads ?? this.config.num_attention_heads + this.num_layers = this.config.num_hidden_layers + this.dim_kv = this.config.hidden_size / this.config.num_attention_heads + } +} +/** + * The bare LLaMA Model outputting raw hidden-states without any specific head on top. + */ +class LlamaModel extends LlamaPreTrainedModel { } + +class LlamaForCausalLM extends LlamaPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Qwen2 models + +/** + * The bare Qwen2 Model outputting raw hidden-states without any specific head on top. + */ +class Qwen2PreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `Qwen2PreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_key_value_heads ?? this.config.num_attention_heads + this.num_layers = this.config.num_hidden_layers + this.dim_kv = this.config.hidden_size / this.config.num_attention_heads + } +} +/** + * The bare Qwen2 Model outputting raw hidden-states without any specific head on top. + */ +class Qwen2Model extends Qwen2PreTrainedModel { } + +class Qwen2ForCausalLM extends Qwen2PreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Phi models + +class PhiPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `PhiPreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id; + + this.num_heads = this.config.num_attention_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} +/** + * The bare Phi Model outputting raw hidden-states without any specific head on top. + */ +class PhiModel extends PhiPreTrainedModel { } + +class PhiForCausalLM extends PhiPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Bloom models +/** + * The Bloom Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). + */ +class BloomPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `BloomPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_head + this.num_layers = this.config.n_layer + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} + +/** + * The bare Bloom Model transformer outputting raw hidden-states without any specific head on top. + */ +class BloomModel extends BloomPreTrainedModel { } + +/** + * The Bloom Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). + */ +class BloomForCausalLM extends BloomPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// MPT models +class MptPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `MptPreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.n_heads + this.num_layers = this.config.n_layers + this.dim_kv = this.config.d_model / this.num_heads; + } +} + +/** + * The bare Mpt Model transformer outputting raw hidden-states without any specific head on top. + */ +class MptModel extends MptPreTrainedModel { } + +/** + * The MPT Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). + */ +class MptForCausalLM extends MptPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// OPT models +class OPTPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `OPTPreTrainedModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_attention_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} + +/** + * The bare OPT Model outputting raw hidden-states without any specific head on top. + */ +class OPTModel extends OPTPreTrainedModel { } + +/** + * The OPT Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). + */ +class OPTForCausalLM extends OPTPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class ViTPreTrainedModel extends PreTrainedModel { } +class ViTModel extends ViTPreTrainedModel { } +class ViTForImageClassification extends ViTPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class VitMattePreTrainedModel extends PreTrainedModel { } + +/** + * ViTMatte framework leveraging any vision backbone e.g. for ADE20k, CityScapes. + * + * **Example:** Perform image matting with a `VitMatteForImageMatting` model. + * ```javascript + * import { AutoProcessor, VitMatteForImageMatting, RawImage } from '@xenova/transformers'; + * + * // Load processor and model + * const processor = await AutoProcessor.from_pretrained('Xenova/vitmatte-small-distinctions-646'); + * const model = await VitMatteForImageMatting.from_pretrained('Xenova/vitmatte-small-distinctions-646'); + * + * // Load image and trimap + * const image = await RawImage.fromURL('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/vitmatte_image.png'); + * const trimap = await RawImage.fromURL('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/vitmatte_trimap.png'); + * + * // Prepare image + trimap for the model + * const inputs = await processor(image, trimap); + * + * // Predict alpha matte + * const { alphas } = await model(inputs); + * // Tensor { + * // dims: [ 1, 1, 640, 960 ], + * // type: 'float32', + * // size: 614400, + * // data: Float32Array(614400) [ 0.9894027709960938, 0.9970508813858032, ... ] + * // } + * ``` + * + * You can visualize the alpha matte as follows: + * ```javascript + * import { Tensor, cat } from '@xenova/transformers'; + * + * // Visualize predicted alpha matte + * const imageTensor = image.toTensor(); + * + * // Convert float (0-1) alpha matte to uint8 (0-255) + * const alphaChannel = alphas + * .squeeze(0) + * .mul_(255) + * .clamp_(0, 255) + * .round_() + * .to('uint8'); + * + * // Concatenate original image with predicted alpha + * const imageData = cat([imageTensor, alphaChannel], 0); + * + * // Save output image + * const outputImage = RawImage.fromTensor(imageData); + * outputImage.save('output.png'); + * ``` + */ +class VitMatteForImageMatting extends VitMattePreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new ImageMattingOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class MobileViTPreTrainedModel extends PreTrainedModel { } +class MobileViTModel extends MobileViTPreTrainedModel { } +class MobileViTForImageClassification extends MobileViTPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +// TODO: MobileViTForSemanticSegmentation + +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class OwlViTPreTrainedModel extends PreTrainedModel { } +class OwlViTModel extends OwlViTPreTrainedModel { } +class OwlViTForObjectDetection extends OwlViTPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class Owlv2PreTrainedModel extends PreTrainedModel { } +class Owlv2Model extends Owlv2PreTrainedModel { } +class Owlv2ForObjectDetection extends Owlv2PreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Beit Models +class BeitPreTrainedModel extends PreTrainedModel { } +class BeitModel extends BeitPreTrainedModel { } +class BeitForImageClassification extends BeitPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class DetrPreTrainedModel extends PreTrainedModel { } +class DetrModel extends DetrPreTrainedModel { } +class DetrForObjectDetection extends DetrPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new DetrObjectDetectionOutput(await super._call(model_inputs)); + } +} + +class DetrForSegmentation extends DetrPreTrainedModel { + /** + * Runs the model with the provided inputs + * @param {Object} model_inputs Model inputs + * @returns {Promise} Object containing segmentation outputs + */ + async _call(model_inputs) { + return new DetrSegmentationOutput(await super._call(model_inputs)); + } +} + +class DetrObjectDetectionOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Classification logits (including no-object) for all queries. + * @param {Tensor} output.pred_boxes Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). + * These values are normalized in [0, 1], relative to the size of each individual image in the batch (disregarding possible padding). + */ + constructor({ logits, pred_boxes }) { + super(); + this.logits = logits; + this.pred_boxes = pred_boxes; + } +} + +class DetrSegmentationOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits The output logits of the model. + * @param {Tensor} output.pred_boxes Predicted boxes. + * @param {Tensor} output.pred_masks Predicted masks. + */ + constructor({ logits, pred_boxes, pred_masks }) { + super(); + this.logits = logits; + this.pred_boxes = pred_boxes; + this.pred_masks = pred_masks; + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class TableTransformerPreTrainedModel extends PreTrainedModel { } + +/** + * The bare Table Transformer Model (consisting of a backbone and encoder-decoder Transformer) + * outputting raw hidden-states without any specific head on top. + */ +class TableTransformerModel extends TableTransformerPreTrainedModel { } + +/** + * Table Transformer Model (consisting of a backbone and encoder-decoder Transformer) + * with object detection heads on top, for tasks such as COCO detection. + */ +class TableTransformerForObjectDetection extends TableTransformerPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new TableTransformerObjectDetectionOutput(await super._call(model_inputs)); + } +} +class TableTransformerObjectDetectionOutput extends DetrObjectDetectionOutput { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class DeiTPreTrainedModel extends PreTrainedModel { } +class DeiTModel extends DeiTPreTrainedModel { } +class DeiTForImageClassification extends DeiTPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +/** + * An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. + */ +class ResNetPreTrainedModel extends PreTrainedModel { } + +/** + * The bare ResNet model outputting raw features without any specific head on top. + */ +class ResNetModel extends ResNetPreTrainedModel { } + +/** + * ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for ImageNet. + */ +class ResNetForImageClassification extends ResNetPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class SwinPreTrainedModel extends PreTrainedModel { } +class SwinModel extends SwinPreTrainedModel { } +class SwinForImageClassification extends SwinPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class Swin2SRPreTrainedModel extends PreTrainedModel { } + +/** + * The bare Swin2SR Model transformer outputting raw hidden-states without any specific head on top. + */ +class Swin2SRModel extends Swin2SRPreTrainedModel { } + +/** + * Swin2SR Model transformer with an upsampler head on top for image super resolution and restoration. + * + * **Example:** Super-resolution w/ `Xenova/swin2SR-classical-sr-x2-64`. + * + * ```javascript + * import { AutoProcessor, Swin2SRForImageSuperResolution, RawImage } from '@xenova/transformers'; + * + * // Load processor and model + * const model_id = 'Xenova/swin2SR-classical-sr-x2-64'; + * const processor = await AutoProcessor.from_pretrained(model_id); + * const model = await Swin2SRForImageSuperResolution.from_pretrained(model_id); + * + * // Prepare model inputs + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/butterfly.jpg'; + * const image = await RawImage.fromURL(url); + * const inputs = await processor(image); + * + * // Run model + * const outputs = await model(inputs); + * + * // Convert Tensor to RawImage + * const output = outputs.reconstruction.squeeze().clamp_(0, 1).mul_(255).round_().to('uint8'); + * const outputImage = RawImage.fromTensor(output); + * // RawImage { + * // data: Uint8Array(786432) [ 41, 31, 24, ... ], + * // width: 512, + * // height: 512, + * // channels: 3 + * // } + * ``` + */ +class Swin2SRForImageSuperResolution extends Swin2SRPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class DPTPreTrainedModel extends PreTrainedModel { } + +/** + * The bare DPT Model transformer outputting raw hidden-states without any specific head on top. + */ +class DPTModel extends DPTPreTrainedModel { } + +/** + * DPT Model with a depth estimation head on top (consisting of 3 convolutional layers) e.g. for KITTI, NYUv2. + * + * **Example:** Depth estimation w/ `Xenova/dpt-hybrid-midas`. + * ```javascript + * import { DPTForDepthEstimation, AutoProcessor, RawImage, interpolate, max } from '@xenova/transformers'; + * + * // Load model and processor + * const model_id = 'Xenova/dpt-hybrid-midas'; + * const model = await DPTForDepthEstimation.from_pretrained(model_id); + * const processor = await AutoProcessor.from_pretrained(model_id); + * + * // Load image from URL + * const url = 'http://images.cocodataset.org/val2017/000000039769.jpg'; + * const image = await RawImage.fromURL(url); + * + * // Prepare image for the model + * const inputs = await processor(image); + * + * // Run model + * const { predicted_depth } = await model(inputs); + * + * // Interpolate to original size + * const prediction = interpolate(predicted_depth, image.size.reverse(), 'bilinear', false); + * + * // Visualize the prediction + * const formatted = prediction.mul_(255 / max(prediction.data)[0]).to('uint8'); + * const depth = RawImage.fromTensor(formatted); + * // RawImage { + * // data: Uint8Array(307200) [ 85, 85, 84, ... ], + * // width: 640, + * // height: 480, + * // channels: 1 + * // } + * ``` + */ +class DPTForDepthEstimation extends DPTPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class DepthAnythingPreTrainedModel extends PreTrainedModel { } + +/** + * Depth Anything Model with a depth estimation head on top (consisting of 3 convolutional layers) e.g. for KITTI, NYUv2. + */ +class DepthAnythingForDepthEstimation extends DepthAnythingPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class GLPNPreTrainedModel extends PreTrainedModel { } + +/** + * The bare GLPN encoder (Mix-Transformer) outputting raw hidden-states without any specific head on top. + */ +class GLPNModel extends GLPNPreTrainedModel { } + +/** + * GLPN Model transformer with a lightweight depth estimation head on top e.g. for KITTI, NYUv2. + * + * **Example:** Depth estimation w/ `Xenova/glpn-kitti`. + * ```javascript + * import { GLPNForDepthEstimation, AutoProcessor, RawImage, interpolate, max } from '@xenova/transformers'; + * + * // Load model and processor + * const model_id = 'Xenova/glpn-kitti'; + * const model = await GLPNForDepthEstimation.from_pretrained(model_id); + * const processor = await AutoProcessor.from_pretrained(model_id); + * + * // Load image from URL + * const url = 'http://images.cocodataset.org/val2017/000000039769.jpg'; + * const image = await RawImage.fromURL(url); + * + * // Prepare image for the model + * const inputs = await processor(image); + * + * // Run model + * const { predicted_depth } = await model(inputs); + * + * // Interpolate to original size + * const prediction = interpolate(predicted_depth, image.size.reverse(), 'bilinear', false); + * + * // Visualize the prediction + * const formatted = prediction.mul_(255 / max(prediction.data)[0]).to('uint8'); + * const depth = RawImage.fromTensor(formatted); + * // RawImage { + * // data: Uint8Array(307200) [ 207, 169, 154, ... ], + * // width: 640, + * // height: 480, + * // channels: 1 + * // } + * ``` + */ +class GLPNForDepthEstimation extends GLPNPreTrainedModel { } +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class DonutSwinPreTrainedModel extends PreTrainedModel { } + +/** + * The bare Donut Swin Model transformer outputting raw hidden-states without any specific head on top. + * + * **Example:** Step-by-step Document Parsing. + * + * ```javascript + * import { AutoProcessor, AutoTokenizer, AutoModelForVision2Seq, RawImage } from '@xenova/transformers'; + * + * // Choose model to use + * const model_id = 'Xenova/donut-base-finetuned-cord-v2'; + * + * // Prepare image inputs + * const processor = await AutoProcessor.from_pretrained(model_id); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/receipt.png'; + * const image = await RawImage.read(url); + * const image_inputs = await processor(image); + * + * // Prepare decoder inputs + * const tokenizer = await AutoTokenizer.from_pretrained(model_id); + * const task_prompt = ''; + * const decoder_input_ids = tokenizer(task_prompt, { + * add_special_tokens: false, + * }).input_ids; + * + * // Create the model + * const model = await AutoModelForVision2Seq.from_pretrained(model_id); + * + * // Run inference + * const output = await model.generate(image_inputs.pixel_values, { + * decoder_input_ids, + * max_length: model.config.decoder.max_position_embeddings, + * }); + * + * // Decode output + * const decoded = tokenizer.batch_decode(output)[0]; + * // CINNAMON SUGAR 17,000 1 x 17,000 17,000 17,000 20,000 3,000 + * ``` + * + * **Example:** Step-by-step Document Visual Question Answering (DocVQA) + * + * ```javascript + * import { AutoProcessor, AutoTokenizer, AutoModelForVision2Seq, RawImage } from '@xenova/transformers'; + * + * // Choose model to use + * const model_id = 'Xenova/donut-base-finetuned-docvqa'; + * + * // Prepare image inputs + * const processor = await AutoProcessor.from_pretrained(model_id); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/invoice.png'; + * const image = await RawImage.read(url); + * const image_inputs = await processor(image); + * + * // Prepare decoder inputs + * const tokenizer = await AutoTokenizer.from_pretrained(model_id); + * const question = 'What is the invoice number?'; + * const task_prompt = `${question}`; + * const decoder_input_ids = tokenizer(task_prompt, { + * add_special_tokens: false, + * }).input_ids; + * + * // Create the model + * const model = await AutoModelForVision2Seq.from_pretrained(model_id); + * + * // Run inference + * const output = await model.generate(image_inputs.pixel_values, { + * decoder_input_ids, + * max_length: model.config.decoder.max_position_embeddings, + * }); + * + * // Decode output + * const decoded = tokenizer.batch_decode(output)[0]; + * // What is the invoice number? us-001 + * ``` + */ +class DonutSwinModel extends DonutSwinPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class ConvNextPreTrainedModel extends PreTrainedModel { } + +/** + * The bare ConvNext model outputting raw features without any specific head on top. + */ +class ConvNextModel extends ConvNextPreTrainedModel { } + +/** + * ConvNext Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for ImageNet. + */ +class ConvNextForImageClassification extends ConvNextPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class ConvNextV2PreTrainedModel extends PreTrainedModel { } + +/** + * The bare ConvNextV2 model outputting raw features without any specific head on top. + */ +class ConvNextV2Model extends ConvNextV2PreTrainedModel { } + +/** + * ConvNextV2 Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for ImageNet. + */ +class ConvNextV2ForImageClassification extends ConvNextV2PreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class Dinov2PreTrainedModel extends PreTrainedModel { } + +/** + * The bare DINOv2 Model transformer outputting raw hidden-states without any specific head on top. + */ +class Dinov2Model extends Dinov2PreTrainedModel { } + +/** + * Dinov2 Model transformer with an image classification head on top (a linear layer on top of the final hidden state of the [CLS] token) e.g. for ImageNet. + */ +class Dinov2ForImageClassification extends Dinov2PreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class YolosPreTrainedModel extends PreTrainedModel { } +class YolosModel extends YolosPreTrainedModel { } +class YolosForObjectDetection extends YolosPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new YolosObjectDetectionOutput(await super._call(model_inputs)); + } +} + +class YolosObjectDetectionOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Classification logits (including no-object) for all queries. + * @param {Tensor} output.pred_boxes Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). + * These values are normalized in [0, 1], relative to the size of each individual image in the batch (disregarding possible padding). + */ + constructor({ logits, pred_boxes }) { + super(); + this.logits = logits; + this.pred_boxes = pred_boxes; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class SamPreTrainedModel extends PreTrainedModel { } + +/** + * Segment Anything Model (SAM) for generating segmentation masks, given an input image + * and optional 2D location and bounding boxes. + * + * **Example:** Perform mask generation w/ `Xenova/sam-vit-base`. + * ```javascript + * import { SamModel, AutoProcessor, RawImage } from '@xenova/transformers'; + * + * const model = await SamModel.from_pretrained('Xenova/sam-vit-base'); + * const processor = await AutoProcessor.from_pretrained('Xenova/sam-vit-base'); + * + * const img_url = 'https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png'; + * const raw_image = await RawImage.read(img_url); + * const input_points = [[[450, 600]]] // 2D localization of a window + * + * const inputs = await processor(raw_image, input_points); + * const outputs = await model(inputs); + * + * const masks = await processor.post_process_masks(outputs.pred_masks, inputs.original_sizes, inputs.reshaped_input_sizes); + * // [ + * // Tensor { + * // dims: [ 1, 3, 1764, 2646 ], + * // type: 'bool', + * // data: Uint8Array(14002632) [ ... ], + * // size: 14002632 + * // } + * // ] + * const scores = outputs.iou_scores; + * // Tensor { + * // dims: [ 1, 1, 3 ], + * // type: 'float32', + * // data: Float32Array(3) [ + * // 0.8892380595207214, + * // 0.9311248064041138, + * // 0.983696699142456 + * // ], + * // size: 3 + * // } + * ``` + */ +class SamModel extends SamPreTrainedModel { + /** + * Creates a new instance of the `SamModel` class. + * @param {Object} config The configuration object specifying the hyperparameters and other model settings. + * @param {Object} vision_encoder The ONNX session containing the vision encoder model. + * @param {any} prompt_encoder_mask_decoder The ONNX session containing the prompt encoder and mask decoder model. + */ + constructor(config, vision_encoder, prompt_encoder_mask_decoder) { + super(config, vision_encoder); + this.prompt_encoder_mask_decoder = prompt_encoder_mask_decoder; + } + + /** + * Compute image embeddings and positional image embeddings, given the pixel values of an image. + * @param {Object} model_inputs Object containing the model inputs. + * @param {Tensor} model_inputs.pixel_values Pixel values obtained using a `SamProcessor`. + * @returns {Promise<{ image_embeddings: Tensor, image_positional_embeddings: Tensor }>} The image embeddings and positional image embeddings. + */ + async get_image_embeddings({ pixel_values }) { + // in: + // - pixel_values: tensor.float32[batch_size,3,1024,1024] + // + // out: + // - image_embeddings: tensor.float32[batch_size,256,64,64] + // - image_positional_embeddings: tensor.float32[batch_size,256,64,64] + return await encoderForward(this, { pixel_values }) + } + + /** + * @typedef {Object} SamModelInputs Object containing the model inputs. + * @property {Tensor} pixel_values Pixel values as a Tensor with shape `(batch_size, num_channels, height, width)`. + * These can be obtained using a `SamProcessor`. + * @property {Tensor} input_points Input 2D spatial points with shape `(batch_size, num_points, 2)`. + * This is used by the prompt encoder to encode the prompt. + * @property {Tensor} [input_labels] Input labels for the points, as a Tensor of shape `(batch_size, point_batch_size, num_points)`. + * This is used by the prompt encoder to encode the prompt. There are 4 types of labels: + * - `1`: the point is a point that contains the object of interest + * - `0`: the point is a point that does not contain the object of interest + * - `-1`: the point corresponds to the background + * - `-10`: the point is a padding point, thus should be ignored by the prompt encoder + * @property {Tensor} [image_embeddings] Image embeddings used by the mask decoder. + * @property {Tensor} [image_positional_embeddings] Image positional embeddings used by the mask decoder. + */ + + /** + * @param {SamModelInputs} model_inputs Object containing the model inputs. + * @returns {Promise} The output of the model. + */ + async forward(model_inputs) { + if (!model_inputs.image_embeddings || !model_inputs.image_positional_embeddings) { + // Compute the image embeddings if they are missing + model_inputs = { + ...model_inputs, + ...(await this.get_image_embeddings(model_inputs)) + } + } + + if (!model_inputs.input_labels) { + // Set default input labels if they are missing + const shape = model_inputs.input_points.dims.slice(0, -1); + const numElements = shape.reduce((a, b) => a * b, 1); + model_inputs.input_labels = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor( + 'int64', + new BigInt64Array(numElements).fill(1n), + shape + ); + } + + // Returns: + // - iou_scores: tensor.float32[batch_size,point_batch_size,3] + // - pred_masks: tensor.float32[batch_size,point_batch_size,3,256,256] + return await sessionRun(this.prompt_encoder_mask_decoder, { + input_points: model_inputs.input_points, + input_labels: model_inputs.input_labels, + image_embeddings: model_inputs.image_embeddings, + image_positional_embeddings: model_inputs.image_positional_embeddings, + }); + } + + /** + * Runs the model with the provided inputs + * @param {Object} model_inputs Model inputs + * @returns {Promise} Object containing segmentation outputs + */ + async _call(model_inputs) { + return new SamImageSegmentationOutput(await super._call(model_inputs)); + } +} + + +/** + * Base class for Segment-Anything model's output. + */ +class SamImageSegmentationOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.iou_scores The output logits of the model. + * @param {Tensor} output.pred_masks Predicted boxes. + */ + constructor({ iou_scores, pred_masks }) { + super(); + this.iou_scores = iou_scores; + this.pred_masks = pred_masks; + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// MarianMT models +class MarianPreTrainedModel extends PreTrainedModel { }; + +class MarianModel extends MarianPreTrainedModel { } + +class MarianMTModel extends MarianPreTrainedModel { + + /** + * Creates a new instance of the `MarianMTModel` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {any} decoder_merged_session + * @param {any} generation_config + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// M2M100 models +class M2M100PreTrainedModel extends PreTrainedModel { }; + +class M2M100Model extends M2M100PreTrainedModel { } + +class M2M100ForConditionalGeneration extends M2M100PreTrainedModel { + + /** + * Creates a new instance of the `M2M100ForConditionalGeneration` class. + * @param {Object} config The model configuration object. + * @param {Object} session The ONNX session object. + * @param {any} decoder_merged_session + * @param {any} generation_config + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.d_model / this.num_encoder_heads; + } + +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Wav2Vec2 models +class Wav2Vec2PreTrainedModel extends PreTrainedModel { }; + +/** + * The bare Wav2Vec2 Model transformer outputting raw hidden-states without any specific head on top. + * + * **Example:** Load and run a `Wav2Vec2Model` for feature extraction. + * + * ```javascript + * import { AutoProcessor, AutoModel, read_audio } from '@xenova/transformers'; + * + * // Read and preprocess audio + * const processor = await AutoProcessor.from_pretrained('Xenova/mms-300m'); + * const audio = await read_audio('https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac', 16000); + * const inputs = await processor(audio); + * + * // Run model with inputs + * const model = await AutoModel.from_pretrained('Xenova/mms-300m'); + * const output = await model(inputs); + * // { + * // last_hidden_state: Tensor { + * // dims: [ 1, 1144, 1024 ], + * // type: 'float32', + * // data: Float32Array(1171456) [ ... ], + * // size: 1171456 + * // } + * // } + * ``` + */ +class Wav2Vec2Model extends Wav2Vec2PreTrainedModel { } + +class Wav2Vec2ForCTC extends Wav2Vec2PreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +class Wav2Vec2ForSequenceClassification extends Wav2Vec2PreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * Wav2Vec2 Model with a frame classification head on top for tasks like Speaker Diarization. + */ +class Wav2Vec2ForAudioFrameClassification extends Wav2Vec2PreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// UniSpeech models +class UniSpeechPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare UniSpeech Model transformer outputting raw hidden-states without any specific head on top. + */ +class UniSpeechModel extends UniSpeechPreTrainedModel { } + +/** + * UniSpeech Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). + */ +class UniSpeechForCTC extends UniSpeechPreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +/** + * UniSpeech Model with a sequence classification head on top (a linear layer over the pooled output). + */ +class UniSpeechForSequenceClassification extends UniSpeechPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// UniSpeechSat models +class UniSpeechSatPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare UniSpeechSat Model transformer outputting raw hidden-states without any specific head on top. + */ +class UniSpeechSatModel extends UniSpeechSatPreTrainedModel { } + +/** + * UniSpeechSat Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). + */ +class UniSpeechSatForCTC extends UniSpeechSatPreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +/** + * UniSpeechSat Model with a sequence classification head on top (a linear layer over the pooled output). + */ +class UniSpeechSatForSequenceClassification extends UniSpeechSatPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * UniSpeechSat Model with a frame classification head on top for tasks like Speaker Diarization. + */ +class UniSpeechSatForAudioFrameClassification extends UniSpeechSatPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Wav2Vec2Bert models +class Wav2Vec2BertPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare Wav2Vec2Bert Model transformer outputting raw hidden-states without any specific head on top. + */ +class Wav2Vec2BertModel extends Wav2Vec2BertPreTrainedModel { } + +/** + * Wav2Vec2Bert Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). + */ +class Wav2Vec2BertForCTC extends Wav2Vec2BertPreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_features Float values of input mel-spectrogram. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +/** + * Wav2Vec2Bert Model with a sequence classification head on top (a linear layer over the pooled output). + */ +class Wav2Vec2BertForSequenceClassification extends Wav2Vec2BertPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Hubert models +class HubertPreTrainedModel extends PreTrainedModel { } + +/** + * The bare Hubert Model transformer outputting raw hidden-states without any specific head on top. + * + * **Example:** Load and run a `HubertModel` for feature extraction. + * + * ```javascript + * import { AutoProcessor, AutoModel, read_audio } from '@xenova/transformers'; + * + * // Read and preprocess audio + * const processor = await AutoProcessor.from_pretrained('Xenova/hubert-base-ls960'); + * const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav', 16000); + * const inputs = await processor(audio); + * + * // Load and run model with inputs + * const model = await AutoModel.from_pretrained('Xenova/hubert-base-ls960'); + * const output = await model(inputs); + * // { + * // last_hidden_state: Tensor { + * // dims: [ 1, 549, 768 ], + * // type: 'float32', + * // data: Float32Array(421632) [0.0682469978928566, 0.08104046434164047, -0.4975186586380005, ...], + * // size: 421632 + * // } + * // } + * ``` + */ +class HubertModel extends Wav2Vec2PreTrainedModel { } + +/** + * Hubert Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). + */ +class HubertForCTC extends Wav2Vec2PreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +/** + * Hubert Model with a sequence classification head on top (a linear layer over the pooled output) for tasks like SUPERB Keyword Spotting. + */ +class HubertForSequenceClassification extends Wav2Vec2PreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// WavLM models +/** + * An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. + */ +class WavLMPreTrainedModel extends PreTrainedModel { }; + +/** + * The bare WavLM Model transformer outputting raw hidden-states without any specific head on top. + * + * **Example:** Load and run a `WavLMModel` for feature extraction. + * + * ```javascript + * import { AutoProcessor, AutoModel, read_audio } from '@xenova/transformers'; + * + * // Read and preprocess audio + * const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base'); + * const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav', 16000); + * const inputs = await processor(audio); + * + * // Run model with inputs + * const model = await AutoModel.from_pretrained('Xenova/wavlm-base'); + * const output = await model(inputs); + * // { + * // last_hidden_state: Tensor { + * // dims: [ 1, 549, 768 ], + * // type: 'float32', + * // data: Float32Array(421632) [-0.349443256855011, -0.39341306686401367, 0.022836603224277496, ...], + * // size: 421632 + * // } + * // } + * ``` + */ +class WavLMModel extends WavLMPreTrainedModel { } + +/** + * WavLM Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). + */ +class WavLMForCTC extends WavLMPreTrainedModel { + /** + * @param {Object} model_inputs + * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. + * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] + */ + async _call(model_inputs) { + return new CausalLMOutput(await super._call(model_inputs)); + } +} + +/** + * WavLM Model with a sequence classification head on top (a linear layer over the pooled output). + */ +class WavLMForSequenceClassification extends WavLMPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} + +/** + * WavLM Model with an XVector feature extraction head on top for tasks like Speaker Verification. + * + * **Example:** Extract speaker embeddings with `WavLMForXVector`. + * ```javascript + * import { AutoProcessor, AutoModel, read_audio } from '@xenova/transformers'; + * + * // Read and preprocess audio + * const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base-plus-sv'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const audio = await read_audio(url, 16000); + * const inputs = await processor(audio); + * + * // Run model with inputs + * const model = await AutoModel.from_pretrained('Xenova/wavlm-base-plus-sv'); + * const outputs = await model(inputs); + * // { + * // logits: Tensor { + * // dims: [ 1, 512 ], + * // type: 'float32', + * // data: Float32Array(512) [0.5847219228744507, ...], + * // size: 512 + * // }, + * // embeddings: Tensor { + * // dims: [ 1, 512 ], + * // type: 'float32', + * // data: Float32Array(512) [-0.09079201519489288, ...], + * // size: 512 + * // } + * // } + * ``` + */ +class WavLMForXVector extends WavLMPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits and speaker embeddings. + */ + async _call(model_inputs) { + return new XVectorOutput(await super._call(model_inputs)); + } +} + +/** + * WavLM Model with a frame classification head on top for tasks like Speaker Diarization. + * + * **Example:** Perform speaker diarization with `WavLMForAudioFrameClassification`. + * ```javascript + * import { AutoProcessor, AutoModelForAudioFrameClassification, read_audio } from '@xenova/transformers'; + * + * // Read and preprocess audio + * const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base-plus-sd'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const audio = await read_audio(url, 16000); + * const inputs = await processor(audio); + * + * // Run model with inputs + * const model = await AutoModelForAudioFrameClassification.from_pretrained('Xenova/wavlm-base-plus-sd'); + * const { logits } = await model(inputs); + * // { + * // logits: Tensor { + * // dims: [ 1, 549, 2 ], // [batch_size, num_frames, num_speakers] + * // type: 'float32', + * // data: Float32Array(1098) [-3.5301010608673096, ...], + * // size: 1098 + * // } + * // } + * + * const labels = logits[0].sigmoid().tolist().map( + * frames => frames.map(speaker => speaker > 0.5 ? 1 : 0) + * ); + * console.log(labels); // labels is a one-hot array of shape (num_frames, num_speakers) + * // [ + * // [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], + * // [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], + * // [0, 0], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], + * // ... + * // ] + * ``` + */ +class WavLMForAudioFrameClassification extends WavLMPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} An object containing the model's output logits for sequence classification. + */ + async _call(model_inputs) { + return new TokenClassifierOutput(await super._call(model_inputs)); + } +} + +////////////////////////////////////////////////// +// SpeechT5 models +/** + * An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. + */ +class SpeechT5PreTrainedModel extends PreTrainedModel { }; + +/** + * The bare SpeechT5 Encoder-Decoder Model outputting raw hidden-states without any specific pre- or post-nets. + */ +class SpeechT5Model extends SpeechT5PreTrainedModel { }; + +/** + * SpeechT5 Model with a speech encoder and a text decoder. + * + * **Example:** Generate speech from text with `SpeechT5ForSpeechToText`. + * ```javascript + * import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@xenova/transformers'; + * + * // Load the tokenizer and processor + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/speecht5_tts'); + * const processor = await AutoProcessor.from_pretrained('Xenova/speecht5_tts'); + * + * // Load the models + * // NOTE: We use the unquantized versions as they are more accurate + * const model = await SpeechT5ForTextToSpeech.from_pretrained('Xenova/speecht5_tts', { quantized: false }); + * const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { quantized: false }); + * + * // Load speaker embeddings from URL + * const speaker_embeddings_data = new Float32Array( + * await (await fetch('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin')).arrayBuffer() + * ); + * const speaker_embeddings = new Tensor( + * 'float32', + * speaker_embeddings_data, + * [1, speaker_embeddings_data.length] + * ) + * + * // Run tokenization + * const { input_ids } = tokenizer('Hello, my dog is cute'); + * + * // Generate waveform + * const { waveform } = await model.generate_speech(input_ids, speaker_embeddings, { vocoder }); + * console.log(waveform) + * // Tensor { + * // dims: [ 26112 ], + * // type: 'float32', + * // size: 26112, + * // data: Float32Array(26112) [ -0.00043630177970044315, -0.00018082228780258447, ... ], + * // } + * ``` + */ +class SpeechT5ForSpeechToText extends SpeechT5PreTrainedModel { } + +/** + * SpeechT5 Model with a text encoder and a speech decoder. + */ +class SpeechT5ForTextToSpeech extends SpeechT5PreTrainedModel { + + /** + * Creates a new instance of the `SpeechT5ForTextToSpeech` class. + * @param {Object} config The model configuration. + * @param {any} session session for the model. + * @param {any} decoder_merged_session session for the decoder. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, decoder_merged_session, generation_config) { + super(config, session); + this.decoder_merged_session = decoder_merged_session; + this.generation_config = generation_config; + + this.num_decoder_layers = this.config.decoder_layers; + this.num_decoder_heads = this.config.decoder_attention_heads; + this.decoder_dim_kv = this.config.hidden_size / this.num_decoder_heads; + + this.num_encoder_layers = this.config.encoder_layers; + this.num_encoder_heads = this.config.encoder_attention_heads; + this.encoder_dim_kv = this.config.hidden_size / this.num_encoder_heads; + } + + /** + * @typedef {Object} SpeechOutput + * @property {Tensor} [spectrogram] The predicted log-mel spectrogram of shape + * `(output_sequence_length, config.num_mel_bins)`. Returned when no `vocoder` is provided + * @property {Tensor} [waveform] The predicted waveform of shape `(num_frames,)`. Returned when a `vocoder` is provided. + * @property {Tensor} [cross_attentions] The outputs of the decoder's cross-attention layers of shape + * `(config.decoder_layers, config.decoder_attention_heads, output_sequence_length, input_sequence_length)`. returned when `output_cross_attentions` is `true`. + */ + + /** + * Converts a sequence of input tokens into a sequence of mel spectrograms, which are subsequently turned into a speech waveform using a vocoder. + * @param {Tensor} input_values Indices of input sequence tokens in the vocabulary. + * @param {Tensor} speaker_embeddings Tensor containing the speaker embeddings. + * @param {Object} options Optional parameters for generating speech. + * @param {number} [options.threshold=0.5] The generated sequence ends when the predicted stop token probability exceeds this value. + * @param {number} [options.minlenratio=0.0] Used to calculate the minimum required length for the output sequence. + * @param {number} [options.maxlenratio=20.0] Used to calculate the maximum allowed length for the output sequence. + * @param {Object} [options.vocoder=null] The vocoder that converts the mel spectrogram into a speech waveform. If `null`, the output is the mel spectrogram. + * @param {boolean} [options.output_cross_attentions=false] Whether or not to return the attentions tensors of the decoder's cross-attention layers. + * @returns {Promise} A promise which resolves to an object containing the spectrogram, waveform, and cross-attention tensors. + */ + async generate_speech(input_values, speaker_embeddings, { + threshold = 0.5, + minlenratio = 0.0, + maxlenratio = 20.0, + vocoder = null, + // output_cross_attentions = false, // TODO add + } = {}) { + + const model_inputs = { + input_ids: input_values + } + + const { encoder_outputs, encoder_attention_mask } = await encoderForward(this, model_inputs); + + const r = encoder_outputs.dims[1] / this.config.reduction_factor; + const maxlen = Math.floor(r * maxlenratio); + const minlen = Math.floor(r * minlenratio); + + const num_mel_bins = this.config.num_mel_bins; + + let spectrogramParts = []; + let past_key_values = null; + let decoder_outputs = null; + let idx = 0; + + while (true) { + ++idx; + + const use_cache_branch = boolTensor(!!decoder_outputs); + let output_sequence; + if (decoder_outputs) { + output_sequence = decoder_outputs.output_sequence_out; + } else { + output_sequence = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.Tensor( + 'float32', + new Float32Array(num_mel_bins), + [1, 1, num_mel_bins], + ) + } + let decoderFeeds = { + use_cache_branch, + output_sequence, + encoder_attention_mask: encoder_attention_mask, + speaker_embeddings: speaker_embeddings, + encoder_hidden_states: encoder_outputs, + }; + + this.addPastKeyValues(decoderFeeds, past_key_values); + decoder_outputs = await sessionRun(this.decoder_merged_session, decoderFeeds); + past_key_values = this.getPastKeyValues(decoder_outputs, past_key_values); + + const { prob, spectrum } = decoder_outputs; + spectrogramParts.push(spectrum); + + if (idx >= minlen && ( + // Finished when stop token or maximum length is reached. + Array.from(prob.data).filter(p => p >= threshold).length > 0 || idx >= maxlen + )) { + break; + } + } + + const spectrogram = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_4__.cat)(spectrogramParts); + const { waveform } = await sessionRun(vocoder.session, { spectrogram }); + + return { + spectrogram, + waveform, + // cross_attentions: null, // TODO add + } + } +} + +/** + * HiFi-GAN vocoder. + * + * See [SpeechT5ForSpeechToText](./models#module_models.SpeechT5ForSpeechToText) for example usage. + */ +class SpeechT5HifiGan extends PreTrainedModel { + main_input_name = 'spectrogram'; +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// TrOCR models +class TrOCRPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `TrOCRPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id; + + this.num_encoder_layers = this.num_decoder_layers = this.config.decoder_layers; + this.num_encoder_heads = this.num_decoder_heads = this.config.decoder_attention_heads; + this.encoder_dim_kv = this.decoder_dim_kv = this.config.d_model / this.num_decoder_heads; + } +} + +/** + * The TrOCR Decoder with a language modeling head. + */ +class TrOCRForCausalLM extends TrOCRPreTrainedModel { } + +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Mistral models +/** + * The bare Mistral Model outputting raw hidden-states without any specific head on top. + */ +class MistralPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `MistralPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_key_value_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.config.num_attention_heads; + } +} + +class MistralModel extends MistralPreTrainedModel { } + +class MistralForCausalLM extends MistralPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Starcoder2 models +/** + * The bare Starcoder2 Model outputting raw hidden-states without any specific head on top. + */ +class Starcoder2PreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `Starcoder2PreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_key_value_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.config.num_attention_heads; + } +} + +class Starcoder2Model extends Starcoder2PreTrainedModel { } + +class Starcoder2ForCausalLM extends Starcoder2PreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// Falcon models +/** + * The bare Falcon Model outputting raw hidden-states without any specific head on top. + */ +class FalconPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `FalconPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_attention_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.config.num_attention_heads; + } +} + +class FalconModel extends FalconPreTrainedModel { } + +class FalconForCausalLM extends FalconPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// CLAP models +class ClapPreTrainedModel extends PreTrainedModel { } + +class ClapModel extends ClapPreTrainedModel { } + +/** + * CLAP Text Model with a projection layer on top (a linear layer on top of the pooled output). + * + * **Example:** Compute text embeddings with `ClapTextModelWithProjection`. + * + * ```javascript + * import { AutoTokenizer, ClapTextModelWithProjection } from '@xenova/transformers'; + * + * // Load tokenizer and text model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clap-htsat-unfused'); + * const text_model = await ClapTextModelWithProjection.from_pretrained('Xenova/clap-htsat-unfused'); + * + * // Run tokenization + * const texts = ['a sound of a cat', 'a sound of a dog']; + * const text_inputs = tokenizer(texts, { padding: true, truncation: true }); + * + * // Compute embeddings + * const { text_embeds } = await text_model(text_inputs); + * // Tensor { + * // dims: [ 2, 512 ], + * // type: 'float32', + * // data: Float32Array(1024) [ ... ], + * // size: 1024 + * // } + * ``` + */ +class ClapTextModelWithProjection extends ClapPreTrainedModel { + + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'text_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} + +/** + * CLAP Audio Model with a projection layer on top (a linear layer on top of the pooled output). + * + * **Example:** Compute audio embeddings with `ClapAudioModelWithProjection`. + * + * ```javascript + * import { AutoProcessor, ClapAudioModelWithProjection, read_audio } from '@xenova/transformers'; + * + * // Load processor and audio model + * const processor = await AutoProcessor.from_pretrained('Xenova/clap-htsat-unfused'); + * const audio_model = await ClapAudioModelWithProjection.from_pretrained('Xenova/clap-htsat-unfused'); + * + * // Read audio and run processor + * const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cat_meow.wav'); + * const audio_inputs = await processor(audio); + * + * // Compute embeddings + * const { audio_embeds } = await audio_model(audio_inputs); + * // Tensor { + * // dims: [ 1, 512 ], + * // type: 'float32', + * // data: Float32Array(512) [ ... ], + * // size: 512 + * // } + * ``` + */ +class ClapAudioModelWithProjection extends ClapPreTrainedModel { + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, options = {}) { + // Update default model file name if not provided + options.model_file_name ??= 'audio_model'; + return super.from_pretrained(pretrained_model_name_or_path, options); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// VITS models +class VitsPreTrainedModel extends PreTrainedModel { } + +/** + * The complete VITS model, for text-to-speech synthesis. + * + * **Example:** Generate speech from text with `VitsModel`. + * ```javascript + * import { AutoTokenizer, VitsModel } from '@xenova/transformers'; + * + * // Load the tokenizer and model + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/mms-tts-eng'); + * const model = await VitsModel.from_pretrained('Xenova/mms-tts-eng'); + * + * // Run tokenization + * const inputs = tokenizer('I love transformers'); + * + * // Generate waveform + * const { waveform } = await model(inputs); + * // Tensor { + * // dims: [ 1, 35328 ], + * // type: 'float32', + * // data: Float32Array(35328) [ ... ], + * // size: 35328, + * // } + * ``` + */ +class VitsModel extends VitsPreTrainedModel { + /** + * Calls the model on new inputs. + * @param {Object} model_inputs The inputs to the model. + * @returns {Promise} The outputs for the VITS model. + */ + async _call(model_inputs) { + return new VitsModelOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// Segformer models +class SegformerPreTrainedModel extends PreTrainedModel { } + +/** + * The bare SegFormer encoder (Mix-Transformer) outputting raw hidden-states without any specific head on top. + */ +class SegformerModel extends SegformerPreTrainedModel { } + +/** + * SegFormer Model transformer with an image classification head on top (a linear layer on top of the final hidden states) e.g. for ImageNet. + */ +class SegformerForImageClassification extends SegformerPreTrainedModel { } + +/** + * SegFormer Model transformer with an all-MLP decode head on top e.g. for ADE20k, CityScapes. + */ +class SegformerForSemanticSegmentation extends SegformerPreTrainedModel { } + +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +// StableLm models +class StableLmPreTrainedModel extends PreTrainedModel { + /** + * Creates a new instance of the `StableLmPreTrainedModel` class. + * @param {Object} config The configuration of the model. + * @param {any} session The ONNX session containing the model weights. + * @param {GenerationConfig} generation_config The generation configuration. + */ + constructor(config, session, generation_config) { + super(config, session); + this.generation_config = generation_config; + + // config doesn't contain pad_token_id, so we assume it is the eos_token_id + this.config.pad_token_id = this.config.eos_token_id + + this.num_heads = this.config.num_attention_heads; + this.num_layers = this.config.num_hidden_layers; + this.dim_kv = this.config.hidden_size / this.num_heads; + } +} + +/** + * The bare StableLm Model transformer outputting raw hidden-states without any specific head on top. + */ +class StableLmModel extends StableLmPreTrainedModel { } + +/** + * StableLm Model with a `language modeling` head on top for Causal Language Modeling (with past). + */ +class StableLmForCausalLM extends StableLmPreTrainedModel { } +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +class EfficientNetPreTrainedModel extends PreTrainedModel { } + +/** + * The bare EfficientNet model outputting raw features without any specific head on top. + */ +class EfficientNetModel extends EfficientNetPreTrainedModel { } + +/** + * EfficientNet Model with an image classification head on top (a linear layer on top of the pooled features). + */ +class EfficientNetForImageClassification extends EfficientNetPreTrainedModel { + /** + * @param {any} model_inputs + */ + async _call(model_inputs) { + return new SequenceClassifierOutput(await super._call(model_inputs)); + } +} +////////////////////////////////////////////////// + + +////////////////////////////////////////////////// +// AutoModels, used to simplify construction of PreTrainedModels +// (uses config to instantiate correct class) + +/** + * Base class of all AutoModels. Contains the `from_pretrained` function + * which is used to instantiate pretrained models. + */ +class PretrainedMixin { + /** + * Mapping from model type to model class. + * @type {Map[]} + */ + static MODEL_CLASS_MAPPINGS = null; + + /** + * Whether to attempt to instantiate the base class (`PretrainedModel`) if + * the model type is not found in the mapping. + */ + static BASE_IF_FAIL = false; + + + /** @type {PreTrainedModel.from_pretrained} */ + static async from_pretrained(pretrained_model_name_or_path, { + quantized = true, + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + model_file_name = null, + } = {}) { + + let options = { + quantized, + progress_callback, + config, + cache_dir, + local_files_only, + revision, + model_file_name, + } + config = await _configs_js__WEBPACK_IMPORTED_MODULE_0__.AutoConfig.from_pretrained(pretrained_model_name_or_path, options); + if (!options.config) { + // If no config was passed, reuse this config for future processing + options.config = config; + } + + if (!this.MODEL_CLASS_MAPPINGS) { + throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: " + this.name); + } + + for (let MODEL_CLASS_MAPPING of this.MODEL_CLASS_MAPPINGS) { + const modelInfo = MODEL_CLASS_MAPPING.get(config.model_type); + if (!modelInfo) { + continue; // Item not found in this mapping + } + return await modelInfo[1].from_pretrained(pretrained_model_name_or_path, options); + } + + if (this.BASE_IF_FAIL) { + console.warn(`Unknown model class "${config.model_type}", attempting to construct from base class.`); + return await PreTrainedModel.from_pretrained(pretrained_model_name_or_path, options); + } else { + throw Error(`Unsupported model type: ${config.model_type}`) + } + } +} + +const MODEL_MAPPING_NAMES_ENCODER_ONLY = new Map([ + ['bert', ['BertModel', BertModel]], + ['nomic_bert', ['NomicBertModel', NomicBertModel]], + ['roformer', ['RoFormerModel', RoFormerModel]], + ['electra', ['ElectraModel', ElectraModel]], + ['esm', ['EsmModel', EsmModel]], + ['convbert', ['ConvBertModel', ConvBertModel]], + ['camembert', ['CamembertModel', CamembertModel]], + ['deberta', ['DebertaModel', DebertaModel]], + ['deberta-v2', ['DebertaV2Model', DebertaV2Model]], + ['mpnet', ['MPNetModel', MPNetModel]], + ['albert', ['AlbertModel', AlbertModel]], + ['distilbert', ['DistilBertModel', DistilBertModel]], + ['roberta', ['RobertaModel', RobertaModel]], + ['xlm', ['XLMModel', XLMModel]], + ['xlm-roberta', ['XLMRobertaModel', XLMRobertaModel]], + ['clap', ['ClapModel', ClapModel]], + ['clip', ['CLIPModel', CLIPModel]], + ['clipseg', ['CLIPSegModel', CLIPSegModel]], + ['chinese_clip', ['ChineseCLIPModel', ChineseCLIPModel]], + ['siglip', ['SiglipModel', SiglipModel]], + ['mobilebert', ['MobileBertModel', MobileBertModel]], + ['squeezebert', ['SqueezeBertModel', SqueezeBertModel]], + ['wav2vec2', ['Wav2Vec2Model', Wav2Vec2Model]], + ['wav2vec2-bert', ['Wav2Vec2BertModel', Wav2Vec2BertModel]], + ['unispeech', ['UniSpeechModel', UniSpeechModel]], + ['unispeech-sat', ['UniSpeechSatModel', UniSpeechSatModel]], + ['hubert', ['HubertModel', HubertModel]], + ['wavlm', ['WavLMModel', WavLMModel]], + ['audio-spectrogram-transformer', ['ASTModel', ASTModel]], + ['vits', ['VitsModel', VitsModel]], + + ['detr', ['DetrModel', DetrModel]], + ['table-transformer', ['TableTransformerModel', TableTransformerModel]], + ['vit', ['ViTModel', ViTModel]], + ['mobilevit', ['MobileViTModel', MobileViTModel]], + ['owlvit', ['OwlViTModel', OwlViTModel]], + ['owlv2', ['Owlv2Model', Owlv2Model]], + ['beit', ['BeitModel', BeitModel]], + ['deit', ['DeiTModel', DeiTModel]], + ['convnext', ['ConvNextModel', ConvNextModel]], + ['convnextv2', ['ConvNextV2Model', ConvNextV2Model]], + ['dinov2', ['Dinov2Model', Dinov2Model]], + ['resnet', ['ResNetModel', ResNetModel]], + ['swin', ['SwinModel', SwinModel]], + ['swin2sr', ['Swin2SRModel', Swin2SRModel]], + ['donut-swin', ['DonutSwinModel', DonutSwinModel]], + ['yolos', ['YolosModel', YolosModel]], + ['dpt', ['DPTModel', DPTModel]], + ['glpn', ['GLPNModel', GLPNModel]], + + ['hifigan', ['SpeechT5HifiGan', SpeechT5HifiGan]], + ['efficientnet', ['EfficientNetModel', EfficientNetModel]], + +]); + +const MODEL_MAPPING_NAMES_ENCODER_DECODER = new Map([ + ['t5', ['T5Model', T5Model]], + ['longt5', ['LongT5Model', LongT5Model]], + ['mt5', ['MT5Model', MT5Model]], + ['bart', ['BartModel', BartModel]], + ['mbart', ['MBartModel', MBartModel]], + ['marian', ['MarianModel', MarianModel]], + ['whisper', ['WhisperModel', WhisperModel]], + ['m2m_100', ['M2M100Model', M2M100Model]], + ['blenderbot', ['BlenderbotModel', BlenderbotModel]], + ['blenderbot-small', ['BlenderbotSmallModel', BlenderbotSmallModel]], +]); + + +const MODEL_MAPPING_NAMES_DECODER_ONLY = new Map([ + ['bloom', ['BloomModel', BloomModel]], + ['gpt2', ['GPT2Model', GPT2Model]], + ['gptj', ['GPTJModel', GPTJModel]], + ['gpt_bigcode', ['GPTBigCodeModel', GPTBigCodeModel]], + ['gpt_neo', ['GPTNeoModel', GPTNeoModel]], + ['gpt_neox', ['GPTNeoXModel', GPTNeoXModel]], + ['codegen', ['CodeGenModel', CodeGenModel]], + ['llama', ['LlamaModel', LlamaModel]], + ['qwen2', ['Qwen2Model', Qwen2Model]], + ['phi', ['PhiModel', PhiModel]], + ['mpt', ['MptModel', MptModel]], + ['opt', ['OPTModel', OPTModel]], + ['mistral', ['MistralModel', MistralModel]], + ['starcoder2', ['Starcoder2Model', Starcoder2Model]], + ['falcon', ['FalconModel', FalconModel]], +]); + +const MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = new Map([ + ['speecht5', ['SpeechT5ForSpeechToText', SpeechT5ForSpeechToText]], + ['whisper', ['WhisperForConditionalGeneration', WhisperForConditionalGeneration]], +]); + +const MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES = new Map([ + ['speecht5', ['SpeechT5ForTextToSpeech', SpeechT5ForTextToSpeech]], +]); + +const MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES = new Map([ + ['vits', ['VitsModel', VitsModel]], +]); + +const MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = new Map([ + ['bert', ['BertForSequenceClassification', BertForSequenceClassification]], + ['roformer', ['RoFormerForSequenceClassification', RoFormerForSequenceClassification]], + ['electra', ['ElectraForSequenceClassification', ElectraForSequenceClassification]], + ['esm', ['EsmForSequenceClassification', EsmForSequenceClassification]], + ['convbert', ['ConvBertForSequenceClassification', ConvBertForSequenceClassification]], + ['camembert', ['CamembertForSequenceClassification', CamembertForSequenceClassification]], + ['deberta', ['DebertaForSequenceClassification', DebertaForSequenceClassification]], + ['deberta-v2', ['DebertaV2ForSequenceClassification', DebertaV2ForSequenceClassification]], + ['mpnet', ['MPNetForSequenceClassification', MPNetForSequenceClassification]], + ['albert', ['AlbertForSequenceClassification', AlbertForSequenceClassification]], + ['distilbert', ['DistilBertForSequenceClassification', DistilBertForSequenceClassification]], + ['roberta', ['RobertaForSequenceClassification', RobertaForSequenceClassification]], + ['xlm', ['XLMForSequenceClassification', XLMForSequenceClassification]], + ['xlm-roberta', ['XLMRobertaForSequenceClassification', XLMRobertaForSequenceClassification]], + ['bart', ['BartForSequenceClassification', BartForSequenceClassification]], + ['mbart', ['MBartForSequenceClassification', MBartForSequenceClassification]], + ['mobilebert', ['MobileBertForSequenceClassification', MobileBertForSequenceClassification]], + ['squeezebert', ['SqueezeBertForSequenceClassification', SqueezeBertForSequenceClassification]], +]); + +const MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = new Map([ + ['bert', ['BertForTokenClassification', BertForTokenClassification]], + ['roformer', ['RoFormerForTokenClassification', RoFormerForTokenClassification]], + ['electra', ['ElectraForTokenClassification', ElectraForTokenClassification]], + ['esm', ['EsmForTokenClassification', EsmForTokenClassification]], + ['convbert', ['ConvBertForTokenClassification', ConvBertForTokenClassification]], + ['camembert', ['CamembertForTokenClassification', CamembertForTokenClassification]], + ['deberta', ['DebertaForTokenClassification', DebertaForTokenClassification]], + ['deberta-v2', ['DebertaV2ForTokenClassification', DebertaV2ForTokenClassification]], + ['mpnet', ['MPNetForTokenClassification', MPNetForTokenClassification]], + ['distilbert', ['DistilBertForTokenClassification', DistilBertForTokenClassification]], + ['roberta', ['RobertaForTokenClassification', RobertaForTokenClassification]], + ['xlm', ['XLMForTokenClassification', XLMForTokenClassification]], + ['xlm-roberta', ['XLMRobertaForTokenClassification', XLMRobertaForTokenClassification]], +]); + +const MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = new Map([ + ['t5', ['T5ForConditionalGeneration', T5ForConditionalGeneration]], + ['longt5', ['LongT5ForConditionalGeneration', LongT5ForConditionalGeneration]], + ['mt5', ['MT5ForConditionalGeneration', MT5ForConditionalGeneration]], + ['bart', ['BartForConditionalGeneration', BartForConditionalGeneration]], + ['mbart', ['MBartForConditionalGeneration', MBartForConditionalGeneration]], + ['marian', ['MarianMTModel', MarianMTModel]], + ['m2m_100', ['M2M100ForConditionalGeneration', M2M100ForConditionalGeneration]], + ['blenderbot', ['BlenderbotForConditionalGeneration', BlenderbotForConditionalGeneration]], + ['blenderbot-small', ['BlenderbotSmallForConditionalGeneration', BlenderbotSmallForConditionalGeneration]], +]); + +const MODEL_WITH_LM_HEAD_MAPPING_NAMES = new Map([ + ['bloom', ['BloomForCausalLM', BloomForCausalLM]], + ['gpt2', ['GPT2LMHeadModel', GPT2LMHeadModel]], + ['gptj', ['GPTJForCausalLM', GPTJForCausalLM]], + ['gpt_bigcode', ['GPTBigCodeForCausalLM', GPTBigCodeForCausalLM]], + ['gpt_neo', ['GPTNeoForCausalLM', GPTNeoForCausalLM]], + ['gpt_neox', ['GPTNeoXForCausalLM', GPTNeoXForCausalLM]], + ['codegen', ['CodeGenForCausalLM', CodeGenForCausalLM]], + ['llama', ['LlamaForCausalLM', LlamaForCausalLM]], + ['qwen2', ['Qwen2ForCausalLM', Qwen2ForCausalLM]], + ['phi', ['PhiForCausalLM', PhiForCausalLM]], + ['mpt', ['MptForCausalLM', MptForCausalLM]], + ['opt', ['OPTForCausalLM', OPTForCausalLM]], + ['mbart', ['MBartForCausalLM', MBartForCausalLM]], + ['mistral', ['MistralForCausalLM', MistralForCausalLM]], + ['starcoder2', ['Starcoder2ForCausalLM', Starcoder2ForCausalLM]], + ['falcon', ['FalconForCausalLM', FalconForCausalLM]], + ['trocr', ['TrOCRForCausalLM', TrOCRForCausalLM]], + ['stablelm', ['StableLmForCausalLM', StableLmForCausalLM]], +]); + +const MODEL_FOR_MASKED_LM_MAPPING_NAMES = new Map([ + ['bert', ['BertForMaskedLM', BertForMaskedLM]], + ['roformer', ['RoFormerForMaskedLM', RoFormerForMaskedLM]], + ['electra', ['ElectraForMaskedLM', ElectraForMaskedLM]], + ['esm', ['EsmForMaskedLM', EsmForMaskedLM]], + ['convbert', ['ConvBertForMaskedLM', ConvBertForMaskedLM]], + ['camembert', ['CamembertForMaskedLM', CamembertForMaskedLM]], + ['deberta', ['DebertaForMaskedLM', DebertaForMaskedLM]], + ['deberta-v2', ['DebertaV2ForMaskedLM', DebertaV2ForMaskedLM]], + ['mpnet', ['MPNetForMaskedLM', MPNetForMaskedLM]], + ['albert', ['AlbertForMaskedLM', AlbertForMaskedLM]], + ['distilbert', ['DistilBertForMaskedLM', DistilBertForMaskedLM]], + ['roberta', ['RobertaForMaskedLM', RobertaForMaskedLM]], + ['xlm', ['XLMWithLMHeadModel', XLMWithLMHeadModel]], + ['xlm-roberta', ['XLMRobertaForMaskedLM', XLMRobertaForMaskedLM]], + ['mobilebert', ['MobileBertForMaskedLM', MobileBertForMaskedLM]], + ['squeezebert', ['SqueezeBertForMaskedLM', SqueezeBertForMaskedLM]], +]); + +const MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = new Map([ + ['bert', ['BertForQuestionAnswering', BertForQuestionAnswering]], + ['roformer', ['RoFormerForQuestionAnswering', RoFormerForQuestionAnswering]], + ['electra', ['ElectraForQuestionAnswering', ElectraForQuestionAnswering]], + ['convbert', ['ConvBertForQuestionAnswering', ConvBertForQuestionAnswering]], + ['camembert', ['CamembertForQuestionAnswering', CamembertForQuestionAnswering]], + ['deberta', ['DebertaForQuestionAnswering', DebertaForQuestionAnswering]], + ['deberta-v2', ['DebertaV2ForQuestionAnswering', DebertaV2ForQuestionAnswering]], + ['mpnet', ['MPNetForQuestionAnswering', MPNetForQuestionAnswering]], + ['albert', ['AlbertForQuestionAnswering', AlbertForQuestionAnswering]], + ['distilbert', ['DistilBertForQuestionAnswering', DistilBertForQuestionAnswering]], + ['roberta', ['RobertaForQuestionAnswering', RobertaForQuestionAnswering]], + ['xlm', ['XLMForQuestionAnswering', XLMForQuestionAnswering]], + ['xlm-roberta', ['XLMRobertaForQuestionAnswering', XLMRobertaForQuestionAnswering]], + ['mobilebert', ['MobileBertForQuestionAnswering', MobileBertForQuestionAnswering]], + ['squeezebert', ['SqueezeBertForQuestionAnswering', SqueezeBertForQuestionAnswering]], +]); + +const MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = new Map([ + ['vision-encoder-decoder', ['VisionEncoderDecoderModel', VisionEncoderDecoderModel]], +]); + +const MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES = new Map([ + ['vision-encoder-decoder', ['VisionEncoderDecoderModel', VisionEncoderDecoderModel]], +]); + +const MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = new Map([ + ['vit', ['ViTForImageClassification', ViTForImageClassification]], + ['mobilevit', ['MobileViTForImageClassification', MobileViTForImageClassification]], + ['beit', ['BeitForImageClassification', BeitForImageClassification]], + ['deit', ['DeiTForImageClassification', DeiTForImageClassification]], + ['convnext', ['ConvNextForImageClassification', ConvNextForImageClassification]], + ['convnextv2', ['ConvNextV2ForImageClassification', ConvNextV2ForImageClassification]], + ['dinov2', ['Dinov2ForImageClassification', Dinov2ForImageClassification]], + ['resnet', ['ResNetForImageClassification', ResNetForImageClassification]], + ['swin', ['SwinForImageClassification', SwinForImageClassification]], + ['segformer', ['SegformerForImageClassification', SegformerForImageClassification]], + ['efficientnet', ['EfficientNetForImageClassification', EfficientNetForImageClassification]], +]); + +const MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = new Map([ + ['detr', ['DetrForObjectDetection', DetrForObjectDetection]], + ['table-transformer', ['TableTransformerForObjectDetection', TableTransformerForObjectDetection]], + ['yolos', ['YolosForObjectDetection', YolosForObjectDetection]], +]); + +const MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES = new Map([ + ['owlvit', ['OwlViTForObjectDetection', OwlViTForObjectDetection]], + ['owlv2', ['Owlv2ForObjectDetection', Owlv2ForObjectDetection]], +]); + +const MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES = new Map([ + ['detr', ['DetrForSegmentation', DetrForSegmentation]], + ['clipseg', ['CLIPSegForImageSegmentation', CLIPSegForImageSegmentation]], +]); + +const MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES = new Map([ + ['segformer', ['SegformerForSemanticSegmentation', SegformerForSemanticSegmentation]], +]); + +const MODEL_FOR_MASK_GENERATION_MAPPING_NAMES = new Map([ + ['sam', ['SamModel', SamModel]], +]); + +const MODEL_FOR_CTC_MAPPING_NAMES = new Map([ + ['wav2vec2', ['Wav2Vec2ForCTC', Wav2Vec2ForCTC]], + ['wav2vec2-bert', ['Wav2Vec2BertForCTC', Wav2Vec2BertForCTC]], + ['unispeech', ['UniSpeechForCTC', UniSpeechForCTC]], + ['unispeech-sat', ['UniSpeechSatForCTC', UniSpeechSatForCTC]], + ['wavlm', ['WavLMForCTC', WavLMForCTC]], + ['hubert', ['HubertForCTC', HubertForCTC]], +]); + +const MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = new Map([ + ['wav2vec2', ['Wav2Vec2ForSequenceClassification', Wav2Vec2ForSequenceClassification]], + ['wav2vec2-bert', ['Wav2Vec2BertForSequenceClassification', Wav2Vec2BertForSequenceClassification]], + ['unispeech', ['UniSpeechForSequenceClassification', UniSpeechForSequenceClassification]], + ['unispeech-sat', ['UniSpeechSatForSequenceClassification', UniSpeechSatForSequenceClassification]], + ['wavlm', ['WavLMForSequenceClassification', WavLMForSequenceClassification]], + ['hubert', ['HubertForSequenceClassification', HubertForSequenceClassification]], + ['audio-spectrogram-transformer', ['ASTForAudioClassification', ASTForAudioClassification]], +]); + +const MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES = new Map([ + ['wavlm', ['WavLMForXVector', WavLMForXVector]], +]); + +const MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES = new Map([ + ['unispeech-sat', ['UniSpeechSatForAudioFrameClassification', UniSpeechSatForAudioFrameClassification]], + ['wavlm', ['WavLMForAudioFrameClassification', WavLMForAudioFrameClassification]], + ['wav2vec2', ['Wav2Vec2ForAudioFrameClassification', Wav2Vec2ForAudioFrameClassification]], +]); + +const MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES = new Map([ + ['vitmatte', ['VitMatteForImageMatting', VitMatteForImageMatting]], +]); + +const MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES = new Map([ + ['swin2sr', ['Swin2SRForImageSuperResolution', Swin2SRForImageSuperResolution]], +]) + +const MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES = new Map([ + ['dpt', ['DPTForDepthEstimation', DPTForDepthEstimation]], + ['depth_anything', ['DepthAnythingForDepthEstimation', DepthAnythingForDepthEstimation]], + ['glpn', ['GLPNForDepthEstimation', GLPNForDepthEstimation]], +]) + +// NOTE: This is custom to Transformers.js, and is necessary because certain models +// (e.g., CLIP) are split into vision and text components +const MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES = new Map([ + ['clip', ['CLIPVisionModelWithProjection', CLIPVisionModelWithProjection]], + ['siglip', ['SiglipVisionModel', SiglipVisionModel]], +]) + +const MODEL_CLASS_TYPE_MAPPING = [ + [MODEL_MAPPING_NAMES_ENCODER_ONLY, MODEL_TYPES.EncoderOnly], + [MODEL_MAPPING_NAMES_ENCODER_DECODER, MODEL_TYPES.EncoderDecoder], + [MODEL_MAPPING_NAMES_DECODER_ONLY, MODEL_TYPES.DecoderOnly], + [MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES, MODEL_TYPES.Seq2Seq], + [MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES, MODEL_TYPES.Seq2Seq], + [MODEL_WITH_LM_HEAD_MAPPING_NAMES, MODEL_TYPES.DecoderOnly], + [MODEL_FOR_MASKED_LM_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES, MODEL_TYPES.Vision2Seq], + [MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_MASK_GENERATION_MAPPING_NAMES, MODEL_TYPES.MaskGeneration], + [MODEL_FOR_CTC_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES, MODEL_TYPES.Seq2Seq], + [MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + [MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], + + // Custom: + [MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES, MODEL_TYPES.EncoderOnly], +]; + +for (const [mappings, type] of MODEL_CLASS_TYPE_MAPPING) { + // @ts-ignore + for (const [name, model] of mappings.values()) { + MODEL_TYPE_MAPPING.set(name, type); + MODEL_CLASS_TO_NAME_MAPPING.set(model, name); + MODEL_NAME_TO_CLASS_MAPPING.set(name, model); + } +} + +const CUSTOM_MAPPING = [ + ['CLIPTextModelWithProjection', CLIPTextModelWithProjection, MODEL_TYPES.EncoderOnly], + ['SiglipTextModel', SiglipTextModel, MODEL_TYPES.EncoderOnly], + ['ClapTextModelWithProjection', ClapTextModelWithProjection, MODEL_TYPES.EncoderOnly], + ['ClapAudioModelWithProjection', ClapAudioModelWithProjection, MODEL_TYPES.EncoderOnly], +] +for (const [name, model, type] of CUSTOM_MAPPING) { + MODEL_TYPE_MAPPING.set(name, type); + MODEL_CLASS_TO_NAME_MAPPING.set(model, name); + MODEL_NAME_TO_CLASS_MAPPING.set(name, model); +} + + +/** + * Helper class which is used to instantiate pretrained models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModel.from_pretrained('bert-base-uncased'); + */ +class AutoModel extends PretrainedMixin { + /** @type {Map[]} */ + // @ts-ignore + static MODEL_CLASS_MAPPINGS = MODEL_CLASS_TYPE_MAPPING.map(x => x[0]); + static BASE_IF_FAIL = true; +} + +/** + * Helper class which is used to instantiate pretrained sequence classification models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForSequenceClassification.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english'); + */ +class AutoModelForSequenceClassification extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained token classification models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForTokenClassification.from_pretrained('Davlan/distilbert-base-multilingual-cased-ner-hrl'); + */ +class AutoModelForTokenClassification extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained sequence-to-sequence models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForSeq2SeqLM.from_pretrained('t5-small'); + */ +class AutoModelForSeq2SeqLM extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained sequence-to-sequence speech-to-text models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForSpeechSeq2Seq.from_pretrained('openai/whisper-tiny.en'); + */ +class AutoModelForSpeechSeq2Seq extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained sequence-to-sequence text-to-spectrogram models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForTextToSpectrogram.from_pretrained('microsoft/speecht5_tts'); + */ +class AutoModelForTextToSpectrogram extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained text-to-waveform models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForTextToSpectrogram.from_pretrained('facebook/mms-tts-eng'); + */ +class AutoModelForTextToWaveform extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained causal language models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForCausalLM.from_pretrained('gpt2'); + */ +class AutoModelForCausalLM extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_WITH_LM_HEAD_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained masked language models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForMaskedLM.from_pretrained('bert-base-uncased'); + */ +class AutoModelForMaskedLM extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_MASKED_LM_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained question answering models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForQuestionAnswering.from_pretrained('distilbert-base-cased-distilled-squad'); + */ +class AutoModelForQuestionAnswering extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained vision-to-sequence models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForVision2Seq.from_pretrained('nlpconnect/vit-gpt2-image-captioning'); + */ +class AutoModelForVision2Seq extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained image classification models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForImageClassification.from_pretrained('google/vit-base-patch16-224'); + */ +class AutoModelForImageClassification extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained image segmentation models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForImageSegmentation.from_pretrained('facebook/detr-resnet-50-panoptic'); + */ +class AutoModelForImageSegmentation extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained image segmentation models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForSemanticSegmentation.from_pretrained('nvidia/segformer-b3-finetuned-cityscapes-1024-1024'); + */ +class AutoModelForSemanticSegmentation extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]; +} + +/** + * Helper class which is used to instantiate pretrained object detection models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForObjectDetection.from_pretrained('facebook/detr-resnet-50'); + */ +class AutoModelForObjectDetection extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]; +} + +class AutoModelForZeroShotObjectDetection extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]; +} + + +/** + * Helper class which is used to instantiate pretrained mask generation models with the `from_pretrained` function. + * The chosen model class is determined by the type specified in the model config. + * + * @example + * let model = await AutoModelForMaskGeneration.from_pretrained('Xenova/sam-vit-base'); + */ +class AutoModelForMaskGeneration extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]; +} + +class AutoModelForCTC extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_CTC_MAPPING_NAMES]; +} + +class AutoModelForAudioClassification extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]; +} + +class AutoModelForXVector extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]; +} + +class AutoModelForAudioFrameClassification extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]; +} + +class AutoModelForDocumentQuestionAnswering extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]; +} + +class AutoModelForImageMatting extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]; +} + +class AutoModelForImageToImage extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]; +} + +class AutoModelForDepthEstimation extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]; +} + +class AutoModelForImageFeatureExtraction extends PretrainedMixin { + static MODEL_CLASS_MAPPINGS = [MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]; +} + +////////////////////////////////////////////////// + +////////////////////////////////////////////////// +class Seq2SeqLMOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits The output logits of the model. + * @param {Tensor} output.past_key_values An tensor of key/value pairs that represent the previous state of the model. + * @param {Tensor} output.encoder_outputs The output of the encoder in a sequence-to-sequence model. + * @param {Tensor} [output.decoder_attentions] Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the self-attention heads. + * @param {Tensor} [output.cross_attentions] Attentions weights of the decoder's cross-attention layer, after the attention softmax, used to compute the weighted average in the cross-attention heads. + */ + constructor({ logits, past_key_values, encoder_outputs, decoder_attentions = null, cross_attentions = null }) { + super(); + this.logits = logits; + this.past_key_values = past_key_values; + this.encoder_outputs = encoder_outputs; + this.decoder_attentions = decoder_attentions; + this.cross_attentions = cross_attentions; + } +} + +/** + * Base class for outputs of sentence classification models. + */ +class SequenceClassifierOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits classification (or regression if config.num_labels==1) scores (before SoftMax). + */ + constructor({ logits }) { + super(); + this.logits = logits; + } +} + +/** + * Base class for outputs of XVector models. + */ +class XVectorOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Classification hidden states before AMSoftmax, of shape `(batch_size, config.xvector_output_dim)`. + * @param {Tensor} output.embeddings Utterance embeddings used for vector similarity-based retrieval, of shape `(batch_size, config.xvector_output_dim)`. + */ + constructor({ logits, embeddings }) { + super(); + this.logits = logits; + this.embeddings = embeddings; + } +} + +/** + * Base class for outputs of token classification models. + */ +class TokenClassifierOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Classification scores (before SoftMax). + */ + constructor({ logits }) { + super(); + this.logits = logits; + } +} + +/** + * Base class for masked language models outputs. + */ +class MaskedLMOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax). + */ + constructor({ logits }) { + super(); + this.logits = logits; + } +} + +/** + * Base class for outputs of question answering models. + */ +class QuestionAnsweringModelOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.start_logits Span-start scores (before SoftMax). + * @param {Tensor} output.end_logits Span-end scores (before SoftMax). + */ + constructor({ start_logits, end_logits }) { + super(); + this.start_logits = start_logits; + this.end_logits = end_logits; + } +} + + +/** + * Base class for causal language model (or autoregressive) outputs. + */ +class CausalLMOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Prediction scores of the language modeling head (scores for each vocabulary token before softmax). + */ + constructor({ logits }) { + super(); + this.logits = logits; + } +} + +/** + * Base class for causal language model (or autoregressive) outputs. + */ +class CausalLMOutputWithPast extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.logits Prediction scores of the language modeling head (scores for each vocabulary token before softmax). + * @param {Tensor} output.past_key_values Contains pre-computed hidden-states (key and values in the self-attention blocks) + * that can be used (see `past_key_values` input) to speed up sequential decoding. + */ + constructor({ logits, past_key_values }) { + super(); + this.logits = logits; + this.past_key_values = past_key_values; + } +} + +class ImageMattingOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.alphas Estimated alpha values, of shape `(batch_size, num_channels, height, width)`. + */ + constructor({ alphas }) { + super(); + this.alphas = alphas; + } +} + +/** + * Describes the outputs for the VITS model. + */ +class VitsModelOutput extends ModelOutput { + /** + * @param {Object} output The output of the model. + * @param {Tensor} output.waveform The final audio waveform predicted by the model, of shape `(batch_size, sequence_length)`. + * @param {Tensor} output.spectrogram The log-mel spectrogram predicted at the output of the flow model. + * This spectrogram is passed to the Hi-Fi GAN decoder model to obtain the final audio waveform. + */ + constructor({ waveform, spectrogram }) { + super(); + this.waveform = waveform; + this.spectrogram = spectrogram; + } +} + + +/***/ }), + +/***/ "./src/pipelines.js": +/*!**************************!*\ + !*** ./src/pipelines.js ***! + \**************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "AudioClassificationPipeline": () => (/* binding */ AudioClassificationPipeline), +/* harmony export */ "AutomaticSpeechRecognitionPipeline": () => (/* binding */ AutomaticSpeechRecognitionPipeline), +/* harmony export */ "DepthEstimationPipeline": () => (/* binding */ DepthEstimationPipeline), +/* harmony export */ "DocumentQuestionAnsweringPipeline": () => (/* binding */ DocumentQuestionAnsweringPipeline), +/* harmony export */ "FeatureExtractionPipeline": () => (/* binding */ FeatureExtractionPipeline), +/* harmony export */ "FillMaskPipeline": () => (/* binding */ FillMaskPipeline), +/* harmony export */ "ImageClassificationPipeline": () => (/* binding */ ImageClassificationPipeline), +/* harmony export */ "ImageFeatureExtractionPipeline": () => (/* binding */ ImageFeatureExtractionPipeline), +/* harmony export */ "ImageSegmentationPipeline": () => (/* binding */ ImageSegmentationPipeline), +/* harmony export */ "ImageToImagePipeline": () => (/* binding */ ImageToImagePipeline), +/* harmony export */ "ImageToTextPipeline": () => (/* binding */ ImageToTextPipeline), +/* harmony export */ "ObjectDetectionPipeline": () => (/* binding */ ObjectDetectionPipeline), +/* harmony export */ "Pipeline": () => (/* binding */ Pipeline), +/* harmony export */ "QuestionAnsweringPipeline": () => (/* binding */ QuestionAnsweringPipeline), +/* harmony export */ "SummarizationPipeline": () => (/* binding */ SummarizationPipeline), +/* harmony export */ "Text2TextGenerationPipeline": () => (/* binding */ Text2TextGenerationPipeline), +/* harmony export */ "TextClassificationPipeline": () => (/* binding */ TextClassificationPipeline), +/* harmony export */ "TextGenerationPipeline": () => (/* binding */ TextGenerationPipeline), +/* harmony export */ "TextToAudioPipeline": () => (/* binding */ TextToAudioPipeline), +/* harmony export */ "TokenClassificationPipeline": () => (/* binding */ TokenClassificationPipeline), +/* harmony export */ "TranslationPipeline": () => (/* binding */ TranslationPipeline), +/* harmony export */ "ZeroShotAudioClassificationPipeline": () => (/* binding */ ZeroShotAudioClassificationPipeline), +/* harmony export */ "ZeroShotClassificationPipeline": () => (/* binding */ ZeroShotClassificationPipeline), +/* harmony export */ "ZeroShotImageClassificationPipeline": () => (/* binding */ ZeroShotImageClassificationPipeline), +/* harmony export */ "ZeroShotObjectDetectionPipeline": () => (/* binding */ ZeroShotObjectDetectionPipeline), +/* harmony export */ "pipeline": () => (/* binding */ pipeline) +/* harmony export */ }); +/* harmony import */ var _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tokenizers.js */ "./src/tokenizers.js"); +/* harmony import */ var _models_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./models.js */ "./src/models.js"); +/* harmony import */ var _processors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./processors.js */ "./src/processors.js"); +/* harmony import */ var _utils_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils/core.js */ "./src/utils/core.js"); +/* harmony import */ var _utils_maths_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/maths.js */ "./src/utils/maths.js"); +/* harmony import */ var _utils_audio_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./utils/audio.js */ "./src/utils/audio.js"); +/* harmony import */ var _utils_tensor_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./utils/tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _utils_image_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils/image.js */ "./src/utils/image.js"); +/** + * @file Pipelines provide a high-level, easy to use, API for running machine learning models. + * + * **Example:** Instantiate pipeline using the `pipeline` function. + * ```javascript + * import { pipeline } from '@xenova/transformers'; + * + * const classifier = await pipeline('sentiment-analysis'); + * const output = await classifier('I love transformers!'); + * // [{'label': 'POSITIVE', 'score': 0.999817686}] + * ``` + * + * @module pipelines + */ + + + + + + + + + + + + + +/** + * @typedef {string | RawImage | URL} ImageInput + * @typedef {ImageInput|ImageInput[]} ImagePipelineInputs + */ + +/** + * Prepare images for further tasks. + * @param {ImagePipelineInputs} images images to prepare. + * @returns {Promise} returns processed images. + * @private + */ +async function prepareImages(images) { + if (!Array.isArray(images)) { + images = [images]; + } + + // Possibly convert any non-images to images + return await Promise.all(images.map(x => _utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage.read(x))); +} + +/** + * @typedef {string | URL | Float32Array | Float64Array} AudioInput + * @typedef {AudioInput|AudioInput[]} AudioPipelineInputs + */ + +/** + * Prepare audios for further tasks. + * @param {AudioPipelineInputs} audios audios to prepare. + * @param {number} sampling_rate sampling rate of the audios. + * @returns {Promise} The preprocessed audio data. + * @private + */ +async function prepareAudios(audios, sampling_rate) { + if (!Array.isArray(audios)) { + audios = [audios]; + } + + return await Promise.all(audios.map(x => { + if (typeof x === 'string' || x instanceof URL) { + return (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.read_audio)(x, sampling_rate); + } else if (x instanceof Float64Array) { + return new Float32Array(x); + } + return x; + })); +} + +/** + * @typedef {Object} BoundingBox + * @property {number} xmin The minimum x coordinate of the bounding box. + * @property {number} ymin The minimum y coordinate of the bounding box. + * @property {number} xmax The maximum x coordinate of the bounding box. + * @property {number} ymax The maximum y coordinate of the bounding box. + */ + +/** + * Helper function to convert list [xmin, xmax, ymin, ymax] into object { "xmin": xmin, ... } + * @param {number[]} box The bounding box as a list. + * @param {boolean} asInteger Whether to cast to integers. + * @returns {BoundingBox} The bounding box as an object. + * @private + */ +function get_bounding_box(box, asInteger) { + if (asInteger) { + box = box.map(x => x | 0); + } + const [xmin, ymin, xmax, ymax] = box; + + return { xmin, ymin, xmax, ymax }; +} + + +/** + * @callback DisposeType Disposes the item. + * @returns {Promise} A promise that resolves when the item has been disposed. + * + * @typedef {Object} Disposable + * @property {DisposeType} dispose A promise that resolves when the pipeline has been disposed. + */ + +/** + * The Pipeline class is the class from which all pipelines inherit. + * Refer to this class for methods shared across different pipelines. + * @extends Callable + */ +class Pipeline extends _utils_core_js__WEBPACK_IMPORTED_MODULE_3__.Callable { + /** + * Create a new Pipeline. + * @param {Object} options An object containing the following properties: + * @param {string} [options.task] The task of the pipeline. Useful for specifying subtasks. + * @param {PreTrainedModel} [options.model] The model used by the pipeline. + * @param {PreTrainedTokenizer} [options.tokenizer=null] The tokenizer used by the pipeline (if any). + * @param {Processor} [options.processor=null] The processor used by the pipeline (if any). + */ + constructor({ task, model, tokenizer = null, processor = null }) { + super(); + this.task = task; + this.model = model; + this.tokenizer = tokenizer; + this.processor = processor; + } + + /** @type {DisposeType} */ + async dispose() { + await this.model.dispose(); + } +} + +/** + * @typedef {Object} ModelTokenizerConstructorArgs + * @property {string} task The task of the pipeline. Useful for specifying subtasks. + * @property {PreTrainedModel} model The model used by the pipeline. + * @property {PreTrainedTokenizer} tokenizer The tokenizer used by the pipeline. + * + * @typedef {ModelTokenizerConstructorArgs} TextPipelineConstructorArgs An object used to instantiate a text-based pipeline. + */ + +/** + * @typedef {Object} ModelProcessorConstructorArgs + * @property {string} task The task of the pipeline. Useful for specifying subtasks. + * @property {PreTrainedModel} model The model used by the pipeline. + * @property {Processor} processor The processor used by the pipeline. + * + * @typedef {ModelProcessorConstructorArgs} AudioPipelineConstructorArgs An object used to instantiate an audio-based pipeline. + * @typedef {ModelProcessorConstructorArgs} ImagePipelineConstructorArgs An object used to instantiate an image-based pipeline. + */ + + +/** + * @typedef {Object} ModelTokenizerProcessorConstructorArgs + * @property {string} task The task of the pipeline. Useful for specifying subtasks. + * @property {PreTrainedModel} model The model used by the pipeline. + * @property {PreTrainedTokenizer} tokenizer The tokenizer used by the pipeline. + * @property {Processor} processor The processor used by the pipeline. + * + * @typedef {ModelTokenizerProcessorConstructorArgs} TextAudioPipelineConstructorArgs An object used to instantiate a text- and audio-based pipeline. + * @typedef {ModelTokenizerProcessorConstructorArgs} TextImagePipelineConstructorArgs An object used to instantiate a text- and image-based pipeline. + */ + +/** + * @typedef {Object} TextClassificationSingle + * @property {string} label The label predicted. + * @property {number} score The corresponding probability. + * @typedef {TextClassificationSingle[]} TextClassificationOutput + * + * @typedef {Object} TextClassificationPipelineOptions Parameters specific to text classification pipelines. + * @property {number} [topk=1] The number of top predictions to be returned. + * + * @callback TextClassificationPipelineCallback Classify the text(s) given as inputs. + * @param {string|string[]} texts The input text(s) to be classified. + * @param {TextClassificationPipelineOptions} [options] The options to use for text classification. + * @returns {Promise} An array or object containing the predicted labels and scores. + * + * @typedef {TextPipelineConstructorArgs & TextClassificationPipelineCallback & Disposable} TextClassificationPipelineType + */ + +/** + * Text classification pipeline using any `ModelForSequenceClassification`. + * + * **Example:** Sentiment-analysis w/ `Xenova/distilbert-base-uncased-finetuned-sst-2-english`. + * ```javascript + * const classifier = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english'); + * const output = await classifier('I love transformers!'); + * // [{ label: 'POSITIVE', score: 0.999788761138916 }] + * ``` + * + * **Example:** Multilingual sentiment-analysis w/ `Xenova/bert-base-multilingual-uncased-sentiment` (and return top 5 classes). + * ```javascript + * const classifier = await pipeline('sentiment-analysis', 'Xenova/bert-base-multilingual-uncased-sentiment'); + * const output = await classifier('Le meilleur film de tous les temps.', { topk: 5 }); + * // [ + * // { label: '5 stars', score: 0.9610759615898132 }, + * // { label: '4 stars', score: 0.03323351591825485 }, + * // { label: '3 stars', score: 0.0036155181005597115 }, + * // { label: '1 star', score: 0.0011325967498123646 }, + * // { label: '2 stars', score: 0.0009423971059732139 } + * // ] + * ``` + * + * **Example:** Toxic comment classification w/ `Xenova/toxic-bert` (and return all classes). + * ```javascript + * const classifier = await pipeline('text-classification', 'Xenova/toxic-bert'); + * const output = await classifier('I hate you!', { topk: null }); + * // [ + * // { label: 'toxic', score: 0.9593140482902527 }, + * // { label: 'insult', score: 0.16187334060668945 }, + * // { label: 'obscene', score: 0.03452680632472038 }, + * // { label: 'identity_hate', score: 0.0223250575363636 }, + * // { label: 'threat', score: 0.019197041168808937 }, + * // { label: 'severe_toxic', score: 0.005651099607348442 } + * // ] + * ``` + */ +class TextClassificationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => TextClassificationPipelineType} */ (Pipeline)) { + + /** + * Create a new TextClassificationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {TextClassificationPipelineCallback} */ + async _call(texts, { + topk = 1 + } = {}) { + + // Run tokenization + const model_inputs = this.tokenizer(texts, { + padding: true, + truncation: true, + }); + + // Run model + const outputs = await this.model(model_inputs) + + // TODO: Use softmax tensor function + const function_to_apply = + this.model.config.problem_type === 'multi_label_classification' + ? batch => batch.sigmoid().data + : batch => (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(batch.data); // single_label_classification (default) + + const id2label = this.model.config.id2label; + + const toReturn = []; + for (const batch of outputs.logits) { + const output = function_to_apply(batch); + const scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.getTopItems)(output, topk); + + const vals = scores.map(x => ({ + label: id2label[x[0]], + score: x[1], + })); + if (topk === 1) { + toReturn.push(...vals); + } else { + toReturn.push(vals); + } + } + + return Array.isArray(texts) || topk === 1 ? /** @type {TextClassificationOutput} */ (toReturn) : /** @type {TextClassificationOutput[]} */ (toReturn)[0]; + } +} + +/** + * @typedef {Object} TokenClassificationSingle + * @property {string} word The token/word classified. This is obtained by decoding the selected tokens. + * @property {number} score The corresponding probability for `entity`. + * @property {string} entity The entity predicted for that token/word. + * @property {number} index The index of the corresponding token in the sentence. + * @property {number} [start] The index of the start of the corresponding entity in the sentence. + * @property {number} [end] The index of the end of the corresponding entity in the sentence. + * @typedef {TokenClassificationSingle[]} TokenClassificationOutput + * + * @typedef {Object} TokenClassificationPipelineOptions Parameters specific to token classification pipelines. + * @property {string[]} [ignore_labels] A list of labels to ignore. + * + * @callback TokenClassificationPipelineCallback Classify each token of the text(s) given as inputs. + * @param {string|string[]} texts One or several texts (or one list of texts) for token classification. + * @param {TokenClassificationPipelineOptions} [options] The options to use for token classification. + * @returns {Promise} The result. + * + * @typedef {TextPipelineConstructorArgs & TokenClassificationPipelineCallback & Disposable} TokenClassificationPipelineType + */ + +/** + * Named Entity Recognition pipeline using any `ModelForTokenClassification`. + * + * **Example:** Perform named entity recognition with `Xenova/bert-base-NER`. + * ```javascript + * const classifier = await pipeline('token-classification', 'Xenova/bert-base-NER'); + * const output = await classifier('My name is Sarah and I live in London'); + * // [ + * // { entity: 'B-PER', score: 0.9980202913284302, index: 4, word: 'Sarah' }, + * // { entity: 'B-LOC', score: 0.9994474053382874, index: 9, word: 'London' } + * // ] + * ``` + * + * **Example:** Perform named entity recognition with `Xenova/bert-base-NER` (and return all labels). + * ```javascript + * const classifier = await pipeline('token-classification', 'Xenova/bert-base-NER'); + * const output = await classifier('Sarah lives in the United States of America', { ignore_labels: [] }); + * // [ + * // { entity: 'B-PER', score: 0.9966587424278259, index: 1, word: 'Sarah' }, + * // { entity: 'O', score: 0.9987385869026184, index: 2, word: 'lives' }, + * // { entity: 'O', score: 0.9990072846412659, index: 3, word: 'in' }, + * // { entity: 'O', score: 0.9988298416137695, index: 4, word: 'the' }, + * // { entity: 'B-LOC', score: 0.9995510578155518, index: 5, word: 'United' }, + * // { entity: 'I-LOC', score: 0.9990395307540894, index: 6, word: 'States' }, + * // { entity: 'I-LOC', score: 0.9986724853515625, index: 7, word: 'of' }, + * // { entity: 'I-LOC', score: 0.9975294470787048, index: 8, word: 'America' } + * // ] + * ``` + */ +class TokenClassificationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => TokenClassificationPipelineType} */ (Pipeline)) { + + /** + * Create a new TokenClassificationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {TokenClassificationPipelineCallback} */ + async _call(texts, { + ignore_labels = ['O'], + } = {}) { + + const isBatched = Array.isArray(texts); + + // Run tokenization + const model_inputs = this.tokenizer(isBatched ? texts : [texts], { + padding: true, + truncation: true, + }); + + // Run model + const outputs = await this.model(model_inputs) + + const logits = outputs.logits; + const id2label = this.model.config.id2label; + + const toReturn = []; + for (let i = 0; i < logits.dims[0]; ++i) { + const ids = model_inputs.input_ids[i]; + const batch = logits[i]; + + // List of tokens that aren't ignored + const tokens = []; + for (let j = 0; j < batch.dims[0]; ++j) { + const tokenData = batch[j]; + const topScoreIndex = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.max)(tokenData.data)[1]; + + const entity = id2label ? id2label[topScoreIndex] : `LABEL_${topScoreIndex}`; + if (ignore_labels.includes(entity)) { + // We predicted a token that should be ignored. So, we skip it. + continue; + } + + // TODO add option to keep special tokens? + const word = this.tokenizer.decode([ids[j].item()], { skip_special_tokens: true }); + if (word === '') { + // Was a special token. So, we skip it. + continue; + } + + const scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(tokenData.data); + + tokens.push({ + entity: entity, + score: scores[topScoreIndex], + index: j, + word: word, + + // TODO: null for now, but will add + start: null, + end: null, + }); + } + toReturn.push(tokens); + } + return isBatched ? toReturn : toReturn[0]; + } +} + +/** + * @typedef {Object} QuestionAnsweringOutput + * @property {number} score The probability associated to the answer. + * @property {number} [start] The character start index of the answer (in the tokenized version of the input). + * @property {number} [end] The character end index of the answer (in the tokenized version of the input). + * @property {string} answer The answer to the question. + * + * @typedef {Object} QuestionAnsweringPipelineOptions Parameters specific to question answering pipelines. + * @property {number} [topk=1] The number of top answer predictions to be returned. + * + * @callback QuestionAnsweringPipelineCallback Answer the question(s) given as inputs by using the context(s). + * @param {string|string[]} question One or several question(s) (must be used in conjunction with the `context` argument). + * @param {string|string[]} context One or several context(s) associated with the question(s) (must be used in conjunction with the `question` argument). + * @param {QuestionAnsweringPipelineOptions} [options] The options to use for question answering. + * @returns {Promise} An array or object containing the predicted answers and scores. + * + * @typedef {TextPipelineConstructorArgs & QuestionAnsweringPipelineCallback & Disposable} QuestionAnsweringPipelineType + */ + +/** + * Question Answering pipeline using any `ModelForQuestionAnswering`. + * + * **Example:** Run question answering with `Xenova/distilbert-base-uncased-distilled-squad`. + * ```javascript + * const answerer = await pipeline('question-answering', 'Xenova/distilbert-base-uncased-distilled-squad'); + * const question = 'Who was Jim Henson?'; + * const context = 'Jim Henson was a nice puppet.'; + * const output = await answerer(question, context); + * // { + * // answer: "a nice puppet", + * // score: 0.5768911502526741 + * // } + * ``` + */ +class QuestionAnsweringPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => QuestionAnsweringPipelineType} */ (Pipeline)) { + + /** + * Create a new QuestionAnsweringPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {QuestionAnsweringPipelineCallback} */ + async _call(question, context, { + topk = 1 + } = {}) { + + // Run tokenization + const inputs = this.tokenizer(question, { + text_pair: context, + padding: true, + truncation: true, + }); + + const output = await this.model(inputs); + + /** @type {QuestionAnsweringOutput[]} */ + const toReturn = []; + for (let j = 0; j < output.start_logits.dims[0]; ++j) { + const ids = inputs.input_ids[j]; + const sepIndex = ids.indexOf(this.tokenizer.sep_token_id); + + const s1 = Array.from((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(output.start_logits[j].data)) + .map((x, i) => [x, i]) + .filter(x => x[1] > sepIndex); + const e1 = Array.from((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(output.end_logits[j].data)) + .map((x, i) => [x, i]) + .filter(x => x[1] > sepIndex); + + const options = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_3__.product)(s1, e1) + .filter(x => x[0][1] <= x[1][1]) + .map(x => [x[0][1], x[1][1], x[0][0] * x[1][0]]) + .sort((a, b) => b[2] - a[2]); + + for (let k = 0; k < Math.min(options.length, topk); ++k) { + const [start, end, score] = options[k]; + + const answer_tokens = [...ids].slice(start, end + 1) + + const answer = this.tokenizer.decode(answer_tokens, { + skip_special_tokens: true, + }); + + // TODO add start and end? + // NOTE: HF returns character index + toReturn.push({ + answer, score + }); + } + } + + // Mimic HF's return type based on topk + return (topk === 1) ? toReturn[0] : toReturn; + } +} + + +/** + * @typedef {Object} FillMaskSingle + * @property {string} sequence The corresponding input with the mask token prediction. + * @property {number} score The corresponding probability. + * @property {number} token The predicted token id (to replace the masked one). + * @property {string} token_str The predicted token (to replace the masked one). + * @typedef {FillMaskSingle[]} FillMaskOutput + * + * @typedef {Object} FillMaskPipelineOptions Parameters specific to fill mask pipelines. + * @property {number} [topk=5] When passed, overrides the number of predictions to return. + * + * @callback FillMaskPipelineCallback Fill the masked token in the text(s) given as inputs. + * @param {string|string[]} texts One or several texts (or one list of prompts) with masked tokens. + * @param {FillMaskPipelineOptions} [options] The options to use for masked language modelling. + * @returns {Promise} An array of objects containing the score, predicted token, predicted token string, + * and the sequence with the predicted token filled in, or an array of such arrays (one for each input text). + * If only one input text is given, the output will be an array of objects. + * @throws {Error} When the mask token is not found in the input text. + * + * @typedef {TextPipelineConstructorArgs & FillMaskPipelineCallback & Disposable} FillMaskPipelineType + */ + +/** + * Masked language modeling prediction pipeline using any `ModelWithLMHead`. + * + * **Example:** Perform masked language modelling (a.k.a. "fill-mask") with `Xenova/bert-base-uncased`. + * ```javascript + * const unmasker = await pipeline('fill-mask', 'Xenova/bert-base-cased'); + * const output = await unmasker('The goal of life is [MASK].'); + * // [ + * // { token_str: 'survival', score: 0.06137419492006302, token: 8115, sequence: 'The goal of life is survival.' }, + * // { token_str: 'love', score: 0.03902450203895569, token: 1567, sequence: 'The goal of life is love.' }, + * // { token_str: 'happiness', score: 0.03253183513879776, token: 9266, sequence: 'The goal of life is happiness.' }, + * // { token_str: 'freedom', score: 0.018736306577920914, token: 4438, sequence: 'The goal of life is freedom.' }, + * // { token_str: 'life', score: 0.01859794743359089, token: 1297, sequence: 'The goal of life is life.' } + * // ] + * ``` + * + * **Example:** Perform masked language modelling (a.k.a. "fill-mask") with `Xenova/bert-base-cased` (and return top result). + * ```javascript + * const unmasker = await pipeline('fill-mask', 'Xenova/bert-base-cased'); + * const output = await unmasker('The Milky Way is a [MASK] galaxy.', { topk: 1 }); + * // [{ token_str: 'spiral', score: 0.6299987435340881, token: 14061, sequence: 'The Milky Way is a spiral galaxy.' }] + * ``` + */ +class FillMaskPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => FillMaskPipelineType} */ (Pipeline)) { + + /** + * Create a new FillMaskPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {FillMaskPipelineCallback} */ + async _call(texts, { + topk = 5 + } = {}) { + + // Run tokenization + const model_inputs = this.tokenizer(texts, { + padding: true, + truncation: true, + }); + + // Run model + const outputs = await this.model(model_inputs) + + const toReturn = []; + + for (let i = 0; i < model_inputs.input_ids.dims[0]; ++i) { + const ids = model_inputs.input_ids[i]; + const mask_token_index = ids.indexOf(this.tokenizer.mask_token_id) + + if (mask_token_index === -1) { + throw Error(`Mask token (${this.tokenizer.mask_token}) not found in text.`) + } + const logits = outputs.logits[i]; + const itemLogits = logits[mask_token_index]; + + const scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.getTopItems)((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(itemLogits.data), topk); + + toReturn.push(scores.map(x => { + const sequence = [...ids]; + sequence[mask_token_index] = x[0]; + + return { + score: x[1], + token: x[0], + token_str: this.tokenizer.model.vocab[x[0]], + sequence: this.tokenizer.decode(sequence, { skip_special_tokens: true }), + } + })); + } + return Array.isArray(texts) ? toReturn : toReturn[0]; + } +} + + +/** + * @typedef {Object} Text2TextGenerationSingle + * @property {string} generated_text The generated text. + * @typedef {Text2TextGenerationSingle[]} Text2TextGenerationOutput + * + * @callback Text2TextGenerationPipelineCallback Generate the output text(s) using text(s) given as inputs. + * @param {string|string[]} texts Input text for the encoder. + * @param {import('./utils/generation.js').GenerationConfigType} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} + * + * @typedef {TextPipelineConstructorArgs & Text2TextGenerationPipelineCallback & Disposable} Text2TextGenerationPipelineType + */ + +/** + * Text2TextGenerationPipeline class for generating text using a model that performs text-to-text generation tasks. + * + * **Example:** Text-to-text generation w/ `Xenova/LaMini-Flan-T5-783M`. + * ```javascript + * const generator = await pipeline('text2text-generation', 'Xenova/LaMini-Flan-T5-783M'); + * const output = await generator('how can I become more healthy?', { + * max_new_tokens: 100, + * }); + * // [{ generated_text: "To become more healthy, you can: 1. Eat a balanced diet with plenty of fruits, vegetables, whole grains, lean proteins, and healthy fats. 2. Stay hydrated by drinking plenty of water. 3. Get enough sleep and manage stress levels. 4. Avoid smoking and excessive alcohol consumption. 5. Regularly exercise and maintain a healthy weight. 6. Practice good hygiene and sanitation. 7. Seek medical attention if you experience any health issues." }] + * ``` + */ +class Text2TextGenerationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => Text2TextGenerationPipelineType} */ (Pipeline)) { + /** @type {'generated_text'} */ + _key = 'generated_text'; + + /** + * Create a new Text2TextGenerationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {Text2TextGenerationPipelineCallback} */ + async _call(texts, generate_kwargs = {}) { + if (!Array.isArray(texts)) { + texts = [texts]; + } + + + // Add global prefix, if present + if (this.model.config.prefix) { + texts = texts.map(x => this.model.config.prefix + x) + } + + // Handle task specific params: + const task_specific_params = this.model.config.task_specific_params + if (task_specific_params && task_specific_params[this.task]) { + // Add prefixes, if present + if (task_specific_params[this.task].prefix) { + texts = texts.map(x => task_specific_params[this.task].prefix + x) + } + + // TODO update generation config + } + + const tokenizer = this.tokenizer; + const tokenizer_options = { + padding: true, + truncation: true, + } + let input_ids; + if (this instanceof TranslationPipeline && '_build_translation_inputs' in tokenizer) { + // TODO: move to Translation pipeline? + // Currently put here to avoid code duplication + // @ts-ignore + input_ids = tokenizer._build_translation_inputs(texts, tokenizer_options, generate_kwargs).input_ids; + + } else { + input_ids = tokenizer(texts, tokenizer_options).input_ids; + } + + const outputTokenIds = await this.model.generate(input_ids, generate_kwargs); + + return tokenizer.batch_decode(outputTokenIds, { + skip_special_tokens: true, + }).map(text => ({ [this._key]: text })); + } +} + + +/** + * @typedef {Object} SummarizationSingle + * @property {string} summary_text The summary text. + * @typedef {SummarizationSingle[]} SummarizationOutput + * + * @callback SummarizationPipelineCallback Summarize the text(s) given as inputs. + * @param {string|string[]} texts One or several articles (or one list of articles) to summarize. + * @param {import('./utils/generation.js').GenerationConfigType} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} + * + * @typedef {TextPipelineConstructorArgs & SummarizationPipelineCallback & Disposable} SummarizationPipelineType + */ + +/** + * A pipeline for summarization tasks, inheriting from Text2TextGenerationPipeline. + * + * **Example:** Summarization w/ `Xenova/distilbart-cnn-6-6`. + * ```javascript + * const generator = await pipeline('summarization', 'Xenova/distilbart-cnn-6-6'); + * const text = 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, ' + + * 'and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. ' + + * 'During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest ' + + * 'man-made structure in the world, a title it held for 41 years until the Chrysler Building in New ' + + * 'York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to ' + + * 'the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the ' + + * 'Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second ' + + * 'tallest free-standing structure in France after the Millau Viaduct.'; + * const output = await generator(text, { + * max_new_tokens: 100, + * }); + * // [{ summary_text: ' The Eiffel Tower is about the same height as an 81-storey building and the tallest structure in Paris. It is the second tallest free-standing structure in France after the Millau Viaduct.' }] + * ``` + */ +class SummarizationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => SummarizationPipelineType} */ (/** @type {any} */ (Text2TextGenerationPipeline))) { + /** @type {'summary_text'} */ + _key = 'summary_text'; + + /** + * Create a new SummarizationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } +} + + +/** + * @typedef {Object} TranslationSingle + * @property {string} translation_text The translated text. + * @typedef {TranslationSingle[]} TranslationOutput + * + * @callback TranslationPipelineCallback Translate the text(s) given as inputs. + * @param {string|string[]} texts Texts to be translated. + * @param {import('./utils/generation.js').GenerationConfigType} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} + * + * @typedef {TextPipelineConstructorArgs & TranslationPipelineCallback & Disposable} TranslationPipelineType + */ + +/** + * Translates text from one language to another. + * + * **Example:** Multilingual translation w/ `Xenova/nllb-200-distilled-600M`. + * + * See [here](https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200) + * for the full list of languages and their corresponding codes. + * + * ```javascript + * const translator = await pipeline('translation', 'Xenova/nllb-200-distilled-600M'); + * const output = await translator('जीवन एक चॉकलेट बॉक्स की तरह है।', { + * src_lang: 'hin_Deva', // Hindi + * tgt_lang: 'fra_Latn', // French + * }); + * // [{ translation_text: 'La vie est comme une boîte à chocolat.' }] + * ``` + * + * **Example:** Multilingual translation w/ `Xenova/m2m100_418M`. + * + * See [here](https://huggingface.co/facebook/m2m100_418M#languages-covered) + * for the full list of languages and their corresponding codes. + * + * ```javascript + * const translator = await pipeline('translation', 'Xenova/m2m100_418M'); + * const output = await translator('生活就像一盒巧克力。', { + * src_lang: 'zh', // Chinese + * tgt_lang: 'en', // English + * }); + * // [{ translation_text: 'Life is like a box of chocolate.' }] + * ``` + * + * **Example:** Multilingual translation w/ `Xenova/mbart-large-50-many-to-many-mmt`. + * + * See [here](https://huggingface.co/facebook/mbart-large-50-many-to-many-mmt#languages-covered) + * for the full list of languages and their corresponding codes. + * + * ```javascript + * const translator = await pipeline('translation', 'Xenova/mbart-large-50-many-to-many-mmt'); + * const output = await translator('संयुक्त राष्ट्र के प्रमुख का कहना है कि सीरिया में कोई सैन्य समाधान नहीं है', { + * src_lang: 'hi_IN', // Hindi + * tgt_lang: 'fr_XX', // French + * }); + * // [{ translation_text: 'Le chef des Nations affirme qu 'il n 'y a military solution in Syria.' }] + * ``` + */ +class TranslationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => TranslationPipelineType} */ (/** @type {any} */ (Text2TextGenerationPipeline))) { + /** @type {'translation_text'} */ + _key = 'translation_text'; + + /** + * Create a new TranslationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } +} + + +/** + * @typedef {Object} TextGenerationSingle + * @property {string} generated_text The generated text. + * @typedef {TextGenerationSingle[]} TextGenerationOutput + * + * @typedef {Object} TextGenerationSpecificParams Parameters specific to text-generation pipelines. + * @property {boolean} [add_special_tokens] Whether or not to add special tokens when tokenizing the sequences. + * @typedef {import('./utils/generation.js').GenerationConfigType & TextGenerationSpecificParams} TextGenerationConfig + * + * @callback TextGenerationPipelineCallback Complete the prompt(s) given as inputs. + * @param {string|string[]} texts One or several prompts (or one list of prompts) to complete. + * @param {TextGenerationConfig} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} An array or object containing the generated texts. + * + * @typedef {TextPipelineConstructorArgs & TextGenerationPipelineCallback & Disposable} TextGenerationPipelineType + */ + +/** + * Language generation pipeline using any `ModelWithLMHead` or `ModelForCausalLM`. + * This pipeline predicts the words that will follow a specified text prompt. + * NOTE: For the full list of generation parameters, see [`GenerationConfig`](./utils/generation#module_utils/generation.GenerationConfig). + * + * **Example:** Text generation with `Xenova/distilgpt2` (default settings). + * ```javascript + * const generator = await pipeline('text-generation', 'Xenova/distilgpt2'); + * const text = 'I enjoy walking with my cute dog,'; + * const output = await generator(text); + * // [{ generated_text: "I enjoy walking with my cute dog, and I love to play with the other dogs." }] + * ``` + * + * **Example:** Text generation with `Xenova/distilgpt2` (custom settings). + * ```javascript + * const generator = await pipeline('text-generation', 'Xenova/distilgpt2'); + * const text = 'Once upon a time, there was'; + * const output = await generator(text, { + * temperature: 2, + * max_new_tokens: 10, + * repetition_penalty: 1.5, + * no_repeat_ngram_size: 2, + * num_beams: 2, + * num_return_sequences: 2, + * }); + * // [{ + * // "generated_text": "Once upon a time, there was an abundance of information about the history and activities that" + * // }, { + * // "generated_text": "Once upon a time, there was an abundance of information about the most important and influential" + * // }] + * ``` + * + * **Example:** Run code generation with `Xenova/codegen-350M-mono`. + * ```javascript + * const generator = await pipeline('text-generation', 'Xenova/codegen-350M-mono'); + * const text = 'def fib(n):'; + * const output = await generator(text, { + * max_new_tokens: 44, + * }); + * // [{ + * // generated_text: 'def fib(n):\n' + + * // ' if n == 0:\n' + + * // ' return 0\n' + + * // ' elif n == 1:\n' + + * // ' return 1\n' + + * // ' else:\n' + + * // ' return fib(n-1) + fib(n-2)\n' + * // }] + * ``` + */ +class TextGenerationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => TextGenerationPipelineType} */ (Pipeline)) { + + /** + * Create a new TextGenerationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {TextGenerationPipelineCallback} */ + async _call(texts, generate_kwargs = {}) { + + const isBatched = Array.isArray(texts); + if (!isBatched) { + texts = [/** @type {string}*/ (texts)]; + } + + // By default, do not add special tokens + const add_special_tokens = generate_kwargs.add_special_tokens ?? false; + + this.tokenizer.padding_side = 'left'; + const { input_ids, attention_mask } = this.tokenizer(texts, { + add_special_tokens, + padding: true, + truncation: true, + }); + + const outputTokenIds = await this.model.generate(input_ids, generate_kwargs, null, { + inputs_attention_mask: attention_mask + }); + + const decoded = this.tokenizer.batch_decode(outputTokenIds, { + skip_special_tokens: true, + }); + + /** @type {TextGenerationOutput[]} */ + const toReturn = Array.from({ length: texts.length }, _ => []); + for (let i = 0; i < decoded.length; ++i) { + const textIndex = Math.floor(i / outputTokenIds.length * texts.length); + + toReturn[textIndex].push({ + generated_text: decoded[i] + }); + } + return (!isBatched && toReturn.length === 1) ? toReturn[0] : toReturn; + } +} + +/** + * @typedef {Object} ZeroShotClassificationOutput + * @property {string} sequence The sequence for which this is the output. + * @property {string[]} labels The labels sorted by order of likelihood. + * @property {number[]} scores The probabilities for each of the labels. + * + * @typedef {Object} ZeroShotClassificationPipelineOptions Parameters specific to zero-shot classification pipelines. + * @property {string} [hypothesis_template="This example is {}."] The template used to turn each + * candidate label into an NLI-style hypothesis. The candidate label will replace the {} placeholder. + * @property {boolean} [multi_label=false] Whether or not multiple candidate labels can be true. + * If `false`, the scores are normalized such that the sum of the label likelihoods for each sequence + * is 1. If `true`, the labels are considered independent and probabilities are normalized for each + * candidate by doing a softmax of the entailment score vs. the contradiction score. + * + * @callback ZeroShotClassificationPipelineCallback Classify the sequence(s) given as inputs. + * @param {string|string[]} texts The sequence(s) to classify, will be truncated if the model input is too large. + * @param {string|string[]} candidate_labels The set of possible class labels to classify each sequence into. + * Can be a single label, a string of comma-separated labels, or a list of labels. + * @param {ZeroShotClassificationPipelineOptions} [options] The options to use for zero-shot classification. + * @returns {Promise} An array or object containing the predicted labels and scores. + * + * @typedef {TextPipelineConstructorArgs & ZeroShotClassificationPipelineCallback & Disposable} ZeroShotClassificationPipelineType + */ + +/** + * NLI-based zero-shot classification pipeline using a `ModelForSequenceClassification` + * trained on NLI (natural language inference) tasks. Equivalent of `text-classification` + * pipelines, but these models don't require a hardcoded number of potential classes, they + * can be chosen at runtime. It usually means it's slower but it is **much** more flexible. + * + * **Example:** Zero shot classification with `Xenova/mobilebert-uncased-mnli`. + * ```javascript + * const classifier = await pipeline('zero-shot-classification', 'Xenova/mobilebert-uncased-mnli'); + * const text = 'Last week I upgraded my iOS version and ever since then my phone has been overheating whenever I use your app.'; + * const labels = [ 'mobile', 'billing', 'website', 'account access' ]; + * const output = await classifier(text, labels); + * // { + * // sequence: 'Last week I upgraded my iOS version and ever since then my phone has been overheating whenever I use your app.', + * // labels: [ 'mobile', 'website', 'billing', 'account access' ], + * // scores: [ 0.5562091040482018, 0.1843621307860853, 0.13942646639336376, 0.12000229877234923 ] + * // } + * ``` + * + * **Example:** Zero shot classification with `Xenova/nli-deberta-v3-xsmall` (multi-label). + * ```javascript + * const classifier = await pipeline('zero-shot-classification', 'Xenova/nli-deberta-v3-xsmall'); + * const text = 'I have a problem with my iphone that needs to be resolved asap!'; + * const labels = [ 'urgent', 'not urgent', 'phone', 'tablet', 'computer' ]; + * const output = await classifier(text, labels, { multi_label: true }); + * // { + * // sequence: 'I have a problem with my iphone that needs to be resolved asap!', + * // labels: [ 'urgent', 'phone', 'computer', 'tablet', 'not urgent' ], + * // scores: [ 0.9958870956360275, 0.9923963400697035, 0.002333537946160235, 0.0015134138567598765, 0.0010699384208377163 ] + * // } + * ``` + */ +class ZeroShotClassificationPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => ZeroShotClassificationPipelineType} */ (Pipeline)) { + /** + * Create a new ZeroShotClassificationPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + + // Use model config to get label2id mapping + this.label2id = Object.fromEntries( + Object.entries((/** @type {any} */(this).model).config.label2id).map( + ([k, v]) => [k.toLowerCase(), v] + ) + ); + + this.entailment_id = this.label2id['entailment']; + if (this.entailment_id === undefined) { + console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."); + this.entailment_id = 2; + } + + this.contradiction_id = this.label2id['contradiction'] ?? this.label2id['not_entailment']; + if (this.contradiction_id === undefined) { + console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."); + this.contradiction_id = 0; + } + } + + /** @type {ZeroShotClassificationPipelineCallback} */ + async _call(texts, candidate_labels, { + hypothesis_template = "This example is {}.", + multi_label = false, + } = {}) { + + const isBatched = Array.isArray(texts); + if (!isBatched) { + texts = [/** @type {string} */ (texts)]; + } + if (!Array.isArray(candidate_labels)) { + candidate_labels = [candidate_labels]; + } + + // Insert labels into hypothesis template + const hypotheses = candidate_labels.map( + x => hypothesis_template.replace('{}', x) + ); + + // How to perform the softmax over the logits: + // - true: softmax over the entailment vs. contradiction dim for each label independently + // - false: softmax the "entailment" logits over all candidate labels + const softmaxEach = multi_label || candidate_labels.length === 1; + + /** @type {ZeroShotClassificationOutput[]} */ + const toReturn = []; + for (const premise of texts) { + const entails_logits = []; + + for (const hypothesis of hypotheses) { + const inputs = this.tokenizer(premise, { + text_pair: hypothesis, + padding: true, + truncation: true, + }) + const outputs = await this.model(inputs) + + if (softmaxEach) { + entails_logits.push([ + outputs.logits.data[this.contradiction_id], + outputs.logits.data[this.entailment_id] + ]) + } else { + entails_logits.push(outputs.logits.data[this.entailment_id]) + } + } + + /** @type {number[]} */ + const scores = softmaxEach + ? entails_logits.map(x => (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(x)[1]) + : (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(entails_logits); + + // Sort by scores (desc) and return scores with indices + const scores_sorted = scores + .map((x, i) => [x, i]) + .sort((a, b) => (b[0] - a[0])); + + toReturn.push({ + sequence: premise, + labels: scores_sorted.map(x => candidate_labels[x[1]]), + scores: scores_sorted.map(x => x[0]), + }); + } + return isBatched ? toReturn : toReturn[0]; + } +} + +/** + * @typedef {Object} FeatureExtractionPipelineOptions Parameters specific to feature extraction pipelines. + * @property {'none'|'mean'|'cls'} [pooling="none"] The pooling method to use. + * @property {boolean} [normalize=false] Whether or not to normalize the embeddings in the last dimension. + * + * @callback FeatureExtractionPipelineCallback Extract the features of the input(s). + * @param {string|string[]} texts One or several texts (or one list of texts) to get the features of. + * @param {FeatureExtractionPipelineOptions} [options] The options to use for feature extraction. + * @returns {Promise} The features computed by the model. + * + * @typedef {TextPipelineConstructorArgs & FeatureExtractionPipelineCallback & Disposable} FeatureExtractionPipelineType + */ + +/** + * Feature extraction pipeline using no model head. This pipeline extracts the hidden + * states from the base transformer, which can be used as features in downstream tasks. + * + * **Example:** Run feature extraction with `bert-base-uncased` (without pooling/normalization). + * ```javascript + * const extractor = await pipeline('feature-extraction', 'Xenova/bert-base-uncased', { revision: 'default' }); + * const output = await extractor('This is a simple test.'); + * // Tensor { + * // type: 'float32', + * // data: Float32Array [0.05939924716949463, 0.021655935794115067, ...], + * // dims: [1, 8, 768] + * // } + * ``` + * + * **Example:** Run feature extraction with `bert-base-uncased` (with pooling/normalization). + * ```javascript + * const extractor = await pipeline('feature-extraction', 'Xenova/bert-base-uncased', { revision: 'default' }); + * const output = await extractor('This is a simple test.', { pooling: 'mean', normalize: true }); + * // Tensor { + * // type: 'float32', + * // data: Float32Array [0.03373778983950615, -0.010106077417731285, ...], + * // dims: [1, 768] + * // } + * ``` + * + * **Example:** Calculating embeddings with `sentence-transformers` models. + * ```javascript + * const extractor = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'); + * const output = await extractor('This is a simple test.', { pooling: 'mean', normalize: true }); + * // Tensor { + * // type: 'float32', + * // data: Float32Array [0.09094982594251633, -0.014774246141314507, ...], + * // dims: [1, 384] + * // } + * ``` + */ +class FeatureExtractionPipeline extends (/** @type {new (options: TextPipelineConstructorArgs) => FeatureExtractionPipelineType} */ (Pipeline)) { + /** + * Create a new FeatureExtractionPipeline. + * @param {TextPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {FeatureExtractionPipelineCallback} */ + async _call(texts, { + pooling = /** @type {'none'} */('none'), + normalize = false, + } = {}) { + + // Run tokenization + const model_inputs = this.tokenizer(texts, { + padding: true, + truncation: true, + }); + + // Run model + const outputs = await this.model(model_inputs) + + // TODO: Provide warning to the user that they might be using model which was not exported + // specifically for feature extraction + // console.log(this.model.config) + // console.log(outputs) + + /** @type {Tensor} */ + let result = outputs.last_hidden_state ?? outputs.logits; + if (pooling === 'none') { + // Skip pooling + } else if (pooling === 'mean') { + result = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_6__.mean_pooling)(result, model_inputs.attention_mask); + } else if (pooling === 'cls') { + result = result.slice(null, 0); + } else { + throw Error(`Pooling method '${pooling}' not supported.`); + } + + if (normalize) { + result = result.normalize(2, -1); + } + + return result; + } +} + + +/** + * @typedef {Object} ImageFeatureExtractionPipelineOptions Parameters specific to image feature extraction pipelines. + * @property {boolean} [pool=null] Whether or not to return the pooled output. If set to `false`, the model will return the raw hidden states. + * + * @callback ImageFeatureExtractionPipelineCallback Extract the features of the input(s). + * @param {ImagePipelineInputs} images One or several images (or one list of images) to get the features of. + * @param {ImageFeatureExtractionPipelineOptions} [options] The options to use for image feature extraction. + * @returns {Promise} The image features computed by the model. + * + * @typedef {ImagePipelineConstructorArgs & ImageFeatureExtractionPipelineCallback & Disposable} ImageFeatureExtractionPipelineType + */ + +/** + * Image feature extraction pipeline using no model head. This pipeline extracts the hidden + * states from the base transformer, which can be used as features in downstream tasks. + * + * **Example:** Perform image feature extraction with `Xenova/vit-base-patch16-224-in21k`. + * ```javascript + * const image_feature_extractor = await pipeline('image-feature-extraction', 'Xenova/vit-base-patch16-224-in21k'); + * const url = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cats.png'; + * const features = await image_feature_extractor(url); + * // Tensor { + * // dims: [ 1, 197, 768 ], + * // type: 'float32', + * // data: Float32Array(151296) [ ... ], + * // size: 151296 + * // } + * ``` + * + * **Example:** Compute image embeddings with `Xenova/clip-vit-base-patch32`. + * ```javascript + * const image_feature_extractor = await pipeline('image-feature-extraction', 'Xenova/clip-vit-base-patch32'); + * const url = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cats.png'; + * const features = await image_feature_extractor(url); + * // Tensor { + * // dims: [ 1, 512 ], + * // type: 'float32', + * // data: Float32Array(512) [ ... ], + * // size: 512 + * // } + * ``` + */ +class ImageFeatureExtractionPipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => ImageFeatureExtractionPipelineType} */ (Pipeline)) { + /** + * Create a new ImageFeatureExtractionPipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ImageFeatureExtractionPipelineCallback} */ + async _call(images, { + pool = null, + } = {}) { + + const preparedImages = await prepareImages(images); + const { pixel_values } = await this.processor(preparedImages); + const outputs = await this.model({ pixel_values }); + + /** @type {Tensor} */ + let result; + if (pool) { + if (!('pooler_output' in outputs)) { + throw Error(`No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.`); + } + result = outputs.pooler_output; + + } else { + result = outputs.last_hidden_state ?? outputs.logits ?? outputs.image_embeds; + } + return result; + } +} + +// TODO +// export class SentenceSimilarityPipeline extends Pipeline { +// } + +/** + * @typedef {Object} AudioClassificationSingle + * @property {string} label The label predicted. + * @property {number} score The corresponding probability. + * @typedef {AudioClassificationSingle[]} AudioClassificationOutput + * + * @typedef {Object} AudioClassificationPipelineOptions Parameters specific to audio classification pipelines. + * @property {number} [topk=null] The number of top labels that will be returned by the pipeline. + * If the provided number is `null` or higher than the number of labels available in the model configuration, + * it will default to the number of labels. + * + * @callback AudioClassificationPipelineCallback Classify the sequence(s) given as inputs. + * @param {AudioPipelineInputs} audio The input audio file(s) to be classified. The input is either: + * - `string` or `URL` that is the filename/URL of the audio file, the file will be read at the processor's sampling rate + * to get the waveform using the [`AudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) API. + * If `AudioContext` is not available, you should pass the raw waveform in as a Float32Array of shape `(n, )`. + * - `Float32Array` or `Float64Array` of shape `(n, )`, representing the raw audio at the correct sampling rate (no further check will be done). + * @param {AudioClassificationPipelineOptions} [options] The options to use for audio classification. + * @returns {Promise} An array or object containing the predicted labels and scores. + * + * @typedef {AudioPipelineConstructorArgs & AudioClassificationPipelineCallback & Disposable} AudioClassificationPipelineType + */ + +/** + * Audio classification pipeline using any `AutoModelForAudioClassification`. + * This pipeline predicts the class of a raw waveform or an audio file. + * + * **Example:** Perform audio classification with `Xenova/wav2vec2-large-xlsr-53-gender-recognition-librispeech`. + * ```javascript + * const classifier = await pipeline('audio-classification', 'Xenova/wav2vec2-large-xlsr-53-gender-recognition-librispeech'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const output = await classifier(url); + * // [ + * // { label: 'male', score: 0.9981542229652405 }, + * // { label: 'female', score: 0.001845747814513743 } + * // ] + * ``` + * + * **Example:** Perform audio classification with `Xenova/ast-finetuned-audioset-10-10-0.4593` and return top 4 results. + * ```javascript + * const classifier = await pipeline('audio-classification', 'Xenova/ast-finetuned-audioset-10-10-0.4593'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cat_meow.wav'; + * const output = await classifier(url, { topk: 4 }); + * // [ + * // { label: 'Meow', score: 0.5617874264717102 }, + * // { label: 'Cat', score: 0.22365376353263855 }, + * // { label: 'Domestic animals, pets', score: 0.1141069084405899 }, + * // { label: 'Animal', score: 0.08985692262649536 }, + * // ] + * ``` + */ +class AudioClassificationPipeline extends (/** @type {new (options: AudioPipelineConstructorArgs) => AudioClassificationPipelineType} */ (Pipeline)) { + + /** + * Create a new AudioClassificationPipeline. + * @param {AudioPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {AudioClassificationPipelineCallback} */ + async _call(audio, { + topk = null + } = {}) { + + const single = !Array.isArray(audio); + + const sampling_rate = this.processor.feature_extractor.config.sampling_rate; + const preparedAudios = await prepareAudios(audio, sampling_rate); + + const id2label = this.model.config.id2label; + + const toReturn = []; + for (const aud of preparedAudios) { + const inputs = await this.processor(aud); + const output = await this.model(inputs); + const logits = output.logits[0]; + + const scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.getTopItems)((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(logits.data), topk); + + const vals = scores.map(x => ({ + label: /** @type {string} */ (id2label[x[0]]), + score: /** @type {number} */ (x[1]), + })); + + if (topk === 1) { + toReturn.push(...vals); + } else { + toReturn.push(vals); + } + } + return !single || topk === 1 ? /** @type {AudioClassificationOutput} */ (toReturn) : /** @type {AudioClassificationOutput[]} */ (toReturn)[0]; + } +} + +/** + * @typedef {Object} ZeroShotAudioClassificationOutput + * @property {string} label The label identified by the model. It is one of the suggested `candidate_label`. + * @property {number} score The score attributed by the model for that label (between 0 and 1). + * + * @typedef {Object} ZeroShotAudioClassificationPipelineOptions Parameters specific to zero-shot audio classification pipelines. + * @property {string} [hypothesis_template="This is a sound of {}."] The sentence used in conjunction with `candidate_labels` + * to attempt the audio classification by replacing the placeholder with the candidate_labels. + * Then likelihood is estimated by using `logits_per_audio`. + * + * @callback ZeroShotAudioClassificationPipelineCallback Classify the sequence(s) given as inputs. + * @param {AudioPipelineInputs} audio The input audio file(s) to be classified. The input is either: + * - `string` or `URL` that is the filename/URL of the audio file, the file will be read at the processor's sampling rate + * to get the waveform using the [`AudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) API. + * If `AudioContext` is not available, you should pass the raw waveform in as a Float32Array of shape `(n, )`. + * - `Float32Array` or `Float64Array` of shape `(n, )`, representing the raw audio at the correct sampling rate (no further check will be done). + * @param {string[]} candidate_labels The candidate labels for this audio. + * @param {ZeroShotAudioClassificationPipelineOptions} [options] The options to use for zero-shot audio classification. + * @returns {Promise} An array of objects containing the predicted labels and scores. + * + * @typedef {TextAudioPipelineConstructorArgs & ZeroShotAudioClassificationPipelineCallback & Disposable} ZeroShotAudioClassificationPipelineType + */ + +/** + * Zero shot audio classification pipeline using `ClapModel`. This pipeline predicts the class of an audio when you + * provide an audio and a set of `candidate_labels`. + * + * **Example**: Perform zero-shot audio classification with `Xenova/clap-htsat-unfused`. + * ```javascript + * const classifier = await pipeline('zero-shot-audio-classification', 'Xenova/clap-htsat-unfused'); + * const audio = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/dog_barking.wav'; + * const candidate_labels = ['dog', 'vaccum cleaner']; + * const scores = await classifier(audio, candidate_labels); + * // [ + * // { score: 0.9993992447853088, label: 'dog' }, + * // { score: 0.0006007603369653225, label: 'vaccum cleaner' } + * // ] + * ``` + */ +class ZeroShotAudioClassificationPipeline extends (/** @type {new (options: TextAudioPipelineConstructorArgs) => ZeroShotAudioClassificationPipelineType} */ (Pipeline)) { + + /** + * Create a new ZeroShotAudioClassificationPipeline. + * @param {TextAudioPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ZeroShotAudioClassificationPipelineCallback} */ + async _call(audio, candidate_labels, { + hypothesis_template = "This is a sound of {}." + } = {}) { + + const single = !Array.isArray(audio); + if (single) { + audio = [/** @type {AudioInput} */ (audio)]; + } + + // Insert label into hypothesis template + const texts = candidate_labels.map( + x => hypothesis_template.replace('{}', x) + ); + + // Run tokenization + const text_inputs = this.tokenizer(texts, { + padding: true, + truncation: true, + }); + + const sampling_rate = this.processor.feature_extractor.config.sampling_rate; + const preparedAudios = await prepareAudios(audio, sampling_rate); + + const toReturn = []; + for (const aud of preparedAudios) { + const audio_inputs = await this.processor(aud); + + // Run model with both text and audio inputs + const output = await this.model({ ...text_inputs, ...audio_inputs }); + + // Compute softmax per audio + const probs = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(output.logits_per_audio.data); + + toReturn.push([...probs].map((x, i) => ({ + score: x, + label: candidate_labels[i] + }))); + } + return single ? toReturn[0] : toReturn; + } +} + +/** + * @typedef {{stride: number[], input_features: Tensor, is_last: boolean, tokens?: number[], token_timestamps?: number[]}} ChunkCallbackItem + * @callback ChunkCallback + * @param {ChunkCallbackItem} chunk The chunk to process. + */ + +/** + * @typedef {Object} Chunk + * @property {[number, number]} timestamp The start and end timestamp of the chunk in seconds. + * @property {string} text The recognized text. + */ + +/** + * @typedef {Object} AutomaticSpeechRecognitionOutput + * @property {string} text The recognized text. + * @property {Chunk[]} [chunks] When using `return_timestamps`, the `chunks` will become a list + * containing all the various text chunks identified by the model. + * + * @typedef {Object} AutomaticSpeechRecognitionSpecificParams Parameters specific to automatic-speech-recognition pipelines. + * @property {boolean|'word'} [kwargs.return_timestamps] Whether to return timestamps or not. Default is `false`. + * @property {number} [kwargs.chunk_length_s] The length of audio chunks to process in seconds. Default is 0 (no chunking). + * @property {number} [kwargs.stride_length_s] The length of overlap between consecutive audio chunks in seconds. If not provided, defaults to `chunk_length_s / 6`. + * @property {ChunkCallback} [kwargs.chunk_callback] Callback function to be called with each chunk processed. + * @property {boolean} [kwargs.force_full_sequences] Whether to force outputting full sequences or not. Default is `false`. + * @property {string} [kwargs.language] The source language. Default is `null`, meaning it should be auto-detected. Use this to potentially improve performance if the source language is known. + * @property {string} [kwargs.task] The task to perform. Default is `null`, meaning it should be auto-detected. + * @property {number[][]} [kwargs.forced_decoder_ids] A list of pairs of integers which indicates a mapping from generation indices to token indices + * that will be forced before sampling. For example, [[1, 123]] means the second generated token will always be a token of index 123. + * @property {number} [num_frames] The number of frames in the input audio. + * @typedef {import('./utils/generation.js').GenerationConfigType & AutomaticSpeechRecognitionSpecificParams} AutomaticSpeechRecognitionConfig + * + * @callback AutomaticSpeechRecognitionPipelineCallback Transcribe the audio sequence(s) given as inputs to text. + * @param {AudioPipelineInputs} audio The input audio file(s) to be transcribed. The input is either: + * - `string` or `URL` that is the filename/URL of the audio file, the file will be read at the processor's sampling rate + * to get the waveform using the [`AudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) API. + * If `AudioContext` is not available, you should pass the raw waveform in as a Float32Array of shape `(n, )`. + * - `Float32Array` or `Float64Array` of shape `(n, )`, representing the raw audio at the correct sampling rate (no further check will be done). + * @param {AutomaticSpeechRecognitionConfig} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} An object containing the transcription text and optionally timestamps if `return_timestamps` is `true`. + * + * @typedef {TextAudioPipelineConstructorArgs & AutomaticSpeechRecognitionPipelineCallback & Disposable} AutomaticSpeechRecognitionPipelineType + */ + +/** + * Pipeline that aims at extracting spoken text contained within some audio. + * + * **Example:** Transcribe English. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const output = await transcriber(url); + * // { text: " And so my fellow Americans ask not what your country can do for you, ask what you can do for your country." } + * ``` + * + * **Example:** Transcribe English w/ timestamps. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const output = await transcriber(url, { return_timestamps: true }); + * // { + * // text: " And so my fellow Americans ask not what your country can do for you, ask what you can do for your country." + * // chunks: [ + * // { timestamp: [0, 8], text: " And so my fellow Americans ask not what your country can do for you" } + * // { timestamp: [8, 11], text: " ask what you can do for your country." } + * // ] + * // } + * ``` + * + * **Example:** Transcribe English w/ word-level timestamps. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav'; + * const output = await transcriber(url, { return_timestamps: 'word' }); + * // { + * // "text": " And so my fellow Americans ask not what your country can do for you ask what you can do for your country.", + * // "chunks": [ + * // { "text": " And", "timestamp": [0, 0.78] }, + * // { "text": " so", "timestamp": [0.78, 1.06] }, + * // { "text": " my", "timestamp": [1.06, 1.46] }, + * // ... + * // { "text": " for", "timestamp": [9.72, 9.92] }, + * // { "text": " your", "timestamp": [9.92, 10.22] }, + * // { "text": " country.", "timestamp": [10.22, 13.5] } + * // ] + * // } + * ``` + * + * **Example:** Transcribe French. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-small'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/french-audio.mp3'; + * const output = await transcriber(url, { language: 'french', task: 'transcribe' }); + * // { text: " J'adore, j'aime, je n'aime pas, je déteste." } + * ``` + * + * **Example:** Translate French to English. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-small'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/french-audio.mp3'; + * const output = await transcriber(url, { language: 'french', task: 'translate' }); + * // { text: " I love, I like, I don't like, I hate." } + * ``` + * + * **Example:** Transcribe/translate audio longer than 30 seconds. + * ```javascript + * const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ted_60.wav'; + * const output = await transcriber(url, { chunk_length_s: 30, stride_length_s: 5 }); + * // { text: " So in college, I was a government major, which means [...] So I'd start off light and I'd bump it up" } + * ``` + */ +class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options: TextAudioPipelineConstructorArgs) => AutomaticSpeechRecognitionPipelineType} */ (Pipeline)) { + + /** + * Create a new AutomaticSpeechRecognitionPipeline. + * @param {TextAudioPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {AutomaticSpeechRecognitionPipelineCallback} */ + async _call(audio, kwargs = {}) { + switch (this.model.config.model_type) { + case 'whisper': + return this._call_whisper(audio, kwargs) + case 'wav2vec2': + case 'wav2vec2-bert': + case 'unispeech': + case 'unispeech-sat': + case 'hubert': + return this._call_wav2vec2(audio, kwargs) + default: + throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`) + } + } + + /** + * @type {AutomaticSpeechRecognitionPipelineCallback} + * @private + */ + async _call_wav2vec2(audio, kwargs = {}) { + // TODO use kwargs + + if (kwargs.language) { + console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'); + } + if (kwargs.task) { + console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".'); + } + + const single = !Array.isArray(audio); + if (single) { + audio = [/** @type {AudioInput} */ (audio)]; + } + + const sampling_rate = this.processor.feature_extractor.config.sampling_rate; + const preparedAudios = await prepareAudios(audio, sampling_rate); + + const toReturn = []; + for (const aud of preparedAudios) { + const inputs = await this.processor(aud); + const output = await this.model(inputs); + const logits = output.logits[0]; + + const predicted_ids = []; + for (const item of logits) { + predicted_ids.push((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.max)(item.data)[1]) + } + const predicted_sentences = this.tokenizer.decode(predicted_ids) + toReturn.push({ text: predicted_sentences }) + } + return single ? toReturn[0] : toReturn; + } + + /** + * @type {AutomaticSpeechRecognitionPipelineCallback} + * @private + */ + async _call_whisper(audio, kwargs = {}) { + + const return_timestamps = kwargs.return_timestamps ?? false; + const chunk_length_s = kwargs.chunk_length_s ?? 0; + const chunk_callback = kwargs.chunk_callback ?? null; + const force_full_sequences = kwargs.force_full_sequences ?? false; + let stride_length_s = kwargs.stride_length_s ?? null; + + if (return_timestamps === 'word') { + kwargs['return_token_timestamps'] = true; + } + + const language = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_3__.pop)(kwargs, 'language', null); + const task = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_3__.pop)(kwargs, 'task', null); + + if (language || task || return_timestamps) { + if (kwargs.forced_decoder_ids) { + throw new Error("Cannot specify `language`/`task`/`return_timestamps` and `forced_decoder_ids` at the same time.") + } + // @ts-ignore + const decoder_prompt_ids = this.tokenizer.get_decoder_prompt_ids({ language, task, no_timestamps: !return_timestamps }) + if (decoder_prompt_ids.length > 0) { + kwargs.forced_decoder_ids = decoder_prompt_ids; + } + } + + const single = !Array.isArray(audio); + if (single) { + audio = [/** @type {AudioInput} */ (audio)]; + } + + const time_precision = this.processor.feature_extractor.config.chunk_length / this.model.config.max_source_positions; + const hop_length = this.processor.feature_extractor.config.hop_length; + + const sampling_rate = this.processor.feature_extractor.config.sampling_rate; + const preparedAudios = await prepareAudios(audio, sampling_rate); + + const toReturn = []; + for (const aud of preparedAudios) { + /** @type {ChunkCallbackItem[]} */ + let chunks = []; + if (chunk_length_s > 0) { + if (stride_length_s === null) { + stride_length_s = chunk_length_s / 6; + } else if (chunk_length_s <= stride_length_s) { + throw Error("`chunk_length_s` must be larger than `stride_length_s`.") + } + + // TODO support different stride_length_s (for left and right) + + const window = sampling_rate * chunk_length_s; + const stride = sampling_rate * stride_length_s; + const jump = window - 2 * stride; + let offset = 0; + + // Create subarrays of audio with overlaps + + while (offset < aud.length) { + const subarr = aud.subarray(offset, offset + window); + const feature = await this.processor(subarr); + + const isFirst = offset === 0; + const isLast = offset + jump >= aud.length; + chunks.push({ + stride: [ + subarr.length, + isFirst ? 0 : stride, + isLast ? 0 : stride + ], + input_features: feature.input_features, + is_last: isLast + }) + offset += jump; + } + + } else { + chunks = [{ + stride: [aud.length, 0, 0], + input_features: (await this.processor(aud)).input_features, + is_last: true + }] + } + + // Generate for each set of input features + for (const chunk of chunks) { + kwargs.num_frames = Math.floor(chunk.stride[0] / hop_length); + + // NOTE: doing sequentially for now + const data = await this.model.generate(chunk.input_features, kwargs); + + // TODO: Right now we only get top beam + if (return_timestamps === 'word') { + chunk.tokens = data.sequences[0]; + chunk.token_timestamps = data.token_timestamps.tolist()[0].map( + (/** @type {number} */ x) => (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.round)(x, 2) + ); + + } else { + chunk.tokens = data[0]; + } + + // convert stride to seconds + chunk.stride = chunk.stride.map(x => x / sampling_rate); + + if (chunk_callback !== null) { + chunk_callback(chunk) + } + } + + // Merge text chunks + // @ts-ignore + const [full_text, optional] = this.tokenizer._decode_asr(chunks, { + time_precision, return_timestamps, force_full_sequences + }); + + toReturn.push({ text: full_text, ...optional }) + } + return single ? toReturn[0] : toReturn; + } +} + +/** + * @typedef {Object} ImageToTextSingle + * @property {string} generated_text The generated text. + * @typedef {ImageToTextSingle[]} ImageToTextOutput + * + * @callback ImageToTextPipelineCallback Assign labels to the image(s) passed as inputs. + * @param {ImagePipelineInputs} texts The images to be captioned. + * @param {import('./utils/generation.js').GenerationConfigType} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} An object (or array of objects) containing the generated text(s). + * + * @typedef {TextImagePipelineConstructorArgs & ImageToTextPipelineCallback & Disposable} ImageToTextPipelineType + */ + +/** + * Image To Text pipeline using a `AutoModelForVision2Seq`. This pipeline predicts a caption for a given image. + * + * **Example:** Generate a caption for an image w/ `Xenova/vit-gpt2-image-captioning`. + * ```javascript + * const captioner = await pipeline('image-to-text', 'Xenova/vit-gpt2-image-captioning'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg'; + * const output = await captioner(url); + * // [{ generated_text: 'a cat laying on a couch with another cat' }] + * ``` + * + * **Example:** Optical Character Recognition (OCR) w/ `Xenova/trocr-small-handwritten`. + * ```javascript + * const captioner = await pipeline('image-to-text', 'Xenova/trocr-small-handwritten'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/handwriting.jpg'; + * const output = await captioner(url); + * // [{ generated_text: 'Mr. Brown commented icily.' }] + * ``` + */ +class ImageToTextPipeline extends (/** @type {new (options: TextImagePipelineConstructorArgs) => ImageToTextPipelineType} */ (Pipeline)) { + + /** + * Create a new ImageToTextPipeline. + * @param {TextImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ImageToTextPipelineCallback} */ + async _call(images, generate_kwargs = {}) { + + const isBatched = Array.isArray(images); + const preparedImages = await prepareImages(images); + + const { pixel_values } = await this.processor(preparedImages); + + const toReturn = []; + for (const batch of pixel_values) { + batch.dims = [1, ...batch.dims] + const output = await this.model.generate(batch, generate_kwargs); + const decoded = this.tokenizer.batch_decode(output, { + skip_special_tokens: true, + }).map(x => ({ generated_text: x.trim() })) + toReturn.push(decoded); + } + + return isBatched ? toReturn : toReturn[0]; + } +} + +/** + * @typedef {Object} ImageClassificationSingle + * @property {string} label The label identified by the model. + * @property {number} score The score attributed by the model for that label. + * @typedef {ImageClassificationSingle[]} ImageClassificationOutput + * + * @typedef {Object} ImageClassificationPipelineOptions Parameters specific to image classification pipelines. + * @property {number} [topk=1] The number of top labels that will be returned by the pipeline. + * + * @callback ImageClassificationPipelineCallback Assign labels to the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The input images(s) to be classified. + * @param {ImageClassificationPipelineOptions} [options] The options to use for image classification. + * @returns {Promise} An array or object containing the predicted labels and scores. + * + * @typedef {ImagePipelineConstructorArgs & ImageClassificationPipelineCallback & Disposable} ImageClassificationPipelineType + */ + +/** + * Image classification pipeline using any `AutoModelForImageClassification`. + * This pipeline predicts the class of an image. + * + * **Example:** Classify an image. + * ```javascript + * const classifier = await pipeline('image-classification', 'Xenova/vit-base-patch16-224'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg'; + * const output = await classifier(url); + * // [ + * // { label: 'tiger, Panthera tigris', score: 0.632695734500885 }, + * // ] + * ``` + * + * **Example:** Classify an image and return top `n` classes. + * ```javascript + * const classifier = await pipeline('image-classification', 'Xenova/vit-base-patch16-224'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg'; + * const output = await classifier(url, { topk: 3 }); + * // [ + * // { label: 'tiger, Panthera tigris', score: 0.632695734500885 }, + * // { label: 'tiger cat', score: 0.3634825646877289 }, + * // { label: 'lion, king of beasts, Panthera leo', score: 0.00045060308184474707 }, + * // ] + * ``` + * + * **Example:** Classify an image and return all classes. + * ```javascript + * const classifier = await pipeline('image-classification', 'Xenova/vit-base-patch16-224'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg'; + * const output = await classifier(url, { topk: 0 }); + * // [ + * // { label: 'tiger, Panthera tigris', score: 0.632695734500885 }, + * // { label: 'tiger cat', score: 0.3634825646877289 }, + * // { label: 'lion, king of beasts, Panthera leo', score: 0.00045060308184474707 }, + * // { label: 'jaguar, panther, Panthera onca, Felis onca', score: 0.00035465499968267977 }, + * // ... + * // ] + * ``` + */ +class ImageClassificationPipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => ImageClassificationPipelineType} */ (Pipeline)) { + + /** + * Create a new ImageClassificationPipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ImageClassificationPipelineCallback} */ + async _call(images, { + topk = 1 + } = {}) { + + const isBatched = Array.isArray(images); + const preparedImages = await prepareImages(images); + + const { pixel_values } = await this.processor(preparedImages); + const output = await this.model({ pixel_values }); + + const id2label = this.model.config.id2label; + const toReturn = []; + for (const batch of output.logits) { + const scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.getTopItems)((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(batch.data), topk); + + const vals = scores.map(x => ({ + label: id2label[x[0]], + score: x[1], + })); + if (topk === 1) { + toReturn.push(...vals); + } else { + toReturn.push(vals); + } + } + + return isBatched || topk === 1 ? /** @type {ImageClassificationOutput} */ (toReturn) : /** @type {ImageClassificationOutput[]} */ (toReturn)[0]; + } + +} + +/** + * @typedef {Object} ImageSegmentationPipelineOutput + * @property {string} label The label of the segment. + * @property {number|null} score The score of the segment. + * @property {RawImage} mask The mask of the segment. + * + * @typedef {Object} ImageSegmentationPipelineOptions Parameters specific to image segmentation pipelines. + * @property {number} [threshold=0.5] Probability threshold to filter out predicted masks. + * @property {number} [mask_threshold=0.5] Threshold to use when turning the predicted masks into binary values. + * @property {number} [overlap_mask_area_threshold=0.8] Mask overlap threshold to eliminate small, disconnected segments. + * @property {null|string} [subtask=null] Segmentation task to be performed. One of [`panoptic`, `instance`, and `semantic`], + * depending on model capabilities. If not set, the pipeline will attempt to resolve (in that order). + * @property {number[]} [label_ids_to_fuse=null] List of label ids to fuse. If not set, do not fuse any labels. + * @property {number[][]} [target_sizes=null] List of target sizes for the input images. If not set, use the original image sizes. + * + * @callback ImageSegmentationPipelineCallback Segment the input images. + * @param {ImagePipelineInputs} images The input images. + * @param {ImageSegmentationPipelineOptions} [options] The options to use for image segmentation. + * @returns {Promise} The annotated segments. + * + * @typedef {ImagePipelineConstructorArgs & ImageSegmentationPipelineCallback & Disposable} ImageSegmentationPipelineType + */ + +/** + * Image segmentation pipeline using any `AutoModelForXXXSegmentation`. + * This pipeline predicts masks of objects and their classes. + * + * **Example:** Perform image segmentation with `Xenova/detr-resnet-50-panoptic`. + * ```javascript + * const segmenter = await pipeline('image-segmentation', 'Xenova/detr-resnet-50-panoptic'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg'; + * const output = await segmenter(url); + * // [ + * // { label: 'remote', score: 0.9984649419784546, mask: RawImage { ... } }, + * // { label: 'cat', score: 0.9994316101074219, mask: RawImage { ... } } + * // ] + * ``` + */ +class ImageSegmentationPipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => ImageSegmentationPipelineType} */ (Pipeline)) { + /** + * Create a new ImageSegmentationPipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + + this.subtasks_mapping = { + // Mapping of subtasks to their corresponding post-processing function names. + panoptic: 'post_process_panoptic_segmentation', + instance: 'post_process_instance_segmentation', + semantic: 'post_process_semantic_segmentation' + } + } + + /** @type {ImageSegmentationPipelineCallback} */ + async _call(images, { + threshold = 0.5, + mask_threshold = 0.5, + overlap_mask_area_threshold = 0.8, + label_ids_to_fuse = null, + target_sizes = null, + subtask = null, + } = {}) { + const isBatched = Array.isArray(images); + + if (isBatched && images.length !== 1) { + throw Error("Image segmentation pipeline currently only supports a batch size of 1."); + } + + const preparedImages = await prepareImages(images); + const imageSizes = preparedImages.map(x => [x.height, x.width]); + + const { pixel_values, pixel_mask } = await this.processor(preparedImages); + const output = await this.model({ pixel_values, pixel_mask }); + + let fn = null; + if (subtask !== null) { + fn = this.subtasks_mapping[subtask]; + } else { + for (let [task, func] of Object.entries(this.subtasks_mapping)) { + if (func in this.processor.feature_extractor) { + fn = this.processor.feature_extractor[func].bind(this.processor.feature_extractor); + subtask = task; + break; + } + } + } + + const id2label = this.model.config.id2label; + + /** @type {ImageSegmentationPipelineOutput[]} */ + const annotation = []; + if (subtask === 'panoptic' || subtask === 'instance') { + const processed = fn( + output, + threshold, + mask_threshold, + overlap_mask_area_threshold, + label_ids_to_fuse, + target_sizes ?? imageSizes, // TODO FIX? + )[0]; + + const segmentation = processed.segmentation; + + for (const segment of processed.segments_info) { + const maskData = new Uint8ClampedArray(segmentation.data.length); + for (let i = 0; i < segmentation.data.length; ++i) { + if (segmentation.data[i] === segment.id) { + maskData[i] = 255; + } + } + + const mask = new _utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage(maskData, segmentation.dims[1], segmentation.dims[0], 1) + + annotation.push({ + score: segment.score, + label: id2label[segment.label_id], + mask: mask + }) + } + + } else if (subtask === 'semantic') { + const { segmentation, labels } = fn(output, target_sizes ?? imageSizes)[0]; + + for (const label of labels) { + const maskData = new Uint8ClampedArray(segmentation.data.length); + for (let i = 0; i < segmentation.data.length; ++i) { + if (segmentation.data[i] === label) { + maskData[i] = 255; + } + } + + const mask = new _utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage(maskData, segmentation.dims[1], segmentation.dims[0], 1); + + annotation.push({ + score: null, + label: id2label[label], + mask: mask + }); + } + } else { + throw Error(`Subtask ${subtask} not supported.`); + } + + return annotation; + } +} + +/** + * @typedef {Object} ZeroShotImageClassificationOutput + * @property {string} label The label identified by the model. It is one of the suggested `candidate_label`. + * @property {number} score The score attributed by the model for that label (between 0 and 1). + * + * @typedef {Object} ZeroShotImageClassificationPipelineOptions Parameters specific to zero-shot image classification pipelines. + * @property {string} [hypothesis_template="This is a photo of {}"] The sentence used in conjunction with `candidate_labels` + * to attempt the image classification by replacing the placeholder with the candidate_labels. + * Then likelihood is estimated by using `logits_per_image`. + * + * @callback ZeroShotImageClassificationPipelineCallback Assign labels to the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The input images. + * @param {string[]} candidate_labels The candidate labels for this image. + * @param {ZeroShotImageClassificationPipelineOptions} [options] The options to use for zero-shot image classification. + * @returns {Promise} An array of objects containing the predicted labels and scores. + * + * @typedef {TextImagePipelineConstructorArgs & ZeroShotImageClassificationPipelineCallback & Disposable} ZeroShotImageClassificationPipelineType + */ + +/** + * Zero shot image classification pipeline. This pipeline predicts the class of + * an image when you provide an image and a set of `candidate_labels`. + * + * **Example:** Zero shot image classification w/ `Xenova/clip-vit-base-patch32`. + * ```javascript + * const classifier = await pipeline('zero-shot-image-classification', 'Xenova/clip-vit-base-patch32'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg'; + * const output = await classifier(url, ['tiger', 'horse', 'dog']); + * // [ + * // { score: 0.9993917942047119, label: 'tiger' }, + * // { score: 0.0003519294841680676, label: 'horse' }, + * // { score: 0.0002562698791734874, label: 'dog' } + * // ] + * ``` + */ +class ZeroShotImageClassificationPipeline extends (/** @type {new (options: TextImagePipelineConstructorArgs) => ZeroShotImageClassificationPipelineType} */ (Pipeline)) { + /** + * Create a new ZeroShotImageClassificationPipeline. + * @param {TextImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ZeroShotImageClassificationPipelineCallback} */ + async _call(images, candidate_labels, { + hypothesis_template = "This is a photo of {}" + } = {}) { + + const isBatched = Array.isArray(images); + const preparedImages = await prepareImages(images); + + // Insert label into hypothesis template + const texts = candidate_labels.map( + x => hypothesis_template.replace('{}', x) + ); + + // Run tokenization + const text_inputs = this.tokenizer(texts, { + padding: this.model.config.model_type === 'siglip' ? 'max_length' : true, + truncation: true, + }); + + // Run processor + const { pixel_values } = await this.processor(preparedImages); + + // Run model with both text and pixel inputs + const output = await this.model({ ...text_inputs, pixel_values }); + + const function_to_apply = + this.model.config.model_type === 'siglip' + ? batch => batch.sigmoid().data + : batch => (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.softmax)(batch.data); + + // Compare each image with each candidate label + const toReturn = []; + for (const batch of output.logits_per_image) { + // Compute softmax per image + const probs = function_to_apply(batch); + + const result = [...probs].map((x, i) => ({ + score: x, + label: candidate_labels[i] + })); + result.sort((a, b) => b.score - a.score); // sort by score in descending order + toReturn.push(result); + } + + return isBatched ? toReturn : toReturn[0]; + } +} + + +/** + * @typedef {Object} ObjectDetectionPipelineSingle + * @property {string} label The class label identified by the model. + * @property {number} score The score attributed by the model for that label. + * @property {BoundingBox} box The bounding box of detected object in image's original size, or as a percentage if `percentage` is set to true. + * @typedef {ObjectDetectionPipelineSingle[]} ObjectDetectionPipelineOutput + * + * @typedef {Object} ObjectDetectionPipelineOptions Parameters specific to object detection pipelines. + * @property {number} [threshold=0.9] The threshold used to filter boxes by score. + * @property {boolean} [percentage=false] Whether to return the boxes coordinates in percentage (true) or in pixels (false). + * + * @callback ObjectDetectionPipelineCallback Detect objects (bounding boxes & classes) in the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The input images. + * @param {ObjectDetectionPipelineOptions} [options] The options to use for object detection. + * @returns {Promise} A list of objects or a list of list of objects. + * + * @typedef {ImagePipelineConstructorArgs & ObjectDetectionPipelineCallback & Disposable} ObjectDetectionPipelineType + */ + +/** + * Object detection pipeline using any `AutoModelForObjectDetection`. + * This pipeline predicts bounding boxes of objects and their classes. + * + * **Example:** Run object-detection with `Xenova/detr-resnet-50`. + * ```javascript + * const detector = await pipeline('object-detection', 'Xenova/detr-resnet-50'); + * const img = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg'; + * const output = await detector(img, { threshold: 0.9 }); + * // [{ + * // score: 0.9976370930671692, + * // label: "remote", + * // box: { xmin: 31, ymin: 68, xmax: 190, ymax: 118 } + * // }, + * // ... + * // { + * // score: 0.9984092116355896, + * // label: "cat", + * // box: { xmin: 331, ymin: 19, xmax: 649, ymax: 371 } + * // }] + * ``` + */ +class ObjectDetectionPipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => ObjectDetectionPipelineType} */ (Pipeline)) { + + /** + * Create a new ObjectDetectionPipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ObjectDetectionPipelineCallback} */ + async _call(images, { + threshold = 0.9, + percentage = false, + } = {}) { + + const isBatched = Array.isArray(images); + + if (isBatched && images.length !== 1) { + throw Error("Object detection pipeline currently only supports a batch size of 1."); + } + const preparedImages = await prepareImages(images); + + const imageSizes = percentage ? null : preparedImages.map(x => [x.height, x.width]); + + const { pixel_values, pixel_mask } = await this.processor(preparedImages); + const output = await this.model({ pixel_values, pixel_mask }); + + // @ts-ignore + const processed = this.processor.feature_extractor.post_process_object_detection(output, threshold, imageSizes); + + // Add labels + const id2label = this.model.config.id2label; + + // Format output + /** @type {ObjectDetectionPipelineOutput[]} */ + const result = processed.map(batch => ( + batch.boxes.map((box, i) => ({ + score: batch.scores[i], + label: id2label[batch.classes[i]], + box: get_bounding_box(box, !percentage), + })) + )) + + return isBatched ? result : result[0]; + } +} + + +/** + * @typedef {Object} ZeroShotObjectDetectionOutput + * @property {string} label Text query corresponding to the found object. + * @property {number} score Score corresponding to the object (between 0 and 1). + * @property {BoundingBox} box Bounding box of the detected object in image's original size, or as a percentage if `percentage` is set to true. + * + * @typedef {Object} ZeroShotObjectDetectionPipelineOptions Parameters specific to zero-shot object detection pipelines. + * @property {number} [threshold=0.1] The probability necessary to make a prediction. + * @property {number} [topk=null] The number of top predictions that will be returned by the pipeline. + * If the provided number is `null` or higher than the number of predictions available, it will default + * to the number of predictions. + * @property {boolean} [percentage=false] Whether to return the boxes coordinates in percentage (true) or in pixels (false). + * + * @callback ZeroShotObjectDetectionPipelineCallback Detect objects (bounding boxes & classes) in the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The input images. + * @param {string[]} candidate_labels What the model should recognize in the image. + * @param {ZeroShotObjectDetectionPipelineOptions} [options] The options to use for zero-shot object detection. + * @returns {Promise} An array of objects containing the predicted labels, scores, and bounding boxes. + * + * @typedef {TextImagePipelineConstructorArgs & ZeroShotObjectDetectionPipelineCallback & Disposable} ZeroShotObjectDetectionPipelineType + */ + +/** + * Zero-shot object detection pipeline. This pipeline predicts bounding boxes of + * objects when you provide an image and a set of `candidate_labels`. + * + * **Example:** Zero-shot object detection w/ `Xenova/owlvit-base-patch32`. + * ```javascript + * const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/astronaut.png'; + * const candidate_labels = ['human face', 'rocket', 'helmet', 'american flag']; + * const output = await detector(url, candidate_labels); + * // [ + * // { + * // score: 0.24392342567443848, + * // label: 'human face', + * // box: { xmin: 180, ymin: 67, xmax: 274, ymax: 175 } + * // }, + * // { + * // score: 0.15129457414150238, + * // label: 'american flag', + * // box: { xmin: 0, ymin: 4, xmax: 106, ymax: 513 } + * // }, + * // { + * // score: 0.13649864494800568, + * // label: 'helmet', + * // box: { xmin: 277, ymin: 337, xmax: 511, ymax: 511 } + * // }, + * // { + * // score: 0.10262022167444229, + * // label: 'rocket', + * // box: { xmin: 352, ymin: -1, xmax: 463, ymax: 287 } + * // } + * // ] + * ``` + * + * **Example:** Zero-shot object detection w/ `Xenova/owlvit-base-patch32` (returning top 4 matches and setting a threshold). + * ```javascript + * const detector = await pipeline('zero-shot-object-detection', 'Xenova/owlvit-base-patch32'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/beach.png'; + * const candidate_labels = ['hat', 'book', 'sunglasses', 'camera']; + * const output = await detector(url, candidate_labels, { topk: 4, threshold: 0.05 }); + * // [ + * // { + * // score: 0.1606510728597641, + * // label: 'sunglasses', + * // box: { xmin: 347, ymin: 229, xmax: 429, ymax: 264 } + * // }, + * // { + * // score: 0.08935828506946564, + * // label: 'hat', + * // box: { xmin: 38, ymin: 174, xmax: 258, ymax: 364 } + * // }, + * // { + * // score: 0.08530698716640472, + * // label: 'camera', + * // box: { xmin: 187, ymin: 350, xmax: 260, ymax: 411 } + * // }, + * // { + * // score: 0.08349756896495819, + * // label: 'book', + * // box: { xmin: 261, ymin: 280, xmax: 494, ymax: 425 } + * // } + * // ] + * ``` + */ +class ZeroShotObjectDetectionPipeline extends (/** @type {new (options: TextImagePipelineConstructorArgs) => ZeroShotObjectDetectionPipelineType} */ (Pipeline)) { + + /** + * Create a new ZeroShotObjectDetectionPipeline. + * @param {TextImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ZeroShotObjectDetectionPipelineCallback} */ + async _call(images, candidate_labels, { + threshold = 0.1, + topk = null, + percentage = false, + } = {}) { + + const isBatched = Array.isArray(images); + const preparedImages = await prepareImages(images); + + // Run tokenization + const text_inputs = this.tokenizer(candidate_labels, { + padding: true, + truncation: true, + }); + + // Run processor + const model_inputs = await this.processor(preparedImages); + + // Since non-maximum suppression is performed for exporting, we need to + // process each image separately. For more information, see: + // https://github.com/huggingface/optimum/blob/e3b7efb1257c011db907ef40ab340e795cc5684c/optimum/exporters/onnx/model_configs.py#L1028-L1032 + const toReturn = []; + for (let i = 0; i < preparedImages.length; ++i) { + const image = preparedImages[i]; + const imageSize = percentage ? null : [[image.height, image.width]]; + const pixel_values = model_inputs.pixel_values[i].unsqueeze_(0); + + // Run model with both text and pixel inputs + const output = await this.model({ ...text_inputs, pixel_values }); + + // @ts-ignore + const processed = this.processor.feature_extractor.post_process_object_detection(output, threshold, imageSize, true)[0]; + let result = processed.boxes.map((box, i) => ({ + score: processed.scores[i], + label: candidate_labels[processed.classes[i]], + box: get_bounding_box(box, !percentage), + })).sort((a, b) => b.score - a.score); + if (topk !== null) { + result = result.slice(0, topk); + } + toReturn.push(result) + } + + return isBatched ? toReturn : toReturn[0]; + } +} + +/** + * @typedef {Object} DocumentQuestionAnsweringSingle + * @property {string} answer The generated text. + * @typedef {DocumentQuestionAnsweringSingle[]} DocumentQuestionAnsweringOutput + * + * @callback DocumentQuestionAnsweringPipelineCallback Answer the question given as input by using the document. + * @param {ImageInput} image The image of the document to use. + * @param {string} question A question to ask of the document. + * @param {import('./utils/generation.js').GenerationConfigType} [options] Additional keyword arguments to pass along to the generate method of the model. + * @returns {Promise} An object (or array of objects) containing the answer(s). + * + * @typedef {TextImagePipelineConstructorArgs & DocumentQuestionAnsweringPipelineCallback & Disposable} DocumentQuestionAnsweringPipelineType + */ + +/** + * Document Question Answering pipeline using any `AutoModelForDocumentQuestionAnswering`. + * The inputs/outputs are similar to the (extractive) question answering pipeline; however, + * the pipeline takes an image (and optional OCR'd words/boxes) as input instead of text context. + * + * **Example:** Answer questions about a document with `Xenova/donut-base-finetuned-docvqa`. + * ```javascript + * const qa_pipeline = await pipeline('document-question-answering', 'Xenova/donut-base-finetuned-docvqa'); + * const image = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/invoice.png'; + * const question = 'What is the invoice number?'; + * const output = await qa_pipeline(image, question); + * // [{ answer: 'us-001' }] + * ``` + */ +class DocumentQuestionAnsweringPipeline extends (/** @type {new (options: TextImagePipelineConstructorArgs) => DocumentQuestionAnsweringPipelineType} */ (Pipeline)) { + + /** + * Create a new DocumentQuestionAnsweringPipeline. + * @param {TextImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {DocumentQuestionAnsweringPipelineCallback} */ + async _call(image, question, generate_kwargs = {}) { + + // NOTE: For now, we only support a batch size of 1 + + // Preprocess image + const preparedImage = (await prepareImages(image))[0]; + const { pixel_values } = await this.processor(preparedImage); + + // Run tokenization + const task_prompt = `${question}`; + const decoder_input_ids = this.tokenizer(task_prompt, { + add_special_tokens: false, + padding: true, + truncation: true, + }).input_ids; + + // Run model + const output = await this.model.generate( + pixel_values, + { + ...generate_kwargs, + decoder_input_ids, + max_length: this.model.config.decoder.max_position_embeddings, + } + ); + + // Decode output + const decoded = this.tokenizer.batch_decode(output)[0]; + + // Parse answer + const match = decoded.match(/(.*?)<\/s_answer>/); + let answer = null; + if (match && match.length >= 2) { + answer = match[1].trim(); + } + return [{ answer }]; + } +} + + +/** + * @typedef {Object} VocoderOptions + * @property {PreTrainedModel} [vocoder] The vocoder used by the pipeline (if the model uses one). If not provided, use the default HifiGan vocoder. + * @typedef {TextAudioPipelineConstructorArgs & VocoderOptions} TextToAudioPipelineConstructorArgs + */ + +/** + * @typedef {Object} TextToAudioOutput + * @property {Float32Array} audio The generated audio waveform. + * @property {number} sampling_rate The sampling rate of the generated audio waveform. + * + * @typedef {Object} TextToAudioPipelineOptions Parameters specific to text-to-audio pipelines. + * @property {Tensor|Float32Array|string|URL} [speaker_embeddings=null] The speaker embeddings (if the model requires it). + * + * @callback TextToAudioPipelineCallback Generates speech/audio from the inputs. + * @param {string|string[]} texts The text(s) to generate. + * @param {TextToAudioPipelineOptions} options Parameters passed to the model generation/forward method. + * @returns {Promise} An object containing the generated audio and sampling rate. + * + * @typedef {TextToAudioPipelineConstructorArgs & TextToAudioPipelineCallback & Disposable} TextToAudioPipelineType + */ + +/** + * Text-to-audio generation pipeline using any `AutoModelForTextToWaveform` or `AutoModelForTextToSpectrogram`. + * This pipeline generates an audio file from an input text and optional other conditional inputs. + * + * **Example:** Generate audio from text with `Xenova/speecht5_tts`. + * ```javascript + * const synthesizer = await pipeline('text-to-speech', 'Xenova/speecht5_tts', { quantized: false }); + * const speaker_embeddings = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin'; + * const out = await synthesizer('Hello, my dog is cute', { speaker_embeddings }); + * // { + * // audio: Float32Array(26112) [-0.00005657337896991521, 0.00020583874720614403, ...], + * // sampling_rate: 16000 + * // } + * ``` + * + * You can then save the audio to a .wav file with the `wavefile` package: + * ```javascript + * import wavefile from 'wavefile'; + * import fs from 'fs'; + * + * const wav = new wavefile.WaveFile(); + * wav.fromScratch(1, out.sampling_rate, '32f', out.audio); + * fs.writeFileSync('out.wav', wav.toBuffer()); + * ``` + * + * **Example:** Multilingual speech generation with `Xenova/mms-tts-fra`. See [here](https://huggingface.co/models?pipeline_tag=text-to-speech&other=vits&sort=trending) for the full list of available languages (1107). + * ```javascript + * const synthesizer = await pipeline('text-to-speech', 'Xenova/mms-tts-fra'); + * const out = await synthesizer('Bonjour'); + * // { + * // audio: Float32Array(23808) [-0.00037693005288019776, 0.0003325853613205254, ...], + * // sampling_rate: 16000 + * // } + * ``` + */ +class TextToAudioPipeline extends (/** @type {new (options: TextToAudioPipelineConstructorArgs) => TextToAudioPipelineType} */ (Pipeline)) { + DEFAULT_VOCODER_ID = "Xenova/speecht5_hifigan" + + /** + * Create a new TextToAudioPipeline. + * @param {TextToAudioPipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + + // TODO: Find a better way for `pipeline` to set the default vocoder + this.vocoder = options.vocoder ?? null; + } + + + /** @type {TextToAudioPipelineCallback} */ + async _call(text_inputs, { + speaker_embeddings = null, + } = {}) { + + // If this.processor is not set, we are using a `AutoModelForTextToWaveform` model + if (this.processor) { + return this._call_text_to_spectrogram(text_inputs, { speaker_embeddings }); + } else { + return this._call_text_to_waveform(text_inputs); + } + } + + async _call_text_to_waveform(text_inputs) { + + // Run tokenization + const inputs = this.tokenizer(text_inputs, { + padding: true, + truncation: true, + }); + + // Generate waveform + const { waveform } = await this.model(inputs); + + const sampling_rate = this.model.config.sampling_rate; + return { + audio: waveform.data, + sampling_rate, + } + } + + async _call_text_to_spectrogram(text_inputs, { speaker_embeddings }) { + + // Load vocoder, if not provided + if (!this.vocoder) { + console.log('No vocoder specified, using default HifiGan vocoder.'); + this.vocoder = await _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID, { quantized: false }); + } + + // Load speaker embeddings as Float32Array from path/URL + if (typeof speaker_embeddings === 'string' || speaker_embeddings instanceof URL) { + // Load from URL with fetch + speaker_embeddings = new Float32Array( + await (await fetch(speaker_embeddings)).arrayBuffer() + ); + } + + if (speaker_embeddings instanceof Float32Array) { + speaker_embeddings = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_6__.Tensor( + 'float32', + speaker_embeddings, + [1, speaker_embeddings.length] + ) + } else if (!(speaker_embeddings instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_6__.Tensor)) { + throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.") + } + + // Run tokenization + const { input_ids } = this.tokenizer(text_inputs, { + padding: true, + truncation: true, + }); + + // NOTE: At this point, we are guaranteed that `speaker_embeddings` is a `Tensor` + // @ts-ignore + const { waveform } = await this.model.generate_speech(input_ids, speaker_embeddings, { vocoder: this.vocoder }); + + const sampling_rate = this.processor.feature_extractor.config.sampling_rate; + return { + audio: waveform.data, + sampling_rate, + } + } +} + +/** + * @callback ImageToImagePipelineCallback Transform the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The images to transform. + * @returns {Promise} The transformed image or list of images. + * + * @typedef {ImagePipelineConstructorArgs & ImageToImagePipelineCallback & Disposable} ImageToImagePipelineType + */ + +/** + * Image to Image pipeline using any `AutoModelForImageToImage`. This pipeline generates an image based on a previous image input. + * + * **Example:** Super-resolution w/ `Xenova/swin2SR-classical-sr-x2-64` + * ```javascript + * const upscaler = await pipeline('image-to-image', 'Xenova/swin2SR-classical-sr-x2-64'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/butterfly.jpg'; + * const output = await upscaler(url); + * // RawImage { + * // data: Uint8Array(786432) [ 41, 31, 24, 43, ... ], + * // width: 512, + * // height: 512, + * // channels: 3 + * // } + * ``` + */ +class ImageToImagePipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => ImageToImagePipelineType} */ (Pipeline)) { + /** + * Create a new ImageToImagePipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {ImageToImagePipelineCallback} */ + async _call(images) { + + const preparedImages = await prepareImages(images); + const inputs = await this.processor(preparedImages); + const outputs = await this.model(inputs); + + /** @type {RawImage[]} */ + const toReturn = []; + for (const batch of outputs.reconstruction) { + const output = batch.squeeze().clamp_(0, 1).mul_(255).round_().to('uint8'); + toReturn.push(_utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage.fromTensor(output)); + } + + return toReturn.length > 1 ? toReturn : toReturn[0]; + } +} + +/** + * @typedef {Object} DepthEstimationPipelineOutput + * @property {Tensor} predicted_depth The raw depth map predicted by the model. + * @property {RawImage} depth The processed depth map as an image (with the same size as the input image). + * + * @callback DepthEstimationPipelineCallback Predicts the depth for the image(s) passed as inputs. + * @param {ImagePipelineInputs} images The images to compute depth for. + * @returns {Promise} An image or a list of images containing result(s). + * + * @typedef {ImagePipelineConstructorArgs & DepthEstimationPipelineCallback & Disposable} DepthEstimationPipelineType + */ + +/** + * Depth estimation pipeline using any `AutoModelForDepthEstimation`. This pipeline predicts the depth of an image. + * + * **Example:** Depth estimation w/ `Xenova/dpt-hybrid-midas` + * ```javascript + * const depth_estimator = await pipeline('depth-estimation', 'Xenova/dpt-hybrid-midas'); + * const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg'; + * const out = await depth_estimator(url); + * // { + * // predicted_depth: Tensor { + * // dims: [ 384, 384 ], + * // type: 'float32', + * // data: Float32Array(147456) [ 542.859130859375, 545.2833862304688, 546.1649169921875, ... ], + * // size: 147456 + * // }, + * // depth: RawImage { + * // data: Uint8Array(307200) [ 86, 86, 86, ... ], + * // width: 640, + * // height: 480, + * // channels: 1 + * // } + * // } + * ``` + */ +class DepthEstimationPipeline extends (/** @type {new (options: ImagePipelineConstructorArgs) => DepthEstimationPipelineType} */ (Pipeline)) { + /** + * Create a new DepthEstimationPipeline. + * @param {ImagePipelineConstructorArgs} options An object used to instantiate the pipeline. + */ + constructor(options) { + super(options); + } + + /** @type {DepthEstimationPipelineCallback} */ + async _call(images) { + + const preparedImages = await prepareImages(images); + + const inputs = await this.processor(preparedImages); + const { predicted_depth } = await this.model(inputs); + + const toReturn = []; + for (let i = 0; i < preparedImages.length; ++i) { + const prediction = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_6__.interpolate)(predicted_depth[i], preparedImages[i].size.reverse(), 'bilinear', false); + const formatted = prediction.mul_(255 / (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_4__.max)(prediction.data)[0]).to('uint8'); + toReturn.push({ + predicted_depth: predicted_depth[i], + depth: _utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage.fromTensor(formatted), + }); + } + + return toReturn.length > 1 ? toReturn : toReturn[0]; + } +} + +const SUPPORTED_TASKS = Object.freeze({ + "text-classification": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": TextClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSequenceClassification, + "default": { + // TODO: replace with original + // "model": "distilbert-base-uncased-finetuned-sst-2-english", + "model": "Xenova/distilbert-base-uncased-finetuned-sst-2-english", + }, + "type": "text", + }, + "token-classification": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": TokenClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForTokenClassification, + "default": { + // TODO: replace with original + // "model": "Davlan/bert-base-multilingual-cased-ner-hrl", + "model": "Xenova/bert-base-multilingual-cased-ner-hrl", + }, + "type": "text", + }, + "question-answering": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": QuestionAnsweringPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForQuestionAnswering, + "default": { + // TODO: replace with original + // "model": "distilbert-base-cased-distilled-squad", + "model": "Xenova/distilbert-base-cased-distilled-squad", + }, + "type": "text", + }, + + "fill-mask": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": FillMaskPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForMaskedLM, + "default": { + // TODO: replace with original + // "model": "bert-base-uncased", + "model": "Xenova/bert-base-uncased", + }, + "type": "text", + }, + "summarization": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": SummarizationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSeq2SeqLM, + "default": { + // TODO: replace with original + // "model": "sshleifer/distilbart-cnn-6-6", + "model": "Xenova/distilbart-cnn-6-6", + }, + "type": "text", + }, + "translation": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": TranslationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSeq2SeqLM, + "default": { + // TODO: replace with original + // "model": "t5-small", + "model": "Xenova/t5-small", + }, + "type": "text", + }, + "text2text-generation": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": Text2TextGenerationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSeq2SeqLM, + "default": { + // TODO: replace with original + // "model": "google/flan-t5-small", + "model": "Xenova/flan-t5-small", + }, + "type": "text", + }, + "text-generation": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": TextGenerationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForCausalLM, + "default": { + // TODO: replace with original + // "model": "gpt2", + "model": "Xenova/gpt2", + }, + "type": "text", + }, + "zero-shot-classification": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": ZeroShotClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSequenceClassification, + "default": { + // TODO: replace with original + // "model": "typeform/distilbert-base-uncased-mnli", + "model": "Xenova/distilbert-base-uncased-mnli", + }, + "type": "text", + }, + "audio-classification": { + "pipeline": AudioClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForAudioClassification, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "superb/wav2vec2-base-superb-ks", + "model": "Xenova/wav2vec2-base-superb-ks", + }, + "type": "audio", + }, + "zero-shot-audio-classification": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": ZeroShotAudioClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModel, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "laion/clap-htsat-fused", + "model": "Xenova/clap-htsat-unfused", + }, + "type": "multimodal", + }, + "automatic-speech-recognition": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": AutomaticSpeechRecognitionPipeline, + "model": [_models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSpeechSeq2Seq, _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForCTC], + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "openai/whisper-tiny.en", + "model": "Xenova/whisper-tiny.en", + }, + "type": "multimodal", + }, + "text-to-audio": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": TextToAudioPipeline, + "model": [_models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForTextToWaveform, _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForTextToSpectrogram], + "processor": [_processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, /* Some don't use a processor */ null], + "default": { + // TODO: replace with original + // "model": "microsoft/speecht5_tts", + "model": "Xenova/speecht5_tts", + }, + "type": "text", + }, + "image-to-text": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": ImageToTextPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForVision2Seq, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "nlpconnect/vit-gpt2-image-captioning", + "model": "Xenova/vit-gpt2-image-captioning", + }, + "type": "multimodal", + }, + + "image-classification": { + // no tokenizer + "pipeline": ImageClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForImageClassification, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "google/vit-base-patch16-224", + "model": "Xenova/vit-base-patch16-224", + }, + "type": "multimodal", + }, + + "image-segmentation": { + // no tokenizer + "pipeline": ImageSegmentationPipeline, + "model": [_models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForImageSegmentation, _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForSemanticSegmentation], + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "facebook/detr-resnet-50-panoptic", + "model": "Xenova/detr-resnet-50-panoptic", + }, + "type": "multimodal", + }, + + "zero-shot-image-classification": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": ZeroShotImageClassificationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModel, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "openai/clip-vit-base-patch32", + "model": "Xenova/clip-vit-base-patch32", + }, + "type": "multimodal", + }, + + "object-detection": { + // no tokenizer + "pipeline": ObjectDetectionPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForObjectDetection, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "facebook/detr-resnet-50", + "model": "Xenova/detr-resnet-50", + }, + "type": "multimodal", + }, + "zero-shot-object-detection": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": ZeroShotObjectDetectionPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForZeroShotObjectDetection, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "google/owlvit-base-patch32", + "model": "Xenova/owlvit-base-patch32", + }, + "type": "multimodal", + }, + "document-question-answering": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": DocumentQuestionAnsweringPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForDocumentQuestionAnswering, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "naver-clova-ix/donut-base-finetuned-docvqa", + "model": "Xenova/donut-base-finetuned-docvqa", + }, + "type": "multimodal", + }, + "image-to-image": { + // no tokenizer + "pipeline": ImageToImagePipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForImageToImage, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "caidas/swin2SR-classical-sr-x2-64", + "model": "Xenova/swin2SR-classical-sr-x2-64", + }, + "type": "image", + }, + "depth-estimation": { + // no tokenizer + "pipeline": DepthEstimationPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForDepthEstimation, + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "default": { + // TODO: replace with original + // "model": "Intel/dpt-large", + "model": "Xenova/dpt-large", + }, + "type": "image", + }, + + // This task serves as a useful interface for dealing with sentence-transformers (https://huggingface.co/sentence-transformers). + "feature-extraction": { + "tokenizer": _tokenizers_js__WEBPACK_IMPORTED_MODULE_0__.AutoTokenizer, + "pipeline": FeatureExtractionPipeline, + "model": _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModel, + "default": { + // TODO: replace with original + // "model": "sentence-transformers/all-MiniLM-L6-v2", + "model": "Xenova/all-MiniLM-L6-v2", + }, + "type": "text", + }, + "image-feature-extraction": { + "processor": _processors_js__WEBPACK_IMPORTED_MODULE_2__.AutoProcessor, + "pipeline": ImageFeatureExtractionPipeline, + "model": [_models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModelForImageFeatureExtraction, _models_js__WEBPACK_IMPORTED_MODULE_1__.AutoModel], + "default": { + // TODO: replace with original + // "model": "google/vit-base-patch16-224", + "model": "Xenova/vit-base-patch16-224-in21k", + }, + "type": "image", + }, +}) + + +// TODO: Add types for TASK_ALIASES +const TASK_ALIASES = Object.freeze({ + "sentiment-analysis": "text-classification", + "ner": "token-classification", + // "vqa": "visual-question-answering", // TODO: Add + "asr": "automatic-speech-recognition", + "text-to-speech": "text-to-audio", + + // Add for backwards compatibility + "embeddings": "feature-extraction", +}); + +/** + * @typedef {keyof typeof SUPPORTED_TASKS} TaskType + * @typedef {keyof typeof TASK_ALIASES} AliasType + * @typedef {TaskType | AliasType} PipelineType All possible pipeline types. + * @typedef {{[K in TaskType]: InstanceType}} SupportedTasks A mapping of pipeline names to their corresponding pipeline classes. + * @typedef {{[K in AliasType]: InstanceType}} AliasTasks A mapping from pipeline aliases to their corresponding pipeline classes. + * @typedef {SupportedTasks & AliasTasks} AllTasks A mapping from all pipeline names and aliases to their corresponding pipeline classes. + */ + +/** + * Utility factory method to build a `Pipeline` object. + * + * @template {PipelineType} T The type of pipeline to return. + * @param {T} task The task defining which pipeline will be returned. Currently accepted tasks are: + * - `"audio-classification"`: will return a `AudioClassificationPipeline`. + * - `"automatic-speech-recognition"`: will return a `AutomaticSpeechRecognitionPipeline`. + * - `"depth-estimation"`: will return a `DepthEstimationPipeline`. + * - `"document-question-answering"`: will return a `DocumentQuestionAnsweringPipeline`. + * - `"feature-extraction"`: will return a `FeatureExtractionPipeline`. + * - `"fill-mask"`: will return a `FillMaskPipeline`. + * - `"image-classification"`: will return a `ImageClassificationPipeline`. + * - `"image-segmentation"`: will return a `ImageSegmentationPipeline`. + * - `"image-to-text"`: will return a `ImageToTextPipeline`. + * - `"object-detection"`: will return a `ObjectDetectionPipeline`. + * - `"question-answering"`: will return a `QuestionAnsweringPipeline`. + * - `"summarization"`: will return a `SummarizationPipeline`. + * - `"text2text-generation"`: will return a `Text2TextGenerationPipeline`. + * - `"text-classification"` (alias "sentiment-analysis" available): will return a `TextClassificationPipeline`. + * - `"text-generation"`: will return a `TextGenerationPipeline`. + * - `"token-classification"` (alias "ner" available): will return a `TokenClassificationPipeline`. + * - `"translation"`: will return a `TranslationPipeline`. + * - `"translation_xx_to_yy"`: will return a `TranslationPipeline`. + * - `"zero-shot-classification"`: will return a `ZeroShotClassificationPipeline`. + * - `"zero-shot-audio-classification"`: will return a `ZeroShotAudioClassificationPipeline`. + * - `"zero-shot-image-classification"`: will return a `ZeroShotImageClassificationPipeline`. + * - `"zero-shot-object-detection"`: will return a `ZeroShotObjectDetectionPipeline`. + * @param {string} [model=null] The name of the pre-trained model to use. If not specified, the default model for the task will be used. + * @param {import('./utils/hub.js').PretrainedOptions} [options] Optional parameters for the pipeline. + * @returns {Promise} A Pipeline object for the specified task. + * @throws {Error} If an unsupported pipeline is requested. + */ +async function pipeline( + task, + model = null, + { + quantized = true, + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + } = {} +) { + // Helper method to construct pipeline + + // Apply aliases + // @ts-ignore + task = TASK_ALIASES[task] ?? task; + + // Get pipeline info + const pipelineInfo = SUPPORTED_TASKS[task.split('_', 1)[0]]; + if (!pipelineInfo) { + throw Error(`Unsupported pipeline: ${task}. Must be one of [${Object.keys(SUPPORTED_TASKS)}]`) + } + + // Use model if specified, otherwise, use default + if (!model) { + model = pipelineInfo.default.model + console.log(`No model specified. Using default model: "${model}".`); + } + + const pretrainedOptions = { + quantized, + progress_callback, + config, + cache_dir, + local_files_only, + revision, + } + + const classes = new Map([ + ['tokenizer', pipelineInfo.tokenizer], + ['model', pipelineInfo.model], + ['processor', pipelineInfo.processor], + ]); + + // Load model, tokenizer, and processor (if they exist) + const results = await loadItems(classes, model, pretrainedOptions); + results.task = task; + + (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_3__.dispatchCallback)(progress_callback, { + 'status': 'ready', + 'task': task, + 'model': model, + }); + + const pipelineClass = pipelineInfo.pipeline; + return new pipelineClass(results); +} + + +/** + * Helper function to get applicable model, tokenizer, or processor classes for a given model. + * @param {Map} mapping The mapping of names to classes, arrays of classes, or null. + * @param {string} model The name of the model to load. + * @param {import('./utils/hub.js').PretrainedOptions} pretrainedOptions The options to pass to the `from_pretrained` method. + * @private + */ +async function loadItems(mapping, model, pretrainedOptions) { + + const result = Object.create(null); + + /**@type {Promise[]} */ + const promises = []; + for (let [name, cls] of mapping.entries()) { + if (!cls) continue; + + /**@type {Promise} */ + let promise; + if (Array.isArray(cls)) { + promise = new Promise(async (resolve, reject) => { + let e; + for (let c of cls) { + if (c === null) { + // If null, we resolve it immediately, meaning the relevant + // class was not found, but it is optional. + resolve(null); + return; + } + try { + resolve(await c.from_pretrained(model, pretrainedOptions)); + return; + } catch (err) { + e = err; + } + } + reject(e); + }) + } else { + promise = cls.from_pretrained(model, pretrainedOptions); + } + + result[name] = promise; + promises.push(promise); + } + + // Wait for all promises to resolve (in parallel) + await Promise.all(promises); + + // Then assign to result + for (let [name, promise] of Object.entries(result)) { + result[name] = await promise; + } + + return result; +} + +/***/ }), + +/***/ "./src/processors.js": +/*!***************************!*\ + !*** ./src/processors.js ***! + \***************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "ASTFeatureExtractor": () => (/* binding */ ASTFeatureExtractor), +/* harmony export */ "AutoProcessor": () => (/* binding */ AutoProcessor), +/* harmony export */ "BeitFeatureExtractor": () => (/* binding */ BeitFeatureExtractor), +/* harmony export */ "BitImageProcessor": () => (/* binding */ BitImageProcessor), +/* harmony export */ "CLIPFeatureExtractor": () => (/* binding */ CLIPFeatureExtractor), +/* harmony export */ "ChineseCLIPFeatureExtractor": () => (/* binding */ ChineseCLIPFeatureExtractor), +/* harmony export */ "ClapFeatureExtractor": () => (/* binding */ ClapFeatureExtractor), +/* harmony export */ "ConvNextFeatureExtractor": () => (/* binding */ ConvNextFeatureExtractor), +/* harmony export */ "ConvNextImageProcessor": () => (/* binding */ ConvNextImageProcessor), +/* harmony export */ "DPTFeatureExtractor": () => (/* binding */ DPTFeatureExtractor), +/* harmony export */ "DPTImageProcessor": () => (/* binding */ DPTImageProcessor), +/* harmony export */ "DeiTFeatureExtractor": () => (/* binding */ DeiTFeatureExtractor), +/* harmony export */ "DetrFeatureExtractor": () => (/* binding */ DetrFeatureExtractor), +/* harmony export */ "DonutFeatureExtractor": () => (/* binding */ DonutFeatureExtractor), +/* harmony export */ "EfficientNetImageProcessor": () => (/* binding */ EfficientNetImageProcessor), +/* harmony export */ "FeatureExtractor": () => (/* binding */ FeatureExtractor), +/* harmony export */ "GLPNFeatureExtractor": () => (/* binding */ GLPNFeatureExtractor), +/* harmony export */ "ImageFeatureExtractor": () => (/* binding */ ImageFeatureExtractor), +/* harmony export */ "MobileViTFeatureExtractor": () => (/* binding */ MobileViTFeatureExtractor), +/* harmony export */ "NougatImageProcessor": () => (/* binding */ NougatImageProcessor), +/* harmony export */ "OwlViTFeatureExtractor": () => (/* binding */ OwlViTFeatureExtractor), +/* harmony export */ "OwlViTProcessor": () => (/* binding */ OwlViTProcessor), +/* harmony export */ "Owlv2ImageProcessor": () => (/* binding */ Owlv2ImageProcessor), +/* harmony export */ "Processor": () => (/* binding */ Processor), +/* harmony export */ "SamImageProcessor": () => (/* binding */ SamImageProcessor), +/* harmony export */ "SamProcessor": () => (/* binding */ SamProcessor), +/* harmony export */ "SeamlessM4TFeatureExtractor": () => (/* binding */ SeamlessM4TFeatureExtractor), +/* harmony export */ "SegformerFeatureExtractor": () => (/* binding */ SegformerFeatureExtractor), +/* harmony export */ "SiglipImageProcessor": () => (/* binding */ SiglipImageProcessor), +/* harmony export */ "SpeechT5FeatureExtractor": () => (/* binding */ SpeechT5FeatureExtractor), +/* harmony export */ "SpeechT5Processor": () => (/* binding */ SpeechT5Processor), +/* harmony export */ "Swin2SRImageProcessor": () => (/* binding */ Swin2SRImageProcessor), +/* harmony export */ "ViTFeatureExtractor": () => (/* binding */ ViTFeatureExtractor), +/* harmony export */ "ViTImageProcessor": () => (/* binding */ ViTImageProcessor), +/* harmony export */ "VitMatteImageProcessor": () => (/* binding */ VitMatteImageProcessor), +/* harmony export */ "Wav2Vec2FeatureExtractor": () => (/* binding */ Wav2Vec2FeatureExtractor), +/* harmony export */ "Wav2Vec2ProcessorWithLM": () => (/* binding */ Wav2Vec2ProcessorWithLM), +/* harmony export */ "WhisperFeatureExtractor": () => (/* binding */ WhisperFeatureExtractor), +/* harmony export */ "WhisperProcessor": () => (/* binding */ WhisperProcessor), +/* harmony export */ "YolosFeatureExtractor": () => (/* binding */ YolosFeatureExtractor) +/* harmony export */ }); +/* harmony import */ var _utils_core_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/core.js */ "./src/utils/core.js"); +/* harmony import */ var _utils_hub_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/hub.js */ "./src/utils/hub.js"); +/* harmony import */ var _utils_maths_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/maths.js */ "./src/utils/maths.js"); +/* harmony import */ var _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils/tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _utils_image_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/image.js */ "./src/utils/image.js"); +/* harmony import */ var _utils_audio_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./utils/audio.js */ "./src/utils/audio.js"); + +/** + * @file Processors are used to prepare non-textual inputs (e.g., image or audio) for a model. + * + * **Example:** Using a `WhisperProcessor` to prepare an audio input for a model. + * ```javascript + * import { AutoProcessor, read_audio } from '@xenova/transformers'; + * + * let processor = await AutoProcessor.from_pretrained('openai/whisper-tiny.en'); + * let audio = await read_audio('https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac', 16000); + * let { input_features } = await processor(audio); + * // Tensor { + * // data: Float32Array(240000) [0.4752984642982483, 0.5597258806228638, 0.56434166431427, ...], + * // dims: [1, 80, 3000], + * // type: 'float32', + * // size: 240000, + * // } + * ``` + * + * @module processors + */ + + + + + + + + + + + + + +// Helper functions + +/** + * Converts bounding boxes from center format to corners format. + * + * @param {number[]} arr The coordinate for the center of the box and its width, height dimensions (center_x, center_y, width, height) + * @returns {number[]} The coodinates for the top-left and bottom-right corners of the box (top_left_x, top_left_y, bottom_right_x, bottom_right_y) + */ +function center_to_corners_format([centerX, centerY, width, height]) { + return [ + centerX - width / 2, + centerY - height / 2, + centerX + width / 2, + centerY + height / 2 + ]; +} + +/** + * Post-processes the outputs of the model (for object detection). + * @param {Object} outputs The outputs of the model that must be post-processed + * @param {Tensor} outputs.logits The logits + * @param {Tensor} outputs.pred_boxes The predicted boxes. + * @param {number} [threshold=0.5] The threshold to use for the scores. + * @param {number[][]} [target_sizes=null] The sizes of the original images. + * @param {boolean} [is_zero_shot=false] Whether zero-shot object detection was performed. + * @return {Object[]} An array of objects containing the post-processed outputs. + * @private + */ +function post_process_object_detection(outputs, threshold = 0.5, target_sizes = null, is_zero_shot = false) { + const out_logits = outputs.logits; + const out_bbox = outputs.pred_boxes; + const [batch_size, num_boxes, num_classes] = out_logits.dims; + + if (target_sizes !== null && target_sizes.length !== batch_size) { + throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits") + } + let toReturn = []; + for (let i = 0; i < batch_size; ++i) { + let target_size = target_sizes !== null ? target_sizes[i] : null; + let info = { + boxes: [], + classes: [], + scores: [] + } + let logits = out_logits[i]; + let bbox = out_bbox[i]; + + for (let j = 0; j < num_boxes; ++j) { + let logit = logits[j]; + + let indices = []; + let probs; + if (is_zero_shot) { + // Get indices of classes with high enough probability + probs = logit.sigmoid().data; + for (let k = 0; k < probs.length; ++k) { + if (probs[k] > threshold) { + indices.push(k); + } + } + + } else { + // Get most probable class + let maxIndex = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(logit.data)[1]; + + if (maxIndex === num_classes - 1) { + // This is the background class, skip it + continue; + } + indices.push(maxIndex); + + // Compute softmax over classes + probs = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.softmax)(logit.data); + } + + for (const index of indices) { + + // Some class has a high enough probability + /** @type {number[]} */ + let box = bbox[j].data; + + // convert to [x0, y0, x1, y1] format + box = center_to_corners_format(box) + if (target_size !== null) { + box = box.map((x, i) => x * target_size[(i + 1) % 2]) + } + + info.boxes.push(box); + info.classes.push(index); + info.scores.push(probs[index]); + } + } + toReturn.push(info); + } + return toReturn; +} + +/** + * Named tuple to indicate the order we are using is (height x width), even though + * the Graphics’ industry standard is (width x height). + * @typedef {[height: number, width: number]} HeightWidth + */ + +/** + * Helper function to validate audio inputs. + * @param {any} audio The audio data. + * @param {string} feature_extractor The name of the feature extractor. + * @private + */ +function validate_audio_inputs(audio, feature_extractor) { + if (!(audio instanceof Float32Array || audio instanceof Float64Array)) { + throw new Error( + `${feature_extractor} expects input to be a Float32Array or a Float64Array, but got ${audio?.constructor?.name ?? typeof audio} instead. ` + + `If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.` + ) + } +} + +/** + * Helper function to constrain a value to be a multiple of a number. + * @param {number} val The value to constrain. + * @param {number} multiple The number to constrain to. + * @param {number} [minVal=0] The minimum value to constrain to. + * @param {number} [maxVal=null] The maximum value to constrain to. + * @returns {number} The constrained value. + * @private + */ +function constraint_to_multiple_of(val, multiple, minVal = 0, maxVal = null) { + const a = val / multiple; + let x = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.bankers_round)(a) * multiple; + + if (maxVal !== null && x > maxVal) { + x = Math.floor(a) * multiple; + } + + if (x < minVal) { + x = Math.ceil(a) * multiple; + } + + return x; +} + +/** + * Rounds the height and width down to the closest multiple of size_divisibility + * @param {[number, number]} size The size of the image + * @param {number} divisor The divisor to use. + * @returns {[number, number]} The rounded size. + */ +function enforce_size_divisibility([width, height], divisor) { + return [ + Math.max(Math.floor(width / divisor), 1) * divisor, + Math.max(Math.floor(height / divisor), 1) * divisor + ]; +} + + +/** + * Base class for feature extractors. + * + * @extends Callable + */ +class FeatureExtractor extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + /** + * Constructs a new FeatureExtractor instance. + * + * @param {Object} config The configuration for the feature extractor. + */ + constructor(config) { + super(); + this.config = config + } +} + +/** + * @typedef {object} ImageFeatureExtractorResult + * @property {Tensor} pixel_values The pixel values of the batched preprocessed images. + * @property {HeightWidth[]} original_sizes Array of two-dimensional tuples like [[480, 640]]. + * @property {HeightWidth[]} reshaped_input_sizes Array of two-dimensional tuples like [[1000, 1330]]. + */ + +/** + * Feature extractor for image models. + * + * @extends FeatureExtractor + */ +class ImageFeatureExtractor extends FeatureExtractor { + + /** + * Constructs a new ImageFeatureExtractor instance. + * + * @param {Object} config The configuration for the feature extractor. + * @param {number[]} config.image_mean The mean values for image normalization. + * @param {number[]} config.image_std The standard deviation values for image normalization. + * @param {boolean} config.do_rescale Whether to rescale the image pixel values to the [0,1] range. + * @param {number} config.rescale_factor The factor to use for rescaling the image pixel values. + * @param {boolean} config.do_normalize Whether to normalize the image pixel values. + * @param {boolean} config.do_resize Whether to resize the image. + * @param {number} config.resample What method to use for resampling. + * @param {number|Object} config.size The size to resize the image to. + */ + constructor(config) { + super(config); + + this.image_mean = this.config.image_mean ?? this.config.mean; + this.image_std = this.config.image_std ?? this.config.std; + + this.resample = this.config.resample ?? 2; // 2 => bilinear + this.do_rescale = this.config.do_rescale ?? true; + this.rescale_factor = this.config.rescale_factor ?? (1 / 255); + this.do_normalize = this.config.do_normalize; + + this.do_resize = this.config.do_resize; + this.do_thumbnail = this.config.do_thumbnail; + this.size = this.config.size; + this.size_divisibility = this.config.size_divisibility ?? this.config.size_divisor; + + this.do_center_crop = this.config.do_center_crop; + this.crop_size = this.config.crop_size; + this.do_convert_rgb = this.config.do_convert_rgb ?? true; + this.do_crop_margin = this.config.do_crop_margin; + + this.pad_size = this.config.pad_size; + this.do_pad = this.config.do_pad; + + if (this.do_pad && !this.pad_size && this.size && this.size.width !== undefined && this.size.height !== undefined) { + // Should pad, but no pad size specified + // We infer the pad size from the resize size + this.pad_size = this.size + } + } + + /** + * Resize the image to make a thumbnail. The image is resized so that no dimension is larger than any + * corresponding dimension of the specified size. + * @param {RawImage} image The image to be resized. + * @param {{height:number, width:number}} size The size `{"height": h, "width": w}` to resize the image to. + * @param {string | 0 | 1 | 2 | 3 | 4 | 5} [resample=2] The resampling filter to use. + * @returns {Promise} The resized image. + */ + async thumbnail(image, size, resample = 2) { + const input_height = image.height; + const input_width = image.width; + + const output_height = size.height; + const output_width = size.width; + + // We always resize to the smallest of either the input or output size. + let height = Math.min(input_height, output_height) + let width = Math.min(input_width, output_width) + + if (height === input_height && width === input_width) { + return image; + } + if (input_height > input_width) { + width = Math.floor(input_width * height / input_height); + } else if (input_width > input_height) { + height = Math.floor(input_height * width / input_width); + } + return await image.resize(width, height, { resample }); + } + + + /** + * Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the threshold). + * @param {RawImage} image The image to be cropped. + * @param {number} gray_threshold Value below which pixels are considered to be gray. + * @returns {Promise} The cropped image. + */ + async crop_margin(image, gray_threshold = 200) { + + const gray_image = image.clone().grayscale(); + + const minValue = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.min)(gray_image.data)[0]; + const maxValue = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(gray_image.data)[0]; + const diff = maxValue - minValue; + + if (diff === 0) { + return image; + } + + const threshold = gray_threshold / 255; + + let x_min = gray_image.width, y_min = gray_image.height, x_max = 0, y_max = 0; + for (let j = 0; j < gray_image.height; ++j) { + const row = j * gray_image.width; + for (let i = 0; i < gray_image.width; ++i) { + if ((gray_image.data[row + i] - minValue) / diff < threshold) { + // We have a non-zero pixel, so we update the min/max values accordingly + x_min = Math.min(x_min, i); + y_min = Math.min(y_min, j); + x_max = Math.max(x_max, i); + y_max = Math.max(y_max, j); + } + } + } + + image = await image.crop([x_min, y_min, x_max, y_max]); + return image; + } + + /** + * Pad the image by a certain amount. + * @param {Float32Array} pixelData The pixel data to pad. + * @param {number[]} imgDims The dimensions of the image (height, width, channels). + * @param {{width:number; height:number}|number} padSize The dimensions of the padded image. + * @param {Object} options The options for padding. + * @param {'constant'|'symmetric'} [options.mode='constant'] The type of padding to add. + * @param {boolean} [options.center=false] Whether to center the image. + * @param {number} [options.constant_values=0] The constant value to use for padding. + * @returns {[Float32Array, number[]]} The padded pixel data and image dimensions. + */ + pad_image(pixelData, imgDims, padSize, { + mode = 'constant', + center = false, + constant_values = 0, + } = {}) { + const [imageHeight, imageWidth, imageChannels] = imgDims; + + let paddedImageWidth, paddedImageHeight; + if (typeof padSize === 'number') { + paddedImageWidth = padSize; + paddedImageHeight = padSize; + } else { + paddedImageWidth = padSize.width; + paddedImageHeight = padSize.height; + } + + // Only add padding if there is a difference in size + if (paddedImageWidth !== imageWidth || paddedImageHeight !== imageHeight) { + const paddedPixelData = new Float32Array(paddedImageWidth * paddedImageHeight * imageChannels); + if (Array.isArray(constant_values)) { + // Fill with constant values, cycling through the array + for (let i = 0; i < paddedPixelData.length; ++i) { + paddedPixelData[i] = constant_values[i % imageChannels]; + } + } else if (constant_values !== 0) { + paddedPixelData.fill(constant_values); + } + + const [left, top] = center + ? [Math.floor((paddedImageWidth - imageWidth) / 2), Math.floor((paddedImageHeight - imageHeight) / 2)] + : [0, 0]; + + // Copy the original image into the padded image + for (let i = 0; i < imageHeight; ++i) { + const a = (i + top) * paddedImageWidth; + const b = i * imageWidth; + for (let j = 0; j < imageWidth; ++j) { + const c = (a + j + left) * imageChannels; + const d = (b + j) * imageChannels; + for (let k = 0; k < imageChannels; ++k) { + paddedPixelData[c + k] = pixelData[d + k]; + } + } + } + + if (mode === 'symmetric') { + if (center) { + throw new Error('`center` padding is not supported when `mode` is set to `symmetric`.'); + // TODO: Implement this + } + const h1 = imageHeight - 1; + const w1 = imageWidth - 1; + for (let i = 0; i < paddedImageHeight; ++i) { + const a = i * paddedImageWidth; + const b = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.calculateReflectOffset)(i, h1) * imageWidth; + + for (let j = 0; j < paddedImageWidth; ++j) { + if (i < imageHeight && j < imageWidth) continue; // Do not overwrite original image + const c = (a + j) * imageChannels; + const d = (b + (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.calculateReflectOffset)(j, w1)) * imageChannels; + + // Copy channel-wise + for (let k = 0; k < imageChannels; ++k) { + paddedPixelData[c + k] = pixelData[d + k]; + } + } + } + } + + + // Update pixel data and image dimensions + pixelData = paddedPixelData; + imgDims = [paddedImageHeight, paddedImageWidth, imageChannels] + } + return [pixelData, imgDims]; + } + + /** + * Rescale the image' pixel values by `this.rescale_factor`. + * @param {Float32Array} pixelData The pixel data to rescale. + * @returns {void} + */ + rescale(pixelData) { + for (let i = 0; i < pixelData.length; ++i) { + pixelData[i] = this.rescale_factor * pixelData[i]; + } + } + + /** + * Find the target (width, height) dimension of the output image after + * resizing given the input image and the desired size. + * @param {RawImage} image The image to resize. + * @param {any} size The size to use for resizing the image. + * @returns {[number, number]} The target (width, height) dimension of the output image after resizing. + */ + get_resize_output_image_size(image, size) { + // `size` comes in many forms, so we need to handle them all here: + // 1. `size` is an integer, in which case we resize the image to be a square + + const [srcWidth, srcHeight] = image.size; + + let shortest_edge; + let longest_edge; + + if (this.do_thumbnail) { + // NOTE: custom logic for `Donut` models + const { height, width } = size; + shortest_edge = Math.min(height, width) + } + // Support both formats for backwards compatibility + else if (Number.isInteger(size)) { + shortest_edge = size; + longest_edge = this.config.max_size ?? shortest_edge; + + } else if (size !== undefined) { + // Extract known properties from `size` + shortest_edge = size.shortest_edge; + longest_edge = size.longest_edge; + } + + // If `longest_edge` and `shortest_edge` are set, maintain aspect ratio and resize to `shortest_edge` + // while keeping the largest dimension <= `longest_edge` + if (shortest_edge !== undefined || longest_edge !== undefined) { + // http://opensourcehacker.com/2011/12/01/calculate-aspect-ratio-conserving-resize-for-images-in-javascript/ + // Try resize so that shortest edge is `shortest_edge` (target) + const shortResizeFactor = shortest_edge === undefined + ? 1 // If `shortest_edge` is not set, don't upscale + : Math.max(shortest_edge / srcWidth, shortest_edge / srcHeight); + + const newWidth = srcWidth * shortResizeFactor; + const newHeight = srcHeight * shortResizeFactor; + + // The new width and height might be greater than `longest_edge`, so + // we downscale again to ensure the largest dimension is `longest_edge` + const longResizeFactor = longest_edge === undefined + ? 1 // If `longest_edge` is not set, don't downscale + : Math.min(longest_edge / newWidth, longest_edge / newHeight); + + // To avoid certain floating point precision issues, we round to 2 decimal places + let finalWidth = Math.floor(Number((newWidth * longResizeFactor).toFixed(2))); + let finalHeight = Math.floor(Number((newHeight * longResizeFactor).toFixed(2))); + + if (this.size_divisibility !== undefined) { + [finalWidth, finalHeight] = enforce_size_divisibility([finalWidth, finalHeight], this.size_divisibility) + } + return [finalWidth, finalHeight]; + + } else if (size !== undefined && size.width !== undefined && size.height !== undefined) { + // If `width` and `height` are set, resize to those dimensions + + let newWidth = size.width; + let newHeight = size.height; + + // Custom for DPT models + if (this.config.keep_aspect_ratio && this.config.ensure_multiple_of) { + + // determine new height and width + let scale_height = newHeight / srcHeight; + let scale_width = newWidth / srcWidth; + + // scale as little as possible + if (Math.abs(1 - scale_width) < Math.abs(1 - scale_height)) { + // fit width + scale_height = scale_width; + } else { + // fit height + scale_width = scale_height; + } + + newHeight = constraint_to_multiple_of(scale_height * srcHeight, this.config.ensure_multiple_of); + newWidth = constraint_to_multiple_of(scale_width * srcWidth, this.config.ensure_multiple_of); + } + + return [newWidth, newHeight]; + + } else if (this.size_divisibility !== undefined) { + return enforce_size_divisibility([srcWidth, srcHeight], this.size_divisibility); + } else { + throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(size)}`); + } + } + + /** + * Resizes the image. + * @param {RawImage} image The image to resize. + * @returns {Promise} The resized image. + */ + async resize(image) { + const [newWidth, newHeight] = this.get_resize_output_image_size(image, this.size); + return await image.resize(newWidth, newHeight, { + resample: this.resample, + }); + } + + /** + * @typedef {object} PreprocessedImage + * @property {HeightWidth} original_size The original size of the image. + * @property {HeightWidth} reshaped_input_size The reshaped input size of the image. + * @property {Tensor} pixel_values The pixel values of the preprocessed image. + */ + + /** + * Preprocesses the given image. + * + * @param {RawImage} image The image to preprocess. + * @param {Object} overrides The overrides for the preprocessing options. + * @returns {Promise} The preprocessed image. + */ + async preprocess(image, { + do_normalize = null, + do_pad = null, + do_convert_rgb = null, + do_convert_grayscale = null, + } = {}) { + if (this.do_crop_margin) { + // NOTE: Specific to nougat processors. This is done before resizing, + // and can be interpreted as a pre-preprocessing step. + image = await this.crop_margin(image); + } + + const [srcWidth, srcHeight] = image.size; // original image size + + // Convert image to RGB if specified in config. + if (do_convert_rgb ?? this.do_convert_rgb) { + image = image.rgb(); + } else if (do_convert_grayscale) { + image = image.grayscale(); + } + + // TODO: + // For efficiency reasons, it might be best to merge the resize and center crop operations into one. + + // Resize all images + if (this.do_resize) { + image = await this.resize(image); + } + + // Resize the image using thumbnail method. + if (this.do_thumbnail) { + image = await this.thumbnail(image, this.size, this.resample); + } + + if (this.do_center_crop) { + + let crop_width; + let crop_height; + if (Number.isInteger(this.crop_size)) { + crop_width = this.crop_size; + crop_height = this.crop_size; + } else { + crop_width = this.crop_size.width; + crop_height = this.crop_size.height; + } + + image = await image.center_crop(crop_width, crop_height); + } + + /** @type {HeightWidth} */ + const reshaped_input_size = [image.height, image.width]; + + // NOTE: All pixel-level manipulation (i.e., modifying `pixelData`) + // occurs with data in the hwc format (height, width, channels), + // to emulate the behavior of the original Python code (w/ numpy). + let pixelData = Float32Array.from(image.data); + let imgDims = [image.height, image.width, image.channels]; + + if (this.do_rescale) { + this.rescale(pixelData); + } + + if (do_normalize ?? this.do_normalize) { + let image_mean = this.image_mean; + if (!Array.isArray(this.image_mean)) { + image_mean = new Array(image.channels).fill(image_mean); + } + + let image_std = this.image_std; + if (!Array.isArray(this.image_std)) { + image_std = new Array(image.channels).fill(image_mean); + } + + if (image_mean.length !== image.channels || image_std.length !== image.channels) { + throw new Error(`When set to arrays, the length of \`image_mean\` (${image_mean.length}) and \`image_std\` (${image_std.length}) must match the number of channels in the image (${image.channels}).`); + } + + for (let i = 0; i < pixelData.length; i += image.channels) { + for (let j = 0; j < image.channels; ++j) { + pixelData[i + j] = (pixelData[i + j] - image_mean[j]) / image_std[j]; + } + } + } + + // do padding after rescaling/normalizing + if (do_pad ?? this.do_pad) { + if (this.pad_size) { + const padded = this.pad_image(pixelData, [image.height, image.width, image.channels], this.pad_size); + [pixelData, imgDims] = padded; // Update pixel data and image dimensions + } else if (this.size_divisibility) { + const [paddedWidth, paddedHeight] = enforce_size_divisibility([imgDims[1], imgDims[0]], this.size_divisibility); + [pixelData, imgDims] = this.pad_image(pixelData, imgDims, { width: paddedWidth, height: paddedHeight }); + } + } + + const pixel_values = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', pixelData, imgDims) + .permute(2, 0, 1); // convert to channel dimension format (hwc -> chw) + + return { + original_size: [srcHeight, srcWidth], + reshaped_input_size: reshaped_input_size, + pixel_values: pixel_values, + } + } + + /** + * Calls the feature extraction process on an array of images, + * preprocesses each image, and concatenates the resulting + * features into a single Tensor. + * @param {RawImage[]} images The image(s) to extract features from. + * @param {...any} args Additional arguments. + * @returns {Promise} An object containing the concatenated pixel values (and other metadata) of the preprocessed images. + */ + async _call(images, ...args) { + if (!Array.isArray(images)) { + images = [images]; + } + /** @type {PreprocessedImage[]} */ + const imageData = await Promise.all(images.map(x => this.preprocess(x))); + + // Stack pixel values + const pixel_values = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.stack)(imageData.map(x => x.pixel_values), 0); + + return { + pixel_values: pixel_values, + + // Original sizes of images + original_sizes: imageData.map(x => x.original_size), + + // Reshaped sizes of images, before padding or cropping + reshaped_input_sizes: imageData.map(x => x.reshaped_input_size), + } + } + +} + +class SegformerFeatureExtractor extends ImageFeatureExtractor { + + /** + * Converts the output of `SegformerForSemanticSegmentation` into semantic segmentation maps. + * @param {*} outputs Raw outputs of the model. + * @param {number[][]} [target_sizes=null] List of tuples corresponding to the requested final size + * (height, width) of each prediction. If unset, predictions will not be resized. + * @returns {{segmentation: Tensor; labels: number[]}[]} The semantic segmentation maps. + */ + post_process_semantic_segmentation(outputs, target_sizes = null) { + + const logits = outputs.logits; + const batch_size = logits.dims[0]; + + if (target_sizes !== null && target_sizes.length !== batch_size) { + throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits") + } + + const toReturn = []; + for (let i = 0; i < batch_size; ++i) { + const target_size = target_sizes !== null ? target_sizes[i] : null; + + let data = logits[i]; + + // 1. If target_size is not null, we need to resize the masks to the target size + if (target_size !== null) { + // resize the masks to the target size + data = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.interpolate)(data, target_size, 'bilinear', false); + } + const [height, width] = target_size ?? data.dims.slice(-2); + + const segmentation = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int32', + new Int32Array(height * width), + [height, width] + ); + + // Buffer to store current largest value + const buffer = data[0].data; + for (let j = 1; j < data.dims[0]; ++j) { + const row = data[j].data; + for (let k = 0; k < row.length; ++k) { + if (row[k] > buffer[k]) { + buffer[k] = row[k]; + segmentation.data[k] = j; + } + } + } + + // Store which objects have labels + // This is much more efficient that creating a set of the final values + const hasLabel = new Array(data.dims[0]); + const out = segmentation.data; + for (let j = 0; j < out.length; ++j) { + const index = out[j]; + hasLabel[index] = index; + } + /** @type {number[]} The unique list of labels that were detected */ + const labels = hasLabel.filter(x => x !== undefined); + + toReturn.push({ segmentation, labels }); + } + return toReturn; + } +} +class DPTFeatureExtractor extends ImageFeatureExtractor { } +class DPTImageProcessor extends DPTFeatureExtractor { } // NOTE: extends DPTFeatureExtractor +class BitImageProcessor extends ImageFeatureExtractor { } +class GLPNFeatureExtractor extends ImageFeatureExtractor { } +class CLIPFeatureExtractor extends ImageFeatureExtractor { } +class ChineseCLIPFeatureExtractor extends ImageFeatureExtractor { } +class SiglipImageProcessor extends ImageFeatureExtractor { } +class ConvNextFeatureExtractor extends ImageFeatureExtractor { + constructor(config) { + super(config); + + /** + * Percentage of the image to crop. Only has an effect if this.size < 384. + */ + this.crop_pct = this.config.crop_pct ?? (224 / 256); + } + + async resize(image) { + const shortest_edge = this.size?.shortest_edge; + if (shortest_edge === undefined) { + throw new Error(`Size dictionary must contain 'shortest_edge' key.`); + } + + if (shortest_edge < 384) { + // maintain same ratio, resizing shortest edge to shortest_edge/crop_pct + const resize_shortest_edge = Math.floor(shortest_edge / this.crop_pct); + + const [newWidth, newHeight] = this.get_resize_output_image_size(image, { + shortest_edge: resize_shortest_edge, + }); + + image = await image.resize(newWidth, newHeight, { + resample: this.resample, + }); + + // then crop to (shortest_edge, shortest_edge) + image = await image.center_crop(shortest_edge, shortest_edge); + } else { + // warping (no cropping) when evaluated at 384 or larger + image = await image.resize(shortest_edge, shortest_edge, { + resample: this.resample, + }); + } + + return image; + } +} +class ConvNextImageProcessor extends ConvNextFeatureExtractor { } // NOTE extends ConvNextFeatureExtractor +class ViTFeatureExtractor extends ImageFeatureExtractor { } +class ViTImageProcessor extends ImageFeatureExtractor { } + +class EfficientNetImageProcessor extends ImageFeatureExtractor { + constructor(config) { + super(config); + this.include_top = this.config.include_top ?? true; + if (this.include_top) { + this.image_std = this.image_std.map(x => x * x); + } + } +} + + +class MobileViTFeatureExtractor extends ImageFeatureExtractor { } +class OwlViTFeatureExtractor extends ImageFeatureExtractor { + /** @type {post_process_object_detection} */ + post_process_object_detection(...args) { + return post_process_object_detection(...args); + } +} +class Owlv2ImageProcessor extends OwlViTFeatureExtractor { } // NOTE extends OwlViTFeatureExtractor + +class DeiTFeatureExtractor extends ImageFeatureExtractor { } +class BeitFeatureExtractor extends ImageFeatureExtractor { } +class DonutFeatureExtractor extends ImageFeatureExtractor { + pad_image(pixelData, imgDims, padSize, options = {}) { + const [imageHeight, imageWidth, imageChannels] = imgDims; + + let image_mean = this.image_mean; + if (!Array.isArray(this.image_mean)) { + image_mean = new Array(imageChannels).fill(image_mean); + } + + let image_std = this.image_std; + if (!Array.isArray(image_std)) { + image_std = new Array(imageChannels).fill(image_mean); + } + + const constant_values = image_mean.map((x, i) => - x / image_std[i]); + + return super.pad_image(pixelData, imgDims, padSize, { + center: true, + + // Since normalization is done after padding, we need to use certain constant values to ensure the same behaviour is observed. + // For more information, see https://github.com/huggingface/transformers/blob/main/src/transformers/models/donut/image_processing_donut.py#L433-L451 + constant_values: constant_values, + ...options, + }); + } +} +class NougatImageProcessor extends DonutFeatureExtractor { } // NOTE extends DonutFeatureExtractor + +/** + * @typedef {object} DetrFeatureExtractorResultProps + * @property {Tensor} pixel_mask + * @typedef {ImageFeatureExtractorResult & DetrFeatureExtractorResultProps} DetrFeatureExtractorResult + */ + +/** + * Detr Feature Extractor. + * + * @extends ImageFeatureExtractor + */ +class DetrFeatureExtractor extends ImageFeatureExtractor { + /** + * Calls the feature extraction process on an array of images, preprocesses + * each image, and concatenates the resulting features into a single Tensor. + * @param {RawImage[]} images The image(s) to extract features from. + * @returns {Promise} An object containing the concatenated pixel values of the preprocessed images. + */ + async _call(images) { + const result = await super._call(images); + + // TODO support differently-sized images, for now assume all images are the same size. + // TODO support different mask sizes (not just 64x64) + // Currently, just fill pixel mask with 1s + const maskSize = [result.pixel_values.dims[0], 64, 64]; + const pixel_mask = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int64', + new BigInt64Array(maskSize.reduce((a, b) => a * b)).fill(1n), + maskSize + ); + + return { ...result, pixel_mask }; + } + + /** + * Post-processes the outputs of the model (for object detection). + * @param {Object} outputs The outputs of the model that must be post-processed + * @param {Tensor} outputs.logits The logits + * @param {Tensor} outputs.pred_boxes The predicted boxes. + * @return {Object[]} An array of objects containing the post-processed outputs. + */ + + /** @type {post_process_object_detection} */ + post_process_object_detection(...args) { + return post_process_object_detection(...args); + } + + /** + * Binarize the given masks using `object_mask_threshold`, it returns the associated values of `masks`, `scores` and `labels`. + * @param {Tensor} class_logits The class logits. + * @param {Tensor} mask_logits The mask logits. + * @param {number} object_mask_threshold A number between 0 and 1 used to binarize the masks. + * @param {number} num_labels The number of labels. + * @returns {[Tensor[], number[], number[]]} The binarized masks, the scores, and the labels. + */ + remove_low_and_no_objects(class_logits, mask_logits, object_mask_threshold, num_labels) { + + let mask_probs_item = []; + let pred_scores_item = []; + let pred_labels_item = []; + + for (let j = 0; j < class_logits.dims[0]; ++j) { + let cls = class_logits[j]; + let mask = mask_logits[j]; + + let pred_label = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(cls.data)[1]; + if (pred_label === num_labels) { + // Is the background, so we ignore it + continue; + } + + let scores = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.softmax)(cls.data); + let pred_score = scores[pred_label]; + if (pred_score > object_mask_threshold) { + mask_probs_item.push(mask); + pred_scores_item.push(pred_score); + pred_labels_item.push(pred_label); + } + } + + return [mask_probs_item, pred_scores_item, pred_labels_item]; + + } + + /** + * Checks whether the segment is valid or not. + * @param {Int32Array} mask_labels Labels for each pixel in the mask. + * @param {Tensor[]} mask_probs Probabilities for each pixel in the masks. + * @param {number} k The class id of the segment. + * @param {number} mask_threshold The mask threshold. + * @param {number} overlap_mask_area_threshold The overlap mask area threshold. + * @returns {[boolean, number[]]} Whether the segment is valid or not, and the indices of the valid labels. + */ + check_segment_validity( + mask_labels, + mask_probs, + k, + mask_threshold = 0.5, + overlap_mask_area_threshold = 0.8 + ) { + // mask_k is a 1D array of indices, indicating where the mask is equal to k + let mask_k = []; + let mask_k_area = 0; + let original_area = 0; + + // Compute the area of all the stuff in query k + for (let i = 0; i < mask_labels.length; ++i) { + if (mask_labels[i] === k) { + mask_k.push(i); + ++mask_k_area; + } + + if (mask_probs[k].data[i] >= mask_threshold) { + ++original_area; + } + } + let mask_exists = mask_k_area > 0 && original_area > 0; + + // Eliminate disconnected tiny segments + if (mask_exists) { + // Perform additional check + let area_ratio = mask_k_area / original_area; + mask_exists = area_ratio > overlap_mask_area_threshold; + } + + return [mask_exists, mask_k] + } + + /** + * Computes the segments. + * @param {Tensor[]} mask_probs The mask probabilities. + * @param {number[]} pred_scores The predicted scores. + * @param {number[]} pred_labels The predicted labels. + * @param {number} mask_threshold The mask threshold. + * @param {number} overlap_mask_area_threshold The overlap mask area threshold. + * @param {Set} label_ids_to_fuse The label ids to fuse. + * @param {number[]} target_size The target size of the image. + * @returns {[Tensor, Array<{id: number, label_id: number, score: number}>]} The computed segments. + */ + compute_segments( + mask_probs, + pred_scores, + pred_labels, + mask_threshold, + overlap_mask_area_threshold, + label_ids_to_fuse = null, + target_size = null, + ) { + let [height, width] = target_size ?? mask_probs[0].dims; + + let segmentation = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int32', + new Int32Array(height * width), + [height, width] + ); + let segments = []; + + // 1. If target_size is not null, we need to resize the masks to the target size + if (target_size !== null) { + // resize the masks to the target size + for (let i = 0; i < mask_probs.length; ++i) { + mask_probs[i] = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.interpolate)(mask_probs[i], target_size, 'bilinear', false); + } + } + + // 2. Weigh each mask by its prediction score + // NOTE: `mask_probs` is updated in-place + // + // Temporary storage for the best label/scores for each pixel ([height, width]): + let mask_labels = new Int32Array(mask_probs[0].data.length); + let bestScores = new Float32Array(mask_probs[0].data.length); + + for (let i = 0; i < mask_probs.length; ++i) { + let score = pred_scores[i]; + + for (let j = 0; j < mask_probs[i].data.length; ++j) { + mask_probs[i].data[j] *= score + if (mask_probs[i].data[j] > bestScores[j]) { + mask_labels[j] = i; + bestScores[j] = mask_probs[i].data[j]; + } + } + } + + let current_segment_id = 0; + + // let stuff_memory_list = {} + for (let k = 0; k < pred_labels.length; ++k) { + let pred_class = pred_labels[k]; + + // TODO add `should_fuse` + // let should_fuse = pred_class in label_ids_to_fuse + + // Check if mask exists and large enough to be a segment + let [mask_exists, mask_k] = this.check_segment_validity( + mask_labels, + mask_probs, + k, + mask_threshold, + overlap_mask_area_threshold + ) + + if (!mask_exists) { + // Nothing to see here + continue; + } + + // TODO + // if (pred_class in stuff_memory_list) { + // current_segment_id = stuff_memory_list[pred_class] + // } else { + // current_segment_id += 1; + // } + ++current_segment_id; + + + // Add current object segment to final segmentation map + for (let index of mask_k) { + segmentation.data[index] = current_segment_id; + } + + segments.push({ + id: current_segment_id, + label_id: pred_class, + // was_fused: should_fuse, TODO + score: pred_scores[k], + }) + + // TODO + // if(should_fuse){ + // stuff_memory_list[pred_class] = current_segment_id + // } + } + + return [segmentation, segments]; + } + + /** + * Post-process the model output to generate the final panoptic segmentation. + * @param {*} outputs The model output to post process + * @param {number} [threshold=0.5] The probability score threshold to keep predicted instance masks. + * @param {number} [mask_threshold=0.5] Threshold to use when turning the predicted masks into binary values. + * @param {number} [overlap_mask_area_threshold=0.8] The overlap mask area threshold to merge or discard small disconnected parts within each binary instance mask. + * @param {Set} [label_ids_to_fuse=null] The labels in this state will have all their instances be fused together. + * @param {number[][]} [target_sizes=null] The target sizes to resize the masks to. + * @returns {Array<{ segmentation: Tensor, segments_info: Array<{id: number, label_id: number, score: number}>}>} + */ + post_process_panoptic_segmentation( + outputs, + threshold = 0.5, + mask_threshold = 0.5, + overlap_mask_area_threshold = 0.8, + label_ids_to_fuse = null, + target_sizes = null, + ) { + if (label_ids_to_fuse === null) { + console.warn("`label_ids_to_fuse` unset. No instance will be fused.") + label_ids_to_fuse = new Set(); + } + + const class_queries_logits = outputs.logits; // [batch_size, num_queries, num_classes+1] + const masks_queries_logits = outputs.pred_masks; // [batch_size, num_queries, height, width] + + const mask_probs = masks_queries_logits.sigmoid() // [batch_size, num_queries, height, width] + + let [batch_size, num_queries, num_labels] = class_queries_logits.dims; + num_labels -= 1; // Remove last class (background) + + if (target_sizes !== null && target_sizes.length !== batch_size) { + throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits") + } + + let toReturn = []; + for (let i = 0; i < batch_size; ++i) { + let target_size = target_sizes !== null ? target_sizes[i] : null; + + let class_logits = class_queries_logits[i]; + let mask_logits = mask_probs[i]; + + let [mask_probs_item, pred_scores_item, pred_labels_item] = this.remove_low_and_no_objects(class_logits, mask_logits, threshold, num_labels); + + if (pred_labels_item.length === 0) { + // No mask found + let [height, width] = target_size ?? mask_logits.dims.slice(-2); + + let segmentation = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int32', + new Int32Array(height * width).fill(-1), + [height, width] + ) + toReturn.push({ + segmentation: segmentation, + segments_info: [] + }); + continue; + } + + + // Get segmentation map and segment information of batch item + let [segmentation, segments] = this.compute_segments( + mask_probs_item, + pred_scores_item, + pred_labels_item, + mask_threshold, + overlap_mask_area_threshold, + label_ids_to_fuse, + target_size, + ) + + toReturn.push({ + segmentation: segmentation, + segments_info: segments + }) + } + + return toReturn; + } + + post_process_instance_segmentation() { + // TODO + throw Error("Not implemented yet"); + } +} + +class YolosFeatureExtractor extends ImageFeatureExtractor { + /** @type {post_process_object_detection} */ + post_process_object_detection(...args) { + return post_process_object_detection(...args); + } +} + +/** + * @typedef {object} SamImageProcessorResult + * @property {Tensor} pixel_values + * @property {HeightWidth[]} original_sizes + * @property {HeightWidth[]} reshaped_input_sizes + * @property {Tensor} [input_points] + * @property {Tensor} [input_labels] + */ + +class SamImageProcessor extends ImageFeatureExtractor { + + /** + * + * @param {any} input_points + * @param {HeightWidth[]} original_sizes + * @param {HeightWidth[]} reshaped_input_sizes + * @returns {Tensor} + */ + reshape_input_points(input_points, original_sizes, reshaped_input_sizes) { + + // Make deep copy to avoid altering user's input + input_points = structuredClone(input_points); + let shape = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.calculateDimensions)(input_points); + + // TODO: add support for 2D input_points + if (shape.length === 3) { + // Correct user's input + shape = [1, ...shape]; + input_points = [input_points]; + } else if (shape.length !== 4) { + throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.") + } + + // Reshape input points + for (let i = 0; i < input_points.length; ++i) { // batch_size + let originalImageSize = original_sizes[i]; + let reshapedImageSize = reshaped_input_sizes[i]; + + let resizeFactors = [ + reshapedImageSize[0] / originalImageSize[0], + reshapedImageSize[1] / originalImageSize[1] + ] + + for (let j = 0; j < input_points[i].length; ++j) { // point_batch_size + for (let k = 0; k < input_points[i][j].length; ++k) { // nb_points_per_image + for (let w = 0; w < input_points[i][j][k].length; ++w) { // 2 + input_points[i][j][k][w] *= resizeFactors[w]; + } + } + } + } + + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'float32', + Float32Array.from(input_points.flat(Infinity)), + shape + ) + + } + + /** + * + * @param {any} input_labels + * @param {Tensor} input_points + * @returns {Tensor} + */ + add_input_labels(input_labels, input_points) { + let shape = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.calculateDimensions)(input_labels); + if (shape.length === 2) { + // Correct user's input + shape = [1, ...shape]; + input_labels = [input_labels]; + } else if (shape.length !== 3) { + throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.") + } + + if (shape.some((x, i) => x !== input_points.dims[i])) { + throw Error(`The first ${shape.length} dimensions of 'input_points' and 'input_labels' must be the same.`) + } + return new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int64', + input_labels.flat(Infinity).map(BigInt), + shape, + ) + } + /** + * @param {any[]} images The URL(s) of the image(s) to extract features from. + * @param {any} [input_points] A 3D or 4D array, representing the input points provided by the user. + * - 3D: `[point_batch_size, nb_points_per_image, 2]`. In this case, `batch_size` is assumed to be 1. + * - 4D: `[batch_size, point_batch_size, nb_points_per_image, 2]`. + * @param {any} [input_labels] A 2D or 3D array, representing the input labels for the points, used by the prompt encoder to encode the prompt. + * - 2D: `[point_batch_size, nb_points_per_image]`. In this case, `batch_size` is assumed to be 1. + * - 3D: `[batch_size, point_batch_size, nb_points_per_image]`. + * @returns {Promise} + */ + async _call(images, input_points = null, input_labels = null) { + // TODO allow user to use preprocessed images + /** @type {SamImageProcessorResult} */ + const processed = await super._call(images); + + if (input_points) { + processed.input_points = this.reshape_input_points( + input_points, processed.original_sizes, processed.reshaped_input_sizes + ); + } + + if (input_labels) { + if (!processed.input_points) { + throw Error("`input_points` must be provided if `input_labels` are provided.") + } + processed.input_labels = this.add_input_labels(input_labels, processed.input_points); + } + + return processed; + } + + /** + * Remove padding and upscale masks to the original image size. + * @param {Tensor} masks Batched masks from the mask_decoder in (batch_size, num_channels, height, width) format. + * @param {number[][]} original_sizes The original sizes of each image before it was resized to the model's expected input shape, in (height, width) format. + * @param {number[][]} reshaped_input_sizes The size of each image as it is fed to the model, in (height, width) format. Used to remove padding. + * @param {Object} options Optional parameters for post-processing. + * @param {number} [options.mask_threshold] The threshold to use for binarizing the masks. + * @param {boolean} [options.binarize] Whether to binarize the masks. + * @param {Object} [options.pad_size] The target size the images were padded to before being passed to the model. If `null`, the target size is assumed to be the processor's `pad_size`. + * @param {number} [options.pad_size.height] The height the images were padded to. + * @param {number} [options.pad_size.width] The width the images were padded to. + * @returns {Tensor[]} Batched masks in batch_size, num_channels, height, width) format, where (height, width) is given by original_size. + */ + post_process_masks(masks, original_sizes, reshaped_input_sizes, { + mask_threshold = 0.0, + binarize = true, + pad_size = null, + } = {}) { + // masks: [1, 1, 3, 256, 256] + + const output_masks = []; + + pad_size = pad_size ?? this.pad_size; + + const target_image_size = [pad_size.height, pad_size.width]; + + for (let i = 0; i < original_sizes.length; ++i) { + const original_size = original_sizes[i]; + const reshaped_input_size = reshaped_input_sizes[i]; + + const mask = masks[i]; // [b, c, h, w] + + // TODO: improve + const interpolated_masks = []; + for (let j = 0; j < mask.dims[0]; ++j) { + const m = mask[j]; // 3d tensor + + // Upscale mask to padded size + let interpolated_mask = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.interpolate)(m, target_image_size, 'bilinear', false); + + // Crop mask + interpolated_mask = interpolated_mask.slice(null, [0, reshaped_input_size[0]], [0, reshaped_input_size[1]]); + + // Downscale mask + interpolated_mask = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.interpolate)(interpolated_mask, original_size, 'bilinear', false); + + if (binarize) { + const binarizedMaskData = new Uint8Array(interpolated_mask.data.length); + for (let i = 0; i < interpolated_mask.data.length; ++i) { + if (interpolated_mask.data[i] > mask_threshold) { + binarizedMaskData[i] = 1; + } + } + interpolated_mask = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'bool', + binarizedMaskData, + interpolated_mask.dims + ) + } + + interpolated_masks.push(interpolated_mask); + } + + output_masks.push((0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.stack)(interpolated_masks)); + } + + return output_masks; + } +} + +class Swin2SRImageProcessor extends ImageFeatureExtractor { + pad_image(pixelData, imgDims, padSize, options = {}) { + // NOTE: In this case, `padSize` represents the size of the sliding window for the local attention. + // In other words, the image is padded so that its width and height are multiples of `padSize`. + const [imageHeight, imageWidth, imageChannels] = imgDims; + + return super.pad_image(pixelData, imgDims, { + // NOTE: For Swin2SR models, the original python implementation adds padding even when the image's width/height is already + // a multiple of `pad_size`. However, this is most likely a bug (PR: https://github.com/mv-lab/swin2sr/pull/19). + // For this reason, we only add padding when the image's width/height is not a multiple of `pad_size`. + width: imageWidth + (padSize - imageWidth % padSize) % padSize, + height: imageHeight + (padSize - imageHeight % padSize) % padSize, + }, { + mode: 'symmetric', + center: false, + constant_values: -1, + ...options, + }) + } +} + +class VitMatteImageProcessor extends ImageFeatureExtractor { + /** + * Calls the feature extraction process on an array of images, preprocesses + * each image, and concatenates the resulting features into a single Tensor. + * @param {RawImage[]} images The image(s) to extract features from. + * @param {RawImage[]} trimaps The trimaps(s) to extract features from. + * @returns {Promise} An object containing the concatenated pixel values of the preprocessed images. + */ + async _call(images, trimaps) { + if (!Array.isArray(images)) { + images = [images]; + } + if (!Array.isArray(trimaps)) { + trimaps = [trimaps]; + } + + const imageData = await Promise.all(images.map(x => this.preprocess(x))); + const trimapData = await Promise.all(trimaps.map(x => this.preprocess(x, { + do_normalize: false, + do_convert_rgb: false, + do_convert_grayscale: true, + }))); + + + // Stack pixel values + const pixel_values = (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.stack)(imageData.map( + // Concatenate images and trimaps + (x, i) => (0,_utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.cat)([x.pixel_values, trimapData[i].pixel_values], 0) + ), 0); + + return { + pixel_values: pixel_values, + + // Original sizes of images + original_sizes: imageData.map(x => x.original_size), + + // Reshaped sizes of images, before padding or cropping + reshaped_input_sizes: imageData.map(x => x.reshaped_input_size), + } + } +} + +class WhisperFeatureExtractor extends FeatureExtractor { + + constructor(config) { + super(config); + + // Prefer given `mel_filters` from preprocessor_config.json, or calculate them if they don't exist. + this.config.mel_filters ??= (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.mel_filter_bank)( + Math.floor(1 + this.config.n_fft / 2), // num_frequency_bins + this.config.feature_size, // num_mel_filters + 0.0, // min_frequency + 8000.0, // max_frequency + this.config.sampling_rate, // sampling_rate + "slaney", // norm + "slaney", // mel_scale + ); + + this.window = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.window_function)(this.config.n_fft, 'hann'); + } + + /** + * Computes the log-Mel spectrogram of the provided audio waveform. + * @param {Float32Array|Float64Array} waveform The audio waveform to process. + * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers. + */ + _extract_fbank_features(waveform) { + const { data, dims } = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.spectrogram)( + waveform, + this.window, // window + this.config.n_fft, // frame_length + this.config.hop_length, // hop_length + { + power: 2.0, + mel_filters: this.config.mel_filters, + log_mel: 'log10', + + // Custom + max_num_frames: this.config.nb_max_frames, // 3000 + } + ) + + const maxValue = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(data)[0]; + + for (let i = 0; i < data.length; ++i) { + data[i] = (Math.max(data[i], maxValue - 8.0) + 4.0) / 4.0; + } + + return { data, dims }; + } + + /** + * Asynchronously extracts features from a given audio using the provided configuration. + * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. + * @returns {Promise<{ input_features: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor. + */ + async _call(audio) { + validate_audio_inputs(audio, 'WhisperFeatureExtractor'); + + let waveform; + if (audio.length > this.config.n_samples) { + console.warn( + "Attempting to extract features for audio longer than 30 seconds. " + + "If using a pipeline to extract transcript from a long audio clip, " + + "remember to specify `chunk_length_s` and/or `stride_length_s`." + ); + waveform = audio.slice(0, this.config.n_samples); + } else { + // pad with zeros + waveform = new Float32Array(this.config.n_samples); + waveform.set(audio); + } + + const { data, dims } = this._extract_fbank_features(waveform); + + return { + input_features: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', + data, + [1, ...dims] + ) + }; + } +} + +class Wav2Vec2FeatureExtractor extends FeatureExtractor { + + /** + * @param {Float32Array} input_values + * @returns {Float32Array} + */ + _zero_mean_unit_var_norm(input_values) { + // TODO support batch? + const sum = input_values.reduce((a, b) => a + b, 0); + const mean = sum / input_values.length; + const variance = input_values.reduce((a, b) => a + (b - mean) ** 2, 0) / input_values.length; + return input_values.map(x => (x - mean) / Math.sqrt(variance + 1e-7)); + } + + /** + * Asynchronously extracts features from a given audio using the provided configuration. + * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. + * @returns {Promise<{ input_values: Tensor; attention_mask: Tensor }>} A Promise resolving to an object containing the extracted input features and attention mask as Tensors. + */ + async _call(audio) { + validate_audio_inputs(audio, 'Wav2Vec2FeatureExtractor'); + + if (audio instanceof Float64Array) { + audio = new Float32Array(audio); + } + + let input_values = audio; + + // zero-mean and unit-variance normalization + if (this.config.do_normalize) { + input_values = this._zero_mean_unit_var_norm(input_values); + } + + // TODO: allow user to pass in attention mask + const shape = [1, input_values.length]; + return { + input_values: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', input_values, shape), + attention_mask: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('int64', new BigInt64Array(input_values.length).fill(1n), shape) + }; + } +} + +class SeamlessM4TFeatureExtractor extends FeatureExtractor { + + constructor(config) { + super(config); + + const sampling_rate = this.config.sampling_rate; + const mel_filters = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.mel_filter_bank)( + 256, // num_frequency_bins + this.config.num_mel_bins, // num_mel_filters + 20, // min_frequency + Math.floor(sampling_rate / 2), // max_frequency + sampling_rate, // sampling_rate + null, // norm + "kaldi", // mel_scale + true, // triangularize_in_mel_space + ); + + // Do padding: + for (let i = 0; i < mel_filters.length; ++i) { + mel_filters[i].push(0); + } + this.mel_filters = mel_filters; + + this.window = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.window_function)(400, 'povey', { + periodic: false, + }) + } + + /** + * Computes the log-Mel spectrogram of the provided audio waveform. + * @param {Float32Array|Float64Array} waveform The audio waveform to process. + * @param {number} max_length The maximum number of frames to return. + * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers. + */ + _extract_fbank_features(waveform, max_length) { + // NOTE: We don't pad/truncate since that is passed in as `max_num_frames` + + // Kaldi compliance: 16-bit signed integers + // 32768 == 2 ** 15 + waveform = waveform.map((/** @type {number} */ x) => x * 32768) + + return (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.spectrogram)( + waveform, + this.window, // window + 400, // frame_length + 160, // hop_length + { + fft_length: 512, + power: 2.0, + center: false, + preemphasis: 0.97, + mel_filters: this.mel_filters, + log_mel: 'log', + mel_floor: 1.192092955078125e-07, + remove_dc_offset: true, + + // Custom + max_num_frames: max_length, + transpose: true, + } + ) + } + + /** + * Asynchronously extracts features from a given audio using the provided configuration. + * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. + * @param {Object} options Optional parameters for feature extraction. + * @param {boolean} [options.padding=true] Whether to pad the sequence to a multiple of `pad_to_multiple_of`. + * @param {number} [options.pad_to_multiple_of=2] The number to pad the sequence to a multiple of. + * @param {boolean} [options.do_normalize_per_mel_bins=true] Whether or not to zero-mean unit-variance normalize the input per mel-channel. + * @param {boolean} [options.return_attention_mask=true] Whether to return the attention mask. + * @returns {Promise<{ input_features: Tensor, attention_mask?: Tensor }>} A Promise resolving to an object containing the extracted input features and attention masks as Tensors. + */ + async _call(audio, { + padding = true, + pad_to_multiple_of = 2, + do_normalize_per_mel_bins = true, + return_attention_mask = true, + } = {}) { + validate_audio_inputs(audio, 'SeamlessM4TFeatureExtractor'); + + let features = this._extract_fbank_features(audio, this.config.max_length); + + if (do_normalize_per_mel_bins) { + const [num_features, feature_size] = features.dims; + for (let i = 0; i < feature_size; ++i) { + let sum = 0; + for (let j = 0; j < num_features; ++j) { + sum += features.data[j * feature_size + i]; + } + + const mean = sum / num_features; + + let variance = 0; + for (let j = 0; j < num_features; ++j) { + variance += (features.data[j * feature_size + i] - mean) ** 2; + } + variance /= num_features - 1; // NOTE: We use ddof=1 + + const std = Math.sqrt(variance + 1e-7); + for (let j = 0; j < num_features; ++j) { + const index = j * feature_size + i; + features.data[index] = (features.data[index] - mean) / std; + } + } + } + + let padded_attention_mask; + if (padding) { + const [num_frames, num_channels] = features.dims; + + const pad_size = num_frames % pad_to_multiple_of; + if (pad_size > 0) { + const padded_data = new Float32Array(num_channels * (num_frames + pad_size)); + padded_data.set(features.data) + padded_data.fill(this.config.padding_value, features.data.length) + + const numPaddedFrames = num_frames + pad_size; + features = { + data: padded_data, + dims: [numPaddedFrames, num_channels], + } + + if (return_attention_mask) { + padded_attention_mask = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int64', + new BigInt64Array(numPaddedFrames), + [1, numPaddedFrames], + ) + padded_attention_mask.data.fill(1n, 0, num_frames); + } + } + } + + const [num_frames, num_channels] = features.dims; + + const stride = this.config.stride; + const remainder = num_frames % stride; + if (remainder !== 0) { + throw new Error(`The number of frames (${num_frames}) must be a multiple of the stride (${stride}).`) + } + + const input_features = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', + features.data, + features.dims, + ).view( + 1, + Math.floor(num_frames / stride), + num_channels * stride, + ); + + const result = { input_features } + + if (return_attention_mask) { + const reshapedNumFrames = input_features.dims[1]; + + const attention_mask = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor( + 'int64', + new BigInt64Array(reshapedNumFrames), + [1, reshapedNumFrames], + ); + if (padded_attention_mask) { + for (let i = 1, j = 0; i < num_frames; i += stride, ++j) { + attention_mask.data[j] = padded_attention_mask.data[i]; + } + } else { + attention_mask.data.fill(1n); + } + + result.attention_mask = attention_mask; + } + + return result; + } +} + +class ASTFeatureExtractor extends FeatureExtractor { + + + constructor(config) { + super(config); + + const sampling_rate = this.config.sampling_rate; + const mel_filters = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.mel_filter_bank)( + 256, // num_frequency_bins + this.config.num_mel_bins, // num_mel_filters + 20, // min_frequency + Math.floor(sampling_rate / 2), // max_frequency + sampling_rate, // sampling_rate + null, // norm + "kaldi", // mel_scale + true, // triangularize_in_mel_space + ); + + // Do padding: + for (let i = 0; i < mel_filters.length; ++i) { + mel_filters[i].push(0); + } + this.mel_filters = mel_filters; + + this.window = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.window_function)(400, 'hann', { + periodic: false, + }) + + this.mean = this.config.mean; + this.std = this.config.std; + } + + /** + * Computes the log-Mel spectrogram of the provided audio waveform. + * @param {Float32Array|Float64Array} waveform The audio waveform to process. + * @param {number} max_length The maximum number of frames to return. + * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers. + */ + _extract_fbank_features(waveform, max_length) { + // NOTE: We don't pad/truncate since that is passed in as `max_num_frames` + return (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.spectrogram)( + waveform, + this.window, // window + 400, // frame_length + 160, // hop_length + { + fft_length: 512, + power: 2.0, + center: false, + preemphasis: 0.97, + mel_filters: this.mel_filters, + log_mel: 'log', + mel_floor: 1.192092955078125e-07, + remove_dc_offset: true, + + // Custom + max_num_frames: max_length, + transpose: true, + } + ) + } + + + /** + * Asynchronously extracts features from a given audio using the provided configuration. + * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. + * @returns {Promise<{ input_values: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor. + */ + async _call(audio) { + validate_audio_inputs(audio, 'ASTFeatureExtractor'); + + const features = this._extract_fbank_features(audio, this.config.max_length); + if (this.config.do_normalize) { + // Normalize the input audio spectrogram to have mean=0, std=0.5 + const denom = this.std * 2; + for (let i = 0; i < features.data.length; ++i) { + features.data[i] = (features.data[i] - this.mean) / denom; + } + } + + return { + input_values: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', + features.data, + [1, ...features.dims] + ) + }; + } +} + +class ClapFeatureExtractor extends FeatureExtractor { + + constructor(config) { + super(config); + + this.mel_filters = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.mel_filter_bank)( + this.config.nb_frequency_bins, // num_frequency_bins + this.config.feature_size, // num_mel_filters + this.config.frequency_min, // min_frequency + this.config.frequency_max, // max_frequency + this.config.sampling_rate, // sampling_rate + null, // norm + "htk", // mel_scale + ); + + this.mel_filters_slaney = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.mel_filter_bank)( + this.config.nb_frequency_bins, // num_frequency_bins + this.config.feature_size, // num_mel_filters + this.config.frequency_min, // min_frequency + this.config.frequency_max, // max_frequency + this.config.sampling_rate, // sampling_rate + "slaney", // norm + "slaney", // mel_scale + ); + + this.window = (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.window_function)(this.config.fft_window_size, 'hann') + + } + + + /** + * Extracts the mel spectrogram and prepares it for the mode based on the `truncation` and `padding` arguments. + * + * Four different path are possible: + * - `truncation="fusion"` and the length of the waveform is greater than the max length: the mel spectrogram + * will be computed on the entire audio. 3 random crops and a dowsampled version of the full mel spectrogram + * are then stacked together. They will later be used for `feature_fusion`. + * - `truncation="rand_trunc"` and the length of the waveform is smaller than the max length: the audio is + * padded based on `padding`. + * - `truncation="fusion"` and the length of the waveform is smaller than the max length: the audio is padded + * based on `padding`, and is repeated `4` times. + * - `truncation="rand_trunc"` and the length of the waveform is greater than the max length: the mel + * spectrogram will be computed on a random crop of the waveform. + * + * @param {Float32Array|Float64Array} waveform The input waveform. + * @param {number} max_length The maximum length of the waveform. + * @param {string} truncation The truncation strategy to use. + * @param {string} padding The padding strategy to use. + * @returns {{ data: Float32Array; dims: number[]; longer: boolean; }} An object containing the mel spectrogram data as a Float32Array, its dimensions as an array of numbers, and a boolean indicating whether the waveform was longer than the max length. + */ + _get_input_mel(waveform, max_length, truncation, padding) { + + /** @type {{ data: Float32Array; dims: number[]}} */ + let input_mel; + let longer = false; + const diff = waveform.length - max_length; + if (diff > 0) { + if (truncation === 'rand_trunc') { + longer = true; + const idx = Math.floor(Math.random() * (diff + 1)); + waveform = waveform.subarray(idx, idx + max_length); + + input_mel = this._extract_fbank_features(waveform, this.mel_filters_slaney, this.config.nb_max_samples); + input_mel.dims = [1, ...input_mel.dims]; // "unsqueeze" + } else { + // TODO implement fusion strategy + throw new Error(`Truncation strategy "${truncation}" not implemented`) + } + } else { + if (diff < 0) { + let padded = new Float64Array(max_length); // already padded with zeros + padded.set(waveform); + + if (padding === 'repeat') { + for (let i = waveform.length; i < max_length; i += waveform.length) { + padded.set(waveform.subarray(0, Math.min(waveform.length, max_length - i)), i); + } + } else if (padding === 'repeatpad') { + for (let i = waveform.length; i < -diff; i += waveform.length) { + padded.set(waveform, i); + } + } + waveform = padded; + } + + if (truncation === 'fusion') { + throw new Error(`Truncation strategy "${truncation}" not implemented`) + } + + input_mel = this._extract_fbank_features(waveform, this.mel_filters_slaney, this.config.nb_max_samples); + input_mel.dims = [1, ...input_mel.dims]; // "unsqueeze" + } + + return { + ...input_mel, + longer, + } + } + + /** + * Compute the log-mel spectrogram of the provided `waveform` using the Hann window. + * In CLAP, two different filter banks are used depending on the truncation pattern: + * - `self.mel_filters`: they correspond to the default parameters of `torchaudio` which can be obtained from + * calling `torchaudio.transforms.MelSpectrogram().mel_scale.fb`. These filters are used when `truncation` + * is set to `"fusion"`. + * - `self.mel_filteres_slaney` : they correspond to the default parameters of `librosa` which used + * `librosa.filters.mel` when computing the mel spectrogram. These filters were only used in the original + * implementation when the truncation mode is not `"fusion"`. + * + * @param {Float32Array|Float64Array} waveform The audio waveform to process. + * @param {number[][]} mel_filters The mel filters to use. + * @param {number} [max_length=null] The maximum number of frames to return. + * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers. + */ + _extract_fbank_features(waveform, mel_filters, max_length = null) { + // NOTE: We don't pad/truncate since that is passed in as `max_num_frames` + return (0,_utils_audio_js__WEBPACK_IMPORTED_MODULE_5__.spectrogram)( + waveform, + this.window, // window + this.config.fft_window_size, // frame_length + this.config.hop_length, // hop_length + { + power: 2.0, + mel_filters, + log_mel: 'dB', + + // Custom + max_num_frames: max_length, + do_pad: false, + transpose: true, + } + ) + } + + + /** + * Asynchronously extracts features from a given audio using the provided configuration. + * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. + * @returns {Promise<{ input_features: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor. + */ + async _call(audio, { + max_length = null, + } = {}) { + validate_audio_inputs(audio, 'ClapFeatureExtractor'); + + // convert to mel spectrogram, truncate and pad if needed. + const padded_inputs = this._get_input_mel( + audio, + max_length ?? this.config.nb_max_samples, + this.config.truncation, + this.config.padding, + ); + + + return { + input_features: new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('float32', + padded_inputs.data, + [1, ...padded_inputs.dims] + ) + }; + } +} + + + +class SpeechT5FeatureExtractor extends FeatureExtractor { } + +/** + * Represents a Processor that extracts features from an input. + * @extends Callable + */ +class Processor extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + /** + * Creates a new Processor with the given feature extractor. + * @param {FeatureExtractor} feature_extractor The function used to extract features from the input. + */ + constructor(feature_extractor) { + super(); + this.feature_extractor = feature_extractor; + // TODO use tokenizer here? + } + + /** + * Calls the feature_extractor function with the given input. + * @param {any} input The input to extract features from. + * @param {...any} args Additional arguments. + * @returns {Promise} A Promise that resolves with the extracted features. + */ + async _call(input, ...args) { + return await this.feature_extractor(input, ...args); + } +} + +class SamProcessor extends Processor { + /** + * @borrows SamImageProcessor#_call as _call + */ + async _call(...args) { + return await this.feature_extractor(...args); + } + + /** + * @borrows SamImageProcessor#post_process_masks as post_process_masks + */ + post_process_masks(...args) { + // @ts-ignore + return this.feature_extractor.post_process_masks(...args); + } + /** + * @borrows SamImageProcessor#reshape_input_points as reshape_input_points + */ + reshape_input_points(...args) { + // @ts-ignore + return this.feature_extractor.reshape_input_points(...args); + } +} + +/** + * Represents a WhisperProcessor that extracts features from an audio input. + * @extends Processor + */ +class WhisperProcessor extends Processor { + /** + * Calls the feature_extractor function with the given audio input. + * @param {any} audio The audio input to extract features from. + * @returns {Promise} A Promise that resolves with the extracted features. + */ + async _call(audio) { + return await this.feature_extractor(audio) + } +} + + +class Wav2Vec2ProcessorWithLM extends Processor { + /** + * Calls the feature_extractor function with the given audio input. + * @param {any} audio The audio input to extract features from. + * @returns {Promise} A Promise that resolves with the extracted features. + */ + async _call(audio) { + return await this.feature_extractor(audio) + } +} + +class SpeechT5Processor extends Processor { + /** + * Calls the feature_extractor function with the given input. + * @param {any} input The input to extract features from. + * @returns {Promise} A Promise that resolves with the extracted features. + */ + async _call(input) { + return await this.feature_extractor(input) + } +} + +class OwlViTProcessor extends Processor { } + + +////////////////////////////////////////////////// +/** + * Helper class which is used to instantiate pretrained processors with the `from_pretrained` function. + * The chosen processor class is determined by the type specified in the processor config. + * + * **Example:** Load a processor using `from_pretrained`. + * ```javascript + * let processor = await AutoProcessor.from_pretrained('openai/whisper-tiny.en'); + * ``` + * + * **Example:** Run an image through a processor. + * ```javascript + * let processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16'); + * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'); + * let image_inputs = await processor(image); + * // { + * // "pixel_values": { + * // "dims": [ 1, 3, 224, 224 ], + * // "type": "float32", + * // "data": Float32Array [ -1.558687686920166, -1.558687686920166, -1.5440893173217773, ... ], + * // "size": 150528 + * // }, + * // "original_sizes": [ + * // [ 533, 800 ] + * // ], + * // "reshaped_input_sizes": [ + * // [ 224, 224 ] + * // ] + * // } + * ``` + */ +class AutoProcessor { + static FEATURE_EXTRACTOR_CLASS_MAPPING = { + ImageFeatureExtractor, + WhisperFeatureExtractor, + ViTFeatureExtractor, + MobileViTFeatureExtractor, + OwlViTFeatureExtractor, + Owlv2ImageProcessor, + CLIPFeatureExtractor, + ChineseCLIPFeatureExtractor, + SiglipImageProcessor, + ConvNextFeatureExtractor, + ConvNextImageProcessor, + SegformerFeatureExtractor, + BitImageProcessor, + DPTImageProcessor, + DPTFeatureExtractor, + GLPNFeatureExtractor, + BeitFeatureExtractor, + DeiTFeatureExtractor, + DetrFeatureExtractor, + YolosFeatureExtractor, + DonutFeatureExtractor, + NougatImageProcessor, + EfficientNetImageProcessor, + + ViTImageProcessor, + VitMatteImageProcessor, + SamImageProcessor, + Swin2SRImageProcessor, + Wav2Vec2FeatureExtractor, + SeamlessM4TFeatureExtractor, + SpeechT5FeatureExtractor, + ASTFeatureExtractor, + ClapFeatureExtractor, + } + + static PROCESSOR_CLASS_MAPPING = { + WhisperProcessor, + Wav2Vec2ProcessorWithLM, + SamProcessor, + SpeechT5Processor, + OwlViTProcessor, + } + + /** + * Instantiate one of the processor classes of the library from a pretrained model. + * + * The processor class to instantiate is selected based on the `feature_extractor_type` property of the config object + * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) + * + * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: + * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co. + * Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a + * user or organization name, like `dbmdz/bert-base-german-cased`. + * - A path to a *directory* containing processor files, e.g., `./my_model_directory/`. + * @param {import('./utils/hub.js').PretrainedOptions} options Additional options for loading the processor. + * + * @returns {Promise} A new instance of the Processor class. + */ + static async from_pretrained(pretrained_model_name_or_path, { + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + } = {}) { + + let preprocessorConfig = config ?? await (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_1__.getModelJSON)(pretrained_model_name_or_path, 'preprocessor_config.json', true, { + progress_callback, + config, + cache_dir, + local_files_only, + revision, + }) + + // Determine feature extractor class + // TODO: Ensure backwards compatibility with old configs + let key = preprocessorConfig.feature_extractor_type ?? preprocessorConfig.image_processor_type; + let feature_extractor_class = this.FEATURE_EXTRACTOR_CLASS_MAPPING[key]; + + if (!feature_extractor_class) { + if (preprocessorConfig.size !== undefined) { + // Assume ImageFeatureExtractor + console.warn(`Feature extractor type "${key}" not found, assuming ImageFeatureExtractor due to size parameter in config.`); + feature_extractor_class = ImageFeatureExtractor; + } else { + throw new Error(`Unknown Feature Extractor type: ${key}`); + } + } + + // If no associated processor class, use default + let processor_class = this.PROCESSOR_CLASS_MAPPING[preprocessorConfig.processor_class] ?? Processor; + + // Instantiate processor and feature extractor + let feature_extractor = new feature_extractor_class(preprocessorConfig); + return new processor_class(feature_extractor); + } +} +////////////////////////////////////////////////// + + + +/***/ }), + +/***/ "./src/tokenizers.js": +/*!***************************!*\ + !*** ./src/tokenizers.js ***! + \***************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "AlbertTokenizer": () => (/* binding */ AlbertTokenizer), +/* harmony export */ "AutoTokenizer": () => (/* binding */ AutoTokenizer), +/* harmony export */ "BartTokenizer": () => (/* binding */ BartTokenizer), +/* harmony export */ "BertTokenizer": () => (/* binding */ BertTokenizer), +/* harmony export */ "BlenderbotSmallTokenizer": () => (/* binding */ BlenderbotSmallTokenizer), +/* harmony export */ "BlenderbotTokenizer": () => (/* binding */ BlenderbotTokenizer), +/* harmony export */ "BloomTokenizer": () => (/* binding */ BloomTokenizer), +/* harmony export */ "CLIPTokenizer": () => (/* binding */ CLIPTokenizer), +/* harmony export */ "CamembertTokenizer": () => (/* binding */ CamembertTokenizer), +/* harmony export */ "CodeGenTokenizer": () => (/* binding */ CodeGenTokenizer), +/* harmony export */ "CodeLlamaTokenizer": () => (/* binding */ CodeLlamaTokenizer), +/* harmony export */ "CohereTokenizer": () => (/* binding */ CohereTokenizer), +/* harmony export */ "ConvBertTokenizer": () => (/* binding */ ConvBertTokenizer), +/* harmony export */ "DebertaTokenizer": () => (/* binding */ DebertaTokenizer), +/* harmony export */ "DebertaV2Tokenizer": () => (/* binding */ DebertaV2Tokenizer), +/* harmony export */ "DistilBertTokenizer": () => (/* binding */ DistilBertTokenizer), +/* harmony export */ "ElectraTokenizer": () => (/* binding */ ElectraTokenizer), +/* harmony export */ "EsmTokenizer": () => (/* binding */ EsmTokenizer), +/* harmony export */ "FalconTokenizer": () => (/* binding */ FalconTokenizer), +/* harmony export */ "GPT2Tokenizer": () => (/* binding */ GPT2Tokenizer), +/* harmony export */ "GPTNeoXTokenizer": () => (/* binding */ GPTNeoXTokenizer), +/* harmony export */ "GemmaTokenizer": () => (/* binding */ GemmaTokenizer), +/* harmony export */ "Grok1Tokenizer": () => (/* binding */ Grok1Tokenizer), +/* harmony export */ "HerbertTokenizer": () => (/* binding */ HerbertTokenizer), +/* harmony export */ "LlamaTokenizer": () => (/* binding */ LlamaTokenizer), +/* harmony export */ "M2M100Tokenizer": () => (/* binding */ M2M100Tokenizer), +/* harmony export */ "MBart50Tokenizer": () => (/* binding */ MBart50Tokenizer), +/* harmony export */ "MBartTokenizer": () => (/* binding */ MBartTokenizer), +/* harmony export */ "MPNetTokenizer": () => (/* binding */ MPNetTokenizer), +/* harmony export */ "MarianTokenizer": () => (/* binding */ MarianTokenizer), +/* harmony export */ "MobileBertTokenizer": () => (/* binding */ MobileBertTokenizer), +/* harmony export */ "NllbTokenizer": () => (/* binding */ NllbTokenizer), +/* harmony export */ "NougatTokenizer": () => (/* binding */ NougatTokenizer), +/* harmony export */ "PreTrainedTokenizer": () => (/* binding */ PreTrainedTokenizer), +/* harmony export */ "Qwen2Tokenizer": () => (/* binding */ Qwen2Tokenizer), +/* harmony export */ "RoFormerTokenizer": () => (/* binding */ RoFormerTokenizer), +/* harmony export */ "RobertaTokenizer": () => (/* binding */ RobertaTokenizer), +/* harmony export */ "SiglipTokenizer": () => (/* binding */ SiglipTokenizer), +/* harmony export */ "SpeechT5Tokenizer": () => (/* binding */ SpeechT5Tokenizer), +/* harmony export */ "SqueezeBertTokenizer": () => (/* binding */ SqueezeBertTokenizer), +/* harmony export */ "T5Tokenizer": () => (/* binding */ T5Tokenizer), +/* harmony export */ "TokenizerModel": () => (/* binding */ TokenizerModel), +/* harmony export */ "VitsTokenizer": () => (/* binding */ VitsTokenizer), +/* harmony export */ "Wav2Vec2CTCTokenizer": () => (/* binding */ Wav2Vec2CTCTokenizer), +/* harmony export */ "WhisperTokenizer": () => (/* binding */ WhisperTokenizer), +/* harmony export */ "XLMRobertaTokenizer": () => (/* binding */ XLMRobertaTokenizer), +/* harmony export */ "XLMTokenizer": () => (/* binding */ XLMTokenizer) +/* harmony export */ }); +/* harmony import */ var _utils_core_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/core.js */ "./src/utils/core.js"); +/* harmony import */ var _utils_hub_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/hub.js */ "./src/utils/hub.js"); +/* harmony import */ var _utils_maths_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/maths.js */ "./src/utils/maths.js"); +/* harmony import */ var _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils/tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _utils_data_structures_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/data-structures.js */ "./src/utils/data-structures.js"); +/* harmony import */ var _huggingface_jinja__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @huggingface/jinja */ "./node_modules/@huggingface/jinja/dist/index.js"); + +/** + * @file Tokenizers are used to prepare textual inputs for a model. + * + * **Example:** Create an `AutoTokenizer` and use it to tokenize a sentence. + * This will automatically detect the tokenizer type based on the tokenizer class defined in `tokenizer.json`. + * ```javascript + * import { AutoTokenizer } from '@xenova/transformers'; + * + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased'); + * const { input_ids } = await tokenizer('I love transformers!'); + * // Tensor { + * // data: BigInt64Array(6) [101n, 1045n, 2293n, 19081n, 999n, 102n], + * // dims: [1, 6], + * // type: 'int64', + * // size: 6, + * // } + * ``` + * + * @module tokenizers + */ + + + + + + + + + + + + + +/** + * @typedef {Object} TokenizerProperties Additional tokenizer-specific properties. + * @property {boolean} [legacy=false] Whether or not the `legacy` behavior of the tokenizer should be used. + * @typedef {import('./utils/hub.js').PretrainedOptions & TokenizerProperties} PretrainedTokenizerOptions + */ + +/** + * Loads a tokenizer from the specified path. + * @param {string} pretrained_model_name_or_path The path to the tokenizer directory. + * @param {PretrainedTokenizerOptions} options Additional options for loading the tokenizer. + * @returns {Promise} A promise that resolves with information about the loaded tokenizer. + */ +async function loadTokenizer(pretrained_model_name_or_path, options) { + + const info = await Promise.all([ + (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_1__.getModelJSON)(pretrained_model_name_or_path, 'tokenizer.json', true, options), + (0,_utils_hub_js__WEBPACK_IMPORTED_MODULE_1__.getModelJSON)(pretrained_model_name_or_path, 'tokenizer_config.json', true, options), + ]) + + // Override legacy option if `options.legacy` is not null + if (options.legacy !== null) { + info[1].legacy = options.legacy; + } + return info; +} + + +/** + * Helper function to split a string on a regex, but keep the delimiters. + * This is required, because the JavaScript `.split()` method does not keep the delimiters, + * and wrapping in a capturing group causes issues with existing capturing groups (due to nesting). + * @param {string} text The text to split. + * @param {RegExp} regex The regex to split on. + * @returns {string[]} The split string. + */ +function regexSplit(text, regex) { + const result = []; + let prev = 0; + for (const match of text.matchAll(regex)) { + const fullMatch = match[0]; + if (prev < match.index) { + result.push(text.slice(prev, match.index)); + } + if (fullMatch.length > 0) { + result.push(fullMatch); + } + prev = match.index + fullMatch.length; + } + if (prev < text.length) { + result.push(text.slice(prev)); + } + return result; +} + + +/** + * Helper method to construct a pattern from a config object. + * @param {Object} pattern The pattern object. + * @param {boolean} invert Whether to invert the pattern. + * @returns {RegExp|null} The compiled pattern. + */ +function createPattern(pattern, invert = true) { + + if (pattern.Regex !== undefined) { + // In certain cases, the pattern may contain unnecessary escape sequences (e.g., \# or \& or \~). + // i.e., valid in Python (where the patterns are exported from) but invalid in JavaScript (where the patterns are parsed). + // This isn't an issue when creating the regex w/o the 'u' flag, but it is when the 'u' flag is used. + // For this reason, it is necessary to remove these backslashes before creating the regex. + // See https://stackoverflow.com/a/63007777/13989043 for more information + let regex = pattern.Regex.replace(/\\([#&~])/g, '$1'); // TODO: add more characters to this list if necessary + + // We also handle special cases where the regex contains invalid (non-JS compatible) syntax. + for (const [key, value] of PROBLEMATIC_REGEX_MAP) { + regex = regex.replaceAll(key, value); + } + + return new RegExp(regex, 'gu'); + + } else if (pattern.String !== undefined) { + const escaped = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.escapeRegExp)(pattern.String); + // NOTE: if invert is true, we wrap the pattern in a group so that it is kept when performing .split() + return new RegExp(invert ? escaped : `(${escaped})`, 'gu'); + + } else { + console.warn('Unknown pattern type:', pattern) + return null; + } +} + +/** + * Helper function to convert an Object to a Map + * @param {Object} obj The object to convert. + * @returns {Map} The map. + */ +function objectToMap(obj) { + return new Map(Object.entries(obj)); +} + +/** + * Helper function to convert a tensor to a list before decoding. + * @param {Tensor} tensor The tensor to convert. + * @returns {number[]} The tensor as a list. + */ +function prepareTensorForDecode(tensor) { + const dims = tensor.dims; + switch (dims.length) { + case 1: + return tensor.tolist(); + case 2: + if (dims[0] !== 1) { + throw new Error('Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.'); + } + return tensor.tolist()[0]; + default: + throw new Error(`Expected tensor to have 1-2 dimensions, got ${dims.length}.`) + } +} + +/** + * Clean up a list of simple English tokenization artifacts like spaces before punctuations and abbreviated forms + * @param {string} text The text to clean up. + * @returns {string} The cleaned up text. + */ +function clean_up_tokenization(text) { + // Clean up a list of simple English tokenization artifacts + // like spaces before punctuations and abbreviated forms + return text.replace(/ \./g, '.') + .replace(/ \?/g, '?') + .replace(/ \!/g, '!') + .replace(/ ,/g, ',') + .replace(/ \' /g, "'") + .replace(/ n\'t/g, "n't") + .replace(/ \'m/g, "'m") + .replace(/ \'s/g, "'s") + .replace(/ \'ve/g, "'ve") + .replace(/ \'re/g, "'re"); +} + +/** + * Helper function to remove accents from a string. + * @param {string} text The text to remove accents from. + * @returns {string} The text with accents removed. + */ +function remove_accents(text) { + return text.replace(/[\u0300-\u036f]/g, ''); +} + +/** + * Helper function to lowercase a string and remove accents. + * @param {string} text The text to lowercase and remove accents from. + * @returns {string} The lowercased text with accents removed. + */ +function lowercase_and_remove_accent(text) { + return remove_accents(text.toLowerCase()); +} + +/** + * Helper function to fuse consecutive values in an array equal to the specified value. + * @param {string[]} arr The input array + * @param {any} value The value to fuse on. + * @param {Map} mapping The mapping from input domain to value. + */ +function fuse(arr, value, mapping) { + const fused = []; + let i = 0; + while (i < arr.length) { + fused.push(arr[i]) + if ((mapping.get(arr[i]) ?? value) !== value) { + ++i; + continue; + } + + while (i < arr.length && (mapping.get(arr[i]) ?? value) === value) { + ++i; + } + } + + return fused; +} + +/** + * Split a string on whitespace. + * @param {string} text The text to split. + * @returns {string[]} The split string. + */ +function whitespace_split(text) { + return text.match(/\S+/g) || []; +} + +const PUNCTUATION_REGEX = '\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E'; + +// A mapping of regex patterns to their equivalent (but longer) JS-compatible versions. +const PROBLEMATIC_REGEX_MAP = new Map([ + // This uses the case insensitive group modifier, which is not supported in JavaScript. + // When parsing the regex, an "Invalid group" error is thrown. + ["(?i:'s|'t|'re|'ve|'m|'ll|'d)", "(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"], +]) + + +/** + * Represent a token added by the user on top of the existing Model vocabulary. + * AddedToken can be configured to specify the behavior they should have in various situations like: + * - Whether they should only match single words + * - Whether to include any whitespace on its left or right + */ +class AddedToken { + /** + * Creates a new instance of AddedToken. + * @param {Object} config Added token configuration object. + * @param {string} config.content The content of the added token. + * @param {number} config.id The id of the added token. + * @param {boolean} [config.single_word=false] Whether this token must be a single word or can break words. + * @param {boolean} [config.lstrip=false] Whether this token should strip whitespaces on its left. + * @param {boolean} [config.rstrip=false] Whether this token should strip whitespaces on its right. + * @param {boolean} [config.normalized=false] Whether this token should be normalized. + * @param {boolean} [config.special=false] Whether this token is special. + */ + constructor(config) { + this.content = config.content; + this.id = config.id; + this.single_word = config.single_word ?? false; + this.lstrip = config.lstrip ?? false; + this.rstrip = config.rstrip ?? false; + this.special = config.special ?? false; + this.normalized = config.normalized ?? null; + } +} + +/** + * Abstract base class for tokenizer models. + * + * @extends Callable + */ +class TokenizerModel extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + /** + * Creates a new instance of TokenizerModel. + * @param {Object} config The configuration object for the TokenizerModel. + */ + constructor(config) { + super(); + this.config = config; + + /** @type {string[]} */ + this.vocab = []; + + /** + * A mapping of tokens to ids. + * @type {Map} + */ + this.tokens_to_ids = new Map(); + + this.unk_token_id = undefined; + this.unk_token = undefined; + this.end_of_word_suffix = undefined; + + /** @type {boolean} Whether to fuse unknown tokens when encoding. Defaults to false. */ + this.fuse_unk = this.config.fuse_unk ?? false; + } + + /** + * Instantiates a new TokenizerModel instance based on the configuration object provided. + * @param {Object} config The configuration object for the TokenizerModel. + * @param {...*} args Optional arguments to pass to the specific TokenizerModel constructor. + * @returns {TokenizerModel} A new instance of a TokenizerModel. + * @throws Will throw an error if the TokenizerModel type in the config is not recognized. + */ + static fromConfig(config, ...args) { + switch (config.type) { + case 'WordPiece': + return new WordPieceTokenizer(config); + case 'Unigram': + // @ts-ignore + return new Unigram(config, ...args); + + case 'BPE': + return new BPE(config); + + default: + if (config.vocab) { + // @ts-ignore + return new LegacyTokenizerModel(config, ...args); + } + throw new Error(`Unknown TokenizerModel type: ${config.type}`); + } + } + + /** + * Internal function to call the TokenizerModel instance. + * @param {string[]} tokens The tokens to encode. + * @returns {string[]} The encoded token IDs. + */ + _call(tokens) { + let ids = this.encode(tokens); + if (this.fuse_unk) { + // Fuse unknown tokens + ids = fuse(ids, this.unk_token_id, this.tokens_to_ids); + } + return ids; + } + + /** + * Encodes a list of tokens into a list of token IDs. + * @param {string[]} tokens The tokens to encode. + * @returns {string[]} The encoded tokens. + * @throws Will throw an error if not implemented in a subclass. + */ + encode(tokens) { + throw Error("encode should be implemented in subclass.") + } + + /** + * Converts a list of tokens into a list of token IDs. + * @param {string[]} tokens The tokens to convert. + * @returns {number[]} The converted token IDs. + */ + convert_tokens_to_ids(tokens) { + return tokens.map(t => this.tokens_to_ids.get(t) ?? this.unk_token_id); + } + + /** + * Converts a list of token IDs into a list of tokens. + * @param {number[]} ids The token IDs to convert. + * @returns {string[]} The converted tokens. + */ + convert_ids_to_tokens(ids) { + return ids.map(i => this.vocab[i] ?? this.unk_token); + } +} + +/** + * A subclass of TokenizerModel that uses WordPiece encoding to encode tokens. + * @extends TokenizerModel + */ +class WordPieceTokenizer extends TokenizerModel { + /** + * @param {Object} config The configuration object. + * @param {Object} config.vocab A mapping of tokens to ids. + * @param {string} config.unk_token The unknown token string. + * @param {string} config.continuing_subword_prefix The prefix to use for continuing subwords. + * @param {number} [config.max_input_chars_per_word=100] The maximum number of characters per word. + */ + constructor(config) { + super(config); + /** + * A mapping of tokens to ids. + * @type {Map} + */ + this.tokens_to_ids = objectToMap(config.vocab); + + /** + * The id of the unknown token. + * @type {number} + */ + this.unk_token_id = this.tokens_to_ids.get(config.unk_token); + + /** + * The unknown token string. + * @type {string} + */ + this.unk_token = config.unk_token; + + /** + * The maximum number of characters allowed per word. + * @type {number} + */ + this.max_input_chars_per_word = config.max_input_chars_per_word ?? 100; + + /** + * An array of tokens. + * @type {string[]} + */ + this.vocab = new Array(this.tokens_to_ids.size); + for (const [key, value] of this.tokens_to_ids) { + this.vocab[value] = key; + } + } + + /** + * Encodes an array of tokens using WordPiece encoding. + * @param {string[]} tokens The tokens to encode. + * @returns {string[]} An array of encoded tokens. + */ + encode(tokens) { + const outputTokens = []; + for (const token of tokens) { + const chars = [...token]; + if (chars.length > this.max_input_chars_per_word) { + outputTokens.push(this.unk_token); + continue; + } + + let isUnknown = false; + let start = 0; + const subTokens = []; + + while (start < chars.length) { + let end = chars.length; + let currentSubstring = null; + while (start < end) { + let substr = chars.slice(start, end).join(''); + + if (start > 0) { + substr = this.config.continuing_subword_prefix + substr; + } + if (this.tokens_to_ids.has(substr)) { + currentSubstring = substr; + break; + } + + --end; + } + if (currentSubstring === null) { + isUnknown = true; + break; + } + subTokens.push(currentSubstring); + start = end; + } + if (isUnknown) { + outputTokens.push(this.unk_token); + } else { + outputTokens.push(...subTokens); + } + } + + return outputTokens; + } + +} + +/** + * Class representing a Unigram tokenizer model. + * @extends TokenizerModel + */ +class Unigram extends TokenizerModel { + /** + * Create a new Unigram tokenizer model. + * @param {Object} config The configuration object for the Unigram model. + * @param {number} config.unk_id The ID of the unknown token + * @param {any[][]} config.vocab A 2D array representing a mapping of tokens to scores. + * @param {Object} moreConfig Additional configuration object for the Unigram model. + */ + constructor(config, moreConfig) { + super(config); + + const vocabSize = config.vocab.length; + this.vocab = new Array(vocabSize); + this.scores = new Array(vocabSize); + for (let i = 0; i < vocabSize; ++i) { + const piece = config.vocab[i]; + this.vocab[i] = piece[0]; + this.scores[i] = piece[1]; + } + + this.unk_token_id = config.unk_id; + this.unk_token = this.vocab[config.unk_id]; + + this.tokens_to_ids = new Map(this.vocab.map((x, i) => [x, i])); + this.bosToken = ' '; // beginning of a sentence token + + this.bosTokenId = this.tokens_to_ids.get(this.bosToken); // NOTE: may be undefined + this.eosToken = moreConfig.eos_token; + + this.eosTokenId = this.tokens_to_ids.get(this.eosToken); + this.unkToken = this.vocab[this.unk_token_id]; + + this.minScore = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.min)(this.scores)[0]; + + this.unkScore = this.minScore - 10.0; + this.scores[this.unk_token_id] = this.unkScore; + + this.trie = new _utils_data_structures_js__WEBPACK_IMPORTED_MODULE_4__.CharTrie(); + this.trie.extend(this.vocab); + + // NOTE: `fuse_unk` is hardcoded to true for Unigram models + // See: https://github.com/huggingface/tokenizers/blob/b58227c7f1ccf8b73ee2268354336da56d91e492/tokenizers/src/models/unigram/model.rs#L119 + this.fuse_unk = true; + } + + /** + * Populates lattice nodes. + * @param {TokenLattice} lattice The token lattice to populate with nodes. + */ + populateNodes(lattice) { + const sentence = lattice.sentence; + const len = sentence.length; + let beginPos = 0; + while (beginPos < len) { + const mblen = 1; + let hasSingleNode = false; + const tokens = []; + + for (let token of this.trie.commonPrefixSearch(sentence.slice(beginPos))) { + tokens.push(token); + const tokenId = this.tokens_to_ids.get(token); + const tokenScore = this.scores[tokenId]; + const n = token.length; + lattice.insert(beginPos, n, tokenScore, tokenId); + if (!hasSingleNode && n === mblen) { + hasSingleNode = true; + } + } + if (!hasSingleNode) { + lattice.insert(beginPos, mblen, this.unkScore, this.unk_token_id); + } + beginPos += mblen; + } + } + + /** + * Encodes an array of tokens into an array of subtokens using the unigram model. + * + * @param {string} normalized The normalized string. + * @returns {string[]} An array of subtokens obtained by encoding the input tokens using the unigram model. + */ + tokenize(normalized) { + const lattice = new _utils_data_structures_js__WEBPACK_IMPORTED_MODULE_4__.TokenLattice(normalized, this.bosTokenId, this.eosTokenId); + this.populateNodes(lattice); + return lattice.tokens(); + } + + /** + * Encodes an array of tokens using Unigram encoding. + * @param {string[]} tokens The tokens to encode. + * @returns {string[]} An array of encoded tokens. + */ + encode(tokens) { + const toReturn = []; + for (const token of tokens) { + const tokenized = this.tokenize(token); + toReturn.push(...tokenized); + } + return toReturn; + } + +} + +/** + * Returns list of utf-8 byte and a mapping to unicode strings. + * Specifically avoids mapping to whitespace/control characters the BPE code barfs on. + * @returns {Object} Object with utf-8 byte keys and unicode string values. + */ +const BYTES_TO_UNICODE = (() => { + // Returns list of utf-8 byte and a mapping to unicode strings. + // We specifically avoids mapping to whitespace/control characters + // the bpe code barfs on. + + const bs = [ + ...Array.from({ length: "~".charCodeAt(0) - "!".charCodeAt(0) + 1 }, (_, i) => i + "!".charCodeAt(0)), + ...Array.from({ length: "¬".charCodeAt(0) - "¡".charCodeAt(0) + 1 }, (_, i) => i + "¡".charCodeAt(0)), + ...Array.from({ length: "ÿ".charCodeAt(0) - "®".charCodeAt(0) + 1 }, (_, i) => i + "®".charCodeAt(0)), + ]; + const cs = bs.slice(); + let n = 0; + for (let b = 0; b < 256; ++b) { + if (!bs.includes(b)) { + bs.push(b); + cs.push(256 + n); + n += 1; + } + } + const ccs = cs.map(n => String.fromCharCode(n)); + return Object.fromEntries(bs.map((b, i) => [b, ccs[i]])); +})(); + +const UNICODE_TO_BYTES = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.reverseDictionary)(BYTES_TO_UNICODE); + + +/** + * @typedef {Object} BPENode + * @property {string} token The token associated with the node + * @property {number} bias A positional bias for the node. + * @property {number} [score] The score of the node. + * @property {BPENode} [prev] The previous node in the linked list. + * @property {BPENode} [next] The next node in the linked list. + */ + +/** + * BPE class for encoding text into Byte-Pair-Encoding (BPE) tokens. + * @extends TokenizerModel + */ +class BPE extends TokenizerModel { + /** + * Create a BPE instance. + * @param {Object} config The configuration object for BPE. + * @param {Object} config.vocab A mapping of tokens to ids. + * @param {string} config.unk_token The unknown token used for out of vocabulary words. + * @param {string} config.end_of_word_suffix The suffix to place at the end of each word. + * @param {string} [config.continuing_subword_suffix] The suffix to insert between words. + * @param {Array} config.merges An array of BPE merges as strings. + */ + constructor(config) { + super(config); + + this.BPE_SPLIT_TOKEN = ' '; + + /** @type {Map} */ + this.tokens_to_ids = objectToMap(config.vocab); + + this.unk_token_id = this.tokens_to_ids.get(config.unk_token); + this.unk_token = config.unk_token; + + this.vocab = new Array(this.tokens_to_ids.size); + for (const [key, value] of this.tokens_to_ids) { + this.vocab[value] = key; + } + + this.bpe_ranks = new Map(config.merges.map((x, i) => [x, i])); + this.merges = config.merges.map(x => x.split(this.BPE_SPLIT_TOKEN)); + + this.end_of_word_suffix = config.end_of_word_suffix; + + // NOTE: `continuing_subword_suffix` is custom (to support `BlenderbotSmallTokenizer`) + this.continuing_subword_suffix = config.continuing_subword_suffix ?? null; + + this.byte_fallback = this.config.byte_fallback ?? false; + + if (this.byte_fallback) { + this.text_encoder = new TextEncoder(); + } + + /** @type {Map} */ + this.cache = new Map(); + } + + /** + * Apply Byte-Pair-Encoding (BPE) to a given token. Efficient heap-based priority + * queue implementation adapted from https://github.com/belladoreai/llama-tokenizer-js. + * @param {string} token The token to encode. + * @returns {string[]} The BPE encoded tokens. + */ + bpe(token) { + if (token.length === 0) { + return []; + } + + const cached = this.cache.get(token); + if (cached !== undefined) { + return cached; + } + + const word = Array.from(token); + if (this.end_of_word_suffix) { + word[word.length - 1] += this.end_of_word_suffix; + } + + let result = []; + if (word.length > 1) { + // Create a priority queue to store the nodes that will be merged. + // The comparator function compares the scores of the nodes. + const queue = new _utils_data_structures_js__WEBPACK_IMPORTED_MODULE_4__.PriorityQueue((a, b) => a.score < b.score); + + // Construct a doubly-linked list of nodes that will be inserted into the priority queue, + // starting with the individual characters. We also populate each node with a positional + // bias to break ties in the priority queue. + let startingNode = { + token: word[0], + bias: 0, + prev: null, + next: null, + } + + let previousNode = startingNode + for (let i = 1; i < word.length; ++i) { + const currentNode = { + bias: i / word.length, // Add fractional component to break ties + token: word[i], + prev: previousNode, + next: null, + } + previousNode.next = currentNode + this._add_node(queue, previousNode) + previousNode = currentNode + } + + while (!queue.isEmpty()) { + // Get the next node with the highest priority + const node = queue.pop(); + + // Check that this merge is still possible + if (node.deleted || !node.next || node.next.deleted) continue; + + // Here, we mark the current node (left side of the merge) and the next node (right side of the merge) as deleted. + // This is because they will both be replaced by a new node representing the merge result. + node.deleted = true; + node.next.deleted = true; + + // Next, we fix the node that comes before the current node (i.e., left side of the merge). + if (node.prev) { + + // Make a shallow copy of the previous node + const newPreviousNode = { ...node.prev }; + + // Mark the old previous node as deleted. This avoids erroneous merges later, + // because there may still be references to this node in the priority queue. + node.prev.deleted = true; + node.prev = newPreviousNode; + + // Update the reference of the previous node, by pointing its previous node to this new previous node. + if (newPreviousNode.prev) { + newPreviousNode.prev.next = newPreviousNode; + } else { + // If the previous of the previous node does not exist, it means that + // `newPreviousNode` must be the new `startingNode`. + startingNode = newPreviousNode; + } + } + + // Create a new node which represents the result of the merge. + const merged = { + token: node.token + node.next.token, + bias: node.bias, + prev: node.prev, + next: node.next.next, + } + + // We now consider where we can add the new merged node to the priority queue: + // 1. prev <-> merged + if (merged.prev) { + merged.prev.next = merged; + this._add_node(queue, merged.prev); + } else { + // If `merged.prev` does not exist, then `merged` must be the new `startingNode`. + startingNode = merged; + } + + // 2. merged <-> next + if (merged.next) { + merged.next.prev = merged; + this._add_node(queue, merged); + } + } + + // Traverse the linked list, starting from the `startingNode`, and collect the tokens. + for (let currentNode = startingNode; currentNode !== null; currentNode = currentNode.next) { + result.push(currentNode.token); + } + } else { + result = word; + } + + // Possibly append suffix + if (this.continuing_subword_suffix) { + // Do not append suffix to the last token + for (let i = 0; i < result.length - 1; ++i) { + result[i] += this.continuing_subword_suffix; + } + } + + // Save the result to the cache + this.cache.set(token, result); + + return result; + } + + + /** + * Helper function to add a node to the priority queue. + * @param {PriorityQueue} queue + * @param {BPENode} node + * @private + */ + _add_node(queue, node) { + // `score` is a measure of the merge priority: lower means higher priority + // We use the BPE rank as a measure of priority (i.e., the local of the merge in the merges list) + // We also add a fractional component to the score to break ties (with the earlier character having higher priority) + const rank = this.bpe_ranks.get(node.token + this.BPE_SPLIT_TOKEN + node.next.token); + if (rank !== undefined) { + node.score = rank + node.bias; + queue.push(node); + } + } + + /** + * Encodes the input sequence of tokens using the BPE algorithm and returns the resulting subword tokens. + * @param {string[]} tokens The input sequence of tokens to encode. + * @returns {string[]} The resulting subword tokens after applying the BPE algorithm to the input sequence of tokens. + */ + encode(tokens) { + const outputTokens = []; + + for (const token of tokens) { + const bpe_token_list = this.bpe(token); + + for (const t of bpe_token_list) { + if (this.tokens_to_ids.has(t)) { + outputTokens.push(t); + } else { + if (this.byte_fallback) { + outputTokens.push( + ...Array.from(this.text_encoder.encode(t)) + .map(x => `<0x${x.toString(16).toUpperCase().padStart(2, '0')}>`) + ); + } else { + outputTokens.push(this.unk_token); + } + } + } + } + + return outputTokens; + } + +} + +/** + * Legacy tokenizer class for tokenizers with only a vocabulary. + */ +class LegacyTokenizerModel extends TokenizerModel { + /** + * Create a LegacyTokenizerModel instance. + * @param {Object} config The configuration object for LegacyTokenizerModel. + * @param {Object} config.vocab A (possibly nested) mapping of tokens to ids. + * @param {Object} moreConfig Additional configuration object for the LegacyTokenizerModel model. + */ + constructor(config, moreConfig) { + super(config); + + /**@type {Map} */ + this.tokens_to_ids = objectToMap( + moreConfig.target_lang + ? config.vocab[moreConfig.target_lang] + : config.vocab + ); + + this.bos_token = moreConfig.bos_token; + this.bos_token_id = this.tokens_to_ids.get(this.bos_token); + + this.eos_token = moreConfig.eos_token; + this.eos_token_id = this.tokens_to_ids.get(this.eos_token); + + this.pad_token = moreConfig.pad_token; + this.pad_token_id = this.tokens_to_ids.get(this.pad_token); + + this.unk_token = moreConfig.unk_token; + this.unk_token_id = this.tokens_to_ids.get(this.unk_token); + + this.vocab = new Array(this.tokens_to_ids.size); + for (const [key, value] of this.tokens_to_ids) { + this.vocab[value] = key; + } + } + + encode(tokens) { + return tokens; + } +} + + +/** + * A base class for text normalization. + * @abstract + */ +class Normalizer extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + /** + * @param {Object} config The configuration object for the normalizer. + */ + constructor(config) { + super(); + this.config = config; + } + + /** + * Factory method for creating normalizers from config objects. + * @static + * @param {Object} config The configuration object for the normalizer. + * @returns {Normalizer} A Normalizer object. + * @throws {Error} If an unknown Normalizer type is specified in the config. + */ + static fromConfig(config) { + if (config === null) return null; + switch (config.type) { + case 'BertNormalizer': + return new BertNormalizer(config); + case 'Precompiled': + return new Precompiled(config); + case 'Sequence': + return new NormalizerSequence(config); + case 'Replace': + return new Replace(config); + case 'NFC': + return new NFC(config); + case 'NFKC': + return new NFKC(config); + case 'NFKD': + return new NFKD(config); + case 'Strip': + return new StripNormalizer(config); + case 'StripAccents': + return new StripAccents(config); + case 'Lowercase': + return new Lowercase(config); + case 'Prepend': + return new Prepend(config); + default: + throw new Error(`Unknown Normalizer type: ${config.type}`); + } + } + + /** + * Normalize the input text. + * @abstract + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + * @throws {Error} If this method is not implemented in a subclass. + */ + normalize(text) { + throw Error("normalize should be implemented in subclass.") + } + + /** + * Alias for {@link Normalizer#normalize}. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + _call(text) { + return this.normalize(text); + } + +} + +/** + * Replace normalizer that replaces occurrences of a pattern with a given string or regular expression. + * @extends Normalizer + */ +class Replace extends Normalizer { + /** + * Normalize the input text by replacing the pattern with the content. + * @param {string} text The input text to be normalized. + * @returns {string} The normalized text after replacing the pattern with the content. + */ + normalize(text) { + const pattern = createPattern(this.config.pattern); + return pattern === null + ? text + : text.replaceAll(pattern, this.config.content); + } +} + +/** + * A normalizer that applies Unicode normalization form C (NFC) to the input text. + * @extends Normalizer + */ +class NFC extends Normalizer { + /** + * Normalize the input text by applying Unicode normalization form C (NFC). + * @param {string} text The input text to be normalized. + * @returns {string} The normalized text. + */ + normalize(text) { + text = text.normalize('NFC') + return text; + } +} + +/** + * NFKC Normalizer. + * @extends Normalizer + */ +class NFKC extends Normalizer { + /** + * Normalize text using NFKC normalization. + * @param {string} text The text to be normalized. + * @returns {string} The normalized text. + */ + normalize(text) { + text = text.normalize('NFKC') + return text; + } +} +/** + * NFKD Normalizer. + * @extends Normalizer + */ +class NFKD extends Normalizer { + /** + * Normalize text using NFKD normalization. + * @param {string} text The text to be normalized. + * @returns {string} The normalized text. + */ + normalize(text) { + text = text.normalize('NFKD') + return text; + } +} + +/** + * A normalizer that strips leading and/or trailing whitespace from the input text. + */ +class StripNormalizer extends Normalizer { + /** + * Strip leading and/or trailing whitespace from the input text. + * @param {string} text The input text. + * @returns {string} The normalized text. + */ + normalize(text) { + if (this.config.strip_left && this.config.strip_right) { + // Fast path to avoid an extra trim call + text = text.trim(); + } else { + if (this.config.strip_left) { + text = text.trimStart(); + } + if (this.config.strip_right) { + text = text.trimEnd(); + } + } + return text; + } +} + +/** + * StripAccents normalizer removes all accents from the text. + * @extends Normalizer + */ +class StripAccents extends Normalizer { + /** + * Remove all accents from the text. + * @param {string} text The input text. + * @returns {string} The normalized text without accents. + */ + normalize(text) { + text = remove_accents(text); + return text; + } +} + +/** + * A Normalizer that lowercases the input string. + * @extends Normalizer + */ +class Lowercase extends Normalizer { + /** + * Lowercases the input string. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + normalize(text) { + text = text.toLowerCase(); + return text; + } +} + +/** + * A Normalizer that prepends a string to the input string. + * @extends Normalizer + */ +class Prepend extends Normalizer { + /** + * Prepends the input string. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + normalize(text) { + text = this.config.prepend + text; + return text; + } +} + +/** + * A Normalizer that applies a sequence of Normalizers. + * @extends Normalizer + */ +class NormalizerSequence extends Normalizer { + /** + * Create a new instance of NormalizerSequence. + * @param {Object} config The configuration object. + * @param {Object[]} config.normalizers An array of Normalizer configuration objects. + */ + constructor(config) { + super(config); + this.normalizers = config.normalizers.map(x => Normalizer.fromConfig(x)); + } + /** + * Apply a sequence of Normalizers to the input text. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + normalize(text) { + return this.normalizers.reduce((t, normalizer) => { + return normalizer.normalize(t); + }, text); + } +} + +/** + * A class representing a normalizer used in BERT tokenization. + * @extends Normalizer + */ +class BertNormalizer extends Normalizer { + /** + * Adds whitespace around any CJK (Chinese, Japanese, or Korean) character in the input text. + * + * @param {string} text The input text to tokenize. + * @returns {string} The tokenized text with whitespace added around CJK characters. + */ + _tokenize_chinese_chars(text) { + /* Adds whitespace around any CJK character. */ + const output = []; + for (let i = 0; i < text.length; ++i) { + const char = text[i]; + const cp = char.charCodeAt(0); + if (this._is_chinese_char(cp)) { + output.push(" "); + output.push(char); + output.push(" "); + } else { + output.push(char); + } + } + return output.join(""); + } + + /** + * Checks whether the given Unicode codepoint represents a CJK (Chinese, Japanese, or Korean) character. + * + * A "chinese character" is defined as anything in the CJK Unicode block: + * https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block) + * + * Note that the CJK Unicode block is NOT all Japanese and Korean characters, despite its name. + * The modern Korean Hangul alphabet is a different block, as is Japanese Hiragana and Katakana. + * Those alphabets are used to write space-separated words, so they are not treated specially + * and are handled like all other languages. + * + * @param {number} cp The Unicode codepoint to check. + * @returns {boolean} True if the codepoint represents a CJK character, false otherwise. + */ + _is_chinese_char(cp) { + return ( + (cp >= 0x4E00 && cp <= 0x9FFF) + || (cp >= 0x3400 && cp <= 0x4DBF) + || (cp >= 0x20000 && cp <= 0x2A6DF) + || (cp >= 0x2A700 && cp <= 0x2B73F) + || (cp >= 0x2B740 && cp <= 0x2B81F) + || (cp >= 0x2B820 && cp <= 0x2CEAF) + || (cp >= 0xF900 && cp <= 0xFAFF) + || (cp >= 0x2F800 && cp <= 0x2FA1F) + ) + } + /** + * Strips accents from the given text. + * @param {string} text The text to strip accents from. + * @returns {string} The text with accents removed. + */ + stripAccents(text) { + return text.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); + } + + + /** + * Checks whether `char` is a control character. + * @param {string} char The character to check. + * @returns {boolean} Whether `char` is a control character. + * @private + */ + _is_control(char) { + switch (char) { + case '\t': + case '\n': + case '\r': + // These are technically control characters but we count them as whitespace characters. + return false; + + default: + // Check if unicode category starts with C: + // Cc - Control + // Cf - Format + // Co - Private Use + // Cs - Surrogate + return /^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(char); + } + } + + /** + * Performs invalid character removal and whitespace cleanup on text. + * @param {string} text The text to clean. + * @returns {string} The cleaned text. + * @private + */ + _clean_text(text) { + const output = []; + for (const char of text) { + const cp = char.charCodeAt(0); + if (cp === 0 || cp === 0xFFFD || this._is_control(char)) { + continue; + } + if (/^\s$/.test(char)) { // is whitespace + output.push(" "); + } else { + output.push(char); + } + } + return output.join(""); + } + /** + * Normalizes the given text based on the configuration. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + normalize(text) { + if (this.config.clean_text) { + text = this._clean_text(text); + } + + if (this.config.handle_chinese_chars) { + text = this._tokenize_chinese_chars(text); + } + + if (this.config.lowercase) { + text = text.toLowerCase(); + + if (this.config.strip_accents !== false) { + text = this.stripAccents(text); + } + } else if (this.config.strip_accents) { + text = this.stripAccents(text); + } + + return text; + } +} + +/** + * A callable class representing a pre-tokenizer used in tokenization. Subclasses + * should implement the `pre_tokenize_text` method to define the specific pre-tokenization logic. + * @extends Callable + */ +class PreTokenizer extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + /** + * Factory method that returns an instance of a subclass of `PreTokenizer` based on the provided configuration. + * + * @static + * @param {Object} config A configuration object for the pre-tokenizer. + * @returns {PreTokenizer} An instance of a subclass of `PreTokenizer`. + * @throws {Error} If the provided configuration object does not correspond to any known pre-tokenizer. + */ + static fromConfig(config) { + if (config === null) return null; + + switch (config.type) { + case 'BertPreTokenizer': + return new BertPreTokenizer(config); + case 'Sequence': + return new PreTokenizerSequence(config); + case 'Whitespace': + return new WhitespacePreTokenizer(config); + case 'WhitespaceSplit': + return new WhitespaceSplit(config); + case 'Metaspace': + return new MetaspacePreTokenizer(config); + + case 'ByteLevel': + return new ByteLevelPreTokenizer(config); + case 'Split': + return new SplitPreTokenizer(config); + case 'Punctuation': + return new PunctuationPreTokenizer(config); + case 'Digits': + return new DigitsPreTokenizer(config); + case 'Replace': + return new ReplacePreTokenizer(config); + default: + throw new Error(`Unknown PreTokenizer type: ${config.type}`); + } + } + + /** + * Method that should be implemented by subclasses to define the specific pre-tokenization logic. + * + * @abstract + * @param {string} text The text to pre-tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} The pre-tokenized text. + * @throws {Error} If the method is not implemented in the subclass. + */ + pre_tokenize_text(text, options) { + throw Error("pre_tokenize_text should be implemented in subclass.") + } + + /** + * Tokenizes the given text into pre-tokens. + * @param {string|string[]} text The text or array of texts to pre-tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of pre-tokens. + */ + pre_tokenize(text, options) { + return (Array.isArray(text) + ? text.map(x => this.pre_tokenize_text(x, options)) + : this.pre_tokenize_text(text, options) + ).flat(); + } + + /** + * Alias for {@link PreTokenizer#pre_tokenize}. + * @param {string|string[]} text The text or array of texts to pre-tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of pre-tokens. + */ + _call(text, options) { + return this.pre_tokenize(text, options); + } +} + +/** + * @extends PreTokenizer + */ +class BertPreTokenizer extends PreTokenizer { + /** + * A PreTokenizer that splits text into wordpieces using a basic tokenization scheme + * similar to that used in the original implementation of BERT. + * + * @param {Object} config The configuration object. + */ + constructor(config) { + super(); + // Construct a pattern which matches the rust implementation: + // https://github.com/huggingface/tokenizers/blob/b4fcc9ce6e4ad5806e82826f816acfdfdc4fcc67/tokenizers/src/pre_tokenizers/bert.rs#L11 + // Equivalent to removing whitespace and splitting on punctuation (both \p{P} and other ascii characters) + this.pattern = new RegExp(`[^\\s${PUNCTUATION_REGEX}]+|[${PUNCTUATION_REGEX}]`, 'gu'); + } + /** + * Tokenizes a single text using the BERT pre-tokenization scheme. + * + * @param {string} text The text to tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens. + */ + pre_tokenize_text(text, options) { + return text.trim().match(this.pattern) || []; + } +} + +/** + * A pre-tokenizer that splits text into Byte-Pair-Encoding (BPE) subwords. + * @extends PreTokenizer + */ +class ByteLevelPreTokenizer extends PreTokenizer { + /** + * Creates a new instance of the `ByteLevelPreTokenizer` class. + * @param {Object} config The configuration object. + */ + constructor(config) { + super(); + this.config = config; + + /** + * @type {boolean} Whether to add a leading space to the first word. + * This allows to treat the leading word just as any other word. + */ + this.add_prefix_space = this.config.add_prefix_space; + + /** + * @type {boolean} Whether the post processing step should trim offsets + * to avoid including whitespaces. + * @todo Use this in the pretokenization step. + */ + this.trim_offsets = this.config.trim_offsets; + + /** + * @type {boolean} Whether to use the standard GPT2 regex for whitespace splitting. + * Set it to False if you want to use your own splitting. Defaults to true. + */ + this.use_regex = this.config.use_regex ?? true; + this.pattern = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu; + + this.byte_encoder = BYTES_TO_UNICODE; + this.text_encoder = new TextEncoder(); + } + + /** + * Tokenizes a single piece of text using byte-level tokenization. + * @param {string} text The text to tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens. + */ + pre_tokenize_text(text, options) { + // Add a leading space if the option is enabled + if (this.add_prefix_space && !text.startsWith(' ')) { + text = ' ' + text; + } + + // Split on whitespace and punctuation + const tokens = this.use_regex ? (text.match(this.pattern) || []) : [text]; + + // Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case) + return tokens.map( + token => Array.from(this.text_encoder.encode(token), byte => this.byte_encoder[byte]).join('') + ); + } +} + +/** + * @typedef {'removed'|'isolated'|'mergedWithPrevious'|'mergedWithNext'|'contiguous'} SplitDelimiterBehavior + */ + +/** + * Splits text using a given pattern. + * @extends PreTokenizer + */ +class SplitPreTokenizer extends PreTokenizer { + /** + * @param {Object} config The configuration options for the pre-tokenizer. + * @param {Object} config.pattern The pattern used to split the text. Can be a string or a regex object. + * @param {string|undefined} config.pattern.String The string to use for splitting. Only defined if the pattern is a string. + * @param {string|undefined} config.pattern.Regex The regex to use for splitting. Only defined if the pattern is a regex. + * @param {SplitDelimiterBehavior} config.behavior The behavior to use when splitting. + * @param {boolean} config.invert Whether to split (invert=false) or match (invert=true) the pattern. + */ + constructor(config) { + super(); + this.config = config; + // TODO support all behaviours (config.behavior) + + this.pattern = createPattern(this.config.pattern, this.config.invert); + } + + /** + * Tokenizes text by splitting it using the given pattern. + * @param {string} text The text to tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens. + */ + pre_tokenize_text(text, options) { + if (this.pattern === null) { + return []; + } + + if (this.config.invert) { + return text.match(this.pattern) || []; + } else { + return regexSplit(text, this.pattern); + } + } +} + +/** + * Splits text based on punctuation. + * @extends PreTokenizer + */ +class PunctuationPreTokenizer extends PreTokenizer { + /** + * @param {Object} config The configuration options for the pre-tokenizer. + * @param {SplitDelimiterBehavior} config.behavior The behavior to use when splitting. + */ + constructor(config) { + super(); + this.config = config; + this.pattern = new RegExp(`[^${PUNCTUATION_REGEX}]+|[${PUNCTUATION_REGEX}]+`, 'gu'); + } + + /** + * Tokenizes text by splitting it using the given pattern. + * @param {string} text The text to tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens. + */ + pre_tokenize_text(text, options) { + return text.match(this.pattern) || []; + } +} + + +/** + * Splits text based on digits. + * @extends PreTokenizer + */ +class DigitsPreTokenizer extends PreTokenizer { + /** + * @param {Object} config The configuration options for the pre-tokenizer. + * @param {boolean} config.individual_digits Whether to split on individual digits. + */ + constructor(config) { + super(); + this.config = config; + + // Construct a pattern which matches the rust implementation: + const digit_pattern = `[^\\d]+|\\d${this.config.individual_digits ? '' : '+'}`; + this.pattern = new RegExp(digit_pattern, 'gu'); + } + + /** + * Tokenizes text by splitting it using the given pattern. + * @param {string} text The text to tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens. + */ + pre_tokenize_text(text, options) { + return text.match(this.pattern) || []; + } +} + +/** + * @typedef {Object} PostProcessedOutput + * @property {string[]} tokens List of token produced by the post-processor. + * @property {number[]} [token_type_ids] List of token type ids produced by the post-processor. + */ + + +/** + * @typedef {Object} EncodingSingle + * @property {number[]} input_ids List of token ids to be fed to a model. + * @property {number[]} attention_mask List of token type ids to be fed to a model + * @property {number[]} [token_type_ids] List of indices specifying which tokens should be attended to by the model + */ + + +/** + * @extends Callable + */ +class PostProcessor extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + + /** + * @param {Object} config The configuration for the post-processor. + */ + constructor(config) { + super(); + this.config = config; + } + + /** + * Factory method to create a PostProcessor object from a configuration object. + * + * @param {Object} config Configuration object representing a PostProcessor. + * @returns {PostProcessor} A PostProcessor object created from the given configuration. + * @throws {Error} If an unknown PostProcessor type is encountered. + */ + static fromConfig(config) { + if (config === null) return null; + switch (config.type) { + case 'TemplateProcessing': + return new TemplateProcessing(config); + + case 'ByteLevel': + return new ByteLevelPostProcessor(config); + + case 'RobertaProcessing': + return new RobertaProcessing(config); + case 'BertProcessing': + return new BertProcessing(config); + + default: + throw new Error(`Unknown PostProcessor type: ${config.type}`); + } + } + + /** + * Method to be implemented in subclass to apply post-processing on the given tokens. + * + * @param {Array} tokens The input tokens to be post-processed. + * @param {...*} args Additional arguments required by the post-processing logic. + * @returns {PostProcessedOutput} The post-processed tokens. + * @throws {Error} If the method is not implemented in subclass. + */ + post_process(tokens, ...args) { + throw Error("post_process should be implemented in subclass.") + } + + /** + * Alias for {@link PostProcessor#post_process}. + * @param {Array} tokens The text or array of texts to post-process. + * @param {...*} args Additional arguments required by the post-processing logic. + * @returns {PostProcessedOutput} The post-processed tokens. + */ + _call(tokens, ...args) { + return this.post_process(tokens, ...args); + } +} + +/** + * A post-processor that adds special tokens to the beginning and end of the input. + */ +class BertProcessing extends PostProcessor { + /** + * @param {Object} config The configuration for the post-processor. + * @param {string[]} config.cls The special tokens to add to the beginning of the input. + * @param {string[]} config.sep The special tokens to add to the end of the input. + */ + constructor(config) { + super(config); + // TODO use all of config: add_prefix_space, trim_offsets + + this.cls = config.cls[0]; + this.sep = config.sep[0]; + } + + /** + * Adds the special tokens to the beginning and end of the input. + * @param {string[]} tokens The input tokens. + * @param {string[]} [tokens_pair=null] An optional second set of input tokens. + * @returns {PostProcessedOutput} The post-processed tokens with the special tokens added to the beginning and end. + */ + post_process(tokens, tokens_pair = null, { + add_special_tokens = true, + } = {}) { + if (add_special_tokens) { + tokens = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)([this.cls], tokens, [this.sep]); + } + + let token_type_ids = new Array(tokens.length).fill(0); + if (tokens_pair !== null) { + // NOTE: It is intended to add 2 EOS tokens after the first set of tokens + // https://github.com/huggingface/tokenizers/issues/983 + const middle = (add_special_tokens && this instanceof RobertaProcessing) + ? [this.sep] + : []; + const after = add_special_tokens ? [this.sep] : []; + + tokens = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(tokens, middle, tokens_pair, after); + token_type_ids = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(token_type_ids, new Array(tokens_pair.length + middle.length + after.length).fill(1)); + } + return { tokens, token_type_ids }; + } +} +class RobertaProcessing extends BertProcessing { } // NOTE: extends BertProcessing + +/** + * Post processor that replaces special tokens in a template with actual tokens. + * @extends PostProcessor + */ +class TemplateProcessing extends PostProcessor { + /** + * Creates a new instance of `TemplateProcessing`. + * @param {Object} config The configuration options for the post processor. + * @param {Array} config.single The template for a single sequence of tokens. + * @param {Array} config.pair The template for a pair of sequences of tokens. + */ + constructor(config) { + super(config); + + this.single = config.single; + this.pair = config.pair; + } + + /** + * Replaces special tokens in the template with actual tokens. + * @param {string[]} tokens The list of tokens for the first sequence. + * @param {string[]} [tokens_pair=null] The list of tokens for the second sequence (optional). + * @returns {PostProcessedOutput} An object containing the list of tokens with the special tokens replaced with actual tokens. + */ + post_process(tokens, tokens_pair = null, { + add_special_tokens = true, + } = {}) { + const type = tokens_pair === null ? this.single : this.pair + + let processedTokens = []; + let types = []; + for (const item of type) { + if ('SpecialToken' in item) { + if (add_special_tokens) { + processedTokens.push(item.SpecialToken.id); + types.push(item.SpecialToken.type_id); + } + } else if ('Sequence' in item) { + if (item.Sequence.id === 'A') { + processedTokens = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(processedTokens, tokens); + types = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(types, new Array(tokens.length).fill(item.Sequence.type_id)); + + } else if (item.Sequence.id === 'B') { + processedTokens = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(processedTokens, tokens_pair); + types = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(types, new Array(tokens_pair.length).fill(item.Sequence.type_id)); + } + } + } + return { tokens: processedTokens, token_type_ids: types }; + } +} + +/** + * A PostProcessor that returns the given tokens as is. + * @extends PostProcessor + */ +class ByteLevelPostProcessor extends PostProcessor { + /** + * Post process the given tokens. + * @param {string[]} tokens The list of tokens for the first sequence. + * @param {string[]} [tokens_pair=null] The list of tokens for the second sequence (optional). + * @returns {PostProcessedOutput} An object containing the post-processed tokens. + */ + post_process(tokens, tokens_pair = null) { + if (tokens_pair) { + tokens = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(tokens, tokens_pair); + } + return { tokens }; + } +} + +/** + * The base class for token decoders. + * @extends Callable + */ +class Decoder extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + + /** + * Creates an instance of `Decoder`. + * + * @param {Object} config The configuration object. + */ + constructor(config) { + super(); + this.config = config; + + /** @type {AddedToken[]} */ + this.added_tokens = []; + this.end_of_word_suffix = null; + this.trim_offsets = config.trim_offsets; + } + + /** + * Creates a decoder instance based on the provided configuration. + * + * @param {Object} config The configuration object. + * @returns {Decoder} A decoder instance. + * @throws {Error} If an unknown decoder type is provided. + */ + static fromConfig(config) { + if (config === null) return null; + switch (config.type) { + case 'WordPiece': + return new WordPieceDecoder(config); + case 'Metaspace': + return new MetaspaceDecoder(config); + case 'ByteLevel': + return new ByteLevelDecoder(config); + + case 'Replace': + return new ReplaceDecoder(config); + case 'ByteFallback': + return new ByteFallback(config); + case 'Fuse': + return new FuseDecoder(config); + case 'Strip': + return new StripDecoder(config); + + case 'Sequence': + return new DecoderSequence(config); + + case 'CTC': + return new CTCDecoder(config); + case 'BPEDecoder': + return new BPEDecoder(config); + default: + throw new Error(`Unknown Decoder type: ${config.type}`); + } + } + + /** + * Calls the `decode` method. + * + * @param {string[]} tokens The list of tokens. + * @returns {string} The decoded string. + */ + _call(tokens) { + return this.decode(tokens); + } + + /** + * Decodes a list of tokens. + * @param {string[]} tokens The list of tokens. + * @returns {string} The decoded string. + */ + decode(tokens) { + return this.decode_chain(tokens).join(''); + } + + /** + * Apply the decoder to a list of tokens. + * + * @param {string[]} tokens The list of tokens. + * @returns {string[]} The decoded list of tokens. + * @throws {Error} If the `decode_chain` method is not implemented in the subclass. + */ + decode_chain(tokens) { + throw Error("`decode_chain` should be implemented in subclass.") + } + +} + +class ReplaceDecoder extends Decoder { + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + const pattern = createPattern(this.config.pattern); + return pattern === null + ? tokens + : tokens.map(token => token.replaceAll(pattern, this.config.content)) + } +} + + +class ByteFallback extends Decoder { + constructor(config) { + super(config); + + this.text_decoder = new TextDecoder(); + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + + const new_tokens = []; + let previous_byte_tokens = []; + + for (const token of tokens) { + let bytes = null; + if (token.length === 6 && token.startsWith('<0x') && token.endsWith('>')) { + const byte = parseInt(token.slice(3, 5), 16); + if (!isNaN(byte)) { + bytes = byte; + } + } + if (bytes !== null) { + previous_byte_tokens.push(bytes); + } else { + if (previous_byte_tokens.length > 0) { + const string = this.text_decoder.decode(Uint8Array.from(previous_byte_tokens)); + new_tokens.push(string); + previous_byte_tokens = []; + } + new_tokens.push(token); + } + } + if (previous_byte_tokens.length > 0) { + const string = this.text_decoder.decode(Uint8Array.from(previous_byte_tokens)); + new_tokens.push(string); + previous_byte_tokens = []; + } + + return new_tokens; + } +} + +/** + * Fuse simply fuses all tokens into one big string. + * It's usually the last decoding step anyway, but this decoder + * exists incase some decoders need to happen after that step + */ +class FuseDecoder extends Decoder { + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + return [tokens.join('')]; + } +} + + +class StripDecoder extends Decoder { + constructor(config) { + super(config); + + this.content = this.config.content; + this.start = this.config.start; + this.stop = this.config.stop; + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + return tokens.map(token => { + let start_cut = 0; + for (let i = 0; i < this.start; ++i) { + if (token[i] === this.content) { + start_cut = i + 1; + continue; + } else { + break; + } + } + + let stop_cut = token.length; + for (let i = 0; i < this.stop; ++i) { + const index = token.length - i - 1; + if (token[index] === this.content) { + stop_cut = index; + continue; + } else { + break; + } + } + + return token.slice(start_cut, stop_cut) + }); + } +} + +/** + * A decoder that decodes a list of WordPiece tokens into a single string. + * @extends Decoder + */ +class WordPieceDecoder extends Decoder { + + /** + * Creates a new instance of WordPieceDecoder. + * @param {Object} config The configuration object. + * @param {string} config.prefix The prefix used for WordPiece encoding. + * @param {boolean} config.cleanup Whether to cleanup the decoded string. + */ + constructor(config) { + super(config); + this.cleanup = config.cleanup; + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + return tokens.map((token, i) => { + if (i !== 0) { + if (token.startsWith(this.config.prefix)) { + // NOTE: .replace() is intended; only replace first occurrence + token = token.replace(this.config.prefix, ''); + } else { + token = ' ' + token; + } + } + if (this.cleanup) { + token = clean_up_tokenization(token) + } + + return token; + }); + } +} + +/** + * Byte-level decoder for tokenization output. Inherits from the `Decoder` class. + * @extends Decoder + */ +class ByteLevelDecoder extends Decoder { + + /** + * Create a `ByteLevelDecoder` object. + * @param {Object} config Configuration object. + */ + constructor(config) { + super(config); + + this.byte_decoder = UNICODE_TO_BYTES; + this.text_decoder = new TextDecoder("utf-8", { + fatal: false, + ignoreBOM: true, + }); + + this.end_of_word_suffix = null; + } + + /** + * Convert an array of tokens to string by decoding each byte. + * @param {string[]} tokens Array of tokens to be decoded. + * @returns {string} The decoded string. + */ + convert_tokens_to_string(tokens) { + const text = tokens.join(''); + const byteArray = new Uint8Array([...text].map(c => this.byte_decoder[c])); + const decoded_text = this.text_decoder.decode(byteArray); + return decoded_text; + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + // TODO move to base class (like HF) + // tokens === filtered_tokens + + // To avoid mixing byte-level and unicode for byte-level BPT + // we need to build string separately for added tokens and byte-level tokens + // cf. https://github.com/huggingface/transformers/issues/1133 + const sub_texts = []; + let current_sub_text = []; + for (const token of tokens) { + // tokens sent here are already filtered, so we don't need to do this + // if (skip_special_tokens && this.all_special_ids.includes(token)) { + // continue; + // } + + if (this.added_tokens.find(x => x.content === token) !== undefined) { + if (current_sub_text.length > 0) { + sub_texts.push(this.convert_tokens_to_string(current_sub_text)); + current_sub_text = []; + } + sub_texts.push(token); + } else { + current_sub_text.push(token); + } + } + if (current_sub_text.length > 0) { + sub_texts.push(this.convert_tokens_to_string(current_sub_text)); + } + + // TODO add spaces_between_special_tokens and clean_up_tokenization_spaces options + + return sub_texts; + } +} + +/** + * The CTC (Connectionist Temporal Classification) decoder. + * See https://github.com/huggingface/tokenizers/blob/bb38f390a61883fc2f29d659af696f428d1cda6b/tokenizers/src/decoders/ctc.rs + */ +class CTCDecoder extends Decoder { + + constructor(config) { + super(config); + + this.pad_token = this.config.pad_token; + this.word_delimiter_token = this.config.word_delimiter_token; + this.cleanup = this.config.cleanup; + } + /** + * Converts a connectionist-temporal-classification (CTC) output tokens into a single string. + * @param {string[]} tokens Array of tokens to be decoded. + * @returns {string} The decoded string. + */ + convert_tokens_to_string(tokens) { + if (tokens.length === 0) return ''; + + // group same tokens into non-repeating tokens in CTC style decoding + const grouped_tokens = [tokens[0]]; + for (let i = 1; i < tokens.length; ++i) { + if (tokens[i] !== grouped_tokens.at(-1)) { + grouped_tokens.push(tokens[i]); + } + } + + // filter self.pad_token which is used as CTC-blank token + const filtered_tokens = grouped_tokens.filter(token => token !== this.pad_token); + + let text = filtered_tokens.join(''); + if (this.cleanup) { + // cleanup and replace delimiter token + text = clean_up_tokenization(text) + .replaceAll(this.word_delimiter_token, ' ') + .trim(); + } + return text; + } + + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + return [this.convert_tokens_to_string(tokens)]; + } +} + +/** + * Apply a sequence of decoders. + * @extends Decoder + */ +class DecoderSequence extends Decoder { + + /** + * Creates a new instance of DecoderSequence. + * @param {Object} config The configuration object. + * @param {Decoder[]} config.decoders The list of decoders to apply. + */ + constructor(config) { + super(config); + this.decoders = config.decoders.map(x => Decoder.fromConfig(x)); + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + // Use reduce to apply each decoder to the tokens + return this.decoders.reduce((toks, decoder) => { + return decoder.decode_chain(toks); + }, tokens); + } + +} + +class BPEDecoder extends Decoder { + constructor(config) { + super(config); + + this.suffix = this.config.suffix; + } + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + return tokens.map((token, i) => { + return token.replaceAll(this.suffix, (i === tokens.length - 1) ? '' : ' ') + }); + } +} + +// Custom decoder for VITS +class VitsDecoder extends Decoder { + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + let decoded = ''; + for (let i = 1; i < tokens.length; i += 2) { + decoded += tokens[i]; + } + return [decoded]; + } +} + + +/** + * This PreTokenizer replaces spaces with the given replacement character, adds a prefix space if requested, + * and returns a list of tokens. + * @extends PreTokenizer + */ +class MetaspacePreTokenizer extends PreTokenizer { + /** + * @param {Object} config The configuration object for the MetaspacePreTokenizer. + * @param {boolean} config.add_prefix_space Whether to add a prefix space to the first token. + * @param {string} config.replacement The character to replace spaces with. + * @param {string} [config.str_rep=config.replacement] An optional string representation of the replacement character. + * @param {'first'|'never'|'always'} [config.prepend_scheme='always'] The metaspace prepending scheme. + */ + constructor(config) { + super(); + + this.addPrefixSpace = config.add_prefix_space; + this.replacement = config.replacement; + this.strRep = config.str_rep || this.replacement; + this.prepend_scheme = config.prepend_scheme ?? 'always'; + } + + /** + * This method takes a string, replaces spaces with the replacement character, + * adds a prefix space if requested, and returns a new list of tokens. + * @param {string} text The text to pre-tokenize. + * @param {Object} [options] The options for the pre-tokenization. + * @param {number} [options.section_index] The index of the section to pre-tokenize. + * @returns {string[]} A new list of pre-tokenized tokens. + */ + pre_tokenize_text(text, { + section_index = undefined, + } = {}) { + + let normalized = text.replaceAll(' ', this.strRep); + + if ( + // We add a prefix space if: + // (1) The addPrefixSpace option is enabled and the normalized + // token does not already start with the replacement character. + (this.addPrefixSpace && !normalized.startsWith(this.replacement)) + + // and (2) either: + // (a) prepend_scheme is 'always' + // (b) prepend_scheme is 'first' and this is the first section + && ( + this.prepend_scheme === 'always' || + (this.prepend_scheme === 'first' && section_index === 0) + ) + ) { + normalized = this.strRep + normalized; + } + return [normalized]; + } +} + +/** + * MetaspaceDecoder class extends the Decoder class and decodes Metaspace tokenization. + * @extends Decoder + */ +class MetaspaceDecoder extends Decoder { + /** + * Constructs a new MetaspaceDecoder object. + * @param {Object} config The configuration object for the MetaspaceDecoder. + * @param {boolean} config.add_prefix_space Whether to add a prefix space to the decoded string. + * @param {string} config.replacement The string to replace spaces with. + */ + constructor(config) { + super(config); + + this.addPrefixSpace = config.add_prefix_space; + this.replacement = config.replacement; + } + + /** @type {Decoder['decode_chain']} */ + decode_chain(tokens) { + const result = []; + for (let i = 0; i < tokens.length; ++i) { + let normalized = tokens[i].replaceAll(this.replacement, ' '); + if (this.addPrefixSpace && i == 0 && normalized.startsWith(' ')) { + normalized = normalized.substring(1); + } + result.push(normalized); + } + return result; + } +} + +/** + * A normalizer that applies a precompiled charsmap. + * This is useful for applying complex normalizations in C++ and exposing them to JavaScript. + * @extends Normalizer + * @param {Object} config The configuration object for the Precompiled normalizer. + * @param {Object} config.precompiled_charsmap The precompiled charsmap object. + */ +class Precompiled extends Normalizer { + /** + * Create a new instance of Precompiled normalizer. + * @param {Object} config The configuration object. + * @param {any} config.precompiled_charsmap Precompiled chars mapping. + */ + constructor(config) { + super(config); + this.charsmap = config.precompiled_charsmap; + } + + /** + * Normalizes the given text by applying the precompiled charsmap. + * @param {string} text The text to normalize. + * @returns {string} The normalized text. + */ + normalize(text) { + // As stated in the sentencepiece normalization docs (https://github.com/google/sentencepiece/blob/master/doc/normalization.md#use-pre-defined-normalization-rule), + // there are 5 pre-defined normalization rules: + // 1. nmt_nfkc: NFKC normalization with some additional normalization around spaces. (default) + // 2. nfkc: original NFKC normalization. + // 3. nmt_nfkc_cf: nmt_nfkc + Unicode case folding (mostly lower casing) + // 4. nfkc_cf: nfkc + Unicode case folding. + // 5. identity: no normalization + // + // For now, we only implement the default (nmt_nfkc). + // See https://raw.githubusercontent.com/google/sentencepiece/master/data/nmt_nfkc.tsv for the full list of rules. + // TODO: detect when a different `this.charsmap` is used. + + text = text.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm, ''); // Remove control characters + text = text.replace(/[\u0009\u000A\u000C\u000D\u1680\u200B\u200C\u200E\u200F\u2028\u2029\u2581\uFEFF\uFFFD]/gm, '\u0020'); // Replace certain characters with a space + + if (text.includes('\uFF5E')) { + // To match the sentencepiece implementation 100%, we must handle a very strange edge-case. + // For some reason, the "Fullwidth Tilde" character (\uFF5E) should not be converted to the standard Tilde character (\u007E). + // However, NFKC normalization does do this conversion. As a result, we split the string on the Fullwidth Tilde character, + // perform NFKC normalization on each substring, and then join them back together with the Fullwidth Tilde character. + const parts = text.split('\uFF5E'); + text = parts.map(part => part.normalize('NFKC')).join('\uFF5E'); + } else { + text = text.normalize('NFKC'); + } + + return text; + } +} + +/** + * A pre-tokenizer that applies a sequence of pre-tokenizers to the input text. + * @extends PreTokenizer + */ +class PreTokenizerSequence extends PreTokenizer { + /** + * Creates an instance of PreTokenizerSequence. + * @param {Object} config The configuration object for the pre-tokenizer sequence. + * @param {Object[]} config.pretokenizers An array of pre-tokenizer configurations. + */ + constructor(config) { + super(); + this.tokenizers = config.pretokenizers.map(x => PreTokenizer.fromConfig(x)); + } + + /** + * Applies each pre-tokenizer in the sequence to the input text in turn. + * @param {string} text The text to pre-tokenize. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} The pre-tokenized text. + */ + pre_tokenize_text(text, options) { + // Use reduce to apply each tokenizer to the text + return this.tokenizers.reduce((preTokenizedText, tokenizer) => { + return tokenizer.pre_tokenize(preTokenizedText, options); + }, [text]); + } +} + +/** + * Splits on word boundaries (using the following regular expression: `\w+|[^\w\s]+`). + */ +class WhitespacePreTokenizer extends PreTokenizer { + /** + * Creates an instance of WhitespacePreTokenizer. + * @param {Object} config The configuration object for the pre-tokenizer. + */ + constructor(config) { + super(); + } + /** + * Pre-tokenizes the input text by splitting it on word boundaries. + * @param {string} text The text to be pre-tokenized. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens produced by splitting the input text on whitespace. + */ + pre_tokenize_text(text, options) { + return text.match(/\w+|[^\w\s]+/g) || []; + } +} + +/** + * Splits a string of text by whitespace characters into individual tokens. + * @extends PreTokenizer + */ +class WhitespaceSplit extends PreTokenizer { + /** + * Creates an instance of WhitespaceSplit. + * @param {Object} config The configuration object for the pre-tokenizer. + */ + constructor(config) { + super(); + } + /** + * Pre-tokenizes the input text by splitting it on whitespace characters. + * @param {string} text The text to be pre-tokenized. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens produced by splitting the input text on whitespace. + */ + pre_tokenize_text(text, options) { + return whitespace_split(text); + } +} + +// NOTE: `ReplacePreTokenizer` is custom (to support `BlenderbotSmallTokenizer`) +class ReplacePreTokenizer extends PreTokenizer { + /** + * @param {Object} config The configuration options for the pre-tokenizer. + * @param {Object} config.pattern The pattern used to split the text. Can be a string or a regex object. + * @param {string} config.content What to replace the pattern with. + */ + constructor(config) { + super(); + this.config = config; + this.pattern = createPattern(this.config.pattern); + this.content = this.config.content; + } + + /** + * Pre-tokenizes the input text by replacing certain characters. + * @param {string} text The text to be pre-tokenized. + * @param {Object} [options] Additional options for the pre-tokenization logic. + * @returns {string[]} An array of tokens produced by replacing certain characters. + */ + pre_tokenize_text(text, options) { + if (this.pattern === null) { + return [text]; + } + return [text.replaceAll(this.pattern, this.config.content)]; + } +} + +const SPECIAL_TOKEN_ATTRIBUTES = [ + 'bos_token', + 'eos_token', + 'unk_token', + 'sep_token', + 'pad_token', + 'cls_token', + 'mask_token', + // additional_special_tokens (TODO) +] + +/** + * + * Helper function for padding values of an object, which are each arrays. + * NOTE: No additional checks are made here for validity of arguments. + * @param {Record} item The input object. + * @param {number} length The length to pad to. + * @param {(key: string) => any} value_fn Determine the value to fill the array, based on its key. + * @param {'right'|'left'} side Which side to pad the array. + * @private + */ +function padHelper(item, length, value_fn, side) { + for (const key of Object.keys(item)) { + const diff = length - item[key].length; + const value = value_fn(key); + + const padData = new Array(diff).fill(value); + item[key] = side === 'right' + ? (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(item[key], padData) + : (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(padData, item[key]); + } +} + +/** + * Helper function for truncating values of an object, which are each arrays. + * NOTE: No additional checks are made here for validity of arguments. + * @param {Record} item The input object. + * @param {number} length The length to truncate to. + * @private + */ +function truncateHelper(item, length) { + // Setting .length to a lower value truncates the array in-place: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length + for (const key of Object.keys(item)) { + item[key].length = length; + } +} + + +class PreTrainedTokenizer extends _utils_core_js__WEBPACK_IMPORTED_MODULE_0__.Callable { + return_token_type_ids = false; + + _default_chat_template = `{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}`; + + /** + * Create a new PreTrainedTokenizer instance. + * @param {Object} tokenizerJSON The JSON of the tokenizer. + * @param {Object} tokenizerConfig The config of the tokenizer. + */ + constructor(tokenizerJSON, tokenizerConfig) { + super(); + + this._tokenizer_config = tokenizerConfig; + + // Construct parts of the tokenizer from the JSON + this.normalizer = Normalizer.fromConfig(tokenizerJSON.normalizer); + this.pre_tokenizer = PreTokenizer.fromConfig(tokenizerJSON.pre_tokenizer); + this.model = TokenizerModel.fromConfig(tokenizerJSON.model, tokenizerConfig); + this.post_processor = PostProcessor.fromConfig(tokenizerJSON.post_processor); + this.decoder = Decoder.fromConfig(tokenizerJSON.decoder); + + // Add added_tokens to model + this.special_tokens = []; + this.all_special_ids = []; + + /** @type {AddedToken[]} */ + this.added_tokens = []; + for (const addedToken of tokenizerJSON.added_tokens) { + const token = new AddedToken(addedToken); + this.added_tokens.push(token); + + this.model.tokens_to_ids.set(token.content, token.id); + this.model.vocab[token.id] = token.content; + + if (token.special) { + this.special_tokens.push(token.content); + this.all_special_ids.push(token.id); + } + } + + // Update additional_special_tokens + this.additional_special_tokens = tokenizerConfig.additional_special_tokens ?? []; + this.special_tokens.push(...this.additional_special_tokens); + this.special_tokens = [...new Set(this.special_tokens)]; // Remove duplicates + + if (this.decoder) { + // Slight hack, but it prevents code duplication: + this.decoder.added_tokens = this.added_tokens; + + // Another slight hack to add `end_of_word_suffix` (if present) to the decoder + // This is needed for cases where BPE model and ByteLevel decoder are used + // For more information, see https://github.com/xenova/transformers.js/issues/74 + // TODO: save this to the decoder when exporting? + this.decoder.end_of_word_suffix = this.model.end_of_word_suffix; + } + + + this.added_tokens_regex = this.added_tokens.length > 0 ? new RegExp( + this.added_tokens.map(x => `${x.lstrip ? '\\s*' : ''}(${(0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.escapeRegExp)(x.content)})${x.rstrip ? '\\s*' : ''}`).join('|') + ) : null; + + // Set mask token if present (otherwise will be undefined, which is fine) + this.mask_token = this.getToken('mask_token'); + this.mask_token_id = this.model.tokens_to_ids.get(this.mask_token); + + this.pad_token = this.getToken('pad_token', 'eos_token'); + this.pad_token_id = this.model.tokens_to_ids.get(this.pad_token); + + this.sep_token = this.getToken('sep_token'); + this.sep_token_id = this.model.tokens_to_ids.get(this.sep_token); + + this.unk_token = this.getToken('unk_token'); + this.unk_token_id = this.model.tokens_to_ids.get(this.unk_token); + + this.model_max_length = tokenizerConfig.model_max_length; + + /** @type {boolean} Whether or not to strip the text when tokenizing (removing excess spaces before and after the string). */ + this.remove_space = tokenizerConfig.remove_space; + + this.clean_up_tokenization_spaces = tokenizerConfig.clean_up_tokenization_spaces ?? true; + this.do_lowercase_and_remove_accent = tokenizerConfig.do_lowercase_and_remove_accent ?? false; + + // TODO allow user to change this + /** @type {'right'|'left'} */ + this.padding_side = 'right'; + + this.legacy = false; + + this.chat_template = tokenizerConfig.chat_template ?? null; + if (Array.isArray(this.chat_template)) { + // Chat templates are stored as lists of dicts with fixed key names, + // we reconstruct that into a single dict while loading them. + const chat_template = Object.create(null); + for (const { name, template } of this.chat_template) { + if (typeof name !== 'string' || typeof template !== 'string') { + throw new Error('Chat template must be a list of objects with "name" and "template" properties'); + } + chat_template[name] = template; + } + this.chat_template = chat_template; + } + this._compiled_template_cache = new Map(); + } + + /** + * Returns the value of the first matching key in the tokenizer config object. + * @param {...string} keys One or more keys to search for in the tokenizer config object. + * @returns {string|null} The value associated with the first matching key, or null if no match is found. + * @throws {Error} If an object is found for a matching key and its __type property is not "AddedToken". + */ + getToken(...keys) { + for (const key of keys) { + const item = this._tokenizer_config[key]; + + if (!item) continue; + + if (typeof item === 'object') { + if (item.__type === 'AddedToken') { + return item.content; + } else { + throw Error(`Unknown token: ${item}`); + } + } else { + return item; + } + } + return null; + } + + /** + * Loads a pre-trained tokenizer from the given `pretrained_model_name_or_path`. + * + * @param {string} pretrained_model_name_or_path The path to the pre-trained tokenizer. + * @param {PretrainedTokenizerOptions} options Additional options for loading the tokenizer. + * + * @throws {Error} Throws an error if the tokenizer.json or tokenizer_config.json files are not found in the `pretrained_model_name_or_path`. + * @returns {Promise} A new instance of the `PreTrainedTokenizer` class. + */ + static async from_pretrained(pretrained_model_name_or_path, { + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + legacy = null, + } = {}) { + + const info = await loadTokenizer(pretrained_model_name_or_path, { + progress_callback, + config, + cache_dir, + local_files_only, + revision, + legacy, + }) + + // @ts-ignore + return new this(...info); + } + + /** + * @typedef {number[]|number[][]|Tensor} BatchEncodingItem + * + * @typedef {Object} BatchEncoding Holds the output of the tokenizer's call function. + * @property {BatchEncodingItem} input_ids List of token ids to be fed to a model. + * @property {BatchEncodingItem} attention_mask List of indices specifying which tokens should be attended to by the model. + * @property {BatchEncodingItem} [token_type_ids] List of token type ids to be fed to a model. + */ + + /** + * Encode/tokenize the given text(s). + * @param {string|string[]} text The text to tokenize. + * @param {Object} options An optional object containing the following properties: + * @param {string|string[]} [options.text_pair=null] Optional second sequence to be encoded. If set, must be the same type as text. + * @param {boolean|'max_length'} [options.padding=false] Whether to pad the input sequences. + * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model. + * @param {boolean} [options.truncation=null] Whether to truncate the input sequences. + * @param {number} [options.max_length=null] Maximum length of the returned list and optionally padding length. + * @param {boolean} [options.return_tensor=true] Whether to return the results as Tensors or arrays. + * @returns {BatchEncoding} Object to be passed to the model. + */ + _call( + // Required positional arguments + text, + + // Optional keyword arguments + { + text_pair = null, + add_special_tokens = true, + padding = false, + truncation = null, + max_length = null, + return_tensor = true, // Different to HF + } = {}, + ) { + + const isBatched = Array.isArray(text); + + /** @type {EncodingSingle[]} */ + let encodedTokens; + + if (isBatched) { + if (text.length === 0) { + throw Error('text array must be non-empty') + } + + if (text_pair !== null) { + if (!Array.isArray(text_pair)) { + throw Error('text_pair must also be an array') + + } else if (text.length !== text_pair.length) { + throw Error('text and text_pair must have the same length') + } + + encodedTokens = text.map( + (t, i) => this._encode_plus(t, text_pair[i], { add_special_tokens }) + ) + + } else { + encodedTokens = text.map(x => this._encode_plus(x, null, { add_special_tokens })); + } + + } else { + if (text === null) { + throw Error('text may not be null') + } + + if (Array.isArray(text_pair)) { + throw Error('When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).') + } + + // For single input, we just wrap in an array, and then unwrap later. + encodedTokens = [this._encode_plus(text, text_pair, { add_special_tokens })]; + } + // At this point, tokens is batched: [batch_size, tokens] + // However, array may be jagged. So, we pad to max_length + + if (max_length === null) { + if (padding === 'max_length') { + max_length = this.model_max_length; + } else { + // Calculate max length from sequences + max_length = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(encodedTokens.map(x => x.input_ids.length))[0]; + } + } else { + if (!truncation) { + console.warn(`Truncation was not explicitly activated but \`max_length\` is provided a specific value, please use \`truncation=true\` to explicitly truncate examples to max length.`) + } + } + + // Ensure it is less than model max length + max_length = Math.min(max_length, this.model_max_length) + + if (padding || truncation) { + + // Perform padding and/or truncation + for (let i = 0; i < encodedTokens.length; ++i) { + if (encodedTokens[i].input_ids.length === max_length) { + continue; + + } else if (encodedTokens[i].input_ids.length > max_length) { + // possibly truncate + if (truncation) { + truncateHelper(encodedTokens[i], max_length); + } + + } else { // t.length < max_length + // possibly pad + if (padding) { + padHelper( + encodedTokens[i], + max_length, + key => key === 'input_ids' ? this.pad_token_id : 0, + this.padding_side + ); + } + } + } + } + + const result = {}; + + if (return_tensor) { + if (!(padding && truncation)) { + // Not, guaranteed that all items have same length, so + // we perform additional check + + if ( + encodedTokens.some(x => { + for (const key of Object.keys(x)) { + if (x[key].length !== encodedTokens[0][key]?.length) { + return true; + } + } + return false; + }) + ) { + throw Error( + "Unable to create tensor, you should probably activate truncation and/or padding " + + "with 'padding=true' and 'truncation=true' to have batched tensors with the same length." + ) + } + } + + // Now we actually convert to tensor + // NOTE: In the same way as the python library, we return a batched tensor, regardless of + // whether we have a single input or multiple inputs. + const dims = [encodedTokens.length, encodedTokens[0].input_ids.length]; + + for (const key of Object.keys(encodedTokens[0])) { + result[key] = new _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor('int64', + BigInt64Array.from(encodedTokens.flatMap(x => x[key]).map(BigInt)), + dims + ); + } + + } else { + for (const key of Object.keys(encodedTokens[0])) { + result[key] = encodedTokens.map(x => x[key]); + } + + // If not returning a tensor, we match the input type + if (!isBatched) { + // Input was not batched, so we unwrap + for (const key of Object.keys(result)) { + result[key] = result[key][0]; + } + } + } + + return /** @type {BatchEncoding} */(result); + } + + /** + * Encodes a single text using the preprocessor pipeline of the tokenizer. + * + * @param {string|null} text The text to encode. + * @returns {string[]|null} The encoded tokens. + */ + _encode_text(text) { + if (text === null) return null; + + // Actual function which does encoding, for a single text + // First, we take care of special tokens. Needed to avoid issues arising from + // normalization and/or pretokenization (which may not preserve special tokens) + const sections = this.added_tokens_regex ? text.split(this.added_tokens_regex).filter(x => x) : [text]; + + const tokens = sections.map((x, section_index) => { + const addedToken = this.added_tokens.find(t => t.content === x); + if (addedToken !== undefined) { + // Ignore added tokens + return x + } else { + if (this.remove_space === true) { + x = x.trim().split(/\s+/).join(' '); + } + if (this.do_lowercase_and_remove_accent) { + x = lowercase_and_remove_accent(x); + } + + if (this.normalizer !== null) { + x = this.normalizer(x); + } + + // If, after normalization, this section is empty (e.g., trimming whitespace), + // we return an empty array + if (x.length === 0) { + return []; + } + + const sectionTokens = (this.pre_tokenizer !== null) ? this.pre_tokenizer(x, { + section_index, + }) : [x]; + + const tokens = this.model(sectionTokens); + + return tokens; + } + }).flat(); + + return tokens; + } + + /** + * Encodes a single text or a pair of texts using the model's tokenizer. + * + * @param {string} text The text to encode. + * @param {string|null} text_pair The optional second text to encode. + * @param {Object} options An optional object containing the following properties: + * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model. + * @returns {EncodingSingle} An object containing the encoded text. + * @private + */ + _encode_plus(text, text_pair = null, { + add_special_tokens = true, + } = {}) { + // Function called by users to encode possibly multiple texts + const tokens = this._encode_text(text); + const tokens2 = this._encode_text(text_pair); + + const combinedTokens = this.post_processor + ? this.post_processor(tokens, tokens2, { add_special_tokens }) + : { tokens: (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(tokens ?? [], tokens2 ?? []) }; + + const input_ids = this.model.convert_tokens_to_ids(combinedTokens.tokens); + + const result = { + input_ids, + attention_mask: new Array(input_ids.length).fill(1), + } + if (this.return_token_type_ids && combinedTokens.token_type_ids) { + result.token_type_ids = combinedTokens.token_type_ids; + } + return result; + } + + /** + * Encodes a single text or a pair of texts using the model's tokenizer. + * + * @param {string} text The text to encode. + * @param {string|null} text_pair The optional second text to encode. + * @param {Object} options An optional object containing the following properties: + * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model. + * @returns {number[]} An array of token IDs representing the encoded text(s). + */ + encode(text, text_pair = null, { + add_special_tokens = true, + } = {}) { + const { input_ids } = this._encode_plus(text, text_pair, { + add_special_tokens, + }); + return input_ids; + } + + /** + * Decode a batch of tokenized sequences. + * @param {number[][]|Tensor} batch List/Tensor of tokenized input sequences. + * @param {Object} decode_args (Optional) Object with decoding arguments. + * @returns {string[]} List of decoded sequences. + */ + batch_decode(batch, decode_args = {}) { + if (batch instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor) { + batch = batch.tolist(); + } + return batch.map(x => this.decode(x, decode_args)); + } + + /** + * Decodes a sequence of token IDs back to a string. + * + * @param {number[]|Tensor} token_ids List/Tensor of token IDs to decode. + * @param {Object} [decode_args={}] + * @param {boolean} [decode_args.skip_special_tokens=false] If true, special tokens are removed from the output string. + * @param {boolean} [decode_args.clean_up_tokenization_spaces=true] If true, spaces before punctuations and abbreviated forms are removed. + * + * @returns {string} The decoded string. + * @throws {Error} If `token_ids` is not a non-empty array of integers. + */ + decode( + token_ids, + decode_args = {}, + ) { + if (token_ids instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor) { + token_ids = prepareTensorForDecode(token_ids); + } + + if (!Array.isArray(token_ids) || token_ids.length === 0 || !(0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.isIntegralNumber)(token_ids[0])) { + throw Error("token_ids must be a non-empty array of integers."); + } + + return this.decode_single(token_ids, decode_args) + } + + /** + * Decode a single list of token ids to a string. + * @param {number[]} token_ids List of token ids to decode + * @param {Object} decode_args Optional arguments for decoding + * @param {boolean} [decode_args.skip_special_tokens=false] Whether to skip special tokens during decoding + * @param {boolean} [decode_args.clean_up_tokenization_spaces=null] Whether to clean up tokenization spaces during decoding. + * If null, the value is set to `this.decoder.cleanup` if it exists, falling back to `this.clean_up_tokenization_spaces` if it exists, falling back to `true`. + * @returns {string} The decoded string + */ + decode_single( + token_ids, + { + skip_special_tokens = false, + clean_up_tokenization_spaces = null, + } + ) { + let tokens = this.model.convert_ids_to_tokens(token_ids); + if (skip_special_tokens) { + tokens = tokens.filter(x => !this.special_tokens.includes(x)); + } + + // If `this.decoder` is null, we just join tokens with a space: + // https://github.com/huggingface/tokenizers/blob/8edec536a737cb04494b454805be16c020abb14f/tokenizers/src/tokenizer/mod.rs#L835 + /** @type {string} */ + let decoded = this.decoder ? this.decoder(tokens) : tokens.join(' '); + + // Slight hack, but prevents having to pass `skip_special_tokens` to + // each call to `decode`, which would lead to code duplication. + if (this.decoder && this.decoder.end_of_word_suffix) { + decoded = decoded.replaceAll(this.decoder.end_of_word_suffix, ' '); + if (skip_special_tokens) { + decoded = decoded.trim(); + } + } + + if (clean_up_tokenization_spaces ?? this.clean_up_tokenization_spaces) { + decoded = clean_up_tokenization(decoded); + } + + return decoded; + } + + get default_chat_template() { + if (!this._warned_about_chat_template) { + console.warn( + "No chat template is defined for this tokenizer - using a default chat template " + + "that implements the ChatML format. If the default is not appropriate for " + + "your model, please set `tokenizer.chat_template` to an appropriate template. " + + "See https://huggingface.co/docs/transformers/main/chat_templating for more information." + ) + this._warned_about_chat_template = true; // TODO move to logger.warning_once() + } + + return this._default_chat_template; + } + + /** + * @typedef {Object} Message + * @property {string} role The role of the message (e.g., "user" or "assistant" or "system"). + * @property {string} content The content of the message. + */ + + /** + * Converts a list of message objects with `"role"` and `"content"` keys to a list of token + * ids. This method is intended for use with chat models, and will read the tokenizer's chat_template attribute to + * determine the format and control tokens to use when converting. When chat_template is None, it will fall back + * to the default_chat_template specified at the class level. + * + * See [here](https://huggingface.co/docs/transformers/chat_templating) for more information. + * + * **Example:** Applying a chat template to a conversation. + * + * ```javascript + * import { AutoTokenizer } from "@xenova/transformers"; + * + * const tokenizer = await AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1"); + * + * const chat = [ + * { "role": "user", "content": "Hello, how are you?" }, + * { "role": "assistant", "content": "I'm doing great. How can I help you today?" }, + * { "role": "user", "content": "I'd like to show off how chat templating works!" }, + * ] + * + * const text = tokenizer.apply_chat_template(chat, { tokenize: false }); + * // "[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today? [INST] I'd like to show off how chat templating works! [/INST]" + * + * const input_ids = tokenizer.apply_chat_template(chat, { tokenize: true, return_tensor: false }); + * // [1, 733, 16289, 28793, 22557, 28725, 910, 460, 368, 28804, 733, 28748, 16289, 28793, 28737, 28742, 28719, 2548, 1598, 28723, 1602, 541, 315, 1316, 368, 3154, 28804, 2, 28705, 733, 16289, 28793, 315, 28742, 28715, 737, 298, 1347, 805, 910, 10706, 5752, 1077, 3791, 28808, 733, 28748, 16289, 28793] + * ``` + * + * @param {Message[]} conversation A list of message objects with `"role"` and `"content"` keys. + * @param {Object} options An optional object containing the following properties: + * @param {string} [options.chat_template=null] A Jinja template to use for this conversion. If + * this is not passed, the model's default chat template will be used instead. + * @param {boolean} [options.add_generation_prompt=false] Whether to end the prompt with the token(s) that indicate + * the start of an assistant message. This is useful when you want to generate a response from the model. + * Note that this argument will be passed to the chat template, and so it must be supported in the + * template for this argument to have any effect. + * @param {boolean} [options.tokenize=true] Whether to tokenize the output. If false, the output will be a string. + * @param {boolean} [options.padding=false] Whether to pad sequences to the maximum length. Has no effect if tokenize is false. + * @param {boolean} [options.truncation=false] Whether to truncate sequences to the maximum length. Has no effect if tokenize is false. + * @param {number} [options.max_length=null] Maximum length (in tokens) to use for padding or truncation. Has no effect if tokenize is false. + * If not specified, the tokenizer's `max_length` attribute will be used as a default. + * @param {boolean} [options.return_tensor=true] Whether to return the output as a Tensor or an Array. Has no effect if tokenize is false. + * @param {Object} [options.tokenizer_kwargs={}] Additional options to pass to the tokenizer. + * @returns {string | Tensor | number[]| number[][]} The tokenized output. + */ + apply_chat_template(conversation, { + chat_template = null, + add_generation_prompt = false, + tokenize = true, + padding = false, + truncation = false, + max_length = null, + return_tensor = true, + tokenizer_kwargs = {}, + ...kwargs + } = {}) { + + // First, handle the cases when the model has a dict of multiple templates + if ( + (this.chat_template && typeof this.chat_template === 'object') || + (this.chat_template === null && this.default_chat_template && typeof this.default_chat_template === 'object') + ) { + const template_dict = this.chat_template ?? this.default_chat_template; // Guaranteed to be a non-null object + + if (chat_template !== null && Object.hasOwn(template_dict, chat_template)) { + // The user can pass the name of a template to the chat template argument instead of an entire template + chat_template = template_dict[chat_template]; + } else if (chat_template === null && 'default' in template_dict) { + chat_template = template_dict['default']; + } else if (chat_template === null) { + throw Error( + `This model has multiple chat templates with no default specified! Please either pass a chat ` + + `template or the name of the template you wish to use to the 'chat_template' argument. Available ` + + `template names are ${Object.keys(template_dict).sort()}.` + ) + } + } else { + // These are the cases when the model has a single template + // priority: `chat_template` argument > `tokenizer.chat_template` > `tokenizer.default_chat_template + chat_template ??= this.chat_template ?? this.default_chat_template; + } + if (typeof chat_template !== 'string') { + throw Error(`chat_template must be a string, but got ${typeof chat_template}`); + } + + // Compilation function uses a cache to avoid recompiling the same template + let compiledTemplate = this._compiled_template_cache.get(chat_template); + if (compiledTemplate === undefined) { + compiledTemplate = new _huggingface_jinja__WEBPACK_IMPORTED_MODULE_5__.Template(chat_template); + this._compiled_template_cache.set(chat_template, compiledTemplate); + } + + const special_tokens_map = Object.create(null); + for (const key of SPECIAL_TOKEN_ATTRIBUTES) { + const value = this.getToken(key); + if (value) { + special_tokens_map[key] = value; + } + } + + const rendered = compiledTemplate.render({ + messages: conversation, + add_generation_prompt: add_generation_prompt, + + ...special_tokens_map, + ...kwargs, + }); + + if (tokenize) { + return this._call(rendered, { + add_special_tokens: false, + padding, + truncation, + max_length, + return_tensor, + ...tokenizer_kwargs, + }).input_ids; + } + + return rendered; + } +} + +/** + * BertTokenizer is a class used to tokenize text for BERT models. + * @extends PreTrainedTokenizer + */ +class BertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +/** + * Albert tokenizer + * @extends PreTrainedTokenizer + */ +class AlbertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class MobileBertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class SqueezeBertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class DebertaTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class DebertaV2Tokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class HerbertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class ConvBertTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class RoFormerTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} +class DistilBertTokenizer extends PreTrainedTokenizer { } +class CamembertTokenizer extends PreTrainedTokenizer { } +class XLMTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; + + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.') + } +} +class ElectraTokenizer extends PreTrainedTokenizer { + return_token_type_ids = true; +} + +class T5Tokenizer extends PreTrainedTokenizer { } +class GPT2Tokenizer extends PreTrainedTokenizer { + _default_chat_template = `{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}` +} +class BartTokenizer extends PreTrainedTokenizer { } +class MBartTokenizer extends PreTrainedTokenizer { + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + + this.languageRegex = /^[a-z]{2}_[A-Z]{2}$/; + this.language_codes = this.special_tokens.filter(x => this.languageRegex.test(x)); + this.lang_to_token = x => x; // Identity function + } + + /** + * Helper function to build translation inputs for an `MBartTokenizer`. + * @param {string|string[]} raw_inputs The text to tokenize. + * @param {Object} tokenizer_options Options to be sent to the tokenizer + * @param {Object} generate_kwargs Generation options. + * @returns {Object} Object to be passed to the model. + */ + _build_translation_inputs(raw_inputs, tokenizer_options, generate_kwargs) { + return _build_translation_inputs(this, raw_inputs, tokenizer_options, generate_kwargs); + } +} +class MBart50Tokenizer extends MBartTokenizer { } // NOTE: extends MBartTokenizer + +class RobertaTokenizer extends PreTrainedTokenizer { } + +class BloomTokenizer extends GPT2Tokenizer { // NOTE: `GPT2Tokenizer` to get the correct chat template + + constructor(tokenizerJSON, tokenizerConfig) { + // Override the default (invalid) regex of the pretokenizer. + // For more information, see https://github.com/xenova/transformers.js/issues/94 + const splitChars = '.,!?\u2026\u3002\uff0c\u3001\u0964\u06d4\u060c'; + const patternObject = tokenizerJSON.pre_tokenizer?.pretokenizers[0]?.pattern; + if (patternObject && patternObject.Regex === ` ?[^(\\s|[${splitChars}])]+`) { + patternObject.Regex = ` ?[^\\s${splitChars}]+`; + } + super(tokenizerJSON, tokenizerConfig); + } +} + +const SPIECE_UNDERLINE = "▁"; + +class LlamaTokenizer extends PreTrainedTokenizer { + _default_chat_template = `{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\n' + system_message + '\n<>\n\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<>\n' + content.strip() + '\n<>\n\n' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}` + + DEFAULT_SYSTEM_PROMPT = + "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your " + + "answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure " + + "that your responses are socially unbiased and positive in nature.\n\n" + + "If a question does not make any sense, or is not factually coherent, explain why instead of answering something not " + + "correct. If you don't know the answer to a question, please don't share false information." + + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + this.use_default_system_prompt = tokenizerConfig.use_default_system_prompt ?? false; + + this.legacy = tokenizerConfig.legacy ?? true; + if (!this.legacy) { + // See https://github.com/huggingface/transformers/pull/24565 for more information + this.normalizer = null; + this.pre_tokenizer = new MetaspacePreTokenizer({ + replacement: SPIECE_UNDERLINE, + add_prefix_space: true, + prepend_scheme: "first", + }); + } + } + + /** + * Helper function to handle legacy encoding of SPM tokenizers. + * Adapted from https://github.com/huggingface/transformers/blob/e6dcf8abd6f65bb4b6dfc1831b20d9ba49ce00e2/src/transformers/models/t5/tokenization_t5.py#L374-L387 + * @param {string} text The text to encode. + * @returns {string[]} The encoded tokens. + */ + _encode_text(text) { + if (text === null) return null; + + if (this.legacy || text.length === 0) { + return super._encode_text(text); + } + + let tokens = super._encode_text(SPIECE_UNDERLINE + text.replaceAll(SPIECE_UNDERLINE, " ")); + if (tokens.length > 1 && tokens[0] === SPIECE_UNDERLINE && this.special_tokens.includes(tokens[1])) { + tokens = tokens.slice(1); + } + return tokens; + } + + get default_chat_template() { + return super.default_chat_template + .replaceAll('USE_DEFAULT_PROMPT', this.use_default_system_prompt ? 'true' : 'false') + .replaceAll('DEFAULT_SYSTEM_MESSAGE', this.DEFAULT_SYSTEM_PROMPT.replaceAll("\n", "\\n").replaceAll("'", "\\'")); + } +} +class CodeLlamaTokenizer extends LlamaTokenizer { } // NOTE: `LlamaTokenizer` to get the correct chat template + +class XLMRobertaTokenizer extends PreTrainedTokenizer { } +class MPNetTokenizer extends PreTrainedTokenizer { } + +class FalconTokenizer extends PreTrainedTokenizer { } + +class GPTNeoXTokenizer extends PreTrainedTokenizer { } + +class EsmTokenizer extends PreTrainedTokenizer { } + +class Qwen2Tokenizer extends PreTrainedTokenizer { } + +class GemmaTokenizer extends PreTrainedTokenizer { + _default_chat_template = "{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '' + role + '\n' + message['content'] | trim + '\n' }}{% endfor %}{% if add_generation_prompt %}{{'model\n'}}{% endif %}" +} + +class Grok1Tokenizer extends PreTrainedTokenizer { } + +/** + * Helper function to build translation inputs for an `NllbTokenizer` or `M2M100Tokenizer`. + * @param {PreTrainedTokenizer} self The tokenizer instance. + * @param {string|string[]} raw_inputs The text to tokenize. + * @param {Object} tokenizer_options Options to be sent to the tokenizer + * @param {Object} generate_kwargs Generation options. + * @returns {Object} Object to be passed to the model. + * @private + */ +function _build_translation_inputs(self, raw_inputs, tokenizer_options, generate_kwargs) { + if (!('language_codes' in self) || !Array.isArray(self.language_codes)) { + throw new Error('Tokenizer must have `language_codes` attribute set and it should be an array of language ids.') + } + if (!('languageRegex' in self) || !(self.languageRegex instanceof RegExp)) { + throw new Error('Tokenizer must have `languageRegex` attribute set and it should be a regular expression.') + } + if (!('lang_to_token' in self) || typeof self.lang_to_token !== 'function') { + throw new Error('Tokenizer must have `lang_to_token` attribute set and it should be a function.') + } + const src_lang_token = generate_kwargs.src_lang; + const tgt_lang_token = generate_kwargs.tgt_lang; + + // Check that the target language is valid: + if (!self.language_codes.includes(tgt_lang_token)) { + throw new Error(`Target language code "${tgt_lang_token}" is not valid. Must be one of: {${self.language_codes.join(', ')}}`); + } + + // Allow `src_lang` to be optional. If not set, we'll use the tokenizer's default. + if (src_lang_token !== undefined) { + // Check that the source language is valid: + if (!self.language_codes.includes(src_lang_token)) { + throw new Error(`Source language code "${src_lang_token}" is not valid. Must be one of: {${self.language_codes.join(', ')}}`); + } + + // In the same way as the Python library, we override the post-processor + // to force the source language to be first: + for (const item of self.post_processor.config.single) { + if ('SpecialToken' in item && self.languageRegex.test(item.SpecialToken.id)) { + item.SpecialToken.id = self.lang_to_token(src_lang_token); + break; + } + } + // TODO: Do the same for pair? + } + + // Override the `forced_bos_token_id` to force the correct language + generate_kwargs.forced_bos_token_id = self.model.convert_tokens_to_ids([self.lang_to_token(tgt_lang_token)])[0]; + + return self._call(raw_inputs, tokenizer_options); +} + +/** + * The NllbTokenizer class is used to tokenize text for NLLB ("No Language Left Behind") models. + * + * No Language Left Behind (NLLB) is a first-of-its-kind, AI breakthrough project + * that open-sources models capable of delivering high-quality translations directly + * between any pair of 200+ languages — including low-resource languages like Asturian, + * Luganda, Urdu and more. It aims to help people communicate with anyone, anywhere, + * regardless of their language preferences. For more information, check out their + * [paper](https://arxiv.org/abs/2207.04672). + * + * For a list of supported languages (along with their language codes), + * @see {@link https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200} + */ +class NllbTokenizer extends PreTrainedTokenizer { + + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + + this.languageRegex = /^[a-z]{3}_[A-Z][a-z]{3}$/; + this.language_codes = this.special_tokens.filter(x => this.languageRegex.test(x)); + this.lang_to_token = x => x; // Identity function + } + + /** + * Helper function to build translation inputs for an `NllbTokenizer`. + * @param {string|string[]} raw_inputs The text to tokenize. + * @param {Object} tokenizer_options Options to be sent to the tokenizer + * @param {Object} generate_kwargs Generation options. + * @returns {Object} Object to be passed to the model. + */ + _build_translation_inputs(raw_inputs, tokenizer_options, generate_kwargs) { + return _build_translation_inputs(this, raw_inputs, tokenizer_options, generate_kwargs); + } +} + +/** + * The M2M100Tokenizer class is used to tokenize text for M2M100 ("Many-to-Many") models. + * + * M2M100 is a multilingual encoder-decoder (seq-to-seq) model trained for Many-to-Many + * multilingual translation. It was introduced in this [paper](https://arxiv.org/abs/2010.11125) + * and first released in [this](https://github.com/pytorch/fairseq/tree/master/examples/m2m_100) repository. + * + * For a list of supported languages (along with their language codes), + * @see {@link https://huggingface.co/facebook/m2m100_418M#languages-covered} + */ +class M2M100Tokenizer extends PreTrainedTokenizer { + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + + this.languageRegex = /^__[a-z]{2,3}__$/; + this.language_codes = this.special_tokens + .filter(x => this.languageRegex.test(x)) + .map(x => x.slice(2, -2)); + this.lang_to_token = x => `__${x}__`; + } + + /** + * Helper function to build translation inputs for an `M2M100Tokenizer`. + * @param {string|string[]} raw_inputs The text to tokenize. + * @param {Object} tokenizer_options Options to be sent to the tokenizer + * @param {Object} generate_kwargs Generation options. + * @returns {Object} Object to be passed to the model. + */ + _build_translation_inputs(raw_inputs, tokenizer_options, generate_kwargs) { + return _build_translation_inputs(this, raw_inputs, tokenizer_options, generate_kwargs); + } +} + + +const WHISPER_LANGUAGES = [ + ["en", "english"], + ["zh", "chinese"], + ["de", "german"], + ["es", "spanish"], + ["ru", "russian"], + ["ko", "korean"], + ["fr", "french"], + ["ja", "japanese"], + ["pt", "portuguese"], + ["tr", "turkish"], + ["pl", "polish"], + ["ca", "catalan"], + ["nl", "dutch"], + ["ar", "arabic"], + ["sv", "swedish"], + ["it", "italian"], + ["id", "indonesian"], + ["hi", "hindi"], + ["fi", "finnish"], + ["vi", "vietnamese"], + ["he", "hebrew"], + ["uk", "ukrainian"], + ["el", "greek"], + ["ms", "malay"], + ["cs", "czech"], + ["ro", "romanian"], + ["da", "danish"], + ["hu", "hungarian"], + ["ta", "tamil"], + ["no", "norwegian"], + ["th", "thai"], + ["ur", "urdu"], + ["hr", "croatian"], + ["bg", "bulgarian"], + ["lt", "lithuanian"], + ["la", "latin"], + ["mi", "maori"], + ["ml", "malayalam"], + ["cy", "welsh"], + ["sk", "slovak"], + ["te", "telugu"], + ["fa", "persian"], + ["lv", "latvian"], + ["bn", "bengali"], + ["sr", "serbian"], + ["az", "azerbaijani"], + ["sl", "slovenian"], + ["kn", "kannada"], + ["et", "estonian"], + ["mk", "macedonian"], + ["br", "breton"], + ["eu", "basque"], + ["is", "icelandic"], + ["hy", "armenian"], + ["ne", "nepali"], + ["mn", "mongolian"], + ["bs", "bosnian"], + ["kk", "kazakh"], + ["sq", "albanian"], + ["sw", "swahili"], + ["gl", "galician"], + ["mr", "marathi"], + ["pa", "punjabi"], + ["si", "sinhala"], + ["km", "khmer"], + ["sn", "shona"], + ["yo", "yoruba"], + ["so", "somali"], + ["af", "afrikaans"], + ["oc", "occitan"], + ["ka", "georgian"], + ["be", "belarusian"], + ["tg", "tajik"], + ["sd", "sindhi"], + ["gu", "gujarati"], + ["am", "amharic"], + ["yi", "yiddish"], + ["lo", "lao"], + ["uz", "uzbek"], + ["fo", "faroese"], + ["ht", "haitian creole"], + ["ps", "pashto"], + ["tk", "turkmen"], + ["nn", "nynorsk"], + ["mt", "maltese"], + ["sa", "sanskrit"], + ["lb", "luxembourgish"], + ["my", "myanmar"], + ["bo", "tibetan"], + ["tl", "tagalog"], + ["mg", "malagasy"], + ["as", "assamese"], + ["tt", "tatar"], + ["haw", "hawaiian"], + ["ln", "lingala"], + ["ha", "hausa"], + ["ba", "bashkir"], + ["jw", "javanese"], + ["su", "sundanese"], +] + +// @ts-ignore +const WHISPER_LANGUAGE_MAPPING = new Map(WHISPER_LANGUAGES); +// @ts-ignore +const WHISPER_TO_LANGUAGE_CODE_MAPPING = new Map([ + ...WHISPER_LANGUAGES.map(([k, v]) => [v, k]), + ...[ + ["burmese", "my"], + ["valencian", "ca"], + ["flemish", "nl"], + ["haitian", "ht"], + ["letzeburgesch", "lb"], + ["pushto", "ps"], + ["panjabi", "pa"], + ["moldavian", "ro"], + ["moldovan", "ro"], + ["sinhalese", "si"], + ["castilian", "es"], + ] +]); + +/** + * WhisperTokenizer tokenizer + * @extends PreTrainedTokenizer + */ +class WhisperTokenizer extends PreTrainedTokenizer { + _default_chat_template = `{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}`; + + /** + * Decodes automatic speech recognition (ASR) sequences. + * @param {Array<{tokens: number[], token_timestamps?: number[], stride: number[]}>} sequences The sequences to decode. + * @param {Object} options The options to use for decoding. + * @returns {Array, text: string}>}>} The decoded sequences. + */ + _decode_asr(sequences, { + return_timestamps = false, + return_language = false, + time_precision = null, + force_full_sequences = true + } = {}) { + // Set force_full_sequences=false if you want streaming + // TODO add support for `return_language` + + // Internal method meant to only be used by asr pipeline. + // Handles all the little quirks specific to whisper to handle + // the various options not allowed in other seq2seq models + + // =========== Overview ============ + // - iterate over all outputs + // - all tokens within output + // - Each token can be + // - language token + // - special token + // - timestamp token + // - text token + // - We accumulate the text tokens. + // - We split on end timestamps + // - Lots of complexity comes from stride and timestamps + + if (time_precision === null) { + throw Error("Must specify time_precision") + } + let last_language = null; + + const returnWordTimestamps = return_timestamps === "word"; + + function new_chunk() { + return { "language": last_language, "timestamp": [null, null], "text": "" }; + } + + // Welcome to the state machine! + const chunks = []; + let chunk = new_chunk(); + let time_offset = 0.0; + const timestamp_begin = this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0] + 1; + + let previous_tokens = []; + let previous_token_timestamps = []; + + let skip = false; + let right_stride_start = null; + + + const all_special_ids = new Set(this.all_special_ids); + + for (const output of sequences) { + // NOTE: python version has batches, so it uses [0] + const token_ids = output.tokens; + const token_timestamps = returnWordTimestamps ? output.token_timestamps : null; + + // These keep track of timestamps within strides, which need + // to be skipped and resolve all tokens in a single chunk. + let last_timestamp = null; + let first_timestamp = timestamp_begin; + + if ("stride" in output) { + const [chunk_len, stride_left, stride_right] = output.stride; + + // Offset the timings to account for the other `model_outputs`. + time_offset -= stride_left; + right_stride_start = chunk_len - stride_right; + + // Keeping track of timestamps within strides + // We're going to NOT split on those, and delay until we're + // out of BOTH stride. Otherwise lots of issues occur and + // corner cases + if (stride_left) { + first_timestamp = stride_left / time_precision + timestamp_begin; + } + + if (stride_right) { + for (let i = token_ids.length - 1; i >= 0; --i) { + const token = token_ids[i]; + if (token >= timestamp_begin) { + // There can be several token in the right stride + // But the last one is ALWAYS going to be skipped + if (last_timestamp !== null && (token - timestamp_begin) * time_precision < right_stride_start) { + break; + } + last_timestamp = token; + } + } + } + } + + let current_tokens = []; + let current_token_timestamps = []; + + // - all tokens within output + for (let i = 0; i < token_ids.length; ++i) { + const token = token_ids[i]; + // 4 possible states for each token + // - 1/ Language code + // - 2/ all other special tokens (which we ignore) + // - 3/ Timestamp + // - 4/ Regular text + + if (all_special_ids.has(token)) { + const text = this.decode([token]); + const language = WHISPER_LANGUAGE_MAPPING.get(text.slice(2, -2)); + + if (language !== undefined) { + // 1/ Indeed some language + // TODO Handle when language is different from the previous + // one, and we cannot use timestamped tokens to create chunks + if (last_language !== null && language !== last_language && !return_timestamps) { + previous_tokens.push(current_tokens); + const resolved_tokens = this.findLongestCommonSequence(previous_tokens)[0]; + const resolved_text = this.decode(resolved_tokens); + chunk.text = resolved_text; + chunks.push(chunk); + + // Flush all our temporary context + previous_tokens = []; + current_tokens = []; + chunk = new_chunk(); + } + + last_language = chunk.language = language; + } else { + // 2/ This is a regular special token, ignoring it + } + } else if (token >= timestamp_begin) { + // 3/ Timestamp token + const time = (token - timestamp_begin) * time_precision + time_offset; + const rounded_time = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.round)(time, 2); + + if (last_timestamp !== null && token >= last_timestamp) { + // Whisper outputted a timestamp token, but it falls within + // our stride, so we're going to skip it for the time being + // and resolve this later + // Skip is necessary because timestamp tokens always come + // by pair, so we need to skip the next one too (which would mark the start of another chunk). + skip = true; + } else if (skip || (previous_tokens.length > 0 && token < first_timestamp)) { + skip = false; + } else if (chunk.timestamp[0] === null) { + chunk.timestamp[0] = rounded_time; + } else { + // This is the end of the timestamp chunk + if (rounded_time === chunk.timestamp[0]) { + // This is a bug in timestamp token output + // where we're taking the duplicate token + // as a stop where it should be a start. + // This is an issue in the underlying model output + // Let's just skip it so it becomes de-factor a start agin + } else { + chunk.timestamp[1] = rounded_time; + + // Handling merges + previous_tokens.push(current_tokens) + + if (returnWordTimestamps) { + previous_token_timestamps.push(current_token_timestamps); + } + const [resolved_tokens, resolved_token_timestamps] = this.findLongestCommonSequence( + previous_tokens, previous_token_timestamps + ) + + const resolved_text = this.decode(resolved_tokens) + chunk.text = resolved_text + + if (returnWordTimestamps) { + chunk.words = this.collateWordTimestamps( + resolved_tokens, resolved_token_timestamps, last_language, + ) + } + + chunks.push(chunk) + + // Flush all our temporary context + previous_tokens = [] + current_tokens = [] + previous_token_timestamps = [] + current_token_timestamps = [] + chunk = new_chunk() + } + } + + } else { + // 4/ Regular token + // We just append to the list of all tokens so we can handle + // merges later and decode into text. + current_tokens.push(token) + + if (returnWordTimestamps) { + let start_time = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.round)(token_timestamps[i] + time_offset, 2); + + let end_time; + if (i + 1 < token_timestamps.length) { + end_time = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.round)(token_timestamps[i + 1] + time_offset, 2); + } else { + // should never happen + end_time = null; + } + current_token_timestamps.push([start_time, end_time]); + } + + } + } + + if ('stride' in output) { + const [chunk_len, stride_left, stride_right] = output.stride; + time_offset += chunk_len - stride_right + } + + // Leftover tokens + if (current_tokens.length > 0) { + previous_tokens.push(current_tokens) + if (returnWordTimestamps) { + previous_token_timestamps.push(current_token_timestamps); + } + } else if (previous_tokens.every(p => p.length === 0)) { + // Flushing previous tokens (END)" + chunk = new_chunk() + previous_tokens = [] + current_tokens = [] + previous_token_timestamps = []; + current_token_timestamps = []; + } + + } + + if (previous_tokens.length > 0) { + if (force_full_sequences && return_timestamps) { + // Last token should always be timestamps, so there shouldn't be + // leftover + throw new Error( + "Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. " + + "Also make sure WhisperTimeStampLogitsProcessor was used during generation." + ); + } + + // Happens when we don't use timestamps + const [resolved_tokens, resolved_token_timestamps] = this.findLongestCommonSequence(previous_tokens, previous_token_timestamps); + + // Flushing previous tokens (FINAL) + const resolved_text = this.decode(resolved_tokens); + chunk.text = resolved_text; + if (returnWordTimestamps) { + chunk.words = this.collateWordTimestamps( + resolved_tokens, resolved_token_timestamps, last_language, + ) + } + chunks.push(chunk); + } + + let optional = Object.create(null); + + // Preparing and cleaning up the pipeline output + const full_text = chunks.map(chunk => chunk.text).join(''); + if (return_timestamps || return_language) { + for (let i = 0; i < chunks.length; ++i) { + const chunk = chunks[i]; + if (!return_timestamps) { + delete chunk["timestamp"]; + } + + if (!return_language) { + delete chunk["language"]; + } + } + if (returnWordTimestamps) { + const new_chunks = []; + for (const chunk of chunks) { + for (const word of chunk.words) { + new_chunks.push(word); + } + } + optional = { "chunks": new_chunks }; + } else { + optional = { "chunks": chunks }; + } + } + return [full_text, optional]; + + } + + /** + * Finds the longest common sequence among the provided sequences. + * @param {number[][]} sequences An array of sequences of token ids to compare. + * @returns {number[][]} The longest common sequence found. + * @throws {Error} If there is a bug within the function. + * @private + */ + findLongestCommonSequence(sequences, token_timestamp_sequences = null) { + // It would be much harder to do O(n) because of fault tolerance. + // We actually have a really good property which is that the total sequence + // MUST be those subsequences in order. + // If token_timestamp_sequences is provided, will split those sequences in + // exactly the same way. + let leftSequence = sequences[0]; + let leftLength = leftSequence.length; + let totalSequence = []; + + const use_token_timestamp_sequences = Array.isArray(token_timestamp_sequences) && token_timestamp_sequences.length > 0; + let total_token_timestamp_sequence = use_token_timestamp_sequences ? [] : null; + let left_token_timestamp_sequence = use_token_timestamp_sequences ? token_timestamp_sequences[0] : null; + for (let i = 1; i < sequences.length; ++i) { + const rightSequence = sequences[i]; + let max = 0.0; + let maxIndices = [leftLength, leftLength, 0, 0]; + // Here we're sliding matches + // [a, b, c, d] + // [c, d, f] + // = [c] == [d] + + // [a, b, c, d] + // [c, d, f] + // = [c, d] == [c, d] + + + // [a, b, c, d] + // [c, d, f] + + // = [b, c, d] == [c, d, f] + + // [a, b, c, d] + // [c, d, f] + + // [a, b, c] == [c, d, f] + + // [a, b, c, d] + // [d, f] + + // [a, b] == [d, f] + + // [a, b, c, d] + // [f] + + // [a] == [f] + + const rightLength = rightSequence.length; + for (let j = 1; j < leftLength + rightLength; ++j) { + const eps = j / 10000.0; + const leftStart = Math.max(0, leftLength - j); + const leftStop = Math.min(leftLength, leftLength + rightLength - j); + const left = leftSequence.slice(leftStart, leftStop); + const rightStart = Math.max(0, j - leftLength); + const rightStop = Math.min(rightLength, j); + const right = rightSequence.slice(rightStart, rightStop); + if (left.length !== right.length) { + throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference."); + } + const matches = left.filter((elem, idx) => elem === right[idx]).length; + const matching = matches / j + eps; + if (matches > 1 && matching > max) { + max = matching; + maxIndices = [leftStart, leftStop, rightStart, rightStop]; + } + } + const [leftStart, leftStop, rightStart, rightStop] = maxIndices; + const leftMid = Math.floor((leftStop + leftStart) / 2); + const rightMid = Math.floor((rightStop + rightStart) / 2); + totalSequence.push(...leftSequence.slice(0, leftMid)); + leftSequence = rightSequence.slice(rightMid); + leftLength = leftSequence.length; + + if (use_token_timestamp_sequences) { + total_token_timestamp_sequence.push(...left_token_timestamp_sequence.slice(0, leftMid)); + left_token_timestamp_sequence = token_timestamp_sequences[i].slice(rightMid); + } + } + totalSequence.push(...leftSequence); + + if (use_token_timestamp_sequences) { + total_token_timestamp_sequence.push(...left_token_timestamp_sequence); + return [totalSequence, total_token_timestamp_sequence]; + } else { + return [totalSequence, []]; + } + } + + /** @private */ + collateWordTimestamps(tokens, token_timestamps, language) { + + const [words, _, token_indices] = this.combineTokensIntoWords(tokens, language); + + const timings = []; + for (let i = 0; i < words.length; ++i) { + const indices = token_indices[i]; + timings.push({ + text: words[i], + timestamp: [ + token_timestamps[indices.at(0)][0], + token_timestamps[indices.at(-1)][1], + ], + }); + } + return timings; + } + + /** + * Groups tokens by word. Returns a tuple containing a list of strings with the words, + * and a list of `token_id` sequences with the tokens making up each word. + * @param {number[]} tokens + * @param {string} [language] + * @param {string} prepend_punctionations + * @param {string} append_punctuations + * + * @private + */ + combineTokensIntoWords(tokens, language, prepend_punctionations = "\"'“¡¿([{-", append_punctuations = "\"'.。,,!!??::”)]}、") { + language = language ?? 'english'; + + let words, word_tokens, token_indices; + + if (["chinese", "japanese", "thai", "lao", "myanmar"].includes(language)) { + // These languages don't typically use spaces. + [words, word_tokens, token_indices] = this.splitTokensOnUnicode(tokens) + } else { + [words, word_tokens, token_indices] = this.splitTokensOnSpaces(tokens) + } + + return this.mergePunctuations(words, word_tokens, token_indices, prepend_punctionations, append_punctuations); + } + + /** @type {PreTrainedTokenizer['decode']} */ + decode( + token_ids, + decode_args, + ) { + let text; + // @ts-ignore + if (decode_args && decode_args.decode_with_timestamps) { + if (token_ids instanceof _utils_tensor_js__WEBPACK_IMPORTED_MODULE_3__.Tensor) { + token_ids = prepareTensorForDecode(token_ids); + } + text = this.decodeWithTimestamps(token_ids, decode_args); + } else { + text = super.decode(token_ids, decode_args); + } + // TODO: implement offsets + // if (decode_args.output_offsets) { + // let offsets = this.computeOffsets + // } + return text; + } + + /** + * @param {number[]} token_ids List of token IDs to decode. + * @param {Object} decode_args Optional arguments for decoding + * @private + */ + decodeWithTimestamps(token_ids, decode_args) { + const time_precision = decode_args?.time_precision ?? 0.02; + + const timestamp_begin = Array.from(this.all_special_ids).at(-1) + 1; + /**@type {Array} */ + let outputs = [[]]; + for (const token of token_ids) { + if (token >= timestamp_begin) { + const timestamp = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_2__.round)((token - timestamp_begin) * time_precision, 2); + outputs.push(`<|${timestamp}|>`); + outputs.push([]); + } else { + outputs[outputs.length - 1].push(token); + } + } + outputs = outputs.map( + s => { + if (typeof s === 'string') { + return s; + } else { + return super.decode(s, decode_args); + } + } + ) + + return outputs.join(''); + } + + /** + * Combine tokens into words by splitting at any position where the tokens are decoded as valid unicode points. + * @param {number[]} tokens + * @returns {*} + * @private + */ + splitTokensOnUnicode(tokens) { + const decoded_full = this.decode(tokens, { + // @ts-ignore + decode_with_timestamps: true, + }); + const replacement_char = '\uFFFD'; + + const words = [] + const word_tokens = [] + const token_indices = [] + let current_tokens = [] + let current_indices = [] + let unicode_offset = 0 + + for (let token_idx = 0; token_idx < tokens.length; ++token_idx) { + const token = tokens[token_idx]; + + current_tokens.push(token); + current_indices.push(token_idx); + + const decoded = this.decode(current_tokens, { + // @ts-ignore + decode_with_timestamps: true, + }); + + if (!decoded.includes(replacement_char) || decoded_full[unicode_offset + decoded.indexOf(replacement_char)] === replacement_char) { + words.push(decoded) + word_tokens.push(current_tokens) + token_indices.push(current_indices) + current_tokens = [] + current_indices = [] + unicode_offset += decoded.length; + } + + } + + return [words, word_tokens, token_indices] + } + + /** + * Combine tokens into words by splitting at whitespace and punctuation tokens. + * @param {number[]} tokens + * @private + */ + splitTokensOnSpaces(tokens) { + + const [subwords, subword_tokens_list, subword_indices_list] = this.splitTokensOnUnicode(tokens); + + const words = [] + const word_tokens = [] + const token_indices = [] + + const punctuationRegex = new RegExp(`^[${PUNCTUATION_REGEX}]$`, 'gu'); + + for (let i = 0; i < subwords.length; ++i) { + + const subword = subwords[i]; + const subword_tokens = subword_tokens_list[i]; + const subword_indices = subword_indices_list[i]; + + // @ts-ignore + const special = subword_tokens[0] >= this.model.tokens_to_ids.get('<|endoftext|>'); + const with_space = subword.startsWith(' '); + const trimmed = subword.trim(); + const punctuation = punctuationRegex.test(trimmed); + + if (special || with_space || punctuation || words.length === 0) { + words.push(subword); + word_tokens.push(subword_tokens); + token_indices.push(subword_indices); + } else { + const ix = words.length - 1; + words[ix] += subword; + word_tokens[ix].push(...subword_tokens); + token_indices[ix].push(...subword_indices); + } + } + + return [words, word_tokens, token_indices]; + + } + + /** + * Merges punctuation tokens with neighboring words. + * @param {string[]} words + * @param {number[][]} tokens + * @param {number[][]} indices + * @param {string} prepended + * @param {string} appended + * @private + */ + mergePunctuations(words, tokens, indices, prepended, appended) { + + const newWords = structuredClone(words); + const newTokens = structuredClone(tokens); + const newIndices = structuredClone(indices); + + + // prepend punctuations + let i = newWords.length - 2; + let j = newWords.length - 1; + + while (i >= 0) { + if (newWords[i].startsWith(' ') && prepended.includes(newWords[i].trim())) { + newWords[j] = newWords[i] + newWords[j]; + newTokens[j] = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(newTokens[i], newTokens[j]); + newIndices[j] = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(newIndices[i], newIndices[j]); + newWords[i] = ''; + newTokens[i] = []; + newIndices[i] = []; + } else { + j = i; + } + --i; + } + + // append punctuations + i = 0; + j = 1; + while (j < newWords.length) { + if (!newWords[i].endsWith(' ') && appended.includes(newWords[j])) { + newWords[i] += newWords[j]; + newTokens[i] = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(newTokens[i], newTokens[j]); + newIndices[i] = (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)(newIndices[i], newIndices[j]); + newWords[j] = ''; + newTokens[j] = []; + newIndices[j] = []; + } else { + i = j; + } + ++j; + } + + return [ + newWords.filter(x => x), + newTokens.filter(x => x.length > 0), + newIndices.filter(x => x.length > 0), + ] + } + + /** + * Helper function to build translation inputs for a `WhisperTokenizer`, + * depending on the language, task, and whether to predict timestamp tokens. + * + * Used to override the prefix tokens appended to the start of the label sequence. + * + * **Example: Get ids for a language** + * ```javascript + * // instantiate the tokenizer and set the prefix token to Spanish + * const tokenizer = await WhisperTokenizer.from_pretrained('Xenova/whisper-tiny'); + * const forced_decoder_ids = tokenizer.get_decoder_prompt_ids({ language: 'spanish' }); + * // [(1, 50262), (2, 50363)] + * ``` + * + * @param {Object} options Options to generate the decoder prompt. + * @param {string} [options.language] The language of the transcription text. + * The corresponding language id token is appended to the start of the sequence for multilingual + * speech recognition and speech translation tasks, e.g. for "Spanish" the token "<|es|>" is appended + * to the start of sequence. + * @param {string} [options.task] Task identifier to append at the start of sequence (if any). + * This should be used for mulitlingual fine-tuning, with "transcribe" for speech recognition and + * "translate" for speech translation. + * @param {boolean} [options.no_timestamps] Whether to add the <|notimestamps|> token at the start of the sequence. + * @returns {number[][]} The decoder prompt ids. + */ + get_decoder_prompt_ids({ + language = null, + task = null, + no_timestamps = true, + } = {}) { + + // <|lang_id|> <|task|> <|notimestamps|> + + const forced_decoder_ids = []; + + if (language) { + // User wishes to specify the language + language = language.toLowerCase(); + + // Map to code from user-friendly name (e.g., "english" -> "en") + let language_code = WHISPER_TO_LANGUAGE_CODE_MAPPING.get(language); + + if (language_code === undefined) { + // User provided something that is not a language name + + if (WHISPER_LANGUAGE_MAPPING.has(language)) { + // User provided the language code directly (e.g., "en") + language_code = language; + + } else { + // User provided something that is not a language code or name + const is_language_code = language.length === 2; + const langs = is_language_code ? WHISPER_LANGUAGE_MAPPING.keys() : WHISPER_LANGUAGE_MAPPING.values(); + + throw new Error(`Language "${language}" is not supported. Must be one of: ${JSON.stringify(langs)}`); + } + } + + const language_token_id = this.model.tokens_to_ids.get(`<|${language_code}|>`); + if (language_token_id === undefined) { + throw new Error(`Unable to find language "${language_code}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`) + } + + forced_decoder_ids.push(language_token_id); + } else { + // No token will be forced, which leaves the model to predict the language + forced_decoder_ids.push(null); + } + + if (task) { + task = task.toLowerCase(); + if (task !== 'transcribe' && task !== 'translate') { + throw new Error(`Task "${task}" is not supported. Must be one of: ["transcribe", "translate"]`); + } + + const task_token_id = this.model.tokens_to_ids.get(`<|${task}|>`); + if (task_token_id === undefined) { + throw new Error(`Unable to find task "${task}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`) + } + + forced_decoder_ids.push(task_token_id); + } else { + // No token will be forced, which leaves the model to predict the task + forced_decoder_ids.push(null); + } + + if (no_timestamps) { + const no_timestamps_id = this.model.tokens_to_ids.get(`<|notimestamps|>`); + if (no_timestamps_id === undefined) { + throw new Error('Unable to find "<|notimestamps|>" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.') + } + + forced_decoder_ids.push(no_timestamps_id); + } + + return forced_decoder_ids.map((x, i) => [i + 1, x]).filter(x => x[1] !== null); + + } +} +class CodeGenTokenizer extends PreTrainedTokenizer { } +class CLIPTokenizer extends PreTrainedTokenizer { } +class SiglipTokenizer extends PreTrainedTokenizer { } + +/** + * @todo This model is not yet supported by Hugging Face's "fast" tokenizers library (https://github.com/huggingface/tokenizers). + * Therefore, this implementation (which is based on fast tokenizers) may produce slightly inaccurate results. + */ +class MarianTokenizer extends PreTrainedTokenizer { + /** + * Create a new MarianTokenizer instance. + * @param {Object} tokenizerJSON The JSON of the tokenizer. + * @param {Object} tokenizerConfig The config of the tokenizer. + */ + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + + this.languageRegex = /^(>>\w+<<)\s*/g; + + this.supported_language_codes = this.model.vocab.filter( + x => this.languageRegex.test(x) + ); + + console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.') + } + + /** + * Encodes a single text. Overriding this method is necessary since the language codes + * must be removed before encoding with sentencepiece model. + * @see https://github.com/huggingface/transformers/blob/12d51db243a00726a548a43cc333390ebae731e3/src/transformers/models/marian/tokenization_marian.py#L204-L213 + * + * @param {string|null} text The text to encode. + * @returns {Array} The encoded tokens. + */ + _encode_text(text) { + if (text === null) return null; + + // Check if text starts with language code: + const [matchInfo, ...remainder] = text.trim().split(this.languageRegex); + + if (remainder.length === 0) { + // No language code, encode normally + return super._encode_text(matchInfo); + + } else if (remainder.length === 2) { + // Text starts with language code, so we do not encode it with sentencepiece. + const [language, text] = remainder; + + if (!this.supported_language_codes.includes(language)) { + console.warn(`Unsupported language code "${language}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`) + } + return (0,_utils_core_js__WEBPACK_IMPORTED_MODULE_0__.mergeArrays)([language], super._encode_text(text)); + } + } + +} + +class Wav2Vec2CTCTokenizer extends PreTrainedTokenizer { } + +class BlenderbotTokenizer extends PreTrainedTokenizer { + _default_chat_template = `{% for message in messages %}{% if message['role'] == 'user' %}{{ ' ' }}{% endif %}{{ message['content'] }}{% if not loop.last %}{{ ' ' }}{% endif %}{% endfor %}{{ eos_token }}`; +} +class BlenderbotSmallTokenizer extends BlenderbotTokenizer { } // NOTE `BlenderbotTokenizer` to get the correct chat template + +class SpeechT5Tokenizer extends PreTrainedTokenizer { } + +class NougatTokenizer extends PreTrainedTokenizer { } + +class VitsTokenizer extends PreTrainedTokenizer { + + constructor(tokenizerJSON, tokenizerConfig) { + super(tokenizerJSON, tokenizerConfig); + + // Custom decoder function + this.decoder = new VitsDecoder({}); + } +} + +class CohereTokenizer extends PreTrainedTokenizer { } + +/** + * Helper class which is used to instantiate pretrained tokenizers with the `from_pretrained` function. + * The chosen tokenizer class is determined by the type specified in the tokenizer config. + * + * @example + * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased'); + */ +class AutoTokenizer { + static TOKENIZER_CLASS_MAPPING = { + T5Tokenizer, + DistilBertTokenizer, + CamembertTokenizer, + DebertaTokenizer, + DebertaV2Tokenizer, + BertTokenizer, + HerbertTokenizer, + ConvBertTokenizer, + RoFormerTokenizer, + XLMTokenizer, + ElectraTokenizer, + MobileBertTokenizer, + SqueezeBertTokenizer, + AlbertTokenizer, + GPT2Tokenizer, + BartTokenizer, + MBartTokenizer, + MBart50Tokenizer, + RobertaTokenizer, + WhisperTokenizer, + CodeGenTokenizer, + CLIPTokenizer, + SiglipTokenizer, + MarianTokenizer, + BloomTokenizer, + NllbTokenizer, + M2M100Tokenizer, + LlamaTokenizer, + CodeLlamaTokenizer, + XLMRobertaTokenizer, + MPNetTokenizer, + FalconTokenizer, + GPTNeoXTokenizer, + EsmTokenizer, + Wav2Vec2CTCTokenizer, + BlenderbotTokenizer, + BlenderbotSmallTokenizer, + SpeechT5Tokenizer, + NougatTokenizer, + VitsTokenizer, + Qwen2Tokenizer, + GemmaTokenizer, + Grok1Tokenizer, + CohereTokenizer, + + // Base case: + PreTrainedTokenizer, + } + + + /** + * Instantiate one of the tokenizer classes of the library from a pretrained model. + * + * The tokenizer class to instantiate is selected based on the `tokenizer_class` property of the config object + * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible) + * + * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either: + * - A string, the *model id* of a pretrained tokenizer hosted inside a model repo on huggingface.co. + * Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a + * user or organization name, like `dbmdz/bert-base-german-cased`. + * - A path to a *directory* containing tokenizer files, e.g., `./my_model_directory/`. + * @param {PretrainedTokenizerOptions} options Additional options for loading the tokenizer. + * + * @returns {Promise} A new instance of the PreTrainedTokenizer class. + */ + static async from_pretrained(pretrained_model_name_or_path, { + quantized = true, + progress_callback = null, + config = null, + cache_dir = null, + local_files_only = false, + revision = 'main', + legacy = null, + } = {}) { + + const [tokenizerJSON, tokenizerConfig] = await loadTokenizer(pretrained_model_name_or_path, { + quantized, + progress_callback, + config, + cache_dir, + local_files_only, + revision, + legacy, + }) + + // Some tokenizers are saved with the "Fast" suffix, so we remove that if present. + const tokenizerName = tokenizerConfig.tokenizer_class?.replace(/Fast$/, '') ?? 'PreTrainedTokenizer'; + + let cls = this.TOKENIZER_CLASS_MAPPING[tokenizerName]; + if (!cls) { + console.warn(`Unknown tokenizer class "${tokenizerName}", attempting to construct from base class.`); + cls = PreTrainedTokenizer; + } + return new cls(tokenizerJSON, tokenizerConfig); + } +} + + +/***/ }), + +/***/ "./src/transformers.js": +/*!*****************************!*\ + !*** ./src/transformers.js ***! + \*****************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "ASTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ASTFeatureExtractor), +/* harmony export */ "ASTForAudioClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ASTForAudioClassification), +/* harmony export */ "ASTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ASTModel), +/* harmony export */ "ASTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ASTPreTrainedModel), +/* harmony export */ "AlbertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AlbertForMaskedLM), +/* harmony export */ "AlbertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AlbertForQuestionAnswering), +/* harmony export */ "AlbertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AlbertForSequenceClassification), +/* harmony export */ "AlbertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AlbertModel), +/* harmony export */ "AlbertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AlbertPreTrainedModel), +/* harmony export */ "AlbertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.AlbertTokenizer), +/* harmony export */ "AudioClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.AudioClassificationPipeline), +/* harmony export */ "AutoConfig": () => (/* reexport safe */ _configs_js__WEBPACK_IMPORTED_MODULE_5__.AutoConfig), +/* harmony export */ "AutoModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModel), +/* harmony export */ "AutoModelForAudioClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForAudioClassification), +/* harmony export */ "AutoModelForAudioFrameClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForAudioFrameClassification), +/* harmony export */ "AutoModelForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForCTC), +/* harmony export */ "AutoModelForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForCausalLM), +/* harmony export */ "AutoModelForDepthEstimation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForDepthEstimation), +/* harmony export */ "AutoModelForDocumentQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForDocumentQuestionAnswering), +/* harmony export */ "AutoModelForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForImageClassification), +/* harmony export */ "AutoModelForImageFeatureExtraction": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForImageFeatureExtraction), +/* harmony export */ "AutoModelForImageMatting": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForImageMatting), +/* harmony export */ "AutoModelForImageSegmentation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForImageSegmentation), +/* harmony export */ "AutoModelForImageToImage": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForImageToImage), +/* harmony export */ "AutoModelForMaskGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForMaskGeneration), +/* harmony export */ "AutoModelForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForMaskedLM), +/* harmony export */ "AutoModelForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForObjectDetection), +/* harmony export */ "AutoModelForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForQuestionAnswering), +/* harmony export */ "AutoModelForSemanticSegmentation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForSemanticSegmentation), +/* harmony export */ "AutoModelForSeq2SeqLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForSeq2SeqLM), +/* harmony export */ "AutoModelForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForSequenceClassification), +/* harmony export */ "AutoModelForSpeechSeq2Seq": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForSpeechSeq2Seq), +/* harmony export */ "AutoModelForTextToSpectrogram": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForTextToSpectrogram), +/* harmony export */ "AutoModelForTextToWaveform": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForTextToWaveform), +/* harmony export */ "AutoModelForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForTokenClassification), +/* harmony export */ "AutoModelForVision2Seq": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForVision2Seq), +/* harmony export */ "AutoModelForXVector": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForXVector), +/* harmony export */ "AutoModelForZeroShotObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.AutoModelForZeroShotObjectDetection), +/* harmony export */ "AutoProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.AutoProcessor), +/* harmony export */ "AutoTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.AutoTokenizer), +/* harmony export */ "AutomaticSpeechRecognitionPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.AutomaticSpeechRecognitionPipeline), +/* harmony export */ "BartForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BartForConditionalGeneration), +/* harmony export */ "BartForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BartForSequenceClassification), +/* harmony export */ "BartModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BartModel), +/* harmony export */ "BartPretrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BartPretrainedModel), +/* harmony export */ "BartTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.BartTokenizer), +/* harmony export */ "BaseModelOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BaseModelOutput), +/* harmony export */ "BeitFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.BeitFeatureExtractor), +/* harmony export */ "BeitForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BeitForImageClassification), +/* harmony export */ "BeitModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BeitModel), +/* harmony export */ "BeitPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BeitPreTrainedModel), +/* harmony export */ "BertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertForMaskedLM), +/* harmony export */ "BertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertForQuestionAnswering), +/* harmony export */ "BertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertForSequenceClassification), +/* harmony export */ "BertForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertForTokenClassification), +/* harmony export */ "BertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertModel), +/* harmony export */ "BertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BertPreTrainedModel), +/* harmony export */ "BertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.BertTokenizer), +/* harmony export */ "BitImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.BitImageProcessor), +/* harmony export */ "BlenderbotForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotForConditionalGeneration), +/* harmony export */ "BlenderbotModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotModel), +/* harmony export */ "BlenderbotPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotPreTrainedModel), +/* harmony export */ "BlenderbotSmallForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotSmallForConditionalGeneration), +/* harmony export */ "BlenderbotSmallModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotSmallModel), +/* harmony export */ "BlenderbotSmallPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BlenderbotSmallPreTrainedModel), +/* harmony export */ "BlenderbotSmallTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.BlenderbotSmallTokenizer), +/* harmony export */ "BlenderbotTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.BlenderbotTokenizer), +/* harmony export */ "BloomForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BloomForCausalLM), +/* harmony export */ "BloomModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BloomModel), +/* harmony export */ "BloomPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.BloomPreTrainedModel), +/* harmony export */ "BloomTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.BloomTokenizer), +/* harmony export */ "CLIPFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.CLIPFeatureExtractor), +/* harmony export */ "CLIPModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPModel), +/* harmony export */ "CLIPPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPPreTrainedModel), +/* harmony export */ "CLIPSegForImageSegmentation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPSegForImageSegmentation), +/* harmony export */ "CLIPSegModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPSegModel), +/* harmony export */ "CLIPSegPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPSegPreTrainedModel), +/* harmony export */ "CLIPTextModelWithProjection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPTextModelWithProjection), +/* harmony export */ "CLIPTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.CLIPTokenizer), +/* harmony export */ "CLIPVisionModelWithProjection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CLIPVisionModelWithProjection), +/* harmony export */ "CamembertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertForMaskedLM), +/* harmony export */ "CamembertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertForQuestionAnswering), +/* harmony export */ "CamembertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertForSequenceClassification), +/* harmony export */ "CamembertForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertForTokenClassification), +/* harmony export */ "CamembertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertModel), +/* harmony export */ "CamembertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CamembertPreTrainedModel), +/* harmony export */ "CamembertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.CamembertTokenizer), +/* harmony export */ "CausalLMOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CausalLMOutput), +/* harmony export */ "CausalLMOutputWithPast": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CausalLMOutputWithPast), +/* harmony export */ "ChineseCLIPFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ChineseCLIPFeatureExtractor), +/* harmony export */ "ChineseCLIPModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ChineseCLIPModel), +/* harmony export */ "ChineseCLIPPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ChineseCLIPPreTrainedModel), +/* harmony export */ "ClapAudioModelWithProjection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ClapAudioModelWithProjection), +/* harmony export */ "ClapFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ClapFeatureExtractor), +/* harmony export */ "ClapModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ClapModel), +/* harmony export */ "ClapPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ClapPreTrainedModel), +/* harmony export */ "ClapTextModelWithProjection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ClapTextModelWithProjection), +/* harmony export */ "CodeGenForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CodeGenForCausalLM), +/* harmony export */ "CodeGenModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CodeGenModel), +/* harmony export */ "CodeGenPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.CodeGenPreTrainedModel), +/* harmony export */ "CodeGenTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.CodeGenTokenizer), +/* harmony export */ "CodeLlamaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.CodeLlamaTokenizer), +/* harmony export */ "CohereTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.CohereTokenizer), +/* harmony export */ "ConvBertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertForMaskedLM), +/* harmony export */ "ConvBertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertForQuestionAnswering), +/* harmony export */ "ConvBertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertForSequenceClassification), +/* harmony export */ "ConvBertForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertForTokenClassification), +/* harmony export */ "ConvBertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertModel), +/* harmony export */ "ConvBertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvBertPreTrainedModel), +/* harmony export */ "ConvBertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.ConvBertTokenizer), +/* harmony export */ "ConvNextFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ConvNextFeatureExtractor), +/* harmony export */ "ConvNextForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextForImageClassification), +/* harmony export */ "ConvNextImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ConvNextImageProcessor), +/* harmony export */ "ConvNextModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextModel), +/* harmony export */ "ConvNextPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextPreTrainedModel), +/* harmony export */ "ConvNextV2ForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2ForImageClassification), +/* harmony export */ "ConvNextV2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2Model), +/* harmony export */ "ConvNextV2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2PreTrainedModel), +/* harmony export */ "DPTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.DPTFeatureExtractor), +/* harmony export */ "DPTForDepthEstimation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DPTForDepthEstimation), +/* harmony export */ "DPTImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.DPTImageProcessor), +/* harmony export */ "DPTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DPTModel), +/* harmony export */ "DPTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DPTPreTrainedModel), +/* harmony export */ "DebertaForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaForMaskedLM), +/* harmony export */ "DebertaForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaForQuestionAnswering), +/* harmony export */ "DebertaForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaForSequenceClassification), +/* harmony export */ "DebertaForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaForTokenClassification), +/* harmony export */ "DebertaModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaModel), +/* harmony export */ "DebertaPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaPreTrainedModel), +/* harmony export */ "DebertaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.DebertaTokenizer), +/* harmony export */ "DebertaV2ForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2ForMaskedLM), +/* harmony export */ "DebertaV2ForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2ForQuestionAnswering), +/* harmony export */ "DebertaV2ForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2ForSequenceClassification), +/* harmony export */ "DebertaV2ForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2ForTokenClassification), +/* harmony export */ "DebertaV2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2Model), +/* harmony export */ "DebertaV2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DebertaV2PreTrainedModel), +/* harmony export */ "DebertaV2Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.DebertaV2Tokenizer), +/* harmony export */ "DeiTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.DeiTFeatureExtractor), +/* harmony export */ "DeiTForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DeiTForImageClassification), +/* harmony export */ "DeiTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DeiTModel), +/* harmony export */ "DeiTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DeiTPreTrainedModel), +/* harmony export */ "DepthAnythingForDepthEstimation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DepthAnythingForDepthEstimation), +/* harmony export */ "DepthAnythingPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DepthAnythingPreTrainedModel), +/* harmony export */ "DepthEstimationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.DepthEstimationPipeline), +/* harmony export */ "DetrFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.DetrFeatureExtractor), +/* harmony export */ "DetrForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrForObjectDetection), +/* harmony export */ "DetrForSegmentation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrForSegmentation), +/* harmony export */ "DetrModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrModel), +/* harmony export */ "DetrObjectDetectionOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrObjectDetectionOutput), +/* harmony export */ "DetrPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrPreTrainedModel), +/* harmony export */ "DetrSegmentationOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DetrSegmentationOutput), +/* harmony export */ "Dinov2ForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Dinov2ForImageClassification), +/* harmony export */ "Dinov2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Dinov2Model), +/* harmony export */ "Dinov2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Dinov2PreTrainedModel), +/* harmony export */ "DistilBertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertForMaskedLM), +/* harmony export */ "DistilBertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertForQuestionAnswering), +/* harmony export */ "DistilBertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertForSequenceClassification), +/* harmony export */ "DistilBertForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertForTokenClassification), +/* harmony export */ "DistilBertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertModel), +/* harmony export */ "DistilBertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DistilBertPreTrainedModel), +/* harmony export */ "DistilBertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.DistilBertTokenizer), +/* harmony export */ "DocumentQuestionAnsweringPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.DocumentQuestionAnsweringPipeline), +/* harmony export */ "DonutFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.DonutFeatureExtractor), +/* harmony export */ "DonutSwinModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DonutSwinModel), +/* harmony export */ "DonutSwinPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DonutSwinPreTrainedModel), +/* harmony export */ "EfficientNetForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EfficientNetForImageClassification), +/* harmony export */ "EfficientNetImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.EfficientNetImageProcessor), +/* harmony export */ "EfficientNetModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EfficientNetModel), +/* harmony export */ "EfficientNetPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EfficientNetPreTrainedModel), +/* harmony export */ "ElectraForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraForMaskedLM), +/* harmony export */ "ElectraForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraForQuestionAnswering), +/* harmony export */ "ElectraForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraForSequenceClassification), +/* harmony export */ "ElectraForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraForTokenClassification), +/* harmony export */ "ElectraModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraModel), +/* harmony export */ "ElectraPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ElectraPreTrainedModel), +/* harmony export */ "ElectraTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.ElectraTokenizer), +/* harmony export */ "EsmForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EsmForMaskedLM), +/* harmony export */ "EsmForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EsmForSequenceClassification), +/* harmony export */ "EsmForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EsmForTokenClassification), +/* harmony export */ "EsmModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EsmModel), +/* harmony export */ "EsmPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.EsmPreTrainedModel), +/* harmony export */ "EsmTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.EsmTokenizer), +/* harmony export */ "FFT": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.FFT), +/* harmony export */ "FalconForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.FalconForCausalLM), +/* harmony export */ "FalconModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.FalconModel), +/* harmony export */ "FalconPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.FalconPreTrainedModel), +/* harmony export */ "FalconTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.FalconTokenizer), +/* harmony export */ "FeatureExtractionPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.FeatureExtractionPipeline), +/* harmony export */ "FeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.FeatureExtractor), +/* harmony export */ "FillMaskPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.FillMaskPipeline), +/* harmony export */ "GLPNFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.GLPNFeatureExtractor), +/* harmony export */ "GLPNForDepthEstimation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GLPNForDepthEstimation), +/* harmony export */ "GLPNModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GLPNModel), +/* harmony export */ "GLPNPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GLPNPreTrainedModel), +/* harmony export */ "GPT2LMHeadModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPT2LMHeadModel), +/* harmony export */ "GPT2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPT2Model), +/* harmony export */ "GPT2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPT2PreTrainedModel), +/* harmony export */ "GPT2Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.GPT2Tokenizer), +/* harmony export */ "GPTBigCodeForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTBigCodeForCausalLM), +/* harmony export */ "GPTBigCodeModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTBigCodeModel), +/* harmony export */ "GPTBigCodePreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTBigCodePreTrainedModel), +/* harmony export */ "GPTJForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTJForCausalLM), +/* harmony export */ "GPTJModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTJModel), +/* harmony export */ "GPTJPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTJPreTrainedModel), +/* harmony export */ "GPTNeoForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoForCausalLM), +/* harmony export */ "GPTNeoModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoModel), +/* harmony export */ "GPTNeoPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoPreTrainedModel), +/* harmony export */ "GPTNeoXForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoXForCausalLM), +/* harmony export */ "GPTNeoXModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoXModel), +/* harmony export */ "GPTNeoXPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.GPTNeoXPreTrainedModel), +/* harmony export */ "GPTNeoXTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.GPTNeoXTokenizer), +/* harmony export */ "GemmaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.GemmaTokenizer), +/* harmony export */ "Grok1Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.Grok1Tokenizer), +/* harmony export */ "HerbertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.HerbertTokenizer), +/* harmony export */ "HubertForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.HubertForCTC), +/* harmony export */ "HubertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.HubertForSequenceClassification), +/* harmony export */ "HubertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.HubertModel), +/* harmony export */ "HubertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.HubertPreTrainedModel), +/* harmony export */ "ImageClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ImageClassificationPipeline), +/* harmony export */ "ImageFeatureExtractionPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ImageFeatureExtractionPipeline), +/* harmony export */ "ImageFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ImageFeatureExtractor), +/* harmony export */ "ImageMattingOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ImageMattingOutput), +/* harmony export */ "ImageSegmentationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ImageSegmentationPipeline), +/* harmony export */ "ImageToImagePipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ImageToImagePipeline), +/* harmony export */ "ImageToTextPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ImageToTextPipeline), +/* harmony export */ "LlamaForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LlamaForCausalLM), +/* harmony export */ "LlamaModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LlamaModel), +/* harmony export */ "LlamaPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LlamaPreTrainedModel), +/* harmony export */ "LlamaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.LlamaTokenizer), +/* harmony export */ "LongT5ForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LongT5ForConditionalGeneration), +/* harmony export */ "LongT5Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LongT5Model), +/* harmony export */ "LongT5PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.LongT5PreTrainedModel), +/* harmony export */ "M2M100ForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.M2M100ForConditionalGeneration), +/* harmony export */ "M2M100Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.M2M100Model), +/* harmony export */ "M2M100PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.M2M100PreTrainedModel), +/* harmony export */ "M2M100Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.M2M100Tokenizer), +/* harmony export */ "MBart50Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.MBart50Tokenizer), +/* harmony export */ "MBartForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MBartForCausalLM), +/* harmony export */ "MBartForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MBartForConditionalGeneration), +/* harmony export */ "MBartForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MBartForSequenceClassification), +/* harmony export */ "MBartModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MBartModel), +/* harmony export */ "MBartPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MBartPreTrainedModel), +/* harmony export */ "MBartTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.MBartTokenizer), +/* harmony export */ "MPNetForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetForMaskedLM), +/* harmony export */ "MPNetForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetForQuestionAnswering), +/* harmony export */ "MPNetForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetForSequenceClassification), +/* harmony export */ "MPNetForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetForTokenClassification), +/* harmony export */ "MPNetModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetModel), +/* harmony export */ "MPNetPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MPNetPreTrainedModel), +/* harmony export */ "MPNetTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.MPNetTokenizer), +/* harmony export */ "MT5ForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MT5ForConditionalGeneration), +/* harmony export */ "MT5Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MT5Model), +/* harmony export */ "MT5PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MT5PreTrainedModel), +/* harmony export */ "MarianMTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MarianMTModel), +/* harmony export */ "MarianModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MarianModel), +/* harmony export */ "MarianPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MarianPreTrainedModel), +/* harmony export */ "MarianTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.MarianTokenizer), +/* harmony export */ "MaskedLMOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MaskedLMOutput), +/* harmony export */ "MistralForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MistralForCausalLM), +/* harmony export */ "MistralModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MistralModel), +/* harmony export */ "MistralPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MistralPreTrainedModel), +/* harmony export */ "MobileBertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileBertForMaskedLM), +/* harmony export */ "MobileBertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileBertForQuestionAnswering), +/* harmony export */ "MobileBertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileBertForSequenceClassification), +/* harmony export */ "MobileBertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileBertModel), +/* harmony export */ "MobileBertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileBertPreTrainedModel), +/* harmony export */ "MobileBertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.MobileBertTokenizer), +/* harmony export */ "MobileViTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.MobileViTFeatureExtractor), +/* harmony export */ "MobileViTForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileViTForImageClassification), +/* harmony export */ "MobileViTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileViTModel), +/* harmony export */ "MobileViTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MobileViTPreTrainedModel), +/* harmony export */ "ModelOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ModelOutput), +/* harmony export */ "MptForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MptForCausalLM), +/* harmony export */ "MptModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MptModel), +/* harmony export */ "MptPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.MptPreTrainedModel), +/* harmony export */ "NllbTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.NllbTokenizer), +/* harmony export */ "NomicBertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.NomicBertModel), +/* harmony export */ "NomicBertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.NomicBertPreTrainedModel), +/* harmony export */ "NougatImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.NougatImageProcessor), +/* harmony export */ "NougatTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.NougatTokenizer), +/* harmony export */ "OPTForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OPTForCausalLM), +/* harmony export */ "OPTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OPTModel), +/* harmony export */ "OPTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OPTPreTrainedModel), +/* harmony export */ "ObjectDetectionPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ObjectDetectionPipeline), +/* harmony export */ "OwlViTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.OwlViTFeatureExtractor), +/* harmony export */ "OwlViTForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OwlViTForObjectDetection), +/* harmony export */ "OwlViTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OwlViTModel), +/* harmony export */ "OwlViTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.OwlViTPreTrainedModel), +/* harmony export */ "OwlViTProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.OwlViTProcessor), +/* harmony export */ "Owlv2ForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Owlv2ForObjectDetection), +/* harmony export */ "Owlv2ImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.Owlv2ImageProcessor), +/* harmony export */ "Owlv2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Owlv2Model), +/* harmony export */ "Owlv2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Owlv2PreTrainedModel), +/* harmony export */ "PhiForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.PhiForCausalLM), +/* harmony export */ "PhiModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.PhiModel), +/* harmony export */ "PhiPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.PhiPreTrainedModel), +/* harmony export */ "Pipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.Pipeline), +/* harmony export */ "PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.PreTrainedModel), +/* harmony export */ "PreTrainedTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.PreTrainedTokenizer), +/* harmony export */ "PretrainedConfig": () => (/* reexport safe */ _configs_js__WEBPACK_IMPORTED_MODULE_5__.PretrainedConfig), +/* harmony export */ "PretrainedMixin": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.PretrainedMixin), +/* harmony export */ "Processor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.Processor), +/* harmony export */ "QuestionAnsweringModelOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.QuestionAnsweringModelOutput), +/* harmony export */ "QuestionAnsweringPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.QuestionAnsweringPipeline), +/* harmony export */ "Qwen2ForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen2ForCausalLM), +/* harmony export */ "Qwen2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen2Model), +/* harmony export */ "Qwen2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen2PreTrainedModel), +/* harmony export */ "Qwen2Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.Qwen2Tokenizer), +/* harmony export */ "RawImage": () => (/* reexport safe */ _utils_image_js__WEBPACK_IMPORTED_MODULE_7__.RawImage), +/* harmony export */ "ResNetForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ResNetForImageClassification), +/* harmony export */ "ResNetModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ResNetModel), +/* harmony export */ "ResNetPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ResNetPreTrainedModel), +/* harmony export */ "RoFormerForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerForMaskedLM), +/* harmony export */ "RoFormerForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerForQuestionAnswering), +/* harmony export */ "RoFormerForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerForSequenceClassification), +/* harmony export */ "RoFormerForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerForTokenClassification), +/* harmony export */ "RoFormerModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerModel), +/* harmony export */ "RoFormerPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RoFormerPreTrainedModel), +/* harmony export */ "RoFormerTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.RoFormerTokenizer), +/* harmony export */ "RobertaForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaForMaskedLM), +/* harmony export */ "RobertaForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaForQuestionAnswering), +/* harmony export */ "RobertaForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaForSequenceClassification), +/* harmony export */ "RobertaForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaForTokenClassification), +/* harmony export */ "RobertaModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaModel), +/* harmony export */ "RobertaPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RobertaPreTrainedModel), +/* harmony export */ "RobertaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.RobertaTokenizer), +/* harmony export */ "SamImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SamImageProcessor), +/* harmony export */ "SamImageSegmentationOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SamImageSegmentationOutput), +/* harmony export */ "SamModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SamModel), +/* harmony export */ "SamPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SamPreTrainedModel), +/* harmony export */ "SamProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SamProcessor), +/* harmony export */ "SeamlessM4TFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SeamlessM4TFeatureExtractor), +/* harmony export */ "SegformerFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SegformerFeatureExtractor), +/* harmony export */ "SegformerForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SegformerForImageClassification), +/* harmony export */ "SegformerForSemanticSegmentation": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SegformerForSemanticSegmentation), +/* harmony export */ "SegformerModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SegformerModel), +/* harmony export */ "SegformerPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SegformerPreTrainedModel), +/* harmony export */ "Seq2SeqLMOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Seq2SeqLMOutput), +/* harmony export */ "SequenceClassifierOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SequenceClassifierOutput), +/* harmony export */ "SiglipImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SiglipImageProcessor), +/* harmony export */ "SiglipModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SiglipModel), +/* harmony export */ "SiglipPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SiglipPreTrainedModel), +/* harmony export */ "SiglipTextModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SiglipTextModel), +/* harmony export */ "SiglipTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.SiglipTokenizer), +/* harmony export */ "SiglipVisionModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SiglipVisionModel), +/* harmony export */ "SpeechT5FeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SpeechT5FeatureExtractor), +/* harmony export */ "SpeechT5ForSpeechToText": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SpeechT5ForSpeechToText), +/* harmony export */ "SpeechT5ForTextToSpeech": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SpeechT5ForTextToSpeech), +/* harmony export */ "SpeechT5HifiGan": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SpeechT5HifiGan), +/* harmony export */ "SpeechT5Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SpeechT5Model), +/* harmony export */ "SpeechT5PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SpeechT5PreTrainedModel), +/* harmony export */ "SpeechT5Processor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.SpeechT5Processor), +/* harmony export */ "SpeechT5Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.SpeechT5Tokenizer), +/* harmony export */ "SqueezeBertForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SqueezeBertForMaskedLM), +/* harmony export */ "SqueezeBertForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SqueezeBertForQuestionAnswering), +/* harmony export */ "SqueezeBertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SqueezeBertForSequenceClassification), +/* harmony export */ "SqueezeBertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SqueezeBertModel), +/* harmony export */ "SqueezeBertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SqueezeBertPreTrainedModel), +/* harmony export */ "SqueezeBertTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.SqueezeBertTokenizer), +/* harmony export */ "StableLmForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.StableLmForCausalLM), +/* harmony export */ "StableLmModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.StableLmModel), +/* harmony export */ "StableLmPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.StableLmPreTrainedModel), +/* harmony export */ "Starcoder2ForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Starcoder2ForCausalLM), +/* harmony export */ "Starcoder2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Starcoder2Model), +/* harmony export */ "Starcoder2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Starcoder2PreTrainedModel), +/* harmony export */ "SummarizationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.SummarizationPipeline), +/* harmony export */ "Swin2SRForImageSuperResolution": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Swin2SRForImageSuperResolution), +/* harmony export */ "Swin2SRImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.Swin2SRImageProcessor), +/* harmony export */ "Swin2SRModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Swin2SRModel), +/* harmony export */ "Swin2SRPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Swin2SRPreTrainedModel), +/* harmony export */ "SwinForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SwinForImageClassification), +/* harmony export */ "SwinModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SwinModel), +/* harmony export */ "SwinPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.SwinPreTrainedModel), +/* harmony export */ "T5ForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.T5ForConditionalGeneration), +/* harmony export */ "T5Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.T5Model), +/* harmony export */ "T5PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.T5PreTrainedModel), +/* harmony export */ "T5Tokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.T5Tokenizer), +/* harmony export */ "TableTransformerForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TableTransformerForObjectDetection), +/* harmony export */ "TableTransformerModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TableTransformerModel), +/* harmony export */ "TableTransformerObjectDetectionOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TableTransformerObjectDetectionOutput), +/* harmony export */ "TableTransformerPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TableTransformerPreTrainedModel), +/* harmony export */ "Tensor": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.Tensor), +/* harmony export */ "Text2TextGenerationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.Text2TextGenerationPipeline), +/* harmony export */ "TextClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.TextClassificationPipeline), +/* harmony export */ "TextGenerationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.TextGenerationPipeline), +/* harmony export */ "TextToAudioPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.TextToAudioPipeline), +/* harmony export */ "TokenClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.TokenClassificationPipeline), +/* harmony export */ "TokenClassifierOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TokenClassifierOutput), +/* harmony export */ "TokenizerModel": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.TokenizerModel), +/* harmony export */ "TrOCRForCausalLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TrOCRForCausalLM), +/* harmony export */ "TrOCRPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.TrOCRPreTrainedModel), +/* harmony export */ "TranslationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.TranslationPipeline), +/* harmony export */ "UniSpeechForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechForCTC), +/* harmony export */ "UniSpeechForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechForSequenceClassification), +/* harmony export */ "UniSpeechModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechModel), +/* harmony export */ "UniSpeechPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechPreTrainedModel), +/* harmony export */ "UniSpeechSatForAudioFrameClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechSatForAudioFrameClassification), +/* harmony export */ "UniSpeechSatForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechSatForCTC), +/* harmony export */ "UniSpeechSatForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechSatForSequenceClassification), +/* harmony export */ "UniSpeechSatModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechSatModel), +/* harmony export */ "UniSpeechSatPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.UniSpeechSatPreTrainedModel), +/* harmony export */ "ViTFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ViTFeatureExtractor), +/* harmony export */ "ViTForImageClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ViTForImageClassification), +/* harmony export */ "ViTImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.ViTImageProcessor), +/* harmony export */ "ViTModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ViTModel), +/* harmony export */ "ViTPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ViTPreTrainedModel), +/* harmony export */ "VisionEncoderDecoderModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VisionEncoderDecoderModel), +/* harmony export */ "VitMatteForImageMatting": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VitMatteForImageMatting), +/* harmony export */ "VitMatteImageProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.VitMatteImageProcessor), +/* harmony export */ "VitMattePreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VitMattePreTrainedModel), +/* harmony export */ "VitsModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VitsModel), +/* harmony export */ "VitsModelOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VitsModelOutput), +/* harmony export */ "VitsPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.VitsPreTrainedModel), +/* harmony export */ "VitsTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.VitsTokenizer), +/* harmony export */ "Wav2Vec2BertForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2BertForCTC), +/* harmony export */ "Wav2Vec2BertForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2BertForSequenceClassification), +/* harmony export */ "Wav2Vec2BertModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2BertModel), +/* harmony export */ "Wav2Vec2BertPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2BertPreTrainedModel), +/* harmony export */ "Wav2Vec2CTCTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.Wav2Vec2CTCTokenizer), +/* harmony export */ "Wav2Vec2FeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.Wav2Vec2FeatureExtractor), +/* harmony export */ "Wav2Vec2ForAudioFrameClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2ForAudioFrameClassification), +/* harmony export */ "Wav2Vec2ForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2ForCTC), +/* harmony export */ "Wav2Vec2ForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2ForSequenceClassification), +/* harmony export */ "Wav2Vec2Model": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2Model), +/* harmony export */ "Wav2Vec2PreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Wav2Vec2PreTrainedModel), +/* harmony export */ "Wav2Vec2ProcessorWithLM": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.Wav2Vec2ProcessorWithLM), +/* harmony export */ "WavLMForAudioFrameClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMForAudioFrameClassification), +/* harmony export */ "WavLMForCTC": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMForCTC), +/* harmony export */ "WavLMForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMForSequenceClassification), +/* harmony export */ "WavLMForXVector": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMForXVector), +/* harmony export */ "WavLMModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMModel), +/* harmony export */ "WavLMPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WavLMPreTrainedModel), +/* harmony export */ "WhisperFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.WhisperFeatureExtractor), +/* harmony export */ "WhisperForConditionalGeneration": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WhisperForConditionalGeneration), +/* harmony export */ "WhisperModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WhisperModel), +/* harmony export */ "WhisperPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.WhisperPreTrainedModel), +/* harmony export */ "WhisperProcessor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.WhisperProcessor), +/* harmony export */ "WhisperTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.WhisperTokenizer), +/* harmony export */ "XLMForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMForQuestionAnswering), +/* harmony export */ "XLMForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMForSequenceClassification), +/* harmony export */ "XLMForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMForTokenClassification), +/* harmony export */ "XLMModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMModel), +/* harmony export */ "XLMPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMPreTrainedModel), +/* harmony export */ "XLMRobertaForMaskedLM": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaForMaskedLM), +/* harmony export */ "XLMRobertaForQuestionAnswering": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaForQuestionAnswering), +/* harmony export */ "XLMRobertaForSequenceClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaForSequenceClassification), +/* harmony export */ "XLMRobertaForTokenClassification": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaForTokenClassification), +/* harmony export */ "XLMRobertaModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaModel), +/* harmony export */ "XLMRobertaPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMRobertaPreTrainedModel), +/* harmony export */ "XLMRobertaTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.XLMRobertaTokenizer), +/* harmony export */ "XLMTokenizer": () => (/* reexport safe */ _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__.XLMTokenizer), +/* harmony export */ "XLMWithLMHeadModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XLMWithLMHeadModel), +/* harmony export */ "XVectorOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.XVectorOutput), +/* harmony export */ "YolosFeatureExtractor": () => (/* reexport safe */ _processors_js__WEBPACK_IMPORTED_MODULE_4__.YolosFeatureExtractor), +/* harmony export */ "YolosForObjectDetection": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.YolosForObjectDetection), +/* harmony export */ "YolosModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.YolosModel), +/* harmony export */ "YolosObjectDetectionOutput": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.YolosObjectDetectionOutput), +/* harmony export */ "YolosPreTrainedModel": () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.YolosPreTrainedModel), +/* harmony export */ "ZeroShotAudioClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ZeroShotAudioClassificationPipeline), +/* harmony export */ "ZeroShotClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ZeroShotClassificationPipeline), +/* harmony export */ "ZeroShotImageClassificationPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ZeroShotImageClassificationPipeline), +/* harmony export */ "ZeroShotObjectDetectionPipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.ZeroShotObjectDetectionPipeline), +/* harmony export */ "bankers_round": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.bankers_round), +/* harmony export */ "cat": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.cat), +/* harmony export */ "cos_sim": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.cos_sim), +/* harmony export */ "dot": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.dot), +/* harmony export */ "dynamicTimeWarping": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.dynamicTimeWarping), +/* harmony export */ "env": () => (/* reexport safe */ _env_js__WEBPACK_IMPORTED_MODULE_1__.env), +/* harmony export */ "getTopItems": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.getTopItems), +/* harmony export */ "hanning": () => (/* reexport safe */ _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__.hanning), +/* harmony export */ "interpolate": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.interpolate), +/* harmony export */ "interpolate_data": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.interpolate_data), +/* harmony export */ "layer_norm": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.layer_norm), +/* harmony export */ "log_softmax": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.log_softmax), +/* harmony export */ "magnitude": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.magnitude), +/* harmony export */ "max": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.max), +/* harmony export */ "mean": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.mean), +/* harmony export */ "mean_pooling": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.mean_pooling), +/* harmony export */ "medianFilter": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.medianFilter), +/* harmony export */ "mel_filter_bank": () => (/* reexport safe */ _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__.mel_filter_bank), +/* harmony export */ "min": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.min), +/* harmony export */ "ones": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.ones), +/* harmony export */ "ones_like": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.ones_like), +/* harmony export */ "permute": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.permute), +/* harmony export */ "permute_data": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.permute_data), +/* harmony export */ "pipeline": () => (/* reexport safe */ _pipelines_js__WEBPACK_IMPORTED_MODULE_0__.pipeline), +/* harmony export */ "read_audio": () => (/* reexport safe */ _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__.read_audio), +/* harmony export */ "round": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.round), +/* harmony export */ "softmax": () => (/* reexport safe */ _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__.softmax), +/* harmony export */ "spectrogram": () => (/* reexport safe */ _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__.spectrogram), +/* harmony export */ "stack": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.stack), +/* harmony export */ "std_mean": () => (/* reexport safe */ _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__.std_mean), +/* harmony export */ "window_function": () => (/* reexport safe */ _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__.window_function) +/* harmony export */ }); +/* harmony import */ var _pipelines_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pipelines.js */ "./src/pipelines.js"); +/* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./env.js */ "./src/env.js"); +/* harmony import */ var _models_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./models.js */ "./src/models.js"); +/* harmony import */ var _tokenizers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./tokenizers.js */ "./src/tokenizers.js"); +/* harmony import */ var _processors_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./processors.js */ "./src/processors.js"); +/* harmony import */ var _configs_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./configs.js */ "./src/configs.js"); +/* harmony import */ var _utils_audio_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./utils/audio.js */ "./src/utils/audio.js"); +/* harmony import */ var _utils_image_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils/image.js */ "./src/utils/image.js"); +/* harmony import */ var _utils_tensor_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./utils/tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _utils_maths_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./utils/maths.js */ "./src/utils/maths.js"); +/** + * @file Entry point for the Transformers.js library. Only the exports from this file + * are available to the end user, and are grouped as follows: + * + * 1. [Pipelines](./pipelines) + * 2. [Environment variables](./env) + * 3. [Models](./models) + * 4. [Tokenizers](./tokenizers) + * 5. [Processors](./processors) + * + * @module transformers + */ + + + + + + + + + + + + + + +/***/ }), + +/***/ "./src/utils/audio.js": +/*!****************************!*\ + !*** ./src/utils/audio.js ***! + \****************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "hanning": () => (/* binding */ hanning), +/* harmony export */ "mel_filter_bank": () => (/* binding */ mel_filter_bank), +/* harmony export */ "read_audio": () => (/* binding */ read_audio), +/* harmony export */ "spectrogram": () => (/* binding */ spectrogram), +/* harmony export */ "window_function": () => (/* binding */ window_function) +/* harmony export */ }); +/* harmony import */ var _hub_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hub.js */ "./src/utils/hub.js"); +/* harmony import */ var _maths_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./maths.js */ "./src/utils/maths.js"); +/* harmony import */ var _core_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./core.js */ "./src/utils/core.js"); +/** + * @file Helper module for audio processing. + * + * These functions and classes are only used internally, + * meaning an end-user shouldn't need to access anything here. + * + * @module utils/audio + */ + + + + + + +/** + * Helper function to read audio from a path/URL. + * @param {string|URL} url The path/URL to load the audio from. + * @param {number} sampling_rate The sampling rate to use when decoding the audio. + * @returns {Promise} The decoded audio as a `Float32Array`. + */ +async function read_audio(url, sampling_rate) { + if (typeof AudioContext === 'undefined') { + // Running in node or an environment without AudioContext + throw Error( + "Unable to load audio from path/URL since `AudioContext` is not available in your environment. " + + "Instead, audio data should be passed directly to the pipeline/processor. " + + "For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing." + ) + } + + const response = await (await (0,_hub_js__WEBPACK_IMPORTED_MODULE_0__.getFile)(url)).arrayBuffer(); + const audioCTX = new AudioContext({ sampleRate: sampling_rate }); + if (typeof sampling_rate === 'undefined') { + console.warn(`No sampling rate provided, using default of ${audioCTX.sampleRate}Hz.`) + } + const decoded = await audioCTX.decodeAudioData(response); + + /** @type {Float32Array} */ + let audio; + + // We now replicate HuggingFace's `ffmpeg_read` method: + if (decoded.numberOfChannels === 2) { + // When downmixing a stereo audio file to mono using the -ac 1 option in FFmpeg, + // the audio signal is summed across both channels to create a single mono channel. + // However, if the audio is at full scale (i.e. the highest possible volume level), + // the summing of the two channels can cause the audio signal to clip or distort. + + // To prevent this clipping, FFmpeg applies a scaling factor of 1/sqrt(2) (~ 0.707) + // to the audio signal before summing the two channels. This scaling factor ensures + // that the combined audio signal will not exceed the maximum possible level, even + // if both channels are at full scale. + + // After applying this scaling factor, the audio signal from both channels is summed + // to create a single mono channel. It's worth noting that this scaling factor is + // only applied when downmixing stereo audio to mono using the -ac 1 option in FFmpeg. + // If you're using a different downmixing method, or if you're not downmixing the + // audio at all, this scaling factor may not be needed. + const SCALING_FACTOR = Math.sqrt(2); + + const left = decoded.getChannelData(0); + const right = decoded.getChannelData(1); + + audio = new Float32Array(left.length); + for (let i = 0; i < decoded.length; ++i) { + audio[i] = SCALING_FACTOR * (left[i] + right[i]) / 2; + } + + } else { + // If the audio is not stereo, we can just use the first channel: + audio = decoded.getChannelData(0); + } + + return audio; +} + +/** + * Generates a Hanning window of length M. + * + * @param {number} M The length of the Hanning window to generate. + * @returns {Float64Array} The generated Hanning window. + */ +function hanning(M) { + if (M < 1) { + return new Float64Array(); + } + if (M === 1) { + return new Float64Array([1]); + } + const denom = M - 1; + const factor = Math.PI / denom; + const cos_vals = new Float64Array(M); + for (let i = 0; i < M; ++i) { + const n = 2 * i - denom; + cos_vals[i] = 0.5 + 0.5 * Math.cos(factor * n); + } + return cos_vals; +} + +const HERTZ_TO_MEL_MAPPING = { + "htk": (/** @type {number} */ freq) => 2595.0 * Math.log10(1.0 + (freq / 700.0)), + "kaldi": (/** @type {number} */ freq) => 1127.0 * Math.log(1.0 + (freq / 700.0)), + "slaney": (/** @type {number} */ freq, min_log_hertz = 1000.0, min_log_mel = 15.0, logstep = 27.0 / Math.log(6.4)) => + freq >= min_log_hertz + ? min_log_mel + Math.log(freq / min_log_hertz) * logstep + : 3.0 * freq / 200.0, +} + +/** + * @template {Float32Array|Float64Array|number} T + * @param {T} freq + * @param {string} [mel_scale] + * @returns {T} + */ +function hertz_to_mel(freq, mel_scale = "htk") { + const fn = HERTZ_TO_MEL_MAPPING[mel_scale]; + if (!fn) { + throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".'); + } + + return typeof freq === 'number' ? fn(freq) : freq.map(x => fn(x)); +} + +const MEL_TO_HERTZ_MAPPING = { + "htk": (/** @type {number} */ mels) => 700.0 * (10.0 ** (mels / 2595.0) - 1.0), + "kaldi": (/** @type {number} */ mels) => 700.0 * (Math.exp(mels / 1127.0) - 1.0), + "slaney": (/** @type {number} */ mels, min_log_hertz = 1000.0, min_log_mel = 15.0, logstep = Math.log(6.4) / 27.0) => mels >= min_log_mel + ? min_log_hertz * Math.exp(logstep * (mels - min_log_mel)) + : 200.0 * mels / 3.0, +} + +/** + * @template {Float32Array|Float64Array|number} T + * @param {T} mels + * @param {string} [mel_scale] + * @returns {T} + */ +function mel_to_hertz(mels, mel_scale = "htk") { + const fn = MEL_TO_HERTZ_MAPPING[mel_scale]; + if (!fn) { + throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".'); + } + + return typeof mels === 'number' ? fn(mels) : mels.map(x => fn(x)); +} + +/** +* Creates a triangular filter bank. +* +* Adapted from torchaudio and librosa. +* +* @param {Float64Array} fft_freqs Discrete frequencies of the FFT bins in Hz, of shape `(num_frequency_bins,)`. +* @param {Float64Array} filter_freqs Center frequencies of the triangular filters to create, in Hz, of shape `(num_mel_filters,)`. +* @returns {number[][]} of shape `(num_frequency_bins, num_mel_filters)`. +*/ +function _create_triangular_filter_bank(fft_freqs, filter_freqs) { + const filter_diff = Float64Array.from( + { length: filter_freqs.length - 1 }, + (_, i) => filter_freqs[i + 1] - filter_freqs[i] + ); + + const slopes = Array.from({ + length: fft_freqs.length + }, () => new Array(filter_freqs.length)); + + for (let j = 0; j < fft_freqs.length; ++j) { + const slope = slopes[j]; + for (let i = 0; i < filter_freqs.length; ++i) { + slope[i] = filter_freqs[i] - fft_freqs[j]; + } + } + + const numFreqs = filter_freqs.length - 2; + const ret = Array.from({ length: numFreqs }, () => new Array(fft_freqs.length)); + + for (let j = 0; j < fft_freqs.length; ++j) { // 201 + const slope = slopes[j]; + for (let i = 0; i < numFreqs; ++i) { // 80 + const down = -slope[i] / filter_diff[i]; + const up = slope[i + 2] / filter_diff[i + 1]; + ret[i][j] = Math.max(0, Math.min(down, up)); + } + } + return ret; +} + +/** + * Return evenly spaced numbers over a specified interval. + * @param {number} start The starting value of the sequence. + * @param {number} end The end value of the sequence. + * @param {number} num Number of samples to generate. + * @returns `num` evenly spaced samples, calculated over the interval `[start, stop]`. + */ +function linspace(start, end, num) { + const step = (end - start) / (num - 1); + return Float64Array.from({ length: num }, (_, i) => start + step * i); +} + +/** + * Creates a frequency bin conversion matrix used to obtain a mel spectrogram. This is called a *mel filter bank*, and + * various implementation exist, which differ in the number of filters, the shape of the filters, the way the filters + * are spaced, the bandwidth of the filters, and the manner in which the spectrum is warped. The goal of these + * features is to approximate the non-linear human perception of the variation in pitch with respect to the frequency. + * @param {number} num_frequency_bins Number of frequencies used to compute the spectrogram (should be the same as in `stft`). + * @param {number} num_mel_filters Number of mel filters to generate. + * @param {number} min_frequency Lowest frequency of interest in Hz. + * @param {number} max_frequency Highest frequency of interest in Hz. This should not exceed `sampling_rate / 2`. + * @param {number} sampling_rate Sample rate of the audio waveform. + * @param {string} [norm] If `"slaney"`, divide the triangular mel weights by the width of the mel band (area normalization). + * @param {string} [mel_scale] The mel frequency scale to use, `"htk"` or `"slaney"`. + * @param {boolean} [triangularize_in_mel_space] If this option is enabled, the triangular filter is applied in mel space rather than frequency space. + * This should be set to `true` in order to get the same results as `torchaudio` when computing mel filters. + * @returns {number[][]} Triangular filter bank matrix, which is a 2D array of shape (`num_frequency_bins`, `num_mel_filters`). + * This is a projection matrix to go from a spectrogram to a mel spectrogram. + */ +function mel_filter_bank( + num_frequency_bins, + num_mel_filters, + min_frequency, + max_frequency, + sampling_rate, + norm = null, + mel_scale = "htk", + triangularize_in_mel_space = false, +) { + if (norm !== null && norm !== "slaney") { + throw new Error('norm must be one of null or "slaney"'); + } + + const mel_min = hertz_to_mel(min_frequency, mel_scale); + const mel_max = hertz_to_mel(max_frequency, mel_scale); + const mel_freqs = linspace(mel_min, mel_max, num_mel_filters + 2); + + let filter_freqs = mel_to_hertz(mel_freqs, mel_scale); + let fft_freqs; // frequencies of FFT bins in Hz + + if (triangularize_in_mel_space) { + const fft_bin_width = sampling_rate / (num_frequency_bins * 2); + fft_freqs = hertz_to_mel(Float64Array.from({ length: num_frequency_bins }, (_, i) => i * fft_bin_width), mel_scale); + filter_freqs = mel_freqs; + } else { + fft_freqs = linspace(0, Math.floor(sampling_rate / 2), num_frequency_bins); + } + + const mel_filters = _create_triangular_filter_bank(fft_freqs, filter_freqs); + + if (norm !== null && norm === "slaney") { + // Slaney-style mel is scaled to be approx constant energy per channel + for (let i = 0; i < num_mel_filters; ++i) { + const filter = mel_filters[i]; + const enorm = 2.0 / (filter_freqs[i + 2] - filter_freqs[i]); + for (let j = 0; j < num_frequency_bins; ++j) { + // Apply this enorm to all frequency bins + filter[j] *= enorm; + } + } + } + + // TODO warn if there is a zero row + + return mel_filters; + +} + +/** + * @template {Float32Array|Float64Array} T + * Pads an array with a reflected version of itself on both ends. + * @param {T} array The array to pad. + * @param {number} left The amount of padding to add to the left. + * @param {number} right The amount of padding to add to the right. + * @returns {T} The padded array. + */ +function padReflect(array, left, right) { + // @ts-ignore + const padded = new array.constructor(array.length + left + right); + const w = array.length - 1; + + for (let i = 0; i < array.length; ++i) { + padded[left + i] = array[i]; + } + + for (let i = 1; i <= left; ++i) { + padded[left - i] = array[(0,_core_js__WEBPACK_IMPORTED_MODULE_2__.calculateReflectOffset)(i, w)]; + } + + for (let i = 1; i <= right; ++i) { + padded[w + left + i] = array[(0,_core_js__WEBPACK_IMPORTED_MODULE_2__.calculateReflectOffset)(w - i, w)]; + } + + return padded; +} + +/** + * Helper function to compute `amplitude_to_db` and `power_to_db`. + * @template {Float32Array|Float64Array} T + * @param {T} spectrogram + * @param {number} factor + * @param {number} reference + * @param {number} min_value + * @param {number} db_range + * @returns {T} + */ +function _db_conversion_helper(spectrogram, factor, reference, min_value, db_range) { + if (reference <= 0) { + throw new Error('reference must be greater than zero'); + } + + if (min_value <= 0) { + throw new Error('min_value must be greater than zero'); + } + + reference = Math.max(min_value, reference); + + const logReference = Math.log10(reference); + for (let i = 0; i < spectrogram.length; ++i) { + spectrogram[i] = factor * Math.log10(Math.max(min_value, spectrogram[i]) - logReference) + } + + if (db_range !== null) { + if (db_range <= 0) { + throw new Error('db_range must be greater than zero'); + } + const maxValue = (0,_maths_js__WEBPACK_IMPORTED_MODULE_1__.max)(spectrogram)[0] - db_range; + for (let i = 0; i < spectrogram.length; ++i) { + spectrogram[i] = Math.max(spectrogram[i], maxValue); + } + } + + return spectrogram; +} + +/** + * Converts an amplitude spectrogram to the decibel scale. This computes `20 * log10(spectrogram / reference)`, + * using basic logarithm properties for numerical stability. NOTE: Operates in-place. + * + * The motivation behind applying the log function on the (mel) spectrogram is that humans do not hear loudness on a + * linear scale. Generally to double the perceived volume of a sound we need to put 8 times as much energy into it. + * This means that large variations in energy may not sound all that different if the sound is loud to begin with. + * This compression operation makes the (mel) spectrogram features match more closely what humans actually hear. + * + * @template {Float32Array|Float64Array} T + * @param {T} spectrogram The input amplitude (mel) spectrogram. + * @param {number} [reference=1.0] Sets the input spectrogram value that corresponds to 0 dB. + * For example, use `np.max(spectrogram)` to set the loudest part to 0 dB. Must be greater than zero. + * @param {number} [min_value=1e-5] The spectrogram will be clipped to this minimum value before conversion to decibels, + * to avoid taking `log(0)`. The default of `1e-5` corresponds to a minimum of -100 dB. Must be greater than zero. + * @param {number} [db_range=null] Sets the maximum dynamic range in decibels. For example, if `db_range = 80`, the + * difference between the peak value and the smallest value will never be more than 80 dB. Must be greater than zero. + * @returns {T} The modified spectrogram in decibels. + */ +function amplitude_to_db(spectrogram, reference = 1.0, min_value = 1e-5, db_range = null) { + return _db_conversion_helper(spectrogram, 20.0, reference, min_value, db_range); +} + +/** + * Converts a power spectrogram to the decibel scale. This computes `10 * log10(spectrogram / reference)`, + * using basic logarithm properties for numerical stability. NOTE: Operates in-place. + * + * The motivation behind applying the log function on the (mel) spectrogram is that humans do not hear loudness on a + * linear scale. Generally to double the perceived volume of a sound we need to put 8 times as much energy into it. + * This means that large variations in energy may not sound all that different if the sound is loud to begin with. + * This compression operation makes the (mel) spectrogram features match more closely what humans actually hear. + * + * Based on the implementation of `librosa.power_to_db`. + * + * @template {Float32Array|Float64Array} T + * @param {T} spectrogram The input power (mel) spectrogram. Note that a power spectrogram has the amplitudes squared! + * @param {number} [reference=1.0] Sets the input spectrogram value that corresponds to 0 dB. + * For example, use `np.max(spectrogram)` to set the loudest part to 0 dB. Must be greater than zero. + * @param {number} [min_value=1e-10] The spectrogram will be clipped to this minimum value before conversion to decibels, + * to avoid taking `log(0)`. The default of `1e-10` corresponds to a minimum of -100 dB. Must be greater than zero. + * @param {number} [db_range=null] Sets the maximum dynamic range in decibels. For example, if `db_range = 80`, the + * difference between the peak value and the smallest value will never be more than 80 dB. Must be greater than zero. + * @returns {T} The modified spectrogram in decibels. + */ +function power_to_db(spectrogram, reference = 1.0, min_value = 1e-10, db_range = null) { + return _db_conversion_helper(spectrogram, 10.0, reference, min_value, db_range); +} + +/** + * Calculates a spectrogram over one waveform using the Short-Time Fourier Transform. + * + * This function can create the following kinds of spectrograms: + * - amplitude spectrogram (`power = 1.0`) + * - power spectrogram (`power = 2.0`) + * - complex-valued spectrogram (`power = None`) + * - log spectrogram (use `log_mel` argument) + * - mel spectrogram (provide `mel_filters`) + * - log-mel spectrogram (provide `mel_filters` and `log_mel`) + * + * In this implementation, the window is assumed to be zero-padded to have the same size as the analysis frame. + * A padded window can be obtained from `window_function()`. The FFT input buffer may be larger than the analysis frame, + * typically the next power of two. + * + * @param {Float32Array|Float64Array} waveform The input waveform of shape `(length,)`. This must be a single real-valued, mono waveform. + * @param {Float32Array|Float64Array} window The windowing function to apply of shape `(frame_length,)`, including zero-padding if necessary. The actual window length may be + * shorter than `frame_length`, but we're assuming the array has already been zero-padded. + * @param {number} frame_length The length of the analysis frames in samples (a.k.a., `fft_length`). + * @param {number} hop_length The stride between successive analysis frames in samples. + * @param {Object} options + * @param {number} [options.fft_length=null] The size of the FFT buffer in samples. This determines how many frequency bins the spectrogram will have. + * For optimal speed, this should be a power of two. If `null`, uses `frame_length`. + * @param {number} [options.power=1.0] If 1.0, returns the amplitude spectrogram. If 2.0, returns the power spectrogram. If `null`, returns complex numbers. + * @param {boolean} [options.center=true] Whether to pad the waveform so that frame `t` is centered around time `t * hop_length`. If `false`, frame + * `t` will start at time `t * hop_length`. + * @param {string} [options.pad_mode="reflect"] Padding mode used when `center` is `true`. Possible values are: `"constant"` (pad with zeros), + * `"edge"` (pad with edge values), `"reflect"` (pads with mirrored values). + * @param {boolean} [options.onesided=true] If `true`, only computes the positive frequencies and returns a spectrogram containing `fft_length // 2 + 1` + * frequency bins. If `false`, also computes the negative frequencies and returns `fft_length` frequency bins. + * @param {number} [options.preemphasis=null] Coefficient for a low-pass filter that applies pre-emphasis before the DFT. + * @param {number[][]} [options.mel_filters=null] The mel filter bank of shape `(num_freq_bins, num_mel_filters)`. + * If supplied, applies this filter bank to create a mel spectrogram. + * @param {number} [options.mel_floor=1e-10] Minimum value of mel frequency banks. + * @param {string} [options.log_mel=null] How to convert the spectrogram to log scale. Possible options are: + * `null` (don't convert), `"log"` (take the natural logarithm) `"log10"` (take the base-10 logarithm), `"dB"` (convert to decibels). + * Can only be used when `power` is not `null`. + * @param {number} [options.reference=1.0] Sets the input spectrogram value that corresponds to 0 dB. For example, use `max(spectrogram)[0]` to set + * the loudest part to 0 dB. Must be greater than zero. + * @param {number} [options.min_value=1e-10] The spectrogram will be clipped to this minimum value before conversion to decibels, to avoid taking `log(0)`. + * For a power spectrogram, the default of `1e-10` corresponds to a minimum of -100 dB. For an amplitude spectrogram, the value `1e-5` corresponds to -100 dB. + * Must be greater than zero. + * @param {number} [options.db_range=null] Sets the maximum dynamic range in decibels. For example, if `db_range = 80`, the difference between the + * peak value and the smallest value will never be more than 80 dB. Must be greater than zero. + * @param {boolean} [options.remove_dc_offset=null] Subtract mean from waveform on each frame, applied before pre-emphasis. This should be set to `true` in + * order to get the same results as `torchaudio.compliance.kaldi.fbank` when computing mel filters. + * @param {number} [options.max_num_frames=null] If provided, limits the number of frames to compute to this value. + * @param {boolean} [options.do_pad=true] If `true`, pads the output spectrogram to have `max_num_frames` frames. + * @param {boolean} [options.transpose=false] If `true`, the returned spectrogram will have shape `(num_frames, num_frequency_bins/num_mel_filters)`. If `false`, the returned spectrogram will have shape `(num_frequency_bins/num_mel_filters, num_frames)`. + * @returns {{data: Float32Array, dims: number[]}} Spectrogram of shape `(num_frequency_bins, length)` (regular spectrogram) or shape `(num_mel_filters, length)` (mel spectrogram). + */ +function spectrogram( + waveform, + window, + frame_length, + hop_length, + { + fft_length = null, + power = 1.0, + center = true, + pad_mode = "reflect", + onesided = true, + preemphasis = null, + mel_filters = null, + mel_floor = 1e-10, + log_mel = null, + reference = 1.0, + min_value = 1e-10, + db_range = null, + remove_dc_offset = null, + + // Custom parameters for efficiency reasons + max_num_frames = null, + do_pad = true, + transpose = false, + } = {} +) { + const window_length = window.length; + if (fft_length === null) { + fft_length = frame_length; + } + if (frame_length > fft_length) { + throw Error(`frame_length (${frame_length}) may not be larger than fft_length (${fft_length})`) + } + + if (window_length !== frame_length) { + throw new Error(`Length of the window (${window_length}) must equal frame_length (${frame_length})`); + } + + if (hop_length <= 0) { + throw new Error("hop_length must be greater than zero"); + } + + if (center) { + if (pad_mode !== 'reflect') { + throw new Error(`pad_mode="${pad_mode}" not implemented yet.`) + } + const half_window = Math.floor((fft_length - 1) / 2) + 1; + waveform = padReflect(waveform, half_window, half_window); + } + + // split waveform into frames of frame_length size + const num_frames = Math.floor(1 + Math.floor((waveform.length - frame_length) / hop_length)) + + const num_frequency_bins = onesided ? Math.floor(fft_length / 2) + 1 : fft_length + + let d1 = num_frames; + let d1Max = num_frames; + + // If maximum number of frames is provided, we must either pad or truncate + if (max_num_frames !== null) { + if (max_num_frames > num_frames) { // input is too short, so we pad + if (do_pad) { + d1Max = max_num_frames; + } + } else { // input is too long, so we truncate + d1Max = d1 = max_num_frames; + } + } + + // Preallocate arrays to store output. + const fft = new _maths_js__WEBPACK_IMPORTED_MODULE_1__.FFT(fft_length); + const inputBuffer = new Float64Array(fft_length); + const outputBuffer = new Float64Array(fft.outputBufferSize); + const magnitudes = new Array(d1); + + for (let i = 0; i < d1; ++i) { + // Populate buffer with waveform data + const offset = i * hop_length; + for (let j = 0; j < frame_length; ++j) { + inputBuffer[j] = waveform[offset + j]; + } + + if (remove_dc_offset) { + let sum = 0; + for (let j = 0; j < frame_length; ++j) { + sum += inputBuffer[j]; + } + const mean = sum / frame_length; + for (let j = 0; j < frame_length; ++j) { + inputBuffer[j] -= mean; + } + } + + if (preemphasis !== null) { + // Done in reverse to avoid copies and distructive modification + for (let j = frame_length - 1; j >= 1; --j) { + inputBuffer[j] -= preemphasis * inputBuffer[j - 1]; + } + inputBuffer[0] *= 1 - preemphasis; + } + + for (let j = 0; j < window.length; ++j) { + inputBuffer[j] *= window[j]; + } + + fft.realTransform(outputBuffer, inputBuffer); + + // compute magnitudes + const row = new Array(num_frequency_bins); + for (let j = 0; j < row.length; ++j) { + const j2 = j << 1; + row[j] = outputBuffer[j2] ** 2 + outputBuffer[j2 + 1] ** 2; + } + magnitudes[i] = row; + } + + // TODO what should happen if power is None? + // https://github.com/huggingface/transformers/issues/27772 + if (power !== null && power !== 2) { + // slight optimization to not sqrt + const pow = 2 / power; // we use 2 since we already squared + for (let i = 0; i < magnitudes.length; ++i) { + const magnitude = magnitudes[i]; + for (let j = 0; j < magnitude.length; ++j) { + magnitude[j] **= pow; + } + } + } + + // TODO: What if `mel_filters` is null? + const num_mel_filters = mel_filters.length; + + // Only here do we create Float32Array + const mel_spec = new Float32Array(num_mel_filters * d1Max); + + // Perform matrix muliplication: + // mel_spec = mel_filters @ magnitudes.T + // - mel_filters.shape=(80, 201) + // - magnitudes.shape=(3000, 201) => - magnitudes.T.shape=(201, 3000) + // - mel_spec.shape=(80, 3000) + const dims = transpose ? [d1Max, num_mel_filters] : [num_mel_filters, d1Max]; + for (let i = 0; i < num_mel_filters; ++i) { // num melfilters (e.g., 80) + const filter = mel_filters[i]; + for (let j = 0; j < d1; ++j) { // num frames (e.g., 3000) + const magnitude = magnitudes[j]; + + let sum = 0; + for (let k = 0; k < num_frequency_bins; ++k) { // num frequency bins (e.g., 201) + sum += filter[k] * magnitude[k]; + } + + mel_spec[ + transpose + ? j * num_mel_filters + i + : i * d1 + j + ] = Math.max(mel_floor, sum); + } + } + + if (power !== null && log_mel !== null) { + const o = Math.min(mel_spec.length, d1 * num_mel_filters); + switch (log_mel) { + case 'log': + for (let i = 0; i < o; ++i) { + mel_spec[i] = Math.log(mel_spec[i]); + } + break; + case 'log10': + for (let i = 0; i < o; ++i) { + mel_spec[i] = Math.log10(mel_spec[i]); + } + break; + case 'dB': + if (power === 1.0) { + // NOTE: operates in-place + amplitude_to_db(mel_spec, reference, min_value, db_range); + } else if (power === 2.0) { + power_to_db(mel_spec, reference, min_value, db_range); + } else { + throw new Error(`Cannot use log_mel option '${log_mel}' with power ${power}`) + } + break; + default: + throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${log_mel}'`); + } + } + + return { data: mel_spec, dims }; +} + +/** + * Returns an array containing the specified window. + * @param {number} window_length The length of the window in samples. + * @param {string} name The name of the window function. + * @param {Object} options Additional options. + * @param {boolean} [options.periodic=true] Whether the window is periodic or symmetric. + * @param {number} [options.frame_length=null] The length of the analysis frames in samples. + * Provide a value for `frame_length` if the window is smaller than the frame length, so that it will be zero-padded. + * @param {boolean} [options.center=true] Whether to center the window inside the FFT buffer. Only used when `frame_length` is provided. + * @returns {Float64Array} The window of shape `(window_length,)` or `(frame_length,)`. + */ +function window_function(window_length, name, { + periodic = true, + frame_length = null, + center = true, +} = {}) { + const length = periodic ? window_length + 1 : window_length; + let window; + switch (name) { + case 'boxcar': + window = new Float64Array(length).fill(1.0); + break; + case 'hann': + case 'hann_window': + window = hanning(length); + break; + case 'povey': + window = hanning(length).map(x => Math.pow(x, 0.85)); + break; + default: + throw new Error(`Unknown window type ${name}.`); + } + if (periodic) { + window = window.subarray(0, window_length); + } + if (frame_length === null) { + return window; + } + if (window_length > frame_length) { + throw new Error(`Length of the window (${window_length}) may not be larger than frame_length (${frame_length})`); + } + + return window; +} + + +/***/ }), + +/***/ "./src/utils/core.js": +/*!***************************!*\ + !*** ./src/utils/core.js ***! + \***************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "Callable": () => (/* binding */ Callable), +/* harmony export */ "calculateDimensions": () => (/* binding */ calculateDimensions), +/* harmony export */ "calculateReflectOffset": () => (/* binding */ calculateReflectOffset), +/* harmony export */ "dispatchCallback": () => (/* binding */ dispatchCallback), +/* harmony export */ "escapeRegExp": () => (/* binding */ escapeRegExp), +/* harmony export */ "exists": () => (/* binding */ exists), +/* harmony export */ "isIntegralNumber": () => (/* binding */ isIntegralNumber), +/* harmony export */ "isTypedArray": () => (/* binding */ isTypedArray), +/* harmony export */ "mergeArrays": () => (/* binding */ mergeArrays), +/* harmony export */ "pop": () => (/* binding */ pop), +/* harmony export */ "product": () => (/* binding */ product), +/* harmony export */ "reverseDictionary": () => (/* binding */ reverseDictionary) +/* harmony export */ }); + +/** + * @file Core utility functions/classes for Transformers.js. + * + * These are only used internally, meaning an end-user shouldn't + * need to access anything here. + * + * @module utils/core + */ + +/** + * Helper function to dispatch progress callbacks. + * + * @param {Function} progress_callback The progress callback function to dispatch. + * @param {any} data The data to pass to the progress callback function. + * @returns {void} + * @private + */ +function dispatchCallback(progress_callback, data) { + if (progress_callback) progress_callback(data); +} + +/** + * Reverses the keys and values of an object. + * + * @param {Object} data The object to reverse. + * @returns {Object} The reversed object. + * @see https://ultimatecourses.com/blog/reverse-object-keys-and-values-in-javascript + */ +function reverseDictionary(data) { + // https://ultimatecourses.com/blog/reverse-object-keys-and-values-in-javascript + return Object.fromEntries(Object.entries(data).map(([key, value]) => [value, key])); +} + +/** + * Escapes regular expression special characters from a string by replacing them with their escaped counterparts. + * + * @param {string} string The string to escape. + * @returns {string} The escaped string. + */ +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} + +/** + * A base class for creating callable objects. + * + * @type {new () => {(...args: any[]): any, _call(...args: any[]): any}} + */ +const Callable = /** @type {any} */ (class { + /** + * Creates a new instance of the Callable class. + */ + constructor() { + /** + * Creates a closure that delegates to a private method '_call' with the given arguments. + * @type {any} + * @param {...any} args Zero or more arguments to pass to the '_call' method. + * @returns {*} The result of calling the '_call' method. + */ + let closure = function (...args) { + return closure._call(...args) + } + return Object.setPrototypeOf(closure, new.target.prototype) + } + + /** + * This method should be implemented in subclasses to provide the + * functionality of the callable object. + * + * @param {any[]} args + * @throws {Error} If the subclass does not implement the `_call` method. + */ + _call(...args) { + throw Error('Must implement _call method in subclass') + } +}); + +/** + * Check if a value is a typed array. + * @param {*} val The value to check. + * @returns {boolean} True if the value is a `TypedArray`, false otherwise. + * + * Adapted from https://stackoverflow.com/a/71091338/13989043 + */ +function isTypedArray(val) { + return val?.prototype?.__proto__?.constructor?.name === 'TypedArray'; +} + + +/** + * Check if a value is an integer. + * @param {*} x The value to check. + * @returns {boolean} True if the value is a string, false otherwise. + */ +function isIntegralNumber(x) { + return Number.isInteger(x) || typeof x === 'bigint' +} + +/** + * Check if a value is exists. + * @param {*} x The value to check. + * @returns {boolean} True if the value exists, false otherwise. + */ +function exists(x) { + return x !== undefined && x !== null; +} + +/** + * Calculates the dimensions of a nested array. + * + * @param {any[]} arr The nested array to calculate dimensions for. + * @returns {number[]} An array containing the dimensions of the input array. + */ +function calculateDimensions(arr) { + const dimensions = []; + let current = arr; + while (Array.isArray(current)) { + dimensions.push(current.length); + current = current[0]; + } + return dimensions; +} + +/** + * Replicate python's .pop() method for objects. + * @param {Object} obj The object to pop from. + * @param {string} key The key to pop. + * @param {*} defaultValue The default value to return if the key does not exist. + * @returns {*} The value of the popped key. + * @throws {Error} If the key does not exist and no default value is provided. + */ +function pop(obj, key, defaultValue = undefined) { + const value = obj[key]; + if (value !== undefined) { + delete obj[key]; + return value; + } + if (defaultValue === undefined) { + throw Error(`Key ${key} does not exist in object.`) + } + return defaultValue; +} + +/** + * Efficiently merge arrays, creating a new copy. + * Adapted from https://stackoverflow.com/a/6768642/13989043 + * @param {Array[]} arrs Arrays to merge. + * @returns {Array} The merged array. + */ +function mergeArrays(...arrs) { + return Array.prototype.concat.apply([], arrs); +} + +/** + * Compute the Cartesian product of given arrays + * @param {...Array} a Arrays to compute the product + * @returns {Array} Returns the computed Cartesian product as an array + * @private + */ +function product(...a) { + // Cartesian product of items + // Adapted from https://stackoverflow.com/a/43053803 + return a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e]))); +} + +/** + * Calculates the index offset for a given index and window size. + * @param {number} i The index. + * @param {number} w The window size. + * @returns {number} The index offset. + */ +function calculateReflectOffset(i, w) { + return Math.abs((i + w) % (2 * w) - w); +} + + +/***/ }), + +/***/ "./src/utils/data-structures.js": +/*!**************************************!*\ + !*** ./src/utils/data-structures.js ***! + \**************************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "CharTrie": () => (/* binding */ CharTrie), +/* harmony export */ "PriorityQueue": () => (/* binding */ PriorityQueue), +/* harmony export */ "TokenLattice": () => (/* binding */ TokenLattice) +/* harmony export */ }); + +/** + * @file Custom data structures. + * + * These are only used internally, meaning an end-user shouldn't + * need to access anything here. + * + * @module utils/data-structures + */ + + +/** + * Efficient Heap-based Implementation of a Priority Queue. + * It uses an array-based binary heap, where the root is at index `0`, and the + * children of node `i` are located at indices `2i + 1` and `2i + 2`, respectively. + * + * Adapted from the following sources: + * - https://stackoverflow.com/a/42919752/13989043 (original) + * - https://github.com/belladoreai/llama-tokenizer-js (minor improvements) + */ +class PriorityQueue { + + /** + * Create a new PriorityQueue. + * @param {Function} comparator Comparator function to determine priority. Defaults to a MaxHeap. + */ + constructor(comparator = (a, b) => a > b) { + this._heap = []; + this._comparator = comparator; + } + + /** + * The size of the queue + */ + get size() { + return this._heap.length; + } + + /** + * Check if the queue is empty. + * @returns {boolean} `true` if the queue is empty, `false` otherwise. + */ + isEmpty() { + return this.size === 0; + } + + /** + * Return the element with the highest priority in the queue. + * @returns {any} The highest priority element in the queue. + */ + peek() { + return this._heap[0]; + } + + /** + * Add one or more elements to the queue. + * @param {...any} values The values to push into the queue. + * @returns {number} The new size of the queue. + */ + push(...values) { + return this.extend(values); + } + + /** + * Add multiple elements to the queue. + * @param {any[]} values The values to push into the queue. + * @returns {number} The new size of the queue. + */ + extend(values) { + for (const value of values) { + this._heap.push(value); + this._siftUp(); + } + return this.size; + } + + /** + * Remove and return the element with the highest priority in the queue. + * @returns {any} The element with the highest priority in the queue. + */ + pop() { + const poppedValue = this.peek(); + const bottom = this.size - 1; + if (bottom > 0) { + this._swap(0, bottom); + } + this._heap.pop(); + this._siftDown(); + return poppedValue; + } + + /** + * Replace the element with the highest priority in the queue with a new value. + * @param {*} value The new value. + * @returns {*} The replaced value. + */ + replace(value) { + const replacedValue = this.peek(); + this._heap[0] = value; + this._siftDown(); + return replacedValue; + } + + /** + * Compute the index for the parent of the node at index `i`. + * @param {number} i The index of the node to get the parent of. + * @returns {number} The index of the parent node. + * @private + */ + _parent(i) { + return ((i + 1) >>> 1) - 1; + } + + /** + * Compute the index for the left child of the node at index `i`. + * @param {number} i The index of the node to get the left child of. + * @returns {number} The index of the left child. + * @private + */ + _left(i) { + return (i << 1) + 1; + } + + /** + * Compute the index for the right child of the node at index `i`. + * @param {number} i The index of the node to get the right child of. + * @returns {number} The index of the right child. + * @private + */ + _right(i) { + return (i + 1) << 1; + } + + /** + * Check if the element at index `i` is greater than the element at index `j`. + * @param {number} i The index of the first element to compare. + * @param {number} j The index of the second element to compare. + * @returns {boolean} `true` if the element at index `i` is greater than the element at index `j`, `false` otherwise. + * @private + */ + _greater(i, j) { + return this._comparator(this._heap[i], this._heap[j]); + } + + /** + * Swap the elements at indices `i` and `j`. + * @param {number} i The index of the first element to swap. + * @param {number} j The index of the second element to swap. + * @private + */ + _swap(i, j) { + const temp = this._heap[i]; + this._heap[i] = this._heap[j]; + this._heap[j] = temp; + } + + /** + * Maintain the heap property by updating positions in the heap, + * starting at the last element and moving up the heap. + * @private + */ + _siftUp() { + let node = this.size - 1; + while (node > 0 && this._greater(node, this._parent(node))) { + this._swap(node, this._parent(node)); + node = this._parent(node); + } + } + /** + * Maintain the heap property by updating positions in the heap, + * starting at the first element and moving down the heap. + * @private + */ + _siftDown() { + let node = 0; + while ( + (this._left(node) < this.size && this._greater(this._left(node), node)) || + (this._right(node) < this.size && this._greater(this._right(node), node)) + ) { + const maxChild = (this._right(node) < this.size && this._greater(this._right(node), this._left(node))) + ? this._right(node) + : this._left(node); + this._swap(node, maxChild); + node = maxChild; + } + } +} + +/** + * A trie structure to efficiently store and search for strings. + */ +class CharTrie { + constructor() { + this.root = CharTrieNode.default(); + } + + /** + * Adds one or more `texts` to the trie. + * @param {string[]} texts The strings to add to the trie. + */ + extend(texts) { + for (let text of texts) { + this.push(text); + } + } + + /** + * Adds text to the trie. + * @param {string} text The string to add to the trie. + */ + push(text) { + let node = this.root; + for (let ch of text) { + let child = node.children.get(ch); + if (child === undefined) { + child = CharTrieNode.default(); + node.children.set(ch, child); + } + node = child; + } + node.isLeaf = true; + } + + /** + * Searches the trie for all strings with a common prefix of `text`. + * @param {string} text The common prefix to search for. + * @yields {string} Each string in the trie that has `text` as a prefix. + */ + *commonPrefixSearch(text) { + let node = this.root; + let prefix = ""; + for (let i = 0; i < text.length && node !== undefined; ++i) { + const ch = text[i]; + prefix += ch; + node = node.children.get(ch); + if (node !== undefined && node.isLeaf) { + yield prefix; + } + } + } +} + +/** + * Represents a node in a character trie. + */ +class CharTrieNode { + /** + * Create a new CharTrieNode. + * @param {boolean} isLeaf Whether the node is a leaf node or not. + * @param {Map} children A map containing the node's children, where the key is a character and the value is a `CharTrieNode`. + */ + constructor(isLeaf, children) { + this.isLeaf = isLeaf; + this.children = children; + } + + /** + * Returns a new `CharTrieNode` instance with default values. + * @returns {CharTrieNode} A new `CharTrieNode` instance with `isLeaf` set to `false` and an empty `children` map. + */ + static default() { + return new CharTrieNode(false, new Map()); + } +} + +/** + * A lattice data structure to be used for tokenization. + */ +class TokenLattice { + /** + * Creates a new TokenLattice instance. + * + * @param {string} sentence The input sentence to be tokenized. + * @param {number} bosTokenId The beginning-of-sequence token ID. + * @param {number} eosTokenId The end-of-sequence token ID. + */ + constructor(sentence, bosTokenId, eosTokenId) { + this.sentence = sentence; + this.len = sentence.length; + this.bosTokenId = bosTokenId; + this.eosTokenId = eosTokenId; + this.nodes = []; + this.beginNodes = Array.from({ length: this.len + 1 }, () => []); + this.endNodes = Array.from({ length: this.len + 1 }, () => []); + + const bos = new TokenLatticeNode(this.bosTokenId, 0, 0, 0, 0.0); + const eos = new TokenLatticeNode(this.eosTokenId, 1, this.len, 0, 0.0); + this.nodes.push(bos.clone()); + this.nodes.push(eos.clone()); + this.beginNodes[this.len].push(eos); + this.endNodes[0].push(bos); + } + + /** + * Inserts a new token node into the token lattice. + * + * @param {number} pos The starting position of the token. + * @param {number} length The length of the token. + * @param {number} score The score of the token. + * @param {number} tokenId The token ID of the token. + */ + insert(pos, length, score, tokenId) { + const nodeId = this.nodes.length; + const node = new TokenLatticeNode(tokenId, nodeId, pos, length, score); + this.beginNodes[pos].push(node); + this.endNodes[pos + length].push(node); + this.nodes.push(node); + } + + /** + * Implements the Viterbi algorithm to compute the most likely sequence of tokens. + * + * @returns {TokenLatticeNode[]} The array of nodes representing the most likely sequence of tokens. + */ + viterbi() { + const len = this.len; + let pos = 0; + while (pos <= len) { + if (this.beginNodes[pos].length == 0) { + return []; + } + for (let rnode of this.beginNodes[pos]) { + rnode.prev = null; + let bestScore = 0.0; + let bestNode = null; + for (let lnode of this.endNodes[pos]) { + const score = lnode.backtraceScore + rnode.score; + if (bestNode === null || score > bestScore) { + bestNode = lnode.clone(); + bestScore = score; + } + } + + if (bestNode !== null) { + rnode.prev = bestNode; + rnode.backtraceScore = bestScore; + } else { + return []; + } + } + ++pos; + } + + const results = []; + const root = this.beginNodes[len][0]; + const prev = root.prev; + if (prev === null) { + return []; + } + + let node = prev.clone(); + while (node.prev !== null) { + results.push(node.clone()); + const n = node.clone(); + node = n.prev.clone(); + } + + results.reverse(); + return results; + } + + /** + * @param {TokenLatticeNode} node + * @returns {string} The array of nodes representing the most likely sequence of tokens. + */ + piece(node) { + return this.sentence.slice(node.pos, node.pos + node.length); + } + + /** + * @returns {Array} The array of nodes representing the most likely sequence of tokens. + */ + tokens() { + const nodes = this.viterbi(); + return nodes.map(x => this.piece(x)); + } + + /** + * @returns {Array} The array of nodes representing the most likely sequence of tokens. + */ + tokenIds() { + const nodes = this.viterbi(); + return nodes.map(x => x.tokenId); + } +} +class TokenLatticeNode { + /** + * Represents a node in a token lattice for a given sentence. + * @param {number} tokenId The ID of the token associated with this node. + * @param {number} nodeId The ID of this node. + * @param {number} pos The starting position of the token in the sentence. + * @param {number} length The length of the token. + * @param {number} score The score associated with the token. + */ + constructor(tokenId, nodeId, pos, length, score) { + this.tokenId = tokenId; + this.nodeId = nodeId; + this.pos = pos; + this.length = length; + this.score = score; + this.prev = null; + this.backtraceScore = 0.0; + } + + /** + * Returns a clone of this node. + * @returns {TokenLatticeNode} A clone of this node. + */ + clone() { + const n = new TokenLatticeNode(this.tokenId, this.nodeId, this.pos, this.length, this.score); + n.prev = this.prev; + n.backtraceScore = this.backtraceScore; + return n; + } +} + + +/***/ }), + +/***/ "./src/utils/generation.js": +/*!*********************************!*\ + !*** ./src/utils/generation.js ***! + \*********************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "ForceTokensLogitsProcessor": () => (/* binding */ ForceTokensLogitsProcessor), +/* harmony export */ "ForcedBOSTokenLogitsProcessor": () => (/* binding */ ForcedBOSTokenLogitsProcessor), +/* harmony export */ "ForcedEOSTokenLogitsProcessor": () => (/* binding */ ForcedEOSTokenLogitsProcessor), +/* harmony export */ "GenerationConfig": () => (/* binding */ GenerationConfig), +/* harmony export */ "LogitsProcessor": () => (/* binding */ LogitsProcessor), +/* harmony export */ "LogitsProcessorList": () => (/* binding */ LogitsProcessorList), +/* harmony export */ "MinLengthLogitsProcessor": () => (/* binding */ MinLengthLogitsProcessor), +/* harmony export */ "MinNewTokensLengthLogitsProcessor": () => (/* binding */ MinNewTokensLengthLogitsProcessor), +/* harmony export */ "NoBadWordsLogitsProcessor": () => (/* binding */ NoBadWordsLogitsProcessor), +/* harmony export */ "NoRepeatNGramLogitsProcessor": () => (/* binding */ NoRepeatNGramLogitsProcessor), +/* harmony export */ "RepetitionPenaltyLogitsProcessor": () => (/* binding */ RepetitionPenaltyLogitsProcessor), +/* harmony export */ "Sampler": () => (/* binding */ Sampler), +/* harmony export */ "SuppressTokensAtBeginLogitsProcessor": () => (/* binding */ SuppressTokensAtBeginLogitsProcessor), +/* harmony export */ "WhisperTimeStampLogitsProcessor": () => (/* binding */ WhisperTimeStampLogitsProcessor) +/* harmony export */ }); +/* harmony import */ var _tensor_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var _core_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./core.js */ "./src/utils/core.js"); +/* harmony import */ var _maths_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./maths.js */ "./src/utils/maths.js"); + +/** + * @file Classes, functions, and utilities for generation. + * + * @todo Describe how to create a custom `GenerationConfig`. + * + * @module utils/generation + */ + + + + +/** + * A class representing a list of logits processors. A logits processor is a function that modifies the logits + * output of a language model. This class provides methods for adding new processors and applying all processors to a + * batch of logits. + * + * @extends Callable + */ +class LogitsProcessorList extends _core_js__WEBPACK_IMPORTED_MODULE_1__.Callable { + /** + * Constructs a new instance of `LogitsProcessorList`. + */ + constructor() { + super(); + this.processors = []; + } + + /** + * Adds a new logits processor to the list. + * + * @param {LogitsProcessor} item The logits processor function to add. + */ + push(item) { + this.processors.push(item); + } + + /** + * Adds multiple logits processors to the list. + * + * @param {LogitsProcessor[]} items The logits processor functions to add. + */ + extend(items) { + this.processors.push(...items); + } + + /** + * Applies all logits processors in the list to a batch of logits, modifying them in-place. + * + * @param {number[]} input_ids The input IDs for the language model. + * @param {number[][]} batchedLogits A 2D array of logits, where each row corresponds to a single + * input sequence in the batch. + */ + _call(input_ids, batchedLogits) { + // NOTE: This is different from the Python code, since vanilla JS does not support vectorized operations. + // As a result, we apply each processor to each item in the batch. + for (let logits of batchedLogits) { + // Modifies logits inplace + this.processors.forEach( + func => func(input_ids, logits) + ) + } + } + + [Symbol.iterator]() { + return this.processors.values(); + } +} + +/** + * Base class for processing logits. + * @extends Callable + */ +class LogitsProcessor extends _core_js__WEBPACK_IMPORTED_MODULE_1__.Callable { + /** + * Apply the processor to the input logits. + * + * @abstract + * @param {Array} input_ids The input ids. + * @param {Tensor} logits The logits to process. + * @throws {Error} Throws an error if `_call` is not implemented in the subclass. + */ + _call(input_ids, logits) { + throw Error("`_call` should be implemented in a subclass") + } +} + +/** + * A logits processor that forces a specific token to be generated by the decoder. + * + * @extends LogitsProcessor + */ +class ForceTokensLogitsProcessor extends LogitsProcessor { + /** + * Constructs a new instance of `ForceTokensLogitsProcessor`. + * + * @param {Array} forced_decoder_ids The ids of tokens that should be forced. + */ + constructor(forced_decoder_ids) { + super(); + this.force_token_map = Object.fromEntries(forced_decoder_ids ?? []); + } + + /** + * Apply the processor to the input logits. + * + * @param {Array} input_ids The input ids. + * @param {Tensor} logits The logits to process. + * @returns {Tensor} The processed logits. + */ + _call(input_ids, logits) { + let map = this.force_token_map[input_ids.length]; + if ((0,_core_js__WEBPACK_IMPORTED_MODULE_1__.exists)(map)) { // There exists a mapping + logits.data.fill(-Infinity) + logits.data[map] = 0; + } + return logits; + } +} + +/** + * A LogitsProcessor that forces a BOS token at the beginning of the generated sequence. + * @extends LogitsProcessor + */ +class ForcedBOSTokenLogitsProcessor extends LogitsProcessor { + /** + * Create a ForcedBOSTokenLogitsProcessor. + * @param {number} bos_token_id The ID of the beginning-of-sequence token to be forced. + */ + constructor(bos_token_id) { + super(); + this.bos_token_id = bos_token_id; + } + + /** + * Apply the BOS token forcing to the logits. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The logits with BOS token forcing. + */ + _call(input_ids, logits) { + if (input_ids.length === 1) { + logits.data.fill(-Infinity) + logits.data[this.bos_token_id] = 0; + } + return logits; + } +} + +/** + * A logits processor that forces end-of-sequence token probability to 1. + * + * @extends LogitsProcessor + */ +class ForcedEOSTokenLogitsProcessor extends LogitsProcessor { + /** + * Create a ForcedEOSTokenLogitsProcessor. + * @param {number} max_length Max length of the sequence. + * @param {number|number[]} forced_eos_token_id The ID of the end-of-sequence token to be forced. + */ + constructor(max_length, forced_eos_token_id) { + super(); + this.max_length = max_length; + this.forced_eos_token_id = forced_eos_token_id; + } + + /** + * Apply the processor to input_ids and logits. + * + * @param {number[]} input_ids The input ids. + * @param {Tensor} logits The logits tensor. + */ + _call(input_ids, logits) { + // console.log('call ForcedEOSTokenLogitsProcessor') + // TODO + } +} + +/** + * A LogitsProcessor that suppresses a list of tokens as soon as the `generate` function starts + * generating using `begin_index` tokens. This should ensure that the tokens defined by + * `begin_suppress_tokens` at not sampled at the begining of the generation. + * @extends LogitsProcessor + */ +class SuppressTokensAtBeginLogitsProcessor extends LogitsProcessor { + /** + * Create a SuppressTokensAtBeginLogitsProcessor. + * @param {number[]} begin_suppress_tokens The IDs of the tokens to suppress. + * @param {number} begin_index The number of tokens to generate before suppressing tokens. + */ + constructor(begin_suppress_tokens, begin_index) { + super(); + this.begin_suppress_tokens = begin_suppress_tokens; + this.begin_index = begin_index; + } + + /** + * Apply the BOS token forcing to the logits. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The logits with BOS token forcing. + */ + _call(input_ids, logits) { + if (input_ids.length === this.begin_index) { + for (let token_id of this.begin_suppress_tokens) { + logits.data[token_id] = -Infinity; + } + } + return logits; + } +} + +/** + * A LogitsProcessor that handles adding timestamps to generated text. + * @extends LogitsProcessor + */ +class WhisperTimeStampLogitsProcessor extends LogitsProcessor { + /** + * Constructs a new WhisperTimeStampLogitsProcessor. + * @param {Object} generate_config The config object passed to the `generate()` method of a transformer model. + * @param {number} generate_config.eos_token_id The ID of the end-of-sequence token. + * @param {number} generate_config.no_timestamps_token_id The ID of the token used to indicate that a token should not have a timestamp. + * @param {number[][]} [generate_config.forced_decoder_ids] An array of two-element arrays representing decoder IDs that are forced to appear in the output. The second element of each array indicates whether the token is a timestamp. + * @param {number} [generate_config.max_initial_timestamp_index] The maximum index at which an initial timestamp can appear. + */ + constructor(generate_config) { + super(); + this.eos_token_id = generate_config.eos_token_id; + this.no_timestamps_token_id = generate_config.no_timestamps_token_id; + this.timestamp_begin = this.no_timestamps_token_id + 1; + + this.begin_index = (generate_config.forced_decoder_ids || []).length + 2; + if (generate_config.forced_decoder_ids.slice(-1)[0][1] === this.no_timestamps_token_id) { + this.begin_index -= 1; + } + this.max_initial_timestamp_index = generate_config.max_initial_timestamp_index; + + } + + /** + * Modify the logits to handle timestamp tokens. + * @param {Array} input_ids The input sequence of tokens. + * @param {Tensor} logits The logits output by the model. + * @returns {Tensor} The modified logits. + */ + _call(input_ids, logits) { + const logitsData = /** @type {Float32Array} */(logits.data); + + // suppress <|notimestamps|> which is handled by without_timestamps + logitsData[this.no_timestamps_token_id] = -Infinity; + + if (input_ids.length === this.begin_index - 1) { + logitsData.fill(-Infinity); + logitsData[this.timestamp_begin] = 0; + return logits; + } + + // timestamps have to appear in pairs, except directly before eos_token; mask logits accordingly + const seq = input_ids.slice(this.begin_index); + const last_was_timestamp = seq.length >= 1 && seq[seq.length - 1] >= this.timestamp_begin; + const penultimate_was_timestamp = seq.length < 2 || seq[seq.length - 2] >= this.timestamp_begin; + + if (last_was_timestamp) { + if (penultimate_was_timestamp) { // has to be non-timestamp + logitsData.subarray(this.timestamp_begin).fill(-Infinity); + } else { // cannot be normal text tokens + logitsData.subarray(0, this.eos_token_id).fill(-Infinity); + } + } + + // apply the `max_initial_timestamp` option + if (input_ids.length === this.begin_index && this.max_initial_timestamp_index !== null) { + const last_allowed = this.timestamp_begin + this.max_initial_timestamp_index; + logitsData.subarray(last_allowed + 1).fill(-Infinity); + } + + // if sum of probability over timestamps is above any other token, sample timestamp + const logprobs = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.log_softmax)(logitsData); + const timestamp_logprob = Math.log(logprobs.subarray(this.timestamp_begin).map(Math.exp).reduce((a, b) => a + b)); + const max_text_token_logprob = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(logprobs.subarray(0, this.timestamp_begin))[0]; + + if (timestamp_logprob > max_text_token_logprob) { + logitsData.subarray(0, this.timestamp_begin).fill(-Infinity); + } + + return logits; + } +} + +/** + * A logits processor that disallows ngrams of a certain size to be repeated. + * + * @extends LogitsProcessor + */ +class NoRepeatNGramLogitsProcessor extends LogitsProcessor { + /** + * Create a NoRepeatNGramLogitsProcessor. + * @param {number} no_repeat_ngram_size The no-repeat-ngram size. All ngrams of this size can only occur once. + */ + constructor(no_repeat_ngram_size) { + super(); + this.no_repeat_ngram_size = no_repeat_ngram_size; + } + + /** + * Generate n-grams from a sequence of token ids. + * @param {number[]} prevInputIds List of previous input ids + * @returns {Map} Map of generated n-grams + */ + getNgrams(prevInputIds) { + const curLen = prevInputIds.length; + + /**@type {number[][]} */ + const ngrams = []; + for (let j = 0; j < curLen + 1 - this.no_repeat_ngram_size; ++j) { + const ngram = []; + for (let k = 0; k < this.no_repeat_ngram_size; ++k) { + ngram.push(prevInputIds[j + k]); + } + ngrams.push(ngram); + } + + /** @type {Map} */ + const generatedNgram = new Map(); + for (const ngram of ngrams) { + const prevNgram = ngram.slice(0, ngram.length - 1); + const prevNgramKey = JSON.stringify(prevNgram); + const prevNgramValue = generatedNgram.get(prevNgramKey) ?? []; + prevNgramValue.push(ngram[ngram.length - 1]); + generatedNgram.set(prevNgramKey, prevNgramValue); + } + return generatedNgram; + } + + /** + * Generate n-grams from a sequence of token ids. + * @param {Map} bannedNgrams Map of banned n-grams + * @param {number[]} prevInputIds List of previous input ids + * @returns {number[]} Map of generated n-grams + */ + getGeneratedNgrams(bannedNgrams, prevInputIds) { + const ngramIdx = prevInputIds.slice(prevInputIds.length + 1 - this.no_repeat_ngram_size, prevInputIds.length); + const banned = bannedNgrams.get(JSON.stringify(ngramIdx)) ?? []; + return banned; + } + + /** + * Calculate banned n-gram tokens + * @param {number[]} prevInputIds List of previous input ids + * @returns {number[]} Map of generated n-grams + */ + calcBannedNgramTokens(prevInputIds) { + const bannedTokens = []; + if (prevInputIds.length + 1 < this.no_repeat_ngram_size) { + // return no banned tokens if we haven't generated no_repeat_ngram_size tokens yet + return bannedTokens; + + } else { + const generatedNgrams = this.getNgrams(prevInputIds); + const bannedTokens = this.getGeneratedNgrams(generatedNgrams, prevInputIds); + return bannedTokens; + } + } + + /** + * Apply the no-repeat-ngram processor to the logits. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The logits with no-repeat-ngram processing. + */ + _call(input_ids, logits) { + const bannedTokens = this.calcBannedNgramTokens(input_ids); + + for (const token of bannedTokens) { + logits.data[token] = -Infinity; + } + return logits; + } +} + +/** + * A logits processor that penalises repeated output tokens. + * + * @extends LogitsProcessor + */ +class RepetitionPenaltyLogitsProcessor extends LogitsProcessor { + /** + * Create a RepetitionPenaltyLogitsProcessor. + * @param {number} penalty The penalty to apply for repeated tokens. + */ + constructor(penalty) { + super(); + this.penalty = penalty; + } + + /** + * Apply the repetition penalty to the logits. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The logits with repetition penalty processing. + */ + _call(input_ids, logits) { + // Modify the logits corresponding to each element in `input_ids`. + // As a consequence, the logits corresponding to tokens that appear + // many times in the output will be penalised more. + for (const input_id of input_ids) { + if (logits.data[input_id] < 0) { + logits.data[input_id] *= this.penalty; + } else { + logits.data[input_id] /= this.penalty; + } + } + return logits + } +} + +/** + * A logits processor that enforces a minimum number of tokens. + * + * @extends LogitsProcessor + */ +class MinLengthLogitsProcessor extends LogitsProcessor { + /** + * Create a MinLengthLogitsProcessor. + * @param {number} min_length The minimum length below which the score of `eos_token_id` is set to negative infinity. + * @param {number|number[]} eos_token_id The ID/IDs of the end-of-sequence token. + */ + constructor(min_length, eos_token_id) { + super(); + this.min_length = min_length; + this.eos_token_id = Array.isArray(eos_token_id) ? eos_token_id : [eos_token_id]; + } + + /** + * Apply logit processor. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The processed logits. + */ + _call(input_ids, logits) { + if (input_ids.length < this.min_length) { + for (const eos_token of this.eos_token_id) { + logits.data[eos_token] = -Infinity; + } + } + + return logits + } +} + +/** + * A logits processor that enforces a minimum number of new tokens. + * + * @extends LogitsProcessor + */ +class MinNewTokensLengthLogitsProcessor extends LogitsProcessor { + /** + * Create a MinNewTokensLengthLogitsProcessor. + * @param {number} prompt_length_to_skip The input tokens length. + * @param {number} min_new_tokens The minimum *new* tokens length below which the score of `eos_token_id` is set to negative infinity. + * @param {number|number[]} eos_token_id The ID/IDs of the end-of-sequence token. + */ + constructor(prompt_length_to_skip, min_new_tokens, eos_token_id) { + super(); + this.prompt_length_to_skip = prompt_length_to_skip; + this.min_new_tokens = min_new_tokens; + this.eos_token_id = Array.isArray(eos_token_id) ? eos_token_id : [eos_token_id]; + } + + /** + * Apply logit processor. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The processed logits. + */ + _call(input_ids, logits) { + const new_tokens_length = input_ids.length - this.prompt_length_to_skip; + if (new_tokens_length < this.min_new_tokens) { + for (const eos_token of this.eos_token_id) { + logits.data[eos_token] = -Infinity; + } + } + + return logits + } +} + +class NoBadWordsLogitsProcessor extends LogitsProcessor { + /** + * Create a `NoBadWordsLogitsProcessor`. + * @param {number[][]} bad_words_ids List of list of token ids that are not allowed to be generated. + * @param {number|number[]} eos_token_id The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens. + */ + constructor(bad_words_ids, eos_token_id) { + super(); + this.bad_words_ids = bad_words_ids; + this.eos_token_id = Array.isArray(eos_token_id) ? eos_token_id : [eos_token_id]; + } + + /** + * Apply logit processor. + * @param {Array} input_ids The input IDs. + * @param {Object} logits The logits. + * @returns {Object} The processed logits. + */ + _call(input_ids, logits) { + + for (const bad_word_ids of this.bad_words_ids) { + // Whether to modify the logits of the last token in the bad word id sequence + let mark = true; + + // For each bad word in the list, if the current sequence of input ids ends with this sequence (excluding the last), + // then we set the logits of the last bad word id to -Infinity. + for (let i = 1; i <= bad_word_ids.length - 1 && bad_word_ids.length < input_ids.length; ++i) { + + if (bad_word_ids.at(-i - 1) !== input_ids.at(-i)) { + // We have found a mismatch + mark = false; + break; + } + } + if (mark) { + logits.data[bad_word_ids.at(-1)] = -Infinity; + } + } + + return logits + } +} + +/** + * @typedef {Object} GenerationConfigType The default configuration parameters. + * @property {number} [max_length=20] The maximum length the generated tokens can have. Corresponds to the length of the input prompt + `max_new_tokens`. Its effect is overridden by `max_new_tokens`, if also set. + * @property {number} [max_new_tokens=null] The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt. + * @property {number} [min_length=0] The minimum length of the sequence to be generated. Corresponds to the length of the input prompt + `min_new_tokens`. Its effect is overridden by `min_new_tokens`, if also set. + * @property {number} [min_new_tokens=null] The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt. + * @property {boolean|"never"} [early_stopping=false] Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values: + * - `true`, where the generation stops as soon as there are `num_beams` complete candidates; + * - `false`, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates; + * - `"never"`, where the beam search procedure only stops when there cannot be better candidates (canonical beam search algorithm). + * @property {number} [max_time=null] The maximum amount of time you allow the computation to run for in seconds. Generation will still finish the current pass after allocated time has been passed. + * + * @property {boolean} [do_sample=false] Whether or not to use sampling; use greedy decoding otherwise. + * @property {number} [num_beams=1] Number of beams for beam search. 1 means no beam search. + * @property {number} [num_beam_groups=1] Number of groups to divide `num_beams` into in order to ensure diversity among different groups of beams. See [this paper](https://arxiv.org/pdf/1610.02424.pdf) for more details. + * @property {number} [penalty_alpha=null] The values balance the model confidence and the degeneration penalty in contrastive search decoding. + * @property {boolean} [use_cache=true] Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding. + * + * @property {number} [temperature=1.0] The value used to modulate the next token probabilities. + * @property {number} [top_k=50] The number of highest probability vocabulary tokens to keep for top-k-filtering. + * @property {number} [top_p=1.0] If set to float < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation. + * @property {number} [typical_p=1.0] Local typicality measures how similar the conditional probability of predicting a target token next is to the expected conditional probability of predicting a random token next, given the partial text already generated. If set to float < 1, the smallest set of the most locally typical tokens with probabilities that add up to `typical_p` or higher are kept for generation. See [this paper](https://arxiv.org/pdf/2202.00666.pdf) for more details. + * @property {number} [epsilon_cutoff=0.0] If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled. In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details. + * @property {number} [eta_cutoff=0.0] Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to float strictly between 0 and 1, a token is only considered if it is greater than either `eta_cutoff` or `sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits)))`. The latter term is intuitively the expected next token probability, scaled by `sqrt(eta_cutoff)`. In the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details. + * @property {number} [diversity_penalty=0.0] This value is subtracted from a beam's score if it generates a token same as any beam from other group at a particular time. Note that `diversity_penalty` is only effective if `group beam search` is enabled. + * @property {number} [repetition_penalty=1.0] The parameter for repetition penalty. 1.0 means no penalty. See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details. + * @property {number} [encoder_repetition_penalty=1.0] The paramater for encoder_repetition_penalty. An exponential penalty on sequences that are not in the original input. 1.0 means no penalty. + * @property {number} [length_penalty=1.0] Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent to the sequence length, which in turn is used to divide the score of the sequence. Since the score is the log likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences, while `length_penalty` < 0.0 encourages shorter sequences. + * @property {number} [no_repeat_ngram_size=0] If set to int > 0, all ngrams of that size can only occur once. + * @property {number[][]} [bad_words_ids=null] List of token ids that are not allowed to be generated. In order to get the token ids of the words that should not appear in the generated text, use `(await tokenizer(bad_words, {add_prefix_space: true, add_special_tokens: false})).input_ids`. + * @property {number[][]|number[][][]} [force_words_ids=null] List of token ids that must be generated. If given a `number[][]`, this is treated as a simple list of words that must be included, the opposite to `bad_words_ids`. If given `number[][][]`, this triggers a [disjunctive constraint](https://github.com/huggingface/transformers/issues/14081), where one can allow different forms of each word. + * @property {boolean} [renormalize_logits=false] Whether to renormalize the logits after applying all the logits processors or warpers (including the custom ones). It's highly recommended to set this flag to `true` as the search algorithms suppose the score logits are normalized but some logit processors or warpers break the normalization. + * @property {Object[]} [constraints=null] Custom constraints that can be added to the generation to ensure that the output will contain the use of certain tokens as defined by `Constraint` objects, in the most sensible way possible. + * + * @property {number} [forced_bos_token_id=null] The id of the token to force as the first generated token after the `decoder_start_token_id`. Useful for multilingual models like mBART where the first generated token needs to be the target language token. + * @property {number|number[]} [forced_eos_token_id=null] The id of the token to force as the last generated token when `max_length` is reached. Optionally, use a list to set multiple *end-of-sequence* tokens. + * @property {boolean} [remove_invalid_values=false] Whether to remove possible *nan* and *inf* outputs of the model to prevent the generation method to crash. Note that using `remove_invalid_values` can slow down generation. + * @property {number[]} [exponential_decay_length_penalty=null] This Tuple adds an exponentially increasing length penalty, after a certain amount of tokens have been generated. The tuple shall consist of: `(start_index, decay_factor)` where `start_index` indicates where penalty starts and `decay_factor` represents the factor of exponential decay. + * @property {number[]} [suppress_tokens=null] A list of tokens that will be suppressed at generation. The `SupressTokens` logit processor will set their log probs to `-inf` so that they are not sampled. + * @property {number[]} [begin_suppress_tokens=null] A list of tokens that will be suppressed at the beginning of the generation. The `SupressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled. + * @property {number[][]} [forced_decoder_ids=null] A list of pairs of integers which indicates a mapping from generation indices to token indices that will be forced before sampling. For example, `[[1, 123]]` means the second generated token will always be a token of index 123. + * + * @property {number} [num_return_sequences=1] The number of independently computed returned sequences for each element in the batch. + * @property {boolean} [output_attentions=false] Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned tensors for more details. + * @property {boolean} [output_hidden_states=false] Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for more details. + * @property {boolean} [output_scores=false] Whether or not to return the prediction scores. See `scores` under returned tensors for more details. + * @property {boolean} [return_dict_in_generate=false] Whether or not to return a `ModelOutput` instead of a plain tuple. + * + * @property {number} [pad_token_id=null] The id of the *padding* token. + * @property {number} [bos_token_id=null] The id of the *beginning-of-sequence* token. + * @property {number|number[]} [eos_token_id=null] The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens. + * + * @property {number} [encoder_no_repeat_ngram_size=0] If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`. + * @property {number} [decoder_start_token_id=null] If an encoder-decoder model starts decoding with a different token than *bos*, the id of that token. + * + * @property {Object} [generation_kwargs={}] Additional generation kwargs will be forwarded to the `generate` function of the model. Kwargs that are not present in `generate`'s signature will be used in the model forward pass. + */ + +/** + * Class that holds a configuration for a generation task. + * @type {new (kwargs?: GenerationConfigType) => GenerationConfigType} + */ +const GenerationConfig = /** @type {any} */ (class { + + /** + * Create a new GenerationConfig object. + * @param {GenerationConfigType} kwargs + */ + constructor(kwargs = {}) { + // Parameters that control the length of the output + this.max_length = kwargs.max_length ?? 20; + this.max_new_tokens = kwargs.max_new_tokens ?? null; + this.min_length = kwargs.min_length ?? 0; + this.min_new_tokens = kwargs.min_new_tokens ?? null; + this.early_stopping = kwargs.early_stopping ?? false; + this.max_time = kwargs.max_time ?? null; + + // Parameters that control the generation strategy used + this.do_sample = kwargs.do_sample ?? false; + this.num_beams = kwargs.num_beams ?? 1; + this.num_beam_groups = kwargs.num_beam_groups ?? 1; + this.penalty_alpha = kwargs.penalty_alpha ?? null; + this.use_cache = kwargs.use_cache ?? true; + + // Parameters for manipulation of the model output logits + this.temperature = kwargs.temperature ?? 1.0; + this.top_k = kwargs.top_k ?? 50; + this.top_p = kwargs.top_p ?? 1.0; + this.typical_p = kwargs.typical_p ?? 1.0; + this.epsilon_cutoff = kwargs.epsilon_cutoff ?? 0.0; + this.eta_cutoff = kwargs.eta_cutoff ?? 0.0; + this.diversity_penalty = kwargs.diversity_penalty ?? 0.0; + this.repetition_penalty = kwargs.repetition_penalty ?? 1.0; + this.encoder_repetition_penalty = kwargs.encoder_repetition_penalty ?? 1.0; + this.length_penalty = kwargs.length_penalty ?? 1.0; + this.no_repeat_ngram_size = kwargs.no_repeat_ngram_size ?? 0; + this.bad_words_ids = kwargs.bad_words_ids ?? null; + this.force_words_ids = kwargs.force_words_ids ?? null; + this.renormalize_logits = kwargs.renormalize_logits ?? false; + this.constraints = kwargs.constraints ?? null; + this.forced_bos_token_id = kwargs.forced_bos_token_id ?? null; + this.forced_eos_token_id = kwargs.forced_eos_token_id ?? null; + this.remove_invalid_values = kwargs.remove_invalid_values ?? false; + this.exponential_decay_length_penalty = kwargs.exponential_decay_length_penalty ?? null; + this.suppress_tokens = kwargs.suppress_tokens ?? null; + this.begin_suppress_tokens = kwargs.begin_suppress_tokens ?? null; + this.forced_decoder_ids = kwargs.forced_decoder_ids ?? null; + + // Parameters that define the output variables of `generate` + this.num_return_sequences = kwargs.num_return_sequences ?? 1; + this.output_attentions = kwargs.output_attentions ?? false; + this.output_hidden_states = kwargs.output_hidden_states ?? false; + this.output_scores = kwargs.output_scores ?? false; + this.return_dict_in_generate = kwargs.return_dict_in_generate ?? false; + + // Special tokens that can be used at generation time + this.pad_token_id = kwargs.pad_token_id ?? null; + this.bos_token_id = kwargs.bos_token_id ?? null; + this.eos_token_id = kwargs.eos_token_id ?? null; + + // Generation parameters exclusive to encoder-decoder models + this.encoder_no_repeat_ngram_size = kwargs.encoder_no_repeat_ngram_size ?? 0; + this.decoder_start_token_id = kwargs.decoder_start_token_id ?? null; + + // Wild card + this.generation_kwargs = kwargs.generation_kwargs ?? {}; + } +}); + +/** + * Sampler is a base class for all sampling methods used for text generation. + */ +class Sampler extends _core_js__WEBPACK_IMPORTED_MODULE_1__.Callable { + /** + * Creates a new Sampler object with the specified generation config. + * @param {GenerationConfigType} generation_config The generation config. + */ + constructor(generation_config) { + super(); + this.generation_config = generation_config; + } + + /** + * Executes the sampler, using the specified logits. + * @param {Tensor} logits + * @param {number} index + * @returns {void} + */ + _call(logits, index = -1) { + // Sample from logits, of dims [batch, sequence_length, vocab_size]. + // If index is specified, sample from [batch, index, vocab_size]. + return this.sample(logits, index); + } + + /** + * Abstract method for sampling the logits. + * @param {Tensor} logits + * @param {number} index + * @throws {Error} + */ + sample(logits, index) { + throw Error("sample should be implemented in subclasses.") + } + + /** + * Returns the specified logits as an array, with temperature applied. + * @param {Tensor} logits + * @param {number} index + * @returns {Float32Array} + */ + getLogits(logits, index) { + let vocabSize = logits.dims.at(-1); + + let logs = /** @type {Float32Array} */(logits.data); + + if (index === -1) { + logs = logs.slice(-vocabSize); + } else { + let startIndex = index * vocabSize; + logs = logs.slice(startIndex, startIndex + vocabSize); + } + + // add temperature + if (this.generation_config.temperature > 0) { + logs = logs.map(x => x / this.generation_config.temperature) + } + return logs; + } + + /** + * Selects an item randomly based on the specified probabilities. + * @param {Array} probabilities An array of probabilities to use for selection. + * @returns {number} The index of the selected item. + */ + randomSelect(probabilities) { + // Return index of chosen item + let sumProbabilities = probabilities.reduce((acc, curr) => acc + curr, 0); + + let r = Math.random() * sumProbabilities; + for (let i = 0; i < probabilities.length; ++i) { + r -= probabilities[i]; + if (r <= 0) { + return i; + } + } + return 0; // return first (most probable) as a fallback + } + + /** + * Returns a Sampler object based on the specified options. + * @param {GenerationConfigType} generation_config An object containing options for the sampler. + * @returns {Sampler} A Sampler object. + */ + static getSampler(generation_config) { + // - *greedy decoding*: `num_beams=1` and `do_sample=False` + // - *contrastive search*: `penalty_alpha>0` and `top_k>1` + // - *multinomial sampling*: `num_beams=1` and `do_sample=True` + // - *beam-search decoding*: `num_beams>1` and `do_sample=False` + // - *beam-search multinomial sampling*: `num_beams>1` and `do_sample=True` + // - *diverse beam-search decoding*: `num_beams>1` and `num_beam_groups>1` + // - *constrained beam-search decoding*: `constraints!=None` or `force_words_ids!=None` + + // NOTE: beam search is implemented directly into the generation function + if (generation_config.do_sample) { + return new MultinomialSampler(generation_config); + + } else if (generation_config.num_beams > 1) { + return new BeamSearchSampler(generation_config); + + } else { + if (generation_config.num_return_sequences > 1) { + throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${generation_config.num_return_sequences}.`) + } + return new GreedySampler(generation_config); + } + } +} + +/** + * Class representing a Greedy Sampler. + * @extends Sampler + */ +class GreedySampler extends Sampler { + /** + * Sample the maximum probability of a given logits tensor. + * @param {Tensor} logits + * @param {number} [index=-1] + * @returns {Array} An array with a single tuple, containing the index of the maximum value and a meaningless score (since this is a greedy search). + */ + sample(logits, index = -1) { + // NOTE: no need to do log_softmax here since we only take the maximum + let logs = this.getLogits(logits, index); + let argmax = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.max)(logs)[1]; + + // Note: score is meaningless in this context, since we are performing + // greedy search (p = 1 => log(p) = 0) + return [ + [argmax, 0] + ]; + } +} + +/** + * Class representing a MultinomialSampler. + * @extends Sampler + */ +class MultinomialSampler extends Sampler { + + /** + * Sample from the logits. + * @param {Tensor} logits + * @param {number} index + * @returns {Array} + */ + sample(logits, index = -1) { + let k = logits.dims.at(-1); // defaults to vocab size + if (this.generation_config.top_k > 0) { + k = Math.min(this.generation_config.top_k, k); + } + + // Get logits of nth token + const logs = this.getLogits(logits, index); + + // Get top k tokens + const topLogits = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.getTopItems)(logs, k); + + // Compute softmax over logits + const probabilities = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.softmax)(topLogits.map(x => x[1])); + + return Array.from({ length: this.generation_config.num_beams }, () => { + const sampledIndex = this.randomSelect(probabilities); + return [ + topLogits[sampledIndex][0], // token id + Math.log(probabilities[sampledIndex]), // score + ]; + }); + } +} + + +/** + * Class representing a BeamSearchSampler. + * @extends Sampler + */ +class BeamSearchSampler extends Sampler { + + /** + * Sample from the logits. + * @param {Tensor} logits + * @param {number} index + * @returns {Array} + */ + sample(logits, index = -1) { + let k = logits.dims.at(-1); // defaults to vocab size + if (this.generation_config.top_k > 0) { + k = Math.min(this.generation_config.top_k, k); + } + + // Get logits of nth token + const logs = this.getLogits(logits, index); + + // Get top k tokens + const topLogits = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.getTopItems)(logs, k); + + // Compute softmax over logits + const probabilities = (0,_maths_js__WEBPACK_IMPORTED_MODULE_2__.softmax)(topLogits.map(x => x[1])); + + return Array.from({ length: this.generation_config.num_beams }, (_, i) => { + return [ + topLogits[i][0], // token id + Math.log(probabilities[i]), // score + ]; + }); + } +} + + +/***/ }), + +/***/ "./src/utils/hub.js": +/*!**************************!*\ + !*** ./src/utils/hub.js ***! + \**************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "getFile": () => (/* binding */ getFile), +/* harmony export */ "getModelFile": () => (/* binding */ getModelFile), +/* harmony export */ "getModelJSON": () => (/* binding */ getModelJSON) +/* harmony export */ }); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fs */ "?7a2c"); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! path */ "?a42a"); +/* harmony import */ var stream_web__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! stream/web */ "?e65c"); +/* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../env.js */ "./src/env.js"); +/* harmony import */ var _core_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./core.js */ "./src/utils/core.js"); + +/** + * @file Utility functions to interact with the Hugging Face Hub (https://huggingface.co/models) + * + * @module utils/hub + */ + + + + + + + + +if (!globalThis.ReadableStream) { + // @ts-ignore + globalThis.ReadableStream = stream_web__WEBPACK_IMPORTED_MODULE_2__.ReadableStream; // ReadableStream is not a global with Node 16 +} + +/** + * @typedef {Object} PretrainedOptions Options for loading a pretrained model. + * @property {boolean?} [quantized=true] Whether to load the 8-bit quantized version of the model (only applicable when loading model files). + * @property {function} [progress_callback=null] If specified, this function will be called during model construction, to provide the user with progress updates. + * @property {Object} [config=null] Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when: + * - The model is a model provided by the library (loaded with the *model id* string of a pretrained model). + * - The model is loaded by supplying a local directory as `pretrained_model_name_or_path` and a configuration JSON file named *config.json* is found in the directory. + * @property {string} [cache_dir=null] Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. + * @property {boolean} [local_files_only=false] Whether or not to only look at local files (e.g., not try downloading the model). + * @property {string} [revision='main'] The specific model version to use. It can be a branch name, a tag name, or a commit id, + * since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git. + * NOTE: This setting is ignored for local requests. + * @property {string} [model_file_name=null] If specified, load the model with this name (excluding the .onnx suffix). Currently only valid for encoder- or decoder-only models. + */ + +class FileResponse { + /** + * Mapping from file extensions to MIME types. + */ + _CONTENT_TYPE_MAP = { + 'txt': 'text/plain', + 'html': 'text/html', + 'css': 'text/css', + 'js': 'text/javascript', + 'json': 'application/json', + 'png': 'image/png', + 'jpg': 'image/jpeg', + 'jpeg': 'image/jpeg', + 'gif': 'image/gif', + } + /** + * Creates a new `FileResponse` object. + * @param {string|URL} filePath + */ + constructor(filePath) { + this.filePath = filePath; + this.headers = new Headers(); + + this.exists = fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(filePath); + if (this.exists) { + this.status = 200; + this.statusText = 'OK'; + + let stats = fs__WEBPACK_IMPORTED_MODULE_0__.statSync(filePath); + this.headers.set('content-length', stats.size.toString()); + + this.updateContentType(); + + let self = this; + this.body = new ReadableStream({ + start(controller) { + self.arrayBuffer().then(buffer => { + controller.enqueue(new Uint8Array(buffer)); + controller.close(); + }) + } + }); + } else { + this.status = 404; + this.statusText = 'Not Found'; + this.body = null; + } + } + + /** + * Updates the 'content-type' header property of the response based on the extension of + * the file specified by the filePath property of the current object. + * @returns {void} + */ + updateContentType() { + // Set content-type header based on file extension + const extension = this.filePath.toString().split('.').pop().toLowerCase(); + this.headers.set('content-type', this._CONTENT_TYPE_MAP[extension] ?? 'application/octet-stream'); + } + + /** + * Clone the current FileResponse object. + * @returns {FileResponse} A new FileResponse object with the same properties as the current object. + */ + clone() { + let response = new FileResponse(this.filePath); + response.exists = this.exists; + response.status = this.status; + response.statusText = this.statusText; + response.headers = new Headers(this.headers); + return response; + } + + /** + * Reads the contents of the file specified by the filePath property and returns a Promise that + * resolves with an ArrayBuffer containing the file's contents. + * @returns {Promise} A Promise that resolves with an ArrayBuffer containing the file's contents. + * @throws {Error} If the file cannot be read. + */ + async arrayBuffer() { + const data = await fs__WEBPACK_IMPORTED_MODULE_0__.promises.readFile(this.filePath); + return data.buffer; + } + + /** + * Reads the contents of the file specified by the filePath property and returns a Promise that + * resolves with a Blob containing the file's contents. + * @returns {Promise} A Promise that resolves with a Blob containing the file's contents. + * @throws {Error} If the file cannot be read. + */ + async blob() { + const data = await fs__WEBPACK_IMPORTED_MODULE_0__.promises.readFile(this.filePath); + return new Blob([data], { type: this.headers.get('content-type') }); + } + + /** + * Reads the contents of the file specified by the filePath property and returns a Promise that + * resolves with a string containing the file's contents. + * @returns {Promise} A Promise that resolves with a string containing the file's contents. + * @throws {Error} If the file cannot be read. + */ + async text() { + const data = await fs__WEBPACK_IMPORTED_MODULE_0__.promises.readFile(this.filePath, 'utf8'); + return data; + } + + /** + * Reads the contents of the file specified by the filePath property and returns a Promise that + * resolves with a parsed JavaScript object containing the file's contents. + * + * @returns {Promise} A Promise that resolves with a parsed JavaScript object containing the file's contents. + * @throws {Error} If the file cannot be read. + */ + async json() { + return JSON.parse(await this.text()); + } +} + +/** + * Determines whether the given string is a valid HTTP or HTTPS URL. + * @param {string|URL} string The string to test for validity as an HTTP or HTTPS URL. + * @param {string[]} [validHosts=null] A list of valid hostnames. If specified, the URL's hostname must be in this list. + * @returns {boolean} True if the string is a valid HTTP or HTTPS URL, false otherwise. + */ +function isValidHttpUrl(string, validHosts = null) { + // https://stackoverflow.com/a/43467144 + let url; + try { + url = new URL(string); + } catch (_) { + return false; + } + if (validHosts && !validHosts.includes(url.hostname)) { + return false; + } + return url.protocol === "http:" || url.protocol === "https:"; +} + +/** + * Helper function to get a file, using either the Fetch API or FileSystem API. + * + * @param {URL|string} urlOrPath The URL/path of the file to get. + * @returns {Promise} A promise that resolves to a FileResponse object (if the file is retrieved using the FileSystem API), or a Response object (if the file is retrieved using the Fetch API). + */ +async function getFile(urlOrPath) { + + if (_env_js__WEBPACK_IMPORTED_MODULE_3__.env.useFS && !isValidHttpUrl(urlOrPath)) { + return new FileResponse(urlOrPath); + + } else if (typeof process !== 'undefined' && process?.release?.name === 'node') { + const IS_CI = !!process.env?.TESTING_REMOTELY; + const version = _env_js__WEBPACK_IMPORTED_MODULE_3__.env.version; + + const headers = new Headers(); + headers.set('User-Agent', `transformers.js/${version}; is_ci/${IS_CI};`); + + // Check whether we are making a request to the Hugging Face Hub. + const isHFURL = isValidHttpUrl(urlOrPath, ['huggingface.co', 'hf.co']); + if (isHFURL) { + // If an access token is present in the environment variables, + // we add it to the request headers. + // NOTE: We keep `HF_ACCESS_TOKEN` for backwards compatibility (as a fallback). + const token = process.env?.HF_TOKEN ?? process.env?.HF_ACCESS_TOKEN; + if (token) { + headers.set('Authorization', `Bearer ${token}`); + } + } + return fetch(urlOrPath, { headers }); + } else { + // Running in a browser-environment, so we use default headers + // NOTE: We do not allow passing authorization headers in the browser, + // since this would require exposing the token to the client. + return fetch(urlOrPath); + } +} + +const ERROR_MAPPING = { + // 4xx errors (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses) + 400: 'Bad request error occurred while trying to load file', + 401: 'Unauthorized access to file', + 403: 'Forbidden access to file', + 404: 'Could not locate file', + 408: 'Request timeout error occurred while trying to load file', + + // 5xx errors (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) + 500: 'Internal server error error occurred while trying to load file', + 502: 'Bad gateway error occurred while trying to load file', + 503: 'Service unavailable error occurred while trying to load file', + 504: 'Gateway timeout error occurred while trying to load file', +} +/** + * Helper method to handle fatal errors that occur while trying to load a file from the Hugging Face Hub. + * @param {number} status The HTTP status code of the error. + * @param {string} remoteURL The URL of the file that could not be loaded. + * @param {boolean} fatal Whether to raise an error if the file could not be loaded. + * @returns {null} Returns `null` if `fatal = true`. + * @throws {Error} If `fatal = false`. + */ +function handleError(status, remoteURL, fatal) { + if (!fatal) { + // File was not loaded correctly, but it is optional. + // TODO in future, cache the response? + return null; + } + + const message = ERROR_MAPPING[status] ?? `Error (${status}) occurred while trying to load file`; + throw Error(`${message}: "${remoteURL}".`); +} + +class FileCache { + /** + * Instantiate a `FileCache` object. + * @param {string} path + */ + constructor(path) { + this.path = path; + } + + /** + * Checks whether the given request is in the cache. + * @param {string} request + * @returns {Promise} + */ + async match(request) { + + let filePath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.path, request); + let file = new FileResponse(filePath); + + if (file.exists) { + return file; + } else { + return undefined; + } + } + + /** + * Adds the given response to the cache. + * @param {string} request + * @param {Response|FileResponse} response + * @returns {Promise} + */ + async put(request, response) { + const buffer = Buffer.from(await response.arrayBuffer()); + + let outputPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.path, request); + + try { + await fs__WEBPACK_IMPORTED_MODULE_0__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_1__.dirname(outputPath), { recursive: true }); + await fs__WEBPACK_IMPORTED_MODULE_0__.promises.writeFile(outputPath, buffer); + + } catch (err) { + console.warn('An error occurred while writing the file to cache:', err) + } + } + + // TODO add the rest? + // addAll(requests: RequestInfo[]): Promise; + // delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; + // keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise>; + // match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; + // matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise>; +} + +/** + * + * @param {FileCache|Cache} cache The cache to search + * @param {string[]} names The names of the item to search for + * @returns {Promise} The item from the cache, or undefined if not found. + */ +async function tryCache(cache, ...names) { + for (let name of names) { + try { + let result = await cache.match(name); + if (result) return result; + } catch (e) { + continue; + } + } + return undefined; +} + +/** + * + * Retrieves a file from either a remote URL using the Fetch API or from the local file system using the FileSystem API. + * If the filesystem is available and `env.useCache = true`, the file will be downloaded and cached. + * + * @param {string} path_or_repo_id This can be either: + * - a string, the *model id* of a model repo on huggingface.co. + * - a path to a *directory* potentially containing the file. + * @param {string} filename The name of the file to locate in `path_or_repo`. + * @param {boolean} [fatal=true] Whether to throw an error if the file is not found. + * @param {PretrainedOptions} [options] An object containing optional parameters. + * + * @throws Will throw an error if the file is not found and `fatal` is true. + * @returns {Promise} A Promise that resolves with the file content as a buffer. + */ +async function getModelFile(path_or_repo_id, filename, fatal = true, options = {}) { + + if (!_env_js__WEBPACK_IMPORTED_MODULE_3__.env.allowLocalModels) { + // User has disabled local models, so we just make sure other settings are correct. + + if (options.local_files_only) { + throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).") + } else if (!_env_js__WEBPACK_IMPORTED_MODULE_3__.env.allowRemoteModels) { + throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.") + } + } + + // Initiate file retrieval + (0,_core_js__WEBPACK_IMPORTED_MODULE_4__.dispatchCallback)(options.progress_callback, { + status: 'initiate', + name: path_or_repo_id, + file: filename + }) + + // First, check if the a caching backend is available + // If no caching mechanism available, will download the file every time + let cache; + if (!cache && _env_js__WEBPACK_IMPORTED_MODULE_3__.env.useBrowserCache) { + if (typeof caches === 'undefined') { + throw Error('Browser cache is not available in this environment.') + } + try { + // In some cases, the browser cache may be visible, but not accessible due to security restrictions. + // For example, when running an application in an iframe, if a user attempts to load the page in + // incognito mode, the following error is thrown: `DOMException: Failed to execute 'open' on 'CacheStorage': + // An attempt was made to break through the security policy of the user agent.` + // So, instead of crashing, we just ignore the error and continue without using the cache. + cache = await caches.open('transformers-cache'); + } catch (e) { + console.warn('An error occurred while opening the browser cache:', e); + } + } + + if (!cache && _env_js__WEBPACK_IMPORTED_MODULE_3__.env.useFSCache) { + // TODO throw error if not available + + // If `cache_dir` is not specified, use the default cache directory + cache = new FileCache(options.cache_dir ?? _env_js__WEBPACK_IMPORTED_MODULE_3__.env.cacheDir); + } + + if (!cache && _env_js__WEBPACK_IMPORTED_MODULE_3__.env.useCustomCache) { + // Allow the user to specify a custom cache system. + if (!_env_js__WEBPACK_IMPORTED_MODULE_3__.env.customCache) { + throw Error('`env.useCustomCache=true`, but `env.customCache` is not defined.') + } + + // Check that the required methods are defined: + if (!_env_js__WEBPACK_IMPORTED_MODULE_3__.env.customCache.match || !_env_js__WEBPACK_IMPORTED_MODULE_3__.env.customCache.put) { + throw new Error( + "`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. " + + "For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache" + ) + } + cache = _env_js__WEBPACK_IMPORTED_MODULE_3__.env.customCache; + } + + const revision = options.revision ?? 'main'; + + let requestURL = pathJoin(path_or_repo_id, filename); + let localPath = pathJoin(_env_js__WEBPACK_IMPORTED_MODULE_3__.env.localModelPath, requestURL); + + let remoteURL = pathJoin( + _env_js__WEBPACK_IMPORTED_MODULE_3__.env.remoteHost, + _env_js__WEBPACK_IMPORTED_MODULE_3__.env.remotePathTemplate.replaceAll('{model}', path_or_repo_id) + .replaceAll('{revision}', encodeURIComponent(revision)), + filename + ); + + // Choose cache key for filesystem cache + // When using the main revision (default), we use the request URL as the cache key. + // If a specific revision is requested, we account for this in the cache key. + let fsCacheKey = revision === 'main' ? requestURL : pathJoin(path_or_repo_id, revision, filename); + + /** @type {string} */ + let cacheKey; + let proposedCacheKey = cache instanceof FileCache ? fsCacheKey : remoteURL; + + // Whether to cache the final response in the end. + let toCacheResponse = false; + + /** @type {Response|FileResponse|undefined} */ + let response; + + if (cache) { + // A caching system is available, so we try to get the file from it. + // 1. We first try to get from cache using the local path. In some environments (like deno), + // non-URL cache keys are not allowed. In these cases, `response` will be undefined. + // 2. If no response is found, we try to get from cache using the remote URL or file system cache. + response = await tryCache(cache, localPath, proposedCacheKey); + } + + const cacheHit = response !== undefined; + + if (response === undefined) { + // Caching not available, or file is not cached, so we perform the request + + if (_env_js__WEBPACK_IMPORTED_MODULE_3__.env.allowLocalModels) { + // Accessing local models is enabled, so we try to get the file locally. + // If request is a valid HTTP URL, we skip the local file check. Otherwise, we try to get the file locally. + const isURL = isValidHttpUrl(requestURL); + if (!isURL) { + try { + response = await getFile(localPath); + cacheKey = localPath; // Update the cache key to be the local path + } catch (e) { + // Something went wrong while trying to get the file locally. + // NOTE: error handling is done in the next step (since `response` will be undefined) + console.warn(`Unable to load from local path "${localPath}": "${e}"`); + } + } else if (options.local_files_only) { + throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${requestURL}.`); + } else if (!_env_js__WEBPACK_IMPORTED_MODULE_3__.env.allowRemoteModels) { + throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${requestURL}.`); + } + } + + if (response === undefined || response.status === 404) { + // File not found locally. This means either: + // - The user has disabled local file access (`env.allowLocalModels=false`) + // - the path is a valid HTTP url (`response === undefined`) + // - the path is not a valid HTTP url and the file is not present on the file system or local server (`response.status === 404`) + + if (options.local_files_only || !_env_js__WEBPACK_IMPORTED_MODULE_3__.env.allowRemoteModels) { + // User requested local files only, but the file is not found locally. + if (fatal) { + throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${localPath}".`); + } else { + // File not found, but this file is optional. + // TODO in future, cache the response? + return null; + } + } + + // File not found locally, so we try to download it from the remote server + response = await getFile(remoteURL); + + if (response.status !== 200) { + return handleError(response.status, remoteURL, fatal); + } + + // Success! We use the proposed cache key from earlier + cacheKey = proposedCacheKey; + } + + // Only cache the response if: + toCacheResponse = + cache // 1. A caching system is available + && typeof Response !== 'undefined' // 2. `Response` is defined (i.e., we are in a browser-like environment) + && response instanceof Response // 3. result is a `Response` object (i.e., not a `FileResponse`) + && response.status === 200 // 4. request was successful (status code 200) + } + + // Start downloading + (0,_core_js__WEBPACK_IMPORTED_MODULE_4__.dispatchCallback)(options.progress_callback, { + status: 'download', + name: path_or_repo_id, + file: filename + }) + + const progressInfo = { + status: 'progress', + name: path_or_repo_id, + file: filename + } + + /** @type {Uint8Array} */ + let buffer; + + if (!options.progress_callback) { + // If no progress callback is specified, we can use the `.arrayBuffer()` + // method to read the response. + buffer = new Uint8Array(await response.arrayBuffer()); + + } else if ( + cacheHit // The item is being read from the cache + && + typeof navigator !== 'undefined' && /firefox/i.test(navigator.userAgent) // We are in Firefox + ) { + // Due to bug in Firefox, we cannot display progress when loading from cache. + // Fortunately, since this should be instantaneous, this should not impact users too much. + buffer = new Uint8Array(await response.arrayBuffer()); + + // For completeness, we still fire the final progress callback + (0,_core_js__WEBPACK_IMPORTED_MODULE_4__.dispatchCallback)(options.progress_callback, { + ...progressInfo, + progress: 100, + loaded: buffer.length, + total: buffer.length, + }) + } else { + buffer = await readResponse(response, data => { + (0,_core_js__WEBPACK_IMPORTED_MODULE_4__.dispatchCallback)(options.progress_callback, { + ...progressInfo, + ...data, + }) + }) + } + + if ( + // Only cache web responses + // i.e., do not cache FileResponses (prevents duplication) + toCacheResponse && cacheKey + && + // Check again whether request is in cache. If not, we add the response to the cache + (await cache.match(cacheKey) === undefined) + ) { + // NOTE: We use `new Response(buffer, ...)` instead of `response.clone()` to handle LFS files + await cache.put(cacheKey, new Response(buffer, { + headers: response.headers + })) + .catch(err => { + // Do not crash if unable to add to cache (e.g., QuotaExceededError). + // Rather, log a warning and proceed with execution. + console.warn(`Unable to add response to browser cache: ${err}.`); + }); + + } + + (0,_core_js__WEBPACK_IMPORTED_MODULE_4__.dispatchCallback)(options.progress_callback, { + status: 'done', + name: path_or_repo_id, + file: filename + }); + + return buffer; +} + +/** + * Fetches a JSON file from a given path and file name. + * + * @param {string} modelPath The path to the directory containing the file. + * @param {string} fileName The name of the file to fetch. + * @param {boolean} [fatal=true] Whether to throw an error if the file is not found. + * @param {PretrainedOptions} [options] An object containing optional parameters. + * @returns {Promise} The JSON data parsed into a JavaScript object. + * @throws Will throw an error if the file is not found and `fatal` is true. + */ +async function getModelJSON(modelPath, fileName, fatal = true, options = {}) { + let buffer = await getModelFile(modelPath, fileName, fatal, options); + if (buffer === null) { + // Return empty object + return {} + } + + let decoder = new TextDecoder('utf-8'); + let jsonData = decoder.decode(buffer); + + return JSON.parse(jsonData); +} + +/** + * Read and track progress when reading a Response object + * + * @param {any} response The Response object to read + * @param {function} progress_callback The function to call with progress updates + * @returns {Promise} A Promise that resolves with the Uint8Array buffer + */ +async function readResponse(response, progress_callback) { + + const contentLength = response.headers.get('Content-Length'); + if (contentLength === null) { + console.warn('Unable to determine content-length from response headers. Will expand buffer when needed.') + } + let total = parseInt(contentLength ?? '0'); + let buffer = new Uint8Array(total); + let loaded = 0; + + const reader = response.body.getReader(); + async function read() { + const { done, value } = await reader.read(); + if (done) return; + + let newLoaded = loaded + value.length; + if (newLoaded > total) { + total = newLoaded; + + // Adding the new data will overflow buffer. + // In this case, we extend the buffer + let newBuffer = new Uint8Array(total); + + // copy contents + newBuffer.set(buffer); + + buffer = newBuffer; + } + buffer.set(value, loaded) + loaded = newLoaded; + + const progress = (loaded / total) * 100; + + // Call your function here + progress_callback({ + progress: progress, + loaded: loaded, + total: total, + }) + + return read(); + } + + // Actually read + await read(); + + return buffer; +} + +/** + * Joins multiple parts of a path into a single path, while handling leading and trailing slashes. + * + * @param {...string} parts Multiple parts of a path. + * @returns {string} A string representing the joined path. + */ +function pathJoin(...parts) { + // https://stackoverflow.com/a/55142565 + parts = parts.map((part, index) => { + if (index) { + part = part.replace(new RegExp('^/'), ''); + } + if (index !== parts.length - 1) { + part = part.replace(new RegExp('/$'), ''); + } + return part; + }) + return parts.join('/'); +} + + +/***/ }), + +/***/ "./src/utils/image.js": +/*!****************************!*\ + !*** ./src/utils/image.js ***! + \****************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "RawImage": () => (/* binding */ RawImage) +/* harmony export */ }); +/* harmony import */ var _hub_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hub.js */ "./src/utils/hub.js"); +/* harmony import */ var _env_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../env.js */ "./src/env.js"); +/* harmony import */ var _tensor_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tensor.js */ "./src/utils/tensor.js"); +/* harmony import */ var sharp__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! sharp */ "?2b25"); + +/** + * @file Helper module for image processing. + * + * These functions and classes are only used internally, + * meaning an end-user shouldn't need to access anything here. + * + * @module utils/image + */ + + + + + +// Will be empty (or not used) if running in browser or web-worker + + +const BROWSER_ENV = typeof self !== 'undefined'; +const WEBWORKER_ENV = BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope'; + +let createCanvasFunction; +let ImageDataClass; +let loadImageFunction; +if (BROWSER_ENV) { + // Running in browser or web-worker + createCanvasFunction = (/** @type {number} */ width, /** @type {number} */ height) => { + if (!self.OffscreenCanvas) { + throw new Error('OffscreenCanvas not supported by this browser.'); + } + return new self.OffscreenCanvas(width, height) + }; + loadImageFunction = self.createImageBitmap; + ImageDataClass = self.ImageData; + +} else if (sharp__WEBPACK_IMPORTED_MODULE_3__) { + // Running in Node.js, electron, or other non-browser environment + + loadImageFunction = async (/**@type {sharp.Sharp}*/img) => { + const metadata = await img.metadata(); + const rawChannels = metadata.channels; + + let { data, info } = await img.raw().toBuffer({ resolveWithObject: true }); + + const newImage = new RawImage(new Uint8ClampedArray(data), info.width, info.height, info.channels); + if (rawChannels !== undefined && rawChannels !== info.channels) { + // Make sure the new image has the same number of channels as the input image. + // This is necessary for grayscale images. + newImage.convert(rawChannels); + } + return newImage; + } + +} else { + throw new Error('Unable to load image processing library.'); +} + + +// Defined here: https://github.com/python-pillow/Pillow/blob/a405e8406b83f8bfb8916e93971edc7407b8b1ff/src/libImaging/Imaging.h#L262-L268 +const RESAMPLING_MAPPING = { + 0: 'nearest', + 1: 'lanczos', + 2: 'bilinear', + 3: 'bicubic', + 4: 'box', + 5: 'hamming', +} + +/** + * Mapping from file extensions to MIME types. + */ +const CONTENT_TYPE_MAP = new Map([ + ['png', 'image/png'], + ['jpg', 'image/jpeg'], + ['jpeg', 'image/jpeg'], + ['gif', 'image/gif'], +]); + +class RawImage { + + /** + * Create a new `RawImage` object. + * @param {Uint8ClampedArray|Uint8Array} data The pixel data. + * @param {number} width The width of the image. + * @param {number} height The height of the image. + * @param {1|2|3|4} channels The number of channels. + */ + constructor(data, width, height, channels) { + this.data = data; + this.width = width; + this.height = height; + this.channels = channels; + } + + /** + * Returns the size of the image (width, height). + * @returns {[number, number]} The size of the image (width, height). + */ + get size() { + return [this.width, this.height]; + } + + /** + * Helper method for reading an image from a variety of input types. + * @param {RawImage|string|URL} input + * @returns The image object. + * + * **Example:** Read image from a URL. + * ```javascript + * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'); + * // RawImage { + * // "data": Uint8ClampedArray [ 25, 25, 25, 19, 19, 19, ... ], + * // "width": 800, + * // "height": 533, + * // "channels": 3 + * // } + * ``` + */ + static async read(input) { + if (input instanceof RawImage) { + return input; + } else if (typeof input === 'string' || input instanceof URL) { + return await this.fromURL(input); + } else { + throw new Error(`Unsupported input type: ${typeof input}`); + } + } + + + /** + * Read an image from a URL or file path. + * @param {string|URL} url The URL or file path to read the image from. + * @returns {Promise} The image object. + */ + static async fromURL(url) { + let response = await (0,_hub_js__WEBPACK_IMPORTED_MODULE_0__.getFile)(url); + if (response.status !== 200) { + throw new Error(`Unable to read image from "${url}" (${response.status} ${response.statusText})`); + } + let blob = await response.blob(); + return this.fromBlob(blob); + } + + /** + * Helper method to create a new Image from a blob. + * @param {Blob} blob The blob to read the image from. + * @returns {Promise} The image object. + */ + static async fromBlob(blob) { + if (BROWSER_ENV) { + // Running in environment with canvas + let img = await loadImageFunction(blob); + + const ctx = createCanvasFunction(img.width, img.height).getContext('2d'); + + // Draw image to context + ctx.drawImage(img, 0, 0); + + return new this(ctx.getImageData(0, 0, img.width, img.height).data, img.width, img.height, 4); + + } else { + // Use sharp.js to read (and possible resize) the image. + let img = sharp__WEBPACK_IMPORTED_MODULE_3__(await blob.arrayBuffer()); + + return await loadImageFunction(img); + } + } + + /** + * Helper method to create a new Image from a tensor + * @param {Tensor} tensor + */ + static fromTensor(tensor, channel_format = 'CHW') { + if (tensor.dims.length !== 3) { + throw new Error(`Tensor should have 3 dimensions, but has ${tensor.dims.length} dimensions.`); + } + + if (channel_format === 'CHW') { + tensor = tensor.transpose(1, 2, 0); + } else if (channel_format === 'HWC') { + // Do nothing + } else { + throw new Error(`Unsupported channel format: ${channel_format}`); + } + if (!(tensor.data instanceof Uint8ClampedArray || tensor.data instanceof Uint8Array)) { + throw new Error(`Unsupported tensor type: ${tensor.type}`); + } + switch (tensor.dims[2]) { + case 1: + case 2: + case 3: + case 4: + return new RawImage(tensor.data, tensor.dims[1], tensor.dims[0], tensor.dims[2]); + default: + throw new Error(`Unsupported number of channels: ${tensor.dims[2]}`); + } + } + + /** + * Convert the image to grayscale format. + * @returns {RawImage} `this` to support chaining. + */ + grayscale() { + if (this.channels === 1) { + return this; + } + + let newData = new Uint8ClampedArray(this.width * this.height * 1); + switch (this.channels) { + case 3: // rgb to grayscale + case 4: // rgba to grayscale + for (let i = 0, offset = 0; i < this.data.length; i += this.channels) { + const red = this.data[i]; + const green = this.data[i + 1]; + const blue = this.data[i + 2]; + + newData[offset++] = Math.round(0.2989 * red + 0.5870 * green + 0.1140 * blue); + } + break; + default: + throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`); + } + return this._update(newData, this.width, this.height, 1); + } + + /** + * Convert the image to RGB format. + * @returns {RawImage} `this` to support chaining. + */ + rgb() { + if (this.channels === 3) { + return this; + } + + let newData = new Uint8ClampedArray(this.width * this.height * 3); + + switch (this.channels) { + case 1: // grayscale to rgb + for (let i = 0, offset = 0; i < this.data.length; ++i) { + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i]; + } + break; + case 4: // rgba to rgb + for (let i = 0, offset = 0; i < this.data.length; i += 4) { + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i + 1]; + newData[offset++] = this.data[i + 2]; + } + break; + default: + throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`); + } + return this._update(newData, this.width, this.height, 3); + + } + + /** + * Convert the image to RGBA format. + * @returns {RawImage} `this` to support chaining. + */ + rgba() { + if (this.channels === 4) { + return this; + } + + let newData = new Uint8ClampedArray(this.width * this.height * 4); + + switch (this.channels) { + case 1: // grayscale to rgba + for (let i = 0, offset = 0; i < this.data.length; ++i) { + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i]; + newData[offset++] = 255; + } + break; + case 3: // rgb to rgba + for (let i = 0, offset = 0; i < this.data.length; i += 3) { + newData[offset++] = this.data[i]; + newData[offset++] = this.data[i + 1]; + newData[offset++] = this.data[i + 2]; + newData[offset++] = 255; + } + break; + default: + throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`); + } + + return this._update(newData, this.width, this.height, 4); + } + + /** + * Resize the image to the given dimensions. This method uses the canvas API to perform the resizing. + * @param {number} width The width of the new image. + * @param {number} height The height of the new image. + * @param {Object} options Additional options for resizing. + * @param {0|1|2|3|4|5|string} [options.resample] The resampling method to use. + * @returns {Promise} `this` to support chaining. + */ + async resize(width, height, { + resample = 2, + } = {}) { + + // Ensure resample method is a string + let resampleMethod = RESAMPLING_MAPPING[resample] ?? resample; + + if (BROWSER_ENV) { + // TODO use `resample` in browser environment + + // Store number of channels before resizing + let numChannels = this.channels; + + // Create canvas object for this image + let canvas = this.toCanvas(); + + // Actually perform resizing using the canvas API + const ctx = createCanvasFunction(width, height).getContext('2d'); + + // Draw image to context, resizing in the process + ctx.drawImage(canvas, 0, 0, width, height); + + // Create image from the resized data + let resizedImage = new RawImage(ctx.getImageData(0, 0, width, height).data, width, height, 4); + + // Convert back so that image has the same number of channels as before + return resizedImage.convert(numChannels); + + } else { + // Create sharp image from raw data, and resize + let img = this.toSharp(); + + switch (resampleMethod) { + case 'box': + case 'hamming': + if (resampleMethod === 'box' || resampleMethod === 'hamming') { + console.warn(`Resampling method ${resampleMethod} is not yet supported. Using bilinear instead.`); + resampleMethod = 'bilinear'; + } + + case 'nearest': + case 'bilinear': + case 'bicubic': + // Perform resizing using affine transform. + // This matches how the python Pillow library does it. + img = img.affine([width / this.width, 0, 0, height / this.height], { + interpolator: resampleMethod + }); + break; + + case 'lanczos': + // https://github.com/python-pillow/Pillow/discussions/5519 + // https://github.com/lovell/sharp/blob/main/docs/api-resize.md + img = img.resize({ + width, height, + fit: 'fill', + kernel: 'lanczos3', // PIL Lanczos uses a kernel size of 3 + }); + break; + + default: + throw new Error(`Resampling method ${resampleMethod} is not supported.`); + } + + return await loadImageFunction(img); + } + + } + + async pad([left, right, top, bottom]) { + left = Math.max(left, 0); + right = Math.max(right, 0); + top = Math.max(top, 0); + bottom = Math.max(bottom, 0); + + if (left === 0 && right === 0 && top === 0 && bottom === 0) { + // No padding needed + return this; + } + + if (BROWSER_ENV) { + // Store number of channels before padding + let numChannels = this.channels; + + // Create canvas object for this image + let canvas = this.toCanvas(); + + let newWidth = this.width + left + right; + let newHeight = this.height + top + bottom; + + // Create a new canvas of the desired size. + const ctx = createCanvasFunction(newWidth, newHeight).getContext('2d'); + + // Draw image to context, padding in the process + ctx.drawImage(canvas, + 0, 0, this.width, this.height, + left, top, newWidth, newHeight + ); + + // Create image from the padded data + let paddedImage = new RawImage( + ctx.getImageData(0, 0, newWidth, newHeight).data, + newWidth, newHeight, 4); + + // Convert back so that image has the same number of channels as before + return paddedImage.convert(numChannels); + + } else { + let img = this.toSharp().extend({ left, right, top, bottom }); + return await loadImageFunction(img); + } + } + + async crop([x_min, y_min, x_max, y_max]) { + // Ensure crop bounds are within the image + x_min = Math.max(x_min, 0); + y_min = Math.max(y_min, 0); + x_max = Math.min(x_max, this.width - 1); + y_max = Math.min(y_max, this.height - 1); + + // Do nothing if the crop is the entire image + if (x_min === 0 && y_min === 0 && x_max === this.width - 1 && y_max === this.height - 1) { + return this; + } + + const crop_width = x_max - x_min + 1; + const crop_height = y_max - y_min + 1; + + if (BROWSER_ENV) { + // Store number of channels before resizing + const numChannels = this.channels; + + // Create canvas object for this image + const canvas = this.toCanvas(); + + // Create a new canvas of the desired size. This is needed since if the + // image is too small, we need to pad it with black pixels. + const ctx = createCanvasFunction(crop_width, crop_height).getContext('2d'); + + // Draw image to context, cropping in the process + ctx.drawImage(canvas, + x_min, y_min, crop_width, crop_height, + 0, 0, crop_width, crop_height + ); + + // Create image from the resized data + const resizedImage = new RawImage(ctx.getImageData(0, 0, crop_width, crop_height).data, crop_width, crop_height, 4); + + // Convert back so that image has the same number of channels as before + return resizedImage.convert(numChannels); + + } else { + // Create sharp image from raw data + const img = this.toSharp().extract({ + left: x_min, + top: y_min, + width: crop_width, + height: crop_height, + }); + + return await loadImageFunction(img); + } + + } + + async center_crop(crop_width, crop_height) { + // If the image is already the desired size, return it + if (this.width === crop_width && this.height === crop_height) { + return this; + } + + // Determine bounds of the image in the new canvas + let width_offset = (this.width - crop_width) / 2; + let height_offset = (this.height - crop_height) / 2; + + + if (BROWSER_ENV) { + // Store number of channels before resizing + let numChannels = this.channels; + + // Create canvas object for this image + let canvas = this.toCanvas(); + + // Create a new canvas of the desired size. This is needed since if the + // image is too small, we need to pad it with black pixels. + const ctx = createCanvasFunction(crop_width, crop_height).getContext('2d'); + + let sourceX = 0; + let sourceY = 0; + let destX = 0; + let destY = 0; + + if (width_offset >= 0) { + sourceX = width_offset; + } else { + destX = -width_offset; + } + + if (height_offset >= 0) { + sourceY = height_offset; + } else { + destY = -height_offset; + } + + // Draw image to context, cropping in the process + ctx.drawImage(canvas, + sourceX, sourceY, crop_width, crop_height, + destX, destY, crop_width, crop_height + ); + + // Create image from the resized data + let resizedImage = new RawImage(ctx.getImageData(0, 0, crop_width, crop_height).data, crop_width, crop_height, 4); + + // Convert back so that image has the same number of channels as before + return resizedImage.convert(numChannels); + + } else { + // Create sharp image from raw data + let img = this.toSharp(); + + if (width_offset >= 0 && height_offset >= 0) { + // Cropped image lies entirely within the original image + img = img.extract({ + left: Math.floor(width_offset), + top: Math.floor(height_offset), + width: crop_width, + height: crop_height, + }) + } else if (width_offset <= 0 && height_offset <= 0) { + // Cropped image lies entirely outside the original image, + // so we add padding + let top = Math.floor(-height_offset); + let left = Math.floor(-width_offset); + img = img.extend({ + top: top, + left: left, + + // Ensures the resulting image has the desired dimensions + right: crop_width - this.width - left, + bottom: crop_height - this.height - top, + }); + } else { + // Cropped image lies partially outside the original image. + // We first pad, then crop. + + let y_padding = [0, 0]; + let y_extract = 0; + if (height_offset < 0) { + y_padding[0] = Math.floor(-height_offset); + y_padding[1] = crop_height - this.height - y_padding[0]; + } else { + y_extract = Math.floor(height_offset); + } + + let x_padding = [0, 0]; + let x_extract = 0; + if (width_offset < 0) { + x_padding[0] = Math.floor(-width_offset); + x_padding[1] = crop_width - this.width - x_padding[0]; + } else { + x_extract = Math.floor(width_offset); + } + + img = img.extend({ + top: y_padding[0], + bottom: y_padding[1], + left: x_padding[0], + right: x_padding[1], + }).extract({ + left: x_extract, + top: y_extract, + width: crop_width, + height: crop_height, + }) + } + + return await loadImageFunction(img); + } + } + + async toBlob(type = 'image/png', quality = 1) { + if (!BROWSER_ENV) { + throw new Error('toBlob() is only supported in browser environments.') + } + + const canvas = this.toCanvas(); + return await canvas.convertToBlob({ type, quality }); + } + + toTensor(channel_format = 'CHW') { + let tensor = new _tensor_js__WEBPACK_IMPORTED_MODULE_2__.Tensor( + 'uint8', + new Uint8Array(this.data), + [this.height, this.width, this.channels] + ); + + if (channel_format === 'HWC') { + // Do nothing + } else if (channel_format === 'CHW') { // hwc -> chw + tensor = tensor.permute(2, 0, 1); + } else { + throw new Error(`Unsupported channel format: ${channel_format}`); + } + return tensor; + } + + toCanvas() { + if (!BROWSER_ENV) { + throw new Error('toCanvas() is only supported in browser environments.') + } + + // Clone, and convert data to RGBA before drawing to canvas. + // This is because the canvas API only supports RGBA + let cloned = this.clone().rgba(); + + // Create canvas object for the cloned image + let clonedCanvas = createCanvasFunction(cloned.width, cloned.height); + + // Draw image to context + let data = new ImageDataClass(cloned.data, cloned.width, cloned.height); + clonedCanvas.getContext('2d').putImageData(data, 0, 0); + + return clonedCanvas; + } + + /** + * Helper method to update the image data. + * @param {Uint8ClampedArray} data The new image data. + * @param {number} width The new width of the image. + * @param {number} height The new height of the image. + * @param {1|2|3|4|null} [channels] The new number of channels of the image. + * @private + */ + _update(data, width, height, channels = null) { + this.data = data; + this.width = width; + this.height = height; + if (channels !== null) { + this.channels = channels; + } + return this; + } + + /** + * Clone the image + * @returns {RawImage} The cloned image + */ + clone() { + return new RawImage(this.data.slice(), this.width, this.height, this.channels); + } + + /** + * Helper method for converting image to have a certain number of channels + * @param {number} numChannels The number of channels. Must be 1, 3, or 4. + * @returns {RawImage} `this` to support chaining. + */ + convert(numChannels) { + if (this.channels === numChannels) return this; // Already correct number of channels + + switch (numChannels) { + case 1: + this.grayscale(); + break; + case 3: + this.rgb(); + break; + case 4: + this.rgba(); + break; + default: + throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`); + } + return this; + } + + /** + * Save the image to the given path. + * @param {string} path The path to save the image to. + */ + async save(path) { + + if (BROWSER_ENV) { + if (WEBWORKER_ENV) { + throw new Error('Unable to save an image from a Web Worker.') + } + + const extension = path.split('.').pop().toLowerCase(); + const mime = CONTENT_TYPE_MAP.get(extension) ?? 'image/png'; + + // Convert image to Blob + const blob = await this.toBlob(mime); + + // Convert the canvas content to a data URL + const dataURL = URL.createObjectURL(blob); + + // Create an anchor element with the data URL as the href attribute + const downloadLink = document.createElement('a'); + downloadLink.href = dataURL; + + // Set the download attribute to specify the desired filename for the downloaded image + downloadLink.download = path; + + // Trigger the download + downloadLink.click(); + + // Clean up: remove the anchor element from the DOM + downloadLink.remove(); + + } else if (!_env_js__WEBPACK_IMPORTED_MODULE_1__.env.useFS) { + throw new Error('Unable to save the image because filesystem is disabled in this environment.') + + } else { + const img = this.toSharp(); + return await img.toFile(path); + } + } + + toSharp() { + if (BROWSER_ENV) { + throw new Error('toSharp() is only supported in server-side environments.') + } + + return sharp__WEBPACK_IMPORTED_MODULE_3__(this.data, { + raw: { + width: this.width, + height: this.height, + channels: this.channels + } + }); + } +} + + +/***/ }), + +/***/ "./src/utils/maths.js": +/*!****************************!*\ + !*** ./src/utils/maths.js ***! + \****************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "FFT": () => (/* binding */ FFT), +/* harmony export */ "bankers_round": () => (/* binding */ bankers_round), +/* harmony export */ "cos_sim": () => (/* binding */ cos_sim), +/* harmony export */ "dot": () => (/* binding */ dot), +/* harmony export */ "getTopItems": () => (/* binding */ getTopItems), +/* harmony export */ "interpolate_data": () => (/* binding */ interpolate_data), +/* harmony export */ "log_softmax": () => (/* binding */ log_softmax), +/* harmony export */ "magnitude": () => (/* binding */ magnitude), +/* harmony export */ "max": () => (/* binding */ max), +/* harmony export */ "medianFilter": () => (/* binding */ medianFilter), +/* harmony export */ "min": () => (/* binding */ min), +/* harmony export */ "permute_data": () => (/* binding */ permute_data), +/* harmony export */ "round": () => (/* binding */ round), +/* harmony export */ "softmax": () => (/* binding */ softmax) +/* harmony export */ }); + +/** + * @file Helper module for mathematical processing. + * + * These functions and classes are only used internally, + * meaning an end-user shouldn't need to access anything here. + * + * @module utils/maths + */ + +/** + * @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array} TypedArray + * @typedef {BigInt64Array | BigUint64Array} BigTypedArray + * @typedef {TypedArray | BigTypedArray} AnyTypedArray + */ + +/** + * @param {TypedArray} input + */ +function interpolate_data(input, [in_channels, in_height, in_width], [out_height, out_width], mode = 'bilinear', align_corners = false) { + // TODO use mode and align_corners + + // Output image dimensions + const x_scale = out_width / in_width; + const y_scale = out_height / in_height; + + // Output image + // @ts-ignore + const out_img = new input.constructor(out_height * out_width * in_channels); + + // Pre-calculate strides + const inStride = in_height * in_width; + const outStride = out_height * out_width; + + for (let i = 0; i < out_height; ++i) { + for (let j = 0; j < out_width; ++j) { + // Calculate output offset + const outOffset = i * out_width + j; + + // Calculate input pixel coordinates + const x = (j + 0.5) / x_scale - 0.5; + const y = (i + 0.5) / y_scale - 0.5; + + // Calculate the four nearest input pixels + // We also check if the input pixel coordinates are within the image bounds + let x1 = Math.floor(x); + let y1 = Math.floor(y); + const x2 = Math.min(x1 + 1, in_width - 1); + const y2 = Math.min(y1 + 1, in_height - 1); + + x1 = Math.max(x1, 0); + y1 = Math.max(y1, 0); + + + // Calculate the fractional distances between the input pixel and the four nearest pixels + const s = x - x1; + const t = y - y1; + + // Perform bilinear interpolation + const w1 = (1 - s) * (1 - t); + const w2 = s * (1 - t); + const w3 = (1 - s) * t; + const w4 = s * t; + + // Calculate the four nearest input pixel indices + const yStride = y1 * in_width; + const xStride = y2 * in_width; + const idx1 = yStride + x1; + const idx2 = yStride + x2; + const idx3 = xStride + x1; + const idx4 = xStride + x2; + + for (let k = 0; k < in_channels; ++k) { + // Calculate channel offset + const cOffset = k * inStride; + + out_img[k * outStride + outOffset] = + w1 * input[cOffset + idx1] + + w2 * input[cOffset + idx2] + + w3 * input[cOffset + idx3] + + w4 * input[cOffset + idx4]; + } + } + } + + return out_img; +} + + +/** + * Helper method to permute a `AnyTypedArray` directly + * @template {AnyTypedArray} T + * @param {T} array + * @param {number[]} dims + * @param {number[]} axes + * @returns {[T, number[]]} The permuted array and the new shape. + */ +function permute_data(array, dims, axes) { + // Calculate the new shape of the permuted array + // and the stride of the original array + const shape = new Array(axes.length); + const stride = new Array(axes.length); + + for (let i = axes.length - 1, s = 1; i >= 0; --i) { + stride[i] = s; + shape[i] = dims[axes[i]]; + s *= shape[i]; + } + + // Precompute inverse mapping of stride + const invStride = axes.map((_, i) => stride[axes.indexOf(i)]); + + // Create the permuted array with the new shape + // @ts-ignore + const permutedData = new array.constructor(array.length); + + // Permute the original array to the new array + for (let i = 0; i < array.length; ++i) { + let newIndex = 0; + for (let j = dims.length - 1, k = i; j >= 0; --j) { + newIndex += (k % dims[j]) * invStride[j]; + k = Math.floor(k / dims[j]); + } + permutedData[newIndex] = array[i]; + } + + return [permutedData, shape]; +} + + +/** + * Compute the softmax of an array of numbers. + * @template {TypedArray|number[]} T + * @param {T} arr The array of numbers to compute the softmax of. + * @returns {T} The softmax array. + */ +function softmax(arr) { + // Compute the maximum value in the array + const maxVal = max(arr)[0]; + + // Compute the exponentials of the array values + const exps = arr.map(x => Math.exp(x - maxVal)); + + // Compute the sum of the exponentials + // @ts-ignore + const sumExps = exps.reduce((acc, val) => acc + val, 0); + + // Compute the softmax values + const softmaxArr = exps.map(x => x / sumExps); + + return /** @type {T} */(softmaxArr); +} + +/** + * Calculates the logarithm of the softmax function for the input array. + * @template {TypedArray|number[]} T + * @param {T} arr The input array to calculate the log_softmax function for. + * @returns {T} The resulting log_softmax array. + */ +function log_softmax(arr) { + // Compute the softmax values + const softmaxArr = softmax(arr); + + // Apply log formula to each element + const logSoftmaxArr = softmaxArr.map(x => Math.log(x)); + + return /** @type {T} */(logSoftmaxArr); +} + +/** + * Calculates the dot product of two arrays. + * @param {number[]} arr1 The first array. + * @param {number[]} arr2 The second array. + * @returns {number} The dot product of arr1 and arr2. + */ +function dot(arr1, arr2) { + return arr1.reduce((acc, val, i) => acc + val * arr2[i], 0); +} + + +/** + * Get the top k items from an iterable, sorted by descending order + * @param {any[]|TypedArray} items The items to be sorted + * @param {number|null} [top_k=0] The number of top items to return (default: 0 = return all) + * @returns {[number, any][]} The top k items, sorted by descending order + */ +function getTopItems(items, top_k = 0) { + // if top == 0, return all + + items = Array.from(items) + .map((x, i) => [i, x]) // Get indices ([index, score]) + .sort((a, b) => b[1] - a[1]) // Sort by log probabilities + + if (top_k !== null && top_k > 0) { + items = items.slice(0, top_k); // Get top k items + } + + return items +} + +/** + * Computes the cosine similarity between two arrays. + * + * @param {number[]} arr1 The first array. + * @param {number[]} arr2 The second array. + * @returns {number} The cosine similarity between the two arrays. + */ +function cos_sim(arr1, arr2) { + // Calculate dot product of the two arrays + const dotProduct = dot(arr1, arr2); + + // Calculate the magnitude of the first array + const magnitudeA = magnitude(arr1); + + // Calculate the magnitude of the second array + const magnitudeB = magnitude(arr2); + + // Calculate the cosine similarity + const cosineSimilarity = dotProduct / (magnitudeA * magnitudeB); + + return cosineSimilarity; +} + +/** + * Calculates the magnitude of a given array. + * @param {number[]} arr The array to calculate the magnitude of. + * @returns {number} The magnitude of the array. + */ +function magnitude(arr) { + return Math.sqrt(arr.reduce((acc, val) => acc + val * val, 0)); +} + + +/** + * Returns the value and index of the minimum element in an array. + * @param {number[]|TypedArray} arr array of numbers. + * @returns {number[]} the value and index of the minimum element, of the form: [valueOfMin, indexOfMin] + * @throws {Error} If array is empty. + */ +function min(arr) { + if (arr.length === 0) throw Error('Array must not be empty'); + let min = arr[0]; + let indexOfMin = 0; + for (let i = 1; i < arr.length; ++i) { + if (arr[i] < min) { + min = arr[i]; + indexOfMin = i; + } + } + return [min, indexOfMin]; +} + + +/** + * Returns the value and index of the maximum element in an array. + * @param {number[]|AnyTypedArray} arr array of numbers. + * @returns {[number, number]} the value and index of the maximum element, of the form: [valueOfMax, indexOfMax] + * @throws {Error} If array is empty. + */ +function max(arr) { + if (arr.length === 0) throw Error('Array must not be empty'); + let max = arr[0]; + let indexOfMax = 0; + for (let i = 1; i < arr.length; ++i) { + if (arr[i] > max) { + max = arr[i]; + indexOfMax = i; + } + } + return [Number(max), indexOfMax]; +} + +function isPowerOfTwo(number) { + // Check if the number is greater than 0 and has only one bit set to 1 + return (number > 0) && ((number & (number - 1)) === 0); +} + +/** + * Implementation of Radix-4 FFT. + * + * P2FFT class provides functionality for performing Fast Fourier Transform on arrays + * which are a power of two in length. + * Code adapted from https://www.npmjs.com/package/fft.js + */ +class P2FFT { + /** + * @param {number} size The size of the input array. Must be a power of two larger than 1. + * @throws {Error} FFT size must be a power of two larger than 1. + */ + constructor(size) { + this.size = size | 0; // convert to a 32-bit signed integer + if (this.size <= 1 || !isPowerOfTwo(this.size)) + throw new Error('FFT size must be a power of two larger than 1'); + + this._csize = size << 1; + + this.table = new Float64Array(this.size * 2); + for (let i = 0; i < this.table.length; i += 2) { + const angle = Math.PI * i / this.size; + this.table[i] = Math.cos(angle); + this.table[i + 1] = -Math.sin(angle); + } + + // Find size's power of two + let power = 0; + for (let t = 1; this.size > t; t <<= 1) + ++power; + + // Calculate initial step's width: + // * If we are full radix-4, it is 2x smaller to give inital len=8 + // * Otherwise it is the same as `power` to give len=4 + this._width = power % 2 === 0 ? power - 1 : power; + + // Pre-compute bit-reversal patterns + this._bitrev = new Int32Array(1 << this._width); + for (let j = 0; j < this._bitrev.length; ++j) { + this._bitrev[j] = 0; + for (let shift = 0; shift < this._width; shift += 2) { + const revShift = this._width - shift - 2; + this._bitrev[j] |= ((j >>> shift) & 3) << revShift; + } + } + } + + /** + * Create a complex number array with size `2 * size` + * + * @returns {Float64Array} A complex number array with size `2 * size` + */ + createComplexArray() { + return new Float64Array(this._csize); + } + + /** + * Converts a complex number representation stored in a Float64Array to an array of real numbers. + * + * @param {Float64Array} complex The complex number representation to be converted. + * @param {number[]} [storage] An optional array to store the result in. + * @returns {number[]} An array of real numbers representing the input complex number representation. + */ + fromComplexArray(complex, storage) { + const res = storage || new Array(complex.length >>> 1); + for (let i = 0; i < complex.length; i += 2) + res[i >>> 1] = complex[i]; + return res; + } + + /** + * Convert a real-valued input array to a complex-valued output array. + * @param {Float64Array} input The real-valued input array. + * @param {Float64Array} [storage] Optional buffer to store the output array. + * @returns {Float64Array} The complex-valued output array. + */ + toComplexArray(input, storage) { + const res = storage || this.createComplexArray(); + for (let i = 0; i < res.length; i += 2) { + res[i] = input[i >>> 1]; + res[i + 1] = 0; + } + return res; + } + + /** + * Completes the spectrum by adding its mirrored negative frequency components. + * @param {Float64Array} spectrum The input spectrum. + * @returns {void} + */ + completeSpectrum(spectrum) { + const size = this._csize; + const half = size >>> 1; + for (let i = 2; i < half; i += 2) { + spectrum[size - i] = spectrum[i]; + spectrum[size - i + 1] = -spectrum[i + 1]; + } + } + + /** + * Performs a Fast Fourier Transform (FFT) on the given input data and stores the result in the output buffer. + * + * @param {Float64Array} out The output buffer to store the result. + * @param {Float64Array} data The input data to transform. + * + * @throws {Error} Input and output buffers must be different. + * + * @returns {void} + */ + transform(out, data) { + if (out === data) + throw new Error('Input and output buffers must be different'); + + this._transform4(out, data, 1 /* DONE */); + } + + /** + * Performs a real-valued forward FFT on the given input buffer and stores the result in the given output buffer. + * The input buffer must contain real values only, while the output buffer will contain complex values. The input and + * output buffers must be different. + * + * @param {Float64Array} out The output buffer. + * @param {Float64Array} data The input buffer containing real values. + * + * @throws {Error} If the input and output buffers are the same. + */ + realTransform(out, data) { + if (out === data) + throw new Error('Input and output buffers must be different'); + + this._realTransform4(out, data, 1 /* DONE */); + } + + /** + * Performs an inverse FFT transformation on the given `data` array, and stores the result in `out`. + * The `out` array must be a different buffer than the `data` array. The `out` array will contain the + * result of the transformation. The `data` array will not be modified. + * + * @param {Float64Array} out The output buffer for the transformed data. + * @param {Float64Array} data The input data to transform. + * @throws {Error} If `out` and `data` refer to the same buffer. + * @returns {void} + */ + inverseTransform(out, data) { + if (out === data) + throw new Error('Input and output buffers must be different'); + + this._transform4(out, data, -1 /* DONE */); + for (let i = 0; i < out.length; ++i) + out[i] /= this.size; + } + + /** + * Performs a radix-4 implementation of a discrete Fourier transform on a given set of data. + * + * @param {Float64Array} out The output buffer for the transformed data. + * @param {Float64Array} data The input buffer of data to be transformed. + * @param {number} inv A scaling factor to apply to the transform. + * @returns {void} + */ + _transform4(out, data, inv) { + // radix-4 implementation + + const size = this._csize; + + // Initial step (permute and transform) + const width = this._width; + let step = 1 << width; + let len = (size / step) << 1; + + let outOff; + let t; + const bitrev = this._bitrev; + if (len === 4) { + for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) { + const off = bitrev[t]; + this._singleTransform2(data, out, outOff, off, step); + } + } else { + // len === 8 + for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) { + const off = bitrev[t]; + this._singleTransform4(data, out, outOff, off, step, inv); + } + } + + // Loop through steps in decreasing order + for (step >>= 2; step >= 2; step >>= 2) { + len = (size / step) << 1; + const quarterLen = len >>> 2; + + // Loop through offsets in the data + for (outOff = 0; outOff < size; outOff += len) { + // Full case + const limit = outOff + quarterLen - 1; + for (let i = outOff, k = 0; i < limit; i += 2, k += step) { + const A = i; + const B = A + quarterLen; + const C = B + quarterLen; + const D = C + quarterLen; + + // Original values + const Ar = out[A]; + const Ai = out[A + 1]; + const Br = out[B]; + const Bi = out[B + 1]; + const Cr = out[C]; + const Ci = out[C + 1]; + const Dr = out[D]; + const Di = out[D + 1]; + + const tableBr = this.table[k]; + const tableBi = inv * this.table[k + 1]; + const MBr = Br * tableBr - Bi * tableBi; + const MBi = Br * tableBi + Bi * tableBr; + + const tableCr = this.table[2 * k]; + const tableCi = inv * this.table[2 * k + 1]; + const MCr = Cr * tableCr - Ci * tableCi; + const MCi = Cr * tableCi + Ci * tableCr; + + const tableDr = this.table[3 * k]; + const tableDi = inv * this.table[3 * k + 1]; + const MDr = Dr * tableDr - Di * tableDi; + const MDi = Dr * tableDi + Di * tableDr; + + // Pre-Final values + const T0r = Ar + MCr; + const T0i = Ai + MCi; + const T1r = Ar - MCr; + const T1i = Ai - MCi; + const T2r = MBr + MDr; + const T2i = MBi + MDi; + const T3r = inv * (MBr - MDr); + const T3i = inv * (MBi - MDi); + + // Final values + out[A] = T0r + T2r; + out[A + 1] = T0i + T2i; + out[B] = T1r + T3i; + out[B + 1] = T1i - T3r; + out[C] = T0r - T2r; + out[C + 1] = T0i - T2i; + out[D] = T1r - T3i; + out[D + 1] = T1i + T3r; + } + } + } + } + + /** + * Performs a radix-2 implementation of a discrete Fourier transform on a given set of data. + * + * @param {Float64Array} data The input buffer of data to be transformed. + * @param {Float64Array} out The output buffer for the transformed data. + * @param {number} outOff The offset at which to write the output data. + * @param {number} off The offset at which to begin reading the input data. + * @param {number} step The step size for indexing the input data. + * @returns {void} + */ + _singleTransform2(data, out, outOff, off, step) { + // radix-2 implementation + // NOTE: Only called for len=4 + + const evenR = data[off]; + const evenI = data[off + 1]; + const oddR = data[off + step]; + const oddI = data[off + step + 1]; + + out[outOff] = evenR + oddR; + out[outOff + 1] = evenI + oddI; + out[outOff + 2] = evenR - oddR; + out[outOff + 3] = evenI - oddI; + } + + /** + * Performs radix-4 transformation on input data of length 8 + * + * @param {Float64Array} data Input data array of length 8 + * @param {Float64Array} out Output data array of length 8 + * @param {number} outOff Index of output array to start writing from + * @param {number} off Index of input array to start reading from + * @param {number} step Step size between elements in input array + * @param {number} inv Scaling factor for inverse transform + * + * @returns {void} + */ + _singleTransform4(data, out, outOff, off, step, inv) { + // radix-4 + // NOTE: Only called for len=8 + const step2 = step * 2; + const step3 = step * 3; + + // Original values + const Ar = data[off]; + const Ai = data[off + 1]; + const Br = data[off + step]; + const Bi = data[off + step + 1]; + const Cr = data[off + step2]; + const Ci = data[off + step2 + 1]; + const Dr = data[off + step3]; + const Di = data[off + step3 + 1]; + + // Pre-Final values + const T0r = Ar + Cr; + const T0i = Ai + Ci; + const T1r = Ar - Cr; + const T1i = Ai - Ci; + const T2r = Br + Dr; + const T2i = Bi + Di; + const T3r = inv * (Br - Dr); + const T3i = inv * (Bi - Di); + + // Final values + out[outOff] = T0r + T2r; + out[outOff + 1] = T0i + T2i; + out[outOff + 2] = T1r + T3i; + out[outOff + 3] = T1i - T3r; + out[outOff + 4] = T0r - T2r; + out[outOff + 5] = T0i - T2i; + out[outOff + 6] = T1r - T3i; + out[outOff + 7] = T1i + T3r; + } + + /** + * Real input radix-4 implementation + * @param {Float64Array} out Output array for the transformed data + * @param {Float64Array} data Input array of real data to be transformed + * @param {number} inv The scale factor used to normalize the inverse transform + */ + _realTransform4(out, data, inv) { + // Real input radix-4 implementation + const size = this._csize; + + // Initial step (permute and transform) + const width = this._width; + let step = 1 << width; + let len = (size / step) << 1; + + let outOff; + let t; + const bitrev = this._bitrev; + if (len === 4) { + for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) { + const off = bitrev[t]; + this._singleRealTransform2(data, out, outOff, off >>> 1, step >>> 1); + } + } else { + // len === 8 + for (outOff = 0, t = 0; outOff < size; outOff += len, ++t) { + const off = bitrev[t]; + this._singleRealTransform4(data, out, outOff, off >>> 1, step >>> 1, inv); + } + } + + // TODO: Optimize once https://github.com/indutny/fft.js/issues/25 is fixed + // Loop through steps in decreasing order + for (step >>= 2; step >= 2; step >>= 2) { + len = (size / step) << 1; + const quarterLen = len >>> 2; + + // Loop through offsets in the data + for (outOff = 0; outOff < size; outOff += len) { + // Full case + const limit = outOff + quarterLen - 1; + for (let i = outOff, k = 0; i < limit; i += 2, k += step) { + const A = i; + const B = A + quarterLen; + const C = B + quarterLen; + const D = C + quarterLen; + + // Original values + const Ar = out[A]; + const Ai = out[A + 1]; + const Br = out[B]; + const Bi = out[B + 1]; + const Cr = out[C]; + const Ci = out[C + 1]; + const Dr = out[D]; + const Di = out[D + 1]; + + const tableBr = this.table[k]; + const tableBi = inv * this.table[k + 1]; + const MBr = Br * tableBr - Bi * tableBi; + const MBi = Br * tableBi + Bi * tableBr; + + const tableCr = this.table[2 * k]; + const tableCi = inv * this.table[2 * k + 1]; + const MCr = Cr * tableCr - Ci * tableCi; + const MCi = Cr * tableCi + Ci * tableCr; + + const tableDr = this.table[3 * k]; + const tableDi = inv * this.table[3 * k + 1]; + const MDr = Dr * tableDr - Di * tableDi; + const MDi = Dr * tableDi + Di * tableDr; + + // Pre-Final values + const T0r = Ar + MCr; + const T0i = Ai + MCi; + const T1r = Ar - MCr; + const T1i = Ai - MCi; + const T2r = MBr + MDr; + const T2i = MBi + MDi; + const T3r = inv * (MBr - MDr); + const T3i = inv * (MBi - MDi); + + // Final values + out[A] = T0r + T2r; + out[A + 1] = T0i + T2i; + out[B] = T1r + T3i; + out[B + 1] = T1i - T3r; + out[C] = T0r - T2r; + out[C + 1] = T0i - T2i; + out[D] = T1r - T3i; + out[D + 1] = T1i + T3r; + } + } + } + } + + /** + * Performs a single real input radix-2 transformation on the provided data + * + * @param {Float64Array} data The input data array + * @param {Float64Array} out The output data array + * @param {number} outOff The output offset + * @param {number} off The input offset + * @param {number} step The step + * + * @returns {void} + */ + _singleRealTransform2(data, out, outOff, off, step) { + // radix-2 implementation + // NOTE: Only called for len=4 + + const evenR = data[off]; + const oddR = data[off + step]; + + out[outOff] = evenR + oddR; + out[outOff + 1] = 0; + out[outOff + 2] = evenR - oddR; + out[outOff + 3] = 0; + } + + /** + * Computes a single real-valued transform using radix-4 algorithm. + * This method is only called for len=8. + * + * @param {Float64Array} data The input data array. + * @param {Float64Array} out The output data array. + * @param {number} outOff The offset into the output array. + * @param {number} off The offset into the input array. + * @param {number} step The step size for the input array. + * @param {number} inv The value of inverse. + */ + _singleRealTransform4(data, out, outOff, off, step, inv) { + // radix-4 + // NOTE: Only called for len=8 + const step2 = step * 2; + const step3 = step * 3; + + // Original values + const Ar = data[off]; + const Br = data[off + step]; + const Cr = data[off + step2]; + const Dr = data[off + step3]; + + // Pre-Final values + const T0r = Ar + Cr; + const T1r = Ar - Cr; + const T2r = Br + Dr; + const T3r = inv * (Br - Dr); + + // Final values + out[outOff] = T0r + T2r; + out[outOff + 1] = 0; + out[outOff + 2] = T1r; + out[outOff + 3] = -T3r; + out[outOff + 4] = T0r - T2r; + out[outOff + 5] = 0; + out[outOff + 6] = T1r; + out[outOff + 7] = T3r; + } +} + +/** + * NP2FFT class provides functionality for performing Fast Fourier Transform on arrays + * which are not a power of two in length. In such cases, the chirp-z transform is used. + * + * For more information, see: https://math.stackexchange.com/questions/77118/non-power-of-2-ffts/77156#77156 + */ +class NP2FFT { + + /** + * Constructs a new NP2FFT object. + * @param {number} fft_length The length of the FFT + */ + constructor(fft_length) { + // Helper variables + const a = 2 * (fft_length - 1); + const b = 2 * (2 * fft_length - 1); + const nextP2 = 2 ** (Math.ceil(Math.log2(b))) + this.bufferSize = nextP2; + this._a = a; + + // Define buffers + // Compute chirp for transform + const chirp = new Float64Array(b); + const ichirp = new Float64Array(nextP2); + this._chirpBuffer = new Float64Array(nextP2); + this._buffer1 = new Float64Array(nextP2); + this._buffer2 = new Float64Array(nextP2); + this._outBuffer1 = new Float64Array(nextP2); + this._outBuffer2 = new Float64Array(nextP2); + + // Compute complex exponentiation + const theta = -2 * Math.PI / fft_length; + const baseR = Math.cos(theta); + const baseI = Math.sin(theta); + + // Precompute helper for chirp-z transform + for (let i = 0; i < b >> 1; ++i) { + // Compute complex power: + const e = (i + 1 - fft_length) ** 2 / 2.0; + + // Compute the modulus and argument of the result + const result_mod = Math.sqrt(baseR ** 2 + baseI ** 2) ** e; + const result_arg = e * Math.atan2(baseI, baseR); + + // Convert the result back to rectangular form + // and assign to chirp and ichirp + const i2 = 2 * i; + chirp[i2] = result_mod * Math.cos(result_arg); + chirp[i2 + 1] = result_mod * Math.sin(result_arg); + + // conjugate + ichirp[i2] = chirp[i2]; + ichirp[i2 + 1] = - chirp[i2 + 1]; + } + this._slicedChirpBuffer = chirp.subarray(a, b); + + // create object to perform Fast Fourier Transforms + // with `nextP2` complex numbers + this._f = new P2FFT(nextP2 >> 1); + this._f.transform(this._chirpBuffer, ichirp); + } + + _transform(output, input, real) { + const ib1 = this._buffer1; + const ib2 = this._buffer2; + const ob2 = this._outBuffer1; + const ob3 = this._outBuffer2; + const cb = this._chirpBuffer; + const sb = this._slicedChirpBuffer; + const a = this._a; + + if (real) { + // Real multiplication + for (let j = 0; j < sb.length; j += 2) { + const j2 = j + 1 + const j3 = j >> 1; + + const a_real = input[j3]; + ib1[j] = a_real * sb[j]; + ib1[j2] = a_real * sb[j2]; + } + } else { + // Complex multiplication + for (let j = 0; j < sb.length; j += 2) { + const j2 = j + 1 + ib1[j] = input[j] * sb[j] - input[j2] * sb[j2]; + ib1[j2] = input[j] * sb[j2] + input[j2] * sb[j]; + } + } + this._f.transform(ob2, ib1); + + for (let j = 0; j < cb.length; j += 2) { + const j2 = j + 1; + + ib2[j] = ob2[j] * cb[j] - ob2[j2] * cb[j2]; + ib2[j2] = ob2[j] * cb[j2] + ob2[j2] * cb[j]; + } + this._f.inverseTransform(ob3, ib2); + + for (let j = 0; j < ob3.length; j += 2) { + const a_real = ob3[j + a]; + const a_imag = ob3[j + a + 1]; + const b_real = sb[j]; + const b_imag = sb[j + 1]; + + output[j] = a_real * b_real - a_imag * b_imag; + output[j + 1] = a_real * b_imag + a_imag * b_real; + } + } + + transform(output, input) { + this._transform(output, input, false); + } + + realTransform(output, input) { + this._transform(output, input, true); + } +} + +class FFT { + constructor(fft_length) { + this.fft_length = fft_length; + this.isPowerOfTwo = isPowerOfTwo(fft_length); + if (this.isPowerOfTwo) { + this.fft = new P2FFT(fft_length); + this.outputBufferSize = 2 * fft_length; + } else { + this.fft = new NP2FFT(fft_length); + this.outputBufferSize = this.fft.bufferSize; + } + } + + realTransform(out, input) { + this.fft.realTransform(out, input); + } + + transform(out, input) { + this.fft.transform(out, input); + } +} + + +/** + * Performs median filter on the provided data. Padding is done by mirroring the data. + * @param {AnyTypedArray} data The input array + * @param {number} windowSize The window size + */ +function medianFilter(data, windowSize) { + + if (windowSize % 2 === 0 || windowSize <= 0) { + throw new Error('Window size must be a positive odd number'); + } + + // @ts-ignore + const outputArray = new data.constructor(data.length); + + // @ts-ignore + const buffer = new data.constructor(windowSize); // Reusable array for storing values + + const halfWindowSize = Math.floor(windowSize / 2); + + for (let i = 0; i < data.length; ++i) { + let valuesIndex = 0; + + for (let j = -halfWindowSize; j <= halfWindowSize; ++j) { + let index = i + j; + if (index < 0) { + index = Math.abs(index); + } else if (index >= data.length) { + index = 2 * (data.length - 1) - index; + } + + buffer[valuesIndex++] = data[index]; + } + + buffer.sort(); + outputArray[i] = buffer[halfWindowSize]; + } + + return outputArray; +} + +/** + * Helper function to round a number to a given number of decimals + * @param {number} num The number to round + * @param {number} decimals The number of decimals + * @returns {number} The rounded number + */ +function round(num, decimals) { + const pow = Math.pow(10, decimals); + return Math.round(num * pow) / pow; +} + +/** + * Helper function to round a number to the nearest integer, with ties rounded to the nearest even number. + * Also known as "bankers' rounding". This is the default rounding mode in python. For example: + * 1.5 rounds to 2 and 2.5 rounds to 2. + * + * @param {number} x The number to round + * @returns {number} The rounded number + */ +function bankers_round(x) { + const r = Math.round(x); + const br = Math.abs(x) % 1 === 0.5 ? (r % 2 === 0 ? r : r - 1) : r; + return br; +} + + +/***/ }), + +/***/ "./src/utils/tensor.js": +/*!*****************************!*\ + !*** ./src/utils/tensor.js ***! + \*****************************/ +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "Tensor": () => (/* binding */ Tensor), +/* harmony export */ "cat": () => (/* binding */ cat), +/* harmony export */ "dynamicTimeWarping": () => (/* binding */ dynamicTimeWarping), +/* harmony export */ "interpolate": () => (/* binding */ interpolate), +/* harmony export */ "layer_norm": () => (/* binding */ layer_norm), +/* harmony export */ "mean": () => (/* binding */ mean), +/* harmony export */ "mean_pooling": () => (/* binding */ mean_pooling), +/* harmony export */ "ones": () => (/* binding */ ones), +/* harmony export */ "ones_like": () => (/* binding */ ones_like), +/* harmony export */ "permute": () => (/* binding */ permute), +/* harmony export */ "stack": () => (/* binding */ stack), +/* harmony export */ "std_mean": () => (/* binding */ std_mean) +/* harmony export */ }); +/* harmony import */ var _backends_onnx_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../backends/onnx.js */ "./src/backends/onnx.js"); +/* harmony import */ var _maths_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./maths.js */ "./src/utils/maths.js"); +/** + * @file Helper module for `Tensor` processing. + * + * These functions and classes are only used internally, + * meaning an end-user shouldn't need to access anything here. + * + * @module utils/tensor + */ + + + + + + +const DataTypeMap = Object.freeze({ + float32: Float32Array, + float64: Float64Array, + string: Array, // string[] + int8: Int8Array, + uint8: Uint8Array, + int16: Int16Array, + uint16: Uint16Array, + int32: Int32Array, + uint32: Uint32Array, + int64: BigInt64Array, + uint64: BigUint64Array, + bool: Uint8Array, +}); + +/** + * @typedef {keyof typeof DataTypeMap} DataType + * @typedef {import('./maths.js').AnyTypedArray | any[]} DataArray + */ + +const ONNXTensor = _backends_onnx_js__WEBPACK_IMPORTED_MODULE_0__.ONNX.Tensor; + +class Tensor { + /** @type {number[]} Dimensions of the tensor. */ + dims; + + /** @type {DataType} Type of the tensor. */ + type; + + /** @type {DataArray} The data stored in the tensor. */ + data; + + /** @type {number} The number of elements in the tensor. */ + size; + + /** + * Create a new Tensor or copy an existing Tensor. + * @param {[DataType, DataArray, number[]]|[import('onnxruntime-common').Tensor]} args + */ + constructor(...args) { + if (args[0] instanceof ONNXTensor) { + // Create shallow copy + Object.assign(this, args[0]); + + } else { + // Create new tensor + Object.assign(this, new ONNXTensor( + /** @type {DataType} */(args[0]), + /** @type {Exclude} */(args[1]), + args[2] + )); + } + + return new Proxy(this, { + get: (obj, key) => { + if (typeof key === 'string') { + let index = Number(key); + if (Number.isInteger(index)) { + // key is an integer (i.e., index) + return obj._getitem(index); + } + } + // @ts-ignore + return obj[key]; + }, + set: (obj, key, value) => { + // TODO allow setting of data + + // @ts-ignore + return obj[key] = value; + } + }); + } + + /** + * Returns an iterator object for iterating over the tensor data in row-major order. + * If the tensor has more than one dimension, the iterator will yield subarrays. + * @returns {Iterator} An iterator object for iterating over the tensor data in row-major order. + */ + *[Symbol.iterator]() { + const [iterLength, ...iterDims] = this.dims; + + if (iterDims.length > 0) { + const iterSize = iterDims.reduce((a, b) => a * b); + for (let i = 0; i < iterLength; ++i) { + yield this._subarray(i, iterSize, iterDims); + } + } else { + yield* this.data + } + + } + + /** + * Index into a Tensor object. + * @param {number} index The index to access. + * @returns {Tensor} The data at the specified index. + */ + _getitem(index) { + const [iterLength, ...iterDims] = this.dims; + + index = safeIndex(index, iterLength); + + if (iterDims.length > 0) { + const iterSize = iterDims.reduce((a, b) => a * b); + return this._subarray(index, iterSize, iterDims); + } else { + return new Tensor(this.type, [this.data[index]], iterDims); + } + } + + /** + * @param {number|bigint} item The item to search for in the tensor + * @returns {number} The index of the first occurrence of item in the tensor data. + */ + indexOf(item) { + for (let index = 0; index < this.data.length; ++index) { + // Note: == instead of === so we can match Ints with BigInts + if (this.data[index] == item) { + return index; + } + } + return -1; + } + + /** + * @param {number} index + * @param {number} iterSize + * @param {any} iterDims + * @returns {Tensor} + */ + _subarray(index, iterSize, iterDims) { + const o1 = index * iterSize; + const o2 = (index + 1) * iterSize; + + // We use subarray if available (typed array), otherwise we use slice (normal array) + const data = + ('subarray' in this.data) + ? this.data.subarray(o1, o2) + : this.data.slice(o1, o2); + return new Tensor(this.type, data, iterDims); + } + + /** + * Returns the value of this tensor as a standard JavaScript Number. This only works + * for tensors with one element. For other cases, see `Tensor.tolist()`. + * @returns {number|bigint} The value of this tensor as a standard JavaScript Number. + * @throws {Error} If the tensor has more than one element. + */ + item() { + if (this.data.length !== 1) { + throw new Error(`a Tensor with ${this.data.length} elements cannot be converted to Scalar`); + } + return this.data[0]; + } + + /** + * Convert tensor data to a n-dimensional JS list + * @returns {Array} + */ + tolist() { + return reshape(this.data, this.dims) + } + + /** + * Return a new Tensor with the sigmoid function applied to each element. + * @returns {Tensor} The tensor with the sigmoid function applied. + */ + sigmoid() { + return this.clone().sigmoid_(); + } + + /** + * Applies the sigmoid function to the tensor in place. + * @returns {Tensor} Returns `this`. + */ + sigmoid_() { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] = 1 / (1 + Math.exp(-this.data[i])); + } + return this; + } + + /** + * Return a new Tensor with every element multiplied by a constant. + * @param {number} val The value to multiply by. + * @returns {Tensor} The new tensor. + */ + mul(val) { + return this.clone().mul_(val); + } + + /** + * Multiply the tensor by a constant in place. + * @param {number} val The value to multiply by. + * @returns {Tensor} Returns `this`. + */ + mul_(val) { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] *= val; + } + return this; + } + + + /** + * Return a new Tensor with every element added by a constant. + * @param {number} val The value to add by. + * @returns {Tensor} The new tensor. + */ + add(val) { + return this.clone().add_(val); + } + + /** + * Add the tensor by a constant in place. + * @param {number} val The value to add by. + * @returns {Tensor} Returns `this`. + */ + add_(val) { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] += val; + } + return this; + } + clone() { + return new Tensor(this.type, this.data.slice(), this.dims.slice()); + } + + slice(...slices) { + // This allows for slicing with ranges and numbers + let newTensorDims = []; + let newOffsets = []; + + // slices is an array of numbers or arrays of numbers + // e.g., slices = [0, [1, 3], null, [0, 3]] + for (let sliceIndex = 0; sliceIndex < this.dims.length; ++sliceIndex) { + let slice = slices[sliceIndex]; + + if (slice === null || slice === undefined) { + // null or undefined means take the whole dimension + newOffsets.push([0, this.dims[sliceIndex]]); + newTensorDims.push(this.dims[sliceIndex]); + + } else if (typeof slice === 'number') { + slice = safeIndex(slice, this.dims[sliceIndex], sliceIndex); + + // A number means take a single element + newOffsets.push([slice, slice + 1]); + + } else if (Array.isArray(slice) && slice.length === 2) { + // An array of length 2 means take a range of elements + + if (slice[0] > slice[1]) { + throw new Error(`Invalid slice: ${slice}`); + } + + let offsets = [ + Math.max(slice[0], 0), + Math.min(slice[1], this.dims[sliceIndex]) + ]; + + newOffsets.push(offsets); + newTensorDims.push(offsets[1] - offsets[0]); + + } else { + throw new Error(`Invalid slice: ${slice}`); + } + } + + let newDims = newOffsets.map(([start, end]) => end - start); + let newBufferSize = newDims.reduce((a, b) => a * b); + + // Allocate memory + // @ts-ignore + let data = new this.data.constructor(newBufferSize); + + // Precompute strides + const stride = this.stride(); + + for (let i = 0; i < newBufferSize; ++i) { + let originalIndex = 0; + for (let j = newDims.length - 1, num = i; j >= 0; --j) { + const size = newDims[j]; + originalIndex += ((num % size) + newOffsets[j][0]) * stride[j]; + num = Math.floor(num / size); + } + data[i] = this.data[originalIndex]; + } + return new Tensor(this.type, data, newTensorDims); + + } + + /** + * Return a permuted version of this Tensor, according to the provided dimensions. + * @param {...number} dims Dimensions to permute. + * @returns {Tensor} The permuted tensor. + */ + permute(...dims) { + return permute(this, dims); + } + + // TODO: implement transpose. For now (backwards compatibility), it's just an alias for permute() + transpose(...dims) { + return this.permute(...dims); + } + + // TODO add .max() and .min() methods + + /** + * Returns the sum of each row of the input tensor in the given dimension dim. + * + * @param {number} [dim=null] The dimension or dimensions to reduce. If `null`, all dimensions are reduced. + * @param {boolean} keepdim Whether the output tensor has `dim` retained or not. + * @returns The summed tensor + */ + sum(dim = null, keepdim = false) { + return this.norm(1, dim, keepdim); + } + + /** + * Returns the matrix norm or vector norm of a given tensor. + * @param {number|string} [p='fro'] The order of norm + * @param {number} [dim=null] Specifies which dimension of the tensor to calculate the norm across. + * If dim is None, the norm will be calculated across all dimensions of input. + * @param {boolean} [keepdim=false] Whether the output tensors have dim retained or not. + * @returns {Tensor} The norm of the tensor. + */ + norm(p = 'fro', dim = null, keepdim = false) { + if (p === 'fro') { + // NOTE: Since we only support integer dims, Frobenius norm produces the same result as p=2. + p = 2; + } else if (typeof p === 'string') { + throw Error(`Unsupported norm: ${p}`); + } + + if (dim === null) { + // @ts-ignore + let val = this.data.reduce((a, b) => a + (b ** p), 0) ** (1 / p); + return new Tensor(this.type, [val], []); + } + + // Negative indexing + dim = safeIndex(dim, this.dims.length); + + // Calculate the shape of the resulting array after summation + const resultDims = this.dims.slice(); // Copy the original dimensions + resultDims[dim] = 1; // Remove the specified axis + + // Create a new array to store the accumulated values + // @ts-ignore + const result = new this.data.constructor(this.data.length / this.dims[dim]); + + // Iterate over the data array + for (let i = 0; i < this.data.length; ++i) { + + // Calculate the index in the resulting array + let resultIndex = 0; + + for (let j = this.dims.length - 1, num = i, resultMultiplier = 1; j >= 0; --j) { + const size = this.dims[j]; + if (j !== dim) { + const index = num % size; + resultIndex += index * resultMultiplier; + resultMultiplier *= resultDims[j]; + } + num = Math.floor(num / size); + } + + // Accumulate the value at the current index + result[resultIndex] += (this.data[i]) ** p; + } + + if (p !== 1) { + for (let i = 0; i < result.length; ++i) { + result[i] = result[i] ** (1 / p); + } + } + + if (!keepdim) { + resultDims.splice(dim, 1); + } + + return new Tensor(this.type, result, resultDims); + } + + /** + * Performs `L_p` normalization of inputs over specified dimension. Operates in place. + * @param {number} [p=2] The exponent value in the norm formulation + * @param {number} [dim=1] The dimension to reduce + * @returns {Tensor} `this` for operation chaining. + */ + normalize_(p = 2.0, dim = 1) { + dim = safeIndex(dim, this.dims.length); + + const norm = this.norm(p, dim, true); + + for (let i = 0; i < this.data.length; ++i) { + + // Calculate the index in the resulting array + let resultIndex = 0; + + for (let j = this.dims.length - 1, num = i, resultMultiplier = 1; j >= 0; --j) { + const size = this.dims[j]; + if (j !== dim) { + const index = num % size; + resultIndex += index * resultMultiplier; + resultMultiplier *= this.dims[j]; + } + num = Math.floor(num / size); + } + + // Divide by normalized value + this.data[i] /= norm.data[resultIndex]; + } + + return this; + } + + /** + * Performs `L_p` normalization of inputs over specified dimension. + * @param {number} [p=2] The exponent value in the norm formulation + * @param {number} [dim=1] The dimension to reduce + * @returns {Tensor} The normalized tensor. + */ + normalize(p = 2.0, dim = 1) { + return this.clone().normalize_(p, dim); + } + + /** + * Compute and return the stride of this tensor. + * Stride is the jump necessary to go from one element to the next one in the specified dimension dim. + * @returns {number[]} The stride of this tensor. + */ + stride() { + return dimsToStride(this.dims); + } + + /** + * Returns a tensor with all specified dimensions of input of size 1 removed. + * + * NOTE: The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other. + * If you would like a copy, use `tensor.clone()` before squeezing. + * + * @param {number} [dim=null] If given, the input will be squeezed only in the specified dimensions. + * @returns The squeezed tensor + */ + squeeze(dim = null) { + return new Tensor( + this.type, + this.data, + calc_squeeze_dims(this.dims, dim) + ) + } + + /** + * In-place version of @see {@link Tensor.squeeze} + */ + squeeze_(dim = null) { + this.dims = calc_squeeze_dims(this.dims, dim); + return this; + } + + /** + * Returns a new tensor with a dimension of size one inserted at the specified position. + * + * NOTE: The returned tensor shares the same underlying data with this tensor. + * + * @param {number} dim The index at which to insert the singleton dimension + * @returns The unsqueezed tensor + */ + unsqueeze(dim = null) { + return new Tensor( + this.type, + this.data, + calc_unsqueeze_dims(this.dims, dim) + ); + } + + /** + * In-place version of @see {@link Tensor.unsqueeze} + */ + unsqueeze_(dim = null) { + this.dims = calc_unsqueeze_dims(this.dims, dim); + return this; + } + + /** + * In-place version of @see {@link Tensor.flatten} + */ + flatten_(start_dim = 0, end_dim = -1) { + // TODO validate inputs + end_dim = (end_dim + this.dims.length) % this.dims.length; + + let dimsToKeepBefore = this.dims.slice(0, start_dim); + let dimsToFlatten = this.dims.slice(start_dim, end_dim + 1); + let dimsToKeepAfter = this.dims.slice(end_dim + 1); + + this.dims = [...dimsToKeepBefore, dimsToFlatten.reduce((a, b) => a * b, 1), ...dimsToKeepAfter] + return this; + } + + /** + * Flattens input by reshaping it into a one-dimensional tensor. + * If `start_dim` or `end_dim` are passed, only dimensions starting with `start_dim` + * and ending with `end_dim` are flattened. The order of elements in input is unchanged. + * @param {number} start_dim the first dim to flatten + * @param {number} end_dim the last dim to flatten + * @returns The flattened tensor. + */ + flatten(start_dim = 0, end_dim = -1) { + return this.clone().flatten_(start_dim, end_dim); + } + + /** + * Returns a new tensor with the same data as the `self` tensor but of a different `shape`. + * @param {...number} dims the desired size + * @returns {Tensor} The tensor with the same data but different shape + */ + view(...dims) { + // TODO: validate dims + let inferredIndex = -1; + for (let i = 0; i < dims.length; ++i) { + if (dims[i] === -1) { + if (inferredIndex !== -1) { + throw new Error("Only one dimension can be inferred"); + } + inferredIndex = i; + } + } + + if (inferredIndex !== -1) { + // Some dimension must be inferred + const productOther = dims.reduce((product, curr, index) => { + return index !== inferredIndex ? product * curr : product + }, 1); + + dims[inferredIndex] = this.data.length / productOther; + } + return new Tensor(this.type, this.data, dims); // NOTE: uses same underlying storage + } + + neg_() { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] = -this.data[i]; + } + return this; + } + neg() { + return this.clone().neg_(); + } + + /** + * In-place version of @see {@link Tensor.clamp} + */ + clamp_(min, max) { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] = Math.min(Math.max(this.data[i], min), max); + } + return this; + } + + /** + * Clamps all elements in input into the range [ min, max ] + * @param {number} min lower-bound of the range to be clamped to + * @param {number} max upper-bound of the range to be clamped to + * @returns the output tensor. + */ + clamp(min, max) { + return this.clone().clamp_(min, max); + } + + /** + * In-place version of @see {@link Tensor.round} + */ + round_() { + for (let i = 0; i < this.data.length; ++i) { + this.data[i] = Math.round(this.data[i]); + } + return this; + } + + /** + * Rounds elements of input to the nearest integer. + * @returns the output tensor. + */ + round() { + return this.clone().round_(); + } + + /** + * Performs Tensor dtype conversion. + * @param {DataType} type The desired data type. + * @returns {Tensor} The converted tensor. + */ + to(type) { + // If the self Tensor already has the correct dtype, then self is returned. + if (this.type === type) return this; + + // Otherwise, the returned tensor is a copy of self with the desired dtype. + if (!DataTypeMap.hasOwnProperty(type)) { + throw new Error(`Unsupported type: ${type}`); + } + // @ts-ignore + return new Tensor(type, DataTypeMap[type].from(this.data), this.dims); + } +} + +/** + * This creates a nested array of a given type and depth (see examples). + * + * @example + * NestArray; // string[] + * @example + * NestArray; // number[][] + * @example + * NestArray; // string[][][] etc. + * @template T + * @template {number} Depth + * @template {never[]} [Acc=[]] + * @typedef {Acc['length'] extends Depth ? T : NestArray} NestArray + */ + +/** + * Reshapes a 1-dimensional array into an n-dimensional array, according to the provided dimensions. + * + * @example + * reshape([10 ], [1 ]); // Type: number[] Value: [10] + * reshape([1, 2, 3, 4 ], [2, 2 ]); // Type: number[][] Value: [[1, 2], [3, 4]] + * reshape([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]); // Type: number[][][] Value: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] + * reshape([1, 2, 3, 4, 5, 6, 7, 8], [4, 2 ]); // Type: number[][] Value: [[1, 2], [3, 4], [5, 6], [7, 8]] + * @param {T[]|DataArray} data The input array to reshape. + * @param {DIM} dimensions The target shape/dimensions. + * @template T + * @template {[number]|number[]} DIM + * @returns {NestArray} The reshaped array. + */ +function reshape(data, dimensions) { + + const totalElements = data.length; + const dimensionSize = dimensions.reduce((a, b) => a * b); + + if (totalElements !== dimensionSize) { + throw Error(`cannot reshape array of size ${totalElements} into shape (${dimensions})`); + } + + /** @type {any} */ + let reshapedArray = data; + + for (let i = dimensions.length - 1; i >= 0; i--) { + reshapedArray = reshapedArray.reduce((acc, val) => { + let lastArray = acc[acc.length - 1]; + + if (lastArray.length < dimensions[i]) { + lastArray.push(val); + } else { + acc.push([val]); + } + + return acc; + }, [[]]); + } + + return reshapedArray[0]; +} + +/** + * Permutes a tensor according to the provided axes. + * @param {any} tensor The input tensor to permute. + * @param {Array} axes The axes to permute the tensor along. + * @returns {Tensor} The permuted tensor. + */ +function permute(tensor, axes) { + const [permutedData, shape] = (0,_maths_js__WEBPACK_IMPORTED_MODULE_1__.permute_data)(tensor.data, tensor.dims, axes); + return new Tensor(tensor.type, permutedData, shape); +} + + +/** + * Interpolates an Tensor to the given size. + * @param {Tensor} input The input tensor to interpolate. Data must be channel-first (i.e., [c, h, w]) + * @param {number[]} size The output size of the image + * @param {string} mode The interpolation mode + * @param {boolean} align_corners Whether to align corners. + * @returns {Tensor} The interpolated tensor. + */ +function interpolate(input, [out_height, out_width], mode = 'bilinear', align_corners = false) { + + // Input image dimensions + const in_channels = input.dims.at(-3) ?? 1; + const in_height = input.dims.at(-2); + const in_width = input.dims.at(-1); + + let output = (0,_maths_js__WEBPACK_IMPORTED_MODULE_1__.interpolate_data)( + /** @type {import('./maths.js').TypedArray}*/(input.data), + [in_channels, in_height, in_width], + [out_height, out_width], + mode, + align_corners + ); + return new Tensor(input.type, output, [in_channels, out_height, out_width]); +} + +/** + * Perform mean pooling of the last hidden state followed by a normalization step. + * @param {Tensor} last_hidden_state Tensor of shape [batchSize, seqLength, embedDim] + * @param {Tensor} attention_mask Tensor of shape [batchSize, seqLength] + * @returns {Tensor} Returns a new Tensor of shape [batchSize, embedDim]. + */ +function mean_pooling(last_hidden_state, attention_mask) { + // last_hidden_state: [batchSize, seqLength, embedDim] + // attention_mask: [batchSize, seqLength] + + let shape = [last_hidden_state.dims[0], last_hidden_state.dims[2]]; + // @ts-ignore + let returnedData = new last_hidden_state.data.constructor(shape[0] * shape[1]); + let [batchSize, seqLength, embedDim] = last_hidden_state.dims; + + let outIndex = 0; + for (let i = 0; i < batchSize; ++i) { + let offset = i * embedDim * seqLength; + + for (let k = 0; k < embedDim; ++k) { + let sum = 0; + let count = 0; + + let attnMaskOffset = i * seqLength; + let offset2 = offset + k; + // Pool over all words in sequence + for (let j = 0; j < seqLength; ++j) { + // index into attention mask + let attn = Number(attention_mask.data[attnMaskOffset + j]); + + count += attn; + sum += last_hidden_state.data[offset2 + j * embedDim] * attn; + } + + let avg = sum / count; + returnedData[outIndex++] = avg; + } + } + + return new Tensor( + last_hidden_state.type, + returnedData, + shape + ) +} + +/** + * Apply Layer Normalization for last certain number of dimensions. + * @param {Tensor} input The input tensor + * @param {number[]} normalized_shape input shape from an expected input of size + * @param {Object} options The options for the layer normalization + * @param {number} [options.eps=1e-5] A value added to the denominator for numerical stability. + * @returns {Tensor} The normalized tensor. + */ +function layer_norm(input, normalized_shape, { + eps = 1e-5, +} = {}) { + if (input.dims.length !== 2) { + throw new Error('`layer_norm` currently only supports 2D input.'); + } + + const [batchSize, featureDim] = input.dims; + + if (normalized_shape.length !== 1 && normalized_shape[0] !== featureDim) { + throw new Error('`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.'); + } + + const [std, mean] = std_mean(input, 1, 0, true); + + // @ts-ignore + const returnedData = new input.data.constructor(input.data.length); + + for (let i = 0; i < batchSize; ++i) { + const offset = i * featureDim; + for (let j = 0; j < featureDim; ++j) { + const offset2 = offset + j; + returnedData[offset2] = (input.data[offset2] - mean.data[i]) / (std.data[i] + eps); + } + } + return new Tensor(input.type, returnedData, input.dims); +} + +/** + * Helper function to calculate new dimensions when performing a squeeze operation. + * @param {number[]} dims The dimensions of the tensor. + * @param {number|number[]|null} dim The dimension(s) to squeeze. + * @returns The new dimensions. + * @private + */ +function calc_squeeze_dims(dims, dim) { + dims = dims.slice(); + if (dim === null) { + dims = dims.filter((d) => d !== 1); + } else if (typeof dim === 'number') { + if (dims[dim] === 1) { + dims.splice(dim, 1); + } + } else if (Array.isArray(dim)) { + dims = dims.filter((x, i) => { + return x !== 1 || !dim.includes(i); + }); + } + return dims; +} + +/** + * Helper function to calculate new dimensions when performing an unsqueeze operation. + * @param {number[]} dims The dimensions of the tensor. + * @param {number} dim The dimension to unsqueeze. + * @returns The new dimensions. + * @private + */ +function calc_unsqueeze_dims(dims, dim) { + // Dimension out of range (e.g., "expected to be in range of [-4, 3], but got 4") + // + 1 since we allow inserting at the end (i.e. dim = -1) + dim = safeIndex(dim, dims.length + 1); + dims = dims.slice(); + // Insert 1 into specified dimension + dims.splice(dim, 0, 1); + return dims; +} + +/** + * Safely calculate the index for an array of a given size, allowing negative indexing. + * @param {number} index The index that will be used. + * @param {number} size The size of the array. + * @param {number} [dimension=null] The dimension that the index is for (optional). + * @returns {number} The index, guaranteed to be non-negative and less than `arrayLength`. + * + * @throws {Error} If the index is out of range. + * @private + */ +function safeIndex(index, size, dimension = null) { + if (index < -size || index >= size) { + throw new Error(`IndexError: index ${index} is out of bounds for dimension${dimension === null ? '' : ' ' + dimension} with size ${size}`); + } + + if (index < 0) { + // Negative indexing, ensuring positive index + index = ((index % size) + size) % size; + } + return index; +} + +/** + * Concatenates an array of tensors along a specified dimension. + * @param {Tensor[]} tensors The array of tensors to concatenate. + * @param {number} dim The dimension to concatenate along. + * @returns {Tensor} The concatenated tensor. + */ +function cat(tensors, dim = 0) { + dim = safeIndex(dim, tensors[0].dims.length); + + // TODO do validation of shapes + + const resultDims = tensors[0].dims.slice(); + resultDims[dim] = tensors.reduce((a, b) => a + b.dims[dim], 0); + + // Create a new array to store the accumulated values + const resultSize = resultDims.reduce((a, b) => a * b, 1); + // @ts-ignore + const result = new tensors[0].data.constructor(resultSize); + + // Create output tensor of same type as first + const resultType = tensors[0].type; + + if (dim === 0) { + // Handle special case for performance reasons + + let offset = 0; + for (let t of tensors) { + result.set(t.data, offset); + offset += t.data.length; + } + + } else { + + let currentDim = 0; + + for (let t = 0; t < tensors.length; ++t) { + let tensor = tensors[t]; + + // Iterate over the data array + for (let i = 0; i < tensor.data.length; ++i) { + // Calculate the index in the resulting array + let resultIndex = 0; + + for (let j = tensor.dims.length - 1, num = i, resultMultiplier = 1; j >= 0; --j) { + const size = tensor.dims[j]; + let index = num % size; + if (j === dim) { + index += currentDim; + } + resultIndex += index * resultMultiplier; + resultMultiplier *= resultDims[j]; + num = Math.floor(num / size); + } + // Accumulate the value at the current index + result[resultIndex] = tensor.data[i]; + } + + currentDim += tensor.dims[dim]; + } + } + return new Tensor(resultType, result, resultDims); +} + +/** + * Stack an array of tensors along a specified dimension. + * @param {Tensor[]} tensors The array of tensors to stack. + * @param {number} dim The dimension to stack along. + * @returns {Tensor} The stacked tensor. + */ +function stack(tensors, dim = 0) { + // TODO do validation of shapes + // NOTE: stack expects each tensor to be equal size + return cat(tensors.map(t => t.unsqueeze(dim)), dim); +} + + +/** + * Calculates the standard deviation and mean over the dimensions specified by dim. dim can be a single dimension or `null` to reduce over all dimensions. + * @param {Tensor} input the input tenso + * @param {number|null} dim the dimension to reduce. If None, all dimensions are reduced. + * @param {number} correction difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1. + * @param {boolean} keepdim whether the output tensor has dim retained or not. + * @returns {Tensor[]} A tuple of (std, mean) tensors. + */ +function std_mean(input, dim = null, correction = 1, keepdim = false) { + + if (dim === null) { + // None to reduce over all dimensions. + // @ts-ignore + const sum = input.data.reduce((a, b) => a + b, 0); + const mean = sum / input.data.length; + // @ts-ignore + const std = Math.sqrt(input.data.reduce((a, b) => a + (b - mean) ** 2, 0) / (input.data.length - correction)); + + const meanTensor = new Tensor(input.type, [mean], [/* scalar */]); + const stdTensor = new Tensor(input.type, [std], [/* scalar */]); + + return [stdTensor, meanTensor]; + } + + // Negative indexing + dim = safeIndex(dim, input.dims.length); + + const meanTensor = mean(input, dim, keepdim); + + // Calculate the shape of the resulting array after summation + const resultDims = input.dims.slice(); // Copy the original dimensions + resultDims[dim] = 1; // Remove the specified axis + + // Create a new array to store the accumulated values + // @ts-ignore + const result = new input.data.constructor(input.data.length / input.dims[dim]); + + // Iterate over the data array + for (let i = 0; i < input.data.length; ++i) { + + // Calculate the index in the resulting array + let resultIndex = 0; + + for (let j = input.dims.length - 1, num = i, resultMultiplier = 1; j >= 0; --j) { + const size = input.dims[j]; + if (j !== dim) { + const index = num % size; + resultIndex += index * resultMultiplier; + resultMultiplier *= resultDims[j]; + } + num = Math.floor(num / size); + } + + // Accumulate the value at the current index + result[resultIndex] += (input.data[i] - meanTensor.data[resultIndex]) ** 2; + } + + for (let i = 0; i < result.length; ++i) { + result[i] = Math.sqrt(result[i] / (input.dims[dim] - correction)); + } + + if (!keepdim) { + resultDims.splice(dim, 1); + } + + const stdTensor = new Tensor(input.type, result, resultDims); + + return [stdTensor, meanTensor]; +} + + +/** + * Returns the mean value of each row of the input tensor in the given dimension dim. + * @param {Tensor} input the input tensor. + * @param {number|null} dim the dimension to reduce. + * @param {boolean} keepdim whether the output tensor has dim retained or not. + * @returns A new tensor with means taken along the specified dimension. + */ +function mean(input, dim = null, keepdim = false) { + + if (dim === null) { + // None to reduce over all dimensions. + // @ts-ignore + let val = input.data.reduce((a, b) => a + b, 0); + return new Tensor(input.type, [val / input.data.length], [/* scalar */]); + } + + // Negative indexing + dim = safeIndex(dim, input.dims.length); + + // Calculate the shape of the resulting array after summation + const resultDims = input.dims.slice(); // Copy the original dimensions + resultDims[dim] = 1; // Remove the specified axis + + // Create a new array to store the accumulated values + // @ts-ignore + const result = new input.data.constructor(input.data.length / input.dims[dim]); + + // Iterate over the data array + for (let i = 0; i < input.data.length; ++i) { + + // Calculate the index in the resulting array + let resultIndex = 0; + + for (let j = input.dims.length - 1, num = i, resultMultiplier = 1; j >= 0; --j) { + const size = input.dims[j]; + if (j !== dim) { + const index = num % size; + resultIndex += index * resultMultiplier; + resultMultiplier *= resultDims[j]; + } + num = Math.floor(num / size); + } + + // Accumulate the value at the current index + result[resultIndex] += input.data[i]; + } + + if (input.dims[dim] !== 1) { + for (let i = 0; i < result.length; ++i) { + result[i] = result[i] / input.dims[dim]; + } + } + + if (!keepdim) { + resultDims.splice(dim, 1); + } + + return new Tensor(input.type, result, resultDims); +} + + +/** + * + * Measures similarity between two temporal sequences (e.g., input audio and output tokens + * to generate token-level timestamps). + * @param {Tensor} matrix + * @returns {number[][]} + */ +function dynamicTimeWarping(matrix) { + const [output_length, input_length] = matrix.dims; + + const outputShape = [output_length + 1, input_length + 1]; + + const cost = new Tensor( + 'float32', + new Float32Array(outputShape[0] * outputShape[1]).fill(Infinity), + outputShape + ); + + const trace = new Tensor( + 'float32', + new Float32Array(outputShape[0] * outputShape[1]).fill(-1), + outputShape + ) + + // same as `cost[0][0] = 0`; + cost[0].data[0] = 0; + + for (let j = 1; j < input_length + 1; ++j) { + for (let i = 1; i < output_length + 1; ++i) { + + const c0 = cost[i - 1][j - 1].item(); + const c1 = cost[i - 1][j].item(); + const c2 = cost[i][j - 1].item(); + + let c, t; + if (c0 < c1 && c0 < c2) { + c = c0; + t = 0; + } else if (c1 < c0 && c1 < c2) { + c = c1; + t = 1; + } else { + c = c2; + t = 2; + } + + cost[i].data[j] = matrix[i - 1][j - 1].item() + c; + trace[i].data[j] = t; + } + } + + // backtrace + let i = output_length; + let j = input_length; + + // @ts-ignore + trace.data.fill(2, 0, outputShape[1]) // trace[0, :] = 2 + for (let i = 0; i < outputShape[0]; ++i) { // trace[:, 0] = 1 + trace[i].data[0] = 1; + } + + let text_indices = []; + let time_indices = []; + + while (i > 0 || j > 0) { + text_indices.push(i - 1); + time_indices.push(j - 1); + + const t = trace[i][j].item(); + switch (t) { + case 0: + --i; --j; + break; + case 1: + --i; + break; + case 2: + --j; + break; + default: + throw new Error( + `Internal error in dynamic time warping. Unexpected trace[${i}, ${j}]. Please file a bug report.` + ) + } + } + + text_indices.reverse(); + time_indices.reverse(); + + return [text_indices, time_indices]; + +} + +function dimsToStride(dims) { + const stride = new Array(dims.length); + for (let i = dims.length - 1, s2 = 1; i >= 0; --i) { + stride[i] = s2; + s2 *= dims[i]; + } + return stride; +} + +/** + * Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size. + * @param {number[]} size A sequence of integers defining the shape of the output tensor. + */ +function ones(size) { + const numElements = size.reduce((a, b) => a * b, 1); + return new Tensor( + 'int64', + new BigInt64Array(numElements).fill(1n), + size + ) +} + +/** + * Returns a tensor filled with the scalar value 1, with the same size as input. + * @param {Tensor} tensor The size of input will determine size of the output tensor. + * @returns The ones tensor. + */ +function ones_like(tensor) { + return ones(tensor.dims); +} + + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __webpack_require__("./src/transformers.js"); +/******/ var __webpack_exports__ASTFeatureExtractor = __webpack_exports__.ASTFeatureExtractor; +/******/ var __webpack_exports__ASTForAudioClassification = __webpack_exports__.ASTForAudioClassification; +/******/ var __webpack_exports__ASTModel = __webpack_exports__.ASTModel; +/******/ var __webpack_exports__ASTPreTrainedModel = __webpack_exports__.ASTPreTrainedModel; +/******/ var __webpack_exports__AlbertForMaskedLM = __webpack_exports__.AlbertForMaskedLM; +/******/ var __webpack_exports__AlbertForQuestionAnswering = __webpack_exports__.AlbertForQuestionAnswering; +/******/ var __webpack_exports__AlbertForSequenceClassification = __webpack_exports__.AlbertForSequenceClassification; +/******/ var __webpack_exports__AlbertModel = __webpack_exports__.AlbertModel; +/******/ var __webpack_exports__AlbertPreTrainedModel = __webpack_exports__.AlbertPreTrainedModel; +/******/ var __webpack_exports__AlbertTokenizer = __webpack_exports__.AlbertTokenizer; +/******/ var __webpack_exports__AudioClassificationPipeline = __webpack_exports__.AudioClassificationPipeline; +/******/ var __webpack_exports__AutoConfig = __webpack_exports__.AutoConfig; +/******/ var __webpack_exports__AutoModel = __webpack_exports__.AutoModel; +/******/ var __webpack_exports__AutoModelForAudioClassification = __webpack_exports__.AutoModelForAudioClassification; +/******/ var __webpack_exports__AutoModelForAudioFrameClassification = __webpack_exports__.AutoModelForAudioFrameClassification; +/******/ var __webpack_exports__AutoModelForCTC = __webpack_exports__.AutoModelForCTC; +/******/ var __webpack_exports__AutoModelForCausalLM = __webpack_exports__.AutoModelForCausalLM; +/******/ var __webpack_exports__AutoModelForDepthEstimation = __webpack_exports__.AutoModelForDepthEstimation; +/******/ var __webpack_exports__AutoModelForDocumentQuestionAnswering = __webpack_exports__.AutoModelForDocumentQuestionAnswering; +/******/ var __webpack_exports__AutoModelForImageClassification = __webpack_exports__.AutoModelForImageClassification; +/******/ var __webpack_exports__AutoModelForImageFeatureExtraction = __webpack_exports__.AutoModelForImageFeatureExtraction; +/******/ var __webpack_exports__AutoModelForImageMatting = __webpack_exports__.AutoModelForImageMatting; +/******/ var __webpack_exports__AutoModelForImageSegmentation = __webpack_exports__.AutoModelForImageSegmentation; +/******/ var __webpack_exports__AutoModelForImageToImage = __webpack_exports__.AutoModelForImageToImage; +/******/ var __webpack_exports__AutoModelForMaskGeneration = __webpack_exports__.AutoModelForMaskGeneration; +/******/ var __webpack_exports__AutoModelForMaskedLM = __webpack_exports__.AutoModelForMaskedLM; +/******/ var __webpack_exports__AutoModelForObjectDetection = __webpack_exports__.AutoModelForObjectDetection; +/******/ var __webpack_exports__AutoModelForQuestionAnswering = __webpack_exports__.AutoModelForQuestionAnswering; +/******/ var __webpack_exports__AutoModelForSemanticSegmentation = __webpack_exports__.AutoModelForSemanticSegmentation; +/******/ var __webpack_exports__AutoModelForSeq2SeqLM = __webpack_exports__.AutoModelForSeq2SeqLM; +/******/ var __webpack_exports__AutoModelForSequenceClassification = __webpack_exports__.AutoModelForSequenceClassification; +/******/ var __webpack_exports__AutoModelForSpeechSeq2Seq = __webpack_exports__.AutoModelForSpeechSeq2Seq; +/******/ var __webpack_exports__AutoModelForTextToSpectrogram = __webpack_exports__.AutoModelForTextToSpectrogram; +/******/ var __webpack_exports__AutoModelForTextToWaveform = __webpack_exports__.AutoModelForTextToWaveform; +/******/ var __webpack_exports__AutoModelForTokenClassification = __webpack_exports__.AutoModelForTokenClassification; +/******/ var __webpack_exports__AutoModelForVision2Seq = __webpack_exports__.AutoModelForVision2Seq; +/******/ var __webpack_exports__AutoModelForXVector = __webpack_exports__.AutoModelForXVector; +/******/ var __webpack_exports__AutoModelForZeroShotObjectDetection = __webpack_exports__.AutoModelForZeroShotObjectDetection; +/******/ var __webpack_exports__AutoProcessor = __webpack_exports__.AutoProcessor; +/******/ var __webpack_exports__AutoTokenizer = __webpack_exports__.AutoTokenizer; +/******/ var __webpack_exports__AutomaticSpeechRecognitionPipeline = __webpack_exports__.AutomaticSpeechRecognitionPipeline; +/******/ var __webpack_exports__BartForConditionalGeneration = __webpack_exports__.BartForConditionalGeneration; +/******/ var __webpack_exports__BartForSequenceClassification = __webpack_exports__.BartForSequenceClassification; +/******/ var __webpack_exports__BartModel = __webpack_exports__.BartModel; +/******/ var __webpack_exports__BartPretrainedModel = __webpack_exports__.BartPretrainedModel; +/******/ var __webpack_exports__BartTokenizer = __webpack_exports__.BartTokenizer; +/******/ var __webpack_exports__BaseModelOutput = __webpack_exports__.BaseModelOutput; +/******/ var __webpack_exports__BeitFeatureExtractor = __webpack_exports__.BeitFeatureExtractor; +/******/ var __webpack_exports__BeitForImageClassification = __webpack_exports__.BeitForImageClassification; +/******/ var __webpack_exports__BeitModel = __webpack_exports__.BeitModel; +/******/ var __webpack_exports__BeitPreTrainedModel = __webpack_exports__.BeitPreTrainedModel; +/******/ var __webpack_exports__BertForMaskedLM = __webpack_exports__.BertForMaskedLM; +/******/ var __webpack_exports__BertForQuestionAnswering = __webpack_exports__.BertForQuestionAnswering; +/******/ var __webpack_exports__BertForSequenceClassification = __webpack_exports__.BertForSequenceClassification; +/******/ var __webpack_exports__BertForTokenClassification = __webpack_exports__.BertForTokenClassification; +/******/ var __webpack_exports__BertModel = __webpack_exports__.BertModel; +/******/ var __webpack_exports__BertPreTrainedModel = __webpack_exports__.BertPreTrainedModel; +/******/ var __webpack_exports__BertTokenizer = __webpack_exports__.BertTokenizer; +/******/ var __webpack_exports__BitImageProcessor = __webpack_exports__.BitImageProcessor; +/******/ var __webpack_exports__BlenderbotForConditionalGeneration = __webpack_exports__.BlenderbotForConditionalGeneration; +/******/ var __webpack_exports__BlenderbotModel = __webpack_exports__.BlenderbotModel; +/******/ var __webpack_exports__BlenderbotPreTrainedModel = __webpack_exports__.BlenderbotPreTrainedModel; +/******/ var __webpack_exports__BlenderbotSmallForConditionalGeneration = __webpack_exports__.BlenderbotSmallForConditionalGeneration; +/******/ var __webpack_exports__BlenderbotSmallModel = __webpack_exports__.BlenderbotSmallModel; +/******/ var __webpack_exports__BlenderbotSmallPreTrainedModel = __webpack_exports__.BlenderbotSmallPreTrainedModel; +/******/ var __webpack_exports__BlenderbotSmallTokenizer = __webpack_exports__.BlenderbotSmallTokenizer; +/******/ var __webpack_exports__BlenderbotTokenizer = __webpack_exports__.BlenderbotTokenizer; +/******/ var __webpack_exports__BloomForCausalLM = __webpack_exports__.BloomForCausalLM; +/******/ var __webpack_exports__BloomModel = __webpack_exports__.BloomModel; +/******/ var __webpack_exports__BloomPreTrainedModel = __webpack_exports__.BloomPreTrainedModel; +/******/ var __webpack_exports__BloomTokenizer = __webpack_exports__.BloomTokenizer; +/******/ var __webpack_exports__CLIPFeatureExtractor = __webpack_exports__.CLIPFeatureExtractor; +/******/ var __webpack_exports__CLIPModel = __webpack_exports__.CLIPModel; +/******/ var __webpack_exports__CLIPPreTrainedModel = __webpack_exports__.CLIPPreTrainedModel; +/******/ var __webpack_exports__CLIPSegForImageSegmentation = __webpack_exports__.CLIPSegForImageSegmentation; +/******/ var __webpack_exports__CLIPSegModel = __webpack_exports__.CLIPSegModel; +/******/ var __webpack_exports__CLIPSegPreTrainedModel = __webpack_exports__.CLIPSegPreTrainedModel; +/******/ var __webpack_exports__CLIPTextModelWithProjection = __webpack_exports__.CLIPTextModelWithProjection; +/******/ var __webpack_exports__CLIPTokenizer = __webpack_exports__.CLIPTokenizer; +/******/ var __webpack_exports__CLIPVisionModelWithProjection = __webpack_exports__.CLIPVisionModelWithProjection; +/******/ var __webpack_exports__CamembertForMaskedLM = __webpack_exports__.CamembertForMaskedLM; +/******/ var __webpack_exports__CamembertForQuestionAnswering = __webpack_exports__.CamembertForQuestionAnswering; +/******/ var __webpack_exports__CamembertForSequenceClassification = __webpack_exports__.CamembertForSequenceClassification; +/******/ var __webpack_exports__CamembertForTokenClassification = __webpack_exports__.CamembertForTokenClassification; +/******/ var __webpack_exports__CamembertModel = __webpack_exports__.CamembertModel; +/******/ var __webpack_exports__CamembertPreTrainedModel = __webpack_exports__.CamembertPreTrainedModel; +/******/ var __webpack_exports__CamembertTokenizer = __webpack_exports__.CamembertTokenizer; +/******/ var __webpack_exports__CausalLMOutput = __webpack_exports__.CausalLMOutput; +/******/ var __webpack_exports__CausalLMOutputWithPast = __webpack_exports__.CausalLMOutputWithPast; +/******/ var __webpack_exports__ChineseCLIPFeatureExtractor = __webpack_exports__.ChineseCLIPFeatureExtractor; +/******/ var __webpack_exports__ChineseCLIPModel = __webpack_exports__.ChineseCLIPModel; +/******/ var __webpack_exports__ChineseCLIPPreTrainedModel = __webpack_exports__.ChineseCLIPPreTrainedModel; +/******/ var __webpack_exports__ClapAudioModelWithProjection = __webpack_exports__.ClapAudioModelWithProjection; +/******/ var __webpack_exports__ClapFeatureExtractor = __webpack_exports__.ClapFeatureExtractor; +/******/ var __webpack_exports__ClapModel = __webpack_exports__.ClapModel; +/******/ var __webpack_exports__ClapPreTrainedModel = __webpack_exports__.ClapPreTrainedModel; +/******/ var __webpack_exports__ClapTextModelWithProjection = __webpack_exports__.ClapTextModelWithProjection; +/******/ var __webpack_exports__CodeGenForCausalLM = __webpack_exports__.CodeGenForCausalLM; +/******/ var __webpack_exports__CodeGenModel = __webpack_exports__.CodeGenModel; +/******/ var __webpack_exports__CodeGenPreTrainedModel = __webpack_exports__.CodeGenPreTrainedModel; +/******/ var __webpack_exports__CodeGenTokenizer = __webpack_exports__.CodeGenTokenizer; +/******/ var __webpack_exports__CodeLlamaTokenizer = __webpack_exports__.CodeLlamaTokenizer; +/******/ var __webpack_exports__CohereTokenizer = __webpack_exports__.CohereTokenizer; +/******/ var __webpack_exports__ConvBertForMaskedLM = __webpack_exports__.ConvBertForMaskedLM; +/******/ var __webpack_exports__ConvBertForQuestionAnswering = __webpack_exports__.ConvBertForQuestionAnswering; +/******/ var __webpack_exports__ConvBertForSequenceClassification = __webpack_exports__.ConvBertForSequenceClassification; +/******/ var __webpack_exports__ConvBertForTokenClassification = __webpack_exports__.ConvBertForTokenClassification; +/******/ var __webpack_exports__ConvBertModel = __webpack_exports__.ConvBertModel; +/******/ var __webpack_exports__ConvBertPreTrainedModel = __webpack_exports__.ConvBertPreTrainedModel; +/******/ var __webpack_exports__ConvBertTokenizer = __webpack_exports__.ConvBertTokenizer; +/******/ var __webpack_exports__ConvNextFeatureExtractor = __webpack_exports__.ConvNextFeatureExtractor; +/******/ var __webpack_exports__ConvNextForImageClassification = __webpack_exports__.ConvNextForImageClassification; +/******/ var __webpack_exports__ConvNextImageProcessor = __webpack_exports__.ConvNextImageProcessor; +/******/ var __webpack_exports__ConvNextModel = __webpack_exports__.ConvNextModel; +/******/ var __webpack_exports__ConvNextPreTrainedModel = __webpack_exports__.ConvNextPreTrainedModel; +/******/ var __webpack_exports__ConvNextV2ForImageClassification = __webpack_exports__.ConvNextV2ForImageClassification; +/******/ var __webpack_exports__ConvNextV2Model = __webpack_exports__.ConvNextV2Model; +/******/ var __webpack_exports__ConvNextV2PreTrainedModel = __webpack_exports__.ConvNextV2PreTrainedModel; +/******/ var __webpack_exports__DPTFeatureExtractor = __webpack_exports__.DPTFeatureExtractor; +/******/ var __webpack_exports__DPTForDepthEstimation = __webpack_exports__.DPTForDepthEstimation; +/******/ var __webpack_exports__DPTImageProcessor = __webpack_exports__.DPTImageProcessor; +/******/ var __webpack_exports__DPTModel = __webpack_exports__.DPTModel; +/******/ var __webpack_exports__DPTPreTrainedModel = __webpack_exports__.DPTPreTrainedModel; +/******/ var __webpack_exports__DebertaForMaskedLM = __webpack_exports__.DebertaForMaskedLM; +/******/ var __webpack_exports__DebertaForQuestionAnswering = __webpack_exports__.DebertaForQuestionAnswering; +/******/ var __webpack_exports__DebertaForSequenceClassification = __webpack_exports__.DebertaForSequenceClassification; +/******/ var __webpack_exports__DebertaForTokenClassification = __webpack_exports__.DebertaForTokenClassification; +/******/ var __webpack_exports__DebertaModel = __webpack_exports__.DebertaModel; +/******/ var __webpack_exports__DebertaPreTrainedModel = __webpack_exports__.DebertaPreTrainedModel; +/******/ var __webpack_exports__DebertaTokenizer = __webpack_exports__.DebertaTokenizer; +/******/ var __webpack_exports__DebertaV2ForMaskedLM = __webpack_exports__.DebertaV2ForMaskedLM; +/******/ var __webpack_exports__DebertaV2ForQuestionAnswering = __webpack_exports__.DebertaV2ForQuestionAnswering; +/******/ var __webpack_exports__DebertaV2ForSequenceClassification = __webpack_exports__.DebertaV2ForSequenceClassification; +/******/ var __webpack_exports__DebertaV2ForTokenClassification = __webpack_exports__.DebertaV2ForTokenClassification; +/******/ var __webpack_exports__DebertaV2Model = __webpack_exports__.DebertaV2Model; +/******/ var __webpack_exports__DebertaV2PreTrainedModel = __webpack_exports__.DebertaV2PreTrainedModel; +/******/ var __webpack_exports__DebertaV2Tokenizer = __webpack_exports__.DebertaV2Tokenizer; +/******/ var __webpack_exports__DeiTFeatureExtractor = __webpack_exports__.DeiTFeatureExtractor; +/******/ var __webpack_exports__DeiTForImageClassification = __webpack_exports__.DeiTForImageClassification; +/******/ var __webpack_exports__DeiTModel = __webpack_exports__.DeiTModel; +/******/ var __webpack_exports__DeiTPreTrainedModel = __webpack_exports__.DeiTPreTrainedModel; +/******/ var __webpack_exports__DepthAnythingForDepthEstimation = __webpack_exports__.DepthAnythingForDepthEstimation; +/******/ var __webpack_exports__DepthAnythingPreTrainedModel = __webpack_exports__.DepthAnythingPreTrainedModel; +/******/ var __webpack_exports__DepthEstimationPipeline = __webpack_exports__.DepthEstimationPipeline; +/******/ var __webpack_exports__DetrFeatureExtractor = __webpack_exports__.DetrFeatureExtractor; +/******/ var __webpack_exports__DetrForObjectDetection = __webpack_exports__.DetrForObjectDetection; +/******/ var __webpack_exports__DetrForSegmentation = __webpack_exports__.DetrForSegmentation; +/******/ var __webpack_exports__DetrModel = __webpack_exports__.DetrModel; +/******/ var __webpack_exports__DetrObjectDetectionOutput = __webpack_exports__.DetrObjectDetectionOutput; +/******/ var __webpack_exports__DetrPreTrainedModel = __webpack_exports__.DetrPreTrainedModel; +/******/ var __webpack_exports__DetrSegmentationOutput = __webpack_exports__.DetrSegmentationOutput; +/******/ var __webpack_exports__Dinov2ForImageClassification = __webpack_exports__.Dinov2ForImageClassification; +/******/ var __webpack_exports__Dinov2Model = __webpack_exports__.Dinov2Model; +/******/ var __webpack_exports__Dinov2PreTrainedModel = __webpack_exports__.Dinov2PreTrainedModel; +/******/ var __webpack_exports__DistilBertForMaskedLM = __webpack_exports__.DistilBertForMaskedLM; +/******/ var __webpack_exports__DistilBertForQuestionAnswering = __webpack_exports__.DistilBertForQuestionAnswering; +/******/ var __webpack_exports__DistilBertForSequenceClassification = __webpack_exports__.DistilBertForSequenceClassification; +/******/ var __webpack_exports__DistilBertForTokenClassification = __webpack_exports__.DistilBertForTokenClassification; +/******/ var __webpack_exports__DistilBertModel = __webpack_exports__.DistilBertModel; +/******/ var __webpack_exports__DistilBertPreTrainedModel = __webpack_exports__.DistilBertPreTrainedModel; +/******/ var __webpack_exports__DistilBertTokenizer = __webpack_exports__.DistilBertTokenizer; +/******/ var __webpack_exports__DocumentQuestionAnsweringPipeline = __webpack_exports__.DocumentQuestionAnsweringPipeline; +/******/ var __webpack_exports__DonutFeatureExtractor = __webpack_exports__.DonutFeatureExtractor; +/******/ var __webpack_exports__DonutSwinModel = __webpack_exports__.DonutSwinModel; +/******/ var __webpack_exports__DonutSwinPreTrainedModel = __webpack_exports__.DonutSwinPreTrainedModel; +/******/ var __webpack_exports__EfficientNetForImageClassification = __webpack_exports__.EfficientNetForImageClassification; +/******/ var __webpack_exports__EfficientNetImageProcessor = __webpack_exports__.EfficientNetImageProcessor; +/******/ var __webpack_exports__EfficientNetModel = __webpack_exports__.EfficientNetModel; +/******/ var __webpack_exports__EfficientNetPreTrainedModel = __webpack_exports__.EfficientNetPreTrainedModel; +/******/ var __webpack_exports__ElectraForMaskedLM = __webpack_exports__.ElectraForMaskedLM; +/******/ var __webpack_exports__ElectraForQuestionAnswering = __webpack_exports__.ElectraForQuestionAnswering; +/******/ var __webpack_exports__ElectraForSequenceClassification = __webpack_exports__.ElectraForSequenceClassification; +/******/ var __webpack_exports__ElectraForTokenClassification = __webpack_exports__.ElectraForTokenClassification; +/******/ var __webpack_exports__ElectraModel = __webpack_exports__.ElectraModel; +/******/ var __webpack_exports__ElectraPreTrainedModel = __webpack_exports__.ElectraPreTrainedModel; +/******/ var __webpack_exports__ElectraTokenizer = __webpack_exports__.ElectraTokenizer; +/******/ var __webpack_exports__EsmForMaskedLM = __webpack_exports__.EsmForMaskedLM; +/******/ var __webpack_exports__EsmForSequenceClassification = __webpack_exports__.EsmForSequenceClassification; +/******/ var __webpack_exports__EsmForTokenClassification = __webpack_exports__.EsmForTokenClassification; +/******/ var __webpack_exports__EsmModel = __webpack_exports__.EsmModel; +/******/ var __webpack_exports__EsmPreTrainedModel = __webpack_exports__.EsmPreTrainedModel; +/******/ var __webpack_exports__EsmTokenizer = __webpack_exports__.EsmTokenizer; +/******/ var __webpack_exports__FFT = __webpack_exports__.FFT; +/******/ var __webpack_exports__FalconForCausalLM = __webpack_exports__.FalconForCausalLM; +/******/ var __webpack_exports__FalconModel = __webpack_exports__.FalconModel; +/******/ var __webpack_exports__FalconPreTrainedModel = __webpack_exports__.FalconPreTrainedModel; +/******/ var __webpack_exports__FalconTokenizer = __webpack_exports__.FalconTokenizer; +/******/ var __webpack_exports__FeatureExtractionPipeline = __webpack_exports__.FeatureExtractionPipeline; +/******/ var __webpack_exports__FeatureExtractor = __webpack_exports__.FeatureExtractor; +/******/ var __webpack_exports__FillMaskPipeline = __webpack_exports__.FillMaskPipeline; +/******/ var __webpack_exports__GLPNFeatureExtractor = __webpack_exports__.GLPNFeatureExtractor; +/******/ var __webpack_exports__GLPNForDepthEstimation = __webpack_exports__.GLPNForDepthEstimation; +/******/ var __webpack_exports__GLPNModel = __webpack_exports__.GLPNModel; +/******/ var __webpack_exports__GLPNPreTrainedModel = __webpack_exports__.GLPNPreTrainedModel; +/******/ var __webpack_exports__GPT2LMHeadModel = __webpack_exports__.GPT2LMHeadModel; +/******/ var __webpack_exports__GPT2Model = __webpack_exports__.GPT2Model; +/******/ var __webpack_exports__GPT2PreTrainedModel = __webpack_exports__.GPT2PreTrainedModel; +/******/ var __webpack_exports__GPT2Tokenizer = __webpack_exports__.GPT2Tokenizer; +/******/ var __webpack_exports__GPTBigCodeForCausalLM = __webpack_exports__.GPTBigCodeForCausalLM; +/******/ var __webpack_exports__GPTBigCodeModel = __webpack_exports__.GPTBigCodeModel; +/******/ var __webpack_exports__GPTBigCodePreTrainedModel = __webpack_exports__.GPTBigCodePreTrainedModel; +/******/ var __webpack_exports__GPTJForCausalLM = __webpack_exports__.GPTJForCausalLM; +/******/ var __webpack_exports__GPTJModel = __webpack_exports__.GPTJModel; +/******/ var __webpack_exports__GPTJPreTrainedModel = __webpack_exports__.GPTJPreTrainedModel; +/******/ var __webpack_exports__GPTNeoForCausalLM = __webpack_exports__.GPTNeoForCausalLM; +/******/ var __webpack_exports__GPTNeoModel = __webpack_exports__.GPTNeoModel; +/******/ var __webpack_exports__GPTNeoPreTrainedModel = __webpack_exports__.GPTNeoPreTrainedModel; +/******/ var __webpack_exports__GPTNeoXForCausalLM = __webpack_exports__.GPTNeoXForCausalLM; +/******/ var __webpack_exports__GPTNeoXModel = __webpack_exports__.GPTNeoXModel; +/******/ var __webpack_exports__GPTNeoXPreTrainedModel = __webpack_exports__.GPTNeoXPreTrainedModel; +/******/ var __webpack_exports__GPTNeoXTokenizer = __webpack_exports__.GPTNeoXTokenizer; +/******/ var __webpack_exports__GemmaTokenizer = __webpack_exports__.GemmaTokenizer; +/******/ var __webpack_exports__Grok1Tokenizer = __webpack_exports__.Grok1Tokenizer; +/******/ var __webpack_exports__HerbertTokenizer = __webpack_exports__.HerbertTokenizer; +/******/ var __webpack_exports__HubertForCTC = __webpack_exports__.HubertForCTC; +/******/ var __webpack_exports__HubertForSequenceClassification = __webpack_exports__.HubertForSequenceClassification; +/******/ var __webpack_exports__HubertModel = __webpack_exports__.HubertModel; +/******/ var __webpack_exports__HubertPreTrainedModel = __webpack_exports__.HubertPreTrainedModel; +/******/ var __webpack_exports__ImageClassificationPipeline = __webpack_exports__.ImageClassificationPipeline; +/******/ var __webpack_exports__ImageFeatureExtractionPipeline = __webpack_exports__.ImageFeatureExtractionPipeline; +/******/ var __webpack_exports__ImageFeatureExtractor = __webpack_exports__.ImageFeatureExtractor; +/******/ var __webpack_exports__ImageMattingOutput = __webpack_exports__.ImageMattingOutput; +/******/ var __webpack_exports__ImageSegmentationPipeline = __webpack_exports__.ImageSegmentationPipeline; +/******/ var __webpack_exports__ImageToImagePipeline = __webpack_exports__.ImageToImagePipeline; +/******/ var __webpack_exports__ImageToTextPipeline = __webpack_exports__.ImageToTextPipeline; +/******/ var __webpack_exports__LlamaForCausalLM = __webpack_exports__.LlamaForCausalLM; +/******/ var __webpack_exports__LlamaModel = __webpack_exports__.LlamaModel; +/******/ var __webpack_exports__LlamaPreTrainedModel = __webpack_exports__.LlamaPreTrainedModel; +/******/ var __webpack_exports__LlamaTokenizer = __webpack_exports__.LlamaTokenizer; +/******/ var __webpack_exports__LongT5ForConditionalGeneration = __webpack_exports__.LongT5ForConditionalGeneration; +/******/ var __webpack_exports__LongT5Model = __webpack_exports__.LongT5Model; +/******/ var __webpack_exports__LongT5PreTrainedModel = __webpack_exports__.LongT5PreTrainedModel; +/******/ var __webpack_exports__M2M100ForConditionalGeneration = __webpack_exports__.M2M100ForConditionalGeneration; +/******/ var __webpack_exports__M2M100Model = __webpack_exports__.M2M100Model; +/******/ var __webpack_exports__M2M100PreTrainedModel = __webpack_exports__.M2M100PreTrainedModel; +/******/ var __webpack_exports__M2M100Tokenizer = __webpack_exports__.M2M100Tokenizer; +/******/ var __webpack_exports__MBart50Tokenizer = __webpack_exports__.MBart50Tokenizer; +/******/ var __webpack_exports__MBartForCausalLM = __webpack_exports__.MBartForCausalLM; +/******/ var __webpack_exports__MBartForConditionalGeneration = __webpack_exports__.MBartForConditionalGeneration; +/******/ var __webpack_exports__MBartForSequenceClassification = __webpack_exports__.MBartForSequenceClassification; +/******/ var __webpack_exports__MBartModel = __webpack_exports__.MBartModel; +/******/ var __webpack_exports__MBartPreTrainedModel = __webpack_exports__.MBartPreTrainedModel; +/******/ var __webpack_exports__MBartTokenizer = __webpack_exports__.MBartTokenizer; +/******/ var __webpack_exports__MPNetForMaskedLM = __webpack_exports__.MPNetForMaskedLM; +/******/ var __webpack_exports__MPNetForQuestionAnswering = __webpack_exports__.MPNetForQuestionAnswering; +/******/ var __webpack_exports__MPNetForSequenceClassification = __webpack_exports__.MPNetForSequenceClassification; +/******/ var __webpack_exports__MPNetForTokenClassification = __webpack_exports__.MPNetForTokenClassification; +/******/ var __webpack_exports__MPNetModel = __webpack_exports__.MPNetModel; +/******/ var __webpack_exports__MPNetPreTrainedModel = __webpack_exports__.MPNetPreTrainedModel; +/******/ var __webpack_exports__MPNetTokenizer = __webpack_exports__.MPNetTokenizer; +/******/ var __webpack_exports__MT5ForConditionalGeneration = __webpack_exports__.MT5ForConditionalGeneration; +/******/ var __webpack_exports__MT5Model = __webpack_exports__.MT5Model; +/******/ var __webpack_exports__MT5PreTrainedModel = __webpack_exports__.MT5PreTrainedModel; +/******/ var __webpack_exports__MarianMTModel = __webpack_exports__.MarianMTModel; +/******/ var __webpack_exports__MarianModel = __webpack_exports__.MarianModel; +/******/ var __webpack_exports__MarianPreTrainedModel = __webpack_exports__.MarianPreTrainedModel; +/******/ var __webpack_exports__MarianTokenizer = __webpack_exports__.MarianTokenizer; +/******/ var __webpack_exports__MaskedLMOutput = __webpack_exports__.MaskedLMOutput; +/******/ var __webpack_exports__MistralForCausalLM = __webpack_exports__.MistralForCausalLM; +/******/ var __webpack_exports__MistralModel = __webpack_exports__.MistralModel; +/******/ var __webpack_exports__MistralPreTrainedModel = __webpack_exports__.MistralPreTrainedModel; +/******/ var __webpack_exports__MobileBertForMaskedLM = __webpack_exports__.MobileBertForMaskedLM; +/******/ var __webpack_exports__MobileBertForQuestionAnswering = __webpack_exports__.MobileBertForQuestionAnswering; +/******/ var __webpack_exports__MobileBertForSequenceClassification = __webpack_exports__.MobileBertForSequenceClassification; +/******/ var __webpack_exports__MobileBertModel = __webpack_exports__.MobileBertModel; +/******/ var __webpack_exports__MobileBertPreTrainedModel = __webpack_exports__.MobileBertPreTrainedModel; +/******/ var __webpack_exports__MobileBertTokenizer = __webpack_exports__.MobileBertTokenizer; +/******/ var __webpack_exports__MobileViTFeatureExtractor = __webpack_exports__.MobileViTFeatureExtractor; +/******/ var __webpack_exports__MobileViTForImageClassification = __webpack_exports__.MobileViTForImageClassification; +/******/ var __webpack_exports__MobileViTModel = __webpack_exports__.MobileViTModel; +/******/ var __webpack_exports__MobileViTPreTrainedModel = __webpack_exports__.MobileViTPreTrainedModel; +/******/ var __webpack_exports__ModelOutput = __webpack_exports__.ModelOutput; +/******/ var __webpack_exports__MptForCausalLM = __webpack_exports__.MptForCausalLM; +/******/ var __webpack_exports__MptModel = __webpack_exports__.MptModel; +/******/ var __webpack_exports__MptPreTrainedModel = __webpack_exports__.MptPreTrainedModel; +/******/ var __webpack_exports__NllbTokenizer = __webpack_exports__.NllbTokenizer; +/******/ var __webpack_exports__NomicBertModel = __webpack_exports__.NomicBertModel; +/******/ var __webpack_exports__NomicBertPreTrainedModel = __webpack_exports__.NomicBertPreTrainedModel; +/******/ var __webpack_exports__NougatImageProcessor = __webpack_exports__.NougatImageProcessor; +/******/ var __webpack_exports__NougatTokenizer = __webpack_exports__.NougatTokenizer; +/******/ var __webpack_exports__OPTForCausalLM = __webpack_exports__.OPTForCausalLM; +/******/ var __webpack_exports__OPTModel = __webpack_exports__.OPTModel; +/******/ var __webpack_exports__OPTPreTrainedModel = __webpack_exports__.OPTPreTrainedModel; +/******/ var __webpack_exports__ObjectDetectionPipeline = __webpack_exports__.ObjectDetectionPipeline; +/******/ var __webpack_exports__OwlViTFeatureExtractor = __webpack_exports__.OwlViTFeatureExtractor; +/******/ var __webpack_exports__OwlViTForObjectDetection = __webpack_exports__.OwlViTForObjectDetection; +/******/ var __webpack_exports__OwlViTModel = __webpack_exports__.OwlViTModel; +/******/ var __webpack_exports__OwlViTPreTrainedModel = __webpack_exports__.OwlViTPreTrainedModel; +/******/ var __webpack_exports__OwlViTProcessor = __webpack_exports__.OwlViTProcessor; +/******/ var __webpack_exports__Owlv2ForObjectDetection = __webpack_exports__.Owlv2ForObjectDetection; +/******/ var __webpack_exports__Owlv2ImageProcessor = __webpack_exports__.Owlv2ImageProcessor; +/******/ var __webpack_exports__Owlv2Model = __webpack_exports__.Owlv2Model; +/******/ var __webpack_exports__Owlv2PreTrainedModel = __webpack_exports__.Owlv2PreTrainedModel; +/******/ var __webpack_exports__PhiForCausalLM = __webpack_exports__.PhiForCausalLM; +/******/ var __webpack_exports__PhiModel = __webpack_exports__.PhiModel; +/******/ var __webpack_exports__PhiPreTrainedModel = __webpack_exports__.PhiPreTrainedModel; +/******/ var __webpack_exports__Pipeline = __webpack_exports__.Pipeline; +/******/ var __webpack_exports__PreTrainedModel = __webpack_exports__.PreTrainedModel; +/******/ var __webpack_exports__PreTrainedTokenizer = __webpack_exports__.PreTrainedTokenizer; +/******/ var __webpack_exports__PretrainedConfig = __webpack_exports__.PretrainedConfig; +/******/ var __webpack_exports__PretrainedMixin = __webpack_exports__.PretrainedMixin; +/******/ var __webpack_exports__Processor = __webpack_exports__.Processor; +/******/ var __webpack_exports__QuestionAnsweringModelOutput = __webpack_exports__.QuestionAnsweringModelOutput; +/******/ var __webpack_exports__QuestionAnsweringPipeline = __webpack_exports__.QuestionAnsweringPipeline; +/******/ var __webpack_exports__Qwen2ForCausalLM = __webpack_exports__.Qwen2ForCausalLM; +/******/ var __webpack_exports__Qwen2Model = __webpack_exports__.Qwen2Model; +/******/ var __webpack_exports__Qwen2PreTrainedModel = __webpack_exports__.Qwen2PreTrainedModel; +/******/ var __webpack_exports__Qwen2Tokenizer = __webpack_exports__.Qwen2Tokenizer; +/******/ var __webpack_exports__RawImage = __webpack_exports__.RawImage; +/******/ var __webpack_exports__ResNetForImageClassification = __webpack_exports__.ResNetForImageClassification; +/******/ var __webpack_exports__ResNetModel = __webpack_exports__.ResNetModel; +/******/ var __webpack_exports__ResNetPreTrainedModel = __webpack_exports__.ResNetPreTrainedModel; +/******/ var __webpack_exports__RoFormerForMaskedLM = __webpack_exports__.RoFormerForMaskedLM; +/******/ var __webpack_exports__RoFormerForQuestionAnswering = __webpack_exports__.RoFormerForQuestionAnswering; +/******/ var __webpack_exports__RoFormerForSequenceClassification = __webpack_exports__.RoFormerForSequenceClassification; +/******/ var __webpack_exports__RoFormerForTokenClassification = __webpack_exports__.RoFormerForTokenClassification; +/******/ var __webpack_exports__RoFormerModel = __webpack_exports__.RoFormerModel; +/******/ var __webpack_exports__RoFormerPreTrainedModel = __webpack_exports__.RoFormerPreTrainedModel; +/******/ var __webpack_exports__RoFormerTokenizer = __webpack_exports__.RoFormerTokenizer; +/******/ var __webpack_exports__RobertaForMaskedLM = __webpack_exports__.RobertaForMaskedLM; +/******/ var __webpack_exports__RobertaForQuestionAnswering = __webpack_exports__.RobertaForQuestionAnswering; +/******/ var __webpack_exports__RobertaForSequenceClassification = __webpack_exports__.RobertaForSequenceClassification; +/******/ var __webpack_exports__RobertaForTokenClassification = __webpack_exports__.RobertaForTokenClassification; +/******/ var __webpack_exports__RobertaModel = __webpack_exports__.RobertaModel; +/******/ var __webpack_exports__RobertaPreTrainedModel = __webpack_exports__.RobertaPreTrainedModel; +/******/ var __webpack_exports__RobertaTokenizer = __webpack_exports__.RobertaTokenizer; +/******/ var __webpack_exports__SamImageProcessor = __webpack_exports__.SamImageProcessor; +/******/ var __webpack_exports__SamImageSegmentationOutput = __webpack_exports__.SamImageSegmentationOutput; +/******/ var __webpack_exports__SamModel = __webpack_exports__.SamModel; +/******/ var __webpack_exports__SamPreTrainedModel = __webpack_exports__.SamPreTrainedModel; +/******/ var __webpack_exports__SamProcessor = __webpack_exports__.SamProcessor; +/******/ var __webpack_exports__SeamlessM4TFeatureExtractor = __webpack_exports__.SeamlessM4TFeatureExtractor; +/******/ var __webpack_exports__SegformerFeatureExtractor = __webpack_exports__.SegformerFeatureExtractor; +/******/ var __webpack_exports__SegformerForImageClassification = __webpack_exports__.SegformerForImageClassification; +/******/ var __webpack_exports__SegformerForSemanticSegmentation = __webpack_exports__.SegformerForSemanticSegmentation; +/******/ var __webpack_exports__SegformerModel = __webpack_exports__.SegformerModel; +/******/ var __webpack_exports__SegformerPreTrainedModel = __webpack_exports__.SegformerPreTrainedModel; +/******/ var __webpack_exports__Seq2SeqLMOutput = __webpack_exports__.Seq2SeqLMOutput; +/******/ var __webpack_exports__SequenceClassifierOutput = __webpack_exports__.SequenceClassifierOutput; +/******/ var __webpack_exports__SiglipImageProcessor = __webpack_exports__.SiglipImageProcessor; +/******/ var __webpack_exports__SiglipModel = __webpack_exports__.SiglipModel; +/******/ var __webpack_exports__SiglipPreTrainedModel = __webpack_exports__.SiglipPreTrainedModel; +/******/ var __webpack_exports__SiglipTextModel = __webpack_exports__.SiglipTextModel; +/******/ var __webpack_exports__SiglipTokenizer = __webpack_exports__.SiglipTokenizer; +/******/ var __webpack_exports__SiglipVisionModel = __webpack_exports__.SiglipVisionModel; +/******/ var __webpack_exports__SpeechT5FeatureExtractor = __webpack_exports__.SpeechT5FeatureExtractor; +/******/ var __webpack_exports__SpeechT5ForSpeechToText = __webpack_exports__.SpeechT5ForSpeechToText; +/******/ var __webpack_exports__SpeechT5ForTextToSpeech = __webpack_exports__.SpeechT5ForTextToSpeech; +/******/ var __webpack_exports__SpeechT5HifiGan = __webpack_exports__.SpeechT5HifiGan; +/******/ var __webpack_exports__SpeechT5Model = __webpack_exports__.SpeechT5Model; +/******/ var __webpack_exports__SpeechT5PreTrainedModel = __webpack_exports__.SpeechT5PreTrainedModel; +/******/ var __webpack_exports__SpeechT5Processor = __webpack_exports__.SpeechT5Processor; +/******/ var __webpack_exports__SpeechT5Tokenizer = __webpack_exports__.SpeechT5Tokenizer; +/******/ var __webpack_exports__SqueezeBertForMaskedLM = __webpack_exports__.SqueezeBertForMaskedLM; +/******/ var __webpack_exports__SqueezeBertForQuestionAnswering = __webpack_exports__.SqueezeBertForQuestionAnswering; +/******/ var __webpack_exports__SqueezeBertForSequenceClassification = __webpack_exports__.SqueezeBertForSequenceClassification; +/******/ var __webpack_exports__SqueezeBertModel = __webpack_exports__.SqueezeBertModel; +/******/ var __webpack_exports__SqueezeBertPreTrainedModel = __webpack_exports__.SqueezeBertPreTrainedModel; +/******/ var __webpack_exports__SqueezeBertTokenizer = __webpack_exports__.SqueezeBertTokenizer; +/******/ var __webpack_exports__StableLmForCausalLM = __webpack_exports__.StableLmForCausalLM; +/******/ var __webpack_exports__StableLmModel = __webpack_exports__.StableLmModel; +/******/ var __webpack_exports__StableLmPreTrainedModel = __webpack_exports__.StableLmPreTrainedModel; +/******/ var __webpack_exports__Starcoder2ForCausalLM = __webpack_exports__.Starcoder2ForCausalLM; +/******/ var __webpack_exports__Starcoder2Model = __webpack_exports__.Starcoder2Model; +/******/ var __webpack_exports__Starcoder2PreTrainedModel = __webpack_exports__.Starcoder2PreTrainedModel; +/******/ var __webpack_exports__SummarizationPipeline = __webpack_exports__.SummarizationPipeline; +/******/ var __webpack_exports__Swin2SRForImageSuperResolution = __webpack_exports__.Swin2SRForImageSuperResolution; +/******/ var __webpack_exports__Swin2SRImageProcessor = __webpack_exports__.Swin2SRImageProcessor; +/******/ var __webpack_exports__Swin2SRModel = __webpack_exports__.Swin2SRModel; +/******/ var __webpack_exports__Swin2SRPreTrainedModel = __webpack_exports__.Swin2SRPreTrainedModel; +/******/ var __webpack_exports__SwinForImageClassification = __webpack_exports__.SwinForImageClassification; +/******/ var __webpack_exports__SwinModel = __webpack_exports__.SwinModel; +/******/ var __webpack_exports__SwinPreTrainedModel = __webpack_exports__.SwinPreTrainedModel; +/******/ var __webpack_exports__T5ForConditionalGeneration = __webpack_exports__.T5ForConditionalGeneration; +/******/ var __webpack_exports__T5Model = __webpack_exports__.T5Model; +/******/ var __webpack_exports__T5PreTrainedModel = __webpack_exports__.T5PreTrainedModel; +/******/ var __webpack_exports__T5Tokenizer = __webpack_exports__.T5Tokenizer; +/******/ var __webpack_exports__TableTransformerForObjectDetection = __webpack_exports__.TableTransformerForObjectDetection; +/******/ var __webpack_exports__TableTransformerModel = __webpack_exports__.TableTransformerModel; +/******/ var __webpack_exports__TableTransformerObjectDetectionOutput = __webpack_exports__.TableTransformerObjectDetectionOutput; +/******/ var __webpack_exports__TableTransformerPreTrainedModel = __webpack_exports__.TableTransformerPreTrainedModel; +/******/ var __webpack_exports__Tensor = __webpack_exports__.Tensor; +/******/ var __webpack_exports__Text2TextGenerationPipeline = __webpack_exports__.Text2TextGenerationPipeline; +/******/ var __webpack_exports__TextClassificationPipeline = __webpack_exports__.TextClassificationPipeline; +/******/ var __webpack_exports__TextGenerationPipeline = __webpack_exports__.TextGenerationPipeline; +/******/ var __webpack_exports__TextToAudioPipeline = __webpack_exports__.TextToAudioPipeline; +/******/ var __webpack_exports__TokenClassificationPipeline = __webpack_exports__.TokenClassificationPipeline; +/******/ var __webpack_exports__TokenClassifierOutput = __webpack_exports__.TokenClassifierOutput; +/******/ var __webpack_exports__TokenizerModel = __webpack_exports__.TokenizerModel; +/******/ var __webpack_exports__TrOCRForCausalLM = __webpack_exports__.TrOCRForCausalLM; +/******/ var __webpack_exports__TrOCRPreTrainedModel = __webpack_exports__.TrOCRPreTrainedModel; +/******/ var __webpack_exports__TranslationPipeline = __webpack_exports__.TranslationPipeline; +/******/ var __webpack_exports__UniSpeechForCTC = __webpack_exports__.UniSpeechForCTC; +/******/ var __webpack_exports__UniSpeechForSequenceClassification = __webpack_exports__.UniSpeechForSequenceClassification; +/******/ var __webpack_exports__UniSpeechModel = __webpack_exports__.UniSpeechModel; +/******/ var __webpack_exports__UniSpeechPreTrainedModel = __webpack_exports__.UniSpeechPreTrainedModel; +/******/ var __webpack_exports__UniSpeechSatForAudioFrameClassification = __webpack_exports__.UniSpeechSatForAudioFrameClassification; +/******/ var __webpack_exports__UniSpeechSatForCTC = __webpack_exports__.UniSpeechSatForCTC; +/******/ var __webpack_exports__UniSpeechSatForSequenceClassification = __webpack_exports__.UniSpeechSatForSequenceClassification; +/******/ var __webpack_exports__UniSpeechSatModel = __webpack_exports__.UniSpeechSatModel; +/******/ var __webpack_exports__UniSpeechSatPreTrainedModel = __webpack_exports__.UniSpeechSatPreTrainedModel; +/******/ var __webpack_exports__ViTFeatureExtractor = __webpack_exports__.ViTFeatureExtractor; +/******/ var __webpack_exports__ViTForImageClassification = __webpack_exports__.ViTForImageClassification; +/******/ var __webpack_exports__ViTImageProcessor = __webpack_exports__.ViTImageProcessor; +/******/ var __webpack_exports__ViTModel = __webpack_exports__.ViTModel; +/******/ var __webpack_exports__ViTPreTrainedModel = __webpack_exports__.ViTPreTrainedModel; +/******/ var __webpack_exports__VisionEncoderDecoderModel = __webpack_exports__.VisionEncoderDecoderModel; +/******/ var __webpack_exports__VitMatteForImageMatting = __webpack_exports__.VitMatteForImageMatting; +/******/ var __webpack_exports__VitMatteImageProcessor = __webpack_exports__.VitMatteImageProcessor; +/******/ var __webpack_exports__VitMattePreTrainedModel = __webpack_exports__.VitMattePreTrainedModel; +/******/ var __webpack_exports__VitsModel = __webpack_exports__.VitsModel; +/******/ var __webpack_exports__VitsModelOutput = __webpack_exports__.VitsModelOutput; +/******/ var __webpack_exports__VitsPreTrainedModel = __webpack_exports__.VitsPreTrainedModel; +/******/ var __webpack_exports__VitsTokenizer = __webpack_exports__.VitsTokenizer; +/******/ var __webpack_exports__Wav2Vec2BertForCTC = __webpack_exports__.Wav2Vec2BertForCTC; +/******/ var __webpack_exports__Wav2Vec2BertForSequenceClassification = __webpack_exports__.Wav2Vec2BertForSequenceClassification; +/******/ var __webpack_exports__Wav2Vec2BertModel = __webpack_exports__.Wav2Vec2BertModel; +/******/ var __webpack_exports__Wav2Vec2BertPreTrainedModel = __webpack_exports__.Wav2Vec2BertPreTrainedModel; +/******/ var __webpack_exports__Wav2Vec2CTCTokenizer = __webpack_exports__.Wav2Vec2CTCTokenizer; +/******/ var __webpack_exports__Wav2Vec2FeatureExtractor = __webpack_exports__.Wav2Vec2FeatureExtractor; +/******/ var __webpack_exports__Wav2Vec2ForAudioFrameClassification = __webpack_exports__.Wav2Vec2ForAudioFrameClassification; +/******/ var __webpack_exports__Wav2Vec2ForCTC = __webpack_exports__.Wav2Vec2ForCTC; +/******/ var __webpack_exports__Wav2Vec2ForSequenceClassification = __webpack_exports__.Wav2Vec2ForSequenceClassification; +/******/ var __webpack_exports__Wav2Vec2Model = __webpack_exports__.Wav2Vec2Model; +/******/ var __webpack_exports__Wav2Vec2PreTrainedModel = __webpack_exports__.Wav2Vec2PreTrainedModel; +/******/ var __webpack_exports__Wav2Vec2ProcessorWithLM = __webpack_exports__.Wav2Vec2ProcessorWithLM; +/******/ var __webpack_exports__WavLMForAudioFrameClassification = __webpack_exports__.WavLMForAudioFrameClassification; +/******/ var __webpack_exports__WavLMForCTC = __webpack_exports__.WavLMForCTC; +/******/ var __webpack_exports__WavLMForSequenceClassification = __webpack_exports__.WavLMForSequenceClassification; +/******/ var __webpack_exports__WavLMForXVector = __webpack_exports__.WavLMForXVector; +/******/ var __webpack_exports__WavLMModel = __webpack_exports__.WavLMModel; +/******/ var __webpack_exports__WavLMPreTrainedModel = __webpack_exports__.WavLMPreTrainedModel; +/******/ var __webpack_exports__WhisperFeatureExtractor = __webpack_exports__.WhisperFeatureExtractor; +/******/ var __webpack_exports__WhisperForConditionalGeneration = __webpack_exports__.WhisperForConditionalGeneration; +/******/ var __webpack_exports__WhisperModel = __webpack_exports__.WhisperModel; +/******/ var __webpack_exports__WhisperPreTrainedModel = __webpack_exports__.WhisperPreTrainedModel; +/******/ var __webpack_exports__WhisperProcessor = __webpack_exports__.WhisperProcessor; +/******/ var __webpack_exports__WhisperTokenizer = __webpack_exports__.WhisperTokenizer; +/******/ var __webpack_exports__XLMForQuestionAnswering = __webpack_exports__.XLMForQuestionAnswering; +/******/ var __webpack_exports__XLMForSequenceClassification = __webpack_exports__.XLMForSequenceClassification; +/******/ var __webpack_exports__XLMForTokenClassification = __webpack_exports__.XLMForTokenClassification; +/******/ var __webpack_exports__XLMModel = __webpack_exports__.XLMModel; +/******/ var __webpack_exports__XLMPreTrainedModel = __webpack_exports__.XLMPreTrainedModel; +/******/ var __webpack_exports__XLMRobertaForMaskedLM = __webpack_exports__.XLMRobertaForMaskedLM; +/******/ var __webpack_exports__XLMRobertaForQuestionAnswering = __webpack_exports__.XLMRobertaForQuestionAnswering; +/******/ var __webpack_exports__XLMRobertaForSequenceClassification = __webpack_exports__.XLMRobertaForSequenceClassification; +/******/ var __webpack_exports__XLMRobertaForTokenClassification = __webpack_exports__.XLMRobertaForTokenClassification; +/******/ var __webpack_exports__XLMRobertaModel = __webpack_exports__.XLMRobertaModel; +/******/ var __webpack_exports__XLMRobertaPreTrainedModel = __webpack_exports__.XLMRobertaPreTrainedModel; +/******/ var __webpack_exports__XLMRobertaTokenizer = __webpack_exports__.XLMRobertaTokenizer; +/******/ var __webpack_exports__XLMTokenizer = __webpack_exports__.XLMTokenizer; +/******/ var __webpack_exports__XLMWithLMHeadModel = __webpack_exports__.XLMWithLMHeadModel; +/******/ var __webpack_exports__XVectorOutput = __webpack_exports__.XVectorOutput; +/******/ var __webpack_exports__YolosFeatureExtractor = __webpack_exports__.YolosFeatureExtractor; +/******/ var __webpack_exports__YolosForObjectDetection = __webpack_exports__.YolosForObjectDetection; +/******/ var __webpack_exports__YolosModel = __webpack_exports__.YolosModel; +/******/ var __webpack_exports__YolosObjectDetectionOutput = __webpack_exports__.YolosObjectDetectionOutput; +/******/ var __webpack_exports__YolosPreTrainedModel = __webpack_exports__.YolosPreTrainedModel; +/******/ var __webpack_exports__ZeroShotAudioClassificationPipeline = __webpack_exports__.ZeroShotAudioClassificationPipeline; +/******/ var __webpack_exports__ZeroShotClassificationPipeline = __webpack_exports__.ZeroShotClassificationPipeline; +/******/ var __webpack_exports__ZeroShotImageClassificationPipeline = __webpack_exports__.ZeroShotImageClassificationPipeline; +/******/ var __webpack_exports__ZeroShotObjectDetectionPipeline = __webpack_exports__.ZeroShotObjectDetectionPipeline; +/******/ var __webpack_exports__bankers_round = __webpack_exports__.bankers_round; +/******/ var __webpack_exports__cat = __webpack_exports__.cat; +/******/ var __webpack_exports__cos_sim = __webpack_exports__.cos_sim; +/******/ var __webpack_exports__dot = __webpack_exports__.dot; +/******/ var __webpack_exports__dynamicTimeWarping = __webpack_exports__.dynamicTimeWarping; +/******/ var __webpack_exports__env = __webpack_exports__.env; +/******/ var __webpack_exports__getTopItems = __webpack_exports__.getTopItems; +/******/ var __webpack_exports__hanning = __webpack_exports__.hanning; +/******/ var __webpack_exports__interpolate = __webpack_exports__.interpolate; +/******/ var __webpack_exports__interpolate_data = __webpack_exports__.interpolate_data; +/******/ var __webpack_exports__layer_norm = __webpack_exports__.layer_norm; +/******/ var __webpack_exports__log_softmax = __webpack_exports__.log_softmax; +/******/ var __webpack_exports__magnitude = __webpack_exports__.magnitude; +/******/ var __webpack_exports__max = __webpack_exports__.max; +/******/ var __webpack_exports__mean = __webpack_exports__.mean; +/******/ var __webpack_exports__mean_pooling = __webpack_exports__.mean_pooling; +/******/ var __webpack_exports__medianFilter = __webpack_exports__.medianFilter; +/******/ var __webpack_exports__mel_filter_bank = __webpack_exports__.mel_filter_bank; +/******/ var __webpack_exports__min = __webpack_exports__.min; +/******/ var __webpack_exports__ones = __webpack_exports__.ones; +/******/ var __webpack_exports__ones_like = __webpack_exports__.ones_like; +/******/ var __webpack_exports__permute = __webpack_exports__.permute; +/******/ var __webpack_exports__permute_data = __webpack_exports__.permute_data; +/******/ var __webpack_exports__pipeline = __webpack_exports__.pipeline; +/******/ var __webpack_exports__read_audio = __webpack_exports__.read_audio; +/******/ var __webpack_exports__round = __webpack_exports__.round; +/******/ var __webpack_exports__softmax = __webpack_exports__.softmax; +/******/ var __webpack_exports__spectrogram = __webpack_exports__.spectrogram; +/******/ var __webpack_exports__stack = __webpack_exports__.stack; +/******/ var __webpack_exports__std_mean = __webpack_exports__.std_mean; +/******/ var __webpack_exports__window_function = __webpack_exports__.window_function; +/******/ export { __webpack_exports__ASTFeatureExtractor as ASTFeatureExtractor, __webpack_exports__ASTForAudioClassification as ASTForAudioClassification, __webpack_exports__ASTModel as ASTModel, __webpack_exports__ASTPreTrainedModel as ASTPreTrainedModel, __webpack_exports__AlbertForMaskedLM as AlbertForMaskedLM, __webpack_exports__AlbertForQuestionAnswering as AlbertForQuestionAnswering, __webpack_exports__AlbertForSequenceClassification as AlbertForSequenceClassification, __webpack_exports__AlbertModel as AlbertModel, __webpack_exports__AlbertPreTrainedModel as AlbertPreTrainedModel, __webpack_exports__AlbertTokenizer as AlbertTokenizer, __webpack_exports__AudioClassificationPipeline as AudioClassificationPipeline, __webpack_exports__AutoConfig as AutoConfig, __webpack_exports__AutoModel as AutoModel, __webpack_exports__AutoModelForAudioClassification as AutoModelForAudioClassification, __webpack_exports__AutoModelForAudioFrameClassification as AutoModelForAudioFrameClassification, __webpack_exports__AutoModelForCTC as AutoModelForCTC, __webpack_exports__AutoModelForCausalLM as AutoModelForCausalLM, __webpack_exports__AutoModelForDepthEstimation as AutoModelForDepthEstimation, __webpack_exports__AutoModelForDocumentQuestionAnswering as AutoModelForDocumentQuestionAnswering, __webpack_exports__AutoModelForImageClassification as AutoModelForImageClassification, __webpack_exports__AutoModelForImageFeatureExtraction as AutoModelForImageFeatureExtraction, __webpack_exports__AutoModelForImageMatting as AutoModelForImageMatting, __webpack_exports__AutoModelForImageSegmentation as AutoModelForImageSegmentation, __webpack_exports__AutoModelForImageToImage as AutoModelForImageToImage, __webpack_exports__AutoModelForMaskGeneration as AutoModelForMaskGeneration, __webpack_exports__AutoModelForMaskedLM as AutoModelForMaskedLM, __webpack_exports__AutoModelForObjectDetection as AutoModelForObjectDetection, __webpack_exports__AutoModelForQuestionAnswering as AutoModelForQuestionAnswering, __webpack_exports__AutoModelForSemanticSegmentation as AutoModelForSemanticSegmentation, __webpack_exports__AutoModelForSeq2SeqLM as AutoModelForSeq2SeqLM, __webpack_exports__AutoModelForSequenceClassification as AutoModelForSequenceClassification, __webpack_exports__AutoModelForSpeechSeq2Seq as AutoModelForSpeechSeq2Seq, __webpack_exports__AutoModelForTextToSpectrogram as AutoModelForTextToSpectrogram, __webpack_exports__AutoModelForTextToWaveform as AutoModelForTextToWaveform, __webpack_exports__AutoModelForTokenClassification as AutoModelForTokenClassification, __webpack_exports__AutoModelForVision2Seq as AutoModelForVision2Seq, __webpack_exports__AutoModelForXVector as AutoModelForXVector, __webpack_exports__AutoModelForZeroShotObjectDetection as AutoModelForZeroShotObjectDetection, __webpack_exports__AutoProcessor as AutoProcessor, __webpack_exports__AutoTokenizer as AutoTokenizer, __webpack_exports__AutomaticSpeechRecognitionPipeline as AutomaticSpeechRecognitionPipeline, __webpack_exports__BartForConditionalGeneration as BartForConditionalGeneration, __webpack_exports__BartForSequenceClassification as BartForSequenceClassification, __webpack_exports__BartModel as BartModel, __webpack_exports__BartPretrainedModel as BartPretrainedModel, __webpack_exports__BartTokenizer as BartTokenizer, __webpack_exports__BaseModelOutput as BaseModelOutput, __webpack_exports__BeitFeatureExtractor as BeitFeatureExtractor, __webpack_exports__BeitForImageClassification as BeitForImageClassification, __webpack_exports__BeitModel as BeitModel, __webpack_exports__BeitPreTrainedModel as BeitPreTrainedModel, __webpack_exports__BertForMaskedLM as BertForMaskedLM, __webpack_exports__BertForQuestionAnswering as BertForQuestionAnswering, __webpack_exports__BertForSequenceClassification as BertForSequenceClassification, __webpack_exports__BertForTokenClassification as BertForTokenClassification, __webpack_exports__BertModel as BertModel, __webpack_exports__BertPreTrainedModel as BertPreTrainedModel, __webpack_exports__BertTokenizer as BertTokenizer, __webpack_exports__BitImageProcessor as BitImageProcessor, __webpack_exports__BlenderbotForConditionalGeneration as BlenderbotForConditionalGeneration, __webpack_exports__BlenderbotModel as BlenderbotModel, __webpack_exports__BlenderbotPreTrainedModel as BlenderbotPreTrainedModel, __webpack_exports__BlenderbotSmallForConditionalGeneration as BlenderbotSmallForConditionalGeneration, __webpack_exports__BlenderbotSmallModel as BlenderbotSmallModel, __webpack_exports__BlenderbotSmallPreTrainedModel as BlenderbotSmallPreTrainedModel, __webpack_exports__BlenderbotSmallTokenizer as BlenderbotSmallTokenizer, __webpack_exports__BlenderbotTokenizer as BlenderbotTokenizer, __webpack_exports__BloomForCausalLM as BloomForCausalLM, __webpack_exports__BloomModel as BloomModel, __webpack_exports__BloomPreTrainedModel as BloomPreTrainedModel, __webpack_exports__BloomTokenizer as BloomTokenizer, __webpack_exports__CLIPFeatureExtractor as CLIPFeatureExtractor, __webpack_exports__CLIPModel as CLIPModel, __webpack_exports__CLIPPreTrainedModel as CLIPPreTrainedModel, __webpack_exports__CLIPSegForImageSegmentation as CLIPSegForImageSegmentation, __webpack_exports__CLIPSegModel as CLIPSegModel, __webpack_exports__CLIPSegPreTrainedModel as CLIPSegPreTrainedModel, __webpack_exports__CLIPTextModelWithProjection as CLIPTextModelWithProjection, __webpack_exports__CLIPTokenizer as CLIPTokenizer, __webpack_exports__CLIPVisionModelWithProjection as CLIPVisionModelWithProjection, __webpack_exports__CamembertForMaskedLM as CamembertForMaskedLM, __webpack_exports__CamembertForQuestionAnswering as CamembertForQuestionAnswering, __webpack_exports__CamembertForSequenceClassification as CamembertForSequenceClassification, __webpack_exports__CamembertForTokenClassification as CamembertForTokenClassification, __webpack_exports__CamembertModel as CamembertModel, __webpack_exports__CamembertPreTrainedModel as CamembertPreTrainedModel, __webpack_exports__CamembertTokenizer as CamembertTokenizer, __webpack_exports__CausalLMOutput as CausalLMOutput, __webpack_exports__CausalLMOutputWithPast as CausalLMOutputWithPast, __webpack_exports__ChineseCLIPFeatureExtractor as ChineseCLIPFeatureExtractor, __webpack_exports__ChineseCLIPModel as ChineseCLIPModel, __webpack_exports__ChineseCLIPPreTrainedModel as ChineseCLIPPreTrainedModel, __webpack_exports__ClapAudioModelWithProjection as ClapAudioModelWithProjection, __webpack_exports__ClapFeatureExtractor as ClapFeatureExtractor, __webpack_exports__ClapModel as ClapModel, __webpack_exports__ClapPreTrainedModel as ClapPreTrainedModel, __webpack_exports__ClapTextModelWithProjection as ClapTextModelWithProjection, __webpack_exports__CodeGenForCausalLM as CodeGenForCausalLM, __webpack_exports__CodeGenModel as CodeGenModel, __webpack_exports__CodeGenPreTrainedModel as CodeGenPreTrainedModel, __webpack_exports__CodeGenTokenizer as CodeGenTokenizer, __webpack_exports__CodeLlamaTokenizer as CodeLlamaTokenizer, __webpack_exports__CohereTokenizer as CohereTokenizer, __webpack_exports__ConvBertForMaskedLM as ConvBertForMaskedLM, __webpack_exports__ConvBertForQuestionAnswering as ConvBertForQuestionAnswering, __webpack_exports__ConvBertForSequenceClassification as ConvBertForSequenceClassification, __webpack_exports__ConvBertForTokenClassification as ConvBertForTokenClassification, __webpack_exports__ConvBertModel as ConvBertModel, __webpack_exports__ConvBertPreTrainedModel as ConvBertPreTrainedModel, __webpack_exports__ConvBertTokenizer as ConvBertTokenizer, __webpack_exports__ConvNextFeatureExtractor as ConvNextFeatureExtractor, __webpack_exports__ConvNextForImageClassification as ConvNextForImageClassification, __webpack_exports__ConvNextImageProcessor as ConvNextImageProcessor, __webpack_exports__ConvNextModel as ConvNextModel, __webpack_exports__ConvNextPreTrainedModel as ConvNextPreTrainedModel, __webpack_exports__ConvNextV2ForImageClassification as ConvNextV2ForImageClassification, __webpack_exports__ConvNextV2Model as ConvNextV2Model, __webpack_exports__ConvNextV2PreTrainedModel as ConvNextV2PreTrainedModel, __webpack_exports__DPTFeatureExtractor as DPTFeatureExtractor, __webpack_exports__DPTForDepthEstimation as DPTForDepthEstimation, __webpack_exports__DPTImageProcessor as DPTImageProcessor, __webpack_exports__DPTModel as DPTModel, __webpack_exports__DPTPreTrainedModel as DPTPreTrainedModel, __webpack_exports__DebertaForMaskedLM as DebertaForMaskedLM, __webpack_exports__DebertaForQuestionAnswering as DebertaForQuestionAnswering, __webpack_exports__DebertaForSequenceClassification as DebertaForSequenceClassification, __webpack_exports__DebertaForTokenClassification as DebertaForTokenClassification, __webpack_exports__DebertaModel as DebertaModel, __webpack_exports__DebertaPreTrainedModel as DebertaPreTrainedModel, __webpack_exports__DebertaTokenizer as DebertaTokenizer, __webpack_exports__DebertaV2ForMaskedLM as DebertaV2ForMaskedLM, __webpack_exports__DebertaV2ForQuestionAnswering as DebertaV2ForQuestionAnswering, __webpack_exports__DebertaV2ForSequenceClassification as DebertaV2ForSequenceClassification, __webpack_exports__DebertaV2ForTokenClassification as DebertaV2ForTokenClassification, __webpack_exports__DebertaV2Model as DebertaV2Model, __webpack_exports__DebertaV2PreTrainedModel as DebertaV2PreTrainedModel, __webpack_exports__DebertaV2Tokenizer as DebertaV2Tokenizer, __webpack_exports__DeiTFeatureExtractor as DeiTFeatureExtractor, __webpack_exports__DeiTForImageClassification as DeiTForImageClassification, __webpack_exports__DeiTModel as DeiTModel, __webpack_exports__DeiTPreTrainedModel as DeiTPreTrainedModel, __webpack_exports__DepthAnythingForDepthEstimation as DepthAnythingForDepthEstimation, __webpack_exports__DepthAnythingPreTrainedModel as DepthAnythingPreTrainedModel, __webpack_exports__DepthEstimationPipeline as DepthEstimationPipeline, __webpack_exports__DetrFeatureExtractor as DetrFeatureExtractor, __webpack_exports__DetrForObjectDetection as DetrForObjectDetection, __webpack_exports__DetrForSegmentation as DetrForSegmentation, __webpack_exports__DetrModel as DetrModel, __webpack_exports__DetrObjectDetectionOutput as DetrObjectDetectionOutput, __webpack_exports__DetrPreTrainedModel as DetrPreTrainedModel, __webpack_exports__DetrSegmentationOutput as DetrSegmentationOutput, __webpack_exports__Dinov2ForImageClassification as Dinov2ForImageClassification, __webpack_exports__Dinov2Model as Dinov2Model, __webpack_exports__Dinov2PreTrainedModel as Dinov2PreTrainedModel, __webpack_exports__DistilBertForMaskedLM as DistilBertForMaskedLM, __webpack_exports__DistilBertForQuestionAnswering as DistilBertForQuestionAnswering, __webpack_exports__DistilBertForSequenceClassification as DistilBertForSequenceClassification, __webpack_exports__DistilBertForTokenClassification as DistilBertForTokenClassification, __webpack_exports__DistilBertModel as DistilBertModel, __webpack_exports__DistilBertPreTrainedModel as DistilBertPreTrainedModel, __webpack_exports__DistilBertTokenizer as DistilBertTokenizer, __webpack_exports__DocumentQuestionAnsweringPipeline as DocumentQuestionAnsweringPipeline, __webpack_exports__DonutFeatureExtractor as DonutFeatureExtractor, __webpack_exports__DonutSwinModel as DonutSwinModel, __webpack_exports__DonutSwinPreTrainedModel as DonutSwinPreTrainedModel, __webpack_exports__EfficientNetForImageClassification as EfficientNetForImageClassification, __webpack_exports__EfficientNetImageProcessor as EfficientNetImageProcessor, __webpack_exports__EfficientNetModel as EfficientNetModel, __webpack_exports__EfficientNetPreTrainedModel as EfficientNetPreTrainedModel, __webpack_exports__ElectraForMaskedLM as ElectraForMaskedLM, __webpack_exports__ElectraForQuestionAnswering as ElectraForQuestionAnswering, __webpack_exports__ElectraForSequenceClassification as ElectraForSequenceClassification, __webpack_exports__ElectraForTokenClassification as ElectraForTokenClassification, __webpack_exports__ElectraModel as ElectraModel, __webpack_exports__ElectraPreTrainedModel as ElectraPreTrainedModel, __webpack_exports__ElectraTokenizer as ElectraTokenizer, __webpack_exports__EsmForMaskedLM as EsmForMaskedLM, __webpack_exports__EsmForSequenceClassification as EsmForSequenceClassification, __webpack_exports__EsmForTokenClassification as EsmForTokenClassification, __webpack_exports__EsmModel as EsmModel, __webpack_exports__EsmPreTrainedModel as EsmPreTrainedModel, __webpack_exports__EsmTokenizer as EsmTokenizer, __webpack_exports__FFT as FFT, __webpack_exports__FalconForCausalLM as FalconForCausalLM, __webpack_exports__FalconModel as FalconModel, __webpack_exports__FalconPreTrainedModel as FalconPreTrainedModel, __webpack_exports__FalconTokenizer as FalconTokenizer, __webpack_exports__FeatureExtractionPipeline as FeatureExtractionPipeline, __webpack_exports__FeatureExtractor as FeatureExtractor, __webpack_exports__FillMaskPipeline as FillMaskPipeline, __webpack_exports__GLPNFeatureExtractor as GLPNFeatureExtractor, __webpack_exports__GLPNForDepthEstimation as GLPNForDepthEstimation, __webpack_exports__GLPNModel as GLPNModel, __webpack_exports__GLPNPreTrainedModel as GLPNPreTrainedModel, __webpack_exports__GPT2LMHeadModel as GPT2LMHeadModel, __webpack_exports__GPT2Model as GPT2Model, __webpack_exports__GPT2PreTrainedModel as GPT2PreTrainedModel, __webpack_exports__GPT2Tokenizer as GPT2Tokenizer, __webpack_exports__GPTBigCodeForCausalLM as GPTBigCodeForCausalLM, __webpack_exports__GPTBigCodeModel as GPTBigCodeModel, __webpack_exports__GPTBigCodePreTrainedModel as GPTBigCodePreTrainedModel, __webpack_exports__GPTJForCausalLM as GPTJForCausalLM, __webpack_exports__GPTJModel as GPTJModel, __webpack_exports__GPTJPreTrainedModel as GPTJPreTrainedModel, __webpack_exports__GPTNeoForCausalLM as GPTNeoForCausalLM, __webpack_exports__GPTNeoModel as GPTNeoModel, __webpack_exports__GPTNeoPreTrainedModel as GPTNeoPreTrainedModel, __webpack_exports__GPTNeoXForCausalLM as GPTNeoXForCausalLM, __webpack_exports__GPTNeoXModel as GPTNeoXModel, __webpack_exports__GPTNeoXPreTrainedModel as GPTNeoXPreTrainedModel, __webpack_exports__GPTNeoXTokenizer as GPTNeoXTokenizer, __webpack_exports__GemmaTokenizer as GemmaTokenizer, __webpack_exports__Grok1Tokenizer as Grok1Tokenizer, __webpack_exports__HerbertTokenizer as HerbertTokenizer, __webpack_exports__HubertForCTC as HubertForCTC, __webpack_exports__HubertForSequenceClassification as HubertForSequenceClassification, __webpack_exports__HubertModel as HubertModel, __webpack_exports__HubertPreTrainedModel as HubertPreTrainedModel, __webpack_exports__ImageClassificationPipeline as ImageClassificationPipeline, __webpack_exports__ImageFeatureExtractionPipeline as ImageFeatureExtractionPipeline, __webpack_exports__ImageFeatureExtractor as ImageFeatureExtractor, __webpack_exports__ImageMattingOutput as ImageMattingOutput, __webpack_exports__ImageSegmentationPipeline as ImageSegmentationPipeline, __webpack_exports__ImageToImagePipeline as ImageToImagePipeline, __webpack_exports__ImageToTextPipeline as ImageToTextPipeline, __webpack_exports__LlamaForCausalLM as LlamaForCausalLM, __webpack_exports__LlamaModel as LlamaModel, __webpack_exports__LlamaPreTrainedModel as LlamaPreTrainedModel, __webpack_exports__LlamaTokenizer as LlamaTokenizer, __webpack_exports__LongT5ForConditionalGeneration as LongT5ForConditionalGeneration, __webpack_exports__LongT5Model as LongT5Model, __webpack_exports__LongT5PreTrainedModel as LongT5PreTrainedModel, __webpack_exports__M2M100ForConditionalGeneration as M2M100ForConditionalGeneration, __webpack_exports__M2M100Model as M2M100Model, __webpack_exports__M2M100PreTrainedModel as M2M100PreTrainedModel, __webpack_exports__M2M100Tokenizer as M2M100Tokenizer, __webpack_exports__MBart50Tokenizer as MBart50Tokenizer, __webpack_exports__MBartForCausalLM as MBartForCausalLM, __webpack_exports__MBartForConditionalGeneration as MBartForConditionalGeneration, __webpack_exports__MBartForSequenceClassification as MBartForSequenceClassification, __webpack_exports__MBartModel as MBartModel, __webpack_exports__MBartPreTrainedModel as MBartPreTrainedModel, __webpack_exports__MBartTokenizer as MBartTokenizer, __webpack_exports__MPNetForMaskedLM as MPNetForMaskedLM, __webpack_exports__MPNetForQuestionAnswering as MPNetForQuestionAnswering, __webpack_exports__MPNetForSequenceClassification as MPNetForSequenceClassification, __webpack_exports__MPNetForTokenClassification as MPNetForTokenClassification, __webpack_exports__MPNetModel as MPNetModel, __webpack_exports__MPNetPreTrainedModel as MPNetPreTrainedModel, __webpack_exports__MPNetTokenizer as MPNetTokenizer, __webpack_exports__MT5ForConditionalGeneration as MT5ForConditionalGeneration, __webpack_exports__MT5Model as MT5Model, __webpack_exports__MT5PreTrainedModel as MT5PreTrainedModel, __webpack_exports__MarianMTModel as MarianMTModel, __webpack_exports__MarianModel as MarianModel, __webpack_exports__MarianPreTrainedModel as MarianPreTrainedModel, __webpack_exports__MarianTokenizer as MarianTokenizer, __webpack_exports__MaskedLMOutput as MaskedLMOutput, __webpack_exports__MistralForCausalLM as MistralForCausalLM, __webpack_exports__MistralModel as MistralModel, __webpack_exports__MistralPreTrainedModel as MistralPreTrainedModel, __webpack_exports__MobileBertForMaskedLM as MobileBertForMaskedLM, __webpack_exports__MobileBertForQuestionAnswering as MobileBertForQuestionAnswering, __webpack_exports__MobileBertForSequenceClassification as MobileBertForSequenceClassification, __webpack_exports__MobileBertModel as MobileBertModel, __webpack_exports__MobileBertPreTrainedModel as MobileBertPreTrainedModel, __webpack_exports__MobileBertTokenizer as MobileBertTokenizer, __webpack_exports__MobileViTFeatureExtractor as MobileViTFeatureExtractor, __webpack_exports__MobileViTForImageClassification as MobileViTForImageClassification, __webpack_exports__MobileViTModel as MobileViTModel, __webpack_exports__MobileViTPreTrainedModel as MobileViTPreTrainedModel, __webpack_exports__ModelOutput as ModelOutput, __webpack_exports__MptForCausalLM as MptForCausalLM, __webpack_exports__MptModel as MptModel, __webpack_exports__MptPreTrainedModel as MptPreTrainedModel, __webpack_exports__NllbTokenizer as NllbTokenizer, __webpack_exports__NomicBertModel as NomicBertModel, __webpack_exports__NomicBertPreTrainedModel as NomicBertPreTrainedModel, __webpack_exports__NougatImageProcessor as NougatImageProcessor, __webpack_exports__NougatTokenizer as NougatTokenizer, __webpack_exports__OPTForCausalLM as OPTForCausalLM, __webpack_exports__OPTModel as OPTModel, __webpack_exports__OPTPreTrainedModel as OPTPreTrainedModel, __webpack_exports__ObjectDetectionPipeline as ObjectDetectionPipeline, __webpack_exports__OwlViTFeatureExtractor as OwlViTFeatureExtractor, __webpack_exports__OwlViTForObjectDetection as OwlViTForObjectDetection, __webpack_exports__OwlViTModel as OwlViTModel, __webpack_exports__OwlViTPreTrainedModel as OwlViTPreTrainedModel, __webpack_exports__OwlViTProcessor as OwlViTProcessor, __webpack_exports__Owlv2ForObjectDetection as Owlv2ForObjectDetection, __webpack_exports__Owlv2ImageProcessor as Owlv2ImageProcessor, __webpack_exports__Owlv2Model as Owlv2Model, __webpack_exports__Owlv2PreTrainedModel as Owlv2PreTrainedModel, __webpack_exports__PhiForCausalLM as PhiForCausalLM, __webpack_exports__PhiModel as PhiModel, __webpack_exports__PhiPreTrainedModel as PhiPreTrainedModel, __webpack_exports__Pipeline as Pipeline, __webpack_exports__PreTrainedModel as PreTrainedModel, __webpack_exports__PreTrainedTokenizer as PreTrainedTokenizer, __webpack_exports__PretrainedConfig as PretrainedConfig, __webpack_exports__PretrainedMixin as PretrainedMixin, __webpack_exports__Processor as Processor, __webpack_exports__QuestionAnsweringModelOutput as QuestionAnsweringModelOutput, __webpack_exports__QuestionAnsweringPipeline as QuestionAnsweringPipeline, __webpack_exports__Qwen2ForCausalLM as Qwen2ForCausalLM, __webpack_exports__Qwen2Model as Qwen2Model, __webpack_exports__Qwen2PreTrainedModel as Qwen2PreTrainedModel, __webpack_exports__Qwen2Tokenizer as Qwen2Tokenizer, __webpack_exports__RawImage as RawImage, __webpack_exports__ResNetForImageClassification as ResNetForImageClassification, __webpack_exports__ResNetModel as ResNetModel, __webpack_exports__ResNetPreTrainedModel as ResNetPreTrainedModel, __webpack_exports__RoFormerForMaskedLM as RoFormerForMaskedLM, __webpack_exports__RoFormerForQuestionAnswering as RoFormerForQuestionAnswering, __webpack_exports__RoFormerForSequenceClassification as RoFormerForSequenceClassification, __webpack_exports__RoFormerForTokenClassification as RoFormerForTokenClassification, __webpack_exports__RoFormerModel as RoFormerModel, __webpack_exports__RoFormerPreTrainedModel as RoFormerPreTrainedModel, __webpack_exports__RoFormerTokenizer as RoFormerTokenizer, __webpack_exports__RobertaForMaskedLM as RobertaForMaskedLM, __webpack_exports__RobertaForQuestionAnswering as RobertaForQuestionAnswering, __webpack_exports__RobertaForSequenceClassification as RobertaForSequenceClassification, __webpack_exports__RobertaForTokenClassification as RobertaForTokenClassification, __webpack_exports__RobertaModel as RobertaModel, __webpack_exports__RobertaPreTrainedModel as RobertaPreTrainedModel, __webpack_exports__RobertaTokenizer as RobertaTokenizer, __webpack_exports__SamImageProcessor as SamImageProcessor, __webpack_exports__SamImageSegmentationOutput as SamImageSegmentationOutput, __webpack_exports__SamModel as SamModel, __webpack_exports__SamPreTrainedModel as SamPreTrainedModel, __webpack_exports__SamProcessor as SamProcessor, __webpack_exports__SeamlessM4TFeatureExtractor as SeamlessM4TFeatureExtractor, __webpack_exports__SegformerFeatureExtractor as SegformerFeatureExtractor, __webpack_exports__SegformerForImageClassification as SegformerForImageClassification, __webpack_exports__SegformerForSemanticSegmentation as SegformerForSemanticSegmentation, __webpack_exports__SegformerModel as SegformerModel, __webpack_exports__SegformerPreTrainedModel as SegformerPreTrainedModel, __webpack_exports__Seq2SeqLMOutput as Seq2SeqLMOutput, __webpack_exports__SequenceClassifierOutput as SequenceClassifierOutput, __webpack_exports__SiglipImageProcessor as SiglipImageProcessor, __webpack_exports__SiglipModel as SiglipModel, __webpack_exports__SiglipPreTrainedModel as SiglipPreTrainedModel, __webpack_exports__SiglipTextModel as SiglipTextModel, __webpack_exports__SiglipTokenizer as SiglipTokenizer, __webpack_exports__SiglipVisionModel as SiglipVisionModel, __webpack_exports__SpeechT5FeatureExtractor as SpeechT5FeatureExtractor, __webpack_exports__SpeechT5ForSpeechToText as SpeechT5ForSpeechToText, __webpack_exports__SpeechT5ForTextToSpeech as SpeechT5ForTextToSpeech, __webpack_exports__SpeechT5HifiGan as SpeechT5HifiGan, __webpack_exports__SpeechT5Model as SpeechT5Model, __webpack_exports__SpeechT5PreTrainedModel as SpeechT5PreTrainedModel, __webpack_exports__SpeechT5Processor as SpeechT5Processor, __webpack_exports__SpeechT5Tokenizer as SpeechT5Tokenizer, __webpack_exports__SqueezeBertForMaskedLM as SqueezeBertForMaskedLM, __webpack_exports__SqueezeBertForQuestionAnswering as SqueezeBertForQuestionAnswering, __webpack_exports__SqueezeBertForSequenceClassification as SqueezeBertForSequenceClassification, __webpack_exports__SqueezeBertModel as SqueezeBertModel, __webpack_exports__SqueezeBertPreTrainedModel as SqueezeBertPreTrainedModel, __webpack_exports__SqueezeBertTokenizer as SqueezeBertTokenizer, __webpack_exports__StableLmForCausalLM as StableLmForCausalLM, __webpack_exports__StableLmModel as StableLmModel, __webpack_exports__StableLmPreTrainedModel as StableLmPreTrainedModel, __webpack_exports__Starcoder2ForCausalLM as Starcoder2ForCausalLM, __webpack_exports__Starcoder2Model as Starcoder2Model, __webpack_exports__Starcoder2PreTrainedModel as Starcoder2PreTrainedModel, __webpack_exports__SummarizationPipeline as SummarizationPipeline, __webpack_exports__Swin2SRForImageSuperResolution as Swin2SRForImageSuperResolution, __webpack_exports__Swin2SRImageProcessor as Swin2SRImageProcessor, __webpack_exports__Swin2SRModel as Swin2SRModel, __webpack_exports__Swin2SRPreTrainedModel as Swin2SRPreTrainedModel, __webpack_exports__SwinForImageClassification as SwinForImageClassification, __webpack_exports__SwinModel as SwinModel, __webpack_exports__SwinPreTrainedModel as SwinPreTrainedModel, __webpack_exports__T5ForConditionalGeneration as T5ForConditionalGeneration, __webpack_exports__T5Model as T5Model, __webpack_exports__T5PreTrainedModel as T5PreTrainedModel, __webpack_exports__T5Tokenizer as T5Tokenizer, __webpack_exports__TableTransformerForObjectDetection as TableTransformerForObjectDetection, __webpack_exports__TableTransformerModel as TableTransformerModel, __webpack_exports__TableTransformerObjectDetectionOutput as TableTransformerObjectDetectionOutput, __webpack_exports__TableTransformerPreTrainedModel as TableTransformerPreTrainedModel, __webpack_exports__Tensor as Tensor, __webpack_exports__Text2TextGenerationPipeline as Text2TextGenerationPipeline, __webpack_exports__TextClassificationPipeline as TextClassificationPipeline, __webpack_exports__TextGenerationPipeline as TextGenerationPipeline, __webpack_exports__TextToAudioPipeline as TextToAudioPipeline, __webpack_exports__TokenClassificationPipeline as TokenClassificationPipeline, __webpack_exports__TokenClassifierOutput as TokenClassifierOutput, __webpack_exports__TokenizerModel as TokenizerModel, __webpack_exports__TrOCRForCausalLM as TrOCRForCausalLM, __webpack_exports__TrOCRPreTrainedModel as TrOCRPreTrainedModel, __webpack_exports__TranslationPipeline as TranslationPipeline, __webpack_exports__UniSpeechForCTC as UniSpeechForCTC, __webpack_exports__UniSpeechForSequenceClassification as UniSpeechForSequenceClassification, __webpack_exports__UniSpeechModel as UniSpeechModel, __webpack_exports__UniSpeechPreTrainedModel as UniSpeechPreTrainedModel, __webpack_exports__UniSpeechSatForAudioFrameClassification as UniSpeechSatForAudioFrameClassification, __webpack_exports__UniSpeechSatForCTC as UniSpeechSatForCTC, __webpack_exports__UniSpeechSatForSequenceClassification as UniSpeechSatForSequenceClassification, __webpack_exports__UniSpeechSatModel as UniSpeechSatModel, __webpack_exports__UniSpeechSatPreTrainedModel as UniSpeechSatPreTrainedModel, __webpack_exports__ViTFeatureExtractor as ViTFeatureExtractor, __webpack_exports__ViTForImageClassification as ViTForImageClassification, __webpack_exports__ViTImageProcessor as ViTImageProcessor, __webpack_exports__ViTModel as ViTModel, __webpack_exports__ViTPreTrainedModel as ViTPreTrainedModel, __webpack_exports__VisionEncoderDecoderModel as VisionEncoderDecoderModel, __webpack_exports__VitMatteForImageMatting as VitMatteForImageMatting, __webpack_exports__VitMatteImageProcessor as VitMatteImageProcessor, __webpack_exports__VitMattePreTrainedModel as VitMattePreTrainedModel, __webpack_exports__VitsModel as VitsModel, __webpack_exports__VitsModelOutput as VitsModelOutput, __webpack_exports__VitsPreTrainedModel as VitsPreTrainedModel, __webpack_exports__VitsTokenizer as VitsTokenizer, __webpack_exports__Wav2Vec2BertForCTC as Wav2Vec2BertForCTC, __webpack_exports__Wav2Vec2BertForSequenceClassification as Wav2Vec2BertForSequenceClassification, __webpack_exports__Wav2Vec2BertModel as Wav2Vec2BertModel, __webpack_exports__Wav2Vec2BertPreTrainedModel as Wav2Vec2BertPreTrainedModel, __webpack_exports__Wav2Vec2CTCTokenizer as Wav2Vec2CTCTokenizer, __webpack_exports__Wav2Vec2FeatureExtractor as Wav2Vec2FeatureExtractor, __webpack_exports__Wav2Vec2ForAudioFrameClassification as Wav2Vec2ForAudioFrameClassification, __webpack_exports__Wav2Vec2ForCTC as Wav2Vec2ForCTC, __webpack_exports__Wav2Vec2ForSequenceClassification as Wav2Vec2ForSequenceClassification, __webpack_exports__Wav2Vec2Model as Wav2Vec2Model, __webpack_exports__Wav2Vec2PreTrainedModel as Wav2Vec2PreTrainedModel, __webpack_exports__Wav2Vec2ProcessorWithLM as Wav2Vec2ProcessorWithLM, __webpack_exports__WavLMForAudioFrameClassification as WavLMForAudioFrameClassification, __webpack_exports__WavLMForCTC as WavLMForCTC, __webpack_exports__WavLMForSequenceClassification as WavLMForSequenceClassification, __webpack_exports__WavLMForXVector as WavLMForXVector, __webpack_exports__WavLMModel as WavLMModel, __webpack_exports__WavLMPreTrainedModel as WavLMPreTrainedModel, __webpack_exports__WhisperFeatureExtractor as WhisperFeatureExtractor, __webpack_exports__WhisperForConditionalGeneration as WhisperForConditionalGeneration, __webpack_exports__WhisperModel as WhisperModel, __webpack_exports__WhisperPreTrainedModel as WhisperPreTrainedModel, __webpack_exports__WhisperProcessor as WhisperProcessor, __webpack_exports__WhisperTokenizer as WhisperTokenizer, __webpack_exports__XLMForQuestionAnswering as XLMForQuestionAnswering, __webpack_exports__XLMForSequenceClassification as XLMForSequenceClassification, __webpack_exports__XLMForTokenClassification as XLMForTokenClassification, __webpack_exports__XLMModel as XLMModel, __webpack_exports__XLMPreTrainedModel as XLMPreTrainedModel, __webpack_exports__XLMRobertaForMaskedLM as XLMRobertaForMaskedLM, __webpack_exports__XLMRobertaForQuestionAnswering as XLMRobertaForQuestionAnswering, __webpack_exports__XLMRobertaForSequenceClassification as XLMRobertaForSequenceClassification, __webpack_exports__XLMRobertaForTokenClassification as XLMRobertaForTokenClassification, __webpack_exports__XLMRobertaModel as XLMRobertaModel, __webpack_exports__XLMRobertaPreTrainedModel as XLMRobertaPreTrainedModel, __webpack_exports__XLMRobertaTokenizer as XLMRobertaTokenizer, __webpack_exports__XLMTokenizer as XLMTokenizer, __webpack_exports__XLMWithLMHeadModel as XLMWithLMHeadModel, __webpack_exports__XVectorOutput as XVectorOutput, __webpack_exports__YolosFeatureExtractor as YolosFeatureExtractor, __webpack_exports__YolosForObjectDetection as YolosForObjectDetection, __webpack_exports__YolosModel as YolosModel, __webpack_exports__YolosObjectDetectionOutput as YolosObjectDetectionOutput, __webpack_exports__YolosPreTrainedModel as YolosPreTrainedModel, __webpack_exports__ZeroShotAudioClassificationPipeline as ZeroShotAudioClassificationPipeline, __webpack_exports__ZeroShotClassificationPipeline as ZeroShotClassificationPipeline, __webpack_exports__ZeroShotImageClassificationPipeline as ZeroShotImageClassificationPipeline, __webpack_exports__ZeroShotObjectDetectionPipeline as ZeroShotObjectDetectionPipeline, __webpack_exports__bankers_round as bankers_round, __webpack_exports__cat as cat, __webpack_exports__cos_sim as cos_sim, __webpack_exports__dot as dot, __webpack_exports__dynamicTimeWarping as dynamicTimeWarping, __webpack_exports__env as env, __webpack_exports__getTopItems as getTopItems, __webpack_exports__hanning as hanning, __webpack_exports__interpolate as interpolate, __webpack_exports__interpolate_data as interpolate_data, __webpack_exports__layer_norm as layer_norm, __webpack_exports__log_softmax as log_softmax, __webpack_exports__magnitude as magnitude, __webpack_exports__max as max, __webpack_exports__mean as mean, __webpack_exports__mean_pooling as mean_pooling, __webpack_exports__medianFilter as medianFilter, __webpack_exports__mel_filter_bank as mel_filter_bank, __webpack_exports__min as min, __webpack_exports__ones as ones, __webpack_exports__ones_like as ones_like, __webpack_exports__permute as permute, __webpack_exports__permute_data as permute_data, __webpack_exports__pipeline as pipeline, __webpack_exports__read_audio as read_audio, __webpack_exports__round as round, __webpack_exports__softmax as softmax, __webpack_exports__spectrogram as spectrogram, __webpack_exports__stack as stack, __webpack_exports__std_mean as std_mean, __webpack_exports__window_function as window_function }; +/******/ + +//# sourceMappingURL=transformers.js.map \ No newline at end of file diff --git a/toolkit/components/ml/vendor/transformers.js b/toolkit/components/ml/vendor/transformers.js new file mode 100644 index 0000000000..41b2600090 --- /dev/null +++ b/toolkit/components/ml/vendor/transformers.js @@ -0,0 +1,77 @@ +import*as e from"chrome://global/content/ml/ort-dev.js";var t={"onnxruntime-web": +/*!********************************************************!*\ + !*** external "chrome://global/content/ml/ort-dev.js" ***! + \********************************************************/t=>{t.exports=e},"?7a2c": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/()=>{},"?a42a": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/()=>{},"?2b25": +/*!***********************!*\ + !*** sharp (ignored) ***! + \***********************/()=>{},"?e65c": +/*!****************************!*\ + !*** stream/web (ignored) ***! + \****************************/()=>{},"?569f": +/*!********************!*\ + !*** fs (ignored) ***! + \********************/()=>{},"?3f59": +/*!**********************!*\ + !*** path (ignored) ***! + \**********************/()=>{},"?154a": +/*!*********************!*\ + !*** url (ignored) ***! + \*********************/()=>{},"./node_modules/@huggingface/jinja/dist/index.js": +/*!*******************************************************!*\ + !*** ./node_modules/@huggingface/jinja/dist/index.js ***! + \*******************************************************/(e,t,s)=>{s.r(t),s.d(t,{Environment:()=>X,Interpreter:()=>Q,Template:()=>Y,parse:()=>z,tokenize:()=>d});var o=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",Is:"Is",NotIn:"NotIn",Else:"Else",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator"}),n=Object.freeze({set:o.Set,for:o.For,in:o.In,is:o.Is,if:o.If,else:o.Else,endif:o.EndIf,elif:o.ElseIf,endfor:o.EndFor,and:o.And,or:o.Or,not:o.Not,"not in":o.NotIn,true:o.BooleanLiteral,false:o.BooleanLiteral}),r=class{constructor(e,t){this.value=e,this.type=t}};function a(e){return/\w/.test(e)}function i(e){return/[0-9]/.test(e)}var l=[["{%",o.OpenStatement],["%}",o.CloseStatement],["{{",o.OpenExpression],["}}",o.CloseExpression],["(",o.OpenParen],[")",o.CloseParen],["{",o.OpenCurlyBracket],["}",o.CloseCurlyBracket],["[",o.OpenSquareBracket],["]",o.CloseSquareBracket],[",",o.Comma],[".",o.Dot],[":",o.Colon],["|",o.Pipe],["<=",o.ComparisonBinaryOperator],[">=",o.ComparisonBinaryOperator],["==",o.ComparisonBinaryOperator],["!=",o.ComparisonBinaryOperator],["<",o.ComparisonBinaryOperator],[">",o.ComparisonBinaryOperator],["+",o.AdditiveBinaryOperator],["-",o.AdditiveBinaryOperator],["*",o.MultiplicativeBinaryOperator],["/",o.MultiplicativeBinaryOperator],["%",o.MultiplicativeBinaryOperator],["=",o.Equals]],c=new Map([["n","\n"],["t","\t"],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function d(e,t={}){const s=[],d=function(e,t={}){return e.endsWith("\n")&&(e=e.slice(0,-1)),e=e.replace(/{#.*?#}/gs,"{##}"),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%])/gm,"$1")),t.trim_blocks&&(e=e.replace(/([#%]})\n/g,"$1")),e.replace(/{##}/g,"").replace(/-%}\s*/g,"%}").replace(/\s*{%-/g,"{%").replace(/-}}\s*/g,"}}").replace(/\s*{{-/g,"{{")}(e,t);let u=0;const h=e=>{let t="";for(;e(d[u]);)if("\\"!==d[u]){if(t+=d[u++],u>=d.length)throw new SyntaxError("Unexpected end of input")}else{if(++u,u>=d.length)throw new SyntaxError("Unexpected end of input");const e=d[u++],s=c.get(e);if(void 0===s)throw new SyntaxError(`Unexpected escaped character: ${e}`);t+=s}return t};e:for(;u0){s.push(new r(e,o.Text));continue}}h((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=s.at(-1)?.type;if(e===o.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case o.Identifier:case o.NumericLiteral:case o.BooleanLiteral:case o.StringLiteral:case o.CloseParen:case o.CloseSquareBracket:break;default:{++u;const e=h(i);s.push(new r(`${t}${e}`,e.length>0?o.NumericLiteral:o.UnaryOperator));continue}}}for(const[e,t]of l){if(d.slice(u,u+e.length)===e){s.push(new r(e,t)),u+=e.length;continue e}}if("'"!==t&&'"'!==t)if(i(t)){const e=h(i);s.push(new r(e,o.NumericLiteral))}else{if(!a(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=h(a),t=Object.hasOwn(n,e)?n[e]:o.Identifier;t===o.In&&s.at(-1)?.type===o.Not?(s.pop(),s.push(new r("not in",o.NotIn))):s.push(new r(e,t))}}else{++u;const e=h((e=>e!==t));s.push(new r(e,o.StringLiteral)),++u}}return s}var u=class{type="Statement"},h=class extends u{constructor(e){super(),this.body=e}type="Program"},p=class extends u{constructor(e,t,s){super(),this.test=e,this.body=t,this.alternate=s}type="If"},_=class extends u{constructor(e,t,s){super(),this.loopvar=e,this.iterable=t,this.body=s}type="For"},m=class extends u{constructor(e,t){super(),this.assignee=e,this.value=t}type="Set"},f=class extends u{type="Expression"},g=class extends f{constructor(e,t,s){super(),this.object=e,this.property=t,this.computed=s}type="MemberExpression"},M=class extends f{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},w=class extends f{constructor(e){super(),this.value=e}type="Identifier"},T=class extends f{constructor(e){super(),this.value=e}type="Literal"},k=class extends T{type="NumericLiteral"},b=class extends T{type="StringLiteral"},x=class extends T{type="BooleanLiteral"},y=class extends T{type="ArrayLiteral"},F=class extends T{type="TupleLiteral"},C=class extends T{type="ObjectLiteral"},P=class extends f{constructor(e,t,s){super(),this.operator=e,this.left=t,this.right=s}type="BinaryExpression"},v=class extends f{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},S=class extends f{constructor(e,t,s){super(),this.operand=e,this.negate=t,this.test=s}type="TestExpression"},A=class extends f{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},L=class extends f{constructor(e=void 0,t=void 0,s=void 0){super(),this.start=e,this.stop=t,this.step=s}type="SliceExpression"},E=class extends f{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function z(e){const t=new h([]);let s=0;function n(t,o){const n=e[s++];if(!n||n.type!==t)throw new Error(`Parser Error: ${o}. ${n.type} !== ${t}.`);return n}function r(){switch(e[s].type){case o.Text:return new b(n(o.Text,"Expected text token").value);case o.OpenStatement:return function(){let t;switch(n(o.OpenStatement,"Expected opening statement token"),e[s].type){case o.Set:++s,t=l(),n(o.CloseStatement,"Expected closing statement token");break;case o.If:++s,t=c(),n(o.OpenStatement,"Expected {% token"),n(o.EndIf,"Expected endif token"),n(o.CloseStatement,"Expected %} token");break;case o.For:++s,t=function(){const e=d(!0);if(!(e instanceof w||e instanceof F))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);n(o.In,"Expected `in` keyword following loop variable");const t=u();n(o.CloseStatement,"Expected closing statement token");const s=[];for(;a(o.OpenStatement,o.EndFor);)s.push(r());return new _(e,t,s)}(),n(o.OpenStatement,"Expected {% token"),n(o.EndFor,"Expected endfor token"),n(o.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${e[s].type}`)}return t}();case o.OpenExpression:return function(){n(o.OpenExpression,"Expected opening expression token");const e=u();return n(o.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[s].type}`)}}function a(...t){return s+t.length<=e.length&&t.some(((t,o)=>t!==e[s+o].type))}function i(...t){return s+t.length<=e.length&&t.every(((t,o)=>t===e[s+o].type))}function l(){const e=u();if(i(o.Equals)){++s;const t=l();return new m(e,t)}return e}function c(){const t=u();n(o.CloseStatement,"Expected closing statement token");const a=[],l=[];for(;e[s]?.type!==o.OpenStatement||e[s+1]?.type!==o.ElseIf&&e[s+1]?.type!==o.Else&&e[s+1]?.type!==o.EndIf;)a.push(r());if(e[s]?.type===o.OpenStatement&&e[s+1]?.type!==o.EndIf)if(++s,i(o.ElseIf))n(o.ElseIf,"Expected elseif token"),l.push(c());else for(n(o.Else,"Expected else token"),n(o.CloseStatement,"Expected closing statement token");e[s]?.type!==o.OpenStatement||e[s+1]?.type!==o.EndIf;)l.push(r());return new p(t,a,l)}function d(e=!1){const t=e?q:u,n=[t()],r=i(o.Comma);for(;r&&(++s,n.push(t()),i(o.Comma)););return r?new F(n):n[0]}function u(){return function(){const e=f();if(i(o.If)){++s;const t=f();n(o.Else,"Expected else token");const r=f();return new p(t,[e],[r])}return e}()}function f(){let t=T();for(;i(o.Or);){const o=e[s];++s;const n=T();t=new P(o,t,n)}return t}function T(){let t=z();for(;i(o.And);){const o=e[s];++s;const n=z();t=new P(o,t,n)}return t}function z(){let t;for(;i(o.Not);){const o=e[s];++s;const n=z();t=new A(o,n)}return t??function(){let t=B();for(;i(o.ComparisonBinaryOperator)||i(o.In)||i(o.NotIn);){const o=e[s];++s;const n=B();t=new P(o,t,n)}return t}()}function B(){let t=N();for(;i(o.AdditiveBinaryOperator);){const o=e[s];++s;const n=N();t=new P(o,t,n)}return t}function I(){const t=function(){let t=q();for(;i(o.Dot)||i(o.OpenSquareBracket);){const r=e[s];let a;++s;const i=r.type!==o.Dot;if(i)a=D(),n(o.CloseSquareBracket,"Expected closing square bracket");else if(a=q(),"Identifier"!==a.type)throw new SyntaxError("Expected identifier following dot operator");t=new g(t,a,i)}return t}();return i(o.OpenParen)?O(t):t}function O(e){let t=new M(e,function(){n(o.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!i(o.CloseParen);){let t=u();if(i(o.Equals)){if(++s,!(t instanceof w))throw new SyntaxError("Expected identifier for keyword argument");const e=u();t=new E(t,e)}e.push(t),i(o.Comma)&&++s}return e}();return n(o.CloseParen,"Expected closing parenthesis for arguments list"),e}());return i(o.OpenParen)&&(t=O(t)),t}function D(){const e=[];let t=!1;for(;!i(o.CloseSquareBracket);)i(o.Colon)?(e.push(void 0),++s,t=!0):(e.push(u()),i(o.Colon)&&(++s,t=!0));if(0===e.length)throw new SyntaxError("Expected at least one argument for member/slice expression");if(t){if(e.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new L(...e)}return e[0]}function N(){let t=V();for(;i(o.MultiplicativeBinaryOperator);){const o=e[s];++s;const n=V();t=new P(o,t,n)}return t}function V(){let e=function(){let e=I();for(;i(o.Pipe);){++s;let t=q();if(!(t instanceof w))throw new SyntaxError("Expected identifier for the filter");i(o.OpenParen)&&(t=O(t)),e=new v(e,t)}return e}();for(;i(o.Is);){++s;const t=i(o.Not);t&&++s;let n=q();if(n instanceof x&&(n=new w(n.value.toString())),!(n instanceof w))throw new SyntaxError("Expected identifier for the test");e=new S(e,t,n)}return e}function q(){const t=e[s];switch(t.type){case o.NumericLiteral:return++s,new k(Number(t.value));case o.StringLiteral:return++s,new b(t.value);case o.BooleanLiteral:return++s,new x("true"===t.value);case o.Identifier:return++s,new w(t.value);case o.OpenParen:{++s;const t=d();if(e[s].type!==o.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[s].type} instead`);return++s,t}case o.OpenSquareBracket:{++s;const e=[];for(;!i(o.CloseSquareBracket);)e.push(u()),i(o.Comma)&&++s;return++s,new y(e)}case o.OpenCurlyBracket:{++s;const e=new Map;for(;!i(o.CloseCurlyBracket);){const t=u();n(o.Colon,"Expected colon between key and value in object literal");const r=u();e.set(t,r),i(o.Comma)&&++s}return++s,new C(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;s=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),s=(s??=e.length)<0?Math.max(e.length+s,0):Math.min(s,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),s=(s??=-1)<-1?Math.max(e.length+s,-1):Math.min(s,e.length-1));const r=[];for(let a=t;n*ae.toUpperCase()))}var D=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new q(!!this.value)}},N=class extends D{type="NumericValue"},V=class extends D{type="StringValue";builtins=new Map([["upper",new W((()=>new V(this.value.toUpperCase())))],["lower",new W((()=>new V(this.value.toLowerCase())))],["strip",new W((()=>new V(this.value.trim())))],["title",new W((()=>new V(O(this.value))))],["length",new N(this.value.length)]])},q=class extends D{type="BooleanValue"},j=class extends D{type="ObjectValue";__bool__(){return new q(this.value.size>0)}builtins=new Map([["get",new W((([e,t])=>{if(!(e instanceof V))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new $}))],["items",new W((()=>new R(Array.from(this.value.entries()).map((([e,t])=>new R([new V(e),t]))))))]])},R=class extends D{type="ArrayValue";builtins=new Map([["length",new N(this.value.length)]]);__bool__(){return new q(this.value.length>0)}},G=class extends R{type="TupleValue"},W=class extends D{type="FunctionValue"},$=class extends D{type="NullValue"},U=class extends D{type="UndefinedValue"},X=class{constructor(e){this.parent=e}variables=new Map([["namespace",new W((e=>{if(0===e.length)return new j(new Map);if(1!==e.length||!(e[0]instanceof j))throw new Error("`namespace` expects either zero arguments or a single object argument");return e[0]}))]]);tests=new Map([["boolean",e=>"BooleanValue"===e.type],["callable",e=>e instanceof W],["odd",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "odd" to type: ${e.type}`);return e.value%2!=0}],["even",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "even" to type: ${e.type}`);return e.value%2==0}],["false",e=>"BooleanValue"===e.type&&!e.value],["true",e=>"BooleanValue"===e.type&&e.value],["number",e=>"NumericValue"===e.type],["integer",e=>"NumericValue"===e.type&&Number.isInteger(e.value)],["iterable",e=>e instanceof R||e instanceof V],["lower",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toLowerCase()}],["upper",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toUpperCase()}],["none",e=>"NullValue"===e.type],["defined",e=>"UndefinedValue"!==e.type],["undefined",e=>"UndefinedValue"===e.type],["equalto",(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,H(t))}declareVariable(e,t){if(this.variables.has(e))throw new SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw new Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new U}catch{return new U}}},Q=class{global;constructor(e){this.global=e??new X}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){const s=this.evaluate(e.left,t);switch(e.operator.value){case"and":return s.__bool__().value?this.evaluate(e.right,t):s;case"or":return s.__bool__().value?s:this.evaluate(e.right,t)}const o=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new q(s.value==o.value);case"!=":return new q(s.value!=o.value)}if(s instanceof U||o instanceof U)throw new Error("Cannot perform operation on undefined values");if(s instanceof $||o instanceof $)throw new Error("Cannot perform operation on null values");if(s instanceof N&&o instanceof N)switch(e.operator.value){case"+":return new N(s.value+o.value);case"-":return new N(s.value-o.value);case"*":return new N(s.value*o.value);case"/":return new N(s.value/o.value);case"%":return new N(s.value%o.value);case"<":return new q(s.value":return new q(s.value>o.value);case">=":return new q(s.value>=o.value);case"<=":return new q(s.value<=o.value)}else if(s instanceof R&&o instanceof R){if("+"===e.operator.value)return new R(s.value.concat(o.value))}else if(o instanceof R){const t=void 0!==o.value.find((e=>e.value===s.value));switch(e.operator.value){case"in":return new q(t);case"not in":return new q(!t)}}if((s instanceof V||o instanceof V)&&"+"===e.operator.value)return new V(s.value.toString()+o.value.toString());if(s instanceof V&&o instanceof V)switch(e.operator.value){case"in":return new q(o.value.includes(s.value));case"not in":return new q(!o.value.includes(s.value))}if(s instanceof V&&o instanceof j)switch(e.operator.value){case"in":return new q(o.value.has(s.value));case"not in":return new q(!o.value.has(s.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${s.type} and ${o.type}`)}evaluateFilterExpression(e,t){const s=this.evaluate(e.operand,t);if("Identifier"===e.filter.type){const t=e.filter;if(s instanceof R)switch(t.value){case"list":return s;case"first":return s.value[0];case"last":return s.value[s.value.length-1];case"length":return new N(s.value.length);case"reverse":return new R(s.value.reverse());case"sort":return new R(s.value.sort(((e,t)=>{if(e.type!==t.type)throw new Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case"NumericValue":return e.value-t.value;case"StringValue":return e.value.localeCompare(t.value);default:throw new Error(`Cannot compare type: ${e.type}`)}})));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(s instanceof V)switch(t.value){case"length":return new N(s.value.length);case"upper":return new V(s.value.toUpperCase());case"lower":return new V(s.value.toLowerCase());case"title":return new V(O(s.value));case"capitalize":return new V(s.value.charAt(0).toUpperCase()+s.value.slice(1));case"trim":return new V(s.value.trim());default:throw new Error(`Unknown StringValue filter: ${t.value}`)}else{if(s instanceof N){if("abs"===t.value)return new N(Math.abs(s.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(s instanceof j)switch(t.value){case"items":return new R(Array.from(s.value.entries()).map((([e,t])=>new R([new V(e),t]))));case"length":return new N(s.value.size);default:throw new Error(`Unknown ObjectValue filter: ${t.value}`)}}throw new Error(`Cannot apply filter "${t.value}" to type: ${s.type}`)}if("CallExpression"===e.filter.type){const o=e.filter;if("Identifier"!==o.callee.type)throw new Error(`Unknown filter: ${o.callee.type}`);const n=o.callee.value;if(s instanceof R){if("selectattr"===n){if(s.value.some((e=>!(e instanceof j))))throw new Error("`selectattr` can only be applied to array of objects");if(o.args.some((e=>"StringLiteral"!==e.type)))throw new Error("arguments of `selectattr` must be strings");const[e,n,r]=o.args.map((e=>this.evaluate(e,t)));let a;if(n){const e=t.tests.get(n.value);if(!e)throw new Error(`Unknown test: ${n.value}`);a=e}else a=(...e)=>e[0].__bool__().value;const i=s.value.filter((t=>{const s=t.value.get(e.value);return!!s&&a(s,r)}));return new R(i)}throw new Error(`Unknown ArrayValue filter: ${n}`)}throw new Error(`Cannot apply filter "${n}" to type: ${s.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const s=this.evaluate(e.operand,t),o=t.tests.get(e.test.value);if(!o)throw new Error(`Unknown test: ${e.test.value}`);const n=o(s);return new q(e.negate?!n:n)}evaluateUnaryExpression(e,t){const s=this.evaluate(e.argument,t);if("not"===e.operator.value)return new q(!s.value);throw new SyntaxError(`Unknown operator: ${e.operator.value}`)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let s="";for(const o of e){const e=this.evaluate(o,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(s+=e.value)}return new V(s)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const s=[],o=new Map;for(const n of e.args)if("KeywordArgumentExpression"===n.type){const e=n;o.set(e.key.value,this.evaluate(e.value,t))}else s.push(this.evaluate(n,t));o.size>0&&s.push(new j(o));const n=this.evaluate(e.callee,t);if("FunctionValue"!==n.type)throw new Error(`Cannot call something that is not a function: got ${n.type}`);return n.value(s,t)}evaluateSliceExpression(e,t,s){if(!(e instanceof R||e instanceof V))throw new Error("Slice object must be an array or string");const o=this.evaluate(t.start,s),n=this.evaluate(t.stop,s),r=this.evaluate(t.step,s);if(!(o instanceof N||o instanceof U))throw new Error("Slice start must be numeric or undefined");if(!(n instanceof N||n instanceof U))throw new Error("Slice stop must be numeric or undefined");if(!(r instanceof N||r instanceof U))throw new Error("Slice step must be numeric or undefined");return e instanceof R?new R(I(e.value,o.value,n.value,r.value)):new V(I(Array.from(e.value),o.value,n.value,r.value).join(""))}evaluateMemberExpression(e,t){const s=this.evaluate(e.object,t);let o,n;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(s,e.property,t);o=this.evaluate(e.property,t)}else o=new V(e.property.value);if(s instanceof j){if(!(o instanceof V))throw new Error(`Cannot access property with non-string: got ${o.type}`);n=s.value.get(o.value)??s.builtins.get(o.value)}else if(s instanceof R||s instanceof V)if(o instanceof N)n=s.value.at(o.value),s instanceof V&&(n=new V(s.value.at(o.value)));else{if(!(o instanceof V))throw new Error(`Cannot access property with non-string/non-number: got ${o.type}`);n=s.builtins.get(o.value)}else{if(!(o instanceof V))throw new Error(`Cannot access property with non-string: got ${o.type}`);n=s.builtins.get(o.value)}return n instanceof D?n:new U}evaluateSet(e,t){const s=this.evaluate(e.value,t);if("Identifier"===e.assignee.type){const o=e.assignee.value;t.setVariable(o,s)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const o=e.assignee,n=this.evaluate(o.object,t);if(!(n instanceof j))throw new Error("Cannot assign to member of non-object");if("Identifier"!==o.property.type)throw new Error("Cannot assign to member with non-identifier property");n.value.set(o.property.value,s)}}return new $}evaluateIf(e,t){const s=this.evaluate(e.test,t);return this.evaluateBlock(s.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){const s=new X(t),o=this.evaluate(e.iterable,s);if(!(o instanceof R))throw new Error(`Expected iterable type in for loop: got ${o.type}`);let n="";for(let t=0;t0?o.value[t-1]:new U],["nextitem",to.value.length?"few":"many"} items to unpack`);for(let e=0;ethis.evaluate(e,t))));case"TupleLiteral":return new G(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const s=new Map;for(const[o,n]of e.value){const e=this.evaluate(o,t);if(!(e instanceof V))throw new Error(`Object keys must be strings: got ${e.type}`);s.set(e.value,this.evaluate(n,t))}return new j(s)}case"Identifier":return this.evaluateIdentifier(e,t);case"CallExpression":return this.evaluateCallExpression(e,t);case"MemberExpression":return this.evaluateMemberExpression(e,t);case"UnaryExpression":return this.evaluateUnaryExpression(e,t);case"BinaryExpression":return this.evaluateBinaryExpression(e,t);case"FilterExpression":return this.evaluateFilterExpression(e,t);case"TestExpression":return this.evaluateTestExpression(e,t);default:throw new SyntaxError(`Unknown node type: ${e.type}`)}}};function H(e){switch(typeof e){case"number":return new N(e);case"string":return new V(e);case"boolean":return new q(e);case"object":return null===e?new $:Array.isArray(e)?new R(e.map(H)):new j(new Map(Object.entries(e).map((([e,t])=>[e,H(t)]))));case"function":return new W(((t,s)=>H(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}var Y=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=z(t)}render(e){const t=new X;t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",B);for(const[s,o]of Object.entries(e))t.set(s,o);return new Q(t).run(this.parsed).value}}},"./src/backends/onnx.js": +/*!******************************!*\ + !*** ./src/backends/onnx.js ***! + \******************************/(e,t,s)=>{s.r(t),s.d(t,{ONNX:()=>n,executionProviders:()=>r});s(/*! onnxruntime-web */"onnxruntime-web");const o=ort;let n;const r=["wasm"];if("undefined"!=typeof process&&"node"===process?.release?.name)n=ONNX_NODE.default??ONNX_NODE,r.unshift("cpu");else{n=o.default??o;"undefined"!=typeof navigator&&/iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent)&&(n.env.wasm.simd=!1)}},"./src/configs.js": +/*!************************!*\ + !*** ./src/configs.js ***! + \************************/(e,t,s)=>{s.r(t),s.d(t,{AutoConfig:()=>r,PretrainedConfig:()=>n});var o=s(/*! ./utils/hub.js */"./src/utils/hub.js");class n{constructor(e){this.model_type=null,this.is_encoder_decoder=!1,Object.assign(this,e)}static async from_pretrained(e,{progress_callback:t=null,config:s=null,cache_dir:n=null,local_files_only:r=!1,revision:a="main"}={}){let i=s??await async function(e,t){return await(0,o.getModelJSON)(e,"config.json",!0,t)}(e,{progress_callback:t,config:s,cache_dir:n,local_files_only:r,revision:a});return new this(i)}}class r{static async from_pretrained(...e){return n.from_pretrained(...e)}}},"./src/env.js": +/*!********************!*\ + !*** ./src/env.js ***! + \********************/(e,t,s)=>{s.r(t),s.d(t,{env:()=>g});var o=s(/*! fs */"?569f"),n=s(/*! path */"?3f59"),r=s(/*! url */"?154a"),a=s(/*! ./backends/onnx.js */"./src/backends/onnx.js");const{env:i}=a.ONNX,l="2.16.1",c="undefined"!=typeof self&&"caches"in self,d=!M(o),u=!M(n),h=d&&u,p=h?n.dirname(n.dirname(r.fileURLToPath("file:///Users/tarekziade/Dev/mozilla-central/toolkit/components/ml/vendor/tmp/transformers.js/src/env.js"))):"./",_=h?n.join(p,"/.cache/"):null,m="/models/",f=h?n.join(p,m):m;i?.wasm&&(i.wasm.wasmPaths=h?n.join(p,"/dist/"):`https://cdn.jsdelivr.net/npm/@xenova/transformers@${l}/dist/`);const g={backends:{onnx:i,tfjs:{}},__dirname:p,version:l,allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!0,localModelPath:f,useFS:d,useBrowserCache:c,useFSCache:d,cacheDir:_,useCustomCache:!1,customCache:null};function M(e){return 0===Object.keys(e).length}},"./src/models.js": +/*!***********************!*\ + !*** ./src/models.js ***! + \***********************/(e,t,s)=>{s.r(t),s.d(t,{ASTForAudioClassification:()=>Kt,ASTModel:()=>Zt,ASTPreTrainedModel:()=>Jt,AlbertForMaskedLM:()=>lt,AlbertForQuestionAnswering:()=>it,AlbertForSequenceClassification:()=>at,AlbertModel:()=>rt,AlbertPreTrainedModel:()=>nt,AutoModel:()=>ta,AutoModelForAudioClassification:()=>wa,AutoModelForAudioFrameClassification:()=>ka,AutoModelForCTC:()=>Ma,AutoModelForCausalLM:()=>la,AutoModelForDepthEstimation:()=>Fa,AutoModelForDocumentQuestionAnswering:()=>ba,AutoModelForImageClassification:()=>ha,AutoModelForImageFeatureExtraction:()=>Ca,AutoModelForImageMatting:()=>xa,AutoModelForImageSegmentation:()=>pa,AutoModelForImageToImage:()=>ya,AutoModelForMaskGeneration:()=>ga,AutoModelForMaskedLM:()=>ca,AutoModelForObjectDetection:()=>ma,AutoModelForQuestionAnswering:()=>da,AutoModelForSemanticSegmentation:()=>_a,AutoModelForSeq2SeqLM:()=>na,AutoModelForSequenceClassification:()=>sa,AutoModelForSpeechSeq2Seq:()=>ra,AutoModelForTextToSpectrogram:()=>aa,AutoModelForTextToWaveform:()=>ia,AutoModelForTokenClassification:()=>oa,AutoModelForVision2Seq:()=>ua,AutoModelForXVector:()=>Ta,AutoModelForZeroShotObjectDetection:()=>fa,BartForConditionalGeneration:()=>Tt,BartForSequenceClassification:()=>kt,BartModel:()=>wt,BartPretrainedModel:()=>Mt,BaseModelOutput:()=>q,BeitForImageClassification:()=>fo,BeitModel:()=>mo,BeitPreTrainedModel:()=>_o,BertForMaskedLM:()=>G,BertForQuestionAnswering:()=>U,BertForSequenceClassification:()=>W,BertForTokenClassification:()=>$,BertModel:()=>R,BertPreTrainedModel:()=>j,BlenderbotForConditionalGeneration:()=>St,BlenderbotModel:()=>vt,BlenderbotPreTrainedModel:()=>Pt,BlenderbotSmallForConditionalGeneration:()=>Et,BlenderbotSmallModel:()=>Lt,BlenderbotSmallPreTrainedModel:()=>At,BloomForCausalLM:()=>Us,BloomModel:()=>$s,BloomPreTrainedModel:()=>Ws,CLIPModel:()=>rs,CLIPPreTrainedModel:()=>ns,CLIPSegForImageSegmentation:()=>fs,CLIPSegModel:()=>ms,CLIPSegPreTrainedModel:()=>_s,CLIPTextModelWithProjection:()=>as,CLIPVisionModelWithProjection:()=>is,CamembertForMaskedLM:()=>me,CamembertForQuestionAnswering:()=>Me,CamembertForSequenceClassification:()=>fe,CamembertForTokenClassification:()=>ge,CamembertModel:()=>_e,CamembertPreTrainedModel:()=>pe,CausalLMOutput:()=>za,CausalLMOutputWithPast:()=>Ba,ChineseCLIPModel:()=>ps,ChineseCLIPPreTrainedModel:()=>hs,ClapAudioModelWithProjection:()=>ur,ClapModel:()=>cr,ClapPreTrainedModel:()=>lr,ClapTextModelWithProjection:()=>dr,CodeGenForCausalLM:()=>Bs,CodeGenModel:()=>zs,CodeGenPreTrainedModel:()=>Es,ConvBertForMaskedLM:()=>oe,ConvBertForQuestionAnswering:()=>ae,ConvBertForSequenceClassification:()=>ne,ConvBertForTokenClassification:()=>re,ConvBertModel:()=>se,ConvBertPreTrainedModel:()=>te,ConvNextForImageClassification:()=>Jo,ConvNextModel:()=>Yo,ConvNextPreTrainedModel:()=>Ho,ConvNextV2ForImageClassification:()=>en,ConvNextV2Model:()=>Ko,ConvNextV2PreTrainedModel:()=>Zo,DPTForDepthEstimation:()=>jo,DPTModel:()=>qo,DPTPreTrainedModel:()=>Vo,DebertaForMaskedLM:()=>ke,DebertaForQuestionAnswering:()=>ye,DebertaForSequenceClassification:()=>be,DebertaForTokenClassification:()=>xe,DebertaModel:()=>Te,DebertaPreTrainedModel:()=>we,DebertaV2ForMaskedLM:()=>Pe,DebertaV2ForQuestionAnswering:()=>Ae,DebertaV2ForSequenceClassification:()=>ve,DebertaV2ForTokenClassification:()=>Se,DebertaV2Model:()=>Ce,DebertaV2PreTrainedModel:()=>Fe,DeiTForImageClassification:()=>So,DeiTModel:()=>vo,DeiTPreTrainedModel:()=>Po,DepthAnythingForDepthEstimation:()=>Go,DepthAnythingPreTrainedModel:()=>Ro,DetrForObjectDetection:()=>wo,DetrForSegmentation:()=>To,DetrModel:()=>Mo,DetrObjectDetectionOutput:()=>ko,DetrPreTrainedModel:()=>go,DetrSegmentationOutput:()=>bo,Dinov2ForImageClassification:()=>on,Dinov2Model:()=>sn,Dinov2PreTrainedModel:()=>tn,DistilBertForMaskedLM:()=>Oe,DistilBertForQuestionAnswering:()=>Ie,DistilBertForSequenceClassification:()=>ze,DistilBertForTokenClassification:()=>Be,DistilBertModel:()=>Ee,DistilBertPreTrainedModel:()=>Le,DonutSwinModel:()=>Qo,DonutSwinPreTrainedModel:()=>Xo,EfficientNetForImageClassification:()=>xr,EfficientNetModel:()=>br,EfficientNetPreTrainedModel:()=>kr,ElectraForMaskedLM:()=>ce,ElectraForQuestionAnswering:()=>he,ElectraForSequenceClassification:()=>de,ElectraForTokenClassification:()=>ue,ElectraModel:()=>le,ElectraPreTrainedModel:()=>ie,EsmForMaskedLM:()=>Ve,EsmForSequenceClassification:()=>qe,EsmForTokenClassification:()=>je,EsmModel:()=>Ne,EsmPreTrainedModel:()=>De,FalconForCausalLM:()=>ir,FalconModel:()=>ar,FalconPreTrainedModel:()=>rr,GLPNForDepthEstimation:()=>Uo,GLPNModel:()=>$o,GLPNPreTrainedModel:()=>Wo,GPT2LMHeadModel:()=>ws,GPT2Model:()=>Ms,GPT2PreTrainedModel:()=>gs,GPTBigCodeForCausalLM:()=>Ls,GPTBigCodeModel:()=>As,GPTBigCodePreTrainedModel:()=>Ss,GPTJForCausalLM:()=>vs,GPTJModel:()=>Ps,GPTJPreTrainedModel:()=>Cs,GPTNeoForCausalLM:()=>bs,GPTNeoModel:()=>ks,GPTNeoPreTrainedModel:()=>Ts,GPTNeoXForCausalLM:()=>Fs,GPTNeoXModel:()=>ys,GPTNeoXPreTrainedModel:()=>xs,HubertForCTC:()=>Nn,HubertForSequenceClassification:()=>Vn,HubertModel:()=>Dn,HubertPreTrainedModel:()=>On,ImageMattingOutput:()=>Ia,LlamaForCausalLM:()=>Ds,LlamaModel:()=>Os,LlamaPreTrainedModel:()=>Is,LongT5ForConditionalGeneration:()=>_t,LongT5Model:()=>pt,LongT5PreTrainedModel:()=>ht,M2M100ForConditionalGeneration:()=>gn,M2M100Model:()=>fn,M2M100PreTrainedModel:()=>mn,MBartForCausalLM:()=>Ct,MBartForConditionalGeneration:()=>yt,MBartForSequenceClassification:()=>Ft,MBartModel:()=>xt,MBartPreTrainedModel:()=>bt,MPNetForMaskedLM:()=>He,MPNetForQuestionAnswering:()=>Ze,MPNetForSequenceClassification:()=>Ye,MPNetForTokenClassification:()=>Je,MPNetModel:()=>Qe,MPNetPreTrainedModel:()=>Xe,MT5ForConditionalGeneration:()=>gt,MT5Model:()=>ft,MT5PreTrainedModel:()=>mt,MarianMTModel:()=>_n,MarianModel:()=>pn,MarianPreTrainedModel:()=>hn,MaskedLMOutput:()=>La,MistralForCausalLM:()=>tr,MistralModel:()=>er,MistralPreTrainedModel:()=>Kn,MobileBertForMaskedLM:()=>We,MobileBertForQuestionAnswering:()=>Ue,MobileBertForSequenceClassification:()=>$e,MobileBertModel:()=>Ge,MobileBertPreTrainedModel:()=>Re,MobileViTForImageClassification:()=>ao,MobileViTModel:()=>ro,MobileViTPreTrainedModel:()=>no,ModelOutput:()=>V,MptForCausalLM:()=>Hs,MptModel:()=>Qs,MptPreTrainedModel:()=>Xs,NomicBertModel:()=>Q,NomicBertPreTrainedModel:()=>X,OPTForCausalLM:()=>Zs,OPTModel:()=>Js,OPTPreTrainedModel:()=>Ys,OwlViTForObjectDetection:()=>co,OwlViTModel:()=>lo,OwlViTPreTrainedModel:()=>io,Owlv2ForObjectDetection:()=>po,Owlv2Model:()=>ho,Owlv2PreTrainedModel:()=>uo,PhiForCausalLM:()=>Gs,PhiModel:()=>Rs,PhiPreTrainedModel:()=>js,PreTrainedModel:()=>N,PretrainedMixin:()=>yr,QuestionAnsweringModelOutput:()=>Ea,Qwen2ForCausalLM:()=>qs,Qwen2Model:()=>Vs,Qwen2PreTrainedModel:()=>Ns,ResNetForImageClassification:()=>Eo,ResNetModel:()=>Lo,ResNetPreTrainedModel:()=>Ao,RoFormerForMaskedLM:()=>J,RoFormerForQuestionAnswering:()=>ee,RoFormerForSequenceClassification:()=>Z,RoFormerForTokenClassification:()=>K,RoFormerModel:()=>Y,RoFormerPreTrainedModel:()=>H,RobertaForMaskedLM:()=>It,RobertaForQuestionAnswering:()=>Nt,RobertaForSequenceClassification:()=>Ot,RobertaForTokenClassification:()=>Dt,RobertaModel:()=>Bt,RobertaPreTrainedModel:()=>zt,SamImageSegmentationOutput:()=>un,SamModel:()=>dn,SamPreTrainedModel:()=>cn,SegformerForImageClassification:()=>fr,SegformerForSemanticSegmentation:()=>gr,SegformerModel:()=>mr,SegformerPreTrainedModel:()=>_r,Seq2SeqLMOutput:()=>Pa,SequenceClassifierOutput:()=>va,SiglipModel:()=>cs,SiglipPreTrainedModel:()=>ls,SiglipTextModel:()=>ds,SiglipVisionModel:()=>us,SpeechT5ForSpeechToText:()=>Qn,SpeechT5ForTextToSpeech:()=>Hn,SpeechT5HifiGan:()=>Yn,SpeechT5Model:()=>Xn,SpeechT5PreTrainedModel:()=>Un,SqueezeBertForMaskedLM:()=>tt,SqueezeBertForQuestionAnswering:()=>ot,SqueezeBertForSequenceClassification:()=>st,SqueezeBertModel:()=>et,SqueezeBertPreTrainedModel:()=>Ke,StableLmForCausalLM:()=>Tr,StableLmModel:()=>wr,StableLmPreTrainedModel:()=>Mr,Starcoder2ForCausalLM:()=>nr,Starcoder2Model:()=>or,Starcoder2PreTrainedModel:()=>sr,Swin2SRForImageSuperResolution:()=>No,Swin2SRModel:()=>Do,Swin2SRPreTrainedModel:()=>Oo,SwinForImageClassification:()=>Io,SwinModel:()=>Bo,SwinPreTrainedModel:()=>zo,T5ForConditionalGeneration:()=>ut,T5Model:()=>dt,T5PreTrainedModel:()=>ct,TableTransformerForObjectDetection:()=>Fo,TableTransformerModel:()=>yo,TableTransformerObjectDetectionOutput:()=>Co,TableTransformerPreTrainedModel:()=>xo,TokenClassifierOutput:()=>Aa,TrOCRForCausalLM:()=>Zn,TrOCRPreTrainedModel:()=>Jn,UniSpeechForCTC:()=>Fn,UniSpeechForSequenceClassification:()=>Cn,UniSpeechModel:()=>yn,UniSpeechPreTrainedModel:()=>xn,UniSpeechSatForAudioFrameClassification:()=>Ln,UniSpeechSatForCTC:()=>Sn,UniSpeechSatForSequenceClassification:()=>An,UniSpeechSatModel:()=>vn,UniSpeechSatPreTrainedModel:()=>Pn,ViTForImageClassification:()=>to,ViTModel:()=>eo,ViTPreTrainedModel:()=>Ks,VisionEncoderDecoderModel:()=>os,VitMatteForImageMatting:()=>oo,VitMattePreTrainedModel:()=>so,VitsModel:()=>pr,VitsModelOutput:()=>Oa,VitsPreTrainedModel:()=>hr,Wav2Vec2BertForCTC:()=>Bn,Wav2Vec2BertForSequenceClassification:()=>In,Wav2Vec2BertModel:()=>zn,Wav2Vec2BertPreTrainedModel:()=>En,Wav2Vec2ForAudioFrameClassification:()=>bn,Wav2Vec2ForCTC:()=>Tn,Wav2Vec2ForSequenceClassification:()=>kn,Wav2Vec2Model:()=>wn,Wav2Vec2PreTrainedModel:()=>Mn,WavLMForAudioFrameClassification:()=>$n,WavLMForCTC:()=>Rn,WavLMForSequenceClassification:()=>Gn,WavLMForXVector:()=>Wn,WavLMModel:()=>jn,WavLMPreTrainedModel:()=>qn,WhisperForConditionalGeneration:()=>ss,WhisperModel:()=>ts,WhisperPreTrainedModel:()=>es,XLMForQuestionAnswering:()=>Wt,XLMForSequenceClassification:()=>Rt,XLMForTokenClassification:()=>Gt,XLMModel:()=>qt,XLMPreTrainedModel:()=>Vt,XLMRobertaForMaskedLM:()=>Xt,XLMRobertaForQuestionAnswering:()=>Yt,XLMRobertaForSequenceClassification:()=>Qt,XLMRobertaForTokenClassification:()=>Ht,XLMRobertaModel:()=>Ut,XLMRobertaPreTrainedModel:()=>$t,XLMWithLMHeadModel:()=>jt,XVectorOutput:()=>Sa,YolosForObjectDetection:()=>an,YolosModel:()=>rn,YolosObjectDetectionOutput:()=>ln,YolosPreTrainedModel:()=>nn});var o=s(/*! ./configs.js */"./src/configs.js"),n=s(/*! ./utils/core.js */"./src/utils/core.js"),r=s(/*! ./utils/hub.js */"./src/utils/hub.js"),a=s(/*! ./utils/generation.js */"./src/utils/generation.js"),i=s(/*! ./utils/tensor.js */"./src/utils/tensor.js"),l=s(/*! ./backends/onnx.js */"./src/backends/onnx.js"),c=s(/*! ./transformers.js */"./src/transformers.js");const{InferenceSession:d,Tensor:u,env:h}=l.ONNX,p=0,_=1,m=2,f=3,g=4,M=5,w=new Map,T=new Map,k=new Map;async function b(e,t,s){let o=`onnx/${t}${s.quantized?"_quantized":""}.onnx`,n=await(0,r.getModelFile)(e,o,!0,s);try{return await d.create(n,{executionProviders:l.executionProviders})}catch(e){if(1===l.executionProviders.length&&"wasm"===l.executionProviders[0])throw e;return console.warn(e),console.warn("Something went wrong during model construction (most likely a missing operation). Using `wasm` as a fallback. "),await d.create(n,{executionProviders:["wasm"]})}}async function x(e,t){const s=function(e,t){const s=Object.create(null),o=[];for(const n of e.inputNames){const e=t[n];e instanceof i.Tensor?s[n]=h.wasm.proxy?e.clone():e:o.push(n)}if(o.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${o.join(", ")}.`);const n=Object.keys(t).length,r=e.inputNames.length;if(n>r){let s=Object.keys(t).filter((t=>!e.inputNames.includes(t)));console.warn(`WARNING: Too many inputs were provided (${n} > ${r}). The following inputs will be ignored: "${s.join(", ")}".`)}return s}(e,t);try{let t=await e.run(s);return t=y(t),t}catch(e){throw console.error(`An error occurred during model execution: "${e}".`),console.error("Inputs given to model:",s),e}}function y(e){for(let t in e)e[t]instanceof u?e[t]=new i.Tensor(e[t]):"object"==typeof e[t]&&y(e[t]);return e}function F(e){if(e instanceof i.Tensor)return e;if(0===e.length)throw Error("items must be non-empty");if(Array.isArray(e[0])){if(e.some((t=>t.length!==e[0].length)))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new i.Tensor("int64",BigInt64Array.from(e.flat().map((e=>BigInt(e)))),[e.length,e[0].length])}return new i.Tensor("int64",BigInt64Array.from(e.map((e=>BigInt(e)))),[1,e.length])}function C(e,t){let s=e.config.pad_token_id??null,o=e.config.eos_token_id??null;(0,n.isIntegralNumber)(o)&&(o=[o]);let r=-1!==t.indexOf(s),a=null===o||!o.includes(s);if(r&&a){let e=BigInt64Array.from(t.data.map((e=>e!=s)));return new i.Tensor("int64",e,t.dims)}return(0,i.ones_like)(t)}function P(e,t,s){if(!e.inputNames.includes("position_ids"))return;const o=new BigInt64Array(t.attention_mask.data.length);for(let e=0;e0&&o.push(new a.NoRepeatNGramLogitsProcessor(e.no_repeat_ngram_size)),null!==e.bad_words_ids&&o.push(new a.NoBadWordsLogitsProcessor(e.bad_words_ids,e.eos_token_id)),null!==e.min_length&&null!==e.eos_token_id&&e.min_length>0&&o.push(new a.MinLengthLogitsProcessor(e.min_length,e.eos_token_id)),null!==e.min_new_tokens&&null!==e.eos_token_id&&e.min_new_tokens>0&&o.push(new a.MinNewTokensLengthLogitsProcessor(t,e.min_new_tokens,e.eos_token_id)),null!==e.forced_bos_token_id&&o.push(new a.ForcedBOSTokenLogitsProcessor(e.forced_bos_token_id)),null!==e.forced_eos_token_id&&o.push(new a.ForcedEOSTokenLogitsProcessor(e.max_length,e.forced_eos_token_id)),null!==e.begin_suppress_tokens){let s=t>1||null===e.forced_bos_token_id?t:t+1;null!==e.forced_decoder_ids&&(s+=e.forced_decoder_ids[e.forced_decoder_ids.length-1][0]),o.push(new a.SuppressTokensAtBeginLogitsProcessor(e.begin_suppress_tokens,s))}return null!==e.forced_decoder_ids&&o.push(new a.ForceTokensLogitsProcessor(e.forced_decoder_ids)),null!==s&&o.extend(s),o}_get_generation_config(e){let t=new a.GenerationConfig(this.config);return"generation_config"in this&&Object.assign(t,this.generation_config),null!==e&&Object.assign(t,e),t}async generate(e,t=null,s=null,{inputs_attention_mask:o=null}={}){if(!this.can_generate){let e=`The current model class (${k.get(this.constructor)}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;const t=this.config.model_type,s=Br.get(t)??zr.get(t)??vr.get(t)??Dr.get(t);throw s&&(e+=` Please use the following class instead: '${s[0]}'`),Error(e)}if(!(e instanceof i.Tensor||(0,n.isTypedArray)(e)||Array.isArray(e)))throw Error(`\`inputs\` must be a Tensor, TypedArray, or Array, but is "${e.constructor.name}".`);let r;if(this.config.is_encoder_decoder)r=0;else if(r=e instanceof i.Tensor?e.dims.at(-1):e.length,0===r)throw Error("Must supply a non-empty array of input token ids.");t=this._get_generation_config(t),s=s??new a.LogitsProcessorList,s=this._get_logits_processor(t,r,s);let l=t.eos_token_id;null===l||Array.isArray(l)||(l=[l]);let c=1;const d=c+(t.max_new_tokens??1/0),u=Number.isInteger(t.max_length)&&null===(t.max_new_tokens??null);let h=a.Sampler.getSampler(t),p=this.getStartBeams(e,t,c,o);for(;p.some((e=>!e.done))&&c=t.max_length){o.done=!0,e.push(o);continue}let n=await this.runBeam(o);t.output_attentions&&this.addAttentionsToBeam(o,n),t.output_scores;let r=n.logits.slice(null,-1,null);s(o.output_token_ids,r);let a=h(r);for(let[t,s]of a){let n={...o};this.updateBeam(n,t),n.score+=s,l&&l.includes(t)&&(n.done=!0),e.push(n)}}++c,e=this.groupBeams(e).map((e=>e.sort(((e,t)=>t.score-e.score)).slice(0,t.num_beams))),p=e.flat(),t.callback_function&&t.callback_function(p)}const _=this.groupBeams(p),m=e=>_.map((s=>t.num_return_sequences>1?s.slice(0,t.num_return_sequences).map((t=>t[e])):[s[0][e]])).flat(),f=m("output_token_ids");if(t.return_dict_in_generate){return{sequences:f,decoder_attentions:m("decoder_attentions"),cross_attentions:m("cross_attentions")}}return f}addAttentionsToBeam(e,t){if(this.config.is_encoder_decoder){if(!t.cross_attentions||0===t.cross_attentions.length)throw Error("`output_attentions` is true, but the model did not produce cross-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.cross_attentions||(e.cross_attentions=[]),e.cross_attentions.push(t.cross_attentions)}if(!t.decoder_attentions||0===t.decoder_attentions.length)throw Error("`output_attentions` is true, but the model did not produce decoder-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.decoder_attentions||(e.decoder_attentions=[]),e.decoder_attentions.push(t.decoder_attentions)}groupBeams(e){const t=Object.create(null);for(const s of e)void 0===t[s.id]?t[s.id]=[s]:t[s.id].push(s);return Object.values(t)}getPastKeyValues(e,t){const s=Object.create(null);for(const o in e)if(o.startsWith("present")){let n=o.replace("present","past_key_values");t&&o.includes("encoder")?s[n]=t[n]:s[n]=e[o]}return s}getAttentions(e){const t=Object.create(null);for(const s of["cross_attentions","decoder_attentions"]){const o=[];for(const t in e)if(t.startsWith(s)){o[t.split(".").pop()]=e[t]}t[s]=o}return t}addPastKeyValues(e,t){if(t)Object.assign(e,t);else{const t=1;if(this.config.is_encoder_decoder&&(this.add_encoder_pkv??1)){let s=[t,this.num_encoder_heads,0,this.encoder_dim_kv],o=[t,this.num_decoder_heads,0,this.decoder_dim_kv];for(let t=0;t{let o=Array.from({length:this.config.decoder_layers},((t,s)=>(0,i.cat)(e.map((e=>e[s])),2))),n=(0,i.stack)(t.map((([e,t])=>s?o[e].slice(null,t,null,[0,s]):o[e].slice(null,t))));n=n.transpose(1,0,2,3);let[a,l]=(0,i.std_mean)(n,-2,0,!0),d=n.clone();for(let e=0;es[t+1]-s[t])),c=(0,n.mergeArrays)([1],l).map((e=>!!e)),u=[];for(let e=0;ee*t),1);e.input_labels=new i.Tensor("int64",new BigInt64Array(s).fill(1n),t)}return await x(this.prompt_encoder_mask_decoder,{input_points:e.input_points,input_labels:e.input_labels,image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings})}async _call(e){return new un(await super._call(e))}}class un extends V{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class hn extends N{}class pn extends hn{}class _n extends hn{constructor(e,t,s,o){super(e,t),this.decoder_merged_session=s,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}}class mn extends N{}class fn extends mn{}class gn extends mn{constructor(e,t,s,o){super(e,t),this.decoder_merged_session=s,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}}class Mn extends N{}class wn extends Mn{}class Tn extends Mn{async _call(e){return new za(await super._call(e))}}class kn extends Mn{async _call(e){return new va(await super._call(e))}}class bn extends Mn{async _call(e){return new Aa(await super._call(e))}}class xn extends N{}class yn extends xn{}class Fn extends xn{async _call(e){return new za(await super._call(e))}}class Cn extends xn{async _call(e){return new va(await super._call(e))}}class Pn extends N{}class vn extends Pn{}class Sn extends Pn{async _call(e){return new za(await super._call(e))}}class An extends Pn{async _call(e){return new va(await super._call(e))}}class Ln extends Pn{async _call(e){return new Aa(await super._call(e))}}class En extends N{}class zn extends En{}class Bn extends En{async _call(e){return new za(await super._call(e))}}class In extends En{async _call(e){return new va(await super._call(e))}}class On extends N{}class Dn extends Mn{}class Nn extends Mn{async _call(e){return new za(await super._call(e))}}class Vn extends Mn{async _call(e){return new va(await super._call(e))}}class qn extends N{}class jn extends qn{}class Rn extends qn{async _call(e){return new za(await super._call(e))}}class Gn extends qn{async _call(e){return new va(await super._call(e))}}class Wn extends qn{async _call(e){return new Sa(await super._call(e))}}class $n extends qn{async _call(e){return new Aa(await super._call(e))}}class Un extends N{}class Xn extends Un{}class Qn extends Un{}class Hn extends Un{constructor(e,t,s,o){super(e,t),this.decoder_merged_session=s,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.hidden_size/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.hidden_size/this.num_encoder_heads}async generate_speech(e,t,{threshold:s=.5,minlenratio:o=0,maxlenratio:n=20,vocoder:r=null}={}){const a={input_ids:e},{encoder_outputs:l,encoder_attention_mask:c}=await z(this,a),d=l.dims[1]/this.config.reduction_factor,u=Math.floor(d*n),h=Math.floor(d*o),p=this.config.num_mel_bins;let _=[],m=null,f=null,g=0;for(;;){++g;const e=v(!!f);let o;o=f?f.output_sequence_out:new i.Tensor("float32",new Float32Array(p),[1,1,p]);let n={use_cache_branch:e,output_sequence:o,encoder_attention_mask:c,speaker_embeddings:t,encoder_hidden_states:l};this.addPastKeyValues(n,m),f=await x(this.decoder_merged_session,n),m=this.getPastKeyValues(f,m);const{prob:r,spectrum:a}=f;if(_.push(a),g>=h&&(Array.from(r.data).filter((e=>e>=s)).length>0||g>=u))break}const M=(0,i.cat)(_),{waveform:w}=await x(r.session,{spectrogram:M});return{spectrogram:M,waveform:w}}}class Yn extends N{main_input_name="spectrogram"}class Jn extends N{constructor(e,t,s){super(e,t),this.generation_config=s,this.config.pad_token_id=this.config.eos_token_id,this.num_encoder_layers=this.num_decoder_layers=this.config.decoder_layers,this.num_encoder_heads=this.num_decoder_heads=this.config.decoder_attention_heads,this.encoder_dim_kv=this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads}}class Zn extends Jn{}class Kn extends N{constructor(e,t,s){super(e,t),this.generation_config=s,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_key_value_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.config.num_attention_heads}}class er extends Kn{}class tr extends Kn{}class sr extends N{constructor(e,t,s){super(e,t),this.generation_config=s,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_key_value_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.config.num_attention_heads}}class or extends sr{}class nr extends sr{}class rr extends N{constructor(e,t,s){super(e,t),this.generation_config=s,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_attention_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.config.num_attention_heads}}class ar extends rr{}class ir extends rr{}class lr extends N{}class cr extends lr{}class dr extends lr{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class ur extends lr{static async from_pretrained(e,t={}){return t.model_file_name??="audio_model",super.from_pretrained(e,t)}}class hr extends N{}class pr extends hr{async _call(e){return new Oa(await super._call(e))}}class _r extends N{}class mr extends _r{}class fr extends _r{}class gr extends _r{}class Mr extends N{constructor(e,t,s){super(e,t),this.generation_config=s,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_attention_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.num_heads}}class wr extends Mr{}class Tr extends Mr{}class kr extends N{}class br extends kr{}class xr extends kr{async _call(e){return new va(await super._call(e))}}class yr{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{quantized:t=!0,progress_callback:s=null,config:n=null,cache_dir:r=null,local_files_only:a=!1,revision:i="main",model_file_name:l=null}={}){let c={quantized:t,progress_callback:s,config:n,cache_dir:r,local_files_only:a,revision:i,model_file_name:l};if(n=await o.AutoConfig.from_pretrained(e,c),c.config||(c.config=n),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);for(let t of this.MODEL_CLASS_MAPPINGS){const s=t.get(n.model_type);if(s)return await s[1].from_pretrained(e,c)}if(this.BASE_IF_FAIL)return console.warn(`Unknown model class "${n.model_type}", attempting to construct from base class.`),await N.from_pretrained(e,c);throw Error(`Unsupported model type: ${n.model_type}`)}}const Fr=new Map([["bert",["BertModel",R]],["nomic_bert",["NomicBertModel",Q]],["roformer",["RoFormerModel",Y]],["electra",["ElectraModel",le]],["esm",["EsmModel",Ne]],["convbert",["ConvBertModel",se]],["camembert",["CamembertModel",_e]],["deberta",["DebertaModel",Te]],["deberta-v2",["DebertaV2Model",Ce]],["mpnet",["MPNetModel",Qe]],["albert",["AlbertModel",rt]],["distilbert",["DistilBertModel",Ee]],["roberta",["RobertaModel",Bt]],["xlm",["XLMModel",qt]],["xlm-roberta",["XLMRobertaModel",Ut]],["clap",["ClapModel",cr]],["clip",["CLIPModel",rs]],["clipseg",["CLIPSegModel",ms]],["chinese_clip",["ChineseCLIPModel",ps]],["siglip",["SiglipModel",cs]],["mobilebert",["MobileBertModel",Ge]],["squeezebert",["SqueezeBertModel",et]],["wav2vec2",["Wav2Vec2Model",wn]],["wav2vec2-bert",["Wav2Vec2BertModel",zn]],["unispeech",["UniSpeechModel",yn]],["unispeech-sat",["UniSpeechSatModel",vn]],["hubert",["HubertModel",Dn]],["wavlm",["WavLMModel",jn]],["audio-spectrogram-transformer",["ASTModel",Zt]],["vits",["VitsModel",pr]],["detr",["DetrModel",Mo]],["table-transformer",["TableTransformerModel",yo]],["vit",["ViTModel",eo]],["mobilevit",["MobileViTModel",ro]],["owlvit",["OwlViTModel",lo]],["owlv2",["Owlv2Model",ho]],["beit",["BeitModel",mo]],["deit",["DeiTModel",vo]],["convnext",["ConvNextModel",Yo]],["convnextv2",["ConvNextV2Model",Ko]],["dinov2",["Dinov2Model",sn]],["resnet",["ResNetModel",Lo]],["swin",["SwinModel",Bo]],["swin2sr",["Swin2SRModel",Do]],["donut-swin",["DonutSwinModel",Qo]],["yolos",["YolosModel",rn]],["dpt",["DPTModel",qo]],["glpn",["GLPNModel",$o]],["hifigan",["SpeechT5HifiGan",Yn]],["efficientnet",["EfficientNetModel",br]]]),Cr=new Map([["t5",["T5Model",dt]],["longt5",["LongT5Model",pt]],["mt5",["MT5Model",ft]],["bart",["BartModel",wt]],["mbart",["MBartModel",xt]],["marian",["MarianModel",pn]],["whisper",["WhisperModel",ts]],["m2m_100",["M2M100Model",fn]],["blenderbot",["BlenderbotModel",vt]],["blenderbot-small",["BlenderbotSmallModel",Lt]]]),Pr=new Map([["bloom",["BloomModel",$s]],["gpt2",["GPT2Model",Ms]],["gptj",["GPTJModel",Ps]],["gpt_bigcode",["GPTBigCodeModel",As]],["gpt_neo",["GPTNeoModel",ks]],["gpt_neox",["GPTNeoXModel",ys]],["codegen",["CodeGenModel",zs]],["llama",["LlamaModel",Os]],["qwen2",["Qwen2Model",Vs]],["phi",["PhiModel",Rs]],["mpt",["MptModel",Qs]],["opt",["OPTModel",Js]],["mistral",["MistralModel",er]],["starcoder2",["Starcoder2Model",or]],["falcon",["FalconModel",ar]]]),vr=new Map([["speecht5",["SpeechT5ForSpeechToText",Qn]],["whisper",["WhisperForConditionalGeneration",ss]]]),Sr=new Map([["speecht5",["SpeechT5ForTextToSpeech",Hn]]]),Ar=new Map([["vits",["VitsModel",pr]]]),Lr=new Map([["bert",["BertForSequenceClassification",W]],["roformer",["RoFormerForSequenceClassification",Z]],["electra",["ElectraForSequenceClassification",de]],["esm",["EsmForSequenceClassification",qe]],["convbert",["ConvBertForSequenceClassification",ne]],["camembert",["CamembertForSequenceClassification",fe]],["deberta",["DebertaForSequenceClassification",be]],["deberta-v2",["DebertaV2ForSequenceClassification",ve]],["mpnet",["MPNetForSequenceClassification",Ye]],["albert",["AlbertForSequenceClassification",at]],["distilbert",["DistilBertForSequenceClassification",ze]],["roberta",["RobertaForSequenceClassification",Ot]],["xlm",["XLMForSequenceClassification",Rt]],["xlm-roberta",["XLMRobertaForSequenceClassification",Qt]],["bart",["BartForSequenceClassification",kt]],["mbart",["MBartForSequenceClassification",Ft]],["mobilebert",["MobileBertForSequenceClassification",$e]],["squeezebert",["SqueezeBertForSequenceClassification",st]]]),Er=new Map([["bert",["BertForTokenClassification",$]],["roformer",["RoFormerForTokenClassification",K]],["electra",["ElectraForTokenClassification",ue]],["esm",["EsmForTokenClassification",je]],["convbert",["ConvBertForTokenClassification",re]],["camembert",["CamembertForTokenClassification",ge]],["deberta",["DebertaForTokenClassification",xe]],["deberta-v2",["DebertaV2ForTokenClassification",Se]],["mpnet",["MPNetForTokenClassification",Je]],["distilbert",["DistilBertForTokenClassification",Be]],["roberta",["RobertaForTokenClassification",Dt]],["xlm",["XLMForTokenClassification",Gt]],["xlm-roberta",["XLMRobertaForTokenClassification",Ht]]]),zr=new Map([["t5",["T5ForConditionalGeneration",ut]],["longt5",["LongT5ForConditionalGeneration",_t]],["mt5",["MT5ForConditionalGeneration",gt]],["bart",["BartForConditionalGeneration",Tt]],["mbart",["MBartForConditionalGeneration",yt]],["marian",["MarianMTModel",_n]],["m2m_100",["M2M100ForConditionalGeneration",gn]],["blenderbot",["BlenderbotForConditionalGeneration",St]],["blenderbot-small",["BlenderbotSmallForConditionalGeneration",Et]]]),Br=new Map([["bloom",["BloomForCausalLM",Us]],["gpt2",["GPT2LMHeadModel",ws]],["gptj",["GPTJForCausalLM",vs]],["gpt_bigcode",["GPTBigCodeForCausalLM",Ls]],["gpt_neo",["GPTNeoForCausalLM",bs]],["gpt_neox",["GPTNeoXForCausalLM",Fs]],["codegen",["CodeGenForCausalLM",Bs]],["llama",["LlamaForCausalLM",Ds]],["qwen2",["Qwen2ForCausalLM",qs]],["phi",["PhiForCausalLM",Gs]],["mpt",["MptForCausalLM",Hs]],["opt",["OPTForCausalLM",Zs]],["mbart",["MBartForCausalLM",Ct]],["mistral",["MistralForCausalLM",tr]],["starcoder2",["Starcoder2ForCausalLM",nr]],["falcon",["FalconForCausalLM",ir]],["trocr",["TrOCRForCausalLM",Zn]],["stablelm",["StableLmForCausalLM",Tr]]]),Ir=new Map([["bert",["BertForMaskedLM",G]],["roformer",["RoFormerForMaskedLM",J]],["electra",["ElectraForMaskedLM",ce]],["esm",["EsmForMaskedLM",Ve]],["convbert",["ConvBertForMaskedLM",oe]],["camembert",["CamembertForMaskedLM",me]],["deberta",["DebertaForMaskedLM",ke]],["deberta-v2",["DebertaV2ForMaskedLM",Pe]],["mpnet",["MPNetForMaskedLM",He]],["albert",["AlbertForMaskedLM",lt]],["distilbert",["DistilBertForMaskedLM",Oe]],["roberta",["RobertaForMaskedLM",It]],["xlm",["XLMWithLMHeadModel",jt]],["xlm-roberta",["XLMRobertaForMaskedLM",Xt]],["mobilebert",["MobileBertForMaskedLM",We]],["squeezebert",["SqueezeBertForMaskedLM",tt]]]),Or=new Map([["bert",["BertForQuestionAnswering",U]],["roformer",["RoFormerForQuestionAnswering",ee]],["electra",["ElectraForQuestionAnswering",he]],["convbert",["ConvBertForQuestionAnswering",ae]],["camembert",["CamembertForQuestionAnswering",Me]],["deberta",["DebertaForQuestionAnswering",ye]],["deberta-v2",["DebertaV2ForQuestionAnswering",Ae]],["mpnet",["MPNetForQuestionAnswering",Ze]],["albert",["AlbertForQuestionAnswering",it]],["distilbert",["DistilBertForQuestionAnswering",Ie]],["roberta",["RobertaForQuestionAnswering",Nt]],["xlm",["XLMForQuestionAnswering",Wt]],["xlm-roberta",["XLMRobertaForQuestionAnswering",Yt]],["mobilebert",["MobileBertForQuestionAnswering",Ue]],["squeezebert",["SqueezeBertForQuestionAnswering",ot]]]),Dr=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",os]]]),Nr=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",os]]]),Vr=new Map([["vit",["ViTForImageClassification",to]],["mobilevit",["MobileViTForImageClassification",ao]],["beit",["BeitForImageClassification",fo]],["deit",["DeiTForImageClassification",So]],["convnext",["ConvNextForImageClassification",Jo]],["convnextv2",["ConvNextV2ForImageClassification",en]],["dinov2",["Dinov2ForImageClassification",on]],["resnet",["ResNetForImageClassification",Eo]],["swin",["SwinForImageClassification",Io]],["segformer",["SegformerForImageClassification",fr]],["efficientnet",["EfficientNetForImageClassification",xr]]]),qr=new Map([["detr",["DetrForObjectDetection",wo]],["table-transformer",["TableTransformerForObjectDetection",Fo]],["yolos",["YolosForObjectDetection",an]]]),jr=new Map([["owlvit",["OwlViTForObjectDetection",co]],["owlv2",["Owlv2ForObjectDetection",po]]]),Rr=new Map([["detr",["DetrForSegmentation",To]],["clipseg",["CLIPSegForImageSegmentation",fs]]]),Gr=new Map([["segformer",["SegformerForSemanticSegmentation",gr]]]),Wr=new Map([["sam",["SamModel",dn]]]),$r=new Map([["wav2vec2",["Wav2Vec2ForCTC",Tn]],["wav2vec2-bert",["Wav2Vec2BertForCTC",Bn]],["unispeech",["UniSpeechForCTC",Fn]],["unispeech-sat",["UniSpeechSatForCTC",Sn]],["wavlm",["WavLMForCTC",Rn]],["hubert",["HubertForCTC",Nn]]]),Ur=new Map([["wav2vec2",["Wav2Vec2ForSequenceClassification",kn]],["wav2vec2-bert",["Wav2Vec2BertForSequenceClassification",In]],["unispeech",["UniSpeechForSequenceClassification",Cn]],["unispeech-sat",["UniSpeechSatForSequenceClassification",An]],["wavlm",["WavLMForSequenceClassification",Gn]],["hubert",["HubertForSequenceClassification",Vn]],["audio-spectrogram-transformer",["ASTForAudioClassification",Kt]]]),Xr=new Map([["wavlm",["WavLMForXVector",Wn]]]),Qr=new Map([["unispeech-sat",["UniSpeechSatForAudioFrameClassification",Ln]],["wavlm",["WavLMForAudioFrameClassification",$n]],["wav2vec2",["Wav2Vec2ForAudioFrameClassification",bn]]]),Hr=new Map([["vitmatte",["VitMatteForImageMatting",oo]]]),Yr=new Map([["swin2sr",["Swin2SRForImageSuperResolution",No]]]),Jr=new Map([["dpt",["DPTForDepthEstimation",jo]],["depth_anything",["DepthAnythingForDepthEstimation",Go]],["glpn",["GLPNForDepthEstimation",Uo]]]),Zr=new Map([["clip",["CLIPVisionModelWithProjection",is]],["siglip",["SiglipVisionModel",us]]]),Kr=[[Fr,p],[Cr,_],[Pr,g],[Lr,p],[Er,p],[zr,m],[vr,m],[Br,g],[Ir,p],[Or,p],[Dr,f],[Vr,p],[Rr,p],[Gr,p],[Hr,p],[Yr,p],[Jr,p],[qr,p],[jr,p],[Wr,M],[$r,p],[Ur,p],[Sr,m],[Ar,p],[Xr,p],[Qr,p],[Zr,p]];for(const[e,t]of Kr)for(const[s,o]of e.values())w.set(s,t),k.set(o,s),T.set(s,o);const ea=[["CLIPTextModelWithProjection",as,p],["SiglipTextModel",ds,p],["ClapTextModelWithProjection",dr,p],["ClapAudioModelWithProjection",ur,p]];for(const[e,t,s]of ea)w.set(e,s),k.set(t,e),T.set(e,t);class ta extends yr{static MODEL_CLASS_MAPPINGS=Kr.map((e=>e[0]));static BASE_IF_FAIL=!0}class sa extends yr{static MODEL_CLASS_MAPPINGS=[Lr]}class oa extends yr{static MODEL_CLASS_MAPPINGS=[Er]}class na extends yr{static MODEL_CLASS_MAPPINGS=[zr]}class ra extends yr{static MODEL_CLASS_MAPPINGS=[vr]}class aa extends yr{static MODEL_CLASS_MAPPINGS=[Sr]}class ia extends yr{static MODEL_CLASS_MAPPINGS=[Ar]}class la extends yr{static MODEL_CLASS_MAPPINGS=[Br]}class ca extends yr{static MODEL_CLASS_MAPPINGS=[Ir]}class da extends yr{static MODEL_CLASS_MAPPINGS=[Or]}class ua extends yr{static MODEL_CLASS_MAPPINGS=[Dr]}class ha extends yr{static MODEL_CLASS_MAPPINGS=[Vr]}class pa extends yr{static MODEL_CLASS_MAPPINGS=[Rr]}class _a extends yr{static MODEL_CLASS_MAPPINGS=[Gr]}class ma extends yr{static MODEL_CLASS_MAPPINGS=[qr]}class fa extends yr{static MODEL_CLASS_MAPPINGS=[jr]}class ga extends yr{static MODEL_CLASS_MAPPINGS=[Wr]}class Ma extends yr{static MODEL_CLASS_MAPPINGS=[$r]}class wa extends yr{static MODEL_CLASS_MAPPINGS=[Ur]}class Ta extends yr{static MODEL_CLASS_MAPPINGS=[Xr]}class ka extends yr{static MODEL_CLASS_MAPPINGS=[Qr]}class ba extends yr{static MODEL_CLASS_MAPPINGS=[Nr]}class xa extends yr{static MODEL_CLASS_MAPPINGS=[Hr]}class ya extends yr{static MODEL_CLASS_MAPPINGS=[Yr]}class Fa extends yr{static MODEL_CLASS_MAPPINGS=[Jr]}class Ca extends yr{static MODEL_CLASS_MAPPINGS=[Zr]}class Pa extends V{constructor({logits:e,past_key_values:t,encoder_outputs:s,decoder_attentions:o=null,cross_attentions:n=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=s,this.decoder_attentions=o,this.cross_attentions=n}}class va extends V{constructor({logits:e}){super(),this.logits=e}}class Sa extends V{constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}}class Aa extends V{constructor({logits:e}){super(),this.logits=e}}class La extends V{constructor({logits:e}){super(),this.logits=e}}class Ea extends V{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}class za extends V{constructor({logits:e}){super(),this.logits=e}}class Ba extends V{constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}}class Ia extends V{constructor({alphas:e}){super(),this.alphas=e}}class Oa extends V{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}}},"./src/pipelines.js": +/*!**************************!*\ + !*** ./src/pipelines.js ***! + \**************************/(e,t,s)=>{s.r(t),s.d(t,{AudioClassificationPipeline:()=>C,AutomaticSpeechRecognitionPipeline:()=>v,DepthEstimationPipeline:()=>N,DocumentQuestionAnsweringPipeline:()=>I,FeatureExtractionPipeline:()=>y,FillMaskPipeline:()=>M,ImageClassificationPipeline:()=>A,ImageFeatureExtractionPipeline:()=>F,ImageSegmentationPipeline:()=>L,ImageToImagePipeline:()=>D,ImageToTextPipeline:()=>S,ObjectDetectionPipeline:()=>z,Pipeline:()=>_,QuestionAnsweringPipeline:()=>g,SummarizationPipeline:()=>T,Text2TextGenerationPipeline:()=>w,TextClassificationPipeline:()=>m,TextGenerationPipeline:()=>b,TextToAudioPipeline:()=>O,TokenClassificationPipeline:()=>f,TranslationPipeline:()=>k,ZeroShotAudioClassificationPipeline:()=>P,ZeroShotClassificationPipeline:()=>x,ZeroShotImageClassificationPipeline:()=>E,ZeroShotObjectDetectionPipeline:()=>B,pipeline:()=>j});var o=s(/*! ./tokenizers.js */"./src/tokenizers.js"),n=s(/*! ./models.js */"./src/models.js"),r=s(/*! ./processors.js */"./src/processors.js"),a=s(/*! ./utils/core.js */"./src/utils/core.js"),i=s(/*! ./utils/maths.js */"./src/utils/maths.js"),l=s(/*! ./utils/audio.js */"./src/utils/audio.js"),c=s(/*! ./utils/tensor.js */"./src/utils/tensor.js"),d=s(/*! ./utils/image.js */"./src/utils/image.js");async function u(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>d.RawImage.read(e))))}async function h(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>"string"==typeof e||e instanceof URL?(0,l.read_audio)(e,t):e instanceof Float64Array?new Float32Array(e):e)))}function p(e,t){t&&(e=e.map((e=>0|e)));const[s,o,n,r]=e;return{xmin:s,ymin:o,xmax:n,ymax:r}}class _ extends a.Callable{constructor({task:e,model:t,tokenizer:s=null,processor:o=null}){super(),this.task=e,this.model=t,this.tokenizer=s,this.processor=o}async dispose(){await this.model.dispose()}}class m extends _{constructor(e){super(e)}async _call(e,{topk:t=1}={}){const s=this.tokenizer(e,{padding:!0,truncation:!0}),o=await this.model(s),n="multi_label_classification"===this.model.config.problem_type?e=>e.sigmoid().data:e=>(0,i.softmax)(e.data),r=this.model.config.id2label,a=[];for(const e of o.logits){const s=n(e),o=(0,i.getTopItems)(s,t).map((e=>({label:r[e[0]],score:e[1]})));1===t?a.push(...o):a.push(o)}return Array.isArray(e)||1===t?a:a[0]}}class f extends _{constructor(e){super(e)}async _call(e,{ignore_labels:t=["O"]}={}){const s=Array.isArray(e),o=this.tokenizer(s?e:[e],{padding:!0,truncation:!0}),n=(await this.model(o)).logits,r=this.model.config.id2label,a=[];for(let e=0;e[e,t])).filter((e=>e[1]>l)),d=Array.from((0,i.softmax)(n.end_logits[e].data)).map(((e,t)=>[e,t])).filter((e=>e[1]>l)),u=(0,a.product)(c,d).filter((e=>e[0][1]<=e[1][1])).map((e=>[e[0][1],e[1][1],e[0][0]*e[1][0]])).sort(((e,t)=>t[2]-e[2]));for(let e=0;e{const t=[...r];return t[a]=e[0],{score:e[1],token:e[0],token_str:this.tokenizer.model.vocab[e[0]],sequence:this.tokenizer.decode(t,{skip_special_tokens:!0})}})))}return Array.isArray(e)?n:n[0]}}class w extends _{_key="generated_text";constructor(e){super(e)}async _call(e,t={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map((e=>this.model.config.prefix+e)));const s=this.model.config.task_specific_params;s&&s[this.task]&&s[this.task].prefix&&(e=e.map((e=>s[this.task].prefix+e)));const o=this.tokenizer,n={padding:!0,truncation:!0};let r;r=this instanceof k&&"_build_translation_inputs"in o?o._build_translation_inputs(e,n,t).input_ids:o(e,n).input_ids;const a=await this.model.generate(r,t);return o.batch_decode(a,{skip_special_tokens:!0}).map((e=>({[this._key]:e})))}}class T extends w{_key="summary_text";constructor(e){super(e)}}class k extends w{_key="translation_text";constructor(e){super(e)}}class b extends _{constructor(e){super(e)}async _call(e,t={}){const s=Array.isArray(e);s||(e=[e]);const o=t.add_special_tokens??!1;this.tokenizer.padding_side="left";const{input_ids:n,attention_mask:r}=this.tokenizer(e,{add_special_tokens:o,padding:!0,truncation:!0}),a=await this.model.generate(n,t,null,{inputs_attention_mask:r}),i=this.tokenizer.batch_decode(a,{skip_special_tokens:!0}),l=Array.from({length:e.length},(e=>[]));for(let t=0;t[e.toLowerCase(),t]))),this.entailment_id=this.label2id.entailment,void 0===this.entailment_id&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,void 0===this.contradiction_id&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:s="This example is {}.",multi_label:o=!1}={}){const n=Array.isArray(e);n||(e=[e]),Array.isArray(t)||(t=[t]);const r=t.map((e=>s.replace("{}",e))),a=o||1===t.length,l=[];for(const s of e){const e=[];for(const t of r){const o=this.tokenizer(s,{text_pair:t,padding:!0,truncation:!0}),n=await this.model(o);a?e.push([n.logits.data[this.contradiction_id],n.logits.data[this.entailment_id]]):e.push(n.logits.data[this.entailment_id])}const o=(a?e.map((e=>(0,i.softmax)(e)[1])):(0,i.softmax)(e)).map(((e,t)=>[e,t])).sort(((e,t)=>t[0]-e[0]));l.push({sequence:s,labels:o.map((e=>t[e[1]])),scores:o.map((e=>e[0]))})}return n?l:l[0]}}class y extends _{constructor(e){super(e)}async _call(e,{pooling:t="none",normalize:s=!1}={}){const o=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(o);let r=n.last_hidden_state??n.logits;if("none"===t);else if("mean"===t)r=(0,c.mean_pooling)(r,o.attention_mask);else{if("cls"!==t)throw Error(`Pooling method '${t}' not supported.`);r=r.slice(null,0)}return s&&(r=r.normalize(2,-1)),r}}class F extends _{constructor(e){super(e)}async _call(e,{pool:t=null}={}){const s=await u(e),{pixel_values:o}=await this.processor(s),n=await this.model({pixel_values:o});let r;if(t){if(!("pooler_output"in n))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");r=n.pooler_output}else r=n.last_hidden_state??n.logits??n.image_embeds;return r}}class C extends _{constructor(e){super(e)}async _call(e,{topk:t=null}={}){const s=!Array.isArray(e),o=this.processor.feature_extractor.config.sampling_rate,n=await h(e,o),r=this.model.config.id2label,a=[];for(const e of n){const s=await this.processor(e),o=(await this.model(s)).logits[0],n=(0,i.getTopItems)((0,i.softmax)(o.data),t).map((e=>({label:r[e[0]],score:e[1]})));1===t?a.push(...n):a.push(n)}return s&&1!==t?a[0]:a}}class P extends _{constructor(e){super(e)}async _call(e,t,{hypothesis_template:s="This is a sound of {}."}={}){const o=!Array.isArray(e);o&&(e=[e]);const n=t.map((e=>s.replace("{}",e))),r=this.tokenizer(n,{padding:!0,truncation:!0}),a=this.processor.feature_extractor.config.sampling_rate,l=await h(e,a),c=[];for(const e of l){const s=await this.processor(e),o=await this.model({...r,...s}),n=(0,i.softmax)(o.logits_per_audio.data);c.push([...n].map(((e,s)=>({score:e,label:t[s]}))))}return o?c[0]:c}}class v extends _{constructor(e){super(e)}async _call(e,t={}){switch(this.model.config.model_type){case"whisper":return this._call_whisper(e,t);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":return this._call_wav2vec2(e,t);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,t={}){t.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),t.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const s=!Array.isArray(e);s&&(e=[e]);const o=this.processor.feature_extractor.config.sampling_rate,n=await h(e,o),r=[];for(const e of n){const t=await this.processor(e),s=(await this.model(t)).logits[0],o=[];for(const e of s)o.push((0,i.max)(e.data)[1]);const n=this.tokenizer.decode(o);r.push({text:n})}return s?r[0]:r}async _call_whisper(e,t={}){const s=t.return_timestamps??!1,o=t.chunk_length_s??0,n=t.chunk_callback??null,r=t.force_full_sequences??!1;let l=t.stride_length_s??null;"word"===s&&(t.return_token_timestamps=!0);const c=(0,a.pop)(t,"language",null),d=(0,a.pop)(t,"task",null);if(c||d||s){if(t.forced_decoder_ids)throw new Error("Cannot specify `language`/`task`/`return_timestamps` and `forced_decoder_ids` at the same time.");const e=this.tokenizer.get_decoder_prompt_ids({language:c,task:d,no_timestamps:!s});e.length>0&&(t.forced_decoder_ids=e)}const u=!Array.isArray(e);u&&(e=[e]);const p=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,_=this.processor.feature_extractor.config.hop_length,m=this.processor.feature_extractor.config.sampling_rate,f=await h(e,m),g=[];for(const e of f){let a=[];if(o>0){if(null===l)l=o/6;else if(o<=l)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const t=m*o,s=m*l,n=t-2*s;let r=0;for(;r=e.length;a.push({stride:[o.length,l?0:s,c?0:s],input_features:i.input_features,is_last:c}),r+=n}}else a=[{stride:[e.length,0,0],input_features:(await this.processor(e)).input_features,is_last:!0}];for(const e of a){t.num_frames=Math.floor(e.stride[0]/_);const o=await this.model.generate(e.input_features,t);"word"===s?(e.tokens=o.sequences[0],e.token_timestamps=o.token_timestamps.tolist()[0].map((e=>(0,i.round)(e,2)))):e.tokens=o[0],e.stride=e.stride.map((e=>e/m)),null!==n&&n(e)}const[c,d]=this.tokenizer._decode_asr(a,{time_precision:p,return_timestamps:s,force_full_sequences:r});g.push({text:c,...d})}return u?g[0]:g}}class S extends _{constructor(e){super(e)}async _call(e,t={}){const s=Array.isArray(e),o=await u(e),{pixel_values:n}=await this.processor(o),r=[];for(const e of n){e.dims=[1,...e.dims];const s=await this.model.generate(e,t),o=this.tokenizer.batch_decode(s,{skip_special_tokens:!0}).map((e=>({generated_text:e.trim()})));r.push(o)}return s?r:r[0]}}class A extends _{constructor(e){super(e)}async _call(e,{topk:t=1}={}){const s=Array.isArray(e),o=await u(e),{pixel_values:n}=await this.processor(o),r=await this.model({pixel_values:n}),a=this.model.config.id2label,l=[];for(const e of r.logits){const s=(0,i.getTopItems)((0,i.softmax)(e.data),t).map((e=>({label:a[e[0]],score:e[1]})));1===t?l.push(...s):l.push(s)}return s||1===t?l:l[0]}}class L extends _{constructor(e){super(e),this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(e,{threshold:t=.5,mask_threshold:s=.5,overlap_mask_area_threshold:o=.8,label_ids_to_fuse:n=null,target_sizes:r=null,subtask:a=null}={}){if(Array.isArray(e)&&1!==e.length)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const i=await u(e),l=i.map((e=>[e.height,e.width])),{pixel_values:c,pixel_mask:h}=await this.processor(i),p=await this.model({pixel_values:c,pixel_mask:h});let _=null;if(null!==a)_=this.subtasks_mapping[a];else for(let[e,t]of Object.entries(this.subtasks_mapping))if(t in this.processor.feature_extractor){_=this.processor.feature_extractor[t].bind(this.processor.feature_extractor),a=e;break}const m=this.model.config.id2label,f=[];if("panoptic"===a||"instance"===a){const e=_(p,t,s,o,n,r??l)[0],a=e.segmentation;for(const t of e.segments_info){const e=new Uint8ClampedArray(a.data.length);for(let s=0;ss.replace("{}",e))),a=this.tokenizer(r,{padding:"siglip"!==this.model.config.model_type||"max_length",truncation:!0}),{pixel_values:l}=await this.processor(n),c=await this.model({...a,pixel_values:l}),d="siglip"===this.model.config.model_type?e=>e.sigmoid().data:e=>(0,i.softmax)(e.data),h=[];for(const e of c.logits_per_image){const s=[...d(e)].map(((e,s)=>({score:e,label:t[s]})));s.sort(((e,t)=>t.score-e.score)),h.push(s)}return o?h:h[0]}}class z extends _{constructor(e){super(e)}async _call(e,{threshold:t=.9,percentage:s=!1}={}){const o=Array.isArray(e);if(o&&1!==e.length)throw Error("Object detection pipeline currently only supports a batch size of 1.");const n=await u(e),r=s?null:n.map((e=>[e.height,e.width])),{pixel_values:a,pixel_mask:i}=await this.processor(n),l=await this.model({pixel_values:a,pixel_mask:i}),c=this.processor.feature_extractor.post_process_object_detection(l,t,r),d=this.model.config.id2label,h=c.map((e=>e.boxes.map(((t,o)=>({score:e.scores[o],label:d[e.classes[o]],box:p(t,!s)})))));return o?h:h[0]}}class B extends _{constructor(e){super(e)}async _call(e,t,{threshold:s=.1,topk:o=null,percentage:n=!1}={}){const r=Array.isArray(e),a=await u(e),i=this.tokenizer(t,{padding:!0,truncation:!0}),l=await this.processor(a),c=[];for(let e=0;e({score:_.scores[s],label:t[_.classes[s]],box:p(e,!n)}))).sort(((e,t)=>t.score-e.score));null!==o&&(m=m.slice(0,o)),c.push(m)}return r?c:c[0]}}class I extends _{constructor(e){super(e)}async _call(e,t,s={}){const o=(await u(e))[0],{pixel_values:n}=await this.processor(o),r=`${t}`,a=this.tokenizer(r,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,i=await this.model.generate(n,{...s,decoder_input_ids:a,max_length:this.model.config.decoder.max_position_embeddings}),l=this.tokenizer.batch_decode(i)[0].match(/(.*?)<\/s_answer>/);let c=null;return l&&l.length>=2&&(c=l[1].trim()),[{answer:c}]}}class O extends _{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _call(e,{speaker_embeddings:t=null}={}){return this.processor?this._call_text_to_spectrogram(e,{speaker_embeddings:t}):this._call_text_to_waveform(e)}async _call_text_to_waveform(e){const t=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model(t),o=this.model.config.sampling_rate;return{audio:s.data,sampling_rate:o}}async _call_text_to_spectrogram(e,{speaker_embeddings:t}){if(this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await n.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{quantized:!1})),("string"==typeof t||t instanceof URL)&&(t=new Float32Array(await(await fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new c.Tensor("float32",t,[1,t.length]);else if(!(t instanceof c.Tensor))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");const{input_ids:s}=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:o}=await this.model.generate_speech(s,t,{vocoder:this.vocoder}),r=this.processor.feature_extractor.config.sampling_rate;return{audio:o.data,sampling_rate:r}}}class D extends _{constructor(e){super(e)}async _call(e){const t=await u(e),s=await this.processor(t),o=await this.model(s),n=[];for(const e of o.reconstruction){const t=e.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");n.push(d.RawImage.fromTensor(t))}return n.length>1?n:n[0]}}class N extends _{constructor(e){super(e)}async _call(e){const t=await u(e),s=await this.processor(t),{predicted_depth:o}=await this.model(s),n=[];for(let e=0;e1?n:n[0]}}const V=Object.freeze({"text-classification":{tokenizer:o.AutoTokenizer,pipeline:m,model:n.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:o.AutoTokenizer,pipeline:f,model:n.AutoModelForTokenClassification,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:o.AutoTokenizer,pipeline:g,model:n.AutoModelForQuestionAnswering,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:o.AutoTokenizer,pipeline:M,model:n.AutoModelForMaskedLM,default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:o.AutoTokenizer,pipeline:T,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:o.AutoTokenizer,pipeline:k,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:o.AutoTokenizer,pipeline:w,model:n.AutoModelForSeq2SeqLM,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:o.AutoTokenizer,pipeline:b,model:n.AutoModelForCausalLM,default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:o.AutoTokenizer,pipeline:x,model:n.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:C,model:n.AutoModelForAudioClassification,processor:r.AutoProcessor,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:o.AutoTokenizer,pipeline:P,model:n.AutoModel,processor:r.AutoProcessor,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:o.AutoTokenizer,pipeline:v,model:[n.AutoModelForSpeechSeq2Seq,n.AutoModelForCTC],processor:r.AutoProcessor,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:o.AutoTokenizer,pipeline:O,model:[n.AutoModelForTextToWaveform,n.AutoModelForTextToSpectrogram],processor:[r.AutoProcessor,null],default:{model:"Xenova/speecht5_tts"},type:"text"},"image-to-text":{tokenizer:o.AutoTokenizer,pipeline:S,model:n.AutoModelForVision2Seq,processor:r.AutoProcessor,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:A,model:n.AutoModelForImageClassification,processor:r.AutoProcessor,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:L,model:[n.AutoModelForImageSegmentation,n.AutoModelForSemanticSegmentation],processor:r.AutoProcessor,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"zero-shot-image-classification":{tokenizer:o.AutoTokenizer,pipeline:E,model:n.AutoModel,processor:r.AutoProcessor,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:z,model:n.AutoModelForObjectDetection,processor:r.AutoProcessor,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:o.AutoTokenizer,pipeline:B,model:n.AutoModelForZeroShotObjectDetection,processor:r.AutoProcessor,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:o.AutoTokenizer,pipeline:I,model:n.AutoModelForDocumentQuestionAnswering,processor:r.AutoProcessor,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:D,model:n.AutoModelForImageToImage,processor:r.AutoProcessor,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:N,model:n.AutoModelForDepthEstimation,processor:r.AutoProcessor,default:{model:"Xenova/dpt-large"},type:"image"},"feature-extraction":{tokenizer:o.AutoTokenizer,pipeline:y,model:n.AutoModel,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"},"image-feature-extraction":{processor:r.AutoProcessor,pipeline:F,model:[n.AutoModelForImageFeatureExtraction,n.AutoModel],default:{model:"Xenova/vit-base-patch16-224-in21k"},type:"image"}}),q=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function j(e,t=null,{quantized:s=!0,progress_callback:o=null,config:n=null,cache_dir:r=null,local_files_only:i=!1,revision:l="main"}={}){e=q[e]??e;const c=V[e.split("_",1)[0]];if(!c)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(V)}]`);t||(t=c.default.model,console.log(`No model specified. Using default model: "${t}".`));const d={quantized:s,progress_callback:o,config:n,cache_dir:r,local_files_only:i,revision:l},u=new Map([["tokenizer",c.tokenizer],["model",c.model],["processor",c.processor]]),h=await async function(e,t,s){const o=Object.create(null),n=[];for(let[r,a]of e.entries()){if(!a)continue;let e;e=Array.isArray(a)?new Promise((async(e,o)=>{let n;for(let o of a){if(null===o)return void e(null);try{return void e(await o.from_pretrained(t,s))}catch(e){n=e}}o(n)})):a.from_pretrained(t,s),o[r]=e,n.push(e)}await Promise.all(n);for(let[e,t]of Object.entries(o))o[e]=await t;return o}(u,t,d);h.task=e,(0,a.dispatchCallback)(o,{status:"ready",task:e,model:t});return new(0,c.pipeline)(h)}},"./src/processors.js": +/*!***************************!*\ + !*** ./src/processors.js ***! + \***************************/(e,t,s)=>{s.r(t),s.d(t,{ASTFeatureExtractor:()=>G,AutoProcessor:()=>Z,BeitFeatureExtractor:()=>E,BitImageProcessor:()=>M,CLIPFeatureExtractor:()=>T,ChineseCLIPFeatureExtractor:()=>k,ClapFeatureExtractor:()=>W,ConvNextFeatureExtractor:()=>x,ConvNextImageProcessor:()=>y,DPTFeatureExtractor:()=>f,DPTImageProcessor:()=>g,DeiTFeatureExtractor:()=>L,DetrFeatureExtractor:()=>I,DonutFeatureExtractor:()=>z,EfficientNetImageProcessor:()=>P,FeatureExtractor:()=>p,GLPNFeatureExtractor:()=>w,ImageFeatureExtractor:()=>_,MobileViTFeatureExtractor:()=>v,NougatImageProcessor:()=>B,OwlViTFeatureExtractor:()=>S,OwlViTProcessor:()=>J,Owlv2ImageProcessor:()=>A,Processor:()=>U,SamImageProcessor:()=>D,SamProcessor:()=>X,SeamlessM4TFeatureExtractor:()=>R,SegformerFeatureExtractor:()=>m,SiglipImageProcessor:()=>b,SpeechT5FeatureExtractor:()=>$,SpeechT5Processor:()=>Y,Swin2SRImageProcessor:()=>N,ViTFeatureExtractor:()=>F,ViTImageProcessor:()=>C,VitMatteImageProcessor:()=>V,Wav2Vec2FeatureExtractor:()=>j,Wav2Vec2ProcessorWithLM:()=>H,WhisperFeatureExtractor:()=>q,WhisperProcessor:()=>Q,YolosFeatureExtractor:()=>O});var o=s(/*! ./utils/core.js */"./src/utils/core.js"),n=s(/*! ./utils/hub.js */"./src/utils/hub.js"),r=s(/*! ./utils/maths.js */"./src/utils/maths.js"),a=s(/*! ./utils/tensor.js */"./src/utils/tensor.js"),i=(s(/*! ./utils/image.js */"./src/utils/image.js"),s(/*! ./utils/audio.js */"./src/utils/audio.js"));function l([e,t,s,o]){return[e-s/2,t-o/2,e+s/2,t+o/2]}function c(e,t=.5,s=null,o=!1){const n=e.logits,a=e.pred_boxes,[i,c,d]=n.dims;if(null!==s&&s.length!==i)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let u=[];for(let e=0;et&&a.push(e)}else{let e=(0,r.max)(n.data)[1];if(e===d-1)continue;a.push(e),s=(0,r.softmax)(n.data)}for(const t of a){let o=_[e].data;o=l(o),null!==i&&(o=o.map(((e,t)=>e*i[(t+1)%2]))),h.boxes.push(o),h.classes.push(t),h.scores.push(s[t])}}u.push(h)}return u}function d(e,t){if(!(e instanceof Float32Array||e instanceof Float64Array))throw new Error(`${t} expects input to be a Float32Array or a Float64Array, but got ${e?.constructor?.name??typeof e} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}function u(e,t,s=0,o=null){const n=e/t;let a=(0,r.bankers_round)(n)*t;return null!==o&&a>o&&(a=Math.floor(n)*t),an?l=Math.floor(n*i/o):n>o&&(i=Math.floor(o*l/n)),await e.resize(l,i,{resample:s}))}async crop_margin(e,t=200){const s=e.clone().grayscale(),o=(0,r.min)(s.data)[0],n=(0,r.max)(s.data)[0]-o;if(0===n)return e;const a=t/255;let i=s.width,l=s.height,c=0,d=0;for(let e=0;ethis.preprocess(e))));return{pixel_values:(0,a.stack)(s.map((e=>e.pixel_values)),0),original_sizes:s.map((e=>e.original_size)),reshaped_input_sizes:s.map((e=>e.reshaped_input_size))}}}class m extends _{post_process_semantic_segmentation(e,t=null){const s=e.logits,o=s.dims[0];if(null!==t&&t.length!==o)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");const n=[];for(let e=0;ed[s]&&(d[s]=t[s],c.data[s]=e)}const u=new Array(r.dims[0]),h=c.data;for(let e=0;evoid 0!==e));n.push({segmentation:c,labels:p})}return n}}class f extends _{}class g extends f{}class M extends _{}class w extends _{}class T extends _{}class k extends _{}class b extends _{}class x extends _{constructor(e){super(e),this.crop_pct=this.config.crop_pct??.875}async resize(e){const t=this.size?.shortest_edge;if(void 0===t)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(t<384){const s=Math.floor(t/this.crop_pct),[o,n]=this.get_resize_output_image_size(e,{shortest_edge:s});e=await e.resize(o,n,{resample:this.resample}),e=await e.center_crop(t,t)}else e=await e.resize(t,t,{resample:this.resample});return e}}class y extends x{}class F extends _{}class C extends _{}class P extends _{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map((e=>e*e)))}}class v extends _{}class S extends _{post_process_object_detection(...e){return c(...e)}}class A extends S{}class L extends _{}class E extends _{}class z extends _{pad_image(e,t,s,o={}){const[n,r,a]=t;let i=this.image_mean;Array.isArray(this.image_mean)||(i=new Array(a).fill(i));let l=this.image_std;Array.isArray(l)||(l=new Array(a).fill(i));const c=i.map(((e,t)=>-e/l[t]));return super.pad_image(e,t,s,{center:!0,constant_values:c,...o})}}class B extends z{}class I extends _{async _call(e){const t=await super._call(e),s=[t.pixel_values.dims[0],64,64],o=new a.Tensor("int64",new BigInt64Array(s.reduce(((e,t)=>e*t))).fill(1n),s);return{...t,pixel_mask:o}}post_process_object_detection(...e){return c(...e)}remove_low_and_no_objects(e,t,s,o){let n=[],a=[],i=[];for(let l=0;ls&&(n.push(d),a.push(h),i.push(u))}return[n,a,i]}check_segment_validity(e,t,s,o=.5,n=.8){let r=[],a=0,i=0;for(let n=0;n=o&&++i;let l=a>0&&i>0;if(l){l=a/i>n}return[l,r]}compute_segments(e,t,s,o,n,r=null,i=null){let[l,c]=i??e[0].dims,d=new a.Tensor("int32",new Int32Array(l*c),[l,c]),u=[];if(null!==i)for(let t=0;tp[t]&&(h[t]=s,p[t]=e[s].data[t])}let _=0;for(let r=0;re!==t.dims[s])))throw Error(`The first ${s.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new a.Tensor("int64",e.flat(1/0).map(BigInt),s)}async _call(e,t=null,s=null){const o=await super._call(e);if(t&&(o.input_points=this.reshape_input_points(t,o.original_sizes,o.reshaped_input_sizes)),s){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(s,o.input_points)}return o}post_process_masks(e,t,s,{mask_threshold:o=0,binarize:n=!0,pad_size:r=null}={}){const i=[],l=[(r=r??this.pad_size).height,r.width];for(let r=0;ro&&(e[t]=1);s=new a.Tensor("bool",e,s.dims)}h.push(s)}i.push((0,a.stack)(h))}return i}}class N extends _{pad_image(e,t,s,o={}){const[n,r,a]=t;return super.pad_image(e,t,{width:r+(s-r%s)%s,height:n+(s-n%s)%s},{mode:"symmetric",center:!1,constant_values:-1,...o})}}class V extends _{async _call(e,t){Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);const s=await Promise.all(e.map((e=>this.preprocess(e)))),o=await Promise.all(t.map((e=>this.preprocess(e,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0}))));return{pixel_values:(0,a.stack)(s.map(((e,t)=>(0,a.cat)([e.pixel_values,o[t].pixel_values],0))),0),original_sizes:s.map((e=>e.original_size)),reshaped_input_sizes:s.map((e=>e.reshaped_input_size))}}}class q extends p{constructor(e){super(e),this.config.mel_filters??=(0,i.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=(0,i.window_function)(this.config.n_fft,"hann")}_extract_fbank_features(e){const{data:t,dims:s}=(0,i.spectrogram)(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:this.config.nb_max_frames}),o=(0,r.max)(t)[0];for(let e=0;ethis.config.n_samples?(console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),t=e.slice(0,this.config.n_samples)):(t=new Float32Array(this.config.n_samples),t.set(e));const{data:s,dims:o}=this._extract_fbank_features(t);return{input_features:new a.Tensor("float32",s,[1,...o])}}}class j extends p{_zero_mean_unit_var_norm(e){const t=e.reduce(((e,t)=>e+t),0)/e.length,s=e.reduce(((e,s)=>e+(s-t)**2),0)/e.length;return e.map((e=>(e-t)/Math.sqrt(s+1e-7)))}async _call(e){d(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let t=e;this.config.do_normalize&&(t=this._zero_mean_unit_var_norm(t));const s=[1,t.length];return{input_values:new a.Tensor("float32",t,s),attention_mask:new a.Tensor("int64",new BigInt64Array(t.length).fill(1n),s)}}}class R extends p{constructor(e){super(e);const t=this.config.sampling_rate,s=(0,i.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e32768*e)),(0,i.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e,{padding:t=!0,pad_to_multiple_of:s=2,do_normalize_per_mel_bins:o=!0,return_attention_mask:n=!0}={}){d(e,"SeamlessM4TFeatureExtractor");let r,i=this._extract_fbank_features(e,this.config.max_length);if(o){const[e,t]=i.dims;for(let s=0;s0){const s=new Float32Array(t*(e+o));s.set(i.data),s.fill(this.config.padding_value,i.data.length);const l=e+o;i={data:s,dims:[l,t]},n&&(r=new a.Tensor("int64",new BigInt64Array(l),[1,l]),r.data.fill(1n,0,e))}}const[l,c]=i.dims,u=this.config.stride;if(0!==l%u)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${u}).`);const h=new a.Tensor("float32",i.data,i.dims).view(1,Math.floor(l/u),c*u),p={input_features:h};if(n){const e=h.dims[1],t=new a.Tensor("int64",new BigInt64Array(e),[1,e]);if(r)for(let e=1,s=0;e0){if("rand_trunc"!==s)throw new Error(`Truncation strategy "${s}" not implemented`);{r=!0;const s=Math.floor(Math.random()*(a+1));e=e.subarray(s,s+t),n=this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples),n.dims=[1,...n.dims]}}else{if(a<0){let s=new Float64Array(t);if(s.set(e),"repeat"===o)for(let o=e.length;o{s.r(t),s.d(t,{AlbertTokenizer:()=>fe,AutoTokenizer:()=>dt,BartTokenizer:()=>Ae,BertTokenizer:()=>me,BlenderbotSmallTokenizer:()=>rt,BlenderbotTokenizer:()=>nt,BloomTokenizer:()=>Be,CLIPTokenizer:()=>et,CamembertTokenizer:()=>Fe,CodeGenTokenizer:()=>Ke,CodeLlamaTokenizer:()=>De,CohereTokenizer:()=>ct,ConvBertTokenizer:()=>be,DebertaTokenizer:()=>we,DebertaV2Tokenizer:()=>Te,DistilBertTokenizer:()=>ye,ElectraTokenizer:()=>Pe,EsmTokenizer:()=>Re,FalconTokenizer:()=>qe,GPT2Tokenizer:()=>Se,GPTNeoXTokenizer:()=>je,GemmaTokenizer:()=>We,Grok1Tokenizer:()=>$e,HerbertTokenizer:()=>ke,LlamaTokenizer:()=>Oe,M2M100Tokenizer:()=>Qe,MBart50Tokenizer:()=>Ee,MBartTokenizer:()=>Le,MPNetTokenizer:()=>Ve,MarianTokenizer:()=>st,MobileBertTokenizer:()=>ge,NllbTokenizer:()=>Xe,NougatTokenizer:()=>it,PreTrainedTokenizer:()=>_e,Qwen2Tokenizer:()=>Ge,RoFormerTokenizer:()=>xe,RobertaTokenizer:()=>ze,SiglipTokenizer:()=>tt,SpeechT5Tokenizer:()=>at,SqueezeBertTokenizer:()=>Me,T5Tokenizer:()=>ve,TokenizerModel:()=>M,VitsTokenizer:()=>lt,Wav2Vec2CTCTokenizer:()=>ot,WhisperTokenizer:()=>Ze,XLMRobertaTokenizer:()=>Ne,XLMTokenizer:()=>Ce});var o=s(/*! ./utils/core.js */"./src/utils/core.js"),n=s(/*! ./utils/hub.js */"./src/utils/hub.js"),r=s(/*! ./utils/maths.js */"./src/utils/maths.js"),a=s(/*! ./utils/tensor.js */"./src/utils/tensor.js"),i=s(/*! ./utils/data-structures.js */"./src/utils/data-structures.js"),l=s(/*! @huggingface/jinja */"./node_modules/@huggingface/jinja/dist/index.js");async function c(e,t){const s=await Promise.all([(0,n.getModelJSON)(e,"tokenizer.json",!0,t),(0,n.getModelJSON)(e,"tokenizer_config.json",!0,t)]);return null!==t.legacy&&(s[1].legacy=t.legacy),s}function d(e,t=!0){if(void 0!==e.Regex){let t=e.Regex.replace(/\\([#&~])/g,"$1");for(const[e,s]of f)t=t.replaceAll(e,s);return new RegExp(t,"gu")}if(void 0!==e.String){const s=(0,o.escapeRegExp)(e.String);return new RegExp(t?s:`(${s})`,"gu")}return console.warn("Unknown pattern type:",e),null}function u(e){return new Map(Object.entries(e))}function h(e){const t=e.dims;switch(t.length){case 1:return e.tolist();case 2:if(1!==t[0])throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return e.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${t.length}.`)}}function p(e){return e.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n\'t/g,"n't").replace(/ \'m/g,"'m").replace(/ \'s/g,"'s").replace(/ \'ve/g,"'ve").replace(/ \'re/g,"'re")}function _(e){return e.replace(/[\u0300-\u036f]/g,"")}const m="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",f=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"]]);class g{constructor(e){this.content=e.content,this.id=e.id,this.single_word=e.single_word??!1,this.lstrip=e.lstrip??!1,this.rstrip=e.rstrip??!1,this.special=e.special??!1,this.normalized=e.normalized??null}}class M extends o.Callable{constructor(e){super(),this.config=e,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}static fromConfig(e,...t){switch(e.type){case"WordPiece":return new w(e);case"Unigram":return new T(e,...t);case"BPE":return new x(e);default:if(e.vocab)return new y(e,...t);throw new Error(`Unknown TokenizerModel type: ${e.type}`)}}_call(e){let t=this.encode(e);return this.fuse_unk&&(t=function(e,t,s){const o=[];let n=0;for(;nthis.tokens_to_ids.get(e)??this.unk_token_id))}convert_ids_to_tokens(e){return e.map((e=>this.vocab[e]??this.unk_token))}}class w extends M{constructor(e){super(e),this.tokens_to_ids=u(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.max_input_chars_per_word=e.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){const t=[];for(const s of e){const e=[...s];if(e.length>this.max_input_chars_per_word){t.push(this.unk_token);continue}let o=!1,n=0;const r=[];for(;n0&&(o=this.config.continuing_subword_prefix+o),this.tokens_to_ids.has(o)){s=o;break}--t}if(null===s){o=!0;break}r.push(s),n=t}o?t.push(this.unk_token):t.push(...r)}return t}}class T extends M{constructor(e,t){super(e);const s=e.vocab.length;this.vocab=new Array(s),this.scores=new Array(s);for(let t=0;t[e,t]))),this.bosToken=" ",this.bosTokenId=this.tokens_to_ids.get(this.bosToken),this.eosToken=t.eos_token,this.eosTokenId=this.tokens_to_ids.get(this.eosToken),this.unkToken=this.vocab[this.unk_token_id],this.minScore=(0,r.min)(this.scores)[0],this.unkScore=this.minScore-10,this.scores[this.unk_token_id]=this.unkScore,this.trie=new i.CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){const t=e.sentence,s=t.length;let o=0;for(;o{const e=[...Array.from({length:"~".charCodeAt(0)-"!".charCodeAt(0)+1},((e,t)=>t+"!".charCodeAt(0))),...Array.from({length:"¬".charCodeAt(0)-"¡".charCodeAt(0)+1},((e,t)=>t+"¡".charCodeAt(0))),...Array.from({length:"ÿ".charCodeAt(0)-"®".charCodeAt(0)+1},((e,t)=>t+"®".charCodeAt(0)))],t=e.slice();let s=0;for(let o=0;o<256;++o)e.includes(o)||(e.push(o),t.push(256+s),s+=1);const o=t.map((e=>String.fromCharCode(e)));return Object.fromEntries(e.map(((e,t)=>[e,o[t]])))})(),b=(0,o.reverseDictionary)(k);class x extends M{constructor(e){super(e),this.BPE_SPLIT_TOKEN=" ",this.tokens_to_ids=u(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e;this.bpe_ranks=new Map(e.merges.map(((e,t)=>[e,t]))),this.merges=e.merges.map((e=>e.split(this.BPE_SPLIT_TOKEN))),this.end_of_word_suffix=e.end_of_word_suffix,this.continuing_subword_suffix=e.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.cache=new Map}bpe(e){if(0===e.length)return[];const t=this.cache.get(e);if(void 0!==t)return t;const s=Array.from(e);this.end_of_word_suffix&&(s[s.length-1]+=this.end_of_word_suffix);let o=[];if(s.length>1){const e=new i.PriorityQueue(((e,t)=>e.score`<0x${e.toString(16).toUpperCase().padStart(2,"0")}>`))):t.push(this.unk_token)}return t}}class y extends M{constructor(e,t){super(e),this.tokens_to_ids=u(t.target_lang?e.vocab[t.target_lang]:e.vocab),this.bos_token=t.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=t.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=t.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){return e}}class F extends o.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"BertNormalizer":return new I(e);case"Precompiled":return new ae(e);case"Sequence":return new B(e);case"Replace":return new C(e);case"NFC":return new P(e);case"NFKC":return new v(e);case"NFKD":return new S(e);case"Strip":return new A(e);case"StripAccents":return new L(e);case"Lowercase":return new E(e);case"Prepend":return new z(e);default:throw new Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error("normalize should be implemented in subclass.")}_call(e){return this.normalize(e)}}class C extends F{normalize(e){const t=d(this.config.pattern);return null===t?e:e.replaceAll(t,this.config.content)}}class P extends F{normalize(e){return e=e.normalize("NFC")}}class v extends F{normalize(e){return e=e.normalize("NFKC")}}class S extends F{normalize(e){return e=e.normalize("NFKD")}}class A extends F{normalize(e){return this.config.strip_left&&this.config.strip_right?e=e.trim():(this.config.strip_left&&(e=e.trimStart()),this.config.strip_right&&(e=e.trimEnd())),e}}class L extends F{normalize(e){return e=_(e)}}class E extends F{normalize(e){return e=e.toLowerCase()}}class z extends F{normalize(e){return e=this.config.prepend+e}}class B extends F{constructor(e){super(e),this.normalizers=e.normalizers.map((e=>F.fromConfig(e)))}normalize(e){return this.normalizers.reduce(((e,t)=>t.normalize(e)),e)}}class I extends F{_tokenize_chinese_chars(e){const t=[];for(let s=0;s=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}stripAccents(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}_is_control(e){switch(e){case"\t":case"\n":case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(e)}}_clean_text(e){const t=[];for(const s of e){const e=s.charCodeAt(0);0===e||65533===e||this._is_control(s)||(/^\s$/.test(s)?t.push(" "):t.push(s))}return t.join("")}normalize(e){return this.config.clean_text&&(e=this._clean_text(e)),this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),!1!==this.config.strip_accents&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class O extends o.Callable{static fromConfig(e){if(null===e)return null;switch(e.type){case"BertPreTokenizer":return new D(e);case"Sequence":return new ie(e);case"Whitespace":return new le(e);case"WhitespaceSplit":return new ce(e);case"Metaspace":return new ne(e);case"ByteLevel":return new N(e);case"Split":return new V(e);case"Punctuation":return new q(e);case"Digits":return new j(e);case"Replace":return new de(e);default:throw new Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e,t){throw Error("pre_tokenize_text should be implemented in subclass.")}pre_tokenize(e,t){return(Array.isArray(e)?e.map((e=>this.pre_tokenize_text(e,t))):this.pre_tokenize_text(e,t)).flat()}_call(e,t){return this.pre_tokenize(e,t)}}class D extends O{constructor(e){super(),this.pattern=new RegExp(`[^\\s${m}]+|[${m}]`,"gu")}pre_tokenize_text(e,t){return e.trim().match(this.pattern)||[]}}class N extends O{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=k,this.text_encoder=new TextEncoder}pre_tokenize_text(e,t){this.add_prefix_space&&!e.startsWith(" ")&&(e=" "+e);return(this.use_regex?e.match(this.pattern)||[]:[e]).map((e=>Array.from(this.text_encoder.encode(e),(e=>this.byte_encoder[e])).join("")))}}class V extends O{constructor(e){super(),this.config=e,this.pattern=d(this.config.pattern,this.config.invert)}pre_tokenize_text(e,t){return null===this.pattern?[]:this.config.invert?e.match(this.pattern)||[]:function(e,t){const s=[];let o=0;for(const n of e.matchAll(t)){const t=n[0];o0&&s.push(t),o=n.index+t.length}return oe.replaceAll(t,this.config.content)))}}class H extends X{constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){const t=[];let s=[];for(const o of e){let e=null;if(6===o.length&&o.startsWith("<0x")&&o.endsWith(">")){const t=parseInt(o.slice(3,5),16);isNaN(t)||(e=t)}if(null!==e)s.push(e);else{if(s.length>0){const e=this.text_decoder.decode(Uint8Array.from(s));t.push(e),s=[]}t.push(o)}}if(s.length>0){const e=this.text_decoder.decode(Uint8Array.from(s));t.push(e),s=[]}return t}}class Y extends X{decode_chain(e){return[e.join("")]}}class J extends X{constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map((e=>{let t=0;for(let s=0;s(0!==t&&(e=e.startsWith(this.config.prefix)?e.replace(this.config.prefix,""):" "+e),this.cleanup&&(e=p(e)),e)))}}class K extends X{constructor(e){super(e),this.byte_decoder=b,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){const t=e.join(""),s=new Uint8Array([...t].map((e=>this.byte_decoder[e])));return this.text_decoder.decode(s)}decode_chain(e){const t=[];let s=[];for(const o of e)void 0!==this.added_tokens.find((e=>e.content===o))?(s.length>0&&(t.push(this.convert_tokens_to_string(s)),s=[]),t.push(o)):s.push(o);return s.length>0&&t.push(this.convert_tokens_to_string(s)),t}}class ee extends X{constructor(e){super(e),this.pad_token=this.config.pad_token,this.word_delimiter_token=this.config.word_delimiter_token,this.cleanup=this.config.cleanup}convert_tokens_to_string(e){if(0===e.length)return"";const t=[e[0]];for(let s=1;se!==this.pad_token)).join("");return this.cleanup&&(s=p(s).replaceAll(this.word_delimiter_token," ").trim()),s}decode_chain(e){return[this.convert_tokens_to_string(e)]}}class te extends X{constructor(e){super(e),this.decoders=e.decoders.map((e=>X.fromConfig(e)))}decode_chain(e){return this.decoders.reduce(((e,t)=>t.decode_chain(e)),e)}}class se extends X{constructor(e){super(e),this.suffix=this.config.suffix}decode_chain(e){return e.map(((t,s)=>t.replaceAll(this.suffix,s===e.length-1?"":" ")))}}class oe extends X{decode_chain(e){let t="";for(let s=1;se.normalize("NFKC"))).join("~")}else e=e.normalize("NFKC");return e}}class ie extends O{constructor(e){super(),this.tokenizers=e.pretokenizers.map((e=>O.fromConfig(e)))}pre_tokenize_text(e,t){return this.tokenizers.reduce(((e,s)=>s.pre_tokenize(e,t)),[e])}}class le extends O{constructor(e){super()}pre_tokenize_text(e,t){return e.match(/\w+|[^\w\s]+/g)||[]}}class ce extends O{constructor(e){super()}pre_tokenize_text(e,t){return function(e){return e.match(/\S+/g)||[]}(e)}}class de extends O{constructor(e){super(),this.config=e,this.pattern=d(this.config.pattern),this.content=this.config.content}pre_tokenize_text(e,t){return null===this.pattern?[e]:[e.replaceAll(this.pattern,this.config.content)]}}const ue=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function he(e,t,s,n){for(const r of Object.keys(e)){const a=t-e[r].length,i=s(r),l=new Array(a).fill(i);e[r]="right"===n?(0,o.mergeArrays)(e[r],l):(0,o.mergeArrays)(l,e[r])}}function pe(e,t){for(const s of Object.keys(e))e[s].length=t}class _e extends o.Callable{return_token_type_ids=!1;_default_chat_template="{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}";constructor(e,t){super(),this._tokenizer_config=t,this.normalizer=F.fromConfig(e.normalizer),this.pre_tokenizer=O.fromConfig(e.pre_tokenizer),this.model=M.fromConfig(e.model,t),this.post_processor=R.fromConfig(e.post_processor),this.decoder=X.fromConfig(e.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];for(const t of e.added_tokens){const e=new g(t);this.added_tokens.push(e),this.model.tokens_to_ids.set(e.content,e.id),this.model.vocab[e.id]=e.content,e.special&&(this.special_tokens.push(e.content),this.all_special_ids.push(e.id))}if(this.additional_special_tokens=t.additional_special_tokens??[],this.special_tokens.push(...this.additional_special_tokens),this.special_tokens=[...new Set(this.special_tokens)],this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.added_tokens_regex=this.added_tokens.length>0?new RegExp(this.added_tokens.map((e=>`${e.lstrip?"\\s*":""}(${(0,o.escapeRegExp)(e.content)})${e.rstrip?"\\s*":""}`)).join("|")):null,this.mask_token=this.getToken("mask_token"),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken("pad_token","eos_token"),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken("sep_token"),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.unk_token=this.getToken("unk_token"),this.unk_token_id=this.model.tokens_to_ids.get(this.unk_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=t.do_lowercase_and_remove_accent??!1,this.padding_side="right",this.legacy=!1,this.chat_template=t.chat_template??null,Array.isArray(this.chat_template)){const e=Object.create(null);for(const{name:t,template:s}of this.chat_template){if("string"!=typeof t||"string"!=typeof s)throw new Error('Chat template must be a list of objects with "name" and "template" properties');e[t]=s}this.chat_template=e}this._compiled_template_cache=new Map}getToken(...e){for(const t of e){const e=this._tokenizer_config[t];if(e){if("object"==typeof e){if("AddedToken"===e.__type)return e.content;throw Error(`Unknown token: ${e}`)}return e}}return null}static async from_pretrained(e,{progress_callback:t=null,config:s=null,cache_dir:o=null,local_files_only:n=!1,revision:r="main",legacy:a=null}={}){return new this(...await c(e,{progress_callback:t,config:s,cache_dir:o,local_files_only:n,revision:r,legacy:a}))}_call(e,{text_pair:t=null,add_special_tokens:s=!0,padding:o=!1,truncation:n=null,max_length:i=null,return_tensor:l=!0}={}){const c=Array.isArray(e);let d;if(c){if(0===e.length)throw Error("text array must be non-empty");if(null!==t){if(!Array.isArray(t))throw Error("text_pair must also be an array");if(e.length!==t.length)throw Error("text and text_pair must have the same length");d=e.map(((e,o)=>this._encode_plus(e,t[o],{add_special_tokens:s})))}else d=e.map((e=>this._encode_plus(e,null,{add_special_tokens:s})))}else{if(null===e)throw Error("text may not be null");if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");d=[this._encode_plus(e,t,{add_special_tokens:s})]}if(null===i?i="max_length"===o?this.model_max_length:(0,r.max)(d.map((e=>e.input_ids.length)))[0]:n||console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length."),i=Math.min(i,this.model_max_length),o||n)for(let e=0;ei?n&&pe(d[e],i):o&&he(d[e],i,(e=>"input_ids"===e?this.pad_token_id:0),this.padding_side));const u={};if(l){if((!o||!n)&&d.some((e=>{for(const t of Object.keys(e))if(e[t].length!==d[0][t]?.length)return!0;return!1})))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");const e=[d.length,d[0].input_ids.length];for(const t of Object.keys(d[0]))u[t]=new a.Tensor("int64",BigInt64Array.from(d.flatMap((e=>e[t])).map(BigInt)),e)}else{for(const e of Object.keys(d[0]))u[e]=d.map((t=>t[e]));if(!c)for(const e of Object.keys(u))u[e]=u[e][0]}return u}_encode_text(e){if(null===e)return null;const t=(this.added_tokens_regex?e.split(this.added_tokens_regex).filter((e=>e)):[e]).map(((e,t)=>{if(void 0!==this.added_tokens.find((t=>t.content===e)))return e;{if(!0===this.remove_space&&(e=e.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(e=function(e){return _(e.toLowerCase())}(e)),null!==this.normalizer&&(e=this.normalizer(e)),0===e.length)return[];const s=null!==this.pre_tokenizer?this.pre_tokenizer(e,{section_index:t}):[e];return this.model(s)}})).flat();return t}_encode_plus(e,t=null,{add_special_tokens:s=!0}={}){const n=this._encode_text(e),r=this._encode_text(t),a=this.post_processor?this.post_processor(n,r,{add_special_tokens:s}):{tokens:(0,o.mergeArrays)(n??[],r??[])},i=this.model.convert_tokens_to_ids(a.tokens),l={input_ids:i,attention_mask:new Array(i.length).fill(1)};return this.return_token_type_ids&&a.token_type_ids&&(l.token_type_ids=a.token_type_ids),l}encode(e,t=null,{add_special_tokens:s=!0}={}){const{input_ids:o}=this._encode_plus(e,t,{add_special_tokens:s});return o}batch_decode(e,t={}){return e instanceof a.Tensor&&(e=e.tolist()),e.map((e=>this.decode(e,t)))}decode(e,t={}){if(e instanceof a.Tensor&&(e=h(e)),!Array.isArray(e)||0===e.length||!(0,o.isIntegralNumber)(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:s=null}){let o=this.model.convert_ids_to_tokens(e);t&&(o=o.filter((e=>!this.special_tokens.includes(e))));let n=this.decoder?this.decoder(o):o.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(n=n.replaceAll(this.decoder.end_of_word_suffix," "),t&&(n=n.trim())),(s??this.clean_up_tokenization_spaces)&&(n=p(n)),n}get default_chat_template(){return this._warned_about_chat_template||(console.warn("No chat template is defined for this tokenizer - using a default chat template that implements the ChatML format. If the default is not appropriate for your model, please set `tokenizer.chat_template` to an appropriate template. See https://huggingface.co/docs/transformers/main/chat_templating for more information."),this._warned_about_chat_template=!0),this._default_chat_template}apply_chat_template(e,{chat_template:t=null,add_generation_prompt:s=!1,tokenize:o=!0,padding:n=!1,truncation:r=!1,max_length:a=null,return_tensor:i=!0,tokenizer_kwargs:c={},...d}={}){if(this.chat_template&&"object"==typeof this.chat_template||null===this.chat_template&&this.default_chat_template&&"object"==typeof this.default_chat_template){const e=this.chat_template??this.default_chat_template;if(null!==t&&Object.hasOwn(e,t))t=e[t];else if(null===t&&"default"in e)t=e.default;else if(null===t)throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(e).sort()}.`)}else t??=this.chat_template??this.default_chat_template;if("string"!=typeof t)throw Error("chat_template must be a string, but got "+typeof t);let u=this._compiled_template_cache.get(t);void 0===u&&(u=new l.Template(t),this._compiled_template_cache.set(t,u));const h=Object.create(null);for(const e of ue){const t=this.getToken(e);t&&(h[e]=t)}const p=u.render({messages:e,add_generation_prompt:s,...h,...d});return o?this._call(p,{add_special_tokens:!1,padding:n,truncation:r,max_length:a,return_tensor:i,...c}).input_ids:p}}class me extends _e{return_token_type_ids=!0}class fe extends _e{return_token_type_ids=!0}class ge extends _e{return_token_type_ids=!0}class Me extends _e{return_token_type_ids=!0}class we extends _e{return_token_type_ids=!0}class Te extends _e{return_token_type_ids=!0}class ke extends _e{return_token_type_ids=!0}class be extends _e{return_token_type_ids=!0}class xe extends _e{return_token_type_ids=!0}class ye extends _e{}class Fe extends _e{}class Ce extends _e{return_token_type_ids=!0;constructor(e,t){super(e,t),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}}class Pe extends _e{return_token_type_ids=!0}class ve extends _e{}class Se extends _e{_default_chat_template='{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}'}class Ae extends _e{}class Le extends _e{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,s){return Ue(this,e,t,s)}}class Ee extends Le{}class ze extends _e{}class Be extends Se{constructor(e,t){const s=".,!?…。,、।۔،",o=e.pre_tokenizer?.pretokenizers[0]?.pattern;o&&o.Regex===` ?[^(\\s|[${s}])]+`&&(o.Regex=` ?[^\\s${s}]+`),super(e,t)}}const Ie="▁";class Oe extends _e{_default_chat_template="{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\n' + system_message + '\n<>\n\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<>\n' + content.strip() + '\n<>\n\n' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}";DEFAULT_SYSTEM_PROMPT="You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.";constructor(e,t){super(e,t),this.use_default_system_prompt=t.use_default_system_prompt??!1,this.legacy=t.legacy??!0,this.legacy||(this.normalizer=null,this.pre_tokenizer=new ne({replacement:Ie,add_prefix_space:!0,prepend_scheme:"first"}))}_encode_text(e){if(null===e)return null;if(this.legacy||0===e.length)return super._encode_text(e);let t=super._encode_text(Ie+e.replaceAll(Ie," "));return t.length>1&&t[0]===Ie&&this.special_tokens.includes(t[1])&&(t=t.slice(1)),t}get default_chat_template(){return super.default_chat_template.replaceAll("USE_DEFAULT_PROMPT",this.use_default_system_prompt?"true":"false").replaceAll("DEFAULT_SYSTEM_MESSAGE",this.DEFAULT_SYSTEM_PROMPT.replaceAll("\n","\\n").replaceAll("'","\\'"))}}class De extends Oe{}class Ne extends _e{}class Ve extends _e{}class qe extends _e{}class je extends _e{}class Re extends _e{}class Ge extends _e{}class We extends _e{_default_chat_template="{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '' + role + '\n' + message['content'] | trim + '\n' }}{% endfor %}{% if add_generation_prompt %}{{'model\n'}}{% endif %}"}class $e extends _e{}function Ue(e,t,s,o){if(!("language_codes"in e)||!Array.isArray(e.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in e&&e.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in e)||"function"!=typeof e.lang_to_token)throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");const n=o.src_lang,r=o.tgt_lang;if(!e.language_codes.includes(r))throw new Error(`Target language code "${r}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);if(void 0!==n){if(!e.language_codes.includes(n))throw new Error(`Source language code "${n}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);for(const t of e.post_processor.config.single)if("SpecialToken"in t&&e.languageRegex.test(t.SpecialToken.id)){t.SpecialToken.id=e.lang_to_token(n);break}}return o.forced_bos_token_id=e.model.convert_tokens_to_ids([e.lang_to_token(r)])[0],e._call(t,s)}class Xe extends _e{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,s){return Ue(this,e,t,s)}}class Qe extends _e{constructor(e,t){super(e,t),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))).map((e=>e.slice(2,-2))),this.lang_to_token=e=>`__${e}__`}_build_translation_inputs(e,t,s){return Ue(this,e,t,s)}}const He=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],Ye=new Map(He),Je=new Map([...He.map((([e,t])=>[t,e])),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);class Ze extends _e{_default_chat_template='{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}';_decode_asr(e,{return_timestamps:t=!1,return_language:s=!1,time_precision:o=null,force_full_sequences:n=!0}={}){if(null===o)throw Error("Must specify time_precision");let a=null;const i="word"===t;function l(){return{language:a,timestamp:[null,null],text:""}}const c=[];let d=l(),u=0;const h=this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0]+1;let p=[],_=[],m=!1,f=null;const g=new Set(this.all_special_ids);for(const s of e){const e=s.tokens,n=i?s.token_timestamps:null;let M=null,w=h;if("stride"in s){const[t,n,r]=s.stride;if(u-=n,f=t-r,n&&(w=n/o+h),r)for(let t=e.length-1;t>=0;--t){const s=e[t];if(s>=h){if(null!==M&&(s-h)*o=h){const e=(f-h)*o+u,t=(0,r.round)(e,2);if(null!==M&&f>=M)m=!0;else if(m||p.length>0&&f0?(p.push(T),i&&_.push(k)):p.every((e=>0===e.length))&&(d=l(),p=[],T=[],_=[],k=[])}if(p.length>0){if(n&&t)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");const[e,s]=this.findLongestCommonSequence(p,_),o=this.decode(e);d.text=o,i&&(d.words=this.collateWordTimestamps(e,s,a)),c.push(d)}let M=Object.create(null);const w=c.map((e=>e.text)).join("");if(t||s){for(let e=0;e0;let a=r?[]:null,i=r?t[0]:null;for(let l=1;le===p[t])).length,m=_/e+t;_>1&&m>d&&(d=m,u=[n,r,i,l])}const[p,_,m,f]=u,g=Math.floor((_+p)/2),M=Math.floor((f+m)/2);n.push(...s.slice(0,g)),s=c.slice(M),o=s.length,r&&(a.push(...i.slice(0,g)),i=t[l].slice(M))}return n.push(...s),r?(a.push(...i),[n,a]):[n,[]]}collateWordTimestamps(e,t,s){const[o,n,r]=this.combineTokensIntoWords(e,s),a=[];for(let e=0;e=o){const e=(0,r.round)((t-o)*s,2);n.push(`<|${e}|>`),n.push([])}else n[n.length-1].push(t);return n=n.map((e=>"string"==typeof e?e:super.decode(e,t))),n.join("")}splitTokensOnUnicode(e){const t=this.decode(e,{decode_with_timestamps:!0}),s=[],o=[],n=[];let r=[],a=[],i=0;for(let l=0;l=this.model.tokens_to_ids.get("<|endoftext|>"),h=l.startsWith(" "),p=l.trim(),_=i.test(p);if(u||h||_||0===n.length)n.push(l),r.push(c),a.push(d);else{const e=n.length-1;n[e]+=l,r[e].push(...c),a[e].push(...d)}}return[n,r,a]}mergePunctuations(e,t,s,n,r){const a=structuredClone(e),i=structuredClone(t),l=structuredClone(s);let c=a.length-2,d=a.length-1;for(;c>=0;)a[c].startsWith(" ")&&n.includes(a[c].trim())?(a[d]=a[c]+a[d],i[d]=(0,o.mergeArrays)(i[c],i[d]),l[d]=(0,o.mergeArrays)(l[c],l[d]),a[c]="",i[c]=[],l[c]=[]):d=c,--c;for(c=0,d=1;de)),i.filter((e=>e.length>0)),l.filter((e=>e.length>0))]}get_decoder_prompt_ids({language:e=null,task:t=null,no_timestamps:s=!0}={}){const o=[];if(e){e=e.toLowerCase();let t=Je.get(e);if(void 0===t){if(!Ye.has(e)){const t=2===e.length?Ye.keys():Ye.values();throw new Error(`Language "${e}" is not supported. Must be one of: ${JSON.stringify(t)}`)}t=e}const s=this.model.tokens_to_ids.get(`<|${t}|>`);if(void 0===s)throw new Error(`Unable to find language "${t}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);o.push(s)}else o.push(null);if(t){if("transcribe"!==(t=t.toLowerCase())&&"translate"!==t)throw new Error(`Task "${t}" is not supported. Must be one of: ["transcribe", "translate"]`);const e=this.model.tokens_to_ids.get(`<|${t}|>`);if(void 0===e)throw new Error(`Unable to find task "${t}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);o.push(e)}else o.push(null);if(s){const e=this.model.tokens_to_ids.get("<|notimestamps|>");if(void 0===e)throw new Error('Unable to find "<|notimestamps|>" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.');o.push(e)}return o.map(((e,t)=>[t+1,e])).filter((e=>null!==e[1]))}}class Ke extends _e{}class et extends _e{}class tt extends _e{}class st extends _e{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter((e=>this.languageRegex.test(e))),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(null===e)return null;const[t,...s]=e.trim().split(this.languageRegex);if(0===s.length)return super._encode_text(t);if(2===s.length){const[e,t]=s;return this.supported_language_codes.includes(e)||console.warn(`Unsupported language code "${e}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),(0,o.mergeArrays)([e],super._encode_text(t))}}}class ot extends _e{}class nt extends _e{_default_chat_template="{% for message in messages %}{% if message['role'] == 'user' %}{{ ' ' }}{% endif %}{{ message['content'] }}{% if not loop.last %}{{ ' ' }}{% endif %}{% endfor %}{{ eos_token }}"}class rt extends nt{}class at extends _e{}class it extends _e{}class lt extends _e{constructor(e,t){super(e,t),this.decoder=new oe({})}}class ct extends _e{}class dt{static TOKENIZER_CLASS_MAPPING={T5Tokenizer:ve,DistilBertTokenizer:ye,CamembertTokenizer:Fe,DebertaTokenizer:we,DebertaV2Tokenizer:Te,BertTokenizer:me,HerbertTokenizer:ke,ConvBertTokenizer:be,RoFormerTokenizer:xe,XLMTokenizer:Ce,ElectraTokenizer:Pe,MobileBertTokenizer:ge,SqueezeBertTokenizer:Me,AlbertTokenizer:fe,GPT2Tokenizer:Se,BartTokenizer:Ae,MBartTokenizer:Le,MBart50Tokenizer:Ee,RobertaTokenizer:ze,WhisperTokenizer:Ze,CodeGenTokenizer:Ke,CLIPTokenizer:et,SiglipTokenizer:tt,MarianTokenizer:st,BloomTokenizer:Be,NllbTokenizer:Xe,M2M100Tokenizer:Qe,LlamaTokenizer:Oe,CodeLlamaTokenizer:De,XLMRobertaTokenizer:Ne,MPNetTokenizer:Ve,FalconTokenizer:qe,GPTNeoXTokenizer:je,EsmTokenizer:Re,Wav2Vec2CTCTokenizer:ot,BlenderbotTokenizer:nt,BlenderbotSmallTokenizer:rt,SpeechT5Tokenizer:at,NougatTokenizer:it,VitsTokenizer:lt,Qwen2Tokenizer:Ge,GemmaTokenizer:We,Grok1Tokenizer:$e,CohereTokenizer:ct,PreTrainedTokenizer:_e};static async from_pretrained(e,{quantized:t=!0,progress_callback:s=null,config:o=null,cache_dir:n=null,local_files_only:r=!1,revision:a="main",legacy:i=null}={}){const[l,d]=await c(e,{quantized:t,progress_callback:s,config:o,cache_dir:n,local_files_only:r,revision:a,legacy:i}),u=d.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer";let h=this.TOKENIZER_CLASS_MAPPING[u];return h||(console.warn(`Unknown tokenizer class "${u}", attempting to construct from base class.`),h=_e),new h(l,d)}}},"./src/transformers.js": +/*!*****************************!*\ + !*** ./src/transformers.js ***! + \*****************************/(e,t,s)=>{s.r(t),s.d(t,{ASTFeatureExtractor:()=>i.ASTFeatureExtractor,ASTForAudioClassification:()=>r.ASTForAudioClassification,ASTModel:()=>r.ASTModel,ASTPreTrainedModel:()=>r.ASTPreTrainedModel,AlbertForMaskedLM:()=>r.AlbertForMaskedLM,AlbertForQuestionAnswering:()=>r.AlbertForQuestionAnswering,AlbertForSequenceClassification:()=>r.AlbertForSequenceClassification,AlbertModel:()=>r.AlbertModel,AlbertPreTrainedModel:()=>r.AlbertPreTrainedModel,AlbertTokenizer:()=>a.AlbertTokenizer,AudioClassificationPipeline:()=>o.AudioClassificationPipeline,AutoConfig:()=>l.AutoConfig,AutoModel:()=>r.AutoModel,AutoModelForAudioClassification:()=>r.AutoModelForAudioClassification,AutoModelForAudioFrameClassification:()=>r.AutoModelForAudioFrameClassification,AutoModelForCTC:()=>r.AutoModelForCTC,AutoModelForCausalLM:()=>r.AutoModelForCausalLM,AutoModelForDepthEstimation:()=>r.AutoModelForDepthEstimation,AutoModelForDocumentQuestionAnswering:()=>r.AutoModelForDocumentQuestionAnswering,AutoModelForImageClassification:()=>r.AutoModelForImageClassification,AutoModelForImageFeatureExtraction:()=>r.AutoModelForImageFeatureExtraction,AutoModelForImageMatting:()=>r.AutoModelForImageMatting,AutoModelForImageSegmentation:()=>r.AutoModelForImageSegmentation,AutoModelForImageToImage:()=>r.AutoModelForImageToImage,AutoModelForMaskGeneration:()=>r.AutoModelForMaskGeneration,AutoModelForMaskedLM:()=>r.AutoModelForMaskedLM,AutoModelForObjectDetection:()=>r.AutoModelForObjectDetection,AutoModelForQuestionAnswering:()=>r.AutoModelForQuestionAnswering,AutoModelForSemanticSegmentation:()=>r.AutoModelForSemanticSegmentation,AutoModelForSeq2SeqLM:()=>r.AutoModelForSeq2SeqLM,AutoModelForSequenceClassification:()=>r.AutoModelForSequenceClassification,AutoModelForSpeechSeq2Seq:()=>r.AutoModelForSpeechSeq2Seq,AutoModelForTextToSpectrogram:()=>r.AutoModelForTextToSpectrogram,AutoModelForTextToWaveform:()=>r.AutoModelForTextToWaveform,AutoModelForTokenClassification:()=>r.AutoModelForTokenClassification,AutoModelForVision2Seq:()=>r.AutoModelForVision2Seq,AutoModelForXVector:()=>r.AutoModelForXVector,AutoModelForZeroShotObjectDetection:()=>r.AutoModelForZeroShotObjectDetection,AutoProcessor:()=>i.AutoProcessor,AutoTokenizer:()=>a.AutoTokenizer,AutomaticSpeechRecognitionPipeline:()=>o.AutomaticSpeechRecognitionPipeline,BartForConditionalGeneration:()=>r.BartForConditionalGeneration,BartForSequenceClassification:()=>r.BartForSequenceClassification,BartModel:()=>r.BartModel,BartPretrainedModel:()=>r.BartPretrainedModel,BartTokenizer:()=>a.BartTokenizer,BaseModelOutput:()=>r.BaseModelOutput,BeitFeatureExtractor:()=>i.BeitFeatureExtractor,BeitForImageClassification:()=>r.BeitForImageClassification,BeitModel:()=>r.BeitModel,BeitPreTrainedModel:()=>r.BeitPreTrainedModel,BertForMaskedLM:()=>r.BertForMaskedLM,BertForQuestionAnswering:()=>r.BertForQuestionAnswering,BertForSequenceClassification:()=>r.BertForSequenceClassification,BertForTokenClassification:()=>r.BertForTokenClassification,BertModel:()=>r.BertModel,BertPreTrainedModel:()=>r.BertPreTrainedModel,BertTokenizer:()=>a.BertTokenizer,BitImageProcessor:()=>i.BitImageProcessor,BlenderbotForConditionalGeneration:()=>r.BlenderbotForConditionalGeneration,BlenderbotModel:()=>r.BlenderbotModel,BlenderbotPreTrainedModel:()=>r.BlenderbotPreTrainedModel,BlenderbotSmallForConditionalGeneration:()=>r.BlenderbotSmallForConditionalGeneration,BlenderbotSmallModel:()=>r.BlenderbotSmallModel,BlenderbotSmallPreTrainedModel:()=>r.BlenderbotSmallPreTrainedModel,BlenderbotSmallTokenizer:()=>a.BlenderbotSmallTokenizer,BlenderbotTokenizer:()=>a.BlenderbotTokenizer,BloomForCausalLM:()=>r.BloomForCausalLM,BloomModel:()=>r.BloomModel,BloomPreTrainedModel:()=>r.BloomPreTrainedModel,BloomTokenizer:()=>a.BloomTokenizer,CLIPFeatureExtractor:()=>i.CLIPFeatureExtractor,CLIPModel:()=>r.CLIPModel,CLIPPreTrainedModel:()=>r.CLIPPreTrainedModel,CLIPSegForImageSegmentation:()=>r.CLIPSegForImageSegmentation,CLIPSegModel:()=>r.CLIPSegModel,CLIPSegPreTrainedModel:()=>r.CLIPSegPreTrainedModel,CLIPTextModelWithProjection:()=>r.CLIPTextModelWithProjection,CLIPTokenizer:()=>a.CLIPTokenizer,CLIPVisionModelWithProjection:()=>r.CLIPVisionModelWithProjection,CamembertForMaskedLM:()=>r.CamembertForMaskedLM,CamembertForQuestionAnswering:()=>r.CamembertForQuestionAnswering,CamembertForSequenceClassification:()=>r.CamembertForSequenceClassification,CamembertForTokenClassification:()=>r.CamembertForTokenClassification,CamembertModel:()=>r.CamembertModel,CamembertPreTrainedModel:()=>r.CamembertPreTrainedModel,CamembertTokenizer:()=>a.CamembertTokenizer,CausalLMOutput:()=>r.CausalLMOutput,CausalLMOutputWithPast:()=>r.CausalLMOutputWithPast,ChineseCLIPFeatureExtractor:()=>i.ChineseCLIPFeatureExtractor,ChineseCLIPModel:()=>r.ChineseCLIPModel,ChineseCLIPPreTrainedModel:()=>r.ChineseCLIPPreTrainedModel,ClapAudioModelWithProjection:()=>r.ClapAudioModelWithProjection,ClapFeatureExtractor:()=>i.ClapFeatureExtractor,ClapModel:()=>r.ClapModel,ClapPreTrainedModel:()=>r.ClapPreTrainedModel,ClapTextModelWithProjection:()=>r.ClapTextModelWithProjection,CodeGenForCausalLM:()=>r.CodeGenForCausalLM,CodeGenModel:()=>r.CodeGenModel,CodeGenPreTrainedModel:()=>r.CodeGenPreTrainedModel,CodeGenTokenizer:()=>a.CodeGenTokenizer,CodeLlamaTokenizer:()=>a.CodeLlamaTokenizer,CohereTokenizer:()=>a.CohereTokenizer,ConvBertForMaskedLM:()=>r.ConvBertForMaskedLM,ConvBertForQuestionAnswering:()=>r.ConvBertForQuestionAnswering,ConvBertForSequenceClassification:()=>r.ConvBertForSequenceClassification,ConvBertForTokenClassification:()=>r.ConvBertForTokenClassification,ConvBertModel:()=>r.ConvBertModel,ConvBertPreTrainedModel:()=>r.ConvBertPreTrainedModel,ConvBertTokenizer:()=>a.ConvBertTokenizer,ConvNextFeatureExtractor:()=>i.ConvNextFeatureExtractor,ConvNextForImageClassification:()=>r.ConvNextForImageClassification,ConvNextImageProcessor:()=>i.ConvNextImageProcessor,ConvNextModel:()=>r.ConvNextModel,ConvNextPreTrainedModel:()=>r.ConvNextPreTrainedModel,ConvNextV2ForImageClassification:()=>r.ConvNextV2ForImageClassification,ConvNextV2Model:()=>r.ConvNextV2Model,ConvNextV2PreTrainedModel:()=>r.ConvNextV2PreTrainedModel,DPTFeatureExtractor:()=>i.DPTFeatureExtractor,DPTForDepthEstimation:()=>r.DPTForDepthEstimation,DPTImageProcessor:()=>i.DPTImageProcessor,DPTModel:()=>r.DPTModel,DPTPreTrainedModel:()=>r.DPTPreTrainedModel,DebertaForMaskedLM:()=>r.DebertaForMaskedLM,DebertaForQuestionAnswering:()=>r.DebertaForQuestionAnswering,DebertaForSequenceClassification:()=>r.DebertaForSequenceClassification,DebertaForTokenClassification:()=>r.DebertaForTokenClassification,DebertaModel:()=>r.DebertaModel,DebertaPreTrainedModel:()=>r.DebertaPreTrainedModel,DebertaTokenizer:()=>a.DebertaTokenizer,DebertaV2ForMaskedLM:()=>r.DebertaV2ForMaskedLM,DebertaV2ForQuestionAnswering:()=>r.DebertaV2ForQuestionAnswering,DebertaV2ForSequenceClassification:()=>r.DebertaV2ForSequenceClassification,DebertaV2ForTokenClassification:()=>r.DebertaV2ForTokenClassification,DebertaV2Model:()=>r.DebertaV2Model,DebertaV2PreTrainedModel:()=>r.DebertaV2PreTrainedModel,DebertaV2Tokenizer:()=>a.DebertaV2Tokenizer,DeiTFeatureExtractor:()=>i.DeiTFeatureExtractor,DeiTForImageClassification:()=>r.DeiTForImageClassification,DeiTModel:()=>r.DeiTModel,DeiTPreTrainedModel:()=>r.DeiTPreTrainedModel,DepthAnythingForDepthEstimation:()=>r.DepthAnythingForDepthEstimation,DepthAnythingPreTrainedModel:()=>r.DepthAnythingPreTrainedModel,DepthEstimationPipeline:()=>o.DepthEstimationPipeline,DetrFeatureExtractor:()=>i.DetrFeatureExtractor,DetrForObjectDetection:()=>r.DetrForObjectDetection,DetrForSegmentation:()=>r.DetrForSegmentation,DetrModel:()=>r.DetrModel,DetrObjectDetectionOutput:()=>r.DetrObjectDetectionOutput,DetrPreTrainedModel:()=>r.DetrPreTrainedModel,DetrSegmentationOutput:()=>r.DetrSegmentationOutput,Dinov2ForImageClassification:()=>r.Dinov2ForImageClassification,Dinov2Model:()=>r.Dinov2Model,Dinov2PreTrainedModel:()=>r.Dinov2PreTrainedModel,DistilBertForMaskedLM:()=>r.DistilBertForMaskedLM,DistilBertForQuestionAnswering:()=>r.DistilBertForQuestionAnswering,DistilBertForSequenceClassification:()=>r.DistilBertForSequenceClassification,DistilBertForTokenClassification:()=>r.DistilBertForTokenClassification,DistilBertModel:()=>r.DistilBertModel,DistilBertPreTrainedModel:()=>r.DistilBertPreTrainedModel,DistilBertTokenizer:()=>a.DistilBertTokenizer,DocumentQuestionAnsweringPipeline:()=>o.DocumentQuestionAnsweringPipeline,DonutFeatureExtractor:()=>i.DonutFeatureExtractor,DonutSwinModel:()=>r.DonutSwinModel,DonutSwinPreTrainedModel:()=>r.DonutSwinPreTrainedModel,EfficientNetForImageClassification:()=>r.EfficientNetForImageClassification,EfficientNetImageProcessor:()=>i.EfficientNetImageProcessor,EfficientNetModel:()=>r.EfficientNetModel,EfficientNetPreTrainedModel:()=>r.EfficientNetPreTrainedModel,ElectraForMaskedLM:()=>r.ElectraForMaskedLM,ElectraForQuestionAnswering:()=>r.ElectraForQuestionAnswering,ElectraForSequenceClassification:()=>r.ElectraForSequenceClassification,ElectraForTokenClassification:()=>r.ElectraForTokenClassification,ElectraModel:()=>r.ElectraModel,ElectraPreTrainedModel:()=>r.ElectraPreTrainedModel,ElectraTokenizer:()=>a.ElectraTokenizer,EsmForMaskedLM:()=>r.EsmForMaskedLM,EsmForSequenceClassification:()=>r.EsmForSequenceClassification,EsmForTokenClassification:()=>r.EsmForTokenClassification,EsmModel:()=>r.EsmModel,EsmPreTrainedModel:()=>r.EsmPreTrainedModel,EsmTokenizer:()=>a.EsmTokenizer,FFT:()=>h.FFT,FalconForCausalLM:()=>r.FalconForCausalLM,FalconModel:()=>r.FalconModel,FalconPreTrainedModel:()=>r.FalconPreTrainedModel,FalconTokenizer:()=>a.FalconTokenizer,FeatureExtractionPipeline:()=>o.FeatureExtractionPipeline,FeatureExtractor:()=>i.FeatureExtractor,FillMaskPipeline:()=>o.FillMaskPipeline,GLPNFeatureExtractor:()=>i.GLPNFeatureExtractor,GLPNForDepthEstimation:()=>r.GLPNForDepthEstimation,GLPNModel:()=>r.GLPNModel,GLPNPreTrainedModel:()=>r.GLPNPreTrainedModel,GPT2LMHeadModel:()=>r.GPT2LMHeadModel,GPT2Model:()=>r.GPT2Model,GPT2PreTrainedModel:()=>r.GPT2PreTrainedModel,GPT2Tokenizer:()=>a.GPT2Tokenizer,GPTBigCodeForCausalLM:()=>r.GPTBigCodeForCausalLM,GPTBigCodeModel:()=>r.GPTBigCodeModel,GPTBigCodePreTrainedModel:()=>r.GPTBigCodePreTrainedModel,GPTJForCausalLM:()=>r.GPTJForCausalLM,GPTJModel:()=>r.GPTJModel,GPTJPreTrainedModel:()=>r.GPTJPreTrainedModel,GPTNeoForCausalLM:()=>r.GPTNeoForCausalLM,GPTNeoModel:()=>r.GPTNeoModel,GPTNeoPreTrainedModel:()=>r.GPTNeoPreTrainedModel,GPTNeoXForCausalLM:()=>r.GPTNeoXForCausalLM,GPTNeoXModel:()=>r.GPTNeoXModel,GPTNeoXPreTrainedModel:()=>r.GPTNeoXPreTrainedModel,GPTNeoXTokenizer:()=>a.GPTNeoXTokenizer,GemmaTokenizer:()=>a.GemmaTokenizer,Grok1Tokenizer:()=>a.Grok1Tokenizer,HerbertTokenizer:()=>a.HerbertTokenizer,HubertForCTC:()=>r.HubertForCTC,HubertForSequenceClassification:()=>r.HubertForSequenceClassification,HubertModel:()=>r.HubertModel,HubertPreTrainedModel:()=>r.HubertPreTrainedModel,ImageClassificationPipeline:()=>o.ImageClassificationPipeline,ImageFeatureExtractionPipeline:()=>o.ImageFeatureExtractionPipeline,ImageFeatureExtractor:()=>i.ImageFeatureExtractor,ImageMattingOutput:()=>r.ImageMattingOutput,ImageSegmentationPipeline:()=>o.ImageSegmentationPipeline,ImageToImagePipeline:()=>o.ImageToImagePipeline,ImageToTextPipeline:()=>o.ImageToTextPipeline,LlamaForCausalLM:()=>r.LlamaForCausalLM,LlamaModel:()=>r.LlamaModel,LlamaPreTrainedModel:()=>r.LlamaPreTrainedModel,LlamaTokenizer:()=>a.LlamaTokenizer,LongT5ForConditionalGeneration:()=>r.LongT5ForConditionalGeneration,LongT5Model:()=>r.LongT5Model,LongT5PreTrainedModel:()=>r.LongT5PreTrainedModel,M2M100ForConditionalGeneration:()=>r.M2M100ForConditionalGeneration,M2M100Model:()=>r.M2M100Model,M2M100PreTrainedModel:()=>r.M2M100PreTrainedModel,M2M100Tokenizer:()=>a.M2M100Tokenizer,MBart50Tokenizer:()=>a.MBart50Tokenizer,MBartForCausalLM:()=>r.MBartForCausalLM,MBartForConditionalGeneration:()=>r.MBartForConditionalGeneration,MBartForSequenceClassification:()=>r.MBartForSequenceClassification,MBartModel:()=>r.MBartModel,MBartPreTrainedModel:()=>r.MBartPreTrainedModel,MBartTokenizer:()=>a.MBartTokenizer,MPNetForMaskedLM:()=>r.MPNetForMaskedLM,MPNetForQuestionAnswering:()=>r.MPNetForQuestionAnswering,MPNetForSequenceClassification:()=>r.MPNetForSequenceClassification,MPNetForTokenClassification:()=>r.MPNetForTokenClassification,MPNetModel:()=>r.MPNetModel,MPNetPreTrainedModel:()=>r.MPNetPreTrainedModel,MPNetTokenizer:()=>a.MPNetTokenizer,MT5ForConditionalGeneration:()=>r.MT5ForConditionalGeneration,MT5Model:()=>r.MT5Model,MT5PreTrainedModel:()=>r.MT5PreTrainedModel,MarianMTModel:()=>r.MarianMTModel,MarianModel:()=>r.MarianModel,MarianPreTrainedModel:()=>r.MarianPreTrainedModel,MarianTokenizer:()=>a.MarianTokenizer,MaskedLMOutput:()=>r.MaskedLMOutput,MistralForCausalLM:()=>r.MistralForCausalLM,MistralModel:()=>r.MistralModel,MistralPreTrainedModel:()=>r.MistralPreTrainedModel,MobileBertForMaskedLM:()=>r.MobileBertForMaskedLM,MobileBertForQuestionAnswering:()=>r.MobileBertForQuestionAnswering,MobileBertForSequenceClassification:()=>r.MobileBertForSequenceClassification,MobileBertModel:()=>r.MobileBertModel,MobileBertPreTrainedModel:()=>r.MobileBertPreTrainedModel,MobileBertTokenizer:()=>a.MobileBertTokenizer,MobileViTFeatureExtractor:()=>i.MobileViTFeatureExtractor,MobileViTForImageClassification:()=>r.MobileViTForImageClassification,MobileViTModel:()=>r.MobileViTModel,MobileViTPreTrainedModel:()=>r.MobileViTPreTrainedModel,ModelOutput:()=>r.ModelOutput,MptForCausalLM:()=>r.MptForCausalLM,MptModel:()=>r.MptModel,MptPreTrainedModel:()=>r.MptPreTrainedModel,NllbTokenizer:()=>a.NllbTokenizer,NomicBertModel:()=>r.NomicBertModel,NomicBertPreTrainedModel:()=>r.NomicBertPreTrainedModel,NougatImageProcessor:()=>i.NougatImageProcessor,NougatTokenizer:()=>a.NougatTokenizer,OPTForCausalLM:()=>r.OPTForCausalLM,OPTModel:()=>r.OPTModel,OPTPreTrainedModel:()=>r.OPTPreTrainedModel,ObjectDetectionPipeline:()=>o.ObjectDetectionPipeline,OwlViTFeatureExtractor:()=>i.OwlViTFeatureExtractor,OwlViTForObjectDetection:()=>r.OwlViTForObjectDetection,OwlViTModel:()=>r.OwlViTModel,OwlViTPreTrainedModel:()=>r.OwlViTPreTrainedModel,OwlViTProcessor:()=>i.OwlViTProcessor,Owlv2ForObjectDetection:()=>r.Owlv2ForObjectDetection,Owlv2ImageProcessor:()=>i.Owlv2ImageProcessor,Owlv2Model:()=>r.Owlv2Model,Owlv2PreTrainedModel:()=>r.Owlv2PreTrainedModel,PhiForCausalLM:()=>r.PhiForCausalLM,PhiModel:()=>r.PhiModel,PhiPreTrainedModel:()=>r.PhiPreTrainedModel,Pipeline:()=>o.Pipeline,PreTrainedModel:()=>r.PreTrainedModel,PreTrainedTokenizer:()=>a.PreTrainedTokenizer,PretrainedConfig:()=>l.PretrainedConfig,PretrainedMixin:()=>r.PretrainedMixin,Processor:()=>i.Processor,QuestionAnsweringModelOutput:()=>r.QuestionAnsweringModelOutput,QuestionAnsweringPipeline:()=>o.QuestionAnsweringPipeline,Qwen2ForCausalLM:()=>r.Qwen2ForCausalLM,Qwen2Model:()=>r.Qwen2Model,Qwen2PreTrainedModel:()=>r.Qwen2PreTrainedModel,Qwen2Tokenizer:()=>a.Qwen2Tokenizer,RawImage:()=>d.RawImage,ResNetForImageClassification:()=>r.ResNetForImageClassification,ResNetModel:()=>r.ResNetModel,ResNetPreTrainedModel:()=>r.ResNetPreTrainedModel,RoFormerForMaskedLM:()=>r.RoFormerForMaskedLM,RoFormerForQuestionAnswering:()=>r.RoFormerForQuestionAnswering,RoFormerForSequenceClassification:()=>r.RoFormerForSequenceClassification,RoFormerForTokenClassification:()=>r.RoFormerForTokenClassification,RoFormerModel:()=>r.RoFormerModel,RoFormerPreTrainedModel:()=>r.RoFormerPreTrainedModel,RoFormerTokenizer:()=>a.RoFormerTokenizer,RobertaForMaskedLM:()=>r.RobertaForMaskedLM,RobertaForQuestionAnswering:()=>r.RobertaForQuestionAnswering,RobertaForSequenceClassification:()=>r.RobertaForSequenceClassification,RobertaForTokenClassification:()=>r.RobertaForTokenClassification,RobertaModel:()=>r.RobertaModel,RobertaPreTrainedModel:()=>r.RobertaPreTrainedModel,RobertaTokenizer:()=>a.RobertaTokenizer,SamImageProcessor:()=>i.SamImageProcessor,SamImageSegmentationOutput:()=>r.SamImageSegmentationOutput,SamModel:()=>r.SamModel,SamPreTrainedModel:()=>r.SamPreTrainedModel,SamProcessor:()=>i.SamProcessor,SeamlessM4TFeatureExtractor:()=>i.SeamlessM4TFeatureExtractor,SegformerFeatureExtractor:()=>i.SegformerFeatureExtractor,SegformerForImageClassification:()=>r.SegformerForImageClassification,SegformerForSemanticSegmentation:()=>r.SegformerForSemanticSegmentation,SegformerModel:()=>r.SegformerModel,SegformerPreTrainedModel:()=>r.SegformerPreTrainedModel,Seq2SeqLMOutput:()=>r.Seq2SeqLMOutput,SequenceClassifierOutput:()=>r.SequenceClassifierOutput,SiglipImageProcessor:()=>i.SiglipImageProcessor,SiglipModel:()=>r.SiglipModel,SiglipPreTrainedModel:()=>r.SiglipPreTrainedModel,SiglipTextModel:()=>r.SiglipTextModel,SiglipTokenizer:()=>a.SiglipTokenizer,SiglipVisionModel:()=>r.SiglipVisionModel,SpeechT5FeatureExtractor:()=>i.SpeechT5FeatureExtractor,SpeechT5ForSpeechToText:()=>r.SpeechT5ForSpeechToText,SpeechT5ForTextToSpeech:()=>r.SpeechT5ForTextToSpeech,SpeechT5HifiGan:()=>r.SpeechT5HifiGan,SpeechT5Model:()=>r.SpeechT5Model,SpeechT5PreTrainedModel:()=>r.SpeechT5PreTrainedModel,SpeechT5Processor:()=>i.SpeechT5Processor,SpeechT5Tokenizer:()=>a.SpeechT5Tokenizer,SqueezeBertForMaskedLM:()=>r.SqueezeBertForMaskedLM,SqueezeBertForQuestionAnswering:()=>r.SqueezeBertForQuestionAnswering,SqueezeBertForSequenceClassification:()=>r.SqueezeBertForSequenceClassification,SqueezeBertModel:()=>r.SqueezeBertModel,SqueezeBertPreTrainedModel:()=>r.SqueezeBertPreTrainedModel,SqueezeBertTokenizer:()=>a.SqueezeBertTokenizer,StableLmForCausalLM:()=>r.StableLmForCausalLM,StableLmModel:()=>r.StableLmModel,StableLmPreTrainedModel:()=>r.StableLmPreTrainedModel,Starcoder2ForCausalLM:()=>r.Starcoder2ForCausalLM,Starcoder2Model:()=>r.Starcoder2Model,Starcoder2PreTrainedModel:()=>r.Starcoder2PreTrainedModel,SummarizationPipeline:()=>o.SummarizationPipeline,Swin2SRForImageSuperResolution:()=>r.Swin2SRForImageSuperResolution,Swin2SRImageProcessor:()=>i.Swin2SRImageProcessor,Swin2SRModel:()=>r.Swin2SRModel,Swin2SRPreTrainedModel:()=>r.Swin2SRPreTrainedModel,SwinForImageClassification:()=>r.SwinForImageClassification,SwinModel:()=>r.SwinModel,SwinPreTrainedModel:()=>r.SwinPreTrainedModel,T5ForConditionalGeneration:()=>r.T5ForConditionalGeneration,T5Model:()=>r.T5Model,T5PreTrainedModel:()=>r.T5PreTrainedModel,T5Tokenizer:()=>a.T5Tokenizer,TableTransformerForObjectDetection:()=>r.TableTransformerForObjectDetection,TableTransformerModel:()=>r.TableTransformerModel,TableTransformerObjectDetectionOutput:()=>r.TableTransformerObjectDetectionOutput,TableTransformerPreTrainedModel:()=>r.TableTransformerPreTrainedModel,Tensor:()=>u.Tensor,Text2TextGenerationPipeline:()=>o.Text2TextGenerationPipeline,TextClassificationPipeline:()=>o.TextClassificationPipeline,TextGenerationPipeline:()=>o.TextGenerationPipeline,TextToAudioPipeline:()=>o.TextToAudioPipeline,TokenClassificationPipeline:()=>o.TokenClassificationPipeline,TokenClassifierOutput:()=>r.TokenClassifierOutput,TokenizerModel:()=>a.TokenizerModel,TrOCRForCausalLM:()=>r.TrOCRForCausalLM,TrOCRPreTrainedModel:()=>r.TrOCRPreTrainedModel,TranslationPipeline:()=>o.TranslationPipeline,UniSpeechForCTC:()=>r.UniSpeechForCTC,UniSpeechForSequenceClassification:()=>r.UniSpeechForSequenceClassification,UniSpeechModel:()=>r.UniSpeechModel,UniSpeechPreTrainedModel:()=>r.UniSpeechPreTrainedModel,UniSpeechSatForAudioFrameClassification:()=>r.UniSpeechSatForAudioFrameClassification,UniSpeechSatForCTC:()=>r.UniSpeechSatForCTC,UniSpeechSatForSequenceClassification:()=>r.UniSpeechSatForSequenceClassification,UniSpeechSatModel:()=>r.UniSpeechSatModel,UniSpeechSatPreTrainedModel:()=>r.UniSpeechSatPreTrainedModel,ViTFeatureExtractor:()=>i.ViTFeatureExtractor,ViTForImageClassification:()=>r.ViTForImageClassification,ViTImageProcessor:()=>i.ViTImageProcessor,ViTModel:()=>r.ViTModel,ViTPreTrainedModel:()=>r.ViTPreTrainedModel,VisionEncoderDecoderModel:()=>r.VisionEncoderDecoderModel,VitMatteForImageMatting:()=>r.VitMatteForImageMatting,VitMatteImageProcessor:()=>i.VitMatteImageProcessor,VitMattePreTrainedModel:()=>r.VitMattePreTrainedModel,VitsModel:()=>r.VitsModel,VitsModelOutput:()=>r.VitsModelOutput,VitsPreTrainedModel:()=>r.VitsPreTrainedModel,VitsTokenizer:()=>a.VitsTokenizer,Wav2Vec2BertForCTC:()=>r.Wav2Vec2BertForCTC,Wav2Vec2BertForSequenceClassification:()=>r.Wav2Vec2BertForSequenceClassification,Wav2Vec2BertModel:()=>r.Wav2Vec2BertModel,Wav2Vec2BertPreTrainedModel:()=>r.Wav2Vec2BertPreTrainedModel,Wav2Vec2CTCTokenizer:()=>a.Wav2Vec2CTCTokenizer,Wav2Vec2FeatureExtractor:()=>i.Wav2Vec2FeatureExtractor,Wav2Vec2ForAudioFrameClassification:()=>r.Wav2Vec2ForAudioFrameClassification,Wav2Vec2ForCTC:()=>r.Wav2Vec2ForCTC,Wav2Vec2ForSequenceClassification:()=>r.Wav2Vec2ForSequenceClassification,Wav2Vec2Model:()=>r.Wav2Vec2Model,Wav2Vec2PreTrainedModel:()=>r.Wav2Vec2PreTrainedModel,Wav2Vec2ProcessorWithLM:()=>i.Wav2Vec2ProcessorWithLM,WavLMForAudioFrameClassification:()=>r.WavLMForAudioFrameClassification,WavLMForCTC:()=>r.WavLMForCTC,WavLMForSequenceClassification:()=>r.WavLMForSequenceClassification,WavLMForXVector:()=>r.WavLMForXVector,WavLMModel:()=>r.WavLMModel,WavLMPreTrainedModel:()=>r.WavLMPreTrainedModel,WhisperFeatureExtractor:()=>i.WhisperFeatureExtractor,WhisperForConditionalGeneration:()=>r.WhisperForConditionalGeneration,WhisperModel:()=>r.WhisperModel,WhisperPreTrainedModel:()=>r.WhisperPreTrainedModel,WhisperProcessor:()=>i.WhisperProcessor,WhisperTokenizer:()=>a.WhisperTokenizer,XLMForQuestionAnswering:()=>r.XLMForQuestionAnswering,XLMForSequenceClassification:()=>r.XLMForSequenceClassification,XLMForTokenClassification:()=>r.XLMForTokenClassification,XLMModel:()=>r.XLMModel,XLMPreTrainedModel:()=>r.XLMPreTrainedModel,XLMRobertaForMaskedLM:()=>r.XLMRobertaForMaskedLM,XLMRobertaForQuestionAnswering:()=>r.XLMRobertaForQuestionAnswering,XLMRobertaForSequenceClassification:()=>r.XLMRobertaForSequenceClassification,XLMRobertaForTokenClassification:()=>r.XLMRobertaForTokenClassification,XLMRobertaModel:()=>r.XLMRobertaModel,XLMRobertaPreTrainedModel:()=>r.XLMRobertaPreTrainedModel,XLMRobertaTokenizer:()=>a.XLMRobertaTokenizer,XLMTokenizer:()=>a.XLMTokenizer,XLMWithLMHeadModel:()=>r.XLMWithLMHeadModel,XVectorOutput:()=>r.XVectorOutput,YolosFeatureExtractor:()=>i.YolosFeatureExtractor,YolosForObjectDetection:()=>r.YolosForObjectDetection,YolosModel:()=>r.YolosModel,YolosObjectDetectionOutput:()=>r.YolosObjectDetectionOutput,YolosPreTrainedModel:()=>r.YolosPreTrainedModel,ZeroShotAudioClassificationPipeline:()=>o.ZeroShotAudioClassificationPipeline,ZeroShotClassificationPipeline:()=>o.ZeroShotClassificationPipeline,ZeroShotImageClassificationPipeline:()=>o.ZeroShotImageClassificationPipeline,ZeroShotObjectDetectionPipeline:()=>o.ZeroShotObjectDetectionPipeline,bankers_round:()=>h.bankers_round,cat:()=>u.cat,cos_sim:()=>h.cos_sim,dot:()=>h.dot,dynamicTimeWarping:()=>u.dynamicTimeWarping,env:()=>n.env,getTopItems:()=>h.getTopItems,hanning:()=>c.hanning,interpolate:()=>u.interpolate,interpolate_data:()=>h.interpolate_data,layer_norm:()=>u.layer_norm,log_softmax:()=>h.log_softmax,magnitude:()=>h.magnitude,max:()=>h.max,mean:()=>u.mean,mean_pooling:()=>u.mean_pooling,medianFilter:()=>h.medianFilter,mel_filter_bank:()=>c.mel_filter_bank,min:()=>h.min,ones:()=>u.ones,ones_like:()=>u.ones_like,permute:()=>u.permute,permute_data:()=>h.permute_data,pipeline:()=>o.pipeline,read_audio:()=>c.read_audio,round:()=>h.round,softmax:()=>h.softmax,spectrogram:()=>c.spectrogram,stack:()=>u.stack,std_mean:()=>u.std_mean,window_function:()=>c.window_function});var o=s(/*! ./pipelines.js */"./src/pipelines.js"),n=s(/*! ./env.js */"./src/env.js"),r=s(/*! ./models.js */"./src/models.js"),a=s(/*! ./tokenizers.js */"./src/tokenizers.js"),i=s(/*! ./processors.js */"./src/processors.js"),l=s(/*! ./configs.js */"./src/configs.js"),c=s(/*! ./utils/audio.js */"./src/utils/audio.js"),d=s(/*! ./utils/image.js */"./src/utils/image.js"),u=s(/*! ./utils/tensor.js */"./src/utils/tensor.js"),h=s(/*! ./utils/maths.js */"./src/utils/maths.js")},"./src/utils/audio.js": +/*!****************************!*\ + !*** ./src/utils/audio.js ***! + \****************************/(e,t,s)=>{s.r(t),s.d(t,{hanning:()=>i,mel_filter_bank:()=>h,read_audio:()=>a,spectrogram:()=>_,window_function:()=>m});var o=s(/*! ./hub.js */"./src/utils/hub.js"),n=s(/*! ./maths.js */"./src/utils/maths.js"),r=s(/*! ./core.js */"./src/utils/core.js");async function a(e,t){if("undefined"==typeof AudioContext)throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");const s=await(await(0,o.getFile)(e)).arrayBuffer(),n=new AudioContext({sampleRate:t});void 0===t&&console.warn(`No sampling rate provided, using default of ${n.sampleRate}Hz.`);const r=await n.decodeAudioData(s);let a;if(2===r.numberOfChannels){const e=Math.sqrt(2),t=r.getChannelData(0),s=r.getChannelData(1);a=new Float32Array(t.length);for(let o=0;o2595*Math.log10(1+e/700),kaldi:e=>1127*Math.log(1+e/700),slaney:(e,t=1e3,s=15,o=27/Math.log(6.4))=>e>=t?s+Math.log(e/t)*o:3*e/200};function c(e,t="htk"){const s=l[t];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?s(e):e.map((e=>s(e)))}const d={htk:e=>700*(10**(e/2595)-1),kaldi:e=>700*(Math.exp(e/1127)-1),slaney:(e,t=1e3,s=15,o=Math.log(6.4)/27)=>e>=s?t*Math.exp(o*(e-s)):200*e/3};function u(e,t,s){const o=(t-e)/(s-1);return Float64Array.from({length:s},((t,s)=>e+o*s))}function h(e,t,s,o,n,r=null,a="htk",i=!1){if(null!==r&&"slaney"!==r)throw new Error('norm must be one of null or "slaney"');const l=u(c(s,a),c(o,a),t+2);let h,p=function(e,t="htk"){const s=d[t];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?s(e):e.map((e=>s(e)))}(l,a);if(i){const t=n/(2*e);h=c(Float64Array.from({length:e},((e,s)=>s*t)),a),p=l}else h=u(0,Math.floor(n/2),e);const _=function(e,t){const s=Float64Array.from({length:t.length-1},((e,s)=>t[s+1]-t[s])),o=Array.from({length:e.length},(()=>new Array(t.length)));for(let s=0;snew Array(e.length)));for(let t=0;ta)throw Error(`frame_length (${s}) may not be larger than fft_length (${a})`);if(x!==s)throw new Error(`Length of the window (${x}) must equal frame_length (${s})`);if(o<=0)throw new Error("hop_length must be greater than zero");if(l){if("reflect"!==c)throw new Error(`pad_mode="${c}" not implemented yet.`);const t=Math.floor((a-1)/2)+1;e=function(e,t,s){const o=new e.constructor(e.length+t+s),n=e.length-1;for(let s=0;sy?k&&(P=T):P=C=T);const v=new n.FFT(a),S=new Float64Array(a),A=new Float64Array(v.outputBufferSize),L=new Array(C);for(let n=0;n=1;--e)S[e]-=u*S[e-1];S[0]*=1-u}for(let e=0;eMath.pow(e,.85)));break;default:throw new Error(`Unknown window type ${t}.`)}if(s&&(a=a.subarray(0,e)),null===o)return a;if(e>o)throw new Error(`Length of the window (${e}) may not be larger than frame_length (${o})`);return a}},"./src/utils/core.js": +/*!***************************!*\ + !*** ./src/utils/core.js ***! + \***************************/(e,t,s)=>{function o(e,t){e&&e(t)}function n(e){return Object.fromEntries(Object.entries(e).map((([e,t])=>[t,e])))}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}s.r(t),s.d(t,{Callable:()=>a,calculateDimensions:()=>d,calculateReflectOffset:()=>_,dispatchCallback:()=>o,escapeRegExp:()=>r,exists:()=>c,isIntegralNumber:()=>l,isTypedArray:()=>i,mergeArrays:()=>h,pop:()=>u,product:()=>p,reverseDictionary:()=>n});const a=class{constructor(){let e=function(...t){return e._call(...t)};return Object.setPrototypeOf(e,new.target.prototype)}_call(...e){throw Error("Must implement _call method in subclass")}};function i(e){return"TypedArray"===e?.prototype?.__proto__?.constructor?.name}function l(e){return Number.isInteger(e)||"bigint"==typeof e}function c(e){return null!=e}function d(e){const t=[];let s=e;for(;Array.isArray(s);)t.push(s.length),s=s[0];return t}function u(e,t,s=void 0){const o=e[t];if(void 0!==o)return delete e[t],o;if(void 0===s)throw Error(`Key ${t} does not exist in object.`);return s}function h(...e){return Array.prototype.concat.apply([],e)}function p(...e){return e.reduce(((e,t)=>e.flatMap((e=>t.map((t=>[e,t]))))))}function _(e,t){return Math.abs((e+t)%(2*t)-t)}},"./src/utils/data-structures.js": +/*!**************************************!*\ + !*** ./src/utils/data-structures.js ***! + \**************************************/(e,t,s)=>{s.r(t),s.d(t,{CharTrie:()=>n,PriorityQueue:()=>o,TokenLattice:()=>a});class o{constructor(e=((e,t)=>e>t)){this._heap=[],this._comparator=e}get size(){return this._heap.length}isEmpty(){return 0===this.size}peek(){return this._heap[0]}push(...e){return this.extend(e)}extend(e){for(const t of e)this._heap.push(t),this._siftUp();return this.size}pop(){const e=this.peek(),t=this.size-1;return t>0&&this._swap(0,t),this._heap.pop(),this._siftDown(),e}replace(e){const t=this.peek();return this._heap[0]=e,this._siftDown(),t}_parent(e){return(e+1>>>1)-1}_left(e){return 1+(e<<1)}_right(e){return e+1<<1}_greater(e,t){return this._comparator(this._heap[e],this._heap[t])}_swap(e,t){const s=this._heap[e];this._heap[e]=this._heap[t],this._heap[t]=s}_siftUp(){let e=this.size-1;for(;e>0&&this._greater(e,this._parent(e));)this._swap(e,this._parent(e)),e=this._parent(e)}_siftDown(){let e=0;for(;this._left(e)[])),this.endNodes=Array.from({length:this.len+1},(()=>[]));const o=new i(this.bosTokenId,0,0,0,0),n=new i(this.eosTokenId,1,this.len,0,0);this.nodes.push(o.clone()),this.nodes.push(n.clone()),this.beginNodes[this.len].push(n),this.endNodes[0].push(o)}insert(e,t,s,o){const n=this.nodes.length,r=new i(o,n,e,t,s);this.beginNodes[e].push(r),this.endNodes[e+t].push(r),this.nodes.push(r)}viterbi(){const e=this.len;let t=0;for(;t<=e;){if(0==this.beginNodes[t].length)return[];for(let e of this.beginNodes[t]){e.prev=null;let s=0,o=null;for(let n of this.endNodes[t]){const t=n.backtraceScore+e.score;(null===o||t>s)&&(o=n.clone(),s=t)}if(null===o)return[];e.prev=o,e.backtraceScore=s}++t}const s=[],o=this.beginNodes[e][0].prev;if(null===o)return[];let n=o.clone();for(;null!==n.prev;){s.push(n.clone());const e=n.clone();n=e.prev.clone()}return s.reverse(),s}piece(e){return this.sentence.slice(e.pos,e.pos+e.length)}tokens(){return this.viterbi().map((e=>this.piece(e)))}tokenIds(){return this.viterbi().map((e=>e.tokenId))}}class i{constructor(e,t,s,o,n){this.tokenId=e,this.nodeId=t,this.pos=s,this.length=o,this.score=n,this.prev=null,this.backtraceScore=0}clone(){const e=new i(this.tokenId,this.nodeId,this.pos,this.length,this.score);return e.prev=this.prev,e.backtraceScore=this.backtraceScore,e}}},"./src/utils/generation.js": +/*!*********************************!*\ + !*** ./src/utils/generation.js ***! + \*********************************/(e,t,s)=>{s.r(t),s.d(t,{ForceTokensLogitsProcessor:()=>i,ForcedBOSTokenLogitsProcessor:()=>l,ForcedEOSTokenLogitsProcessor:()=>c,GenerationConfig:()=>g,LogitsProcessor:()=>a,LogitsProcessorList:()=>r,MinLengthLogitsProcessor:()=>_,MinNewTokensLengthLogitsProcessor:()=>m,NoBadWordsLogitsProcessor:()=>f,NoRepeatNGramLogitsProcessor:()=>h,RepetitionPenaltyLogitsProcessor:()=>p,Sampler:()=>M,SuppressTokensAtBeginLogitsProcessor:()=>d,WhisperTimeStampLogitsProcessor:()=>u});s(/*! ./tensor.js */"./src/utils/tensor.js");var o=s(/*! ./core.js */"./src/utils/core.js"),n=s(/*! ./maths.js */"./src/utils/maths.js");class r extends o.Callable{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){for(let s of t)this.processors.forEach((t=>t(e,s)))}[Symbol.iterator](){return this.processors.values()}}class a extends o.Callable{_call(e,t){throw Error("`_call` should be implemented in a subclass")}}class i extends a{constructor(e){super(),this.force_token_map=Object.fromEntries(e??[])}_call(e,t){let s=this.force_token_map[e.length];return(0,o.exists)(s)&&(t.data.fill(-1/0),t.data[s]=0),t}}class l extends a{constructor(e){super(),this.bos_token_id=e}_call(e,t){return 1===e.length&&(t.data.fill(-1/0),t.data[this.bos_token_id]=0),t}}class c extends a{constructor(e,t){super(),this.max_length=e,this.forced_eos_token_id=t}_call(e,t){}}class d extends a{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){if(e.length===this.begin_index)for(let e of this.begin_suppress_tokens)t.data[e]=-1/0;return t}}class u extends a{constructor(e){super(),this.eos_token_id=e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=(e.forced_decoder_ids||[]).length+2,e.forced_decoder_ids.slice(-1)[0][1]===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){const s=t.data;if(s[this.no_timestamps_token_id]=-1/0,e.length===this.begin_index-1)return s.fill(-1/0),s[this.timestamp_begin]=0,t;const o=e.slice(this.begin_index),r=o.length>=1&&o[o.length-1]>=this.timestamp_begin,a=o.length<2||o[o.length-2]>=this.timestamp_begin;if(r&&(a?s.subarray(this.timestamp_begin).fill(-1/0):s.subarray(0,this.eos_token_id).fill(-1/0)),e.length===this.begin_index&&null!==this.max_initial_timestamp_index){const e=this.timestamp_begin+this.max_initial_timestamp_index;s.subarray(e+1).fill(-1/0)}const i=(0,n.log_softmax)(s);return Math.log(i.subarray(this.timestamp_begin).map(Math.exp).reduce(((e,t)=>e+t)))>(0,n.max)(i.subarray(0,this.timestamp_begin))[0]&&s.subarray(0,this.timestamp_begin).fill(-1/0),t}}class h extends a{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){const t=e.length,s=[];for(let o=0;o0&&(o=o.map((e=>e/this.generation_config.temperature))),o}randomSelect(e){let t=e.reduce(((e,t)=>e+t),0),s=Math.random()*t;for(let t=0;t1)return new k(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new w(e)}}class w extends M{sample(e,t=-1){let s=this.getLogits(e,t);return[[(0,n.max)(s)[1],0]]}}class T extends M{sample(e,t=-1){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));const o=this.getLogits(e,t),r=(0,n.getTopItems)(o,s),a=(0,n.softmax)(r.map((e=>e[1])));return Array.from({length:this.generation_config.num_beams},(()=>{const e=this.randomSelect(a);return[r[e][0],Math.log(a[e])]}))}}class k extends M{sample(e,t=-1){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));const o=this.getLogits(e,t),r=(0,n.getTopItems)(o,s),a=(0,n.softmax)(r.map((e=>e[1])));return Array.from({length:this.generation_config.num_beams},((e,t)=>[r[t][0],Math.log(a[t])]))}}},"./src/utils/hub.js": +/*!**************************!*\ + !*** ./src/utils/hub.js ***! + \**************************/(e,t,s)=>{s.r(t),s.d(t,{getFile:()=>d,getModelFile:()=>p,getModelJSON:()=>_});var o=s(/*! fs */"?7a2c"),n=s(/*! path */"?a42a"),r=s(/*! stream/web */"?e65c"),a=s(/*! ../env.js */"./src/env.js"),i=s(/*! ./core.js */"./src/utils/core.js");globalThis.ReadableStream||(globalThis.ReadableStream=r.ReadableStream);class l{_CONTENT_TYPE_MAP={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"};constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=o.existsSync(e),this.exists){this.status=200,this.statusText="OK";let t=o.statSync(e);this.headers.set("content-length",t.size.toString()),this.updateContentType();let s=this;this.body=new ReadableStream({start(e){s.arrayBuffer().then((t=>{e.enqueue(new Uint8Array(t)),e.close()}))}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){const e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",this._CONTENT_TYPE_MAP[e]??"application/octet-stream")}clone(){let e=new l(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await o.promises.readFile(this.filePath)).buffer}async blob(){const e=await o.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await o.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}}function c(e,t=null){let s;try{s=new URL(e)}catch(e){return!1}return!(t&&!t.includes(s.hostname))&&("http:"===s.protocol||"https:"===s.protocol)}async function d(e){if(a.env.useFS&&!c(e))return new l(e);if("undefined"!=typeof process&&"node"===process?.release?.name){const t=!!process.env?.TESTING_REMOTELY,s=a.env.version,o=new Headers;o.set("User-Agent",`transformers.js/${s}; is_ci/${t};`);if(c(e,["huggingface.co","hf.co"])){const e=process.env?.HF_TOKEN??process.env?.HF_ACCESS_TOKEN;e&&o.set("Authorization",`Bearer ${e}`)}return fetch(e,{headers:o})}return fetch(e)}const u={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"};class h{constructor(e){this.path=e}async match(e){let t=n.join(this.path,e),s=new l(t);return s.exists?s:void 0}async put(e,t){const s=Buffer.from(await t.arrayBuffer());let r=n.join(this.path,e);try{await o.promises.mkdir(n.dirname(r),{recursive:!0}),await o.promises.writeFile(r,s)}catch(e){console.warn("An error occurred while writing the file to cache:",e)}}}async function p(e,t,s=!0,o={}){if(!a.env.allowLocalModels){if(o.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!a.env.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}let n;if((0,i.dispatchCallback)(o.progress_callback,{status:"initiate",name:e,file:t}),!n&&a.env.useBrowserCache){if("undefined"==typeof caches)throw Error("Browser cache is not available in this environment.");try{n=await caches.open("transformers-cache")}catch(e){console.warn("An error occurred while opening the browser cache:",e)}}if(!n&&a.env.useFSCache&&(n=new h(o.cache_dir??a.env.cacheDir)),!n&&a.env.useCustomCache){if(!a.env.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!a.env.customCache.match||!a.env.customCache.put)throw new Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");n=a.env.customCache}const r=o.revision??"main";let l,p,_=m(e,t),f=m(a.env.localModelPath,_),g=m(a.env.remoteHost,a.env.remotePathTemplate.replaceAll("{model}",e).replaceAll("{revision}",encodeURIComponent(r)),t),M="main"===r?_:m(e,r,t),w=n instanceof h?M:g,T=!1;n&&(p=await async function(e,...t){for(let s of t)try{let t=await e.match(s);if(t)return t}catch(e){continue}}(n,f,w));const k=void 0!==p;if(void 0===p){if(a.env.allowLocalModels){if(c(_)){if(o.local_files_only)throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${_}.`);if(!a.env.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${_}.`)}else try{p=await d(f),l=f}catch(e){console.warn(`Unable to load from local path "${f}": "${e}"`)}}if(void 0===p||404===p.status){if(o.local_files_only||!a.env.allowRemoteModels){if(s)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${f}".`);return null}if(p=await d(g),200!==p.status)return function(e,t,s){if(!s)return null;const o=u[e]??`Error (${e}) occurred while trying to load file`;throw Error(`${o}: "${t}".`)}(p.status,g,s);l=w}T=n&&"undefined"!=typeof Response&&p instanceof Response&&200===p.status}(0,i.dispatchCallback)(o.progress_callback,{status:"download",name:e,file:t});const b={status:"progress",name:e,file:t};let x;return o.progress_callback?k&&"undefined"!=typeof navigator&&/firefox/i.test(navigator.userAgent)?(x=new Uint8Array(await p.arrayBuffer()),(0,i.dispatchCallback)(o.progress_callback,{...b,progress:100,loaded:x.length,total:x.length})):x=await async function(e,t){const s=e.headers.get("Content-Length");null===s&&console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let o=parseInt(s??"0"),n=new Uint8Array(o),r=0;const a=e.body.getReader();async function i(){const{done:e,value:s}=await a.read();if(e)return;let l=r+s.length;if(l>o){o=l;let e=new Uint8Array(o);e.set(n),n=e}n.set(s,r),r=l;return t({progress:r/o*100,loaded:r,total:o}),i()}return await i(),n}(p,(e=>{(0,i.dispatchCallback)(o.progress_callback,{...b,...e})})):x=new Uint8Array(await p.arrayBuffer()),T&&l&&void 0===await n.match(l)&&await n.put(l,new Response(x,{headers:p.headers})).catch((e=>{console.warn(`Unable to add response to browser cache: ${e}.`)})),(0,i.dispatchCallback)(o.progress_callback,{status:"done",name:e,file:t}),x}async function _(e,t,s=!0,o={}){let n=await p(e,t,s,o);if(null===n)return{};let r=new TextDecoder("utf-8").decode(n);return JSON.parse(r)}function m(...e){return(e=e.map(((t,s)=>(s&&(t=t.replace(new RegExp("^/"),"")),s!==e.length-1&&(t=t.replace(new RegExp("/$"),"")),t)))).join("/")}},"./src/utils/image.js": +/*!****************************!*\ + !*** ./src/utils/image.js ***! + \****************************/(e,t,s)=>{s.r(t),s.d(t,{RawImage:()=>_});var o=s(/*! ./hub.js */"./src/utils/hub.js"),n=s(/*! ../env.js */"./src/env.js"),r=s(/*! ./tensor.js */"./src/utils/tensor.js"),a=s(/*! sharp */"?2b25");const i="undefined"!=typeof self,l=i&&"DedicatedWorkerGlobalScope"===self.constructor.name;let c,d,u;if(i)c=(e,t)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(e,t)},u=self.createImageBitmap,d=self.ImageData;else{if(!a)throw new Error("Unable to load image processing library.");u=async e=>{const t=(await e.metadata()).channels;let{data:s,info:o}=await e.raw().toBuffer({resolveWithObject:!0});const n=new _(new Uint8ClampedArray(s),o.width,o.height,o.channels);return void 0!==t&&t!==o.channels&&n.convert(t),n}}const h={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},p=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]);class _{constructor(e,t,s,o){this.data=e,this.width=t,this.height=s,this.channels=o}get size(){return[this.width,this.height]}static async read(e){if(e instanceof _)return e;if("string"==typeof e||e instanceof URL)return await this.fromURL(e);throw new Error("Unsupported input type: "+typeof e)}static async fromURL(e){let t=await(0,o.getFile)(e);if(200!==t.status)throw new Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);let s=await t.blob();return this.fromBlob(s)}static async fromBlob(e){if(i){let t=await u(e);const s=c(t.width,t.height).getContext("2d");return s.drawImage(t,0,0),new this(s.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}{let t=a(await e.arrayBuffer());return await u(t)}}static fromTensor(e,t="CHW"){if(3!==e.dims.length)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if("CHW"===t)e=e.transpose(1,2,0);else if("HWC"!==t)throw new Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new _(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(1===this.channels)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,s=0;t=0?i=s:d=-s,o>=0?l=o:u=-o,a.drawImage(r,i,l,e,t,d,u,e,t),new _(a.getImageData(0,0,e,t).data,e,t,4).convert(n)}{let n=this.toSharp();if(s>=0&&o>=0)n=n.extract({left:Math.floor(s),top:Math.floor(o),width:e,height:t});else if(s<=0&&o<=0){let r=Math.floor(-o),a=Math.floor(-s);n=n.extend({top:r,left:a,right:e-this.width-a,bottom:t-this.height-r})}else{let r=[0,0],a=0;o<0?(r[0]=Math.floor(-o),r[1]=t-this.height-r[0]):a=Math.floor(o);let i=[0,0],l=0;s<0?(i[0]=Math.floor(-s),i[1]=e-this.width-i[0]):l=Math.floor(s),n=n.extend({top:r[0],bottom:r[1],left:i[0],right:i[1]}).extract({left:l,top:a,width:e,height:t})}return await u(n)}}async toBlob(e="image/png",t=1){if(!i)throw new Error("toBlob() is only supported in browser environments.");const s=this.toCanvas();return await s.convertToBlob({type:e,quality:t})}toTensor(e="CHW"){let t=new r.Tensor("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if("HWC"===e);else{if("CHW"!==e)throw new Error(`Unsupported channel format: ${e}`);t=t.permute(2,0,1)}return t}toCanvas(){if(!i)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),t=c(e.width,e.height),s=new d(e.data,e.width,e.height);return t.getContext("2d").putImageData(s,0,0),t}_update(e,t,s,o=null){return this.data=e,this.width=t,this.height=s,null!==o&&(this.channels=o),this}clone(){return new _(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(!i){if(n.env.useFS){const t=this.toSharp();return await t.toFile(e)}throw new Error("Unable to save the image because filesystem is disabled in this environment.")}{if(l)throw new Error("Unable to save an image from a Web Worker.");const t=e.split(".").pop().toLowerCase(),s=p.get(t)??"image/png",o=await this.toBlob(s),n=URL.createObjectURL(o),r=document.createElement("a");r.href=n,r.download=e,r.click(),r.remove()}}toSharp(){if(i)throw new Error("toSharp() is only supported in server-side environments.");return a(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}},"./src/utils/maths.js": +/*!****************************!*\ + !*** ./src/utils/maths.js ***! + \****************************/(e,t,s)=>{function o(e,[t,s,o],[n,r],a="bilinear",i=!1){const l=r/o,c=n/s,d=new e.constructor(n*r*t),u=s*o,h=n*r;for(let a=0;a=0;--e)n[e]=r,o[e]=t[s[e]],r*=o[e];const r=s.map(((e,t)=>n[s.indexOf(t)])),a=new e.constructor(e.length);for(let s=0;s=0;--e)o+=n%t[e]*r[e],n=Math.floor(n/t[e]);a[o]=e[s]}return[a,o]}function r(e){const t=h(e)[0],s=e.map((e=>Math.exp(e-t))),o=s.reduce(((e,t)=>e+t),0);return s.map((e=>e/o))}function a(e){return r(e).map((e=>Math.log(e)))}function i(e,t){return e.reduce(((e,s,o)=>e+s*t[o]),0)}function l(e,t=0){return e=Array.from(e).map(((e,t)=>[t,e])).sort(((e,t)=>t[1]-e[1])),null!==t&&t>0&&(e=e.slice(0,t)),e}function c(e,t){return i(e,t)/(d(e)*d(t))}function d(e){return Math.sqrt(e.reduce(((e,t)=>e+t*t),0))}function u(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],s=0;for(let o=1;ot&&(t=e[o],s=o);return[Number(t),s]}function p(e){return e>0&&0==(e&e-1)}s.r(t),s.d(t,{FFT:()=>f,bankers_round:()=>w,cos_sim:()=>c,dot:()=>i,getTopItems:()=>l,interpolate_data:()=>o,log_softmax:()=>a,magnitude:()=>d,max:()=>h,medianFilter:()=>g,min:()=>u,permute_data:()=>n,round:()=>M,softmax:()=>r});class _{constructor(e){if(this.size=0|e,this.size<=1||!p(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(2*this.size);for(let e=0;ee;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<>>t&3)<>>1);for(let t=0;t>>1]=e[t];return s}toComplexArray(e,t){const s=t||this.createComplexArray();for(let t=0;t>>1],s[t+1]=0;return s}completeSpectrum(e){const t=this._csize,s=t>>>1;for(let o=2;o>=2;a>=2;a>>=2){i=o/a<<1;const t=i>>>2;for(n=0;n>>1,a>>>1)}else for(n=0,r=0;n>>1,a>>>1,s)}for(a>>=2;a>=2;a>>=2){i=o/a<<1;const t=i>>>2;for(n=0;n>1;++t){const s=(t+1-e)**2/2,o=Math.sqrt(i**2+l**2)**s,a=s*Math.atan2(l,i),c=2*t;n[c]=o*Math.cos(a),n[c+1]=o*Math.sin(a),r[c]=n[c],r[c+1]=-n[c+1]}this._slicedChirpBuffer=n.subarray(t,s),this._f=new _(o>>1),this._f.transform(this._chirpBuffer,r)}_transform(e,t,s){const o=this._buffer1,n=this._buffer2,r=this._outBuffer1,a=this._outBuffer2,i=this._chirpBuffer,l=this._slicedChirpBuffer,c=this._a;if(s)for(let e=0;e>1];o[e]=n*l[e],o[s]=n*l[s]}else for(let e=0;e=e.length&&(n=2*(e.length-1)-n),o[r++]=e[n]}o.sort(),s[t]=o[n]}return s}function M(e,t){const s=Math.pow(10,t);return Math.round(e*s)/s}function w(e){const t=Math.round(e);return Math.abs(e)%1==.5?t%2==0?t:t-1:t}},"./src/utils/tensor.js": +/*!*****************************!*\ + !*** ./src/utils/tensor.js ***! + \*****************************/(e,t,s)=>{s.r(t),s.d(t,{Tensor:()=>i,cat:()=>m,dynamicTimeWarping:()=>w,interpolate:()=>c,layer_norm:()=>u,mean:()=>M,mean_pooling:()=>d,ones:()=>T,ones_like:()=>k,permute:()=>l,stack:()=>f,std_mean:()=>g});var o=s(/*! ../backends/onnx.js */"./src/backends/onnx.js"),n=s(/*! ./maths.js */"./src/utils/maths.js");const r=Object.freeze({float32:Float32Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array}),a=o.ONNX.Tensor;class i{dims;type;data;size;constructor(...e){return e[0]instanceof a?Object.assign(this,e[0]):Object.assign(this,new a(e[0],e[1],e[2])),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let s=Number(t);if(Number.isInteger(s))return e._getitem(s)}return e[t]},set:(e,t,s)=>e[t]=s})}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const s=t.reduce(((e,t)=>e*t));for(let o=0;o0){const t=s.reduce(((e,t)=>e*t));return this._subarray(e,t,s)}return new i(this.type,[this.data[e]],s)}indexOf(e){for(let t=0;te*t));if(s!==o)throw Error(`cannot reshape array of size ${s} into shape (${t})`);let n=e;for(let e=t.length-1;e>=0;e--)n=n.reduce(((s,o)=>{let n=s[s.length-1];return n.lengthn[1])throw new Error(`Invalid slice: ${n}`);let e=[Math.max(n[0],0),Math.min(n[1],this.dims[o])];s.push(e),t.push(e[1]-e[0])}}}let o=s.map((([e,t])=>t-e)),n=o.reduce(((e,t)=>e*t)),r=new this.data.constructor(n);const a=this.stride();for(let e=0;e=0;--n){const e=o[n];t+=(r%e+s[n][0])*a[n],r=Math.floor(r/e)}r[e]=this.data[t]}return new i(this.type,r,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,s=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);if(null===t){let t=this.data.reduce(((t,s)=>t+s**e),0)**(1/e);return new i(this.type,[t],[])}t=_(t,this.dims.length);const o=this.dims.slice();o[t]=1;const n=new this.data.constructor(this.data.length/this.dims[t]);for(let s=0;s=0;--e){const s=this.dims[e];if(e!==t){r+=n%s*a,a*=o[e]}n=Math.floor(n/s)}n[r]+=this.data[s]**e}if(1!==e)for(let t=0;t=0;--s){const e=this.dims[s];if(s!==t){o+=n%e*r,r*=this.dims[s]}n=Math.floor(n/e)}this.data[e]/=s.data[o]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){const t=new Array(e.length);for(let s=e.length-1,o=1;s>=0;--s)t[s]=o,o*=e[s];return t}(this.dims)}squeeze(e=null){return new i(this.type,this.data,h(this.dims,e))}squeeze_(e=null){return this.dims=h(this.dims,e),this}unsqueeze(e=null){return new i(this.type,this.data,p(this.dims,e))}unsqueeze_(e=null){return this.dims=p(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let s=this.dims.slice(0,e),o=this.dims.slice(e,t+1),n=this.dims.slice(t+1);return this.dims=[...s,o.reduce(((e,t)=>e*t),1),...n],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let s=0;so!==t?e*s:e),1);e[t]=this.data.length/s}return new i(this.type,this.data,e)}neg_(){for(let e=0;e1!==e)):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter(((e,s)=>1!==e||!t.includes(s)))),e}function p(e,t){return t=_(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function _(e,t,s=null){if(e<-t||e>=t)throw new Error(`IndexError: index ${e} is out of bounds for dimension${null===s?"":" "+s} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function m(e,t=0){t=_(t,e[0].dims.length);const s=e[0].dims.slice();s[t]=e.reduce(((e,s)=>e+s.dims[t]),0);const o=s.reduce(((e,t)=>e*t),1),n=new e[0].data.constructor(o),r=e[0].type;if(0===t){let t=0;for(let s of e)n.set(s.data,t),t+=s.data.length}else{let o=0;for(let r=0;r=0;--n){const e=a.dims[n];let c=i%e;n===t&&(c+=o),r+=c*l,l*=s[n],i=Math.floor(i/e)}n[r]=a.data[e]}o+=a.dims[t]}}return new i(r,n,s)}function f(e,t=0){return m(e.map((e=>e.unsqueeze(t))),t)}function g(e,t=null,s=1,o=!1){if(null===t){const t=e.data.reduce(((e,t)=>e+t),0)/e.data.length,o=Math.sqrt(e.data.reduce(((e,s)=>e+(s-t)**2),0)/(e.data.length-s)),n=new i(e.type,[t],[]);return[new i(e.type,[o],[]),n]}const n=M(e,t=_(t,e.dims.length),o),r=e.dims.slice();r[t]=1;const a=new e.data.constructor(e.data.length/e.dims[t]);for(let s=0;s=0;--n){const s=e.dims[n];if(n!==t){o+=a%s*i,i*=r[n]}a=Math.floor(a/s)}a[o]+=(e.data[s]-n.data[o])**2}for(let o=0;oe+t),0);return new i(e.type,[t/e.data.length],[])}t=_(t,e.dims.length);const o=e.dims.slice();o[t]=1;const n=new e.data.constructor(e.data.length/e.dims[t]);for(let s=0;s=0;--n){const s=e.dims[n];if(n!==t){r+=a%s*i,i*=o[n]}a=Math.floor(a/s)}n[r]+=e.data[s]}if(1!==e.dims[t])for(let s=0;s0||l>0;){c.push(a-1),d.push(l-1);switch(r[a][l].item()){case 0:--a,--l;break;case 1:--a;break;case 2:--l;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${a}, ${l}]. Please file a bug report.`)}}return c.reverse(),d.reverse(),[c,d]}function T(e){const t=e.reduce(((e,t)=>e*t),1);return new i("int64",new BigInt64Array(t).fill(1n),e)}function k(e){return T(e.dims)}}},s={};function o(e){var n=s[e];if(void 0!==n)return n.exports;var r=s[e]={exports:{}};return t[e](r,r.exports,o),r.exports}o.d=(e,t)=>{for(var s in t)o.o(t,s)&&!o.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n=o("./src/transformers.js"),r=n.ASTFeatureExtractor,a=n.ASTForAudioClassification,i=n.ASTModel,l=n.ASTPreTrainedModel,c=n.AlbertForMaskedLM,d=n.AlbertForQuestionAnswering,u=n.AlbertForSequenceClassification,h=n.AlbertModel,p=n.AlbertPreTrainedModel,_=n.AlbertTokenizer,m=n.AudioClassificationPipeline,f=n.AutoConfig,g=n.AutoModel,M=n.AutoModelForAudioClassification,w=n.AutoModelForAudioFrameClassification,T=n.AutoModelForCTC,k=n.AutoModelForCausalLM,b=n.AutoModelForDepthEstimation,x=n.AutoModelForDocumentQuestionAnswering,y=n.AutoModelForImageClassification,F=n.AutoModelForImageFeatureExtraction,C=n.AutoModelForImageMatting,P=n.AutoModelForImageSegmentation,v=n.AutoModelForImageToImage,S=n.AutoModelForMaskGeneration,A=n.AutoModelForMaskedLM,L=n.AutoModelForObjectDetection,E=n.AutoModelForQuestionAnswering,z=n.AutoModelForSemanticSegmentation,B=n.AutoModelForSeq2SeqLM,I=n.AutoModelForSequenceClassification,O=n.AutoModelForSpeechSeq2Seq,D=n.AutoModelForTextToSpectrogram,N=n.AutoModelForTextToWaveform,V=n.AutoModelForTokenClassification,q=n.AutoModelForVision2Seq,j=n.AutoModelForXVector,R=n.AutoModelForZeroShotObjectDetection,G=n.AutoProcessor,W=n.AutoTokenizer,$=n.AutomaticSpeechRecognitionPipeline,U=n.BartForConditionalGeneration,X=n.BartForSequenceClassification,Q=n.BartModel,H=n.BartPretrainedModel,Y=n.BartTokenizer,J=n.BaseModelOutput,Z=n.BeitFeatureExtractor,K=n.BeitForImageClassification,ee=n.BeitModel,te=n.BeitPreTrainedModel,se=n.BertForMaskedLM,oe=n.BertForQuestionAnswering,ne=n.BertForSequenceClassification,re=n.BertForTokenClassification,ae=n.BertModel,ie=n.BertPreTrainedModel,le=n.BertTokenizer,ce=n.BitImageProcessor,de=n.BlenderbotForConditionalGeneration,ue=n.BlenderbotModel,he=n.BlenderbotPreTrainedModel,pe=n.BlenderbotSmallForConditionalGeneration,_e=n.BlenderbotSmallModel,me=n.BlenderbotSmallPreTrainedModel,fe=n.BlenderbotSmallTokenizer,ge=n.BlenderbotTokenizer,Me=n.BloomForCausalLM,we=n.BloomModel,Te=n.BloomPreTrainedModel,ke=n.BloomTokenizer,be=n.CLIPFeatureExtractor,xe=n.CLIPModel,ye=n.CLIPPreTrainedModel,Fe=n.CLIPSegForImageSegmentation,Ce=n.CLIPSegModel,Pe=n.CLIPSegPreTrainedModel,ve=n.CLIPTextModelWithProjection,Se=n.CLIPTokenizer,Ae=n.CLIPVisionModelWithProjection,Le=n.CamembertForMaskedLM,Ee=n.CamembertForQuestionAnswering,ze=n.CamembertForSequenceClassification,Be=n.CamembertForTokenClassification,Ie=n.CamembertModel,Oe=n.CamembertPreTrainedModel,De=n.CamembertTokenizer,Ne=n.CausalLMOutput,Ve=n.CausalLMOutputWithPast,qe=n.ChineseCLIPFeatureExtractor,je=n.ChineseCLIPModel,Re=n.ChineseCLIPPreTrainedModel,Ge=n.ClapAudioModelWithProjection,We=n.ClapFeatureExtractor,$e=n.ClapModel,Ue=n.ClapPreTrainedModel,Xe=n.ClapTextModelWithProjection,Qe=n.CodeGenForCausalLM,He=n.CodeGenModel,Ye=n.CodeGenPreTrainedModel,Je=n.CodeGenTokenizer,Ze=n.CodeLlamaTokenizer,Ke=n.CohereTokenizer,et=n.ConvBertForMaskedLM,tt=n.ConvBertForQuestionAnswering,st=n.ConvBertForSequenceClassification,ot=n.ConvBertForTokenClassification,nt=n.ConvBertModel,rt=n.ConvBertPreTrainedModel,at=n.ConvBertTokenizer,it=n.ConvNextFeatureExtractor,lt=n.ConvNextForImageClassification,ct=n.ConvNextImageProcessor,dt=n.ConvNextModel,ut=n.ConvNextPreTrainedModel,ht=n.ConvNextV2ForImageClassification,pt=n.ConvNextV2Model,_t=n.ConvNextV2PreTrainedModel,mt=n.DPTFeatureExtractor,ft=n.DPTForDepthEstimation,gt=n.DPTImageProcessor,Mt=n.DPTModel,wt=n.DPTPreTrainedModel,Tt=n.DebertaForMaskedLM,kt=n.DebertaForQuestionAnswering,bt=n.DebertaForSequenceClassification,xt=n.DebertaForTokenClassification,yt=n.DebertaModel,Ft=n.DebertaPreTrainedModel,Ct=n.DebertaTokenizer,Pt=n.DebertaV2ForMaskedLM,vt=n.DebertaV2ForQuestionAnswering,St=n.DebertaV2ForSequenceClassification,At=n.DebertaV2ForTokenClassification,Lt=n.DebertaV2Model,Et=n.DebertaV2PreTrainedModel,zt=n.DebertaV2Tokenizer,Bt=n.DeiTFeatureExtractor,It=n.DeiTForImageClassification,Ot=n.DeiTModel,Dt=n.DeiTPreTrainedModel,Nt=n.DepthAnythingForDepthEstimation,Vt=n.DepthAnythingPreTrainedModel,qt=n.DepthEstimationPipeline,jt=n.DetrFeatureExtractor,Rt=n.DetrForObjectDetection,Gt=n.DetrForSegmentation,Wt=n.DetrModel,$t=n.DetrObjectDetectionOutput,Ut=n.DetrPreTrainedModel,Xt=n.DetrSegmentationOutput,Qt=n.Dinov2ForImageClassification,Ht=n.Dinov2Model,Yt=n.Dinov2PreTrainedModel,Jt=n.DistilBertForMaskedLM,Zt=n.DistilBertForQuestionAnswering,Kt=n.DistilBertForSequenceClassification,es=n.DistilBertForTokenClassification,ts=n.DistilBertModel,ss=n.DistilBertPreTrainedModel,os=n.DistilBertTokenizer,ns=n.DocumentQuestionAnsweringPipeline,rs=n.DonutFeatureExtractor,as=n.DonutSwinModel,is=n.DonutSwinPreTrainedModel,ls=n.EfficientNetForImageClassification,cs=n.EfficientNetImageProcessor,ds=n.EfficientNetModel,us=n.EfficientNetPreTrainedModel,hs=n.ElectraForMaskedLM,ps=n.ElectraForQuestionAnswering,_s=n.ElectraForSequenceClassification,ms=n.ElectraForTokenClassification,fs=n.ElectraModel,gs=n.ElectraPreTrainedModel,Ms=n.ElectraTokenizer,ws=n.EsmForMaskedLM,Ts=n.EsmForSequenceClassification,ks=n.EsmForTokenClassification,bs=n.EsmModel,xs=n.EsmPreTrainedModel,ys=n.EsmTokenizer,Fs=n.FFT,Cs=n.FalconForCausalLM,Ps=n.FalconModel,vs=n.FalconPreTrainedModel,Ss=n.FalconTokenizer,As=n.FeatureExtractionPipeline,Ls=n.FeatureExtractor,Es=n.FillMaskPipeline,zs=n.GLPNFeatureExtractor,Bs=n.GLPNForDepthEstimation,Is=n.GLPNModel,Os=n.GLPNPreTrainedModel,Ds=n.GPT2LMHeadModel,Ns=n.GPT2Model,Vs=n.GPT2PreTrainedModel,qs=n.GPT2Tokenizer,js=n.GPTBigCodeForCausalLM,Rs=n.GPTBigCodeModel,Gs=n.GPTBigCodePreTrainedModel,Ws=n.GPTJForCausalLM,$s=n.GPTJModel,Us=n.GPTJPreTrainedModel,Xs=n.GPTNeoForCausalLM,Qs=n.GPTNeoModel,Hs=n.GPTNeoPreTrainedModel,Ys=n.GPTNeoXForCausalLM,Js=n.GPTNeoXModel,Zs=n.GPTNeoXPreTrainedModel,Ks=n.GPTNeoXTokenizer,eo=n.GemmaTokenizer,to=n.Grok1Tokenizer,so=n.HerbertTokenizer,oo=n.HubertForCTC,no=n.HubertForSequenceClassification,ro=n.HubertModel,ao=n.HubertPreTrainedModel,io=n.ImageClassificationPipeline,lo=n.ImageFeatureExtractionPipeline,co=n.ImageFeatureExtractor,uo=n.ImageMattingOutput,ho=n.ImageSegmentationPipeline,po=n.ImageToImagePipeline,_o=n.ImageToTextPipeline,mo=n.LlamaForCausalLM,fo=n.LlamaModel,go=n.LlamaPreTrainedModel,Mo=n.LlamaTokenizer,wo=n.LongT5ForConditionalGeneration,To=n.LongT5Model,ko=n.LongT5PreTrainedModel,bo=n.M2M100ForConditionalGeneration,xo=n.M2M100Model,yo=n.M2M100PreTrainedModel,Fo=n.M2M100Tokenizer,Co=n.MBart50Tokenizer,Po=n.MBartForCausalLM,vo=n.MBartForConditionalGeneration,So=n.MBartForSequenceClassification,Ao=n.MBartModel,Lo=n.MBartPreTrainedModel,Eo=n.MBartTokenizer,zo=n.MPNetForMaskedLM,Bo=n.MPNetForQuestionAnswering,Io=n.MPNetForSequenceClassification,Oo=n.MPNetForTokenClassification,Do=n.MPNetModel,No=n.MPNetPreTrainedModel,Vo=n.MPNetTokenizer,qo=n.MT5ForConditionalGeneration,jo=n.MT5Model,Ro=n.MT5PreTrainedModel,Go=n.MarianMTModel,Wo=n.MarianModel,$o=n.MarianPreTrainedModel,Uo=n.MarianTokenizer,Xo=n.MaskedLMOutput,Qo=n.MistralForCausalLM,Ho=n.MistralModel,Yo=n.MistralPreTrainedModel,Jo=n.MobileBertForMaskedLM,Zo=n.MobileBertForQuestionAnswering,Ko=n.MobileBertForSequenceClassification,en=n.MobileBertModel,tn=n.MobileBertPreTrainedModel,sn=n.MobileBertTokenizer,on=n.MobileViTFeatureExtractor,nn=n.MobileViTForImageClassification,rn=n.MobileViTModel,an=n.MobileViTPreTrainedModel,ln=n.ModelOutput,cn=n.MptForCausalLM,dn=n.MptModel,un=n.MptPreTrainedModel,hn=n.NllbTokenizer,pn=n.NomicBertModel,_n=n.NomicBertPreTrainedModel,mn=n.NougatImageProcessor,fn=n.NougatTokenizer,gn=n.OPTForCausalLM,Mn=n.OPTModel,wn=n.OPTPreTrainedModel,Tn=n.ObjectDetectionPipeline,kn=n.OwlViTFeatureExtractor,bn=n.OwlViTForObjectDetection,xn=n.OwlViTModel,yn=n.OwlViTPreTrainedModel,Fn=n.OwlViTProcessor,Cn=n.Owlv2ForObjectDetection,Pn=n.Owlv2ImageProcessor,vn=n.Owlv2Model,Sn=n.Owlv2PreTrainedModel,An=n.PhiForCausalLM,Ln=n.PhiModel,En=n.PhiPreTrainedModel,zn=n.Pipeline,Bn=n.PreTrainedModel,In=n.PreTrainedTokenizer,On=n.PretrainedConfig,Dn=n.PretrainedMixin,Nn=n.Processor,Vn=n.QuestionAnsweringModelOutput,qn=n.QuestionAnsweringPipeline,jn=n.Qwen2ForCausalLM,Rn=n.Qwen2Model,Gn=n.Qwen2PreTrainedModel,Wn=n.Qwen2Tokenizer,$n=n.RawImage,Un=n.ResNetForImageClassification,Xn=n.ResNetModel,Qn=n.ResNetPreTrainedModel,Hn=n.RoFormerForMaskedLM,Yn=n.RoFormerForQuestionAnswering,Jn=n.RoFormerForSequenceClassification,Zn=n.RoFormerForTokenClassification,Kn=n.RoFormerModel,er=n.RoFormerPreTrainedModel,tr=n.RoFormerTokenizer,sr=n.RobertaForMaskedLM,or=n.RobertaForQuestionAnswering,nr=n.RobertaForSequenceClassification,rr=n.RobertaForTokenClassification,ar=n.RobertaModel,ir=n.RobertaPreTrainedModel,lr=n.RobertaTokenizer,cr=n.SamImageProcessor,dr=n.SamImageSegmentationOutput,ur=n.SamModel,hr=n.SamPreTrainedModel,pr=n.SamProcessor,_r=n.SeamlessM4TFeatureExtractor,mr=n.SegformerFeatureExtractor,fr=n.SegformerForImageClassification,gr=n.SegformerForSemanticSegmentation,Mr=n.SegformerModel,wr=n.SegformerPreTrainedModel,Tr=n.Seq2SeqLMOutput,kr=n.SequenceClassifierOutput,br=n.SiglipImageProcessor,xr=n.SiglipModel,yr=n.SiglipPreTrainedModel,Fr=n.SiglipTextModel,Cr=n.SiglipTokenizer,Pr=n.SiglipVisionModel,vr=n.SpeechT5FeatureExtractor,Sr=n.SpeechT5ForSpeechToText,Ar=n.SpeechT5ForTextToSpeech,Lr=n.SpeechT5HifiGan,Er=n.SpeechT5Model,zr=n.SpeechT5PreTrainedModel,Br=n.SpeechT5Processor,Ir=n.SpeechT5Tokenizer,Or=n.SqueezeBertForMaskedLM,Dr=n.SqueezeBertForQuestionAnswering,Nr=n.SqueezeBertForSequenceClassification,Vr=n.SqueezeBertModel,qr=n.SqueezeBertPreTrainedModel,jr=n.SqueezeBertTokenizer,Rr=n.StableLmForCausalLM,Gr=n.StableLmModel,Wr=n.StableLmPreTrainedModel,$r=n.Starcoder2ForCausalLM,Ur=n.Starcoder2Model,Xr=n.Starcoder2PreTrainedModel,Qr=n.SummarizationPipeline,Hr=n.Swin2SRForImageSuperResolution,Yr=n.Swin2SRImageProcessor,Jr=n.Swin2SRModel,Zr=n.Swin2SRPreTrainedModel,Kr=n.SwinForImageClassification,ea=n.SwinModel,ta=n.SwinPreTrainedModel,sa=n.T5ForConditionalGeneration,oa=n.T5Model,na=n.T5PreTrainedModel,ra=n.T5Tokenizer,aa=n.TableTransformerForObjectDetection,ia=n.TableTransformerModel,la=n.TableTransformerObjectDetectionOutput,ca=n.TableTransformerPreTrainedModel,da=n.Tensor,ua=n.Text2TextGenerationPipeline,ha=n.TextClassificationPipeline,pa=n.TextGenerationPipeline,_a=n.TextToAudioPipeline,ma=n.TokenClassificationPipeline,fa=n.TokenClassifierOutput,ga=n.TokenizerModel,Ma=n.TrOCRForCausalLM,wa=n.TrOCRPreTrainedModel,Ta=n.TranslationPipeline,ka=n.UniSpeechForCTC,ba=n.UniSpeechForSequenceClassification,xa=n.UniSpeechModel,ya=n.UniSpeechPreTrainedModel,Fa=n.UniSpeechSatForAudioFrameClassification,Ca=n.UniSpeechSatForCTC,Pa=n.UniSpeechSatForSequenceClassification,va=n.UniSpeechSatModel,Sa=n.UniSpeechSatPreTrainedModel,Aa=n.ViTFeatureExtractor,La=n.ViTForImageClassification,Ea=n.ViTImageProcessor,za=n.ViTModel,Ba=n.ViTPreTrainedModel,Ia=n.VisionEncoderDecoderModel,Oa=n.VitMatteForImageMatting,Da=n.VitMatteImageProcessor,Na=n.VitMattePreTrainedModel,Va=n.VitsModel,qa=n.VitsModelOutput,ja=n.VitsPreTrainedModel,Ra=n.VitsTokenizer,Ga=n.Wav2Vec2BertForCTC,Wa=n.Wav2Vec2BertForSequenceClassification,$a=n.Wav2Vec2BertModel,Ua=n.Wav2Vec2BertPreTrainedModel,Xa=n.Wav2Vec2CTCTokenizer,Qa=n.Wav2Vec2FeatureExtractor,Ha=n.Wav2Vec2ForAudioFrameClassification,Ya=n.Wav2Vec2ForCTC,Ja=n.Wav2Vec2ForSequenceClassification,Za=n.Wav2Vec2Model,Ka=n.Wav2Vec2PreTrainedModel,ei=n.Wav2Vec2ProcessorWithLM,ti=n.WavLMForAudioFrameClassification,si=n.WavLMForCTC,oi=n.WavLMForSequenceClassification,ni=n.WavLMForXVector,ri=n.WavLMModel,ai=n.WavLMPreTrainedModel,ii=n.WhisperFeatureExtractor,li=n.WhisperForConditionalGeneration,ci=n.WhisperModel,di=n.WhisperPreTrainedModel,ui=n.WhisperProcessor,hi=n.WhisperTokenizer,pi=n.XLMForQuestionAnswering,_i=n.XLMForSequenceClassification,mi=n.XLMForTokenClassification,fi=n.XLMModel,gi=n.XLMPreTrainedModel,Mi=n.XLMRobertaForMaskedLM,wi=n.XLMRobertaForQuestionAnswering,Ti=n.XLMRobertaForSequenceClassification,ki=n.XLMRobertaForTokenClassification,bi=n.XLMRobertaModel,xi=n.XLMRobertaPreTrainedModel,yi=n.XLMRobertaTokenizer,Fi=n.XLMTokenizer,Ci=n.XLMWithLMHeadModel,Pi=n.XVectorOutput,vi=n.YolosFeatureExtractor,Si=n.YolosForObjectDetection,Ai=n.YolosModel,Li=n.YolosObjectDetectionOutput,Ei=n.YolosPreTrainedModel,zi=n.ZeroShotAudioClassificationPipeline,Bi=n.ZeroShotClassificationPipeline,Ii=n.ZeroShotImageClassificationPipeline,Oi=n.ZeroShotObjectDetectionPipeline,Di=n.bankers_round,Ni=n.cat,Vi=n.cos_sim,qi=n.dot,ji=n.dynamicTimeWarping,Ri=n.env,Gi=n.getTopItems,Wi=n.hanning,$i=n.interpolate,Ui=n.interpolate_data,Xi=n.layer_norm,Qi=n.log_softmax,Hi=n.magnitude,Yi=n.max,Ji=n.mean,Zi=n.mean_pooling,Ki=n.medianFilter,el=n.mel_filter_bank,tl=n.min,sl=n.ones,ol=n.ones_like,nl=n.permute,rl=n.permute_data,al=n.pipeline,il=n.read_audio,ll=n.round,cl=n.softmax,dl=n.spectrogram,ul=n.stack,hl=n.std_mean,pl=n.window_function;export{r as ASTFeatureExtractor,a as ASTForAudioClassification,i as ASTModel,l as ASTPreTrainedModel,c as AlbertForMaskedLM,d as AlbertForQuestionAnswering,u as AlbertForSequenceClassification,h as AlbertModel,p as AlbertPreTrainedModel,_ as AlbertTokenizer,m as AudioClassificationPipeline,f as AutoConfig,g as AutoModel,M as AutoModelForAudioClassification,w as AutoModelForAudioFrameClassification,T as AutoModelForCTC,k as AutoModelForCausalLM,b as AutoModelForDepthEstimation,x as AutoModelForDocumentQuestionAnswering,y as AutoModelForImageClassification,F as AutoModelForImageFeatureExtraction,C as AutoModelForImageMatting,P as AutoModelForImageSegmentation,v as AutoModelForImageToImage,S as AutoModelForMaskGeneration,A as AutoModelForMaskedLM,L as AutoModelForObjectDetection,E as AutoModelForQuestionAnswering,z as AutoModelForSemanticSegmentation,B as AutoModelForSeq2SeqLM,I as AutoModelForSequenceClassification,O as AutoModelForSpeechSeq2Seq,D as AutoModelForTextToSpectrogram,N as AutoModelForTextToWaveform,V as AutoModelForTokenClassification,q as AutoModelForVision2Seq,j as AutoModelForXVector,R as AutoModelForZeroShotObjectDetection,G as AutoProcessor,W as AutoTokenizer,$ as AutomaticSpeechRecognitionPipeline,U as BartForConditionalGeneration,X as BartForSequenceClassification,Q as BartModel,H as BartPretrainedModel,Y as BartTokenizer,J as BaseModelOutput,Z as BeitFeatureExtractor,K as BeitForImageClassification,ee as BeitModel,te as BeitPreTrainedModel,se as BertForMaskedLM,oe as BertForQuestionAnswering,ne as BertForSequenceClassification,re as BertForTokenClassification,ae as BertModel,ie as BertPreTrainedModel,le as BertTokenizer,ce as BitImageProcessor,de as BlenderbotForConditionalGeneration,ue as BlenderbotModel,he as BlenderbotPreTrainedModel,pe as BlenderbotSmallForConditionalGeneration,_e as BlenderbotSmallModel,me as BlenderbotSmallPreTrainedModel,fe as BlenderbotSmallTokenizer,ge as BlenderbotTokenizer,Me as BloomForCausalLM,we as BloomModel,Te as BloomPreTrainedModel,ke as BloomTokenizer,be as CLIPFeatureExtractor,xe as CLIPModel,ye as CLIPPreTrainedModel,Fe as CLIPSegForImageSegmentation,Ce as CLIPSegModel,Pe as CLIPSegPreTrainedModel,ve as CLIPTextModelWithProjection,Se as CLIPTokenizer,Ae as CLIPVisionModelWithProjection,Le as CamembertForMaskedLM,Ee as CamembertForQuestionAnswering,ze as CamembertForSequenceClassification,Be as CamembertForTokenClassification,Ie as CamembertModel,Oe as CamembertPreTrainedModel,De as CamembertTokenizer,Ne as CausalLMOutput,Ve as CausalLMOutputWithPast,qe as ChineseCLIPFeatureExtractor,je as ChineseCLIPModel,Re as ChineseCLIPPreTrainedModel,Ge as ClapAudioModelWithProjection,We as ClapFeatureExtractor,$e as ClapModel,Ue as ClapPreTrainedModel,Xe as ClapTextModelWithProjection,Qe as CodeGenForCausalLM,He as CodeGenModel,Ye as CodeGenPreTrainedModel,Je as CodeGenTokenizer,Ze as CodeLlamaTokenizer,Ke as CohereTokenizer,et as ConvBertForMaskedLM,tt as ConvBertForQuestionAnswering,st as ConvBertForSequenceClassification,ot as ConvBertForTokenClassification,nt as ConvBertModel,rt as ConvBertPreTrainedModel,at as ConvBertTokenizer,it as ConvNextFeatureExtractor,lt as ConvNextForImageClassification,ct as ConvNextImageProcessor,dt as ConvNextModel,ut as ConvNextPreTrainedModel,ht as ConvNextV2ForImageClassification,pt as ConvNextV2Model,_t as ConvNextV2PreTrainedModel,mt as DPTFeatureExtractor,ft as DPTForDepthEstimation,gt as DPTImageProcessor,Mt as DPTModel,wt as DPTPreTrainedModel,Tt as DebertaForMaskedLM,kt as DebertaForQuestionAnswering,bt as DebertaForSequenceClassification,xt as DebertaForTokenClassification,yt as DebertaModel,Ft as DebertaPreTrainedModel,Ct as DebertaTokenizer,Pt as DebertaV2ForMaskedLM,vt as DebertaV2ForQuestionAnswering,St as DebertaV2ForSequenceClassification,At as DebertaV2ForTokenClassification,Lt as DebertaV2Model,Et as DebertaV2PreTrainedModel,zt as DebertaV2Tokenizer,Bt as DeiTFeatureExtractor,It as DeiTForImageClassification,Ot as DeiTModel,Dt as DeiTPreTrainedModel,Nt as DepthAnythingForDepthEstimation,Vt as DepthAnythingPreTrainedModel,qt as DepthEstimationPipeline,jt as DetrFeatureExtractor,Rt as DetrForObjectDetection,Gt as DetrForSegmentation,Wt as DetrModel,$t as DetrObjectDetectionOutput,Ut as DetrPreTrainedModel,Xt as DetrSegmentationOutput,Qt as Dinov2ForImageClassification,Ht as Dinov2Model,Yt as Dinov2PreTrainedModel,Jt as DistilBertForMaskedLM,Zt as DistilBertForQuestionAnswering,Kt as DistilBertForSequenceClassification,es as DistilBertForTokenClassification,ts as DistilBertModel,ss as DistilBertPreTrainedModel,os as DistilBertTokenizer,ns as DocumentQuestionAnsweringPipeline,rs as DonutFeatureExtractor,as as DonutSwinModel,is as DonutSwinPreTrainedModel,ls as EfficientNetForImageClassification,cs as EfficientNetImageProcessor,ds as EfficientNetModel,us as EfficientNetPreTrainedModel,hs as ElectraForMaskedLM,ps as ElectraForQuestionAnswering,_s as ElectraForSequenceClassification,ms as ElectraForTokenClassification,fs as ElectraModel,gs as ElectraPreTrainedModel,Ms as ElectraTokenizer,ws as EsmForMaskedLM,Ts as EsmForSequenceClassification,ks as EsmForTokenClassification,bs as EsmModel,xs as EsmPreTrainedModel,ys as EsmTokenizer,Fs as FFT,Cs as FalconForCausalLM,Ps as FalconModel,vs as FalconPreTrainedModel,Ss as FalconTokenizer,As as FeatureExtractionPipeline,Ls as FeatureExtractor,Es as FillMaskPipeline,zs as GLPNFeatureExtractor,Bs as GLPNForDepthEstimation,Is as GLPNModel,Os as GLPNPreTrainedModel,Ds as GPT2LMHeadModel,Ns as GPT2Model,Vs as GPT2PreTrainedModel,qs as GPT2Tokenizer,js as GPTBigCodeForCausalLM,Rs as GPTBigCodeModel,Gs as GPTBigCodePreTrainedModel,Ws as GPTJForCausalLM,$s as GPTJModel,Us as GPTJPreTrainedModel,Xs as GPTNeoForCausalLM,Qs as GPTNeoModel,Hs as GPTNeoPreTrainedModel,Ys as GPTNeoXForCausalLM,Js as GPTNeoXModel,Zs as GPTNeoXPreTrainedModel,Ks as GPTNeoXTokenizer,eo as GemmaTokenizer,to as Grok1Tokenizer,so as HerbertTokenizer,oo as HubertForCTC,no as HubertForSequenceClassification,ro as HubertModel,ao as HubertPreTrainedModel,io as ImageClassificationPipeline,lo as ImageFeatureExtractionPipeline,co as ImageFeatureExtractor,uo as ImageMattingOutput,ho as ImageSegmentationPipeline,po as ImageToImagePipeline,_o as ImageToTextPipeline,mo as LlamaForCausalLM,fo as LlamaModel,go as LlamaPreTrainedModel,Mo as LlamaTokenizer,wo as LongT5ForConditionalGeneration,To as LongT5Model,ko as LongT5PreTrainedModel,bo as M2M100ForConditionalGeneration,xo as M2M100Model,yo as M2M100PreTrainedModel,Fo as M2M100Tokenizer,Co as MBart50Tokenizer,Po as MBartForCausalLM,vo as MBartForConditionalGeneration,So as MBartForSequenceClassification,Ao as MBartModel,Lo as MBartPreTrainedModel,Eo as MBartTokenizer,zo as MPNetForMaskedLM,Bo as MPNetForQuestionAnswering,Io as MPNetForSequenceClassification,Oo as MPNetForTokenClassification,Do as MPNetModel,No as MPNetPreTrainedModel,Vo as MPNetTokenizer,qo as MT5ForConditionalGeneration,jo as MT5Model,Ro as MT5PreTrainedModel,Go as MarianMTModel,Wo as MarianModel,$o as MarianPreTrainedModel,Uo as MarianTokenizer,Xo as MaskedLMOutput,Qo as MistralForCausalLM,Ho as MistralModel,Yo as MistralPreTrainedModel,Jo as MobileBertForMaskedLM,Zo as MobileBertForQuestionAnswering,Ko as MobileBertForSequenceClassification,en as MobileBertModel,tn as MobileBertPreTrainedModel,sn as MobileBertTokenizer,on as MobileViTFeatureExtractor,nn as MobileViTForImageClassification,rn as MobileViTModel,an as MobileViTPreTrainedModel,ln as ModelOutput,cn as MptForCausalLM,dn as MptModel,un as MptPreTrainedModel,hn as NllbTokenizer,pn as NomicBertModel,_n as NomicBertPreTrainedModel,mn as NougatImageProcessor,fn as NougatTokenizer,gn as OPTForCausalLM,Mn as OPTModel,wn as OPTPreTrainedModel,Tn as ObjectDetectionPipeline,kn as OwlViTFeatureExtractor,bn as OwlViTForObjectDetection,xn as OwlViTModel,yn as OwlViTPreTrainedModel,Fn as OwlViTProcessor,Cn as Owlv2ForObjectDetection,Pn as Owlv2ImageProcessor,vn as Owlv2Model,Sn as Owlv2PreTrainedModel,An as PhiForCausalLM,Ln as PhiModel,En as PhiPreTrainedModel,zn as Pipeline,Bn as PreTrainedModel,In as PreTrainedTokenizer,On as PretrainedConfig,Dn as PretrainedMixin,Nn as Processor,Vn as QuestionAnsweringModelOutput,qn as QuestionAnsweringPipeline,jn as Qwen2ForCausalLM,Rn as Qwen2Model,Gn as Qwen2PreTrainedModel,Wn as Qwen2Tokenizer,$n as RawImage,Un as ResNetForImageClassification,Xn as ResNetModel,Qn as ResNetPreTrainedModel,Hn as RoFormerForMaskedLM,Yn as RoFormerForQuestionAnswering,Jn as RoFormerForSequenceClassification,Zn as RoFormerForTokenClassification,Kn as RoFormerModel,er as RoFormerPreTrainedModel,tr as RoFormerTokenizer,sr as RobertaForMaskedLM,or as RobertaForQuestionAnswering,nr as RobertaForSequenceClassification,rr as RobertaForTokenClassification,ar as RobertaModel,ir as RobertaPreTrainedModel,lr as RobertaTokenizer,cr as SamImageProcessor,dr as SamImageSegmentationOutput,ur as SamModel,hr as SamPreTrainedModel,pr as SamProcessor,_r as SeamlessM4TFeatureExtractor,mr as SegformerFeatureExtractor,fr as SegformerForImageClassification,gr as SegformerForSemanticSegmentation,Mr as SegformerModel,wr as SegformerPreTrainedModel,Tr as Seq2SeqLMOutput,kr as SequenceClassifierOutput,br as SiglipImageProcessor,xr as SiglipModel,yr as SiglipPreTrainedModel,Fr as SiglipTextModel,Cr as SiglipTokenizer,Pr as SiglipVisionModel,vr as SpeechT5FeatureExtractor,Sr as SpeechT5ForSpeechToText,Ar as SpeechT5ForTextToSpeech,Lr as SpeechT5HifiGan,Er as SpeechT5Model,zr as SpeechT5PreTrainedModel,Br as SpeechT5Processor,Ir as SpeechT5Tokenizer,Or as SqueezeBertForMaskedLM,Dr as SqueezeBertForQuestionAnswering,Nr as SqueezeBertForSequenceClassification,Vr as SqueezeBertModel,qr as SqueezeBertPreTrainedModel,jr as SqueezeBertTokenizer,Rr as StableLmForCausalLM,Gr as StableLmModel,Wr as StableLmPreTrainedModel,$r as Starcoder2ForCausalLM,Ur as Starcoder2Model,Xr as Starcoder2PreTrainedModel,Qr as SummarizationPipeline,Hr as Swin2SRForImageSuperResolution,Yr as Swin2SRImageProcessor,Jr as Swin2SRModel,Zr as Swin2SRPreTrainedModel,Kr as SwinForImageClassification,ea as SwinModel,ta as SwinPreTrainedModel,sa as T5ForConditionalGeneration,oa as T5Model,na as T5PreTrainedModel,ra as T5Tokenizer,aa as TableTransformerForObjectDetection,ia as TableTransformerModel,la as TableTransformerObjectDetectionOutput,ca as TableTransformerPreTrainedModel,da as Tensor,ua as Text2TextGenerationPipeline,ha as TextClassificationPipeline,pa as TextGenerationPipeline,_a as TextToAudioPipeline,ma as TokenClassificationPipeline,fa as TokenClassifierOutput,ga as TokenizerModel,Ma as TrOCRForCausalLM,wa as TrOCRPreTrainedModel,Ta as TranslationPipeline,ka as UniSpeechForCTC,ba as UniSpeechForSequenceClassification,xa as UniSpeechModel,ya as UniSpeechPreTrainedModel,Fa as UniSpeechSatForAudioFrameClassification,Ca as UniSpeechSatForCTC,Pa as UniSpeechSatForSequenceClassification,va as UniSpeechSatModel,Sa as UniSpeechSatPreTrainedModel,Aa as ViTFeatureExtractor,La as ViTForImageClassification,Ea as ViTImageProcessor,za as ViTModel,Ba as ViTPreTrainedModel,Ia as VisionEncoderDecoderModel,Oa as VitMatteForImageMatting,Da as VitMatteImageProcessor,Na as VitMattePreTrainedModel,Va as VitsModel,qa as VitsModelOutput,ja as VitsPreTrainedModel,Ra as VitsTokenizer,Ga as Wav2Vec2BertForCTC,Wa as Wav2Vec2BertForSequenceClassification,$a as Wav2Vec2BertModel,Ua as Wav2Vec2BertPreTrainedModel,Xa as Wav2Vec2CTCTokenizer,Qa as Wav2Vec2FeatureExtractor,Ha as Wav2Vec2ForAudioFrameClassification,Ya as Wav2Vec2ForCTC,Ja as Wav2Vec2ForSequenceClassification,Za as Wav2Vec2Model,Ka as Wav2Vec2PreTrainedModel,ei as Wav2Vec2ProcessorWithLM,ti as WavLMForAudioFrameClassification,si as WavLMForCTC,oi as WavLMForSequenceClassification,ni as WavLMForXVector,ri as WavLMModel,ai as WavLMPreTrainedModel,ii as WhisperFeatureExtractor,li as WhisperForConditionalGeneration,ci as WhisperModel,di as WhisperPreTrainedModel,ui as WhisperProcessor,hi as WhisperTokenizer,pi as XLMForQuestionAnswering,_i as XLMForSequenceClassification,mi as XLMForTokenClassification,fi as XLMModel,gi as XLMPreTrainedModel,Mi as XLMRobertaForMaskedLM,wi as XLMRobertaForQuestionAnswering,Ti as XLMRobertaForSequenceClassification,ki as XLMRobertaForTokenClassification,bi as XLMRobertaModel,xi as XLMRobertaPreTrainedModel,yi as XLMRobertaTokenizer,Fi as XLMTokenizer,Ci as XLMWithLMHeadModel,Pi as XVectorOutput,vi as YolosFeatureExtractor,Si as YolosForObjectDetection,Ai as YolosModel,Li as YolosObjectDetectionOutput,Ei as YolosPreTrainedModel,zi as ZeroShotAudioClassificationPipeline,Bi as ZeroShotClassificationPipeline,Ii as ZeroShotImageClassificationPipeline,Oi as ZeroShotObjectDetectionPipeline,Di as bankers_round,Ni as cat,Vi as cos_sim,qi as dot,ji as dynamicTimeWarping,Ri as env,Gi as getTopItems,Wi as hanning,$i as interpolate,Ui as interpolate_data,Xi as layer_norm,Qi as log_softmax,Hi as magnitude,Yi as max,Ji as mean,Zi as mean_pooling,Ki as medianFilter,el as mel_filter_bank,tl as min,sl as ones,ol as ones_like,nl as permute,rl as permute_data,al as pipeline,il as read_audio,ll as round,cl as softmax,dl as spectrogram,ul as stack,hl as std_mean,pl as window_function}; +//# sourceMappingURL=transformers.min.js.map \ No newline at end of file diff --git a/toolkit/components/nimbus/FeatureManifest.yaml b/toolkit/components/nimbus/FeatureManifest.yaml index c540e0e387..f03834c8d2 100644 --- a/toolkit/components/nimbus/FeatureManifest.yaml +++ b/toolkit/components/nimbus/FeatureManifest.yaml @@ -106,12 +106,6 @@ search: pref: browser.urlbar.richSuggestions.featureGate description: >- Feature gate that controls whether Rich Suggestions are enabled. - serpEventTelemetryEnabled: - type: boolean - setPref: - branch: default - pref: browser.search.serpEventTelemetry.enabled - description: Whether the Glean SERP event telemetry is enabled. serpEventTelemetryCategorizationEnabled: type: boolean setPref: @@ -627,6 +621,20 @@ windowsLaunchOnLogin: pref: browser.startup.windowsLaunchOnLogin.enabled description: Should users see the Windows launch on login checkbox. +firefoxBridge: + description: "Controls for Firefox Bridge extension and extension registration" + owner: install-update@mozilla.com + hasExposure: false + variables: + enabled: + type: boolean + setPref: + branch: default + pref: browser.firefoxbridge.enabled + description: >- + Should Firefox Bridge be registered within firefoxBridgeNativeMessaging + startup idle task for use with native messaging proxy. + windowsJumpList: description: "Controls for the Windows Jump List integration." owner: mconley@mozilla.com @@ -641,14 +649,15 @@ windowsJumpList: abouthomecache: description: "The startup about:home cache." - owner: omc@mozilla.com + owner: omc@mozilla.com, mconley@mozilla.com hasExposure: false - isEarlyStartup: true variables: enabled: type: boolean - fallbackPref: browser.startup.homepage.abouthome_cache.enabled description: Is the feature enabled? + setPref: + branch: user + pref: browser.startup.homepage.abouthome_cache.enabled newtab: description: "The about:newtab page" @@ -929,6 +938,11 @@ pocketNewtab: type: string fallbackPref: >- browser.newtabpage.activity-stream.discoverystream.region-spocs-config + regionWeatherConfig: + description: A comma-separated list of regions that get weather by default. + type: string + fallbackPref: >- + browser.newtabpage.activity-stream.discoverystream.region-weather-config topSitesMaxSponsored: # Defined under `pocketNewtab` as it needs to be used along with other variables type: int @@ -943,6 +957,12 @@ pocketNewtab: type: boolean fallbackPref: >- browser.topsites.contile.sov.enabled + pocketFeedParameters: + type: string + fallbackPref: >- + browser.newtabpage.activity-stream.discoverystream.pocket-feed-parameters + description: >- + Add parameters to Pocket feed URL. saveToPocket: description: The save to Pocket feature @@ -1131,6 +1151,18 @@ fullPageTranslationAutomaticPopup: branch: user pref: browser.translations.automaticallyPopup +selectTranslation: + description: This feature enables the option to translate selected text from the context menu. + owner: enordin@mozilla.com + hasExposure: false + variables: + boolean: + description: Set to true to enable the select-translations feature + type: boolean + setPref: + branch: user + pref: browser.translations.select.enable + pdfjs: description: The Firefox pdf reader. owner: pdfjs-team@mozilla.com @@ -1392,13 +1424,13 @@ gleanInternalSdk: description: "The Glean internal SDK feature intended only for internal Glean Team use" owner: glean-team@mozilla.com hasExposure: false - # Some variables are used through the C++ API and thus require pref-storage. - # We rely on those values at Glean.init time, which happens at startup. - isEarlyStartup: true variables: finalInactive: type: "boolean" description: "Enables FOG early shutdown pings when true" + setPref: + branch: user + pref: telemetry.glean.internal.finalInactive gleanMetricConfiguration: type: json description: | @@ -1409,33 +1441,9 @@ gleanInternalSdk: type: int description: >- Maximum number of pings that can be sent in a 60 second interval - -majorRelease2022: - description: Major Release 2022 - owner: firefoxview@mozilla.com - hasExposure: false - isEarlyStartup: true - variables: - feltPrivacyPBMDarkTheme: - type: boolean - fallbackPref: "browser.theme.dark-private-windows" - description: "Use dark theme variant for PBM windows. This is only supported if the theme sets darkTheme data." - feltPrivacyShowPreferencesSection: - type: boolean - fallbackPref: "browser.privacySegmentation.preferences.show" - description: "Controls visibility of the privacy segmentation preferences section." - feltPrivacyWindowSeparation: - type: boolean - fallbackPref: "browser.privateWindowSeparation.enabled" - description: "Whether or not private browsing windows use a separate icon in the Windows taskbar" - colorwayCloset: - type: boolean - fallbackPref: "browser.theme.colorway-closet" - description: "Whether or not to show the colorway closet modal" - onboarding: - type: boolean - fallbackPref: "browser.majorrelease.onboarding" - description: "Whether or not to use the MR2022 onboarding settings." + setPref: + branch: user + pref: telemetry.glean.internal.maxPingsPerMinute browserLowMemoryPrefs: description: Prefs which control the browser's behaviour under low memory. @@ -1694,26 +1702,20 @@ dapTelemetry: description: DAP Telemetry owner: simon@mozilla.com hasExposure: false - isEarlyStartup: true # Data is sent on startup with a trigger in BrowserGlue.sys.mjs variables: enabled: type: boolean - fallbackPref: toolkit.telemetry.dap_enabled description: Whether to automatically send DAP measurements. task1Enabled: type: boolean - fallbackPref: toolkit.telemetry.dap_task1_enabled description: Whether to send fake measurements for task 1. task1TaskId: type: string - fallbackPref: toolkit.telemetry.dap_task1_taskid description: The task ID to use for task 1 measurements. visitCountingEnabled: type: boolean - fallbackPref: toolkit.telemetry.dap_visit_counting_enabled description: Whether to count visits to the provided list of URLs. visitCountingExperimentList: - fallbackPref: toolkit.telemetry.dap_visit_counting_experiment_list type: json description: A list of experiments with URLs for which we want to count visits. @@ -2098,6 +2100,12 @@ gc: setPref: branch: user pref: "javascript.options.mem.gc_parallel_marking_threshold_mb" + gc_max_parallel_marking_threads: + description: The maximum number of threads to use for parallel marking, if enabled. + type: int + setPref: + branch: user + pref: "javascript.options.mem.gc_max_parallel_marking_threads" gc_per_zone: description: Whether per-zone GC is enabled. If not, all zones are collected every time. type: boolean @@ -2397,20 +2405,6 @@ backgroundUpdate: branch: user pref: app.update.background.allowUpdatesForUnelevatedInstallations -defaultAgent: - description: >- - Features that configure the Windows Default Browser Agent. - owner: install-update@mozilla.com - applications: - - firefox-desktop-background-task - hasExposure: false - variables: - cppFallback: - description: >- - Triggers the Default Agent to fall back to the C++ implementation of DoTask if true. - type: boolean - fallbackPref: "defaultAgent.cppFallback.enabled" - bookmarks: description: Prefs to control aspects of the bookmarks system. owner: omc@mozilla.com @@ -2706,6 +2700,10 @@ contentRelevancy: setPref: branch: user pref: toolkit.contentRelevancy.timerInterval + ingestEnabled: + description: Enable the ingestion through the Rust component + type: boolean + fallbackPref: toolkit.contentRelevancy.ingestEnabled tabPreview: description: Prefs to control Tab Previews @@ -2733,6 +2731,29 @@ backupService: description: >- When true, the profile backup service will be initialized soon after startup. + prefsUIEnabled: + type: boolean + setPref: + branch: default + pref: browser.backup.preferences.ui.enabled + description: >- + When true, the section in about:preferences to control the backup + feature is visible. + sqlitePagesPerStep: + description: >- + The number of database pages to backup per step when backing up an + SQLite database. + type: int + setPref: + branch: user + pref: browser.backup.sqlite.pages_per_step + sqliteStepDelayMs: + description: >- + The delay between SQLite database backup steps in milliseconds. + type: int + setPref: + branch: user + pref: browser.backup.sqlite.step_delay_ms pqcrypto: description: Prefs that control the use of post-quantum cryptography. diff --git a/toolkit/components/nimbus/generate/generate_feature_manifest.py b/toolkit/components/nimbus/generate/generate_feature_manifest.py index 55e681fdf8..fab73c4ce7 100644 --- a/toolkit/components/nimbus/generate/generate_feature_manifest.py +++ b/toolkit/components/nimbus/generate/generate_feature_manifest.py @@ -24,11 +24,7 @@ NIMBUS_FALLBACK_PREFS = ( # Do not add new feature IDs to this list! isEarlyStartup is being deprecated. # See https://bugzilla.mozilla.org/show_bug.cgi?id=1875331 for details. ALLOWED_ISEARLYSTARTUP_FEATURE_IDS = { - "abouthomecache", "aboutwelcome", - "dapTelemetry", - "gleanInternalSdk", - "majorRelease2022", "newtab", "pocketNewtab", "searchConfiguration", diff --git a/toolkit/components/nimbus/lib/ExperimentManager.sys.mjs b/toolkit/components/nimbus/lib/ExperimentManager.sys.mjs index 8bd847b067..78299da1b4 100644 --- a/toolkit/components/nimbus/lib/ExperimentManager.sys.mjs +++ b/toolkit/components/nimbus/lib/ExperimentManager.sys.mjs @@ -207,7 +207,7 @@ export class _ExperimentManager { lazy.NimbusFeatures.nimbusTelemetry.getVariable( "gleanMetricConfiguration" ) ?? {}; - Services.fog.setMetricsFeatureConfig(JSON.stringify(cfg)); + Services.fog.applyServerKnobsConfig(JSON.stringify(cfg)); }); } diff --git a/toolkit/components/nimbus/test/unit/head.js b/toolkit/components/nimbus/test/unit/head.js index e74212161c..e2e42ee4c9 100644 --- a/toolkit/components/nimbus/test/unit/head.js +++ b/toolkit/components/nimbus/test/unit/head.js @@ -63,10 +63,15 @@ async function assertEmptyStore(store, { cleanup = false } = {}) { "Store should have no active enrollments" ); + store + .getAll() + .filter(e => !e.active) + .forEach(e => store._deleteForTests(e.slug)); + Assert.deepEqual( store .getAll() - .filter(e => e.inactive) + .filter(e => !e.active) .map(e => e.slug), [], "Store should have no inactive enrollments" diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentAPI_NimbusFeatures.js b/toolkit/components/nimbus/test/unit/test_ExperimentAPI_NimbusFeatures.js index 79304cd66e..9bbf26a6a0 100644 --- a/toolkit/components/nimbus/test/unit/test_ExperimentAPI_NimbusFeatures.js +++ b/toolkit/components/nimbus/test/unit/test_ExperimentAPI_NimbusFeatures.js @@ -92,8 +92,11 @@ add_task(async function readyCallAfterStore_with_remote_value() { await manager.store.addEnrollment(MATCHING_ROLLOUT); Assert.ok(!feature.getVariable("enabled"), "Loads value from store"); - manager.store._deleteForTests("aboutwelcome"); + + manager.unenroll(MATCHING_ROLLOUT.slug, "test-cleanup"); + sandbox.restore(); + await assertEmptyStore(manager.store); }); add_task(async function has_sync_value_before_ready() { @@ -121,7 +124,11 @@ add_task(async function has_sync_value_before_ready() { Assert.equal(feature.getVariable("remoteValue"), true, "Sync load from pref"); - manager.store._deleteForTests("aboutwelcome"); + Services.prefs.clearUserPref("nimbus.syncdefaultsstore.aboutwelcome"); + Services.prefs.clearUserPref( + "nimbus.syncdefaultsstore.aboutwelcome.remoteValue" + ); + await assertEmptyStore(manager.store); }); add_task(async function update_remote_defaults_onUpdate() { @@ -137,8 +144,10 @@ add_task(async function update_remote_defaults_onUpdate() { Assert.equal(stub.callCount, 1, "Called once for remote configs"); Assert.equal(stub.firstCall.args[1], "rollout-updated", "Correct reason"); - manager.store._deleteForTests("aboutwelcome"); + manager.unenroll(MATCHING_ROLLOUT.slug, "test-cleanup"); + sandbox.restore(); + await assertEmptyStore(manager.store); }); add_task(async function test_features_over_feature() { @@ -190,6 +199,9 @@ add_task(async function test_features_over_feature() { manager.store._deleteForTests("aboutwelcome"); manager.store._deleteForTests("matching-rollout"); + + await assertEmptyStore(manager.store); + sandbox.restore(); }); @@ -208,7 +220,8 @@ add_task(async function update_remote_defaults_readyPromise() { "Update called after enrollment processed." ); - manager.store._deleteForTests("aboutwelcome"); + manager.unenroll(MATCHING_ROLLOUT.slug, "test-cleanup"); + await assertEmptyStore(manager.store); sandbox.restore(); }); @@ -229,7 +242,8 @@ add_task(async function update_remote_defaults_enabled() { "Feature is disabled by remote configuration" ); - manager.store._deleteForTests("aboutwelcome"); + manager.unenroll(NON_MATCHING_ROLLOUT.slug, "test-cleanup"); + await assertEmptyStore(manager.store); sandbox.restore(); }); @@ -252,6 +266,7 @@ add_task(async function test_getVariable_no_mutation() { Assert.ok(feature.getVariable("mochitest"), "Got back the expected feature"); + await assertEmptyStore(manager.store); sandbox.restore(); }); @@ -284,4 +299,7 @@ add_task(async function remote_isEarlyStartup_config() { Services.prefs.clearUserPref( "nimbus.syncdefaultsstore.password-autocomplete" ); + + manager.unenroll(rollout.slug, "test-cleanup"); + await assertEmptyStore(manager.store); }); diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentManager_enroll.js b/toolkit/components/nimbus/test/unit/test_ExperimentManager_enroll.js index 1a57b33d66..4bc67a5883 100644 --- a/toolkit/components/nimbus/test/unit/test_ExperimentManager_enroll.js +++ b/toolkit/components/nimbus/test/unit/test_ExperimentManager_enroll.js @@ -670,7 +670,6 @@ add_task(async function enroll_in_reference_aw_experiment() { Assert.ok(prefValue.length < 3498, "Make sure we don't bloat the prefs"); manager.unenroll(recipe.slug, "enroll_in_reference_aw_experiment:cleanup"); - manager.store._deleteForTests("aboutwelcome"); await assertEmptyStore(manager.store); }); @@ -756,6 +755,7 @@ add_task(async function test_rollout_unenroll_conflict() { ); Assert.ok(enrollStub.calledOnce, "Should call enroll as expected"); + manager.unenroll(rollout.slug, "test-cleanup"); await assertEmptyStore(manager.store); sandbox.restore(); @@ -838,7 +838,6 @@ add_task(async function test_forceEnroll() { for (const { slug } of expected) { manager.unenroll(`optin-${slug}`); - manager.store._deleteForTests(`optin-${slug}`); } } diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js b/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js index a32de32cd6..2173e34b5a 100644 --- a/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js +++ b/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js @@ -513,7 +513,9 @@ add_task(async function test_check_unseen_enrollments_telemetry_events() { featureId: "nimbusTelemetry", value: { gleanMetricConfiguration: { - "nimbus_events.enrollment_status": true, + metrics_enabled: { + "nimbus_events.enrollment_status": true, + }, }, }, }, diff --git a/toolkit/components/normandy/lib/AddonRollouts.sys.mjs b/toolkit/components/normandy/lib/AddonRollouts.sys.mjs index ab2994a5f9..2e3f969920 100644 --- a/toolkit/components/normandy/lib/AddonRollouts.sys.mjs +++ b/toolkit/components/normandy/lib/AddonRollouts.sys.mjs @@ -37,13 +37,13 @@ ChromeUtils.defineESModuleGetters(lazy, { const DB_NAME = "normandy-addon-rollout"; const STORE_NAME = "addon-rollouts"; -const DB_OPTIONS = { version: 1 }; +const DB_VERSION = 1; /** * Create a new connection to the database. */ function openDatabase() { - return lazy.IndexedDB.open(DB_NAME, DB_OPTIONS, db => { + return lazy.IndexedDB.open(DB_NAME, DB_VERSION, db => { db.createObjectStore(STORE_NAME, { keyPath: "slug", }); diff --git a/toolkit/components/passwordmgr/LoginAutoComplete.sys.mjs b/toolkit/components/passwordmgr/LoginAutoComplete.sys.mjs index 187caf9d62..a7ea1bfa2c 100644 --- a/toolkit/components/passwordmgr/LoginAutoComplete.sys.mjs +++ b/toolkit/components/passwordmgr/LoginAutoComplete.sys.mjs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * nsIAutoCompleteResult and nsILoginAutoCompleteSearch implementations for saved logins. + * nsIAutoCompleteResult implementations for saved logins. */ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; @@ -15,11 +15,7 @@ import { const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { - InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.sys.mjs", - LoginFormFactory: "resource://gre/modules/LoginFormFactory.sys.mjs", LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs", - LoginManagerChild: "resource://gre/modules/LoginManagerChild.sys.mjs", - NewPasswordModel: "resource://gre/modules/NewPasswordModel.sys.mjs", }); XPCOMUtils.defineLazyServiceGetter( lazy, @@ -335,6 +331,8 @@ export class LoginAutoCompleteResult { // The footer comes last if it's enabled if (isFooterEnabled()) { + // TODO: This would be removed once autofill is triggered from the parent. + gAutoCompleteListener.init(); if (autocompleteItems) { this.#rows.push( ...autocompleteItems.map( @@ -472,252 +470,6 @@ export class LoginAutoCompleteResult { } } -export class LoginAutoComplete { - // HTMLInputElement to number, the element's new-password heuristic confidence score - #cachedNewPasswordScore = new WeakMap(); - #autoCompleteLookupPromise = null; - classID = Components.ID("{2bdac17c-53f1-4896-a521-682ccdeef3a8}"); - QueryInterface = ChromeUtils.generateQI(["nsILoginAutoCompleteSearch"]); - - /** - * Yuck. This is called directly by satchel: - * nsFormFillController::StartSearch() - * [toolkit/components/satchel/nsFormFillController.cpp] - * - * We really ought to have a simple way for code to register an - * auto-complete provider, and not have satchel calling pwmgr directly. - * - * @param {string} aSearchString The value typed in the field. - * @param {nsIAutoCompleteResult} aPreviousResult - * @param {HTMLInputElement} aElement - * @param {nsIFormFillCompleteObserver} aCallback - */ - startSearch(aSearchString, aPreviousResult, aElement, aCallback) { - let { isNullPrincipal } = aElement.nodePrincipal; - if ( - aElement.nodePrincipal.schemeIs("about") || - aElement.nodePrincipal.isSystemPrincipal - ) { - // Don't show autocomplete results for about: pages. - // XXX: Don't we need to call the callback here? - return; - } - - let searchStartTimeMS = Services.telemetry.msSystemNow(); - - // Show the insecure login warning in the passwords field on null principal documents. - // Avoid loading InsecurePasswordUtils.sys.mjs in a sandboxed document (e.g. an ad. frame) if we - // already know it has a null principal and will therefore get the insecure autocomplete - // treatment. - // InsecurePasswordUtils doesn't handle the null principal case as not secure because we don't - // want the same treatment: - // * The web console warnings will be confusing (as they're primarily about http:) and not very - // useful if the developer intentionally sandboxed the document. - // * The site identity insecure field warning would require LoginManagerChild being loaded and - // listening to some of the DOM events we're ignoring in null principal documents. For memory - // reasons it's better to not load LMC at all for these sandboxed frames. Also, if the top- - // document is sandboxing a document, it probably doesn't want that sandboxed document to be - // able to affect the identity icon in the address bar by adding a password field. - let form = lazy.LoginFormFactory.createFromField(aElement); - let isSecure = - !isNullPrincipal && lazy.InsecurePasswordUtils.isFormSecure(form); - let { hasBeenTypePassword } = aElement; - let hostname = aElement.ownerDocument.documentURIObject.host; - let formOrigin = lazy.LoginHelper.getLoginOrigin( - aElement.ownerDocument.documentURI - ); - let loginManagerActor = lazy.LoginManagerChild.forWindow( - aElement.ownerGlobal - ); - let completeSearch = async autoCompleteLookupPromise => { - // Assign to the member synchronously before awaiting the Promise. - this.#autoCompleteLookupPromise = autoCompleteLookupPromise; - - let { - generatedPassword, - importable, - logins, - autocompleteItems, - willAutoSaveGeneratedPassword, - } = await autoCompleteLookupPromise; - - // If the search was canceled before we got our - // results, don't bother reporting them. - // N.B. This check must occur after the `await` above for it to be - // effective. - if (this.#autoCompleteLookupPromise !== autoCompleteLookupPromise) { - lazy.log.debug("Ignoring result from previous search."); - return; - } - - let telemetryEventData = { - acFieldName: aElement.getAutocompleteInfo().fieldName, - hadPrevious: !!aPreviousResult, - typeWasPassword: aElement.hasBeenTypePassword, - fieldType: aElement.type, - searchStartTimeMS, - stringLength: aSearchString.length, - }; - - this.#autoCompleteLookupPromise = null; - let results = new LoginAutoCompleteResult( - aSearchString, - logins, - autocompleteItems, - formOrigin, - { - generatedPassword, - willAutoSaveGeneratedPassword, - importable, - actor: loginManagerActor, - isSecure, - hasBeenTypePassword, - hostname, - telemetryEventData, - } - ); - aCallback.onSearchCompletion(results); - }; - - if (isNullPrincipal) { - // Don't search login storage when the field has a null principal as we don't want to fill - // logins for the `location` in this case. - completeSearch(Promise.resolve({ logins: [] })); - return; - } - - if ( - hasBeenTypePassword && - aSearchString && - !loginManagerActor.isPasswordGenerationForcedOn(aElement) - ) { - // Return empty result on password fields with password already filled, - // unless password generation was forced. - completeSearch(Promise.resolve({ logins: [] })); - return; - } - - if (!lazy.LoginHelper.enabled) { - completeSearch(Promise.resolve({ logins: [] })); - return; - } - - let previousResult; - if (aPreviousResult) { - previousResult = { - searchString: aPreviousResult.searchString, - logins: lazy.LoginHelper.loginsToVanillaObjects( - aPreviousResult.wrappedJSObject.logins - ), - }; - } else { - previousResult = null; - } - - let acLookupPromise = this.#requestAutoCompleteResultsFromParent({ - searchString: aSearchString, - previousResult, - inputElement: aElement, - form, - hasBeenTypePassword, - }); - completeSearch(acLookupPromise).catch(lazy.log.error.bind(lazy.log)); - } - - stopSearch() { - this.#autoCompleteLookupPromise = null; - } - - async #requestAutoCompleteResultsFromParent({ - searchString, - previousResult, - inputElement, - form, - hasBeenTypePassword, - }) { - let actionOrigin = lazy.LoginHelper.getFormActionOrigin(form); - let autocompleteInfo = inputElement.getAutocompleteInfo(); - - let loginManagerActor = lazy.LoginManagerChild.forWindow( - inputElement.ownerGlobal - ); - let forcePasswordGeneration = false; - let isProbablyANewPasswordField = false; - if (hasBeenTypePassword) { - forcePasswordGeneration = - loginManagerActor.isPasswordGenerationForcedOn(inputElement); - // Run the Fathom model only if the password field does not have the - // autocomplete="new-password" attribute. - isProbablyANewPasswordField = - autocompleteInfo.fieldName == "new-password" || - this.isProbablyANewPasswordField(inputElement); - } - const scenario = loginManagerActor.getScenario(inputElement); - - if (lazy.LoginHelper.showAutoCompleteFooter) { - gAutoCompleteListener.init(); - } - - lazy.log.debug("LoginAutoComplete search:", { - forcePasswordGeneration, - hasBeenTypePassword, - isProbablyANewPasswordField, - searchStringLength: searchString.length, - }); - - const result = await loginManagerActor.sendQuery( - "PasswordManager:autoCompleteLogins", - { - actionOrigin, - searchString, - previousResult, - forcePasswordGeneration, - hasBeenTypePassword, - isProbablyANewPasswordField, - scenarioName: scenario?.constructor.name, - inputMaxLength: inputElement.maxLength, - isWebAuthn: this.#isWebAuthnCredentials(autocompleteInfo), - } - ); - - return { - generatedPassword: result.generatedPassword, - importable: result.importable, - autocompleteItems: result.autocompleteItems, - logins: lazy.LoginHelper.vanillaObjectsToLogins(result.logins), - willAutoSaveGeneratedPassword: result.willAutoSaveGeneratedPassword, - }; - } - - isProbablyANewPasswordField(inputElement) { - const threshold = lazy.LoginHelper.generationConfidenceThreshold; - if (threshold == -1) { - // Fathom is disabled - return false; - } - - let score = this.#cachedNewPasswordScore.get(inputElement); - if (score) { - return score >= threshold; - } - - const { rules, type } = lazy.NewPasswordModel; - const results = rules.against(inputElement); - score = results.get(inputElement).scoreFor(type); - this.#cachedNewPasswordScore.set(inputElement, score); - return score >= threshold; - } - - /** - * @param {string} autocompleteInfo - * @returns whether the non-autofill credential type (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#non-autofill-credential-type) - * of the input field is "webauthn" - */ - #isWebAuthnCredentials(autocompleteInfo) { - return autocompleteInfo.credentialType == "webauthn"; - } -} - let gAutoCompleteListener = { added: false, diff --git a/toolkit/components/passwordmgr/LoginHelper.sys.mjs b/toolkit/components/passwordmgr/LoginHelper.sys.mjs index 5626312f17..615ac79449 100644 --- a/toolkit/components/passwordmgr/LoginHelper.sys.mjs +++ b/toolkit/components/passwordmgr/LoginHelper.sys.mjs @@ -18,6 +18,13 @@ ChromeUtils.defineESModuleGetters(lazy, { OSKeyStore: "resource://gre/modules/OSKeyStore.sys.mjs", }); +XPCOMUtils.defineLazyServiceGetter( + lazy, + "Crypto", + "@mozilla.org/login-manager/crypto/SDR;1", + "nsILoginManagerCrypto" +); + export class ParentAutocompleteOption { image; title; @@ -366,7 +373,7 @@ class ImportRowProcessor { return this.summary; } } - +const OS_AUTH_FOR_PASSWORDS_PREF = "signon.management.page.os-auth.optout"; /** * Contains functions shared by different Login Manager components. */ @@ -394,6 +401,7 @@ export const LoginHelper = { testOnlyUserHasInteractedWithDocument: null, userInputRequiredToCapture: null, captureInputChanges: null, + OS_AUTH_FOR_PASSWORDS_PREF, init() { // Watch for pref changes to update cached pref values. @@ -1582,6 +1590,90 @@ export const LoginHelper = { return token.hasPassword; }, + /** + * Get the decrypted value for a string pref. + * + * @param {string} prefName -> The pref whose value is needed. + * @param {string} safeDefaultValue -> Value to be returned incase the pref is not yet set. + * @returns {string} + */ + getSecurePref(prefName, safeDefaultValue) { + try { + const encryptedValue = Services.prefs.getStringPref(prefName, ""); + return encryptedValue === "" + ? safeDefaultValue + : lazy.Crypto.decrypt(encryptedValue); + } catch { + return safeDefaultValue; + } + }, + + /** + * Set the pref to the encrypted form of the value. + * + * @param {string} prefName -> The pref whose value is to be set. + * @param {string} value -> The value to be set in its encrypted form. + */ + setSecurePref(prefName, value) { + if (value) { + const encryptedValue = lazy.Crypto.encrypt(value); + Services.prefs.setStringPref(prefName, encryptedValue); + } else { + Services.prefs.clearUserPref(prefName); + } + }, + + /** + * Get whether the OSAuth is enabled or not. + * + * @param {string} prefName -> The name of the pref (creditcards or addresses) + * @returns {boolean} + */ + getOSAuthEnabled(prefName) { + return ( + lazy.OSKeyStore.canReauth() && + this.getSecurePref(prefName, "") !== "opt out" + ); + }, + + /** + * Set whether the OSAuth is enabled or not. + * + * @param {string} prefName -> The pref to encrypt. + * @param {boolean} enable -> Whether the pref is to be enabled. + */ + setOSAuthEnabled(prefName, enable) { + this.setSecurePref(prefName, enable ? null : "opt out"); + }, + + async verifyUserOSAuth( + prefName, + promptMessage, + captionDialog = "", + parentWindow = null, + generateKeyIfNotAvailable = true + ) { + if (!this.getOSAuthEnabled(prefName)) { + promptMessage = false; + } + try { + return ( + await lazy.OSKeyStore.ensureLoggedIn( + promptMessage, + captionDialog, + parentWindow, + generateKeyIfNotAvailable + ) + ).authenticated; + } catch (ex) { + // Since Win throws an exception whereas Mac resolves to false upon cancelling. + if (ex.result !== Cr.NS_ERROR_FAILURE) { + throw ex; + } + } + return false; + }, + /** * Shows the Primary Password prompt if enabled, or the * OS auth dialog otherwise. @@ -1637,18 +1729,21 @@ export const LoginHelper = { } // Use the OS auth dialog if there is no primary password if (!token.hasPassword && OSReauthEnabled) { - let result = await lazy.OSKeyStore.ensureLoggedIn( + let isAuthorized = await this.verifyUserOSAuth( + OS_AUTH_FOR_PASSWORDS_PREF, messageText, captionText, browser.ownerGlobal, false ); - isAuthorized = result.authenticated; + let value = lazy.OSKeyStore.canReauth() + ? "success" + : "success_unsupported_platform"; + telemetryEvent = { object: "os_auth", method: "reauthenticate", - value: result.auth_details, - extra: result.auth_details_extra, + value: isAuthorized ? value : "fail", }; return { isAuthorized, diff --git a/toolkit/components/passwordmgr/LoginManagerChild.sys.mjs b/toolkit/components/passwordmgr/LoginManagerChild.sys.mjs index 66f45416f8..5433083ede 100644 --- a/toolkit/components/passwordmgr/LoginManagerChild.sys.mjs +++ b/toolkit/components/passwordmgr/LoginManagerChild.sys.mjs @@ -51,10 +51,12 @@ ChromeUtils.defineESModuleGetters(lazy, { FormScenarios: "resource://gre/modules/FormScenarios.sys.mjs", FORM_SUBMISSION_REASON: "resource://gre/actors/FormHandlerChild.sys.mjs", InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.sys.mjs", + LoginAutoCompleteResult: "resource://gre/modules/LoginAutoComplete.sys.mjs", LoginFormFactory: "resource://gre/modules/LoginFormFactory.sys.mjs", LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs", LoginRecipesContent: "resource://gre/modules/LoginRecipes.sys.mjs", LoginManagerTelemetry: "resource://gre/modules/LoginManagerTelemetry.sys.mjs", + NewPasswordModel: "resource://gre/modules/NewPasswordModel.sys.mjs", }); XPCOMUtils.defineLazyServiceGetter( @@ -157,40 +159,6 @@ const observer = { loginManagerChild()._onNavigation(window.document); }, - // nsIObserver - observe(subject, topic, _data) { - switch (topic) { - case "autocomplete-did-enter-text": { - let input = subject.QueryInterface(Ci.nsIAutoCompleteInput); - let { selectedIndex } = input.popup; - if (selectedIndex < 0 || selectedIndex >= input.controller.matchCount) { - break; - } - - let { focusedInput } = lazy.gFormFillService; - if (focusedInput.nodePrincipal.isNullPrincipal) { - // If we have a null principal then prevent any more password manager code from running and - // incorrectly using the document `location`. - return; - } - - let window = focusedInput.ownerGlobal; - let loginManagerChild = LoginManagerChild.forWindow(window); - - let style = input.controller.getStyleAt(selectedIndex); - if (style == "login" || style == "loginWithOrigin") { - let details = JSON.parse( - input.controller.getCommentAt(selectedIndex) - ); - loginManagerChild.onFieldAutoComplete(focusedInput, details.guid); - } else if (style == "generatedPassword") { - loginManagerChild._filledWithGeneratedPassword(focusedInput); - } - break; - } - } - }, - // nsIDOMEventListener handleEvent(aEvent) { if (!aEvent.isTrusted) { @@ -435,9 +403,6 @@ const observer = { }, }; -// Add this observer once for the process. -Services.obs.addObserver(observer, "autocomplete-did-enter-text"); - /** * Form scenario defines what can be done with form. */ @@ -812,7 +777,9 @@ export class LoginFormState { // The login manager is responsible for fields with the "webauthn" credential type. let acCredentialType = focusedField.getAutocompleteInfo()?.credentialType; if (acCredentialType == "webauthn") { - lazy.gFormFillService.markAsLoginManagerField(focusedField); + const actor = + focusedField.ownerGlobal.windowGlobalChild.getActor("LoginManager"); + actor.markAsAutoCompletableField(focusedField); } lazy.log("Opening the autocomplete popup."); @@ -1525,6 +1492,16 @@ export class LoginManagerChild extends JSWindowActorChild { this.notifyObserversOfFormProcessed(msg.data.formid); break; } + case "PasswordManager:fillFields": { + const login = lazy.LoginHelper.vanillaObjectToLogin(msg.data); + this.fillFields(login); + break; + } + case "PasswordManager:fillGeneratedPassword": { + const { focusedInput } = lazy.gFormFillService; + this.filledWithGeneratedPassword(focusedInput); + break; + } } return undefined; @@ -2174,7 +2151,7 @@ export class LoginManagerChild extends JSWindowActorChild { /** * A username or password was autocompleted into a field. */ - onFieldAutoComplete(acInputField, loginGUID) { + onFieldAutoComplete(acInputField, login) { if (!lazy.LoginHelper.enabled) { return; } @@ -2189,7 +2166,7 @@ export class LoginManagerChild extends JSWindowActorChild { } if (lazy.LoginHelper.isUsernameFieldType(acInputField)) { - this.onUsernameAutocompleted(acInputField, loginGUID); + this.onUsernameAutocompleted(acInputField, [login]); } else if (acInputField.hasBeenTypePassword) { // Ensure the field gets re-masked and edits don't overwrite the generated // password in case a generated password was filled into it previously. @@ -2203,7 +2180,7 @@ export class LoginManagerChild extends JSWindowActorChild { * A username field was filled or tabbed away from so try fill in the * associated password in the password field. */ - onUsernameAutocompleted(acInputField, loginGUID = null) { + async onUsernameAutocompleted(acInputField, loginsFound = null) { lazy.log(`Autocompleting input field with name: ${acInputField.name}`); let acForm = lazy.LoginFormFactory.createFromField(acInputField); @@ -2219,43 +2196,49 @@ export class LoginManagerChild extends JSWindowActorChild { const docState = this.stateForDocument(acInputField.ownerDocument); let { usernameField, newPasswordField: passwordField } = docState._getFormFields(acForm, false, recipes); - if (usernameField == acInputField) { - // Fill the form when a password field is present. - if (passwordField) { - this._getLoginDataFromParent(acForm, { - guid: loginGUID, - showPrimaryPassword: false, - }) - .then(({ form, loginsFound, recipes }) => { - if (!loginGUID) { - // not an explicit autocomplete menu selection, filter for exact matches only - loginsFound = this._filterForExactFormOriginLogins( - loginsFound, - acForm - ); - // filter the list for exact matches with the username - // NOTE: this could be an empty string which is a valid username - let searchString = usernameField.value.toLowerCase(); - loginsFound = loginsFound.filter( - l => l.username.toLowerCase() == searchString - ); - } - - this._fillForm(form, loginsFound, recipes, { - autofillForm: true, - clobberPassword: true, - userTriggered: true, - }); - }) - .catch(console.error); - // Use `loginGUID !== null` to distinguish whether this is called when the - // field is filled or tabbed away from. For the latter, don't highlight the field. - } else if (loginGUID !== null) { + // Ignore the event, it's for some input we don't care about. + if (usernameField != acInputField) { + return; + } + + if (!passwordField) { + // Use `loginsFound !== null` to distinguish whether this is called when the + // field is filled or tabbed away from. For the latter, don't highlight the field. + if (loginsFound !== null) { LoginFormState._highlightFilledField(usernameField); } - } else { - // Ignore the event, it's for some input we don't care about. + return; + } + + // Fill the form when a password field is present. + if (!loginsFound) { + const loginData = await this._getLoginDataFromParent(acForm, { + showPrimaryPassword: false, + }).catch(console.error); + + if (!loginData?.loginsFound.length) { + return; + } + + // not an explicit autocomplete menu selection, filter for exact matches only + loginsFound = this._filterForExactFormOriginLogins( + loginData.loginsFound, + acForm + ); + // filter the list for exact matches with the username + // NOTE: this could be an empty string which is a valid username + const searchString = usernameField.value.toLowerCase(); + loginsFound = loginsFound.filter( + l => l.username.toLowerCase() == searchString + ); + recipes = loginData.recipes; } + + this._fillForm(acForm, loginsFound, recipes, { + autofillForm: true, + clobberPassword: true, + userTriggered: true, + }); } /** @@ -2399,7 +2382,7 @@ export class LoginManagerChild extends JSWindowActorChild { }; if (fields.usernameField) { - lazy.gFormFillService.markAsLoginManagerField(fields.usernameField); + this.markAsAutoCompletableField(fields.usernameField); } // It's possible the field triggering this message isn't one of those found by _getFormFields' heuristics @@ -2639,7 +2622,7 @@ export class LoginManagerChild extends JSWindowActorChild { * field is handled accordingly. * @param {HTMLInputElement} passwordField */ - _filledWithGeneratedPassword(passwordField) { + filledWithGeneratedPassword(passwordField) { LoginFormState._highlightFilledField(passwordField); this._passwordEditedOrGenerated(passwordField, { triggeredByFillingGenerated: true, @@ -2821,7 +2804,7 @@ export class LoginManagerChild extends JSWindowActorChild { if (scenario) { docState.setScenario(form.rootElement, scenario); - lazy.gFormFillService.markAsLoginManagerField(usernameField); + this.markAsAutoCompletableField(usernameField); } } @@ -2868,7 +2851,7 @@ export class LoginManagerChild extends JSWindowActorChild { // We would also need this attached to show the insecure login // warning, regardless of saved login. if (usernameField) { - lazy.gFormFillService.markAsLoginManagerField(usernameField); + this.markAsAutoCompletableField(usernameField); usernameField.addEventListener("keydown", observer); } @@ -3116,7 +3099,7 @@ export class LoginManagerChild extends JSWindowActorChild { } if (style === "generatedPassword") { - this._filledWithGeneratedPassword(passwordField); + this.filledWithGeneratedPassword(passwordField); } lazy.log("_fillForm succeeded"); @@ -3173,4 +3156,199 @@ export class LoginManagerChild extends JSWindowActorChild { const docState = this.stateForDocument(inputElement.ownerDocument); return docState.getScenario(inputElement); } + + #interestedInputs = []; + + markAsAutoCompletableField(input) { + this.#interestedInputs.push(input); + this.manager + .getActor("AutoComplete") + ?.markAsAutoCompletableField(input, this); + } + + get actorName() { + return "LoginManager"; + } + + /** + * Get the search options when searching for autocomplete entries in the parent + * + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @returns {object} the search options for the input + */ + getAutoCompleteSearchOption(input, searchString) { + const form = lazy.LoginFormFactory.createFromField(input); + const formOrigin = lazy.LoginHelper.getLoginOrigin( + input.ownerDocument.documentURI + ); + const actionOrigin = lazy.LoginHelper.getFormActionOrigin(form); + const autocompleteInfo = input.getAutocompleteInfo(); + const hasBeenTypePassword = input.hasBeenTypePassword; + + let forcePasswordGeneration = false; + let isProbablyANewPasswordField = false; + if (hasBeenTypePassword) { + forcePasswordGeneration = this.isPasswordGenerationForcedOn(input); + // Run the Fathom model only if the password field does not have the + // autocomplete="new-password" attribute. + isProbablyANewPasswordField = + autocompleteInfo.fieldName == "new-password" || + this.isProbablyANewPasswordField(input); + } + + const scenarioName = lazy.FormScenarios.detect({ input }).signUpForm + ? "SignUpFormScenario" + : ""; + + const r = { + formOrigin, + actionOrigin, + searchString, + forcePasswordGeneration, + hasBeenTypePassword, + isProbablyANewPasswordField, + scenarioName, + inputMaxLength: input.maxLength, + isWebAuthn: this.#isWebAuthnCredentials(autocompleteInfo), + }; + return r; + } + + #searchStartTimeMS = null; + + /** + * Ask the provider whether it might have autocomplete entry to show + * for the given input. + * + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @returns {boolean} true if we shold search for autocomplete entries + */ + shouldSearchForAutoComplete(input, searchString) { + this.#searchStartTimeMS = Services.telemetry.msSystemNow(); + + // Don't search login storage when the field has a null principal as we don't want to fill + // logins for the `location` in this case. + if (input.nodePrincipal.isNullPrincipal) { + return false; + } + + // Return empty result on password fields with password already filled, + // unless password generation was forced. + if ( + input.hasBeenTypePassword && + searchString && + !this.isPasswordGenerationForcedOn(input) + ) { + return false; + } + + if (!lazy.LoginHelper.enabled) { + return false; + } + + return true; + } + + /** + * Convert the search result to autocomplete results + * + * @param {string} searchString - The string to search for + * @param {HTMLInputElement} input - The input element to search for autocompelte entries + * @param {Array} records - autocomplete records + * @returns {AutocompleteResult} + */ + searchResultToAutoCompleteResult(searchString, input, records) { + if ( + input.nodePrincipal.schemeIs("about") || + input.nodePrincipal.isSystemPrincipal + ) { + // Don't show autocomplete results for about: pages. + return null; + } + + let { + generatedPassword, + autocompleteItems, + importable, + logins, + willAutoSaveGeneratedPassword, + } = records ?? {}; + logins ||= []; + + const formOrigin = lazy.LoginHelper.getLoginOrigin( + input.ownerDocument.documentURI + ); + + const isNullPrincipal = input.nodePrincipal.isNullPrincipal; + const form = lazy.LoginFormFactory.createFromField(input); + const isSecure = + !isNullPrincipal && lazy.InsecurePasswordUtils.isFormSecure(form); + + const telemetryEventData = { + acFieldName: input.getAutocompleteInfo().fieldName, + //hadPrevious: !!aPreviousResult, + hadPrevious: false, + typeWasPassword: input.hasBeenTypePassword, + fieldType: input.type, + searchStartTimeMS: this.#searchStartTimeMS, + stringLength: searchString.length, + }; + + const acResult = new lazy.LoginAutoCompleteResult( + searchString, + lazy.LoginHelper.vanillaObjectsToLogins(logins), + autocompleteItems, + formOrigin, + { + generatedPassword, + willAutoSaveGeneratedPassword, + importable, + actor: this, + isSecure, + hasBeenTypePassword: input.hasBeenTypePassword, + hostname: input.ownerDocument.documentURIObject.host, + telemetryEventData, + } + ); + return acResult; + } + + isLoginManagerField(input) { + return input.hasBeenTypePassword || this.#interestedInputs.includes(input); + } + + #cachedNewPasswordScore = new WeakMap(); + + isProbablyANewPasswordField(inputElement) { + const threshold = lazy.LoginHelper.generationConfidenceThreshold; + if (threshold == -1) { + // Fathom is disabled + return false; + } + + let score = this.#cachedNewPasswordScore.get(inputElement); + if (score) { + return score >= threshold; + } + + const { rules, type } = lazy.NewPasswordModel; + const results = rules.against(inputElement); + score = results.get(inputElement).scoreFor(type); + this.#cachedNewPasswordScore.set(inputElement, score); + return score >= threshold; + } + + /** + * @param {string} autocompleteInfo + * @returns whether the non-autofill credential type (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#non-autofill-credential-type) + * of the input field is "webauthn" + */ + #isWebAuthnCredentials(autocompleteInfo) { + return autocompleteInfo.credentialType == "webauthn"; + } + + fillFields(login) { + let { focusedInput } = lazy.gFormFillService; + this.onFieldAutoComplete(focusedInput, login); + } } diff --git a/toolkit/components/passwordmgr/LoginManagerParent.sys.mjs b/toolkit/components/passwordmgr/LoginManagerParent.sys.mjs index 862ab6b846..cb3ea2bd7c 100644 --- a/toolkit/components/passwordmgr/LoginManagerParent.sys.mjs +++ b/toolkit/components/passwordmgr/LoginManagerParent.sys.mjs @@ -829,15 +829,19 @@ export class LoginManagerParent extends JSWindowActorParent { })) ); } - autocompleteItems.push( - ...(await lazy.WebAuthnFeature.autocompleteItemsAsync( - this._overrideBrowsingContextId ?? - this.getRootBrowser().browsingContext.id, - formOrigin, - scenarioName, - isWebAuthn - )) - ); + // This check is only used to init webauthn in tests, which causes + // intermittent like Bug 1890419. + if (LoginManagerParent._webAuthnAutoComplete) { + autocompleteItems.push( + ...(await lazy.WebAuthnFeature.autocompleteItemsAsync( + this._overrideBrowsingContextId ?? + this.getRootBrowser().browsingContext.id, + formOrigin, + scenarioName, + isWebAuthn + )) + ); + } return { generatedPassword, @@ -1541,6 +1545,27 @@ export class LoginManagerParent extends JSWindowActorParent { return gRecipeManager.initializationPromise; } + + async searchAutoCompleteEntries(searchString, data) { + return this.doAutocompleteSearch(data.formOrigin, data); + } + + previewFields(_result) { + // Logins do not show previews + } + + autofillFields(result) { + if (result.style == "login" || result.style == "loginWithOrigin") { + try { + const profile = JSON.parse(result.comment); + this.sendAsyncMessage("PasswordManager:fillFields", profile.login); + } catch (e) { + lazy.log("Fail to get autofill profile: ", e.message); + } + } else if (result.style == "generatedPassword") { + this.sendAsyncMessage("PasswordManager:fillGeneratedPassword"); + } + } } LoginManagerParent.SUGGEST_IMPORT_DEBOUNCE_MS = 10000; @@ -1551,3 +1576,10 @@ XPCOMUtils.defineLazyPreferenceGetter( "signon.masterPasswordReprompt.timeout_ms", 900000 ); // 15 Minutes + +XPCOMUtils.defineLazyPreferenceGetter( + LoginManagerParent, + "_webAuthnAutoComplete", + "signon.webauthn.autocomplete", + true +); diff --git a/toolkit/components/passwordmgr/moz.build b/toolkit/components/passwordmgr/moz.build index 4fbb9dcbf4..16e4303702 100644 --- a/toolkit/components/passwordmgr/moz.build +++ b/toolkit/components/passwordmgr/moz.build @@ -16,7 +16,6 @@ TESTING_JS_MODULES += [ ] XPIDL_SOURCES += [ - "nsILoginAutoCompleteSearch.idl", "nsILoginInfo.idl", "nsILoginManager.idl", "nsILoginManagerAuthPrompter.idl", diff --git a/toolkit/components/passwordmgr/nsILoginAutoCompleteSearch.idl b/toolkit/components/passwordmgr/nsILoginAutoCompleteSearch.idl deleted file mode 100644 index 586292d04d..0000000000 --- a/toolkit/components/passwordmgr/nsILoginAutoCompleteSearch.idl +++ /dev/null @@ -1,31 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" - -interface nsIAutoCompleteResult; -interface nsIFormFillCompleteObserver; - -webidl HTMLInputElement; - -[scriptable, uuid(2bdac17c-53f1-4896-a521-682ccdeef3a8)] -interface nsILoginAutoCompleteSearch : nsISupports { - /** - * Generate results for a login field autocomplete menu. - * - * NOTE: This interface is provided for use only by the FormFillController, - * which calls it directly. This isn't really ideal, it should - * probably be callback registered through the FFC. - * NOTE: This API is different than nsIAutoCompleteSearch. - */ - void startSearch(in AString aSearchString, - in nsIAutoCompleteResult aPreviousResult, - in HTMLInputElement aElement, - in nsIFormFillCompleteObserver aListener); - - /** - * Stop a previously-started search. - */ - void stopSearch(); -}; diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html index 54cb450815..b5db098174 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_password_generation_confirm.html @@ -146,21 +146,29 @@ Login Manager test: filling generated passwords into confirm password fields "resetLoginsAndGeneratedPasswords", () => { LoginTestUtils.clearData(); LoginTestUtils.resetGeneratedPasswordsCache(); + return Promise.resolve(); } ); }); function resetLoginsAndGeneratedPasswords() { - return setupScript.sendAsyncMessage("resetLoginsAndGeneratedPasswords"); + return setupScript.sendQuery("resetLoginsAndGeneratedPasswords"); } async function triggerPasswordGeneration(form) { await openPopupOn(form.pword); synthesizeKey("KEY_ArrowDown"); synthesizeKey("KEY_Enter"); + + const storageAddPromise = promiseStorageChanged(["addLogin"]); await SimpleTest.promiseWaitForCondition(() => !!form.pword.value, "Wait for generated password to get filled"); + await storageAddPromise; } + add_setup(async () => { + SpecialPowers.pushPrefEnv({"set": [["signon.webauthn.autocomplete", false]]}); + }) + add_named_task("autocomplete menu contains option to generate password", async () => { await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form1); @@ -206,7 +214,7 @@ Login Manager test: filling generated passwords into confirm password fields await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form1); await triggerPasswordGeneration(form); - is(form.pwordNext.value, form.pword.value, "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pword.value == form.pwordNext.value, "Value of the confirm field has been filled with generated password"); }); add_named_task("password field is not masked initially after password generation", async () => { @@ -270,7 +278,7 @@ Login Manager test: filling generated passwords into confirm password fields form.pword.blur(); await messageSentPromise; - is(form.pwordNext.value, generatedPassword, "Value of the confirm field still holds the original generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == generatedPassword, "Value of the confirm field still holds the original generated password"); ok(form.pwordNext.matches(":autofill"), "Highlight is still applied to password confirmation field"); }); @@ -314,21 +322,21 @@ Login Manager test: filling generated passwords into confirm password fields form.pwordNext.focus() sendString("edited value"); await triggerPasswordGeneration(form); - is(form.pwordNext.value, "edited value", "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == "edited value", "Value of the confirm field has been filled with generated password"); }); add_named_task("password confirmation does not get filled with the generated password if its readonly", async () => { await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form3); await triggerPasswordGeneration(form); - is(form.pwordNext.value, "", "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == "", "Value of the confirm field has been filled with generated password"); }); add_named_task("password confirmation does not get filled with the generated password if its disabled", async () => { await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form4); await triggerPasswordGeneration(form); - is(form.pwordNext.value, "", "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == "", "Value of the confirm field has been filled with generated password"); }); add_named_task("password confirmation matching autocomplete info gets filled with the generated password", async () => { @@ -336,14 +344,14 @@ Login Manager test: filling generated passwords into confirm password fields const form = setContentForTask(formTemplates.form5); await triggerPasswordGeneration(form); is(form.pwordBetween.value, "", "Value of the between field has not been filled"); - is(form.pwordNext.value, form.pword.value, "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == form.pword.value, "Value of the confirm field has been filled with generated password"); }); add_named_task("password confirmation matching autocomplete info gets ignored if its disabled, even if has autocomplete info", async () => { await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form6); await triggerPasswordGeneration(form); - is(form.pwordNext.value, form.pword.value, "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == form.pword.value, "Value of the confirm field has been filled with generated password"); is(form.pwordAfter.value, "", "Value of the disabled confirmation field has not been filled"); }); @@ -365,7 +373,7 @@ Login Manager test: filling generated passwords into confirm password fields await resetLoginsAndGeneratedPasswords(); const form = setContentForTask(formTemplates.form9); await triggerPasswordGeneration(form); - is(form.pwordNext.value, form.pword.value, "Value of the confirm field has been filled with generated password"); + await SimpleTest.promiseWaitForCondition(() => form.pwordNext.value == form.pword.value, "Value of the confirm field has been filled with generated password"); }); add_named_task("do not fill third password field after the confirm-password field", async () => { diff --git a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html index 803197c2a2..ae4586f1bb 100644 --- a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html @@ -22,6 +22,8 @@ const iframe = document.getElementsByTagName("iframe")[0]; let iframeDoc, hostname; add_setup(async () => { + SpecialPowers.pushPrefEnv({"set": [["signon.webauthn.autocomplete", false]]}); + const origin = window.location.origin; await setStoredLoginsAsync( [origin, origin, null, "name", "pass"], @@ -96,9 +98,9 @@ add_task(async function test_not_reopened_after_selecting() { listenForUnexpectedPopupShown(); await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() { - let formFillController = SpecialPowers.getFormFillController(); + const actor = content.windowGlobalChild.getActor("AutoComplete"); let usernameField = this.content.document.getElementById("form-basic-username"); - formFillController.markAsLoginManagerField(usernameField); + actor.markAsAutoCompletableField(usernameField); }); info("Waiting to see if a popupshown occurs"); diff --git a/toolkit/components/passwordmgr/test/unit/test_isProbablyANewPasswordField.js b/toolkit/components/passwordmgr/test/unit/test_isProbablyANewPasswordField.js index 167c160da2..0bc88734d2 100644 --- a/toolkit/components/passwordmgr/test/unit/test_isProbablyANewPasswordField.js +++ b/toolkit/components/passwordmgr/test/unit/test_isProbablyANewPasswordField.js @@ -4,9 +4,10 @@ "use strict"; -const LoginAutoComplete = Cc[ - "@mozilla.org/login-manager/autocompletesearch;1" -].getService(Ci.nsILoginAutoCompleteSearch).wrappedJSObject; +const { LoginManagerChild } = ChromeUtils.importESModule( + "resource://gre/modules/LoginManagerChild.sys.mjs" +); + // TODO: create a fake window for the test document to pass fathom.isVisible check. // We should consider moving these tests to mochitest because many fathom // signals rely on visibility, position, etc., of the test element (See Bug 1712699), @@ -143,9 +144,10 @@ add_task(async function test_returns_false_when_pref_disabled() { "http://localhost:8080/test/", testcase.document ); + const lmc = new LoginManagerChild(); for (let [i, input] of testcase.inputs || document.querySelectorAll(`input[type="password"]`).entries()) { - const result = LoginAutoComplete.isProbablyANewPasswordField(input); + const result = lmc.isProbablyANewPasswordField(input); Assert.strictEqual( result, false, @@ -172,10 +174,11 @@ for (let testcase of TESTCASES) { document = makeDocumentVisibleToFathom(document); + const lmc = new LoginManagerChild(); const results = []; for (let input of testcase.inputs || document.querySelectorAll(`input[type="password"]`)) { - const result = LoginAutoComplete.isProbablyANewPasswordField(input); + const result = lmc.isProbablyANewPasswordField(input); results.push(result); } diff --git a/toolkit/components/pdfjs/content/build/pdf.mjs b/toolkit/components/pdfjs/content/build/pdf.mjs index dbba618862..9da8bfdf6e 100644 --- a/toolkit/components/pdfjs/content/build/pdf.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.mjs @@ -827,6 +827,12 @@ class BaseFilterFactory { addHCMFilter(fgColor, bgColor) { return "none"; } + addAlphaFilter(map) { + return "none"; + } + addLuminosityFilter(map) { + return "none"; + } addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) { return "none"; } @@ -1011,6 +1017,27 @@ class DOMFilterFactory extends BaseFilterFactory { } return this.#_defs; } + #createTables(maps) { + if (maps.length === 1) { + const mapR = maps[0]; + const buffer = new Array(256); + for (let i = 0; i < 256; i++) { + buffer[i] = mapR[i] / 255; + } + const table = buffer.join(","); + return [table, table, table]; + } + const [mapR, mapG, mapB] = maps; + const bufferR = new Array(256); + const bufferG = new Array(256); + const bufferB = new Array(256); + for (let i = 0; i < 256; i++) { + bufferR[i] = mapR[i] / 255; + bufferG[i] = mapG[i] / 255; + bufferB[i] = mapB[i] / 255; + } + return [bufferR.join(","), bufferG.join(","), bufferB.join(",")]; + } addFilter(maps) { if (!maps) { return "none"; @@ -1019,29 +1046,8 @@ class DOMFilterFactory extends BaseFilterFactory { if (value) { return value; } - let tableR, tableG, tableB, key; - if (maps.length === 1) { - const mapR = maps[0]; - const buffer = new Array(256); - for (let i = 0; i < 256; i++) { - buffer[i] = mapR[i] / 255; - } - key = tableR = tableG = tableB = buffer.join(","); - } else { - const [mapR, mapG, mapB] = maps; - const bufferR = new Array(256); - const bufferG = new Array(256); - const bufferB = new Array(256); - for (let i = 0; i < 256; i++) { - bufferR[i] = mapR[i] / 255; - bufferG[i] = mapG[i] / 255; - bufferB[i] = mapB[i] / 255; - } - tableR = bufferR.join(","); - tableG = bufferG.join(","); - tableB = bufferB.join(","); - key = `${tableR}${tableG}${tableB}`; - } + const [tableR, tableG, tableB] = this.#createTables(maps); + const key = maps.length === 1 ? tableR : `${tableR}${tableG}${tableB}`; value = this.#cache.get(key); if (value) { this.#cache.set(maps, value); @@ -1109,6 +1115,54 @@ class DOMFilterFactory extends BaseFilterFactory { info.url = `url(#${id})`; return info.url; } + addAlphaFilter(map) { + let value = this.#cache.get(map); + if (value) { + return value; + } + const [tableA] = this.#createTables([map]); + const key = `alpha_${tableA}`; + value = this.#cache.get(key); + if (value) { + this.#cache.set(map, value); + return value; + } + const id = `g_${this.#docId}_alpha_map_${this.#id++}`; + const url = `url(#${id})`; + this.#cache.set(map, url); + this.#cache.set(key, url); + const filter = this.#createFilter(id); + this.#addTransferMapAlphaConversion(tableA, filter); + return url; + } + addLuminosityFilter(map) { + let value = this.#cache.get(map || "luminosity"); + if (value) { + return value; + } + let tableA, key; + if (map) { + [tableA] = this.#createTables([map]); + key = `luminosity_${tableA}`; + } else { + key = "luminosity"; + } + value = this.#cache.get(key); + if (value) { + this.#cache.set(map, value); + return value; + } + const id = `g_${this.#docId}_luminosity_map_${this.#id++}`; + const url = `url(#${id})`; + this.#cache.set(map, url); + this.#cache.set(key, url); + const filter = this.#createFilter(id); + this.#addLuminosityConversion(filter); + if (map) { + this.#addTransferMapAlphaConversion(tableA, filter); + } + return url; + } addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) { const key = `${fgColor}-${bgColor}-${newFgColor}-${newBgColor}`; let info = this.#hcmCache.get(filterName); @@ -1179,6 +1233,12 @@ class DOMFilterFactory extends BaseFilterFactory { } this.#id = 0; } + #addLuminosityConversion(filter) { + const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix"); + feColorMatrix.setAttribute("type", "matrix"); + feColorMatrix.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"); + filter.append(feColorMatrix); + } #addGrayConversion(filter) { const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix"); feColorMatrix.setAttribute("type", "matrix"); @@ -1205,6 +1265,11 @@ class DOMFilterFactory extends BaseFilterFactory { this.#appendFeFunc(feComponentTransfer, "feFuncG", gTable); this.#appendFeFunc(feComponentTransfer, "feFuncB", bTable); } + #addTransferMapAlphaConversion(aTable, filter) { + const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer"); + filter.append(feComponentTransfer); + this.#appendFeFunc(feComponentTransfer, "feFuncA", aTable); + } #getRGB(color) { this.#defs.style.color = color; return getRGB(getComputedStyle(this.#defs).getPropertyValue("color")); @@ -2084,6 +2149,7 @@ class AnnotationEditorUIManager { #allLayers = new Map(); #altTextManager = null; #annotationStorage = null; + #changedExistingAnnotations = null; #commandManager = new CommandManager(); #currentPageIndex = 0; #deletedAnnotationsElementIds = new Set(); @@ -2858,6 +2924,7 @@ class AnnotationEditorUIManager { } addDeletedAnnotationElement(editor) { this.#deletedAnnotationsElementIds.add(editor.annotationElementId); + this.addChangedExistingAnnotation(editor); editor.deleted = true; } isDeletedAnnotationElement(annotationElementId) { @@ -2865,6 +2932,7 @@ class AnnotationEditorUIManager { } removeDeletedAnnotationElement(editor) { this.#deletedAnnotationsElementIds.delete(editor.annotationElementId); + this.removeChangedExistingAnnotation(editor); editor.deleted = false; } #addEditorToLayer(editor) { @@ -3269,6 +3337,31 @@ class AnnotationEditorUIManager { } return boxes.length === 0 ? null : boxes; } + addChangedExistingAnnotation({ + annotationElementId, + id + }) { + (this.#changedExistingAnnotations ||= new Map()).set(annotationElementId, id); + } + removeChangedExistingAnnotation({ + annotationElementId + }) { + this.#changedExistingAnnotations?.delete(annotationElementId); + } + renderAnnotationElement(annotation) { + const editorId = this.#changedExistingAnnotations?.get(annotation.data.id); + if (!editorId) { + return; + } + const editor = this.#annotationStorage.getRawValue(editorId); + if (!editor) { + return; + } + if (this.#mode === AnnotationEditorType.NONE && !editor.hasBeenModified) { + return; + } + editor.renderAnnotationElement(annotation); + } } ;// CONCATENATED MODULE: ./src/display/editor/alt_text.js @@ -3869,6 +3962,7 @@ class AnnotationEditor { }; this.parent.togglePointerEvents(false); window.addEventListener("pointermove", boundResizerPointermove, pointerMoveOptions); + window.addEventListener("contextmenu", noContextMenu); const savedX = this.x; const savedY = this.y; const savedWidth = this.width; @@ -3883,6 +3977,7 @@ class AnnotationEditor { window.removeEventListener("pointerup", pointerUpCallback); window.removeEventListener("blur", pointerUpCallback); window.removeEventListener("pointermove", boundResizerPointermove, pointerMoveOptions); + window.removeEventListener("contextmenu", noContextMenu); this.parent.div.style.cursor = savedParentCursor; this.div.style.cursor = savedCursor; this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight); @@ -4234,6 +4329,9 @@ class AnnotationEditor { editor.height = height / pageHeight; return editor; } + get hasBeenModified() { + return !!this.annotationElementId && (this.deleted || this.serialize() !== null); + } remove() { this.div.removeEventListener("focusin", this.#boundFocusin); this.div.removeEventListener("focusout", this.#boundFocusout); @@ -4493,6 +4591,28 @@ class AnnotationEditor { } this.#disabled = true; } + renderAnnotationElement(annotation) { + let content = annotation.container.querySelector(".annotationContent"); + if (!content) { + content = document.createElement("div"); + content.classList.add("annotationContent", this.editorType); + annotation.container.prepend(content); + } else if (content.nodeName === "CANVAS") { + const canvas = content; + content = document.createElement("div"); + content.classList.add("annotationContent", this.editorType); + canvas.before(content); + } + return content; + } + resetAnnotationElement(annotation) { + const { + firstChild + } = annotation.container; + if (firstChild.nodeName === "DIV" && firstChild.classList.contains("annotationContent")) { + firstChild.remove(); + } + } } class FakeEditor extends AnnotationEditor { constructor(params) { @@ -5596,7 +5716,6 @@ function grayToRGBA(src, dest) { const MIN_FONT_SIZE = 16; const MAX_FONT_SIZE = 100; -const MAX_GROUP_SIZE = 4096; const EXECUTION_TIME = 15; const EXECUTION_STEPS = 10; const MAX_SIZE_TO_COMPILE = 1000; @@ -6148,83 +6267,15 @@ function resetCtxToDefault(ctx) { ctx.filter = "none"; } } -function composeSMaskBackdrop(bytes, r0, g0, b0) { - const length = bytes.length; - for (let i = 3; i < length; i += 4) { - const alpha = bytes[i]; - if (alpha === 0) { - bytes[i - 3] = r0; - bytes[i - 2] = g0; - bytes[i - 1] = b0; - } else if (alpha < 255) { - const alpha_ = 255 - alpha; - bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8; - bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8; - bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8; - } - } -} -function composeSMaskAlpha(maskData, layerData, transferMap) { - const length = maskData.length; - const scale = 1 / 255; - for (let i = 3; i < length; i += 4) { - const alpha = transferMap ? transferMap[maskData[i]] : maskData[i]; - layerData[i] = layerData[i] * alpha * scale | 0; - } -} -function composeSMaskLuminosity(maskData, layerData, transferMap) { - const length = maskData.length; - for (let i = 3; i < length; i += 4) { - const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28; - layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16; - } -} -function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) { - const hasBackdrop = !!backdrop; - const r0 = hasBackdrop ? backdrop[0] : 0; - const g0 = hasBackdrop ? backdrop[1] : 0; - const b0 = hasBackdrop ? backdrop[2] : 0; - const composeFn = subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha; - const PIXELS_TO_PROCESS = 1048576; - const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width)); - for (let row = 0; row < height; row += chunkSize) { - const chunkHeight = Math.min(chunkSize, height - row); - const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight); - const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight); - if (hasBackdrop) { - composeSMaskBackdrop(maskData.data, r0, g0, b0); - } - composeFn(maskData.data, layerData.data, transferMap); - layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY); - } -} -function composeSMask(ctx, smask, layerCtx, layerBox) { - const layerOffsetX = layerBox[0]; - const layerOffsetY = layerBox[1]; - const layerWidth = layerBox[2] - layerOffsetX; - const layerHeight = layerBox[3] - layerOffsetY; - if (layerWidth === 0 || layerHeight === 0) { - return; - } - genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY); - ctx.save(); - ctx.globalAlpha = 1; - ctx.globalCompositeOperation = "source-over"; - ctx.setTransform(1, 0, 0, 1, 0, 0); - ctx.drawImage(layerCtx.canvas, 0, 0); - ctx.restore(); -} function getImageSmoothingEnabled(transform, interpolate) { + if (interpolate) { + return true; + } const scale = Util.singularValueDecompose2dScale(transform); scale[0] = Math.fround(scale[0]); scale[1] = Math.fround(scale[1]); const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS); - if (interpolate !== undefined) { - return interpolate; - } else if (scale[0] <= actualScale || scale[1] <= actualScale) { - return true; - } - return false; + return scale[0] <= actualScale && scale[1] <= actualScale; } const LINE_CAP_STYLES = ["butt", "round", "square"]; const LINE_JOIN_STYLES = ["miter", "round", "bevel"]; @@ -6616,12 +6667,73 @@ class CanvasGraphics { } const smask = this.current.activeSMask; const suspendedCtx = this.suspendedCtx; - composeSMask(suspendedCtx, smask, this.ctx, dirtyBox); + this.composeSMask(suspendedCtx, smask, this.ctx, dirtyBox); this.ctx.save(); this.ctx.setTransform(1, 0, 0, 1, 0, 0); this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height); this.ctx.restore(); } + composeSMask(ctx, smask, layerCtx, layerBox) { + const layerOffsetX = layerBox[0]; + const layerOffsetY = layerBox[1]; + const layerWidth = layerBox[2] - layerOffsetX; + const layerHeight = layerBox[3] - layerOffsetY; + if (layerWidth === 0 || layerHeight === 0) { + return; + } + this.genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY); + ctx.save(); + ctx.globalAlpha = 1; + ctx.globalCompositeOperation = "source-over"; + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.drawImage(layerCtx.canvas, 0, 0); + ctx.restore(); + } + genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) { + let maskCanvas = maskCtx.canvas; + let maskX = layerOffsetX - maskOffsetX; + let maskY = layerOffsetY - maskOffsetY; + if (backdrop) { + if (maskX < 0 || maskY < 0 || maskX + width > maskCanvas.width || maskY + height > maskCanvas.height) { + const canvas = this.cachedCanvases.getCanvas("maskExtension", width, height); + const ctx = canvas.context; + ctx.drawImage(maskCanvas, -maskX, -maskY); + if (backdrop.some(c => c !== 0)) { + ctx.globalCompositeOperation = "destination-atop"; + ctx.fillStyle = Util.makeHexColor(...backdrop); + ctx.fillRect(0, 0, width, height); + ctx.globalCompositeOperation = "source-over"; + } + maskCanvas = canvas.canvas; + maskX = maskY = 0; + } else if (backdrop.some(c => c !== 0)) { + maskCtx.save(); + maskCtx.globalAlpha = 1; + maskCtx.setTransform(1, 0, 0, 1, 0, 0); + const clip = new Path2D(); + clip.rect(maskX, maskY, width, height); + maskCtx.clip(clip); + maskCtx.globalCompositeOperation = "destination-atop"; + maskCtx.fillStyle = Util.makeHexColor(...backdrop); + maskCtx.fillRect(maskX, maskY, width, height); + maskCtx.restore(); + } + } + layerCtx.save(); + layerCtx.globalAlpha = 1; + layerCtx.setTransform(1, 0, 0, 1, 0, 0); + if (subtype === "Alpha" && transferMap) { + layerCtx.filter = this.filterFactory.addAlphaFilter(transferMap); + } else if (subtype === "Luminosity") { + layerCtx.filter = this.filterFactory.addLuminosityFilter(transferMap); + } + const clip = new Path2D(); + clip.rect(layerOffsetX, layerOffsetY, width, height); + layerCtx.clip(clip); + layerCtx.globalCompositeOperation = "destination-in"; + layerCtx.drawImage(maskCanvas, maskX, maskY, width, height, layerOffsetX, layerOffsetY, width, height); + layerCtx.restore(); + } save() { if (this.inSMaskMode) { copyCtxState(this.ctx, this.suspendedCtx); @@ -7304,18 +7416,8 @@ class CanvasGraphics { bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0]; const offsetX = Math.floor(bounds[0]); const offsetY = Math.floor(bounds[1]); - let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1); - let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1); - let scaleX = 1, - scaleY = 1; - if (drawnWidth > MAX_GROUP_SIZE) { - scaleX = drawnWidth / MAX_GROUP_SIZE; - drawnWidth = MAX_GROUP_SIZE; - } - if (drawnHeight > MAX_GROUP_SIZE) { - scaleY = drawnHeight / MAX_GROUP_SIZE; - drawnHeight = MAX_GROUP_SIZE; - } + const drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1); + const drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1); this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]); let cacheId = "groupAt" + this.groupLevel; if (group.smask) { @@ -7323,7 +7425,6 @@ class CanvasGraphics { } const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight); const groupCtx = scratchCanvas.context; - groupCtx.scale(1 / scaleX, 1 / scaleY); groupCtx.translate(-offsetX, -offsetY); groupCtx.transform(...currentTransform); if (group.smask) { @@ -7332,8 +7433,6 @@ class CanvasGraphics { context: groupCtx, offsetX, offsetY, - scaleX, - scaleY, subtype: group.smask.subtype, backdrop: group.smask.backdrop, transferMap: group.smask.transferMap || null, @@ -7342,7 +7441,6 @@ class CanvasGraphics { } else { currentCtx.setTransform(1, 0, 0, 1, 0, 0); currentCtx.translate(offsetX, offsetY); - currentCtx.scale(scaleX, scaleY); currentCtx.save(); } copyCtxState(currentCtx, groupCtx); @@ -9255,7 +9353,7 @@ function getDocument(src) { } const fetchDocParams = { docId, - apiVersion: "4.1.379", + apiVersion: "4.3.8", data, password, disableAutoFetch, @@ -9340,6 +9438,9 @@ function getDataProp(val) { } throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property."); } +function isRefProxy(ref) { + return typeof ref === "object" && Number.isInteger(ref?.num) && ref.num >= 0 && Number.isInteger(ref?.gen) && ref.gen >= 0; +} class PDFDocumentLoadingTask { static #docId = 0; constructor() { @@ -9523,6 +9624,9 @@ class PDFDocumentProxy { destroy() { return this.loadingTask.destroy(); } + cachedPageNumber(ref) { + return this._transport.cachedPageNumber(ref); + } get loadingParams() { return this._transport.loadingParams; } @@ -10140,6 +10244,7 @@ class WorkerTransport { #methodPromises = new Map(); #pageCache = new Map(); #pagePromises = new Map(); + #pageRefCache = new Map(); #passwordCapability = null; constructor(messageHandler, loadingTask, networkStream, params, factory) { this.messageHandler = messageHandler; @@ -10228,6 +10333,7 @@ class WorkerTransport { } this.#pageCache.clear(); this.#pagePromises.clear(); + this.#pageRefCache.clear(); if (this.hasOwnProperty("annotationStorage")) { this.annotationStorage.resetModified(); } @@ -10557,6 +10663,9 @@ class WorkerTransport { if (this.destroyed) { throw new Error("Transport destroyed"); } + if (pageInfo.refStr) { + this.#pageRefCache.set(pageInfo.refStr, pageNumber); + } const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug); this.#pageCache.set(pageIndex, page); return page; @@ -10565,7 +10674,7 @@ class WorkerTransport { return promise; } getPageIndex(ref) { - if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) { + if (!isRefProxy(ref)) { return Promise.reject(new Error("Invalid pageIndex request.")); } return this.messageHandler.sendWithPromise("GetPageIndex", { @@ -10676,6 +10785,13 @@ class WorkerTransport { this.filterFactory.destroy(true); cleanupTextLayer(); } + cachedPageNumber(ref) { + if (!isRefProxy(ref)) { + return null; + } + const refStr = ref.gen === 0 ? `${ref.num}R` : `${ref.num}R${ref.gen}`; + return this.#pageRefCache.get(refStr) ?? null; + } get loadingParams() { const { disableAutoFetch, @@ -10897,8 +11013,8 @@ class InternalRenderTask { } } } -const version = "4.1.379"; -const build = "017e49244"; +const version = "4.3.8"; +const build = "c419c8333"; ;// CONCATENATED MODULE: ./src/shared/scripting_utils.js function makeColorComp(n) { @@ -11247,6 +11363,7 @@ class AnnotationElementFactory { } } class AnnotationElement { + #updates = null; #hasBorder = false; constructor(parameters, { isRenderable = false, @@ -11283,6 +11400,61 @@ class AnnotationElement { get hasPopupData() { return AnnotationElement._hasPopupData(this.data); } + updateEdited(params) { + if (!this.container) { + return; + } + this.#updates ||= { + rect: this.data.rect.slice(0) + }; + const { + rect + } = params; + if (rect) { + this.#setRectEdited(rect); + } + } + resetEdited() { + if (!this.#updates) { + return; + } + this.#setRectEdited(this.#updates.rect); + this.#updates = null; + } + #setRectEdited(rect) { + const { + container: { + style + }, + data: { + rect: currentRect, + rotation + }, + parent: { + viewport: { + rawDims: { + pageWidth, + pageHeight, + pageX, + pageY + } + } + } + } = this; + currentRect?.splice(0, 4, ...rect); + const { + width, + height + } = getRectDims(rect); + style.left = `${100 * (rect[0] - pageX) / pageWidth}%`; + style.top = `${100 * (pageHeight - rect[3] + pageY) / pageHeight}%`; + if (rotation === 0) { + style.width = `${100 * width / pageWidth}%`; + style.height = `${100 * height / pageHeight}%`; + } else { + this.setRotation(rotation); + } + } _createContainer(ignoreBorder) { const { data, @@ -11296,7 +11468,10 @@ class AnnotationElement { if (!(this instanceof WidgetAnnotationElement)) { container.tabIndex = DEFAULT_TAB_INDEX; } - container.style.zIndex = this.parent.zIndex++; + const { + style + } = container; + style.zIndex = this.parent.zIndex++; if (data.popupRef) { container.setAttribute("aria-haspopup", "dialog"); } @@ -11306,12 +11481,6 @@ class AnnotationElement { if (data.noRotate) { container.classList.add("norotate"); } - const { - pageWidth, - pageHeight, - pageX, - pageY - } = viewport.rawDims; if (!data.rect || this instanceof PopupAnnotationElement) { const { rotation @@ -11325,24 +11494,23 @@ class AnnotationElement { width, height } = getRectDims(data.rect); - const rect = Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]); if (!ignoreBorder && data.borderStyle.width > 0) { - container.style.borderWidth = `${data.borderStyle.width}px`; + style.borderWidth = `${data.borderStyle.width}px`; const horizontalRadius = data.borderStyle.horizontalCornerRadius; const verticalRadius = data.borderStyle.verticalCornerRadius; if (horizontalRadius > 0 || verticalRadius > 0) { const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`; - container.style.borderRadius = radius; + style.borderRadius = radius; } else if (this instanceof RadioButtonWidgetAnnotationElement) { const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`; - container.style.borderRadius = radius; + style.borderRadius = radius; } switch (data.borderStyle.style) { case AnnotationBorderStyleType.SOLID: - container.style.borderStyle = "solid"; + style.borderStyle = "solid"; break; case AnnotationBorderStyleType.DASHED: - container.style.borderStyle = "dashed"; + style.borderStyle = "dashed"; break; case AnnotationBorderStyleType.BEVELED: warn("Unimplemented border style: beveled"); @@ -11351,7 +11519,7 @@ class AnnotationElement { warn("Unimplemented border style: inset"); break; case AnnotationBorderStyleType.UNDERLINE: - container.style.borderBottomStyle = "solid"; + style.borderBottomStyle = "solid"; break; default: break; @@ -11359,19 +11527,26 @@ class AnnotationElement { const borderColor = data.borderColor || null; if (borderColor) { this.#hasBorder = true; - container.style.borderColor = Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0); + style.borderColor = Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0); } else { - container.style.borderWidth = 0; + style.borderWidth = 0; } } - container.style.left = `${100 * (rect[0] - pageX) / pageWidth}%`; - container.style.top = `${100 * (rect[1] - pageY) / pageHeight}%`; + const rect = Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]); + const { + pageWidth, + pageHeight, + pageX, + pageY + } = viewport.rawDims; + style.left = `${100 * (rect[0] - pageX) / pageWidth}%`; + style.top = `${100 * (rect[1] - pageY) / pageHeight}%`; const { rotation } = data; if (data.hasOwnCanvas || rotation === 0) { - container.style.width = `${100 * width / pageWidth}%`; - container.style.height = `${100 * height / pageHeight}%`; + style.width = `${100 * width / pageWidth}%`; + style.height = `${100 * height / pageHeight}%`; } else { this.setRotation(rotation, container); } @@ -11786,6 +11961,9 @@ class LinkAnnotationElement extends AnnotationElement { } #bindAttachment(link, attachment, dest = null) { link.href = this.linkService.getAnchorUrl(""); + if (attachment.description) { + link.title = attachment.description; + } link.onclick = () => { this.downloadManager?.openOrDownloadData(attachment.content, attachment.filename, dest); return false; @@ -12746,6 +12924,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { }); selectElement.addEventListener("input", event => { const exportValue = getValue(true); + const change = getValue(false); storage.setValue(id, { value: exportValue }); @@ -12756,6 +12935,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { id, name: "Keystroke", value: selectedValues, + change, changeEx: exportValue, willCommit: false, commitKey: 1, @@ -13372,14 +13552,16 @@ class FileAttachmentAnnotationElement extends AnnotationElement { }); const { filename, - content + content, + description } = this.data.file; this.filename = getFilenameFromUrl(filename, true); this.content = content; this.linkService.eventBus?.dispatch("fileattachmentannotation", { source: this, filename, - content + content, + description }); } render() { @@ -13434,6 +13616,7 @@ class AnnotationLayer { div, accessibilityManager, annotationCanvasMap, + annotationEditorUIManager, page, viewport }) { @@ -13443,6 +13626,7 @@ class AnnotationLayer { this.page = page; this.viewport = viewport; this.zIndex = 0; + this._annotationEditorUIManager = annotationEditorUIManager; } #appendElement(element, id) { const contentElement = element.firstChild || element; @@ -13505,14 +13689,15 @@ class AnnotationLayer { elements.push(element); } } - if (element.annotationEditorType > 0) { - this.#editableAnnotations.set(element.data.id, element); - } const rendered = element.render(); if (data.hidden) { rendered.style.visibility = "hidden"; } this.#appendElement(rendered, data.id); + if (element.annotationEditorType > 0) { + this.#editableAnnotations.set(element.data.id, element); + this._annotationEditorUIManager?.renderAnnotationElement(element); + } } this.#setAnnotationCanvasMap(); } @@ -13537,6 +13722,7 @@ class AnnotationLayer { if (!element) { continue; } + canvas.className = "annotationContent"; const { firstChild } = element; @@ -13544,8 +13730,10 @@ class AnnotationLayer { element.append(canvas); } else if (firstChild.nodeName === "CANVAS") { firstChild.replaceWith(canvas); - } else { + } else if (!firstChild.classList.contains("annotationContent")) { firstChild.before(canvas); + } else { + firstChild.after(canvas); } } this.#annotationCanvasMap.clear(); @@ -13795,11 +13983,14 @@ class FreeTextEditor extends AnnotationEditor { div } = this; const savedDisplay = div.style.display; + const savedVisibility = div.classList.contains("hidden"); + div.classList.remove("hidden"); div.style.display = "hidden"; currentLayer.div.append(this.div); rect = div.getBoundingClientRect(); div.remove(); div.style.display = savedDisplay; + div.classList.toggle("hidden", savedVisibility); } if (this.rotation % 180 === this.parentRotation % 180) { this.width = rect.width / parentWidth; @@ -14080,7 +14271,7 @@ class FreeTextEditor extends AnnotationEditor { value: textContent.join("\n"), position: textPosition, pageIndex: pageNumber - 1, - rect, + rect: rect.slice(0), rotation, id, deleted: false @@ -14136,6 +14327,32 @@ class FreeTextEditor extends AnnotationEditor { } = this.#initialData; return this._hasBeenMoved || serialized.value !== value || serialized.fontSize !== fontSize || serialized.color.some((c, i) => c !== color[i]) || serialized.pageIndex !== pageIndex; } + renderAnnotationElement(annotation) { + const content = super.renderAnnotationElement(annotation); + if (this.deleted) { + return content; + } + const { + style + } = content; + style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`; + style.color = this.#color; + content.replaceChildren(); + for (const line of this.#content.split("\n")) { + const div = document.createElement("div"); + div.append(line ? document.createTextNode(line) : document.createElement("br")); + content.append(div); + } + const padding = FreeTextEditor._internalPadding * this.parentScale; + annotation.updateEdited({ + rect: this.getRect(padding, padding) + }); + return content; + } + resetAnnotationElement(annotation) { + super.resetAnnotationElement(annotation); + annotation.resetEdited(); + } } ;// CONCATENATED MODULE: ./src/display/editor/outliner.js @@ -16917,7 +17134,9 @@ class AnnotationEditorLayer { const annotationElementIds = new Set(); for (const editor of this.#editors.values()) { editor.enableEditing(); + editor.show(true); if (editor.annotationElementId) { + this.#uiManager.removeChangedExistingAnnotation(editor); annotationElementIds.add(editor.annotationElementId); } } @@ -16945,13 +17164,19 @@ class AnnotationEditorLayer { this.#isDisabling = true; this.div.tabIndex = -1; this.togglePointerEvents(false); - const hiddenAnnotationIds = new Set(); + const changedAnnotations = new Map(); + const resetAnnotations = new Map(); for (const editor of this.#editors.values()) { editor.disableEditing(); - if (!editor.annotationElementId || editor.serialize() !== null) { - hiddenAnnotationIds.add(editor.annotationElementId); + if (!editor.annotationElementId) { continue; } + if (editor.serialize() !== null) { + changedAnnotations.set(editor.annotationElementId, editor); + continue; + } else { + resetAnnotations.set(editor.annotationElementId, editor); + } this.getEditableAnnotation(editor.annotationElementId)?.show(); editor.remove(); } @@ -16961,9 +17186,22 @@ class AnnotationEditorLayer { const { id } = editable.data; - if (hiddenAnnotationIds.has(id) || this.#uiManager.isDeletedAnnotationElement(id)) { + if (this.#uiManager.isDeletedAnnotationElement(id)) { continue; } + let editor = resetAnnotations.get(id); + if (editor) { + editor.resetAnnotationElement(editable); + editor.show(false); + editable.show(); + continue; + } + editor = changedAnnotations.get(id); + if (editor) { + this.#uiManager.addChangedExistingAnnotation(editor); + editor.renderAnnotationElement(editable); + editor.show(false); + } editable.show(); } } @@ -17074,7 +17312,7 @@ class AnnotationEditorLayer { if (editor.parent === this) { return; } - if (editor.annotationElementId) { + if (editor.parent && editor.annotationElementId) { this.#uiManager.addDeletedAnnotationElement(editor.annotationElementId); AnnotationEditor.deleteAnnotationElement(editor); editor.annotationElementId = null; @@ -17566,8 +17804,8 @@ class DrawLayer { -const pdfjsVersion = "4.1.379"; -const pdfjsBuild = "017e49244"; +const pdfjsVersion = "4.3.8"; +const pdfjsBuild = "c419c8333"; var __webpack_exports__AbortException = __webpack_exports__.AbortException; var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer; diff --git a/toolkit/components/pdfjs/content/build/pdf.scripting.mjs b/toolkit/components/pdfjs/content/build/pdf.scripting.mjs index 8f4c2a7762..b2c74fc902 100644 --- a/toolkit/components/pdfjs/content/build/pdf.scripting.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.scripting.mjs @@ -1613,7 +1613,7 @@ class EventDispatcher { formatAll() { const event = globalThis.event = new Event({}); for (const source of Object.values(this._objects)) { - event.value = source.obj.value; + event.value = source.obj._getValue(); this.runActions(source, source, event, "Format"); } } @@ -1622,8 +1622,7 @@ class EventDispatcher { if (event.rc) { source.obj.value = event.value; this.runCalculate(source, event); - const savedValue = source.obj._getValue(); - event.value = source.obj.value; + const savedValue = event.value = source.obj._getValue(); let formattedValue = null; if (this.runActions(source, source, event, "Format")) { formattedValue = event.value?.toString?.(); @@ -3957,8 +3956,8 @@ function initSandbox(params) { ;// CONCATENATED MODULE: ./src/pdf.scripting.js -const pdfjsVersion = "4.1.379"; -const pdfjsBuild = "017e49244"; +const pdfjsVersion = "4.3.8"; +const pdfjsBuild = "c419c8333"; globalThis.pdfjsScripting = { initSandbox: initSandbox }; diff --git a/toolkit/components/pdfjs/content/build/pdf.worker.mjs b/toolkit/components/pdfjs/content/build/pdf.worker.mjs index 76770f6556..ba1bddd48f 100644 --- a/toolkit/components/pdfjs/content/build/pdf.worker.mjs +++ b/toolkit/components/pdfjs/content/build/pdf.worker.mjs @@ -1010,6 +1010,11 @@ class RefSetCache { clear() { this._map.clear(); } + *items() { + for (const [ref, value] of this._map) { + yield [Ref.fromString(ref), value]; + } + } } function isName(v, name) { return v instanceof Name && (name === undefined || v.name === name); @@ -1216,6 +1221,9 @@ function readUint32(data, offset) { function isWhiteSpace(ch) { return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a; } +function isNumberArray(arr, len) { + return Array.isArray(arr) && (len === null || arr.length === len) && arr.every(x => typeof x === "number"); +} function parseXFAPath(path) { const positionPattern = /(.+)\[(\d+)\]$/; return path.split(".").map(component => { @@ -3119,14 +3127,14 @@ class DecodeStream extends BaseStream { } return this.buffer[this.pos++]; } - getBytes(length) { + getBytes(length, ignoreColorSpace = false) { const pos = this.pos; let end; if (length) { this.ensureBuffer(pos + length); end = pos + length; while (!this.eof && this.bufferLength < end) { - this.readBlock(); + this.readBlock(ignoreColorSpace); } const bufEnd = this.bufferLength; if (end > bufEnd) { @@ -3134,7 +3142,7 @@ class DecodeStream extends BaseStream { } } else { while (!this.eof) { - this.readBlock(); + this.readBlock(ignoreColorSpace); } end = this.bufferLength; } @@ -4453,7 +4461,7 @@ class ArithmeticDecoder { class Jbig2Error extends BaseException { constructor(msg) { - super(`JBIG2 error: ${msg}`, "Jbig2Error"); + super(msg, "Jbig2Error"); } } class ContextCache { @@ -6361,7 +6369,7 @@ function grayToRGBA(src, dest) { class JpegError extends BaseException { constructor(msg) { - super(`JPEG error: ${msg}`, "JpegError"); + super(msg, "JpegError"); } } class DNLMarkerError extends BaseException { @@ -7498,1914 +7506,506 @@ class JpegStream extends DecodeStream { } } -;// CONCATENATED MODULE: ./src/core/jpx.js - - - -class JpxError extends BaseException { - constructor(msg) { - super(`JPX error: ${msg}`, "JpxError"); - } -} -const SubbandsGainLog2 = { - LL: 0, - LH: 1, - HL: 1, - HH: 2 -}; -class JpxImage { - constructor() { - this.failOnCorruptedImage = false; - } - parse(data) { - const head = readUint16(data, 0); - if (head === 0xff4f) { - this.parseCodestream(data, 0, data.length); - return; - } - const length = data.length; - let position = 0; - while (position < length) { - let headerSize = 8; - let lbox = readUint32(data, position); - const tbox = readUint32(data, position + 4); - position += headerSize; - if (lbox === 1) { - lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4); - position += 8; - headerSize += 8; - } - if (lbox === 0) { - lbox = length - position + headerSize; - } - if (lbox < headerSize) { - throw new JpxError("Invalid box field size"); - } - const dataLength = lbox - headerSize; - let jumpDataLength = true; - switch (tbox) { - case 0x6a703268: - jumpDataLength = false; - break; - case 0x636f6c72: - const method = data[position]; - if (method === 1) { - const colorspace = readUint32(data, position + 3); - switch (colorspace) { - case 16: - case 17: - case 18: - break; - default: - warn("Unknown colorspace " + colorspace); - break; - } - } else if (method === 2) { - info("ICC profile not supported"); - } - break; - case 0x6a703263: - this.parseCodestream(data, position, position + dataLength); - break; - case 0x6a502020: - if (readUint32(data, position) !== 0x0d0a870a) { - warn("Invalid JP2 signature"); - } - break; - case 0x6a501a1a: - case 0x66747970: - case 0x72726571: - case 0x72657320: - case 0x69686472: - break; - default: - const headerType = String.fromCharCode(tbox >> 24 & 0xff, tbox >> 16 & 0xff, tbox >> 8 & 0xff, tbox & 0xff); - warn(`Unsupported header type ${tbox} (${headerType}).`); - break; - } - if (jumpDataLength) { - position += dataLength; - } - } - } - parseImageProperties(stream) { - let newByte = stream.getByte(); - while (newByte >= 0) { - const oldByte = newByte; - newByte = stream.getByte(); - const code = oldByte << 8 | newByte; - if (code === 0xff51) { - stream.skip(4); - const Xsiz = stream.getInt32() >>> 0; - const Ysiz = stream.getInt32() >>> 0; - const XOsiz = stream.getInt32() >>> 0; - const YOsiz = stream.getInt32() >>> 0; - stream.skip(16); - const Csiz = stream.getUint16(); - this.width = Xsiz - XOsiz; - this.height = Ysiz - YOsiz; - this.componentsCount = Csiz; - this.bitsPerComponent = 8; - return; - } - } - throw new JpxError("No size marker found in JPX stream"); - } - parseCodestream(data, start, end) { - const context = {}; - let doNotRecover = false; - try { - let position = start; - while (position + 1 < end) { - const code = readUint16(data, position); - position += 2; - let length = 0, - j, - sqcd, - spqcds, - spqcdSize, - scalarExpounded, - tile; - switch (code) { - case 0xff4f: - context.mainHeader = true; - break; - case 0xffd9: - break; - case 0xff51: - length = readUint16(data, position); - const siz = {}; - siz.Xsiz = readUint32(data, position + 4); - siz.Ysiz = readUint32(data, position + 8); - siz.XOsiz = readUint32(data, position + 12); - siz.YOsiz = readUint32(data, position + 16); - siz.XTsiz = readUint32(data, position + 20); - siz.YTsiz = readUint32(data, position + 24); - siz.XTOsiz = readUint32(data, position + 28); - siz.YTOsiz = readUint32(data, position + 32); - const componentsCount = readUint16(data, position + 36); - siz.Csiz = componentsCount; - const components = []; - j = position + 38; - for (let i = 0; i < componentsCount; i++) { - const component = { - precision: (data[j] & 0x7f) + 1, - isSigned: !!(data[j] & 0x80), - XRsiz: data[j + 1], - YRsiz: data[j + 2] - }; - j += 3; - calculateComponentDimensions(component, siz); - components.push(component); - } - context.SIZ = siz; - context.components = components; - calculateTileGrids(context, components); - context.QCC = []; - context.COC = []; - break; - case 0xff5c: - length = readUint16(data, position); - const qcd = {}; - j = position + 2; - sqcd = data[j++]; - switch (sqcd & 0x1f) { - case 0: - spqcdSize = 8; - scalarExpounded = true; - break; - case 1: - spqcdSize = 16; - scalarExpounded = false; - break; - case 2: - spqcdSize = 16; - scalarExpounded = true; - break; - default: - throw new Error("Invalid SQcd value " + sqcd); - } - qcd.noQuantization = spqcdSize === 8; - qcd.scalarExpounded = scalarExpounded; - qcd.guardBits = sqcd >> 5; - spqcds = []; - while (j < length + position) { - const spqcd = {}; - if (spqcdSize === 8) { - spqcd.epsilon = data[j++] >> 3; - spqcd.mu = 0; - } else { - spqcd.epsilon = data[j] >> 3; - spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1]; - j += 2; - } - spqcds.push(spqcd); - } - qcd.SPqcds = spqcds; - if (context.mainHeader) { - context.QCD = qcd; - } else { - context.currentTile.QCD = qcd; - context.currentTile.QCC = []; - } - break; - case 0xff5d: - length = readUint16(data, position); - const qcc = {}; - j = position + 2; - let cqcc; - if (context.SIZ.Csiz < 257) { - cqcc = data[j++]; - } else { - cqcc = readUint16(data, j); - j += 2; - } - sqcd = data[j++]; - switch (sqcd & 0x1f) { - case 0: - spqcdSize = 8; - scalarExpounded = true; - break; - case 1: - spqcdSize = 16; - scalarExpounded = false; - break; - case 2: - spqcdSize = 16; - scalarExpounded = true; - break; - default: - throw new Error("Invalid SQcd value " + sqcd); - } - qcc.noQuantization = spqcdSize === 8; - qcc.scalarExpounded = scalarExpounded; - qcc.guardBits = sqcd >> 5; - spqcds = []; - while (j < length + position) { - const spqcd = {}; - if (spqcdSize === 8) { - spqcd.epsilon = data[j++] >> 3; - spqcd.mu = 0; - } else { - spqcd.epsilon = data[j] >> 3; - spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1]; - j += 2; - } - spqcds.push(spqcd); - } - qcc.SPqcds = spqcds; - if (context.mainHeader) { - context.QCC[cqcc] = qcc; - } else { - context.currentTile.QCC[cqcc] = qcc; - } - break; - case 0xff52: - length = readUint16(data, position); - const cod = {}; - j = position + 2; - const scod = data[j++]; - cod.entropyCoderWithCustomPrecincts = !!(scod & 1); - cod.sopMarkerUsed = !!(scod & 2); - cod.ephMarkerUsed = !!(scod & 4); - cod.progressionOrder = data[j++]; - cod.layersCount = readUint16(data, j); - j += 2; - cod.multipleComponentTransform = data[j++]; - cod.decompositionLevelsCount = data[j++]; - cod.xcb = (data[j++] & 0xf) + 2; - cod.ycb = (data[j++] & 0xf) + 2; - const blockStyle = data[j++]; - cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1); - cod.resetContextProbabilities = !!(blockStyle & 2); - cod.terminationOnEachCodingPass = !!(blockStyle & 4); - cod.verticallyStripe = !!(blockStyle & 8); - cod.predictableTermination = !!(blockStyle & 16); - cod.segmentationSymbolUsed = !!(blockStyle & 32); - cod.reversibleTransformation = data[j++]; - if (cod.entropyCoderWithCustomPrecincts) { - const precinctsSizes = []; - while (j < length + position) { - const precinctsSize = data[j++]; - precinctsSizes.push({ - PPx: precinctsSize & 0xf, - PPy: precinctsSize >> 4 - }); - } - cod.precinctsSizes = precinctsSizes; - } - const unsupported = []; - if (cod.selectiveArithmeticCodingBypass) { - unsupported.push("selectiveArithmeticCodingBypass"); - } - if (cod.terminationOnEachCodingPass) { - unsupported.push("terminationOnEachCodingPass"); - } - if (cod.verticallyStripe) { - unsupported.push("verticallyStripe"); - } - if (cod.predictableTermination) { - unsupported.push("predictableTermination"); - } - if (unsupported.length > 0) { - doNotRecover = true; - warn(`JPX: Unsupported COD options (${unsupported.join(", ")}).`); - } - if (context.mainHeader) { - context.COD = cod; - } else { - context.currentTile.COD = cod; - context.currentTile.COC = []; - } - break; - case 0xff90: - length = readUint16(data, position); - tile = {}; - tile.index = readUint16(data, position + 2); - tile.length = readUint32(data, position + 4); - tile.dataEnd = tile.length + position - 2; - tile.partIndex = data[position + 8]; - tile.partsCount = data[position + 9]; - context.mainHeader = false; - if (tile.partIndex === 0) { - tile.COD = context.COD; - tile.COC = context.COC.slice(0); - tile.QCD = context.QCD; - tile.QCC = context.QCC.slice(0); - } - context.currentTile = tile; - break; - case 0xff93: - tile = context.currentTile; - if (tile.partIndex === 0) { - initializeTile(context, tile.index); - buildPackets(context); - } - length = tile.dataEnd - position; - parseTilePackets(context, data, position, length); - break; - case 0xff53: - warn("JPX: Codestream code 0xFF53 (COC) is not implemented."); - case 0xff55: - case 0xff57: - case 0xff58: - case 0xff64: - length = readUint16(data, position); - break; - default: - throw new Error("Unknown codestream code: " + code.toString(16)); +;// CONCATENATED MODULE: ./external/openjpeg/openjpeg.js +var OpenJPEG = (() => { + var _scriptDir = "file:///home/calixte/dev/mozilla/pdf.js.release/external/openjpeg/openjpeg.js"; + return function (moduleArg = {}) { + var Module = moduleArg; + var readyPromiseResolve, readyPromiseReject; + var readyPromise = new Promise((resolve, reject) => { + readyPromiseResolve = resolve; + readyPromiseReject = reject; + }); + "use strict"; + Module.decode = function (bytes, ignoreColorSpace) { + const size = bytes.length; + const ptr = Module._malloc(size); + Module.HEAPU8.set(bytes, ptr); + const ret = Module._jp2_decode(ptr, size, ignoreColorSpace ? 1 : 0); + Module._free(ptr); + if (ret) { + const { + errorMessages: errorMessages + } = Module; + if (errorMessages) { + delete Module.errorMessages; + return errorMessages; } - position += length; + return "Unknown error"; } - } catch (e) { - if (doNotRecover || this.failOnCorruptedImage) { - throw new JpxError(e.message); + const { + imageData: imageData + } = Module; + Module.imageData = null; + return imageData; + }; + var moduleOverrides = Object.assign({}, Module); + var arguments_ = []; + var thisProgram = "./this.program"; + var quit_ = (status, toThrow) => { + throw toThrow; + }; + var ENVIRONMENT_IS_WEB = true; + var ENVIRONMENT_IS_WORKER = false; + var scriptDirectory = ""; + var read_, readAsync, readBinary; + if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = self.location.href; + } else if (typeof document != "undefined" && document.currentScript) { + scriptDirectory = document.currentScript.src; + } + if (_scriptDir) { + scriptDirectory = _scriptDir; + } + if (scriptDirectory.startsWith("blob:")) { + scriptDirectory = ""; } else { - warn(`JPX: Trying to recover from: "${e.message}".`); - } - } - this.tiles = transformComponents(context); - this.width = context.SIZ.Xsiz - context.SIZ.XOsiz; - this.height = context.SIZ.Ysiz - context.SIZ.YOsiz; - this.componentsCount = context.SIZ.Csiz; - } -} -function calculateComponentDimensions(component, siz) { - component.x0 = Math.ceil(siz.XOsiz / component.XRsiz); - component.x1 = Math.ceil(siz.Xsiz / component.XRsiz); - component.y0 = Math.ceil(siz.YOsiz / component.YRsiz); - component.y1 = Math.ceil(siz.Ysiz / component.YRsiz); - component.width = component.x1 - component.x0; - component.height = component.y1 - component.y0; -} -function calculateTileGrids(context, components) { - const siz = context.SIZ; - const tiles = []; - let tile; - const numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); - const numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); - for (let q = 0; q < numYtiles; q++) { - for (let p = 0; p < numXtiles; p++) { - tile = {}; - tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); - tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); - tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz); - tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz); - tile.width = tile.tx1 - tile.tx0; - tile.height = tile.ty1 - tile.ty0; - tile.components = []; - tiles.push(tile); - } - } - context.tiles = tiles; - const componentsCount = siz.Csiz; - for (let i = 0, ii = componentsCount; i < ii; i++) { - const component = components[i]; - for (let j = 0, jj = tiles.length; j < jj; j++) { - const tileComponent = {}; - tile = tiles[j]; - tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz); - tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); - tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz); - tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz); - tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0; - tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0; - tile.components[i] = tileComponent; - } - } -} -function getBlocksDimensions(context, component, r) { - const codOrCoc = component.codingStyleParameters; - const result = {}; - if (!codOrCoc.entropyCoderWithCustomPrecincts) { - result.PPx = 15; - result.PPy = 15; - } else { - result.PPx = codOrCoc.precinctsSizes[r].PPx; - result.PPy = codOrCoc.precinctsSizes[r].PPy; - } - result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx); - result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy); - return result; -} -function buildPrecincts(context, resolution, dimensions) { - const precinctWidth = 1 << dimensions.PPx; - const precinctHeight = 1 << dimensions.PPy; - const isZeroRes = resolution.resLevel === 0; - const precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1); - const precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1); - const numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0; - const numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0; - const numprecincts = numprecinctswide * numprecinctshigh; - resolution.precinctParameters = { - precinctWidth, - precinctHeight, - numprecinctswide, - numprecinctshigh, - numprecincts, - precinctWidthInSubband, - precinctHeightInSubband - }; -} -function buildCodeblocks(context, subband, dimensions) { - const xcb_ = dimensions.xcb_; - const ycb_ = dimensions.ycb_; - const codeblockWidth = 1 << xcb_; - const codeblockHeight = 1 << ycb_; - const cbx0 = subband.tbx0 >> xcb_; - const cby0 = subband.tby0 >> ycb_; - const cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_; - const cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_; - const precinctParameters = subband.resolution.precinctParameters; - const codeblocks = []; - const precincts = []; - let i, j, codeblock, precinctNumber; - for (j = cby0; j < cby1; j++) { - for (i = cbx0; i < cbx1; i++) { - codeblock = { - cbx: i, - cby: j, - tbx0: codeblockWidth * i, - tby0: codeblockHeight * j, - tbx1: codeblockWidth * (i + 1), - tby1: codeblockHeight * (j + 1) - }; - codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0); - codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0); - codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1); - codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1); - const pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband); - const pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband); - precinctNumber = pi + pj * precinctParameters.numprecinctswide; - codeblock.precinctNumber = precinctNumber; - codeblock.subbandType = subband.type; - codeblock.Lblock = 3; - if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) { - continue; + scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); } - codeblocks.push(codeblock); - let precinct = precincts[precinctNumber]; - if (precinct !== undefined) { - if (i < precinct.cbxMin) { - precinct.cbxMin = i; - } else if (i > precinct.cbxMax) { - precinct.cbxMax = i; - } - if (j < precinct.cbyMin) { - precinct.cbxMin = j; - } else if (j > precinct.cbyMax) { - precinct.cbyMax = j; - } - } else { - precincts[precinctNumber] = precinct = { - cbxMin: i, - cbyMin: j, - cbxMax: i, - cbyMax: j + read_ = url => { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.send(null); + return xhr.responseText; + }; + if (ENVIRONMENT_IS_WORKER) { + readBinary = url => { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.responseType = "arraybuffer"; + xhr.send(null); + return new Uint8Array(xhr.response); }; } - codeblock.precinct = precinct; - } - } - subband.codeblockParameters = { - codeblockWidth: xcb_, - codeblockHeight: ycb_, - numcodeblockwide: cbx1 - cbx0 + 1, - numcodeblockhigh: cby1 - cby0 + 1 - }; - subband.codeblocks = codeblocks; - subband.precincts = precincts; -} -function createPacket(resolution, precinctNumber, layerNumber) { - const precinctCodeblocks = []; - const subbands = resolution.subbands; - for (let i = 0, ii = subbands.length; i < ii; i++) { - const subband = subbands[i]; - const codeblocks = subband.codeblocks; - for (let j = 0, jj = codeblocks.length; j < jj; j++) { - const codeblock = codeblocks[j]; - if (codeblock.precinctNumber !== precinctNumber) { - continue; - } - precinctCodeblocks.push(codeblock); - } - } - return { - layerNumber, - codeblocks: precinctCodeblocks - }; -} -function LayerResolutionComponentPositionIterator(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const layersCount = tile.codingStyleDefaultParameters.layersCount; - const componentsCount = siz.Csiz; - let maxDecompositionLevelsCount = 0; - for (let q = 0; q < componentsCount; q++) { - maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); - } - let l = 0, - r = 0, - i = 0, - k = 0; - this.nextPacket = function JpxImage_nextPacket() { - for (; l < layersCount; l++) { - for (; r <= maxDecompositionLevelsCount; r++) { - for (; i < componentsCount; i++) { - const component = tile.components[i]; - if (r > component.codingStyleParameters.decompositionLevelsCount) { - continue; - } - const resolution = component.resolutions[r]; - const numprecincts = resolution.precinctParameters.numprecincts; - for (; k < numprecincts;) { - const packet = createPacket(resolution, k, l); - k++; - return packet; - } - k = 0; - } - i = 0; - } - r = 0; - } - throw new JpxError("Out of packets"); - }; -} -function ResolutionLayerComponentPositionIterator(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const layersCount = tile.codingStyleDefaultParameters.layersCount; - const componentsCount = siz.Csiz; - let maxDecompositionLevelsCount = 0; - for (let q = 0; q < componentsCount; q++) { - maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); - } - let r = 0, - l = 0, - i = 0, - k = 0; - this.nextPacket = function JpxImage_nextPacket() { - for (; r <= maxDecompositionLevelsCount; r++) { - for (; l < layersCount; l++) { - for (; i < componentsCount; i++) { - const component = tile.components[i]; - if (r > component.codingStyleParameters.decompositionLevelsCount) { - continue; - } - const resolution = component.resolutions[r]; - const numprecincts = resolution.precinctParameters.numprecincts; - for (; k < numprecincts;) { - const packet = createPacket(resolution, k, l); - k++; - return packet; + readAsync = (url, onload, onerror) => { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + xhr.responseType = "arraybuffer"; + xhr.onload = () => { + if (xhr.status == 200 || xhr.status == 0 && xhr.response) { + onload(xhr.response); + return; } - k = 0; - } - i = 0; + onerror(); + }; + xhr.onerror = onerror; + xhr.send(null); + }; + } else {} + var out = Module["print"] || console.log.bind(console); + var err = Module["printErr"] || console.error.bind(console); + Object.assign(Module, moduleOverrides); + moduleOverrides = null; + if (Module["arguments"]) arguments_ = Module["arguments"]; + if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; + if (Module["quit"]) quit_ = Module["quit"]; + var wasmBinary; + if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"]; + function intArrayFromBase64(s) { + var decoded = atob(s); + var bytes = new Uint8Array(decoded.length); + for (var i = 0; i < decoded.length; ++i) { + bytes[i] = decoded.charCodeAt(i); } - l = 0; + return bytes; } - throw new JpxError("Out of packets"); - }; -} -function ResolutionPositionComponentLayerIterator(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const layersCount = tile.codingStyleDefaultParameters.layersCount; - const componentsCount = siz.Csiz; - let l, r, c, p; - let maxDecompositionLevelsCount = 0; - for (c = 0; c < componentsCount; c++) { - const component = tile.components[c]; - maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount); - } - const maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1); - for (r = 0; r <= maxDecompositionLevelsCount; ++r) { - let maxNumPrecincts = 0; - for (c = 0; c < componentsCount; ++c) { - const resolutions = tile.components[c].resolutions; - if (r < resolutions.length) { - maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts); - } - } - maxNumPrecinctsInLevel[r] = maxNumPrecincts; - } - l = 0; - r = 0; - c = 0; - p = 0; - this.nextPacket = function JpxImage_nextPacket() { - for (; r <= maxDecompositionLevelsCount; r++) { - for (; p < maxNumPrecinctsInLevel[r]; p++) { - for (; c < componentsCount; c++) { - const component = tile.components[c]; - if (r > component.codingStyleParameters.decompositionLevelsCount) { - continue; - } - const resolution = component.resolutions[r]; - const numprecincts = resolution.precinctParameters.numprecincts; - if (p >= numprecincts) { - continue; - } - for (; l < layersCount;) { - const packet = createPacket(resolution, p, l); - l++; - return packet; - } - l = 0; - } - c = 0; + function tryParseAsDataURI(filename) { + if (!isDataURI(filename)) { + return; } - p = 0; - } - throw new JpxError("Out of packets"); - }; -} -function PositionComponentResolutionLayerIterator(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const layersCount = tile.codingStyleDefaultParameters.layersCount; - const componentsCount = siz.Csiz; - const precinctsSizes = getPrecinctSizesInImageScale(tile); - const precinctsIterationSizes = precinctsSizes; - let l = 0, - r = 0, - c = 0, - px = 0, - py = 0; - this.nextPacket = function JpxImage_nextPacket() { - for (; py < precinctsIterationSizes.maxNumHigh; py++) { - for (; px < precinctsIterationSizes.maxNumWide; px++) { - for (; c < componentsCount; c++) { - const component = tile.components[c]; - const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; - for (; r <= decompositionLevelsCount; r++) { - const resolution = component.resolutions[r]; - const sizeInImageScale = precinctsSizes.components[c].resolutions[r]; - const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); - if (k === null) { - continue; - } - for (; l < layersCount;) { - const packet = createPacket(resolution, k, l); - l++; - return packet; - } - l = 0; - } - r = 0; + return intArrayFromBase64(filename.slice(dataURIPrefix.length)); + } + var wasmMemory; + var ABORT = false; + var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; + function updateMemoryViews() { + var b = wasmMemory.buffer; + Module["HEAP8"] = HEAP8 = new Int8Array(b); + Module["HEAP16"] = HEAP16 = new Int16Array(b); + Module["HEAPU8"] = HEAPU8 = new Uint8Array(b); + Module["HEAPU16"] = HEAPU16 = new Uint16Array(b); + Module["HEAP32"] = HEAP32 = new Int32Array(b); + Module["HEAPU32"] = HEAPU32 = new Uint32Array(b); + Module["HEAPF32"] = HEAPF32 = new Float32Array(b); + Module["HEAPF64"] = HEAPF64 = new Float64Array(b); + } + var __ATPRERUN__ = []; + var __ATINIT__ = []; + var __ATPOSTRUN__ = []; + var runtimeInitialized = false; + function preRun() { + if (Module["preRun"]) { + if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]]; + while (Module["preRun"].length) { + addOnPreRun(Module["preRun"].shift()); + } + } + callRuntimeCallbacks(__ATPRERUN__); + } + function initRuntime() { + runtimeInitialized = true; + callRuntimeCallbacks(__ATINIT__); + } + function postRun() { + if (Module["postRun"]) { + if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]]; + while (Module["postRun"].length) { + addOnPostRun(Module["postRun"].shift()); + } + } + callRuntimeCallbacks(__ATPOSTRUN__); + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb); + } + function addOnInit(cb) { + __ATINIT__.unshift(cb); + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb); + } + var runDependencies = 0; + var runDependencyWatcher = null; + var dependenciesFulfilled = null; + function addRunDependency(id) { + runDependencies++; + Module["monitorRunDependencies"]?.(runDependencies); + } + function removeRunDependency(id) { + runDependencies--; + Module["monitorRunDependencies"]?.(runDependencies); + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher); + runDependencyWatcher = null; + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled; + dependenciesFulfilled = null; + callback(); + } + } + } + var dataURIPrefix = "data:application/octet-stream;base64,"; + var isDataURI = filename => filename.startsWith(dataURIPrefix); + var wasmBinaryFile; + wasmBinaryFile = "data:application/octet-stream;base64,AGFzbQEAAAABzgEaYAN/f38Bf2AEf39/fwF/YAF/AGACf38AYAF/AX9gA39/fwBgAn9/AX9gBH9/f38AYAN/fn8BfmACfn8Bf2AFf39/f38Bf2ACfn8BfmADf35/AX9gAAF/YAd/f39/f39/AX9gBX9/f39/AGAJf39/f39/f39/AX9gC39/f39/f39/f39/AX9gBn9/f39/fwF/YAZ/fH9/f38Bf2AIf39/f39/f38AYAh/f39/f39/fwF/YAAAYAZ/f39/f38AYAd/f39/f39/AGACfH8BfAIxCAFhAWEAAgFhAWIABAFhAWMABgFhAWQABgFhAWUAAQFhAWYABQFhAWcAAgFhAWgAAwO+AbwBBwIFAAYEAAUGBQE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CCAKIAasIgt8IAt/xHwgB4enIA7EIA98QgF9IAeHp2siAkEASARAIAMgAjYCFCADIAQ2AhAgAUEBQajlACADQRBqEAhBACECDAMLIAAgAjYCDCAAQTRqIQBBASECIARBAWoiBCAFRw0ACwwBCyABQQFBpzNBABAICyADQSBqJAAgAgvXBgEGfyAABEACQCAAKAIABEAgACgCDCIBBEAgARApIAAoAgwQCSAAQQA2AgwLIAAoAhAiAQRAIAEQCSAAQgA3AxALIAAoAkAQCSAAQgA3AjwMAQsgACgCLCIBBEAgARAJIABBADYCLAsgACgCICIBBEAgARAJIABCADcDIAsgACgCNCIBRQ0AIAEQCSAAQgA3AjQLIAAoAtABEE4gACgCnAEiAQRAIAAoAmggACgCbGwiAwR/A0AgARApIAFBjCxqIQEgAkEBaiICIANHDQALIAAoApwBBSABCxAJIABBADYCnAELIAAoAnQiAQRAIAAoAnAiAgRAQQAhAQNAIAAoAnQgAUEDdGooAgAiAwRAIAMQCSAAKAJwIQILIAFBAWoiASACSQ0ACyAAKAJ0IQELIABBADYCcCABEAkgAEEANgJ0CyAAKAKIARAJIABBADYCeCAAQQA2AogBIAAoAmQQCSAAQQA2AmQgAC0AvAFBAnFFBEAgACgCqAEQCQsgAEHQAGpBAEHwABAOGiAAKALAARAtIABBADYCwAEgACgCxAEQLSAAQQA2AsABIAAoAsgBIgEEQCABKAIcIgIEQCACEAkgAUEANgIcCyABKAIoIgIEQCABKAIkBEADQCACIAVBKGwiA2ooAiQiBARAIAQQCSABKAIoIgIgA2pBADYCJAsgAiADaigCECIEBEAgBBAJIAEoAigiAiADakEANgIQCyACIANqKAIYIgQEQCAEEAkgASgCKCICIANqQQA2AhgLIAVBAWoiBSABKAIkSQ0ACwsgAhAJIAFBADYCKAsgARAJCyAAQQA2AsgBIAAoAkgQGCAAQQA2AkggACgCTBAYIABBADYCTCAAKALUASIDBEACQCADKAIIRQ0AIAMoAgwEQCADQQA2AigDQCADKAIYQQBKDQALCyADQQE2AhAgAygCABAJIAMoAhwi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AJKAIARwR/IAkoAgwgCSgCBEYFQQELDQAgAygCJCIBIAkoAhhBKG5PBEAgCEEBQYIVQQAQCAwECyAJKAIUIAFBKGxqIgEoAiAQWyABKAIkEFsgASgCFCABKAIQbCINRQ0AIAEoAhghASANQQhPBEAgDUF4cSELQQAhCgNAIAFCADcC6AMgAUIANwKoAyABQgA3AugCIAFCADcCqAIgAUIANwLoASABQgA3AqgBIAFCADcCaCABQgA3AiggAUGABGohASAKQQhqIgogC0cNAAsLQQAhCiANQQdxIg1FDQADQCABQgA3AiggAUFAayEBIApBAWoiCiANRw0ACwsgCUEkaiEJIAxBAWoiDCARKAIYSQ0ACwsgBSENAkAgAi0AAEECcUUNACAHQQVNBEAgCEECQbEfQQAQCAwBCwJAIAUtAABB/wFGBEAgBS0AAUGRAUYNAQsgCEECQdsfQQAQCAwBCyAPIAVBBmoiDTYCGAtBFBANIgtFDQACfyAALQBsQQFxBEAgAEEoaiEHIAAoAighDSAAQSxqDAELIAItAIgsQQJxBEAgAkGwKGohByACKAKwKCENIAJBvChqDAELIA8gBSAHaiANazYCHCAPQRhqIQcgD0EcagsiEigCACEAIAtCADcCDCALIA02AgggCyANNgIAIAsgACANajYCBCALQQEQGUUEQCALEF0aIAsoAgggCygCAGshGiALECUgGiANaiEBAkAgAi0AAEEEcUUNACAHKAIAIBIoAgAgAWtqQQFNBEAgCEECQZghQQAQCAwBCwJAIAEtAABB/wFGBEAgAS0AAUGSAUYNAQsgCEECQcIhQQAQCAwBCyABQQJqIQELIBIgEigCACAHKAIAIAFrajYCACAHIAE2AgAgBEEANgIAIAYgDygCGCAFazYCAEEBIRcMAQsgESgCGARAIBFBHGohEANAIAMoAiQhACAQKAIUIQECQCAQKAIIIBAoAgBHBH8gECgCDCAQKAIERgVBAQsNACABIABBKGxqIhQoAhQgFCgCEGwiGEUNACAUKAIYIQlBACEVA0ACQAJ/IAkoAihFBEAgCyAUKAIgIBUgAygCKEEBahBZDAELIAtBARAZC0UEQCAJQQA2AiQMAQ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A0EBQeknIARBEGoQCCAAQQE2AjhBACEFDAULIAUgATYC2CsLIAEgBCgCZEEBakcNACAAIAAtAERBAXI6AEQLIAQoAmwhASAAQRA2AgggAEEAIAFBDGsgACgCOBs2AhgCQCAAKAIsIgFBf0YEQEEEIQUgAiAHIAhsayIBIAAoAhxJDQEgASAAKAIkTw0BIAcgACgCIEkNASAHIAAoAihPQQJ0IQUMAQsgACgCzAEgAUdBAnQhBQsgACAALQBEQfsBcSAFcjoAREEBIQUgACgCyAEiAUUNAiABKAIoIgYgACgCzAEiAkEobGoiByACNgIAIAcgBCgCZCIINgIMIAQoAmgiAQRAIAcgATYCBCAHIAQoAmgiATYCCCAHKAIQIgJFBEAgAUEYEAwhASAAKALIASgCKCAAKALMAUEobGogATYCECABDQRBACEFIANBAUHJNEEAEAgMBAsgAiABQRhsEBAhASAAKALIASgCKCAAKALMAUEobGohAiABRQRAIAIoAhAQCUEAIQUgACgCyAEoAiggACgCzAFBKGxqQQA2AhAgA0EBQck0QQAQCAwECyACIAE2AhAMAwsgBygCECIBRQRAIAdBCjYCCEEKQRgQDCEBIAAoAsgBKAIoIgYgACgCzAEiAkEobGoiByABNgIQIAFFDQIgBCgCZCEICyAIIAYgAkEobGoiAigCCEkNAiACIAhBAWoiAjYCCCABIAJBGGwQECEBIAAoAsgBKAIoIAAoAswBQShsaiECIAFFBEAgAigCEBAJQQAhBSAAKALIASgCKCAAKALMAUEobGoiAEEANgIIIABBADYCECADQQFByTRBABAIDAMLIAIgATYCEAwCCyAEIAE2AkAgA0EBQYLaACAEQUBrEAhBACEFDAELQQAhBSAHQQA2AgggA0EBQck0QQAQCAsgBEHwAGokACAFC6sHAQh/IwBB0ABrIgQkACAEQQE2AkwCQAJAIAAoAsgBIgUoAigiAw0AIAUgACgCbCAAKAJobCIDNgIkIANBKBAMIQMgACgCyAEiBSADNgIoIANFBEBBACEFDAILIAUoAiRFDQADQEEAIQUgAyAGQShsIgdqIgNBADYCFCADQeQANgIcQeQAQRgQDCE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CFCABbEECdGoQViABQQFqIgEgACgCIEkNAAsLIAAoAgAQCSAAEAkLqAEBBX8gACgCVCIDKAIAIQUgAygCBCIEIAAoAhQgACgCHCIHayIGIAQgBkkbIgYEQCAFIAcgBhALGiADIAMoAgAgBmoiBTYCACADIAMoAgQgBmsiBDYCBAsgBCACIAIgBEsbIgQEQCAFIAEgBBALGiADIAMoAgAgBGoiBTYCACADIAMoAgQgBGs2AgQLIAVBADoAACAAIAAoAiwiATYCHCAAIAE2AhQgAgueBQIGfgR/IAEgASgCAEEHakF4cSIBQRBqNgIAIAAhCyABKQMAIQMgASkDCCEHIwBBIGsiCCQAIAdC////////P4MhBAJ+IAdCMIhC//8BgyIFpyIKQYH4AGtB/Q9NBEAgBEIEhiADQjyIhCECIApBgPgAa60hBQJAIANC//////////8PgyIDQoGAgICAgICACFoEQCACQgF8IQIMAQsgA0KAgICAgICAgAhSDQAgAkIBgyACfCECC0IAIAIgAkL/////////B1YiABshAiAArSAFfAwBCwJAIAMgBIRQDQAgBUL//wFSDQAgBEIEhiADQjyIhEKAgICAgICABIQhAkL/DwwBC0L/DyAKQf6HAUsNABpCAEGA+ABBgfgAIAVQIgEbIgAgCmsiCUHwAEoNABogAyECIAQgBEKAgICAgIDAAIQgARsiBiEEAkBBgAEgCWsiAUHAAHEEQCADIAFBQGqthiEEQgAhAgwBCyABRQ0AIAQgAa0iBYYgAkHAACABa62IhCEEIAIgBYYhAgsgCCACNwMQIAggBDcDGAJAIAlBwABxBEAgBiAJQUBqrYghA0IAIQYMAQsgCUUNACAGQcAAIAlrrYYgAyAJrSICiIQhAyAGIAKIIQYLIAggAzcDACAIIAY3AwggCCkDCEIEhiAIKQMAIgJCPIiEIQMCQCAAIApHIAgpAxAgCCkDGIRCAFJxrSACQv//////////D4OEIgJCgYCAgICAgIAIWgRAIANCAXwhAwwBCyACQoCAgICAgICACFINACADQgGDIAN8IQMLIANCgICAgICAgAiFIAMgA0L/////////B1YiABshAiAArQshAyAIQSBqJAAgCyA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AAQAAAAhAAAAWP8AABAAAAAiAAAAYP8AAAQAAAAjAAAAYf8AABAAAAAkAAAAkf8AQZi/AQtlY/8AAAQAAAAlAAAAZP8AABQAAAAmAAAAdP8AABQAAAAnAAAAeP8AAAQAAAAoAAAAUP8AAAQAAAApAAAAWf8AAAQAAAAqAAAAdf8AABQAAAArAAAAd/8AABQAAAAsAAAAAAAAABQAQZDAAQs1LQAAAC4AAAAvAAAAMAAAADEAAAAyAAAAMwAAADQAAAAgIFBqNgAAAHB5dGY3AAAAaDJwajgAQdDAAQsycmRoaTkAAABybG9jOgAAAGNjcGI7AAAAcmxjcDwAAABwYW1jPQAAAGZlZGM+AAAAeGIAQZDBAQtBGQALABkZGQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAAZAAoKGRkZAwoHAAEACQsYAAAJBgsAAAsABhkAAAAZGRkAQeHBAQshDgAAAAAAAAAAGQALDRkZGQANAAACAAkOAAAACQAOAAAOAEGbwgELAQwAQafCAQsVEwAAAAATAAAAAAkMAAAAAAAMAAAMAEHVwgELARAAQeHCAQsVDwAAAAQPAAAAAAkQAAAAAAAQAAAQAEGPwwELARIAQZvDAQseEQAAAAARAAAAAAkSAAAAAAASAAASAAAaAAAAGhoaAEHSwwELDhoAAAAaGhoAAAAAAAAJAEGDxAELARQAQY/EAQsVFwAAAAAXAAAAAAkUAAAAAAAUAAAUAEG9xAELARYAQcnEAQsnFQAAAAAVAAAAAAkWAAAAAAAWAAAWAAAwMTIzNDU2Nzg5QUJDREVGAEHxxAELCGwBAAAAAAAFAEGExQELAWkAQZzFAQsOagAAAGsAAAD4ZwAAAAQAQbTFAQsBAQBBxMUBCwX/////Cg=="; + function getBinarySync(file) { + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary); + } + var binary = tryParseAsDataURI(file); + if (binary) { + return binary; + } + if (readBinary) { + return readBinary(file); + } + throw 'sync fetching of the wasm failed: you can preload it to Module["wasmBinary"] manually, or emcc.py will do that for you when generating HTML (but not JS)'; + } + function instantiateSync(file, info) { + var module; + var binary = getBinarySync(file); + module = new WebAssembly.Module(binary); + var instance = new WebAssembly.Instance(module, info); + return [instance, module]; + } + function createWasm() { + var info = { + "a": wasmImports + }; + function receiveInstance(instance, module) { + wasmExports = instance.exports; + wasmMemory = wasmExports["i"]; + updateMemoryViews(); + addOnInit(wasmExports["j"]); + removeRunDependency("wasm-instantiate"); + return wasmExports; + } + addRunDependency("wasm-instantiate"); + if (Module["instantiateWasm"]) { + try { + return Module["instantiateWasm"](info, receiveInstance); + } catch (e) { + err(`Module.instantiateWasm callback failed with error: ${e}`); + readyPromiseReject(e); } - c = 0; } - px = 0; + var result = instantiateSync(wasmBinaryFile, info); + return receiveInstance(result[0]); } - throw new JpxError("Out of packets"); - }; -} -function ComponentPositionResolutionLayerIterator(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const layersCount = tile.codingStyleDefaultParameters.layersCount; - const componentsCount = siz.Csiz; - const precinctsSizes = getPrecinctSizesInImageScale(tile); - let l = 0, - r = 0, - c = 0, - px = 0, - py = 0; - this.nextPacket = function JpxImage_nextPacket() { - for (; c < componentsCount; ++c) { - const component = tile.components[c]; - const precinctsIterationSizes = precinctsSizes.components[c]; - const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; - for (; py < precinctsIterationSizes.maxNumHigh; py++) { - for (; px < precinctsIterationSizes.maxNumWide; px++) { - for (; r <= decompositionLevelsCount; r++) { - const resolution = component.resolutions[r]; - const sizeInImageScale = precinctsIterationSizes.resolutions[r]; - const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); - if (k === null) { - continue; - } - for (; l < layersCount;) { - const packet = createPacket(resolution, k, l); - l++; - return packet; - } - l = 0; - } - r = 0; - } - px = 0; + var callRuntimeCallbacks = callbacks => { + while (callbacks.length > 0) { + callbacks.shift()(Module); } - py = 0; - } - throw new JpxError("Out of packets"); - }; -} -function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) { - const posX = pxIndex * precinctIterationSizes.minWidth; - const posY = pyIndex * precinctIterationSizes.minHeight; - if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) { - return null; - } - const startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide; - return posX / sizeInImageScale.height + startPrecinctRowIndex; -} -function getPrecinctSizesInImageScale(tile) { - const componentsCount = tile.components.length; - let minWidth = Number.MAX_VALUE; - let minHeight = Number.MAX_VALUE; - let maxNumWide = 0; - let maxNumHigh = 0; - const sizePerComponent = new Array(componentsCount); - for (let c = 0; c < componentsCount; c++) { - const component = tile.components[c]; - const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; - const sizePerResolution = new Array(decompositionLevelsCount + 1); - let minWidthCurrentComponent = Number.MAX_VALUE; - let minHeightCurrentComponent = Number.MAX_VALUE; - let maxNumWideCurrentComponent = 0; - let maxNumHighCurrentComponent = 0; - let scale = 1; - for (let r = decompositionLevelsCount; r >= 0; --r) { - const resolution = component.resolutions[r]; - const widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth; - const heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight; - minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution); - minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution); - maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide); - maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh); - sizePerResolution[r] = { - width: widthCurrentResolution, - height: heightCurrentResolution - }; - scale <<= 1; - } - minWidth = Math.min(minWidth, minWidthCurrentComponent); - minHeight = Math.min(minHeight, minHeightCurrentComponent); - maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent); - maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent); - sizePerComponent[c] = { - resolutions: sizePerResolution, - minWidth: minWidthCurrentComponent, - minHeight: minHeightCurrentComponent, - maxNumWide: maxNumWideCurrentComponent, - maxNumHigh: maxNumHighCurrentComponent }; - } - return { - components: sizePerComponent, - minWidth, - minHeight, - maxNumWide, - maxNumHigh - }; -} -function buildPackets(context) { - const siz = context.SIZ; - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const componentsCount = siz.Csiz; - for (let c = 0; c < componentsCount; c++) { - const component = tile.components[c]; - const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; - const resolutions = []; - const subbands = []; - for (let r = 0; r <= decompositionLevelsCount; r++) { - const blocksDimensions = getBlocksDimensions(context, component, r); - const resolution = {}; - const scale = 1 << decompositionLevelsCount - r; - resolution.trx0 = Math.ceil(component.tcx0 / scale); - resolution.try0 = Math.ceil(component.tcy0 / scale); - resolution.trx1 = Math.ceil(component.tcx1 / scale); - resolution.try1 = Math.ceil(component.tcy1 / scale); - resolution.resLevel = r; - buildPrecincts(context, resolution, blocksDimensions); - resolutions.push(resolution); - let subband; - if (r === 0) { - subband = {}; - subband.type = "LL"; - subband.tbx0 = Math.ceil(component.tcx0 / scale); - subband.tby0 = Math.ceil(component.tcy0 / scale); - subband.tbx1 = Math.ceil(component.tcx1 / scale); - subband.tby1 = Math.ceil(component.tcy1 / scale); - subband.resolution = resolution; - buildCodeblocks(context, subband, blocksDimensions); - subbands.push(subband); - resolution.subbands = [subband]; - } else { - const bscale = 1 << decompositionLevelsCount - r + 1; - const resolutionSubbands = []; - subband = {}; - subband.type = "HL"; - subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5); - subband.tby0 = Math.ceil(component.tcy0 / bscale); - subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5); - subband.tby1 = Math.ceil(component.tcy1 / bscale); - subband.resolution = resolution; - buildCodeblocks(context, subband, blocksDimensions); - subbands.push(subband); - resolutionSubbands.push(subband); - subband = {}; - subband.type = "LH"; - subband.tbx0 = Math.ceil(component.tcx0 / bscale); - subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5); - subband.tbx1 = Math.ceil(component.tcx1 / bscale); - subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5); - subband.resolution = resolution; - buildCodeblocks(context, subband, blocksDimensions); - subbands.push(subband); - resolutionSubbands.push(subband); - subband = {}; - subband.type = "HH"; - subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5); - subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5); - subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5); - subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5); - subband.resolution = resolution; - buildCodeblocks(context, subband, blocksDimensions); - subbands.push(subband); - resolutionSubbands.push(subband); - resolution.subbands = resolutionSubbands; - } - } - component.resolutions = resolutions; - component.subbands = subbands; - } - const progressionOrder = tile.codingStyleDefaultParameters.progressionOrder; - switch (progressionOrder) { - case 0: - tile.packetsIterator = new LayerResolutionComponentPositionIterator(context); - break; - case 1: - tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context); - break; - case 2: - tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context); - break; - case 3: - tile.packetsIterator = new PositionComponentResolutionLayerIterator(context); - break; - case 4: - tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context); - break; - default: - throw new JpxError(`Unsupported progression order ${progressionOrder}`); - } -} -function parseTilePackets(context, data, offset, dataLength) { - let position = 0; - let buffer, - bufferSize = 0, - skipNextBit = false; - function readBits(count) { - while (bufferSize < count) { - const b = data[offset + position]; - position++; - if (skipNextBit) { - buffer = buffer << 7 | b; - bufferSize += 7; - skipNextBit = false; - } else { - buffer = buffer << 8 | b; - bufferSize += 8; - } - if (b === 0xff) { - skipNextBit = true; - } - } - bufferSize -= count; - return buffer >>> bufferSize & (1 << count) - 1; - } - function skipMarkerIfEqual(value) { - if (data[offset + position - 1] === 0xff && data[offset + position] === value) { - skipBytes(1); - return true; - } else if (data[offset + position] === 0xff && data[offset + position + 1] === value) { - skipBytes(2); - return true; - } - return false; - } - function skipBytes(count) { - position += count; - } - function alignToByte() { - bufferSize = 0; - if (skipNextBit) { - position++; - skipNextBit = false; - } - } - function readCodingpasses() { - if (readBits(1) === 0) { - return 1; - } - if (readBits(1) === 0) { - return 2; - } - let value = readBits(2); - if (value < 3) { - return value + 3; - } - value = readBits(5); - if (value < 31) { - return value + 6; - } - value = readBits(7); - return value + 37; - } - const tileIndex = context.currentTile.index; - const tile = context.tiles[tileIndex]; - const sopMarkerUsed = context.COD.sopMarkerUsed; - const ephMarkerUsed = context.COD.ephMarkerUsed; - const packetsIterator = tile.packetsIterator; - while (position < dataLength) { - alignToByte(); - if (sopMarkerUsed && skipMarkerIfEqual(0x91)) { - skipBytes(4); - } - const packet = packetsIterator.nextPacket(); - if (!readBits(1)) { - continue; - } - const layerNumber = packet.layerNumber, - queue = []; - let codeblock; - for (let i = 0, ii = packet.codeblocks.length; i < ii; i++) { - codeblock = packet.codeblocks[i]; - let precinct = codeblock.precinct; - const codeblockColumn = codeblock.cbx - precinct.cbxMin; - const codeblockRow = codeblock.cby - precinct.cbyMin; - let codeblockIncluded = false; - let firstTimeInclusion = false; - let valueReady, zeroBitPlanesTree; - if (codeblock.included !== undefined) { - codeblockIncluded = !!readBits(1); - } else { - precinct = codeblock.precinct; - let inclusionTree; - if (precinct.inclusionTree !== undefined) { - inclusionTree = precinct.inclusionTree; - } else { - const width = precinct.cbxMax - precinct.cbxMin + 1; - const height = precinct.cbyMax - precinct.cbyMin + 1; - inclusionTree = new InclusionTree(width, height, layerNumber); - zeroBitPlanesTree = new TagTree(width, height); - precinct.inclusionTree = inclusionTree; - precinct.zeroBitPlanesTree = zeroBitPlanesTree; - for (let l = 0; l < layerNumber; l++) { - if (readBits(1) !== 0) { - throw new JpxError("Invalid tag tree"); - } - } - } - if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) { - while (true) { - if (readBits(1)) { - valueReady = !inclusionTree.nextLevel(); - if (valueReady) { - codeblock.included = true; - codeblockIncluded = firstTimeInclusion = true; - break; - } - } else { - inclusionTree.incrementValue(layerNumber); - break; - } - } - } - } - if (!codeblockIncluded) { - continue; - } - if (firstTimeInclusion) { - zeroBitPlanesTree = precinct.zeroBitPlanesTree; - zeroBitPlanesTree.reset(codeblockColumn, codeblockRow); - while (true) { - if (readBits(1)) { - valueReady = !zeroBitPlanesTree.nextLevel(); - if (valueReady) { - break; - } - } else { - zeroBitPlanesTree.incrementValue(); - } - } - codeblock.zeroBitPlanes = zeroBitPlanesTree.value; - } - const codingpasses = readCodingpasses(); - while (readBits(1)) { - codeblock.Lblock++; + var noExitRuntime = Module["noExitRuntime"] || true; + var __emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num); + var getHeapMax = () => 2147483648; + var growMemory = size => { + var b = wasmMemory.buffer; + var pages = (size - b.byteLength + 65535) / 65536; + try { + wasmMemory.grow(pages); + updateMemoryViews(); + return 1; + } catch (e) {} + }; + var _emscripten_resize_heap = requestedSize => { + var oldSize = HEAPU8.length; + requestedSize >>>= 0; + var maxHeapSize = getHeapMax(); + if (requestedSize > maxHeapSize) { + return false; } - const codingpassesLog2 = log2(codingpasses); - const bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock; - const codedDataLength = readBits(bits); - queue.push({ - codeblock, - codingpasses, - dataLength: codedDataLength - }); - } - alignToByte(); - if (ephMarkerUsed) { - skipMarkerIfEqual(0x92); - } - while (queue.length > 0) { - const packetItem = queue.shift(); - codeblock = packetItem.codeblock; - if (codeblock.data === undefined) { - codeblock.data = []; - } - codeblock.data.push({ - data, - start: offset + position, - end: offset + position + packetItem.dataLength, - codingpasses: packetItem.codingpasses - }); - position += packetItem.dataLength; - } - } - return position; -} -function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities) { - const x0 = subband.tbx0; - const y0 = subband.tby0; - const width = subband.tbx1 - subband.tbx0; - const codeblocks = subband.codeblocks; - const right = subband.type.charAt(0) === "H" ? 1 : 0; - const bottom = subband.type.charAt(1) === "H" ? levelWidth : 0; - for (let i = 0, ii = codeblocks.length; i < ii; ++i) { - const codeblock = codeblocks[i]; - const blockWidth = codeblock.tbx1_ - codeblock.tbx0_; - const blockHeight = codeblock.tby1_ - codeblock.tby0_; - if (blockWidth === 0 || blockHeight === 0) { - continue; - } - if (codeblock.data === undefined) { - continue; - } - const bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb); - let currentCodingpassType = 2; - const data = codeblock.data; - let totalLength = 0, - codingpasses = 0; - let j, jj, dataItem; - for (j = 0, jj = data.length; j < jj; j++) { - dataItem = data[j]; - totalLength += dataItem.end - dataItem.start; - codingpasses += dataItem.codingpasses; - } - const encodedData = new Uint8Array(totalLength); - let position = 0; - for (j = 0, jj = data.length; j < jj; j++) { - dataItem = data[j]; - const chunk = dataItem.data.subarray(dataItem.start, dataItem.end); - encodedData.set(chunk, position); - position += chunk.length; - } - const decoder = new ArithmeticDecoder(encodedData, 0, totalLength); - bitModel.setDecoder(decoder); - for (j = 0; j < codingpasses; j++) { - switch (currentCodingpassType) { - case 0: - bitModel.runSignificancePropagationPass(); - break; - case 1: - bitModel.runMagnitudeRefinementPass(); - break; - case 2: - bitModel.runCleanupPass(); - if (segmentationSymbolUsed) { - bitModel.checkSegmentationSymbol(); - } - break; - } - if (resetContextProbabilities) { - bitModel.reset(); - } - currentCodingpassType = (currentCodingpassType + 1) % 3; - } - let offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width; - const sign = bitModel.coefficentsSign; - const magnitude = bitModel.coefficentsMagnitude; - const bitsDecoded = bitModel.bitsDecoded; - const magnitudeCorrection = reversible ? 0 : 0.5; - let k, n, nb; - position = 0; - const interleave = subband.type !== "LL"; - for (j = 0; j < blockHeight; j++) { - const row = offset / width | 0; - const levelOffset = 2 * row * (levelWidth - width) + right + bottom; - for (k = 0; k < blockWidth; k++) { - n = magnitude[position]; - if (n !== 0) { - n = (n + magnitudeCorrection) * delta; - if (sign[position] !== 0) { - n = -n; - } - nb = bitsDecoded[position]; - const pos = interleave ? levelOffset + (offset << 1) : offset; - coefficients[pos] = reversible && nb >= mb ? n : n * (1 << mb - nb); + var alignUp = (x, multiple) => x + (multiple - x % multiple) % multiple; + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + .2 / cutDown); + overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296); + var newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536)); + var replacement = growMemory(newSize); + if (replacement) { + return true; } - offset++; - position++; - } - offset += width - blockWidth; - } - } -} -function transformTile(context, tile, c) { - const component = tile.components[c]; - const codingStyleParameters = component.codingStyleParameters; - const quantizationParameters = component.quantizationParameters; - const decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount; - const spqcds = quantizationParameters.SPqcds; - const scalarExpounded = quantizationParameters.scalarExpounded; - const guardBits = quantizationParameters.guardBits; - const segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; - const resetContextProbabilities = codingStyleParameters.resetContextProbabilities; - const precision = context.components[c].precision; - const reversible = codingStyleParameters.reversibleTransformation; - const transform = reversible ? new ReversibleTransform() : new IrreversibleTransform(); - const subbandCoefficients = []; - let b = 0; - for (let i = 0; i <= decompositionLevelsCount; i++) { - const resolution = component.resolutions[i]; - const width = resolution.trx1 - resolution.trx0; - const height = resolution.try1 - resolution.try0; - const coefficients = new Float32Array(width * height); - for (let j = 0, jj = resolution.subbands.length; j < jj; j++) { - let mu, epsilon; - if (!scalarExpounded) { - mu = spqcds[0].mu; - epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0); - } else { - mu = spqcds[b].mu; - epsilon = spqcds[b].epsilon; - b++; } - const subband = resolution.subbands[j]; - const gainLog2 = SubbandsGainLog2[subband.type]; - const delta = reversible ? 1 : 2 ** (precision + gainLog2 - epsilon) * (1 + mu / 2048); - const mb = guardBits + epsilon - 1; - copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities); - } - subbandCoefficients.push({ - width, - height, - items: coefficients - }); - } - const result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0); - return { - left: component.tcx0, - top: component.tcy0, - width: result.width, - height: result.height, - items: result.items - }; -} -function transformComponents(context) { - const siz = context.SIZ; - const components = context.components; - const componentsCount = siz.Csiz; - const resultImages = []; - for (let i = 0, ii = context.tiles.length; i < ii; i++) { - const tile = context.tiles[i]; - const transformedTiles = []; - for (let c = 0; c < componentsCount; c++) { - transformedTiles[c] = transformTile(context, tile, c); - } - const tile0 = transformedTiles[0]; - const out = new Uint8ClampedArray(tile0.items.length * componentsCount); - const result = { - left: tile0.left, - top: tile0.top, - width: tile0.width, - height: tile0.height, - items: out + return false; }; - let shift, offset; - let pos = 0, - j, - jj, - y0, - y1, - y2; - if (tile.codingStyleDefaultParameters.multipleComponentTransform) { - const fourComponents = componentsCount === 4; - const y0items = transformedTiles[0].items; - const y1items = transformedTiles[1].items; - const y2items = transformedTiles[2].items; - const y3items = fourComponents ? transformedTiles[3].items : null; - shift = components[0].precision - 8; - offset = (128 << shift) + 0.5; - const component0 = tile.components[0]; - const alpha01 = componentsCount - 3; - jj = y0items.length; - if (!component0.codingStyleParameters.reversibleTransformation) { - for (j = 0; j < jj; j++, pos += alpha01) { - y0 = y0items[j] + offset; - y1 = y1items[j]; - y2 = y2items[j]; - out[pos++] = y0 + 1.402 * y2 >> shift; - out[pos++] = y0 - 0.34413 * y1 - 0.71414 * y2 >> shift; - out[pos++] = y0 + 1.772 * y1 >> shift; - } - } else { - for (j = 0; j < jj; j++, pos += alpha01) { - y0 = y0items[j] + offset; - y1 = y1items[j]; - y2 = y2items[j]; - const g = y0 - (y2 + y1 >> 2); - out[pos++] = g + y2 >> shift; - out[pos++] = g >> shift; - out[pos++] = g + y1 >> shift; + var ENV = {}; + var getExecutableName = () => thisProgram || "./this.program"; + var getEnvStrings = () => { + if (!getEnvStrings.strings) { + var lang = (typeof navigator == "object" && navigator.languages && navigator.languages[0] || "C").replace("-", "_") + ".UTF-8"; + var env = { + "USER": "web_user", + "LOGNAME": "web_user", + "PATH": "/", + "PWD": "/", + "HOME": "/home/web_user", + "LANG": lang, + "_": getExecutableName() + }; + for (var x in ENV) { + if (ENV[x] === undefined) delete env[x];else env[x] = ENV[x]; } - } - if (fourComponents) { - for (j = 0, pos = 3; j < jj; j++, pos += 4) { - out[pos] = y3items[j] + offset >> shift; + var strings = []; + for (var x in env) { + strings.push(`${x}=${env[x]}`); } + getEnvStrings.strings = strings; } - } else { - for (let c = 0; c < componentsCount; c++) { - const items = transformedTiles[c].items; - shift = components[c].precision - 8; - offset = (128 << shift) + 0.5; - for (pos = c, j = 0, jj = items.length; j < jj; j++) { - out[pos] = items[j] + offset >> shift; - pos += componentsCount; - } - } - } - resultImages.push(result); - } - return resultImages; -} -function initializeTile(context, tileIndex) { - const siz = context.SIZ; - const componentsCount = siz.Csiz; - const tile = context.tiles[tileIndex]; - for (let c = 0; c < componentsCount; c++) { - const component = tile.components[c]; - const qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD; - component.quantizationParameters = qcdOrQcc; - const codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD; - component.codingStyleParameters = codOrCoc; - } - tile.codingStyleDefaultParameters = context.currentTile.COD; -} -class TagTree { - constructor(width, height) { - const levelsLength = log2(Math.max(width, height)) + 1; - this.levels = []; - for (let i = 0; i < levelsLength; i++) { - const level = { - width, - height, - items: [] - }; - this.levels.push(level); - width = Math.ceil(width / 2); - height = Math.ceil(height / 2); - } - } - reset(i, j) { - let currentLevel = 0, - value = 0, - level; - while (currentLevel < this.levels.length) { - level = this.levels[currentLevel]; - const index = i + j * level.width; - if (level.items[index] !== undefined) { - value = level.items[index]; - break; - } - level.index = index; - i >>= 1; - j >>= 1; - currentLevel++; - } - currentLevel--; - level = this.levels[currentLevel]; - level.items[level.index] = value; - this.currentLevel = currentLevel; - delete this.value; - } - incrementValue() { - const level = this.levels[this.currentLevel]; - level.items[level.index]++; - } - nextLevel() { - let currentLevel = this.currentLevel; - let level = this.levels[currentLevel]; - const value = level.items[level.index]; - currentLevel--; - if (currentLevel < 0) { - this.value = value; - return false; - } - this.currentLevel = currentLevel; - level = this.levels[currentLevel]; - level.items[level.index] = value; - return true; - } -} -class InclusionTree { - constructor(width, height, defaultValue) { - const levelsLength = log2(Math.max(width, height)) + 1; - this.levels = []; - for (let i = 0; i < levelsLength; i++) { - const items = new Uint8Array(width * height); - for (let j = 0, jj = items.length; j < jj; j++) { - items[j] = defaultValue; - } - const level = { - width, - height, - items - }; - this.levels.push(level); - width = Math.ceil(width / 2); - height = Math.ceil(height / 2); - } - } - reset(i, j, stopValue) { - let currentLevel = 0; - while (currentLevel < this.levels.length) { - const level = this.levels[currentLevel]; - const index = i + j * level.width; - level.index = index; - const value = level.items[index]; - if (value === 0xff) { - break; - } - if (value > stopValue) { - this.currentLevel = currentLevel; - this.propagateValues(); - return false; - } - i >>= 1; - j >>= 1; - currentLevel++; - } - this.currentLevel = currentLevel - 1; - return true; - } - incrementValue(stopValue) { - const level = this.levels[this.currentLevel]; - level.items[level.index] = stopValue + 1; - this.propagateValues(); - } - propagateValues() { - let levelIndex = this.currentLevel; - let level = this.levels[levelIndex]; - const currentValue = level.items[level.index]; - while (--levelIndex >= 0) { - level = this.levels[levelIndex]; - level.items[level.index] = currentValue; - } - } - nextLevel() { - let currentLevel = this.currentLevel; - let level = this.levels[currentLevel]; - const value = level.items[level.index]; - level.items[level.index] = 0xff; - currentLevel--; - if (currentLevel < 0) { - return false; - } - this.currentLevel = currentLevel; - level = this.levels[currentLevel]; - level.items[level.index] = value; - return true; - } -} -class BitModel { - static UNIFORM_CONTEXT = 17; - static RUNLENGTH_CONTEXT = 18; - static LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]); - static HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]); - static HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]); - constructor(width, height, subband, zeroBitPlanes, mb) { - this.width = width; - this.height = height; - let contextLabelTable; - if (subband === "HH") { - contextLabelTable = BitModel.HHContextLabel; - } else if (subband === "HL") { - contextLabelTable = BitModel.HLContextLabel; - } else { - contextLabelTable = BitModel.LLAndLHContextsLabel; - } - this.contextLabelTable = contextLabelTable; - const coefficientCount = width * height; - this.neighborsSignificance = new Uint8Array(coefficientCount); - this.coefficentsSign = new Uint8Array(coefficientCount); - let coefficentsMagnitude; - if (mb > 14) { - coefficentsMagnitude = new Uint32Array(coefficientCount); - } else if (mb > 6) { - coefficentsMagnitude = new Uint16Array(coefficientCount); - } else { - coefficentsMagnitude = new Uint8Array(coefficientCount); - } - this.coefficentsMagnitude = coefficentsMagnitude; - this.processingFlags = new Uint8Array(coefficientCount); - const bitsDecoded = new Uint8Array(coefficientCount); - if (zeroBitPlanes !== 0) { - for (let i = 0; i < coefficientCount; i++) { - bitsDecoded[i] = zeroBitPlanes; - } - } - this.bitsDecoded = bitsDecoded; - this.reset(); - } - setDecoder(decoder) { - this.decoder = decoder; - } - reset() { - this.contexts = new Int8Array(19); - this.contexts[0] = 4 << 1 | 0; - this.contexts[BitModel.UNIFORM_CONTEXT] = 46 << 1 | 0; - this.contexts[BitModel.RUNLENGTH_CONTEXT] = 3 << 1 | 0; - } - setNeighborsSignificance(row, column, index) { - const neighborsSignificance = this.neighborsSignificance; - const width = this.width, - height = this.height; - const left = column > 0; - const right = column + 1 < width; - let i; - if (row > 0) { - i = index - width; - if (left) { - neighborsSignificance[i - 1] += 0x10; - } - if (right) { - neighborsSignificance[i + 1] += 0x10; - } - neighborsSignificance[i] += 0x04; - } - if (row + 1 < height) { - i = index + width; - if (left) { - neighborsSignificance[i - 1] += 0x10; - } - if (right) { - neighborsSignificance[i + 1] += 0x10; - } - neighborsSignificance[i] += 0x04; - } - if (left) { - neighborsSignificance[index - 1] += 0x01; - } - if (right) { - neighborsSignificance[index + 1] += 0x01; - } - neighborsSignificance[index] |= 0x80; - } - runSignificancePropagationPass() { - const decoder = this.decoder; - const width = this.width, - height = this.height; - const coefficentsMagnitude = this.coefficentsMagnitude; - const coefficentsSign = this.coefficentsSign; - const neighborsSignificance = this.neighborsSignificance; - const processingFlags = this.processingFlags; - const contexts = this.contexts; - const labels = this.contextLabelTable; - const bitsDecoded = this.bitsDecoded; - const processedInverseMask = ~1; - const processedMask = 1; - const firstMagnitudeBitMask = 2; - for (let i0 = 0; i0 < height; i0 += 4) { - for (let j = 0; j < width; j++) { - let index = i0 * width + j; - for (let i1 = 0; i1 < 4; i1++, index += width) { - const i = i0 + i1; - if (i >= height) { - break; - } - processingFlags[index] &= processedInverseMask; - if (coefficentsMagnitude[index] || !neighborsSignificance[index]) { - continue; - } - const contextLabel = labels[neighborsSignificance[index]]; - const decision = decoder.readBit(contexts, contextLabel); - if (decision) { - const sign = this.decodeSignBit(i, j, index); - coefficentsSign[index] = sign; - coefficentsMagnitude[index] = 1; - this.setNeighborsSignificance(i, j, index); - processingFlags[index] |= firstMagnitudeBitMask; - } - bitsDecoded[index]++; - processingFlags[index] |= processedMask; - } - } - } - } - decodeSignBit(row, column, index) { - const width = this.width, - height = this.height; - const coefficentsMagnitude = this.coefficentsMagnitude; - const coefficentsSign = this.coefficentsSign; - let contribution, sign0, sign1, significance1; - let contextLabel, decoded; - significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0; - if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) { - sign1 = coefficentsSign[index + 1]; - if (significance1) { - sign0 = coefficentsSign[index - 1]; - contribution = 1 - sign1 - sign0; - } else { - contribution = 1 - sign1 - sign1; - } - } else if (significance1) { - sign0 = coefficentsSign[index - 1]; - contribution = 1 - sign0 - sign0; - } else { - contribution = 0; - } - const horizontalContribution = 3 * contribution; - significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0; - if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) { - sign1 = coefficentsSign[index + width]; - if (significance1) { - sign0 = coefficentsSign[index - width]; - contribution = 1 - sign1 - sign0 + horizontalContribution; - } else { - contribution = 1 - sign1 - sign1 + horizontalContribution; + return getEnvStrings.strings; + }; + var stringToAscii = (str, buffer) => { + for (var i = 0; i < str.length; ++i) { + HEAP8[buffer++] = str.charCodeAt(i); } - } else if (significance1) { - sign0 = coefficentsSign[index - width]; - contribution = 1 - sign0 - sign0 + horizontalContribution; - } else { - contribution = horizontalContribution; - } - if (contribution >= 0) { - contextLabel = 9 + contribution; - decoded = this.decoder.readBit(this.contexts, contextLabel); - } else { - contextLabel = 9 - contribution; - decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; - } - return decoded; - } - runMagnitudeRefinementPass() { - const decoder = this.decoder; - const width = this.width, - height = this.height; - const coefficentsMagnitude = this.coefficentsMagnitude; - const neighborsSignificance = this.neighborsSignificance; - const contexts = this.contexts; - const bitsDecoded = this.bitsDecoded; - const processingFlags = this.processingFlags; - const processedMask = 1; - const firstMagnitudeBitMask = 2; - const length = width * height; - const width4 = width * 4; - for (let index0 = 0, indexNext; index0 < length; index0 = indexNext) { - indexNext = Math.min(length, index0 + width4); - for (let j = 0; j < width; j++) { - for (let index = index0 + j; index < indexNext; index += width) { - if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { - continue; - } - let contextLabel = 16; - if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) { - processingFlags[index] ^= firstMagnitudeBitMask; - const significance = neighborsSignificance[index] & 127; - contextLabel = significance === 0 ? 15 : 14; - } - const bit = decoder.readBit(contexts, contextLabel); - coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit; - bitsDecoded[index]++; - processingFlags[index] |= processedMask; - } - } - } - } - runCleanupPass() { - const decoder = this.decoder; - const width = this.width, - height = this.height; - const neighborsSignificance = this.neighborsSignificance; - const coefficentsMagnitude = this.coefficentsMagnitude; - const coefficentsSign = this.coefficentsSign; - const contexts = this.contexts; - const labels = this.contextLabelTable; - const bitsDecoded = this.bitsDecoded; - const processingFlags = this.processingFlags; - const processedMask = 1; - const firstMagnitudeBitMask = 2; - const oneRowDown = width; - const twoRowsDown = width * 2; - const threeRowsDown = width * 3; - let iNext; - for (let i0 = 0; i0 < height; i0 = iNext) { - iNext = Math.min(i0 + 4, height); - const indexBase = i0 * width; - const checkAllEmpty = i0 + 3 < height; - for (let j = 0; j < width; j++) { - const index0 = indexBase + j; - const allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0; - let i1 = 0, - index = index0; - let i = i0, - sign; - if (allEmpty) { - const hasSignificantCoefficent = decoder.readBit(contexts, BitModel.RUNLENGTH_CONTEXT); - if (!hasSignificantCoefficent) { - bitsDecoded[index0]++; - bitsDecoded[index0 + oneRowDown]++; - bitsDecoded[index0 + twoRowsDown]++; - bitsDecoded[index0 + threeRowsDown]++; - continue; - } - i1 = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT); - if (i1 !== 0) { - i = i0 + i1; - index += i1 * width; - } - sign = this.decodeSignBit(i, j, index); - coefficentsSign[index] = sign; - coefficentsMagnitude[index] = 1; - this.setNeighborsSignificance(i, j, index); - processingFlags[index] |= firstMagnitudeBitMask; - index = index0; - for (let i2 = i0; i2 <= i; i2++, index += width) { - bitsDecoded[index]++; - } - i1++; - } - for (i = i0 + i1; i < iNext; i++, index += width) { - if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { - continue; - } - const contextLabel = labels[neighborsSignificance[index]]; - const decision = decoder.readBit(contexts, contextLabel); - if (decision === 1) { - sign = this.decodeSignBit(i, j, index); - coefficentsSign[index] = sign; - coefficentsMagnitude[index] = 1; - this.setNeighborsSignificance(i, j, index); - processingFlags[index] |= firstMagnitudeBitMask; - } - bitsDecoded[index]++; + HEAP8[buffer] = 0; + }; + var _environ_get = (__environ, environ_buf) => { + var bufSize = 0; + getEnvStrings().forEach((string, i) => { + var ptr = environ_buf + bufSize; + HEAPU32[__environ + i * 4 >> 2] = ptr; + stringToAscii(string, ptr); + bufSize += string.length + 1; + }); + return 0; + }; + var _environ_sizes_get = (penviron_count, penviron_buf_size) => { + var strings = getEnvStrings(); + HEAPU32[penviron_count >> 2] = strings.length; + var bufSize = 0; + strings.forEach(string => bufSize += string.length + 1); + HEAPU32[penviron_buf_size >> 2] = bufSize; + return 0; + }; + var printCharBuffers = [null, [], []]; + var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined; + var UTF8ArrayToString = (heapOrArray, idx, maxBytesToRead) => { + var endIdx = idx + maxBytesToRead; + var endPtr = idx; + while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; + if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { + return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); + } + var str = ""; + while (idx < endPtr) { + var u0 = heapOrArray[idx++]; + if (!(u0 & 128)) { + str += String.fromCharCode(u0); + continue; } - } - } - } - checkSegmentationSymbol() { - const decoder = this.decoder; - const contexts = this.contexts; - const symbol = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT); - if (symbol !== 0xa) { - throw new JpxError("Invalid segmentation symbol"); - } - } -} -class Transform { - constructor() { - if (this.constructor === Transform) { - unreachable("Cannot initialize Transform."); - } - } - calculate(subbands, u0, v0) { - let ll = subbands[0]; - for (let i = 1, ii = subbands.length; i < ii; i++) { - ll = this.iterate(ll, subbands[i], u0, v0); - } - return ll; - } - extend(buffer, offset, size) { - let i1 = offset - 1, - j1 = offset + 1; - let i2 = offset + size - 2, - j2 = offset + size; - buffer[i1--] = buffer[j1++]; - buffer[j2++] = buffer[i2--]; - buffer[i1--] = buffer[j1++]; - buffer[j2++] = buffer[i2--]; - buffer[i1--] = buffer[j1++]; - buffer[j2++] = buffer[i2--]; - buffer[i1] = buffer[j1]; - buffer[j2] = buffer[i2]; - } - filter(x, offset, length) { - unreachable("Abstract method `filter` called"); - } - iterate(ll, hl_lh_hh, u0, v0) { - const llWidth = ll.width, - llHeight = ll.height; - let llItems = ll.items; - const width = hl_lh_hh.width; - const height = hl_lh_hh.height; - const items = hl_lh_hh.items; - let i, j, k, l, u, v; - for (k = 0, i = 0; i < llHeight; i++) { - l = i * 2 * width; - for (j = 0; j < llWidth; j++, k++, l += 2) { - items[l] = llItems[k]; - } - } - llItems = ll.items = null; - const bufferPadding = 4; - const rowBuffer = new Float32Array(width + 2 * bufferPadding); - if (width === 1) { - if ((u0 & 1) !== 0) { - for (v = 0, k = 0; v < height; v++, k += width) { - items[k] *= 0.5; + var u1 = heapOrArray[idx++] & 63; + if ((u0 & 224) == 192) { + str += String.fromCharCode((u0 & 31) << 6 | u1); + continue; } - } - } else { - for (v = 0, k = 0; v < height; v++, k += width) { - rowBuffer.set(items.subarray(k, k + width), bufferPadding); - this.extend(rowBuffer, bufferPadding, width); - this.filter(rowBuffer, bufferPadding, width); - items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k); - } - } - let numBuffers = 16; - const colBuffers = []; - for (i = 0; i < numBuffers; i++) { - colBuffers.push(new Float32Array(height + 2 * bufferPadding)); - } - let b, - currentBuffer = 0; - ll = bufferPadding + height; - if (height === 1) { - if ((v0 & 1) !== 0) { - for (u = 0; u < width; u++) { - items[u] *= 0.5; + var u2 = heapOrArray[idx++] & 63; + if ((u0 & 240) == 224) { + u0 = (u0 & 15) << 12 | u1 << 6 | u2; + } else { + u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63; } - } - } else { - for (u = 0; u < width; u++) { - if (currentBuffer === 0) { - numBuffers = Math.min(width - u, numBuffers); - for (k = u, l = bufferPadding; l < ll; k += width, l++) { - for (b = 0; b < numBuffers; b++) { - colBuffers[b][l] = items[k + b]; - } - } - currentBuffer = numBuffers; - } - currentBuffer--; - const buffer = colBuffers[currentBuffer]; - this.extend(buffer, bufferPadding, height); - this.filter(buffer, bufferPadding, height); - if (currentBuffer === 0) { - k = u - numBuffers + 1; - for (l = bufferPadding; l < ll; k += width, l++) { - for (b = 0; b < numBuffers; b++) { - items[k + b] = colBuffers[b][l]; - } - } + if (u0 < 65536) { + str += String.fromCharCode(u0); + } else { + var ch = u0 - 65536; + str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); } } - } - return { - width, - height, - items + return str; }; - } -} -class IrreversibleTransform extends Transform { - filter(x, offset, length) { - const len = length >> 1; - offset |= 0; - let j, n, current, next; - const alpha = -1.586134342059924; - const beta = -0.052980118572961; - const gamma = 0.882911075530934; - const delta = 0.443506852043971; - const K = 1.230174104914001; - const K_ = 1 / K; - j = offset - 3; - for (n = len + 4; n--; j += 2) { - x[j] *= K_; - } - j = offset - 2; - current = delta * x[j - 1]; - for (n = len + 3; n--; j += 2) { - next = delta * x[j + 1]; - x[j] = K * x[j] - current - next; - if (n--) { - j += 2; - current = delta * x[j + 1]; - x[j] = K * x[j] - current - next; + var printChar = (stream, curr) => { + var buffer = printCharBuffers[stream]; + if (curr === 0 || curr === 10) { + (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)); + buffer.length = 0; } else { - break; + buffer.push(curr); } + }; + var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""; + var _fd_write = (fd, iov, iovcnt, pnum) => { + var num = 0; + for (var i = 0; i < iovcnt; i++) { + var ptr = HEAPU32[iov >> 2]; + var len = HEAPU32[iov + 4 >> 2]; + iov += 8; + for (var j = 0; j < len; j++) { + printChar(fd, HEAPU8[ptr + j]); + } + num += len; + } + HEAPU32[pnum >> 2] = num; + return 0; + }; + function _jsPrintWarning(message_ptr) { + const message = UTF8ToString(message_ptr); + (Module.warn || console.warn)(`OpenJPEG: ${message}`); } - j = offset - 1; - current = gamma * x[j - 1]; - for (n = len + 2; n--; j += 2) { - next = gamma * x[j + 1]; - x[j] -= current + next; - if (n--) { - j += 2; - current = gamma * x[j + 1]; - x[j] -= current + next; + function _setImageData(array_ptr, array_size) { + Module.imageData = new Uint8ClampedArray(Module.HEAPU8.subarray(array_ptr, array_ptr + array_size)); + } + function _storeErrorMessage(message_ptr) { + const message = UTF8ToString(message_ptr); + if (!Module.errorMessages) { + Module.errorMessages = message; } else { - break; + Module.errorMessages += "\n" + message; + } + } + var wasmImports = { + f: __emscripten_memcpy_js, + b: _emscripten_resize_heap, + c: _environ_get, + d: _environ_sizes_get, + e: _fd_write, + g: _jsPrintWarning, + h: _setImageData, + a: _storeErrorMessage + }; + var wasmExports = createWasm(); + var ___wasm_call_ctors = wasmExports["j"]; + var _malloc = Module["_malloc"] = wasmExports["k"]; + var _free = Module["_free"] = wasmExports["l"]; + var _jp2_decode = Module["_jp2_decode"] = wasmExports["n"]; + var __emscripten_stack_restore = wasmExports["_emscripten_stack_restore"]; + var __emscripten_stack_alloc = wasmExports["_emscripten_stack_alloc"]; + var _emscripten_stack_get_current = wasmExports["emscripten_stack_get_current"]; + var calledRun; + dependenciesFulfilled = function runCaller() { + if (!calledRun) run(); + if (!calledRun) dependenciesFulfilled = runCaller; + }; + function run() { + if (runDependencies > 0) { + return; } - } - j = offset; - current = beta * x[j - 1]; - for (n = len + 1; n--; j += 2) { - next = beta * x[j + 1]; - x[j] -= current + next; - if (n--) { - j += 2; - current = beta * x[j + 1]; - x[j] -= current + next; + preRun(); + if (runDependencies > 0) { + return; + } + function doRun() { + if (calledRun) return; + calledRun = true; + Module["calledRun"] = true; + if (ABORT) return; + initRuntime(); + readyPromiseResolve(Module); + if (Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"](); + postRun(); + } + if (Module["setStatus"]) { + Module["setStatus"]("Running..."); + setTimeout(function () { + setTimeout(function () { + Module["setStatus"](""); + }, 1); + doRun(); + }, 1); } else { - break; + doRun(); } } - if (len !== 0) { - j = offset + 1; - current = alpha * x[j - 1]; - for (n = len; n--; j += 2) { - next = alpha * x[j + 1]; - x[j] -= current + next; - if (n--) { - j += 2; - current = alpha * x[j + 1]; - x[j] -= current + next; - } else { - break; - } + if (Module["preInit"]) { + if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]]; + while (Module["preInit"].length > 0) { + Module["preInit"].pop()(); } } + run(); + return moduleArg; + }; +})(); +/* harmony default export */ const openjpeg = (OpenJPEG); +;// CONCATENATED MODULE: ./src/core/jpx.js + + + +class JpxError extends BaseException { + constructor(msg) { + super(msg, "JpxError"); } } -class ReversibleTransform extends Transform { - filter(x, offset, length) { - const len = length >> 1; - offset |= 0; - let j, n; - for (j = offset, n = len + 1; n--; j += 2) { - x[j] -= x[j - 1] + x[j + 1] + 2 >> 2; +class JpxImage { + static #module = null; + static decode(data, ignoreColorSpace = false) { + this.#module ||= openjpeg({ + warn: warn + }); + const imageData = this.#module.decode(data, ignoreColorSpace); + if (typeof imageData === "string") { + throw new JpxError(imageData); } - for (j = offset + 1, n = len; n--; j += 2) { - x[j] += x[j - 1] + x[j + 1] >> 1; + return imageData; + } + static cleanup() { + this.#module = null; + } + static parseImageProperties(stream) { + let newByte = stream.getByte(); + while (newByte >= 0) { + const oldByte = newByte; + newByte = stream.getByte(); + const code = oldByte << 8 | newByte; + if (code === 0xff51) { + stream.skip(4); + const Xsiz = stream.getInt32() >>> 0; + const Ysiz = stream.getInt32() >>> 0; + const XOsiz = stream.getInt32() >>> 0; + const YOsiz = stream.getInt32() >>> 0; + stream.skip(16); + const Csiz = stream.getUint16(); + return { + width: Xsiz - XOsiz, + height: Ysiz - YOsiz, + bitsPerComponent: 8, + componentsCount: Csiz + }; + } } + throw new JpxError("No size marker found in JPX stream"); } } @@ -9425,40 +8025,11 @@ class JpxStream extends DecodeStream { return shadow(this, "bytes", this.stream.getBytes(this.maybeLength)); } ensureBuffer(requested) {} - readBlock() { + readBlock(ignoreColorSpace) { if (this.eof) { return; } - const jpxImage = new JpxImage(); - jpxImage.parse(this.bytes); - const width = jpxImage.width; - const height = jpxImage.height; - const componentsCount = jpxImage.componentsCount; - const tileCount = jpxImage.tiles.length; - if (tileCount === 1) { - this.buffer = jpxImage.tiles[0].items; - } else { - const data = new Uint8ClampedArray(width * height * componentsCount); - for (let k = 0; k < tileCount; k++) { - const tileComponents = jpxImage.tiles[k]; - const tileWidth = tileComponents.width; - const tileHeight = tileComponents.height; - const tileLeft = tileComponents.left; - const tileTop = tileComponents.top; - const src = tileComponents.items; - let srcPosition = 0; - let dataPosition = (width * tileTop + tileLeft) * componentsCount; - const imgRowSize = width * componentsCount; - const tileRowSize = tileWidth * componentsCount; - for (let j = 0; j < tileHeight; j++) { - const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize); - data.set(rowBytes, dataPosition); - srcPosition += tileRowSize; - dataPosition += imgRowSize; - } - } - this.buffer = data; - } + this.buffer = JpxImage.decode(this.bytes, ignoreColorSpace); this.bufferLength = this.buffer.length; this.eof = true; } @@ -18576,6 +17147,7 @@ class CFFFont { + function getUint32(data, offset) { return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0; } @@ -19213,7 +17785,7 @@ class Commands { cmds = []; add(cmd, args) { if (args) { - if (args.some(arg => typeof arg !== "number")) { + if (!isNumberArray(args, null)) { warn(`Commands.add - "${cmd}" has at least one non-number arg: "${args}".`); const newArgs = args.map(arg => typeof arg === "number" ? arg : 0); this.cmds.push(cmd, ...newArgs); @@ -19239,20 +17811,20 @@ class CompiledFont { charCode, glyphId } = lookupCmap(this.cmap, unicode); - let fn = this.compiledGlyphs[glyphId]; + let fn = this.compiledGlyphs[glyphId], + compileEx; if (!fn) { try { - fn = this.compiledGlyphs[glyphId] = this.compileGlyph(this.glyphs[glyphId], glyphId); + fn = this.compileGlyph(this.glyphs[glyphId], glyphId); } catch (ex) { - this.compiledGlyphs[glyphId] = NOOP; - if (this.compiledCharCodeToGlyphId[charCode] === undefined) { - this.compiledCharCodeToGlyphId[charCode] = glyphId; - } - throw ex; + fn = NOOP; + compileEx = ex; } + this.compiledGlyphs[glyphId] = fn; } - if (this.compiledCharCodeToGlyphId[charCode] === undefined) { - this.compiledCharCodeToGlyphId[charCode] = glyphId; + this.compiledCharCodeToGlyphId[charCode] ??= glyphId; + if (compileEx) { + throw compileEx; } return fn; } @@ -27807,6 +26379,7 @@ class GlobalImageCache { + class PDFFunctionFactory { constructor({ xref, @@ -27882,15 +26455,8 @@ function toNumberArray(arr) { if (!Array.isArray(arr)) { return null; } - const length = arr.length; - for (let i = 0; i < length; i++) { - if (typeof arr[i] !== "number") { - const result = new Array(length); - for (let j = 0; j < length; j++) { - result[j] = +arr[j]; - } - return result; - } + if (!isNumberArray(arr, null)) { + return arr.map(x => +x); } return arr; } @@ -29076,6 +27642,7 @@ function bidi(str, startLevel = -1, vertical = false) { ;// CONCATENATED MODULE: ./src/core/font_substitutions.js + const NORMAL = { style: "normal", weight: "normal" @@ -29266,10 +27833,13 @@ function generateFont({ } return result; } -function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFontName, standardFontName) { +function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFontName, standardFontName, type) { if (baseFontName.startsWith("InvalidPDFjsFont_")) { return null; } + if ((type === "TrueType" || type === "Type1") && /^[A-Z]{6}\+/.test(baseFontName)) { + baseFontName = baseFontName.slice(7); + } baseFontName = normalizeFontName(baseFontName); const key = baseFontName; let substitutionInfo = systemFontCache.get(key); @@ -29294,6 +27864,7 @@ function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFont const loadedName = `${idFactory.getDocId()}_s${idFactory.createFontId()}`; if (!substitution) { if (!validateFontName(baseFontName)) { + warn(`Cannot substitute the font because of its name: ${baseFontName}`); systemFontCache.set(key, null); return null; } @@ -30257,6 +28828,7 @@ class PDFImage { localColorSpaceCache }) { this.image = image; + let jpxDecode = false; const dict = image.dict; const filter = dict.get("F", "Filter"); let filterName; @@ -30270,13 +28842,14 @@ class PDFImage { } switch (filterName) { case "JPXDecode": - const jpxImage = new JpxImage(); - jpxImage.parseImageProperties(image.stream); + ({ + width: image.width, + height: image.height, + componentsCount: image.numComps, + bitsPerComponent: image.bitsPerComponent + } = JpxImage.parseImageProperties(image.stream)); image.stream.reset(); - image.width = jpxImage.width; - image.height = jpxImage.height; - image.bitsPerComponent = jpxImage.bitsPerComponent; - image.numComps = jpxImage.componentsCount; + jpxDecode = true; break; case "JBIG2Decode": image.bitsPerComponent = 1; @@ -30336,6 +28909,7 @@ class PDFImage { localColorSpaceCache }); this.numComps = this.colorSpace.numComps; + this.ignoreColorSpace = jpxDecode && this.colorSpace.name === "Indexed"; } this.decode = dict.getArray("D", "Decode"); this.needsDecode = false; @@ -30923,7 +29497,7 @@ class PDFImage { this.image.drawHeight = drawHeight || this.height; this.image.forceRGBA = !!forceRGBA; this.image.forceRGB = !!forceRGB; - const imageBytes = this.image.getBytes(length); + const imageBytes = this.image.getBytes(length, this.ignoreColorSpace); if (internal || this.image instanceof DecodeStream) { return imageBytes; } @@ -30957,6 +29531,7 @@ class PDFImage { + const DefaultPartialEvaluatorOptions = Object.freeze({ @@ -31433,7 +30008,7 @@ class PartialEvaluator { return; } const SMALL_IMAGE_DIMENSIONS = 200; - if (isInline && !dict.has("SMask") && !dict.has("Mask") && w + h < SMALL_IMAGE_DIMENSIONS) { + if (isInline && w + h < SMALL_IMAGE_DIMENSIONS && !dict.has("SMask") && !dict.has("Mask")) { try { const imageObj = new PDFImage({ xref: this.xref, @@ -31469,7 +30044,7 @@ class PartialEvaluator { operatorList.addDependency(objId); args = [objId, w, h]; operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent); - if (cacheGlobally && w * h > 250000) { + if (cacheGlobally && (w * h > 250000 || dict.has("SMask") || dict.has("Mask"))) { const localLength = await this.handler.sendWithPromise("commonobj", [objId, "CopyLocalImage", { imageRef }]); @@ -33637,56 +32212,85 @@ class PartialEvaluator { let defaultWidth = 0; const glyphsVMetrics = []; let defaultVMetrics; - let i, ii, j, jj, start, code, widths; if (properties.composite) { - defaultWidth = dict.has("DW") ? dict.get("DW") : 1000; - widths = dict.get("W"); - if (widths) { - for (i = 0, ii = widths.length; i < ii; i++) { - start = xref.fetchIfRef(widths[i++]); - code = xref.fetchIfRef(widths[i]); + const dw = dict.get("DW"); + defaultWidth = Number.isInteger(dw) ? dw : 1000; + const widths = dict.get("W"); + if (Array.isArray(widths)) { + for (let i = 0, ii = widths.length; i < ii; i++) { + let start = xref.fetchIfRef(widths[i++]); + if (!Number.isInteger(start)) { + break; + } + const code = xref.fetchIfRef(widths[i]); if (Array.isArray(code)) { - for (j = 0, jj = code.length; j < jj; j++) { - glyphsWidths[start++] = xref.fetchIfRef(code[j]); + for (const c of code) { + const width = xref.fetchIfRef(c); + if (typeof width === "number") { + glyphsWidths[start] = width; + } + start++; } - } else { + } else if (Number.isInteger(code)) { const width = xref.fetchIfRef(widths[++i]); - for (j = start; j <= code; j++) { + if (typeof width !== "number") { + continue; + } + for (let j = start; j <= code; j++) { glyphsWidths[j] = width; } + } else { + break; } } } if (properties.vertical) { - let vmetrics = dict.getArray("DW2") || [880, -1000]; + const dw2 = dict.getArray("DW2"); + let vmetrics = isNumberArray(dw2, 2) ? dw2 : [880, -1000]; defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]]; vmetrics = dict.get("W2"); - if (vmetrics) { - for (i = 0, ii = vmetrics.length; i < ii; i++) { - start = xref.fetchIfRef(vmetrics[i++]); - code = xref.fetchIfRef(vmetrics[i]); + if (Array.isArray(vmetrics)) { + for (let i = 0, ii = vmetrics.length; i < ii; i++) { + let start = xref.fetchIfRef(vmetrics[i++]); + if (!Number.isInteger(start)) { + break; + } + const code = xref.fetchIfRef(vmetrics[i]); if (Array.isArray(code)) { - for (j = 0, jj = code.length; j < jj; j++) { - glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])]; + for (let j = 0, jj = code.length; j < jj; j++) { + const vmetric = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])]; + if (isNumberArray(vmetric, null)) { + glyphsVMetrics[start] = vmetric; + } + start++; } - } else { + } else if (Number.isInteger(code)) { const vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])]; - for (j = start; j <= code; j++) { + if (!isNumberArray(vmetric, null)) { + continue; + } + for (let j = start; j <= code; j++) { glyphsVMetrics[j] = vmetric; } + } else { + break; } } } } } else { - const firstChar = properties.firstChar; - widths = dict.get("Widths"); - if (widths) { - j = firstChar; - for (i = 0, ii = widths.length; i < ii; i++) { - glyphsWidths[j++] = xref.fetchIfRef(widths[i]); - } - defaultWidth = parseFloat(descriptor.get("MissingWidth")) || 0; + const widths = dict.get("Widths"); + if (Array.isArray(widths)) { + let j = properties.firstChar; + for (const w of widths) { + const width = xref.fetchIfRef(w); + if (typeof width === "number") { + glyphsWidths[j] = width; + } + j++; + } + const missingWidth = descriptor.get("MissingWidth"); + defaultWidth = typeof missingWidth === "number" ? missingWidth : 0; } else { const baseFontName = dict.get("BaseFont"); if (baseFontName instanceof Name) { @@ -33788,8 +32392,14 @@ class PartialEvaluator { } composite = true; } - const firstChar = dict.get("FirstChar") || 0, - lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff); + let firstChar = dict.get("FirstChar"); + if (!Number.isInteger(firstChar)) { + firstChar = 0; + } + let lastChar = dict.get("LastChar"); + if (!Number.isInteger(lastChar)) { + lastChar = composite ? 0xffff : 0xff; + } const descriptor = dict.get("FontDescriptor"); const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode"); if (descriptor) { @@ -33894,9 +32504,13 @@ class PartialEvaluator { const isType3Font = type === "Type3"; if (!descriptor) { if (isType3Font) { + let bbox = dict.getArray("FontBBox"); + if (!isNumberArray(bbox, 4)) { + bbox = [0, 0, 0, 0]; + } descriptor = new Dict(null); descriptor.set("FontName", Name.get(type)); - descriptor.set("FontBBox", dict.getArray("FontBBox") || [0, 0, 0, 0]); + descriptor.set("FontBBox", bbox); } else { let baseFontName = dict.get("BaseFont"); if (!(baseFontName instanceof Name)) { @@ -33931,14 +32545,18 @@ class PartialEvaluator { properties.isInternalFont = !!file; } if (!properties.isInternalFont && this.options.useSystemFonts) { - properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName); + properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName, type); } const newProperties = await this.extractDataStructures(dict, properties); - if (widths) { + if (Array.isArray(widths)) { const glyphWidths = []; let j = firstChar; - for (const width of widths) { - glyphWidths[j++] = this.xref.fetchIfRef(width); + for (const w of widths) { + const width = this.xref.fetchIfRef(w); + if (typeof width === "number") { + glyphWidths[j] = width; + } + j++; } newProperties.widths = glyphWidths; } else { @@ -34008,13 +32626,41 @@ class PartialEvaluator { isInternalFont = !!fontFile; } if (!isInternalFont && this.options.useSystemFonts) { - systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName); + systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName, type); } } let fontMatrix = dict.getArray("FontMatrix"); - if (!Array.isArray(fontMatrix) || fontMatrix.length !== 6 || fontMatrix.some(x => typeof x !== "number")) { + if (!isNumberArray(fontMatrix, 6)) { fontMatrix = FONT_IDENTITY_MATRIX; } + let bbox = descriptor.getArray("FontBBox") || dict.getArray("FontBBox"); + if (!isNumberArray(bbox, 4)) { + bbox = undefined; + } + let ascent = descriptor.get("Ascent"); + if (typeof ascent !== "number") { + ascent = undefined; + } + let descent = descriptor.get("Descent"); + if (typeof descent !== "number") { + descent = undefined; + } + let xHeight = descriptor.get("XHeight"); + if (typeof xHeight !== "number") { + xHeight = 0; + } + let capHeight = descriptor.get("CapHeight"); + if (typeof capHeight !== "number") { + capHeight = 0; + } + let flags = descriptor.get("Flags"); + if (!Number.isInteger(flags)) { + flags = 0; + } + let italicAngle = descriptor.get("ItalicAngle"); + if (typeof italicAngle !== "number") { + italicAngle = 0; + } const properties = { type, name: fontName.name, @@ -34031,13 +32677,13 @@ class PartialEvaluator { firstChar, lastChar, toUnicode, - bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"), - ascent: descriptor.get("Ascent"), - descent: descriptor.get("Descent"), - xHeight: descriptor.get("XHeight") || 0, - capHeight: descriptor.get("CapHeight") || 0, - flags: descriptor.get("Flags"), - italicAngle: descriptor.get("ItalicAngle") || 0, + bbox, + ascent, + descent, + xHeight, + capHeight, + flags, + italicAngle, isType3Font, cssFontInfo, scaleFactors: glyphScaleFactors, @@ -35319,10 +33965,12 @@ class NumberTree extends NameOrNumberTree { + function clearGlobalCaches() { clearPatternCaches(); clearPrimitiveCaches(); clearUnicodeCaches(); + JpxImage.cleanup(); } ;// CONCATENATED MODULE: ./src/core/file_spec.js @@ -35354,7 +34002,6 @@ class FileSpec { if (root.has("FS")) { this.fs = root.get("FS"); } - this.description = root.has("Desc") ? stringToPDFString(root.get("Desc")) : ""; if (root.has("RF")) { warn("Related file specifications are not supported"); } @@ -35393,10 +34040,19 @@ class FileSpec { } return content; } + get description() { + let description = ""; + const desc = this.root?.get("Desc"); + if (desc && typeof desc === "string") { + description = stringToPDFString(desc); + } + return shadow(this, "description", description); + } get serializable() { return { filename: this.filename, - content: this.content + content: this.content, + description: this.description }; } } @@ -37262,7 +35918,7 @@ async function writeStream(stream, buffer, transform) { const filterZero = Array.isArray(filter) ? await dict.xref.fetchIfRefAsync(filter[0]) : filter; const isFilterZeroFlateDecode = isName(filterZero, "FlateDecode"); const MIN_LENGTH_FOR_COMPRESSING = 256; - if (typeof CompressionStream !== "undefined" && (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode)) { + if (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode) { try { const cs = new CompressionStream("deflate"); const writer = cs.writable.getWriter(); @@ -37463,8 +36119,12 @@ async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) { buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`); indexesPosition += 2; } - buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`); - baseOffset += data.length; + if (data !== null) { + buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`); + baseOffset += data.length; + } else { + buffer.push(`0000000000 ${Math.min(ref.gen + 1, 0xffff).toString().padStart(5, "0")} f\r\n`); + } } computeIDs(baseOffset, xrefInfo, newXref); buffer.push("trailer\n"); @@ -37492,11 +36152,17 @@ async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer ref, data } of newRefs) { + let gen; maxOffset = Math.max(maxOffset, baseOffset); - const gen = Math.min(ref.gen, 0xffff); + if (data !== null) { + gen = Math.min(ref.gen, 0xffff); + xrefTableData.push([1, baseOffset, gen]); + baseOffset += data.length; + } else { + gen = Math.min(ref.gen + 1, 0xffff); + xrefTableData.push([0, 0, gen]); + } maxGen = Math.max(maxGen, gen); - xrefTableData.push([1, baseOffset, gen]); - baseOffset += data.length; } newXref.set("Index", getIndexes(newRefs)); const offsetSize = getSizeInBytes(maxOffset); @@ -37580,21 +36246,21 @@ async function incrementalUpdate({ xref }); } - let buffer, baseOffset; + const buffer = []; + let baseOffset = originalData.length; const lastByte = originalData.at(-1); - if (lastByte === 0x0a || lastByte === 0x0d) { - buffer = []; - baseOffset = originalData.length; - } else { - buffer = ["\n"]; - baseOffset = originalData.length + 1; + if (lastByte !== 0x0a && lastByte !== 0x0d) { + buffer.push("\n"); + baseOffset += 1; } const newXref = getTrailerDict(xrefInfo, newRefs, useXrefStream); newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num); for (const { data } of newRefs) { - buffer.push(data); + if (data !== null) { + buffer.push(data); + } } await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer)); const totalLength = buffer.reduce((a, str) => a + str.length, originalData.length); @@ -37703,20 +36369,17 @@ class StructTreeRoot { newRefs }) { const root = pdfManager.catalog.cloneDict(); + const cache = new RefSetCache(); + cache.put(catalogRef, root); const structTreeRootRef = xref.getNewTemporaryRef(); root.set("StructTreeRoot", structTreeRootRef); - const buffer = []; - await writeObject(catalogRef, root, buffer, xref); - newRefs.push({ - ref: catalogRef, - data: buffer.join("") - }); const structTreeRoot = new Dict(xref); structTreeRoot.set("Type", Name.get("StructTreeRoot")); const parentTreeRef = xref.getNewTemporaryRef(); structTreeRoot.set("ParentTree", parentTreeRef); const kids = []; structTreeRoot.set("K", kids); + cache.put(structTreeRootRef, structTreeRoot); const parentTree = new Dict(xref); const nums = []; parentTree.set("Nums", nums); @@ -37727,22 +36390,19 @@ class StructTreeRoot { nums, xref, pdfManager, - newRefs, - buffer + cache }); structTreeRoot.set("ParentTreeNextKey", nextKey); - buffer.length = 0; - await writeObject(parentTreeRef, parentTree, buffer, xref); - newRefs.push({ - ref: parentTreeRef, - data: buffer.join("") - }); - buffer.length = 0; - await writeObject(structTreeRootRef, structTreeRoot, buffer, xref); - newRefs.push({ - ref: structTreeRootRef, - data: buffer.join("") - }); + cache.put(parentTreeRef, parentTree); + const buffer = []; + for (const [ref, obj] of cache.items()) { + buffer.length = 0; + await writeObject(ref, obj, buffer, xref); + newRefs.push({ + ref, + data: buffer.join("") + }); + } } async canUpdateStructTree({ pdfManager, @@ -37819,6 +36479,8 @@ class StructTreeRoot { const xref = this.dict.xref; const structTreeRoot = this.dict.clone(); const structTreeRootRef = this.ref; + const cache = new RefSetCache(); + cache.put(structTreeRootRef, structTreeRoot); let parentTreeRef = structTreeRoot.getRaw("ParentTree"); let parentTree; if (parentTreeRef instanceof Ref) { @@ -37829,6 +36491,7 @@ class StructTreeRoot { structTreeRoot.set("ParentTree", parentTreeRef); } parentTree = parentTree.clone(); + cache.put(parentTreeRef, parentTree); let nums = parentTree.getRaw("Nums"); let numsRef = null; if (nums instanceof Ref) { @@ -37839,54 +36502,28 @@ class StructTreeRoot { if (!numsRef) { parentTree.set("Nums", nums); } - let kids = structTreeRoot.getRaw("K"); - let kidsRef = null; - if (kids instanceof Ref) { - kidsRef = kids; - kids = xref.fetch(kidsRef); - } else { - kidsRef = xref.getNewTemporaryRef(); - structTreeRoot.set("K", kidsRef); - } - kids = Array.isArray(kids) ? kids.slice() : [kids]; - const buffer = []; const newNextkey = await StructTreeRoot.#writeKids({ newAnnotationsByPage, structTreeRootRef, - kids, + kids: null, nums, xref, pdfManager, - newRefs, - buffer + cache }); structTreeRoot.set("ParentTreeNextKey", newNextkey); - buffer.length = 0; - await writeObject(kidsRef, kids, buffer, xref); - newRefs.push({ - ref: kidsRef, - data: buffer.join("") - }); if (numsRef) { + cache.put(numsRef, nums); + } + const buffer = []; + for (const [ref, obj] of cache.items()) { buffer.length = 0; - await writeObject(numsRef, nums, buffer, xref); + await writeObject(ref, obj, buffer, xref); newRefs.push({ - ref: numsRef, + ref, data: buffer.join("") }); } - buffer.length = 0; - await writeObject(parentTreeRef, parentTree, buffer, xref); - newRefs.push({ - ref: parentTreeRef, - data: buffer.join("") - }); - buffer.length = 0; - await writeObject(structTreeRootRef, structTreeRoot, buffer, xref); - newRefs.push({ - ref: structTreeRootRef, - data: buffer.join("") - }); } static async #writeKids({ newAnnotationsByPage, @@ -37895,8 +36532,7 @@ class StructTreeRoot { nums, xref, pdfManager, - newRefs, - buffer + cache }) { const objr = Name.get("OBJR"); let nextKey = -Infinity; @@ -37941,19 +36577,15 @@ class StructTreeRoot { if (actualText) { tagDict.set("ActualText", actualText); } - if (structTreeParent) { - await this.#updateParentTag({ - structTreeParent, - tagDict, - newTagRef: tagRef, - fallbackRef: structTreeRootRef, - xref, - newRefs, - buffer - }); - } else { - tagDict.set("P", structTreeRootRef); - } + await this.#updateParentTag({ + structTreeParent, + tagDict, + newTagRef: tagRef, + structTreeRootRef, + fallbackKids: kids, + xref, + cache + }); const objDict = new Dict(xref); tagDict.set("K", objDict); objDict.set("Type", objr); @@ -37961,14 +36593,8 @@ class StructTreeRoot { objDict.set("Pg", pageRef); } objDict.set("Obj", ref); - buffer.length = 0; - await writeObject(tagRef, tagDict, buffer, xref); - newRefs.push({ - ref: tagRef, - data: buffer.join("") - }); + cache.put(tagRef, tagDict); nums.push(parentTreeId, tagRef); - kids.push(tagRef); } } return nextKey + 1; @@ -37979,11 +36605,16 @@ class StructTreeRoot { pageDict, numberTree }) { - const idToElement = new Map(); + const idToElements = new Map(); for (const element of elements) { if (element.structTreeParentId) { const id = parseInt(element.structTreeParentId.split("_mc")[1], 10); - idToElement.set(id, element); + let elems = idToElements.get(id); + if (!elems) { + elems = []; + idToElements.set(id, elems); + } + elems.push(element); } } const id = pageDict.get("StructParents"); @@ -37992,15 +36623,18 @@ class StructTreeRoot { } const parentArray = numberTree.get(id); const updateElement = (kid, pageKid, kidRef) => { - const element = idToElement.get(kid); - if (element) { + const elems = idToElements.get(kid); + if (elems) { const parentRef = pageKid.getRaw("P"); const parentDict = xref.fetchIfRef(parentRef); if (parentRef instanceof Ref && parentDict instanceof Dict) { - element.structTreeParent = { + const params = { ref: kidRef, dict: pageKid }; + for (const element of elems) { + element.structTreeParent = params; + } } return true; } @@ -38024,67 +36658,60 @@ class StructTreeRoot { if (Number.isInteger(kid) && updateElement(kid, pageKid, kidRef)) { break; } + if (!(kid instanceof Dict)) { + continue; + } + if (!isName(kid.get("Type"), "MCR")) { + break; + } + const mcid = kid.get("MCID"); + if (Number.isInteger(mcid) && updateElement(mcid, pageKid, kidRef)) { + break; + } } } } static async #updateParentTag({ - structTreeParent: { - ref, - dict - }, + structTreeParent, tagDict, newTagRef, - fallbackRef, + structTreeRootRef, + fallbackKids, xref, - newRefs, - buffer + cache }) { - const parentRef = dict.getRaw("P"); - let parentDict = xref.fetchIfRef(parentRef); - tagDict.set("P", parentRef); - let saveParentDict = false; - let parentKids; - let parentKidsRef = parentDict.getRaw("K"); - if (!(parentKidsRef instanceof Ref)) { - parentKids = parentKidsRef; - parentKidsRef = xref.getNewTemporaryRef(); - parentDict = parentDict.clone(); - parentDict.set("K", parentKidsRef); - saveParentDict = true; + let ref = null; + let parentRef; + if (structTreeParent) { + ({ + ref + } = structTreeParent); + parentRef = structTreeParent.dict.getRaw("P") || structTreeRootRef; } else { - parentKids = xref.fetch(parentKidsRef); - } - if (Array.isArray(parentKids)) { - const index = parentKids.indexOf(ref); - if (index >= 0) { - parentKids = parentKids.slice(); - parentKids.splice(index + 1, 0, newTagRef); - } else { - warn("Cannot update the struct tree: parent kid not found."); - tagDict.set("P", fallbackRef); - return; - } - } else if (parentKids instanceof Dict) { - parentKids = [parentKidsRef, newTagRef]; - parentKidsRef = xref.getNewTemporaryRef(); - parentDict.set("K", parentKidsRef); - saveParentDict = true; + parentRef = structTreeRootRef; } - buffer.length = 0; - await writeObject(parentKidsRef, parentKids, buffer, xref); - newRefs.push({ - ref: parentKidsRef, - data: buffer.join("") - }); - if (!saveParentDict) { + tagDict.set("P", parentRef); + const parentDict = xref.fetchIfRef(parentRef); + if (!parentDict) { + fallbackKids.push(newTagRef); return; } - buffer.length = 0; - await writeObject(parentRef, parentDict, buffer, xref); - newRefs.push({ - ref: parentRef, - data: buffer.join("") - }); + let cachedParentDict = cache.get(parentRef); + if (!cachedParentDict) { + cachedParentDict = parentDict.clone(); + cache.put(parentRef, cachedParentDict); + } + const parentKidsRaw = cachedParentDict.getRaw("K"); + let cachedParentKids = parentKidsRaw instanceof Ref ? cache.get(parentKidsRaw) : null; + if (!cachedParentKids) { + cachedParentKids = xref.fetchIfRef(parentKidsRaw); + cachedParentKids = Array.isArray(cachedParentKids) ? cachedParentKids.slice() : [parentKidsRaw]; + const parentKidsRef = xref.getNewTemporaryRef(); + cachedParentDict.set("K", parentKidsRef); + cache.put(parentKidsRef, cachedParentKids); + } + const index = cachedParentKids.indexOf(ref); + cachedParentKids.splice(index >= 0 ? index + 1 : cachedParentKids.length, 0, newTagRef); } } class StructElementNode { @@ -38365,11 +36992,56 @@ class StructTreePage { -function fetchDestination(dest) { +function isValidExplicitDest(dest) { + if (!Array.isArray(dest) || dest.length < 2) { + return false; + } + const [page, zoom, ...args] = dest; + if (!(page instanceof Ref) && !Number.isInteger(page)) { + return false; + } + if (!(zoom instanceof Name)) { + return false; + } + let allowNull = true; + switch (zoom.name) { + case "XYZ": + if (args.length !== 3) { + return false; + } + break; + case "Fit": + case "FitB": + return args.length === 0; + case "FitH": + case "FitBH": + case "FitV": + case "FitBV": + if (args.length !== 1) { + return false; + } + break; + case "FitR": + if (args.length !== 4) { + return false; + } + allowNull = false; + break; + default: + return false; + } + for (const arg of args) { + if (!(typeof arg === "number" || allowNull && arg === null)) { + return false; + } + } + return true; +} +function fetchDest(dest) { if (dest instanceof Dict) { dest = dest.get("D"); } - return Array.isArray(dest) ? dest : null; + return isValidExplicitDest(dest) ? dest : null; } function fetchRemoteDest(action) { let dest = action.get("D"); @@ -38379,7 +37051,7 @@ function fetchRemoteDest(action) { } if (typeof dest === "string") { return stringToPDFString(dest); - } else if (Array.isArray(dest)) { + } else if (isValidExplicitDest(dest)) { return JSON.stringify(dest); } } @@ -38864,14 +37536,14 @@ class Catalog { dests = Object.create(null); if (obj instanceof NameTree) { for (const [key, value] of obj.getAll()) { - const dest = fetchDestination(value); + const dest = fetchDest(value); if (dest) { dests[stringToPDFString(key)] = dest; } } } else if (obj instanceof Dict) { obj.forEach(function (key, value) { - const dest = fetchDestination(value); + const dest = fetchDest(value); if (dest) { dests[key] = dest; } @@ -38882,7 +37554,7 @@ class Catalog { getDestination(id) { const obj = this._readDests(); if (obj instanceof NameTree) { - const dest = fetchDestination(obj.get(id)); + const dest = fetchDest(obj.get(id)); if (dest) { return dest; } @@ -38892,7 +37564,7 @@ class Catalog { return allDest; } } else if (obj instanceof Dict) { - const dest = fetchDestination(obj.get(id)); + const dest = fetchDest(obj.get(id)); if (dest) { return dest; } @@ -39729,7 +38401,7 @@ class Catalog { } if (typeof dest === "string") { resultObj.dest = stringToPDFString(dest); - } else if (Array.isArray(dest)) { + } else if (isValidExplicitDest(dest)) { resultObj.dest = dest; } } @@ -48575,7 +47247,7 @@ class Trace extends XFAObject { this.area = new XFAObjectArray(); } } -class config_Transform extends XFAObject { +class Transform extends XFAObject { constructor(attributes) { super(CONFIG_NS_ID, "transform", true); this.groupParent = null; @@ -49078,7 +47750,7 @@ class ConfigNamespace { return new Trace(attrs); } static transform(attrs) { - return new config_Transform(attrs); + return new Transform(attrs); } static type(attrs) { return new Type(attrs); @@ -51173,9 +49845,21 @@ class Annotation { }); } async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) { - const data = this.data; + const { + hasOwnCanvas, + id, + rect + } = this.data; let appearance = this.appearance; - const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY); + const isUsingOwnCanvas = !!(hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY); + if (isUsingOwnCanvas && (rect[0] === rect[2] || rect[1] === rect[3])) { + this.data.hasOwnCanvas = false; + return { + opList: new OperatorList(), + separateForm: false, + separateCanvas: false + }; + } if (!appearance) { if (!isUsingOwnCanvas) { return { @@ -51191,7 +49875,7 @@ class Annotation { const resources = await this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"], appearance); const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1]; const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0]; - const transform = getTransformMatrix(data.rect, bbox, matrix); + const transform = getTransformMatrix(rect, bbox, matrix); const opList = new OperatorList(); let optionalContent; if (this.oc) { @@ -51200,7 +49884,7 @@ class Annotation { if (optionalContent !== undefined) { opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]); } - opList.addOp(OPS.beginAnnotation, [data.id, data.rect, transform, matrix, isUsingOwnCanvas]); + opList.addOp(OPS.beginAnnotation, [id, rect, transform, matrix, isUsingOwnCanvas]); await evaluator.getOperatorList({ stream: appearance, task, @@ -54827,7 +53511,7 @@ class Page { continue; } if (annotation.deleted) { - deletedAnnotations.put(ref); + deletedAnnotations.put(ref, ref); continue; } existingAnnotations?.put(ref); @@ -54852,7 +53536,7 @@ class Page { systemFontCache: this.systemFontCache, options: this.evaluatorOptions }); - const deletedAnnotations = new RefSet(); + const deletedAnnotations = new RefSetCache(); const existingAnnotations = new RefSet(); this.#replaceIdByRef(annotations, deletedAnnotations, existingAnnotations); const pageDict = this.pageDict; @@ -54877,6 +53561,12 @@ class Page { ref: this.ref, data: buffer.join("") }, ...newData.annotations); + for (const deletedRef of deletedAnnotations) { + objects.push({ + ref: deletedRef, + data: null + }); + } return objects; } save(handler, task, annotationStorage) { @@ -56749,7 +55439,7 @@ class WorkerMessageHandler { docId, apiVersion } = docParams; - const workerVersion = "4.1.379"; + const workerVersion = "4.3.8"; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); } @@ -56966,6 +55656,7 @@ class WorkerMessageHandler { return { rotate, ref, + refStr: ref?.toString() ?? null, userUnit, view }; @@ -57311,8 +56002,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" && ;// CONCATENATED MODULE: ./src/pdf.worker.js -const pdfjsVersion = "4.1.379"; -const pdfjsBuild = "017e49244"; +const pdfjsVersion = "4.3.8"; +const pdfjsBuild = "c419c8333"; var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler; export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler }; diff --git a/toolkit/components/pdfjs/content/web/images/toolbarButton-editorStamp.svg b/toolkit/components/pdfjs/content/web/images/toolbarButton-editorStamp.svg index f0469b1b1a..a1fef4922d 100644 --- a/toolkit/components/pdfjs/content/web/images/toolbarButton-editorStamp.svg +++ b/toolkit/components/pdfjs/content/web/images/toolbarButton-editorStamp.svg @@ -1,7 +1,7 @@ - + diff --git a/toolkit/components/pdfjs/content/web/viewer-geckoview.css b/toolkit/components/pdfjs/content/web/viewer-geckoview.css index c336b4f7fc..4228a2e45b 100644 --- a/toolkit/components/pdfjs/content/web/viewer-geckoview.css +++ b/toolkit/components/pdfjs/content/web/viewer-geckoview.css @@ -179,11 +179,22 @@ } } - canvas{ + .annotationContent{ position:absolute; width:100%; height:100%; pointer-events:none; + + &.freetext{ + background:transparent; + border:none; + inset:0; + overflow:visible; + white-space:nowrap; + font:10px sans-serif; + line-height:1.35; + user-select:none; + } } section{ @@ -192,6 +203,12 @@ pointer-events:auto; box-sizing:border-box; transform-origin:0 0; + + &:has(div.annotationContent){ + canvas.annotationContent{ + display:none; + } + } } :is(.linkAnnotation, .buttonWidgetAnnotation.pushButton) > a{ diff --git a/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs b/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs index feda69146e..f78da4b528 100644 --- a/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs +++ b/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs @@ -808,44 +808,8 @@ const LinkTarget = { PARENT: 3, TOP: 4 }; -function addLinkAttributes(link, { - url, - target, - rel, - enabled = true -} = {}) { - if (!url || typeof url !== "string") { - throw new Error('A valid "url" parameter must provided.'); - } - if (enabled) { - link.href = link.title = url; - } else { - link.href = ""; - link.title = `Disabled: ${url}`; - link.onclick = () => false; - } - let targetStr = ""; - switch (target) { - case LinkTarget.NONE: - break; - case LinkTarget.SELF: - targetStr = "_self"; - break; - case LinkTarget.BLANK: - targetStr = "_blank"; - break; - case LinkTarget.PARENT: - targetStr = "_parent"; - break; - case LinkTarget.TOP: - targetStr = "_top"; - break; - } - link.target = targetStr; - link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; -} class PDFLinkService { - #pagesRefCache = new Map(); + externalLinkEnabled = true; constructor({ eventBus, externalLinkTarget = null, @@ -855,7 +819,6 @@ class PDFLinkService { this.eventBus = eventBus; this.externalLinkTarget = externalLinkTarget; this.externalLinkRel = externalLinkRel; - this.externalLinkEnabled = true; this._ignoreDestinationZoom = ignoreDestinationZoom; this.baseUrl = null; this.pdfDocument = null; @@ -865,7 +828,6 @@ class PDFLinkService { setDocument(pdfDocument, baseUrl = null) { this.baseUrl = baseUrl; this.pdfDocument = pdfDocument; - this.#pagesRefCache.clear(); } setViewer(pdfViewer) { this.pdfViewer = pdfViewer; @@ -877,42 +839,56 @@ class PDFLinkService { return this.pdfDocument ? this.pdfDocument.numPages : 0; } get page() { - return this.pdfViewer.currentPageNumber; + return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1; } set page(value) { - this.pdfViewer.currentPageNumber = value; + if (this.pdfDocument) { + this.pdfViewer.currentPageNumber = value; + } } get rotation() { - return this.pdfViewer.pagesRotation; + return this.pdfDocument ? this.pdfViewer.pagesRotation : 0; } set rotation(value) { - this.pdfViewer.pagesRotation = value; + if (this.pdfDocument) { + this.pdfViewer.pagesRotation = value; + } } get isInPresentationMode() { - return this.pdfViewer.isInPresentationMode; + return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false; } - #goToDestinationHelper(rawDest, namedDest = null, explicitDest) { - const destRef = explicitDest[0]; - let pageNumber; - if (typeof destRef === "object" && destRef !== null) { - pageNumber = this._cachedPageNumber(destRef); + async goToDestination(dest) { + if (!this.pdfDocument) { + return; + } + let namedDest, explicitDest, pageNumber; + if (typeof dest === "string") { + namedDest = dest; + explicitDest = await this.pdfDocument.getDestination(dest); + } else { + namedDest = null; + explicitDest = await dest; + } + if (!Array.isArray(explicitDest)) { + console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`); + return; + } + const [destRef] = explicitDest; + if (destRef && typeof destRef === "object") { + pageNumber = this.pdfDocument.cachedPageNumber(destRef); if (!pageNumber) { - this.pdfDocument.getPageIndex(destRef).then(pageIndex => { - this.cachePageRef(pageIndex + 1, destRef); - this.#goToDestinationHelper(rawDest, namedDest, explicitDest); - }).catch(() => { - console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`); - }); - return; + try { + pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1; + } catch { + console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`); + return; + } } } else if (Number.isInteger(destRef)) { pageNumber = destRef + 1; - } else { - console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`); - return; } if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { - console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`); + console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`); return; } if (this.pdfHistory) { @@ -929,24 +905,6 @@ class PDFLinkService { ignoreDestinationZoom: this._ignoreDestinationZoom }); } - async goToDestination(dest) { - if (!this.pdfDocument) { - return; - } - let namedDest, explicitDest; - if (typeof dest === "string") { - namedDest = dest; - explicitDest = await this.pdfDocument.getDestination(dest); - } else { - namedDest = null; - explicitDest = await dest; - } - if (!Array.isArray(explicitDest)) { - console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`); - return; - } - this.#goToDestinationHelper(dest, namedDest, explicitDest); - } goToPage(val) { if (!this.pdfDocument) { return; @@ -965,12 +923,37 @@ class PDFLinkService { }); } addLinkAttributes(link, url, newWindow = false) { - addLinkAttributes(link, { - url, - target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget, - rel: this.externalLinkRel, - enabled: this.externalLinkEnabled - }); + if (!url || typeof url !== "string") { + throw new Error('A valid "url" parameter must provided.'); + } + const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, + rel = this.externalLinkRel; + if (this.externalLinkEnabled) { + link.href = link.title = url; + } else { + link.href = ""; + link.title = `Disabled: ${url}`; + link.onclick = () => false; + } + let targetStr = ""; + switch (target) { + case LinkTarget.NONE: + break; + case LinkTarget.SELF: + targetStr = "_self"; + break; + case LinkTarget.BLANK: + targetStr = "_blank"; + break; + case LinkTarget.PARENT: + targetStr = "_parent"; + break; + case LinkTarget.TOP: + targetStr = "_top"; + break; + } + link.target = targetStr; + link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; } getDestinationHash(dest) { if (typeof dest === "string") { @@ -1064,13 +1047,16 @@ class PDFLinkService { dest = dest.toString(); } } catch {} - if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) { + if (typeof dest === "string" || PDFLinkService.#isValidExplicitDest(dest)) { this.goToDestination(dest); return; } console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`); } executeNamedAction(action) { + if (!this.pdfDocument) { + return; + } switch (action) { case "GoBack": this.pdfHistory?.back(); @@ -1099,64 +1085,48 @@ class PDFLinkService { }); } async executeSetOCGState(action) { - const pdfDocument = this.pdfDocument; - const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; + if (!this.pdfDocument) { + return; + } + const pdfDocument = this.pdfDocument, + optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; if (pdfDocument !== this.pdfDocument) { return; } optionalContentConfig.setOCGState(action); this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig); } - cachePageRef(pageNum, pageRef) { - if (!pageRef) { - return; - } - const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; - this.#pagesRefCache.set(refStr, pageNum); - } - _cachedPageNumber(pageRef) { - if (!pageRef) { - return null; - } - const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; - return this.#pagesRefCache.get(refStr) || null; - } - static #isValidExplicitDestination(dest) { - if (!Array.isArray(dest)) { - return false; - } - const destLength = dest.length; - if (destLength < 2) { + static #isValidExplicitDest(dest) { + if (!Array.isArray(dest) || dest.length < 2) { return false; } - const page = dest[0]; - if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) { + const [page, zoom, ...args] = dest; + if (!(typeof page === "object" && Number.isInteger(page?.num) && Number.isInteger(page?.gen)) && !Number.isInteger(page)) { return false; } - const zoom = dest[1]; - if (!(typeof zoom === "object" && typeof zoom.name === "string")) { + if (!(typeof zoom === "object" && typeof zoom?.name === "string")) { return false; } let allowNull = true; switch (zoom.name) { case "XYZ": - if (destLength !== 5) { + if (args.length !== 3) { return false; } break; case "Fit": case "FitB": - return destLength === 2; + return args.length === 0; case "FitH": case "FitBH": case "FitV": case "FitBV": - if (destLength !== 3) { + if (args.length !== 1) { return false; } break; case "FitR": - if (destLength !== 6) { + if (args.length !== 4) { return false; } allowNull = false; @@ -1164,51 +1134,16 @@ class PDFLinkService { default: return false; } - for (let i = 2; i < destLength; i++) { - const param = dest[i]; - if (!(typeof param === "number" || allowNull && param === null)) { + for (const arg of args) { + if (!(typeof arg === "number" || allowNull && arg === null)) { return false; } } return true; } } -class SimpleLinkService { - constructor() { - this.externalLinkEnabled = true; - } - get pagesCount() { - return 0; - } - get page() { - return 0; - } - set page(value) {} - get rotation() { - return 0; - } - set rotation(value) {} - get isInPresentationMode() { - return false; - } - async goToDestination(dest) {} - goToPage(val) {} - addLinkAttributes(link, url, newWindow = false) { - addLinkAttributes(link, { - url, - enabled: this.externalLinkEnabled - }); - } - getDestinationHash(dest) { - return "#"; - } - getAnchorUrl(hash) { - return "#"; - } - setHash(hash) {} - executeNamedAction(action) {} - executeSetOCGState(action) {} - cachePageRef(pageNum, pageRef) {} +class SimpleLinkService extends PDFLinkService { + setDocument(pdfDocument, baseUrl = null) {} } ;// CONCATENATED MODULE: ./web/pdfjs.js @@ -1277,25 +1212,17 @@ async function waitOnEventOrTimeout({ promise, resolve } = Promise.withResolvers(); + const ac = new AbortController(); function handler(type) { - if (target instanceof EventBus) { - target._off(name, eventHandler); - } else { - target.removeEventListener(name, eventHandler); - } - if (timeout) { - clearTimeout(timeout); - } + ac.abort(); + clearTimeout(timeout); resolve(type); } - const eventHandler = handler.bind(null, WaitOnType.EVENT); - if (target instanceof EventBus) { - target._on(name, eventHandler); - } else { - target.addEventListener(name, eventHandler); - } - const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); - const timeout = setTimeout(timeoutHandler, delay); + const evtMethod = target instanceof EventBus ? "_on" : "addEventListener"; + target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), { + signal: ac.signal + }); + const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay); return promise; } class EventBus { @@ -1303,14 +1230,12 @@ class EventBus { on(eventName, listener, options = null) { this._on(eventName, listener, { external: true, - once: options?.once + once: options?.once, + signal: options?.signal }); } off(eventName, listener, options = null) { - this._off(eventName, listener, { - external: true, - once: options?.once - }); + this._off(eventName, listener); } dispatch(eventName, data) { const eventListeners = this.#listeners[eventName]; @@ -1340,11 +1265,25 @@ class EventBus { } } _on(eventName, listener, options = null) { + let rmAbort = null; + if (options?.signal instanceof AbortSignal) { + const { + signal + } = options; + if (signal.aborted) { + console.error("Cannot use an `aborted` signal."); + return; + } + const onAbort = () => this._off(eventName, listener); + rmAbort = () => signal.removeEventListener("abort", onAbort); + signal.addEventListener("abort", onAbort); + } const eventListeners = this.#listeners[eventName] ||= []; eventListeners.push({ listener, external: options?.external === true, - once: options?.once === true + once: options?.once === true, + rmAbort }); } _off(eventName, listener, options = null) { @@ -1353,7 +1292,9 @@ class EventBus { return; } for (let i = 0, ii = eventListeners.length; i < ii; i++) { - if (eventListeners[i].listener === listener) { + const evt = eventListeners[i]; + if (evt.listener === listener) { + evt.rmAbort?.(); eventListeners.splice(i, 1); return; } @@ -3050,6 +2991,7 @@ function getCurrentHash() { return document.location.hash; } class PDFHistory { + #eventAbortController = null; constructor({ linkService, eventBus @@ -3059,7 +3001,6 @@ class PDFHistory { this._initialized = false; this._fingerprint = ""; this.reset(); - this._boundEvents = null; this.eventBus._on("pagesinit", () => { this._isPagesLoaded = false; this.eventBus._on("pagesloaded", evt => { @@ -3085,7 +3026,7 @@ class PDFHistory { this._fingerprint = fingerprint; this._updateUrl = updateUrl === true; this._initialized = true; - this._bindEvents(); + this.#bindEvents(); const state = window.history.state; this._popStateInProgress = false; this._blockHashChange = 0; @@ -3094,17 +3035,17 @@ class PDFHistory { this._uid = this._maxUid = 0; this._destination = null; this._position = null; - if (!this._isValidState(state, true) || resetHistory) { + if (!this.#isValidState(state, true) || resetHistory) { const { hash, page, rotation - } = this._parseCurrentHash(true); + } = this.#parseCurrentHash(true); if (!hash || reInitialized || resetHistory) { - this._pushOrReplaceState(null, true); + this.#pushOrReplaceState(null, true); return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ hash, page, rotation @@ -3112,7 +3053,7 @@ class PDFHistory { return; } const destination = state.destination; - this._updateInternalState(destination, state.uid, true); + this.#updateInternalState(destination, state.uid, true); if (destination.rotation !== undefined) { this._initialRotation = destination.rotation; } @@ -3127,9 +3068,9 @@ class PDFHistory { } reset() { if (this._initialized) { - this._pageHide(); + this.#pageHide(); this._initialized = false; - this._unbindEvents(); + this.#unbindEvents(); } if (this._updateViewareaTimeout) { clearTimeout(this._updateViewareaTimeout); @@ -3152,7 +3093,7 @@ class PDFHistory { } else if (!Array.isArray(explicitDest)) { console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`); return; - } else if (!this._isValidPage(pageNumber)) { + } else if (!this.#isValidPage(pageNumber)) { if (pageNumber !== null || this._destination) { console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`); return; @@ -3172,7 +3113,7 @@ class PDFHistory { if (this._popStateInProgress && !forceReplace) { return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ dest: explicitDest, hash, page: pageNumber, @@ -3189,7 +3130,7 @@ class PDFHistory { if (!this._initialized) { return; } - if (!this._isValidPage(pageNumber)) { + if (!this.#isValidPage(pageNumber)) { console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`); return; } @@ -3199,7 +3140,7 @@ class PDFHistory { if (this._popStateInProgress) { return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ dest: null, hash: `page=${pageNumber}`, page: pageNumber, @@ -3216,14 +3157,14 @@ class PDFHistory { if (!this._initialized || this._popStateInProgress) { return; } - this._tryPushCurrentPosition(); + this.#tryPushCurrentPosition(); } back() { if (!this._initialized || this._popStateInProgress) { return; } const state = window.history.state; - if (this._isValidState(state) && state.uid > 0) { + if (this.#isValidState(state) && state.uid > 0) { window.history.back(); } } @@ -3232,7 +3173,7 @@ class PDFHistory { return; } const state = window.history.state; - if (this._isValidState(state) && state.uid < this._maxUid) { + if (this.#isValidState(state) && state.uid < this._maxUid) { window.history.forward(); } } @@ -3245,14 +3186,14 @@ class PDFHistory { get initialRotation() { return this._initialized ? this._initialRotation : null; } - _pushOrReplaceState(destination, forceReplace = false) { + #pushOrReplaceState(destination, forceReplace = false) { const shouldReplace = forceReplace || !this._destination; const newState = { fingerprint: this._fingerprint, uid: shouldReplace ? this._uid : this._uid + 1, destination }; - this._updateInternalState(destination, newState.uid); + this.#updateInternalState(destination, newState.uid); let newUrl; if (this._updateUrl && destination?.hash) { const baseUrl = document.location.href.split("#", 1)[0]; @@ -3266,7 +3207,7 @@ class PDFHistory { window.history.pushState(newState, "", newUrl); } } - _tryPushCurrentPosition(temporary = false) { + #tryPushCurrentPosition(temporary = false) { if (!this._position) { return; } @@ -3276,11 +3217,11 @@ class PDFHistory { position.temporary = true; } if (!this._destination) { - this._pushOrReplaceState(position); + this.#pushOrReplaceState(position); return; } if (this._destination.temporary) { - this._pushOrReplaceState(position, true); + this.#pushOrReplaceState(position, true); return; } if (this._destination.hash === position.hash) { @@ -3296,12 +3237,12 @@ class PDFHistory { } forceReplace = true; } - this._pushOrReplaceState(position, forceReplace); + this.#pushOrReplaceState(position, forceReplace); } - _isValidPage(val) { + #isValidPage(val) { return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount; } - _isValidState(state, checkReload = false) { + #isValidState(state, checkReload = false) { if (!state) { return false; } @@ -3326,7 +3267,7 @@ class PDFHistory { } return true; } - _updateInternalState(destination, uid, removeTemporary = false) { + #updateInternalState(destination, uid, removeTemporary = false) { if (this._updateViewareaTimeout) { clearTimeout(this._updateViewareaTimeout); this._updateViewareaTimeout = null; @@ -3339,12 +3280,12 @@ class PDFHistory { this._maxUid = Math.max(this._maxUid, uid); this._numPositionUpdates = 0; } - _parseCurrentHash(checkNameddest = false) { + #parseCurrentHash(checkNameddest = false) { const hash = unescape(getCurrentHash()).substring(1); const params = parseQueryString(hash); const nameddest = params.get("nameddest") || ""; let page = params.get("page") | 0; - if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) { + if (!this.#isValidPage(page) || checkNameddest && nameddest.length > 0) { page = null; } return { @@ -3353,7 +3294,7 @@ class PDFHistory { rotation: this.linkService.rotation }; } - _updateViewarea({ + #updateViewarea({ location }) { if (this._updateViewareaTimeout) { @@ -3375,13 +3316,13 @@ class PDFHistory { if (UPDATE_VIEWAREA_TIMEOUT > 0) { this._updateViewareaTimeout = setTimeout(() => { if (!this._popStateInProgress) { - this._tryPushCurrentPosition(true); + this.#tryPushCurrentPosition(true); } this._updateViewareaTimeout = null; }, UPDATE_VIEWAREA_TIMEOUT); } } - _popState({ + #popState({ state }) { const newHash = getCurrentHash(), @@ -3393,15 +3334,15 @@ class PDFHistory { hash, page, rotation - } = this._parseCurrentHash(); - this._pushOrReplaceState({ + } = this.#parseCurrentHash(); + this.#pushOrReplaceState({ hash, page, rotation }, true); return; } - if (!this._isValidState(state)) { + if (!this.#isValidState(state)) { return; } this._popStateInProgress = true; @@ -3416,7 +3357,7 @@ class PDFHistory { }); } const destination = state.destination; - this._updateInternalState(destination, state.uid, true); + this.#updateInternalState(destination, state.uid, true); if (isValidRotation(destination.rotation)) { this.linkService.rotation = destination.rotation; } @@ -3431,32 +3372,32 @@ class PDFHistory { this._popStateInProgress = false; }); } - _pageHide() { + #pageHide() { if (!this._destination || this._destination.temporary) { - this._tryPushCurrentPosition(); + this.#tryPushCurrentPosition(); } } - _bindEvents() { - if (this._boundEvents) { + #bindEvents() { + if (this.#eventAbortController) { return; } - this._boundEvents = { - updateViewarea: this._updateViewarea.bind(this), - popState: this._popState.bind(this), - pageHide: this._pageHide.bind(this) - }; - this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea); - window.addEventListener("popstate", this._boundEvents.popState); - window.addEventListener("pagehide", this._boundEvents.pageHide); + this.#eventAbortController = new AbortController(); + const { + signal + } = this.#eventAbortController; + this.eventBus._on("updateviewarea", this.#updateViewarea.bind(this), { + signal + }); + window.addEventListener("popstate", this.#popState.bind(this), { + signal + }); + window.addEventListener("pagehide", this.#pageHide.bind(this), { + signal + }); } - _unbindEvents() { - if (!this._boundEvents) { - return; - } - this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea); - window.removeEventListener("popstate", this._boundEvents.popState); - window.removeEventListener("pagehide", this._boundEvents.pageHide); - this._boundEvents = null; + #unbindEvents() { + this.#eventAbortController?.abort(); + this.#eventAbortController = null; } } function isDestHashesEqual(destHash, pushHash) { @@ -3845,6 +3786,7 @@ class PDFScriptingManager { #closeCapability = null; #destroyCapability = null; #docProperties = null; + #eventAbortController = null; #eventBus = null; #externalServices = null; #pdfDocument = null; @@ -3887,15 +3829,24 @@ class PDFScriptingManager { await this.#destroyScripting(); return; } - this._internalEvents.set("updatefromsandbox", event => { + const eventBus = this.#eventBus; + this.#eventAbortController = new AbortController(); + const { + signal + } = this.#eventAbortController; + eventBus._on("updatefromsandbox", event => { if (event?.source === window) { this.#updateFromSandbox(event.detail); } + }, { + signal }); - this._internalEvents.set("dispatcheventinsandbox", event => { + eventBus._on("dispatcheventinsandbox", event => { this.#scripting?.dispatchEventInSandbox(event.detail); + }, { + signal }); - this._internalEvents.set("pagechanging", ({ + eventBus._on("pagechanging", ({ pageNumber, previous }) => { @@ -3904,8 +3855,10 @@ class PDFScriptingManager { } this.#dispatchPageClose(previous); this.#dispatchPageOpen(pageNumber); + }, { + signal }); - this._internalEvents.set("pagerendered", ({ + eventBus._on("pagerendered", ({ pageNumber }) => { if (!this._pageOpenPending.has(pageNumber)) { @@ -3915,18 +3868,19 @@ class PDFScriptingManager { return; } this.#dispatchPageOpen(pageNumber); + }, { + signal }); - this._internalEvents.set("pagesdestroy", async () => { + eventBus._on("pagesdestroy", async () => { await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber); await this.#scripting?.dispatchEventInSandbox({ id: "doc", name: "WillClose" }); this.#closeCapability?.resolve(); + }, { + signal }); - for (const [name, listener] of this._internalEvents) { - this.#eventBus._on(name, listener); - } try { const docProperties = await this.#docProperties(pdfDocument); if (pdfDocument !== this.#pdfDocument) { @@ -3944,7 +3898,7 @@ class PDFScriptingManager { actions: docActions } }); - this.#eventBus.dispatch("sandboxcreated", { + eventBus.dispatch("sandboxcreated", { source: this }); } catch (error) { @@ -4005,9 +3959,6 @@ class PDFScriptingManager { get ready() { return this.#ready; } - get _internalEvents() { - return shadow(this, "_internalEvents", new Map()); - } get _pageOpenPending() { return shadow(this, "_pageOpenPending", new Set()); } @@ -4183,10 +4134,8 @@ class PDFScriptingManager { } catch {} this.#willPrintCapability?.reject(new Error("Scripting destroyed.")); this.#willPrintCapability = null; - for (const [name, listener] of this._internalEvents) { - this.#eventBus._off(name, listener); - } - this._internalEvents.clear(); + this.#eventAbortController?.abort(); + this.#eventAbortController = null; this._pageOpenPending.clear(); this._visitedPages.clear(); this.#scripting = null; @@ -4285,7 +4234,7 @@ class AnnotationEditorLayerBuilder { class AnnotationLayerBuilder { #onAppend = null; - #onPresentationModeChanged = null; + #eventAbortController = null; constructor({ pdfPage, linkService, @@ -4298,6 +4247,7 @@ class AnnotationLayerBuilder { fieldObjectsPromise = null, annotationCanvasMap = null, accessibilityManager = null, + annotationEditorUIManager = null, onAppend = null }) { this.pdfPage = pdfPage; @@ -4311,6 +4261,7 @@ class AnnotationLayerBuilder { this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null); this._annotationCanvasMap = annotationCanvasMap; this._accessibilityManager = accessibilityManager; + this._annotationEditorUIManager = annotationEditorUIManager; this.#onAppend = onAppend; this.annotationLayer = null; this.div = null; @@ -4346,6 +4297,7 @@ class AnnotationLayerBuilder { div, accessibilityManager: this._accessibilityManager, annotationCanvasMap: this._annotationCanvasMap, + annotationEditorUIManager: this._annotationEditorUIManager, page: this.pdfPage, viewport: viewport.clone({ dontFlip: true @@ -4365,19 +4317,19 @@ class AnnotationLayerBuilder { if (this.linkService.isInPresentationMode) { this.#updatePresentationModeState(PresentationModeState.FULLSCREEN); } - if (!this.#onPresentationModeChanged) { - this.#onPresentationModeChanged = evt => { + if (!this.#eventAbortController) { + this.#eventAbortController = new AbortController(); + this._eventBus?._on("presentationmodechanged", evt => { this.#updatePresentationModeState(evt.state); - }; - this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged); + }, { + signal: this.#eventAbortController.signal + }); } } cancel() { this._cancelled = true; - if (this.#onPresentationModeChanged) { - this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged); - this.#onPresentationModeChanged = null; - } + this.#eventAbortController?.abort(); + this.#eventAbortController = null; } hide() { if (!this.div) { @@ -4708,6 +4660,7 @@ class TextAccessibilityManager { ;// CONCATENATED MODULE: ./web/text_highlighter.js class TextHighlighter { + #eventAbortController = null; constructor({ findController, eventBus, @@ -4717,7 +4670,6 @@ class TextHighlighter { this.matches = []; this.eventBus = eventBus; this.pageIdx = pageIndex; - this._onUpdateTextLayerMatches = null; this.textDivs = null; this.textContentItemsStr = null; this.enabled = false; @@ -4734,13 +4686,15 @@ class TextHighlighter { throw new Error("TextHighlighter is already enabled."); } this.enabled = true; - if (!this._onUpdateTextLayerMatches) { - this._onUpdateTextLayerMatches = evt => { + if (!this.#eventAbortController) { + this.#eventAbortController = new AbortController(); + this.eventBus._on("updatetextlayermatches", evt => { if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) { this._updateMatches(); } - }; - this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches); + }, { + signal: this.#eventAbortController.signal + }); } this._updateMatches(); } @@ -4749,10 +4703,8 @@ class TextHighlighter { return; } this.enabled = false; - if (this._onUpdateTextLayerMatches) { - this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches); - this._onUpdateTextLayerMatches = null; - } + this.#eventAbortController?.abort(); + this.#eventAbortController = null; this._updateMatches(true); } _convertMatches(matches, matchesLength) { @@ -5663,6 +5615,7 @@ class PDFPageView { if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) { const { annotationStorage, + annotationEditorUIManager, downloadManager, enableScripting, fieldObjectsPromise, @@ -5682,6 +5635,7 @@ class PDFPageView { fieldObjectsPromise, annotationCanvasMap: this._annotationCanvasMap, accessibilityManager: this._accessibilityManager, + annotationEditorUIManager, onAppend: annotationLayerDiv => { this.#addLayer(annotationLayerDiv, "annotationLayer"); } @@ -5919,7 +5873,7 @@ class PDFViewer { #scaleTimeoutId = null; #textLayerMode = TextLayerMode.ENABLE; constructor(options) { - const viewerVersion = "4.1.379"; + const viewerVersion = "4.3.8"; if (version !== viewerVersion) { throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); } @@ -6349,11 +6303,7 @@ class PDFViewer { }); this._pages.push(pageView); } - const firstPageView = this._pages[0]; - if (firstPageView) { - firstPageView.setPdfPage(firstPdfPage); - this.linkService.cachePageRef(1, firstPdfPage.ref); - } + this._pages[0]?.setPdfPage(firstPdfPage); if (this._scrollMode === ScrollMode.PAGE) { this.#ensurePageViewVisible(); } else if (this._spreadMode !== SpreadMode.NONE) { @@ -6387,7 +6337,6 @@ class PDFViewer { if (!pageView.pdfPage) { pageView.setPdfPage(pdfPage); } - this.linkService.cachePageRef(pageNum, pdfPage.ref); if (--getPagesLeft === 0) { this._pagesCapability.resolve(); } @@ -6894,9 +6843,6 @@ class PDFViewer { if (!pageView.pdfPage) { pageView.setPdfPage(pdfPage); } - if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) { - this.linkService.cachePageRef(pageView.id, pdfPage.ref); - } return pdfPage; } catch (reason) { console.error("Unable to get page for page view", reason); @@ -7508,7 +7454,8 @@ const PDFViewerApplication = { url: "", baseUrl: "", _downloadUrl: "", - _boundEvents: Object.create(null), + _eventBusAbortController: null, + _windowAbortController: null, documentInfo: null, metadata: null, _contentDispositionFilename: null, @@ -7527,8 +7474,6 @@ const PDFViewerApplication = { _nimbusDataPromise: null, _caretBrowsing: null, _isScrolling: false, - _lastScrollTop: 0, - _lastScrollLeft: 0, async initialize(appConfig) { let l10nPromise; l10nPromise = this.externalServices.createL10n(); @@ -7653,7 +7598,6 @@ const PDFViewerApplication = { const container = appConfig.mainContainer, viewer = appConfig.viewerContainer; const annotationEditorMode = AppOptions.get("annotationEditorMode"); - const isOffscreenCanvasSupported = AppOptions.get("isOffscreenCanvasSupported") && FeatureTest.isOffscreenCanvasSupported; const pageColors = AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? { background: AppOptions.get("pageColorsBackground"), foreground: AppOptions.get("pageColorsForeground") @@ -7708,7 +7652,7 @@ const PDFViewerApplication = { } if (appConfig.annotationEditorParams) { if (annotationEditorMode !== AnnotationEditorType.DISABLE) { - if (AppOptions.get("enableStampEditor") && isOffscreenCanvasSupported) { + if (AppOptions.get("enableStampEditor")) { appConfig.toolbar?.editorStampButton?.classList.remove("hidden"); } const editorHighlightButton = appConfig.toolbar?.editorHighlightButton; @@ -8540,65 +8484,160 @@ const PDFViewerApplication = { window.print(); }, bindEvents() { + if (this._eventBusAbortController) { + return; + } + this._eventBusAbortController = new AbortController(); const { eventBus, - _boundEvents + _eventBusAbortController: { + signal + } } = this; - _boundEvents.beforePrint = this.beforePrint.bind(this); - _boundEvents.afterPrint = this.afterPrint.bind(this); - eventBus._on("resize", webViewerResize); - eventBus._on("hashchange", webViewerHashchange); - eventBus._on("beforeprint", _boundEvents.beforePrint); - eventBus._on("afterprint", _boundEvents.afterPrint); - eventBus._on("pagerender", webViewerPageRender); - eventBus._on("pagerendered", webViewerPageRendered); - eventBus._on("updateviewarea", webViewerUpdateViewarea); - eventBus._on("pagechanging", webViewerPageChanging); - eventBus._on("scalechanging", webViewerScaleChanging); - eventBus._on("rotationchanging", webViewerRotationChanging); - eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged); - eventBus._on("pagemode", webViewerPageMode); - eventBus._on("namedaction", webViewerNamedAction); - eventBus._on("presentationmodechanged", webViewerPresentationModeChanged); - eventBus._on("presentationmode", webViewerPresentationMode); - eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode); - eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams); - eventBus._on("print", webViewerPrint); - eventBus._on("download", webViewerDownload); - eventBus._on("firstpage", webViewerFirstPage); - eventBus._on("lastpage", webViewerLastPage); - eventBus._on("nextpage", webViewerNextPage); - eventBus._on("previouspage", webViewerPreviousPage); - eventBus._on("zoomin", webViewerZoomIn); - eventBus._on("zoomout", webViewerZoomOut); - eventBus._on("zoomreset", webViewerZoomReset); - eventBus._on("pagenumberchanged", webViewerPageNumberChanged); - eventBus._on("scalechanged", webViewerScaleChanged); - eventBus._on("rotatecw", webViewerRotateCw); - eventBus._on("rotateccw", webViewerRotateCcw); - eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig); - eventBus._on("switchscrollmode", webViewerSwitchScrollMode); - eventBus._on("scrollmodechanged", webViewerScrollModeChanged); - eventBus._on("switchspreadmode", webViewerSwitchSpreadMode); - eventBus._on("spreadmodechanged", webViewerSpreadModeChanged); - eventBus._on("documentproperties", webViewerDocumentProperties); - eventBus._on("findfromurlhash", webViewerFindFromUrlHash); - eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount); - eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState); + eventBus._on("resize", webViewerResize, { + signal + }); + eventBus._on("hashchange", webViewerHashchange, { + signal + }); + eventBus._on("beforeprint", this.beforePrint.bind(this), { + signal + }); + eventBus._on("afterprint", this.afterPrint.bind(this), { + signal + }); + eventBus._on("pagerender", webViewerPageRender, { + signal + }); + eventBus._on("pagerendered", webViewerPageRendered, { + signal + }); + eventBus._on("updateviewarea", webViewerUpdateViewarea, { + signal + }); + eventBus._on("pagechanging", webViewerPageChanging, { + signal + }); + eventBus._on("scalechanging", webViewerScaleChanging, { + signal + }); + eventBus._on("rotationchanging", webViewerRotationChanging, { + signal + }); + eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged, { + signal + }); + eventBus._on("pagemode", webViewerPageMode, { + signal + }); + eventBus._on("namedaction", webViewerNamedAction, { + signal + }); + eventBus._on("presentationmodechanged", webViewerPresentationModeChanged, { + signal + }); + eventBus._on("presentationmode", webViewerPresentationMode, { + signal + }); + eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode, { + signal + }); + eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams, { + signal + }); + eventBus._on("print", webViewerPrint, { + signal + }); + eventBus._on("download", webViewerDownload, { + signal + }); + eventBus._on("firstpage", webViewerFirstPage, { + signal + }); + eventBus._on("lastpage", webViewerLastPage, { + signal + }); + eventBus._on("nextpage", webViewerNextPage, { + signal + }); + eventBus._on("previouspage", webViewerPreviousPage, { + signal + }); + eventBus._on("zoomin", webViewerZoomIn, { + signal + }); + eventBus._on("zoomout", webViewerZoomOut, { + signal + }); + eventBus._on("zoomreset", webViewerZoomReset, { + signal + }); + eventBus._on("pagenumberchanged", webViewerPageNumberChanged, { + signal + }); + eventBus._on("scalechanged", webViewerScaleChanged, { + signal + }); + eventBus._on("rotatecw", webViewerRotateCw, { + signal + }); + eventBus._on("rotateccw", webViewerRotateCcw, { + signal + }); + eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig, { + signal + }); + eventBus._on("switchscrollmode", webViewerSwitchScrollMode, { + signal + }); + eventBus._on("scrollmodechanged", webViewerScrollModeChanged, { + signal + }); + eventBus._on("switchspreadmode", webViewerSwitchSpreadMode, { + signal + }); + eventBus._on("spreadmodechanged", webViewerSpreadModeChanged, { + signal + }); + eventBus._on("documentproperties", webViewerDocumentProperties, { + signal + }); + eventBus._on("findfromurlhash", webViewerFindFromUrlHash, { + signal + }); + eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount, { + signal + }); + eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState, { + signal + }); if (AppOptions.get("pdfBug")) { - _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug; - eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug); - eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug); + eventBus._on("pagerendered", reportPageStatsPDFBug, { + signal + }); + eventBus._on("pagechanging", reportPageStatsPDFBug, { + signal + }); } - eventBus._on("annotationeditorstateschanged", webViewerAnnotationEditorStatesChanged); - eventBus._on("reporttelemetry", webViewerReportTelemetry); + eventBus._on("annotationeditorstateschanged", webViewerAnnotationEditorStatesChanged, { + signal + }); + eventBus._on("reporttelemetry", webViewerReportTelemetry, { + signal + }); }, bindWindowEvents() { + if (this._windowAbortController) { + return; + } + this._windowAbortController = new AbortController(); const { eventBus, - _boundEvents, appConfig: { mainContainer + }, + _windowAbortController: { + signal } } = this; function addWindowResolutionChange(evt = null) { @@ -8607,135 +8646,117 @@ const PDFViewerApplication = { } const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`); mediaQueryList.addEventListener("change", addWindowResolutionChange, { - once: true + once: true, + signal }); - _boundEvents.removeWindowResolutionChange ||= function () { - mediaQueryList.removeEventListener("change", addWindowResolutionChange); - _boundEvents.removeWindowResolutionChange = null; - }; } addWindowResolutionChange(); - _boundEvents.windowResize = () => { + window.addEventListener("visibilitychange", webViewerVisibilityChange, { + signal + }); + window.addEventListener("wheel", webViewerWheel, { + passive: false, + signal + }); + window.addEventListener("touchstart", webViewerTouchStart, { + passive: false, + signal + }); + window.addEventListener("touchmove", webViewerTouchMove, { + passive: false, + signal + }); + window.addEventListener("touchend", webViewerTouchEnd, { + passive: false, + signal + }); + window.addEventListener("click", webViewerClick, { + signal + }); + window.addEventListener("keydown", webViewerKeyDown, { + signal + }); + window.addEventListener("keyup", webViewerKeyUp, { + signal + }); + window.addEventListener("resize", () => { eventBus.dispatch("resize", { source: window }); - }; - _boundEvents.windowHashChange = () => { + }, { + signal + }); + window.addEventListener("hashchange", () => { eventBus.dispatch("hashchange", { source: window, hash: document.location.hash.substring(1) }); - }; - _boundEvents.windowBeforePrint = () => { + }, { + signal + }); + window.addEventListener("beforeprint", () => { eventBus.dispatch("beforeprint", { source: window }); - }; - _boundEvents.windowAfterPrint = () => { + }, { + signal + }); + window.addEventListener("afterprint", () => { eventBus.dispatch("afterprint", { source: window }); - }; - _boundEvents.windowUpdateFromSandbox = event => { + }, { + signal + }); + window.addEventListener("updatefromsandbox", event => { eventBus.dispatch("updatefromsandbox", { source: window, detail: event.detail }); - }; - window.addEventListener("visibilitychange", webViewerVisibilityChange); - window.addEventListener("wheel", webViewerWheel, { - passive: false - }); - window.addEventListener("touchstart", webViewerTouchStart, { - passive: false - }); - window.addEventListener("touchmove", webViewerTouchMove, { - passive: false + }, { + signal }); - window.addEventListener("touchend", webViewerTouchEnd, { - passive: false - }); - window.addEventListener("click", webViewerClick); - window.addEventListener("keydown", webViewerKeyDown); - window.addEventListener("keyup", webViewerKeyUp); - window.addEventListener("resize", _boundEvents.windowResize); - window.addEventListener("hashchange", _boundEvents.windowHashChange); - window.addEventListener("beforeprint", _boundEvents.windowBeforePrint); - window.addEventListener("afterprint", _boundEvents.windowAfterPrint); - window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); - ({ - scrollTop: this._lastScrollTop, - scrollLeft: this._lastScrollLeft - } = mainContainer); - const scrollend = _boundEvents.mainContainerScrollend = () => { - ({ - scrollTop: this._lastScrollTop, - scrollLeft: this._lastScrollLeft - } = mainContainer); + const scrollend = () => { this._isScrolling = false; mainContainer.addEventListener("scroll", scroll, { - passive: true + passive: true, + signal + }); + mainContainer.removeEventListener("scrollend", scrollend, { + signal + }); + mainContainer.removeEventListener("blur", scrollend, { + signal }); - mainContainer.removeEventListener("scrollend", scrollend); - mainContainer.removeEventListener("blur", scrollend); }; - const scroll = _boundEvents.mainContainerScroll = () => { - if (this._isCtrlKeyDown || this._lastScrollTop === mainContainer.scrollTop && this._lastScrollLeft === mainContainer.scrollLeft) { + const scroll = () => { + if (this._isCtrlKeyDown) { return; } mainContainer.removeEventListener("scroll", scroll, { - passive: true + passive: true, + signal }); this._isScrolling = true; - mainContainer.addEventListener("scrollend", scrollend); - mainContainer.addEventListener("blur", scrollend); + mainContainer.addEventListener("scrollend", scrollend, { + signal + }); + mainContainer.addEventListener("blur", scrollend, { + signal + }); }; mainContainer.addEventListener("scroll", scroll, { - passive: true + passive: true, + signal }); }, unbindEvents() { - throw new Error("Not implemented: unbindEvents"); + this._eventBusAbortController?.abort(); + this._eventBusAbortController = null; }, unbindWindowEvents() { - const { - _boundEvents, - appConfig: { - mainContainer - } - } = this; - window.removeEventListener("visibilitychange", webViewerVisibilityChange); - window.removeEventListener("wheel", webViewerWheel, { - passive: false - }); - window.removeEventListener("touchstart", webViewerTouchStart, { - passive: false - }); - window.removeEventListener("touchmove", webViewerTouchMove, { - passive: false - }); - window.removeEventListener("touchend", webViewerTouchEnd, { - passive: false - }); - window.removeEventListener("click", webViewerClick); - window.removeEventListener("keydown", webViewerKeyDown); - window.removeEventListener("keyup", webViewerKeyUp); - window.removeEventListener("resize", _boundEvents.windowResize); - window.removeEventListener("hashchange", _boundEvents.windowHashChange); - window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint); - window.removeEventListener("afterprint", _boundEvents.windowAfterPrint); - window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); - mainContainer.removeEventListener("scroll", _boundEvents.mainContainerScroll); - mainContainer.removeEventListener("scrollend", _boundEvents.mainContainerScrollend); - mainContainer.removeEventListener("blur", _boundEvents.mainContainerScrollend); - _boundEvents.removeWindowResolutionChange?.(); - _boundEvents.windowResize = null; - _boundEvents.windowHashChange = null; - _boundEvents.windowBeforePrint = null; - _boundEvents.windowAfterPrint = null; - _boundEvents.windowUpdateFromSandbox = null; - _boundEvents.mainContainerScroll = null; - _boundEvents.mainContainerScrollend = null; + this._windowAbortController?.abort(); + this._windowAbortController = null; }, _accumulateTicks(ticks, prop) { if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) { @@ -9536,8 +9557,8 @@ function webViewerReportTelemetry({ -const pdfjsVersion = "4.1.379"; -const pdfjsBuild = "017e49244"; +const pdfjsVersion = "4.3.8"; +const pdfjsBuild = "c419c8333"; const AppConstants = null; window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplicationConstants = AppConstants; diff --git a/toolkit/components/pdfjs/content/web/viewer.css b/toolkit/components/pdfjs/content/web/viewer.css index 063fa1632b..cbdaff2757 100644 --- a/toolkit/components/pdfjs/content/web/viewer.css +++ b/toolkit/components/pdfjs/content/web/viewer.css @@ -179,11 +179,22 @@ } } - canvas{ + .annotationContent{ position:absolute; width:100%; height:100%; pointer-events:none; + + &.freetext{ + background:transparent; + border:none; + inset:0; + overflow:visible; + white-space:nowrap; + font:10px sans-serif; + line-height:1.35; + user-select:none; + } } section{ @@ -192,6 +203,12 @@ pointer-events:auto; box-sizing:border-box; transform-origin:0 0; + + &:has(div.annotationContent){ + canvas.annotationContent{ + display:none; + } + } } :is(.linkAnnotation, .buttonWidgetAnnotation.pushButton) > a{ @@ -985,7 +1002,7 @@ background-color:var(--toggle-dot-background-color-on-pressed); } - &[aria-pressed="true"]:-moz-locale-dir(rtl)::before, + &[aria-pressed="true"]:-moz-locale-dir(rtl)::before, &[aria-pressed="true"]:dir(rtl)::before{ translate:calc(-1 * var(--toggle-dot-transform-x)); } diff --git a/toolkit/components/pdfjs/content/web/viewer.mjs b/toolkit/components/pdfjs/content/web/viewer.mjs index 5202de12c7..12e4919428 100644 --- a/toolkit/components/pdfjs/content/web/viewer.mjs +++ b/toolkit/components/pdfjs/content/web/viewer.mjs @@ -808,44 +808,8 @@ const LinkTarget = { PARENT: 3, TOP: 4 }; -function addLinkAttributes(link, { - url, - target, - rel, - enabled = true -} = {}) { - if (!url || typeof url !== "string") { - throw new Error('A valid "url" parameter must provided.'); - } - if (enabled) { - link.href = link.title = url; - } else { - link.href = ""; - link.title = `Disabled: ${url}`; - link.onclick = () => false; - } - let targetStr = ""; - switch (target) { - case LinkTarget.NONE: - break; - case LinkTarget.SELF: - targetStr = "_self"; - break; - case LinkTarget.BLANK: - targetStr = "_blank"; - break; - case LinkTarget.PARENT: - targetStr = "_parent"; - break; - case LinkTarget.TOP: - targetStr = "_top"; - break; - } - link.target = targetStr; - link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; -} class PDFLinkService { - #pagesRefCache = new Map(); + externalLinkEnabled = true; constructor({ eventBus, externalLinkTarget = null, @@ -855,7 +819,6 @@ class PDFLinkService { this.eventBus = eventBus; this.externalLinkTarget = externalLinkTarget; this.externalLinkRel = externalLinkRel; - this.externalLinkEnabled = true; this._ignoreDestinationZoom = ignoreDestinationZoom; this.baseUrl = null; this.pdfDocument = null; @@ -865,7 +828,6 @@ class PDFLinkService { setDocument(pdfDocument, baseUrl = null) { this.baseUrl = baseUrl; this.pdfDocument = pdfDocument; - this.#pagesRefCache.clear(); } setViewer(pdfViewer) { this.pdfViewer = pdfViewer; @@ -877,42 +839,56 @@ class PDFLinkService { return this.pdfDocument ? this.pdfDocument.numPages : 0; } get page() { - return this.pdfViewer.currentPageNumber; + return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1; } set page(value) { - this.pdfViewer.currentPageNumber = value; + if (this.pdfDocument) { + this.pdfViewer.currentPageNumber = value; + } } get rotation() { - return this.pdfViewer.pagesRotation; + return this.pdfDocument ? this.pdfViewer.pagesRotation : 0; } set rotation(value) { - this.pdfViewer.pagesRotation = value; + if (this.pdfDocument) { + this.pdfViewer.pagesRotation = value; + } } get isInPresentationMode() { - return this.pdfViewer.isInPresentationMode; + return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false; } - #goToDestinationHelper(rawDest, namedDest = null, explicitDest) { - const destRef = explicitDest[0]; - let pageNumber; - if (typeof destRef === "object" && destRef !== null) { - pageNumber = this._cachedPageNumber(destRef); + async goToDestination(dest) { + if (!this.pdfDocument) { + return; + } + let namedDest, explicitDest, pageNumber; + if (typeof dest === "string") { + namedDest = dest; + explicitDest = await this.pdfDocument.getDestination(dest); + } else { + namedDest = null; + explicitDest = await dest; + } + if (!Array.isArray(explicitDest)) { + console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`); + return; + } + const [destRef] = explicitDest; + if (destRef && typeof destRef === "object") { + pageNumber = this.pdfDocument.cachedPageNumber(destRef); if (!pageNumber) { - this.pdfDocument.getPageIndex(destRef).then(pageIndex => { - this.cachePageRef(pageIndex + 1, destRef); - this.#goToDestinationHelper(rawDest, namedDest, explicitDest); - }).catch(() => { - console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`); - }); - return; + try { + pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1; + } catch { + console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`); + return; + } } } else if (Number.isInteger(destRef)) { pageNumber = destRef + 1; - } else { - console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`); - return; } if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { - console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`); + console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`); return; } if (this.pdfHistory) { @@ -929,24 +905,6 @@ class PDFLinkService { ignoreDestinationZoom: this._ignoreDestinationZoom }); } - async goToDestination(dest) { - if (!this.pdfDocument) { - return; - } - let namedDest, explicitDest; - if (typeof dest === "string") { - namedDest = dest; - explicitDest = await this.pdfDocument.getDestination(dest); - } else { - namedDest = null; - explicitDest = await dest; - } - if (!Array.isArray(explicitDest)) { - console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`); - return; - } - this.#goToDestinationHelper(dest, namedDest, explicitDest); - } goToPage(val) { if (!this.pdfDocument) { return; @@ -965,12 +923,37 @@ class PDFLinkService { }); } addLinkAttributes(link, url, newWindow = false) { - addLinkAttributes(link, { - url, - target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget, - rel: this.externalLinkRel, - enabled: this.externalLinkEnabled - }); + if (!url || typeof url !== "string") { + throw new Error('A valid "url" parameter must provided.'); + } + const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, + rel = this.externalLinkRel; + if (this.externalLinkEnabled) { + link.href = link.title = url; + } else { + link.href = ""; + link.title = `Disabled: ${url}`; + link.onclick = () => false; + } + let targetStr = ""; + switch (target) { + case LinkTarget.NONE: + break; + case LinkTarget.SELF: + targetStr = "_self"; + break; + case LinkTarget.BLANK: + targetStr = "_blank"; + break; + case LinkTarget.PARENT: + targetStr = "_parent"; + break; + case LinkTarget.TOP: + targetStr = "_top"; + break; + } + link.target = targetStr; + link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; } getDestinationHash(dest) { if (typeof dest === "string") { @@ -1064,13 +1047,16 @@ class PDFLinkService { dest = dest.toString(); } } catch {} - if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) { + if (typeof dest === "string" || PDFLinkService.#isValidExplicitDest(dest)) { this.goToDestination(dest); return; } console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`); } executeNamedAction(action) { + if (!this.pdfDocument) { + return; + } switch (action) { case "GoBack": this.pdfHistory?.back(); @@ -1099,64 +1085,48 @@ class PDFLinkService { }); } async executeSetOCGState(action) { - const pdfDocument = this.pdfDocument; - const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; + if (!this.pdfDocument) { + return; + } + const pdfDocument = this.pdfDocument, + optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; if (pdfDocument !== this.pdfDocument) { return; } optionalContentConfig.setOCGState(action); this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig); } - cachePageRef(pageNum, pageRef) { - if (!pageRef) { - return; - } - const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; - this.#pagesRefCache.set(refStr, pageNum); - } - _cachedPageNumber(pageRef) { - if (!pageRef) { - return null; - } - const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`; - return this.#pagesRefCache.get(refStr) || null; - } - static #isValidExplicitDestination(dest) { - if (!Array.isArray(dest)) { + static #isValidExplicitDest(dest) { + if (!Array.isArray(dest) || dest.length < 2) { return false; } - const destLength = dest.length; - if (destLength < 2) { + const [page, zoom, ...args] = dest; + if (!(typeof page === "object" && Number.isInteger(page?.num) && Number.isInteger(page?.gen)) && !Number.isInteger(page)) { return false; } - const page = dest[0]; - if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) { - return false; - } - const zoom = dest[1]; - if (!(typeof zoom === "object" && typeof zoom.name === "string")) { + if (!(typeof zoom === "object" && typeof zoom?.name === "string")) { return false; } let allowNull = true; switch (zoom.name) { case "XYZ": - if (destLength !== 5) { + if (args.length !== 3) { return false; } break; case "Fit": case "FitB": - return destLength === 2; + return args.length === 0; case "FitH": case "FitBH": case "FitV": case "FitBV": - if (destLength !== 3) { + if (args.length !== 1) { return false; } break; case "FitR": - if (destLength !== 6) { + if (args.length !== 4) { return false; } allowNull = false; @@ -1164,51 +1134,16 @@ class PDFLinkService { default: return false; } - for (let i = 2; i < destLength; i++) { - const param = dest[i]; - if (!(typeof param === "number" || allowNull && param === null)) { + for (const arg of args) { + if (!(typeof arg === "number" || allowNull && arg === null)) { return false; } } return true; } } -class SimpleLinkService { - constructor() { - this.externalLinkEnabled = true; - } - get pagesCount() { - return 0; - } - get page() { - return 0; - } - set page(value) {} - get rotation() { - return 0; - } - set rotation(value) {} - get isInPresentationMode() { - return false; - } - async goToDestination(dest) {} - goToPage(val) {} - addLinkAttributes(link, url, newWindow = false) { - addLinkAttributes(link, { - url, - enabled: this.externalLinkEnabled - }); - } - getDestinationHash(dest) { - return "#"; - } - getAnchorUrl(hash) { - return "#"; - } - setHash(hash) {} - executeNamedAction(action) {} - executeSetOCGState(action) {} - cachePageRef(pageNum, pageRef) {} +class SimpleLinkService extends PDFLinkService { + setDocument(pdfDocument, baseUrl = null) {} } ;// CONCATENATED MODULE: ./web/pdfjs.js @@ -1277,25 +1212,17 @@ async function waitOnEventOrTimeout({ promise, resolve } = Promise.withResolvers(); + const ac = new AbortController(); function handler(type) { - if (target instanceof EventBus) { - target._off(name, eventHandler); - } else { - target.removeEventListener(name, eventHandler); - } - if (timeout) { - clearTimeout(timeout); - } + ac.abort(); + clearTimeout(timeout); resolve(type); } - const eventHandler = handler.bind(null, WaitOnType.EVENT); - if (target instanceof EventBus) { - target._on(name, eventHandler); - } else { - target.addEventListener(name, eventHandler); - } - const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); - const timeout = setTimeout(timeoutHandler, delay); + const evtMethod = target instanceof EventBus ? "_on" : "addEventListener"; + target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), { + signal: ac.signal + }); + const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay); return promise; } class EventBus { @@ -1303,14 +1230,12 @@ class EventBus { on(eventName, listener, options = null) { this._on(eventName, listener, { external: true, - once: options?.once + once: options?.once, + signal: options?.signal }); } off(eventName, listener, options = null) { - this._off(eventName, listener, { - external: true, - once: options?.once - }); + this._off(eventName, listener); } dispatch(eventName, data) { const eventListeners = this.#listeners[eventName]; @@ -1340,11 +1265,25 @@ class EventBus { } } _on(eventName, listener, options = null) { + let rmAbort = null; + if (options?.signal instanceof AbortSignal) { + const { + signal + } = options; + if (signal.aborted) { + console.error("Cannot use an `aborted` signal."); + return; + } + const onAbort = () => this._off(eventName, listener); + rmAbort = () => signal.removeEventListener("abort", onAbort); + signal.addEventListener("abort", onAbort); + } const eventListeners = this.#listeners[eventName] ||= []; eventListeners.push({ listener, external: options?.external === true, - once: options?.once === true + once: options?.once === true, + rmAbort }); } _off(eventName, listener, options = null) { @@ -1353,7 +1292,9 @@ class EventBus { return; } for (let i = 0, ii = eventListeners.length; i < ii; i++) { - if (eventListeners[i].listener === listener) { + const evt = eventListeners[i]; + if (evt.listener === listener) { + evt.rmAbort?.(); eventListeners.splice(i, 1); return; } @@ -2663,8 +2604,12 @@ class PDFAttachmentViewer extends BaseTreeViewer { } _bindLink(element, { content, + description, filename }) { + if (description) { + element.title = description; + } element.onclick = () => { this.downloadManager.openOrDownloadData(content, filename); return false; @@ -2687,12 +2632,14 @@ class PDFAttachmentViewer extends BaseTreeViewer { for (const name in attachments) { const item = attachments[name]; const content = item.content, + description = item.description, filename = getFilenameFromUrl(item.filename, true); const div = document.createElement("div"); div.className = "treeItem"; const element = document.createElement("a"); this._bindLink(element, { content, + description, filename }); element.textContent = this._normalizeTextContent(filename); @@ -2704,7 +2651,8 @@ class PDFAttachmentViewer extends BaseTreeViewer { } #appendAttachment({ filename, - content + content, + description }) { const renderedPromise = this._renderedCapability.promise; renderedPromise.then(() => { @@ -2719,7 +2667,8 @@ class PDFAttachmentViewer extends BaseTreeViewer { } attachments[filename] = { filename, - content + content, + description }; this.render({ attachments, @@ -2881,7 +2830,13 @@ class PDFCursorTools { } #addEventListeners() { this.eventBus._on("switchcursortool", evt => { - this.switchTool(evt.tool); + if (!evt.reset) { + this.switchTool(evt.tool); + } else if (this.#prevActive !== null) { + annotationEditorMode = AnnotationEditorType.NONE; + presentationModeState = PresentationModeState.NORMAL; + enableActive(); + } }); let annotationEditorMode = AnnotationEditorType.NONE, presentationModeState = PresentationModeState.NORMAL; @@ -2897,13 +2852,6 @@ class PDFCursorTools { this.switchTool(prevActive); } }; - this.eventBus._on("secondarytoolbarreset", evt => { - if (this.#prevActive !== null) { - annotationEditorMode = AnnotationEditorType.NONE; - presentationModeState = PresentationModeState.NORMAL; - enableActive(); - } - }); this.eventBus._on("annotationeditormodechanged", ({ mode }) => { @@ -4103,6 +4051,7 @@ function getCurrentHash() { return document.location.hash; } class PDFHistory { + #eventAbortController = null; constructor({ linkService, eventBus @@ -4112,7 +4061,6 @@ class PDFHistory { this._initialized = false; this._fingerprint = ""; this.reset(); - this._boundEvents = null; this.eventBus._on("pagesinit", () => { this._isPagesLoaded = false; this.eventBus._on("pagesloaded", evt => { @@ -4138,7 +4086,7 @@ class PDFHistory { this._fingerprint = fingerprint; this._updateUrl = updateUrl === true; this._initialized = true; - this._bindEvents(); + this.#bindEvents(); const state = window.history.state; this._popStateInProgress = false; this._blockHashChange = 0; @@ -4147,17 +4095,17 @@ class PDFHistory { this._uid = this._maxUid = 0; this._destination = null; this._position = null; - if (!this._isValidState(state, true) || resetHistory) { + if (!this.#isValidState(state, true) || resetHistory) { const { hash, page, rotation - } = this._parseCurrentHash(true); + } = this.#parseCurrentHash(true); if (!hash || reInitialized || resetHistory) { - this._pushOrReplaceState(null, true); + this.#pushOrReplaceState(null, true); return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ hash, page, rotation @@ -4165,7 +4113,7 @@ class PDFHistory { return; } const destination = state.destination; - this._updateInternalState(destination, state.uid, true); + this.#updateInternalState(destination, state.uid, true); if (destination.rotation !== undefined) { this._initialRotation = destination.rotation; } @@ -4180,9 +4128,9 @@ class PDFHistory { } reset() { if (this._initialized) { - this._pageHide(); + this.#pageHide(); this._initialized = false; - this._unbindEvents(); + this.#unbindEvents(); } if (this._updateViewareaTimeout) { clearTimeout(this._updateViewareaTimeout); @@ -4205,7 +4153,7 @@ class PDFHistory { } else if (!Array.isArray(explicitDest)) { console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`); return; - } else if (!this._isValidPage(pageNumber)) { + } else if (!this.#isValidPage(pageNumber)) { if (pageNumber !== null || this._destination) { console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`); return; @@ -4225,7 +4173,7 @@ class PDFHistory { if (this._popStateInProgress && !forceReplace) { return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ dest: explicitDest, hash, page: pageNumber, @@ -4242,7 +4190,7 @@ class PDFHistory { if (!this._initialized) { return; } - if (!this._isValidPage(pageNumber)) { + if (!this.#isValidPage(pageNumber)) { console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`); return; } @@ -4252,7 +4200,7 @@ class PDFHistory { if (this._popStateInProgress) { return; } - this._pushOrReplaceState({ + this.#pushOrReplaceState({ dest: null, hash: `page=${pageNumber}`, page: pageNumber, @@ -4269,14 +4217,14 @@ class PDFHistory { if (!this._initialized || this._popStateInProgress) { return; } - this._tryPushCurrentPosition(); + this.#tryPushCurrentPosition(); } back() { if (!this._initialized || this._popStateInProgress) { return; } const state = window.history.state; - if (this._isValidState(state) && state.uid > 0) { + if (this.#isValidState(state) && state.uid > 0) { window.history.back(); } } @@ -4285,7 +4233,7 @@ class PDFHistory { return; } const state = window.history.state; - if (this._isValidState(state) && state.uid < this._maxUid) { + if (this.#isValidState(state) && state.uid < this._maxUid) { window.history.forward(); } } @@ -4298,14 +4246,14 @@ class PDFHistory { get initialRotation() { return this._initialized ? this._initialRotation : null; } - _pushOrReplaceState(destination, forceReplace = false) { + #pushOrReplaceState(destination, forceReplace = false) { const shouldReplace = forceReplace || !this._destination; const newState = { fingerprint: this._fingerprint, uid: shouldReplace ? this._uid : this._uid + 1, destination }; - this._updateInternalState(destination, newState.uid); + this.#updateInternalState(destination, newState.uid); let newUrl; if (this._updateUrl && destination?.hash) { const baseUrl = document.location.href.split("#", 1)[0]; @@ -4319,7 +4267,7 @@ class PDFHistory { window.history.pushState(newState, "", newUrl); } } - _tryPushCurrentPosition(temporary = false) { + #tryPushCurrentPosition(temporary = false) { if (!this._position) { return; } @@ -4329,11 +4277,11 @@ class PDFHistory { position.temporary = true; } if (!this._destination) { - this._pushOrReplaceState(position); + this.#pushOrReplaceState(position); return; } if (this._destination.temporary) { - this._pushOrReplaceState(position, true); + this.#pushOrReplaceState(position, true); return; } if (this._destination.hash === position.hash) { @@ -4349,12 +4297,12 @@ class PDFHistory { } forceReplace = true; } - this._pushOrReplaceState(position, forceReplace); + this.#pushOrReplaceState(position, forceReplace); } - _isValidPage(val) { + #isValidPage(val) { return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount; } - _isValidState(state, checkReload = false) { + #isValidState(state, checkReload = false) { if (!state) { return false; } @@ -4379,7 +4327,7 @@ class PDFHistory { } return true; } - _updateInternalState(destination, uid, removeTemporary = false) { + #updateInternalState(destination, uid, removeTemporary = false) { if (this._updateViewareaTimeout) { clearTimeout(this._updateViewareaTimeout); this._updateViewareaTimeout = null; @@ -4392,12 +4340,12 @@ class PDFHistory { this._maxUid = Math.max(this._maxUid, uid); this._numPositionUpdates = 0; } - _parseCurrentHash(checkNameddest = false) { + #parseCurrentHash(checkNameddest = false) { const hash = unescape(getCurrentHash()).substring(1); const params = parseQueryString(hash); const nameddest = params.get("nameddest") || ""; let page = params.get("page") | 0; - if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) { + if (!this.#isValidPage(page) || checkNameddest && nameddest.length > 0) { page = null; } return { @@ -4406,7 +4354,7 @@ class PDFHistory { rotation: this.linkService.rotation }; } - _updateViewarea({ + #updateViewarea({ location }) { if (this._updateViewareaTimeout) { @@ -4428,13 +4376,13 @@ class PDFHistory { if (UPDATE_VIEWAREA_TIMEOUT > 0) { this._updateViewareaTimeout = setTimeout(() => { if (!this._popStateInProgress) { - this._tryPushCurrentPosition(true); + this.#tryPushCurrentPosition(true); } this._updateViewareaTimeout = null; }, UPDATE_VIEWAREA_TIMEOUT); } } - _popState({ + #popState({ state }) { const newHash = getCurrentHash(), @@ -4446,15 +4394,15 @@ class PDFHistory { hash, page, rotation - } = this._parseCurrentHash(); - this._pushOrReplaceState({ + } = this.#parseCurrentHash(); + this.#pushOrReplaceState({ hash, page, rotation }, true); return; } - if (!this._isValidState(state)) { + if (!this.#isValidState(state)) { return; } this._popStateInProgress = true; @@ -4469,7 +4417,7 @@ class PDFHistory { }); } const destination = state.destination; - this._updateInternalState(destination, state.uid, true); + this.#updateInternalState(destination, state.uid, true); if (isValidRotation(destination.rotation)) { this.linkService.rotation = destination.rotation; } @@ -4484,32 +4432,32 @@ class PDFHistory { this._popStateInProgress = false; }); } - _pageHide() { + #pageHide() { if (!this._destination || this._destination.temporary) { - this._tryPushCurrentPosition(); + this.#tryPushCurrentPosition(); } } - _bindEvents() { - if (this._boundEvents) { + #bindEvents() { + if (this.#eventAbortController) { return; } - this._boundEvents = { - updateViewarea: this._updateViewarea.bind(this), - popState: this._popState.bind(this), - pageHide: this._pageHide.bind(this) - }; - this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea); - window.addEventListener("popstate", this._boundEvents.popState); - window.addEventListener("pagehide", this._boundEvents.pageHide); + this.#eventAbortController = new AbortController(); + const { + signal + } = this.#eventAbortController; + this.eventBus._on("updateviewarea", this.#updateViewarea.bind(this), { + signal + }); + window.addEventListener("popstate", this.#popState.bind(this), { + signal + }); + window.addEventListener("pagehide", this.#pageHide.bind(this), { + signal + }); } - _unbindEvents() { - if (!this._boundEvents) { - return; - } - this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea); - window.removeEventListener("popstate", this._boundEvents.popState); - window.removeEventListener("pagehide", this._boundEvents.pageHide); - this._boundEvents = null; + #unbindEvents() { + this.#eventAbortController?.abort(); + this.#eventAbortController = null; } } function isDestHashesEqual(destHash, pushHash) { @@ -4955,17 +4903,8 @@ class PDFOutlineViewer extends BaseTreeViewer { } if (Array.isArray(explicitDest)) { const [destRef] = explicitDest; - if (typeof destRef === "object" && destRef !== null) { - pageNumber = this.linkService._cachedPageNumber(destRef); - if (!pageNumber) { - try { - pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1; - if (pdfDocument !== this._pdfDocument) { - return null; - } - this.linkService.cachePageRef(pageNumber, destRef); - } catch {} - } + if (destRef && typeof destRef === "object") { + pageNumber = pdfDocument.cachedPageNumber(destRef); } else if (Number.isInteger(destRef)) { pageNumber = destRef + 1; } @@ -5001,6 +4940,8 @@ const SWIPE_ANGLE_THRESHOLD = Math.PI / 6; class PDFPresentationMode { #state = PresentationModeState.UNKNOWN; #args = null; + #fullscreenChangeAbortController = null; + #windowAbortController = null; constructor({ container, pdfViewer, @@ -5220,55 +5161,62 @@ class PDFPresentationMode { } } #addWindowListeners() { - this.showControlsBind = this.#showControls.bind(this); - this.mouseDownBind = this.#mouseDown.bind(this); - this.mouseWheelBind = this.#mouseWheel.bind(this); - this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this); - this.contextMenuBind = this.#contextMenu.bind(this); - this.touchSwipeBind = this.#touchSwipe.bind(this); - window.addEventListener("mousemove", this.showControlsBind); - window.addEventListener("mousedown", this.mouseDownBind); - window.addEventListener("wheel", this.mouseWheelBind, { - passive: false - }); - window.addEventListener("keydown", this.resetMouseScrollStateBind); - window.addEventListener("contextmenu", this.contextMenuBind); - window.addEventListener("touchstart", this.touchSwipeBind); - window.addEventListener("touchmove", this.touchSwipeBind); - window.addEventListener("touchend", this.touchSwipeBind); + if (this.#windowAbortController) { + return; + } + this.#windowAbortController = new AbortController(); + const { + signal + } = this.#windowAbortController; + const touchSwipeBind = this.#touchSwipe.bind(this); + window.addEventListener("mousemove", this.#showControls.bind(this), { + signal + }); + window.addEventListener("mousedown", this.#mouseDown.bind(this), { + signal + }); + window.addEventListener("wheel", this.#mouseWheel.bind(this), { + passive: false, + signal + }); + window.addEventListener("keydown", this.#resetMouseScrollState.bind(this), { + signal + }); + window.addEventListener("contextmenu", this.#contextMenu.bind(this), { + signal + }); + window.addEventListener("touchstart", touchSwipeBind, { + signal + }); + window.addEventListener("touchmove", touchSwipeBind, { + signal + }); + window.addEventListener("touchend", touchSwipeBind, { + signal + }); } #removeWindowListeners() { - window.removeEventListener("mousemove", this.showControlsBind); - window.removeEventListener("mousedown", this.mouseDownBind); - window.removeEventListener("wheel", this.mouseWheelBind, { - passive: false - }); - window.removeEventListener("keydown", this.resetMouseScrollStateBind); - window.removeEventListener("contextmenu", this.contextMenuBind); - window.removeEventListener("touchstart", this.touchSwipeBind); - window.removeEventListener("touchmove", this.touchSwipeBind); - window.removeEventListener("touchend", this.touchSwipeBind); - delete this.showControlsBind; - delete this.mouseDownBind; - delete this.mouseWheelBind; - delete this.resetMouseScrollStateBind; - delete this.contextMenuBind; - delete this.touchSwipeBind; - } - #fullscreenChange() { - if (document.fullscreenElement) { - this.#enter(); - } else { - this.#exit(); - } + this.#windowAbortController?.abort(); + this.#windowAbortController = null; } #addFullscreenChangeListeners() { - this.fullscreenChangeBind = this.#fullscreenChange.bind(this); - window.addEventListener("fullscreenchange", this.fullscreenChangeBind); + if (this.#fullscreenChangeAbortController) { + return; + } + this.#fullscreenChangeAbortController = new AbortController(); + window.addEventListener("fullscreenchange", () => { + if (document.fullscreenElement) { + this.#enter(); + } else { + this.#exit(); + } + }, { + signal: this.#fullscreenChangeAbortController.signal + }); } #removeFullscreenChangeListeners() { - window.removeEventListener("fullscreenchange", this.fullscreenChangeBind); - delete this.fullscreenChangeBind; + this.#fullscreenChangeAbortController?.abort(); + this.#fullscreenChangeAbortController = null; } } @@ -5610,6 +5558,7 @@ class PDFScriptingManager { #closeCapability = null; #destroyCapability = null; #docProperties = null; + #eventAbortController = null; #eventBus = null; #externalServices = null; #pdfDocument = null; @@ -5652,15 +5601,24 @@ class PDFScriptingManager { await this.#destroyScripting(); return; } - this._internalEvents.set("updatefromsandbox", event => { + const eventBus = this.#eventBus; + this.#eventAbortController = new AbortController(); + const { + signal + } = this.#eventAbortController; + eventBus._on("updatefromsandbox", event => { if (event?.source === window) { this.#updateFromSandbox(event.detail); } + }, { + signal }); - this._internalEvents.set("dispatcheventinsandbox", event => { + eventBus._on("dispatcheventinsandbox", event => { this.#scripting?.dispatchEventInSandbox(event.detail); + }, { + signal }); - this._internalEvents.set("pagechanging", ({ + eventBus._on("pagechanging", ({ pageNumber, previous }) => { @@ -5669,8 +5627,10 @@ class PDFScriptingManager { } this.#dispatchPageClose(previous); this.#dispatchPageOpen(pageNumber); + }, { + signal }); - this._internalEvents.set("pagerendered", ({ + eventBus._on("pagerendered", ({ pageNumber }) => { if (!this._pageOpenPending.has(pageNumber)) { @@ -5680,18 +5640,19 @@ class PDFScriptingManager { return; } this.#dispatchPageOpen(pageNumber); + }, { + signal }); - this._internalEvents.set("pagesdestroy", async () => { + eventBus._on("pagesdestroy", async () => { await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber); await this.#scripting?.dispatchEventInSandbox({ id: "doc", name: "WillClose" }); this.#closeCapability?.resolve(); + }, { + signal }); - for (const [name, listener] of this._internalEvents) { - this.#eventBus._on(name, listener); - } try { const docProperties = await this.#docProperties(pdfDocument); if (pdfDocument !== this.#pdfDocument) { @@ -5709,7 +5670,7 @@ class PDFScriptingManager { actions: docActions } }); - this.#eventBus.dispatch("sandboxcreated", { + eventBus.dispatch("sandboxcreated", { source: this }); } catch (error) { @@ -5770,9 +5731,6 @@ class PDFScriptingManager { get ready() { return this.#ready; } - get _internalEvents() { - return shadow(this, "_internalEvents", new Map()); - } get _pageOpenPending() { return shadow(this, "_pageOpenPending", new Set()); } @@ -5948,10 +5906,8 @@ class PDFScriptingManager { } catch {} this.#willPrintCapability?.reject(new Error("Scripting destroyed.")); this.#willPrintCapability = null; - for (const [name, listener] of this._internalEvents) { - this.#eventBus._off(name, listener); - } - this._internalEvents.clear(); + this.#eventAbortController?.abort(); + this.#eventAbortController = null; this._pageOpenPending.clear(); this._visitedPages.clear(); this.#scripting = null; @@ -6858,7 +6814,7 @@ class AnnotationEditorLayerBuilder { class AnnotationLayerBuilder { #onAppend = null; - #onPresentationModeChanged = null; + #eventAbortController = null; constructor({ pdfPage, linkService, @@ -6871,6 +6827,7 @@ class AnnotationLayerBuilder { fieldObjectsPromise = null, annotationCanvasMap = null, accessibilityManager = null, + annotationEditorUIManager = null, onAppend = null }) { this.pdfPage = pdfPage; @@ -6884,6 +6841,7 @@ class AnnotationLayerBuilder { this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null); this._annotationCanvasMap = annotationCanvasMap; this._accessibilityManager = accessibilityManager; + this._annotationEditorUIManager = annotationEditorUIManager; this.#onAppend = onAppend; this.annotationLayer = null; this.div = null; @@ -6919,6 +6877,7 @@ class AnnotationLayerBuilder { div, accessibilityManager: this._accessibilityManager, annotationCanvasMap: this._annotationCanvasMap, + annotationEditorUIManager: this._annotationEditorUIManager, page: this.pdfPage, viewport: viewport.clone({ dontFlip: true @@ -6938,19 +6897,19 @@ class AnnotationLayerBuilder { if (this.linkService.isInPresentationMode) { this.#updatePresentationModeState(PresentationModeState.FULLSCREEN); } - if (!this.#onPresentationModeChanged) { - this.#onPresentationModeChanged = evt => { + if (!this.#eventAbortController) { + this.#eventAbortController = new AbortController(); + this._eventBus?._on("presentationmodechanged", evt => { this.#updatePresentationModeState(evt.state); - }; - this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged); + }, { + signal: this.#eventAbortController.signal + }); } } cancel() { this._cancelled = true; - if (this.#onPresentationModeChanged) { - this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged); - this.#onPresentationModeChanged = null; - } + this.#eventAbortController?.abort(); + this.#eventAbortController = null; } hide() { if (!this.div) { @@ -7281,6 +7240,7 @@ class TextAccessibilityManager { ;// CONCATENATED MODULE: ./web/text_highlighter.js class TextHighlighter { + #eventAbortController = null; constructor({ findController, eventBus, @@ -7290,7 +7250,6 @@ class TextHighlighter { this.matches = []; this.eventBus = eventBus; this.pageIdx = pageIndex; - this._onUpdateTextLayerMatches = null; this.textDivs = null; this.textContentItemsStr = null; this.enabled = false; @@ -7307,13 +7266,15 @@ class TextHighlighter { throw new Error("TextHighlighter is already enabled."); } this.enabled = true; - if (!this._onUpdateTextLayerMatches) { - this._onUpdateTextLayerMatches = evt => { + if (!this.#eventAbortController) { + this.#eventAbortController = new AbortController(); + this.eventBus._on("updatetextlayermatches", evt => { if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) { this._updateMatches(); } - }; - this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches); + }, { + signal: this.#eventAbortController.signal + }); } this._updateMatches(); } @@ -7322,10 +7283,8 @@ class TextHighlighter { return; } this.enabled = false; - if (this._onUpdateTextLayerMatches) { - this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches); - this._onUpdateTextLayerMatches = null; - } + this.#eventAbortController?.abort(); + this.#eventAbortController = null; this._updateMatches(true); } _convertMatches(matches, matchesLength) { @@ -8236,6 +8195,7 @@ class PDFPageView { if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) { const { annotationStorage, + annotationEditorUIManager, downloadManager, enableScripting, fieldObjectsPromise, @@ -8255,6 +8215,7 @@ class PDFPageView { fieldObjectsPromise, annotationCanvasMap: this._annotationCanvasMap, accessibilityManager: this._accessibilityManager, + annotationEditorUIManager, onAppend: annotationLayerDiv => { this.#addLayer(annotationLayerDiv, "annotationLayer"); } @@ -8492,7 +8453,7 @@ class PDFViewer { #scaleTimeoutId = null; #textLayerMode = TextLayerMode.ENABLE; constructor(options) { - const viewerVersion = "4.1.379"; + const viewerVersion = "4.3.8"; if (version !== viewerVersion) { throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); } @@ -8922,11 +8883,7 @@ class PDFViewer { }); this._pages.push(pageView); } - const firstPageView = this._pages[0]; - if (firstPageView) { - firstPageView.setPdfPage(firstPdfPage); - this.linkService.cachePageRef(1, firstPdfPage.ref); - } + this._pages[0]?.setPdfPage(firstPdfPage); if (this._scrollMode === ScrollMode.PAGE) { this.#ensurePageViewVisible(); } else if (this._spreadMode !== SpreadMode.NONE) { @@ -8960,7 +8917,6 @@ class PDFViewer { if (!pageView.pdfPage) { pageView.setPdfPage(pdfPage); } - this.linkService.cachePageRef(pageNum, pdfPage.ref); if (--getPagesLeft === 0) { this._pagesCapability.resolve(); } @@ -9467,9 +9423,6 @@ class PDFViewer { if (!pageView.pdfPage) { pageView.setPdfPage(pdfPage); } - if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) { - this.linkService.cachePageRef(pageView.id, pdfPage.ref); - } return pdfPage; } catch (reason) { console.error("Unable to get page for page view", reason); @@ -10030,6 +9983,10 @@ class SecondaryToolbar { this.pageNumber = 0; this.pagesCount = 0; this.#updateUIState(); + this.eventBus.dispatch("switchcursortool", { + source: this, + reset: true + }); this.#scrollModeChanged({ mode: ScrollMode.VERTICAL }); @@ -10571,7 +10528,8 @@ const PDFViewerApplication = { url: "", baseUrl: "", _downloadUrl: "", - _boundEvents: Object.create(null), + _eventBusAbortController: null, + _windowAbortController: null, documentInfo: null, metadata: null, _contentDispositionFilename: null, @@ -10590,8 +10548,6 @@ const PDFViewerApplication = { _nimbusDataPromise: null, _caretBrowsing: null, _isScrolling: false, - _lastScrollTop: 0, - _lastScrollLeft: 0, async initialize(appConfig) { let l10nPromise; l10nPromise = this.externalServices.createL10n(); @@ -10715,7 +10671,6 @@ const PDFViewerApplication = { const container = appConfig.mainContainer, viewer = appConfig.viewerContainer; const annotationEditorMode = AppOptions.get("annotationEditorMode"); - const isOffscreenCanvasSupported = AppOptions.get("isOffscreenCanvasSupported") && FeatureTest.isOffscreenCanvasSupported; const pageColors = AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? { background: AppOptions.get("pageColorsBackground"), foreground: AppOptions.get("pageColorsForeground") @@ -10770,7 +10725,7 @@ const PDFViewerApplication = { } if (appConfig.annotationEditorParams) { if (annotationEditorMode !== AnnotationEditorType.DISABLE) { - if (AppOptions.get("enableStampEditor") && isOffscreenCanvasSupported) { + if (AppOptions.get("enableStampEditor")) { appConfig.toolbar?.editorStampButton?.classList.remove("hidden"); } const editorHighlightButton = appConfig.toolbar?.editorHighlightButton; @@ -11635,65 +11590,160 @@ const PDFViewerApplication = { window.print(); }, bindEvents() { + if (this._eventBusAbortController) { + return; + } + this._eventBusAbortController = new AbortController(); const { eventBus, - _boundEvents + _eventBusAbortController: { + signal + } } = this; - _boundEvents.beforePrint = this.beforePrint.bind(this); - _boundEvents.afterPrint = this.afterPrint.bind(this); - eventBus._on("resize", webViewerResize); - eventBus._on("hashchange", webViewerHashchange); - eventBus._on("beforeprint", _boundEvents.beforePrint); - eventBus._on("afterprint", _boundEvents.afterPrint); - eventBus._on("pagerender", webViewerPageRender); - eventBus._on("pagerendered", webViewerPageRendered); - eventBus._on("updateviewarea", webViewerUpdateViewarea); - eventBus._on("pagechanging", webViewerPageChanging); - eventBus._on("scalechanging", webViewerScaleChanging); - eventBus._on("rotationchanging", webViewerRotationChanging); - eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged); - eventBus._on("pagemode", webViewerPageMode); - eventBus._on("namedaction", webViewerNamedAction); - eventBus._on("presentationmodechanged", webViewerPresentationModeChanged); - eventBus._on("presentationmode", webViewerPresentationMode); - eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode); - eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams); - eventBus._on("print", webViewerPrint); - eventBus._on("download", webViewerDownload); - eventBus._on("firstpage", webViewerFirstPage); - eventBus._on("lastpage", webViewerLastPage); - eventBus._on("nextpage", webViewerNextPage); - eventBus._on("previouspage", webViewerPreviousPage); - eventBus._on("zoomin", webViewerZoomIn); - eventBus._on("zoomout", webViewerZoomOut); - eventBus._on("zoomreset", webViewerZoomReset); - eventBus._on("pagenumberchanged", webViewerPageNumberChanged); - eventBus._on("scalechanged", webViewerScaleChanged); - eventBus._on("rotatecw", webViewerRotateCw); - eventBus._on("rotateccw", webViewerRotateCcw); - eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig); - eventBus._on("switchscrollmode", webViewerSwitchScrollMode); - eventBus._on("scrollmodechanged", webViewerScrollModeChanged); - eventBus._on("switchspreadmode", webViewerSwitchSpreadMode); - eventBus._on("spreadmodechanged", webViewerSpreadModeChanged); - eventBus._on("documentproperties", webViewerDocumentProperties); - eventBus._on("findfromurlhash", webViewerFindFromUrlHash); - eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount); - eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState); + eventBus._on("resize", webViewerResize, { + signal + }); + eventBus._on("hashchange", webViewerHashchange, { + signal + }); + eventBus._on("beforeprint", this.beforePrint.bind(this), { + signal + }); + eventBus._on("afterprint", this.afterPrint.bind(this), { + signal + }); + eventBus._on("pagerender", webViewerPageRender, { + signal + }); + eventBus._on("pagerendered", webViewerPageRendered, { + signal + }); + eventBus._on("updateviewarea", webViewerUpdateViewarea, { + signal + }); + eventBus._on("pagechanging", webViewerPageChanging, { + signal + }); + eventBus._on("scalechanging", webViewerScaleChanging, { + signal + }); + eventBus._on("rotationchanging", webViewerRotationChanging, { + signal + }); + eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged, { + signal + }); + eventBus._on("pagemode", webViewerPageMode, { + signal + }); + eventBus._on("namedaction", webViewerNamedAction, { + signal + }); + eventBus._on("presentationmodechanged", webViewerPresentationModeChanged, { + signal + }); + eventBus._on("presentationmode", webViewerPresentationMode, { + signal + }); + eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode, { + signal + }); + eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams, { + signal + }); + eventBus._on("print", webViewerPrint, { + signal + }); + eventBus._on("download", webViewerDownload, { + signal + }); + eventBus._on("firstpage", webViewerFirstPage, { + signal + }); + eventBus._on("lastpage", webViewerLastPage, { + signal + }); + eventBus._on("nextpage", webViewerNextPage, { + signal + }); + eventBus._on("previouspage", webViewerPreviousPage, { + signal + }); + eventBus._on("zoomin", webViewerZoomIn, { + signal + }); + eventBus._on("zoomout", webViewerZoomOut, { + signal + }); + eventBus._on("zoomreset", webViewerZoomReset, { + signal + }); + eventBus._on("pagenumberchanged", webViewerPageNumberChanged, { + signal + }); + eventBus._on("scalechanged", webViewerScaleChanged, { + signal + }); + eventBus._on("rotatecw", webViewerRotateCw, { + signal + }); + eventBus._on("rotateccw", webViewerRotateCcw, { + signal + }); + eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig, { + signal + }); + eventBus._on("switchscrollmode", webViewerSwitchScrollMode, { + signal + }); + eventBus._on("scrollmodechanged", webViewerScrollModeChanged, { + signal + }); + eventBus._on("switchspreadmode", webViewerSwitchSpreadMode, { + signal + }); + eventBus._on("spreadmodechanged", webViewerSpreadModeChanged, { + signal + }); + eventBus._on("documentproperties", webViewerDocumentProperties, { + signal + }); + eventBus._on("findfromurlhash", webViewerFindFromUrlHash, { + signal + }); + eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount, { + signal + }); + eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState, { + signal + }); if (AppOptions.get("pdfBug")) { - _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug; - eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug); - eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug); + eventBus._on("pagerendered", reportPageStatsPDFBug, { + signal + }); + eventBus._on("pagechanging", reportPageStatsPDFBug, { + signal + }); } - eventBus._on("annotationeditorstateschanged", webViewerAnnotationEditorStatesChanged); - eventBus._on("reporttelemetry", webViewerReportTelemetry); + eventBus._on("annotationeditorstateschanged", webViewerAnnotationEditorStatesChanged, { + signal + }); + eventBus._on("reporttelemetry", webViewerReportTelemetry, { + signal + }); }, bindWindowEvents() { + if (this._windowAbortController) { + return; + } + this._windowAbortController = new AbortController(); const { eventBus, - _boundEvents, appConfig: { mainContainer + }, + _windowAbortController: { + signal } } = this; function addWindowResolutionChange(evt = null) { @@ -11702,135 +11752,117 @@ const PDFViewerApplication = { } const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`); mediaQueryList.addEventListener("change", addWindowResolutionChange, { - once: true + once: true, + signal }); - _boundEvents.removeWindowResolutionChange ||= function () { - mediaQueryList.removeEventListener("change", addWindowResolutionChange); - _boundEvents.removeWindowResolutionChange = null; - }; } addWindowResolutionChange(); - _boundEvents.windowResize = () => { + window.addEventListener("visibilitychange", webViewerVisibilityChange, { + signal + }); + window.addEventListener("wheel", webViewerWheel, { + passive: false, + signal + }); + window.addEventListener("touchstart", webViewerTouchStart, { + passive: false, + signal + }); + window.addEventListener("touchmove", webViewerTouchMove, { + passive: false, + signal + }); + window.addEventListener("touchend", webViewerTouchEnd, { + passive: false, + signal + }); + window.addEventListener("click", webViewerClick, { + signal + }); + window.addEventListener("keydown", webViewerKeyDown, { + signal + }); + window.addEventListener("keyup", webViewerKeyUp, { + signal + }); + window.addEventListener("resize", () => { eventBus.dispatch("resize", { source: window }); - }; - _boundEvents.windowHashChange = () => { + }, { + signal + }); + window.addEventListener("hashchange", () => { eventBus.dispatch("hashchange", { source: window, hash: document.location.hash.substring(1) }); - }; - _boundEvents.windowBeforePrint = () => { + }, { + signal + }); + window.addEventListener("beforeprint", () => { eventBus.dispatch("beforeprint", { source: window }); - }; - _boundEvents.windowAfterPrint = () => { + }, { + signal + }); + window.addEventListener("afterprint", () => { eventBus.dispatch("afterprint", { source: window }); - }; - _boundEvents.windowUpdateFromSandbox = event => { + }, { + signal + }); + window.addEventListener("updatefromsandbox", event => { eventBus.dispatch("updatefromsandbox", { source: window, detail: event.detail }); - }; - window.addEventListener("visibilitychange", webViewerVisibilityChange); - window.addEventListener("wheel", webViewerWheel, { - passive: false - }); - window.addEventListener("touchstart", webViewerTouchStart, { - passive: false - }); - window.addEventListener("touchmove", webViewerTouchMove, { - passive: false + }, { + signal }); - window.addEventListener("touchend", webViewerTouchEnd, { - passive: false - }); - window.addEventListener("click", webViewerClick); - window.addEventListener("keydown", webViewerKeyDown); - window.addEventListener("keyup", webViewerKeyUp); - window.addEventListener("resize", _boundEvents.windowResize); - window.addEventListener("hashchange", _boundEvents.windowHashChange); - window.addEventListener("beforeprint", _boundEvents.windowBeforePrint); - window.addEventListener("afterprint", _boundEvents.windowAfterPrint); - window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); - ({ - scrollTop: this._lastScrollTop, - scrollLeft: this._lastScrollLeft - } = mainContainer); - const scrollend = _boundEvents.mainContainerScrollend = () => { - ({ - scrollTop: this._lastScrollTop, - scrollLeft: this._lastScrollLeft - } = mainContainer); + const scrollend = () => { this._isScrolling = false; mainContainer.addEventListener("scroll", scroll, { - passive: true + passive: true, + signal + }); + mainContainer.removeEventListener("scrollend", scrollend, { + signal + }); + mainContainer.removeEventListener("blur", scrollend, { + signal }); - mainContainer.removeEventListener("scrollend", scrollend); - mainContainer.removeEventListener("blur", scrollend); }; - const scroll = _boundEvents.mainContainerScroll = () => { - if (this._isCtrlKeyDown || this._lastScrollTop === mainContainer.scrollTop && this._lastScrollLeft === mainContainer.scrollLeft) { + const scroll = () => { + if (this._isCtrlKeyDown) { return; } mainContainer.removeEventListener("scroll", scroll, { - passive: true + passive: true, + signal }); this._isScrolling = true; - mainContainer.addEventListener("scrollend", scrollend); - mainContainer.addEventListener("blur", scrollend); + mainContainer.addEventListener("scrollend", scrollend, { + signal + }); + mainContainer.addEventListener("blur", scrollend, { + signal + }); }; mainContainer.addEventListener("scroll", scroll, { - passive: true + passive: true, + signal }); }, unbindEvents() { - throw new Error("Not implemented: unbindEvents"); + this._eventBusAbortController?.abort(); + this._eventBusAbortController = null; }, unbindWindowEvents() { - const { - _boundEvents, - appConfig: { - mainContainer - } - } = this; - window.removeEventListener("visibilitychange", webViewerVisibilityChange); - window.removeEventListener("wheel", webViewerWheel, { - passive: false - }); - window.removeEventListener("touchstart", webViewerTouchStart, { - passive: false - }); - window.removeEventListener("touchmove", webViewerTouchMove, { - passive: false - }); - window.removeEventListener("touchend", webViewerTouchEnd, { - passive: false - }); - window.removeEventListener("click", webViewerClick); - window.removeEventListener("keydown", webViewerKeyDown); - window.removeEventListener("keyup", webViewerKeyUp); - window.removeEventListener("resize", _boundEvents.windowResize); - window.removeEventListener("hashchange", _boundEvents.windowHashChange); - window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint); - window.removeEventListener("afterprint", _boundEvents.windowAfterPrint); - window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox); - mainContainer.removeEventListener("scroll", _boundEvents.mainContainerScroll); - mainContainer.removeEventListener("scrollend", _boundEvents.mainContainerScrollend); - mainContainer.removeEventListener("blur", _boundEvents.mainContainerScrollend); - _boundEvents.removeWindowResolutionChange?.(); - _boundEvents.windowResize = null; - _boundEvents.windowHashChange = null; - _boundEvents.windowBeforePrint = null; - _boundEvents.windowAfterPrint = null; - _boundEvents.windowUpdateFromSandbox = null; - _boundEvents.mainContainerScroll = null; - _boundEvents.mainContainerScrollend = null; + this._windowAbortController?.abort(); + this._windowAbortController = null; }, _accumulateTicks(ticks, prop) { if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) { @@ -12631,8 +12663,8 @@ function webViewerReportTelemetry({ -const pdfjsVersion = "4.1.379"; -const pdfjsBuild = "017e49244"; +const pdfjsVersion = "4.3.8"; +const pdfjsBuild = "c419c8333"; const AppConstants = null; window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplicationConstants = AppConstants; diff --git a/toolkit/components/pdfjs/moz.yaml b/toolkit/components/pdfjs/moz.yaml index 0938b8d987..eb83950671 100644 --- a/toolkit/components/pdfjs/moz.yaml +++ b/toolkit/components/pdfjs/moz.yaml @@ -20,8 +20,8 @@ origin: # Human-readable identifier for this version/release # Generally "version NNN", "tag SSS", "bookmark SSS" - release: a208d6bca72f8cb700f7bb506ea1bc3e76cbaec0 (2024-04-09T07:48:17Z). - revision: a208d6bca72f8cb700f7bb506ea1bc3e76cbaec0 + release: c419c8333b1b509fe90242135d9594aa026a8724 (2024-05-02T12:41:02Z). + revision: c419c8333b1b509fe90242135d9594aa026a8724 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/ diff --git a/toolkit/components/pdfjs/update.sh b/toolkit/components/pdfjs/update.sh index 3673f68784..50bde30eb6 100755 --- a/toolkit/components/pdfjs/update.sh +++ b/toolkit/components/pdfjs/update.sh @@ -44,6 +44,9 @@ rsync -a -v --delete "$ROOT/build/mozcentral/browser/extensions/pdfjs/content/we ls -R "$ROOT/build/mozcentral/browser/" cp "$ROOT"/build/mozcentral/browser/locales/en-US/pdfviewer/*.ftl "$GECKO_PATH/toolkit/locales/en-US/toolkit/pdfviewer/" || true +# Update the revision in the toolchains.yml file for the Talos tests. +sed -i -z "s/\(mozilla-pdf\.js.*revision: \)[0-9a-f]*/\1$1/g" "$GECKO_PATH/taskcluster/kinds/fetch/toolchains.yml" + if [ -v PDFJS_TMPDIR ]; then rm -rf "$PDFJS_TMPDIR" fi \ No newline at end of file diff --git a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs index 2356548bf8..6265b83b3c 100644 --- a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs +++ b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs @@ -246,8 +246,6 @@ export var PictureInPicture = { let panel = browser.ownerDocument.querySelector("#PictureInPicturePanel"); if (!panel) { - browser.ownerGlobal.ensureCustomElements("moz-toggle"); - browser.ownerGlobal.ensureCustomElements("moz-support-link"); let template = browser.ownerDocument.querySelector( "#PictureInPicturePanelTemplate" ); diff --git a/toolkit/components/places/BookmarkHTMLUtils.sys.mjs b/toolkit/components/places/BookmarkHTMLUtils.sys.mjs index 81bd791730..d619f9fed2 100644 --- a/toolkit/components/places/BookmarkHTMLUtils.sys.mjs +++ b/toolkit/components/places/BookmarkHTMLUtils.sys.mjs @@ -1082,21 +1082,11 @@ BookmarkExporter.prototype = { function insertFaviconForNode(node) { if (node.icon) { try { - // Create a fake faviconURI to use (FIXME: bug 523932) - let faviconURI = Services.io.newURI("fake-favicon-uri:" + node.url); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - faviconURI, - node.icon, - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - PlacesUtils.favicons.setAndFetchFaviconForPage( + PlacesUtils.favicons.setFaviconForPage( Services.io.newURI(node.url), - faviconURI, - false, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - null, - Services.scriptSecurityManager.getSystemPrincipal() + // Create a fake favicon URI to use (FIXME: bug 523932) + Services.io.newURI("fake-favicon-uri:" + node.url), + Services.io.newURI(node.icon) ); } catch (ex) { console.error("Failed to import favicon data:", ex); diff --git a/toolkit/components/places/BookmarkJSONUtils.sys.mjs b/toolkit/components/places/BookmarkJSONUtils.sys.mjs index 0a27db3696..e453e7e094 100644 --- a/toolkit/components/places/BookmarkJSONUtils.sys.mjs +++ b/toolkit/components/places/BookmarkJSONUtils.sys.mjs @@ -21,7 +21,7 @@ const OLD_BOOKMARK_QUERY_TRANSLATIONS = { MOBILE_BOOKMARKS: PlacesUtils.bookmarks.mobileGuid, }; -export var BookmarkJSONUtils = Object.freeze({ +export var BookmarkJSONUtils = { /** * Import bookmarks from a url. * @@ -162,7 +162,7 @@ export var BookmarkJSONUtils = Object.freeze({ }); return { count, hash }; }, -}); +}; function BookmarkImporter(aReplace, aSource) { this._replace = aReplace; @@ -503,21 +503,11 @@ function translateTreeTypes(node) { function insertFaviconForNode(node) { if (node.icon) { try { - // Create a fake faviconURI to use (FIXME: bug 523932) - let faviconURI = Services.io.newURI("fake-favicon-uri:" + node.url); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - faviconURI, - node.icon, - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - PlacesUtils.favicons.setAndFetchFaviconForPage( + PlacesUtils.favicons.setFaviconForPage( Services.io.newURI(node.url), - faviconURI, - false, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - null, - Services.scriptSecurityManager.getSystemPrincipal() + // Create a fake faviconURI to use (FIXME: bug 523932) + Services.io.newURI("fake-favicon-uri:" + node.url), + Services.io.newURI(node.icon) ); } catch (ex) { console.error("Failed to import favicon data:", ex); diff --git a/toolkit/components/places/FaviconHelpers.cpp b/toolkit/components/places/FaviconHelpers.cpp index 1c565a3de1..df06885e1f 100644 --- a/toolkit/components/places/FaviconHelpers.cpp +++ b/toolkit/components/places/FaviconHelpers.cpp @@ -959,6 +959,49 @@ AsyncAssociateIconToPage::Run() { return NS_OK; } +//////////////////////////////////////////////////////////////////////////////// +//// AsyncSetIconForPage + +AsyncSetIconForPage::AsyncSetIconForPage(const IconData& aIcon, + const PageData& aPage, + PlacesCompletionCallback* aCallback) + : Runnable("places::AsyncSetIconForPage"), + mCallback(new nsMainThreadPtrHolder( + "AsyncSetIconForPage::mCallback", aCallback, false)), + mIcon(aIcon), + mPage(aPage) {} + +NS_IMETHODIMP +AsyncSetIconForPage::Run() { + MOZ_ASSERT(!NS_IsMainThread()); + MOZ_ASSERT(mIcon.payloads.Length(), "The icon should have valid data"); + MOZ_ASSERT(mPage.spec.Length(), "The page should have spec"); + MOZ_ASSERT(mPage.guid.IsEmpty(), "The page should not have guid"); + + nsresult rv = NS_OK; + auto guard = MakeScopeExit([&]() { + if (mCallback) { + NS_DispatchToMainThread( + NS_NewRunnableFunction("AsyncSetIconForPage::Callback", + [rv, callback = std::move(mCallback)]() { + (void)callback->Complete(rv); + })); + } + }); + + // Fetch the page data. + RefPtr DB = Database::GetDatabase(); + if (MOZ_UNLIKELY(!DB)) { + return (rv = NS_ERROR_UNEXPECTED); + } + rv = FetchPageInfo(DB, mPage); + NS_ENSURE_SUCCESS(rv, rv); + + nsMainThreadPtrHandle nullCallback; + AsyncAssociateIconToPage event(mIcon, mPage, nullCallback); + return (rv = event.Run()); +} + //////////////////////////////////////////////////////////////////////////////// //// AsyncGetFaviconURLForPage @@ -1040,61 +1083,6 @@ AsyncGetFaviconDataForPage::Run() { return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// -//// AsyncReplaceFaviconData - -AsyncReplaceFaviconData::AsyncReplaceFaviconData(const IconData& aIcon) - : Runnable("places::AsyncReplaceFaviconData"), mIcon(aIcon) { - MOZ_ASSERT(NS_IsMainThread()); -} - -NS_IMETHODIMP -AsyncReplaceFaviconData::Run() { - MOZ_ASSERT(!NS_IsMainThread()); - - RefPtr DB = Database::GetDatabase(); - NS_ENSURE_STATE(DB); - - mozStorageTransaction transaction( - DB->MainConn(), false, mozIStorageConnection::TRANSACTION_IMMEDIATE); - - // XXX Handle the error, bug 1696133. - Unused << NS_WARN_IF(NS_FAILED(transaction.Start())); - - nsresult rv = SetIconInfo(DB, mIcon, true); - if (rv == NS_ERROR_NOT_AVAILABLE) { - // There's no previous icon to replace, we don't need to do anything. - (void)transaction.Commit(); - return NS_OK; - } - NS_ENSURE_SUCCESS(rv, rv); - rv = transaction.Commit(); - NS_ENSURE_SUCCESS(rv, rv); - - // We can invalidate the cache version since we now persist the icon. - nsCOMPtr event = NewRunnableMethod( - "places::AsyncReplaceFaviconData::RemoveIconDataCacheEntry", this, - &AsyncReplaceFaviconData::RemoveIconDataCacheEntry); - rv = NS_DispatchToMainThread(event); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult AsyncReplaceFaviconData::RemoveIconDataCacheEntry() { - MOZ_ASSERT(NS_IsMainThread()); - - nsCOMPtr iconURI; - nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec); - NS_ENSURE_SUCCESS(rv, rv); - - nsFaviconService* favicons = nsFaviconService::GetFaviconService(); - NS_ENSURE_STATE(favicons); - favicons->mUnassociatedIcons.RemoveEntry(iconURI); - - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// //// NotifyIconObservers @@ -1207,7 +1195,8 @@ AsyncCopyFavicons::Run() { } NS_ENSURE_SUCCESS(rv, rv); - // Get just one icon, to check whether the page has any, and to notify later. + // Get just one icon, to check whether the page has any, and to notify + // later. rv = FetchIconPerSpec(DB, mFromPage.spec, ""_ns, icon, UINT16_MAX); NS_ENSURE_SUCCESS(rv, rv); diff --git a/toolkit/components/places/FaviconHelpers.h b/toolkit/components/places/FaviconHelpers.h index ba3407722c..aaa5396fe6 100644 --- a/toolkit/components/places/FaviconHelpers.h +++ b/toolkit/components/places/FaviconHelpers.h @@ -14,6 +14,7 @@ #include "nsThreadUtils.h" #include "nsProxyRelease.h" #include "imgLoader.h" +#include "PlacesCompletionCallback.h" class nsIPrincipal; @@ -191,6 +192,33 @@ class AsyncAssociateIconToPage final : public Runnable { PageData mPage; }; +/** + * Set favicon for the page, finally dispatches an event to the + * main thread to notify the change to observers. + */ +class AsyncSetIconForPage final : public Runnable { + public: + NS_DECL_NSIRUNNABLE + + /** + * Constructor. + * + * @param aIcon + * Icon to be associated. + * @param aPage + * Page to which associate the icon. + * @param aCallback + * Function to be called when the associate process finishes. + */ + AsyncSetIconForPage(const IconData& aIcon, const PageData& aPage, + PlacesCompletionCallback* aCallback); + + private: + nsMainThreadPtrHandle mCallback; + IconData mIcon; + PageData mPage; +}; + /** * Asynchronously tries to get the URL of a page's favicon, then notifies the * given observer. @@ -256,18 +284,6 @@ class AsyncGetFaviconDataForPage final : public Runnable { nsCString mPageHost; }; -class AsyncReplaceFaviconData final : public Runnable { - public: - NS_DECL_NSIRUNNABLE - - explicit AsyncReplaceFaviconData(const IconData& aIcon); - - private: - nsresult RemoveIconDataCacheEntry(); - - IconData mIcon; -}; - /** * Notifies the icon change to favicon observers. */ @@ -276,7 +292,7 @@ class NotifyIconObservers final : public Runnable { NS_DECL_NSIRUNNABLE /** - * Constructor. + * Constructor for nsIFaviconDataCallback. * * @param aIcon * Icon information. Can be empty if no icon is associated to the page. diff --git a/toolkit/components/places/History.cpp b/toolkit/components/places/History.cpp index 6c066f47be..474b2cdac8 100644 --- a/toolkit/components/places/History.cpp +++ b/toolkit/components/places/History.cpp @@ -1434,6 +1434,13 @@ void NotifyEmbedVisit(VisitData& aPlace, (void)NS_DispatchToMainThread(event); } +void NotifyOriginRestrictedVisit(nsIURI* aURI) { + MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread!"); + + nsCOMPtr event = new NotifyManyVisitsObservers(VisitData(aURI)); + (void)NS_DispatchToMainThread(event); +} + void NotifyVisitIfHavingUserPass(nsIURI* aURI) { MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread!"); @@ -1868,6 +1875,64 @@ const mozIStorageConnection* History::GetConstDBConn() { return mDB->MainConn(); } +void History::UpdateOriginFloodingRestriction(nsACString& aOrigin) { + MOZ_ASSERT(NS_IsMainThread()); + + TimeStamp latestInputTimeStamp = UserActivation::LatestUserInputStart(); + if (latestInputTimeStamp.IsNull()) { + // Probably just after browser initialization. + return; + } + + TimeStamp now = TimeStamp::Now(); + + // Remove expired flooding resrictions. + for (auto iter = mOriginFloodingRestrictions.Iter(); !iter.Done(); + iter.Next()) { + if ((now - iter.Data().mLastVisitTimeStamp).ToSeconds() > + iter.Data().mExpireIntervalSeconds) { + iter.Remove(); + } + } + + // If not long enough time elapsed sincer last user interaction, this visit + // can be stored. + if ((now - latestInputTimeStamp).ToSeconds() < + StaticPrefs:: + places_history_floodingPrevention_maxSecondsFromLastUserInteraction()) { + mOriginFloodingRestrictions.Remove(aOrigin); + return; + } + + // Otherwise, update the flooding restriction for the origin. + auto restriction = mOriginFloodingRestrictions.Lookup(aOrigin); + if (restriction) { + if (restriction->mAllowedVisitCount) { + // Count down to 0. If 0, the origin should be restricted. + restriction->mAllowedVisitCount -= 1; + } else { + // Since the origin is marked as restricted make its expiration time + // longer. + restriction->mExpireIntervalSeconds *= 2; + } + } else { + // Initialize OriginFloodingRestriction to store the origin restriction. + mOriginFloodingRestrictions.InsertOrUpdate( + aOrigin, + OriginFloodingRestriction{ + now, + StaticPrefs:: + places_history_floodingPrevention_restrictionExpireSeconds(), + StaticPrefs::places_history_floodingPrevention_restrictionCount()}); + } +} + +bool History::IsRestrictedOrigin(nsACString& aOrigin) { + auto restriction = mOriginFloodingRestrictions.Lookup(aOrigin); + // If the count is 0, need to restrict the origin. + return restriction && !restriction->mAllowedVisitCount; +} + void History::Shutdown() { MOZ_ASSERT(NS_IsMainThread()); MutexAutoLock lockedScope(mBlockShutdownMutex); @@ -2019,6 +2084,31 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI, // Error pages should never be autocompleted. place.isUnrecoverableError = aFlags & IHistory::UNRECOVERABLE_ERROR; + // EMBED visits should not go through the database. + // They exist only to keep track of isVisited status during the session. + if (place.transitionType == nsINavHistoryService::TRANSITION_EMBED) { + NotifyEmbedVisit(place); + return NS_OK; + } + + if (StaticPrefs::places_history_floodingPrevention_enabled()) { + // If the origin is restricted, make isVisited status available during the + // session but not stored in the database. + nsAutoCString origin; + Unused << visitedURI->GetHost(origin); + if (StringBeginsWith(origin, "www."_ns)) { + origin.Cut(0, 4); + } + + UpdateOriginFloodingRestriction(origin); + + if (IsRestrictedOrigin(origin)) { + NotifyOriginRestrictedVisit(visitedURI); + NotifyVisitIfHavingUserPass(aURI); + return NS_OK; + } + } + nsCOMPtr bwt = do_ImportESModule("resource:///modules/BrowserWindowTracker.sys.mjs", "BrowserWindowTracker", &rv); @@ -2075,17 +2165,11 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI, } } - // EMBED visits should not go through the database. - // They exist only to keep track of isVisited status during the session. - if (place.transitionType == nsINavHistoryService::TRANSITION_EMBED) { - NotifyEmbedVisit(place); - } else { - mozIStorageConnection* dbConn = GetDBConn(); - NS_ENSURE_STATE(dbConn); + mozIStorageConnection* dbConn = GetDBConn(); + NS_ENSURE_STATE(dbConn); - rv = InsertVisitedURIs::Start(dbConn, std::move(placeArray)); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = InsertVisitedURIs::Start(dbConn, std::move(placeArray)); + NS_ENSURE_SUCCESS(rv, rv); // URIs with a userpass component are not stored in the database for security // reasons, we store the exposable URI version of them instead. @@ -2323,6 +2407,7 @@ History::IsURIVisited(nsIURI* aURI, mozIVisitedStatusCallback* aCallback) { NS_IMETHODIMP History::ClearCache() { mRecentlyVisitedURIs.Clear(); + mOriginFloodingRestrictions.Clear(); return NS_OK; } diff --git a/toolkit/components/places/History.h b/toolkit/components/places/History.h index 03a31186fd..a5007082cd 100644 --- a/toolkit/components/places/History.h +++ b/toolkit/components/places/History.h @@ -196,6 +196,16 @@ class History final : public BaseHistory, }; nsTHashMap mRecentlyVisitedURIs; + + struct OriginFloodingRestriction { + TimeStamp mLastVisitTimeStamp; + uint32_t mExpireIntervalSeconds; + uint32_t mAllowedVisitCount; + }; + nsTHashMap + mOriginFloodingRestrictions; + void UpdateOriginFloodingRestriction(nsACString& aOrigin); + bool IsRestrictedOrigin(nsACString& aOrigin); }; } // namespace mozilla::places diff --git a/toolkit/components/places/PlacesCompletionCallback.idl b/toolkit/components/places/PlacesCompletionCallback.idl new file mode 100644 index 0000000000..8cc089c0e7 --- /dev/null +++ b/toolkit/components/places/PlacesCompletionCallback.idl @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +[scriptable, function, uuid(ea26627b-d21a-4f97-b2d0-f8df7be24808)] +interface PlacesCompletionCallback : nsISupports { + /** + * Indicates that the event this callback was passed in for has completed. + * + * @param status + * The status of the call. Generally NS_OK if the operation + * completed successfully. + */ + void complete(in nsresult status); +}; diff --git a/toolkit/components/places/PlacesQuery.sys.mjs b/toolkit/components/places/PlacesQuery.sys.mjs index 7ddf5ee988..d969687def 100644 --- a/toolkit/components/places/PlacesQuery.sys.mjs +++ b/toolkit/components/places/PlacesQuery.sys.mjs @@ -58,7 +58,7 @@ export class PlacesQuery { #historyListenerCallback = null; /** @type {DeferredTask} */ #historyObserverTask = null; - searchInProgress = false; + #searchInProgress = false; /** * Get a snapshot of history visits at this moment. @@ -118,14 +118,18 @@ export class PlacesQuery { groupBy = "url"; break; } + const whereClause = + daysOld == Infinity + ? "" + : `WHERE visit_date >= (strftime('%s','now','localtime','start of day','-${Number( + daysOld + )} days','utc') * 1000000)`; const sql = `SELECT MAX(visit_date) as visit_date, title, url FROM moz_historyvisits v JOIN moz_places h ON v.place_id = h.id - WHERE visit_date >= (strftime('%s','now','localtime','start of day','-${Number( - daysOld - )} days','utc') * 1000000) AND hidden = 0 + ${whereClause} GROUP BY ${groupBy} ORDER BY visit_date DESC LIMIT ${limit > 0 ? limit : -1}`; @@ -169,11 +173,11 @@ export class PlacesQuery { GROUP BY url ORDER BY ${orderBy} LIMIT ${limit > 0 ? limit : -1}`; - if (this.searchInProgress) { + if (this.#searchInProgress) { db.interrupt(); } try { - this.searchInProgress = true; + this.#searchInProgress = true; const rows = await db.executeCached(sql, { query, matchBehavior: Ci.mozIPlacesAutoComplete.MATCH_ANYWHERE_UNMODIFIED, @@ -181,7 +185,7 @@ export class PlacesQuery { }); return rows.map(row => this.formatRowAsVisit(row)); } finally { - this.searchInProgress = false; + this.#searchInProgress = false; } } @@ -309,7 +313,7 @@ export class PlacesQuery { } this.#historyListener = null; this.#historyListenerCallback = null; - if (!this.#historyObserverTask.isFinalized) { + if (this.#historyObserverTask && !this.#historyObserverTask.isFinalized) { this.#historyObserverTask.disarm(); this.#historyObserverTask.finalize(); } diff --git a/toolkit/components/places/moz.build b/toolkit/components/places/moz.build index 28a7421fba..797d5709f6 100644 --- a/toolkit/components/places/moz.build +++ b/toolkit/components/places/moz.build @@ -23,6 +23,7 @@ if CONFIG["MOZ_PLACES"]: "nsINavBookmarksService.idl", "nsIPlacesPreviewsHelperService.idl", "nsITaggingService.idl", + "PlacesCompletionCallback.idl", ] EXPORTS.mozilla.places = [ diff --git a/toolkit/components/places/nsFaviconService.cpp b/toolkit/components/places/nsFaviconService.cpp index c236d7a680..ba338e9d52 100644 --- a/toolkit/components/places/nsFaviconService.cpp +++ b/toolkit/components/places/nsFaviconService.cpp @@ -14,6 +14,7 @@ */ #include "nsFaviconService.h" +#include "PlacesCompletionCallback.h" #include "nsNavHistory.h" #include "nsPlacesMacros.h" @@ -24,6 +25,7 @@ #include "nsStreamUtils.h" #include "plbase64.h" #include "nsIClassInfoImpl.h" +#include "mozilla/AppShutdown.h" #include "mozilla/ArrayUtils.h" #include "mozilla/LoadInfo.h" #include "mozilla/NullPrincipal.h" @@ -35,13 +37,6 @@ #include "nsContentUtils.h" #include "imgICache.h" -#define UNASSOCIATED_FAVICONS_LENGTH 32 - -// When replaceFaviconData is called, we store the icons in an in-memory cache -// instead of in storage. Icons in the cache are expired according to this -// interval. -#define UNASSOCIATED_ICON_EXPIRY_INTERVAL 60000 - using namespace mozilla; using namespace mozilla::places; @@ -123,12 +118,10 @@ nsresult GetFramesInfoForContainer(imgIContainer* aContainer, PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsFaviconService, gFaviconService) NS_IMPL_CLASSINFO(nsFaviconService, nullptr, 0, NS_FAVICONSERVICE_CID) -NS_IMPL_ISUPPORTS_CI(nsFaviconService, nsIFaviconService, nsITimerCallback, - nsINamed) +NS_IMPL_ISUPPORTS_CI(nsFaviconService, nsIFaviconService) nsFaviconService::nsFaviconService() - : mUnassociatedIcons(UNASSOCIATED_FAVICONS_LENGTH), - mDefaultIconURIPreferredSize(UINT16_MAX) { + : mDefaultIconURIPreferredSize(UINT16_MAX) { NS_ASSERTION(!gFaviconService, "Attempting to create two instances of the service!"); gFaviconService = this; @@ -152,10 +145,6 @@ nsFaviconService::StoreLastInsertedId(const nsACString& aTable, nsresult nsFaviconService::Init() { mDB = Database::GetDatabase(); NS_ENSURE_STATE(mDB); - - mExpireUnassociatedIconsTimer = NS_NewTimer(); - NS_ENSURE_STATE(mExpireUnassociatedIconsTimer); - return NS_OK; } @@ -187,41 +176,6 @@ nsFaviconService::ExpireAllFavicons() { return conn->ExecuteAsync(stmts, callback, getter_AddRefs(ps)); } -//////////////////////////////////////////////////////////////////////////////// -//// nsITimerCallback - -NS_IMETHODIMP -nsFaviconService::Notify(nsITimer* timer) { - if (timer != mExpireUnassociatedIconsTimer.get()) { - return NS_ERROR_INVALID_ARG; - } - - PRTime now = PR_Now(); - for (auto iter = mUnassociatedIcons.Iter(); !iter.Done(); iter.Next()) { - UnassociatedIconHashKey* iconKey = iter.Get(); - if (now - iconKey->created >= UNASSOCIATED_ICON_EXPIRY_INTERVAL) { - iter.Remove(); - } - } - - // Re-init the expiry timer if the cache isn't empty. - if (mUnassociatedIcons.Count() > 0) { - mExpireUnassociatedIconsTimer->InitWithCallback( - this, UNASSOCIATED_ICON_EXPIRY_INTERVAL, nsITimer::TYPE_ONE_SHOT); - } - - return NS_OK; -} - -//////////////////////////////////////////////////////////////////////// -//// nsINamed - -NS_IMETHODIMP -nsFaviconService::GetName(nsACString& aName) { - aName.AssignLiteral("nsFaviconService"); - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// //// nsIFaviconService @@ -258,6 +212,161 @@ void nsFaviconService::ClearImageCache(nsIURI* aImageURI) { } } +NS_IMETHODIMP +nsFaviconService::SetFaviconForPage( + nsIURI* aPageURI, nsIURI* aFaviconURI, nsIURI* aDataURL, + PRTime aExpiration = 0, PlacesCompletionCallback* aCallback = nullptr) { + MOZ_ASSERT(NS_IsMainThread()); + NS_ENSURE_ARG(aPageURI); + NS_ENSURE_ARG(aFaviconURI); + NS_ENSURE_ARG(aDataURL); + + MOZ_DIAGNOSTIC_ASSERT(aDataURL->SchemeIs("data")); + if (!aDataURL->SchemeIs("data")) { + return NS_ERROR_INVALID_ARG; + } + + if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { + return NS_OK; + } + + PRTime now = PR_Now(); + if (aExpiration < now + MIN_FAVICON_EXPIRATION) { + // Invalid input, just use the default. + aExpiration = now + MAX_FAVICON_EXPIRATION; + } + + // Use the data: protocol handler to convert the data. + nsresult rv = NS_OK; + auto guard = MakeScopeExit([&]() { + if (aCallback) { + aCallback->Complete(rv); + } + }); + + nsCOMPtr ioService = do_GetIOService(&rv); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr protocolHandler; + rv = ioService->GetProtocolHandler("data", getter_AddRefs(protocolHandler)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr loadingPrincipal = + NullPrincipal::CreateWithoutOriginAttributes(); + if (MOZ_UNLIKELY(!(loadingPrincipal))) { + return (rv = NS_ERROR_NULL_POINTER); + } + + nsCOMPtr loadInfo = new mozilla::net::LoadInfo( + loadingPrincipal, + nullptr, // aTriggeringPrincipal + nullptr, // aLoadingNode + nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT | + nsILoadInfo::SEC_ALLOW_CHROME | nsILoadInfo::SEC_DISALLOW_SCRIPT, + nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON); + + nsCOMPtr channel; + rv = protocolHandler->NewChannel(aDataURL, loadInfo, getter_AddRefs(channel)); + NS_ENSURE_SUCCESS(rv, rv); + + // Blocking stream is OK for data URIs. + nsCOMPtr stream; + rv = channel->Open(getter_AddRefs(stream)); + NS_ENSURE_SUCCESS(rv, rv); + + uint64_t available64; + rv = stream->Available(&available64); + NS_ENSURE_SUCCESS(rv, rv); + if (available64 == 0 || available64 > UINT32_MAX / sizeof(uint8_t)) { + return (rv = NS_ERROR_FILE_TOO_BIG); + } + uint32_t available = (uint32_t)available64; + + // Read all the decoded data. + nsTArray buffer; + buffer.SetLength(available); + uint32_t numRead; + rv = stream->Read(TO_CHARBUFFER(buffer.Elements()), available, &numRead); + NS_ENSURE_SUCCESS(rv, rv); + if (numRead != available) { + return (rv = NS_ERROR_UNEXPECTED); + } + + nsAutoCString mimeType; + rv = channel->GetContentType(mimeType); + NS_ENSURE_SUCCESS(rv, rv); + if (!imgLoader::SupportImageWithMimeType( + mimeType, AcceptedMimeTypes::IMAGES_AND_DOCUMENTS)) { + return (rv = NS_ERROR_UNEXPECTED); + } + + // Favicon should be handled without userpass. + nsCOMPtr faviconURI = GetExposableURI(aFaviconURI); + nsCOMPtr pageURI = GetExposableURI(aPageURI); + + IconData icon; + icon.expiration = aExpiration; + icon.status = ICON_STATUS_CACHED; + icon.fetchMode = FETCH_NEVER; + rv = faviconURI->GetSpec(icon.spec); + NS_ENSURE_SUCCESS(rv, rv); + // URIs can arguably lack a host. + (void)faviconURI->GetHost(icon.host); + if (StringBeginsWith(icon.host, "www."_ns)) { + icon.host.Cut(0, 4); + } + + IconPayload payload; + payload.mimeType = mimeType; + payload.data.Assign(TO_CHARBUFFER(buffer.Elements()), buffer.Length()); + if (payload.mimeType.EqualsLiteral(SVG_MIME_TYPE)) { + payload.width = UINT16_MAX; + } + icon.payloads.AppendElement(payload); + + rv = OptimizeIconSizes(icon); + NS_ENSURE_SUCCESS(rv, rv); + + PageData page; + rv = pageURI->GetSpec(page.spec); + NS_ENSURE_SUCCESS(rv, rv); + // URIs can arguably lack a host. + (void)pageURI->GetHost(page.host); + if (StringBeginsWith(page.host, "www."_ns)) { + page.host.Cut(0, 4); + } + + // A root icon is when the icon and page have the same host and the path + // is just /favicon.ico. These icons are considered valid for the whole + // origin and expired with the origin through a trigger. + nsAutoCString path; + if (NS_SUCCEEDED(faviconURI->GetPathQueryRef(path)) && !icon.host.IsEmpty() && + icon.host.Equals(page.host) && path.EqualsLiteral("/favicon.ico")) { + icon.rootIcon = 1; + } + + // If the page url points to an image, the icon's url will be the same. + // TODO (Bug 403651): store a resample of the image. For now avoid that + // for database size and UX concerns. + // Don't store favicons for error pages either. + if (icon.spec.Equals(page.spec) || + icon.spec.EqualsLiteral(FAVICON_CERTERRORPAGE_URL) || + icon.spec.EqualsLiteral(FAVICON_ERRORPAGE_URL)) { + return NS_OK; + } + + RefPtr event = + new AsyncSetIconForPage(icon, page, aCallback); + RefPtr DB = Database::GetDatabase(); + if (MOZ_UNLIKELY(!DB)) { + return (rv = NS_ERROR_UNEXPECTED); + } + + DB->DispatchToAsyncThread(event); + + guard.release(); + return NS_OK; +} + NS_IMETHODIMP nsFaviconService::SetAndFetchFaviconForPage( nsIURI* aPageURI, nsIURI* aFaviconURI, bool aForceReload, @@ -310,20 +419,13 @@ nsFaviconService::SetAndFetchFaviconForPage( // Build icon data. IconData icon; - // If we have an in-memory icon payload, it overwrites the actual request. - UnassociatedIconHashKey* iconKey = mUnassociatedIcons.GetEntry(faviconURI); - if (iconKey) { - icon = iconKey->iconData; - mUnassociatedIcons.RemoveEntry(iconKey); - } else { - icon.fetchMode = aForceReload ? FETCH_ALWAYS : FETCH_IF_MISSING; - rv = faviconURI->GetSpec(icon.spec); - NS_ENSURE_SUCCESS(rv, rv); - // URIs can arguably lack a host. - Unused << faviconURI->GetHost(icon.host); - if (StringBeginsWith(icon.host, "www."_ns)) { - icon.host.Cut(0, 4); - } + icon.fetchMode = aForceReload ? FETCH_ALWAYS : FETCH_IF_MISSING; + rv = faviconURI->GetSpec(icon.spec); + NS_ENSURE_SUCCESS(rv, rv); + // URIs can arguably lack a host. + Unused << faviconURI->GetHost(icon.host); + if (StringBeginsWith(icon.host, "www."_ns)) { + icon.host.Cut(0, 4); } // A root icon is when the icon and page have the same host and the path @@ -360,182 +462,6 @@ nsFaviconService::SetAndFetchFaviconForPage( return NS_OK; } -NS_IMETHODIMP -nsFaviconService::ReplaceFaviconData(nsIURI* aFaviconURI, - const nsTArray& aData, - const nsACString& aMimeType, - PRTime aExpiration) { - MOZ_ASSERT(NS_IsMainThread()); - NS_ENSURE_ARG(aFaviconURI); - NS_ENSURE_ARG(aData.Length() > 0); - NS_ENSURE_ARG(aMimeType.Length() > 0); - NS_ENSURE_ARG(imgLoader::SupportImageWithMimeType( - aMimeType, AcceptedMimeTypes::IMAGES_AND_DOCUMENTS)); - - nsCOMPtr faviconURI = GetExposableURI(aFaviconURI); - - PRTime now = PR_Now(); - if (aExpiration < now + MIN_FAVICON_EXPIRATION) { - // Invalid input, just use the default. - aExpiration = now + MAX_FAVICON_EXPIRATION; - } - - UnassociatedIconHashKey* iconKey = mUnassociatedIcons.PutEntry(faviconURI); - if (!iconKey) { - return NS_ERROR_OUT_OF_MEMORY; - } - - iconKey->created = now; - - // If the cache contains unassociated icons, an expiry timer should already - // exist, otherwise there may be a timer left hanging around, so make sure we - // fire a new one. - uint32_t unassociatedCount = mUnassociatedIcons.Count(); - if (unassociatedCount == 1) { - mExpireUnassociatedIconsTimer->Cancel(); - mExpireUnassociatedIconsTimer->InitWithCallback( - this, UNASSOCIATED_ICON_EXPIRY_INTERVAL, nsITimer::TYPE_ONE_SHOT); - } - - IconData* iconData = &(iconKey->iconData); - iconData->expiration = aExpiration; - iconData->status = ICON_STATUS_CACHED; - iconData->fetchMode = FETCH_NEVER; - nsresult rv = faviconURI->GetSpec(iconData->spec); - NS_ENSURE_SUCCESS(rv, rv); - // URIs can arguably lack a host. - Unused << faviconURI->GetHost(iconData->host); - if (StringBeginsWith(iconData->host, "www."_ns)) { - iconData->host.Cut(0, 4); - } - - // Note we can't set rootIcon here, because don't know the page it will be - // associated with. We'll do that later in SetAndFetchFaviconForPage if the - // icon doesn't exist; otherwise, if AsyncReplaceFaviconData updates an - // existing icon, it will take care of not overwriting an existing - // root = 1 value. - - IconPayload payload; - payload.mimeType = aMimeType; - payload.data.Assign(TO_CHARBUFFER(aData.Elements()), aData.Length()); - if (payload.mimeType.EqualsLiteral(SVG_MIME_TYPE)) { - payload.width = UINT16_MAX; - } - // There may already be a previous payload, so ensure to only have one. - iconData->payloads.Clear(); - iconData->payloads.AppendElement(payload); - - rv = OptimizeIconSizes(*iconData); - NS_ENSURE_SUCCESS(rv, rv); - - // If there's not valid payload, don't store the icon into to the database. - if ((*iconData).payloads.Length() == 0) { - // We cannot optimize this favicon size and we are over the maximum size - // allowed, so we will not save data to the db to avoid bloating it. - mUnassociatedIcons.RemoveEntry(faviconURI); - return NS_ERROR_FAILURE; - } - - // If the database contains an icon at the given url, we will update the - // database immediately so that the associated pages are kept in sync. - // Otherwise, do nothing and let the icon be picked up from the memory hash. - RefPtr event = - new AsyncReplaceFaviconData(*iconData); - RefPtr DB = Database::GetDatabase(); - NS_ENSURE_STATE(DB); - DB->DispatchToAsyncThread(event); - - return NS_OK; -} - -NS_IMETHODIMP -nsFaviconService::ReplaceFaviconDataFromDataURL( - nsIURI* aFaviconURI, const nsAString& aDataURL, PRTime aExpiration, - nsIPrincipal* aLoadingPrincipal) { - NS_ENSURE_ARG(aFaviconURI); - NS_ENSURE_TRUE(aDataURL.Length() > 0, NS_ERROR_INVALID_ARG); - PRTime now = PR_Now(); - if (aExpiration < now + MIN_FAVICON_EXPIRATION) { - // Invalid input, just use the default. - aExpiration = now + MAX_FAVICON_EXPIRATION; - } - - nsCOMPtr dataURI; - nsresult rv = NS_NewURI(getter_AddRefs(dataURI), aDataURL); - NS_ENSURE_SUCCESS(rv, rv); - - // Use the data: protocol handler to convert the data. - nsCOMPtr ioService = do_GetIOService(&rv); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr protocolHandler; - rv = ioService->GetProtocolHandler("data", getter_AddRefs(protocolHandler)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr loadingPrincipal = aLoadingPrincipal; - MOZ_ASSERT(loadingPrincipal, - "please provide aLoadingPrincipal for this favicon"); - if (!loadingPrincipal) { - // Let's default to the nullPrincipal if no loadingPrincipal is provided. - AutoTArray params = { - u"nsFaviconService::ReplaceFaviconDataFromDataURL()"_ns, - u"nsFaviconService::ReplaceFaviconDataFromDataURL(...," - " [optional aLoadingPrincipal])"_ns}; - nsContentUtils::ReportToConsole( - nsIScriptError::warningFlag, "Security by Default"_ns, - nullptr, // aDocument - nsContentUtils::eNECKO_PROPERTIES, "APIDeprecationWarning", params); - - loadingPrincipal = NullPrincipal::CreateWithoutOriginAttributes(); - } - NS_ENSURE_TRUE(loadingPrincipal, NS_ERROR_FAILURE); - - nsCOMPtr loadInfo = new mozilla::net::LoadInfo( - loadingPrincipal, - nullptr, // aTriggeringPrincipal - nullptr, // aLoadingNode - nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT | - nsILoadInfo::SEC_ALLOW_CHROME | nsILoadInfo::SEC_DISALLOW_SCRIPT, - nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON); - - nsCOMPtr channel; - rv = protocolHandler->NewChannel(dataURI, loadInfo, getter_AddRefs(channel)); - NS_ENSURE_SUCCESS(rv, rv); - - // Blocking stream is OK for data URIs. - nsCOMPtr stream; - rv = channel->Open(getter_AddRefs(stream)); - NS_ENSURE_SUCCESS(rv, rv); - - uint64_t available64; - rv = stream->Available(&available64); - NS_ENSURE_SUCCESS(rv, rv); - if (available64 == 0 || available64 > UINT32_MAX / sizeof(uint8_t)) { - return NS_ERROR_FILE_TOO_BIG; - } - uint32_t available = (uint32_t)available64; - - // Read all the decoded data. - nsTArray buffer; - buffer.SetLength(available); - uint32_t numRead; - rv = stream->Read(TO_CHARBUFFER(buffer.Elements()), available, &numRead); - if (NS_FAILED(rv) || numRead != available) { - return rv; - } - - nsAutoCString mimeType; - rv = channel->GetContentType(mimeType); - if (NS_FAILED(rv)) { - return rv; - } - - // ReplaceFaviconData can now do the dirty work. - rv = ReplaceFaviconData(aFaviconURI, buffer, mimeType, aExpiration); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - NS_IMETHODIMP nsFaviconService::GetFaviconURLForPage(nsIURI* aPageURI, nsIFaviconDataCallback* aCallback, diff --git a/toolkit/components/places/nsFaviconService.h b/toolkit/components/places/nsFaviconService.h index 4485bbaf28..ab142bb5fc 100644 --- a/toolkit/components/places/nsFaviconService.h +++ b/toolkit/components/places/nsFaviconService.h @@ -16,8 +16,6 @@ #include "nsCOMPtr.h" #include "nsComponentManagerUtils.h" #include "nsIFaviconService.h" -#include "nsINamed.h" -#include "nsITimer.h" #include "nsServiceManagerUtils.h" #include "nsString.h" #include "nsTHashtable.h" @@ -32,21 +30,7 @@ extern const uint16_t gFaviconSizes[7]; // forward class definitions class mozIStorageStatementCallback; -class UnassociatedIconHashKey : public nsURIHashKey { - public: - explicit UnassociatedIconHashKey(const nsIURI* aURI) - : nsURIHashKey(aURI), created(PR_Now()) {} - UnassociatedIconHashKey(UnassociatedIconHashKey&& aOther) noexcept - : nsURIHashKey(std::move(aOther)), - iconData(std::move(aOther.iconData)), - created(std::move(aOther.created)) {} - mozilla::places::IconData iconData; - PRTime created; -}; - -class nsFaviconService final : public nsIFaviconService, - public nsITimerCallback, - public nsINamed { +class nsFaviconService final : public nsIFaviconService { public: nsFaviconService(); @@ -107,8 +91,6 @@ class nsFaviconService final : public nsIFaviconService, NS_DECL_ISUPPORTS NS_DECL_NSIFAVICONSERVICE - NS_DECL_NSITIMERCALLBACK - NS_DECL_NSINAMED private: imgITools* GetImgTools() { @@ -122,7 +104,6 @@ class nsFaviconService final : public nsIFaviconService, RefPtr mDB; - nsCOMPtr mExpireUnassociatedIconsTimer; nsCOMPtr mImgTools; static nsFaviconService* gFaviconService; @@ -134,11 +115,6 @@ class nsFaviconService final : public nsIFaviconService, * they get back. May be null, in which case it needs initialization. */ nsCOMPtr mDefaultIcon; - - // This class needs access to the icons cache. - friend class mozilla::places::AsyncReplaceFaviconData; - nsTHashtable mUnassociatedIcons; - uint16_t mDefaultIconURIPreferredSize; }; diff --git a/toolkit/components/places/nsIFaviconService.idl b/toolkit/components/places/nsIFaviconService.idl index 5bc26545c6..f0aeda711f 100644 --- a/toolkit/components/places/nsIFaviconService.idl +++ b/toolkit/components/places/nsIFaviconService.idl @@ -9,6 +9,7 @@ interface nsIURI; interface nsIPrincipal; interface mozIPlacesPendingOperation; interface nsIFaviconDataCallback; +interface PlacesCompletionCallback; [scriptable, uuid(e81e0b0c-b9f1-4c2e-8f3c-b809933cf73c)] interface nsIFaviconService : nsISupports @@ -141,72 +142,35 @@ interface nsIFaviconService : nsISupports [optional] in unsigned long long aRequestContextID); /** - * Sets the data for a given favicon URI either by replacing existing data in - * the database or taking the place of otherwise fetched icon data when - * calling setAndFetchFaviconForPage later. - * - * Favicon data for favicon URIs that are not associated with a page URI via - * setAndFetchFaviconForPage will be stored in memory, but may be expired at - * any time, so you should make an effort to associate favicon URIs with page - * URIs as soon as possible. - * - * It's better to not use this function for chrome: icon URIs since you can - * reference the chrome image yourself. getFaviconLinkForIcon/Page will ignore - * any associated data if the favicon URI is "chrome:" and just return the - * same chrome URI. - * - * This function does NOT send out notifications that the data has changed. - * Pages using this favicons that are visible in history or bookmarks views - * will keep the old icon until they have been refreshed by other means. - * - * This function tries to optimize the favicon size, if it is bigger - * than a defined limit we will try to convert it to a 16x16 png image. - * If the conversion fails and favicon is still bigger than our max accepted - * size it won't be saved. - * - * @param aFaviconURI - * URI of the favicon whose data is being set. - * @param aData - * Binary contents of the favicon to save - * @param aMimeType - * MIME type of the data to store. This is important so that we know - * what to report when the favicon is used. You should always set this - * param unless you are clearing an icon. - * @param [optional] aExpiration - * Time in microseconds since the epoch when this favicon expires. - * Until this time, we won't try to load it again. - * @throws NS_ERROR_FAILURE - * Thrown if the favicon is overbloated and won't be saved to the db. - */ - void replaceFaviconData(in nsIURI aFaviconURI, - in Array aData, - in AUTF8String aMimeType, - [optional] in PRTime aExpiration); - - /** - * Same as replaceFaviconData but the data is provided by a string - * containing a data URL. - * - * @see replaceFaviconData + * Stores the relation between a page URI and a favicon URI, whose icon data + * is provided through a data URL. + * The process is asynchronous and a callback with the status of the operation + * will be invoked at the end of it. * + * @param aPageURI + * URI of the page whose favicon is being set. * @param aFaviconURI - * URI of the favicon whose data is being set. + * URI of the favicon to associate with the page. * @param aDataURL - * string containing a data URL that represents the contents of - * the favicon to save + * String that represents a data URL to replace as the favicon content. * @param [optional] aExpiration * Time in microseconds since the epoch when this favicon expires. * Until this time, we won't try to load it again. - * @param [optional] aLoadingPrincipal - * Principal of the page whose favicon is being set. If this argument - * is omitted, the loadingPrincipal defaults to the nullPrincipal. - * @throws NS_ERROR_FAILURE - * Thrown if the favicon is overbloated and won't be saved to the db. + * If this argument is omitted, the expiration defaults to + * 7 days (FaviconHelpers::MAX_FAVICON_EXPIRATION) from now. + * @param [optional] aCallback + * Once we're done setting and/or fetching the favicon, we invoke this + * callback. + * + * @see PlacesCompletionCallback in PlacesCompletionCallback.idl. */ - void replaceFaviconDataFromDataURL(in nsIURI aFaviconURI, - in AString aDataURL, - [optional] in PRTime aExpiration, - [optional] in nsIPrincipal aLoadingPrincipal); + void setFaviconForPage( + in nsIURI aPageURI, + in nsIURI aFaviconURI, + in nsIURI aDataURL, + [optional] in PRTime aExpiration, + [optional] in PlacesCompletionCallback aCallback + ); /** * Retrieves the favicon URI associated to the given page, if any. diff --git a/toolkit/components/places/tests/PlacesTestUtils.sys.mjs b/toolkit/components/places/tests/PlacesTestUtils.sys.mjs index 4e459d2e32..97dda6367f 100644 --- a/toolkit/components/places/tests/PlacesTestUtils.sys.mjs +++ b/toolkit/components/places/tests/PlacesTestUtils.sys.mjs @@ -156,6 +156,43 @@ export var PlacesTestUtils = Object.freeze({ await Promise.all(faviconPromises); }, + /* + * Helper function to call PlacesUtils.favicons.setFaviconForPage() and waits + * finishing setting. This function throws an error if the status of + * PlacesUtils.favicons.setFaviconForPage() is not success. + * + * @param {string or nsIURI} pageURI + * @param {string or nsIURI} faviconURI + * @param {string or nsIURI} faviconDataURL + * @param {Number} [optional] expiration + * @return {Promise} waits for finishing setting + */ + setFaviconForPage(pageURI, faviconURI, faviconDataURL, expiration = 0) { + return new Promise((resolve, reject) => { + lazy.PlacesUtils.favicons.setFaviconForPage( + pageURI instanceof Ci.nsIURI ? pageURI : Services.io.newURI(pageURI), + faviconURI instanceof Ci.nsIURI + ? faviconURI + : Services.io.newURI(faviconURI), + faviconDataURL instanceof Ci.nsIURI + ? faviconDataURL + : Services.io.newURI(faviconDataURL), + expiration, + status => { + if (Components.isSuccessCode(status)) { + resolve(status); + } else { + reject( + new Error( + `Failed to process setFaviconForPage(): status code = ${status}` + ) + ); + } + } + ); + }); + }, + /** * Clears any favicons stored in the database. */ diff --git a/toolkit/components/places/tests/browser/browser.toml b/toolkit/components/places/tests/browser/browser.toml index b7d688c980..aceee48f24 100644 --- a/toolkit/components/places/tests/browser/browser.toml +++ b/toolkit/components/places/tests/browser/browser.toml @@ -117,3 +117,15 @@ support-files = [ "favicon.html", "final.html", ] + +["browser_visituri_restriction.js"] +skip-if = [ + "verify", + "os == 'linux' && (asan || tsan)", # Bug 1891145 +] + +["browser_visituri_restriction_origin.js"] +skip-if = [ + "verify", + "os == 'linux' && (asan || tsan)", # Bug 1891145 +] diff --git a/toolkit/components/places/tests/browser/browser_visituri_restriction.js b/toolkit/components/places/tests/browser/browser_visituri_restriction.js new file mode 100644 index 0000000000..2af41e6f51 --- /dev/null +++ b/toolkit/components/places/tests/browser/browser_visituri_restriction.js @@ -0,0 +1,227 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const TEST_PAGE = `data:text/html, + https://example.com + http://example.com + https://www.example.com + https://example.org`; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + // Enable restriction feature. + ["places.history.floodingPrevention.enabled", true], + // Restrict from the second visit. + ["places.history.floodingPrevention.restrictionCount", 1], + ["places.history.floodingPrevention.restrictionExpireSeconds", 4], + // Not apply flooding prevention until some seconds elapse after user + // interaction begins. + [ + "places.history.floodingPrevention.maxSecondsFromLastUserInteraction", + 4, + ], + // To enable UserActivation by EventUtils.synthesizeMouseAtCenter() in + // ContentTask.spawn() in synthesizeVisitByUser(). + ["test.events.async.enabled", true], + ], + }); + await clearHistoryAndHistoryCache(); +}); + +add_task(async function basic() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: TEST_PAGE }, + async browser => { + info("Sanity check"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://www.example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://example.org/", { + visitCount: 0, + isVisited: false, + }); + + info("Visit https://example.com/ by user"); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 1, + isVisited: true, + }); + + info( + "Visit https://example.com/ by script within maxSecondsFromLastUserInteraction" + ); + await synthesizeVisitByScript(browser, "https://example.com/"); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 3, + isVisited: true, + }); + + await waitForPrefSeconds("maxSecondsFromLastUserInteraction"); + + info( + "Visit https://example.com/ by script without maxSecondsFromLastUserInteraction" + ); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 4, + isVisited: true, + }); + + info("Visit again, but it should be restricted"); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 4, + isVisited: true, + }); + + info("Check other"); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await assertLinkVisitedStatus(browser, "http://example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://www.example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://example.org/", { + visitCount: 0, + isVisited: false, + }); + } + ); + + await clearHistoryAndHistoryCache(); +}); + +add_task(async function expireRestriction() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: TEST_PAGE }, + async browser => { + info("Visit https://example.com/ by user"); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 1, + isVisited: true, + }); + + info( + "Visit https://example.com/ by script within maxSecondsFromLastUserInteraction" + ); + await synthesizeVisitByScript(browser, "https://example.com/"); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 3, + isVisited: true, + }); + + await waitForPrefSeconds("maxSecondsFromLastUserInteraction"); + + info( + "Visit https://example.com/ by script without maxSecondsFromLastUserInteraction" + ); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 4, + isVisited: true, + }); + + await waitForPrefSeconds("restrictionExpireSeconds"); + + info("Visit again, it should not be restricted"); + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 5, + isVisited: true, + }); + } + ); + + await clearHistoryAndHistoryCache(); +}); + +add_task(async function userInputAlwaysAcceptable() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: TEST_PAGE }, + async browser => { + info("Visit by user"); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 1, + isVisited: true, + }); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 2, + isVisited: true, + }); + + await waitForPrefSeconds("maxSecondsFromLastUserInteraction"); + + info("Visit by user input"); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 3, + isVisited: true, + }); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 4, + isVisited: true, + }); + } + ); + + await clearHistoryAndHistoryCache(); +}); + +add_task(async function disable() { + await SpecialPowers.pushPrefEnv({ + set: [["places.history.floodingPrevention.enabled", false]], + }); + + await BrowserTestUtils.withNewTab( + { gBrowser, url: TEST_PAGE }, + async browser => { + info("Any visits are stored"); + for (let i = 0; i < 3; i++) { + await synthesizeVisitByScript(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: i + 1, + isVisited: true, + }); + } + } + ); + + await clearHistoryAndHistoryCache(); +}); + +async function waitForPrefSeconds(pref) { + info(`Wait until elapsing ${pref}`); + return new Promise(r => + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + setTimeout( + r, + Services.prefs.getIntPref(`places.history.floodingPrevention.${pref}`) * + 1000 + + 100 + ) + ); +} diff --git a/toolkit/components/places/tests/browser/browser_visituri_restriction_origin.js b/toolkit/components/places/tests/browser/browser_visituri_restriction_origin.js new file mode 100644 index 0000000000..ee691c79e8 --- /dev/null +++ b/toolkit/components/places/tests/browser/browser_visituri_restriction_origin.js @@ -0,0 +1,92 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const TEST_PAGE = `data:text/html, + https://example.com + http://example.com + https://www.example.com + https://example.org`; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + // Enable restriction feature. + ["places.history.floodingPrevention.enabled", true], + // Restrict from the second visit. + ["places.history.floodingPrevention.restrictionCount", 1], + // Stop expiring. + ["places.history.floodingPrevention.restrictionExpireSeconds", 100], + // Always appply flooding preveition. + [ + "places.history.floodingPrevention.maxSecondsFromLastUserInteraction", + 0, + ], + // To enable UserActivation by EventUtils.synthesizeMouseAtCenter() in ContentTask.spawn() in synthesizeVisitByUser(). + ["test.events.async.enabled", true], + ], + }); +}); + +add_task(async function same_origin_but_other() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: TEST_PAGE }, + async browser => { + info("Sanity check"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 0, + isVisited: false, + }); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await assertLinkVisitedStatus(browser, "http://example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://www.example.com/", { + visitCount: 0, + isVisited: false, + }); + await assertLinkVisitedStatus(browser, "https://example.org/", { + visitCount: 0, + isVisited: false, + }); + + info("Visit https://example.com/ by user"); + await synthesizeVisitByUser(browser, "https://example.com/"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 1, + isVisited: true, + }); + + info("Visit others by Scripts"); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await synthesizeVisitByScript(browser, "http://example.com/"); + await synthesizeVisitByScript(browser, "https://www.example.com/"); + await synthesizeVisitByScript(browser, "https://example.org/"); + + info("Check the status"); + await assertLinkVisitedStatus(browser, "https://example.com/", { + visitCount: 1, + isVisited: true, + }); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await assertLinkVisitedStatus(browser, "http://example.com/", { + visitCount: 0, + isVisited: true, + }); + await assertLinkVisitedStatus(browser, "https://www.example.com/", { + visitCount: 0, + isVisited: true, + }); + await assertLinkVisitedStatus(browser, "https://example.org/", { + visitCount: 1, + isVisited: true, + }); + } + ); + + await clearHistoryAndHistoryCache(); +}); diff --git a/toolkit/components/places/tests/browser/head.js b/toolkit/components/places/tests/browser/head.js index b1b916ee29..da40a832c6 100644 --- a/toolkit/components/places/tests/browser/head.js +++ b/toolkit/components/places/tests/browser/head.js @@ -17,3 +17,80 @@ function whenNewWindowLoaded(aOptions, aCallback) { BrowserTestUtils.waitForNewWindow().then(aCallback); OpenBrowserWindow(aOptions); } + +async function clearHistoryAndHistoryCache() { + await PlacesUtils.history.clear(); + // Clear HistoryRestiction cache as well. + Cc["@mozilla.org/browser/history;1"] + .getService(Ci.mozIAsyncHistory) + .clearCache(); +} + +async function synthesizeVisitByUser(browser, url) { + let onNewTab = BrowserTestUtils.waitForNewTab(browser.ownerGlobal.gBrowser); + // We intentionally turn off this a11y check, because the following click is + // purposefully sent on an arbitrary web content that is not expected to be + // tested by itself with the browser mochitests, therefore this rule check + // shall be ignored by a11y_checks suite. + AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false }); + await ContentTask.spawn(browser, [url], async ([href]) => { + EventUtils.synthesizeMouseAtCenter( + content.document.querySelector(`a[href='${href}'`), + {}, + content + ); + }); + AccessibilityUtils.resetEnv(); + let tab = await onNewTab; + BrowserTestUtils.removeTab(tab); +} + +async function synthesizeVisitByScript(browser, url) { + let onNewTab = BrowserTestUtils.waitForNewTab(browser.ownerGlobal.gBrowser); + AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false }); + await ContentTask.spawn(browser, [url], async ([href]) => { + let a = content.document.querySelector(`a[href='${href}'`); + a.click(); + }); + AccessibilityUtils.resetEnv(); + let tab = await onNewTab; + BrowserTestUtils.removeTab(tab); +} + +async function assertLinkVisitedStatus( + browser, + url, + { visitCount: expectedVisitCount, isVisited: expectedVisited } +) { + await BrowserTestUtils.waitForCondition(async () => { + let visitCount = + (await PlacesTestUtils.getDatabaseValue("moz_places", "visit_count", { + url, + })) ?? 0; + + if (visitCount != expectedVisitCount) { + return false; + } + + Assert.equal(visitCount, expectedVisitCount, "The visit count is correct"); + return true; + }); + + await ContentTask.spawn( + browser, + [url, expectedVisited], + async ([href, visited]) => { + // ElementState::VISITED + const VISITED_STATE = 1 << 18; + await ContentTaskUtils.waitForCondition(() => { + let isVisited = !!( + content.InspectorUtils.getContentState( + content.document.querySelector(`a[href='${href}']`) + ) & VISITED_STATE + ); + return isVisited == visited; + }); + } + ); + Assert.ok(true, "The visited state is corerct"); +} diff --git a/toolkit/components/places/tests/chrome/test_cached_favicon.xhtml b/toolkit/components/places/tests/chrome/test_cached_favicon.xhtml index f7e7f4f1d8..1046574bdf 100644 --- a/toolkit/components/places/tests/chrome/test_cached_favicon.xhtml +++ b/toolkit/components/places/tests/chrome/test_cached_favicon.xhtml @@ -104,19 +104,12 @@ function test() // icon with a page explicitly in order for it to be visible through // the protocol. info("Replace favicon data"); - var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"] - .createInstance(Ci.nsIPrincipal); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - Services.io.newURI(tests[1].url), - tests[1].expectedIcon, - (Date.now() + 86400) * 1000, - systemPrincipal); - info("Set favicon data"); - PlacesUtils.favicons.setAndFetchFaviconForPage( + PlacesUtils.favicons.setFaviconForPage( Services.io.newURI("https://example.com/favicon_annotations"), Services.io.newURI(tests[1].url), - true, PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, null, - systemPrincipal); + Services.io.newURI(tests[1].expectedIcon), + (Date.now() + 86400) * 1000, + ); // And start our test process. loadNextTest(); diff --git a/toolkit/components/places/tests/expiration/test_debug_expiration.js b/toolkit/components/places/tests/expiration/test_debug_expiration.js index 204295d46c..22657e6b24 100644 --- a/toolkit/components/places/tests/expiration/test_debug_expiration.js +++ b/toolkit/components/places/tests/expiration/test_debug_expiration.js @@ -356,13 +356,7 @@ add_task(async function test_expire_icons() { } if (entry.icon) { - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - Services.io.newURI(entry.icon), - dataUrl, - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - await PlacesTestUtils.addFavicons(new Map([[entry.page, entry.icon]])); + await PlacesTestUtils.setFaviconForPage(entry.page, entry.icon, dataUrl); Assert.equal( await getFaviconUrlForPage(entry.page), entry.icon, @@ -380,13 +374,7 @@ add_task(async function test_expire_icons() { } if (entry.root) { - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - Services.io.newURI(entry.root), - dataUrl, - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - await PlacesTestUtils.addFavicons(new Map([[entry.page, entry.root]])); + await PlacesTestUtils.setFaviconForPage(entry.page, entry.root, dataUrl); } if (entry.iconExpired) { diff --git a/toolkit/components/places/tests/favicons/head_favicons.js b/toolkit/components/places/tests/favicons/head_favicons.js index afd2c4924f..73dd2a61ed 100644 --- a/toolkit/components/places/tests/favicons/head_favicons.js +++ b/toolkit/components/places/tests/favicons/head_favicons.js @@ -15,6 +15,9 @@ const systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); +// Used in createFavicon(). +let uniqueFaviconId = 0; + /** * Checks that the favicon for the given page matches the provided data. * @@ -24,6 +27,7 @@ const systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); * Expected MIME type of the icon, for example "image/png". * @param aExpectedData * Expected icon data, expressed as an array of byte values. + * If set null, skip the test for the favicon data. * @param aCallback * This function is called after the check finished. */ @@ -37,7 +41,9 @@ function checkFaviconDataForPage( aPageURI, async function (aURI, aDataLen, aData, aMimeType) { Assert.equal(aExpectedMimeType, aMimeType); - Assert.ok(compareArrays(aExpectedData, aData)); + if (aExpectedData) { + Assert.ok(compareArrays(aExpectedData, aData)); + } await check_guid_for_uri(aPageURI); aCallback(); } @@ -76,3 +82,82 @@ function promiseFaviconChanged(aExpectedPageURI, aExpectedFaviconURI) { }); }); } + +/** + * Create favicon file to temp directory. + * + * @param {string} aFileName + * File name that will be created in temp directory. + * @returns {object} + * { + * file: nsIFile, + * uri: nsIURI, + * data: byte Array, + * mimetype: String, + * } + */ +async function createFavicon(aFileName) { + // Copy the favicon file we have to the specified file in temp directory. + let originalFaviconFile = do_get_file("favicon-normal16.png"); + let tempDir = Services.dirsvc.get("TmpD", Ci.nsIFile); + let faviconFile = tempDir.clone(); + faviconFile.append(aFileName); + await IOUtils.copy(originalFaviconFile.path, faviconFile.path); + + // Append some data that sniffers/encoders will ignore that will distinguish + // the different favicons we'll create. + let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( + Ci.nsIFileOutputStream + ); + const WRONLY_PERMISSION = 0o600; + stream.init( + faviconFile, + FileUtils.MODE_WRONLY | FileUtils.MODE_APPEND, + WRONLY_PERMISSION, + 0 + ); + uniqueFaviconId++; + let uniqueStr = "uid:" + uniqueFaviconId; + stream.write(uniqueStr, uniqueStr.length); + stream.close(); + + Assert.equal(faviconFile.leafName.substr(0, aFileName.length), aFileName); + + return { + file: faviconFile, + uri: uri(faviconFile), + data: readFileData(faviconFile), + mimeType: "image/png", + }; +} + +/** + * Create nsIURI for given favicon object. + * + * @param {object} aFavicon + * Favicon object created by createFavicon(). + * @returns {nsIURI} + */ +async function createDataURLForFavicon(aFavicon) { + let dataURL = await toDataURL(aFavicon.data, aFavicon.mimeType); + return uri(dataURL); +} + +/** + * Create data URL string from given byte array and type. + * + * @param {Array} data + * Byte array. + * @param {string} type + * The type of this data. + * @returns {string} + */ +function toDataURL(data, type) { + let blob = new Blob([new Uint8Array(data)], { type }); + return new Promise((resolve, reject) => { + let reader = new FileReader(); + reader.addEventListener("load", () => resolve(reader.result)); + reader.addEventListener("error", reject); + reader.readAsDataURL(blob); + }); +} diff --git a/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js b/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js index c1f6689a70..52eb81ae85 100644 --- a/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js +++ b/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js @@ -68,14 +68,12 @@ add_task(async function () { info("Test that the content type of a favicon we add is correct."); let testURI = uri("http://mozilla.org/"); // Add the data before opening - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.addVisits(testURI); + await PlacesTestUtils.setFaviconForPage( + testURI, testIconURI, - testFaviconData, - 0, - systemPrincipal + testFaviconData ); - await PlacesTestUtils.addVisits(testURI); - await setFaviconForPage(testURI, testIconURI); // Open the channel let channel = NetUtil.newChannel({ uri: PlacesUtils.favicons.getFaviconLinkForIcon(testIconURI).spec, @@ -120,14 +118,12 @@ add_task(async function test_userpass() { CACHED_ICON_NORMAL, CACHED_ICON_USERPASS, ]) { - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.addVisits(pageURI); + await PlacesTestUtils.setFaviconForPage( + pageURI, iconURI, - testFaviconData, - 0, - systemPrincipal + testFaviconData ); - await PlacesTestUtils.addVisits(pageURI); - await setFaviconForPage(pageURI, iconURI); // Open the channel let channel = NetUtil.newChannel({ diff --git a/toolkit/components/places/tests/favicons/test_expire_on_new_icons.js b/toolkit/components/places/tests/favicons/test_expire_on_new_icons.js index d5a7c42ba3..f0089d737b 100644 --- a/toolkit/components/places/tests/favicons/test_expire_on_new_icons.js +++ b/toolkit/components/places/tests/favicons/test_expire_on_new_icons.js @@ -28,23 +28,23 @@ add_task(async function test_expire_associated() { ]; for (let icon of favicons) { - let data = readFileData(do_get_file(icon.name)); - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(TEST_URL + icon.name), - data, + let dataURL = await readFileDataAsDataURL( + do_get_file(icon.name), icon.mimeType ); - await setFaviconForPage(TEST_URL, TEST_URL + icon.name); + await PlacesTestUtils.setFaviconForPage( + TEST_URL, + TEST_URL + icon.name, + dataURL + ); if (icon.expired) { await expireIconRelationsForPage(TEST_URL); // Add the same icon to another page. - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(TEST_URL + icon.name), - data, - icon.mimeType, - icon.expire + await PlacesTestUtils.setFaviconForPage( + TEST_URL2, + TEST_URL + icon.name, + dataURL ); - await setFaviconForPage(TEST_URL2, TEST_URL + icon.name); } } @@ -88,13 +88,7 @@ add_task(async function test_expire_root() { // Insert an expired icon. let iconURI = NetUtil.newURI(pageURI.spec + "favicon-normal16.png"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - iconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal - ); - await setFaviconForPage(pageURI, iconURI); + await PlacesTestUtils.setFaviconForPage(pageURI, iconURI, SMALLPNG_DATA_URI); Assert.equal( await countEntries("moz_icons_to_pages"), 1, @@ -105,13 +99,11 @@ add_task(async function test_expire_root() { // Now insert a new root icon. let rootIconURI = NetUtil.newURI(pageURI.spec + "favicon.ico"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + pageURI, rootIconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal + SMALLPNG_DATA_URI ); - await setFaviconForPage(pageURI, rootIconURI); // Only the root icon should have survived. Assert.equal( diff --git a/toolkit/components/places/tests/favicons/test_favicons_conversions.js b/toolkit/components/places/tests/favicons/test_favicons_conversions.js index 28a0fffb7f..dd8a35c5ac 100644 --- a/toolkit/components/places/tests/favicons/test_favicons_conversions.js +++ b/toolkit/components/places/tests/favicons/test_favicons_conversions.js @@ -43,29 +43,24 @@ async function checkFaviconDataConversion( }); let faviconURI = NetUtil.newURI("http://places.test/icon/" + aFileName); let fileData = readFileOfLength(aFileName, aFileLength); + let fileDataURL = await fileDataToDataURL(fileData, aFileMimeType); + await PlacesTestUtils.setFaviconForPage( + pageURI.spec, + faviconURI.spec, + fileDataURL + ); - PlacesUtils.favicons.replaceFaviconData(faviconURI, fileData, aFileMimeType); await new Promise(resolve => { - PlacesUtils.favicons.setAndFetchFaviconForPage( - pageURI, - faviconURI, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - (aURI, aDataLen, aData, aMimeType) => { - if (!aExpectConversion) { - Assert.ok(compareArrays(aData, fileData)); - Assert.equal(aMimeType, aFileMimeType); - } else { - if (!aVaryOnWindows || !isWindows) { - let expectedFile = do_get_file("expected-" + aFileName + ".png"); - Assert.ok(compareArrays(aData, readFileData(expectedFile))); - } - Assert.equal(aMimeType, "image/png"); - } - resolve(); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); + if (!aExpectConversion) { + checkFaviconDataForPage(pageURI, aFileMimeType, fileData, resolve); + } else if (!aVaryOnWindows || !isWindows) { + let expectedFile = do_get_file("expected-" + aFileName + ".png"); + let expectedData = readFileData(expectedFile); + checkFaviconDataForPage(pageURI, "image/png", expectedData, resolve); + } else { + // Not check the favicon data. + checkFaviconDataForPage(pageURI, "image/png", null, resolve); + } }); } diff --git a/toolkit/components/places/tests/favicons/test_favicons_protocols_ref.js b/toolkit/components/places/tests/favicons/test_favicons_protocols_ref.js index aa0241a3d2..4d359f7307 100644 --- a/toolkit/components/places/tests/favicons/test_favicons_protocols_ref.js +++ b/toolkit/components/places/tests/favicons/test_favicons_protocols_ref.js @@ -9,21 +9,16 @@ const ICON32_URL = "http://places.test/favicon-normal32.png"; add_task(async function () { await PlacesTestUtils.addVisits(PAGE_URL); // Add 2 differently sized favicons for this page. - - let data = readFileData(do_get_file("favicon-normal16.png")); - PlacesUtils.favicons.replaceFaviconData( - Services.io.newURI(ICON16_URL), - data, + let dataURL16 = await readFileDataAsDataURL( + do_get_file("favicon-normal16.png"), "image/png" ); - await setFaviconForPage(PAGE_URL, ICON16_URL); - data = readFileData(do_get_file("favicon-normal32.png")); - PlacesUtils.favicons.replaceFaviconData( - Services.io.newURI(ICON32_URL), - data, + await PlacesTestUtils.setFaviconForPage(PAGE_URL, ICON16_URL, dataURL16); + let dataURL32 = await readFileDataAsDataURL( + do_get_file("favicon-normal32.png"), "image/png" ); - await setFaviconForPage(PAGE_URL, ICON32_URL); + await PlacesTestUtils.setFaviconForPage(PAGE_URL, ICON32_URL, dataURL32); const PAGE_ICON_URL = "page-icon:" + PAGE_URL; diff --git a/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js b/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js index 80f498f33f..8c6fb0a2bb 100644 --- a/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js +++ b/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js @@ -60,12 +60,8 @@ add_task(async function test_fallback() { info("Set icon for the root"); await PlacesTestUtils.addVisits(ROOT_URL); let data = readFileData(do_get_file("favicon-normal16.png")); - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(ROOT_ICON_URL), - data, - "image/png" - ); - await setFaviconForPage(ROOT_URL, ROOT_ICON_URL); + let dataURL = await fileDataToDataURL(data, "image/png"); + await PlacesTestUtils.setFaviconForPage(ROOT_URL, ROOT_ICON_URL, dataURL); info("check fallback icons"); await new Promise(resolve => { @@ -96,12 +92,8 @@ add_task(async function test_fallback() { info("Now add a proper icon for the page"); await PlacesTestUtils.addVisits(SUBPAGE_URL); let data32 = readFileData(do_get_file("favicon-normal32.png")); - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(ICON32_URL), - data32, - "image/png" - ); - await setFaviconForPage(SUBPAGE_URL, ICON32_URL); + let dataURL32 = await fileDataToDataURL(data32, "image/png"); + await PlacesTestUtils.setFaviconForPage(SUBPAGE_URL, ICON32_URL, dataURL32); info("check no fallback icons"); await new Promise(resolve => { diff --git a/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js b/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js index e8f459cb08..3fa11ae6c0 100644 --- a/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js +++ b/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js @@ -57,13 +57,11 @@ add_task(async function test_fallback() { info("Set icon for the root"); await PlacesTestUtils.addVisits(ROOT_URL); - let data = readFileData(do_get_file("favicon-normal16.png")); - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(ROOT_ICON_URL), - data, + let dataURL = await readFileDataAsDataURL( + do_get_file("favicon-normal16.png"), "image/png" ); - await setFaviconForPage(ROOT_URL, ROOT_ICON_URL); + await PlacesTestUtils.setFaviconForPage(ROOT_URL, ROOT_ICON_URL, dataURL); info("check fallback icons"); Assert.equal( @@ -79,13 +77,11 @@ add_task(async function test_fallback() { info("Now add a proper icon for the page"); await PlacesTestUtils.addVisits(SUBPAGE_URL); - let data32 = readFileData(do_get_file("favicon-normal32.png")); - PlacesUtils.favicons.replaceFaviconData( - NetUtil.newURI(ICON32_URL), - data32, + let dataURL32 = await readFileDataAsDataURL( + do_get_file("favicon-normal32.png"), "image/png" ); - await setFaviconForPage(SUBPAGE_URL, ICON32_URL); + await PlacesTestUtils.setFaviconForPage(SUBPAGE_URL, ICON32_URL, dataURL32); info("check no fallback icons"); Assert.equal( diff --git a/toolkit/components/places/tests/favicons/test_heavy_favicon.js b/toolkit/components/places/tests/favicons/test_heavy_favicon.js index 09adcaf6fa..4541de9bff 100644 --- a/toolkit/components/places/tests/favicons/test_heavy_favicon.js +++ b/toolkit/components/places/tests/favicons/test_heavy_favicon.js @@ -26,8 +26,8 @@ add_task(async function () { let pageURI = uri("http://foo.bar/"); await PlacesTestUtils.addVisits(pageURI); - PlacesUtils.favicons.replaceFaviconData(icon.uri, icon.data, icon.mimetype); - await setFaviconForPage(pageURI, icon.uri); + let dataURI = await fileDataToDataURL(icon.data, icon.mimetype); + await PlacesTestUtils.setFaviconForPage(pageURI.spec, icon.uri.spec, dataURI); Assert.equal( await getFaviconUrlForPage(pageURI), icon.uri.spec, diff --git a/toolkit/components/places/tests/favicons/test_incremental_vacuum.js b/toolkit/components/places/tests/favicons/test_incremental_vacuum.js index ab93121d47..2c1a5ad3f9 100644 --- a/toolkit/components/places/tests/favicons/test_incremental_vacuum.js +++ b/toolkit/components/places/tests/favicons/test_incremental_vacuum.js @@ -16,10 +16,9 @@ add_task(async function () { let url = "http://foo.bar/"; await PlacesTestUtils.addVisits(url); for (let i = 0; i < 10; ++i) { - let iconUri = NetUtil.newURI("http://mozilla.org/" + i); - let data = readFileData(icon.file); - PlacesUtils.favicons.replaceFaviconData(iconUri, data, icon.mimetype); - await setFaviconForPage(url, iconUri); + let iconUri = "http://mozilla.org/" + i; + let dataURL = await readFileDataAsDataURL(icon.file, icon.mimetype); + await PlacesTestUtils.setFaviconForPage(url, iconUri, dataURL); } let promise = TestUtils.topicObserved("places-favicons-expired"); diff --git a/toolkit/components/places/tests/favicons/test_multiple_frames.js b/toolkit/components/places/tests/favicons/test_multiple_frames.js index 5c7f585715..a6aae572de 100644 --- a/toolkit/components/places/tests/favicons/test_multiple_frames.js +++ b/toolkit/components/places/tests/favicons/test_multiple_frames.js @@ -14,9 +14,15 @@ add_task(async function () { let faviconURI = NetUtil.newURI("http://places.test/icon/favicon-multi.ico"); // Fake window. let win = { devicePixelRatio: 1.0 }; - let icoData = readFileData(do_get_file("favicon-multi.ico")); - PlacesUtils.favicons.replaceFaviconData(faviconURI, icoData, "image/x-icon"); - await setFaviconForPage(pageURI, faviconURI); + let icoDataURL = await readFileDataAsDataURL( + do_get_file("favicon-multi.ico"), + "image/x-icon" + ); + await PlacesTestUtils.setFaviconForPage( + pageURI.spec, + faviconURI.spec, + icoDataURL + ); for (let size of [16, 32, 64]) { let file = do_get_file(`favicon-multi-frame${size}.png`); diff --git a/toolkit/components/places/tests/favicons/test_page-icon_protocol.js b/toolkit/components/places/tests/favicons/test_page-icon_protocol.js index 287484868f..2241dec990 100644 --- a/toolkit/components/places/tests/favicons/test_page-icon_protocol.js +++ b/toolkit/components/places/tests/favicons/test_page-icon_protocol.js @@ -76,25 +76,12 @@ var gFavicon; add_task(async function setup() { await PlacesTestUtils.addVisits(TEST_URI); - - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + TEST_URI, ICON_URI, ICON_DATAURL, - (Date.now() + 8640000) * 1000, - Services.scriptSecurityManager.getSystemPrincipal() + (Date.now() + 8640000) * 1000 ); - - await new Promise(resolve => { - PlacesUtils.favicons.setAndFetchFaviconForPage( - TEST_URI, - ICON_URI, - false, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - resolve, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - gDefaultFavicon = await fetchIconForSpec( PlacesUtils.favicons.defaultFavicon.spec ); @@ -133,13 +120,11 @@ add_task(async function subpage_url_fallback() { add_task(async function svg_icon() { let faviconURI = NetUtil.newURI("http://places.test/favicon.svg"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + TEST_URI, faviconURI, - SMALLSVG_DATA_URI.spec, - 0, - Services.scriptSecurityManager.getSystemPrincipal() + SMALLSVG_DATA_URI ); - await setFaviconForPage(TEST_URI, faviconURI); let svgIcon = await fetchIconForSpec(SMALLSVG_DATA_URI.spec); info(svgIcon.contentType); let pageIcon = await fetchIconForSpec("page-icon:" + TEST_URI.spec); @@ -270,23 +255,8 @@ add_task(async function test_with_user_pass() { for (const { pageURI, iconURI } of testData) { for (const loadingIconURISpec of [PAGE_ICON_NORMAL, PAGE_ICON_USERPASS]) { - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - iconURI, - ICON_DATAURL, - 0, - systemPrincipal - ); await PlacesTestUtils.addVisits(pageURI); - await new Promise(resolve => { - PlacesUtils.favicons.setAndFetchFaviconForPage( - pageURI, - iconURI, - false, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - resolve, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); + await PlacesTestUtils.setFaviconForPage(pageURI, iconURI, ICON_DATAURL); let { data, contentType } = await fetchIconForSpec(loadingIconURISpec); Assert.equal(contentType, gFavicon.contentType); diff --git a/toolkit/components/places/tests/favicons/test_replaceFaviconData.js b/toolkit/components/places/tests/favicons/test_replaceFaviconData.js deleted file mode 100644 index 2e9835eaa9..0000000000 --- a/toolkit/components/places/tests/favicons/test_replaceFaviconData.js +++ /dev/null @@ -1,395 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/* - * Tests for replaceFaviconData() - */ - -var iconsvc = PlacesUtils.favicons; - -var originalFavicon = { - file: do_get_file("favicon-normal16.png"), - uri: uri(do_get_file("favicon-normal16.png")), - data: readFileData(do_get_file("favicon-normal16.png")), - mimetype: "image/png", -}; - -var uniqueFaviconId = 0; -function createFavicon(fileName) { - let tempdir = Services.dirsvc.get("TmpD", Ci.nsIFile); - - // remove any existing file at the path we're about to copy to - let outfile = tempdir.clone(); - outfile.append(fileName); - try { - outfile.remove(false); - } catch (e) {} - - originalFavicon.file.copyToFollowingLinks(tempdir, fileName); - - let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( - Ci.nsIFileOutputStream - ); - stream.init(outfile, 0x02 | 0x08 | 0x10, 0o600, 0); - - // append some data that sniffers/encoders will ignore that will distinguish - // the different favicons we'll create - uniqueFaviconId++; - let uniqueStr = "uid:" + uniqueFaviconId; - stream.write(uniqueStr, uniqueStr.length); - stream.close(); - - Assert.equal(outfile.leafName.substr(0, fileName.length), fileName); - - return { - file: outfile, - uri: uri(outfile), - data: readFileData(outfile), - mimetype: "image/png", - }; -} - -function checkCallbackSucceeded( - callbackMimetype, - callbackData, - sourceMimetype, - sourceData -) { - Assert.equal(callbackMimetype, sourceMimetype); - Assert.ok(compareArrays(callbackData, sourceData)); -} - -function run_test() { - // check that the favicon loaded correctly - Assert.equal(originalFavicon.data.length, 286); - run_next_test(); -} - -add_task(async function test_replaceFaviconData_validHistoryURI() { - info("test replaceFaviconData for valid history uri"); - - let pageURI = uri("http://test1.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let favicon = createFavicon("favicon1.png"); - - iconsvc.replaceFaviconData(favicon.uri, favicon.data, favicon.mimetype); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - favicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconData_validHistoryURI_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - dump("GOT " + aMimeType + "\n"); - checkCallbackSucceeded( - aMimeType, - aData, - favicon.mimetype, - favicon.data - ); - checkFaviconDataForPage( - pageURI, - favicon.mimetype, - favicon.data, - function test_replaceFaviconData_validHistoryURI_callback() { - favicon.file.remove(false); - resolve(); - } - ); - }, - systemPrincipal - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_overrideDefaultFavicon() { - info("test replaceFaviconData to override a later setAndFetchFaviconForPage"); - - let pageURI = uri("http://test2.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon2.png"); - let secondFavicon = createFavicon("favicon3.png"); - - iconsvc.replaceFaviconData( - firstFavicon.uri, - secondFavicon.data, - secondFavicon.mimetype - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconData_overrideDefaultFavicon_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconData_overrideDefaultFavicon_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - }, - systemPrincipal - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_replaceExisting() { - info( - "test replaceFaviconData to override a previous setAndFetchFaviconForPage" - ); - - let pageURI = uri("http://test3.bar"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon4.png"); - let secondFavicon = createFavicon("favicon5.png"); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconData_replaceExisting_firstSet_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - firstFavicon.mimetype, - firstFavicon.data - ); - checkFaviconDataForPage( - pageURI, - firstFavicon.mimetype, - firstFavicon.data, - function test_replaceFaviconData_overrideDefaultFavicon_firstCallback() { - iconsvc.replaceFaviconData( - firstFavicon.uri, - secondFavicon.data, - secondFavicon.mimetype - ); - PlacesTestUtils.promiseAsyncUpdates().then(() => { - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconData_overrideDefaultFavicon_secondCallback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - }, - systemPrincipal - ); - }); - } - ); - }, - systemPrincipal - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_unrelatedReplace() { - info("test replaceFaviconData to not make unrelated changes"); - - let pageURI = uri("http://test4.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let favicon = createFavicon("favicon6.png"); - let unrelatedFavicon = createFavicon("favicon7.png"); - - iconsvc.replaceFaviconData( - unrelatedFavicon.uri, - unrelatedFavicon.data, - unrelatedFavicon.mimetype - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - favicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconData_unrelatedReplace_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - favicon.mimetype, - favicon.data - ); - checkFaviconDataForPage( - pageURI, - favicon.mimetype, - favicon.data, - function test_replaceFaviconData_unrelatedReplace_callback() { - favicon.file.remove(false); - unrelatedFavicon.file.remove(false); - resolve(); - } - ); - }, - systemPrincipal - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_badInputs() { - info("test replaceFaviconData to throw on bad inputs"); - let icon = createFavicon("favicon8.png"); - - Assert.throws( - () => iconsvc.replaceFaviconData(icon.uri, icon.data, ""), - /NS_ERROR_ILLEGAL_VALUE/ - ); - Assert.throws( - () => iconsvc.replaceFaviconData(icon.uri, icon.data, "not-an-image"), - /NS_ERROR_ILLEGAL_VALUE/ - ); - Assert.throws( - () => iconsvc.replaceFaviconData(null, icon.data, icon.mimetype), - /NS_ERROR_ILLEGAL_VALUE/ - ); - Assert.throws( - () => iconsvc.replaceFaviconData(icon.uri, [], icon.mimetype), - /NS_ERROR_ILLEGAL_VALUE/ - ); - Assert.throws( - () => iconsvc.replaceFaviconData(icon.uri, null, icon.mimetype), - /NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY/ - ); - - icon.file.remove(false); - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_twiceReplace() { - info("test replaceFaviconData on multiple replacements"); - - let pageURI = uri("http://test5.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon9.png"); - let secondFavicon = createFavicon("favicon10.png"); - - iconsvc.replaceFaviconData( - firstFavicon.uri, - firstFavicon.data, - firstFavicon.mimetype - ); - iconsvc.replaceFaviconData( - firstFavicon.uri, - secondFavicon.data, - secondFavicon.mimetype - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconData_twiceReplace_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconData_twiceReplace_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - }, - systemPrincipal - ); - }, - systemPrincipal - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconData_rootOverwrite() { - info("test replaceFaviconData doesn't overwrite root = 1"); - - async function getRootValue(url) { - let db = await PlacesUtils.promiseDBConnection(); - let rows = await db.execute( - "SELECT root FROM moz_icons WHERE icon_url = :url", - { url } - ); - return rows[0].getResultByName("root"); - } - - const PAGE_URL = "http://rootoverwrite.bar/"; - let pageURI = Services.io.newURI(PAGE_URL); - const ICON_URL = "http://rootoverwrite.bar/favicon.ico"; - let iconURI = Services.io.newURI(ICON_URL); - - await PlacesTestUtils.addVisits(pageURI); - - let icon = createFavicon("favicon9.png"); - PlacesUtils.favicons.replaceFaviconData(iconURI, icon.data, icon.mimetype); - await PlacesTestUtils.addFavicons(new Map([[PAGE_URL, ICON_URL]])); - - Assert.equal(await getRootValue(ICON_URL), 1, "Check root == 1"); - let icon2 = createFavicon("favicon10.png"); - PlacesUtils.favicons.replaceFaviconData(iconURI, icon2.data, icon2.mimetype); - // replaceFaviconData doesn't have a callback, but we must wait its updated. - await PlacesTestUtils.promiseAsyncUpdates(); - Assert.equal(await getRootValue(ICON_URL), 1, "Check root did not change"); - - await PlacesUtils.history.clear(); -}); diff --git a/toolkit/components/places/tests/favicons/test_replaceFaviconDataFromDataURL.js b/toolkit/components/places/tests/favicons/test_replaceFaviconDataFromDataURL.js deleted file mode 100644 index c1b83fc8a7..0000000000 --- a/toolkit/components/places/tests/favicons/test_replaceFaviconDataFromDataURL.js +++ /dev/null @@ -1,537 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/* - * Tests for replaceFaviconData() - */ - -var iconsvc = PlacesUtils.favicons; - -var originalFavicon = { - file: do_get_file("favicon-normal16.png"), - uri: uri(do_get_file("favicon-normal16.png")), - data: readFileData(do_get_file("favicon-normal16.png")), - mimetype: "image/png", -}; - -var uniqueFaviconId = 0; -function createFavicon(fileName) { - let tempdir = Services.dirsvc.get("TmpD", Ci.nsIFile); - - // remove any existing file at the path we're about to copy to - let outfile = tempdir.clone(); - outfile.append(fileName); - try { - outfile.remove(false); - } catch (e) {} - - originalFavicon.file.copyToFollowingLinks(tempdir, fileName); - - let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( - Ci.nsIFileOutputStream - ); - stream.init(outfile, 0x02 | 0x08 | 0x10, 0o600, 0); - - // append some data that sniffers/encoders will ignore that will distinguish - // the different favicons we'll create - uniqueFaviconId++; - let uniqueStr = "uid:" + uniqueFaviconId; - stream.write(uniqueStr, uniqueStr.length); - stream.close(); - - Assert.equal(outfile.leafName.substr(0, fileName.length), fileName); - - return { - file: outfile, - uri: uri(outfile), - data: readFileData(outfile), - mimetype: "image/png", - }; -} - -function createDataURLForFavicon(favicon) { - return "data:" + favicon.mimetype + ";base64," + toBase64(favicon.data); -} - -function checkCallbackSucceeded( - callbackMimetype, - callbackData, - sourceMimetype, - sourceData -) { - Assert.equal(callbackMimetype, sourceMimetype); - Assert.ok(compareArrays(callbackData, sourceData)); -} - -function run_test() { - // check that the favicon loaded correctly - Assert.equal(originalFavicon.data.length, 286); - run_next_test(); -} - -add_task(async function test_replaceFaviconDataFromDataURL_validHistoryURI() { - info("test replaceFaviconDataFromDataURL for valid history uri"); - - let pageURI = uri("http://test1.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let favicon = createFavicon("favicon1.png"); - iconsvc.replaceFaviconDataFromDataURL( - favicon.uri, - createDataURLForFavicon(favicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - favicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_validHistoryURI_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - favicon.mimetype, - favicon.data - ); - checkFaviconDataForPage( - pageURI, - favicon.mimetype, - favicon.data, - function test_replaceFaviconDataFromDataURL_validHistoryURI_callback() { - favicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task( - async function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon() { - info( - "test replaceFaviconDataFromDataURL to override a later setAndFetchFaviconForPage" - ); - - let pageURI = uri("http://test2.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon2.png"); - let secondFavicon = createFavicon("favicon3.png"); - - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(secondFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); - } -); - -add_task(async function test_replaceFaviconDataFromDataURL_replaceExisting() { - info( - "test replaceFaviconDataFromDataURL to override a previous setAndFetchFaviconForPage" - ); - - let pageURI = uri("http://test3.bar"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon4.png"); - let secondFavicon = createFavicon("favicon5.png"); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_replaceExisting_firstSet_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - firstFavicon.mimetype, - firstFavicon.data - ); - checkFaviconDataForPage( - pageURI, - firstFavicon.mimetype, - firstFavicon.data, - function test_replaceFaviconDataFromDataURL_replaceExisting_firstCallback() { - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(secondFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconDataFromDataURL_replaceExisting_secondCallback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconDataFromDataURL_unrelatedReplace() { - info("test replaceFaviconDataFromDataURL to not make unrelated changes"); - - let pageURI = uri("http://test4.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let favicon = createFavicon("favicon6.png"); - let unrelatedFavicon = createFavicon("favicon7.png"); - - iconsvc.replaceFaviconDataFromDataURL( - unrelatedFavicon.uri, - createDataURLForFavicon(unrelatedFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - favicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_unrelatedReplace_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - favicon.mimetype, - favicon.data - ); - checkFaviconDataForPage( - pageURI, - favicon.mimetype, - favicon.data, - function test_replaceFaviconDataFromDataURL_unrelatedReplace_callback() { - favicon.file.remove(false); - unrelatedFavicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconDataFromDataURL_badInputs() { - info("test replaceFaviconDataFromDataURL to throw on bad inputs"); - - let favicon = createFavicon("favicon8.png"); - - let ex = null; - try { - iconsvc.replaceFaviconDataFromDataURL( - favicon.uri, - "", - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - } catch (e) { - ex = e; - } finally { - Assert.ok(!!ex); - } - - ex = null; - try { - iconsvc.replaceFaviconDataFromDataURL( - null, - createDataURLForFavicon(favicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - } catch (e) { - ex = e; - } finally { - Assert.ok(!!ex); - } - - favicon.file.remove(false); - - await PlacesUtils.history.clear(); -}); - -add_task(async function test_replaceFaviconDataFromDataURL_twiceReplace() { - info("test replaceFaviconDataFromDataURL on multiple replacements"); - - let pageURI = uri("http://test5.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon9.png"); - let secondFavicon = createFavicon("favicon10.png"); - - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(firstFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(secondFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_twiceReplace_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconDataFromDataURL_twiceReplace_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); -}); - -add_task( - async function test_replaceFaviconDataFromDataURL_afterRegularAssign() { - info("test replaceFaviconDataFromDataURL after replaceFaviconData"); - - let pageURI = uri("http://test6.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon11.png"); - let secondFavicon = createFavicon("favicon12.png"); - - iconsvc.replaceFaviconData( - firstFavicon.uri, - firstFavicon.data, - firstFavicon.mimetype - ); - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(secondFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_afterRegularAssign_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconDataFromDataURL_afterRegularAssign_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); - } -); - -add_task( - async function test_replaceFaviconDataFromDataURL_beforeRegularAssign() { - info("test replaceFaviconDataFromDataURL before replaceFaviconData"); - - let pageURI = uri("http://test7.bar/"); - await PlacesTestUtils.addVisits(pageURI); - - let firstFavicon = createFavicon("favicon13.png"); - let secondFavicon = createFavicon("favicon14.png"); - - iconsvc.replaceFaviconDataFromDataURL( - firstFavicon.uri, - createDataURLForFavicon(firstFavicon), - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - iconsvc.replaceFaviconData( - firstFavicon.uri, - secondFavicon.data, - secondFavicon.mimetype - ); - - await new Promise(resolve => { - iconsvc.setAndFetchFaviconForPage( - pageURI, - firstFavicon.uri, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - function test_replaceFaviconDataFromDataURL_beforeRegularAssign_check( - aURI, - aDataLen, - aData, - aMimeType - ) { - checkCallbackSucceeded( - aMimeType, - aData, - secondFavicon.mimetype, - secondFavicon.data - ); - checkFaviconDataForPage( - pageURI, - secondFavicon.mimetype, - secondFavicon.data, - function test_replaceFaviconDataFromDataURL_beforeRegularAssign_callback() { - firstFavicon.file.remove(false); - secondFavicon.file.remove(false); - resolve(); - } - ); - }, - Services.scriptSecurityManager.getSystemPrincipal() - ); - }); - - await PlacesUtils.history.clear(); - } -); - -/* toBase64 copied from image/test/unit/test_encoder_png.js */ - -/* Convert data (an array of integers) to a Base64 string. */ -const toBase64Table = - // eslint-disable-next-line no-useless-concat - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + "0123456789+/"; -const base64Pad = "="; -function toBase64(data) { - let result = ""; - let length = data.length; - let i; - // Convert every three bytes to 4 ascii characters. - for (i = 0; i < length - 2; i += 3) { - result += toBase64Table[data[i] >> 2]; - result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)]; - result += toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)]; - result += toBase64Table[data[i + 2] & 0x3f]; - } - - // Convert the remaining 1 or 2 bytes, pad out to 4 characters. - if (length % 3) { - i = length - (length % 3); - result += toBase64Table[data[i] >> 2]; - if (length % 3 == 2) { - result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)]; - result += toBase64Table[(data[i + 1] & 0x0f) << 2]; - result += base64Pad; - } else { - result += toBase64Table[(data[i] & 0x03) << 4]; - result += base64Pad + base64Pad; - } - } - - return result; -} diff --git a/toolkit/components/places/tests/favicons/test_root_icons.js b/toolkit/components/places/tests/favicons/test_root_icons.js index f0487cc162..5a101ed6a6 100644 --- a/toolkit/components/places/tests/favicons/test_root_icons.js +++ b/toolkit/components/places/tests/favicons/test_root_icons.js @@ -9,13 +9,11 @@ add_task(async function () { let pageURI = NetUtil.newURI("http://www.places.test/page/"); await PlacesTestUtils.addVisits(pageURI); let faviconURI = NetUtil.newURI("http://www.places.test/favicon.ico"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + pageURI, faviconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal + SMALLPNG_DATA_URI ); - await setFaviconForPage(pageURI, faviconURI); // Sanity checks. Assert.equal(await getFaviconUrlForPage(pageURI), faviconURI.spec); @@ -70,22 +68,18 @@ add_task(async function test_removePagesByTimeframe() { // Add a normal icon to the most recent page. let faviconURI = NetUtil.newURI(`${BASE_URL}/page/favicon.ico`); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + pageURI, faviconURI, - SMALLSVG_DATA_URI.spec, - 0, - systemPrincipal + SMALLSVG_DATA_URI ); - await setFaviconForPage(pageURI, faviconURI); // Add a root icon to the most recent page. let rootIconURI = NetUtil.newURI(`${BASE_URL}/favicon.ico`); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + pageURI, rootIconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal + SMALLPNG_DATA_URI ); - await setFaviconForPage(pageURI, rootIconURI); // Sanity checks. Assert.equal( @@ -141,13 +135,11 @@ add_task(async function test_different_host() { let pageURI = NetUtil.newURI("http://places.test/page/"); await PlacesTestUtils.addVisits(pageURI); let faviconURI = NetUtil.newURI("http://mozilla.test/favicon.ico"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( + await PlacesTestUtils.setFaviconForPage( + pageURI, faviconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal + SMALLPNG_DATA_URI ); - await setFaviconForPage(pageURI, faviconURI); Assert.equal( await getFaviconUrlForPage(pageURI), @@ -166,16 +158,25 @@ add_task(async function test_different_host() { add_task(async function test_same_size() { // Add two icons with the same size, one is a root icon. Check that the // non-root icon is preferred when a smaller size is requested. - let data = readFileData(do_get_file("favicon-normal32.png")); + let dataURL = await readFileDataAsDataURL( + do_get_file("favicon-normal32.png"), + "image/png" + ); let pageURI = NetUtil.newURI("http://new_places.test/page/"); await PlacesTestUtils.addVisits(pageURI); let faviconURI = NetUtil.newURI("http://new_places.test/favicon.ico"); - PlacesUtils.favicons.replaceFaviconData(faviconURI, data, "image/png"); - await setFaviconForPage(pageURI, faviconURI); + await PlacesTestUtils.setFaviconForPage( + pageURI.spec, + faviconURI.spec, + dataURL + ); faviconURI = NetUtil.newURI("http://new_places.test/another_icon.ico"); - PlacesUtils.favicons.replaceFaviconData(faviconURI, data, "image/png"); - await setFaviconForPage(pageURI, faviconURI); + await PlacesTestUtils.setFaviconForPage( + pageURI.spec, + faviconURI.spec, + dataURL + ); Assert.equal( await getFaviconUrlForPage(pageURI, 20), @@ -207,13 +208,7 @@ add_task(async function test_root_on_different_host() { // Root favicon for TEST_URL1. const ICON_URL = "http://places1.test/favicon.ico"; let iconURI = NetUtil.newURI(ICON_URL); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - iconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal - ); - await setFaviconForPage(pageURI1, iconURI); + await PlacesTestUtils.setFaviconForPage(pageURI1, iconURI, SMALLPNG_DATA_URI); Assert.equal(await getRootValue(ICON_URL), 1, "Check root == 1"); Assert.equal( await getFaviconUrlForPage(pageURI1, 16), @@ -222,13 +217,7 @@ add_task(async function test_root_on_different_host() { ); // Same favicon for TEST_URL2. - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - iconURI, - SMALLPNG_DATA_URI.spec, - 0, - systemPrincipal - ); - await setFaviconForPage(pageURI2, iconURI); + await PlacesTestUtils.setFaviconForPage(pageURI2, iconURI, SMALLPNG_DATA_URI); Assert.equal(await getRootValue(ICON_URL), 1, "Check root == 1"); Assert.equal( await getFaviconUrlForPage(pageURI2, 16), diff --git a/toolkit/components/places/tests/favicons/test_setFaviconForPage.js b/toolkit/components/places/tests/favicons/test_setFaviconForPage.js new file mode 100644 index 0000000000..22364e5410 --- /dev/null +++ b/toolkit/components/places/tests/favicons/test_setFaviconForPage.js @@ -0,0 +1,245 @@ +/* Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Tests for setFaviconForPage() + */ + +add_task(async function test_validHistoryURI() { + let pageURI = uri("http://test1.bar/"); + await PlacesTestUtils.addVisits(pageURI); + + let favicon = await createFavicon("favicon1.png"); + + await doTestSetFaviconForPage({ + pageURI, + faviconURI: favicon.uri, + dataURL: await createDataURLForFavicon(favicon), + expectedFaviconData: favicon.data, + expectedFaviconMimeType: favicon.mimeType, + }); + + await IOUtils.remove(favicon.file.path); + await PlacesUtils.history.clear(); +}); + +add_task(async function test_overrideDefaultFavicon() { + let pageURI = uri("http://test2.bar/"); + await PlacesTestUtils.addVisits(pageURI); + + let firstFavicon = await createFavicon("favicon2.png"); + let secondFavicon = await createFavicon("favicon3.png"); + + await doTestSetFaviconForPage({ + pageURI, + faviconURI: firstFavicon.uri, + dataURL: await createDataURLForFavicon(secondFavicon), + expectedFaviconData: secondFavicon.data, + expectedFaviconMimeType: secondFavicon.mimeType, + }); + + await IOUtils.remove(firstFavicon.file.path); + await IOUtils.remove(secondFavicon.file.path); + await PlacesUtils.history.clear(); +}); + +add_task(async function test_replaceExisting() { + let pageURI = uri("http://test3.bar"); + await PlacesTestUtils.addVisits(pageURI); + + let firstFavicon = await createFavicon("favicon4.png"); + let secondFavicon = await createFavicon("favicon5.png"); + + await new Promise(resolve => { + PlacesUtils.favicons.setAndFetchFaviconForPage( + pageURI, + firstFavicon.uri, + true, + PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, + function test_replaceExisting_firstSet_check( + aURI, + aDataLen, + aData, + aMimeType + ) { + Assert.equal(aMimeType, firstFavicon.mimeType); + Assert.ok(compareArrays(aData, firstFavicon.data)); + checkFaviconDataForPage( + pageURI, + firstFavicon.mimeType, + firstFavicon.data, + resolve + ); + }, + Services.scriptSecurityManager.getSystemPrincipal() + ); + }); + + await doTestSetFaviconForPage({ + pageURI, + faviconURI: firstFavicon.uri, + dataURL: await createDataURLForFavicon(secondFavicon), + expectedFaviconData: secondFavicon.data, + expectedFaviconMimeType: secondFavicon.mimeType, + }); + + await IOUtils.remove(firstFavicon.file.path); + await IOUtils.remove(secondFavicon.file.path); + await PlacesUtils.history.clear(); +}); + +add_task(async function test_twiceReplace() { + let pageURI = uri("http://test5.bar/"); + await PlacesTestUtils.addVisits(pageURI); + + let firstFavicon = await createFavicon("favicon9.png"); + let secondFavicon = await createFavicon("favicon10.png"); + + let firstFaviconDataURL = await createDataURLForFavicon(firstFavicon); + await new Promise(resolve => { + PlacesUtils.favicons.setFaviconForPage( + pageURI, + firstFavicon.uri, + firstFaviconDataURL, + null, + resolve + ); + }); + + await doTestSetFaviconForPage({ + pageURI, + faviconURI: firstFavicon.uri, + dataURL: await createDataURLForFavicon(secondFavicon), + expectedFaviconData: secondFavicon.data, + expectedFaviconMimeType: secondFavicon.mimeType, + }); + + await IOUtils.remove(firstFavicon.file.path); + await IOUtils.remove(secondFavicon.file.path); + await PlacesUtils.history.clear(); +}); + +add_task(async function test_userpass() { + let pageURI = uri("http://user:pass@test1.bar/"); + await PlacesTestUtils.addVisits(pageURI); + + let favicon = await createFavicon("favicon1.png"); + let faviconURI = uri("http://user:pass@test1.bar/favicon1.png"); + + await doTestSetFaviconForPage({ + pageURI, + faviconURI, + dataURL: await createDataURLForFavicon(favicon), + expectedFaviconData: favicon.data, + expectedFaviconMimeType: favicon.mimeType, + }); + + await IOUtils.remove(favicon.file.path); + await PlacesUtils.history.clear(); +}); + +add_task(async function test_svg() { + let pageURI = uri("http://example.com/"); + await PlacesTestUtils.addVisits(pageURI); + + const svgContent = ""; + + await doTestSetFaviconForPage({ + pageURI, + faviconURI: uri("http://example.com/favicon.svg"), + dataURL: uri(`data:image/svg+xml;utf8,${svgContent}`), + expectedFaviconData: Array.from(new TextEncoder().encode(svgContent)), + expectedFaviconMimeType: "image/svg+xml", + }); + + await PlacesUtils.history.clear(); +}); + +add_task(async function test_invalidPageURI() { + await PlacesTestUtils.addVisits(uri("http://example.com/")); + let favicon = await createFavicon("favicon-invalidPageURI.png"); + + for (let invalidURI of [null, "", "http://example.com"]) { + try { + info(`Invalid page URI test for [${invalidURI}]`); + PlacesUtils.favicons.setFaviconForPage( + invalidURI, + favicon.uri, + await createDataURLForFavicon(favicon) + ); + Assert.ok(false, "Error should happened"); + } catch (e) { + Assert.ok(true, `Expected error happend [${e.message}]`); + } + } +}); + +add_task(async function test_invalidFaviconURI() { + let pageURI = uri("http://example.com/"); + await PlacesTestUtils.addVisits(pageURI); + let favicon = await createFavicon("favicon-invalidFaviconURI.png"); + + for (let invalidURI of [null, "", favicon.uri.spec]) { + try { + info(`Invalid favicon URI test for [${invalidURI}]`); + PlacesUtils.favicons.setFaviconForPage( + pageURI, + invalidURI, + await createDataURLForFavicon(favicon) + ); + Assert.ok(false, "Error should happened"); + } catch (e) { + Assert.ok(true, `Expected error happend [${e.message}]`); + } + } +}); + +add_task(async function test_invalidFaviconDataURI() { + let pageURI = uri("http://example.com/"); + await PlacesTestUtils.addVisits(pageURI); + let favicon = createFavicon("favicon-invalidFaviconDataURI.png"); + + for (let invalidURI of [ + null, + "", + "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==", + ]) { + try { + info(`Invalid favicon data URI test for [${invalidURI}]`); + PlacesUtils.favicons.setFaviconForPage(pageURI, favicon.uri, invalidURI); + Assert.ok(false, "Error should happened"); + } catch (e) { + Assert.ok(true, `Expected error happend [${e.message}]`); + } + } +}); + +async function doTestSetFaviconForPage({ + pageURI, + faviconURI, + dataURL, + expectedFaviconData, + expectedFaviconMimeType, +}) { + let result = await new Promise(resolve => { + PlacesUtils.favicons.setFaviconForPage( + pageURI, + faviconURI, + dataURL, + null, + resolve + ); + }); + + info("Check the result of setFaviconForPage"); + Assert.equal(result, 0); + + await new Promise(resolve => { + checkFaviconDataForPage( + pageURI, + expectedFaviconMimeType, + expectedFaviconData, + resolve + ); + }); +} diff --git a/toolkit/components/places/tests/favicons/xpcshell.toml b/toolkit/components/places/tests/favicons/xpcshell.toml index 997aa48e0b..2716e72fda 100644 --- a/toolkit/components/places/tests/favicons/xpcshell.toml +++ b/toolkit/components/places/tests/favicons/xpcshell.toml @@ -57,10 +57,6 @@ support-files = [ ["test_query_result_favicon_changed_on_child.js"] -["test_replaceFaviconData.js"] - -["test_replaceFaviconDataFromDataURL.js"] - ["test_root_icons.js"] ["test_setAndFetchFaviconForPage.js"] @@ -69,4 +65,6 @@ support-files = [ ["test_setAndFetchFaviconForPage_redirects.js"] +["test_setFaviconForPage.js"] + ["test_svg_favicon.js"] diff --git a/toolkit/components/places/tests/gtest/places_test_harness_tail.h b/toolkit/components/places/tests/gtest/places_test_harness_tail.h index 0464d14e0d..27de44eaa9 100644 --- a/toolkit/components/places/tests/gtest/places_test_harness_tail.h +++ b/toolkit/components/places/tests/gtest/places_test_harness_tail.h @@ -20,7 +20,7 @@ class RunNextTest : public mozilla::Runnable { public: RunNextTest() : mozilla::Runnable("RunNextTest") {} NS_IMETHOD Run() override { - NS_ASSERTION(NS_IsMainThread(), "Not running on the main thread?"); + MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?"); if (gTestsIndex < int(mozilla::ArrayLength(gTests))) { do_test_pending(); Test& test = gTests[gTestsIndex++]; @@ -47,7 +47,7 @@ void run_next_test() { int gPendingTests = 0; void do_test_pending() { - NS_ASSERTION(NS_IsMainThread(), "Not running on the main thread?"); + MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?"); if (kDebugRunNextTest) { printf_stderr("do_test_pending()\n"); MozWalkTheStack(stderr); @@ -56,8 +56,8 @@ void do_test_pending() { } void do_test_finished() { - NS_ASSERTION(NS_IsMainThread(), "Not running on the main thread?"); - NS_ASSERTION(gPendingTests > 0, "Invalid pending test count!"); + MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?"); + MOZ_RELEASE_ASSERT(gPendingTests > 0, "Invalid pending test count!"); gPendingTests--; } diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index d7a465786e..22d89db139 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -169,7 +169,6 @@ function readFileData(aFile) { } return bytes; } - /** * Reads the data from the named file, verifying the expected file length. * @@ -186,6 +185,42 @@ function readFileOfLength(aFileName, aExpectedLength) { return data; } +/** + * Reads the data from the specified nsIFile, then returns it as data URL. + * + * @param file + * The nsIFile to read from. + * @param mimeType + * The mime type of the file content. + * @return Promise that retunes data URL. + */ +async function readFileDataAsDataURL(file, mimeType) { + const data = readFileData(file); + return fileDataToDataURL(data, mimeType); +} + +/** + * Converts the given data to the data URL. + * + * @param data + * The file data. + * @param mimeType + * The mime type of the file content. + * @return Promise that retunes data URL. + */ +async function fileDataToDataURL(data, mimeType) { + const dataURL = await new Promise(resolve => { + const buffer = new Uint8ClampedArray(data); + const blob = new Blob([buffer], { type: mimeType }); + const reader = new FileReader(); + reader.onload = e => { + resolve(e.target.result); + }; + reader.readAsDataURL(blob); + }); + return dataURL; +} + /** * Returns the base64-encoded version of the given string. This function is * similar to window.btoa, but is available to xpcshell tests also. diff --git a/toolkit/components/places/tests/history/test_remove.js b/toolkit/components/places/tests/history/test_remove.js index c018a996f3..8c469b5930 100644 --- a/toolkit/components/places/tests/history/test_remove.js +++ b/toolkit/components/places/tests/history/test_remove.js @@ -292,20 +292,7 @@ add_task(async function test_orphans() { ); // Also create a root icon. let faviconURI = Services.io.newURI(uri.spec + "favicon.ico"); - PlacesUtils.favicons.replaceFaviconDataFromDataURL( - faviconURI, - SMALLPNG_DATA_URI.spec, - 0, - Services.scriptSecurityManager.getSystemPrincipal() - ); - PlacesUtils.favicons.setAndFetchFaviconForPage( - uri, - faviconURI, - true, - PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - null, - Services.scriptSecurityManager.getSystemPrincipal() - ); + await PlacesTestUtils.setFaviconForPage(uri, faviconURI, SMALLPNG_DATA_URI); await PlacesUtils.history.update({ url: uri, diff --git a/toolkit/components/places/tests/unit/test_PlacesQuery_history.js b/toolkit/components/places/tests/unit/test_PlacesQuery_history.js index 9546e03730..24a046bcdc 100644 --- a/toolkit/components/places/tests/unit/test_PlacesQuery_history.js +++ b/toolkit/components/places/tests/unit/test_PlacesQuery_history.js @@ -3,6 +3,10 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); + const { PlacesQuery } = ChromeUtils.importESModule( "resource://gre/modules/PlacesQuery.sys.mjs" ); @@ -243,3 +247,32 @@ add_task(async function test_search_visits() { await PlacesUtils.history.clear(); }); + +add_task(async function test_search_interrupt() { + const { promise, reject } = Promise.withResolvers(); + const mockDatabase = { + executeCached: async (_, { query }) => { + if (query === "First Query") { + // Simulate a slow-running query which runs long enough to be + // interrupted by the next one. + await promise; + } + return []; + }, + interrupt: () => reject("interrupt() was called."), + }; + const stub = sinon + .stub(PlacesUtils, "promiseLargeCacheDBConnection") + .resolves(mockDatabase); + + const promiseFirstQuery = placesQuery.searchHistory("First Query"); + const promiseSecondQuery = placesQuery.searchHistory("Second Query"); + await Assert.rejects( + promiseFirstQuery, + /interrupt/, + "The first query was interrupted." + ); + ok(await promiseSecondQuery, "The second query resolved normally."); + + stub.restore(); +}); diff --git a/toolkit/components/processtools/tests/browser/browser_test_powerMetrics.js b/toolkit/components/processtools/tests/browser/browser_test_powerMetrics.js index 0ebaaa969e..7119299b8b 100644 --- a/toolkit/components/processtools/tests/browser/browser_test_powerMetrics.js +++ b/toolkit/components/processtools/tests/browser/browser_test_powerMetrics.js @@ -12,7 +12,7 @@ function GetTestWebBasedURL(fileName) { return ( getRootDirectory(gTestPath).replace( "chrome://mochitests/content", - "http://example.org" + "https://example.org" ) + fileName ); } @@ -372,7 +372,7 @@ add_task(async function test_tracker_power() { [ GetTestWebBasedURL("dummy.html").replace( "example.org", - "trackertest.org" + "itisatracker.org" ), ], async frameUrl => { diff --git a/toolkit/components/prompts/content/selectDialog.css b/toolkit/components/prompts/content/selectDialog.css new file mode 100644 index 0000000000..923cb114d2 --- /dev/null +++ b/toolkit/components/prompts/content/selectDialog.css @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +:root { + min-width: 29em; +} + +#selectContainer { + max-width: 45em; + margin: 5px; +} diff --git a/toolkit/components/prompts/content/selectDialog.js b/toolkit/components/prompts/content/selectDialog.js index 86809bc879..30d7de5c69 100644 --- a/toolkit/components/prompts/content/selectDialog.js +++ b/toolkit/components/prompts/content/selectDialog.js @@ -30,7 +30,8 @@ function onDCL() { document.title = propBag.getProperty("title"); let text = propBag.getProperty("text"); - document.getElementById("info.txt").setAttribute("value", text); + let element = document.getElementById("info.txt"); + element.appendChild(document.createTextNode(text)); let items = propBag.getProperty("list"); listBox = document.getElementById("list"); diff --git a/toolkit/components/prompts/content/selectDialog.xhtml b/toolkit/components/prompts/content/selectDialog.xhtml index 59918cdce0..70d0bbfdfd 100644 --- a/toolkit/components/prompts/content/selectDialog.xhtml +++ b/toolkit/components/prompts/content/selectDialog.xhtml @@ -10,13 +10,19 @@ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" > - + + + + - - + + diff --git a/toolkit/components/prompts/jar.mn b/toolkit/components/prompts/jar.mn index 7a904c4363..e1eefe2149 100644 --- a/toolkit/components/prompts/jar.mn +++ b/toolkit/components/prompts/jar.mn @@ -9,3 +9,4 @@ toolkit.jar: content/global/commonDialog.css (content/commonDialog.css) content/global/selectDialog.js (content/selectDialog.js) content/global/selectDialog.xhtml (content/selectDialog.xhtml) + content/global/selectDialog.css (content/selectDialog.css) diff --git a/toolkit/components/prompts/test/chromeScript.js b/toolkit/components/prompts/test/chromeScript.js index f873c5d04b..cfcc2591c8 100644 --- a/toolkit/components/prompts/test/chromeScript.js +++ b/toolkit/components/prompts/test/chromeScript.js @@ -74,7 +74,7 @@ function getSelectState(ui) { let listbox = ui.getElementById("list"); let state = {}; - state.msg = ui.getElementById("info.txt").value; + state.msg = ui.getElementById("info.txt").firstChild.textContent; state.selectedIndex = listbox.selectedIndex; state.items = []; diff --git a/toolkit/components/reader/AboutReader.sys.mjs b/toolkit/components/reader/AboutReader.sys.mjs index 75776b619f..57fa9d5b48 100644 --- a/toolkit/components/reader/AboutReader.sys.mjs +++ b/toolkit/components/reader/AboutReader.sys.mjs @@ -25,15 +25,19 @@ ChromeUtils.defineLazyGetter( "pluralRules", () => new Services.intl.PluralRules(undefined) ); +ChromeUtils.defineLazyGetter( + lazy, + "l10n", + () => new Localization(["toolkit/about/aboutReader.ftl"], true) +); const COLORSCHEME_L10N_IDS = { - auto: "about-reader-color-theme-auto", - light: "about-reader-color-theme-light", - dark: "about-reader-color-theme-dark", - sepia: "about-reader-color-theme-sepia", - contrast: "about-reader-color-theme-contrast", - gray: "about-reader-color-theme-gray", - custom: "about-reader-color-theme-custom", + auto: "about-reader-color-auto-theme", + light: "about-reader-color-light-theme", + dark: "about-reader-color-dark-theme", + sepia: "about-reader-color-sepia-theme", + contrast: "about-reader-color-contrast-theme", + gray: "about-reader-color-gray-theme", }; const CUSTOM_THEME_COLOR_INPUTS = [ @@ -201,6 +205,7 @@ export var AboutReader = function ( if (Services.prefs.getBoolPref("reader.colors_menu.enabled", false)) { doc.getElementById("regular-color-scheme").hidden = true; doc.getElementById("custom-colors-color-scheme").hidden = false; + this._setupSegmentedButton( "colors-menu-color-scheme-buttons", colorsMenuColorSchemeOptions, @@ -243,13 +248,140 @@ export var AboutReader = function ( ]; let fontType = Services.prefs.getCharPref("reader.font_type"); - this._setupSegmentedButton( - "font-type-buttons", - fontTypeOptions, - fontType, - this._setFontType.bind(this) - ); - this._setFontType(fontType); + + // Differentiates between the tick mark labels for width vs spacing controls + // for localization purposes. + const [narrowWidthLabel, wideWidthLabel] = lazy.l10n.formatMessagesSync([ + "about-reader-slider-label-width-narrow", + "about-reader-slider-label-width-wide", + ]); + const [narrowSpacingLabel, standardSpacingLabel, wideSpacingLabel] = + lazy.l10n.formatMessagesSync([ + "about-reader-slider-label-spacing-narrow", + "about-reader-slider-label-spacing-standard", + "about-reader-slider-label-spacing-wide", + ]); + + let contentWidthSliderOptions = { + min: 1, + max: 9, + ticks: 9, + tickLabels: `["${narrowWidthLabel.value}", "${wideWidthLabel.value}"]`, + l10nId: "about-reader-content-width-label", + icon: "chrome://global/skin/reader/content-width-20.svg", + }; + + let lineSpacingSliderOptions = { + min: 1, + max: 9, + ticks: 9, + tickLabels: `["${narrowSpacingLabel.value}", "${wideSpacingLabel.value}"]`, + l10nId: "about-reader-line-spacing-label", + icon: "chrome://global/skin/reader/line-spacing-20.svg", + }; + + let characterSpacingSliderOptions = { + min: 1, + max: 9, + ticks: 9, + tickLabels: `["${standardSpacingLabel.value}", "${wideSpacingLabel.value}"]`, + l10nId: "about-reader-character-spacing-label", + icon: "chrome://global/skin/reader/character-spacing-20.svg", + }; + + let wordSpacingSliderOptions = { + min: 1, + max: 9, + ticks: 9, + tickLabels: `["${standardSpacingLabel.value}", "${wideSpacingLabel.value}"]`, + l10nId: "about-reader-word-spacing-label", + icon: "chrome://global/skin/reader/word-spacing-20.svg", + }; + + let textAlignmentOptions = [ + { + l10nId: "about-reader-text-alignment-left", + groupName: "text-alignment", + value: "left", + itemClass: "left-align-button", + }, + { + l10nId: "about-reader-text-alignment-center", + groupName: "text-alignment", + value: "center", + itemClass: "center-align-button", + }, + { + l10nId: "about-reader-text-alignment-right", + groupName: "text-alignment", + value: "right", + itemClass: "right-align-button", + }, + ]; + + // If the page is rtl, reverse order of text alignment options. + if (isAppLocaleRTL) { + textAlignmentOptions = textAlignmentOptions.reverse(); + } + + if (Services.prefs.getBoolPref("reader.improved_text_menu.enabled", false)) { + doc.getElementById("regular-text-menu").hidden = true; + doc.getElementById("improved-text-menu").hidden = false; + + let contentWidth = Services.prefs.getIntPref("reader.content_width"); + this._setupSlider( + "content-width", + contentWidthSliderOptions, + contentWidth, + this._setContentWidthSlider.bind(this) + ); + this._setContentWidthSlider(contentWidth); + + let lineSpacing = Services.prefs.getIntPref("reader.line_height"); + this._setupSlider( + "line-spacing", + lineSpacingSliderOptions, + lineSpacing, + this._setLineSpacing.bind(this) + ); + this._setLineSpacing(lineSpacing); + + let characterSpacing = Services.prefs.getStringPref( + "reader.character_spacing" + ); + this._setupSlider( + "character-spacing", + characterSpacingSliderOptions, + characterSpacing, + this._setCharacterSpacing.bind(this) + ); + this._setCharacterSpacing(characterSpacing); + + let wordSpacing = Services.prefs.getStringPref("reader.word_spacing"); + this._setupSlider( + "word-spacing", + wordSpacingSliderOptions, + wordSpacing, + this._setWordSpacing.bind(this) + ); + this._setWordSpacing(wordSpacing); + + let textAlignment = Services.prefs.getCharPref("reader.text_alignment"); + this._setupSegmentedButton( + "text-alignment-buttons", + textAlignmentOptions, + textAlignment, + this._setTextAlignment.bind(this) + ); + this._setTextAlignment(textAlignment); + } else { + this._setupSegmentedButton( + "font-type-buttons", + fontTypeOptions, + fontType, + this._setFontType.bind(this) + ); + } this._setupFontSizeButtons(); @@ -257,6 +389,8 @@ export var AboutReader = function ( this._setupLineHeightButtons(); + this._setFontType(fontType); + if (win.speechSynthesis && Services.prefs.getBoolPref("narrate.enabled")) { new lazy.NarrateControls(win, this._languagePromise); } @@ -775,6 +909,80 @@ AboutReader.prototype = { ); }, + _setupSlider(id, options, initialValue, callback) { + let doc = this._doc; + let slider = doc.createElement("moz-slider"); + + slider.setAttribute("min", options.min); + slider.setAttribute("max", options.max); + slider.setAttribute("value", initialValue); + slider.setAttribute("ticks", options.ticks); + slider.setAttribute("tick-labels", options.tickLabels); + slider.setAttribute("data-l10n-id", options.l10nId); + slider.setAttribute("data-l10n-attrs", "label"); + slider.setAttribute("slider-icon", options.icon); + + slider.addEventListener("slider-changed", e => { + callback(e.detail); + }); + + let sliderContainer = doc.getElementById(`${id}-slider`); + sliderContainer.appendChild(slider); + }, + + // Rename this function to setContentWidth when the old menu is retired. + _setContentWidthSlider(newContentWidth) { + // We map the slider range [1-9] to 20-60em. + let width = 20 + 5 * (newContentWidth - 1) + "em"; + this._doc.body.style.setProperty("--content-width", width); + this._scheduleToolbarOverlapHandler(); + return lazy.AsyncPrefs.set( + "reader.content_width", + parseInt(newContentWidth) + ); + }, + + _setLineSpacing(newLineSpacing) { + // We map the slider range [1-9] to 1-2.6em. + let spacing = 1 + 0.2 * (newLineSpacing - 1) + "em"; + this._containerElement.style.setProperty("--line-height", spacing); + return lazy.AsyncPrefs.set("reader.line_height", parseInt(newLineSpacing)); + }, + + _setCharacterSpacing(newCharSpacing) { + // We map the slider range [1-9] to 0-0.24em. + let spacing = (newCharSpacing - 1) * 0.03; + this._containerElement.style.setProperty( + "--letter-spacing", + `${parseFloat(spacing).toFixed(2)}em` + ); + lazy.AsyncPrefs.set("reader.character_spacing", newCharSpacing); + }, + + _setWordSpacing(newWordSpacing) { + // We map the slider range [1-9] to 0-0.4em. + let spacing = (newWordSpacing - 1) * 0.05; + this._containerElement.style.setProperty( + "--word-spacing", + `${parseFloat(spacing).toFixed(2)}em` + ); + lazy.AsyncPrefs.set("reader.word_spacing", newWordSpacing); + }, + + _setTextAlignment(newTextAlignment) { + if (this._textAlignment === newTextAlignment) { + return false; + } + + this._containerElement.style.setProperty( + "--text-alignment", + newTextAlignment + ); + + lazy.AsyncPrefs.set("reader.text_alignment", newTextAlignment); + return true; + }, + _setColorScheme(newColorScheme) { // There's nothing to change if the new color scheme is the same as our current scheme. if (this._colorScheme === newColorScheme) { @@ -823,7 +1031,11 @@ AboutReader.prototype = { // The input event for the last selected segmented button is fired // upon loading a reader article in the same session. To prevent it // from overwriting custom colors, we return false. - if (this._colorScheme == "custom" && fromInputEvent) { + const colorsMenuEnabled = Services.prefs.getBoolPref( + "reader.colors_menu.enabled", + false + ); + if (colorsMenuEnabled && this._colorScheme == "custom" && fromInputEvent) { lastSelectedTheme = colorSchemePref; return false; } diff --git a/toolkit/components/reader/content/aboutReader.html b/toolkit/components/reader/content/aboutReader.html index d1c9164d42..452d4590b8 100644 --- a/toolkit/components/reader/content/aboutReader.html +++ b/toolkit/components/reader/content/aboutReader.html @@ -23,6 +23,10 @@ /> +