@puth/core 0.0.3 → 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/dist/index.d.cts CHANGED
@@ -1,3 +1,162 @@
1
+ /**
2
+ * The DOM recording format. A recorder in each page sends one keyframe per document, then batches of changes,
3
+ * which the GUI applies to rebuild the document at any point.
4
+ *
5
+ * Applying batch n to the state after batch n - 1 gives the document as it was when batch n was flushed. Batches
6
+ * carry current values, not the history of a change, so they never depend on how the page got there.
7
+ *
8
+ * For size, nodes are flat token lists and strings come from a table per document. A keyframe starts the table,
9
+ * every packet appends the strings it added (DomPacket.strings), in order.
10
+ */
11
+ /** The index of a string in the document's table, or the string itself. */
12
+ type DomString = number | string;
13
+ /**
14
+ * Nodes as flat tokens, in pre-order. Every node has an id that stays the same for as long as the node exists.
15
+ *
16
+ * element: id, 1, tag, namespace, attribute count, (name, value)..., props, child count, children...
17
+ * text and comment: id, 3 or 8, data
18
+ * doctype: id, 10, name, public id, system id
19
+ *
20
+ * An element's open shadow root is in its props: the root's id, then its children as a node list.
21
+ *
22
+ * A node list starts with the number of nodes in it. In the children of a CHILDREN change, a node the replay has
23
+ * already is its negative id.
24
+ */
25
+ type DomTokens = (number | string | DomProps | 0)[];
26
+ declare enum DomNodeType {
27
+ ELEMENT = 1,
28
+ TEXT = 3,
29
+ COMMENT = 8,
30
+ DOCTYPE = 10
31
+ }
32
+ declare enum DomNamespace {
33
+ HTML = 0,
34
+ SVG = 1,
35
+ MATHML = 2
36
+ }
37
+ /** State of form controls and stylesheets that their attributes and children don't show. */
38
+ type DomProps = {
39
+ value?: string;
40
+ checked?: boolean;
41
+ selectedIndex?: number;
42
+ /** The selected options of a select that allows several. */
43
+ selected?: number[];
44
+ /** Rules a script added to a <style> element through the CSSOM, like CSS-in-JS libraries do. */
45
+ css?: string;
46
+ /** The element's open shadow root: its id, then its children as a node list. */
47
+ shadow?: DomTokens;
48
+ /** Whether the element is in the top layer, if it is. */
49
+ top?: DomTopLayer;
50
+ };
51
+ declare enum DomTopLayer {
52
+ NONE = 0,
53
+ /** A dialog opened with showModal(). */
54
+ MODAL = 1,
55
+ /** A popover that is open. */
56
+ POPOVER = 2
57
+ }
58
+ type DomViewport = [width: number, height: number, devicePixelRatio: number];
59
+ /** Scroll position of an element, or of the window for id 0. */
60
+ type DomScroll = [id: number, x: number, y: number];
61
+ declare enum DomOp {
62
+ /** The complete current children of a node: ids of nodes it had before, serialized nodes for new ones. */
63
+ CHILDREN = 1,
64
+ /** The complete current attributes of an element. */
65
+ ATTRIBUTES = 2,
66
+ TEXT = 3,
67
+ CONTROL = 4,
68
+ CSS = 6,
69
+ SCROLL = 7,
70
+ VIEWPORT = 8,
71
+ /** A shadow root attached to an element recorded before: the root's id, then its children as a node list. */
72
+ SHADOW = 9,
73
+ /** The rules of an adopted stylesheet, the first time it is adopted and whenever they change. */
74
+ SHEET = 10,
75
+ /** The complete current adopted stylesheets of the document or of a shadow root, by sheet id. */
76
+ ADOPT = 11,
77
+ TOP_LAYER = 12
78
+ }
79
+ type DomChange = [op: DomOp.CHILDREN, parent: number, children: DomTokens] | [op: DomOp.ATTRIBUTES, element: number, attributes: DomString[]] | [op: DomOp.TEXT, node: number, data: DomString] | [op: DomOp.CONTROL, element: number, value: string | null, checked: boolean | null, selectedIndex: number | null, selected?: number[] | null] | [op: DomOp.CSS, element: number, css: string] | [op: DomOp.SCROLL, ...DomScroll] | [op: DomOp.VIEWPORT, ...DomViewport] | [op: DomOp.SHADOW, host: number, root: DomTokens] | [op: DomOp.SHEET, sheet: number, css: string] | [op: DomOp.ADOPT, root: number, sheets: number[]] | [op: DomOp.TOP_LAYER, element: number, state: DomTopLayer];
80
+ type DomKeyframe = {
81
+ url: string;
82
+ /** The base URL relative URLs resolve against, which a <base> element can change. */
83
+ base: string;
84
+ /** Id of the document node, the parent of the root children. */
85
+ document: number;
86
+ /** The document's children, as a node list. */
87
+ root: DomTokens;
88
+ viewport: DomViewport;
89
+ scroll: DomScroll[];
90
+ /** The adopted stylesheets, as sheet id and rules. */
91
+ sheets?: [sheet: number, css: string][];
92
+ /** The document and shadow roots that adopted stylesheets, with their sheet ids. */
93
+ adopted?: [root: number, sheets: number[]][];
94
+ };
95
+ /**
96
+ * What an action acted on: element node of document doc, and where a mouse action pressed, relative to the element's
97
+ * border box. Without a node, point is in the viewport of doc.
98
+ */
99
+ type DomTarget = {
100
+ doc: string;
101
+ node?: number;
102
+ point?: [x: number, y: number];
103
+ };
104
+ /**
105
+ * A point in a page's DOM recording: the state after batch seq of the top document doc, and of the documents in
106
+ * its frames after the batches in frames.
107
+ */
108
+ type DomPoint = {
109
+ page: number;
110
+ doc: string;
111
+ seq: number;
112
+ frames?: Record<string, number>;
113
+ };
114
+ /** One message of a recorder, recorded as it arrived. */
115
+ type IDomPacket = {
116
+ id: string;
117
+ type: 'dom';
118
+ timestamp: number;
119
+ page: number;
120
+ doc: string;
121
+ seq: number;
122
+ /** The strings this packet added to the document's table. */
123
+ strings?: string[];
124
+ } & ({
125
+ kind: 'keyframe';
126
+ data: DomKeyframe;
127
+ } | {
128
+ kind: 'changes';
129
+ data: DomChange[];
130
+ });
131
+ /**
132
+ * Which document an iframe element shows: the element with id owner in document parentDoc shows document doc,
133
+ * from the time this arrived until another document is linked to the same element.
134
+ */
135
+ type IDomFrame = {
136
+ id: string;
137
+ type: 'dom-frame';
138
+ timestamp: number;
139
+ page: number;
140
+ parentDoc: string;
141
+ owner: number;
142
+ doc: string;
143
+ };
144
+ /** A response body the replay serves to the rebuilt document, like a stylesheet, font or image. */
145
+ type IDomResource = {
146
+ id: string;
147
+ type: 'dom-resource';
148
+ timestamp: number;
149
+ url: string;
150
+ status: number;
151
+ contentType: string;
152
+ content?: Uint8Array;
153
+ /** SHA-256 hash of the body. */
154
+ contentHash?: string;
155
+ /** Packet id containing the body when this resource duplicates an earlier one. */
156
+ contentReference?: string;
157
+ contentLength?: number;
158
+ };
159
+
1
160
  type IPacket = {
2
161
  id: string;
3
162
  type: string;
@@ -31,6 +190,11 @@ type ICommand = IPacket & {
31
190
  took?: number;
32
191
  finished: number;
33
192
  };
193
+ /** Where the DOM recording of the command's page stood when the command started, and what an action acted on. */
194
+ dom?: {
195
+ before?: DomPoint;
196
+ target?: DomTarget;
197
+ };
34
198
  };
