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