@full-self-browsing/phantom-stream 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/bin/phantom-stream.js +193 -0
- package/dist/types/adapters/bookmarklet.d.ts +22 -0
- package/dist/types/adapters/bookmarklet.d.ts.map +1 -0
- package/dist/types/adapters/browser-inject.d.ts +7 -0
- package/dist/types/adapters/browser-inject.d.ts.map +1 -0
- package/dist/types/adapters/extension.d.ts +43 -0
- package/dist/types/adapters/extension.d.ts.map +1 -0
- package/dist/types/adapters/playwright-inject.d.ts +2 -0
- package/dist/types/adapters/playwright-inject.d.ts.map +1 -0
- package/dist/types/adapters/playwright.d.ts +14 -0
- package/dist/types/adapters/playwright.d.ts.map +1 -0
- package/dist/types/capture/index.d.ts +241 -0
- package/dist/types/capture/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/constants.d.ts +35 -0
- package/dist/types/protocol/constants.d.ts.map +1 -0
- package/dist/types/protocol/envelope.d.ts +41 -0
- package/dist/types/protocol/envelope.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +5 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +520 -0
- package/dist/types/protocol/messages.d.ts.map +1 -0
- package/dist/types/protocol/remote-control.d.ts +70 -0
- package/dist/types/protocol/remote-control.d.ts.map +1 -0
- package/dist/types/relay/backends/ws.d.ts +39 -0
- package/dist/types/relay/backends/ws.d.ts.map +1 -0
- package/dist/types/relay/index.d.ts +4 -0
- package/dist/types/relay/index.d.ts.map +1 -0
- package/dist/types/relay/limits.d.ts +54 -0
- package/dist/types/relay/limits.d.ts.map +1 -0
- package/dist/types/relay/relay.d.ts +73 -0
- package/dist/types/relay/relay.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts +62 -0
- package/dist/types/renderer/diff.d.ts.map +1 -0
- package/dist/types/renderer/index.d.ts +211 -0
- package/dist/types/renderer/index.d.ts.map +1 -0
- package/dist/types/renderer/overlays.d.ts +166 -0
- package/dist/types/renderer/overlays.d.ts.map +1 -0
- package/dist/types/renderer/sanitize.d.ts +73 -0
- package/dist/types/renderer/sanitize.d.ts.map +1 -0
- package/dist/types/renderer/snapshot.d.ts +41 -0
- package/dist/types/renderer/snapshot.d.ts.map +1 -0
- package/dist/types/transport/websocket.d.ts +44 -0
- package/dist/types/transport/websocket.d.ts.map +1 -0
- package/docs/ARCHITECTURE.md +273 -0
- package/docs/DESIGN-HISTORY.md +120 -0
- package/docs/QUICKSTARTS.md +289 -0
- package/docs/RELEASE.md +60 -0
- package/docs/SECURITY.md +156 -0
- package/docs/paper/OUTLINE.md +100 -0
- package/examples/bookmarklet-demo/demo.css +102 -0
- package/examples/bookmarklet-demo/server.js +297 -0
- package/examples/bookmarklet-demo/source.html +52 -0
- package/examples/bookmarklet-demo/viewer.html +48 -0
- package/examples/extension-mv3/demo.css +102 -0
- package/examples/extension-mv3/server.js +350 -0
- package/examples/extension-mv3/source.html +48 -0
- package/examples/extension-mv3/viewer.html +48 -0
- package/examples/loopback-mirror.html +369 -0
- package/examples/loopback-transport.js +65 -0
- package/examples/playwright-demo/demo.css +462 -0
- package/examples/playwright-demo/fixture.html +56 -0
- package/examples/playwright-demo/fixture.js +57 -0
- package/examples/playwright-demo/server.js +517 -0
- package/examples/playwright-demo/viewer.html +112 -0
- package/examples/playwright-demo/viewer.js +414 -0
- package/examples/serve.js +97 -0
- package/examples/two-tab-demo/demo.css +266 -0
- package/examples/two-tab-demo/server.js +233 -0
- package/examples/two-tab-demo/source.html +70 -0
- package/examples/two-tab-demo/source.js +213 -0
- package/examples/two-tab-demo/viewer.html +72 -0
- package/examples/two-tab-demo/viewer.js +121 -0
- package/package.json +107 -0
- package/src/adapters/bookmarklet.js +98 -0
- package/src/adapters/browser-inject.js +17 -0
- package/src/adapters/extension.js +322 -0
- package/src/adapters/playwright-inject.js +4401 -0
- package/src/adapters/playwright.js +540 -0
- package/src/capture/README.md +302 -0
- package/src/capture/index.js +4361 -0
- package/src/index.js +5 -0
- package/src/protocol/constants.js +49 -0
- package/src/protocol/envelope.js +75 -0
- package/src/protocol/index.js +4 -0
- package/src/protocol/messages.js +268 -0
- package/src/protocol/remote-control.js +300 -0
- package/src/relay/README.md +22 -0
- package/src/relay/backends/ws.js +186 -0
- package/src/relay/index.js +3 -0
- package/src/relay/limits.js +105 -0
- package/src/relay/relay.js +397 -0
- package/src/renderer/README.md +443 -0
- package/src/renderer/diff.js +389 -0
- package/src/renderer/index.js +1401 -0
- package/src/renderer/overlays.js +528 -0
- package/src/renderer/sanitize.js +366 -0
- package/src/renderer/snapshot.js +202 -0
- package/src/transport/websocket.js +553 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify a raw relay frame without transforming the application payload.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} raw
|
|
5
|
+
* @returns {{type: string, compressed: boolean, parseError: string|null}}
|
|
6
|
+
*/
|
|
7
|
+
export function classifyRelayFrame(raw: string): {
|
|
8
|
+
type: string;
|
|
9
|
+
compressed: boolean;
|
|
10
|
+
parseError: string | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Check whether a raw relay frame fits under the relay cap.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} raw
|
|
16
|
+
* @param {{roomId?: string, role?: string, capBytes?: number}} [options]
|
|
17
|
+
* @returns {{
|
|
18
|
+
* ok: true,
|
|
19
|
+
* byteSize: number,
|
|
20
|
+
* capBytes: number,
|
|
21
|
+
* type: string,
|
|
22
|
+
* compressed: boolean
|
|
23
|
+
* } | {
|
|
24
|
+
* ok: false,
|
|
25
|
+
* error: 'message-too-large',
|
|
26
|
+
* byteSize: number,
|
|
27
|
+
* capBytes: number,
|
|
28
|
+
* type: string,
|
|
29
|
+
* compressed: boolean,
|
|
30
|
+
* roomPrefix: string,
|
|
31
|
+
* role: string|undefined
|
|
32
|
+
* }}
|
|
33
|
+
*/
|
|
34
|
+
export function checkRelayFrameLimit(raw: string, options?: {
|
|
35
|
+
roomId?: string;
|
|
36
|
+
role?: string;
|
|
37
|
+
capBytes?: number;
|
|
38
|
+
}): {
|
|
39
|
+
ok: true;
|
|
40
|
+
byteSize: number;
|
|
41
|
+
capBytes: number;
|
|
42
|
+
type: string;
|
|
43
|
+
compressed: boolean;
|
|
44
|
+
} | {
|
|
45
|
+
ok: false;
|
|
46
|
+
error: "message-too-large";
|
|
47
|
+
byteSize: number;
|
|
48
|
+
capBytes: number;
|
|
49
|
+
type: string;
|
|
50
|
+
compressed: boolean;
|
|
51
|
+
roomPrefix: string;
|
|
52
|
+
role: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/relay/limits.js"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,wCAHW,MAAM,GACJ;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CAwBxE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,0CAnBW,MAAM,YACN;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,GACjD;IACR,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAA;CACpB,GAAG;IACF,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAC,SAAS,CAAA;CACvB,CA6BH"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} RelayClient
|
|
3
|
+
* @property {number} [readyState]
|
|
4
|
+
* @property {number} [bufferedAmount]
|
|
5
|
+
* @property {(raw: string) => void} send
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} RelayOptions
|
|
9
|
+
* @property {number} [capBytes]
|
|
10
|
+
* @property {number} [backpressureLimitBytes]
|
|
11
|
+
* @property {() => number} [now]
|
|
12
|
+
* @property {{warn?: Function, error?: Function}} [logger]
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Create a raw room relay.
|
|
16
|
+
*
|
|
17
|
+
* @param {RelayOptions} [options]
|
|
18
|
+
* @returns {{
|
|
19
|
+
* addClient: (entry: {roomId: string, role: 'source'|'viewer', socket: RelayClient}) => Object,
|
|
20
|
+
* removeClient: (entry: {roomId: string, role?: 'source'|'viewer', socket: RelayClient, event?: string, closeCode?: number, closeReason?: string}) => Object,
|
|
21
|
+
* receive: (entry: {roomId: string, role: 'source'|'viewer', socket?: RelayClient, raw: string}) => Object,
|
|
22
|
+
* getDiagnostics: (roomId?: string) => Object|null,
|
|
23
|
+
* getRoomSnapshot: () => {roomCount: number, rooms: Array<{roomId: string, sourceCount: number, viewerCount: number}>},
|
|
24
|
+
* clear: () => void
|
|
25
|
+
* }}
|
|
26
|
+
*/
|
|
27
|
+
export function createRelay(options?: RelayOptions): {
|
|
28
|
+
addClient: (entry: {
|
|
29
|
+
roomId: string;
|
|
30
|
+
role: "source" | "viewer";
|
|
31
|
+
socket: RelayClient;
|
|
32
|
+
}) => any;
|
|
33
|
+
removeClient: (entry: {
|
|
34
|
+
roomId: string;
|
|
35
|
+
role?: "source" | "viewer";
|
|
36
|
+
socket: RelayClient;
|
|
37
|
+
event?: string;
|
|
38
|
+
closeCode?: number;
|
|
39
|
+
closeReason?: string;
|
|
40
|
+
}) => any;
|
|
41
|
+
receive: (entry: {
|
|
42
|
+
roomId: string;
|
|
43
|
+
role: "source" | "viewer";
|
|
44
|
+
socket?: RelayClient;
|
|
45
|
+
raw: string;
|
|
46
|
+
}) => any;
|
|
47
|
+
getDiagnostics: (roomId?: string) => any | null;
|
|
48
|
+
getRoomSnapshot: () => {
|
|
49
|
+
roomCount: number;
|
|
50
|
+
rooms: Array<{
|
|
51
|
+
roomId: string;
|
|
52
|
+
sourceCount: number;
|
|
53
|
+
viewerCount: number;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
clear: () => void;
|
|
57
|
+
};
|
|
58
|
+
export const BACKPRESSURE_BUFFER_LIMIT_BYTES: number;
|
|
59
|
+
export type RelayClient = {
|
|
60
|
+
readyState?: number;
|
|
61
|
+
bufferedAmount?: number;
|
|
62
|
+
send: (raw: string) => void;
|
|
63
|
+
};
|
|
64
|
+
export type RelayOptions = {
|
|
65
|
+
capBytes?: number;
|
|
66
|
+
backpressureLimitBytes?: number;
|
|
67
|
+
now?: () => number;
|
|
68
|
+
logger?: {
|
|
69
|
+
warn?: Function;
|
|
70
|
+
error?: Function;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../../src/relay/relay.js"],"names":[],"mappings":"AAcA;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;GAYG;AACH,sCAVW,YAAY,GACV;IACR,SAAS,EAAE,CAAC,KAAK,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,GAAC,QAAQ,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAC,QAAW,CAAC;IAC7F,YAAY,EAAE,CAAC,KAAK,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,QAAQ,GAAC,QAAQ,CAAC;QAAC,MAAM,EAAE,WAAW,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAC,QAAW,CAAC;IAC3J,OAAO,EAAE,CAAC,KAAK,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,GAAC,QAAQ,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,QAAW,CAAC;IACzG,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,MAAO,IAAI,CAAC;IACjD,eAAe,EAAE,MAAM;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAC,CAAC,CAAA;KAAC,CAAC;IACrH,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB,CAiTH;AA7UD,qDAAgE;;iBAIlD,MAAM;qBACN,MAAM;UACN,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI;;;eAKrB,MAAM;6BACN,MAAM;UACN,MAAM,MAAM;aACZ;QAAC,IAAI,CAAC,WAAW;QAAC,KAAK,CAAC,WAAU;KAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} DiffCounters
|
|
3
|
+
* @property {number} staleMisses Nid lookups that found no element (stale ops)
|
|
4
|
+
* @property {number} applyFailures Ops (or whole batches) whose apply threw
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} DiffHooks
|
|
8
|
+
* @property {{warn: function(...*): void}} logger
|
|
9
|
+
* Diagnostics sink for misses and failures (console-shaped).
|
|
10
|
+
* @property {function(string, Object): void} requestResync
|
|
11
|
+
* Resync escalation callback. Fired at the parity thresholds; latching
|
|
12
|
+
* and the CONTROL.START send live in createViewer, not here.
|
|
13
|
+
* @property {import('./sanitize.js').SanitizeCounters} [sanitizeCounters]
|
|
14
|
+
* OPTIONAL caller-owned sanitization strip counters (plan 03-02).
|
|
15
|
+
* Defaults to a local throwaway object so the public 4-arg signature is
|
|
16
|
+
* unchanged; createViewer injects its per-session object (Pitfall 3).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Apply a batch of capture diff ops against an injected Document.
|
|
20
|
+
* Behavioral port of dashboard.js:3209-3356: each op addresses its target
|
|
21
|
+
* by the injected identity resolver; a lookup miss is counted and warned, never thrown; a
|
|
22
|
+
* throwing op is contained per-op so the rest of the batch still applies;
|
|
23
|
+
* a failure of the batch machinery itself is caught once and escalated
|
|
24
|
+
* immediately. Missing or empty batches return without side effects.
|
|
25
|
+
*
|
|
26
|
+
* @param {Document} doc Target mirror Document (any Document works)
|
|
27
|
+
* @param {Array<Object>} mutations Diff ops ({op, nid|parentNid, ...})
|
|
28
|
+
* @param {DiffCounters} counters Mutated in place; caller resets per snapshot
|
|
29
|
+
* @param {DiffHooks} hooks Injected logger + resync callback
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
32
|
+
export function applyMutations(doc: Document, mutations: Array<any>, counters: DiffCounters, hooks: DiffHooks): void;
|
|
33
|
+
export type DiffCounters = {
|
|
34
|
+
/**
|
|
35
|
+
* Nid lookups that found no element (stale ops)
|
|
36
|
+
*/
|
|
37
|
+
staleMisses: number;
|
|
38
|
+
/**
|
|
39
|
+
* Ops (or whole batches) whose apply threw
|
|
40
|
+
*/
|
|
41
|
+
applyFailures: number;
|
|
42
|
+
};
|
|
43
|
+
export type DiffHooks = {
|
|
44
|
+
/**
|
|
45
|
+
* Diagnostics sink for misses and failures (console-shaped).
|
|
46
|
+
*/
|
|
47
|
+
logger: {
|
|
48
|
+
warn: (...args: any[]) => void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Resync escalation callback. Fired at the parity thresholds; latching
|
|
52
|
+
* and the CONTROL.START send live in createViewer, not here.
|
|
53
|
+
*/
|
|
54
|
+
requestResync: (arg0: string, arg1: any) => void;
|
|
55
|
+
/**
|
|
56
|
+
* OPTIONAL caller-owned sanitization strip counters (plan 03-02).
|
|
57
|
+
* Defaults to a local throwaway object so the public 4-arg signature is
|
|
58
|
+
* unchanged; createViewer injects its per-session object (Pitfall 3).
|
|
59
|
+
*/
|
|
60
|
+
sanitizeCounters?: import("./sanitize.js").SanitizeCounters;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/renderer/diff.js"],"names":[],"mappings":"AAiEA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;GAaG;AACH,oCANW,QAAQ,aACR,KAAK,KAAQ,YACb,YAAY,SACZ,SAAS,GACP,IAAI,CAoShB;;;;;iBAjUa,MAAM;;;;mBACN,MAAM;;;;;;YAKN;QAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;KAAC;;;;;mBAE5B,CAAS,IAAM,EAAN,MAAM,EAAE,IAAM,UAAG,IAAI;;;;;;uBAG9B,OAAO,eAAe,EAAE,gBAAgB"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host-injected viewer transport. Mirrors the capture Transport's
|
|
3
|
+
* fire-and-forget send contract and adds the receive side; Phase 4's
|
|
4
|
+
* WebSocket transport implements this same interface by encoding/decoding
|
|
5
|
+
* envelopes, so the viewer never changes.
|
|
6
|
+
*
|
|
7
|
+
* @typedef {Object} ViewerTransport
|
|
8
|
+
* @property {(type: string, payload: Object) => void} send
|
|
9
|
+
* Viewer -> capture host (CONTROL.* messages). Fire-and-forget; errors
|
|
10
|
+
* are contained to the injected logger, never thrown into the viewer.
|
|
11
|
+
* @property {(handler: (type: string, payload: Object) => void) => (() => void)} onMessage
|
|
12
|
+
* Subscribe to capture-host -> viewer (STREAM.*) messages. Returns an
|
|
13
|
+
* unsubscribe function; detach() invokes it.
|
|
14
|
+
* @property {(handler: (status: Object) => void) => (() => void)} [onStatus]
|
|
15
|
+
* Optional Phase 4 status subscription implemented by WebSocket transports.
|
|
16
|
+
* Status objects are telemetry only; mirrored payloads never flow here.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} ViewerLogger
|
|
20
|
+
* @property {(...args: *) => void} info
|
|
21
|
+
* @property {(...args: *) => void} warn
|
|
22
|
+
* @property {(...args: *) => void} error
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {Object} ViewerOptions
|
|
26
|
+
* @property {Element} container
|
|
27
|
+
* Required. Host element the viewer root is appended into (auto-attach,
|
|
28
|
+
* D-01). Factory throws Error('viewer-container-required') otherwise.
|
|
29
|
+
* @property {ViewerTransport} transport
|
|
30
|
+
* Required. Factory throws Error('viewer-transport-required') when send
|
|
31
|
+
* or onMessage is not a function.
|
|
32
|
+
* @property {ViewerLogger} [logger]
|
|
33
|
+
* Optional. Defaults to a console-backed logger.
|
|
34
|
+
* @property {number} [disconnectDelayMs]
|
|
35
|
+
* Optional stale-to-disconnected delay for closed transports. Defaults to a
|
|
36
|
+
* short demo-friendly window; tests may set a smaller value.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {Object} ViewerHandle
|
|
40
|
+
* @property {() => void} detach
|
|
41
|
+
* Unsubscribe from the transport, remove the resize listeners, and remove
|
|
42
|
+
* the viewer root from the container. Idempotent.
|
|
43
|
+
* @property {() => void} destroy
|
|
44
|
+
* detach() plus state/overlay reset. Idempotent.
|
|
45
|
+
* @property {() => {scale: Object, viewport: Object, container: Object}} getViewportMapping
|
|
46
|
+
* Return cloned scale, viewport, and container geometry for host-owned
|
|
47
|
+
* input overlays.
|
|
48
|
+
* @property {(nid: string|number) => ({nid: string, exists: boolean, rect: Object, streamSessionId: string, snapshotId: number}|null)} resolveNode
|
|
49
|
+
* Resolve an opaque PhantomStream nid to host-document geometry and stream
|
|
50
|
+
* identity. Missing or stale nids return null.
|
|
51
|
+
* @property {(nid: string|number, options?: {label?: string}) => boolean} highlightNode
|
|
52
|
+
* Show or update a local host-document highlight for a resolved nid.
|
|
53
|
+
* Returns false for stale or missing nids.
|
|
54
|
+
* @property {() => void} clearHighlight
|
|
55
|
+
* Hide the local node highlight. Idempotent.
|
|
56
|
+
* @property {(nid: string|number, options?: {reason?: string}) => string|null} requestSubtree
|
|
57
|
+
* Request a bounded fresh subtree for an indexed truncated marker. Returns
|
|
58
|
+
* the generated requestId, or null when the nid is invalid, missing, or
|
|
59
|
+
* already in flight.
|
|
60
|
+
* @property {(kind: string, renderFn: (payload: *, anchorRect: ?Object, layer: Element) => void) => void} registerOverlay
|
|
61
|
+
* Register a custom overlay kind (delegates to the overlays registry --
|
|
62
|
+
* the host-facing extension seam from D-10).
|
|
63
|
+
* @property {(eventName: 'state'|'health', handler: (event: Object) => void) => (() => void)} on
|
|
64
|
+
* Subscribe to host-facing lifecycle and health events. Returns unsubscribe.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Scale-to-fit math (pure). Port of dashboard.js:2859-2868 simplified to
|
|
68
|
+
* the single fill-container mode per 02-UI-SPEC "Scale-to-fit": page
|
|
69
|
+
* dimensions default to 1920x1080 and floor at 1; the scale factor is the
|
|
70
|
+
* min of the two container/page ratios with a !isFinite/<=0 clamp to 1;
|
|
71
|
+
* letterbox offsets center the scaled page and floor at 0.
|
|
72
|
+
*
|
|
73
|
+
* @param {number} pageW Captured page width (0/undefined -> 1920)
|
|
74
|
+
* @param {number} pageH Captured page height (0/undefined -> 1080)
|
|
75
|
+
* @param {number} containerW Host container width in px
|
|
76
|
+
* @param {number} containerH Host container height in px
|
|
77
|
+
* @returns {{s: number, offsetX: number, offsetY: number, pageW: number, pageH: number}}
|
|
78
|
+
*/
|
|
79
|
+
export function computeScale(pageW: number, pageH: number, containerW: number, containerH: number): {
|
|
80
|
+
s: number;
|
|
81
|
+
offsetX: number;
|
|
82
|
+
offsetY: number;
|
|
83
|
+
pageW: number;
|
|
84
|
+
pageH: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Create an embeddable viewer bound to a host container: sandboxed mirror
|
|
88
|
+
* iframe, host-document overlay layer, transport message dispatch, scale-
|
|
89
|
+
* to-fit, scroll mirroring, and the latched CONTROL.START resync path.
|
|
90
|
+
* Auto-attaches on creation (D-01): calling this yields a live mirror as
|
|
91
|
+
* soon as the first snapshot arrives.
|
|
92
|
+
*
|
|
93
|
+
* Factory-time validation is the ONLY place this module throws (capture
|
|
94
|
+
* precedent); after creation every error routes to the injected logger.
|
|
95
|
+
*
|
|
96
|
+
* @param {ViewerOptions} options
|
|
97
|
+
* @returns {ViewerHandle}
|
|
98
|
+
*/
|
|
99
|
+
export function createViewer(options: ViewerOptions): ViewerHandle;
|
|
100
|
+
export { applyMutations } from "./diff.js";
|
|
101
|
+
/**
|
|
102
|
+
* The host-injected viewer transport. Mirrors the capture Transport's
|
|
103
|
+
* fire-and-forget send contract and adds the receive side; Phase 4's
|
|
104
|
+
* WebSocket transport implements this same interface by encoding/decoding
|
|
105
|
+
* envelopes, so the viewer never changes.
|
|
106
|
+
*/
|
|
107
|
+
export type ViewerTransport = {
|
|
108
|
+
/**
|
|
109
|
+
* Viewer -> capture host (CONTROL.* messages). Fire-and-forget; errors
|
|
110
|
+
* are contained to the injected logger, never thrown into the viewer.
|
|
111
|
+
*/
|
|
112
|
+
send: (type: string, payload: any) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe to capture-host -> viewer (STREAM.*) messages. Returns an
|
|
115
|
+
* unsubscribe function; detach() invokes it.
|
|
116
|
+
*/
|
|
117
|
+
onMessage: (handler: (type: string, payload: any) => void) => (() => void);
|
|
118
|
+
/**
|
|
119
|
+
* Optional Phase 4 status subscription implemented by WebSocket transports.
|
|
120
|
+
* Status objects are telemetry only; mirrored payloads never flow here.
|
|
121
|
+
*/
|
|
122
|
+
onStatus?: (handler: (status: any) => void) => (() => void);
|
|
123
|
+
};
|
|
124
|
+
export type ViewerLogger = {
|
|
125
|
+
info: (...args: any) => void;
|
|
126
|
+
warn: (...args: any) => void;
|
|
127
|
+
error: (...args: any) => void;
|
|
128
|
+
};
|
|
129
|
+
export type ViewerOptions = {
|
|
130
|
+
/**
|
|
131
|
+
* Required. Host element the viewer root is appended into (auto-attach,
|
|
132
|
+
* D-01). Factory throws Error('viewer-container-required') otherwise.
|
|
133
|
+
*/
|
|
134
|
+
container: Element;
|
|
135
|
+
/**
|
|
136
|
+
* Required. Factory throws Error('viewer-transport-required') when send
|
|
137
|
+
* or onMessage is not a function.
|
|
138
|
+
*/
|
|
139
|
+
transport: ViewerTransport;
|
|
140
|
+
/**
|
|
141
|
+
* Optional. Defaults to a console-backed logger.
|
|
142
|
+
*/
|
|
143
|
+
logger?: ViewerLogger;
|
|
144
|
+
/**
|
|
145
|
+
* Optional stale-to-disconnected delay for closed transports. Defaults to a
|
|
146
|
+
* short demo-friendly window; tests may set a smaller value.
|
|
147
|
+
*/
|
|
148
|
+
disconnectDelayMs?: number;
|
|
149
|
+
};
|
|
150
|
+
export type ViewerHandle = {
|
|
151
|
+
/**
|
|
152
|
+
* Unsubscribe from the transport, remove the resize listeners, and remove
|
|
153
|
+
* the viewer root from the container. Idempotent.
|
|
154
|
+
*/
|
|
155
|
+
detach: () => void;
|
|
156
|
+
/**
|
|
157
|
+
* detach() plus state/overlay reset. Idempotent.
|
|
158
|
+
*/
|
|
159
|
+
destroy: () => void;
|
|
160
|
+
/**
|
|
161
|
+
* Return cloned scale, viewport, and container geometry for host-owned
|
|
162
|
+
* input overlays.
|
|
163
|
+
*/
|
|
164
|
+
getViewportMapping: () => {
|
|
165
|
+
scale: any;
|
|
166
|
+
viewport: any;
|
|
167
|
+
container: any;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Resolve an opaque PhantomStream nid to host-document geometry and stream
|
|
171
|
+
* identity. Missing or stale nids return null.
|
|
172
|
+
*/
|
|
173
|
+
resolveNode: (nid: string | number) => ({
|
|
174
|
+
nid: string;
|
|
175
|
+
exists: boolean;
|
|
176
|
+
rect: any;
|
|
177
|
+
streamSessionId: string;
|
|
178
|
+
snapshotId: number;
|
|
179
|
+
} | null);
|
|
180
|
+
/**
|
|
181
|
+
* Show or update a local host-document highlight for a resolved nid.
|
|
182
|
+
* Returns false for stale or missing nids.
|
|
183
|
+
*/
|
|
184
|
+
highlightNode: (nid: string | number, options?: {
|
|
185
|
+
label?: string;
|
|
186
|
+
}) => boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Hide the local node highlight. Idempotent.
|
|
189
|
+
*/
|
|
190
|
+
clearHighlight: () => void;
|
|
191
|
+
/**
|
|
192
|
+
* Request a bounded fresh subtree for an indexed truncated marker. Returns
|
|
193
|
+
* the generated requestId, or null when the nid is invalid, missing, or
|
|
194
|
+
* already in flight.
|
|
195
|
+
*/
|
|
196
|
+
requestSubtree: (nid: string | number, options?: {
|
|
197
|
+
reason?: string;
|
|
198
|
+
}) => string | null;
|
|
199
|
+
/**
|
|
200
|
+
* Register a custom overlay kind (delegates to the overlays registry --
|
|
201
|
+
* the host-facing extension seam from D-10).
|
|
202
|
+
*/
|
|
203
|
+
registerOverlay: (kind: string, renderFn: (payload: any, anchorRect: any | null, layer: Element) => void) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Subscribe to host-facing lifecycle and health events. Returns unsubscribe.
|
|
206
|
+
*/
|
|
207
|
+
on: (eventName: "state" | "health", handler: (event: any) => void) => (() => void);
|
|
208
|
+
};
|
|
209
|
+
export { escapeAttribute, buildShellAttributeString, buildSnapshotHtml, buildFramePlaceholderHtml } from "./snapshot.js";
|
|
210
|
+
export { createOverlays, mapRectToHost, mapHostPointToViewport, OVERLAY_CSS } from "./overlays.js";
|
|
211
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/index.js"],"names":[],"mappings":"AA0CA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;;;GAYG;AACH,oCANW,MAAM,SACN,MAAM,cACN,MAAM,cACN,MAAM,GACJ;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAcvF;AAED;;;;;;;;;;;;GAYG;AACH,sCAHW,aAAa,GACX,YAAY,CA6tCxB;;;;;;;;;;;;;UAj0Ca,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI;;;;;eAGvC,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;;;eAGlE,CAAC,OAAO,EAAE,CAAC,MAAM,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;;;UAOnD,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;UACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;WACpB,CAAC,GAAG,IAAI,EAAE,GAAC,KAAK,IAAI;;;;;;;eAKpB,OAAO;;;;;eAGP,eAAe;;;;aAGf,YAAY;;;;;wBAEZ,MAAM;;;;;;;YAON,MAAM,IAAI;;;;aAGV,MAAM,IAAI;;;;;wBAEV,MAAM;QAAC,KAAK,MAAS;QAAC,QAAQ,MAAS;QAAC,SAAS,MAAQ;KAAC;;;;;iBAG1D,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,MAAS;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAC,IAAI,CAAC;;;;;mBAGxH,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,OAAO;;;;oBAG3D,MAAM,IAAI;;;;;;oBAEV,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,MAAM,GAAC,IAAI;;;;;qBAIhE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;QAG3F,CAAC,SAAS,EAAE,OAAO,GAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map a rect from capture-page viewport coordinates into host-document
|
|
3
|
+
* pixel coordinates over the scaled, letterboxed iframe. Pure parity math
|
|
4
|
+
* (reference dashboard.js:3381-3384):
|
|
5
|
+
*
|
|
6
|
+
* top = offsetY + y * s
|
|
7
|
+
* left = offsetX + x * s
|
|
8
|
+
* width = w * s
|
|
9
|
+
* height = h * s
|
|
10
|
+
*
|
|
11
|
+
* @param {{x: number, y: number, w: number, h: number}} rect
|
|
12
|
+
* Rect in capture-page viewport coordinates.
|
|
13
|
+
* @param {{s: number, offsetX: number, offsetY: number}} scale
|
|
14
|
+
* Scale state from the viewer's scale-to-fit (s = scale factor,
|
|
15
|
+
* offsetX/offsetY = letterbox offsets in host px).
|
|
16
|
+
* @returns {{top: number, left: number, width: number, height: number}}
|
|
17
|
+
* Host-document pixel numbers (callers append 'px').
|
|
18
|
+
*/
|
|
19
|
+
export function mapRectToHost(rect: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
w: number;
|
|
23
|
+
h: number;
|
|
24
|
+
}, scale: {
|
|
25
|
+
s: number;
|
|
26
|
+
offsetX: number;
|
|
27
|
+
offsetY: number;
|
|
28
|
+
}): {
|
|
29
|
+
top: number;
|
|
30
|
+
left: number;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Map a host-document point over the scaled mirror back into captured-page
|
|
36
|
+
* viewport CSS pixels. Letterbox/out-of-bounds points are classified before
|
|
37
|
+
* rounding and clamping so hosts can reject non-dispatchable input.
|
|
38
|
+
*
|
|
39
|
+
* @param {{x: number, y: number}} point
|
|
40
|
+
* Host-stage point relative to the viewer root.
|
|
41
|
+
* @param {{s?: number, offsetX?: number, offsetY?: number, pageW?: number, pageH?: number}} scale
|
|
42
|
+
* Scale state from the viewer. Missing page dimensions are treated as 0.
|
|
43
|
+
* @returns {{inside: boolean, x: number|null, y: number|null}}
|
|
44
|
+
* Dispatchable viewport coordinates, or null coordinates when outside.
|
|
45
|
+
*/
|
|
46
|
+
export function mapHostPointToViewport(point: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}, scale: {
|
|
50
|
+
s?: number;
|
|
51
|
+
offsetX?: number;
|
|
52
|
+
offsetY?: number;
|
|
53
|
+
pageW?: number;
|
|
54
|
+
pageH?: number;
|
|
55
|
+
}): {
|
|
56
|
+
inside: boolean;
|
|
57
|
+
x: number | null;
|
|
58
|
+
y: number | null;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Per-message context handed to handleOverlayMessage by the viewer.
|
|
62
|
+
* @typedef {Object} OverlayContext
|
|
63
|
+
* @property {{s: number, offsetX: number, offsetY: number}} scale
|
|
64
|
+
* Current scale-to-fit state for coordinate mapping.
|
|
65
|
+
* @property {(nid: number|string) => ({top: number, left: number, width: number, height: number}|null)} resolveNidRect
|
|
66
|
+
* Resolve a captured node id to a host-document rect (the viewer reads
|
|
67
|
+
* the mirrored element's bounding rect and maps it). Returns null when
|
|
68
|
+
* the nid no longer resolves (stale anchor).
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Overlay system handle returned by createOverlays.
|
|
72
|
+
* @typedef {Object} OverlaysHandle
|
|
73
|
+
* @property {Element} layer
|
|
74
|
+
* The overlay layer element. The caller (createViewer) appends it into
|
|
75
|
+
* the viewer root as a sibling ABOVE the iframe; this module never
|
|
76
|
+
* touches the host DOM outside this subtree.
|
|
77
|
+
* @property {(kind: string, renderFn: (payload: *, anchorRect: ?Object, layer: Element) => void) => void} register
|
|
78
|
+
* Register a renderer for an overlay kind (registry write; overwrites
|
|
79
|
+
* silently). See register() JSDoc for the renderFn contract.
|
|
80
|
+
* @property {(payload: Object, ctx: OverlayContext) => void} handleOverlayMessage
|
|
81
|
+
* Dispatch one STREAM.OVERLAY payload through the registry.
|
|
82
|
+
* @property {(payload: Object) => void} handleDialogMessage
|
|
83
|
+
* STREAM.DIALOG handler (dialog card show/hide).
|
|
84
|
+
* @property {() => void} resetOverlays
|
|
85
|
+
* Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Create the overlay system: layer element, kind registry, and the three
|
|
89
|
+
* pre-registered parity built-ins (glow, progress, dialog card).
|
|
90
|
+
*
|
|
91
|
+
* @param {{document: Document, logger?: {info: Function, warn: Function, error: Function}}} opts
|
|
92
|
+
* document is required (factory-time validation is the one place this
|
|
93
|
+
* module may throw, matching the capture factory precedent D-07);
|
|
94
|
+
* logger defaults to a console-backed logger.
|
|
95
|
+
* @returns {OverlaysHandle}
|
|
96
|
+
*/
|
|
97
|
+
export function createOverlays(opts: {
|
|
98
|
+
document: Document;
|
|
99
|
+
logger?: {
|
|
100
|
+
info: Function;
|
|
101
|
+
warn: Function;
|
|
102
|
+
error: Function;
|
|
103
|
+
};
|
|
104
|
+
}): OverlaysHandle;
|
|
105
|
+
/**
|
|
106
|
+
* Single injected-CSS string for the overlay built-ins. The host (or
|
|
107
|
+
* createViewer, plan 02-03) appends this as one <style> element -- no
|
|
108
|
+
* external stylesheet, per the zero-dependency constraint. Every value is
|
|
109
|
+
* the parity contract from 02-UI-SPEC.md (exact reference CSS for the
|
|
110
|
+
* dialog card; documented reconstructions for the glow rect and progress
|
|
111
|
+
* pill where the FSB stylesheet is not vendored).
|
|
112
|
+
*/
|
|
113
|
+
export const OVERLAY_CSS: string;
|
|
114
|
+
/**
|
|
115
|
+
* Per-message context handed to handleOverlayMessage by the viewer.
|
|
116
|
+
*/
|
|
117
|
+
export type OverlayContext = {
|
|
118
|
+
/**
|
|
119
|
+
* Current scale-to-fit state for coordinate mapping.
|
|
120
|
+
*/
|
|
121
|
+
scale: {
|
|
122
|
+
s: number;
|
|
123
|
+
offsetX: number;
|
|
124
|
+
offsetY: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Resolve a captured node id to a host-document rect (the viewer reads
|
|
128
|
+
* the mirrored element's bounding rect and maps it). Returns null when
|
|
129
|
+
* the nid no longer resolves (stale anchor).
|
|
130
|
+
*/
|
|
131
|
+
resolveNidRect: (nid: number | string) => ({
|
|
132
|
+
top: number;
|
|
133
|
+
left: number;
|
|
134
|
+
width: number;
|
|
135
|
+
height: number;
|
|
136
|
+
} | null);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Overlay system handle returned by createOverlays.
|
|
140
|
+
*/
|
|
141
|
+
export type OverlaysHandle = {
|
|
142
|
+
/**
|
|
143
|
+
* The overlay layer element. The caller (createViewer) appends it into
|
|
144
|
+
* the viewer root as a sibling ABOVE the iframe; this module never
|
|
145
|
+
* touches the host DOM outside this subtree.
|
|
146
|
+
*/
|
|
147
|
+
layer: Element;
|
|
148
|
+
/**
|
|
149
|
+
* Register a renderer for an overlay kind (registry write; overwrites
|
|
150
|
+
* silently). See register() JSDoc for the renderFn contract.
|
|
151
|
+
*/
|
|
152
|
+
register: (kind: string, renderFn: (payload: any, anchorRect: any | null, layer: Element) => void) => void;
|
|
153
|
+
/**
|
|
154
|
+
* Dispatch one STREAM.OVERLAY payload through the registry.
|
|
155
|
+
*/
|
|
156
|
+
handleOverlayMessage: (payload: any, ctx: OverlayContext) => void;
|
|
157
|
+
/**
|
|
158
|
+
* STREAM.DIALOG handler (dialog card show/hide).
|
|
159
|
+
*/
|
|
160
|
+
handleDialogMessage: (payload: any) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
|
|
163
|
+
*/
|
|
164
|
+
resetOverlays: () => void;
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=overlays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlays.d.ts","sourceRoot":"","sources":["../../../src/renderer/overlays.js"],"names":[],"mappings":"AA6JA;;;;;;;;;;;;;;;;;GAiBG;AACH,oCARW;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,SAE5C;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GAG3C;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAUtE;AAED;;;;;;;;;;;GAWG;AACH,8CAPW;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,SAEtB;IAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,GAE9E;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;IAAC,CAAC,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CA+B7D;AAED;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;GASG;AACH,qCANW;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE;QAAC,IAAI,WAAW;QAAC,IAAI,WAAW;QAAC,KAAK,WAAU;KAAC,CAAA;CAAC,GAI9E,cAAc,CAwQ1B;AA/eD;;;;;;;GAOG;AACH,iCA6Fa;;;;;;;;WAgGC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC;;;;;;oBAE7C,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAC,IAAI,CAAC;;;;;;;;;;;WASzF,OAAO;;;;;cAIP,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;0BAG3F,CAAC,OAAO,KAAQ,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;;;;yBAE9C,CAAC,OAAO,KAAQ,KAAK,IAAI;;;;mBAEzB,MAAM,IAAI"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Targeted CSS value scrub -- the only string-operation pass in the render
|
|
3
|
+
* pipeline, and it is a VALUE scrub (regex), never a parser. Same policy
|
|
4
|
+
* as the capture-side scrub (03-RESEARCH.md A4, src/capture/index.js):
|
|
5
|
+
* - url() with an explicit non-http(s)/non-data:image scheme has its
|
|
6
|
+
* contents replaced with about:blank; scheme-less (relative) url()
|
|
7
|
+
* values pass unchanged
|
|
8
|
+
* - expression() and -moz-binding (legacy script-execution vectors) are
|
|
9
|
+
* neutralized
|
|
10
|
+
* - non-http(s) CSS import targets are neutralized (string and url() forms)
|
|
11
|
+
* - a literal </style sequence is rewritten so captured CSS can never
|
|
12
|
+
* break out of the style tag it is emitted into at the string-assembly
|
|
13
|
+
* layer (src/renderer/snapshot.js)
|
|
14
|
+
* Containment: a scrub failure returns the input unchanged (absolutifyUrl
|
|
15
|
+
* discipline) -- the sandbox + CSP layers backstop CSS regardless.
|
|
16
|
+
* @param {*} css
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
export function scrubCssText(css: any): string;
|
|
20
|
+
/**
|
|
21
|
+
* Attr-op-shaped scrub dispatch for the diff applier's ATTR branch
|
|
22
|
+
* (defense-in-depth render side of 03-RESEARCH Pitfall 5): the caller
|
|
23
|
+
* applies the returned value via setAttribute, or skips the op entirely
|
|
24
|
+
* when drop is true. Pure value transform -- no counters, no DOM; the
|
|
25
|
+
* caller owns counting (its counters, its lifecycle).
|
|
26
|
+
* @param {*} name Attribute name from the wire (untrusted)
|
|
27
|
+
* @param {*} value Attribute value from the wire (untrusted)
|
|
28
|
+
* @returns {{drop: boolean, value: string|null}}
|
|
29
|
+
*/
|
|
30
|
+
export function sanitizeAttrValue(name: any, value: any): {
|
|
31
|
+
drop: boolean;
|
|
32
|
+
value: string | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The render-side chokepoint: walk root (DocumentFragment | Element) plus
|
|
36
|
+
* every descendant element and scrub in place per the module-top policy.
|
|
37
|
+
* Collect-then-mutate (the capture serializer's TreeWalker precedent,
|
|
38
|
+
* src/capture/index.js:596-615): the walker is live, so every element is
|
|
39
|
+
* gathered into an array BEFORE any removal. Elements detached by an
|
|
40
|
+
* earlier subtree drop are skipped (never double-counted). Mutates in
|
|
41
|
+
* place -- never serializes.
|
|
42
|
+
*
|
|
43
|
+
* Containment: never throws. A failed walk warns and returns; a single
|
|
44
|
+
* hostile element's scrub failure warns and the walk continues.
|
|
45
|
+
*
|
|
46
|
+
* @param {DocumentFragment|Element|null} root
|
|
47
|
+
* @param {SanitizeCounters} [counters] Mutated in place; caller-owned
|
|
48
|
+
* lifecycle (per-session in createViewer -- 03-RESEARCH Pitfall 3)
|
|
49
|
+
* @param {{warn: function(...*): void}} [logger]
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
export function sanitizeFragment(root: DocumentFragment | Element | null, counters?: SanitizeCounters, logger?: {
|
|
53
|
+
warn: (...args: any[]) => void;
|
|
54
|
+
}): void;
|
|
55
|
+
export type SanitizeCounters = {
|
|
56
|
+
/**
|
|
57
|
+
* on* attributes + srcdoc attributes removed
|
|
58
|
+
*/
|
|
59
|
+
strippedHandlers: number;
|
|
60
|
+
/**
|
|
61
|
+
* dangerous URL scheme values neutralized
|
|
62
|
+
*/
|
|
63
|
+
blockedUrls: number;
|
|
64
|
+
/**
|
|
65
|
+
* script/noscript/object/embed subtrees removed
|
|
66
|
+
*/
|
|
67
|
+
droppedSubtrees: number;
|
|
68
|
+
/**
|
|
69
|
+
* style values changed by scrubCssText
|
|
70
|
+
*/
|
|
71
|
+
cssScrubs: number;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/renderer/sanitize.js"],"names":[],"mappings":"AAmJA;;;;;;;;;;;;;;;;;GAiBG;AACH,kCAHW,GAAC,GACC,MAAM,CA4BlB;AAED;;;;;;;;;GASG;AACH,wCAJW,GAAC,SACD,GAAC,GACC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CAyB/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,uCANW,gBAAgB,GAAC,OAAO,GAAC,IAAI,aAC7B,gBAAgB,WAEhB;IAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;CAAC,GAC1B,IAAI,CAyHhB;;;;;sBA9Ta,MAAM;;;;iBACN,MAAM;;;;qBACN,MAAM;;;;eACN,MAAM"}
|