import type { TimeStamp } from '@datadog/browser-core' import { elapsed, timeStampNow } from '@datadog/browser-core' import { ChangeType, RecordType, SnapshotFormat } from '../../../types' import type { AddCDataSectionNodeChange, AddDocTypeNodeChange, AddDocumentFragmentNodeChange, AddDocumentNodeChange, AddElementNodeChange, AddNodeChange, AddShadowRootNodeChange, AddTextNodeChange, AttachedStyleSheetsChange, AttributeChange, InsertionPoint, MediaInteractionType, StyleSheetMediaList, StyleSheetRules, } from '../../../types' import type { NodeId, StyleSheetId } from '../itemIds' import type { EmitRecordCallback, EmitStatsCallback } from '../record.types' import type { RecordingScope } from '../recordingScope' import type { SerializationStats } from './serializationStats' import { createSerializationStats, updateSerializationStats } from './serializationStats' import { createChangeEncoder } from './changeEncoder' export const enum SerializationKind { INITIAL_FULL_SNAPSHOT, SUBSEQUENT_FULL_SNAPSHOT, INCREMENTAL_SNAPSHOT, } type AddNodeParams = NodeChange extends [any, any, ...infer Params] ? Params : never export type ChangeSerializationTransactionCallback = (transaction: ChangeSerializationTransaction) => void /** * ChangeSerializationTransaction is used to build and emit a BrowserChangeRecord * containing a serialized snapshot of the DOM. Unlike SerializationTransaction, it * doesn't support emitting arbitrary BrowserRecords; instead, the builder methods it * exposes are used to construct a single BrowserChangeRecord which is emitted at the end * of the transaction. */ export interface ChangeSerializationTransaction { /** * Add a metric to the transaction's statistics. The aggregated statistics will be * emitted when the transaction ends. */ addMetric(metric: keyof SerializationStats, value: number): void /** Add a node to the document at the given insertion point. */ addNode(pos: InsertionPoint, nodeName: '#cdata-section', ...params: AddNodeParams): void addNode(pos: InsertionPoint, nodeName: '#doctype', ...params: AddNodeParams): void addNode(pos: InsertionPoint, nodeName: '#document', ...params: AddNodeParams): void addNode( pos: InsertionPoint, nodeName: '#document-fragment', ...params: AddNodeParams ): void addNode(pos: InsertionPoint, nodeName: '#shadow-root', ...params: AddNodeParams): void addNode(pos: InsertionPoint, nodeName: '#text', ...params: AddNodeParams): void addNode( pos: InsertionPoint, nodeName: Exclude, ...params: AddNodeParams ): void addNode(pos: InsertionPoint, nodeName: string, ...params: AddNodeParams): void /** Add a stylesheet to the document. */ addStyleSheet(rules: StyleSheetRules, mediaList?: StyleSheetMediaList, disabled?: boolean): void /** * Attach one or more stylesheets to a ,