roxxie-proxy-u-prod 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 +661 -0
- package/README.md +123 -0
- package/SOURCE.md +29 -0
- package/THIRD_PARTY_NOTICES.md +24 -0
- package/dist/assets/filters-Bu_3nHVy.bin +0 -0
- package/dist/assets/index-BdRlQ7d_.css +1 -0
- package/dist/assets/index-DcvPYWS3.js +3621 -0
- package/dist/assets/inject-BnVzMVpl.js +40 -0
- package/dist/assets/scramjet-C9HLwI-y.wasm +0 -0
- package/dist/defaultfavicon.png +0 -0
- package/dist/icon.png +0 -0
- package/dist/roxxie-icon.svg +12 -0
- package/embed.js +70 -0
- package/examples/single-page.html +25 -0
- package/package.json +42 -0
- package/runtime/controller.sw.js +273 -0
- package/runtime/index.html +18 -0
- package/runtime/localcontrollersw.js +7 -0
- package/runtime/roxxie-network.json +13 -0
- package/runtime/sw.js +6 -0
- package/scripts/build.mjs +344 -0
- package/scripts/smoke.mjs +123 -0
- package/scripts/verify.mjs +122 -0
- package/source/external/dreamlandjs/LICENSE +21 -0
- package/source/external/dreamlandjs/README.md +22 -0
- package/source/external/dreamlandjs/dist/core.d.ts +167 -0
- package/source/external/dreamlandjs/dist/core.js +2 -0
- package/source/external/dreamlandjs/dist/core.js.map +1 -0
- package/source/external/dreamlandjs/dist/core.size.html +4950 -0
- package/source/external/dreamlandjs/dist/js-runtime.d.ts +3 -0
- package/source/external/dreamlandjs/dist/js-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/js-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.d.ts +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/motion.d.ts +19 -0
- package/source/external/dreamlandjs/dist/motion.js +2 -0
- package/source/external/dreamlandjs/dist/motion.js.map +1 -0
- package/source/external/dreamlandjs/dist/router.d.ts +48 -0
- package/source/external/dreamlandjs/dist/router.js +2 -0
- package/source/external/dreamlandjs/dist/router.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.d.ts +3 -0
- package/source/external/dreamlandjs/dist/ssr.client.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.client.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.d.ts +7 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.server.d.ts +11 -0
- package/source/external/dreamlandjs/dist/ssr.server.js +2373 -0
- package/source/external/dreamlandjs/dist/ssr.server.js.map +1 -0
- package/source/external/dreamlandjs/dist/types/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/dist/types/core/css/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/css/selectorParser.d.ts +50 -0
- package/source/external/dreamlandjs/dist/types/core/delegate.d.ts +10 -0
- package/source/external/dreamlandjs/dist/types/core/index.d.ts +9 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/child.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/definitions.d.ts +76 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/dom.d.ts +28 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/index.d.ts +14 -0
- package/source/external/dreamlandjs/dist/types/core/state/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/core/state/pointers.d.ts +37 -0
- package/source/external/dreamlandjs/dist/types/core/state/state.d.ts +13 -0
- package/source/external/dreamlandjs/dist/types/core/state/use.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/utils.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/js-runtime/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/jsx-runtime/index.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/motion/index.d.ts +15 -0
- package/source/external/dreamlandjs/dist/types/router/index.d.ts +45 -0
- package/source/external/dreamlandjs/dist/types/ssr/client/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/consts.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/serialize.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/types.d.ts +21 -0
- package/source/external/dreamlandjs/dist/types/ssr/hybrid/index.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/index.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/vdom.d.ts +71 -0
- package/source/external/dreamlandjs/dist/types/util/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/util/store.d.ts +26 -0
- package/source/external/dreamlandjs/dist/types/vite/css-minifier.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/vite/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/util.d.ts +29 -0
- package/source/external/dreamlandjs/dist/util.js +2 -0
- package/source/external/dreamlandjs/dist/util.js.map +1 -0
- package/source/external/dreamlandjs/dist/vite.d.ts +19 -0
- package/source/external/dreamlandjs/dist/vite.js +2 -0
- package/source/external/dreamlandjs/dist/vite.js.map +1 -0
- package/source/external/dreamlandjs/package.json +101 -0
- package/source/external/dreamlandjs/rollup.config.ts +302 -0
- package/source/external/dreamlandjs/rollup.plugins.ts +1134 -0
- package/source/external/dreamlandjs/src/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/src/core/consts.js +18 -0
- package/source/external/dreamlandjs/src/core/css/index.ts +111 -0
- package/source/external/dreamlandjs/src/core/css/selectorParser.ts +313 -0
- package/source/external/dreamlandjs/src/core/delegate.ts +28 -0
- package/source/external/dreamlandjs/src/core/index.ts +31 -0
- package/source/external/dreamlandjs/src/core/jsx/child.ts +91 -0
- package/source/external/dreamlandjs/src/core/jsx/definitions.ts +125 -0
- package/source/external/dreamlandjs/src/core/jsx/dom.ts +49 -0
- package/source/external/dreamlandjs/src/core/jsx/index.ts +289 -0
- package/source/external/dreamlandjs/src/core/state/index.ts +1 -0
- package/source/external/dreamlandjs/src/core/state/pointers.ts +310 -0
- package/source/external/dreamlandjs/src/core/state/state.ts +112 -0
- package/source/external/dreamlandjs/src/core/state/use.ts +82 -0
- package/source/external/dreamlandjs/src/core/utils.ts +48 -0
- package/source/external/dreamlandjs/src/js-runtime/index.ts +4 -0
- package/source/external/dreamlandjs/src/jsx-runtime/index.ts +3 -0
- package/source/external/dreamlandjs/src/motion/index.ts +156 -0
- package/source/external/dreamlandjs/src/router/index.tsx +394 -0
- package/source/external/dreamlandjs/src/router/tsconfig.json +9 -0
- package/source/external/dreamlandjs/src/ssr/client/index.ts +193 -0
- package/source/external/dreamlandjs/src/ssr/common/consts.ts +5 -0
- package/source/external/dreamlandjs/src/ssr/common/serialize.ts +115 -0
- package/source/external/dreamlandjs/src/ssr/common/types.ts +28 -0
- package/source/external/dreamlandjs/src/ssr/hybrid/index.ts +144 -0
- package/source/external/dreamlandjs/src/ssr/server/index.ts +157 -0
- package/source/external/dreamlandjs/src/ssr/server/tsconfig.json +7 -0
- package/source/external/dreamlandjs/src/ssr/server/vdom.ts +285 -0
- package/source/external/dreamlandjs/src/util/index.ts +10 -0
- package/source/external/dreamlandjs/src/util/store.ts +134 -0
- package/source/external/dreamlandjs/src/vite/css-minifier.ts +222 -0
- package/source/external/dreamlandjs/src/vite/index.ts +60 -0
- package/source/external/dreamlandjs/src/vite/tsconfig.json +7 -0
- package/source/external/dreamlandjs/tsconfig.json +15 -0
- package/source/package.json +48 -0
- package/source/packages/adrift-protocol/package.json +31 -0
- package/source/packages/adrift-protocol/src/index.ts +348 -0
- package/source/packages/adrift-protocol/tsconfig.json +18 -0
- package/source/packages/cdp/LICENSE +21 -0
- package/source/packages/cdp/README.md +47 -0
- package/source/packages/cdp/dist/chobitsu.js +2 -0
- package/source/packages/cdp/dist/chobitsu.js.map +1 -0
- package/source/packages/cdp/package.json +73 -0
- package/source/packages/cdp/script/build.js +15 -0
- package/source/packages/cdp/src/Chobitsu.ts +110 -0
- package/source/packages/cdp/src/domains/CSS.ts +378 -0
- package/source/packages/cdp/src/domains/CacheStorage.ts +8 -0
- package/source/packages/cdp/src/domains/DOM.ts +487 -0
- package/source/packages/cdp/src/domains/DOMDebugger.ts +109 -0
- package/source/packages/cdp/src/domains/DOMStorage.ts +122 -0
- package/source/packages/cdp/src/domains/Debugger.ts +25 -0
- package/source/packages/cdp/src/domains/IndexedDB.ts +207 -0
- package/source/packages/cdp/src/domains/Input.ts +177 -0
- package/source/packages/cdp/src/domains/Network.ts +251 -0
- package/source/packages/cdp/src/domains/Overlay.ts +230 -0
- package/source/packages/cdp/src/domains/Page.ts +296 -0
- package/source/packages/cdp/src/domains/Runtime.ts +273 -0
- package/source/packages/cdp/src/domains/Storage.ts +71 -0
- package/source/packages/cdp/src/index.d.ts +8 -0
- package/source/packages/cdp/src/index.ts +153 -0
- package/source/packages/cdp/src/lib/connector.ts +15 -0
- package/source/packages/cdp/src/lib/constants.ts +1 -0
- package/source/packages/cdp/src/lib/evaluate.ts +59 -0
- package/source/packages/cdp/src/lib/mutationObserver.ts +39 -0
- package/source/packages/cdp/src/lib/nodeManager.ts +142 -0
- package/source/packages/cdp/src/lib/objManager.ts +422 -0
- package/source/packages/cdp/src/lib/request.ts +313 -0
- package/source/packages/cdp/src/lib/resources.ts +59 -0
- package/source/packages/cdp/src/lib/scriptMananger.ts +62 -0
- package/source/packages/cdp/src/lib/stylesheet.ts +146 -0
- package/source/packages/cdp/src/lib/util.ts +105 -0
- package/source/packages/cdp/tsconfig.json +16 -0
- package/source/packages/cdp/webpack.config.js +48 -0
- package/source/packages/chrome/index.html +17 -0
- package/source/packages/chrome/package.json +41 -0
- package/source/packages/chrome/public/ROXXIE_NETWORK.md +22 -0
- package/source/packages/chrome/public/controller.sw.js +273 -0
- package/source/packages/chrome/public/defaultfavicon.png +0 -0
- package/source/packages/chrome/public/icon.png +0 -0
- package/source/packages/chrome/public/localcontrollersw.js +7 -0
- package/source/packages/chrome/public/roxxie-icon.svg +12 -0
- package/source/packages/chrome/public/roxxie-network.json +13 -0
- package/source/packages/chrome/public/sw.js +6 -0
- package/source/packages/chrome/src/App.tsx +269 -0
- package/source/packages/chrome/src/CDP.ts +285 -0
- package/source/packages/chrome/src/Tab/History.ts +186 -0
- package/source/packages/chrome/src/Tab/Tab.tsx +219 -0
- package/source/packages/chrome/src/Tab/screenshot.ts +66 -0
- package/source/packages/chrome/src/Tab/serialize.ts +221 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.test.ts +159 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.ts +232 -0
- package/source/packages/chrome/src/adblock/AdBlockService.test.ts +148 -0
- package/source/packages/chrome/src/adblock/AdBlockService.ts +166 -0
- package/source/packages/chrome/src/adblock/NOTICE.md +14 -0
- package/source/packages/chrome/src/adblock/assets/filters.bin +0 -0
- package/source/packages/chrome/src/adblock/index.ts +18 -0
- package/source/packages/chrome/src/assets/favicon.ts +4 -0
- package/source/packages/chrome/src/components/BookmarkPopup.tsx +101 -0
- package/source/packages/chrome/src/components/BookmarksStrip.tsx +150 -0
- package/source/packages/chrome/src/components/Button.tsx +99 -0
- package/source/packages/chrome/src/components/Checkbox.tsx +89 -0
- package/source/packages/chrome/src/components/DownloadsPopup.tsx +230 -0
- package/source/packages/chrome/src/components/Favicon.tsx +65 -0
- package/source/packages/chrome/src/components/Icon.tsx +29 -0
- package/source/packages/chrome/src/components/Input.tsx +82 -0
- package/source/packages/chrome/src/components/Menu.tsx +287 -0
- package/source/packages/chrome/src/components/Omnibar/BookmarkButton.tsx +73 -0
- package/source/packages/chrome/src/components/Omnibar/CircularProgress.tsx +83 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibar.tsx +455 -0
- package/source/packages/chrome/src/components/Omnibar/OmnibarButton.tsx +48 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibox.tsx +466 -0
- package/source/packages/chrome/src/components/Omnibar/SiteOptionsButton.tsx +52 -0
- package/source/packages/chrome/src/components/Omnibar/Suggestion.tsx +186 -0
- package/source/packages/chrome/src/components/Omnibar/UrlInput.tsx +198 -0
- package/source/packages/chrome/src/components/Omnibar/suggestions.ts +468 -0
- package/source/packages/chrome/src/components/Omnibar/utils.ts +11 -0
- package/source/packages/chrome/src/components/ReportBrokenSiteModal.tsx +279 -0
- package/source/packages/chrome/src/components/Shell.tsx +191 -0
- package/source/packages/chrome/src/components/SiteInformationPopup.tsx +96 -0
- package/source/packages/chrome/src/components/SmallIconButton.tsx +36 -0
- package/source/packages/chrome/src/components/StartScreen.tsx +386 -0
- package/source/packages/chrome/src/components/TabStrip/DragTab.tsx +546 -0
- package/source/packages/chrome/src/components/TabStrip/Sidebar.tsx +820 -0
- package/source/packages/chrome/src/components/TabStrip/TabHoverCard.tsx +87 -0
- package/source/packages/chrome/src/components/TabStrip/TabStrip.tsx +510 -0
- package/source/packages/chrome/src/components/TopSiteButton.tsx +234 -0
- package/source/packages/chrome/src/consts.ts +3 -0
- package/source/packages/chrome/src/icons.ts +70 -0
- package/source/packages/chrome/src/index.ts +168 -0
- package/source/packages/chrome/src/migrations/0-from-legacy.ts +6 -0
- package/source/packages/chrome/src/migrations/1-vertical-tab-settings.ts +15 -0
- package/source/packages/chrome/src/migrations/index.ts +42 -0
- package/source/packages/chrome/src/pages/AboutPage.tsx +37 -0
- package/source/packages/chrome/src/pages/DownloadsPage.tsx +133 -0
- package/source/packages/chrome/src/pages/HistoryPage.tsx +99 -0
- package/source/packages/chrome/src/pages/NewTabPage.tsx +264 -0
- package/source/packages/chrome/src/pages/PlaygroundPage.tsx +43 -0
- package/source/packages/chrome/src/pages/SettingsPage.tsx +1931 -0
- package/source/packages/chrome/src/proxy/Controller.ts +331 -0
- package/source/packages/chrome/src/proxy/ProxyFrame.ts +26 -0
- package/source/packages/chrome/src/proxy/cache.ts +487 -0
- package/source/packages/chrome/src/proxy/codec.ts +11 -0
- package/source/packages/chrome/src/proxy/contextitems.ts +180 -0
- package/source/packages/chrome/src/proxy/index.ts +5 -0
- package/source/packages/chrome/src/proxy/roxxie.ts +85 -0
- package/source/packages/chrome/src/proxy/scramjet.ts +642 -0
- package/source/packages/chrome/src/reset.css +124 -0
- package/source/packages/chrome/src/runtime-base.ts +16 -0
- package/source/packages/chrome/src/sentry.tsx +45 -0
- package/source/packages/chrome/src/services/DownloadsService.ts +136 -0
- package/source/packages/chrome/src/services/FaviconService.ts +161 -0
- package/source/packages/chrome/src/services/KVWrapper.ts +169 -0
- package/source/packages/chrome/src/services/ProfileService.ts +94 -0
- package/source/packages/chrome/src/services/Service.ts +10 -0
- package/source/packages/chrome/src/services/SettingsService.ts +108 -0
- package/source/packages/chrome/src/services/TabsService.ts +161 -0
- package/source/packages/chrome/src/startup.test.ts +129 -0
- package/source/packages/chrome/src/startup.ts +161 -0
- package/source/packages/chrome/src/style.css +229 -0
- package/source/packages/chrome/src/themes.ts +756 -0
- package/source/packages/chrome/src/util/StatefulClass.ts +31 -0
- package/source/packages/chrome/src/util/index.ts +74 -0
- package/source/packages/chrome/src/util/memoize.ts +13 -0
- package/source/packages/chrome/src/vite-env.d.ts +16 -0
- package/source/packages/chrome/tsconfig.json +30 -0
- package/source/packages/chrome/vite.config.ts +47 -0
- package/source/packages/inject/package.json +20 -0
- package/source/packages/inject/src/context.ts +194 -0
- package/source/packages/inject/src/emulators/alwaysLastBubble.ts +168 -0
- package/source/packages/inject/src/emulators/anchors.ts +55 -0
- package/source/packages/inject/src/emulators/contextmenu.ts +46 -0
- package/source/packages/inject/src/emulators/history.ts +51 -0
- package/source/packages/inject/src/emulators/titlewatcher.ts +42 -0
- package/source/packages/inject/src/emulators/windowopen.ts +134 -0
- package/source/packages/inject/src/errorpage/errorpage.css +234 -0
- package/source/packages/inject/src/errorpage/errorpage.html +29 -0
- package/source/packages/inject/src/errorpage/errorpage.ts +76 -0
- package/source/packages/inject/src/index.ts +62 -0
- package/source/packages/inject/src/transport.ts +97 -0
- package/source/packages/inject/src/types.d.ts +136 -0
- package/source/packages/roxxie-transport/package.json +36 -0
- package/source/packages/roxxie-transport/src/binary.ts +398 -0
- package/source/packages/roxxie-transport/src/config.ts +254 -0
- package/source/packages/roxxie-transport/src/connection.ts +767 -0
- package/source/packages/roxxie-transport/src/index.ts +5 -0
- package/source/packages/roxxie-transport/src/tracker.ts +651 -0
- package/source/packages/roxxie-transport/src/transport.ts +414 -0
- package/source/packages/roxxie-transport/tsconfig.json +18 -0
- package/source/packages/scramjet/packages/controller/package.json +37 -0
- package/source/packages/scramjet/packages/controller/src/index.ts +861 -0
- package/source/packages/scramjet/packages/controller/src/inject.ts +365 -0
- package/source/packages/scramjet/packages/controller/src/sw.ts +231 -0
- package/source/packages/scramjet/packages/controller/src/symbols.ts +1 -0
- package/source/packages/scramjet/packages/controller/src/types.d.ts +140 -0
- package/source/packages/scramjet/packages/controller/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/controller/src/version.ts +30 -0
- package/source/packages/scramjet/packages/controller/tsconfig.json +24 -0
- package/source/packages/scramjet/packages/core/dist/scramjet-external.mjs +57 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js +13599 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs +13649 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.wasm +0 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js +13601 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs +13651 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js +23 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/types/Tap.d.ts +39 -0
- package/source/packages/scramjet/packages/core/dist/types/client/client.d.ts +115 -0
- package/source/packages/scramjet/packages/core/dist/types/client/entry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/dist/types/client/events.d.ts +10 -0
- package/source/packages/scramjet/packages/core/dist/types/client/helpers.d.ts +1 -0
- package/source/packages/scramjet/packages/core/dist/types/client/index.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/client/location.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/eval.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/sourcemaps.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/wrap.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/client/singletonbox.d.ts +18 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/body.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/fetch.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/headers.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/index.d.ts +128 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/parse.d.ts +23 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/util.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/index.d.ts +12 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/cookie.d.ts +26 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/headers.d.ts +13 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/htmlRules.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/index.d.ts +50 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/mime.d.ts +53 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/refresh.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/css.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/html.d.ts +33 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/index.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/js.d.ts +11 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/url.d.ts +24 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/wasm.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/worker.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/set-cookie-parser.d.ts +20 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/snapshot.d.ts +186 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/sniffEncoding.d.ts +65 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/util.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/symbols.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/types.d.ts +60 -0
- package/source/packages/scramjet/packages/core/dist/types/typesEntry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/lib/index.cjs +7 -0
- package/source/packages/scramjet/packages/core/lib/index.d.ts +8 -0
- package/source/packages/scramjet/packages/core/package.json +69 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.lock +1985 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.toml +20 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/Cargo.toml +15 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/analyze.rs +1118 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/ast_table.rs +927 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/helper_index.rs +556 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/lib.rs +455 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/reachability.rs +85 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/templates.rs +192 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/witness.rs +597 -0
- package/source/packages/scramjet/packages/core/rewriter/js/Cargo.toml +18 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/cfg.rs +45 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/changes.rs +379 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/lib.rs +171 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/rewrite.rs +290 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/visitor.rs +967 -0
- package/source/packages/scramjet/packages/core/rewriter/native/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/main.rs +166 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/rewriter.rs +161 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/test_runner.rs +156 -0
- package/source/packages/scramjet/packages/core/rewriter/rust-toolchain.toml +5 -0
- package/source/packages/scramjet/packages/core/rewriter/rustfmt.toml +2 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/Cargo.toml +16 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/lib.rs +242 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/transform.rs +123 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/build.sh +128 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/error.rs +56 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/jsr.rs +125 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/lib.rs +144 -0
- package/source/packages/scramjet/packages/core/src/Tap.ts +166 -0
- package/source/packages/scramjet/packages/core/src/client/client.ts +916 -0
- package/source/packages/scramjet/packages/core/src/client/dom/attr.ts +94 -0
- package/source/packages/scramjet/packages/core/src/client/dom/beacon.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/cookie.ts +21 -0
- package/source/packages/scramjet/packages/core/src/client/dom/css.ts +106 -0
- package/source/packages/scramjet/packages/core/src/client/dom/document.ts +140 -0
- package/source/packages/scramjet/packages/core/src/client/dom/element.ts +783 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fontface.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fragments.ts +32 -0
- package/source/packages/scramjet/packages/core/src/client/dom/history.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/dom/open.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/dom/origin.ts +13 -0
- package/source/packages/scramjet/packages/core/src/client/dom/performance.ts +50 -0
- package/source/packages/scramjet/packages/core/src/client/dom/protocol.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/dom/storage.ts +107 -0
- package/source/packages/scramjet/packages/core/src/client/entry.ts +12 -0
- package/source/packages/scramjet/packages/core/src/client/events.ts +10 -0
- package/source/packages/scramjet/packages/core/src/client/helpers.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/index.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/location.ts +139 -0
- package/source/packages/scramjet/packages/core/src/client/shared/antiantidebugger.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/blob.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/shared/caches.ts +31 -0
- package/source/packages/scramjet/packages/core/src/client/shared/chrome.ts +90 -0
- package/source/packages/scramjet/packages/core/src/client/shared/err.ts +55 -0
- package/source/packages/scramjet/packages/core/src/client/shared/error.ts +42 -0
- package/source/packages/scramjet/packages/core/src/client/shared/eval.ts +40 -0
- package/source/packages/scramjet/packages/core/src/client/shared/event.ts +215 -0
- package/source/packages/scramjet/packages/core/src/client/shared/function.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/shared/import.ts +46 -0
- package/source/packages/scramjet/packages/core/src/client/shared/indexeddb.ts +18 -0
- package/source/packages/scramjet/packages/core/src/client/shared/opfs.ts +27 -0
- package/source/packages/scramjet/packages/core/src/client/shared/postmessage.ts +113 -0
- package/source/packages/scramjet/packages/core/src/client/shared/realm.ts +26 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/eventsource.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/fetch.ts +67 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/websocket.ts +389 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/xmlhttprequest.ts +163 -0
- package/source/packages/scramjet/packages/core/src/client/shared/settimeout.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/sourcemaps.ts +203 -0
- package/source/packages/scramjet/packages/core/src/client/shared/worker.ts +72 -0
- package/source/packages/scramjet/packages/core/src/client/shared/wrap.ts +197 -0
- package/source/packages/scramjet/packages/core/src/client/singletonbox.ts +52 -0
- package/source/packages/scramjet/packages/core/src/client/worker/importScripts.ts +13 -0
- package/source/packages/scramjet/packages/core/src/fetch/body.ts +93 -0
- package/source/packages/scramjet/packages/core/src/fetch/fetch.ts +323 -0
- package/source/packages/scramjet/packages/core/src/fetch/headers.ts +528 -0
- package/source/packages/scramjet/packages/core/src/fetch/index.ts +198 -0
- package/source/packages/scramjet/packages/core/src/fetch/parse.ts +149 -0
- package/source/packages/scramjet/packages/core/src/fetch/util.ts +81 -0
- package/source/packages/scramjet/packages/core/src/global.d.ts +32 -0
- package/source/packages/scramjet/packages/core/src/index.ts +78 -0
- package/source/packages/scramjet/packages/core/src/log.ts +117 -0
- package/source/packages/scramjet/packages/core/src/shared/cookie.ts +199 -0
- package/source/packages/scramjet/packages/core/src/shared/headers.ts +76 -0
- package/source/packages/scramjet/packages/core/src/shared/htmlRules.ts +154 -0
- package/source/packages/scramjet/packages/core/src/shared/index.ts +79 -0
- package/source/packages/scramjet/packages/core/src/shared/mime.ts +234 -0
- package/source/packages/scramjet/packages/core/src/shared/refresh.ts +164 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/css.ts +67 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/html.ts +603 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/index.ts +6 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/js.ts +158 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/url.ts +248 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/wasm.ts +58 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/worker.ts +37 -0
- package/source/packages/scramjet/packages/core/src/shared/set-cookie-parser.ts +195 -0
- package/source/packages/scramjet/packages/core/src/shared/snapshot.ts +245 -0
- package/source/packages/scramjet/packages/core/src/shared/sniffEncoding.ts +1061 -0
- package/source/packages/scramjet/packages/core/src/shared/util.ts +35 -0
- package/source/packages/scramjet/packages/core/src/symbols.ts +9 -0
- package/source/packages/scramjet/packages/core/src/sync.ts +63 -0
- package/source/packages/scramjet/packages/core/src/types.ts +66 -0
- package/source/packages/scramjet/packages/core/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/core/tsconfig.json +21 -0
- package/source/packages/scramjet/packages/rpc/index.ts +100 -0
- package/source/packages/scramjet/packages/rpc/package.json +7 -0
- package/source/packages/scramjet/packages/utils/package.json +39 -0
- package/source/packages/scramjet/packages/utils/src/alwaysLastBubble.ts +172 -0
- package/source/packages/scramjet/packages/utils/src/catch-escaped-links.ts +34 -0
- package/source/packages/scramjet/packages/utils/src/event-handler-plugin.ts +86 -0
- package/source/packages/scramjet/packages/utils/src/global.d.ts +8 -0
- package/source/packages/scramjet/packages/utils/src/http-cache-plugin.ts +475 -0
- package/source/packages/scramjet/packages/utils/src/index.ts +26 -0
- package/source/packages/scramjet/packages/utils/src/link-handler-plugin.ts +75 -0
- package/source/packages/scramjet/packages/utils/src/typesEntry.ts +5 -0
- package/source/packages/scramjet/packages/utils/src/url-watcher.ts +37 -0
- package/source/packages/scramjet/packages/utils/src/version.ts +40 -0
- package/source/packages/scramjet/packages/utils/tsconfig.json +11 -0
- package/source/packages/scramjet/patches/htmlparser2@12.0.0.patch +124 -0
- package/source/packages/scramjet/rspack.config.ts +613 -0
- package/source/packages/scramjet/tsconfig.json +11 -0
- package/source/packages/tracker-protocol/package.json +31 -0
- package/source/packages/tracker-protocol/src/index.ts +745 -0
- package/source/packages/tracker-protocol/tsconfig.json +18 -0
- package/source/pnpm-lock.yaml +12018 -0
- package/source/pnpm-workspace.yaml +31 -0
- package/source/rspack.config.ts +103 -0
- package/source/scripts/update-adblock-assets.mjs +164 -0
- package/third_party/filter-lists/LICENSE-CC-BY-SA-3.0.txt +359 -0
- package/third_party/filter-lists/LICENSE-GPL-3.0.txt +674 -0
- package/third_party/filter-lists/LICENSE-MPL-2.0.txt +375 -0
- package/third_party/filter-lists/README.md +24 -0
- package/third_party/filter-lists/easylist.txt +83088 -0
- package/third_party/filter-lists/easyprivacy.txt +56361 -0
- package/third_party/filter-lists/manifest.json +56 -0
- package/third_party/filter-lists/ublock-filters.txt +10937 -0
- package/third_party/filter-lists/ublock-privacy.txt +3209 -0
- package/third_party/filter-lists/ublock-resources.json +1852 -0
- package/third_party/filter-lists/ublock-unbreak.txt +6026 -0
|
@@ -0,0 +1,1061 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHATWG Encoding Sniffing Algorithm
|
|
3
|
+
*
|
|
4
|
+
* Implements the encoding sniffing algorithm from the HTML spec:
|
|
5
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#determining-the-character-encoding
|
|
6
|
+
*
|
|
7
|
+
* And the "algorithm for extracting a character encoding from a meta element":
|
|
8
|
+
* https://html.spec.whatwg.org/multipage/urls-and-fetching.html#algorithm-for-extracting-a-character-encoding-from-a-meta-element
|
|
9
|
+
*
|
|
10
|
+
* And "get an encoding" from the Encoding spec:
|
|
11
|
+
* https://encoding.spec.whatwg.org/#concept-encoding-get
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { Math_min, String_fromCharCode } from "./snapshot";
|
|
15
|
+
|
|
16
|
+
// https://encoding.spec.whatwg.org/#concept-encoding-get
|
|
17
|
+
// Maps all labels (lowercased, stripped of leading/trailing ASCII whitespace) to their encoding name.
|
|
18
|
+
// This is the full table from the Encoding spec §4.2.
|
|
19
|
+
const ENCODING_LABELS: Record<string, string> = {
|
|
20
|
+
// UTF-8
|
|
21
|
+
"unicode-1-1-utf-8": "UTF-8",
|
|
22
|
+
unicode11utf8: "UTF-8",
|
|
23
|
+
unicode20utf8: "UTF-8",
|
|
24
|
+
"utf-8": "UTF-8",
|
|
25
|
+
utf8: "UTF-8",
|
|
26
|
+
"x-unicode20utf8": "UTF-8",
|
|
27
|
+
|
|
28
|
+
// IBM866
|
|
29
|
+
"866": "IBM866",
|
|
30
|
+
cp866: "IBM866",
|
|
31
|
+
csibm866: "IBM866",
|
|
32
|
+
ibm866: "IBM866",
|
|
33
|
+
|
|
34
|
+
// ISO-8859-2
|
|
35
|
+
csisolatin2: "ISO-8859-2",
|
|
36
|
+
"iso-8859-2": "ISO-8859-2",
|
|
37
|
+
"iso-ir-101": "ISO-8859-2",
|
|
38
|
+
"iso8859-2": "ISO-8859-2",
|
|
39
|
+
iso88592: "ISO-8859-2",
|
|
40
|
+
"iso_8859-2": "ISO-8859-2",
|
|
41
|
+
"iso_8859-2:1987": "ISO-8859-2",
|
|
42
|
+
l2: "ISO-8859-2",
|
|
43
|
+
latin2: "ISO-8859-2",
|
|
44
|
+
|
|
45
|
+
// ISO-8859-3
|
|
46
|
+
csisolatin3: "ISO-8859-3",
|
|
47
|
+
"iso-8859-3": "ISO-8859-3",
|
|
48
|
+
"iso-ir-109": "ISO-8859-3",
|
|
49
|
+
"iso8859-3": "ISO-8859-3",
|
|
50
|
+
iso88593: "ISO-8859-3",
|
|
51
|
+
"iso_8859-3": "ISO-8859-3",
|
|
52
|
+
"iso_8859-3:1988": "ISO-8859-3",
|
|
53
|
+
l3: "ISO-8859-3",
|
|
54
|
+
latin3: "ISO-8859-3",
|
|
55
|
+
|
|
56
|
+
// ISO-8859-4
|
|
57
|
+
csisolatin4: "ISO-8859-4",
|
|
58
|
+
"iso-8859-4": "ISO-8859-4",
|
|
59
|
+
"iso-ir-110": "ISO-8859-4",
|
|
60
|
+
"iso8859-4": "ISO-8859-4",
|
|
61
|
+
iso88594: "ISO-8859-4",
|
|
62
|
+
"iso_8859-4": "ISO-8859-4",
|
|
63
|
+
"iso_8859-4:1988": "ISO-8859-4",
|
|
64
|
+
l4: "ISO-8859-4",
|
|
65
|
+
latin4: "ISO-8859-4",
|
|
66
|
+
|
|
67
|
+
// ISO-8859-5
|
|
68
|
+
csisolatincyrillic: "ISO-8859-5",
|
|
69
|
+
cyrillic: "ISO-8859-5",
|
|
70
|
+
"iso-8859-5": "ISO-8859-5",
|
|
71
|
+
"iso-ir-144": "ISO-8859-5",
|
|
72
|
+
"iso8859-5": "ISO-8859-5",
|
|
73
|
+
iso88595: "ISO-8859-5",
|
|
74
|
+
"iso_8859-5": "ISO-8859-5",
|
|
75
|
+
"iso_8859-5:1988": "ISO-8859-5",
|
|
76
|
+
|
|
77
|
+
// ISO-8859-6
|
|
78
|
+
arabic: "ISO-8859-6",
|
|
79
|
+
"asmo-708": "ISO-8859-6",
|
|
80
|
+
csiso88596e: "ISO-8859-6",
|
|
81
|
+
csiso88596i: "ISO-8859-6",
|
|
82
|
+
csisolatinarabic: "ISO-8859-6",
|
|
83
|
+
"ecma-114": "ISO-8859-6",
|
|
84
|
+
"iso-8859-6": "ISO-8859-6",
|
|
85
|
+
"iso-8859-6-e": "ISO-8859-6",
|
|
86
|
+
"iso-8859-6-i": "ISO-8859-6",
|
|
87
|
+
"iso-ir-127": "ISO-8859-6",
|
|
88
|
+
"iso8859-6": "ISO-8859-6",
|
|
89
|
+
iso88596: "ISO-8859-6",
|
|
90
|
+
"iso_8859-6": "ISO-8859-6",
|
|
91
|
+
"iso_8859-6:1987": "ISO-8859-6",
|
|
92
|
+
|
|
93
|
+
// ISO-8859-7
|
|
94
|
+
csisolatingreek: "ISO-8859-7",
|
|
95
|
+
"ecma-118": "ISO-8859-7",
|
|
96
|
+
elot_928: "ISO-8859-7",
|
|
97
|
+
greek: "ISO-8859-7",
|
|
98
|
+
greek8: "ISO-8859-7",
|
|
99
|
+
"iso-8859-7": "ISO-8859-7",
|
|
100
|
+
"iso-ir-126": "ISO-8859-7",
|
|
101
|
+
"iso8859-7": "ISO-8859-7",
|
|
102
|
+
iso88597: "ISO-8859-7",
|
|
103
|
+
"iso_8859-7": "ISO-8859-7",
|
|
104
|
+
"iso_8859-7:1987": "ISO-8859-7",
|
|
105
|
+
sun_eu_greek: "ISO-8859-7",
|
|
106
|
+
|
|
107
|
+
// ISO-8859-8
|
|
108
|
+
csiso88598e: "ISO-8859-8",
|
|
109
|
+
csisolatinhebrew: "ISO-8859-8",
|
|
110
|
+
hebrew: "ISO-8859-8",
|
|
111
|
+
"iso-8859-8": "ISO-8859-8",
|
|
112
|
+
"iso-8859-8-e": "ISO-8859-8",
|
|
113
|
+
"iso-ir-138": "ISO-8859-8",
|
|
114
|
+
"iso8859-8": "ISO-8859-8",
|
|
115
|
+
iso88598: "ISO-8859-8",
|
|
116
|
+
"iso_8859-8": "ISO-8859-8",
|
|
117
|
+
"iso_8859-8:1988": "ISO-8859-8",
|
|
118
|
+
visual: "ISO-8859-8",
|
|
119
|
+
|
|
120
|
+
// ISO-8859-8-I
|
|
121
|
+
csiso88598i: "ISO-8859-8-I",
|
|
122
|
+
"iso-8859-8-i": "ISO-8859-8-I",
|
|
123
|
+
logical: "ISO-8859-8-I",
|
|
124
|
+
|
|
125
|
+
// ISO-8859-10
|
|
126
|
+
csisolatin6: "ISO-8859-10",
|
|
127
|
+
"iso-8859-10": "ISO-8859-10",
|
|
128
|
+
"iso-ir-157": "ISO-8859-10",
|
|
129
|
+
"iso8859-10": "ISO-8859-10",
|
|
130
|
+
iso885910: "ISO-8859-10",
|
|
131
|
+
l6: "ISO-8859-10",
|
|
132
|
+
latin6: "ISO-8859-10",
|
|
133
|
+
|
|
134
|
+
// ISO-8859-13
|
|
135
|
+
"iso-8859-13": "ISO-8859-13",
|
|
136
|
+
"iso8859-13": "ISO-8859-13",
|
|
137
|
+
iso885913: "ISO-8859-13",
|
|
138
|
+
|
|
139
|
+
// ISO-8859-14
|
|
140
|
+
"iso-8859-14": "ISO-8859-14",
|
|
141
|
+
"iso8859-14": "ISO-8859-14",
|
|
142
|
+
iso885914: "ISO-8859-14",
|
|
143
|
+
|
|
144
|
+
// ISO-8859-15
|
|
145
|
+
csisolatin9: "ISO-8859-15",
|
|
146
|
+
"iso-8859-15": "ISO-8859-15",
|
|
147
|
+
"iso8859-15": "ISO-8859-15",
|
|
148
|
+
iso885915: "ISO-8859-15",
|
|
149
|
+
"iso_8859-15": "ISO-8859-15",
|
|
150
|
+
l9: "ISO-8859-15",
|
|
151
|
+
|
|
152
|
+
// ISO-8859-16
|
|
153
|
+
"iso-8859-16": "ISO-8859-16",
|
|
154
|
+
|
|
155
|
+
// KOI8-R
|
|
156
|
+
cskoi8r: "KOI8-R",
|
|
157
|
+
koi: "KOI8-R",
|
|
158
|
+
koi8: "KOI8-R",
|
|
159
|
+
"koi8-r": "KOI8-R",
|
|
160
|
+
koi8_r: "KOI8-R",
|
|
161
|
+
|
|
162
|
+
// KOI8-U
|
|
163
|
+
"koi8-ru": "KOI8-U",
|
|
164
|
+
"koi8-u": "KOI8-U",
|
|
165
|
+
|
|
166
|
+
// macintosh
|
|
167
|
+
csmacintosh: "macintosh",
|
|
168
|
+
mac: "macintosh",
|
|
169
|
+
macintosh: "macintosh",
|
|
170
|
+
"x-mac-roman": "macintosh",
|
|
171
|
+
|
|
172
|
+
// windows-874
|
|
173
|
+
"dos-874": "windows-874",
|
|
174
|
+
"iso-8859-11": "windows-874",
|
|
175
|
+
"iso8859-11": "windows-874",
|
|
176
|
+
iso885911: "windows-874",
|
|
177
|
+
"tis-620": "windows-874",
|
|
178
|
+
"windows-874": "windows-874",
|
|
179
|
+
|
|
180
|
+
// windows-1250
|
|
181
|
+
cp1250: "windows-1250",
|
|
182
|
+
"windows-1250": "windows-1250",
|
|
183
|
+
"x-cp1250": "windows-1250",
|
|
184
|
+
|
|
185
|
+
// windows-1251
|
|
186
|
+
cp1251: "windows-1251",
|
|
187
|
+
"windows-1251": "windows-1251",
|
|
188
|
+
"x-cp1251": "windows-1251",
|
|
189
|
+
|
|
190
|
+
// windows-1252
|
|
191
|
+
"ansi_x3.4-1968": "windows-1252",
|
|
192
|
+
ascii: "windows-1252",
|
|
193
|
+
cp1252: "windows-1252",
|
|
194
|
+
cp819: "windows-1252",
|
|
195
|
+
csisolatin1: "windows-1252",
|
|
196
|
+
ibm819: "windows-1252",
|
|
197
|
+
"iso-8859-1": "windows-1252",
|
|
198
|
+
"iso-ir-100": "windows-1252",
|
|
199
|
+
"iso8859-1": "windows-1252",
|
|
200
|
+
iso88591: "windows-1252",
|
|
201
|
+
"iso_8859-1": "windows-1252",
|
|
202
|
+
"iso_8859-1:1987": "windows-1252",
|
|
203
|
+
l1: "windows-1252",
|
|
204
|
+
latin1: "windows-1252",
|
|
205
|
+
"us-ascii": "windows-1252",
|
|
206
|
+
"windows-1252": "windows-1252",
|
|
207
|
+
"x-cp1252": "windows-1252",
|
|
208
|
+
|
|
209
|
+
// windows-1253
|
|
210
|
+
cp1253: "windows-1253",
|
|
211
|
+
"windows-1253": "windows-1253",
|
|
212
|
+
"x-cp1253": "windows-1253",
|
|
213
|
+
|
|
214
|
+
// windows-1254
|
|
215
|
+
cp1254: "windows-1254",
|
|
216
|
+
csisolatin5: "windows-1254",
|
|
217
|
+
"iso-8859-9": "windows-1254",
|
|
218
|
+
"iso-ir-148": "windows-1254",
|
|
219
|
+
"iso8859-9": "windows-1254",
|
|
220
|
+
iso88599: "windows-1254",
|
|
221
|
+
"iso_8859-9": "windows-1254",
|
|
222
|
+
"iso_8859-9:1989": "windows-1254",
|
|
223
|
+
l5: "windows-1254",
|
|
224
|
+
latin5: "windows-1254",
|
|
225
|
+
"windows-1254": "windows-1254",
|
|
226
|
+
"x-cp1254": "windows-1254",
|
|
227
|
+
|
|
228
|
+
// windows-1255
|
|
229
|
+
cp1255: "windows-1255",
|
|
230
|
+
"windows-1255": "windows-1255",
|
|
231
|
+
"x-cp1255": "windows-1255",
|
|
232
|
+
|
|
233
|
+
// windows-1256
|
|
234
|
+
cp1256: "windows-1256",
|
|
235
|
+
"windows-1256": "windows-1256",
|
|
236
|
+
"x-cp1256": "windows-1256",
|
|
237
|
+
|
|
238
|
+
// windows-1257
|
|
239
|
+
cp1257: "windows-1257",
|
|
240
|
+
"windows-1257": "windows-1257",
|
|
241
|
+
"x-cp1257": "windows-1257",
|
|
242
|
+
|
|
243
|
+
// windows-1258
|
|
244
|
+
cp1258: "windows-1258",
|
|
245
|
+
"windows-1258": "windows-1258",
|
|
246
|
+
"x-cp1258": "windows-1258",
|
|
247
|
+
|
|
248
|
+
// x-mac-cyrillic
|
|
249
|
+
"x-mac-cyrillic": "x-mac-cyrillic",
|
|
250
|
+
"x-mac-ukrainian": "x-mac-cyrillic",
|
|
251
|
+
|
|
252
|
+
// GBK
|
|
253
|
+
chinese: "GBK",
|
|
254
|
+
csgb2312: "GBK",
|
|
255
|
+
csiso58gb231280: "GBK",
|
|
256
|
+
gb2312: "GBK",
|
|
257
|
+
gb_2312: "GBK",
|
|
258
|
+
"gb_2312-80": "GBK",
|
|
259
|
+
gbk: "GBK",
|
|
260
|
+
"iso-ir-58": "GBK",
|
|
261
|
+
"x-gbk": "GBK",
|
|
262
|
+
|
|
263
|
+
// gb18030
|
|
264
|
+
gb18030: "gb18030",
|
|
265
|
+
|
|
266
|
+
// Big5
|
|
267
|
+
big5: "Big5",
|
|
268
|
+
"big5-hkscs": "Big5",
|
|
269
|
+
"cn-big5": "Big5",
|
|
270
|
+
csbig5: "Big5",
|
|
271
|
+
"x-x-big5": "Big5",
|
|
272
|
+
|
|
273
|
+
// EUC-JP
|
|
274
|
+
cseucpkdfmtjapanese: "EUC-JP",
|
|
275
|
+
"euc-jp": "EUC-JP",
|
|
276
|
+
"x-euc-jp": "EUC-JP",
|
|
277
|
+
|
|
278
|
+
// ISO-2022-JP
|
|
279
|
+
csiso2022jp: "ISO-2022-JP",
|
|
280
|
+
"iso-2022-jp": "ISO-2022-JP",
|
|
281
|
+
|
|
282
|
+
// Shift_JIS
|
|
283
|
+
csshiftjis: "Shift_JIS",
|
|
284
|
+
ms932: "Shift_JIS",
|
|
285
|
+
ms_kanji: "Shift_JIS",
|
|
286
|
+
"shift-jis": "Shift_JIS",
|
|
287
|
+
shift_jis: "Shift_JIS",
|
|
288
|
+
sjis: "Shift_JIS",
|
|
289
|
+
"windows-31j": "Shift_JIS",
|
|
290
|
+
"x-sjis": "Shift_JIS",
|
|
291
|
+
|
|
292
|
+
// EUC-KR
|
|
293
|
+
cseuckr: "EUC-KR",
|
|
294
|
+
csksc56011987: "EUC-KR",
|
|
295
|
+
"euc-kr": "EUC-KR",
|
|
296
|
+
"iso-ir-149": "EUC-KR",
|
|
297
|
+
korean: "EUC-KR",
|
|
298
|
+
"ks_c_5601-1987": "EUC-KR",
|
|
299
|
+
"ks_c_5601-1989": "EUC-KR",
|
|
300
|
+
ksc5601: "EUC-KR",
|
|
301
|
+
ksc_5601: "EUC-KR",
|
|
302
|
+
"windows-949": "EUC-KR",
|
|
303
|
+
|
|
304
|
+
// replacement
|
|
305
|
+
csiso2022kr: "replacement",
|
|
306
|
+
"hz-gb-2312": "replacement",
|
|
307
|
+
"iso-2022-cn": "replacement",
|
|
308
|
+
"iso-2022-cn-ext": "replacement",
|
|
309
|
+
"iso-2022-kr": "replacement",
|
|
310
|
+
replacement: "replacement",
|
|
311
|
+
|
|
312
|
+
// UTF-16BE
|
|
313
|
+
unicodefffe: "UTF-16BE",
|
|
314
|
+
"utf-16be": "UTF-16BE",
|
|
315
|
+
|
|
316
|
+
// UTF-16LE
|
|
317
|
+
csunicode: "UTF-16LE",
|
|
318
|
+
"iso-10646-ucs-2": "UTF-16LE",
|
|
319
|
+
"ucs-2": "UTF-16LE",
|
|
320
|
+
unicode: "UTF-16LE",
|
|
321
|
+
unicodefeff: "UTF-16LE",
|
|
322
|
+
"utf-16": "UTF-16LE",
|
|
323
|
+
"utf-16le": "UTF-16LE",
|
|
324
|
+
|
|
325
|
+
// x-user-defined
|
|
326
|
+
"x-user-defined": "x-user-defined",
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* https://encoding.spec.whatwg.org/#concept-encoding-get
|
|
331
|
+
*
|
|
332
|
+
* "To get an encoding from a string label":
|
|
333
|
+
* 1. Remove any leading and trailing ASCII whitespace from label.
|
|
334
|
+
* 2. If label is an ASCII case-insensitive match for any of the labels listed
|
|
335
|
+
* in the table, return the corresponding encoding; otherwise return failure.
|
|
336
|
+
*/
|
|
337
|
+
export function getEncoding(label: string): string | null {
|
|
338
|
+
const trimmed = label.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, "");
|
|
339
|
+
return ENCODING_LABELS[trimmed.toLowerCase()] ?? null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* https://html.spec.whatwg.org/multipage/urls-and-fetching.html#algorithm-for-extracting-a-character-encoding-from-a-meta-element
|
|
344
|
+
*
|
|
345
|
+
* The algorithm for extracting a character encoding from a `meta` element,
|
|
346
|
+
* given a string s.
|
|
347
|
+
*/
|
|
348
|
+
export function extractCharsetFromMeta(s: string): string | null {
|
|
349
|
+
let position = 0;
|
|
350
|
+
|
|
351
|
+
// Step 2: Loop — find "charset" (case-insensitive) after position
|
|
352
|
+
while (true) {
|
|
353
|
+
const idx = s.toLowerCase().indexOf("charset", position);
|
|
354
|
+
if (idx === -1) return null;
|
|
355
|
+
|
|
356
|
+
position = idx + "charset".length;
|
|
357
|
+
|
|
358
|
+
// Step 3: Skip ASCII whitespace
|
|
359
|
+
while (
|
|
360
|
+
position < s.length &&
|
|
361
|
+
(s[position] === "\t" ||
|
|
362
|
+
s[position] === "\n" ||
|
|
363
|
+
s[position] === "\f" ||
|
|
364
|
+
s[position] === "\r" ||
|
|
365
|
+
s[position] === " ")
|
|
366
|
+
) {
|
|
367
|
+
position++;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Step 4: If next char is not '=', go back to loop
|
|
371
|
+
if (position >= s.length || s[position] !== "=") {
|
|
372
|
+
// Move position to just before the next character and re-loop
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Skip the '='
|
|
377
|
+
position++;
|
|
378
|
+
|
|
379
|
+
// Step 5: Skip ASCII whitespace
|
|
380
|
+
while (
|
|
381
|
+
position < s.length &&
|
|
382
|
+
(s[position] === "\t" ||
|
|
383
|
+
s[position] === "\n" ||
|
|
384
|
+
s[position] === "\f" ||
|
|
385
|
+
s[position] === "\r" ||
|
|
386
|
+
s[position] === " ")
|
|
387
|
+
) {
|
|
388
|
+
position++;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Step 6: Process the next character
|
|
392
|
+
if (position >= s.length) return null;
|
|
393
|
+
|
|
394
|
+
const ch = s[position];
|
|
395
|
+
|
|
396
|
+
// eslint-disable-next-line quotes
|
|
397
|
+
if (ch === '"' || ch === "'") {
|
|
398
|
+
// Find matching close quote
|
|
399
|
+
const closeIdx = s.indexOf(ch, position + 1);
|
|
400
|
+
if (closeIdx === -1) {
|
|
401
|
+
// Unmatched quote
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
const value = s.substring(position + 1, closeIdx);
|
|
405
|
+
return getEncoding(value);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Otherwise: collect until ASCII whitespace or semicolon or end
|
|
409
|
+
let end = position;
|
|
410
|
+
while (
|
|
411
|
+
end < s.length &&
|
|
412
|
+
s[end] !== "\t" &&
|
|
413
|
+
s[end] !== "\n" &&
|
|
414
|
+
s[end] !== "\f" &&
|
|
415
|
+
s[end] !== "\r" &&
|
|
416
|
+
s[end] !== " " &&
|
|
417
|
+
s[end] !== ";"
|
|
418
|
+
) {
|
|
419
|
+
end++;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (end === position) return null;
|
|
423
|
+
|
|
424
|
+
const value = s.substring(position, end);
|
|
425
|
+
return getEncoding(value);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Check if a byte is ASCII whitespace or slash (used in prescan)
|
|
430
|
+
function isSpaceOrSlash(byte: number): boolean {
|
|
431
|
+
return (
|
|
432
|
+
byte === 0x09 || // HT
|
|
433
|
+
byte === 0x0a || // LF
|
|
434
|
+
byte === 0x0c || // FF
|
|
435
|
+
byte === 0x0d || // CR
|
|
436
|
+
byte === 0x20 || // SP
|
|
437
|
+
byte === 0x2f // /
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function isSpace(byte: number): boolean {
|
|
442
|
+
return (
|
|
443
|
+
byte === 0x09 || // HT
|
|
444
|
+
byte === 0x0a || // LF
|
|
445
|
+
byte === 0x0c || // FF
|
|
446
|
+
byte === 0x0d || // CR
|
|
447
|
+
byte === 0x20 // SP
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
interface Attribute {
|
|
452
|
+
name: string;
|
|
453
|
+
value: string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#prescan-a-byte-stream-to-determine-its-encoding
|
|
458
|
+
*
|
|
459
|
+
* "Get an attribute" sub-algorithm used by the prescan algorithm.
|
|
460
|
+
* Returns null if no attribute was found, or the attribute {name, value}.
|
|
461
|
+
*
|
|
462
|
+
* `pos` is an object with a `value` property so we can mutate it.
|
|
463
|
+
*/
|
|
464
|
+
function getAttribute(
|
|
465
|
+
bytes: Uint8Array,
|
|
466
|
+
pos: { value: number }
|
|
467
|
+
): Attribute | null {
|
|
468
|
+
// Step 1: Skip spaces and slashes
|
|
469
|
+
while (pos.value < bytes.length && isSpaceOrSlash(bytes[pos.value])) {
|
|
470
|
+
pos.value++;
|
|
471
|
+
}
|
|
472
|
+
if (pos.value >= bytes.length) return null;
|
|
473
|
+
|
|
474
|
+
// Step 2: If '>', no attribute
|
|
475
|
+
if (bytes[pos.value] === 0x3e) return null;
|
|
476
|
+
|
|
477
|
+
// Step 3: Start of attribute name
|
|
478
|
+
let name = "";
|
|
479
|
+
let value = "";
|
|
480
|
+
|
|
481
|
+
// Step 4: Process bytes for attribute name
|
|
482
|
+
while (pos.value < bytes.length) {
|
|
483
|
+
const b = bytes[pos.value];
|
|
484
|
+
|
|
485
|
+
if (b === 0x3d && name.length > 0) {
|
|
486
|
+
// '=' and name is non-empty — advance and go to value
|
|
487
|
+
pos.value++;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (isSpace(b)) {
|
|
492
|
+
// Go to "spaces" step
|
|
493
|
+
pos.value++;
|
|
494
|
+
goto_spaces();
|
|
495
|
+
return finishFromSpaces();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (b === 0x2f || b === 0x3e) {
|
|
499
|
+
// '/' or '>' — attribute name only, empty value
|
|
500
|
+
return { name, value: "" };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// A-Z -> lowercase
|
|
504
|
+
if (b >= 0x41 && b <= 0x5a) {
|
|
505
|
+
name += String_fromCharCode(b + 0x20);
|
|
506
|
+
} else {
|
|
507
|
+
name += String_fromCharCode(b);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
pos.value++;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (pos.value >= bytes.length) return null;
|
|
514
|
+
|
|
515
|
+
// We got here because we found '=' — now parse value
|
|
516
|
+
return parseValue();
|
|
517
|
+
|
|
518
|
+
function goto_spaces() {
|
|
519
|
+
// Step 6: Skip spaces
|
|
520
|
+
while (pos.value < bytes.length && isSpace(bytes[pos.value])) {
|
|
521
|
+
pos.value++;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function finishFromSpaces(): Attribute | null {
|
|
526
|
+
if (pos.value >= bytes.length) return null;
|
|
527
|
+
|
|
528
|
+
// Step 7: If not '=', return name with empty value
|
|
529
|
+
if (bytes[pos.value] !== 0x3d) {
|
|
530
|
+
return { name, value: "" };
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Step 8: Advance past '='
|
|
534
|
+
pos.value++;
|
|
535
|
+
|
|
536
|
+
return parseValue();
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function parseValue(): Attribute | null {
|
|
540
|
+
// Step 9: Skip spaces before value
|
|
541
|
+
while (pos.value < bytes.length && isSpace(bytes[pos.value])) {
|
|
542
|
+
pos.value++;
|
|
543
|
+
}
|
|
544
|
+
if (pos.value >= bytes.length) return null;
|
|
545
|
+
|
|
546
|
+
const b = bytes[pos.value];
|
|
547
|
+
|
|
548
|
+
// Step 10: Check for quoted value
|
|
549
|
+
if (b === 0x22 || b === 0x27) {
|
|
550
|
+
// " or '
|
|
551
|
+
const quoteChar = b;
|
|
552
|
+
pos.value++;
|
|
553
|
+
|
|
554
|
+
while (pos.value < bytes.length) {
|
|
555
|
+
const qb = bytes[pos.value];
|
|
556
|
+
if (qb === quoteChar) {
|
|
557
|
+
pos.value++;
|
|
558
|
+
return { name, value };
|
|
559
|
+
}
|
|
560
|
+
// A-Z -> lowercase
|
|
561
|
+
if (qb >= 0x41 && qb <= 0x5a) {
|
|
562
|
+
value += String_fromCharCode(qb + 0x20);
|
|
563
|
+
} else {
|
|
564
|
+
value += String_fromCharCode(qb);
|
|
565
|
+
}
|
|
566
|
+
pos.value++;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Ran out of bytes inside quoted value
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// '>'
|
|
574
|
+
if (b === 0x3e) {
|
|
575
|
+
return { name, value: "" };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// A-Z -> lowercase for first char
|
|
579
|
+
if (b >= 0x41 && b <= 0x5a) {
|
|
580
|
+
value += String_fromCharCode(b + 0x20);
|
|
581
|
+
} else {
|
|
582
|
+
value += String_fromCharCode(b);
|
|
583
|
+
}
|
|
584
|
+
pos.value++;
|
|
585
|
+
|
|
586
|
+
// Step 11: Unquoted value — collect until space or '>'
|
|
587
|
+
while (pos.value < bytes.length) {
|
|
588
|
+
const ub = bytes[pos.value];
|
|
589
|
+
|
|
590
|
+
if (isSpace(ub) || ub === 0x3e) {
|
|
591
|
+
return { name, value };
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// A-Z -> lowercase
|
|
595
|
+
if (ub >= 0x41 && ub <= 0x5a) {
|
|
596
|
+
value += String_fromCharCode(ub + 0x20);
|
|
597
|
+
} else {
|
|
598
|
+
value += String_fromCharCode(ub);
|
|
599
|
+
}
|
|
600
|
+
pos.value++;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return { name, value };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#prescan-a-byte-stream-to-determine-its-encoding
|
|
609
|
+
*
|
|
610
|
+
* Prescan the first `limit` bytes of a byte stream to determine its encoding.
|
|
611
|
+
* Returns an encoding name or null if none found.
|
|
612
|
+
*/
|
|
613
|
+
export function prescanByteStream(
|
|
614
|
+
bytes: Uint8Array,
|
|
615
|
+
limit: number = 1024
|
|
616
|
+
): string | null {
|
|
617
|
+
const end = Math_min(bytes.length, limit);
|
|
618
|
+
const pos = { value: 0 };
|
|
619
|
+
|
|
620
|
+
// Step 2: Prescan for UTF-16 XML declarations
|
|
621
|
+
if (
|
|
622
|
+
end >= 6 &&
|
|
623
|
+
bytes[0] === 0x3c &&
|
|
624
|
+
bytes[1] === 0x00 &&
|
|
625
|
+
bytes[2] === 0x3f &&
|
|
626
|
+
bytes[3] === 0x00 &&
|
|
627
|
+
bytes[4] === 0x78 &&
|
|
628
|
+
bytes[5] === 0x00
|
|
629
|
+
) {
|
|
630
|
+
return "UTF-16LE";
|
|
631
|
+
}
|
|
632
|
+
if (
|
|
633
|
+
end >= 6 &&
|
|
634
|
+
bytes[0] === 0x00 &&
|
|
635
|
+
bytes[1] === 0x3c &&
|
|
636
|
+
bytes[2] === 0x00 &&
|
|
637
|
+
bytes[3] === 0x3f &&
|
|
638
|
+
bytes[4] === 0x00 &&
|
|
639
|
+
bytes[5] === 0x78
|
|
640
|
+
) {
|
|
641
|
+
return "UTF-16BE";
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Step 3: Loop
|
|
645
|
+
while (pos.value < end) {
|
|
646
|
+
const b = bytes[pos.value];
|
|
647
|
+
|
|
648
|
+
// Check for <!--
|
|
649
|
+
if (
|
|
650
|
+
b === 0x3c &&
|
|
651
|
+
pos.value + 3 < end &&
|
|
652
|
+
bytes[pos.value + 1] === 0x21 &&
|
|
653
|
+
bytes[pos.value + 2] === 0x2d &&
|
|
654
|
+
bytes[pos.value + 3] === 0x2d
|
|
655
|
+
) {
|
|
656
|
+
// Advance to first '>' preceded by '--'
|
|
657
|
+
pos.value += 4;
|
|
658
|
+
while (pos.value < end) {
|
|
659
|
+
if (
|
|
660
|
+
bytes[pos.value] === 0x3e &&
|
|
661
|
+
pos.value >= 2 &&
|
|
662
|
+
bytes[pos.value - 1] === 0x2d &&
|
|
663
|
+
bytes[pos.value - 2] === 0x2d
|
|
664
|
+
) {
|
|
665
|
+
pos.value++;
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
pos.value++;
|
|
669
|
+
}
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Check for <meta (case-insensitive)
|
|
674
|
+
if (
|
|
675
|
+
b === 0x3c &&
|
|
676
|
+
pos.value + 5 < end &&
|
|
677
|
+
(bytes[pos.value + 1] === 0x4d || bytes[pos.value + 1] === 0x6d) && // M or m
|
|
678
|
+
(bytes[pos.value + 2] === 0x45 || bytes[pos.value + 2] === 0x65) && // E or e
|
|
679
|
+
(bytes[pos.value + 3] === 0x54 || bytes[pos.value + 3] === 0x74) && // T or t
|
|
680
|
+
(bytes[pos.value + 4] === 0x41 || bytes[pos.value + 4] === 0x61) && // A or a
|
|
681
|
+
isSpaceOrSlash(bytes[pos.value + 5])
|
|
682
|
+
) {
|
|
683
|
+
// Step: Advance position to the space/slash
|
|
684
|
+
pos.value += 5;
|
|
685
|
+
|
|
686
|
+
const attributeList: string[] = [];
|
|
687
|
+
let gotPragma = false;
|
|
688
|
+
let needPragma: boolean | null = null;
|
|
689
|
+
let charset: string | null = null;
|
|
690
|
+
|
|
691
|
+
// Attributes loop
|
|
692
|
+
while (true) {
|
|
693
|
+
const attr = getAttribute(bytes, pos);
|
|
694
|
+
if (!attr) break;
|
|
695
|
+
|
|
696
|
+
// Step 7: If already in list, skip
|
|
697
|
+
if (attributeList.includes(attr.name)) continue;
|
|
698
|
+
|
|
699
|
+
// Step 8: Add to list
|
|
700
|
+
attributeList.push(attr.name);
|
|
701
|
+
|
|
702
|
+
// Step 9: Process
|
|
703
|
+
if (attr.name === "http-equiv") {
|
|
704
|
+
if (attr.value === "content-type") {
|
|
705
|
+
gotPragma = true;
|
|
706
|
+
}
|
|
707
|
+
} else if (attr.name === "content") {
|
|
708
|
+
if (charset === null) {
|
|
709
|
+
const extracted = extractCharsetFromMeta(attr.value);
|
|
710
|
+
if (extracted !== null) {
|
|
711
|
+
charset = extracted;
|
|
712
|
+
needPragma = true;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
} else if (attr.name === "charset") {
|
|
716
|
+
charset = getEncoding(attr.value);
|
|
717
|
+
needPragma = false;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// Processing steps
|
|
722
|
+
// Step 11: If needPragma is null, skip
|
|
723
|
+
if (needPragma === null) {
|
|
724
|
+
pos.value++;
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Step 12: If needPragma is true but gotPragma is false, skip
|
|
729
|
+
if (needPragma === true && !gotPragma) {
|
|
730
|
+
pos.value++;
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// Step 13: If charset is failure (null), skip
|
|
735
|
+
if (charset === null) {
|
|
736
|
+
pos.value++;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// Step 14: If charset is UTF-16BE/LE, set to UTF-8
|
|
741
|
+
if (charset === "UTF-16BE" || charset === "UTF-16LE") {
|
|
742
|
+
charset = "UTF-8";
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Step 15: If charset is x-user-defined, set to windows-1252
|
|
746
|
+
if (charset === "x-user-defined") {
|
|
747
|
+
charset = "windows-1252";
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// Step 16: Return charset
|
|
751
|
+
return charset;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// Check for tag: < optionally /, then A-Z or a-z
|
|
755
|
+
if (
|
|
756
|
+
b === 0x3c &&
|
|
757
|
+
pos.value + 1 < end &&
|
|
758
|
+
(isAsciiAlpha(bytes[pos.value + 1]) ||
|
|
759
|
+
(bytes[pos.value + 1] === 0x2f &&
|
|
760
|
+
pos.value + 2 < end &&
|
|
761
|
+
isAsciiAlpha(bytes[pos.value + 2])))
|
|
762
|
+
) {
|
|
763
|
+
// Advance to next space/tab/LF/FF/CR or >
|
|
764
|
+
pos.value++;
|
|
765
|
+
while (
|
|
766
|
+
pos.value < end &&
|
|
767
|
+
!isSpace(bytes[pos.value]) &&
|
|
768
|
+
bytes[pos.value] !== 0x3e
|
|
769
|
+
) {
|
|
770
|
+
pos.value++;
|
|
771
|
+
}
|
|
772
|
+
// Get attributes until none
|
|
773
|
+
while (pos.value < end) {
|
|
774
|
+
const attr = getAttribute(bytes, pos);
|
|
775
|
+
if (!attr) break;
|
|
776
|
+
}
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// Check for <!, </, <?
|
|
781
|
+
if (
|
|
782
|
+
b === 0x3c &&
|
|
783
|
+
pos.value + 1 < end &&
|
|
784
|
+
(bytes[pos.value + 1] === 0x21 ||
|
|
785
|
+
bytes[pos.value + 1] === 0x2f ||
|
|
786
|
+
bytes[pos.value + 1] === 0x3f)
|
|
787
|
+
) {
|
|
788
|
+
// Advance to first '>'
|
|
789
|
+
pos.value += 2;
|
|
790
|
+
while (pos.value < end && bytes[pos.value] !== 0x3e) {
|
|
791
|
+
pos.value++;
|
|
792
|
+
}
|
|
793
|
+
if (pos.value < end) pos.value++; // skip the >
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// Any other byte — do nothing, next byte
|
|
798
|
+
pos.value++;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// If prescan didn't find anything, try get an XML encoding
|
|
802
|
+
return getXmlEncoding(bytes, end);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function isAsciiAlpha(byte: number): boolean {
|
|
806
|
+
return (byte >= 0x41 && byte <= 0x5a) || (byte >= 0x61 && byte <= 0x7a);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#prescan-a-byte-stream-to-determine-its-encoding
|
|
811
|
+
*
|
|
812
|
+
* "get an XML encoding" — invoked when the prescan algorithm aborts without
|
|
813
|
+
* returning an encoding.
|
|
814
|
+
*/
|
|
815
|
+
function getXmlEncoding(bytes: Uint8Array, end: number): string | null {
|
|
816
|
+
// Step 2: Check for <?xml
|
|
817
|
+
if (
|
|
818
|
+
end < 5 ||
|
|
819
|
+
bytes[0] !== 0x3c || // <
|
|
820
|
+
bytes[1] !== 0x3f || // ?
|
|
821
|
+
bytes[2] !== 0x78 || // x
|
|
822
|
+
bytes[3] !== 0x6d || // m
|
|
823
|
+
bytes[4] !== 0x6c // l
|
|
824
|
+
) {
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Step 3: Find '>' for the xml declaration end
|
|
829
|
+
let xmlEnd = -1;
|
|
830
|
+
for (let i = 5; i < end; i++) {
|
|
831
|
+
if (bytes[i] === 0x3e) {
|
|
832
|
+
xmlEnd = i;
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (xmlEnd === -1) return null;
|
|
837
|
+
|
|
838
|
+
// Step 4: Find "encoding" in the xml declaration
|
|
839
|
+
const declBytes = bytes.subarray(0, xmlEnd);
|
|
840
|
+
let encPos = -1;
|
|
841
|
+
const target = [0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67]; // "encoding"
|
|
842
|
+
for (let i = 5; i <= declBytes.length - target.length; i++) {
|
|
843
|
+
let match = true;
|
|
844
|
+
for (let j = 0; j < target.length; j++) {
|
|
845
|
+
if (declBytes[i + j] !== target[j]) {
|
|
846
|
+
match = false;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
if (match) {
|
|
851
|
+
encPos = i + target.length;
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (encPos === -1) return null;
|
|
856
|
+
|
|
857
|
+
// Step 6: Skip spaces/control chars (bytes <= 0x20)
|
|
858
|
+
while (encPos < xmlEnd && declBytes[encPos] <= 0x20) {
|
|
859
|
+
encPos++;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Step 7: Must be '='
|
|
863
|
+
if (encPos >= xmlEnd || declBytes[encPos] !== 0x3d) return null;
|
|
864
|
+
encPos++;
|
|
865
|
+
|
|
866
|
+
// Step 9: Skip spaces/control chars
|
|
867
|
+
while (encPos < xmlEnd && declBytes[encPos] <= 0x20) {
|
|
868
|
+
encPos++;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// Step 10-11: quoteMark must be " or '
|
|
872
|
+
if (encPos >= xmlEnd) return null;
|
|
873
|
+
const quoteMark = declBytes[encPos];
|
|
874
|
+
if (quoteMark !== 0x22 && quoteMark !== 0x27) return null;
|
|
875
|
+
encPos++;
|
|
876
|
+
|
|
877
|
+
// Step 13: Find closing quote
|
|
878
|
+
let encEnd = -1;
|
|
879
|
+
for (let i = encPos; i < xmlEnd; i++) {
|
|
880
|
+
if (declBytes[i] === quoteMark) {
|
|
881
|
+
encEnd = i;
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (encEnd === -1) return null;
|
|
886
|
+
|
|
887
|
+
// Step 14: potentialEncoding
|
|
888
|
+
const potentialEncoding = declBytes.subarray(encPos, encEnd);
|
|
889
|
+
|
|
890
|
+
// Step 15: If it contains bytes <= 0x20, return failure
|
|
891
|
+
for (let i = 0; i < potentialEncoding.length; i++) {
|
|
892
|
+
if (potentialEncoding[i] <= 0x20) return null;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// Step 16: Get encoding
|
|
896
|
+
const encodingName = String_fromCharCode(...potentialEncoding);
|
|
897
|
+
let encoding = getEncoding(encodingName);
|
|
898
|
+
|
|
899
|
+
// Step 17: If UTF-16BE/LE, change to UTF-8
|
|
900
|
+
if (encoding === "UTF-16BE" || encoding === "UTF-16LE") {
|
|
901
|
+
encoding = "UTF-8";
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return encoding;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* https://encoding.spec.whatwg.org/#bom-sniff
|
|
909
|
+
*
|
|
910
|
+
* BOM sniff: check the first 2-3 bytes for a byte order mark.
|
|
911
|
+
*/
|
|
912
|
+
export function bomSniff(bytes: Uint8Array): string | null {
|
|
913
|
+
if (
|
|
914
|
+
bytes.length >= 3 &&
|
|
915
|
+
bytes[0] === 0xef &&
|
|
916
|
+
bytes[1] === 0xbb &&
|
|
917
|
+
bytes[2] === 0xbf
|
|
918
|
+
) {
|
|
919
|
+
return "UTF-8";
|
|
920
|
+
}
|
|
921
|
+
if (bytes.length >= 2 && bytes[0] === 0xfe && bytes[1] === 0xff) {
|
|
922
|
+
return "UTF-16BE";
|
|
923
|
+
}
|
|
924
|
+
if (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xfe) {
|
|
925
|
+
return "UTF-16LE";
|
|
926
|
+
}
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Extract the charset parameter from a Content-Type header value.
|
|
932
|
+
*
|
|
933
|
+
* This parses the Content-Type more carefully than a naive split — it handles
|
|
934
|
+
* quoted values and multiple parameters.
|
|
935
|
+
*
|
|
936
|
+
* This follows what MIME Sniffing / HTTP specs say: find `charset=` parameter.
|
|
937
|
+
*/
|
|
938
|
+
export function extractCharsetFromContentType(
|
|
939
|
+
contentType: string
|
|
940
|
+
): string | null {
|
|
941
|
+
// Find the parameters section (after the first semicolon)
|
|
942
|
+
const semicolonIdx = contentType.indexOf(";");
|
|
943
|
+
if (semicolonIdx === -1) return null;
|
|
944
|
+
|
|
945
|
+
let params = contentType.substring(semicolonIdx + 1);
|
|
946
|
+
|
|
947
|
+
// We may have multiple parameters; iterate through them
|
|
948
|
+
while (params.length > 0) {
|
|
949
|
+
// Trim leading whitespace
|
|
950
|
+
params = params.replace(/^[\t\n\f\r ]+/, "");
|
|
951
|
+
|
|
952
|
+
// Try to find charset=
|
|
953
|
+
const lower = params.toLowerCase();
|
|
954
|
+
if (lower.startsWith("charset")) {
|
|
955
|
+
let pos = "charset".length;
|
|
956
|
+
|
|
957
|
+
// Skip whitespace
|
|
958
|
+
while (
|
|
959
|
+
pos < params.length &&
|
|
960
|
+
(params[pos] === " " ||
|
|
961
|
+
params[pos] === "\t" ||
|
|
962
|
+
params[pos] === "\n" ||
|
|
963
|
+
params[pos] === "\f" ||
|
|
964
|
+
params[pos] === "\r")
|
|
965
|
+
) {
|
|
966
|
+
pos++;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if (pos < params.length && params[pos] === "=") {
|
|
970
|
+
pos++;
|
|
971
|
+
|
|
972
|
+
// Skip whitespace
|
|
973
|
+
while (
|
|
974
|
+
pos < params.length &&
|
|
975
|
+
(params[pos] === " " ||
|
|
976
|
+
params[pos] === "\t" ||
|
|
977
|
+
params[pos] === "\n" ||
|
|
978
|
+
params[pos] === "\f" ||
|
|
979
|
+
params[pos] === "\r")
|
|
980
|
+
) {
|
|
981
|
+
pos++;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
if (pos >= params.length) return null;
|
|
985
|
+
|
|
986
|
+
// Quoted value
|
|
987
|
+
// eslint-disable-next-line quotes
|
|
988
|
+
if (params[pos] === '"') {
|
|
989
|
+
pos++;
|
|
990
|
+
let value = "";
|
|
991
|
+
// eslint-disable-next-line quotes
|
|
992
|
+
while (pos < params.length && params[pos] !== '"') {
|
|
993
|
+
// Handle backslash escape in quoted string per HTTP spec
|
|
994
|
+
if (params[pos] === "\\" && pos + 1 < params.length) {
|
|
995
|
+
pos++;
|
|
996
|
+
}
|
|
997
|
+
value += params[pos];
|
|
998
|
+
pos++;
|
|
999
|
+
}
|
|
1000
|
+
return getEncoding(value);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// Unquoted value — collect until ; or end
|
|
1004
|
+
let value = "";
|
|
1005
|
+
while (
|
|
1006
|
+
pos < params.length &&
|
|
1007
|
+
params[pos] !== ";" &&
|
|
1008
|
+
params[pos] !== " " &&
|
|
1009
|
+
params[pos] !== "\t"
|
|
1010
|
+
) {
|
|
1011
|
+
value += params[pos];
|
|
1012
|
+
pos++;
|
|
1013
|
+
}
|
|
1014
|
+
return getEncoding(value);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// Skip to next parameter
|
|
1019
|
+
const nextSemicolon = params.indexOf(";");
|
|
1020
|
+
if (nextSemicolon === -1) break;
|
|
1021
|
+
params = params.substring(nextSemicolon + 1);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Determine the character encoding of an HTML document's byte stream.
|
|
1029
|
+
*
|
|
1030
|
+
* Implements a simplified version of the WHATWG encoding sniffing algorithm
|
|
1031
|
+
* for use in a service worker / proxy context:
|
|
1032
|
+
*
|
|
1033
|
+
* 1. BOM sniffing (certain)
|
|
1034
|
+
* 2. Transport layer: Content-Type header charset parameter (certain)
|
|
1035
|
+
* 3. Prescan byte stream: look for <meta charset> or
|
|
1036
|
+
* <meta http-equiv="content-type" content="...charset=..."> in first 1024 bytes (tentative)
|
|
1037
|
+
* 4. Default to UTF-8
|
|
1038
|
+
*
|
|
1039
|
+
* Returns an encoding name suitable for use with TextDecoder.
|
|
1040
|
+
*/
|
|
1041
|
+
export function sniffEncoding(
|
|
1042
|
+
bytes: Uint8Array,
|
|
1043
|
+
contentTypeHeader: string | null
|
|
1044
|
+
): string {
|
|
1045
|
+
// Step 1: BOM sniff
|
|
1046
|
+
const bom = bomSniff(bytes);
|
|
1047
|
+
if (bom) return bom;
|
|
1048
|
+
|
|
1049
|
+
// Step 4: Transport layer (Content-Type header charset)
|
|
1050
|
+
if (contentTypeHeader) {
|
|
1051
|
+
const transportCharset = extractCharsetFromContentType(contentTypeHeader);
|
|
1052
|
+
if (transportCharset) return transportCharset;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Step 5: Prescan
|
|
1056
|
+
const prescanResult = prescanByteStream(bytes, 1024);
|
|
1057
|
+
if (prescanResult) return prescanResult;
|
|
1058
|
+
|
|
1059
|
+
// Step 9: Default
|
|
1060
|
+
return "UTF-8";
|
|
1061
|
+
}
|