effect-browser 0.3.0-beta.20 → 0.3.0-beta.22
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/README.md +221 -158
- package/dist/Action-24sLOubi.d.mts +110 -0
- package/dist/Action.d.mts +2 -0
- package/dist/Action.mjs +141 -0
- package/dist/Action.mjs.map +1 -0
- package/dist/ActionPort.d.mts +15 -0
- package/dist/ActionPort.mjs +101 -0
- package/dist/ActionPort.mjs.map +1 -0
- package/dist/Browser-Cq2K1FEA.mjs +4075 -0
- package/dist/Browser-Cq2K1FEA.mjs.map +1 -0
- package/dist/Browser-wZhwZSlG.d.mts +167 -0
- package/dist/Browser.d.mts +2 -129
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
- package/dist/BrowserError.d.mts +2 -2
- package/dist/BrowserError.mjs +46 -9
- package/dist/BrowserError.mjs.map +1 -1
- package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +29 -24
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
- package/dist/Change.d.mts +2 -2
- package/dist/Change.mjs +97 -2
- package/dist/Change.mjs.map +1 -0
- package/dist/Clock.d.mts +57 -0
- package/dist/Clock.mjs +80 -0
- package/dist/Clock.mjs.map +1 -0
- package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
- package/dist/Frame.d.mts +2 -2
- package/dist/Frame.mjs +10 -2
- package/dist/Frame.mjs.map +1 -1
- package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
- package/dist/Geometry.d.mts +2 -0
- package/dist/Geometry.mjs +32 -0
- package/dist/Geometry.mjs.map +1 -0
- package/dist/LICENSE-jpeg-js +28 -0
- package/dist/Matching.d.mts +37 -0
- package/dist/{match.inpage-xOe9LNO0.mjs → Matching.mjs} +28 -4
- package/dist/Matching.mjs.map +1 -0
- package/dist/{Page-CfB6Zn1p.mjs → Page-BF5izr8R.mjs} +216 -31
- package/dist/Page-BF5izr8R.mjs.map +1 -0
- package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +1 -1
- package/dist/Released-tURbFmal.d.mts +15 -0
- package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
- package/dist/Snapshot.d.mts +1 -1
- package/dist/Snapshot.mjs.map +1 -1
- package/dist/Stillness-CNlvayIo.mjs +136 -0
- package/dist/Stillness-CNlvayIo.mjs.map +1 -0
- package/dist/Style-AO4V7Czt.mjs +357 -0
- package/dist/Style-AO4V7Czt.mjs.map +1 -0
- package/dist/Style.d.mts +72 -0
- package/dist/Style.mjs +2 -0
- package/dist/Url.d.mts +26 -0
- package/dist/Url.mjs +74 -0
- package/dist/Url.mjs.map +1 -0
- package/dist/Window-CMddGMt1.d.mts +34 -0
- package/dist/Window.d.mts +2 -0
- package/dist/Window.mjs +35 -0
- package/dist/Window.mjs.map +1 -0
- package/dist/connection-2KHI4_KN.d.mts +41 -0
- package/dist/connection-BTeO0Hiz.mjs +68 -0
- package/dist/connection-BTeO0Hiz.mjs.map +1 -0
- package/dist/index.d.mts +15 -17
- package/dist/index.mjs +11 -14
- package/dist/moment/Moment.d.mts +86 -0
- package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
- package/dist/moment/Moment.mjs.map +1 -0
- package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
- package/dist/{Plan-C-d5QYS8.mjs → plan/index.mjs} +122 -155
- package/dist/plan/index.mjs.map +1 -0
- package/dist/{Policy.d.mts → policy/Policy.d.mts} +5 -9
- package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
- package/dist/policy/Policy.mjs.map +1 -0
- package/dist/presentation/Motion.d.mts +12 -0
- package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
- package/dist/presentation/Motion.mjs.map +1 -0
- package/dist/presentation/Presentation.d.mts +30 -0
- package/dist/presentation/Presentation.mjs +105 -0
- package/dist/presentation/Presentation.mjs.map +1 -0
- package/dist/{Stage.d.mts → presentation/Stage.d.mts} +5 -8
- package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
- package/dist/presentation/Stage.mjs.map +1 -0
- package/dist/presentation/feed.d.mts +20 -0
- package/dist/presentation/feed.mjs +18 -0
- package/dist/presentation/feed.mjs.map +1 -0
- package/dist/providers/Cdp.d.mts +9 -0
- package/dist/providers/Cdp.mjs +15 -0
- package/dist/providers/Cdp.mjs.map +1 -0
- package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
- package/dist/{Chromium.mjs → providers/Chromium.mjs} +7 -16
- package/dist/providers/Chromium.mjs.map +1 -0
- package/dist/providers/Released.d.mts +2 -0
- package/dist/providers/Released.mjs +12 -0
- package/dist/providers/Released.mjs.map +1 -0
- package/dist/stillness/Stillness.d.mts +12 -0
- package/dist/stillness/Stillness.mjs +2 -0
- package/dist/supervisor/Supervisor.d.mts +104 -0
- package/dist/supervisor/Supervisor.mjs +513 -0
- package/dist/supervisor/Supervisor.mjs.map +1 -0
- package/dist/testing/index.d.mts +337 -0
- package/dist/testing/index.mjs +515 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/workerd/Cdp.d.mts +8 -0
- package/dist/workerd/Cdp.mjs +13 -0
- package/dist/workerd/Cdp.mjs.map +1 -0
- package/package.json +94 -33
- package/src/Action.ts +127 -0
- package/src/ActionPort.ts +128 -0
- package/src/Browser.ts +366 -225
- package/src/BrowserError.ts +63 -6
- package/src/BrowserEvent.ts +26 -25
- package/src/Change.ts +0 -2
- package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
- package/src/Frame.ts +14 -0
- package/src/Geometry.ts +48 -0
- package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
- package/src/Page.ts +111 -92
- package/src/Snapshot.ts +5 -0
- package/src/{internal/input/style.ts → Style.ts} +121 -14
- package/src/Window.ts +30 -0
- package/src/index.ts +8 -13
- package/src/internal/input/actions.ts +61 -119
- package/src/internal/input/dispatch.ts +3 -3
- package/src/internal/input/gate.ts +21 -18
- package/src/internal/input/guard.inpage.ts +25 -58
- package/src/internal/input/guard.ts +11 -20
- package/src/internal/input/keyboard.ts +12 -3
- package/src/internal/input/perform.ts +78 -60
- package/src/internal/input/pointer.ts +4 -2
- package/src/internal/input/settle.ts +7 -5
- package/src/internal/input/targets.inpage.ts +1 -1
- package/src/internal/input/targets.ts +4 -9
- package/src/internal/page/bridge.ts +210 -114
- package/src/internal/page/context.ts +23 -73
- package/src/internal/page/dialogs.ts +58 -0
- package/src/internal/page/identity.ts +6 -23
- package/src/internal/page/lane.ts +14 -15
- package/src/internal/page/navigation.ts +50 -42
- package/src/internal/page/openings.ts +11 -5
- package/src/internal/page/page.ts +44 -81
- package/src/internal/page/port.ts +125 -0
- package/src/internal/{input → page}/replies.ts +1 -1
- package/src/internal/page/request-owner.ts +269 -0
- package/src/internal/page/requests.ts +357 -0
- package/src/internal/page/scripts.ts +124 -0
- package/src/internal/pictures/capture.ts +255 -332
- package/src/internal/pictures/dimensions.ts +162 -0
- package/src/internal/pictures/frame.ts +68 -0
- package/src/internal/pictures/pictures.ts +57 -23
- package/src/internal/pictures/quiescence.ts +1 -1
- package/src/internal/pictures/state.ts +26 -0
- package/src/internal/pictures/transport.ts +21 -4
- package/src/internal/reading/controls.inpage.ts +5 -70
- package/src/internal/reading/expect.inpage.ts +13 -17
- package/src/internal/reading/names.inpage.ts +89 -45
- package/src/internal/reading/outline.inpage.ts +6 -7
- package/src/internal/reading/reading.ts +144 -176
- package/src/internal/reading/ready.inpage.ts +6 -17
- package/src/internal/reading/ready.ts +13 -135
- package/src/internal/reading/subjects.inpage.ts +83 -43
- package/src/internal/reading/walk.inpage.ts +33 -13
- package/src/internal/timeline/changes.ts +55 -6
- package/src/internal/timeline/events.ts +15 -5
- package/src/internal/timeline/history.inpage.ts +1 -1
- package/src/internal/timeline/record.inpage.ts +4 -1
- package/src/internal/timeline/window.ts +2 -1
- package/src/{Moment.ts → moment/Moment.ts} +13 -31
- package/src/{internal/timeline → moment}/words.ts +2 -2
- package/src/{internal/reading → plan}/choose.ts +3 -3
- package/src/plan/data.ts +117 -0
- package/src/plan/execute.ts +411 -0
- package/src/plan/index.ts +36 -0
- package/src/plan/record.ts +71 -0
- package/src/plan/targets.ts +71 -0
- package/src/{Policy.ts → policy/Policy.ts} +13 -10
- package/src/{Motion.ts → presentation/Motion.ts} +12 -46
- package/src/presentation/Presentation.ts +176 -0
- package/src/{Stage.ts → presentation/Stage.ts} +147 -112
- package/src/presentation/feed.ts +21 -0
- package/src/providers/Cdp.ts +16 -0
- package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
- package/src/providers/Released.ts +13 -0
- package/src/providers/connection.ts +134 -0
- package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +4 -4
- package/src/stillness/Stillness.ts +166 -0
- package/src/supervisor/Supervisor.ts +170 -0
- package/src/supervisor/contract.ts +105 -0
- package/src/supervisor/lifecycle.ts +272 -0
- package/src/supervisor/runtime.ts +234 -0
- package/src/testing/TestBrowser.ts +115 -0
- package/src/testing/TestPage.ts +10 -0
- package/src/testing/evidence.ts +154 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/model.ts +222 -0
- package/src/testing/page.ts +360 -0
- package/src/workerd/Cdp.ts +11 -0
- package/dist/Browser-BwCldIff.mjs +0 -629
- package/dist/Browser-BwCldIff.mjs.map +0 -1
- package/dist/Cdp.d.mts +0 -32
- package/dist/Cdp.mjs +0 -61
- package/dist/Cdp.mjs.map +0 -1
- package/dist/Change-DNvztNLu.mjs +0 -138
- package/dist/Change-DNvztNLu.mjs.map +0 -1
- package/dist/Chromium.mjs.map +0 -1
- package/dist/Expect.d.mts +0 -62
- package/dist/Expect.mjs +0 -114
- package/dist/Expect.mjs.map +0 -1
- package/dist/Moment.d.mts +0 -2
- package/dist/Moment.mjs.map +0 -1
- package/dist/Motion.d.mts +0 -2
- package/dist/Motion.mjs.map +0 -1
- package/dist/Page-CfB6Zn1p.mjs.map +0 -1
- package/dist/Plan-C-d5QYS8.mjs.map +0 -1
- package/dist/Plan.d.mts +0 -2
- package/dist/Plan.mjs +0 -2
- package/dist/Policy.mjs.map +0 -1
- package/dist/Presentation.d.mts +0 -48
- package/dist/Presentation.mjs +0 -118
- package/dist/Presentation.mjs.map +0 -1
- package/dist/Stage.mjs.map +0 -1
- package/dist/Supervisor-2mPjIYYs.mjs +0 -676
- package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
- package/dist/Supervisor-mVPeEUp8.d.mts +0 -317
- package/dist/Supervisor.d.mts +0 -2
- package/dist/Supervisor.mjs +0 -2
- package/dist/context-w3NJPRLo.mjs +0 -335
- package/dist/context-w3NJPRLo.mjs.map +0 -1
- package/dist/match.inpage-xOe9LNO0.mjs.map +0 -1
- package/dist/page-BKwfF6z-.mjs +0 -5099
- package/dist/page-BKwfF6z-.mjs.map +0 -1
- package/dist/url-Cd04Okid.mjs +0 -264
- package/dist/url-Cd04Okid.mjs.map +0 -1
- package/src/Cdp.ts +0 -101
- package/src/Expect.ts +0 -180
- package/src/Plan.ts +0 -674
- package/src/Presentation.ts +0 -196
- package/src/Supervisor.ts +0 -632
- package/src/internal/supervisor/lifecycle.ts +0 -484
- /package/src/{internal/page/url.ts → Url.ts} +0 -0
- /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Stillness-CNlvayIo.mjs","names":["Motion.picture","Motion.background","Motion.stirs"],"sources":["../src/stillness/Pixels.ts","../src/stillness/Stillness.ts"],"sourcesContent":["/**\n * Where a page's screen moves, from its screencast frames: each frame decoded and cut into\n * 16-pixel blocks, a block moving where a few of its pixels, sampled every other one, changed by\n * more than JPEG's noise in any color channel.\n * What moved among the frames before an input is the page's background, such as an idle\n * animation; foreground stillness ignores it.\n *\n * Frames use Playwright's bundled JPEG decoder. The package build ships that exact decoder\n * alone, keeping its Node utility bundle out of Workers. Source runs use its native export,\n * whose untyped entry point is declared by `utilsBundle.d.ts`.\n */\n// oxlint-disable-next-line typescript/triple-slash-reference -- a declaration of an untyped module cannot be imported, and every program that compiles this source needs it\n/// <reference path=\"./utilsBundle.d.ts\" />\nimport { jpegjs } from \"playwright-core/lib/utilsBundle\";\n\nimport type { Frame } from \"../Frame.ts\";\n\n/** A decoded frame: RGBA, `width` pixels a row. */\nexport type Picture = ReturnType<typeof jpegjs.decode>;\n\nexport const picture = (frame: Frame): Picture => jpegjs.decode(frame.data, { useTArray: true });\n\n/** A sample changed where any color channel moved more than this, beyond JPEG's noise. */\nconst noise = 32;\n\n/** The blocks where two pictures differ, by `row * columns + column`; -1 for different sizes. */\nconst moved = (from: Picture, to: Picture): ReadonlyArray<number> => {\n if (from.width !== to.width || from.height !== to.height) return [-1];\n const columns = Math.ceil(from.width / 16);\n const counts = new Map<number, number>();\n const differs = (at: number) => Math.abs((from.data[at] ?? 0) - (to.data[at] ?? 0)) > noise;\n\n for (let y = 0; y < from.height; y += 2)\n for (let x = 0; x < from.width; x += 2) {\n const at = (y * from.width + x) * 4;\n const block = Math.floor(y / 16) * columns + Math.floor(x / 16);\n\n if (differs(at) || differs(at + 1) || differs(at + 2))\n counts.set(block, (counts.get(block) ?? 0) + 1);\n }\n\n // At least three changed samples, so a stray one is no motion.\n return [...counts].flatMap(([block, count]) => (count >= 3 ? [block] : []));\n};\n\n/** The blocks that moved from one picture to the next and their neighbours; none past a resize. */\nexport const background = (pictures: ReadonlyArray<Picture>): ReadonlySet<number> => {\n const columns = Math.ceil((pictures[0]?.width ?? 0) / 16);\n\n const around = (block: number) =>\n [-1, 0, 1].flatMap((row) =>\n [-1, 0, 1]\n .filter((step) => block >= 0 && (block % columns) + step >= 0)\n .filter((step) => (block % columns) + step < columns)\n .map((step) => block + row * columns + step),\n );\n\n return new Set(\n pictures.flatMap((to, index) => moved(pictures[index - 1] ?? to, to).flatMap(around)),\n );\n};\n\n/** Whether anything moved from one picture to another outside the background. */\nexport const stirs = (from: Picture, to: Picture, mask: ReadonlySet<number>) =>\n moved(from, to).some((block) => !mask.has(block));\n","/** Screen and foreground stillness over the public page capture and owning clock. */\nimport { Clock, Duration, Effect, Option, Schedule, Stream } from \"effect\";\n\nimport { Failed, refuse, Timeout, undispatched } from \"../BrowserError.ts\";\nimport { monotonicMillis } from \"../Clock.ts\";\nimport type { Frame } from \"../Frame.ts\";\nimport type { Page } from \"../Page.ts\";\nimport * as Motion from \"./Pixels.ts\";\n\nexport interface Options {\n readonly still?: \"screen\" | \"content\" | \"foreground\" | undefined;\n readonly quietMillis: number;\n readonly timeout?: Duration.Input | undefined;\n}\n\nconst observe = (page: Page, options: Options, timeout: Duration.Duration) =>\n Effect.gen(function* () {\n const now = () => monotonicMillis(page.clock);\n const deadline = now() + Duration.toMillis(timeout);\n\n const settled = () =>\n page.ready({\n quietMillis: options.quietMillis,\n timeout: Duration.millis(Math.max(0, deadline - now())),\n });\n\n // A capture the wait starts sends its first frame late, over half a second from a hosted\n // browser, so the spell counts from that frame (#202); Chrome sends one as a capture starts,\n // even of a still page.\n const quiet = (millis: number) =>\n Effect.gen(function* () {\n const capture = yield* page.capture();\n\n const foreground = options.still === \"foreground\";\n let counts = yield* capture.stats();\n let stirred = now();\n let reference: Motion.Picture | undefined;\n\n const decoded = (frame: Frame) =>\n Effect.try({\n try: () => Motion.picture(frame),\n catch: (error) =>\n undispatched(\"ready\", new Failed({ detail: `no picture: ${String(error)}` })),\n });\n\n // The background: what moved in up to eight frames of the document's 1.5 s before its\n // latest input, as far back as the capture keeps them.\n const inputAt =\n (yield* page.recentEvents).findLast((event) => event._tag === \"Action\")?.startedAt ??\n Number.NEGATIVE_INFINITY;\n\n const document = (yield* page.state).document;\n\n const before = (foreground ? yield* page.recentFrames : []).filter(\n (frame) =>\n frame.hostTime < inputAt &&\n frame.hostTime >= inputAt - 1500 &&\n frame.document === document,\n );\n\n const sampled = before.filter((_, index) => index % Math.ceil(before.length / 8) === 0);\n const mask = Motion.background(yield* Effect.forEach(sampled, decoded));\n\n // How long the screen has been still: since a frame, or an unanswered acknowledgement. In\n // the foreground, since a frame moved outside the background, or acknowledgements went\n // unanswered with no frame coming.\n const look = Effect.gen(function* () {\n const stats = yield* capture.stats();\n const latest = (yield* page.state).frame;\n const arrived = stats.received !== counts.received;\n const unseen = stats.accepted - counts.accepted;\n\n counts = stats;\n if (latest === undefined || !capture.isCurrent(latest)) stirred = now();\n else if (!foreground ? arrived || stats.ackBacklog > 0 : !arrived && stats.ackBacklog > 0)\n stirred = now();\n else if (foreground && (unseen > 0 || reference === undefined)) {\n // A move and its return between looks both count. Bound decoding; any frames lost\n // from history, or beyond this batch, deny a quiet spell rather than hiding motion.\n const frames = (yield* page.recentFrames).slice(-Math.max(1, Math.min(8, unseen)));\n\n if (unseen > frames.length) stirred = now();\n for (const frame of frames) {\n const seen = yield* decoded(frame);\n\n if (reference === undefined || Motion.stirs(reference, seen, mask)) {\n reference = seen;\n stirred = now();\n }\n }\n }\n\n return now() - stirred;\n });\n\n // Decode at a fixed cadence: adding a delay after a full batch lets its backlog grow.\n const spell = Effect.repeat(look, {\n schedule: Schedule.fixed(Duration.millis(foreground ? 100 : 25)),\n until: (still) => still >= millis,\n });\n\n const still = Effect.gen(function* () {\n for (;;) {\n yield* spell;\n const before = counts.received;\n\n yield* Effect.all([settled(), capture.sync], { concurrency: 2, discard: true });\n if ((yield* look) >= millis && (foreground || counts.received === before)) return;\n }\n });\n\n return yield* Effect.raceFirst(\n capture.stream.pipe(Stream.runDrain, Effect.andThen(Effect.never)),\n still,\n );\n });\n\n yield* page.afterInput(Effect.void);\n if (options.still === \"content\") {\n yield* page.changes();\n yield* Effect.sleep(Duration.millis(options.quietMillis));\n\n return yield* settled();\n }\n yield* settled();\n yield* quiet(options.quietMillis);\n });\n\nexport const wait = (page: Page, options: Options) =>\n Effect.gen(function* () {\n if (!Number.isFinite(options.quietMillis) || options.quietMillis < 0)\n return yield* refuse(\"stillness\", \"quietMillis must be finite and nonnegative\");\n const input = options.timeout ?? Duration.seconds(15);\n\n const components =\n typeof input === \"number\"\n ? [input]\n : typeof input === \"object\" && !Duration.isDuration(input)\n ? Object.values(input)\n : [];\n\n const timeout = Duration.fromInput(input);\n\n if (\n components.some((value) => typeof value === \"number\" && !Number.isFinite(value)) ||\n Option.isNone(timeout) ||\n !Duration.isFinite(timeout.value) ||\n Duration.isNegative(timeout.value)\n )\n return yield* refuse(\"stillness\", \"timeout must be a finite nonnegative duration\");\n const duration = timeout.value;\n\n return yield* observe(page, options, duration).pipe(\n Effect.timeoutOrElse({\n duration,\n orElse: () =>\n Effect.fail(\n undispatched(\"stillness\", new Timeout({ millis: Duration.toMillis(duration) })),\n ),\n }),\n );\n }).pipe(\n Effect.scoped,\n Effect.provideService(Clock.Clock, page.clock),\n Effect.withSpan(\"Stillness.wait\"),\n );\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAa,WAAW,UAA0B,OAAO,OAAO,MAAM,MAAM,EAAE,WAAW,KAAK,CAAC;;AAG/F,MAAM,QAAQ;;AAGd,MAAM,SAAS,MAAe,OAAuC;CACnE,IAAI,KAAK,UAAU,GAAG,SAAS,KAAK,WAAW,GAAG,QAAQ,OAAO,CAAC,EAAE;CACpE,MAAM,UAAU,KAAK,KAAK,KAAK,QAAQ,EAAE;CACzC,MAAM,yBAAS,IAAI,IAAoB;CACvC,MAAM,WAAW,OAAe,KAAK,KAAK,KAAK,KAAK,OAAO,MAAM,GAAG,KAAK,OAAO,EAAE,IAAI;CAEtF,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GACpC,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,OA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AO,OAAO,OAAO,aAAa,4CAA4C;CAChF,MAAM,QAAQ,QAAQ,WAAW,SAAS,QAAQ,EAAE;CAEpD,MAAM,aACJ,OAAO,UAAU,WACb,CAAC,KAAK,IACN,OAAO,UAAU,YAAY,CAAC,SAAS,WAAW,KAAK,IACrD,OAAO,OAAO,KAAK,IACnB,CAAC;CAET,MAAM,UAAU,SAAS,UAAU,KAAK;CAExC,IACE,WAAW,MAAM,UAAU,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,CAAC,KAC/E,OAAO,OAAO,OAAO,KACrB,CAAC,SAAS,SAAS,QAAQ,KAAK,KAChC,SAAS,WAAW,QAAQ,KAAK,GAEjC,OAAO,OAAO,OAAO,aAAa,+CAA+C;CACnF,MAAM,WAAW,QAAQ;CAEzB,OAAO,OAAO,QAAQ,MAAM,SAAS,QAAQ,CAAC,CAAC,KAC7C,OAAO,cAAc;EACnB;EACA,cACE,OAAO,KACL,aAAa,aAAa,IAAI,QAAQ,EAAE,QAAQ,SAAS,SAAS,QAAQ,EAAE,CAAC,CAAC,CAChF;CACJ,CAAC,CACH;AACF,CAAC,CAAC,CAAC,KACD,OAAO,QACP,OAAO,eAAe,MAAM,OAAO,KAAK,KAAK,GAC7C,OAAO,SAAS,gBAAgB,CAClC"}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { normal } from "./Geometry.mjs";
|
|
3
|
+
import { InvalidRequest, refuse, undispatched } from "./BrowserError.mjs";
|
|
4
|
+
import { Context, Effect, Random, Schema } from "effect";
|
|
5
|
+
//#region src/internal/input/keys.ts
|
|
6
|
+
/**
|
|
7
|
+
* Key aliases for Playwright and printable US key descriptions for pipelined Chromium typing.
|
|
8
|
+
*/
|
|
9
|
+
const aliases = {
|
|
10
|
+
ctrl: "Control",
|
|
11
|
+
control: "Control",
|
|
12
|
+
cmd: "Meta",
|
|
13
|
+
command: "Meta",
|
|
14
|
+
meta: "Meta",
|
|
15
|
+
win: "Meta",
|
|
16
|
+
super: "Meta",
|
|
17
|
+
mod: "ControlOrMeta",
|
|
18
|
+
alt: "Alt",
|
|
19
|
+
option: "Alt",
|
|
20
|
+
shift: "Shift",
|
|
21
|
+
enter: "Enter",
|
|
22
|
+
return: "Enter",
|
|
23
|
+
esc: "Escape",
|
|
24
|
+
escape: "Escape",
|
|
25
|
+
tab: "Tab",
|
|
26
|
+
space: "Space",
|
|
27
|
+
spacebar: "Space",
|
|
28
|
+
" ": "Space",
|
|
29
|
+
backspace: "Backspace",
|
|
30
|
+
delete: "Delete",
|
|
31
|
+
del: "Delete",
|
|
32
|
+
insert: "Insert",
|
|
33
|
+
home: "Home",
|
|
34
|
+
end: "End",
|
|
35
|
+
pageup: "PageUp",
|
|
36
|
+
pagedown: "PageDown",
|
|
37
|
+
up: "ArrowUp",
|
|
38
|
+
down: "ArrowDown",
|
|
39
|
+
left: "ArrowLeft",
|
|
40
|
+
right: "ArrowRight",
|
|
41
|
+
arrowup: "ArrowUp",
|
|
42
|
+
arrowdown: "ArrowDown",
|
|
43
|
+
arrowleft: "ArrowLeft",
|
|
44
|
+
arrowright: "ArrowRight"
|
|
45
|
+
};
|
|
46
|
+
const named = new Set(Object.values(aliases));
|
|
47
|
+
/** Parse and validate the whole chord before sending any down events. */
|
|
48
|
+
const parts = (keys) => {
|
|
49
|
+
const tokens = [];
|
|
50
|
+
let building = "";
|
|
51
|
+
for (const character of keys) if (character === "+" && building.trim() !== "") {
|
|
52
|
+
tokens.push(building);
|
|
53
|
+
building = "";
|
|
54
|
+
} else building += character;
|
|
55
|
+
tokens.push(building);
|
|
56
|
+
if (tokens.length > 4) return void 0;
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const token of tokens) {
|
|
59
|
+
const part = token === " " ? "Space" : token.trim();
|
|
60
|
+
const lower = part.toLowerCase();
|
|
61
|
+
const alias = Object.hasOwn(aliases, lower) ? aliases[lower] : void 0;
|
|
62
|
+
if (alias !== void 0) out.push(alias);
|
|
63
|
+
else if (named.has(part) || /^F([1-9]|1[0-2])$/.test(part) || /^(Key[A-Z]|Digit[0-9]|Numpad[0-9])$/.test(part) || description(part) !== void 0) out.push(part);
|
|
64
|
+
else return void 0;
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
};
|
|
68
|
+
const punctuation = [
|
|
69
|
+
[
|
|
70
|
+
"`~",
|
|
71
|
+
"Backquote",
|
|
72
|
+
192
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
"-_",
|
|
76
|
+
"Minus",
|
|
77
|
+
189
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"=+",
|
|
81
|
+
"Equal",
|
|
82
|
+
187
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"\\|",
|
|
86
|
+
"Backslash",
|
|
87
|
+
220
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"[{",
|
|
91
|
+
"BracketLeft",
|
|
92
|
+
219
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"]}",
|
|
96
|
+
"BracketRight",
|
|
97
|
+
221
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
";:",
|
|
101
|
+
"Semicolon",
|
|
102
|
+
186
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"'\"",
|
|
106
|
+
"Quote",
|
|
107
|
+
222
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
",<",
|
|
111
|
+
"Comma",
|
|
112
|
+
188
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
".>",
|
|
116
|
+
"Period",
|
|
117
|
+
190
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"/?",
|
|
121
|
+
"Slash",
|
|
122
|
+
191
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
" ",
|
|
126
|
+
"Space",
|
|
127
|
+
32
|
|
128
|
+
]
|
|
129
|
+
];
|
|
130
|
+
/**
|
|
131
|
+
* Match Playwright's pinned US layout for literal typing. Uppercase and shifted punctuation
|
|
132
|
+
* carry their literal text without synthesizing Shift. Newlines also use insertText so a text
|
|
133
|
+
* payload cannot submit a form; only an explicit Enter or submit option may do that.
|
|
134
|
+
*/
|
|
135
|
+
const description = (character) => {
|
|
136
|
+
if (character === "Backspace") return {
|
|
137
|
+
code: "Backspace",
|
|
138
|
+
keyCode: 8,
|
|
139
|
+
key: "Backspace",
|
|
140
|
+
text: ""
|
|
141
|
+
};
|
|
142
|
+
if (character.length !== 1) return void 0;
|
|
143
|
+
if (/^[A-Za-z]$/.test(character)) {
|
|
144
|
+
const upper = character.toUpperCase();
|
|
145
|
+
return {
|
|
146
|
+
code: `Key${upper}`,
|
|
147
|
+
keyCode: upper.charCodeAt(0),
|
|
148
|
+
key: character,
|
|
149
|
+
text: character
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const digit = "0123456789".indexOf(character);
|
|
153
|
+
const number = digit === -1 ? ")!@#$%^&*(".indexOf(character) : digit;
|
|
154
|
+
if (number !== -1) return {
|
|
155
|
+
code: `Digit${number}`,
|
|
156
|
+
keyCode: 48 + number,
|
|
157
|
+
key: character,
|
|
158
|
+
text: character
|
|
159
|
+
};
|
|
160
|
+
const symbol = punctuation.find(([characters]) => characters.includes(character));
|
|
161
|
+
return symbol === void 0 ? void 0 : {
|
|
162
|
+
code: symbol[1],
|
|
163
|
+
keyCode: symbol[2],
|
|
164
|
+
key: character,
|
|
165
|
+
text: character
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/Style.ts
|
|
170
|
+
/**
|
|
171
|
+
* How input is sent: plainly, as fast as the page takes it, or performed for viewers, with a
|
|
172
|
+
* pointer that glides, keys typed at a person's pace, held buttons and wheels in bursts. A page's
|
|
173
|
+
* actions take one, and the input reaches the same controls either way; only its timing, and
|
|
174
|
+
* what viewers see of it, differ. A presenter builds the performed one.
|
|
175
|
+
*/
|
|
176
|
+
var Style_exports = /* @__PURE__ */ __exportAll({
|
|
177
|
+
Current: () => Current,
|
|
178
|
+
keyGap: () => keyGap,
|
|
179
|
+
maximumDurationMillis: () => maximumDurationMillis,
|
|
180
|
+
pause: () => pause,
|
|
181
|
+
performed: () => performed,
|
|
182
|
+
plain: () => plain,
|
|
183
|
+
provide: () => provide,
|
|
184
|
+
validated: () => validated
|
|
185
|
+
});
|
|
186
|
+
/** Each key as it comes, with no pause; a drag moves in eight short steps so its target sees it. */
|
|
187
|
+
const plain = {
|
|
188
|
+
shown: false,
|
|
189
|
+
pointer: void 0,
|
|
190
|
+
glide: (from, to, dragging) => Effect.succeed(dragging ? Array.from({ length: 8 }, (_, index) => ({
|
|
191
|
+
x: index === 7 ? to.x : from.x + (to.x - from.x) * (index + 1) / 8,
|
|
192
|
+
y: index === 7 ? to.y : from.y + (to.y - from.y) * (index + 1) / 8,
|
|
193
|
+
afterMillis: (index + 1) * 8
|
|
194
|
+
})) : [{
|
|
195
|
+
...to,
|
|
196
|
+
afterMillis: 0
|
|
197
|
+
}]),
|
|
198
|
+
hold: Effect.succeed(0),
|
|
199
|
+
typing: (text, guarded) => Effect.succeed(guarded && text !== "" ? [{
|
|
200
|
+
afterMillis: 0,
|
|
201
|
+
phase: "insert",
|
|
202
|
+
key: text
|
|
203
|
+
}] : [...text].flatMap((key) => description(key) === void 0 ? [{
|
|
204
|
+
afterMillis: 0,
|
|
205
|
+
phase: "insert",
|
|
206
|
+
key
|
|
207
|
+
}] : [{
|
|
208
|
+
afterMillis: 0,
|
|
209
|
+
phase: "down",
|
|
210
|
+
key
|
|
211
|
+
}, {
|
|
212
|
+
afterMillis: 0,
|
|
213
|
+
phase: "up",
|
|
214
|
+
key
|
|
215
|
+
}])),
|
|
216
|
+
keyGap: Effect.succeed(0),
|
|
217
|
+
wheel: (dx, dy) => Effect.succeed([{
|
|
218
|
+
dx,
|
|
219
|
+
dy,
|
|
220
|
+
afterMillis: 0
|
|
221
|
+
}])
|
|
222
|
+
};
|
|
223
|
+
const lognormal = Effect.fnUntraced(function* (median, sigma, minimum, maximum) {
|
|
224
|
+
return Math.max(minimum, Math.min(maximum, median * Math.exp(sigma * (yield* normal))));
|
|
225
|
+
});
|
|
226
|
+
/** A pause around `median`, as the research measured reactions: at most four times it. */
|
|
227
|
+
const pause = (median, sigma) => median <= 0 ? Effect.succeed(0) : lognormal(median, sigma, 0, median * 4);
|
|
228
|
+
const pressHold = lognormal(75.2, .35, 35, 200);
|
|
229
|
+
const keyHold = lognormal(107.8, .2, 60, 220);
|
|
230
|
+
const eventOrder = {
|
|
231
|
+
up: 0,
|
|
232
|
+
insert: 1,
|
|
233
|
+
down: 2
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Plan the whole text before any key goes, so holds overlap without waiting on the network. A
|
|
237
|
+
* physical key is never held twice, as with A and a, or ! and 1. The first key waits for the hand
|
|
238
|
+
* to reach the keys, each later one follows the last by a gap drawn around `gap`, and a word's
|
|
239
|
+
* first key comes 60 ms later.
|
|
240
|
+
*/
|
|
241
|
+
const maximumDurationMillis = 1e4;
|
|
242
|
+
const Delay = Schema.Finite.check(Schema.isBetween({
|
|
243
|
+
minimum: 0,
|
|
244
|
+
maximum: maximumDurationMillis
|
|
245
|
+
}));
|
|
246
|
+
const ordered = (sample) => Schema.Array(sample).check(Schema.makeFilter((samples) => samples.every((event, index) => event.afterMillis >= (samples[index - 1]?.afterMillis ?? 0)), { expected: "nondecreasing input offsets" }));
|
|
247
|
+
const Typing = ordered(Schema.Struct({
|
|
248
|
+
afterMillis: Delay,
|
|
249
|
+
phase: Schema.Literals([
|
|
250
|
+
"down",
|
|
251
|
+
"up",
|
|
252
|
+
"insert"
|
|
253
|
+
]),
|
|
254
|
+
key: Schema.String
|
|
255
|
+
})).check(Schema.makeFilter((events) => {
|
|
256
|
+
const held = /* @__PURE__ */ new Set();
|
|
257
|
+
for (const event of events) {
|
|
258
|
+
if (event.phase === "insert") continue;
|
|
259
|
+
const code = description(event.key)?.code;
|
|
260
|
+
if (code === void 0 || event.phase === "down" === held.has(code)) return false;
|
|
261
|
+
if (event.phase === "down") held.add(code);
|
|
262
|
+
else held.delete(code);
|
|
263
|
+
}
|
|
264
|
+
return held.size === 0;
|
|
265
|
+
}, { expected: "matched key holds" }));
|
|
266
|
+
const Wheel = ordered(Schema.Struct({
|
|
267
|
+
afterMillis: Delay,
|
|
268
|
+
dx: Schema.Finite,
|
|
269
|
+
dy: Schema.Finite
|
|
270
|
+
}));
|
|
271
|
+
const decode = (schema, operation) => (value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.catch(() => refuse(operation, "style must provide a finite bounded ordered input schedule")));
|
|
272
|
+
/** Copy and validate custom schedules before their first input; planning uses the action bound. */
|
|
273
|
+
const validated = (style) => ({
|
|
274
|
+
...style,
|
|
275
|
+
hold: style.hold.pipe(Effect.flatMap(decode(Delay, "click"))),
|
|
276
|
+
keyGap: style.keyGap.pipe(Effect.flatMap(decode(Delay, "press"))),
|
|
277
|
+
typing: (text, guarded) => style.typing(text, guarded).pipe(Effect.flatMap(decode(Typing, "type"))),
|
|
278
|
+
wheel: (dx, dy) => style.wheel(dx, dy).pipe(Effect.flatMap(decode(Wheel, "scroll")))
|
|
279
|
+
});
|
|
280
|
+
const overBudget = (operation) => undispatched(operation, new InvalidRequest({ detail: `presentation must take at most ${maximumDurationMillis} milliseconds` }));
|
|
281
|
+
const typing = Effect.fnUntraced(function* (text, gap) {
|
|
282
|
+
const events = [];
|
|
283
|
+
const releases = /* @__PURE__ */ new Map();
|
|
284
|
+
let due = text === "" ? 0 : yield* Random.nextBetween(150, 400);
|
|
285
|
+
let previous = "";
|
|
286
|
+
for (const character of text) {
|
|
287
|
+
if (due > 1e4) return yield* overBudget("type");
|
|
288
|
+
if (/\s/u.test(previous) && /[\p{L}\p{N}]/u.test(character)) due += 60;
|
|
289
|
+
const description$1 = description(character);
|
|
290
|
+
if (description$1 === void 0) events.push({
|
|
291
|
+
afterMillis: due,
|
|
292
|
+
phase: "insert",
|
|
293
|
+
key: character
|
|
294
|
+
});
|
|
295
|
+
else {
|
|
296
|
+
due = Math.max(due, (releases.get(description$1.code) ?? -1) + 1);
|
|
297
|
+
const released = due + (yield* keyHold);
|
|
298
|
+
events.push({
|
|
299
|
+
afterMillis: due,
|
|
300
|
+
phase: "down",
|
|
301
|
+
key: character
|
|
302
|
+
}, {
|
|
303
|
+
afterMillis: released,
|
|
304
|
+
phase: "up",
|
|
305
|
+
key: character
|
|
306
|
+
});
|
|
307
|
+
releases.set(description$1.code, released);
|
|
308
|
+
}
|
|
309
|
+
due += yield* Random.nextBetween(gap / 2, gap * 3 / 2);
|
|
310
|
+
previous = character;
|
|
311
|
+
}
|
|
312
|
+
if (events.some((event) => event.afterMillis > 1e4)) return yield* overBudget("type");
|
|
313
|
+
return events.toSorted((left, right) => left.afterMillis - right.afterMillis || eventOrder[left.phase] - eventOrder[right.phase]);
|
|
314
|
+
});
|
|
315
|
+
/** A word is five characters; the gap leaves room for each word's later start. */
|
|
316
|
+
const keyGap = (wordsPerMinute) => 12e3 / wordsPerMinute - 10;
|
|
317
|
+
/**
|
|
318
|
+
* The wheel in 100 px notches, 30 to 140 ms apart, in bursts of at most nine, with 0.6 to 2.6 s
|
|
319
|
+
* between bursts, as people scroll.
|
|
320
|
+
*/
|
|
321
|
+
const bursts = Effect.fnUntraced(function* (dx, dy) {
|
|
322
|
+
const notches = Math.max(1, Math.ceil(Math.hypot(dx, dy) / 100));
|
|
323
|
+
if (notches > 334.3333333333333) return yield* overBudget("scroll");
|
|
324
|
+
const steps = [];
|
|
325
|
+
let due = 0;
|
|
326
|
+
for (let index = 0; index < notches; index++) {
|
|
327
|
+
if (index > 0) due += yield* index % 9 === 0 ? Random.nextBetween(600, 2600) : Random.nextBetween(30, 140);
|
|
328
|
+
if (due > 1e4) return yield* overBudget("scroll");
|
|
329
|
+
steps.push({
|
|
330
|
+
dx: dx / notches,
|
|
331
|
+
dy: dy / notches,
|
|
332
|
+
afterMillis: due
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return steps;
|
|
336
|
+
});
|
|
337
|
+
/** Input performed for viewers, with this pointer and pace. */
|
|
338
|
+
const performed = (options) => {
|
|
339
|
+
const gap = keyGap(options.wordsPerMinute);
|
|
340
|
+
return {
|
|
341
|
+
shown: true,
|
|
342
|
+
pointer: options.pointer,
|
|
343
|
+
glide: (from, to) => options.motion.plan(from, to),
|
|
344
|
+
hold: pressHold,
|
|
345
|
+
typing: (text) => typing(text, gap),
|
|
346
|
+
keyGap: Random.nextBetween(gap / 2, gap * 3 / 2),
|
|
347
|
+
wheel: bursts
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
/** Input style in this fiber; plain input is the default. */
|
|
351
|
+
const Current = Context.Reference("effect-browser/Style", { defaultValue: () => plain });
|
|
352
|
+
/** Apply a style through page input, including pages selected later by a browser adapter. */
|
|
353
|
+
const provide = (style) => (effect) => Effect.provideService(effect, Current, style);
|
|
354
|
+
//#endregion
|
|
355
|
+
export { pause as a, provide as c, parts as d, maximumDurationMillis as i, validated as l, Style_exports as n, performed as o, keyGap as r, plain as s, Current as t, description as u };
|
|
356
|
+
|
|
357
|
+
//# sourceMappingURL=Style-AO4V7Czt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Style-AO4V7Czt.mjs","names":["Keys.description","description"],"sources":["../src/internal/input/keys.ts","../src/Style.ts"],"sourcesContent":["/**\n * Key aliases for Playwright and printable US key descriptions for pipelined Chromium typing.\n */\n\nconst aliases: Record<string, string> = {\n ctrl: \"Control\",\n control: \"Control\",\n cmd: \"Meta\",\n command: \"Meta\",\n meta: \"Meta\",\n win: \"Meta\",\n super: \"Meta\",\n mod: \"ControlOrMeta\",\n alt: \"Alt\",\n option: \"Alt\",\n shift: \"Shift\",\n enter: \"Enter\",\n return: \"Enter\",\n esc: \"Escape\",\n escape: \"Escape\",\n tab: \"Tab\",\n space: \"Space\",\n spacebar: \"Space\",\n \" \": \"Space\",\n backspace: \"Backspace\",\n delete: \"Delete\",\n del: \"Delete\",\n insert: \"Insert\",\n home: \"Home\",\n end: \"End\",\n pageup: \"PageUp\",\n pagedown: \"PageDown\",\n up: \"ArrowUp\",\n down: \"ArrowDown\",\n left: \"ArrowLeft\",\n right: \"ArrowRight\",\n arrowup: \"ArrowUp\",\n arrowdown: \"ArrowDown\",\n arrowleft: \"ArrowLeft\",\n arrowright: \"ArrowRight\",\n};\n\nconst named = new Set(Object.values(aliases));\n\n/** Parse and validate the whole chord before sending any down events. */\nexport const parts = (keys: string): ReadonlyArray<string> | undefined => {\n const tokens: Array<string> = [];\n let building = \"\";\n\n // Like Playwright, a plus without a preceding token is the literal plus key: Control++.\n for (const character of keys) {\n if (character === \"+\" && building.trim() !== \"\") {\n tokens.push(building);\n building = \"\";\n } else building += character;\n }\n tokens.push(building);\n if (tokens.length > 4) return undefined;\n const out: Array<string> = [];\n\n for (const token of tokens) {\n const part = token === \" \" ? \"Space\" : token.trim();\n const lower = part.toLowerCase();\n const alias = Object.hasOwn(aliases, lower) ? aliases[lower] : undefined;\n\n if (alias !== undefined) out.push(alias);\n else if (\n named.has(part) ||\n /^F([1-9]|1[0-2])$/.test(part) ||\n /^(Key[A-Z]|Digit[0-9]|Numpad[0-9])$/.test(part) ||\n description(part) !== undefined\n )\n out.push(part);\n else return undefined;\n }\n\n return out;\n};\n\ninterface Description {\n readonly code: string;\n readonly keyCode: number;\n readonly key: string;\n readonly text: string;\n}\n\nconst punctuation: ReadonlyArray<readonly [string, string, number]> = [\n [\"`~\", \"Backquote\", 192],\n [\"-_\", \"Minus\", 189],\n [\"=+\", \"Equal\", 187],\n [\"\\\\|\", \"Backslash\", 220],\n [\"[{\", \"BracketLeft\", 219],\n [\"]}\", \"BracketRight\", 221],\n [\";:\", \"Semicolon\", 186],\n [\"'\\\"\", \"Quote\", 222],\n [\",<\", \"Comma\", 188],\n [\".>\", \"Period\", 190],\n [\"/?\", \"Slash\", 191],\n [\" \", \"Space\", 32],\n];\n\n/**\n * Match Playwright's pinned US layout for literal typing. Uppercase and shifted punctuation\n * carry their literal text without synthesizing Shift. Newlines also use insertText so a text\n * payload cannot submit a form; only an explicit Enter or submit option may do that.\n */\nexport const description = (character: string): Description | undefined => {\n // Prose correction uses the same raw key path so its deletion has a matched release.\n if (character === \"Backspace\")\n return { code: \"Backspace\", keyCode: 8, key: \"Backspace\", text: \"\" };\n if (character.length !== 1) return undefined;\n if (/^[A-Za-z]$/.test(character)) {\n const upper = character.toUpperCase();\n\n return { code: `Key${upper}`, keyCode: upper.charCodeAt(0), key: character, text: character };\n }\n const digit = \"0123456789\".indexOf(character);\n const number = digit === -1 ? \")!@#$%^&*(\".indexOf(character) : digit;\n\n if (number !== -1)\n return { code: `Digit${number}`, keyCode: 48 + number, key: character, text: character };\n const symbol = punctuation.find(([characters]) => characters.includes(character));\n\n return symbol === undefined\n ? undefined\n : { code: symbol[1], keyCode: symbol[2], key: character, text: character };\n};\n","/**\n * How input is sent: plainly, as fast as the page takes it, or performed for viewers, with a\n * pointer that glides, keys typed at a person's pace, held buttons and wheels in bursts. A page's\n * actions take one, and the input reaches the same controls either way; only its timing, and\n * what viewers see of it, differ. A presenter builds the performed one.\n */\nimport {\n Context,\n type Duration,\n Effect,\n type MutableRef,\n type Option,\n Random,\n Schema,\n} from \"effect\";\n\nimport { undispatched, type BrowserError, InvalidRequest, refuse } from \"./BrowserError.ts\";\nimport type * as Motion from \"./Geometry.ts\";\nimport { normal } from \"./Geometry.ts\";\nimport * as Keys from \"./internal/input/keys.ts\";\nimport type { Point } from \"./Page.ts\";\n\nexport interface TypingEvent {\n /** From the start of the typing. */\n readonly afterMillis: number;\n readonly phase: \"down\" | \"up\" | \"insert\";\n readonly key: string;\n}\n\nexport interface WheelStep {\n readonly dx: number;\n readonly dy: number;\n /** From the first step. */\n readonly afterMillis: number;\n}\n\nexport interface Style {\n /** Own presentation only after policy allows input; wait options belong to the page. */\n readonly withInput?:\n | ((options: {\n readonly operation: string;\n readonly wait: Duration.Duration;\n readonly failFast: boolean;\n }) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BrowserError, R>)\n | undefined;\n /**\n * Whether viewers watch the input: then the pointer clicks into a field before typing, finds\n * what lies under it as it scrolls, and scrolls to a target out of view with the wheel.\n */\n readonly shown: boolean;\n /** Where viewers last saw the pointer, which the next glide starts from; else the page's own. */\n readonly pointer: MutableRef.MutableRef<Option.Option<Point>> | undefined;\n /** The pointer's path to `to`, ending exactly there. */\n readonly glide: (\n from: Point,\n to: Point,\n dragging: boolean,\n ) => Effect.Effect<ReadonlyArray<Motion.Sample>>;\n /** How long a button stays down when a click does not say. */\n readonly hold: Effect.Effect<number, BrowserError>;\n /** The key events that type `text`, or one insertion of it under a guard, timed from the start. */\n readonly typing: (\n text: string,\n guarded: boolean,\n ) => Effect.Effect<ReadonlyArray<TypingEvent>, BrowserError>;\n /** The pause between repeated presses of the same keys. */\n readonly keyGap: Effect.Effect<number, BrowserError>;\n /** A wheel scroll as the wheel turns: in one step, or in notches and bursts. */\n readonly wheel: (dx: number, dy: number) => Effect.Effect<ReadonlyArray<WheelStep>, BrowserError>;\n}\n\n/** Each key as it comes, with no pause; a drag moves in eight short steps so its target sees it. */\nexport const plain: Style = {\n shown: false,\n pointer: undefined,\n glide: (from, to, dragging) =>\n Effect.succeed(\n dragging\n ? Array.from({ length: 8 }, (_, index) => ({\n x: index === 7 ? to.x : from.x + ((to.x - from.x) * (index + 1)) / 8,\n y: index === 7 ? to.y : from.y + ((to.y - from.y) * (index + 1)) / 8,\n afterMillis: (index + 1) * 8,\n }))\n : [{ ...to, afterMillis: 0 }],\n ),\n hold: Effect.succeed(0),\n typing: (text, guarded) =>\n Effect.succeed(\n guarded && text !== \"\"\n ? [{ afterMillis: 0, phase: \"insert\", key: text }]\n : [...text].flatMap((key): ReadonlyArray<TypingEvent> =>\n Keys.description(key) === undefined\n ? [{ afterMillis: 0, phase: \"insert\", key }]\n : [\n { afterMillis: 0, phase: \"down\", key },\n { afterMillis: 0, phase: \"up\", key },\n ],\n ),\n ),\n keyGap: Effect.succeed(0),\n wheel: (dx, dy) => Effect.succeed([{ dx, dy, afterMillis: 0 }]),\n};\n\n// A right-skewed draw, clamped so that cleanup and deadlines stay predictable; 1 - U keeps the\n// logarithm defined when Random returns zero.\nconst lognormal = Effect.fnUntraced(function* (\n median: number,\n sigma: number,\n minimum: number,\n maximum: number,\n) {\n return Math.max(minimum, Math.min(maximum, median * Math.exp(sigma * (yield* normal))));\n});\n\n/** A pause around `median`, as the research measured reactions: at most four times it. */\nexport const pause = (median: number, sigma: number) =>\n median <= 0 ? Effect.succeed(0) : lognormal(median, sigma, 0, median * 4);\n\n// A mouse press about 80 ms long on average, a key about 110 ms, each now and then longer: their\n// medians are the means times exp(-sigma^2 / 2).\nconst pressHold = lognormal(75.2, 0.35, 35, 200);\nconst keyHold = lognormal(107.8, 0.2, 60, 220);\nconst eventOrder = { up: 0, insert: 1, down: 2 };\n\n/**\n * Plan the whole text before any key goes, so holds overlap without waiting on the network. A\n * physical key is never held twice, as with A and a, or ! and 1. The first key waits for the hand\n * to reach the keys, each later one follows the last by a gap drawn around `gap`, and a word's\n * first key comes 60 ms later.\n */\nexport const maximumDurationMillis = 10_000;\n\nconst Delay = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: maximumDurationMillis }));\n\nconst ordered = <A extends { readonly afterMillis: number }>(sample: Schema.Codec<A>) =>\n Schema.Array(sample).check(\n Schema.makeFilter(\n (samples) =>\n samples.every(\n (event, index) => event.afterMillis >= (samples[index - 1]?.afterMillis ?? 0),\n ),\n { expected: \"nondecreasing input offsets\" },\n ),\n );\n\nconst Typing = ordered(\n Schema.Struct({\n afterMillis: Delay,\n phase: Schema.Literals([\"down\", \"up\", \"insert\"]),\n key: Schema.String,\n }),\n).check(\n Schema.makeFilter(\n (events) => {\n const held = new Set<string>();\n\n for (const event of events) {\n if (event.phase === \"insert\") continue;\n const code = Keys.description(event.key)?.code;\n\n if (code === undefined || (event.phase === \"down\") === held.has(code)) return false;\n if (event.phase === \"down\") held.add(code);\n else held.delete(code);\n }\n\n return held.size === 0;\n },\n { expected: \"matched key holds\" },\n ),\n);\n\nconst Wheel = ordered(Schema.Struct({ afterMillis: Delay, dx: Schema.Finite, dy: Schema.Finite }));\n\nconst decode =\n <A>(schema: Schema.Codec<A>, operation: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.catch(() =>\n refuse(operation, \"style must provide a finite bounded ordered input schedule\"),\n ),\n );\n\n/** Copy and validate custom schedules before their first input; planning uses the action bound. */\nexport const validated = (style: Style): Style => ({\n ...style,\n hold: style.hold.pipe(Effect.flatMap(decode(Delay, \"click\"))),\n keyGap: style.keyGap.pipe(Effect.flatMap(decode(Delay, \"press\"))),\n typing: (text, guarded) =>\n style.typing(text, guarded).pipe(Effect.flatMap(decode(Typing, \"type\"))),\n wheel: (dx, dy) => style.wheel(dx, dy).pipe(Effect.flatMap(decode(Wheel, \"scroll\"))),\n});\n\nconst overBudget = (operation: string) =>\n undispatched(\n operation,\n new InvalidRequest({\n detail: `presentation must take at most ${maximumDurationMillis} milliseconds`,\n }),\n );\n\nconst typing = Effect.fnUntraced(function* (\n text: string,\n gap: number,\n): Effect.fn.Return<ReadonlyArray<TypingEvent>, BrowserError> {\n const events: Array<TypingEvent> = [];\n const releases = new Map<string, number>();\n let due = text === \"\" ? 0 : yield* Random.nextBetween(150, 400);\n let previous = \"\";\n\n for (const character of text) {\n if (due > maximumDurationMillis) return yield* overBudget(\"type\");\n if (/\\s/u.test(previous) && /[\\p{L}\\p{N}]/u.test(character)) due += 60;\n const description = Keys.description(character);\n\n if (description === undefined)\n events.push({ afterMillis: due, phase: \"insert\", key: character });\n else {\n due = Math.max(due, (releases.get(description.code) ?? -1) + 1);\n const released = due + (yield* keyHold);\n\n events.push(\n { afterMillis: due, phase: \"down\", key: character },\n { afterMillis: released, phase: \"up\", key: character },\n );\n releases.set(description.code, released);\n }\n due += yield* Random.nextBetween(gap / 2, (gap * 3) / 2);\n previous = character;\n }\n\n if (events.some((event) => event.afterMillis > maximumDurationMillis))\n return yield* overBudget(\"type\");\n\n return events.toSorted(\n (left, right) =>\n left.afterMillis - right.afterMillis || eventOrder[left.phase] - eventOrder[right.phase],\n );\n});\n\n/** A word is five characters; the gap leaves room for each word's later start. */\nexport const keyGap = (wordsPerMinute: number) => 12_000 / wordsPerMinute - 10;\n\n/**\n * The wheel in 100 px notches, 30 to 140 ms apart, in bursts of at most nine, with 0.6 to 2.6 s\n * between bursts, as people scroll.\n */\nconst bursts = Effect.fnUntraced(function* (dx: number, dy: number) {\n const notches = Math.max(1, Math.ceil(Math.hypot(dx, dy) / 100));\n\n // Even the shortest possible schedule exceeds the cap; refuse before allocating it.\n if (notches > 1 + maximumDurationMillis / 30) return yield* overBudget(\"scroll\");\n const steps: Array<WheelStep> = [];\n let due = 0;\n\n for (let index = 0; index < notches; index++) {\n if (index > 0)\n due += yield* index % 9 === 0 ? Random.nextBetween(600, 2600) : Random.nextBetween(30, 140);\n if (due > maximumDurationMillis) return yield* overBudget(\"scroll\");\n steps.push({ dx: dx / notches, dy: dy / notches, afterMillis: due });\n }\n\n return steps;\n});\n\n/** Input performed for viewers, with this pointer and pace. */\nexport const performed = (options: {\n readonly pointer: MutableRef.MutableRef<Option.Option<Point>>;\n readonly motion: Motion.Planner;\n readonly wordsPerMinute: number;\n}): Style => {\n const gap = keyGap(options.wordsPerMinute);\n\n return {\n shown: true,\n pointer: options.pointer,\n glide: (from, to) => options.motion.plan(from, to),\n hold: pressHold,\n typing: (text) => typing(text, gap),\n keyGap: Random.nextBetween(gap / 2, (gap * 3) / 2),\n wheel: bursts,\n };\n};\n\n/** Input style in this fiber; plain input is the default. */\nexport const Current = Context.Reference<Style>(\"effect-browser/Style\", {\n defaultValue: () => plain,\n});\n\n/** Apply a style through page input, including pages selected later by a browser adapter. */\nexport const provide =\n (style: Style) =>\n <A, E, R>(effect: Effect.Eff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Vzn.mjs";
|
|
2
|
+
import { a as Sample, r as Planner, t as Geometry_d_exports } from "./Geometry-DJx9qrYy.mjs";
|
|
3
|
+
import { m as Point } from "./Page-CvsOEorc.mjs";
|
|
4
|
+
import { Context, Duration, Effect, MutableRef, Option } from "effect";
|
|
5
|
+
declare namespace Style_d_exports {
|
|
6
|
+
export { Current, Style, TypingEvent, WheelStep, keyGap, maximumDurationMillis, pause, performed, plain, provide, validated };
|
|
7
|
+
}
|
|
8
|
+
export interface TypingEvent {
|
|
9
|
+
/** From the start of the typing. */
|
|
10
|
+
readonly afterMillis: number;
|
|
11
|
+
readonly phase: "down" | "up" | "insert";
|
|
12
|
+
readonly key: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WheelStep {
|
|
15
|
+
readonly dx: number;
|
|
16
|
+
readonly dy: number;
|
|
17
|
+
/** From the first step. */
|
|
18
|
+
readonly afterMillis: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Style {
|
|
21
|
+
/** Own presentation only after policy allows input; wait options belong to the page. */
|
|
22
|
+
readonly withInput?: ((options: {
|
|
23
|
+
readonly operation: string;
|
|
24
|
+
readonly wait: Duration.Duration;
|
|
25
|
+
readonly failFast: boolean;
|
|
26
|
+
}) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BrowserError, R>) | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Whether viewers watch the input: then the pointer clicks into a field before typing, finds
|
|
29
|
+
* what lies under it as it scrolls, and scrolls to a target out of view with the wheel.
|
|
30
|
+
*/
|
|
31
|
+
readonly shown: boolean;
|
|
32
|
+
/** Where viewers last saw the pointer, which the next glide starts from; else the page's own. */
|
|
33
|
+
readonly pointer: MutableRef.MutableRef<Option.Option<Point>> | undefined;
|
|
34
|
+
/** The pointer's path to `to`, ending exactly there. */
|
|
35
|
+
readonly glide: (from: Point, to: Point, dragging: boolean) => Effect.Effect<ReadonlyArray<Sample>>;
|
|
36
|
+
/** How long a button stays down when a click does not say. */
|
|
37
|
+
readonly hold: Effect.Effect<number, BrowserError>;
|
|
38
|
+
/** The key events that type `text`, or one insertion of it under a guard, timed from the start. */
|
|
39
|
+
readonly typing: (text: string, guarded: boolean) => Effect.Effect<ReadonlyArray<TypingEvent>, BrowserError>;
|
|
40
|
+
/** The pause between repeated presses of the same keys. */
|
|
41
|
+
readonly keyGap: Effect.Effect<number, BrowserError>;
|
|
42
|
+
/** A wheel scroll as the wheel turns: in one step, or in notches and bursts. */
|
|
43
|
+
readonly wheel: (dx: number, dy: number) => Effect.Effect<ReadonlyArray<WheelStep>, BrowserError>;
|
|
44
|
+
}
|
|
45
|
+
/** Each key as it comes, with no pause; a drag moves in eight short steps so its target sees it. */
|
|
46
|
+
export declare const plain: Style;
|
|
47
|
+
/** A pause around `median`, as the research measured reactions: at most four times it. */
|
|
48
|
+
export declare const pause: (median: number, sigma: number) => Effect.Effect<number, never, never>;
|
|
49
|
+
/**
|
|
50
|
+
* Plan the whole text before any key goes, so holds overlap without waiting on the network. A
|
|
51
|
+
* physical key is never held twice, as with A and a, or ! and 1. The first key waits for the hand
|
|
52
|
+
* to reach the keys, each later one follows the last by a gap drawn around `gap`, and a word's
|
|
53
|
+
* first key comes 60 ms later.
|
|
54
|
+
*/
|
|
55
|
+
export declare const maximumDurationMillis = 10000;
|
|
56
|
+
/** Copy and validate custom schedules before their first input; planning uses the action bound. */
|
|
57
|
+
export declare const validated: (style: Style) => Style;
|
|
58
|
+
/** A word is five characters; the gap leaves room for each word's later start. */
|
|
59
|
+
export declare const keyGap: (wordsPerMinute: number) => number;
|
|
60
|
+
/** Input performed for viewers, with this pointer and pace. */
|
|
61
|
+
export declare const performed: (options: {
|
|
62
|
+
readonly pointer: MutableRef.MutableRef<Option.Option<Point>>;
|
|
63
|
+
readonly motion: Planner;
|
|
64
|
+
readonly wordsPerMinute: number;
|
|
65
|
+
}) => Style;
|
|
66
|
+
/** Input style in this fiber; plain input is the default. */
|
|
67
|
+
export declare const Current: Context.Reference<Style>;
|
|
68
|
+
/** Apply a style through page input, including pages selected later by a browser adapter. */
|
|
69
|
+
export declare const provide: (style: Style) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, never>>;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { Style_d_exports as t };
|
|
72
|
+
//# sourceMappingURL=Style.d.mts.map
|
package/dist/Style.mjs
ADDED
package/dist/Url.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare namespace Url_d_exports {
|
|
2
|
+
export { addresses, parse, quoted, redact, redactWithin, withheld };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Addresses: reading one the way a person types it, for `Page.goto` and the browser tools alike,
|
|
6
|
+
* and reporting one without the values that are credentials, by one rule that the page script runs
|
|
7
|
+
* too, for the outline's links.
|
|
8
|
+
*/
|
|
9
|
+
/** The URL `input` names. Without a scheme it is a web address: HTTPS, or HTTP on loopback. */
|
|
10
|
+
export declare const parse: (input: string) => URL | null;
|
|
11
|
+
/**
|
|
12
|
+
* The rule that reports an address without its credentials. The page script runs it too, so it
|
|
13
|
+
* stays self-contained, as `names.inpage.ts` says a page-side part must.
|
|
14
|
+
*/
|
|
15
|
+
export declare const addresses: () => {
|
|
16
|
+
withheld: "••••••••";
|
|
17
|
+
redact: (url: string) => string;
|
|
18
|
+
};
|
|
19
|
+
export declare const withheld: "••••••••", redact: (url: string) => string;
|
|
20
|
+
/** An address inside text, as a failure's message quotes one. */
|
|
21
|
+
export declare const quoted: RegExp;
|
|
22
|
+
/** `text` with each address in it redacted. */
|
|
23
|
+
export declare const redactWithin: (text: string) => string;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Url_d_exports as t };
|
|
26
|
+
//# sourceMappingURL=Url.d.mts.map
|
package/dist/Url.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
//#region src/Url.ts
|
|
3
|
+
var Url_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
addresses: () => addresses,
|
|
5
|
+
parse: () => parse,
|
|
6
|
+
quoted: () => quoted,
|
|
7
|
+
redact: () => redact,
|
|
8
|
+
redactWithin: () => redactWithin,
|
|
9
|
+
withheld: () => withheld
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Addresses: reading one the way a person types it, for `Page.goto` and the browser tools alike,
|
|
13
|
+
* and reporting one without the values that are credentials, by one rule that the page script runs
|
|
14
|
+
* too, for the outline's links.
|
|
15
|
+
*/
|
|
16
|
+
const scheme = /^[a-z][a-z0-9+.-]*:/i;
|
|
17
|
+
const hostAndPort = /^[^\s/?#@:]+:\d+(?:[/?#]|$)/;
|
|
18
|
+
const loopback = /^(?:localhost|127(?:\.\d+){3}|\[::1\])(?:[:/?#]|$)/i;
|
|
19
|
+
/** The URL `input` names. Without a scheme it is a web address: HTTPS, or HTTP on loopback. */
|
|
20
|
+
const parse = (input) => {
|
|
21
|
+
const text = input.trim();
|
|
22
|
+
if (scheme.test(text) && !hostAndPort.test(text)) return URL.parse(text);
|
|
23
|
+
return URL.parse(`${loopback.test(text) ? "http" : "https"}://${text}`);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The rule that reports an address without its credentials. The page script runs it too, so it
|
|
27
|
+
* stays self-contained, as `names.inpage.ts` says a page-side part must.
|
|
28
|
+
*/
|
|
29
|
+
const addresses = () => {
|
|
30
|
+
const withheld = "••••••••";
|
|
31
|
+
const credential = /token|secret|passw|passcode|passphrase|signature|credential|assertion|verifier|bearer|jwt|hmac|apikey|accesskey|privatekey|sess(?:ion)?id|saml(?:response|art)|(?:sig|otp)$|(?:auth|api|access|private|secret|signing|client|encryption|licen[cs]e|session|master|app|device|verification|verify|confirmation|confirm|activation|activate|reset|recovery|login|security|magic|onetime|mfa|2fa|sms|email|otp|oob)(?:code|key)$|^(?:auth|authorization|pwd|pass)$/;
|
|
32
|
+
const ambiguous = /^(?:code|key|session|sid|ticket)$/;
|
|
33
|
+
const secret = (name, value) => {
|
|
34
|
+
const bare = name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
35
|
+
return value !== "" && (credential.test(bare) || ambiguous.test(bare) && value.length >= 16 && /\d/.test(value) && /[a-z]/i.test(value));
|
|
36
|
+
};
|
|
37
|
+
const masked = (parameters, separator) => parameters.split(separator).map((parameter) => {
|
|
38
|
+
const [name = "", value = ""] = [...new URLSearchParams(parameter)][0] ?? [];
|
|
39
|
+
return secret(name, value) ? `${parameter.slice(0, parameter.indexOf("=") + 1)}${withheld}` : parameter;
|
|
40
|
+
}).join(separator);
|
|
41
|
+
/**
|
|
42
|
+
* `url` as the library reports it: without userinfo, and with each credential's value withheld,
|
|
43
|
+
* so the rest keeps its identity, such as a chart's `?ticker=ETH`. An address without a host,
|
|
44
|
+
* such as `data:` or `about:blank`, is content or a fixed name, and stays as it is.
|
|
45
|
+
*/
|
|
46
|
+
const redact = (url) => {
|
|
47
|
+
const parsed = URL.parse(url);
|
|
48
|
+
if (parsed === null || parsed.host === "") return url;
|
|
49
|
+
parsed.username = "";
|
|
50
|
+
parsed.password = "";
|
|
51
|
+
parsed.pathname = masked(parsed.pathname, ";");
|
|
52
|
+
parsed.search = masked(parsed.search.slice(1), "&");
|
|
53
|
+
if (parsed.hash.includes("=")) {
|
|
54
|
+
const fragment = parsed.hash.slice(1);
|
|
55
|
+
const question = fragment.indexOf("?");
|
|
56
|
+
const start = question >= 0 && question < fragment.indexOf("=") ? question + 1 : 0;
|
|
57
|
+
parsed.hash = fragment.slice(0, start) + masked(fragment.slice(start), "&");
|
|
58
|
+
}
|
|
59
|
+
return parsed.href.replaceAll(encodeURIComponent(withheld), withheld);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
withheld,
|
|
63
|
+
redact
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const { withheld, redact } = addresses();
|
|
67
|
+
/** An address inside text, as a failure's message quotes one. */
|
|
68
|
+
const quoted = /[a-z][a-z\d+.-]*:\/\/[^\s"'<>]+/gi;
|
|
69
|
+
/** `text` with each address in it redacted. */
|
|
70
|
+
const redactWithin = (text) => text.replace(quoted, (url) => redact(url));
|
|
71
|
+
//#endregion
|
|
72
|
+
export { addresses, parse, quoted, redact, redactWithin, Url_exports as t, withheld };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=Url.mjs.map
|
package/dist/Url.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Url.mjs","names":[],"sources":["../src/Url.ts"],"sourcesContent":["/**\n * Addresses: reading one the way a person types it, for `Page.goto` and the browser tools alike,\n * and reporting one without the values that are credentials, by one rule that the page script runs\n * too, for the outline's links.\n */\n\nconst scheme = /^[a-z][a-z0-9+.-]*:/i;\n\n// `localhost:3000` and `example.com:8080/a` look like a scheme to the URL parser; a port decides.\nconst hostAndPort = /^[^\\s/?#@:]+:\\d+(?:[/?#]|$)/;\n\nconst loopback = /^(?:localhost|127(?:\\.\\d+){3}|\\[::1\\])(?:[:/?#]|$)/i;\n\n/** The URL `input` names. Without a scheme it is a web address: HTTPS, or HTTP on loopback. */\nexport const parse = (input: string): URL | null => {\n const text = input.trim();\n\n if (scheme.test(text) && !hostAndPort.test(text)) return URL.parse(text);\n\n return URL.parse(`${loopback.test(text) ? \"http\" : \"https\"}://${text}`);\n};\n\n/**\n * The rule that reports an address without its credentials. The page script runs it too, so it\n * stays self-contained, as `names.inpage.ts` says a page-side part must.\n */\nexport const addresses = () => {\n // What a credential's value reads as, as a secret field's text does (`Page.redacted`).\n const withheld = \"••••••••\" as const;\n\n // A parameter's name, compared in lowercase without separators, says it is a credential: a token,\n // secret, password, signature, assertion, session id or one-time code, or a code or key of a kind\n // that signs someone in or signs a request, such as `verification_code` or `api_key`.\n const credential =\n /token|secret|passw|passcode|passphrase|signature|credential|assertion|verifier|bearer|jwt|hmac|apikey|accesskey|privatekey|sess(?:ion)?id|saml(?:response|art)|(?:sig|otp)$|(?:auth|api|access|private|secret|signing|client|encryption|licen[cs]e|session|master|app|device|verification|verify|confirmation|confirm|activation|activate|reset|recovery|login|security|magic|onetime|mfa|2fa|sms|email|otp|oob)(?:code|key)$|^(?:auth|authorization|pwd|pass)$/;\n\n // These names as often say what an address is about, such as a stock code, a support ticket or a\n // conference session. Under them a value is a credential when it looks generated, at least 16\n // characters with letters and digits, as tokens, session ids and authorization codes do.\n const ambiguous = /^(?:code|key|session|sid|ticket)$/;\n\n const secret = (name: string, value: string) => {\n const bare = name.toLowerCase().replace(/[^a-z0-9]/g, \"\");\n\n return (\n value !== \"\" &&\n (credential.test(bare) ||\n (ambiguous.test(bare) && value.length >= 16 && /\\d/.test(value) && /[a-z]/i.test(value)))\n );\n };\n\n // Parameters as written, each credential's value withheld: a query's, a fragment's written as a\n // query, or a path's segments', as a Java session id is.\n const masked = (parameters: string, separator: string) =>\n parameters\n .split(separator)\n .map((parameter) => {\n const [name = \"\", value = \"\"] = [...new URLSearchParams(parameter)][0] ?? [];\n\n return secret(name, value)\n ? `${parameter.slice(0, parameter.indexOf(\"=\") + 1)}${withheld}`\n : parameter;\n })\n .join(separator);\n\n /**\n * `url` as the library reports it: without userinfo, and with each credential's value withheld,\n * so the rest keeps its identity, such as a chart's `?ticker=ETH`. An address without a host,\n * such as `data:` or `about:blank`, is content or a fixed name, and stays as it is.\n */\n const redact = (url: string): string => {\n const parsed = URL.parse(url);\n\n if (parsed === null || parsed.host === \"\") return url;\n parsed.username = \"\";\n parsed.password = \"\";\n parsed.pathname = masked(parsed.pathname, \";\");\n parsed.search = masked(parsed.search.slice(1), \"&\");\n if (parsed.hash.includes(\"=\")) {\n const fragment = parsed.hash.slice(1);\n const question = fragment.indexOf(\"?\");\n // A route before the parameters, as in `#/inbox?token=…`, stays.\n const start = question >= 0 && question < fragment.indexOf(\"=\") ? question + 1 : 0;\n\n parsed.hash = fragment.slice(0, start) + masked(fragment.slice(start), \"&\");\n }\n\n return parsed.href.replaceAll(encodeURIComponent(withheld), withheld);\n };\n\n return { withheld, redact };\n};\n\nexport const { withheld, redact } = addresses();\n\n/** An address inside text, as a failure's message quotes one. */\nexport const quoted = /[a-z][a-z\\d+.-]*:\\/\\/[^\\s\"'<>]+/gi;\n\n/** `text` with each address in it redacted. */\nexport const redactWithin = (text: string) => text.replace(quoted, (url) => redact(url));\n"],"mappings":";;;;;;;;;;;;;;;AAMA,MAAM,SAAS;AAGf,MAAM,cAAc;AAEpB,MAAM,WAAW;;AAGjB,MAAa,SAAS,UAA8B;CAClD,MAAM,OAAO,MAAM,KAAK;CAExB,IAAI,OAAO,KAAK,IAAI,KAAK,CAAC,YAAY,KAAK,IAAI,GAAG,OAAO,IAAI,MAAM,IAAI;CAEvE,OAAO,IAAI,MAAM,GAAG,SAAS,KAAK,IAAI,IAAI,SAAS,QAAQ,KAAK,MAAM;AACxE;;;;;AAMA,MAAa,kBAAkB;CAE7B,MAAM,WAAW;CAKjB,MAAM,aACJ;CAKF,MAAM,YAAY;CAElB,MAAM,UAAU,MAAc,UAAkB;EAC9C,MAAM,OAAO,KAAK,YAAY,CAAC,CAAC,QAAQ,cAAc,EAAE;EAExD,OACE,UAAU,OACT,WAAW,KAAK,IAAI,KAClB,UAAU,KAAK,IAAI,KAAK,MAAM,UAAU,MAAM,KAAK,KAAK,KAAK,KAAK,SAAS,KAAK,KAAK;CAE5F;CAIA,MAAM,UAAU,YAAoB,cAClC,WACG,MAAM,SAAS,CAAC,CAChB,KAAK,cAAc;EAClB,MAAM,CAAC,OAAO,IAAI,QAAQ,MAAM,CAAC,GAAG,IAAI,gBAAgB,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;EAE3E,OAAO,OAAO,MAAM,KAAK,IACrB,GAAG,UAAU,MAAM,GAAG,UAAU,QAAQ,GAAG,IAAI,CAAC,IAAI,aACpD;CACN,CAAC,CAAC,CACD,KAAK,SAAS;;;;;;CAOnB,MAAM,UAAU,QAAwB;EACtC,MAAM,SAAS,IAAI,MAAM,GAAG;EAE5B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