@smartesting/rrweb-types
Version:
491 lines (490 loc) • 14 kB
TypeScript
import type { serializedNodeWithId, Mirror, INode, DataURLOptions } from '@smartesting/rrweb-snapshot';
export declare enum EventType {
DomContentLoaded = 0,
Load = 1,
FullSnapshot = 2,
IncrementalSnapshot = 3,
Meta = 4,
Custom = 5,
Plugin = 6
}
export type domContentLoadedEvent = {
type: EventType.DomContentLoaded;
data: unknown;
};
export type loadedEvent = {
type: EventType.Load;
data: unknown;
};
export type fullSnapshotEvent = {
type: EventType.FullSnapshot;
data: {
node: serializedNodeWithId;
initialOffset: {
top: number;
left: number;
};
};
};
export type incrementalSnapshotEvent = {
type: EventType.IncrementalSnapshot;
data: incrementalData;
};
export type metaEvent = {
type: EventType.Meta;
data: {
href: string;
width: number;
height: number;
};
};
export type customEvent<T = unknown> = {
type: EventType.Custom;
data: {
tag: string;
payload: T;
};
};
export type pluginEvent<T = unknown> = {
type: EventType.Plugin;
data: {
plugin: string;
payload: T;
};
};
export declare enum IncrementalSource {
Mutation = 0,
MouseMove = 1,
MouseInteraction = 2,
Scroll = 3,
ViewportResize = 4,
Input = 5,
TouchMove = 6,
MediaInteraction = 7,
StyleSheetRule = 8,
CanvasMutation = 9,
Font = 10,
Log = 11,
Drag = 12,
StyleDeclaration = 13,
Selection = 14,
AdoptedStyleSheet = 15,
CustomElement = 16
}
export type mutationData = {
source: IncrementalSource.Mutation;
} & mutationCallbackParam;
export type mousemoveData = {
source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
positions: mousePosition[];
};
export type mouseInteractionData = {
source: IncrementalSource.MouseInteraction;
} & mouseInteractionParam;
export type scrollData = {
source: IncrementalSource.Scroll;
} & scrollPosition;
export type viewportResizeData = {
source: IncrementalSource.ViewportResize;
} & viewportResizeDimension;
export type inputData = {
source: IncrementalSource.Input;
id: number;
} & inputValue;
export type mediaInteractionData = {
source: IncrementalSource.MediaInteraction;
} & mediaInteractionParam;
export type styleSheetRuleData = {
source: IncrementalSource.StyleSheetRule;
} & styleSheetRuleParam;
export type styleDeclarationData = {
source: IncrementalSource.StyleDeclaration;
} & styleDeclarationParam;
export type canvasMutationData = {
source: IncrementalSource.CanvasMutation;
} & canvasMutationParam;
export type fontData = {
source: IncrementalSource.Font;
} & fontParam;
export type selectionData = {
source: IncrementalSource.Selection;
} & selectionParam;
export type adoptedStyleSheetData = {
source: IncrementalSource.AdoptedStyleSheet;
} & adoptedStyleSheetParam;
export type customElementData = {
source: IncrementalSource.CustomElement;
} & customElementParam;
export type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | selectionData | styleDeclarationData | adoptedStyleSheetData | customElementData;
export type eventWithoutTime = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent | pluginEvent;
export type event = eventWithoutTime;
export type eventWithTime = eventWithoutTime & {
timestamp: number;
delay?: number;
};
export type canvasEventWithTime = eventWithTime & {
type: EventType.IncrementalSnapshot;
data: canvasMutationData;
};
export type blockClass = string | RegExp;
export type maskTextClass = string | RegExp;
export type SamplingStrategy = Partial<{
mousemove: boolean | number;
mousemoveCallback: number;
mouseInteraction: boolean | Record<string, boolean | undefined>;
scroll: number;
media: number;
input: 'all' | 'last';
canvas: 'all' | number;
}>;
export interface ICrossOriginIframeMirror {
getId(iframe: HTMLIFrameElement, remoteId: number, parentToRemoteMap?: Map<number, number>, remoteToParentMap?: Map<number, number>): number;
getIds(iframe: HTMLIFrameElement, remoteId: number[]): number[];
getRemoteId(iframe: HTMLIFrameElement, parentId: number, map?: Map<number, number>): number;
getRemoteIds(iframe: HTMLIFrameElement, parentId: number[]): number[];
reset(iframe?: HTMLIFrameElement): void;
}
export type RecordPlugin<TOptions = unknown> = {
name: string;
observer?: (cb: (...args: Array<unknown>) => void, win: IWindow, options: TOptions) => listenerHandler;
eventProcessor?: <TExtend>(event: eventWithTime) => eventWithTime & TExtend;
getMirror?: (mirrors: {
nodeMirror: Mirror;
crossOriginIframeMirror: ICrossOriginIframeMirror;
crossOriginIframeStyleMirror: ICrossOriginIframeMirror;
}) => void;
options: TOptions;
};
export type hooksParam = {
mutation?: mutationCallBack;
mousemove?: mousemoveCallBack;
mouseInteraction?: mouseInteractionCallBack;
scroll?: scrollCallback;
viewportResize?: viewportResizeCallback;
input?: inputCallback;
mediaInteaction?: mediaInteractionCallback;
styleSheetRule?: styleSheetRuleCallback;
styleDeclaration?: styleDeclarationCallback;
canvasMutation?: canvasMutationCallback;
font?: fontCallback;
selection?: selectionCallback;
customElement?: customElementCallback;
};
export type mutationRecord = Readonly<{
type: string;
target: Node;
oldValue: string | null;
addedNodes: NodeList;
removedNodes: NodeList;
attributeName: string | null;
}>;
export type textCursor = {
node: Node;
value: string | null;
};
export type textMutation = {
id: number;
value: string | null;
};
export type styleOMValue = {
[key: string]: styleValueWithPriority | string | false;
};
export type styleValueWithPriority = [string, string];
export type attributeCursor = {
node: Node;
attributes: {
[key: string]: string | styleOMValue | null;
};
styleDiff: styleOMValue;
_unchangedStyles: styleOMValue;
};
export type attributeMutation = {
id: number;
attributes: {
[key: string]: string | styleOMValue | null;
};
};
export type removedNodeMutation = {
parentId: number;
id: number;
isShadow?: boolean;
};
export type addedNodeMutation = {
parentId: number;
previousId?: number | null;
nextId: number | null;
node: serializedNodeWithId;
};
export type mutationCallbackParam = {
texts: textMutation[];
attributes: attributeMutation[];
removes: removedNodeMutation[];
adds: addedNodeMutation[];
isAttachIframe?: true;
};
export type mutationCallBack = (m: mutationCallbackParam) => void;
export type mousemoveCallBack = (p: mousePosition[], source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag) => void;
export type mousePosition = {
x: number;
y: number;
id: number;
timeOffset: number;
};
export type mouseMovePos = {
x: number;
y: number;
id: number;
debugData: incrementalData;
};
export declare enum MouseInteractions {
MouseUp = 0,
MouseDown = 1,
Click = 2,
ContextMenu = 3,
DblClick = 4,
Focus = 5,
Blur = 6,
TouchStart = 7,
TouchMove_Departed = 8,
TouchEnd = 9,
TouchCancel = 10
}
export declare enum PointerTypes {
Mouse = 0,
Pen = 1,
Touch = 2
}
export declare enum CanvasContext {
'2D' = 0,
WebGL = 1,
WebGL2 = 2
}
export type SerializedCanvasArg = {
rr_type: 'ArrayBuffer';
base64: string;
} | {
rr_type: 'Blob';
data: Array<CanvasArg>;
type?: string;
} | {
rr_type: string;
src: string;
} | {
rr_type: string;
args: Array<CanvasArg>;
} | {
rr_type: string;
index: number;
};
export type CanvasArg = SerializedCanvasArg | string | number | boolean | null | CanvasArg[];
type mouseInteractionParam = {
type: MouseInteractions;
id: number;
x?: number;
y?: number;
pointerType?: PointerTypes;
};
export type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
export type scrollPosition = {
id: number;
x: number;
y: number;
};
export type scrollCallback = (p: scrollPosition) => void;
export type styleSheetAddRule = {
rule: string;
index?: number | number[];
};
export type styleSheetDeleteRule = {
index: number | number[];
};
export type styleSheetRuleParam = {
id?: number;
styleId?: number;
removes?: styleSheetDeleteRule[];
adds?: styleSheetAddRule[];
replace?: string;
replaceSync?: string;
};
export type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
export type adoptedStyleSheetParam = {
id: number;
styles?: {
styleId: number;
rules: styleSheetAddRule[];
}[];
styleIds: number[];
};
export type adoptedStyleSheetCallback = (a: adoptedStyleSheetParam) => void;
export type styleDeclarationParam = {
id?: number;
styleId?: number;
index: number[];
set?: {
property: string;
value: string | null;
priority: string | undefined;
};
remove?: {
property: string;
};
};
export type styleDeclarationCallback = (s: styleDeclarationParam) => void;
export type canvasMutationCommand = {
property: string;
args: Array<unknown>;
setter?: true;
};
export type canvasMutationParam = {
id: number;
type: CanvasContext;
commands: canvasMutationCommand[];
} | ({
id: number;
type: CanvasContext;
} & canvasMutationCommand);
export type canvasMutationWithType = {
type: CanvasContext;
} & canvasMutationCommand;
export type canvasMutationCallback = (p: canvasMutationParam) => void;
export type canvasManagerMutationCallback = (target: HTMLCanvasElement, p: canvasMutationWithType) => void;
export type ImageBitmapDataURLWorkerParams = {
id: number;
bitmap: ImageBitmap;
width: number;
height: number;
dataURLOptions: DataURLOptions;
};
export type ImageBitmapDataURLWorkerResponse = {
id: number;
} | {
id: number;
type: string;
base64: string;
width: number;
height: number;
};
export type fontParam = {
family: string;
fontSource: string;
buffer: boolean;
descriptors?: FontFaceDescriptors;
};
export type fontCallback = (p: fontParam) => void;
export type viewportResizeDimension = {
width: number;
height: number;
};
export type viewportResizeCallback = (d: viewportResizeDimension) => void;
export type inputValue = {
text: string;
isChecked: boolean;
userTriggered?: boolean;
};
export type inputCallback = (v: inputValue & {
id: number;
}) => void;
export declare const enum MediaInteractions {
Play = 0,
Pause = 1,
Seeked = 2,
VolumeChange = 3,
RateChange = 4
}
export type mediaInteractionParam = {
type: MediaInteractions;
id: number;
currentTime?: number;
volume?: number;
muted?: boolean;
loop?: boolean;
playbackRate?: number;
};
export type mediaInteractionCallback = (p: mediaInteractionParam) => void;
export type DocumentDimension = {
x: number;
y: number;
relativeScale: number;
absoluteScale: number;
};
export type SelectionRange = {
start: number;
startOffset: number;
end: number;
endOffset: number;
};
export type selectionParam = {
ranges: Array<SelectionRange>;
};
export type selectionCallback = (p: selectionParam) => void;
export type customElementParam = {
define?: {
name: string;
};
};
export type customElementCallback = (c: customElementParam) => void;
export type DeprecatedMirror = {
map: {
[key: number]: INode;
};
getId: (n: Node) => number;
getNode: (id: number) => INode | null;
removeNodeFromMap: (n: Node) => void;
has: (id: number) => boolean;
reset: () => void;
};
export type throttleOptions = {
leading?: boolean;
trailing?: boolean;
};
export type listenerHandler = () => void;
export type hookResetter = () => void;
export type playerMetaData = {
startTime: number;
endTime: number;
totalTime: number;
};
export type actionWithDelay = {
doAction: () => void;
delay: number;
};
export type Handler = (event?: unknown) => void;
export type Emitter = {
on(type: string, handler: Handler): void;
emit(type: string, event?: unknown): void;
off(type: string, handler: Handler): void;
};
export type Arguments<T> = T extends (...payload: infer U) => unknown ? U : unknown;
export declare enum ReplayerEvents {
Start = "start",
Pause = "pause",
Resume = "resume",
Resize = "resize",
Finish = "finish",
FullsnapshotRebuilded = "fullsnapshot-rebuilded",
LoadStylesheetStart = "load-stylesheet-start",
LoadStylesheetEnd = "load-stylesheet-end",
SkipStart = "skip-start",
SkipEnd = "skip-end",
MouseInteraction = "mouse-interaction",
EventCast = "event-cast",
CustomEvent = "custom-event",
Flush = "flush",
StateChange = "state-change",
PlayBack = "play-back",
Destroy = "destroy"
}
export type KeepIframeSrcFn = (src: string) => boolean;
declare global {
interface Window {
FontFace: typeof FontFace;
}
}
export type IWindow = Window & typeof globalThis;
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export type GetTypedKeys<Obj extends object, ValueType> = TakeTypeHelper<Obj, ValueType>[keyof TakeTypeHelper<Obj, ValueType>];
export type TakeTypeHelper<Obj extends object, ValueType> = {
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
};
export type TakeTypedKeyValues<Obj extends object, Type> = Pick<Obj, TakeTypeHelper<Obj, Type>[keyof TakeTypeHelper<Obj, Type>]>;
export {};