MCPcopy
hub / github.com/rrweb-io/rrweb / buildNode

Function buildNode

packages/rrweb-snapshot/src/rebuild.ts:293–542  ·  view source on GitHub ↗
(
  n: serializedNodeWithId,
  options: {
    doc: Document;
    hackCss: boolean;
    cache: BuildCache;
  },
)

Source from the content-addressed store, hash-verified

291}
292
293function buildNode(
294 n: serializedNodeWithId,
295 options: {
296 doc: Document;
297 hackCss: boolean;
298 cache: BuildCache;
299 },
300): Node | null {
301 const { doc, hackCss, cache } = options;
302 switch (n.type) {
303 case NodeType.Document:
304 return doc.implementation.createDocument(null, '', null);
305 case NodeType.DocumentType:
306 return doc.implementation.createDocumentType(
307 n.name || 'html',
308 n.publicId,
309 n.systemId,
310 );
311 case NodeType.Element: {
312 const tagName = getTagName(n);
313 let node: Element;
314 if (n.isSVG) {
315 node = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
316 } else {
317 if (
318 // If the tag name is a custom element name
319 n.isCustom &&
320 // If the browser supports custom elements
321 doc.defaultView?.customElements &&
322 // If the custom element hasn't been defined yet
323 !doc.defaultView.customElements.get(n.tagName)
324 )
325 doc.defaultView.customElements.define(
326 n.tagName,
327 class extends doc.defaultView.HTMLElement {},
328 );
329 node = doc.createElement(tagName);
330 }
331 /**
332 * Attribute names start with `rr_` are internal attributes added by rrweb.
333 * They often overwrite other attributes on the element.
334 * We need to parse them last so they can overwrite conflicting attributes.
335 */
336 const specialAttributes: { [key: string]: string | number } = {};
337 for (const name in n.attributes) {
338 if (!Object.prototype.hasOwnProperty.call(n.attributes, name)) {
339 continue;
340 }
341 let value = n.attributes[name];
342 if (
343 tagName === 'option' &&
344 name === 'selected' &&
345 (value as legacyAttributes[typeof name]) === false
346 ) {
347 // legacy fix (TODO: if `value === false` can be generated for other attrs,
348 // should we also omit those other attrs from build ?)
349 continue;
350 }

Callers 1

buildNodeWithSNFunction · 0.85

Calls 15

getTagNameFunction · 0.85
buildStyleNodeFunction · 0.85
extractFileExtensionFunction · 0.85
adaptCssForReplayFunction · 0.85
warnMethod · 0.80
createDocumentMethod · 0.65
createDocumentTypeMethod · 0.65
createElementNSMethod · 0.65
createElementMethod · 0.65
appendChildMethod · 0.65
createTextNodeMethod · 0.65
setAttributeNSMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…