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,242 @@
|
|
|
1
|
+
use std::{fmt::Display, marker::PhantomData};
|
|
2
|
+
|
|
3
|
+
use oxc::{
|
|
4
|
+
allocator::{Allocator, Vec},
|
|
5
|
+
span::Span,
|
|
6
|
+
};
|
|
7
|
+
use thiserror::Error;
|
|
8
|
+
|
|
9
|
+
pub mod transform;
|
|
10
|
+
use transform::{Transform, TransformType};
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Error)]
|
|
13
|
+
pub enum TransformError {
|
|
14
|
+
#[cfg(not(feature = "debug"))]
|
|
15
|
+
#[error("out of bounds while applying range {0}..{1} for {2} (span {3}..{4})")]
|
|
16
|
+
Oob(u32, u32, &'static str, u32, u32),
|
|
17
|
+
#[cfg(feature = "debug")]
|
|
18
|
+
#[error(
|
|
19
|
+
"out of bounds while applying range {0}..{1} for {2} (span {3}..{4}, last few spans: {5})"
|
|
20
|
+
)]
|
|
21
|
+
Oob(u32, u32, &'static str, u32, u32, LastSpans),
|
|
22
|
+
|
|
23
|
+
#[cfg(feature = "debug")]
|
|
24
|
+
#[error("Spans inside each other, all spans: {0}")]
|
|
25
|
+
InvalidSpans(LastSpans),
|
|
26
|
+
|
|
27
|
+
#[error("too much code added while applying changes at cursor {0}")]
|
|
28
|
+
AddedTooLarge(u32),
|
|
29
|
+
#[error("Allocator already set")]
|
|
30
|
+
AllocSet,
|
|
31
|
+
#[error("Allocator not set")]
|
|
32
|
+
AllocUnset,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[cfg(feature = "debug")]
|
|
36
|
+
#[derive(Debug)]
|
|
37
|
+
pub struct LastSpans(std::vec::Vec<(Span, std::string::String)>);
|
|
38
|
+
#[cfg(feature = "debug")]
|
|
39
|
+
impl Display for LastSpans {
|
|
40
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
41
|
+
write!(f, "\n(current) ")?;
|
|
42
|
+
for span in &self.0 {
|
|
43
|
+
writeln!(f, "{}..{}: {}", span.0.start, span.0.end, span.1)?;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Ok(())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub struct TransformResult<'alloc> {
|
|
51
|
+
pub source: Vec<'alloc, u8>,
|
|
52
|
+
pub map: Vec<'alloc, u8>,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
pub struct Transformer<'alloc, 'data, T: Transform<'data>> {
|
|
56
|
+
phantom: PhantomData<&'data str>,
|
|
57
|
+
alloc: Option<&'alloc Allocator>,
|
|
58
|
+
inner: std::vec::Vec<T>,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl<'data, T: Transform<'data>> Default for Transformer<'_, 'data, T> {
|
|
62
|
+
fn default() -> Self {
|
|
63
|
+
Self::new()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
impl<'alloc, 'data, T: Transform<'data>> Transformer<'alloc, 'data, T> {
|
|
68
|
+
pub fn new() -> Self {
|
|
69
|
+
Self {
|
|
70
|
+
phantom: PhantomData,
|
|
71
|
+
inner: std::vec::Vec::new(),
|
|
72
|
+
alloc: None,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pub fn add(&mut self, rewrite: impl IntoIterator<Item = T>) {
|
|
77
|
+
self.inner.extend(rewrite);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
pub fn set_alloc(&mut self, alloc: &'alloc Allocator) -> Result<(), TransformError> {
|
|
81
|
+
if self.alloc.is_some() {
|
|
82
|
+
Err(TransformError::AllocSet)
|
|
83
|
+
} else {
|
|
84
|
+
self.alloc.replace(alloc);
|
|
85
|
+
Ok(())
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
pub fn take_alloc(&mut self) -> Result<(), TransformError> {
|
|
90
|
+
self.alloc
|
|
91
|
+
.take()
|
|
92
|
+
.ok_or(TransformError::AllocUnset)
|
|
93
|
+
.map(|_| ())
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pub fn get_alloc(&self) -> Result<&'alloc Allocator, TransformError> {
|
|
97
|
+
self.alloc.ok_or(TransformError::AllocUnset)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub fn empty(&self) -> bool {
|
|
101
|
+
self.inner.is_empty()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
pub fn perform(
|
|
105
|
+
&mut self,
|
|
106
|
+
js: &'data str,
|
|
107
|
+
data: &T::ToLowLevelData,
|
|
108
|
+
build_map: bool,
|
|
109
|
+
) -> Result<TransformResult<'alloc>, TransformError> {
|
|
110
|
+
let mut itoa = itoa::Buffer::new();
|
|
111
|
+
|
|
112
|
+
let alloc = self.get_alloc()?;
|
|
113
|
+
|
|
114
|
+
let mut cursor = 0;
|
|
115
|
+
let mut offset = 0i32;
|
|
116
|
+
let mut buffer = Vec::with_capacity_in(js.len() * 2, alloc);
|
|
117
|
+
|
|
118
|
+
#[cfg(feature = "debug")]
|
|
119
|
+
let mut debug_vec = std::vec::Vec::new();
|
|
120
|
+
|
|
121
|
+
macro_rules! tryget {
|
|
122
|
+
($reason:literal, $start:ident..$end:ident, $span:ident) => {{
|
|
123
|
+
let ret = js.get($start as usize..$end as usize);
|
|
124
|
+
#[cfg(not(feature = "debug"))]
|
|
125
|
+
{
|
|
126
|
+
ret.ok_or_else(|| {
|
|
127
|
+
TransformError::Oob($start, $end, $reason, $span.start, $span.end)
|
|
128
|
+
})?
|
|
129
|
+
}
|
|
130
|
+
#[cfg(feature = "debug")]
|
|
131
|
+
{
|
|
132
|
+
ret.ok_or_else(|| {
|
|
133
|
+
TransformError::Oob(
|
|
134
|
+
$start,
|
|
135
|
+
$end,
|
|
136
|
+
$reason,
|
|
137
|
+
$span.start,
|
|
138
|
+
$span.end,
|
|
139
|
+
LastSpans(debug_vec.iter().rev().cloned().take(6).collect()),
|
|
140
|
+
)
|
|
141
|
+
})?
|
|
142
|
+
}
|
|
143
|
+
}};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// insert has a 9 byte size, replace has a 13 byte minimum and usually it's like 5 bytes
|
|
147
|
+
// for the old str added on so use 16 as a really rough estimate
|
|
148
|
+
let mut map = if build_map {
|
|
149
|
+
let mut map = Vec::with_capacity_in((self.inner.len() * 16) + 4, alloc);
|
|
150
|
+
map.extend_from_slice(&(self.inner.len() as u32).to_le_bytes());
|
|
151
|
+
map
|
|
152
|
+
} else {
|
|
153
|
+
Vec::new_in(alloc)
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
self.inner.sort();
|
|
157
|
+
|
|
158
|
+
#[cfg(feature = "debug")]
|
|
159
|
+
{
|
|
160
|
+
let mut last_end = 0;
|
|
161
|
+
for change in &self.inner {
|
|
162
|
+
let span = change.span();
|
|
163
|
+
if last_end > span.start {
|
|
164
|
+
let vec = self
|
|
165
|
+
.inner
|
|
166
|
+
.drain(..)
|
|
167
|
+
.map(|x| {
|
|
168
|
+
(
|
|
169
|
+
x.span(),
|
|
170
|
+
x.into_low_level(data, 0).to_string(&mut itoa, alloc),
|
|
171
|
+
)
|
|
172
|
+
})
|
|
173
|
+
.collect();
|
|
174
|
+
return Err(TransformError::InvalidSpans(LastSpans(vec)));
|
|
175
|
+
}
|
|
176
|
+
last_end = span.end;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for change in self.inner.drain(..) {
|
|
181
|
+
let span = change.span();
|
|
182
|
+
let Span { start, end, .. } = span;
|
|
183
|
+
|
|
184
|
+
let transform = change.into_low_level(data, offset);
|
|
185
|
+
#[cfg(feature = "debug")]
|
|
186
|
+
debug_vec.push((span, transform.to_string(&mut itoa, alloc)));
|
|
187
|
+
|
|
188
|
+
buffer.extend_from_slice(tryget!("cursor -> start", cursor..start, span).as_bytes());
|
|
189
|
+
|
|
190
|
+
let len = transform.apply(&mut itoa, &mut buffer);
|
|
191
|
+
if build_map {
|
|
192
|
+
// pos
|
|
193
|
+
map.extend_from_slice(&start.wrapping_add_signed(offset).to_le_bytes());
|
|
194
|
+
// size
|
|
195
|
+
map.extend_from_slice(&len.to_le_bytes());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
match transform.ty {
|
|
199
|
+
TransformType::Insert => {
|
|
200
|
+
buffer.extend_from_slice(
|
|
201
|
+
tryget!("insert: start -> end", start..end, span).as_bytes(),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if build_map {
|
|
205
|
+
// INSERT op
|
|
206
|
+
map.push(0);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
offset = offset.wrapping_add_unsigned(len);
|
|
210
|
+
}
|
|
211
|
+
TransformType::Replace => {
|
|
212
|
+
if build_map {
|
|
213
|
+
// REPLACE op
|
|
214
|
+
map.push(1);
|
|
215
|
+
// len
|
|
216
|
+
map.extend_from_slice(&(end - start).to_le_bytes());
|
|
217
|
+
// oldstr
|
|
218
|
+
map.extend_from_slice(
|
|
219
|
+
tryget!("replace: start -> end", start..end, span).as_bytes(),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let len =
|
|
224
|
+
i32::try_from(len).map_err(|_| TransformError::AddedTooLarge(cursor))?;
|
|
225
|
+
let diff = len.wrapping_sub_unsigned(end - start);
|
|
226
|
+
offset = offset.wrapping_add(diff);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
cursor = end;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let js_len = js.len() as u32;
|
|
234
|
+
let span = Span::new(0, js_len);
|
|
235
|
+
buffer.extend_from_slice(tryget!("cursor -> js end", cursor..js_len, span).as_bytes());
|
|
236
|
+
|
|
237
|
+
Ok(TransformResult {
|
|
238
|
+
source: buffer,
|
|
239
|
+
map,
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
use oxc::{
|
|
2
|
+
allocator::{Allocator, Vec},
|
|
3
|
+
ast::ast::AssignmentOperator,
|
|
4
|
+
span::{Atom, Span},
|
|
5
|
+
};
|
|
6
|
+
use smallvec::SmallVec;
|
|
7
|
+
|
|
8
|
+
pub use smallvec as vecimpl;
|
|
9
|
+
|
|
10
|
+
pub enum TransformElement<'a> {
|
|
11
|
+
Str(&'a str),
|
|
12
|
+
U32(u32),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl TransformElement<'_> {
|
|
16
|
+
fn eval(&self, itoa: &mut itoa::Buffer, buffer: &mut Vec<'_, u8>) -> usize {
|
|
17
|
+
match self {
|
|
18
|
+
TransformElement::Str(x) => {
|
|
19
|
+
buffer.extend_from_slice(x.as_bytes());
|
|
20
|
+
x.len()
|
|
21
|
+
}
|
|
22
|
+
TransformElement::U32(x) => {
|
|
23
|
+
let x = itoa.format(*x);
|
|
24
|
+
buffer.extend_from_slice(x.as_bytes());
|
|
25
|
+
x.len()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
impl<'a> From<&'a str> for TransformElement<'a> {
|
|
32
|
+
fn from(value: &'a str) -> Self {
|
|
33
|
+
Self::Str(value)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
impl<'a> From<&&'a str> for TransformElement<'a> {
|
|
38
|
+
fn from(value: &&'a str) -> Self {
|
|
39
|
+
Self::Str(value)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
impl<'a> From<&'a String> for TransformElement<'a> {
|
|
44
|
+
fn from(value: &'a String) -> Self {
|
|
45
|
+
Self::Str(value)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
impl<'a> From<Atom<'a>> for TransformElement<'a> {
|
|
50
|
+
fn from(value: Atom<'a>) -> Self {
|
|
51
|
+
Self::Str(value.as_str())
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
impl From<AssignmentOperator> for TransformElement<'static> {
|
|
56
|
+
fn from(value: AssignmentOperator) -> Self {
|
|
57
|
+
Self::Str(value.as_str())
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl From<u32> for TransformElement<'static> {
|
|
62
|
+
fn from(value: u32) -> Self {
|
|
63
|
+
Self::U32(value)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub type TransformElements<'a> = SmallVec<[TransformElement<'a>; 8]>;
|
|
68
|
+
|
|
69
|
+
pub enum TransformType {
|
|
70
|
+
Insert,
|
|
71
|
+
Replace,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
pub trait Transform<'a>: Ord {
|
|
75
|
+
type ToLowLevelData: 'a;
|
|
76
|
+
|
|
77
|
+
fn span(&self) -> Span;
|
|
78
|
+
fn into_low_level(self, data: &Self::ToLowLevelData, offset: i32) -> TransformLL<'a>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pub struct TransformLL<'a> {
|
|
82
|
+
pub ty: TransformType,
|
|
83
|
+
pub change: TransformElements<'a>,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
impl<'a> TransformLL<'a> {
|
|
87
|
+
pub fn insert(change: TransformElements<'a>) -> Self {
|
|
88
|
+
Self {
|
|
89
|
+
ty: TransformType::Insert,
|
|
90
|
+
change,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pub fn replace(change: TransformElements<'a>) -> Self {
|
|
95
|
+
Self {
|
|
96
|
+
ty: TransformType::Replace,
|
|
97
|
+
change,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pub fn apply(&self, itoa: &mut itoa::Buffer, buffer: &mut Vec<'_, u8>) -> u32 {
|
|
102
|
+
let mut len = 0;
|
|
103
|
+
|
|
104
|
+
for str in &self.change {
|
|
105
|
+
len += str.eval(itoa, buffer) as u32;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
len
|
|
109
|
+
}
|
|
110
|
+
pub fn to_string(&self, itoa: &mut itoa::Buffer, alloc: &Allocator) -> String {
|
|
111
|
+
let mut vec = Vec::new_in(alloc);
|
|
112
|
+
self.apply(itoa, &mut vec);
|
|
113
|
+
std::str::from_utf8(&vec).unwrap().to_string()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[macro_export]
|
|
118
|
+
macro_rules! transforms {
|
|
119
|
+
[] => { $crate::transform::vecimpl::SmallVec::new() };
|
|
120
|
+
[$($change:expr),+] => {
|
|
121
|
+
$crate::transform::vecimpl::smallvec![$(transform::transform::TransformElement::from($change)),+]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "wasm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[lints]
|
|
7
|
+
workspace = true
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
crate-type = ["cdylib"]
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
js-sys = "0.3.82"
|
|
14
|
+
oxc = { workspace = true }
|
|
15
|
+
js = { version = "0.1.0", path = "../js", default-features = false }
|
|
16
|
+
thiserror = "2.0.17"
|
|
17
|
+
wasm-bindgen = "0.2.105"
|
|
18
|
+
web-sys = { version = "0.3.82", features = ["Url","UrlSearchParams"] }
|
|
19
|
+
|
|
20
|
+
[features]
|
|
21
|
+
default = ["debug"]
|
|
22
|
+
debug = ["js/debug"]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
shopt -s inherit_errexit
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if ! [ "${RELEASE:-0}" = "1" ]; then
|
|
8
|
+
WASMOPTFLAGS="${WASMOPTFLAGS:-} -g"
|
|
9
|
+
FEATURES="debug,${FEATURES:-}"
|
|
10
|
+
else
|
|
11
|
+
: "${WASMOPTFLAGS:=}"
|
|
12
|
+
: "${FEATURES:=}"
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
MODE="release"
|
|
16
|
+
if [ "${RELEASE:-0}" != "1" ]; then MODE="debug"; fi
|
|
17
|
+
# shellcheck disable=SC2046
|
|
18
|
+
SRC_HASH=$( (echo "MODE=${MODE}"; sha256sum $(find ../ -type f -not -path "*/\.*" -and \( -name "*.rs" -o -name "*.toml" -o -name "*.sh" -o -name "*.json" -o -name "*.md" \); echo Cargo.toml; echo build.sh) 2>/dev/null | sort -k2 | sha256sum ) | sha256sum | cut -d' ' -f1 ) || SRC_HASH="unknown"
|
|
19
|
+
|
|
20
|
+
if [ -f out/.build-hash ] && [ -f ../../dist/scramjet.wasm ] && [ "$SRC_HASH" != "unknown" ] && grep -q "$SRC_HASH" out/.build-hash; then
|
|
21
|
+
echo "Rewriter sources unchanged (hash $SRC_HASH); skipping rebuild."
|
|
22
|
+
exit 0
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
which cargo wasm-bindgen wasm-opt wasm-snip &> /dev/null || {
|
|
26
|
+
echo "Please install cargo, wasm-bindgen, wasm-opt from https://github.com/WebAssembly/binaryen, and wasm-snip from https://github.com/r58playz/wasm-snip!"
|
|
27
|
+
exit 1
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
WBG="wasm-bindgen 0.2.105"
|
|
31
|
+
if ! [[ "$(wasm-bindgen -V)" =~ ^"$WBG" ]]; then
|
|
32
|
+
echo "Incorrect wasm-bindgen-cli version: '$(wasm-bindgen -V)' != '$WBG'"
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
(
|
|
37
|
+
export RUSTFLAGS='-Zlocation-detail=none -Zfmt-debug=none'
|
|
38
|
+
if [ "${OPTIMIZE_FOR_SIZE:-0}" = "1" ]; then
|
|
39
|
+
export RUSTFLAGS="${RUSTFLAGS} -C opt-level=z"
|
|
40
|
+
fi
|
|
41
|
+
STD_FEATURES=""
|
|
42
|
+
if [ "${OPTIMIZE_FOR_SPEED:-0}" = "0" ]; then
|
|
43
|
+
STD_FEATURES="${STD_FEATURES},optimize_for_size"
|
|
44
|
+
fi
|
|
45
|
+
cargo +nightly build --release --target wasm32-unknown-unknown \
|
|
46
|
+
-Z build-std=panic_abort,std -Z build-std-features=${STD_FEATURES} \
|
|
47
|
+
--no-default-features --features "$FEATURES"
|
|
48
|
+
)
|
|
49
|
+
wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/wasm.wasm
|
|
50
|
+
|
|
51
|
+
if [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "freebsd"* ]] || [[ "$OSTYPE" == "dragonfly"* ]]; then
|
|
52
|
+
sed -i '' 's/import.meta.url/""/g' out/wasm.js
|
|
53
|
+
else
|
|
54
|
+
sed -i 's/import.meta.url/""/g' out/wasm.js
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
cd ../../
|
|
58
|
+
|
|
59
|
+
wasm-snip rewriter/wasm/out/wasm_bg.wasm -o rewriter/wasm/out/wasm_snipped.wasm \
|
|
60
|
+
-p 'oxc_regular_expression::.*' \
|
|
61
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_non_array_type' \
|
|
62
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_import_type' \
|
|
63
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator_or_higher' \
|
|
64
|
+
'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_interface_declaration' \
|
|
65
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_mapped_type' \
|
|
66
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_index_signature_declaration' \
|
|
67
|
+
'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_import_equals_declaration' \
|
|
68
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_or_type_predicate' \
|
|
69
|
+
'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_namespace_or_module_declaration_body' \
|
|
70
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_implements_clause' \
|
|
71
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_intersection_type_or_higher' \
|
|
72
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_name' \
|
|
73
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_literal_type_node' \
|
|
74
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_asserts_type_predicate' \
|
|
75
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_tuple_element_type' \
|
|
76
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_of_type_reference' \
|
|
77
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_call_signature_member' \
|
|
78
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::is_start_of_type' \
|
|
79
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_this_type_predicate' \
|
|
80
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_query' \
|
|
81
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_reference' \
|
|
82
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_operator' \
|
|
83
|
+
'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_literal' \
|
|
84
|
+
'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_enum_declaration' \
|
|
85
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element' \
|
|
86
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_identifier' \
|
|
87
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_element_name' \
|
|
88
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_children' \
|
|
89
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_fragment' \
|
|
90
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression_container' \
|
|
91
|
+
'oxc_parser::jsx::<impl oxc_parser::ParserImpl>::parse_jsx_expression'
|
|
92
|
+
#
|
|
93
|
+
# these are confirmed to break oxc
|
|
94
|
+
# 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_declaration' \
|
|
95
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type' \
|
|
96
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_type_arguments_in_expression' \
|
|
97
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_type_parameters' \
|
|
98
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_class_element_modifiers' \
|
|
99
|
+
# 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::eat_decorators' \
|
|
100
|
+
# 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_nth_at_modifier' \
|
|
101
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::try_parse_type_arguments' \
|
|
102
|
+
# 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::is_at_ts_index_signature_member' \
|
|
103
|
+
# 'oxc_parser::ts::types::<impl oxc_parser::ParserImpl>::parse_ts_return_type_annotation' \
|
|
104
|
+
# 'oxc_parser::ts::statement::<impl oxc_parser::ParserImpl>::parse_ts_type_annotation' \
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if [ "${RELEASE:-0}" = "1" ]; then
|
|
108
|
+
(
|
|
109
|
+
G="--generate-global-effects"
|
|
110
|
+
# shellcheck disable=SC2086
|
|
111
|
+
time wasm-opt $WASMOPTFLAGS \
|
|
112
|
+
rewriter/wasm/out/wasm_snipped.wasm -o rewriter/wasm/out/optimized.wasm \
|
|
113
|
+
--converge -tnh --vacuum \
|
|
114
|
+
$G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
|
|
115
|
+
$G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz \
|
|
116
|
+
$G --code-folding $G --const-hoisting $G --dae $G --flatten $G --merge-locals \
|
|
117
|
+
$G -O4 $G --flatten $G --rereloop $G -O4 $G -O4 $G -O4 \
|
|
118
|
+
$G -Oz $G --flatten $G --rereloop $G -Oz $G -Oz $G -Oz
|
|
119
|
+
)
|
|
120
|
+
else
|
|
121
|
+
cp rewriter/wasm/out/wasm_snipped.wasm rewriter/wasm/out/optimized.wasm
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
mkdir -p dist/
|
|
125
|
+
|
|
126
|
+
cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm
|
|
127
|
+
echo "$SRC_HASH" > rewriter/wasm/out/.build-hash || true
|
|
128
|
+
echo "Rewriter Build Complete!"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
use std::cell::BorrowMutError;
|
|
2
|
+
|
|
3
|
+
use js::RewriterError as JsRewriterError;
|
|
4
|
+
use js_sys::Error;
|
|
5
|
+
use thiserror::Error;
|
|
6
|
+
use wasm_bindgen::{JsError, JsValue};
|
|
7
|
+
|
|
8
|
+
#[derive(Debug, Error)]
|
|
9
|
+
pub enum RewriterError {
|
|
10
|
+
#[error("JS: {0}")]
|
|
11
|
+
Js(String),
|
|
12
|
+
#[error("JS Rewriter: {0}")]
|
|
13
|
+
JsRewriter(#[from] JsRewriterError),
|
|
14
|
+
|
|
15
|
+
#[error("str fromutf8 error: {0}")]
|
|
16
|
+
Str(#[from] std::str::Utf8Error),
|
|
17
|
+
#[error("reflect set failed: {0}")]
|
|
18
|
+
ReflectSetFail(String),
|
|
19
|
+
#[error("Rewriter was already rewriting")]
|
|
20
|
+
AlreadyRewriting(#[from] BorrowMutError),
|
|
21
|
+
|
|
22
|
+
#[error("{0} was not {1}")]
|
|
23
|
+
Not(&'static str, &'static str),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl From<JsValue> for RewriterError {
|
|
27
|
+
fn from(value: JsValue) -> Self {
|
|
28
|
+
Self::Js(Error::from(value).to_string().into())
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl From<RewriterError> for JsValue {
|
|
33
|
+
fn from(value: RewriterError) -> Self {
|
|
34
|
+
JsError::from(value).into()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
impl RewriterError {
|
|
39
|
+
pub fn not_str(x: &'static str) -> Self {
|
|
40
|
+
Self::Not(x, "string")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn not_arr(x: &'static str) -> Self {
|
|
44
|
+
Self::Not(x, "array")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn not_fn(x: &'static str) -> Self {
|
|
48
|
+
Self::Not(x, "function")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
pub fn not_bool(x: &'static str) -> Self {
|
|
52
|
+
Self::Not(x, "bool")
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub type Result<T> = std::result::Result<T, RewriterError>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
use std::error::Error;
|
|
2
|
+
|
|
3
|
+
use js::{
|
|
4
|
+
RewriteResult, Rewriter,
|
|
5
|
+
cfg::{Config, Flags, UrlRewriter},
|
|
6
|
+
};
|
|
7
|
+
use js_sys::{Function, Object, Uint8Array, encode_uri_component};
|
|
8
|
+
use oxc::allocator::StringBuilder;
|
|
9
|
+
use wasm_bindgen::{JsCast, JsValue, prelude::wasm_bindgen};
|
|
10
|
+
use web_sys::Url;
|
|
11
|
+
|
|
12
|
+
use crate::{
|
|
13
|
+
error::{Result, RewriterError},
|
|
14
|
+
get_obj, get_str, set_obj,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// slightly modified https://github.com/ungap/random-uuid/blob/main/index.js
|
|
18
|
+
#[wasm_bindgen(inline_js = r#"
|
|
19
|
+
export function scramtag() {
|
|
20
|
+
return (""+1e10).replace(/[018]/g,
|
|
21
|
+
c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
"#)]
|
|
25
|
+
extern "C" {
|
|
26
|
+
pub fn scramtag() -> std::string::String;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[wasm_bindgen(typescript_custom_section)]
|
|
30
|
+
const REWRITER_OUTPUT: &'static str = r#"
|
|
31
|
+
export type JsRewriterOutput = {
|
|
32
|
+
js: Uint8Array,
|
|
33
|
+
map: Uint8Array,
|
|
34
|
+
scramtag: string,
|
|
35
|
+
errors: string[],
|
|
36
|
+
};
|
|
37
|
+
"#;
|
|
38
|
+
|
|
39
|
+
#[wasm_bindgen]
|
|
40
|
+
extern "C" {
|
|
41
|
+
#[wasm_bindgen(typescript_type = "JsRewriterOutput")]
|
|
42
|
+
pub type JsRewriterOutput;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
pub struct WasmUrlRewriter(Function);
|
|
47
|
+
|
|
48
|
+
impl UrlRewriter for WasmUrlRewriter {
|
|
49
|
+
fn rewrite(
|
|
50
|
+
&self,
|
|
51
|
+
_cfg: &Config,
|
|
52
|
+
flags: &Flags,
|
|
53
|
+
url: &str,
|
|
54
|
+
builder: &mut StringBuilder,
|
|
55
|
+
module: bool,
|
|
56
|
+
) -> std::result::Result<(), Box<dyn Error + Sync + Send>> {
|
|
57
|
+
let url = Url::new_with_base(url, &flags.base)
|
|
58
|
+
.map_err(RewriterError::from)?
|
|
59
|
+
.to_string();
|
|
60
|
+
|
|
61
|
+
let mut rewritten = self
|
|
62
|
+
.0
|
|
63
|
+
.call1(&JsValue::NULL, &url.into())
|
|
64
|
+
.map_err(RewriterError::from)?
|
|
65
|
+
.as_string()
|
|
66
|
+
.ok_or_else(|| RewriterError::not_str("url rewriter output"))?;
|
|
67
|
+
|
|
68
|
+
if module {
|
|
69
|
+
// TODO: keep this in sync with QP.isModule or find a way to make this use the real rewriteUrl function
|
|
70
|
+
let origin = Url::new(&flags.base).map_err(RewriterError::from)?.origin();
|
|
71
|
+
let encoded_origin: String = encode_uri_component(&origin).into();
|
|
72
|
+
rewritten.push_str("?%24module=module&%24io=");
|
|
73
|
+
rewritten.push_str(&encoded_origin);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
builder.push_str(&rewritten);
|
|
77
|
+
|
|
78
|
+
Ok(())
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
pub type JsRewriter = Rewriter;
|
|
83
|
+
|
|
84
|
+
pub fn create_js() -> Result<JsRewriter> {
|
|
85
|
+
Ok(Rewriter::new())
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
pub fn get_url_rewriter(func: Object) -> Result<WasmUrlRewriter> {
|
|
89
|
+
Ok(WasmUrlRewriter(
|
|
90
|
+
func
|
|
91
|
+
.dyn_into()
|
|
92
|
+
.map_err(|_| RewriterError::not_fn("scramjet.codec.encode"))?,
|
|
93
|
+
))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pub fn create_js_output(out: RewriteResult, url: String, src: String) -> Result<JsRewriterOutput> {
|
|
97
|
+
let obj = Object::new();
|
|
98
|
+
set_obj(&obj, "js", &Uint8Array::from(out.js.as_slice()).into())?;
|
|
99
|
+
set_obj(
|
|
100
|
+
&obj,
|
|
101
|
+
"map",
|
|
102
|
+
&Uint8Array::from(out.sourcemap.as_slice()).into(),
|
|
103
|
+
)?;
|
|
104
|
+
set_obj(&obj, "scramtag", &out.flags.sourcetag.into())?;
|
|
105
|
+
|
|
106
|
+
#[cfg(feature = "debug")]
|
|
107
|
+
{
|
|
108
|
+
let src = std::sync::Arc::new(
|
|
109
|
+
oxc::diagnostics::NamedSource::new(url, src).with_language("javascript"),
|
|
110
|
+
);
|
|
111
|
+
let errs: Vec<_> = out
|
|
112
|
+
.errors
|
|
113
|
+
.into_iter()
|
|
114
|
+
.map(|x| format!("{}", x.with_source_code(src.clone())))
|
|
115
|
+
.collect();
|
|
116
|
+
set_obj(&obj, "errors", &errs.into())?;
|
|
117
|
+
}
|
|
118
|
+
#[cfg(not(feature = "debug"))]
|
|
119
|
+
{
|
|
120
|
+
let _ = (url, src);
|
|
121
|
+
set_obj(&obj, "errors", &js_sys::Array::new())?;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Ok(JsRewriterOutput::from(JsValue::from(obj)))
|
|
125
|
+
}
|