@stablyai/internal-playwright-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +3 -0
- package/ThirdPartyNotices.txt +1134 -0
- package/bin/install_media_pack.ps1 +5 -0
- package/bin/install_webkit_wsl.ps1 +35 -0
- package/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/browsers.json +80 -0
- package/cli.js +18 -0
- package/index.d.ts +17 -0
- package/index.js +32 -0
- package/index.mjs +28 -0
- package/lib/androidServerImpl.js +65 -0
- package/lib/browserServerImpl.js +120 -0
- package/lib/cli/cli.js +58 -0
- package/lib/cli/driver.js +97 -0
- package/lib/cli/program.js +634 -0
- package/lib/cli/programWithTestStub.js +74 -0
- package/lib/client/accessibility.js +49 -0
- package/lib/client/android.js +361 -0
- package/lib/client/api.js +137 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +163 -0
- package/lib/client/browserContext.js +529 -0
- package/lib/client/browserType.js +184 -0
- package/lib/client/cdpSession.js +51 -0
- package/lib/client/channelOwner.js +194 -0
- package/lib/client/clientHelper.js +64 -0
- package/lib/client/clientInstrumentation.js +55 -0
- package/lib/client/clientStackTrace.js +69 -0
- package/lib/client/clock.js +68 -0
- package/lib/client/connection.js +314 -0
- package/lib/client/consoleMessage.js +54 -0
- package/lib/client/coverage.js +44 -0
- package/lib/client/dialog.js +56 -0
- package/lib/client/download.js +62 -0
- package/lib/client/electron.js +138 -0
- package/lib/client/elementHandle.js +281 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/events.js +99 -0
- package/lib/client/fetch.js +369 -0
- package/lib/client/fileChooser.js +46 -0
- package/lib/client/fileUtils.js +34 -0
- package/lib/client/frame.js +408 -0
- package/lib/client/harRouter.js +87 -0
- package/lib/client/input.js +84 -0
- package/lib/client/jsHandle.js +109 -0
- package/lib/client/jsonPipe.js +39 -0
- package/lib/client/localUtils.js +60 -0
- package/lib/client/locator.js +368 -0
- package/lib/client/network.js +747 -0
- package/lib/client/page.js +721 -0
- package/lib/client/platform.js +74 -0
- package/lib/client/playwright.js +71 -0
- package/lib/client/selectors.js +55 -0
- package/lib/client/stream.js +39 -0
- package/lib/client/timeoutSettings.js +79 -0
- package/lib/client/tracing.js +117 -0
- package/lib/client/types.js +28 -0
- package/lib/client/video.js +59 -0
- package/lib/client/waiter.js +142 -0
- package/lib/client/webError.js +39 -0
- package/lib/client/webSocket.js +93 -0
- package/lib/client/worker.js +63 -0
- package/lib/client/writableStream.js +39 -0
- package/lib/common/debugLogger.js +90 -0
- package/lib/common/socksProxy.js +569 -0
- package/lib/common/timeoutSettings.js +73 -0
- package/lib/common/types.js +5 -0
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +28 -0
- package/lib/generated/consoleApiSource.js +28 -0
- package/lib/generated/injectedScriptSource.js +28 -0
- package/lib/generated/pollingRecorderSource.js +28 -0
- package/lib/generated/recorderSource.js +28 -0
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +28 -0
- package/lib/generated/webSocketMockSource.js +336 -0
- package/lib/image_tools/colorUtils.js +98 -0
- package/lib/image_tools/compare.js +108 -0
- package/lib/image_tools/imageChannel.js +70 -0
- package/lib/image_tools/stats.js +102 -0
- package/lib/inProcessFactory.js +60 -0
- package/lib/index.js +19 -0
- package/lib/inprocess.js +3 -0
- package/lib/outofprocess.js +76 -0
- package/lib/protocol/debug.js +27 -0
- package/lib/protocol/serializers.js +192 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2919 -0
- package/lib/protocol/validatorPrimitives.js +193 -0
- package/lib/remote/playwrightConnection.js +129 -0
- package/lib/remote/playwrightServer.js +335 -0
- package/lib/server/accessibility.js +69 -0
- package/lib/server/android/android.js +465 -0
- package/lib/server/android/backendAdb.js +177 -0
- package/lib/server/artifact.js +127 -0
- package/lib/server/bidi/bidiBrowser.js +490 -0
- package/lib/server/bidi/bidiChromium.js +153 -0
- package/lib/server/bidi/bidiConnection.js +212 -0
- package/lib/server/bidi/bidiExecutionContext.js +221 -0
- package/lib/server/bidi/bidiFirefox.js +130 -0
- package/lib/server/bidi/bidiInput.js +146 -0
- package/lib/server/bidi/bidiNetworkManager.js +383 -0
- package/lib/server/bidi/bidiOverCdp.js +102 -0
- package/lib/server/bidi/bidiPage.js +552 -0
- package/lib/server/bidi/bidiPdf.js +106 -0
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +24 -0
- package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
- package/lib/server/browser.js +149 -0
- package/lib/server/browserContext.js +695 -0
- package/lib/server/browserType.js +328 -0
- package/lib/server/callLog.js +82 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +402 -0
- package/lib/server/chromium/chromiumSwitches.js +95 -0
- package/lib/server/chromium/crAccessibility.js +263 -0
- package/lib/server/chromium/crBrowser.js +501 -0
- package/lib/server/chromium/crConnection.js +202 -0
- package/lib/server/chromium/crCoverage.js +235 -0
- package/lib/server/chromium/crDevTools.js +113 -0
- package/lib/server/chromium/crDragDrop.js +131 -0
- package/lib/server/chromium/crExecutionContext.js +146 -0
- package/lib/server/chromium/crInput.js +187 -0
- package/lib/server/chromium/crNetworkManager.js +666 -0
- package/lib/server/chromium/crPage.js +1069 -0
- package/lib/server/chromium/crPdf.js +121 -0
- package/lib/server/chromium/crProtocolHelper.js +145 -0
- package/lib/server/chromium/crServiceWorker.js +123 -0
- package/lib/server/chromium/defaultFontFamilies.js +162 -0
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +113 -0
- package/lib/server/clock.js +149 -0
- package/lib/server/codegen/csharp.js +327 -0
- package/lib/server/codegen/java.js +274 -0
- package/lib/server/codegen/javascript.js +270 -0
- package/lib/server/codegen/jsonl.js +52 -0
- package/lib/server/codegen/language.js +132 -0
- package/lib/server/codegen/languages.js +68 -0
- package/lib/server/codegen/python.js +279 -0
- package/lib/server/codegen/types.js +16 -0
- package/lib/server/console.js +53 -0
- package/lib/server/cookieStore.js +206 -0
- package/lib/server/debugController.js +191 -0
- package/lib/server/debugger.js +119 -0
- package/lib/server/deviceDescriptors.js +39 -0
- package/lib/server/deviceDescriptorsSource.json +1779 -0
- package/lib/server/dialog.js +116 -0
- package/lib/server/dispatchers/androidDispatcher.js +325 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +364 -0
- package/lib/server/dispatchers/browserDispatcher.js +118 -0
- package/lib/server/dispatchers/browserTypeDispatcher.js +64 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
- package/lib/server/dispatchers/debugControllerDispatcher.js +78 -0
- package/lib/server/dispatchers/dialogDispatcher.js +47 -0
- package/lib/server/dispatchers/dispatcher.js +371 -0
- package/lib/server/dispatchers/electronDispatcher.js +89 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -0
- package/lib/server/dispatchers/frameDispatcher.js +227 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +85 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +149 -0
- package/lib/server/dispatchers/networkDispatchers.js +213 -0
- package/lib/server/dispatchers/pageDispatcher.js +401 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +108 -0
- package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
- package/lib/server/dispatchers/streamDispatcher.js +67 -0
- package/lib/server/dispatchers/tracingDispatcher.js +68 -0
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +79 -0
- package/lib/server/dom.js +806 -0
- package/lib/server/download.js +70 -0
- package/lib/server/electron/electron.js +270 -0
- package/lib/server/electron/loader.js +29 -0
- package/lib/server/errors.js +69 -0
- package/lib/server/fetch.js +621 -0
- package/lib/server/fileChooser.js +43 -0
- package/lib/server/fileUploadUtils.js +84 -0
- package/lib/server/firefox/ffAccessibility.js +238 -0
- package/lib/server/firefox/ffBrowser.js +428 -0
- package/lib/server/firefox/ffConnection.js +147 -0
- package/lib/server/firefox/ffExecutionContext.js +150 -0
- package/lib/server/firefox/ffInput.js +159 -0
- package/lib/server/firefox/ffNetworkManager.js +256 -0
- package/lib/server/firefox/ffPage.js +503 -0
- package/lib/server/firefox/firefox.js +116 -0
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +147 -0
- package/lib/server/frameSelectors.js +156 -0
- package/lib/server/frames.js +1502 -0
- package/lib/server/har/harRecorder.js +147 -0
- package/lib/server/har/harTracer.js +607 -0
- package/lib/server/harBackend.js +157 -0
- package/lib/server/helper.js +96 -0
- package/lib/server/index.js +58 -0
- package/lib/server/input.js +273 -0
- package/lib/server/instrumentation.js +69 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
- package/lib/server/javascript.js +291 -0
- package/lib/server/launchApp.js +128 -0
- package/lib/server/localUtils.js +218 -0
- package/lib/server/macEditingCommands.js +143 -0
- package/lib/server/network.js +629 -0
- package/lib/server/page.js +871 -0
- package/lib/server/pipeTransport.js +89 -0
- package/lib/server/playwright.js +69 -0
- package/lib/server/progress.js +112 -0
- package/lib/server/protocolError.js +52 -0
- package/lib/server/recorder/chat.js +161 -0
- package/lib/server/recorder/codeGenerator.js +153 -0
- package/lib/server/recorder/csharp.js +310 -0
- package/lib/server/recorder/java.js +248 -0
- package/lib/server/recorder/javascript.js +229 -0
- package/lib/server/recorder/jsonl.js +47 -0
- package/lib/server/recorder/language.js +44 -0
- package/lib/server/recorder/python.js +276 -0
- package/lib/server/recorder/recorderActions.js +5 -0
- package/lib/server/recorder/recorderApp.js +387 -0
- package/lib/server/recorder/recorderRunner.js +138 -0
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +157 -0
- package/lib/server/recorder/throttledFile.js +57 -0
- package/lib/server/recorder/utils.js +45 -0
- package/lib/server/recorder.js +499 -0
- package/lib/server/registry/browserFetcher.js +175 -0
- package/lib/server/registry/dependencies.js +371 -0
- package/lib/server/registry/index.js +1331 -0
- package/lib/server/registry/nativeDeps.js +1280 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +120 -0
- package/lib/server/screenshotter.js +333 -0
- package/lib/server/selectors.js +112 -0
- package/lib/server/socksClientCertificatesInterceptor.js +383 -0
- package/lib/server/socksInterceptor.js +95 -0
- package/lib/server/stably/ai-tools/http-request.js +70 -0
- package/lib/server/stably/ai-tools/stablyApiCaller.js +137 -0
- package/lib/server/stably/autohealing/elementHandleFromCoordinates.js +64 -0
- package/lib/server/stably/autohealing/healingService.js +228 -0
- package/lib/server/stably/autohealing/screenshotFrame.js +41 -0
- package/lib/server/stably/constants.js +31 -0
- package/lib/server/trace/recorder/snapshotter.js +147 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +541 -0
- package/lib/server/trace/recorder/tracing.js +602 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
- package/lib/server/trace/viewer/traceViewer.js +240 -0
- package/lib/server/transport.js +181 -0
- package/lib/server/types.js +28 -0
- package/lib/server/usKeyboardLayout.js +145 -0
- package/lib/server/utils/ascii.js +44 -0
- package/lib/server/utils/comparators.js +161 -0
- package/lib/server/utils/crypto.js +216 -0
- package/lib/server/utils/debug.js +42 -0
- package/lib/server/utils/debugLogger.js +122 -0
- package/lib/server/utils/env.js +73 -0
- package/lib/server/utils/eventsHelper.js +39 -0
- package/lib/server/utils/expectUtils.js +38 -0
- package/lib/server/utils/fileUtils.js +191 -0
- package/lib/server/utils/happyEyeballs.js +207 -0
- package/lib/server/utils/hostPlatform.js +111 -0
- package/lib/server/utils/httpServer.js +218 -0
- package/lib/server/utils/image_tools/colorUtils.js +89 -0
- package/lib/server/utils/image_tools/compare.js +109 -0
- package/lib/server/utils/image_tools/imageChannel.js +78 -0
- package/lib/server/utils/image_tools/stats.js +102 -0
- package/lib/server/utils/linuxUtils.js +71 -0
- package/lib/server/utils/network.js +233 -0
- package/lib/server/utils/nodePlatform.js +148 -0
- package/lib/server/utils/pipeTransport.js +84 -0
- package/lib/server/utils/processLauncher.js +241 -0
- package/lib/server/utils/profiler.js +65 -0
- package/lib/server/utils/socksProxy.js +511 -0
- package/lib/server/utils/spawnAsync.js +41 -0
- package/lib/server/utils/task.js +51 -0
- package/lib/server/utils/userAgent.js +98 -0
- package/lib/server/utils/wsServer.js +121 -0
- package/lib/server/utils/zipFile.js +74 -0
- package/lib/server/utils/zones.js +57 -0
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +119 -0
- package/lib/server/webkit/wkAccessibility.js +237 -0
- package/lib/server/webkit/wkBrowser.js +339 -0
- package/lib/server/webkit/wkConnection.js +149 -0
- package/lib/server/webkit/wkExecutionContext.js +154 -0
- package/lib/server/webkit/wkInput.js +181 -0
- package/lib/server/webkit/wkInterceptableRequest.js +169 -0
- package/lib/server/webkit/wkPage.js +1134 -0
- package/lib/server/webkit/wkProvisionalPage.js +83 -0
- package/lib/server/webkit/wkWorkers.js +104 -0
- package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +74 -0
- package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +113 -0
- package/lib/third_party/diff_match_patch.js +2222 -0
- package/lib/third_party/pixelmatch.js +255 -0
- package/lib/utils/ascii.js +31 -0
- package/lib/utils/comparators.js +171 -0
- package/lib/utils/crypto.js +33 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +89 -0
- package/lib/utils/env.js +49 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/fileUtils.js +205 -0
- package/lib/utils/glob.js +83 -0
- package/lib/utils/happy-eyeballs.js +160 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +128 -0
- package/lib/utils/httpServer.js +236 -0
- package/lib/utils/index.js +346 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
- package/lib/utils/isomorphic/assert.js +31 -0
- package/lib/utils/isomorphic/colors.js +72 -0
- package/lib/utils/isomorphic/cssParser.js +245 -0
- package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
- package/lib/utils/isomorphic/headers.js +53 -0
- package/lib/utils/isomorphic/locatorGenerators.js +673 -0
- package/lib/utils/isomorphic/locatorParser.js +176 -0
- package/lib/utils/isomorphic/locatorUtils.js +81 -0
- package/lib/utils/isomorphic/manualPromise.js +114 -0
- package/lib/utils/isomorphic/mimeType.js +459 -0
- package/lib/utils/isomorphic/multimap.js +80 -0
- package/lib/utils/isomorphic/protocolFormatter.js +78 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
- package/lib/utils/isomorphic/rtti.js +43 -0
- package/lib/utils/isomorphic/selectorParser.js +386 -0
- package/lib/utils/isomorphic/semaphore.js +54 -0
- package/lib/utils/isomorphic/stackTrace.js +158 -0
- package/lib/utils/isomorphic/stringUtils.js +155 -0
- package/lib/utils/isomorphic/time.js +49 -0
- package/lib/utils/isomorphic/timeoutRunner.js +66 -0
- package/lib/utils/isomorphic/traceUtils.js +58 -0
- package/lib/utils/isomorphic/types.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +176 -0
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/mimeType.js +29 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +188 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +44 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +121 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +66 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +127 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +62 -0
- package/lib/utils.js +107 -0
- package/lib/utilsBundle.js +109 -0
- package/lib/utilsBundleImpl/index.js +218 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +84 -0
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
- package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +24 -0
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-Ri0uHF7I.css +1 -0
- package/lib/vite/recorder/assets/index-Y-X2TGJv.js +193 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Bhnc5o2x.js +24 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-ClwvkA2N.js +265 -0
- package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +1 -0
- package/lib/vite/traceViewer/index.DFO9NNF5.js +2 -0
- package/lib/vite/traceViewer/index.I8N9v4jT.css +1 -0
- package/lib/vite/traceViewer/index.html +43 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +3 -0
- package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -0
- package/lib/vite/traceViewer/uiMode.Shu3QS-1.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +17 -0
- package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -0
- package/lib/zipBundle.js +34 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +43 -0
- package/types/protocol.d.ts +23130 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +22857 -0
@@ -0,0 +1,336 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var webSocketMockSource_exports = {};
|
20
|
+
__export(webSocketMockSource_exports, {
|
21
|
+
source: () => source
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(webSocketMockSource_exports);
|
24
|
+
const source = `
|
25
|
+
var __commonJS = obj => {
|
26
|
+
let required = false;
|
27
|
+
let result;
|
28
|
+
return function __require() {
|
29
|
+
if (!required) {
|
30
|
+
required = true;
|
31
|
+
let fn;
|
32
|
+
for (const name in obj) { fn = obj[name]; break; }
|
33
|
+
const module = { exports: {} };
|
34
|
+
fn(module.exports, module);
|
35
|
+
result = module.exports;
|
36
|
+
}
|
37
|
+
return result;
|
38
|
+
}
|
39
|
+
};
|
40
|
+
var __export = (target, all) => {for (var name in all) target[name] = all[name];};
|
41
|
+
var __toESM = mod => ({ ...mod, 'default': mod });
|
42
|
+
var __toCommonJS = mod => ({ ...mod, __esModule: true });
|
43
|
+
|
44
|
+
|
45
|
+
// packages/injected/src/webSocketMock.ts
|
46
|
+
var webSocketMock_exports = {};
|
47
|
+
__export(webSocketMock_exports, {
|
48
|
+
inject: () => inject
|
49
|
+
});
|
50
|
+
module.exports = __toCommonJS(webSocketMock_exports);
|
51
|
+
function inject(globalThis) {
|
52
|
+
if (globalThis.__pwWebSocketDispatch)
|
53
|
+
return;
|
54
|
+
function generateId() {
|
55
|
+
const bytes = new Uint8Array(32);
|
56
|
+
globalThis.crypto.getRandomValues(bytes);
|
57
|
+
const hex = "0123456789abcdef";
|
58
|
+
return [...bytes].map((value) => {
|
59
|
+
const high = Math.floor(value / 16);
|
60
|
+
const low = value % 16;
|
61
|
+
return hex[high] + hex[low];
|
62
|
+
}).join("");
|
63
|
+
}
|
64
|
+
function bufferToData(b) {
|
65
|
+
let s = "";
|
66
|
+
for (let i = 0; i < b.length; i++)
|
67
|
+
s += String.fromCharCode(b[i]);
|
68
|
+
return { data: globalThis.btoa(s), isBase64: true };
|
69
|
+
}
|
70
|
+
function stringToBuffer(s) {
|
71
|
+
s = globalThis.atob(s);
|
72
|
+
const b = new Uint8Array(s.length);
|
73
|
+
for (let i = 0; i < s.length; i++)
|
74
|
+
b[i] = s.charCodeAt(i);
|
75
|
+
return b.buffer;
|
76
|
+
}
|
77
|
+
function messageToData(message, cb) {
|
78
|
+
if (message instanceof globalThis.Blob)
|
79
|
+
return message.arrayBuffer().then((buffer) => cb(bufferToData(new Uint8Array(buffer))));
|
80
|
+
if (typeof message === "string")
|
81
|
+
return cb({ data: message, isBase64: false });
|
82
|
+
if (ArrayBuffer.isView(message))
|
83
|
+
return cb(bufferToData(new Uint8Array(message.buffer, message.byteOffset, message.byteLength)));
|
84
|
+
return cb(bufferToData(new Uint8Array(message)));
|
85
|
+
}
|
86
|
+
function dataToMessage(data, binaryType) {
|
87
|
+
if (!data.isBase64)
|
88
|
+
return data.data;
|
89
|
+
const buffer = stringToBuffer(data.data);
|
90
|
+
return binaryType === "arraybuffer" ? buffer : new Blob([buffer]);
|
91
|
+
}
|
92
|
+
const binding = globalThis.__pwWebSocketBinding;
|
93
|
+
const NativeWebSocket = globalThis.WebSocket;
|
94
|
+
const idToWebSocket = /* @__PURE__ */ new Map();
|
95
|
+
globalThis.__pwWebSocketDispatch = (request) => {
|
96
|
+
const ws = idToWebSocket.get(request.id);
|
97
|
+
if (!ws)
|
98
|
+
return;
|
99
|
+
if (request.type === "connect")
|
100
|
+
ws._apiConnect();
|
101
|
+
if (request.type === "passthrough")
|
102
|
+
ws._apiPassThrough();
|
103
|
+
if (request.type === "ensureOpened")
|
104
|
+
ws._apiEnsureOpened();
|
105
|
+
if (request.type === "sendToPage")
|
106
|
+
ws._apiSendToPage(dataToMessage(request.data, ws.binaryType));
|
107
|
+
if (request.type === "closePage")
|
108
|
+
ws._apiClosePage(request.code, request.reason, request.wasClean);
|
109
|
+
if (request.type === "sendToServer")
|
110
|
+
ws._apiSendToServer(dataToMessage(request.data, ws.binaryType));
|
111
|
+
if (request.type === "closeServer")
|
112
|
+
ws._apiCloseServer(request.code, request.reason, request.wasClean);
|
113
|
+
};
|
114
|
+
const _WebSocketMock = class _WebSocketMock extends EventTarget {
|
115
|
+
constructor(url, protocols) {
|
116
|
+
var _a, _b;
|
117
|
+
super();
|
118
|
+
// WebSocket.CLOSED
|
119
|
+
this.CONNECTING = 0;
|
120
|
+
// WebSocket.CONNECTING
|
121
|
+
this.OPEN = 1;
|
122
|
+
// WebSocket.OPEN
|
123
|
+
this.CLOSING = 2;
|
124
|
+
// WebSocket.CLOSING
|
125
|
+
this.CLOSED = 3;
|
126
|
+
// WebSocket.CLOSED
|
127
|
+
this._oncloseListener = null;
|
128
|
+
this._onerrorListener = null;
|
129
|
+
this._onmessageListener = null;
|
130
|
+
this._onopenListener = null;
|
131
|
+
this.bufferedAmount = 0;
|
132
|
+
this.extensions = "";
|
133
|
+
this.protocol = "";
|
134
|
+
this.readyState = 0;
|
135
|
+
this._origin = "";
|
136
|
+
this._passthrough = false;
|
137
|
+
this._wsBufferedMessages = [];
|
138
|
+
this._binaryType = "blob";
|
139
|
+
this.url = new URL(url, globalThis.window.document.baseURI).href.replace(/^http/, "ws");
|
140
|
+
this._origin = (_b = (_a = URL.parse(this.url)) == null ? void 0 : _a.origin) != null ? _b : "";
|
141
|
+
this._protocols = protocols;
|
142
|
+
this._id = generateId();
|
143
|
+
idToWebSocket.set(this._id, this);
|
144
|
+
binding({ type: "onCreate", id: this._id, url: this.url });
|
145
|
+
}
|
146
|
+
// --- native WebSocket implementation ---
|
147
|
+
get binaryType() {
|
148
|
+
return this._binaryType;
|
149
|
+
}
|
150
|
+
set binaryType(type) {
|
151
|
+
this._binaryType = type;
|
152
|
+
if (this._ws)
|
153
|
+
this._ws.binaryType = type;
|
154
|
+
}
|
155
|
+
get onclose() {
|
156
|
+
return this._oncloseListener;
|
157
|
+
}
|
158
|
+
set onclose(listener) {
|
159
|
+
if (this._oncloseListener)
|
160
|
+
this.removeEventListener("close", this._oncloseListener);
|
161
|
+
this._oncloseListener = listener;
|
162
|
+
if (this._oncloseListener)
|
163
|
+
this.addEventListener("close", this._oncloseListener);
|
164
|
+
}
|
165
|
+
get onerror() {
|
166
|
+
return this._onerrorListener;
|
167
|
+
}
|
168
|
+
set onerror(listener) {
|
169
|
+
if (this._onerrorListener)
|
170
|
+
this.removeEventListener("error", this._onerrorListener);
|
171
|
+
this._onerrorListener = listener;
|
172
|
+
if (this._onerrorListener)
|
173
|
+
this.addEventListener("error", this._onerrorListener);
|
174
|
+
}
|
175
|
+
get onopen() {
|
176
|
+
return this._onopenListener;
|
177
|
+
}
|
178
|
+
set onopen(listener) {
|
179
|
+
if (this._onopenListener)
|
180
|
+
this.removeEventListener("open", this._onopenListener);
|
181
|
+
this._onopenListener = listener;
|
182
|
+
if (this._onopenListener)
|
183
|
+
this.addEventListener("open", this._onopenListener);
|
184
|
+
}
|
185
|
+
get onmessage() {
|
186
|
+
return this._onmessageListener;
|
187
|
+
}
|
188
|
+
set onmessage(listener) {
|
189
|
+
if (this._onmessageListener)
|
190
|
+
this.removeEventListener("message", this._onmessageListener);
|
191
|
+
this._onmessageListener = listener;
|
192
|
+
if (this._onmessageListener)
|
193
|
+
this.addEventListener("message", this._onmessageListener);
|
194
|
+
}
|
195
|
+
send(message) {
|
196
|
+
if (this.readyState === _WebSocketMock.CONNECTING)
|
197
|
+
throw new DOMException(\`Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.\`);
|
198
|
+
if (this.readyState !== _WebSocketMock.OPEN)
|
199
|
+
throw new DOMException(\`WebSocket is already in CLOSING or CLOSED state.\`);
|
200
|
+
if (this._passthrough) {
|
201
|
+
if (this._ws)
|
202
|
+
this._apiSendToServer(message);
|
203
|
+
} else {
|
204
|
+
messageToData(message, (data) => binding({ type: "onMessageFromPage", id: this._id, data }));
|
205
|
+
}
|
206
|
+
}
|
207
|
+
close(code, reason) {
|
208
|
+
if (code !== void 0 && code !== 1e3 && (code < 3e3 || code > 4999))
|
209
|
+
throw new DOMException(\`Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. \${code} is neither.\`);
|
210
|
+
if (this.readyState === _WebSocketMock.OPEN || this.readyState === _WebSocketMock.CONNECTING)
|
211
|
+
this.readyState = _WebSocketMock.CLOSING;
|
212
|
+
if (this._passthrough)
|
213
|
+
this._apiCloseServer(code, reason, true);
|
214
|
+
else
|
215
|
+
binding({ type: "onClosePage", id: this._id, code, reason, wasClean: true });
|
216
|
+
}
|
217
|
+
// --- methods called from the routing API ---
|
218
|
+
_apiEnsureOpened() {
|
219
|
+
if (!this._ws)
|
220
|
+
this._ensureOpened();
|
221
|
+
}
|
222
|
+
_apiSendToPage(message) {
|
223
|
+
this._ensureOpened();
|
224
|
+
if (this.readyState !== _WebSocketMock.OPEN)
|
225
|
+
throw new DOMException(\`WebSocket is already in CLOSING or CLOSED state.\`);
|
226
|
+
this.dispatchEvent(new MessageEvent("message", { data: message, origin: this._origin, cancelable: true }));
|
227
|
+
}
|
228
|
+
_apiSendToServer(message) {
|
229
|
+
if (!this._ws)
|
230
|
+
throw new Error("Cannot send a message before connecting to the server");
|
231
|
+
if (this._ws.readyState === _WebSocketMock.CONNECTING)
|
232
|
+
this._wsBufferedMessages.push(message);
|
233
|
+
else
|
234
|
+
this._ws.send(message);
|
235
|
+
}
|
236
|
+
_apiConnect() {
|
237
|
+
if (this._ws)
|
238
|
+
throw new Error("Can only connect to the server once");
|
239
|
+
this._ws = new NativeWebSocket(this.url, this._protocols);
|
240
|
+
this._ws.binaryType = this._binaryType;
|
241
|
+
this._ws.onopen = () => {
|
242
|
+
for (const message of this._wsBufferedMessages)
|
243
|
+
this._ws.send(message);
|
244
|
+
this._wsBufferedMessages = [];
|
245
|
+
this._ensureOpened();
|
246
|
+
};
|
247
|
+
this._ws.onclose = (event) => {
|
248
|
+
this._onWSClose(event.code, event.reason, event.wasClean);
|
249
|
+
};
|
250
|
+
this._ws.onmessage = (event) => {
|
251
|
+
if (this._passthrough)
|
252
|
+
this._apiSendToPage(event.data);
|
253
|
+
else
|
254
|
+
messageToData(event.data, (data) => binding({ type: "onMessageFromServer", id: this._id, data }));
|
255
|
+
};
|
256
|
+
this._ws.onerror = () => {
|
257
|
+
const event = new Event("error", { cancelable: true });
|
258
|
+
this.dispatchEvent(event);
|
259
|
+
};
|
260
|
+
}
|
261
|
+
// This method connects to the server, and passes all messages through,
|
262
|
+
// as if WebSocketMock was not engaged.
|
263
|
+
_apiPassThrough() {
|
264
|
+
this._passthrough = true;
|
265
|
+
this._apiConnect();
|
266
|
+
}
|
267
|
+
_apiCloseServer(code, reason, wasClean) {
|
268
|
+
if (!this._ws) {
|
269
|
+
this._onWSClose(code, reason, wasClean);
|
270
|
+
return;
|
271
|
+
}
|
272
|
+
if (this._ws.readyState === _WebSocketMock.CONNECTING || this._ws.readyState === _WebSocketMock.OPEN)
|
273
|
+
this._ws.close(code, reason);
|
274
|
+
}
|
275
|
+
_apiClosePage(code, reason, wasClean) {
|
276
|
+
if (this.readyState === _WebSocketMock.CLOSED)
|
277
|
+
return;
|
278
|
+
this.readyState = _WebSocketMock.CLOSED;
|
279
|
+
this.dispatchEvent(new CloseEvent("close", { code, reason, wasClean, cancelable: true }));
|
280
|
+
this._maybeCleanup();
|
281
|
+
if (this._passthrough)
|
282
|
+
this._apiCloseServer(code, reason, wasClean);
|
283
|
+
else
|
284
|
+
binding({ type: "onClosePage", id: this._id, code, reason, wasClean });
|
285
|
+
}
|
286
|
+
// --- internals ---
|
287
|
+
_ensureOpened() {
|
288
|
+
var _a;
|
289
|
+
if (this.readyState !== _WebSocketMock.CONNECTING)
|
290
|
+
return;
|
291
|
+
this.extensions = ((_a = this._ws) == null ? void 0 : _a.extensions) || "";
|
292
|
+
if (this._ws)
|
293
|
+
this.protocol = this._ws.protocol;
|
294
|
+
else if (Array.isArray(this._protocols))
|
295
|
+
this.protocol = this._protocols[0] || "";
|
296
|
+
else
|
297
|
+
this.protocol = this._protocols || "";
|
298
|
+
this.readyState = _WebSocketMock.OPEN;
|
299
|
+
this.dispatchEvent(new Event("open", { cancelable: true }));
|
300
|
+
}
|
301
|
+
_onWSClose(code, reason, wasClean) {
|
302
|
+
if (this._passthrough)
|
303
|
+
this._apiClosePage(code, reason, wasClean);
|
304
|
+
else
|
305
|
+
binding({ type: "onCloseServer", id: this._id, code, reason, wasClean });
|
306
|
+
if (this._ws) {
|
307
|
+
this._ws.onopen = null;
|
308
|
+
this._ws.onclose = null;
|
309
|
+
this._ws.onmessage = null;
|
310
|
+
this._ws.onerror = null;
|
311
|
+
this._ws = void 0;
|
312
|
+
this._wsBufferedMessages = [];
|
313
|
+
}
|
314
|
+
this._maybeCleanup();
|
315
|
+
}
|
316
|
+
_maybeCleanup() {
|
317
|
+
if (this.readyState === _WebSocketMock.CLOSED && !this._ws)
|
318
|
+
idToWebSocket.delete(this._id);
|
319
|
+
}
|
320
|
+
};
|
321
|
+
_WebSocketMock.CONNECTING = 0;
|
322
|
+
// WebSocket.CONNECTING
|
323
|
+
_WebSocketMock.OPEN = 1;
|
324
|
+
// WebSocket.OPEN
|
325
|
+
_WebSocketMock.CLOSING = 2;
|
326
|
+
// WebSocket.CLOSING
|
327
|
+
_WebSocketMock.CLOSED = 3;
|
328
|
+
let WebSocketMock = _WebSocketMock;
|
329
|
+
globalThis.WebSocket = class WebSocket extends WebSocketMock {
|
330
|
+
};
|
331
|
+
}
|
332
|
+
`;
|
333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
334
|
+
0 && (module.exports = {
|
335
|
+
source
|
336
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.blendWithWhite = blendWithWhite;
|
7
|
+
exports.colorDeltaE94 = colorDeltaE94;
|
8
|
+
exports.rgb2gray = rgb2gray;
|
9
|
+
exports.srgb2xyz = srgb2xyz;
|
10
|
+
exports.xyz2lab = xyz2lab;
|
11
|
+
/**
|
12
|
+
* Copyright (c) Microsoft Corporation.
|
13
|
+
*
|
14
|
+
* Licensed under the Apache License, Version 2.0 (the 'License");
|
15
|
+
* you may not use this file except in compliance with the License.
|
16
|
+
* You may obtain a copy of the License at
|
17
|
+
*
|
18
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
*
|
20
|
+
* Unless required by applicable law or agreed to in writing, software
|
21
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
+
* See the License for the specific language governing permissions and
|
24
|
+
* limitations under the License.
|
25
|
+
*/
|
26
|
+
|
27
|
+
function blendWithWhite(c, a) {
|
28
|
+
return 255 + (c - 255) * a;
|
29
|
+
}
|
30
|
+
function rgb2gray(r, g, b) {
|
31
|
+
// NOTE: this is the exact integer formula from SSIM.js.
|
32
|
+
// See https://github.com/obartra/ssim/blob/ca8e3c6a6ff5f4f2e232239e0c3d91806f3c97d5/src/matlab/rgb2gray.ts#L56
|
33
|
+
return 77 * r + 150 * g + 29 * b + 128 >> 8;
|
34
|
+
}
|
35
|
+
|
36
|
+
// Perceived color difference defined by CIE94.
|
37
|
+
// See https://en.wikipedia.org/wiki/Color_difference#CIE94
|
38
|
+
//
|
39
|
+
// The result of 1.0 is a "just-noticeable difference".
|
40
|
+
//
|
41
|
+
// Other results interpretation (taken from http://zschuessler.github.io/DeltaE/learn/):
|
42
|
+
// < 1.0 Not perceptible by human eyes.
|
43
|
+
// 1-2 Perceptible through close observation.
|
44
|
+
// 2-10 Perceptible at a glance.
|
45
|
+
// 11-49 Colors are more similar than opposite
|
46
|
+
// 100 Colors are exact opposite
|
47
|
+
function colorDeltaE94(rgb1, rgb2) {
|
48
|
+
const [l1, a1, b1] = xyz2lab(srgb2xyz(rgb1));
|
49
|
+
const [l2, a2, b2] = xyz2lab(srgb2xyz(rgb2));
|
50
|
+
const deltaL = l1 - l2;
|
51
|
+
const deltaA = a1 - a2;
|
52
|
+
const deltaB = b1 - b2;
|
53
|
+
const c1 = Math.sqrt(a1 ** 2 + b1 ** 2);
|
54
|
+
const c2 = Math.sqrt(a2 ** 2 + b2 ** 2);
|
55
|
+
const deltaC = c1 - c2;
|
56
|
+
let deltaH = deltaA ** 2 + deltaB ** 2 - deltaC ** 2;
|
57
|
+
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
58
|
+
// The k1, k2, kL, kC, kH values for "graphic arts" applications.
|
59
|
+
// See https://en.wikipedia.org/wiki/Color_difference#CIE94
|
60
|
+
const k1 = 0.045;
|
61
|
+
const k2 = 0.015;
|
62
|
+
const kL = 1;
|
63
|
+
const kC = 1;
|
64
|
+
const kH = 1;
|
65
|
+
const sC = 1.0 + k1 * c1;
|
66
|
+
const sH = 1.0 + k2 * c1;
|
67
|
+
const sL = 1;
|
68
|
+
return Math.sqrt((deltaL / sL / kL) ** 2 + (deltaC / sC / kC) ** 2 + (deltaH / sH / kH) ** 2);
|
69
|
+
}
|
70
|
+
|
71
|
+
// sRGB -> 1-normalized XYZ (i.e. Y ∈ [0, 1]) with D65 illuminant
|
72
|
+
// See https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
|
73
|
+
function srgb2xyz(rgb) {
|
74
|
+
let r = rgb[0] / 255;
|
75
|
+
let g = rgb[1] / 255;
|
76
|
+
let b = rgb[2] / 255;
|
77
|
+
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
78
|
+
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
79
|
+
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
80
|
+
return [r * 0.4124 + g * 0.3576 + b * 0.1805, r * 0.2126 + g * 0.7152 + b * 0.0722, r * 0.0193 + g * 0.1192 + b * 0.9505];
|
81
|
+
}
|
82
|
+
const sigma_pow2 = 6 * 6 / 29 / 29;
|
83
|
+
const sigma_pow3 = 6 * 6 * 6 / 29 / 29 / 29;
|
84
|
+
|
85
|
+
// 1-normalized CIE XYZ with D65 to L*a*b*
|
86
|
+
// See https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB
|
87
|
+
function xyz2lab(xyz) {
|
88
|
+
const x = xyz[0] / 0.950489;
|
89
|
+
const y = xyz[1];
|
90
|
+
const z = xyz[2] / 1.088840;
|
91
|
+
const fx = x > sigma_pow3 ? x ** (1 / 3) : x / 3 / sigma_pow2 + 4 / 29;
|
92
|
+
const fy = y > sigma_pow3 ? y ** (1 / 3) : y / 3 / sigma_pow2 + 4 / 29;
|
93
|
+
const fz = z > sigma_pow3 ? z ** (1 / 3) : z / 3 / sigma_pow2 + 4 / 29;
|
94
|
+
const l = 116 * fy - 16;
|
95
|
+
const a = 500 * (fx - fy);
|
96
|
+
const b = 200 * (fy - fz);
|
97
|
+
return [l, a, b];
|
98
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.compare = compare;
|
7
|
+
var _colorUtils = require("./colorUtils");
|
8
|
+
var _imageChannel = require("./imageChannel");
|
9
|
+
var _stats = require("./stats");
|
10
|
+
/**
|
11
|
+
* Copyright (c) Microsoft Corporation.
|
12
|
+
*
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the 'License");
|
14
|
+
* you may not use this file except in compliance with the License.
|
15
|
+
* You may obtain a copy of the License at
|
16
|
+
*
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
+
*
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
+
* See the License for the specific language governing permissions and
|
23
|
+
* limitations under the License.
|
24
|
+
*/
|
25
|
+
|
26
|
+
const SSIM_WINDOW_RADIUS = 15;
|
27
|
+
const VARIANCE_WINDOW_RADIUS = 1;
|
28
|
+
function drawPixel(width, data, x, y, r, g, b) {
|
29
|
+
const idx = (y * width + x) * 4;
|
30
|
+
data[idx + 0] = r;
|
31
|
+
data[idx + 1] = g;
|
32
|
+
data[idx + 2] = b;
|
33
|
+
data[idx + 3] = 255;
|
34
|
+
}
|
35
|
+
function compare(actual, expected, diff, width, height, options = {}) {
|
36
|
+
const {
|
37
|
+
maxColorDeltaE94 = 1.0
|
38
|
+
} = options;
|
39
|
+
const paddingSize = Math.max(VARIANCE_WINDOW_RADIUS, SSIM_WINDOW_RADIUS);
|
40
|
+
const paddingColorEven = [255, 0, 255];
|
41
|
+
const paddingColorOdd = [0, 255, 0];
|
42
|
+
const [r1, g1, b1] = _imageChannel.ImageChannel.intoRGB(width, height, expected, {
|
43
|
+
paddingSize,
|
44
|
+
paddingColorEven,
|
45
|
+
paddingColorOdd
|
46
|
+
});
|
47
|
+
const [r2, g2, b2] = _imageChannel.ImageChannel.intoRGB(width, height, actual, {
|
48
|
+
paddingSize,
|
49
|
+
paddingColorEven,
|
50
|
+
paddingColorOdd
|
51
|
+
});
|
52
|
+
const noop = (x, y) => {};
|
53
|
+
const drawRedPixel = diff ? (x, y) => drawPixel(width, diff, x - paddingSize, y - paddingSize, 255, 0, 0) : noop;
|
54
|
+
const drawYellowPixel = diff ? (x, y) => drawPixel(width, diff, x - paddingSize, y - paddingSize, 255, 255, 0) : noop;
|
55
|
+
const drawGrayPixel = diff ? (x, y) => {
|
56
|
+
const gray = (0, _colorUtils.rgb2gray)(r1.get(x, y), g1.get(x, y), b1.get(x, y));
|
57
|
+
const value = (0, _colorUtils.blendWithWhite)(gray, 0.1);
|
58
|
+
drawPixel(width, diff, x - paddingSize, y - paddingSize, value, value, value);
|
59
|
+
} : noop;
|
60
|
+
let fastR, fastG, fastB;
|
61
|
+
let diffCount = 0;
|
62
|
+
for (let y = paddingSize; y < r1.height - paddingSize; ++y) {
|
63
|
+
for (let x = paddingSize; x < r1.width - paddingSize; ++x) {
|
64
|
+
// Fast-path: equal pixels.
|
65
|
+
if (r1.get(x, y) === r2.get(x, y) && g1.get(x, y) === g2.get(x, y) && b1.get(x, y) === b2.get(x, y)) {
|
66
|
+
drawGrayPixel(x, y);
|
67
|
+
continue;
|
68
|
+
}
|
69
|
+
|
70
|
+
// Compare pixel colors using the dE94 color difference formulae.
|
71
|
+
// The dE94 is normalized so that the value of 1.0 is the "just-noticeable-difference".
|
72
|
+
// Color difference below 1.0 is not noticeable to a human eye, so we can disregard it.
|
73
|
+
// See https://en.wikipedia.org/wiki/Color_difference
|
74
|
+
const delta = (0, _colorUtils.colorDeltaE94)([r1.get(x, y), g1.get(x, y), b1.get(x, y)], [r2.get(x, y), g2.get(x, y), b2.get(x, y)]);
|
75
|
+
if (delta <= maxColorDeltaE94) {
|
76
|
+
drawGrayPixel(x, y);
|
77
|
+
continue;
|
78
|
+
}
|
79
|
+
if (!fastR || !fastG || !fastB) {
|
80
|
+
fastR = new _stats.FastStats(r1, r2);
|
81
|
+
fastG = new _stats.FastStats(g1, g2);
|
82
|
+
fastB = new _stats.FastStats(b1, b2);
|
83
|
+
}
|
84
|
+
const [varX1, varY1] = r1.boundXY(x - VARIANCE_WINDOW_RADIUS, y - VARIANCE_WINDOW_RADIUS);
|
85
|
+
const [varX2, varY2] = r1.boundXY(x + VARIANCE_WINDOW_RADIUS, y + VARIANCE_WINDOW_RADIUS);
|
86
|
+
const var1 = fastR.varianceC1(varX1, varY1, varX2, varY2) + fastG.varianceC1(varX1, varY1, varX2, varY2) + fastB.varianceC1(varX1, varY1, varX2, varY2);
|
87
|
+
const var2 = fastR.varianceC2(varX1, varY1, varX2, varY2) + fastG.varianceC2(varX1, varY1, varX2, varY2) + fastB.varianceC2(varX1, varY1, varX2, varY2);
|
88
|
+
// if this pixel is a part of a flood fill of a 3x3 square of either of the images, then it cannot be
|
89
|
+
// anti-aliasing pixel so it must be a pixel difference.
|
90
|
+
if (var1 === 0 || var2 === 0) {
|
91
|
+
drawRedPixel(x, y);
|
92
|
+
++diffCount;
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
const [ssimX1, ssimY1] = r1.boundXY(x - SSIM_WINDOW_RADIUS, y - SSIM_WINDOW_RADIUS);
|
96
|
+
const [ssimX2, ssimY2] = r1.boundXY(x + SSIM_WINDOW_RADIUS, y + SSIM_WINDOW_RADIUS);
|
97
|
+
const ssimRGB = ((0, _stats.ssim)(fastR, ssimX1, ssimY1, ssimX2, ssimY2) + (0, _stats.ssim)(fastG, ssimX1, ssimY1, ssimX2, ssimY2) + (0, _stats.ssim)(fastB, ssimX1, ssimY1, ssimX2, ssimY2)) / 3.0;
|
98
|
+
const isAntialiased = ssimRGB >= 0.99;
|
99
|
+
if (isAntialiased) {
|
100
|
+
drawYellowPixel(x, y);
|
101
|
+
} else {
|
102
|
+
drawRedPixel(x, y);
|
103
|
+
++diffCount;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return diffCount;
|
108
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ImageChannel = void 0;
|
7
|
+
var _colorUtils = require("./colorUtils");
|
8
|
+
/**
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
10
|
+
*
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the 'License");
|
12
|
+
* you may not use this file except in compliance with the License.
|
13
|
+
* You may obtain a copy of the License at
|
14
|
+
*
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
*
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
* See the License for the specific language governing permissions and
|
21
|
+
* limitations under the License.
|
22
|
+
*/
|
23
|
+
|
24
|
+
class ImageChannel {
|
25
|
+
static intoRGB(width, height, data, options = {}) {
|
26
|
+
const {
|
27
|
+
paddingSize = 0,
|
28
|
+
paddingColorOdd = [255, 0, 255],
|
29
|
+
paddingColorEven = [0, 255, 0]
|
30
|
+
} = options;
|
31
|
+
const newWidth = width + 2 * paddingSize;
|
32
|
+
const newHeight = height + 2 * paddingSize;
|
33
|
+
const r = new Uint8Array(newWidth * newHeight);
|
34
|
+
const g = new Uint8Array(newWidth * newHeight);
|
35
|
+
const b = new Uint8Array(newWidth * newHeight);
|
36
|
+
for (let y = 0; y < newHeight; ++y) {
|
37
|
+
for (let x = 0; x < newWidth; ++x) {
|
38
|
+
const index = y * newWidth + x;
|
39
|
+
if (y >= paddingSize && y < newHeight - paddingSize && x >= paddingSize && x < newWidth - paddingSize) {
|
40
|
+
const offset = ((y - paddingSize) * width + (x - paddingSize)) * 4;
|
41
|
+
const alpha = data[offset + 3] === 255 ? 1 : data[offset + 3] / 255;
|
42
|
+
r[index] = (0, _colorUtils.blendWithWhite)(data[offset], alpha);
|
43
|
+
g[index] = (0, _colorUtils.blendWithWhite)(data[offset + 1], alpha);
|
44
|
+
b[index] = (0, _colorUtils.blendWithWhite)(data[offset + 2], alpha);
|
45
|
+
} else {
|
46
|
+
const color = (y + x) % 2 === 0 ? paddingColorEven : paddingColorOdd;
|
47
|
+
r[index] = color[0];
|
48
|
+
g[index] = color[1];
|
49
|
+
b[index] = color[2];
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return [new ImageChannel(newWidth, newHeight, r), new ImageChannel(newWidth, newHeight, g), new ImageChannel(newWidth, newHeight, b)];
|
54
|
+
}
|
55
|
+
constructor(width, height, data) {
|
56
|
+
this.data = void 0;
|
57
|
+
this.width = void 0;
|
58
|
+
this.height = void 0;
|
59
|
+
this.data = data;
|
60
|
+
this.width = width;
|
61
|
+
this.height = height;
|
62
|
+
}
|
63
|
+
get(x, y) {
|
64
|
+
return this.data[y * this.width + x];
|
65
|
+
}
|
66
|
+
boundXY(x, y) {
|
67
|
+
return [Math.min(Math.max(x, 0), this.width - 1), Math.min(Math.max(y, 0), this.height - 1)];
|
68
|
+
}
|
69
|
+
}
|
70
|
+
exports.ImageChannel = ImageChannel;
|