moved rrweb-snapshot into packages/rrweb-snapshot

This commit is contained in:
Mark-fenng
2026-04-01 12:00:00 +08:00
parent c208a40e8e
commit 392c4bd871
53 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
export interface ParserOptions {
silent?: boolean;
source?: string;
}
export interface ParserError {
message?: string;
reason?: string;
filename?: string;
line?: number;
column?: number;
source?: string;
}
export interface Loc {
line?: number;
column?: number;
}
export interface Node {
type?: string;
parent?: Node;
position?: {
start?: Loc;
end?: Loc;
source?: string;
content?: string;
};
}
export interface Rule extends Node {
selectors?: string[];
declarations?: Array<Declaration | Comment>;
}
export interface Declaration extends Node {
property?: string;
value?: string;
}
export interface Comment extends Node {
comment?: string;
}
export interface Charset extends Node {
charset?: string;
}
export interface CustomMedia extends Node {
name?: string;
media?: string;
}
export interface Document extends Node {
document?: string;
vendor?: string;
rules?: Array<Rule | Comment | AtRule>;
}
export interface FontFace extends Node {
declarations?: Array<Declaration | Comment>;
}
export interface Host extends Node {
rules?: Array<Rule | Comment | AtRule>;
}
export interface Import extends Node {
import?: string;
}
export interface KeyFrames extends Node {
name?: string;
vendor?: string;
keyframes?: Array<KeyFrame | Comment>;
}
export interface KeyFrame extends Node {
values?: string[];
declarations?: Array<Declaration | Comment>;
}
export interface Media extends Node {
media?: string;
rules?: Array<Rule | Comment | AtRule>;
}
export interface Namespace extends Node {
namespace?: string;
}
export interface Page extends Node {
selectors?: string[];
declarations?: Array<Declaration | Comment>;
}
export interface Supports extends Node {
supports?: string;
rules?: Array<Rule | Comment | AtRule>;
}
export declare type AtRule = Charset | CustomMedia | Document | FontFace | Host | Import | KeyFrames | Media | Namespace | Page | Supports;
export interface StyleRules {
source?: string;
rules: Array<Rule | Comment | AtRule>;
parsingErrors?: ParserError[];
}
export interface Stylesheet extends Node {
stylesheet?: StyleRules;
}
export declare function parse(css: string, options?: ParserOptions): Stylesheet;

View File

@@ -0,0 +1,5 @@
import snapshot, { serializeNodeWithId, transformAttribute, visitSnapshot, cleanupSnapshot, needMaskingText, IGNORED_NODE } from './snapshot';
import rebuild, { buildNodeWithSN, addHoverClass } from './rebuild';
export * from './types';
export * from './utils';
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN, addHoverClass, transformAttribute, visitSnapshot, cleanupSnapshot, needMaskingText, IGNORED_NODE, };

View File

@@ -0,0 +1,16 @@
import { serializedNodeWithId, idNodeMap, INode } from './types';
export declare function addHoverClass(cssText: string): string;
export declare function buildNodeWithSN(n: serializedNodeWithId, options: {
doc: Document;
map: idNodeMap;
skipChild?: boolean;
hackCss: boolean;
afterAppend?: (n: INode) => unknown;
}): INode | null;
declare function rebuild(n: serializedNodeWithId, options: {
doc: Document;
onVisit?: (node: INode) => unknown;
hackCss?: boolean;
afterAppend?: (n: INode) => unknown;
}): [Node | null, idNodeMap];
export default rebuild;

View File