35
199
  declare enum ContextStatus {
36
200
  SUCCESSFUL = "successful",
@@ -150,7 +314,80 @@ declare const Constructors: {
150
314
  };
151
315
  declare const ConstructorValues: string[];
152
316
 
153
- declare const SNAPSHOT_VERSION = 1;
317
+ declare const SNAPSHOT_VERSION = 2;
318
+
319
+ /**
320
+ * Rebuilds a recorded document inside another document, like the GUI's replay frame. Uses only DOM APIs, so it runs
321
+ * wherever a document exists.
322
+ *
323
+ * Nothing recorded may load or navigate on its own: iframes, scripts, plugins, refreshes and link hints are
324
+ * neutralized while elements are created, before they are inserted.
325
+ */
326
+ declare class DomReplay {
327
+ private readonly options;
328
+ readonly doc: Document;
329
+ private nodes;
330
+ private base;
331
+ private own;
332
+ viewport: DomViewport;
333
+ private strings;
334
+ private scroll;
335
+ private sheets;
336
+ private pendingTop;
337
+ private recordedOpen;
338
+ /**
339
+ * frameSrc is the page recorded iframes load instead of their own, so a caller can build the documents they
340
+ * showed into them. Without it, iframes stay empty.
341
+ */
342
+ constructor(doc: Document, options?: {
343
+ frameSrc?: string;
344
+ });
345
+ /** Rebuilds the document from a keyframe and the strings that came with it. */
346
+ build(keyframe: DomKeyframe, strings?: string[]): void;
347
+ /** Applies a batch of changes, with the strings it added to the table. */
348
+ apply(changes: DomChange[], strings?: string[]): void;
349
+ /** Scroll positions need layout, so they are restored once, after all changes are applied. */
350
+ restoreScroll(): void;
351
+ /** The iframe elements of the rebuilt document with their recorded ids. */
352
+ frames(): [number, HTMLIFrameElement][];
353
+ /** The node a recorded id stands for, like the target of a command. */
354
+ nodeOf(id: number): Node | undefined;
355
+ private windowOf;
356
+ private string;
357
+ private create;
358
+ private setChildren;
359
+ private attachShadow;
360
+ private setSheet;
361
+ private adopt;
362
+ private applyTop;
363
+ private setTop;
364
+ private nextRecorded;
365
+ private keepBase;
366
+ private setAttributes;
367
+ private rewrite;
368
+ private setProps;
369
+ }
370
+ /** The keyframe and batches of one document, up to and including seq, starting from the last keyframe before it. */
371
+ declare function domPacketsUntil<T extends {
372
+ kind: string;
373
+ seq: number;
374
+ }>(packets: T[], seq: number): T[];
375
+
376
+ /**
377
+ * The document an iframe element shows at a point of its parent's recording: one the point flushed, or else the last
378
+ * one linked to the element before time that had recorded something by then. A frame that started navigating is
379
+ * linked to its new document before that document sent anything, and until then still shows the old one.
380
+ */
381
+ declare function domFrameDocument(links: {
382
+ owner: number;
383
+ doc: string;
384
+ timestamp: number;
385
+ }[], owner: number, frames: Record<string, number> | undefined, time: number, recorded?: (doc: string) => boolean): string | undefined;
386
+ /** The last batch of a document that arrived until time. */
387
+ declare function domSeqAt(packets: {
388
+ seq: number;
389
+ timestamp: number;
390
+ }[], time: number): number | undefined;
154
391
 
155
- export { ConstructorValues, Constructors, ContextStatus, SNAPSHOT_VERSION, SnapshotMode, SnapshotState };
156
- export type { CommandProps, IBlobHandle, ICommand, ICommandError, IConsoleMessageType, IContext, IExpectation, IExpects, ILog, ILogLocation, IPacket, IPageInclude, IResponse, ISnapshot, IViewport };
392
+ export { ConstructorValues, Constructors, ContextStatus, DomNamespace, DomNodeType, DomOp, DomReplay, DomTopLayer, SNAPSHOT_VERSION, SnapshotMode, SnapshotState, domFrameDocument, domPacketsUntil, domSeqAt };
393
+ export type { CommandProps, DomChange, DomKeyframe, DomPoint, DomProps, DomScroll, DomString, DomTarget, DomTokens, DomViewport, IBlobHandle, ICommand, ICommandError, IConsoleMessageType, IContext, IDomFrame, IDomPacket, IDomResource, IExpectation, IExpects, ILog, ILogLocation, IPacket, IPageInclude, IResponse, ISnapshot, IViewport };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,162 @@
1
+ /**
2
+ * The DOM recording format. A recorder in each page sends one keyframe per document, then batches of changes,
3
+ * which the GUI applies to rebuild the document at any point.
4
+ *
5
+ * Applying batch n to the state after batch n - 1 gives the document as it was when batch n was flushed. Batches
6
+ * carry current values, not the history of a change, so they never depend on how the page got there.
7
+ *
8
+ * For size, nodes are flat token lists and strings come from a table per document. A keyframe starts the table,
9
+ * every packet appends the strings it added (DomPacket.strings), in order.
10
+ */
11
+ /** The index of a string in the document's table, or the string itself. */
12
+ type DomString = number | string;
13
+ /**
14
+ * Nodes as flat tokens, in pre-order. Every node has an id that stays the same for as long as the node exists.
15
+ *
16
+ * element: id, 1, tag, namespace, attribute count, (name, value)..., props, child count, children...
17
+ * text and comment: id, 3 or 8, data
18
+ * doctype: id, 10, name, public id, system id
19
+ *
20
+ * An element's open shadow root is in its props: the root's id, then its children as a node list.
21
+ *
22
+ * A node list starts with the number of nodes in it. In the children of a CHILDREN change, a node the replay has
23
+ * already is its negative id.
24
+ */
25
+ type DomTokens = (number | string | DomProps | 0)[];
26
+ declare enum DomNodeType {
27
+ ELEMENT = 1,
28
+ TEXT = 3,
29
+ COMMENT = 8,
30
+ DOCTYPE = 10
31
+ }
32
+ declare enum DomNamespace {
33
+ HTML = 0,
34
+ SVG = 1,
35
+ MATHML = 2
36
+ }
37
+ /** State of form controls and stylesheets that their attributes and children don't show. */
38
+ type DomProps = {
39
+ value?: string;
40
+ checked?: boolean;
41
+ selectedIndex?: number;
42
+ /** The selected options of a select that allows several. */
43
+ selected?: number[];
44
+ /** Rules a script added to a <style> element through the CSSOM, like CSS-in-JS libraries do. */
45
+ css?: string;
46
+ /** The element's open shadow root: its id, then its children as a node list. */
47
+ shadow?: DomTokens;
48
+ /** Whether the element is in the top layer, if it is. */
49
+ top?: DomTopLayer;
50
+ };
51
+ declare enum DomTopLayer {
52
+ NONE = 0,
53
+ /** A dialog opened with showModal(). */
54
+ MODAL = 1,
55
+ /** A popover that is open. */
56
+ POPOVER = 2
57
+ }
58
+ type DomViewport = [width: number, height: number, devicePixelRatio: number];
59
+ /** Scroll position of an element, or of the window for id 0. */
60
+ type DomScroll = [id: number, x: number, y: number];
61
+ declare enum DomOp {
62
+ /** The complete current children of a node: ids of nodes it had before, serialized nodes for new ones. */
63
+ CHILDREN = 1,
64
+ /** The complete current attributes of an element. */
65
+ ATTRIBUTES = 2,
66
+ TEXT = 3,
67
+ CONTROL = 4,
68
+ CSS = 6,
69
+ SCROLL = 7,
70
+ VIEWPORT = 8,
71
+ /** A shadow root attached to an element recorded before: the root's id, then its children as a node list. */
72
+ SHADOW = 9,
73
+ /** The rules of an adopted stylesheet, the first time it is adopted and whenever they change. */
74
+ SHEET = 10,
75
+ /** The complete current adopted stylesheets of the document or of a shadow root, by sheet id. */
76
+ ADOPT = 11,
77
+ TOP_LAYER = 12
78
+ }
79
+ type DomChange = [op: DomOp.CHILDREN, parent: number, children: DomTokens] | [op: DomOp.ATTRIBUTES, element: number, attributes: DomString[]] | [op: DomOp.TEXT, node: number, data: DomString] | [op: DomOp.CONTROL, element: number, value: string | null, checked: boolean | null, selectedIndex: number | null, selected?: number[] | null] | [op: DomOp.CSS, element: number, css: string] | [op: DomOp.SCROLL, ...DomScroll] | [op: DomOp.VIEWPORT, ...DomViewport] | [op: DomOp.SHADOW, host: number, root: DomTokens] | [op: DomOp.SHEET, sheet: number, css: string] | [op: DomOp.ADOPT, root: number, sheets: number[]] | [op: DomOp.TOP_LAYER, element: number, state: DomTopLayer];
80
+ type DomKeyframe = {
81
+ url: string;
82
+ /** The base URL relative URLs resolve against, which a <base> element can change. */
83
+ base: string;
84
+ /** Id of the document node, the parent of the root children. */
85
+ document: number;
86
+ /** The document's children, as a node list. */
87
+ root: DomTokens;
88
+ viewport: DomViewport;
89
+ scroll: DomScroll[];
90
+ /** The adopted stylesheets, as sheet id and rules. */
91
+ sheets?: [sheet: number, css: string][];
92
+ /** The document and shadow roots that adopted stylesheets, with their sheet ids. */
93
+ adopted?: [root: number, sheets: number[]][];
94
+ };
95
+ /**
96
+ * What an action acted on: element node of document doc, and where a mouse action pressed, relative to the element's
97
+ * border box. Without a node, point is in the viewport of doc.
98
+ */
99
+ type DomTarget = {
100
+ doc: string;
101
+ node?: number;
102
+ point?: [x: number, y: number];
103
+ };
104
+ /**
105
+ * A point in a page's DOM recording: the state after batch seq of the top document doc, and of the documents in
106
+ * its frames after the batches in frames.
107
+ */
108
+ type DomPoint = {
109
+ page: number;
110
+ doc: string;
111
+ seq: number;
112
+ frames?: Record<string, number>;
113
+ };
114
+ /** One message of a recorder, recorded as it arrived. */
115
+ type IDomPacket = {
116
+ id: string;
117
+ type: 'dom';
118
+ timestamp: number;
119
+ page: number;
120
+ doc: string;
121
+ seq: number;
122
+ /** The strings this packet added to the document's table. */
123
+ strings?: string[];
124
+ } & ({
125
+ kind: 'keyframe';
126
+ data: DomKeyframe;
127
+ } | {
128
+ kind: 'changes';
129
+ data: DomChange[];
130
+ });
131
+ /**
132
+ * Which document an iframe element shows: the element with id owner in document parentDoc shows document doc,
133
+ * from the time this arrived until another document is linked to the same element.
134
+ */
135
+ type IDomFrame = {
136
+ id: string;
137
+ type: 'dom-frame';
138
+ timestamp: number;
139
+ page: number;
140
+ parentDoc: string;
141
+ owner: number;
142
+ doc: string;
143
+ };
144
+ /** A response body the replay serves to the rebuilt document, like a stylesheet, font or image. */
145
+ type IDomResource = {
146
+ id: string;
147
+ type: 'dom-resource';
148
+ timestamp: number;
149
+ url: string;
150
+ status: number;
151
+ contentType: string;
152
+ content?: Uint8Array;
153
+ /** SHA-256 hash of the body. */
154
+ contentHash?: string;
155
+ /** Packet id containing the body when this resource duplicates an earlier one. */
156
+ contentReference?: string;
157
+ contentLength?: number;
158
+ };
159
+
1
160
  type IPacket = {
2
161
  id: string;
3
162
  type: string;
@@ -31,6 +190,11 @@ type ICommand = IPacket & {
31
190
  took?: number;
32
191
  finished: number;
33
192
  };
193
+ /** Where the DOM recording of the command's page stood when the command started, and what an action acted on. */
194
+ dom?: {
195
+ before?: DomPoint;
196
+ target?: DomTarget;
197
+ };
34
198
  };
35
199
  declare enum ContextStatus {
36
200
  SUCCESSFUL = "successful",
@@ -150,7 +314,80 @@ declare const Constructors: {
150
314
  };
151
315
  declare const ConstructorValues: string[];
152
316
 
153
- declare const SNAPSHOT_VERSION = 1;
317
+ declare const SNAPSHOT_VERSION = 2;
318
+
319
+ /**
320
+ * Rebuilds a recorded document inside another document, like the GUI's replay frame. Uses only DOM APIs, so it runs
321
+ * wherever a document exists.
322
+ *
323
+ * Nothing recorded may load or navigate on its own: iframes, scripts, plugins, refreshes and link hints are
324
+ * neutralized while elements are created, before they are inserted.
325
+ */
326
+ declare class DomReplay {
327
+ private readonly options;
328
+ readonly doc: Document;
329
+ private nodes;
330
+ private base;
331
+ private own;
332
+ viewport: DomViewport;
333
+ private strings;
334
+ private scroll;
335
+ private sheets;
336
+ private pendingTop;
337
+ private recordedOpen;
338
+ /**
339
+ * frameSrc is the page recorded iframes load instead of their own, so a caller can build the documents they
340
+ * showed into them. Without it, iframes stay empty.
341
+ */
342
+ constructor(doc: Document, options?: {
343
+ frameSrc?: string;
344
+ });
345
+ /** Rebuilds the document from a keyframe and the strings that came with it. */
346
+ build(keyframe: DomKeyframe, strings?: string[]): void;
347
+ /** Applies a batch of changes, with the strings it added to the table. */
348
+ apply(changes: DomChange[], strings?: string[]): void;
349
+ /** Scroll positions need layout, so they are restored once, after all changes are applied. */
350
+ restoreScroll(): void;
351
+ /** The iframe elements of the rebuilt document with their recorded ids. */
352
+ frames(): [number, HTMLIFrameElement][];
353
+ /** The node a recorded id stands for, like the target of a command. */
354
+ nodeOf(id: number): Node | undefined;
355
+ private windowOf;
356
+ private string;
357
+ private create;
358
+ private setChildren;
359
+ private attachShadow;
360
+ private setSheet;
361
+ private adopt;
362
+ private applyTop;
363
+ private setTop;
364
+ private nextRecorded;
365
+ private keepBase;
366
+ private setAttributes;
367
+ private rewrite;
368
+ private setProps;
369
+ }
370
+ /** The keyframe and batches of one document, up to and including seq, starting from the last keyframe before it. */
371
+ declare function domPacketsUntil<T extends {
372
+ kind: string;
373
+ seq: number;
374
+ }>(packets: T[], seq: number): T[];
375
+
376
+ /**
377
+ * The document an iframe element shows at a point of its parent's recording: one the point flushed, or else the last
378
+ * one linked to the element before time that had recorded something by then. A frame that started navigating is
379
+ * linked to its new document before that document sent anything, and until then still shows the old one.
380
+ */
381
+ declare function domFrameDocument(links: {
382
+ owner: number;
383
+ doc: string;
384
+ timestamp: number;
385
+ }[], owner: number, frames: Record<string, number> | undefined, time: number, recorded?: (doc: string) => boolean): string | undefined;
386
+ /** The last batch of a document that arrived until time. */
387
+ declare function domSeqAt(packets: {
388
+ seq: number;
389
+ timestamp: number;
390
+ }[], time: number): number | undefined;
154
391
 
155
- export { ConstructorValues, Constructors, ContextStatus, SNAPSHOT_VERSION, SnapshotMode, SnapshotState };
156
- export type { CommandProps, IBlobHandle, ICommand, ICommandError, IConsoleMessageType, IContext, IExpectation, IExpects, ILog, ILogLocation, IPacket, IPageInclude, IResponse, ISnapshot, IViewport };
392
+ export { ConstructorValues, Constructors, ContextStatus, DomNamespace, DomNodeType, DomOp, DomReplay, DomTopLayer, SNAPSHOT_VERSION, SnapshotMode, SnapshotState, domFrameDocument, domPacketsUntil, domSeqAt };
393
+ export type { CommandProps, DomChange, DomKeyframe, DomPoint, DomProps, DomScroll, DomString, DomTarget, DomTokens, DomViewport, IBlobHandle, ICommand, ICommandError, IConsoleMessageType, IContext, IDomFrame, IDomPacket, IDomResource, IExpectation, IExpects, ILog, ILogLocation, IPacket, IPageInclude, IResponse, ISnapshot, IViewport };