@glimt/record 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/record.js CHANGED
@@ -1003,10 +1003,7 @@ function serializeElementNode(n2, options) {
1003
1003
  }
1004
1004
  if (tagName === "canvas" && recordCanvas) {
1005
1005
  if (n2.__context === "2d") {
1006
- console.time("canvas-blank-check");
1007
- const tempBoolean = !is2DCanvasBlank(n2);
1008
- console.timeEnd("canvas-blank-check");
1009
- if (tempBoolean) {
1006
+ if (!is2DCanvasBlank(n2)) {
1010
1007
  attributes.rr_dataURL = n2.toDataURL(
1011
1008
  dataURLOptions.type,
1012
1009
  dataURLOptions.quality
@@ -9395,7 +9392,9 @@ class MutationBuffer {
9395
9392
  __publicField(this, "processedNodeManager");
9396
9393
  __publicField(this, "unattachedDoc");
9397
9394
  __publicField(this, "processMutations", (mutations) => {
9398
- mutations.forEach(this.processMutation);
9395
+ for (const mut of mutations) {
9396
+ this.processMutation(mut);
9397
+ }
9399
9398
  this.emit();
9400
9399
  });
9401
9400
  __publicField(this, "emit", () => {
@@ -9546,34 +9545,91 @@ class MutationBuffer {
9546
9545
  addList.removeNode(node2.value);
9547
9546
  pushAdd(node2.value);
9548
9547
  }
9549
- const payload = {
9550
- texts: this.texts.map((text) => {
9551
- const n2 = text.node;
9552
- const parent = index.parentNode(n2);
9553
- if (parent && parent.tagName === "TEXTAREA") {
9554
- this.genTextAreaValueMutation(parent);
9555
- }
9556
- return {
9557
- id: this.mirror.getId(n2),
9548
+ const payloadTexts = [];
9549
+ for (const text of this.texts) {
9550
+ const n2 = text.node;
9551
+ const parent = index.parentNode(n2);
9552
+ if (parent && parent.tagName === "TEXTAREA") {
9553
+ this.genTextAreaValueMutation(parent);
9554
+ }
9555
+ const id = this.mirror.getId(n2);
9556
+ if (!addedIds.has(id) && this.mirror.has(id)) {
9557
+ payloadTexts.push({
9558
+ id,
9558
9559
  value: text.value
9559
- };
9560
- }).filter((text) => !addedIds.has(text.id)).filter((text) => this.mirror.has(text.id)),
9561
- attributes: this.attributes.map((attribute) => {
9562
- const { attributes } = attribute;
9563
- if (typeof attributes.style === "string") {
9564
- const diffAsStr = JSON.stringify(attribute.styleDiff);
9565
- const unchangedAsStr = JSON.stringify(attribute._unchangedStyles);
9566
- if (diffAsStr.length < attributes.style.length) {
9567
- if ((diffAsStr + unchangedAsStr).split("var(").length === attributes.style.split("var(").length) {
9568
- attributes.style = attribute.styleDiff;
9569
- }
9560
+ });
9561
+ }
9562
+ }
9563
+ const payloadAttributes = [];
9564
+ for (const attribute of this.attributes) {
9565
+ const { attributes } = attribute;
9566
+ if (typeof attributes.style === "string") {
9567
+ const diffAsStr = JSON.stringify(attribute.styleDiff);
9568
+ const unchangedAsStr = JSON.stringify(attribute._unchangedStyles);
9569
+ if (diffAsStr.length < attributes.style.length) {
9570
+ if ((diffAsStr + unchangedAsStr).split("var(").length === attributes.style.split("var(").length) {
9571
+ attributes.style = attribute.styleDiff;
9570
9572
  }
9571
9573
  }
9572
- return {
9573
- id: this.mirror.getId(attribute.node),
9574
+ }
9575
+ const id = this.mirror.getId(attribute.node);
9576
+ if (!addedIds.has(id) && this.mirror.has(id)) {
9577
+ payloadAttributes.push({
9578
+ id,
9574
9579
  attributes
9575
- };
9576
- }).filter((attribute) => !addedIds.has(attribute.id)).filter((attribute) => this.mirror.has(attribute.id)),
9580
+ });
9581
+ }
9582
+ }
9583
+ const payload = {
9584
+ texts: payloadTexts,
9585
+ attributes: payloadAttributes,
9586
+ //original implementation instead of "payloadTexts"
9587
+ // this.texts
9588
+ // .map((text) => {
9589
+ // const n = text.node;
9590
+ // const parent = dom.parentNode(n);
9591
+ // if (parent && (parent as Element).tagName === 'TEXTAREA') {
9592
+ // // the node is being ignored as it isn't in the mirror, so shift mutation to attributes on parent textarea
9593
+ // this.genTextAreaValueMutation(parent as HTMLTextAreaElement);
9594
+ // }
9595
+ // return {
9596
+ // id: this.mirror.getId(n),
9597
+ // value: text.value,
9598
+ // };
9599
+ // })
9600
+ // // no need to include them on added elements, as they have just been serialized with up to date attribubtes
9601
+ // .filter((text) => !addedIds.has(text.id))
9602
+ // // text mutation's id was not in the mirror map means the target node has been removed
9603
+ // .filter((text) => this.mirror.has(text.id)),
9604
+ //original implementation instead of "payloadAttributes"
9605
+ // this.attributes
9606
+ // .map((attribute) => {
9607
+ // const { attributes } = attribute;
9608
+ // if (typeof attributes.style === 'string') {
9609
+ // const diffAsStr = JSON.stringify(attribute.styleDiff);
9610
+ // const unchangedAsStr = JSON.stringify(attribute._unchangedStyles);
9611
+ // // check if the style diff is actually shorter than the regular string based mutation
9612
+ // // (which was the whole point of #464 'compact style mutation').
9613
+ // if (diffAsStr.length < attributes.style.length) {
9614
+ // // also: CSSOM fails badly when var() is present on shorthand properties, so only proceed with
9615
+ // // the compact style mutation if these have all been accounted for
9616
+ // if (
9617
+ // (diffAsStr + unchangedAsStr).split('var(').length ===
9618
+ // attributes.style.split('var(').length
9619
+ // ) {
9620
+ // attributes.style = attribute.styleDiff;
9621
+ // }
9622
+ // }
9623
+ // }
9624
+ // return {
9625
+ // id: this.mirror.getId(attribute.node),
9626
+ // attributes: attributes,
9627
+ // };
9628
+ // })
9629
+ // // no need to include them on added elements, as they have just been serialized with up to date attribubtes
9630
+ // .filter((attribute) => !addedIds.has(attribute.id))
9631
+ // // attribute mutation's id was not in the mirror map means the target node has been removed
9632
+ // .filter((attribute) => this.mirror.has(attribute.id)),
9577
9633
  removes: this.removes,
9578
9634
  adds
9579
9635
  };
@@ -9730,8 +9786,11 @@ class MutationBuffer {
9730
9786
  this.genTextAreaValueMutation(m.target);
9731
9787
  return;
9732
9788
  }
9733
- m.addedNodes.forEach((n2) => this.genAdds(n2, m.target));
9734
- m.removedNodes.forEach((n2) => {
9789
+ for (let i2 = 0; i2 < m.addedNodes.length; i2++) {
9790
+ this.genAdds(m.addedNodes[i2], m.target);
9791
+ }
9792
+ for (let i2 = 0; i2 < m.removedNodes.length; i2++) {
9793
+ const n2 = m.removedNodes[i2];
9735
9794
  const nodeId = this.mirror.getId(n2);
9736
9795
  const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9737
9796
  if (isBlocked(m.target, this.blockClass, this.blockSelector, false) || isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
@@ -9753,7 +9812,7 @@ class MutationBuffer {
9753
9812
  processRemoves(n2, this.removesSubTreeCache);
9754
9813
  }
9755
9814
  this.mapRemoves.push(n2);
9756
- });
9815
+ }
9757
9816
  break;
9758
9817
  }
9759
9818
  }
@@ -9778,12 +9837,17 @@ class MutationBuffer {
9778
9837
  this.droppedSet.delete(n2);
9779
9838
  }
9780
9839
  if (!isBlocked(n2, this.blockClass, this.blockSelector, false)) {
9781
- index.childNodes(n2).forEach((childN) => this.genAdds(childN));
9840
+ const childNodes2 = index.childNodes(n2);
9841
+ for (let i2 = 0; i2 < childNodes2.length; i2++) {
9842
+ this.genAdds(childNodes2[i2]);
9843
+ }
9782
9844
  if (hasShadowRoot(n2)) {
9783
- index.childNodes(index.shadowRoot(n2)).forEach((childN) => {
9845
+ const shadowRootChildNodes = index.childNodes(index.shadowRoot(n2));
9846
+ for (let i2 = 0; i2 < shadowRootChildNodes.length; i2++) {
9847
+ const childN = shadowRootChildNodes[i2];
9784
9848
  this.processedNodeManager.add(childN, this);
9785
9849
  this.genAdds(childN, n2);
9786
- });
9850
+ }
9787
9851
  }
9788
9852
  }
9789
9853
  });
@@ -9843,7 +9907,10 @@ class MutationBuffer {
9843
9907
  }
9844
9908
  function deepDelete(addsSet, n2) {
9845
9909
  addsSet.delete(n2);
9846
- index.childNodes(n2).forEach((childN) => deepDelete(addsSet, childN));
9910
+ const childNodes2 = index.childNodes(n2);
9911
+ for (let i2 = 0; i2 < childNodes2.length; i2++) {
9912
+ deepDelete(addsSet, childNodes2[i2]);
9913
+ }
9847
9914
  }
9848
9915
  function processRemoves(n2, cache) {
9849
9916
  const queue = [n2];
@@ -9851,7 +9918,10 @@ function processRemoves(n2, cache) {
9851
9918
  const next = queue.pop();
9852
9919
  if (cache.has(next)) continue;
9853
9920
  cache.add(next);
9854
- index.childNodes(next).forEach((n22) => queue.push(n22));
9921
+ const childNodes2 = index.childNodes(next);
9922
+ for (let i2 = 0; i2 < childNodes2.length; i2++) {
9923
+ queue.push(childNodes2[i2]);
9924
+ }
9855
9925
  }
9856
9926
  return;
9857
9927
  }