dsh-builtin-browser 1.0.0 → 1.0.3
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/CHANGELOG.md +61 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/pr64-maintenance.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/user-guide.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +218 -0
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +260 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -46
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -54
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-electron/package-removal.js +0 -5
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1301
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/package-removal.ts +0 -4
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { getDomain } from 'tldts'
|
|
2
|
-
import { isIP } from 'node:net'
|
|
3
|
-
import { domainToASCII } from 'node:url'
|
|
4
|
-
|
|
5
|
-
/** Guest cookies scoped by host/domain, path, expiry and Secure, separate from host cookies. */
|
|
6
|
-
export interface StoredCookie {
|
|
7
|
-
readonly origin: string
|
|
8
|
-
readonly domain?: string
|
|
9
|
-
readonly hostOnly?: boolean
|
|
10
|
-
readonly name: string
|
|
11
|
-
readonly value: string
|
|
12
|
-
readonly path: string
|
|
13
|
-
readonly secure: boolean
|
|
14
|
-
readonly httpOnly?: boolean
|
|
15
|
-
readonly sameSite?: 'strict' | 'lax' | 'none'
|
|
16
|
-
readonly expiresAt?: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type ScopedCookie = StoredCookie & { readonly domain: string; readonly hostOnly: boolean }
|
|
20
|
-
|
|
21
|
-
function domainMatches(host: string, domain: string): boolean {
|
|
22
|
-
return host === domain || (isIP(host.replace(/^\[|\]$/gu, '')) === 0 && host.endsWith('.' + domain))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function canonicalDomain(value: string): string | undefined {
|
|
26
|
-
if (value === '' || value.endsWith('.') || /[\s/\\:?#@\[\]%]/u.test(value)) return undefined
|
|
27
|
-
return domainToASCII(value).toLowerCase() || undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function trimCookieWhitespace(value: string): string {
|
|
31
|
-
return value.replace(/^[ \t]+|[ \t]+$/gu, '')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function validCookiePair(name: string, value: string): boolean {
|
|
35
|
-
return name.length + value.length > 0 && name.length + value.length <= 4096
|
|
36
|
-
&& !/[^\x20-\xff]|[\x7f;=]/u.test(name)
|
|
37
|
-
&& !/[^\x20-\xff]|[\x7f;]/u.test(value)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function normalizeStoredCookie(input: unknown): ScopedCookie | undefined {
|
|
41
|
-
if (input === null || typeof input !== 'object') return undefined
|
|
42
|
-
const c = input as Record<string, unknown>
|
|
43
|
-
if (typeof c.origin !== 'string' || typeof c.name !== 'string' || typeof c.value !== 'string'
|
|
44
|
-
|| typeof c.path !== 'string' || typeof c.secure !== 'boolean'
|
|
45
|
-
|| (c.httpOnly !== undefined && typeof c.httpOnly !== 'boolean')
|
|
46
|
-
|| (c.sameSite !== undefined && !['strict', 'lax', 'none'].includes(String(c.sameSite)))
|
|
47
|
-
|| (c.expiresAt !== undefined && (typeof c.expiresAt !== 'number' || !Number.isFinite(c.expiresAt)))
|
|
48
|
-
|| !c.path.startsWith('/') || /[\x00-\x1f\x7f]/u.test(c.path)) return undefined
|
|
49
|
-
const name = trimCookieWhitespace(c.name), value = trimCookieWhitespace(c.value)
|
|
50
|
-
if (!validCookiePair(name, value) || (name === '' && /^(?:__Secure-|__Host-|__Http-)/iu.test(value))) return undefined
|
|
51
|
-
try {
|
|
52
|
-
const url = new URL(c.origin)
|
|
53
|
-
const legacy = c.domain === undefined && c.hostOnly === undefined
|
|
54
|
-
if (!legacy && (typeof c.domain !== 'string' || typeof c.hostOnly !== 'boolean')) return undefined
|
|
55
|
-
const domain = legacy || (c.hostOnly === true && c.domain === url.hostname) ? url.hostname : canonicalDomain(c.domain as string)
|
|
56
|
-
if (domain === undefined || !domainMatches(url.hostname, domain)) return undefined
|
|
57
|
-
const hostOnly = legacy || c.hostOnly === true || getDomain(domain, { allowPrivateDomains: true }) === null
|
|
58
|
-
if (hostOnly && domain !== url.hostname) return undefined
|
|
59
|
-
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password
|
|
60
|
-
|| url.pathname !== '/' || url.search || url.hash || (c.secure && url.protocol !== 'https:')
|
|
61
|
-
|| (/^__Secure-/iu.test(name) && !c.secure)
|
|
62
|
-
|| (/^__Host-/iu.test(name) && (!c.secure || c.path !== '/' || !hostOnly || c.hostOnly === false))
|
|
63
|
-
|| (/^__(?:Host-)?Http-/iu.test(name) && (!c.secure || !c.httpOnly))
|
|
64
|
-
|| (c.sameSite === 'none' && !c.secure)) return undefined
|
|
65
|
-
return { origin: url.origin, domain, hostOnly, name, value, path: c.path, secure: c.secure,
|
|
66
|
-
httpOnly: c.httpOnly !== false, sameSite: c.sameSite as StoredCookie['sameSite'],
|
|
67
|
-
expiresAt: c.expiresAt as number | undefined }
|
|
68
|
-
} catch { return undefined }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function defaultPath(pathname: string): string {
|
|
72
|
-
const lastSlash = pathname.lastIndexOf('/')
|
|
73
|
-
return lastSlash <= 0 ? '/' : pathname.slice(0, lastSlash)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function pathMatches(pathname: string, path: string): boolean {
|
|
77
|
-
return pathname === path || (pathname.startsWith(path) && (path.endsWith('/') || pathname[path.length] === '/'))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export class GuestCookieJar {
|
|
81
|
-
private readonly store = new Map<string, ScopedCookie>()
|
|
82
|
-
|
|
83
|
-
constructor(private readonly changed?: (cookies: readonly StoredCookie[]) => void, saved: readonly StoredCookie[] = []) {
|
|
84
|
-
for (const value of saved) {
|
|
85
|
-
const cookie = normalizeStoredCookie(value)
|
|
86
|
-
if (cookie !== undefined && (cookie.expiresAt === undefined || cookie.expiresAt > Date.now())) {
|
|
87
|
-
this.store.set(String(this.store.size), cookie)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private save(): void {
|
|
93
|
-
this.changed?.([...this.store.values()].filter(cookie => cookie.expiresAt === undefined || cookie.expiresAt > Date.now()))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
setCookies(target: URL, values: readonly string[], script = false): void {
|
|
97
|
-
const now = Date.now()
|
|
98
|
-
for (const raw of values) {
|
|
99
|
-
if (/[\x00-\x08\x0a-\x1f\x7f]/u.test(raw)) continue
|
|
100
|
-
const [pair = '', ...attributes] = raw.split(';').map(trimCookieWhitespace)
|
|
101
|
-
const index = pair.indexOf('=')
|
|
102
|
-
const name = index === -1 ? '' : trimCookieWhitespace(pair.slice(0, index))
|
|
103
|
-
const value = trimCookieWhitespace(index === -1 ? pair : pair.slice(index + 1))
|
|
104
|
-
if (!validCookiePair(name, value)) continue
|
|
105
|
-
let path = defaultPath(target.pathname), secure = false, httpOnly = false, domain: string | undefined
|
|
106
|
-
let sameSite: StoredCookie['sameSite'], explicitRoot = false
|
|
107
|
-
let expires: number | undefined, maxAge: number | undefined
|
|
108
|
-
let validAttributes = true
|
|
109
|
-
for (const attribute of attributes) {
|
|
110
|
-
const equals = attribute.indexOf('=')
|
|
111
|
-
const key = trimCookieWhitespace(equals === -1 ? attribute : attribute.slice(0, equals)).toLowerCase()
|
|
112
|
-
const content = equals === -1 ? '' : trimCookieWhitespace(attribute.slice(equals + 1))
|
|
113
|
-
if (/[\x00-\x1f\x7f]/u.test(key + content)) { validAttributes = false; break }
|
|
114
|
-
if (key === 'domain' && content !== '') domain = content.replace(/^\./u, '').toLowerCase()
|
|
115
|
-
else if (key === 'path') { path = content.startsWith('/') ? content : defaultPath(target.pathname); explicitRoot = content === '/' }
|
|
116
|
-
else if (key === 'secure') secure = true
|
|
117
|
-
else if (key === 'httponly') httpOnly = true
|
|
118
|
-
else if (key === 'samesite') sameSite = ['strict', 'lax', 'none'].includes(content.toLowerCase()) ? content.toLowerCase() as StoredCookie['sameSite'] : undefined
|
|
119
|
-
else if (key === 'max-age' && /^-?\d+$/u.test(content)) maxAge = Math.min(Number(content), 400 * 86400)
|
|
120
|
-
else if (key === 'expires' && Number.isFinite(Date.parse(content))) expires = Date.parse(content)
|
|
121
|
-
}
|
|
122
|
-
const scopedDomain = domain === undefined ? target.hostname : canonicalDomain(domain)
|
|
123
|
-
if (!validAttributes || scopedDomain === undefined || !domainMatches(target.hostname, scopedDomain)) continue
|
|
124
|
-
const hostOnly = domain === undefined || getDomain(scopedDomain, { allowPrivateDomains: true }) === null
|
|
125
|
-
if (hostOnly && scopedDomain !== target.hostname) continue
|
|
126
|
-
if (script && httpOnly) continue
|
|
127
|
-
if (secure && target.protocol !== 'https:') continue
|
|
128
|
-
if (/^__Secure-/iu.test(name) && !secure) continue
|
|
129
|
-
if (/^__Host-/iu.test(name) && (!secure || domain !== undefined || !explicitRoot)) continue
|
|
130
|
-
if (/^__(?:Host-)?Http-/iu.test(name) && (!secure || !httpOnly)) continue
|
|
131
|
-
const cookie = normalizeStoredCookie({ origin: target.origin, domain: scopedDomain, hostOnly, name, value, path, secure, httpOnly, sameSite,
|
|
132
|
-
expiresAt: maxAge === undefined ? expires : maxAge <= 0 ? 0 : now + maxAge * 1000 })
|
|
133
|
-
if (cookie === undefined) continue
|
|
134
|
-
const matching = [...this.store].filter(([, entry]) => entry.domain === cookie.domain && entry.path === path && entry.name === name)
|
|
135
|
-
if (script && matching.some(([, entry]) => entry.httpOnly && (entry.expiresAt === undefined || entry.expiresAt > now))) continue
|
|
136
|
-
if (target.protocol !== 'https:' && [...this.store.values()].some(entry => entry.secure && entry.name === name
|
|
137
|
-
&& (entry.expiresAt === undefined || entry.expiresAt > now)
|
|
138
|
-
&& (domainMatches(cookie.domain, entry.domain) || domainMatches(entry.domain, cookie.domain))
|
|
139
|
-
&& pathMatches(path, entry.path))) continue
|
|
140
|
-
const key = matching[0]?.[0] ?? cookie.domain + '\0' + path + '\0' + name
|
|
141
|
-
for (const [other] of matching) if (other !== key) this.store.delete(other)
|
|
142
|
-
if (cookie.expiresAt !== undefined && cookie.expiresAt <= now) this.store.delete(key)
|
|
143
|
-
else this.store.set(key, cookie)
|
|
144
|
-
}
|
|
145
|
-
if (values.length > 0) this.save()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getDocumentCookie(target: URL): string { return this.getCookieHeader(target, true) ?? '' }
|
|
149
|
-
|
|
150
|
-
setDocumentCookie(target: URL, value: string): void { this.setCookies(target, [value], true) }
|
|
151
|
-
|
|
152
|
-
getCookieHeader(target: URL, script = false, context?: { readonly site: URL; readonly topLevel: boolean; readonly method: string }): string | undefined {
|
|
153
|
-
const now = Date.now()
|
|
154
|
-
const matched: StoredCookie[] = []
|
|
155
|
-
for (const [key, value] of this.store) {
|
|
156
|
-
const cookie = normalizeStoredCookie(value)
|
|
157
|
-
if (cookie === undefined || (cookie.expiresAt !== undefined && cookie.expiresAt <= now)) {
|
|
158
|
-
this.store.delete(key)
|
|
159
|
-
continue
|
|
160
|
-
}
|
|
161
|
-
if ((cookie.hostOnly ? cookie.domain !== target.hostname : !domainMatches(target.hostname, cookie.domain))
|
|
162
|
-
|| (cookie.secure && target.protocol !== 'https:')
|
|
163
|
-
|| (script && cookie.httpOnly)
|
|
164
|
-
|| !pathMatches(target.pathname, cookie.path)) continue
|
|
165
|
-
if (!script && context !== undefined) {
|
|
166
|
-
const site = (url: URL): string => url.protocol + '//' + (getDomain(url.hostname, { allowPrivateDomains: true }) ?? url.hostname)
|
|
167
|
-
const crossSite = site(context.site) !== site(target)
|
|
168
|
-
if (crossSite && cookie.sameSite !== 'none'
|
|
169
|
-
&& (cookie.sameSite === 'strict' || !context.topLevel || !['GET', 'HEAD', 'OPTIONS', 'TRACE'].includes(context.method))) continue
|
|
170
|
-
}
|
|
171
|
-
matched.push(cookie)
|
|
172
|
-
}
|
|
173
|
-
matched.sort((a, b) => b.path.length - a.path.length)
|
|
174
|
-
return matched.length === 0 ? undefined : matched.map(cookie => cookie.name === '' ? cookie.value : cookie.name + '=' + cookie.value).join('; ')
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
|
|
2
|
-
import { randomUUID } from 'node:crypto'
|
|
3
|
-
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
import { GuestCookieJar, normalizeStoredCookie, type StoredCookie } from './guest-cookie-jar.ts'
|
|
6
|
-
import { dshHome } from './paths.ts'
|
|
7
|
-
|
|
8
|
-
export function loadGuestCookies(directory: string): GuestCookieJar {
|
|
9
|
-
const file = join(directory, 'cookies.json')
|
|
10
|
-
let saved: StoredCookie[] = []
|
|
11
|
-
try {
|
|
12
|
-
let fd: number | undefined
|
|
13
|
-
try {
|
|
14
|
-
fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0))
|
|
15
|
-
if (!fstatSync(fd).isFile()) throw new Error()
|
|
16
|
-
fchmodSync(fd, 0o600)
|
|
17
|
-
const data: unknown = JSON.parse(readFileSync(fd, 'utf8'))
|
|
18
|
-
if (data === null || typeof data !== 'object') throw new Error()
|
|
19
|
-
const record = data as Record<string, unknown>
|
|
20
|
-
if (record.version !== 1 || !Array.isArray(record.cookies)) throw new Error()
|
|
21
|
-
saved = record.cookies.flatMap(value => {
|
|
22
|
-
const cookie = normalizeStoredCookie(value)
|
|
23
|
-
return cookie !== undefined && (cookie.expiresAt === undefined || cookie.expiresAt > Date.now()) ? [cookie] : []
|
|
24
|
-
})
|
|
25
|
-
} finally { if (fd !== undefined) closeSync(fd) }
|
|
26
|
-
} catch {}
|
|
27
|
-
const persist = (cookies: readonly StoredCookie[]) => {
|
|
28
|
-
const temporary = file + '.' + randomUUID() + '.tmp'
|
|
29
|
-
let fd: number | undefined
|
|
30
|
-
try {
|
|
31
|
-
mkdirSync(directory, { recursive: true, mode: 0o700 })
|
|
32
|
-
fd = openSync(temporary, 'wx', 0o600)
|
|
33
|
-
fchmodSync(fd, 0o600)
|
|
34
|
-
writeFileSync(fd, JSON.stringify({ version: 1, cookies }))
|
|
35
|
-
fsyncSync(fd)
|
|
36
|
-
closeSync(fd)
|
|
37
|
-
fd = undefined
|
|
38
|
-
renameSync(temporary, file)
|
|
39
|
-
} catch {} finally {
|
|
40
|
-
if (fd !== undefined) { try { closeSync(fd) } catch {} }
|
|
41
|
-
try { rmSync(temporary, { force: true }) } catch { /* A failed write may leave an owner-only temporary file. */ }
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const jar = new GuestCookieJar(persist, saved)
|
|
45
|
-
persist(saved)
|
|
46
|
-
return jar
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const stores = new Map<string, GuestCookieJar>()
|
|
50
|
-
|
|
51
|
-
export function localGuestCookies(): GuestCookieJar {
|
|
52
|
-
const directory = join(dshHome(), BROWSER_PROFILE_DIR, 'web-cookies')
|
|
53
|
-
let store = stores.get(directory)
|
|
54
|
-
if (store === undefined) {
|
|
55
|
-
store = loadGuestCookies(directory)
|
|
56
|
-
stores.set(directory, store)
|
|
57
|
-
}
|
|
58
|
-
return store
|
|
59
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { rewriteCss } from './guest-css.ts'
|
|
2
|
-
|
|
3
|
-
export function guestCssRuntimeScript(): string {
|
|
4
|
-
return `
|
|
5
|
-
const cssBase = sheet => {
|
|
6
|
-
for (let current = sheet; current; current = current.parentStyleSheet) {
|
|
7
|
-
if (current.href) return realURL(current.href).href;
|
|
8
|
-
}
|
|
9
|
-
return document.baseURI ? realURL(document.baseURI).href : real;
|
|
10
|
-
};
|
|
11
|
-
const proxyCss = (value, base = cssBase()) => (${rewriteCss.toString()})(String(value), raw => {
|
|
12
|
-
if (!raw.trim() || raw.trim().startsWith('#')) return undefined;
|
|
13
|
-
try {
|
|
14
|
-
const existing = new URL(raw, location.href);
|
|
15
|
-
if (existing.origin === location.origin && existing.pathname === route) return undefined;
|
|
16
|
-
const resolved = new URL(raw, base);
|
|
17
|
-
return /^https?:$/.test(resolved.protocol) ? toProxy(resolved.href) : undefined;
|
|
18
|
-
} catch { return undefined; }
|
|
19
|
-
});
|
|
20
|
-
const isStyle = node => node && node.nodeType === 1 && node.tagName === 'STYLE';
|
|
21
|
-
const rewriteStyleText = node => {
|
|
22
|
-
if (!isStyle(node)) return;
|
|
23
|
-
const before = node.textContent, after = proxyCss(before);
|
|
24
|
-
if (after !== before) node.textContent = after;
|
|
25
|
-
};
|
|
26
|
-
for (const [name, property] of [['Node', 'textContent'], ['Node', 'nodeValue'], ['CharacterData', 'data']]) attempt(() => {
|
|
27
|
-
const proto = window[name].prototype;
|
|
28
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, property);
|
|
29
|
-
if (!descriptor || !descriptor.set) return;
|
|
30
|
-
Object.defineProperty(proto, property, Object.assign({}, descriptor, {
|
|
31
|
-
set(value) {
|
|
32
|
-
const css = isStyle(this) || (this.nodeType === 3 && isStyle(this.parentNode));
|
|
33
|
-
descriptor.set.call(this, css && value != null ? proxyCss(value) : value);
|
|
34
|
-
}
|
|
35
|
-
}));
|
|
36
|
-
});
|
|
37
|
-
for (const name of ['CSSStyleSheet', 'CSSGroupingRule', 'CSSKeyframesRule']) attempt(() => {
|
|
38
|
-
const proto = window[name].prototype;
|
|
39
|
-
for (const method of ['insertRule', 'replace', 'replaceSync', 'appendRule', 'addRule']) {
|
|
40
|
-
const original = proto[method];
|
|
41
|
-
if (typeof original !== 'function') continue;
|
|
42
|
-
proto[method] = function(...args) {
|
|
43
|
-
const index = method === 'addRule' ? 1 : 0;
|
|
44
|
-
if (args.length > index) args[index] = proxyCss(args[index], cssBase(this.parentStyleSheet || this));
|
|
45
|
-
return original.apply(this, args);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
attempt(() => {
|
|
50
|
-
const proto = CSSStyleDeclaration.prototype, original = proto.setProperty;
|
|
51
|
-
proto.setProperty = function(name, value, priority) {
|
|
52
|
-
return original.call(this, name, value == null ? value : proxyCss(value, cssBase(this.parentRule?.parentStyleSheet)), priority);
|
|
53
|
-
};
|
|
54
|
-
for (const property of Object.getOwnPropertyNames(proto)) {
|
|
55
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, property);
|
|
56
|
-
if (!descriptor?.set) continue;
|
|
57
|
-
Object.defineProperty(proto, property, Object.assign({}, descriptor, {
|
|
58
|
-
set(value) { descriptor.set.call(this, value == null ? value : proxyCss(value, cssBase(this.parentRule?.parentStyleSheet))); }
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
for (const name of ['HTMLElement', 'SVGElement']) attempt(() => {
|
|
63
|
-
const proto = window[name].prototype, descriptor = Object.getOwnPropertyDescriptor(proto, 'style');
|
|
64
|
-
if (!descriptor?.set) return;
|
|
65
|
-
Object.defineProperty(proto, 'style', Object.assign({}, descriptor, {
|
|
66
|
-
set(value) { descriptor.set.call(this, value == null ? value : proxyCss(value)); }
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
attempt(() => {
|
|
70
|
-
const original = Element.prototype.insertAdjacentText;
|
|
71
|
-
Element.prototype.insertAdjacentText = function(position, value) {
|
|
72
|
-
return original.call(this, position, isStyle(this) ? proxyCss(value) : value);
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
`
|
|
76
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export function rewriteCss(css: string, proxy: (url: string) => string | undefined): string {
|
|
2
|
-
const scanner = {
|
|
3
|
-
decode(value: string): string { return value.replace(/\\(?:([\da-f]{1,6})(?:\r\n|[ \t\r\n\f])?|(\r\n|[\r\n\f])|([\s\S]))/giu,
|
|
4
|
-
(_match, hex: string | undefined, newline: string | undefined, literal: string) => {
|
|
5
|
-
if (hex === undefined) return newline === undefined ? literal : ''
|
|
6
|
-
const point = Number.parseInt(hex, 16)
|
|
7
|
-
return point === 0 || point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff) ? '\ufffd' : String.fromCodePoint(point)
|
|
8
|
-
}) },
|
|
9
|
-
stringEnd(start: number): number {
|
|
10
|
-
const quote = css[start]
|
|
11
|
-
let end = start + 1
|
|
12
|
-
while (end < css.length) {
|
|
13
|
-
if (css[end] === '\\') { end += 2; continue }
|
|
14
|
-
if (css[end++] === quote) return end
|
|
15
|
-
}
|
|
16
|
-
return end
|
|
17
|
-
},
|
|
18
|
-
replacement(raw: string): string | undefined { return proxy(this.decode(raw)) },
|
|
19
|
-
}
|
|
20
|
-
const functions: string[] = []
|
|
21
|
-
let result = '', position = 0, importing = false
|
|
22
|
-
while (position < css.length) {
|
|
23
|
-
if (css.startsWith('/*', position)) {
|
|
24
|
-
const close = css.indexOf('*/', position + 2)
|
|
25
|
-
const end = close === -1 ? css.length : close + 2
|
|
26
|
-
result += css.slice(position, end); position = end; continue
|
|
27
|
-
}
|
|
28
|
-
const character = css[position]!
|
|
29
|
-
if (/\s/u.test(character)) { result += character; position++; continue }
|
|
30
|
-
if (character === '"' || character === "'") {
|
|
31
|
-
const end = scanner.stringEnd(position)
|
|
32
|
-
const next = css[end - 1] === character && (importing || /^(?:-webkit-)?image-set$/iu.test(functions.at(-1) ?? ''))
|
|
33
|
-
? scanner.replacement(css.slice(position + 1, end - 1)) : undefined
|
|
34
|
-
result += next === undefined ? css.slice(position, end) : `"${next}"`
|
|
35
|
-
importing = false; position = end; continue
|
|
36
|
-
}
|
|
37
|
-
const identifier = /^[-\w]+/u.exec(css.slice(position))?.[0]
|
|
38
|
-
if (character === '@' && /^@import\b/iu.test(css.slice(position))) {
|
|
39
|
-
result += css.slice(position, position + 7); position += 7; importing = true; continue
|
|
40
|
-
}
|
|
41
|
-
if (identifier !== undefined) {
|
|
42
|
-
const start = position
|
|
43
|
-
position += identifier.length
|
|
44
|
-
if (css[position] !== '(') { result += identifier; importing = false; continue }
|
|
45
|
-
position++
|
|
46
|
-
if (identifier.toLowerCase() !== 'url') {
|
|
47
|
-
functions.push(identifier); result += css.slice(start, position); importing = false; continue
|
|
48
|
-
}
|
|
49
|
-
while (/\s/u.test(css[position] ?? '') && position < css.length) position++
|
|
50
|
-
const quoted = css[position] === '"' || css[position] === "'"
|
|
51
|
-
const valueStart = position
|
|
52
|
-
if (quoted) position = scanner.stringEnd(position)
|
|
53
|
-
else while (position < css.length && css[position] !== ')') position += css[position] === '\\' ? 2 : 1
|
|
54
|
-
const valueEnd = position
|
|
55
|
-
while (/\s/u.test(css[position] ?? '') && position < css.length) position++
|
|
56
|
-
if (css[position] !== ')') { result += css.slice(start, position); importing = false; continue }
|
|
57
|
-
const raw = quoted ? css.slice(valueStart + 1, valueEnd - 1) : css.slice(valueStart, valueEnd).trim()
|
|
58
|
-
const next = scanner.replacement(raw)
|
|
59
|
-
position++
|
|
60
|
-
result += next === undefined ? css.slice(start, position) : `url("${next}")`
|
|
61
|
-
importing = false; continue
|
|
62
|
-
}
|
|
63
|
-
if (character === ')') functions.pop()
|
|
64
|
-
else if (character === '(') functions.push('')
|
|
65
|
-
result += character; position++; importing = false
|
|
66
|
-
}
|
|
67
|
-
return result
|
|
68
|
-
}
|