posthog-js
Version:
Posthog-js allows you to automatically capture usage and send events to PostHog.
680 lines • 20.3 kB
TypeScript
//#region ../rrweb/types/dist/index.d.ts
//#region src/index.d.ts
declare enum EventType {
DomContentLoaded = 0,
Load = 1,
FullSnapshot = 2,
IncrementalSnapshot = 3,
Meta = 4,
Custom = 5,
Plugin = 6
}
type domContentLoadedEvent = {
type: EventType.DomContentLoaded;
data: unknown;
};
type loadedEvent = {
type: EventType.Load;
data: unknown;
};
type fullSnapshotEvent = {
type: EventType.FullSnapshot;
data: {
node: serializedNodeWithId;
initialOffset: {
top: number;
left: number;
};
};
};
type incrementalSnapshotEvent = {
type: EventType.IncrementalSnapshot;
data: incrementalData;
};
type metaEvent = {
type: EventType.Meta;
data: {
href: string;
width: number;
height: number;
};
};
type customEvent$1<T = unknown> = {
type: EventType.Custom;
data: {
tag: string;
payload: T;
};
};
/**
* Reserved custom-event tag emitted by the recorder when an element enters or
* exits the native Fullscreen API. Native fullscreen is rendered by the UA
* `:fullscreen` pseudo-class with no DOM mutation, so rrweb captures nothing —
* this event lets the replayer re-apply fullscreen layout on playback.
*/
declare const FullscreenCustomEventTag = "rrweb/fullscreen";
type fullscreenEventPayload = {
/** mirror id of the element that went fullscreen */
id: number;
enter: boolean;
};
type pluginEvent<T = unknown> = {
type: EventType.Plugin;
data: {
plugin: string;
payload: T;
};
};
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
}
type mutationData = {
source: IncrementalSource.Mutation;
} & mutationCallbackParam;
type mousemoveData = {
source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
positions: mousePosition[];
};
type mouseInteractionData = {
source: IncrementalSource.MouseInteraction;
} & mouseInteractionParam;
type scrollData = {
source: IncrementalSource.Scroll;
} & scrollPosition;
type viewportResizeData = {
source: IncrementalSource.ViewportResize;
} & viewportResizeDimension;
type inputData = {
source: IncrementalSource.Input;
id: number;
} & inputValue;
type mediaInteractionData = {
source: IncrementalSource.MediaInteraction;
} & mediaInteractionParam;
type styleSheetRuleData = {
source: IncrementalSource.StyleSheetRule;
} & styleSheetRuleParam;
type styleDeclarationData = {
source: IncrementalSource.StyleDeclaration;
} & styleDeclarationParam;
type canvasMutationData = {
source: IncrementalSource.CanvasMutation;
} & canvasMutationParam;
type fontData = {
source: IncrementalSource.Font;
} & fontParam;
type selectionData = {
source: IncrementalSource.Selection;
} & selectionParam;
type adoptedStyleSheetData = {
source: IncrementalSource.AdoptedStyleSheet;
} & adoptedStyleSheetParam;
type customElementData = {
source: IncrementalSource.CustomElement;
} & customElementParam;
type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | selectionData | styleDeclarationData | adoptedStyleSheetData | customElementData;
type eventWithoutTime$1 = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent$1 | pluginEvent;
type eventWithTime$1 = eventWithoutTime$1 & {
timestamp: number;
delay?: number;
};
type canvasEventWithTime = eventWithTime$1 & {
type: EventType.IncrementalSnapshot;
data: canvasMutationData;
};
type blockClass = string | RegExp;
type maskTextClass = string | RegExp;
type SamplingStrategy = Partial<{
/**
* false means not to record mouse/touch move events
* number is the throttle threshold of recording mouse/touch move
*/
mousemove: boolean | number;
/**
* number is the throttle threshold of mouse/touch move callback
*/
mousemoveCallback: number;
/**
* false means not to record mouse interaction events
* can also specify record some kinds of mouse interactions
*/
mouseInteraction: boolean | Record<string, boolean | undefined>;
/**
* number is the throttle threshold of recording scroll
*/
scroll: number;
/**
* number is the throttle threshold of recording media interactions
*/
media: number;
/**
* 'all' will record all the input events
* 'last' will only record the last input value while input a sequence of chars
*/
input: "all" | "last";
/**
* 'all' will record every single canvas call
* number between 1 and 60, will record an image snapshots in a web-worker a (maximum) number of times per second.
* Number only supported where [`OffscreenCanvas`](http://mdn.io/offscreencanvas) is supported.
*/
canvas: "all" | number;
}>;
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;
}
type RecordPlugin<TOptions = unknown> = {
name: string;
observer?: (cb: (...args: Array<unknown>) => void, win: IWindow, options: TOptions) => listenerHandler;
eventProcessor?: <TExtend>(event: eventWithTime$1) => eventWithTime$1 & TExtend;
getMirror?: (mirrors: {
nodeMirror: IMirror<Node>;
crossOriginIframeMirror: ICrossOriginIframeMirror;
crossOriginIframeStyleMirror: ICrossOriginIframeMirror;
}) => void;
options: TOptions;
};
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;
};
type mutationRecord = Readonly<{
type: string;
target: Node;
oldValue: string | null;
addedNodes: NodeList;
removedNodes: NodeList;
attributeName: string | null;
attributeNamespace?: string | null;
}>;
type textCursor = {
node: Node;
value: string | null;
};
type textMutation = {
id: number;
value: string | null;
};
type styleOMValue = {
[key: string]: styleValueWithPriority | string | false;
};
type styleValueWithPriority = [string, string];
type attributeCursor = {
node: Node;
attributes: {
[key: string]: string | styleOMValue | null;
};
styleDiff: styleOMValue;
_unchangedStyles: styleOMValue;
};
type attributeMutation = {
id: number;
attributes: {
[key: string]: string | styleOMValue | null;
};
};
type removedNodeMutation = {
parentId: number;
id: number;
isShadow?: boolean;
};
type addedNodeMutation = {
parentId: number;
previousId?: number | null;
nextId: number | null;
node: serializedNodeWithId;
};
type mutationCallbackParam = {
texts: textMutation[];
attributes: attributeMutation[];
removes: removedNodeMutation[];
adds: addedNodeMutation[];
isAttachIframe?: true;
};
type mutationCallBack = (m: mutationCallbackParam) => void;
type mousemoveCallBack = (p: mousePosition[], source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag) => void;
type mousePosition = {
x: number;
y: number;
id: number;
timeOffset: number;
};
type mouseMovePos = {
x: number;
y: number;
id: number;
debugData: incrementalData;
};
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
}
declare enum PointerTypes {
Mouse = 0,
Pen = 1,
Touch = 2
}
declare enum CanvasContext {
"2D" = 0,
WebGL = 1,
WebGL2 = 2
}
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;
};
type CanvasArg = SerializedCanvasArg | string | number | boolean | null | CanvasArg[];
type mouseInteractionParam = {
type: MouseInteractions;
id: number;
x?: number;
y?: number;
pointerType?: PointerTypes;
};
type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
type scrollPosition = {
id: number;
x: number;
y: number;
};
type scrollCallback = (p: scrollPosition) => void;
type styleSheetAddRule = {
rule: string;
index?: number | number[];
};
type styleSheetDeleteRule = {
index: number | number[];
};
type styleSheetRuleParam = {
id?: number;
styleId?: number;
removes?: styleSheetDeleteRule[];
adds?: styleSheetAddRule[];
replace?: string;
replaceSync?: string;
};
type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
type adoptedStyleSheetParam = {
id: number;
styles?: {
styleId: number;
rules: styleSheetAddRule[];
}[];
styleIds: number[];
};
type adoptedStyleSheetCallback = (a: adoptedStyleSheetParam) => void;
type styleDeclarationParam = {
id?: number;
styleId?: number;
index: number[];
set?: {
property: string;
value: string | null;
priority: string | undefined;
};
remove?: {
property: string;
};
};
type styleDeclarationCallback = (s: styleDeclarationParam) => void;
type canvasMutationCommand = {
property: string;
args: Array<unknown>;
setter?: true;
};
type canvasMutationParam = {
id: number;
type: CanvasContext;
commands: canvasMutationCommand[];
displayWidth?: number;
displayHeight?: number;
} | ({
id: number;
type: CanvasContext;
displayWidth?: number;
displayHeight?: number;
} & canvasMutationCommand);
type canvasMutationWithType = {
type: CanvasContext;
} & canvasMutationCommand;
type canvasMutationCallback = (p: canvasMutationParam) => void;
type canvasManagerMutationCallback = (target: HTMLCanvasElement, p: canvasMutationWithType) => void;
type CanvasMaskRegion = {
x: number;
y: number;
width: number;
height: number;
};
type CanvasMasking = {
regionsFn?: (canvas: HTMLCanvasElement) => CanvasMaskRegion[] | null | undefined;
configured?: () => boolean;
};
type ImageBitmapDataURLWorkerParams = {
id: number;
bitmap: ImageBitmap;
width: number;
height: number;
displayWidth: number;
displayHeight: number;
dataURLOptions: DataURLOptions;
maskRegions?: CanvasMaskRegion[];
};
type ImageBitmapDataURLWorkerResetParams = {
resetFrameDedup: true;
};
type ImageBitmapDataURLWorkerMessage = ImageBitmapDataURLWorkerParams | ImageBitmapDataURLWorkerResetParams;
type ImageBitmapDataURLWorkerResponse = {
id: number;
} | {
id: number;
type: string;
base64: string;
displayWidth: number;
displayHeight: number;
};
type fontParam = {
family: string;
fontSource: string;
buffer: boolean;
descriptors?: FontFaceDescriptors;
};
type fontCallback = (p: fontParam) => void;
type viewportResizeDimension = {
width: number;
height: number;
};
type viewportResizeCallback = (d: viewportResizeDimension) => void;
type inputValue = {
text: string;
isChecked: boolean;
userTriggered?: boolean;
};
type inputCallback = (v: inputValue & {
id: number;
}) => void;
declare enum MediaInteractions {
Play = 0,
Pause = 1,
Seeked = 2,
VolumeChange = 3,
RateChange = 4
}
type mediaInteractionParam = {
type: MediaInteractions;
id: number;
currentTime?: number;
volume?: number;
muted?: boolean;
loop?: boolean;
playbackRate?: number;
};
type mediaInteractionCallback = (p: mediaInteractionParam) => void;
type DocumentDimension = {
x: number;
y: number;
relativeScale: number;
absoluteScale: number;
};
type SelectionRange = {
start: number;
startOffset: number;
end: number;
endOffset: number;
};
type selectionParam = {
ranges: Array<SelectionRange>;
};
type selectionCallback = (p: selectionParam) => void;
type customElementParam = {
define?: {
name: string;
};
};
type customElementCallback = (c: customElementParam) => void;
/**
* @deprecated
*/
interface INode extends Node {
__sn: serializedNodeWithId;
}
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;
};
type throttleOptions = {
leading?: boolean;
trailing?: boolean;
};
type listenerHandler = () => void;
type hookResetter = () => void;
type playerMetaData = {
startTime: number;
endTime: number;
totalTime: number;
};
type actionWithDelay = {
doAction: () => void;
delay: number;
};
type Handler = (event?: unknown) => void;
type Emitter = {
on(type: string, handler: Handler): void;
emit(type: string, event?: unknown): void;
off(type: string, handler: Handler): void;
};
type Arguments<T> = T extends ((...payload: infer U) => unknown) ? U : unknown;
declare enum ReplayerEvents {
Start = "start",
Pause = "pause",
/**
* @deprecated use Play instead
*/
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"
}
type KeepIframeSrcFn = (src: string) => boolean;
declare global {
interface Window {
FontFace: typeof FontFace;
}
}
type IWindow = Window & typeof globalThis;
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
type GetTypedKeys<Obj extends object, ValueType> = TakeTypeHelper<Obj, ValueType>[keyof TakeTypeHelper<Obj, ValueType>];
type TakeTypeHelper<Obj extends object, ValueType> = { [K in keyof Obj]: Obj[K] extends ValueType ? K : never; };
type TakeTypedKeyValues<Obj extends object, Type> = Pick<Obj, TakeTypeHelper<Obj, Type>[keyof TakeTypeHelper<Obj, Type>]>;
declare enum NodeType {
Document = 0,
DocumentType = 1,
Element = 2,
Text = 3,
CDATA = 4,
Comment = 5
}
type documentNode = {
type: NodeType.Document;
childNodes: serializedNodeWithId[];
compatMode?: string;
};
type documentTypeNode = {
type: NodeType.DocumentType;
name: string;
publicId: string;
systemId: string;
};
type cssTextKeyAttr = {
_cssText?: string;
};
type attributes = cssTextKeyAttr & {
[key: string]: string | number | true | null;
};
type legacyAttributes = {
/**
* @deprecated old bug in rrweb was causing these to always be set
* @see https://github.com/rrweb-io/rrweb/pull/651
*/
selected: false;
};
type mediaAttributes = {
rr_mediaState: "played" | "paused";
rr_mediaCurrentTime: number;
/**
* for backwards compatibility this is optional but should always be set
*/
rr_mediaPlaybackRate?: number;
/**
* for backwards compatibility this is optional but should always be set
*/
rr_mediaMuted?: boolean;
/**
* for backwards compatibility this is optional but should always be set
*/
rr_mediaLoop?: boolean;
/**
* for backwards compatibility this is optional but should always be set
*/
rr_mediaVolume?: number;
};
type elementNode = {
type: NodeType.Element;
tagName: string;
attributes: attributes;
childNodes: serializedNodeWithId[];
isSVG?: true;
needBlock?: boolean;
isCustom?: true;
};
type textNode = {
type: NodeType.Text;
textContent: string;
/**
* @deprecated styles are now always snapshotted against parent <style> element
* style mutations can still happen via an added textNode, but they don't need this attribute for correct replay
*/
isStyle?: true;
};
type cdataNode = {
type: NodeType.CDATA;
textContent: "";
};
type commentNode = {
type: NodeType.Comment;
textContent: string;
};
type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
rootId?: number;
isShadowHost?: boolean;
isShadow?: boolean;
};
type serializedNodeWithId = serializedNode & {
id: number;
};
type serializedElementNodeWithId = Extract<serializedNodeWithId, Record<"type", NodeType.Element>>;
interface IMirror<TNode> {
getId(n: TNode | undefined | null): number;
getNode(id: number): TNode | null;
getIds(): number[];
getMeta(n: TNode): serializedNodeWithId | null;
removeNodeFromMap(n: TNode): void;
has(id: number): boolean;
hasNode(node: TNode): boolean;
add(n: TNode, meta: serializedNodeWithId): void;
replace(id: number, n: TNode): void;
reset(): void;
}
type DataURLOptions = Partial<{
type: string;
quality: number;
maxBase64ImageLength: number;
}>;
type PackFn = (event: eventWithTime$1) => string;
type UnpackFn = (raw: string) => eventWithTime$1;
//#endregion
//#region lib/src/extensions/replay/types/rrweb-types.d.ts
type customEventData<T = unknown> = {
tag: string;
payload: T;
href?: string;
};
//#endregion
//#region lib/src/entrypoints/rrweb-types.es.d.ts
type WithJsonLdUrl<T> = T extends customEvent$1 ? T & {
data: Pick<customEventData, 'href'>;
} : T;
type customEvent<T = unknown> = WithJsonLdUrl<customEvent$1<T>>;
type eventWithoutTime = WithJsonLdUrl<eventWithoutTime$1>;
type event = eventWithoutTime;
type eventWithTime = WithJsonLdUrl<eventWithTime$1>;
//#endregion
export { Arguments, CanvasArg, CanvasContext, CanvasMaskRegion, CanvasMasking, DataURLOptions, DeprecatedMirror, DocumentDimension, Emitter, EventType, FullscreenCustomEventTag, GetTypedKeys, Handler, ICrossOriginIframeMirror, IMirror, IWindow, ImageBitmapDataURLWorkerMessage, ImageBitmapDataURLWorkerParams, ImageBitmapDataURLWorkerResetParams, ImageBitmapDataURLWorkerResponse, IncrementalSource, KeepIframeSrcFn, MediaInteractions, MouseInteractions, NodeType, Optional, PackFn, PointerTypes, RecordPlugin, ReplayerEvents, SamplingStrategy, SelectionRange, SerializedCanvasArg, TakeTypeHelper, TakeTypedKeyValues, UnpackFn, actionWithDelay, addedNodeMutation, adoptedStyleSheetCallback, adoptedStyleSheetData, adoptedStyleSheetParam, attributeCursor, attributeMutation, attributes, blockClass, canvasEventWithTime, canvasManagerMutationCallback, canvasMutationCallback, canvasMutationCommand, canvasMutationData, canvasMutationParam, canvasMutationWithType, cdataNode, commentNode, customElementCallback, customElementData, customElementParam, customEvent, documentNode, documentTypeNode, domContentLoadedEvent, elementNode, event, eventWithTime, eventWithoutTime, fontCallback, fontData, fontParam, fullSnapshotEvent, fullscreenEventPayload, hookResetter, hooksParam, incrementalData, incrementalSnapshotEvent, inputCallback, inputData, inputValue, legacyAttributes, listenerHandler, loadedEvent, maskTextClass, mediaAttributes, mediaInteractionCallback, mediaInteractionData, mediaInteractionParam, metaEvent, mouseInteractionCallBack, mouseInteractionData, mouseMovePos, mousePosition, mousemoveCallBack, mousemoveData, mutationCallBack, mutationCallbackParam, mutationData, mutationRecord, playerMetaData, pluginEvent, removedNodeMutation, scrollCallback, scrollData, scrollPosition, selectionCallback, selectionData, selectionParam, serializedElementNodeWithId, serializedNode, serializedNodeWithId, styleDeclarationCallback, styleDeclarationData, styleDeclarationParam, styleOMValue, styleSheetAddRule, styleSheetDeleteRule, styleSheetRuleCallback, styleSheetRuleData, styleSheetRuleParam, styleValueWithPriority, textCursor, textMutation, textNode, throttleOptions, viewportResizeCallback, viewportResizeData, viewportResizeDimension };