@@ -0,0 +1,47 @@
import { serializedNodeWithId, INode, idNodeMap, MaskInputOptions, SlimDOMOptions, MaskTextFn, MaskInputFn, KeepIframeSrcFn } from './types';
export declare const IGNORED_NODE = -2;
export declare function absoluteToStylesheet(cssText: string | null, href: string): string;
export declare function absoluteToDoc(doc: Document, attributeValue: string): string;
export declare function transformAttribute(doc: Document, tagName: string, name: string, value: string): string;
export declare function _isBlockedElement(element: HTMLElement, blockClass: string | RegExp, blockSelector: string | null): boolean;
export declare function needMaskingText(node: Node | null, maskTextClass: string | RegExp, maskTextSelector: string | null): boolean;
export declare function serializeNodeWithId(n: Node | INode, options: {
doc: Document;
map: idNodeMap;
blockClass: string | RegExp;
blockSelector: string | null;
maskTextClass: string | RegExp;
maskTextSelector: string | null;
skipChild: boolean;
inlineStylesheet: boolean;
maskInputOptions?: MaskInputOptions;
maskTextFn: MaskTextFn | undefined;
maskInputFn: MaskInputFn | undefined;
slimDOMOptions: SlimDOMOptions;
keepIframeSrcFn?: KeepIframeSrcFn;
recordCanvas?: boolean;
preserveWhiteSpace?: boolean;
onSerialize?: (n: INode) => unknown;
onIframeLoad?: (iframeINode: INode, node: serializedNodeWithId) => unknown;
iframeLoadTimeout?: number;
}): serializedNodeWithId | null;
declare function snapshot(n: Document, options?: {
blockClass?: string | RegExp;
blockSelector?: string | null;
maskTextClass?: string | RegExp;
maskTextSelector?: string | null;
inlineStylesheet?: boolean;
maskAllInputs?: boolean | MaskInputOptions;
maskTextFn?: MaskTextFn;
maskInputFn?: MaskTextFn;
slimDOM?: boolean | SlimDOMOptions;
recordCanvas?: boolean;
preserveWhiteSpace?: boolean;
onSerialize?: (n: INode) => unknown;
onIframeLoad?: (iframeINode: INode, node: serializedNodeWithId) => unknown;
iframeLoadTimeout?: number;
keepIframeSrcFn?: KeepIframeSrcFn;
}): [serializedNodeWithId | null, idNodeMap];
export declare function visitSnapshot(node: serializedNodeWithId, onVisit: (node: serializedNodeWithId) => unknown): void;
export declare function cleanupSnapshot(): void;
export default snapshot;

View File

@@ -0,0 +1,92 @@
export declare enum NodeType {
Document = 0,
DocumentType = 1,
Element = 2,
Text = 3,
CDATA = 4,
Comment = 5
}
export declare type documentNode = {
type: NodeType.Document;
childNodes: serializedNodeWithId[];
};
export declare type documentTypeNode = {
type: NodeType.DocumentType;
name: string;
publicId: string;
systemId: string;
};
export declare type attributes = {
[key: string]: string | number | boolean;
};
export declare type elementNode = {
type: NodeType.Element;
tagName: string;
attributes: attributes;
childNodes: serializedNodeWithId[];
isSVG?: true;
needBlock?: boolean;
};
export declare type textNode = {
type: NodeType.Text;
textContent: string;
isStyle?: true;
};
export declare type cdataNode = {
type: NodeType.CDATA;
textContent: '';
};
export declare type commentNode = {
type: NodeType.Comment;
textContent: string;
};
export declare type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
rootId?: number;
isShadowHost?: boolean;
isShadow?: boolean;
};
export declare type serializedNodeWithId = serializedNode & {
id: number;
};
export declare type tagMap = {
[key: string]: string;
};
export interface INode extends Node {
__sn: serializedNodeWithId;
}
export declare type idNodeMap = {
[key: number]: INode;
};
export declare type MaskInputOptions = Partial<{
color: boolean;
date: boolean;
'datetime-local': boolean;
email: boolean;
month: boolean;
number: boolean;
range: boolean;
search: boolean;
tel: boolean;
text: boolean;
time: boolean;
url: boolean;
week: boolean;
textarea: boolean;
select: boolean;
password: boolean;
}>;
export declare type SlimDOMOptions = Partial<{
script: boolean;
comment: boolean;
headFavicon: boolean;
headWhitespace: boolean;
headMetaDescKeywords: boolean;
headMetaSocial: boolean;
headMetaRobots: boolean;
headMetaHttpEquiv: boolean;
headMetaAuthorship: boolean;
headMetaVerification: boolean;
}>;
export declare type MaskTextFn = (text: string) => string;
export declare type MaskInputFn = (text: string) => string;
export declare type KeepIframeSrcFn = (src: string) => boolean;

View File

@@ -0,0 +1,10 @@
import { INode, MaskInputFn, MaskInputOptions } from './types';
export declare function isElement(n: Node | INode): n is Element;
export declare function isShadowRoot(n: Node): n is ShadowRoot;
export declare function maskInputValue({ maskInputOptions, tagName, type, value, maskInputFn, }: {
maskInputOptions: MaskInputOptions;
tagName: string;
type: string | number | boolean | null;
value: string | null;
maskInputFn?: MaskInputFn;
}): string;