core-outline 1.1.30 → 1.1.32

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/index.es.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import React, { useState, useRef, useEffect } from 'react';
3
+ import { record } from 'rrweb';
3
4
  import { v4 } from 'uuid';
4
5
 
5
6
  function _arrayLikeToArray(r, a) {
@@ -432,3926 +433,6 @@ function _unsupportedIterableToArray(r, a) {
432
433
  }
433
434
  }
434
435
 
435
- var NodeType;
436
- (function (NodeType) {
437
- NodeType[NodeType["Document"] = 0] = "Document";
438
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
439
- NodeType[NodeType["Element"] = 2] = "Element";
440
- NodeType[NodeType["Text"] = 3] = "Text";
441
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
442
- NodeType[NodeType["Comment"] = 5] = "Comment";
443
- })(NodeType || (NodeType = {}));
444
-
445
- function isElement(n) {
446
- return n.nodeType === n.ELEMENT_NODE;
447
- }
448
- function isShadowRoot(n) {
449
- var host = n === null || n === void 0 ? void 0 : n.host;
450
- return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
451
- }
452
- function isNativeShadowDom(shadowRoot) {
453
- return Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]';
454
- }
455
- function fixBrowserCompatibilityIssuesInCSS(cssText) {
456
- if (cssText.includes(' background-clip: text;') &&
457
- !cssText.includes(' -webkit-background-clip: text;')) {
458
- cssText = cssText.replace(' background-clip: text;', ' -webkit-background-clip: text; background-clip: text;');
459
- }
460
- return cssText;
461
- }
462
- function getCssRulesString(s) {
463
- try {
464
- var rules = s.rules || s.cssRules;
465
- return rules
466
- ? fixBrowserCompatibilityIssuesInCSS(Array.from(rules).map(getCssRuleString).join(''))
467
- : null;
468
- }
469
- catch (error) {
470
- return null;
471
- }
472
- }
473
- function getCssRuleString(rule) {
474
- var cssStringified = rule.cssText;
475
- if (isCSSImportRule(rule)) {
476
- try {
477
- cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
478
- }
479
- catch (_a) {
480
- }
481
- }
482
- return cssStringified;
483
- }
484
- function isCSSImportRule(rule) {
485
- return 'styleSheet' in rule;
486
- }
487
- var Mirror = (function () {
488
- function Mirror() {
489
- this.idNodeMap = new Map();
490
- this.nodeMetaMap = new WeakMap();
491
- }
492
- Mirror.prototype.getId = function (n) {
493
- var _a;
494
- if (!n)
495
- return -1;
496
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
497
- return id !== null && id !== void 0 ? id : -1;
498
- };
499
- Mirror.prototype.getNode = function (id) {
500
- return this.idNodeMap.get(id) || null;
501
- };
502
- Mirror.prototype.getIds = function () {
503
- return Array.from(this.idNodeMap.keys());
504
- };
505
- Mirror.prototype.getMeta = function (n) {
506
- return this.nodeMetaMap.get(n) || null;
507
- };
508
- Mirror.prototype.removeNodeFromMap = function (n) {
509
- var _this = this;
510
- var id = this.getId(n);
511
- this.idNodeMap["delete"](id);
512
- if (n.childNodes) {
513
- n.childNodes.forEach(function (childNode) {
514
- return _this.removeNodeFromMap(childNode);
515
- });
516
- }
517
- };
518
- Mirror.prototype.has = function (id) {
519
- return this.idNodeMap.has(id);
520
- };
521
- Mirror.prototype.hasNode = function (node) {
522
- return this.nodeMetaMap.has(node);
523
- };
524
- Mirror.prototype.add = function (n, meta) {
525
- var id = meta.id;
526
- this.idNodeMap.set(id, n);
527
- this.nodeMetaMap.set(n, meta);
528
- };
529
- Mirror.prototype.replace = function (id, n) {
530
- var oldNode = this.getNode(id);
531
- if (oldNode) {
532
- var meta = this.nodeMetaMap.get(oldNode);
533
- if (meta)
534
- this.nodeMetaMap.set(n, meta);
535
- }
536
- this.idNodeMap.set(id, n);
537
- };
538
- Mirror.prototype.reset = function () {
539
- this.idNodeMap = new Map();
540
- this.nodeMetaMap = new WeakMap();
541
- };
542
- return Mirror;
543
- }());
544
- function createMirror() {
545
- return new Mirror();
546
- }
547
- function maskInputValue(_a) {
548
- var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
549
- var text = value || '';
550
- if (maskInputOptions[tagName.toLowerCase()] ||
551
- maskInputOptions[type]) {
552
- if (maskInputFn) {
553
- text = maskInputFn(text);
554
- }
555
- else {
556
- text = '*'.repeat(text.length);
557
- }
558
- }
559
- return text;
560
- }
561
- var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
562
- function is2DCanvasBlank(canvas) {
563
- var ctx = canvas.getContext('2d');
564
- if (!ctx)
565
- return true;
566
- var chunkSize = 50;
567
- for (var x = 0; x < canvas.width; x += chunkSize) {
568
- for (var y = 0; y < canvas.height; y += chunkSize) {
569
- var getImageData = ctx.getImageData;
570
- var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
571
- ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
572
- : getImageData;
573
- var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
574
- if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
575
- return false;
576
- }
577
- }
578
- return true;
579
- }
580
-
581
- var _id = 1;
582
- var tagNameRegex = new RegExp('[^a-z0-9-_:]');
583
- var IGNORED_NODE = -2;
584
- function genId() {
585
- return _id++;
586
- }
587
- function getValidTagName(element) {
588
- if (element instanceof HTMLFormElement) {
589
- return 'form';
590
- }
591
- var processedTagName = element.tagName.toLowerCase().trim();
592
- if (tagNameRegex.test(processedTagName)) {
593
- return 'div';
594
- }
595
- return processedTagName;
596
- }
597
- function stringifyStyleSheet(sheet) {
598
- return sheet.cssRules
599
- ? Array.from(sheet.cssRules)
600
- .map(function (rule) { return rule.cssText || ''; })
601
- .join('')
602
- : '';
603
- }
604
- function extractOrigin(url) {
605
- var origin = '';
606
- if (url.indexOf('//') > -1) {
607
- origin = url.split('/').slice(0, 3).join('/');
608
- }
609
- else {
610
- origin = url.split('/')[0];
611
- }
612
- origin = origin.split('?')[0];
613
- return origin;
614
- }
615
- var canvasService;
616
- var canvasCtx;
617
- var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
618
- var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
619
- var DATA_URI = /^(data:)([^,]*),(.*)/i;
620
- function absoluteToStylesheet(cssText, href) {
621
- return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
622
- var filePath = path1 || path2 || path3;
623
- var maybeQuote = quote1 || quote2 || '';
624
- if (!filePath) {
625
- return origin;
626
- }
627
- if (!RELATIVE_PATH.test(filePath)) {
628
- return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
629
- }
630
- if (DATA_URI.test(filePath)) {
631
- return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
632
- }
633
- if (filePath[0] === '/') {
634
- return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")");
635
- }
636
- var stack = href.split('/');
637
- var parts = filePath.split('/');
638
- stack.pop();
639
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
640
- var part = parts_1[_i];
641
- if (part === '.') {
642
- continue;
643
- }
644
- else if (part === '..') {
645
- stack.pop();
646
- }
647
- else {
648
- stack.push(part);
649
- }
650
- }
651
- return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")");
652
- });
653
- }
654
- var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
655
- var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
656
- function getAbsoluteSrcsetString(doc, attributeValue) {
657
- if (attributeValue.trim() === '') {
658
- return attributeValue;
659
- }
660
- var pos = 0;
661
- function collectCharacters(regEx) {
662
- var chars;
663
- var match = regEx.exec(attributeValue.substring(pos));
664
- if (match) {
665
- chars = match[0];
666
- pos += chars.length;
667
- return chars;
668
- }
669
- return '';
670
- }
671
- var output = [];
672
- while (true) {
673
- collectCharacters(SRCSET_COMMAS_OR_SPACES);
674
- if (pos >= attributeValue.length) {
675
- break;
676
- }
677
- var url = collectCharacters(SRCSET_NOT_SPACES);
678
- if (url.slice(-1) === ',') {
679
- url = absoluteToDoc(doc, url.substring(0, url.length - 1));
680
- output.push(url);
681
- }
682
- else {
683
- var descriptorsStr = '';
684
- url = absoluteToDoc(doc, url);
685
- var inParens = false;
686
- while (true) {
687
- var c = attributeValue.charAt(pos);
688
- if (c === '') {
689
- output.push((url + descriptorsStr).trim());
690
- break;
691
- }
692
- else if (!inParens) {
693
- if (c === ',') {
694
- pos += 1;
695
- output.push((url + descriptorsStr).trim());
696
- break;
697
- }
698
- else if (c === '(') {
699
- inParens = true;
700
- }
701
- }
702
- else {
703
- if (c === ')') {
704
- inParens = false;
705
- }
706
- }
707
- descriptorsStr += c;
708
- pos += 1;
709
- }
710
- }
711
- }
712
- return output.join(', ');
713
- }
714
- function absoluteToDoc(doc, attributeValue) {
715
- if (!attributeValue || attributeValue.trim() === '') {
716
- return attributeValue;
717
- }
718
- var a = doc.createElement('a');
719
- a.href = attributeValue;
720
- return a.href;
721
- }
722
- function isSVGElement(el) {
723
- return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
724
- }
725
- function getHref() {
726
- var a = document.createElement('a');
727
- a.href = '';
728
- return a.href;
729
- }
730
- function transformAttribute(doc, tagName, name, value) {
731
- if (name === 'src' ||
732
- (name === 'href' && value && !(tagName === 'use' && value[0] === '#'))) {
733
- return absoluteToDoc(doc, value);
734
- }
735
- else if (name === 'xlink:href' && value && value[0] !== '#') {
736
- return absoluteToDoc(doc, value);
737
- }
738
- else if (name === 'background' &&
739
- value &&
740
- (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
741
- return absoluteToDoc(doc, value);
742
- }
743
- else if (name === 'srcset' && value) {
744
- return getAbsoluteSrcsetString(doc, value);
745
- }
746
- else if (name === 'style' && value) {
747
- return absoluteToStylesheet(value, getHref());
748
- }
749
- else if (tagName === 'object' && name === 'data' && value) {
750
- return absoluteToDoc(doc, value);
751
- }
752
- else {
753
- return value;
754
- }
755
- }
756
- function _isBlockedElement(element, blockClass, blockSelector) {
757
- if (typeof blockClass === 'string') {
758
- if (element.classList.contains(blockClass)) {
759
- return true;
760
- }
761
- }
762
- else {
763
- for (var eIndex = element.classList.length; eIndex--;) {
764
- var className = element.classList[eIndex];
765
- if (blockClass.test(className)) {
766
- return true;
767
- }
768
- }
769
- }
770
- if (blockSelector) {
771
- return element.matches(blockSelector);
772
- }
773
- return false;
774
- }
775
- function classMatchesRegex(node, regex, checkAncestors) {
776
- if (!node)
777
- return false;
778
- if (node.nodeType !== node.ELEMENT_NODE) {
779
- if (!checkAncestors)
780
- return false;
781
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
782
- }
783
- for (var eIndex = node.classList.length; eIndex--;) {
784
- var className = node.classList[eIndex];
785
- if (regex.test(className)) {
786
- return true;
787
- }
788
- }
789
- if (!checkAncestors)
790
- return false;
791
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
792
- }
793
- function needMaskingText(node, maskTextClass, maskTextSelector) {
794
- var el = node.nodeType === node.ELEMENT_NODE
795
- ? node
796
- : node.parentElement;
797
- if (el === null)
798
- return false;
799
- if (typeof maskTextClass === 'string') {
800
- if (el.classList.contains(maskTextClass))
801
- return true;
802
- if (el.closest(".".concat(maskTextClass)))
803
- return true;
804
- }
805
- else {
806
- if (classMatchesRegex(el, maskTextClass, true))
807
- return true;
808
- }
809
- if (maskTextSelector) {
810
- if (el.matches(maskTextSelector))
811
- return true;
812
- if (el.closest(maskTextSelector))
813
- return true;
814
- }
815
- return false;
816
- }
817
- function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
818
- var win = iframeEl.contentWindow;
819
- if (!win) {
820
- return;
821
- }
822
- var fired = false;
823
- var readyState;
824
- try {
825
- readyState = win.document.readyState;
826
- }
827
- catch (error) {
828
- return;
829
- }
830
- if (readyState !== 'complete') {
831
- var timer_1 = setTimeout(function () {
832
- if (!fired) {
833
- listener();
834
- fired = true;
835
- }
836
- }, iframeLoadTimeout);
837
- iframeEl.addEventListener('load', function () {
838
- clearTimeout(timer_1);
839
- fired = true;
840
- listener();
841
- });
842
- return;
843
- }
844
- var blankUrl = 'about:blank';
845
- if (win.location.href !== blankUrl ||
846
- iframeEl.src === blankUrl ||
847
- iframeEl.src === '') {
848
- setTimeout(listener, 0);
849
- return iframeEl.addEventListener('load', listener);
850
- }
851
- iframeEl.addEventListener('load', listener);
852
- }
853
- function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
854
- var fired = false;
855
- var styleSheetLoaded;
856
- try {
857
- styleSheetLoaded = link.sheet;
858
- }
859
- catch (error) {
860
- return;
861
- }
862
- if (styleSheetLoaded)
863
- return;
864
- var timer = setTimeout(function () {
865
- if (!fired) {
866
- listener();
867
- fired = true;
868
- }
869
- }, styleSheetLoadTimeout);
870
- link.addEventListener('load', function () {
871
- clearTimeout(timer);
872
- fired = true;
873
- listener();
874
- });
875
- }
876
- function serializeNode(n, options) {
877
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c;
878
- var rootId = getRootId(doc, mirror);
879
- switch (n.nodeType) {
880
- case n.DOCUMENT_NODE:
881
- if (n.compatMode !== 'CSS1Compat') {
882
- return {
883
- type: NodeType.Document,
884
- childNodes: [],
885
- compatMode: n.compatMode
886
- };
887
- }
888
- else {
889
- return {
890
- type: NodeType.Document,
891
- childNodes: []
892
- };
893
- }
894
- case n.DOCUMENT_TYPE_NODE:
895
- return {
896
- type: NodeType.DocumentType,
897
- name: n.name,
898
- publicId: n.publicId,
899
- systemId: n.systemId,
900
- rootId: rootId
901
- };
902
- case n.ELEMENT_NODE:
903
- return serializeElementNode(n, {
904
- doc: doc,
905
- blockClass: blockClass,
906
- blockSelector: blockSelector,
907
- inlineStylesheet: inlineStylesheet,
908
- maskInputOptions: maskInputOptions,
909
- maskInputFn: maskInputFn,
910
- dataURLOptions: dataURLOptions,
911
- inlineImages: inlineImages,
912
- recordCanvas: recordCanvas,
913
- keepIframeSrcFn: keepIframeSrcFn,
914
- newlyAddedElement: newlyAddedElement,
915
- rootId: rootId
916
- });
917
- case n.TEXT_NODE:
918
- return serializeTextNode(n, {
919
- maskTextClass: maskTextClass,
920
- maskTextSelector: maskTextSelector,
921
- maskTextFn: maskTextFn,
922
- rootId: rootId
923
- });
924
- case n.CDATA_SECTION_NODE:
925
- return {
926
- type: NodeType.CDATA,
927
- textContent: '',
928
- rootId: rootId
929
- };
930
- case n.COMMENT_NODE:
931
- return {
932
- type: NodeType.Comment,
933
- textContent: n.textContent || '',
934
- rootId: rootId
935
- };
936
- default:
937
- return false;
938
- }
939
- }
940
- function getRootId(doc, mirror) {
941
- if (!mirror.hasNode(doc))
942
- return undefined;
943
- var docId = mirror.getId(doc);
944
- return docId === 1 ? undefined : docId;
945
- }
946
- function serializeTextNode(n, options) {
947
- var _a;
948
- var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, rootId = options.rootId;
949
- var parentTagName = n.parentNode && n.parentNode.tagName;
950
- var textContent = n.textContent;
951
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
952
- var isScript = parentTagName === 'SCRIPT' ? true : undefined;
953
- if (isStyle && textContent) {
954
- try {
955
- if (n.nextSibling || n.previousSibling) {
956
- }
957
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
958
- textContent = stringifyStyleSheet(n.parentNode.sheet);
959
- }
960
- }
961
- catch (err) {
962
- console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(err), n);
963
- }
964
- textContent = absoluteToStylesheet(textContent, getHref());
965
- }
966
- if (isScript) {
967
- textContent = 'SCRIPT_PLACEHOLDER';
968
- }
969
- if (!isStyle &&
970
- !isScript &&
971
- textContent &&
972
- needMaskingText(n, maskTextClass, maskTextSelector)) {
973
- textContent = maskTextFn
974
- ? maskTextFn(textContent)
975
- : textContent.replace(/[\S]/g, '*');
976
- }
977
- return {
978
- type: NodeType.Text,
979
- textContent: textContent || '',
980
- isStyle: isStyle,
981
- rootId: rootId
982
- };
983
- }
984
- function serializeElementNode(n, options) {
985
- var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, rootId = options.rootId;
986
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
987
- var tagName = getValidTagName(n);
988
- var attributes = {};
989
- var len = n.attributes.length;
990
- for (var i = 0; i < len; i++) {
991
- var attr = n.attributes[i];
992
- attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
993
- }
994
- if (tagName === 'link' && inlineStylesheet) {
995
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
996
- return s.href === n.href;
997
- });
998
- var cssText = null;
999
- if (stylesheet) {
1000
- cssText = getCssRulesString(stylesheet);
1001
- }
1002
- if (cssText) {
1003
- delete attributes.rel;
1004
- delete attributes.href;
1005
- attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
1006
- }
1007
- }
1008
- if (tagName === 'style' &&
1009
- n.sheet &&
1010
- !(n.innerText || n.textContent || '').trim().length) {
1011
- var cssText = getCssRulesString(n.sheet);
1012
- if (cssText) {
1013
- attributes._cssText = absoluteToStylesheet(cssText, getHref());
1014
- }
1015
- }
1016
- if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
1017
- var value = n.value;
1018
- var checked = n.checked;
1019
- if (attributes.type !== 'radio' &&
1020
- attributes.type !== 'checkbox' &&
1021
- attributes.type !== 'submit' &&
1022
- attributes.type !== 'button' &&
1023
- value) {
1024
- attributes.value = maskInputValue({
1025
- type: attributes.type,
1026
- tagName: tagName,
1027
- value: value,
1028
- maskInputOptions: maskInputOptions,
1029
- maskInputFn: maskInputFn
1030
- });
1031
- }
1032
- else if (checked) {
1033
- attributes.checked = checked;
1034
- }
1035
- }
1036
- if (tagName === 'option') {
1037
- if (n.selected && !maskInputOptions['select']) {
1038
- attributes.selected = true;
1039
- }
1040
- else {
1041
- delete attributes.selected;
1042
- }
1043
- }
1044
- if (tagName === 'canvas' && recordCanvas) {
1045
- if (n.__context === '2d') {
1046
- if (!is2DCanvasBlank(n)) {
1047
- attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
1048
- }
1049
- }
1050
- else if (!('__context' in n)) {
1051
- var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
1052
- var blankCanvas = document.createElement('canvas');
1053
- blankCanvas.width = n.width;
1054
- blankCanvas.height = n.height;
1055
- var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
1056
- if (canvasDataURL !== blankCanvasDataURL) {
1057
- attributes.rr_dataURL = canvasDataURL;
1058
- }
1059
- }
1060
- }
1061
- if (tagName === 'img' && inlineImages) {
1062
- if (!canvasService) {
1063
- canvasService = doc.createElement('canvas');
1064
- canvasCtx = canvasService.getContext('2d');
1065
- }
1066
- var image_1 = n;
1067
- var oldValue_1 = image_1.crossOrigin;
1068
- image_1.crossOrigin = 'anonymous';
1069
- var recordInlineImage = function () {
1070
- try {
1071
- canvasService.width = image_1.naturalWidth;
1072
- canvasService.height = image_1.naturalHeight;
1073
- canvasCtx.drawImage(image_1, 0, 0);
1074
- attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
1075
- }
1076
- catch (err) {
1077
- console.warn("Cannot inline img src=".concat(image_1.currentSrc, "! Error: ").concat(err));
1078
- }
1079
- oldValue_1
1080
- ? (attributes.crossOrigin = oldValue_1)
1081
- : image_1.removeAttribute('crossorigin');
1082
- };
1083
- if (image_1.complete && image_1.naturalWidth !== 0)
1084
- recordInlineImage();
1085
- else
1086
- image_1.onload = recordInlineImage;
1087
- }
1088
- if (tagName === 'audio' || tagName === 'video') {
1089
- attributes.rr_mediaState = n.paused
1090
- ? 'paused'
1091
- : 'played';
1092
- attributes.rr_mediaCurrentTime = n.currentTime;
1093
- }
1094
- if (!newlyAddedElement) {
1095
- if (n.scrollLeft) {
1096
- attributes.rr_scrollLeft = n.scrollLeft;
1097
- }
1098
- if (n.scrollTop) {
1099
- attributes.rr_scrollTop = n.scrollTop;
1100
- }
1101
- }
1102
- if (needBlock) {
1103
- var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
1104
- attributes = {
1105
- "class": attributes["class"],
1106
- rr_width: "".concat(width, "px"),
1107
- rr_height: "".concat(height, "px")
1108
- };
1109
- }
1110
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
1111
- if (!n.contentDocument) {
1112
- attributes.rr_src = attributes.src;
1113
- }
1114
- delete attributes.src;
1115
- }
1116
- return {
1117
- type: NodeType.Element,
1118
- tagName: tagName,
1119
- attributes: attributes,
1120
- childNodes: [],
1121
- isSVG: isSVGElement(n) || undefined,
1122
- needBlock: needBlock,
1123
- rootId: rootId
1124
- };
1125
- }
1126
- function lowerIfExists(maybeAttr) {
1127
- if (maybeAttr === undefined) {
1128
- return '';
1129
- }
1130
- else {
1131
- return maybeAttr.toLowerCase();
1132
- }
1133
- }
1134
- function slimDOMExcluded(sn, slimDOMOptions) {
1135
- if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
1136
- return true;
1137
- }
1138
- else if (sn.type === NodeType.Element) {
1139
- if (slimDOMOptions.script &&
1140
- (sn.tagName === 'script' ||
1141
- (sn.tagName === 'link' &&
1142
- sn.attributes.rel === 'preload' &&
1143
- sn.attributes.as === 'script') ||
1144
- (sn.tagName === 'link' &&
1145
- sn.attributes.rel === 'prefetch' &&
1146
- typeof sn.attributes.href === 'string' &&
1147
- sn.attributes.href.endsWith('.js')))) {
1148
- return true;
1149
- }
1150
- else if (slimDOMOptions.headFavicon &&
1151
- ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
1152
- (sn.tagName === 'meta' &&
1153
- (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
1154
- lowerIfExists(sn.attributes.name) === 'application-name' ||
1155
- lowerIfExists(sn.attributes.rel) === 'icon' ||
1156
- lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
1157
- lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
1158
- return true;
1159
- }
1160
- else if (sn.tagName === 'meta') {
1161
- if (slimDOMOptions.headMetaDescKeywords &&
1162
- lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
1163
- return true;
1164
- }
1165
- else if (slimDOMOptions.headMetaSocial &&
1166
- (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
1167
- lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
1168
- lowerIfExists(sn.attributes.name) === 'pinterest')) {
1169
- return true;
1170
- }
1171
- else if (slimDOMOptions.headMetaRobots &&
1172
- (lowerIfExists(sn.attributes.name) === 'robots' ||
1173
- lowerIfExists(sn.attributes.name) === 'googlebot' ||
1174
- lowerIfExists(sn.attributes.name) === 'bingbot')) {
1175
- return true;
1176
- }
1177
- else if (slimDOMOptions.headMetaHttpEquiv &&
1178
- sn.attributes['http-equiv'] !== undefined) {
1179
- return true;
1180
- }
1181
- else if (slimDOMOptions.headMetaAuthorship &&
1182
- (lowerIfExists(sn.attributes.name) === 'author' ||
1183
- lowerIfExists(sn.attributes.name) === 'generator' ||
1184
- lowerIfExists(sn.attributes.name) === 'framework' ||
1185
- lowerIfExists(sn.attributes.name) === 'publisher' ||
1186
- lowerIfExists(sn.attributes.name) === 'progid' ||
1187
- lowerIfExists(sn.attributes.property).match(/^article:/) ||
1188
- lowerIfExists(sn.attributes.property).match(/^product:/))) {
1189
- return true;
1190
- }
1191
- else if (slimDOMOptions.headMetaVerification &&
1192
- (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
1193
- lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
1194
- lowerIfExists(sn.attributes.name) === 'csrf-token' ||
1195
- lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
1196
- lowerIfExists(sn.attributes.name) === 'verify-v1' ||
1197
- lowerIfExists(sn.attributes.name) === 'verification' ||
1198
- lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
1199
- return true;
1200
- }
1201
- }
1202
- }
1203
- return false;
1204
- }
1205
- function serializeNodeWithId(n, options) {
1206
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, onStylesheetLoad = options.onStylesheetLoad, _h = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _h === void 0 ? 5000 : _h, _j = options.keepIframeSrcFn, keepIframeSrcFn = _j === void 0 ? function () { return false; } : _j, _k = options.newlyAddedElement, newlyAddedElement = _k === void 0 ? false : _k;
1207
- var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
1208
- var _serializedNode = serializeNode(n, {
1209
- doc: doc,
1210
- mirror: mirror,
1211
- blockClass: blockClass,
1212
- blockSelector: blockSelector,
1213
- maskTextClass: maskTextClass,
1214
- maskTextSelector: maskTextSelector,
1215
- inlineStylesheet: inlineStylesheet,
1216
- maskInputOptions: maskInputOptions,
1217
- maskTextFn: maskTextFn,
1218
- maskInputFn: maskInputFn,
1219
- dataURLOptions: dataURLOptions,
1220
- inlineImages: inlineImages,
1221
- recordCanvas: recordCanvas,
1222
- keepIframeSrcFn: keepIframeSrcFn,
1223
- newlyAddedElement: newlyAddedElement
1224
- });
1225
- if (!_serializedNode) {
1226
- console.warn(n, 'not serialized');
1227
- return null;
1228
- }
1229
- var id;
1230
- if (mirror.hasNode(n)) {
1231
- id = mirror.getId(n);
1232
- }
1233
- else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
1234
- (!preserveWhiteSpace &&
1235
- _serializedNode.type === NodeType.Text &&
1236
- !_serializedNode.isStyle &&
1237
- !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
1238
- id = IGNORED_NODE;
1239
- }
1240
- else {
1241
- id = genId();
1242
- }
1243
- var serializedNode = Object.assign(_serializedNode, { id: id });
1244
- mirror.add(n, serializedNode);
1245
- if (id === IGNORED_NODE) {
1246
- return null;
1247
- }
1248
- if (onSerialize) {
1249
- onSerialize(n);
1250
- }
1251
- var recordChild = !skipChild;
1252
- if (serializedNode.type === NodeType.Element) {
1253
- recordChild = recordChild && !serializedNode.needBlock;
1254
- delete serializedNode.needBlock;
1255
- var shadowRoot = n.shadowRoot;
1256
- if (shadowRoot && isNativeShadowDom(shadowRoot))
1257
- serializedNode.isShadowHost = true;
1258
- }
1259
- if ((serializedNode.type === NodeType.Document ||
1260
- serializedNode.type === NodeType.Element) &&
1261
- recordChild) {
1262
- if (slimDOMOptions.headWhitespace &&
1263
- serializedNode.type === NodeType.Element &&
1264
- serializedNode.tagName === 'head') {
1265
- preserveWhiteSpace = false;
1266
- }
1267
- var bypassOptions = {
1268
- doc: doc,
1269
- mirror: mirror,
1270
- blockClass: blockClass,
1271
- blockSelector: blockSelector,
1272
- maskTextClass: maskTextClass,
1273
- maskTextSelector: maskTextSelector,
1274
- skipChild: skipChild,
1275
- inlineStylesheet: inlineStylesheet,
1276
- maskInputOptions: maskInputOptions,
1277
- maskTextFn: maskTextFn,
1278
- maskInputFn: maskInputFn,
1279
- slimDOMOptions: slimDOMOptions,
1280
- dataURLOptions: dataURLOptions,
1281
- inlineImages: inlineImages,
1282
- recordCanvas: recordCanvas,
1283
- preserveWhiteSpace: preserveWhiteSpace,
1284
- onSerialize: onSerialize,
1285
- onIframeLoad: onIframeLoad,
1286
- iframeLoadTimeout: iframeLoadTimeout,
1287
- onStylesheetLoad: onStylesheetLoad,
1288
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1289
- keepIframeSrcFn: keepIframeSrcFn
1290
- };
1291
- for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
1292
- var childN = _m[_i];
1293
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1294
- if (serializedChildNode) {
1295
- serializedNode.childNodes.push(serializedChildNode);
1296
- }
1297
- }
1298
- if (isElement(n) && n.shadowRoot) {
1299
- for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
1300
- var childN = _p[_o];
1301
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1302
- if (serializedChildNode) {
1303
- isNativeShadowDom(n.shadowRoot) &&
1304
- (serializedChildNode.isShadow = true);
1305
- serializedNode.childNodes.push(serializedChildNode);
1306
- }
1307
- }
1308
- }
1309
- }
1310
- if (n.parentNode &&
1311
- isShadowRoot(n.parentNode) &&
1312
- isNativeShadowDom(n.parentNode)) {
1313
- serializedNode.isShadow = true;
1314
- }
1315
- if (serializedNode.type === NodeType.Element &&
1316
- serializedNode.tagName === 'iframe') {
1317
- onceIframeLoaded(n, function () {
1318
- var iframeDoc = n.contentDocument;
1319
- if (iframeDoc && onIframeLoad) {
1320
- var serializedIframeNode = serializeNodeWithId(iframeDoc, {
1321
- doc: iframeDoc,
1322
- mirror: mirror,
1323
- blockClass: blockClass,
1324
- blockSelector: blockSelector,
1325
- maskTextClass: maskTextClass,
1326
- maskTextSelector: maskTextSelector,
1327
- skipChild: false,
1328
- inlineStylesheet: inlineStylesheet,
1329
- maskInputOptions: maskInputOptions,
1330
- maskTextFn: maskTextFn,
1331
- maskInputFn: maskInputFn,
1332
- slimDOMOptions: slimDOMOptions,
1333
- dataURLOptions: dataURLOptions,
1334
- inlineImages: inlineImages,
1335
- recordCanvas: recordCanvas,
1336
- preserveWhiteSpace: preserveWhiteSpace,
1337
- onSerialize: onSerialize,
1338
- onIframeLoad: onIframeLoad,
1339
- iframeLoadTimeout: iframeLoadTimeout,
1340
- onStylesheetLoad: onStylesheetLoad,
1341
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1342
- keepIframeSrcFn: keepIframeSrcFn
1343
- });
1344
- if (serializedIframeNode) {
1345
- onIframeLoad(n, serializedIframeNode);
1346
- }
1347
- }
1348
- }, iframeLoadTimeout);
1349
- }
1350
- if (serializedNode.type === NodeType.Element &&
1351
- serializedNode.tagName === 'link' &&
1352
- serializedNode.attributes.rel === 'stylesheet') {
1353
- onceStylesheetLoaded(n, function () {
1354
- if (onStylesheetLoad) {
1355
- var serializedLinkNode = serializeNodeWithId(n, {
1356
- doc: doc,
1357
- mirror: mirror,
1358
- blockClass: blockClass,
1359
- blockSelector: blockSelector,
1360
- maskTextClass: maskTextClass,
1361
- maskTextSelector: maskTextSelector,
1362
- skipChild: false,
1363
- inlineStylesheet: inlineStylesheet,
1364
- maskInputOptions: maskInputOptions,
1365
- maskTextFn: maskTextFn,
1366
- maskInputFn: maskInputFn,
1367
- slimDOMOptions: slimDOMOptions,
1368
- dataURLOptions: dataURLOptions,
1369
- inlineImages: inlineImages,
1370
- recordCanvas: recordCanvas,
1371
- preserveWhiteSpace: preserveWhiteSpace,
1372
- onSerialize: onSerialize,
1373
- onIframeLoad: onIframeLoad,
1374
- iframeLoadTimeout: iframeLoadTimeout,
1375
- onStylesheetLoad: onStylesheetLoad,
1376
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1377
- keepIframeSrcFn: keepIframeSrcFn
1378
- });
1379
- if (serializedLinkNode) {
1380
- onStylesheetLoad(n, serializedLinkNode);
1381
- }
1382
- }
1383
- }, stylesheetLoadTimeout);
1384
- }
1385
- return serializedNode;
1386
- }
1387
- function snapshot(n, options) {
1388
- var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror() : _b, _c = _a.blockClass, blockClass = _c === void 0 ? 'rr-block' : _c, _d = _a.blockSelector, blockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'rr-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.inlineStylesheet, inlineStylesheet = _g === void 0 ? true : _g, _h = _a.inlineImages, inlineImages = _h === void 0 ? false : _h, _j = _a.recordCanvas, recordCanvas = _j === void 0 ? false : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? false : _k, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _l = _a.slimDOM, slimDOM = _l === void 0 ? false : _l, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, onStylesheetLoad = _a.onStylesheetLoad, stylesheetLoadTimeout = _a.stylesheetLoadTimeout, _m = _a.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m;
1389
- var maskInputOptions = maskAllInputs === true
1390
- ? {
1391
- color: true,
1392
- date: true,
1393
- 'datetime-local': true,
1394
- email: true,
1395
- month: true,
1396
- number: true,
1397
- range: true,
1398
- search: true,
1399
- tel: true,
1400
- text: true,
1401
- time: true,
1402
- url: true,
1403
- week: true,
1404
- textarea: true,
1405
- select: true,
1406
- password: true
1407
- }
1408
- : maskAllInputs === false
1409
- ? {
1410
- password: true
1411
- }
1412
- : maskAllInputs;
1413
- var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1414
- ?
1415
- {
1416
- script: true,
1417
- comment: true,
1418
- headFavicon: true,
1419
- headWhitespace: true,
1420
- headMetaDescKeywords: slimDOM === 'all',
1421
- headMetaSocial: true,
1422
- headMetaRobots: true,
1423
- headMetaHttpEquiv: true,
1424
- headMetaAuthorship: true,
1425
- headMetaVerification: true
1426
- }
1427
- : slimDOM === false
1428
- ? {}
1429
- : slimDOM;
1430
- return serializeNodeWithId(n, {
1431
- doc: n,
1432
- mirror: mirror,
1433
- blockClass: blockClass,
1434
- blockSelector: blockSelector,
1435
- maskTextClass: maskTextClass,
1436
- maskTextSelector: maskTextSelector,
1437
- skipChild: false,
1438
- inlineStylesheet: inlineStylesheet,
1439
- maskInputOptions: maskInputOptions,
1440
- maskTextFn: maskTextFn,
1441
- maskInputFn: maskInputFn,
1442
- slimDOMOptions: slimDOMOptions,
1443
- dataURLOptions: dataURLOptions,
1444
- inlineImages: inlineImages,
1445
- recordCanvas: recordCanvas,
1446
- preserveWhiteSpace: preserveWhiteSpace,
1447
- onSerialize: onSerialize,
1448
- onIframeLoad: onIframeLoad,
1449
- iframeLoadTimeout: iframeLoadTimeout,
1450
- onStylesheetLoad: onStylesheetLoad,
1451
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1452
- keepIframeSrcFn: keepIframeSrcFn,
1453
- newlyAddedElement: false
1454
- });
1455
- }
1456
-
1457
- function on(type, fn, target = document) {
1458
- const options = { capture: true, passive: true };
1459
- target.addEventListener(type, fn, options);
1460
- return () => target.removeEventListener(type, fn, options);
1461
- }
1462
- const DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
1463
- '\r\n' +
1464
- 'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
1465
- '\r\n' +
1466
- 'or you can use record.mirror to access the mirror instance during recording.';
1467
- let _mirror = {
1468
- map: {},
1469
- getId() {
1470
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1471
- return -1;
1472
- },
1473
- getNode() {
1474
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1475
- return null;
1476
- },
1477
- removeNodeFromMap() {
1478
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1479
- },
1480
- has() {
1481
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1482
- return false;
1483
- },
1484
- reset() {
1485
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1486
- },
1487
- };
1488
- if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
1489
- _mirror = new Proxy(_mirror, {
1490
- get(target, prop, receiver) {
1491
- if (prop === 'map') {
1492
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
1493
- }
1494
- return Reflect.get(target, prop, receiver);
1495
- },
1496
- });
1497
- }
1498
- function throttle(func, wait, options = {}) {
1499
- let timeout = null;
1500
- let previous = 0;
1501
- return function (...args) {
1502
- const now = Date.now();
1503
- if (!previous && options.leading === false) {
1504
- previous = now;
1505
- }
1506
- const remaining = wait - (now - previous);
1507
- const context = this;
1508
- if (remaining <= 0 || remaining > wait) {
1509
- if (timeout) {
1510
- clearTimeout(timeout);
1511
- timeout = null;
1512
- }
1513
- previous = now;
1514
- func.apply(context, args);
1515
- }
1516
- else if (!timeout && options.trailing !== false) {
1517
- timeout = setTimeout(() => {
1518
- previous = options.leading === false ? 0 : Date.now();
1519
- timeout = null;
1520
- func.apply(context, args);
1521
- }, remaining);
1522
- }
1523
- };
1524
- }
1525
- function hookSetter(target, key, d, isRevoked, win = window) {
1526
- const original = win.Object.getOwnPropertyDescriptor(target, key);
1527
- win.Object.defineProperty(target, key, isRevoked
1528
- ? d
1529
- : {
1530
- set(value) {
1531
- setTimeout(() => {
1532
- d.set.call(this, value);
1533
- }, 0);
1534
- if (original && original.set) {
1535
- original.set.call(this, value);
1536
- }
1537
- },
1538
- });
1539
- return () => hookSetter(target, key, original || {}, true);
1540
- }
1541
- function patch(source, name, replacement) {
1542
- try {
1543
- if (!(name in source)) {
1544
- return () => {
1545
- };
1546
- }
1547
- const original = source[name];
1548
- const wrapped = replacement(original);
1549
- if (typeof wrapped === 'function') {
1550
- wrapped.prototype = wrapped.prototype || {};
1551
- Object.defineProperties(wrapped, {
1552
- __rrweb_original__: {
1553
- enumerable: false,
1554
- value: original,
1555
- },
1556
- });
1557
- }
1558
- source[name] = wrapped;
1559
- return () => {
1560
- source[name] = original;
1561
- };
1562
- }
1563
- catch (_a) {
1564
- return () => {
1565
- };
1566
- }
1567
- }
1568
- function getWindowHeight() {
1569
- return (window.innerHeight ||
1570
- (document.documentElement && document.documentElement.clientHeight) ||
1571
- (document.body && document.body.clientHeight));
1572
- }
1573
- function getWindowWidth() {
1574
- return (window.innerWidth ||
1575
- (document.documentElement && document.documentElement.clientWidth) ||
1576
- (document.body && document.body.clientWidth));
1577
- }
1578
- function isBlocked(node, blockClass, blockSelector, checkAncestors) {
1579
- if (!node) {
1580
- return false;
1581
- }
1582
- const el = node.nodeType === node.ELEMENT_NODE
1583
- ? node
1584
- : node.parentElement;
1585
- if (!el)
1586
- return false;
1587
- if (typeof blockClass === 'string') {
1588
- if (el.classList.contains(blockClass))
1589
- return true;
1590
- if (checkAncestors && el.closest('.' + blockClass) !== null)
1591
- return true;
1592
- }
1593
- else {
1594
- if (classMatchesRegex(el, blockClass, checkAncestors))
1595
- return true;
1596
- }
1597
- if (blockSelector) {
1598
- if (node.matches(blockSelector))
1599
- return true;
1600
- if (checkAncestors && el.closest(blockSelector) !== null)
1601
- return true;
1602
- }
1603
- return false;
1604
- }
1605
- function isSerialized(n, mirror) {
1606
- return mirror.getId(n) !== -1;
1607
- }
1608
- function isIgnored(n, mirror) {
1609
- return mirror.getId(n) === IGNORED_NODE;
1610
- }
1611
- function isAncestorRemoved(target, mirror) {
1612
- if (isShadowRoot(target)) {
1613
- return false;
1614
- }
1615
- const id = mirror.getId(target);
1616
- if (!mirror.has(id)) {
1617
- return true;
1618
- }
1619
- if (target.parentNode &&
1620
- target.parentNode.nodeType === target.DOCUMENT_NODE) {
1621
- return false;
1622
- }
1623
- if (!target.parentNode) {
1624
- return true;
1625
- }
1626
- return isAncestorRemoved(target.parentNode, mirror);
1627
- }
1628
- function isTouchEvent(event) {
1629
- return Boolean(event.changedTouches);
1630
- }
1631
- function polyfill(win = window) {
1632
- if ('NodeList' in win && !win.NodeList.prototype.forEach) {
1633
- win.NodeList.prototype.forEach = Array.prototype
1634
- .forEach;
1635
- }
1636
- if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
1637
- win.DOMTokenList.prototype.forEach = Array.prototype
1638
- .forEach;
1639
- }
1640
- if (!Node.prototype.contains) {
1641
- Node.prototype.contains = (...args) => {
1642
- let node = args[0];
1643
- if (!(0 in args)) {
1644
- throw new TypeError('1 argument is required');
1645
- }
1646
- do {
1647
- if (this === node) {
1648
- return true;
1649
- }
1650
- } while ((node = node && node.parentNode));
1651
- return false;
1652
- };
1653
- }
1654
- }
1655
- function isSerializedIframe(n, mirror) {
1656
- return Boolean(n.nodeName === 'IFRAME' && mirror.getMeta(n));
1657
- }
1658
- function isSerializedStylesheet(n, mirror) {
1659
- return Boolean(n.nodeName === 'LINK' &&
1660
- n.nodeType === n.ELEMENT_NODE &&
1661
- n.getAttribute &&
1662
- n.getAttribute('rel') === 'stylesheet' &&
1663
- mirror.getMeta(n));
1664
- }
1665
- function hasShadowRoot(n) {
1666
- return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
1667
- }
1668
- class StyleSheetMirror {
1669
- constructor() {
1670
- this.id = 1;
1671
- this.styleIDMap = new WeakMap();
1672
- this.idStyleMap = new Map();
1673
- }
1674
- getId(stylesheet) {
1675
- var _a;
1676
- return (_a = this.styleIDMap.get(stylesheet)) !== null && _a !== void 0 ? _a : -1;
1677
- }
1678
- has(stylesheet) {
1679
- return this.styleIDMap.has(stylesheet);
1680
- }
1681
- add(stylesheet, id) {
1682
- if (this.has(stylesheet))
1683
- return this.getId(stylesheet);
1684
- let newId;
1685
- if (id === undefined) {
1686
- newId = this.id++;
1687
- }
1688
- else
1689
- newId = id;
1690
- this.styleIDMap.set(stylesheet, newId);
1691
- this.idStyleMap.set(newId, stylesheet);
1692
- return newId;
1693
- }
1694
- getStyle(id) {
1695
- return this.idStyleMap.get(id) || null;
1696
- }
1697
- reset() {
1698
- this.styleIDMap = new WeakMap();
1699
- this.idStyleMap = new Map();
1700
- this.id = 1;
1701
- }
1702
- generateId() {
1703
- return this.id++;
1704
- }
1705
- }
1706
-
1707
- var EventType = /* @__PURE__ */ ((EventType2) => {
1708
- EventType2[EventType2["DomContentLoaded"] = 0] = "DomContentLoaded";
1709
- EventType2[EventType2["Load"] = 1] = "Load";
1710
- EventType2[EventType2["FullSnapshot"] = 2] = "FullSnapshot";
1711
- EventType2[EventType2["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
1712
- EventType2[EventType2["Meta"] = 4] = "Meta";
1713
- EventType2[EventType2["Custom"] = 5] = "Custom";
1714
- EventType2[EventType2["Plugin"] = 6] = "Plugin";
1715
- return EventType2;
1716
- })(EventType || {});
1717
- var IncrementalSource = /* @__PURE__ */ ((IncrementalSource2) => {
1718
- IncrementalSource2[IncrementalSource2["Mutation"] = 0] = "Mutation";
1719
- IncrementalSource2[IncrementalSource2["MouseMove"] = 1] = "MouseMove";
1720
- IncrementalSource2[IncrementalSource2["MouseInteraction"] = 2] = "MouseInteraction";
1721
- IncrementalSource2[IncrementalSource2["Scroll"] = 3] = "Scroll";
1722
- IncrementalSource2[IncrementalSource2["ViewportResize"] = 4] = "ViewportResize";
1723
- IncrementalSource2[IncrementalSource2["Input"] = 5] = "Input";
1724
- IncrementalSource2[IncrementalSource2["TouchMove"] = 6] = "TouchMove";
1725
- IncrementalSource2[IncrementalSource2["MediaInteraction"] = 7] = "MediaInteraction";
1726
- IncrementalSource2[IncrementalSource2["StyleSheetRule"] = 8] = "StyleSheetRule";
1727
- IncrementalSource2[IncrementalSource2["CanvasMutation"] = 9] = "CanvasMutation";
1728
- IncrementalSource2[IncrementalSource2["Font"] = 10] = "Font";
1729
- IncrementalSource2[IncrementalSource2["Log"] = 11] = "Log";
1730
- IncrementalSource2[IncrementalSource2["Drag"] = 12] = "Drag";
1731
- IncrementalSource2[IncrementalSource2["StyleDeclaration"] = 13] = "StyleDeclaration";
1732
- IncrementalSource2[IncrementalSource2["Selection"] = 14] = "Selection";
1733
- IncrementalSource2[IncrementalSource2["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
1734
- return IncrementalSource2;
1735
- })(IncrementalSource || {});
1736
- var MouseInteractions = /* @__PURE__ */ ((MouseInteractions2) => {
1737
- MouseInteractions2[MouseInteractions2["MouseUp"] = 0] = "MouseUp";
1738
- MouseInteractions2[MouseInteractions2["MouseDown"] = 1] = "MouseDown";
1739
- MouseInteractions2[MouseInteractions2["Click"] = 2] = "Click";
1740
- MouseInteractions2[MouseInteractions2["ContextMenu"] = 3] = "ContextMenu";
1741
- MouseInteractions2[MouseInteractions2["DblClick"] = 4] = "DblClick";
1742
- MouseInteractions2[MouseInteractions2["Focus"] = 5] = "Focus";
1743
- MouseInteractions2[MouseInteractions2["Blur"] = 6] = "Blur";
1744
- MouseInteractions2[MouseInteractions2["TouchStart"] = 7] = "TouchStart";
1745
- MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 8] = "TouchMove_Departed";
1746
- MouseInteractions2[MouseInteractions2["TouchEnd"] = 9] = "TouchEnd";
1747
- MouseInteractions2[MouseInteractions2["TouchCancel"] = 10] = "TouchCancel";
1748
- return MouseInteractions2;
1749
- })(MouseInteractions || {});
1750
- var CanvasContext = /* @__PURE__ */ ((CanvasContext2) => {
1751
- CanvasContext2[CanvasContext2["2D"] = 0] = "2D";
1752
- CanvasContext2[CanvasContext2["WebGL"] = 1] = "WebGL";
1753
- CanvasContext2[CanvasContext2["WebGL2"] = 2] = "WebGL2";
1754
- return CanvasContext2;
1755
- })(CanvasContext || {});
1756
-
1757
- function isNodeInLinkedList(n) {
1758
- return '__ln' in n;
1759
- }
1760
- class DoubleLinkedList {
1761
- constructor() {
1762
- this.length = 0;
1763
- this.head = null;
1764
- }
1765
- get(position) {
1766
- if (position >= this.length) {
1767
- throw new Error('Position outside of list range');
1768
- }
1769
- let current = this.head;
1770
- for (let index = 0; index < position; index++) {
1771
- current = (current === null || current === void 0 ? void 0 : current.next) || null;
1772
- }
1773
- return current;
1774
- }
1775
- addNode(n) {
1776
- const node = {
1777
- value: n,
1778
- previous: null,
1779
- next: null,
1780
- };
1781
- n.__ln = node;
1782
- if (n.previousSibling && isNodeInLinkedList(n.previousSibling)) {
1783
- const current = n.previousSibling.__ln.next;
1784
- node.next = current;
1785
- node.previous = n.previousSibling.__ln;
1786
- n.previousSibling.__ln.next = node;
1787
- if (current) {
1788
- current.previous = node;
1789
- }
1790
- }
1791
- else if (n.nextSibling &&
1792
- isNodeInLinkedList(n.nextSibling) &&
1793
- n.nextSibling.__ln.previous) {
1794
- const current = n.nextSibling.__ln.previous;
1795
- node.previous = current;
1796
- node.next = n.nextSibling.__ln;
1797
- n.nextSibling.__ln.previous = node;
1798
- if (current) {
1799
- current.next = node;
1800
- }
1801
- }
1802
- else {
1803
- if (this.head) {
1804
- this.head.previous = node;
1805
- }
1806
- node.next = this.head;
1807
- this.head = node;
1808
- }
1809
- this.length++;
1810
- }
1811
- removeNode(n) {
1812
- const current = n.__ln;
1813
- if (!this.head) {
1814
- return;
1815
- }
1816
- if (!current.previous) {
1817
- this.head = current.next;
1818
- if (this.head) {
1819
- this.head.previous = null;
1820
- }
1821
- }
1822
- else {
1823
- current.previous.next = current.next;
1824
- if (current.next) {
1825
- current.next.previous = current.previous;
1826
- }
1827
- }
1828
- if (n.__ln) {
1829
- delete n.__ln;
1830
- }
1831
- this.length--;
1832
- }
1833
- }
1834
- const moveKey = (id, parentId) => `${id}@${parentId}`;
1835
- class MutationBuffer {
1836
- constructor() {
1837
- this.frozen = false;
1838
- this.locked = false;
1839
- this.texts = [];
1840
- this.attributes = [];
1841
- this.removes = [];
1842
- this.mapRemoves = [];
1843
- this.movedMap = {};
1844
- this.addedSet = new Set();
1845
- this.movedSet = new Set();
1846
- this.droppedSet = new Set();
1847
- this.processMutations = (mutations) => {
1848
- mutations.forEach(this.processMutation);
1849
- this.emit();
1850
- };
1851
- this.emit = () => {
1852
- if (this.frozen || this.locked) {
1853
- return;
1854
- }
1855
- const adds = [];
1856
- const addList = new DoubleLinkedList();
1857
- const getNextId = (n) => {
1858
- let ns = n;
1859
- let nextId = IGNORED_NODE;
1860
- while (nextId === IGNORED_NODE) {
1861
- ns = ns && ns.nextSibling;
1862
- nextId = ns && this.mirror.getId(ns);
1863
- }
1864
- return nextId;
1865
- };
1866
- const pushAdd = (n) => {
1867
- var _a, _b, _c, _d;
1868
- let shadowHost = null;
1869
- if (((_b = (_a = n.getRootNode) === null || _a === void 0 ? void 0 : _a.call(n)) === null || _b === void 0 ? void 0 : _b.nodeType) === Node.DOCUMENT_FRAGMENT_NODE &&
1870
- n.getRootNode().host)
1871
- shadowHost = n.getRootNode().host;
1872
- let rootShadowHost = shadowHost;
1873
- while (((_d = (_c = rootShadowHost === null || rootShadowHost === void 0 ? void 0 : rootShadowHost.getRootNode) === null || _c === void 0 ? void 0 : _c.call(rootShadowHost)) === null || _d === void 0 ? void 0 : _d.nodeType) ===
1874
- Node.DOCUMENT_FRAGMENT_NODE &&
1875
- rootShadowHost.getRootNode().host)
1876
- rootShadowHost = rootShadowHost.getRootNode().host;
1877
- const notInDoc = !this.doc.contains(n) &&
1878
- (!rootShadowHost || !this.doc.contains(rootShadowHost));
1879
- if (!n.parentNode || notInDoc) {
1880
- return;
1881
- }
1882
- const parentId = isShadowRoot(n.parentNode)
1883
- ? this.mirror.getId(shadowHost)
1884
- : this.mirror.getId(n.parentNode);
1885
- const nextId = getNextId(n);
1886
- if (parentId === -1 || nextId === -1) {
1887
- return addList.addNode(n);
1888
- }
1889
- const sn = serializeNodeWithId(n, {
1890
- doc: this.doc,
1891
- mirror: this.mirror,
1892
- blockClass: this.blockClass,
1893
- blockSelector: this.blockSelector,
1894
- maskTextClass: this.maskTextClass,
1895
- maskTextSelector: this.maskTextSelector,
1896
- skipChild: true,
1897
- newlyAddedElement: true,
1898
- inlineStylesheet: this.inlineStylesheet,
1899
- maskInputOptions: this.maskInputOptions,
1900
- maskTextFn: this.maskTextFn,
1901
- maskInputFn: this.maskInputFn,
1902
- slimDOMOptions: this.slimDOMOptions,
1903
- dataURLOptions: this.dataURLOptions,
1904
- recordCanvas: this.recordCanvas,
1905
- inlineImages: this.inlineImages,
1906
- onSerialize: (currentN) => {
1907
- if (isSerializedIframe(currentN, this.mirror)) {
1908
- this.iframeManager.addIframe(currentN);
1909
- }
1910
- if (isSerializedStylesheet(currentN, this.mirror)) {
1911
- this.stylesheetManager.trackLinkElement(currentN);
1912
- }
1913
- if (hasShadowRoot(n)) {
1914
- this.shadowDomManager.addShadowRoot(n.shadowRoot, this.doc);
1915
- }
1916
- },
1917
- onIframeLoad: (iframe, childSn) => {
1918
- this.iframeManager.attachIframe(iframe, childSn);
1919
- this.shadowDomManager.observeAttachShadow(iframe);
1920
- },
1921
- onStylesheetLoad: (link, childSn) => {
1922
- this.stylesheetManager.attachLinkElement(link, childSn);
1923
- },
1924
- });
1925
- if (sn) {
1926
- adds.push({
1927
- parentId,
1928
- nextId,
1929
- node: sn,
1930
- });
1931
- }
1932
- };
1933
- while (this.mapRemoves.length) {
1934
- this.mirror.removeNodeFromMap(this.mapRemoves.shift());
1935
- }
1936
- for (const n of Array.from(this.movedSet.values())) {
1937
- if (isParentRemoved(this.removes, n, this.mirror) &&
1938
- !this.movedSet.has(n.parentNode)) {
1939
- continue;
1940
- }
1941
- pushAdd(n);
1942
- }
1943
- for (const n of Array.from(this.addedSet.values())) {
1944
- if (!isAncestorInSet(this.droppedSet, n) &&
1945
- !isParentRemoved(this.removes, n, this.mirror)) {
1946
- pushAdd(n);
1947
- }
1948
- else if (isAncestorInSet(this.movedSet, n)) {
1949
- pushAdd(n);
1950
- }
1951
- else {
1952
- this.droppedSet.add(n);
1953
- }
1954
- }
1955
- let candidate = null;
1956
- while (addList.length) {
1957
- let node = null;
1958
- if (candidate) {
1959
- const parentId = this.mirror.getId(candidate.value.parentNode);
1960
- const nextId = getNextId(candidate.value);
1961
- if (parentId !== -1 && nextId !== -1) {
1962
- node = candidate;
1963
- }
1964
- }
1965
- if (!node) {
1966
- for (let index = addList.length - 1; index >= 0; index--) {
1967
- const _node = addList.get(index);
1968
- if (_node) {
1969
- const parentId = this.mirror.getId(_node.value.parentNode);
1970
- const nextId = getNextId(_node.value);
1971
- if (nextId === -1)
1972
- continue;
1973
- else if (parentId !== -1) {
1974
- node = _node;
1975
- break;
1976
- }
1977
- else {
1978
- const unhandledNode = _node.value;
1979
- if (unhandledNode.parentNode &&
1980
- unhandledNode.parentNode.nodeType ===
1981
- Node.DOCUMENT_FRAGMENT_NODE) {
1982
- const shadowHost = unhandledNode.parentNode
1983
- .host;
1984
- const parentId = this.mirror.getId(shadowHost);
1985
- if (parentId !== -1) {
1986
- node = _node;
1987
- break;
1988
- }
1989
- }
1990
- }
1991
- }
1992
- }
1993
- }
1994
- if (!node) {
1995
- while (addList.head) {
1996
- addList.removeNode(addList.head.value);
1997
- }
1998
- break;
1999
- }
2000
- candidate = node.previous;
2001
- addList.removeNode(node.value);
2002
- pushAdd(node.value);
2003
- }
2004
- const payload = {
2005
- texts: this.texts
2006
- .map((text) => ({
2007
- id: this.mirror.getId(text.node),
2008
- value: text.value,
2009
- }))
2010
- .filter((text) => this.mirror.has(text.id)),
2011
- attributes: this.attributes
2012
- .map((attribute) => ({
2013
- id: this.mirror.getId(attribute.node),
2014
- attributes: attribute.attributes,
2015
- }))
2016
- .filter((attribute) => this.mirror.has(attribute.id)),
2017
- removes: this.removes,
2018
- adds,
2019
- };
2020
- if (!payload.texts.length &&
2021
- !payload.attributes.length &&
2022
- !payload.removes.length &&
2023
- !payload.adds.length) {
2024
- return;
2025
- }
2026
- this.texts = [];
2027
- this.attributes = [];
2028
- this.removes = [];
2029
- this.addedSet = new Set();
2030
- this.movedSet = new Set();
2031
- this.droppedSet = new Set();
2032
- this.movedMap = {};
2033
- this.mutationCb(payload);
2034
- };
2035
- this.processMutation = (m) => {
2036
- if (isIgnored(m.target, this.mirror)) {
2037
- return;
2038
- }
2039
- switch (m.type) {
2040
- case 'characterData': {
2041
- const value = m.target.textContent;
2042
- if (!isBlocked(m.target, this.blockClass, this.blockSelector, false) &&
2043
- value !== m.oldValue) {
2044
- this.texts.push({
2045
- value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2046
- ? this.maskTextFn
2047
- ? this.maskTextFn(value)
2048
- : value.replace(/[\S]/g, '*')
2049
- : value,
2050
- node: m.target,
2051
- });
2052
- }
2053
- break;
2054
- }
2055
- case 'attributes': {
2056
- const target = m.target;
2057
- let value = m.target.getAttribute(m.attributeName);
2058
- if (m.attributeName === 'value') {
2059
- value = maskInputValue({
2060
- maskInputOptions: this.maskInputOptions,
2061
- tagName: m.target.tagName,
2062
- type: m.target.getAttribute('type'),
2063
- value,
2064
- maskInputFn: this.maskInputFn,
2065
- });
2066
- }
2067
- if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
2068
- value === m.oldValue) {
2069
- return;
2070
- }
2071
- let item = this.attributes.find((a) => a.node === m.target);
2072
- if (target.tagName === 'IFRAME' &&
2073
- m.attributeName === 'src' &&
2074
- !this.keepIframeSrcFn(value)) {
2075
- if (!target.contentDocument) {
2076
- m.attributeName = 'rr_src';
2077
- }
2078
- else {
2079
- return;
2080
- }
2081
- }
2082
- if (!item) {
2083
- item = {
2084
- node: m.target,
2085
- attributes: {},
2086
- };
2087
- this.attributes.push(item);
2088
- }
2089
- if (m.attributeName === 'style') {
2090
- const old = this.doc.createElement('span');
2091
- if (m.oldValue) {
2092
- old.setAttribute('style', m.oldValue);
2093
- }
2094
- if (item.attributes.style === undefined ||
2095
- item.attributes.style === null) {
2096
- item.attributes.style = {};
2097
- }
2098
- const styleObj = item.attributes.style;
2099
- for (const pname of Array.from(target.style)) {
2100
- const newValue = target.style.getPropertyValue(pname);
2101
- const newPriority = target.style.getPropertyPriority(pname);
2102
- if (newValue !== old.style.getPropertyValue(pname) ||
2103
- newPriority !== old.style.getPropertyPriority(pname)) {
2104
- if (newPriority === '') {
2105
- styleObj[pname] = newValue;
2106
- }
2107
- else {
2108
- styleObj[pname] = [newValue, newPriority];
2109
- }
2110
- }
2111
- }
2112
- for (const pname of Array.from(old.style)) {
2113
- if (target.style.getPropertyValue(pname) === '') {
2114
- styleObj[pname] = false;
2115
- }
2116
- }
2117
- }
2118
- else {
2119
- item.attributes[m.attributeName] = transformAttribute(this.doc, target.tagName, m.attributeName, value);
2120
- }
2121
- break;
2122
- }
2123
- case 'childList': {
2124
- if (isBlocked(m.target, this.blockClass, this.blockSelector, true))
2125
- return;
2126
- m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2127
- m.removedNodes.forEach((n) => {
2128
- const nodeId = this.mirror.getId(n);
2129
- const parentId = isShadowRoot(m.target)
2130
- ? this.mirror.getId(m.target.host)
2131
- : this.mirror.getId(m.target);
2132
- if (isBlocked(m.target, this.blockClass, this.blockSelector, false) ||
2133
- isIgnored(n, this.mirror) ||
2134
- !isSerialized(n, this.mirror)) {
2135
- return;
2136
- }
2137
- if (this.addedSet.has(n)) {
2138
- deepDelete(this.addedSet, n);
2139
- this.droppedSet.add(n);
2140
- }
2141
- else if (this.addedSet.has(m.target) && nodeId === -1) ;
2142
- else if (isAncestorRemoved(m.target, this.mirror)) ;
2143
- else if (this.movedSet.has(n) &&
2144
- this.movedMap[moveKey(nodeId, parentId)]) {
2145
- deepDelete(this.movedSet, n);
2146
- }
2147
- else {
2148
- this.removes.push({
2149
- parentId,
2150
- id: nodeId,
2151
- isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target)
2152
- ? true
2153
- : undefined,
2154
- });
2155
- }
2156
- this.mapRemoves.push(n);
2157
- });
2158
- break;
2159
- }
2160
- }
2161
- };
2162
- this.genAdds = (n, target) => {
2163
- if (this.mirror.hasNode(n)) {
2164
- if (isIgnored(n, this.mirror)) {
2165
- return;
2166
- }
2167
- this.movedSet.add(n);
2168
- let targetId = null;
2169
- if (target && this.mirror.hasNode(target)) {
2170
- targetId = this.mirror.getId(target);
2171
- }
2172
- if (targetId && targetId !== -1) {
2173
- this.movedMap[moveKey(this.mirror.getId(n), targetId)] = true;
2174
- }
2175
- }
2176
- else {
2177
- this.addedSet.add(n);
2178
- this.droppedSet.delete(n);
2179
- }
2180
- if (!isBlocked(n, this.blockClass, this.blockSelector, false))
2181
- n.childNodes.forEach((childN) => this.genAdds(childN));
2182
- };
2183
- }
2184
- init(options) {
2185
- [
2186
- 'mutationCb',
2187
- 'blockClass',
2188
- 'blockSelector',
2189
- 'maskTextClass',
2190
- 'maskTextSelector',
2191
- 'inlineStylesheet',
2192
- 'maskInputOptions',
2193
- 'maskTextFn',
2194
- 'maskInputFn',
2195
- 'keepIframeSrcFn',
2196
- 'recordCanvas',
2197
- 'inlineImages',
2198
- 'slimDOMOptions',
2199
- 'dataURLOptions',
2200
- 'doc',
2201
- 'mirror',
2202
- 'iframeManager',
2203
- 'stylesheetManager',
2204
- 'shadowDomManager',
2205
- 'canvasManager',
2206
- ].forEach((key) => {
2207
- this[key] = options[key];
2208
- });
2209
- }
2210
- freeze() {
2211
- this.frozen = true;
2212
- this.canvasManager.freeze();
2213
- }
2214
- unfreeze() {
2215
- this.frozen = false;
2216
- this.canvasManager.unfreeze();
2217
- this.emit();
2218
- }
2219
- isFrozen() {
2220
- return this.frozen;
2221
- }
2222
- lock() {
2223
- this.locked = true;
2224
- this.canvasManager.lock();
2225
- }
2226
- unlock() {
2227
- this.locked = false;
2228
- this.canvasManager.unlock();
2229
- this.emit();
2230
- }
2231
- reset() {
2232
- this.shadowDomManager.reset();
2233
- this.canvasManager.reset();
2234
- }
2235
- }
2236
- function deepDelete(addsSet, n) {
2237
- addsSet.delete(n);
2238
- n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
2239
- }
2240
- function isParentRemoved(removes, n, mirror) {
2241
- if (removes.length === 0)
2242
- return false;
2243
- return _isParentRemoved(removes, n, mirror);
2244
- }
2245
- function _isParentRemoved(removes, n, mirror) {
2246
- const { parentNode } = n;
2247
- if (!parentNode) {
2248
- return false;
2249
- }
2250
- const parentId = mirror.getId(parentNode);
2251
- if (removes.some((r) => r.id === parentId)) {
2252
- return true;
2253
- }
2254
- return _isParentRemoved(removes, parentNode, mirror);
2255
- }
2256
- function isAncestorInSet(set, n) {
2257
- if (set.size === 0)
2258
- return false;
2259
- return _isAncestorInSet(set, n);
2260
- }
2261
- function _isAncestorInSet(set, n) {
2262
- const { parentNode } = n;
2263
- if (!parentNode) {
2264
- return false;
2265
- }
2266
- if (set.has(parentNode)) {
2267
- return true;
2268
- }
2269
- return _isAncestorInSet(set, parentNode);
2270
- }
2271
-
2272
- const mutationBuffers = [];
2273
- const isCSSGroupingRuleSupported = typeof CSSGroupingRule !== 'undefined';
2274
- const isCSSMediaRuleSupported = typeof CSSMediaRule !== 'undefined';
2275
- const isCSSSupportsRuleSupported = typeof CSSSupportsRule !== 'undefined';
2276
- const isCSSConditionRuleSupported = typeof CSSConditionRule !== 'undefined';
2277
- function getEventTarget(event) {
2278
- try {
2279
- if ('composedPath' in event) {
2280
- const path = event.composedPath();
2281
- if (path.length) {
2282
- return path[0];
2283
- }
2284
- }
2285
- else if ('path' in event && event.path.length) {
2286
- return event.path[0];
2287
- }
2288
- return event.target;
2289
- }
2290
- catch (_a) {
2291
- return event.target;
2292
- }
2293
- }
2294
- function initMutationObserver(options, rootEl) {
2295
- var _a, _b;
2296
- const mutationBuffer = new MutationBuffer();
2297
- mutationBuffers.push(mutationBuffer);
2298
- mutationBuffer.init(options);
2299
- let mutationObserverCtor = window.MutationObserver ||
2300
- window.__rrMutationObserver;
2301
- const angularZoneSymbol = (_b = (_a = window === null || window === void 0 ? void 0 : window.Zone) === null || _a === void 0 ? void 0 : _a.__symbol__) === null || _b === void 0 ? void 0 : _b.call(_a, 'MutationObserver');
2302
- if (angularZoneSymbol &&
2303
- window[angularZoneSymbol]) {
2304
- mutationObserverCtor = window[angularZoneSymbol];
2305
- }
2306
- const observer = new mutationObserverCtor(mutationBuffer.processMutations.bind(mutationBuffer));
2307
- observer.observe(rootEl, {
2308
- attributes: true,
2309
- attributeOldValue: true,
2310
- characterData: true,
2311
- characterDataOldValue: true,
2312
- childList: true,
2313
- subtree: true,
2314
- });
2315
- return observer;
2316
- }
2317
- function initMoveObserver({ mousemoveCb, sampling, doc, mirror, }) {
2318
- if (sampling.mousemove === false) {
2319
- return () => {
2320
- };
2321
- }
2322
- const threshold = typeof sampling.mousemove === 'number' ? sampling.mousemove : 50;
2323
- const callbackThreshold = typeof sampling.mousemoveCallback === 'number'
2324
- ? sampling.mousemoveCallback
2325
- : 500;
2326
- let positions = [];
2327
- let timeBaseline;
2328
- const wrappedCb = throttle((source) => {
2329
- const totalOffset = Date.now() - timeBaseline;
2330
- mousemoveCb(positions.map((p) => {
2331
- p.timeOffset -= totalOffset;
2332
- return p;
2333
- }), source);
2334
- positions = [];
2335
- timeBaseline = null;
2336
- }, callbackThreshold);
2337
- const updatePosition = throttle((evt) => {
2338
- const target = getEventTarget(evt);
2339
- const { clientX, clientY } = isTouchEvent(evt)
2340
- ? evt.changedTouches[0]
2341
- : evt;
2342
- if (!timeBaseline) {
2343
- timeBaseline = Date.now();
2344
- }
2345
- positions.push({
2346
- x: clientX,
2347
- y: clientY,
2348
- id: mirror.getId(target),
2349
- timeOffset: Date.now() - timeBaseline,
2350
- });
2351
- wrappedCb(typeof DragEvent !== 'undefined' && evt instanceof DragEvent
2352
- ? IncrementalSource.Drag
2353
- : evt instanceof MouseEvent
2354
- ? IncrementalSource.MouseMove
2355
- : IncrementalSource.TouchMove);
2356
- }, threshold, {
2357
- trailing: false,
2358
- });
2359
- const handlers = [
2360
- on('mousemove', updatePosition, doc),
2361
- on('touchmove', updatePosition, doc),
2362
- on('drag', updatePosition, doc),
2363
- ];
2364
- return () => {
2365
- handlers.forEach((h) => h());
2366
- };
2367
- }
2368
- function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockClass, blockSelector, sampling, }) {
2369
- if (sampling.mouseInteraction === false) {
2370
- return () => {
2371
- };
2372
- }
2373
- const disableMap = sampling.mouseInteraction === true ||
2374
- sampling.mouseInteraction === undefined
2375
- ? {}
2376
- : sampling.mouseInteraction;
2377
- const handlers = [];
2378
- const getHandler = (eventKey) => {
2379
- return (event) => {
2380
- const target = getEventTarget(event);
2381
- if (isBlocked(target, blockClass, blockSelector, true)) {
2382
- return;
2383
- }
2384
- const e = isTouchEvent(event) ? event.changedTouches[0] : event;
2385
- if (!e) {
2386
- return;
2387
- }
2388
- const id = mirror.getId(target);
2389
- const { clientX, clientY } = e;
2390
- mouseInteractionCb({
2391
- type: MouseInteractions[eventKey],
2392
- id,
2393
- x: clientX,
2394
- y: clientY,
2395
- });
2396
- };
2397
- };
2398
- Object.keys(MouseInteractions)
2399
- .filter((key) => Number.isNaN(Number(key)) &&
2400
- !key.endsWith('_Departed') &&
2401
- disableMap[key] !== false)
2402
- .forEach((eventKey) => {
2403
- const eventName = eventKey.toLowerCase();
2404
- const handler = getHandler(eventKey);
2405
- handlers.push(on(eventName, handler, doc));
2406
- });
2407
- return () => {
2408
- handlers.forEach((h) => h());
2409
- };
2410
- }
2411
- function initScrollObserver({ scrollCb, doc, mirror, blockClass, blockSelector, sampling, }) {
2412
- const updatePosition = throttle((evt) => {
2413
- const target = getEventTarget(evt);
2414
- if (!target || isBlocked(target, blockClass, blockSelector, true)) {
2415
- return;
2416
- }
2417
- const id = mirror.getId(target);
2418
- if (target === doc) {
2419
- const scrollEl = (doc.scrollingElement || doc.documentElement);
2420
- scrollCb({
2421
- id,
2422
- x: scrollEl.scrollLeft,
2423
- y: scrollEl.scrollTop,
2424
- });
2425
- }
2426
- else {
2427
- scrollCb({
2428
- id,
2429
- x: target.scrollLeft,
2430
- y: target.scrollTop,
2431
- });
2432
- }
2433
- }, sampling.scroll || 100);
2434
- return on('scroll', updatePosition, doc);
2435
- }
2436
- function initViewportResizeObserver({ viewportResizeCb, }) {
2437
- let lastH = -1;
2438
- let lastW = -1;
2439
- const updateDimension = throttle(() => {
2440
- const height = getWindowHeight();
2441
- const width = getWindowWidth();
2442
- if (lastH !== height || lastW !== width) {
2443
- viewportResizeCb({
2444
- width: Number(width),
2445
- height: Number(height),
2446
- });
2447
- lastH = height;
2448
- lastW = width;
2449
- }
2450
- }, 200);
2451
- return on('resize', updateDimension, window);
2452
- }
2453
- function wrapEventWithUserTriggeredFlag(v, enable) {
2454
- const value = Object.assign({}, v);
2455
- if (!enable)
2456
- delete value.userTriggered;
2457
- return value;
2458
- }
2459
- const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
2460
- const lastInputValueMap = new WeakMap();
2461
- function initInputObserver({ inputCb, doc, mirror, blockClass, blockSelector, ignoreClass, maskInputOptions, maskInputFn, sampling, userTriggeredOnInput, }) {
2462
- function eventHandler(event) {
2463
- let target = getEventTarget(event);
2464
- const userTriggered = event.isTrusted;
2465
- if (target && target.tagName === 'OPTION')
2466
- target = target.parentElement;
2467
- if (!target ||
2468
- !target.tagName ||
2469
- INPUT_TAGS.indexOf(target.tagName) < 0 ||
2470
- isBlocked(target, blockClass, blockSelector, true)) {
2471
- return;
2472
- }
2473
- const type = target.type;
2474
- if (target.classList.contains(ignoreClass)) {
2475
- return;
2476
- }
2477
- let text = target.value;
2478
- let isChecked = false;
2479
- if (type === 'radio' || type === 'checkbox') {
2480
- isChecked = target.checked;
2481
- }
2482
- else if (maskInputOptions[target.tagName.toLowerCase()] ||
2483
- maskInputOptions[type]) {
2484
- text = maskInputValue({
2485
- maskInputOptions,
2486
- tagName: target.tagName,
2487
- type,
2488
- value: text,
2489
- maskInputFn,
2490
- });
2491
- }
2492
- cbWithDedup(target, wrapEventWithUserTriggeredFlag({ text, isChecked, userTriggered }, userTriggeredOnInput));
2493
- const name = target.name;
2494
- if (type === 'radio' && name && isChecked) {
2495
- doc
2496
- .querySelectorAll(`input[type="radio"][name="${name}"]`)
2497
- .forEach((el) => {
2498
- if (el !== target) {
2499
- cbWithDedup(el, wrapEventWithUserTriggeredFlag({
2500
- text: el.value,
2501
- isChecked: !isChecked,
2502
- userTriggered: false,
2503
- }, userTriggeredOnInput));
2504
- }
2505
- });
2506
- }
2507
- }
2508
- function cbWithDedup(target, v) {
2509
- const lastInputValue = lastInputValueMap.get(target);
2510
- if (!lastInputValue ||
2511
- lastInputValue.text !== v.text ||
2512
- lastInputValue.isChecked !== v.isChecked) {
2513
- lastInputValueMap.set(target, v);
2514
- const id = mirror.getId(target);
2515
- inputCb(Object.assign(Object.assign({}, v), { id }));
2516
- }
2517
- }
2518
- const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
2519
- const handlers = events.map((eventName) => on(eventName, eventHandler, doc));
2520
- const currentWindow = doc.defaultView;
2521
- if (!currentWindow) {
2522
- return () => {
2523
- handlers.forEach((h) => h());
2524
- };
2525
- }
2526
- const propertyDescriptor = currentWindow.Object.getOwnPropertyDescriptor(currentWindow.HTMLInputElement.prototype, 'value');
2527
- const hookProperties = [
2528
- [currentWindow.HTMLInputElement.prototype, 'value'],
2529
- [currentWindow.HTMLInputElement.prototype, 'checked'],
2530
- [currentWindow.HTMLSelectElement.prototype, 'value'],
2531
- [currentWindow.HTMLTextAreaElement.prototype, 'value'],
2532
- [currentWindow.HTMLSelectElement.prototype, 'selectedIndex'],
2533
- [currentWindow.HTMLOptionElement.prototype, 'selected'],
2534
- ];
2535
- if (propertyDescriptor && propertyDescriptor.set) {
2536
- handlers.push(...hookProperties.map((p) => hookSetter(p[0], p[1], {
2537
- set() {
2538
- eventHandler({ target: this });
2539
- },
2540
- }, false, currentWindow)));
2541
- }
2542
- return () => {
2543
- handlers.forEach((h) => h());
2544
- };
2545
- }
2546
- function getNestedCSSRulePositions(rule) {
2547
- const positions = [];
2548
- function recurse(childRule, pos) {
2549
- if ((isCSSGroupingRuleSupported &&
2550
- childRule.parentRule instanceof CSSGroupingRule) ||
2551
- (isCSSMediaRuleSupported &&
2552
- childRule.parentRule instanceof CSSMediaRule) ||
2553
- (isCSSSupportsRuleSupported &&
2554
- childRule.parentRule instanceof CSSSupportsRule) ||
2555
- (isCSSConditionRuleSupported &&
2556
- childRule.parentRule instanceof CSSConditionRule)) {
2557
- const rules = Array.from(childRule.parentRule.cssRules);
2558
- const index = rules.indexOf(childRule);
2559
- pos.unshift(index);
2560
- }
2561
- else if (childRule.parentStyleSheet) {
2562
- const rules = Array.from(childRule.parentStyleSheet.cssRules);
2563
- const index = rules.indexOf(childRule);
2564
- pos.unshift(index);
2565
- }
2566
- return pos;
2567
- }
2568
- return recurse(rule, positions);
2569
- }
2570
- function getIdAndStyleId(sheet, mirror, styleMirror) {
2571
- let id, styleId;
2572
- if (!sheet)
2573
- return {};
2574
- if (sheet.ownerNode)
2575
- id = mirror.getId(sheet.ownerNode);
2576
- else
2577
- styleId = styleMirror.getId(sheet);
2578
- return {
2579
- styleId,
2580
- id,
2581
- };
2582
- }
2583
- function initStyleSheetObserver({ styleSheetRuleCb, mirror, stylesheetManager }, { win }) {
2584
- const insertRule = win.CSSStyleSheet.prototype.insertRule;
2585
- win.CSSStyleSheet.prototype.insertRule = function (rule, index) {
2586
- const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
2587
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2588
- styleSheetRuleCb({
2589
- id,
2590
- styleId,
2591
- adds: [{ rule, index }],
2592
- });
2593
- }
2594
- return insertRule.apply(this, [rule, index]);
2595
- };
2596
- const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
2597
- win.CSSStyleSheet.prototype.deleteRule = function (index) {
2598
- const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
2599
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2600
- styleSheetRuleCb({
2601
- id,
2602
- styleId,
2603
- removes: [{ index }],
2604
- });
2605
- }
2606
- return deleteRule.apply(this, [index]);
2607
- };
2608
- let replace;
2609
- if (win.CSSStyleSheet.prototype.replace) {
2610
- replace = win.CSSStyleSheet.prototype.replace;
2611
- win.CSSStyleSheet.prototype.replace = function (text) {
2612
- const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
2613
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2614
- styleSheetRuleCb({
2615
- id,
2616
- styleId,
2617
- replace: text,
2618
- });
2619
- }
2620
- return replace.apply(this, [text]);
2621
- };
2622
- }
2623
- let replaceSync;
2624
- if (win.CSSStyleSheet.prototype.replaceSync) {
2625
- replaceSync = win.CSSStyleSheet.prototype.replaceSync;
2626
- win.CSSStyleSheet.prototype.replaceSync = function (text) {
2627
- const { id, styleId } = getIdAndStyleId(this, mirror, stylesheetManager.styleMirror);
2628
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2629
- styleSheetRuleCb({
2630
- id,
2631
- styleId,
2632
- replaceSync: text,
2633
- });
2634
- }
2635
- return replaceSync.apply(this, [text]);
2636
- };
2637
- }
2638
- const supportedNestedCSSRuleTypes = {};
2639
- if (isCSSGroupingRuleSupported) {
2640
- supportedNestedCSSRuleTypes.CSSGroupingRule = win.CSSGroupingRule;
2641
- }
2642
- else {
2643
- if (isCSSMediaRuleSupported) {
2644
- supportedNestedCSSRuleTypes.CSSMediaRule = win.CSSMediaRule;
2645
- }
2646
- if (isCSSConditionRuleSupported) {
2647
- supportedNestedCSSRuleTypes.CSSConditionRule = win.CSSConditionRule;
2648
- }
2649
- if (isCSSSupportsRuleSupported) {
2650
- supportedNestedCSSRuleTypes.CSSSupportsRule = win.CSSSupportsRule;
2651
- }
2652
- }
2653
- const unmodifiedFunctions = {};
2654
- Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
2655
- unmodifiedFunctions[typeKey] = {
2656
- insertRule: type.prototype.insertRule,
2657
- deleteRule: type.prototype.deleteRule,
2658
- };
2659
- type.prototype.insertRule = function (rule, index) {
2660
- const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2661
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2662
- styleSheetRuleCb({
2663
- id,
2664
- styleId,
2665
- adds: [
2666
- {
2667
- rule,
2668
- index: [
2669
- ...getNestedCSSRulePositions(this),
2670
- index || 0,
2671
- ],
2672
- },
2673
- ],
2674
- });
2675
- }
2676
- return unmodifiedFunctions[typeKey].insertRule.apply(this, [rule, index]);
2677
- };
2678
- type.prototype.deleteRule = function (index) {
2679
- const { id, styleId } = getIdAndStyleId(this.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2680
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2681
- styleSheetRuleCb({
2682
- id,
2683
- styleId,
2684
- removes: [
2685
- { index: [...getNestedCSSRulePositions(this), index] },
2686
- ],
2687
- });
2688
- }
2689
- return unmodifiedFunctions[typeKey].deleteRule.apply(this, [index]);
2690
- };
2691
- });
2692
- return () => {
2693
- win.CSSStyleSheet.prototype.insertRule = insertRule;
2694
- win.CSSStyleSheet.prototype.deleteRule = deleteRule;
2695
- replace && (win.CSSStyleSheet.prototype.replace = replace);
2696
- replaceSync && (win.CSSStyleSheet.prototype.replaceSync = replaceSync);
2697
- Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
2698
- type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
2699
- type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
2700
- });
2701
- };
2702
- }
2703
- function initAdoptedStyleSheetObserver({ mirror, stylesheetManager, }, host) {
2704
- var _a, _b, _c;
2705
- let hostId = null;
2706
- if (host.nodeName === '#document')
2707
- hostId = mirror.getId(host);
2708
- else
2709
- hostId = mirror.getId(host.host);
2710
- const patchTarget = host.nodeName === '#document'
2711
- ? (_a = host.defaultView) === null || _a === void 0 ? void 0 : _a.Document
2712
- : (_c = (_b = host.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.ShadowRoot;
2713
- const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(patchTarget === null || patchTarget === void 0 ? void 0 : patchTarget.prototype, 'adoptedStyleSheets');
2714
- if (hostId === null ||
2715
- hostId === -1 ||
2716
- !patchTarget ||
2717
- !originalPropertyDescriptor)
2718
- return () => {
2719
- };
2720
- Object.defineProperty(host, 'adoptedStyleSheets', {
2721
- configurable: originalPropertyDescriptor.configurable,
2722
- enumerable: originalPropertyDescriptor.enumerable,
2723
- get() {
2724
- var _a;
2725
- return (_a = originalPropertyDescriptor.get) === null || _a === void 0 ? void 0 : _a.call(this);
2726
- },
2727
- set(sheets) {
2728
- var _a;
2729
- const result = (_a = originalPropertyDescriptor.set) === null || _a === void 0 ? void 0 : _a.call(this, sheets);
2730
- if (hostId !== null && hostId !== -1) {
2731
- try {
2732
- stylesheetManager.adoptStyleSheets(sheets, hostId);
2733
- }
2734
- catch (e) {
2735
- }
2736
- }
2737
- return result;
2738
- },
2739
- });
2740
- return () => {
2741
- Object.defineProperty(host, 'adoptedStyleSheets', {
2742
- configurable: originalPropertyDescriptor.configurable,
2743
- enumerable: originalPropertyDescriptor.enumerable,
2744
- get: originalPropertyDescriptor.get,
2745
- set: originalPropertyDescriptor.set,
2746
- });
2747
- };
2748
- }
2749
- function initStyleDeclarationObserver({ styleDeclarationCb, mirror, ignoreCSSAttributes, stylesheetManager, }, { win }) {
2750
- const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
2751
- win.CSSStyleDeclaration.prototype.setProperty = function (property, value, priority) {
2752
- var _a;
2753
- if (ignoreCSSAttributes.has(property)) {
2754
- return setProperty.apply(this, [property, value, priority]);
2755
- }
2756
- const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2757
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2758
- styleDeclarationCb({
2759
- id,
2760
- styleId,
2761
- set: {
2762
- property,
2763
- value,
2764
- priority,
2765
- },
2766
- index: getNestedCSSRulePositions(this.parentRule),
2767
- });
2768
- }
2769
- return setProperty.apply(this, [property, value, priority]);
2770
- };
2771
- const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
2772
- win.CSSStyleDeclaration.prototype.removeProperty = function (property) {
2773
- var _a;
2774
- if (ignoreCSSAttributes.has(property)) {
2775
- return removeProperty.apply(this, [property]);
2776
- }
2777
- const { id, styleId } = getIdAndStyleId((_a = this.parentRule) === null || _a === void 0 ? void 0 : _a.parentStyleSheet, mirror, stylesheetManager.styleMirror);
2778
- if ((id && id !== -1) || (styleId && styleId !== -1)) {
2779
- styleDeclarationCb({
2780
- id,
2781
- styleId,
2782
- remove: {
2783
- property,
2784
- },
2785
- index: getNestedCSSRulePositions(this.parentRule),
2786
- });
2787
- }
2788
- return removeProperty.apply(this, [property]);
2789
- };
2790
- return () => {
2791
- win.CSSStyleDeclaration.prototype.setProperty = setProperty;
2792
- win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
2793
- };
2794
- }
2795
- function initMediaInteractionObserver({ mediaInteractionCb, blockClass, blockSelector, mirror, sampling, }) {
2796
- const handler = (type) => throttle((event) => {
2797
- const target = getEventTarget(event);
2798
- if (!target ||
2799
- isBlocked(target, blockClass, blockSelector, true)) {
2800
- return;
2801
- }
2802
- const { currentTime, volume, muted, playbackRate, } = target;
2803
- mediaInteractionCb({
2804
- type,
2805
- id: mirror.getId(target),
2806
- currentTime,
2807
- volume,
2808
- muted,
2809
- playbackRate,
2810
- });
2811
- }, sampling.media || 500);
2812
- const handlers = [
2813
- on('play', handler(0)),
2814
- on('pause', handler(1)),
2815
- on('seeked', handler(2)),
2816
- on('volumechange', handler(3)),
2817
- on('ratechange', handler(4)),
2818
- ];
2819
- return () => {
2820
- handlers.forEach((h) => h());
2821
- };
2822
- }
2823
- function initFontObserver({ fontCb, doc }) {
2824
- const win = doc.defaultView;
2825
- if (!win) {
2826
- return () => {
2827
- };
2828
- }
2829
- const handlers = [];
2830
- const fontMap = new WeakMap();
2831
- const originalFontFace = win.FontFace;
2832
- win.FontFace = function FontFace(family, source, descriptors) {
2833
- const fontFace = new originalFontFace(family, source, descriptors);
2834
- fontMap.set(fontFace, {
2835
- family,
2836
- buffer: typeof source !== 'string',
2837
- descriptors,
2838
- fontSource: typeof source === 'string'
2839
- ? source
2840
- : JSON.stringify(Array.from(new Uint8Array(source))),
2841
- });
2842
- return fontFace;
2843
- };
2844
- const restoreHandler = patch(doc.fonts, 'add', function (original) {
2845
- return function (fontFace) {
2846
- setTimeout(() => {
2847
- const p = fontMap.get(fontFace);
2848
- if (p) {
2849
- fontCb(p);
2850
- fontMap.delete(fontFace);
2851
- }
2852
- }, 0);
2853
- return original.apply(this, [fontFace]);
2854
- };
2855
- });
2856
- handlers.push(() => {
2857
- win.FontFace = originalFontFace;
2858
- });
2859
- handlers.push(restoreHandler);
2860
- return () => {
2861
- handlers.forEach((h) => h());
2862
- };
2863
- }
2864
- function initSelectionObserver(param) {
2865
- const { doc, mirror, blockClass, blockSelector, selectionCb } = param;
2866
- let collapsed = true;
2867
- const updateSelection = () => {
2868
- const selection = doc.getSelection();
2869
- if (!selection || (collapsed && (selection === null || selection === void 0 ? void 0 : selection.isCollapsed)))
2870
- return;
2871
- collapsed = selection.isCollapsed || false;
2872
- const ranges = [];
2873
- const count = selection.rangeCount || 0;
2874
- for (let i = 0; i < count; i++) {
2875
- const range = selection.getRangeAt(i);
2876
- const { startContainer, startOffset, endContainer, endOffset } = range;
2877
- const blocked = isBlocked(startContainer, blockClass, blockSelector, true) ||
2878
- isBlocked(endContainer, blockClass, blockSelector, true);
2879
- if (blocked)
2880
- continue;
2881
- ranges.push({
2882
- start: mirror.getId(startContainer),
2883
- startOffset,
2884
- end: mirror.getId(endContainer),
2885
- endOffset,
2886
- });
2887
- }
2888
- selectionCb({ ranges });
2889
- };
2890
- updateSelection();
2891
- return on('selectionchange', updateSelection);
2892
- }
2893
- function mergeHooks(o, hooks) {
2894
- const { mutationCb, mousemoveCb, mouseInteractionCb, scrollCb, viewportResizeCb, inputCb, mediaInteractionCb, styleSheetRuleCb, styleDeclarationCb, canvasMutationCb, fontCb, selectionCb, } = o;
2895
- o.mutationCb = (...p) => {
2896
- if (hooks.mutation) {
2897
- hooks.mutation(...p);
2898
- }
2899
- mutationCb(...p);
2900
- };
2901
- o.mousemoveCb = (...p) => {
2902
- if (hooks.mousemove) {
2903
- hooks.mousemove(...p);
2904
- }
2905
- mousemoveCb(...p);
2906
- };
2907
- o.mouseInteractionCb = (...p) => {
2908
- if (hooks.mouseInteraction) {
2909
- hooks.mouseInteraction(...p);
2910
- }
2911
- mouseInteractionCb(...p);
2912
- };
2913
- o.scrollCb = (...p) => {
2914
- if (hooks.scroll) {
2915
- hooks.scroll(...p);
2916
- }
2917
- scrollCb(...p);
2918
- };
2919
- o.viewportResizeCb = (...p) => {
2920
- if (hooks.viewportResize) {
2921
- hooks.viewportResize(...p);
2922
- }
2923
- viewportResizeCb(...p);
2924
- };
2925
- o.inputCb = (...p) => {
2926
- if (hooks.input) {
2927
- hooks.input(...p);
2928
- }
2929
- inputCb(...p);
2930
- };
2931
- o.mediaInteractionCb = (...p) => {
2932
- if (hooks.mediaInteaction) {
2933
- hooks.mediaInteaction(...p);
2934
- }
2935
- mediaInteractionCb(...p);
2936
- };
2937
- o.styleSheetRuleCb = (...p) => {
2938
- if (hooks.styleSheetRule) {
2939
- hooks.styleSheetRule(...p);
2940
- }
2941
- styleSheetRuleCb(...p);
2942
- };
2943
- o.styleDeclarationCb = (...p) => {
2944
- if (hooks.styleDeclaration) {
2945
- hooks.styleDeclaration(...p);
2946
- }
2947
- styleDeclarationCb(...p);
2948
- };
2949
- o.canvasMutationCb = (...p) => {
2950
- if (hooks.canvasMutation) {
2951
- hooks.canvasMutation(...p);
2952
- }
2953
- canvasMutationCb(...p);
2954
- };
2955
- o.fontCb = (...p) => {
2956
- if (hooks.font) {
2957
- hooks.font(...p);
2958
- }
2959
- fontCb(...p);
2960
- };
2961
- o.selectionCb = (...p) => {
2962
- if (hooks.selection) {
2963
- hooks.selection(...p);
2964
- }
2965
- selectionCb(...p);
2966
- };
2967
- }
2968
- function initObservers(o, hooks = {}) {
2969
- const currentWindow = o.doc.defaultView;
2970
- if (!currentWindow) {
2971
- return () => {
2972
- };
2973
- }
2974
- mergeHooks(o, hooks);
2975
- const mutationObserver = initMutationObserver(o, o.doc);
2976
- const mousemoveHandler = initMoveObserver(o);
2977
- const mouseInteractionHandler = initMouseInteractionObserver(o);
2978
- const scrollHandler = initScrollObserver(o);
2979
- const viewportResizeHandler = initViewportResizeObserver(o);
2980
- const inputHandler = initInputObserver(o);
2981
- const mediaInteractionHandler = initMediaInteractionObserver(o);
2982
- const styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
2983
- const adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
2984
- const styleDeclarationObserver = initStyleDeclarationObserver(o, {
2985
- win: currentWindow,
2986
- });
2987
- const fontObserver = o.collectFonts
2988
- ? initFontObserver(o)
2989
- : () => {
2990
- };
2991
- const selectionObserver = initSelectionObserver(o);
2992
- const pluginHandlers = [];
2993
- for (const plugin of o.plugins) {
2994
- pluginHandlers.push(plugin.observer(plugin.callback, currentWindow, plugin.options));
2995
- }
2996
- return () => {
2997
- mutationBuffers.forEach((b) => b.reset());
2998
- mutationObserver.disconnect();
2999
- mousemoveHandler();
3000
- mouseInteractionHandler();
3001
- scrollHandler();
3002
- viewportResizeHandler();
3003
- inputHandler();
3004
- mediaInteractionHandler();
3005
- styleSheetObserver();
3006
- adoptedStyleSheetObserver();
3007
- styleDeclarationObserver();
3008
- fontObserver();
3009
- selectionObserver();
3010
- pluginHandlers.forEach((h) => h());
3011
- };
3012
- }
3013
-
3014
- class CrossOriginIframeMirror {
3015
- constructor(generateIdFn) {
3016
- this.generateIdFn = generateIdFn;
3017
- this.iframeIdToRemoteIdMap = new WeakMap();
3018
- this.iframeRemoteIdToIdMap = new WeakMap();
3019
- }
3020
- getId(iframe, remoteId, idToRemoteMap, remoteToIdMap) {
3021
- const idToRemoteIdMap = idToRemoteMap || this.getIdToRemoteIdMap(iframe);
3022
- const remoteIdToIdMap = remoteToIdMap || this.getRemoteIdToIdMap(iframe);
3023
- let id = idToRemoteIdMap.get(remoteId);
3024
- if (!id) {
3025
- id = this.generateIdFn();
3026
- idToRemoteIdMap.set(remoteId, id);
3027
- remoteIdToIdMap.set(id, remoteId);
3028
- }
3029
- return id;
3030
- }
3031
- getIds(iframe, remoteId) {
3032
- const idToRemoteIdMap = this.getIdToRemoteIdMap(iframe);
3033
- const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
3034
- return remoteId.map((id) => this.getId(iframe, id, idToRemoteIdMap, remoteIdToIdMap));
3035
- }
3036
- getRemoteId(iframe, id, map) {
3037
- const remoteIdToIdMap = map || this.getRemoteIdToIdMap(iframe);
3038
- if (typeof id !== 'number')
3039
- return id;
3040
- const remoteId = remoteIdToIdMap.get(id);
3041
- if (!remoteId)
3042
- return -1;
3043
- return remoteId;
3044
- }
3045
- getRemoteIds(iframe, ids) {
3046
- const remoteIdToIdMap = this.getRemoteIdToIdMap(iframe);
3047
- return ids.map((id) => this.getRemoteId(iframe, id, remoteIdToIdMap));
3048
- }
3049
- reset(iframe) {
3050
- if (!iframe) {
3051
- this.iframeIdToRemoteIdMap = new WeakMap();
3052
- this.iframeRemoteIdToIdMap = new WeakMap();
3053
- return;
3054
- }
3055
- this.iframeIdToRemoteIdMap.delete(iframe);
3056
- this.iframeRemoteIdToIdMap.delete(iframe);
3057
- }
3058
- getIdToRemoteIdMap(iframe) {
3059
- let idToRemoteIdMap = this.iframeIdToRemoteIdMap.get(iframe);
3060
- if (!idToRemoteIdMap) {
3061
- idToRemoteIdMap = new Map();
3062
- this.iframeIdToRemoteIdMap.set(iframe, idToRemoteIdMap);
3063
- }
3064
- return idToRemoteIdMap;
3065
- }
3066
- getRemoteIdToIdMap(iframe) {
3067
- let remoteIdToIdMap = this.iframeRemoteIdToIdMap.get(iframe);
3068
- if (!remoteIdToIdMap) {
3069
- remoteIdToIdMap = new Map();
3070
- this.iframeRemoteIdToIdMap.set(iframe, remoteIdToIdMap);
3071
- }
3072
- return remoteIdToIdMap;
3073
- }
3074
- }
3075
-
3076
- class IframeManager {
3077
- constructor(options) {
3078
- this.iframes = new WeakMap();
3079
- this.crossOriginIframeMap = new WeakMap();
3080
- this.crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
3081
- this.mutationCb = options.mutationCb;
3082
- this.wrappedEmit = options.wrappedEmit;
3083
- this.stylesheetManager = options.stylesheetManager;
3084
- this.recordCrossOriginIframes = options.recordCrossOriginIframes;
3085
- this.crossOriginIframeStyleMirror = new CrossOriginIframeMirror(this.stylesheetManager.styleMirror.generateId.bind(this.stylesheetManager.styleMirror));
3086
- this.mirror = options.mirror;
3087
- if (this.recordCrossOriginIframes) {
3088
- window.addEventListener('message', this.handleMessage.bind(this));
3089
- }
3090
- }
3091
- addIframe(iframeEl) {
3092
- this.iframes.set(iframeEl, true);
3093
- if (iframeEl.contentWindow)
3094
- this.crossOriginIframeMap.set(iframeEl.contentWindow, iframeEl);
3095
- }
3096
- addLoadListener(cb) {
3097
- this.loadListener = cb;
3098
- }
3099
- attachIframe(iframeEl, childSn) {
3100
- var _a;
3101
- this.mutationCb({
3102
- adds: [
3103
- {
3104
- parentId: this.mirror.getId(iframeEl),
3105
- nextId: null,
3106
- node: childSn,
3107
- },
3108
- ],
3109
- removes: [],
3110
- texts: [],
3111
- attributes: [],
3112
- isAttachIframe: true,
3113
- });
3114
- (_a = this.loadListener) === null || _a === void 0 ? void 0 : _a.call(this, iframeEl);
3115
- if (iframeEl.contentDocument &&
3116
- iframeEl.contentDocument.adoptedStyleSheets &&
3117
- iframeEl.contentDocument.adoptedStyleSheets.length > 0)
3118
- this.stylesheetManager.adoptStyleSheets(iframeEl.contentDocument.adoptedStyleSheets, this.mirror.getId(iframeEl.contentDocument));
3119
- }
3120
- handleMessage(message) {
3121
- if (message.data.type === 'rrweb') {
3122
- const iframeSourceWindow = message.source;
3123
- if (!iframeSourceWindow)
3124
- return;
3125
- const iframeEl = this.crossOriginIframeMap.get(message.source);
3126
- if (!iframeEl)
3127
- return;
3128
- const transformedEvent = this.transformCrossOriginEvent(iframeEl, message.data.event);
3129
- if (transformedEvent)
3130
- this.wrappedEmit(transformedEvent, message.data.isCheckout);
3131
- }
3132
- }
3133
- transformCrossOriginEvent(iframeEl, e) {
3134
- var _a;
3135
- switch (e.type) {
3136
- case EventType.FullSnapshot: {
3137
- this.crossOriginIframeMirror.reset(iframeEl);
3138
- this.crossOriginIframeStyleMirror.reset(iframeEl);
3139
- this.replaceIdOnNode(e.data.node, iframeEl);
3140
- return {
3141
- timestamp: e.timestamp,
3142
- type: EventType.IncrementalSnapshot,
3143
- data: {
3144
- source: IncrementalSource.Mutation,
3145
- adds: [
3146
- {
3147
- parentId: this.mirror.getId(iframeEl),
3148
- nextId: null,
3149
- node: e.data.node,
3150
- },
3151
- ],
3152
- removes: [],
3153
- texts: [],
3154
- attributes: [],
3155
- isAttachIframe: true,
3156
- },
3157
- };
3158
- }
3159
- case EventType.Meta:
3160
- case EventType.Load:
3161
- case EventType.DomContentLoaded: {
3162
- return false;
3163
- }
3164
- case EventType.Plugin: {
3165
- return e;
3166
- }
3167
- case EventType.Custom: {
3168
- this.replaceIds(e.data.payload, iframeEl, ['id', 'parentId', 'previousId', 'nextId']);
3169
- return e;
3170
- }
3171
- case EventType.IncrementalSnapshot: {
3172
- switch (e.data.source) {
3173
- case IncrementalSource.Mutation: {
3174
- e.data.adds.forEach((n) => {
3175
- this.replaceIds(n, iframeEl, [
3176
- 'parentId',
3177
- 'nextId',
3178
- 'previousId',
3179
- ]);
3180
- this.replaceIdOnNode(n.node, iframeEl);
3181
- });
3182
- e.data.removes.forEach((n) => {
3183
- this.replaceIds(n, iframeEl, ['parentId', 'id']);
3184
- });
3185
- e.data.attributes.forEach((n) => {
3186
- this.replaceIds(n, iframeEl, ['id']);
3187
- });
3188
- e.data.texts.forEach((n) => {
3189
- this.replaceIds(n, iframeEl, ['id']);
3190
- });
3191
- return e;
3192
- }
3193
- case IncrementalSource.Drag:
3194
- case IncrementalSource.TouchMove:
3195
- case IncrementalSource.MouseMove: {
3196
- e.data.positions.forEach((p) => {
3197
- this.replaceIds(p, iframeEl, ['id']);
3198
- });
3199
- return e;
3200
- }
3201
- case IncrementalSource.ViewportResize: {
3202
- return false;
3203
- }
3204
- case IncrementalSource.MediaInteraction:
3205
- case IncrementalSource.MouseInteraction:
3206
- case IncrementalSource.Scroll:
3207
- case IncrementalSource.CanvasMutation:
3208
- case IncrementalSource.Input: {
3209
- this.replaceIds(e.data, iframeEl, ['id']);
3210
- return e;
3211
- }
3212
- case IncrementalSource.StyleSheetRule:
3213
- case IncrementalSource.StyleDeclaration: {
3214
- this.replaceIds(e.data, iframeEl, ['id']);
3215
- this.replaceStyleIds(e.data, iframeEl, ['styleId']);
3216
- return e;
3217
- }
3218
- case IncrementalSource.Font: {
3219
- return e;
3220
- }
3221
- case IncrementalSource.Selection: {
3222
- e.data.ranges.forEach((range) => {
3223
- this.replaceIds(range, iframeEl, ['start', 'end']);
3224
- });
3225
- return e;
3226
- }
3227
- case IncrementalSource.AdoptedStyleSheet: {
3228
- this.replaceIds(e.data, iframeEl, ['id']);
3229
- this.replaceStyleIds(e.data, iframeEl, ['styleIds']);
3230
- (_a = e.data.styles) === null || _a === void 0 ? void 0 : _a.forEach((style) => {
3231
- this.replaceStyleIds(style, iframeEl, ['styleId']);
3232
- });
3233
- return e;
3234
- }
3235
- }
3236
- }
3237
- }
3238
- }
3239
- replace(iframeMirror, obj, iframeEl, keys) {
3240
- for (const key of keys) {
3241
- if (!Array.isArray(obj[key]) && typeof obj[key] !== 'number')
3242
- continue;
3243
- if (Array.isArray(obj[key])) {
3244
- obj[key] = iframeMirror.getIds(iframeEl, obj[key]);
3245
- }
3246
- else {
3247
- obj[key] = iframeMirror.getId(iframeEl, obj[key]);
3248
- }
3249
- }
3250
- return obj;
3251
- }
3252
- replaceIds(obj, iframeEl, keys) {
3253
- return this.replace(this.crossOriginIframeMirror, obj, iframeEl, keys);
3254
- }
3255
- replaceStyleIds(obj, iframeEl, keys) {
3256
- return this.replace(this.crossOriginIframeStyleMirror, obj, iframeEl, keys);
3257
- }
3258
- replaceIdOnNode(node, iframeEl) {
3259
- this.replaceIds(node, iframeEl, ['id']);
3260
- if ('childNodes' in node) {
3261
- node.childNodes.forEach((child) => {
3262
- this.replaceIdOnNode(child, iframeEl);
3263
- });
3264
- }
3265
- }
3266
- }
3267
-
3268
- class ShadowDomManager {
3269
- constructor(options) {
3270
- this.shadowDoms = new WeakSet();
3271
- this.restorePatches = [];
3272
- this.mutationCb = options.mutationCb;
3273
- this.scrollCb = options.scrollCb;
3274
- this.bypassOptions = options.bypassOptions;
3275
- this.mirror = options.mirror;
3276
- const manager = this;
3277
- this.restorePatches.push(patch(Element.prototype, 'attachShadow', function (original) {
3278
- return function (option) {
3279
- const shadowRoot = original.call(this, option);
3280
- if (this.shadowRoot)
3281
- manager.addShadowRoot(this.shadowRoot, this.ownerDocument);
3282
- return shadowRoot;
3283
- };
3284
- }));
3285
- }
3286
- addShadowRoot(shadowRoot, doc) {
3287
- if (!isNativeShadowDom(shadowRoot))
3288
- return;
3289
- if (this.shadowDoms.has(shadowRoot))
3290
- return;
3291
- this.shadowDoms.add(shadowRoot);
3292
- initMutationObserver(Object.assign(Object.assign({}, this.bypassOptions), { doc, mutationCb: this.mutationCb, mirror: this.mirror, shadowDomManager: this }), shadowRoot);
3293
- initScrollObserver(Object.assign(Object.assign({}, this.bypassOptions), { scrollCb: this.scrollCb, doc: shadowRoot, mirror: this.mirror }));
3294
- setTimeout(() => {
3295
- if (shadowRoot.adoptedStyleSheets &&
3296
- shadowRoot.adoptedStyleSheets.length > 0)
3297
- this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
3298
- initAdoptedStyleSheetObserver({
3299
- mirror: this.mirror,
3300
- stylesheetManager: this.bypassOptions.stylesheetManager,
3301
- }, shadowRoot);
3302
- }, 0);
3303
- }
3304
- observeAttachShadow(iframeElement) {
3305
- if (iframeElement.contentWindow) {
3306
- const manager = this;
3307
- this.restorePatches.push(patch(iframeElement.contentWindow.HTMLElement.prototype, 'attachShadow', function (original) {
3308
- return function (option) {
3309
- const shadowRoot = original.call(this, option);
3310
- if (this.shadowRoot)
3311
- manager.addShadowRoot(this.shadowRoot, iframeElement.contentDocument);
3312
- return shadowRoot;
3313
- };
3314
- }));
3315
- }
3316
- }
3317
- reset() {
3318
- this.restorePatches.forEach((restorePatch) => restorePatch());
3319
- this.shadowDoms = new WeakSet();
3320
- }
3321
- }
3322
-
3323
- /*! *****************************************************************************
3324
- Copyright (c) Microsoft Corporation.
3325
-
3326
- Permission to use, copy, modify, and/or distribute this software for any
3327
- purpose with or without fee is hereby granted.
3328
-
3329
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3330
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3331
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3332
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3333
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3334
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3335
- PERFORMANCE OF THIS SOFTWARE.
3336
- ***************************************************************************** */
3337
-
3338
- function __rest(s, e) {
3339
- var t = {};
3340
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3341
- t[p] = s[p];
3342
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
3343
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3344
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3345
- t[p[i]] = s[p[i]];
3346
- }
3347
- return t;
3348
- }
3349
-
3350
- function __awaiter(thisArg, _arguments, P, generator) {
3351
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3352
- return new (P || (P = Promise))(function (resolve, reject) {
3353
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3354
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3355
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3356
- step((generator = generator.apply(thisArg, _arguments || [])).next());
3357
- });
3358
- }
3359
-
3360
- /*
3361
- * base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
3362
- * Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
3363
- * Released under MIT License
3364
- */
3365
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
3366
- // Use a lookup table to find the index.
3367
- var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
3368
- for (var i = 0; i < chars.length; i++) {
3369
- lookup[chars.charCodeAt(i)] = i;
3370
- }
3371
- var encode = function (arraybuffer) {
3372
- var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
3373
- for (i = 0; i < len; i += 3) {
3374
- base64 += chars[bytes[i] >> 2];
3375
- base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
3376
- base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
3377
- base64 += chars[bytes[i + 2] & 63];
3378
- }
3379
- if (len % 3 === 2) {
3380
- base64 = base64.substring(0, base64.length - 1) + '=';
3381
- }
3382
- else if (len % 3 === 1) {
3383
- base64 = base64.substring(0, base64.length - 2) + '==';
3384
- }
3385
- return base64;
3386
- };
3387
-
3388
- const canvasVarMap = new Map();
3389
- function variableListFor(ctx, ctor) {
3390
- let contextMap = canvasVarMap.get(ctx);
3391
- if (!contextMap) {
3392
- contextMap = new Map();
3393
- canvasVarMap.set(ctx, contextMap);
3394
- }
3395
- if (!contextMap.has(ctor)) {
3396
- contextMap.set(ctor, []);
3397
- }
3398
- return contextMap.get(ctor);
3399
- }
3400
- const saveWebGLVar = (value, win, ctx) => {
3401
- if (!value ||
3402
- !(isInstanceOfWebGLObject(value, win) || typeof value === 'object'))
3403
- return;
3404
- const name = value.constructor.name;
3405
- const list = variableListFor(ctx, name);
3406
- let index = list.indexOf(value);
3407
- if (index === -1) {
3408
- index = list.length;
3409
- list.push(value);
3410
- }
3411
- return index;
3412
- };
3413
- function serializeArg(value, win, ctx) {
3414
- if (value instanceof Array) {
3415
- return value.map((arg) => serializeArg(arg, win, ctx));
3416
- }
3417
- else if (value === null) {
3418
- return value;
3419
- }
3420
- else if (value instanceof Float32Array ||
3421
- value instanceof Float64Array ||
3422
- value instanceof Int32Array ||
3423
- value instanceof Uint32Array ||
3424
- value instanceof Uint8Array ||
3425
- value instanceof Uint16Array ||
3426
- value instanceof Int16Array ||
3427
- value instanceof Int8Array ||
3428
- value instanceof Uint8ClampedArray) {
3429
- const name = value.constructor.name;
3430
- return {
3431
- rr_type: name,
3432
- args: [Object.values(value)],
3433
- };
3434
- }
3435
- else if (value instanceof ArrayBuffer) {
3436
- const name = value.constructor.name;
3437
- const base64 = encode(value);
3438
- return {
3439
- rr_type: name,
3440
- base64,
3441
- };
3442
- }
3443
- else if (value instanceof DataView) {
3444
- const name = value.constructor.name;
3445
- return {
3446
- rr_type: name,
3447
- args: [
3448
- serializeArg(value.buffer, win, ctx),
3449
- value.byteOffset,
3450
- value.byteLength,
3451
- ],
3452
- };
3453
- }
3454
- else if (value instanceof HTMLImageElement) {
3455
- const name = value.constructor.name;
3456
- const { src } = value;
3457
- return {
3458
- rr_type: name,
3459
- src,
3460
- };
3461
- }
3462
- else if (value instanceof HTMLCanvasElement) {
3463
- const name = 'HTMLImageElement';
3464
- const src = value.toDataURL();
3465
- return {
3466
- rr_type: name,
3467
- src,
3468
- };
3469
- }
3470
- else if (value instanceof ImageData) {
3471
- const name = value.constructor.name;
3472
- return {
3473
- rr_type: name,
3474
- args: [serializeArg(value.data, win, ctx), value.width, value.height],
3475
- };
3476
- }
3477
- else if (isInstanceOfWebGLObject(value, win) || typeof value === 'object') {
3478
- const name = value.constructor.name;
3479
- const index = saveWebGLVar(value, win, ctx);
3480
- return {
3481
- rr_type: name,
3482
- index: index,
3483
- };
3484
- }
3485
- return value;
3486
- }
3487
- const serializeArgs = (args, win, ctx) => {
3488
- return [...args].map((arg) => serializeArg(arg, win, ctx));
3489
- };
3490
- const isInstanceOfWebGLObject = (value, win) => {
3491
- const webGLConstructorNames = [
3492
- 'WebGLActiveInfo',
3493
- 'WebGLBuffer',
3494
- 'WebGLFramebuffer',
3495
- 'WebGLProgram',
3496
- 'WebGLRenderbuffer',
3497
- 'WebGLShader',
3498
- 'WebGLShaderPrecisionFormat',
3499
- 'WebGLTexture',
3500
- 'WebGLUniformLocation',
3501
- 'WebGLVertexArrayObject',
3502
- 'WebGLVertexArrayObjectOES',
3503
- ];
3504
- const supportedWebGLConstructorNames = webGLConstructorNames.filter((name) => typeof win[name] === 'function');
3505
- return Boolean(supportedWebGLConstructorNames.find((name) => value instanceof win[name]));
3506
- };
3507
-
3508
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
3509
- const handlers = [];
3510
- const props2D = Object.getOwnPropertyNames(win.CanvasRenderingContext2D.prototype);
3511
- for (const prop of props2D) {
3512
- try {
3513
- if (typeof win.CanvasRenderingContext2D.prototype[prop] !== 'function') {
3514
- continue;
3515
- }
3516
- const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
3517
- return function (...args) {
3518
- if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
3519
- setTimeout(() => {
3520
- const recordArgs = serializeArgs([...args], win, this);
3521
- cb(this.canvas, {
3522
- type: CanvasContext['2D'],
3523
- property: prop,
3524
- args: recordArgs,
3525
- });
3526
- }, 0);
3527
- }
3528
- return original.apply(this, args);
3529
- };
3530
- });
3531
- handlers.push(restoreHandler);
3532
- }
3533
- catch (_a) {
3534
- const hookHandler = hookSetter(win.CanvasRenderingContext2D.prototype, prop, {
3535
- set(v) {
3536
- cb(this.canvas, {
3537
- type: CanvasContext['2D'],
3538
- property: prop,
3539
- args: [v],
3540
- setter: true,
3541
- });
3542
- },
3543
- });
3544
- handlers.push(hookHandler);
3545
- }
3546
- }
3547
- return () => {
3548
- handlers.forEach((h) => h());
3549
- };
3550
- }
3551
-
3552
- function initCanvasContextObserver(win, blockClass, blockSelector) {
3553
- const handlers = [];
3554
- try {
3555
- const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
3556
- return function (contextType, ...args) {
3557
- if (!isBlocked(this, blockClass, blockSelector, true)) {
3558
- if (!('__context' in this))
3559
- this.__context = contextType;
3560
- }
3561
- return original.apply(this, [contextType, ...args]);
3562
- };
3563
- });
3564
- handlers.push(restoreHandler);
3565
- }
3566
- catch (_a) {
3567
- console.error('failed to patch HTMLCanvasElement.prototype.getContext');
3568
- }
3569
- return () => {
3570
- handlers.forEach((h) => h());
3571
- };
3572
- }
3573
-
3574
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, mirror, win) {
3575
- const handlers = [];
3576
- const props = Object.getOwnPropertyNames(prototype);
3577
- for (const prop of props) {
3578
- if ([
3579
- 'isContextLost',
3580
- 'canvas',
3581
- 'drawingBufferWidth',
3582
- 'drawingBufferHeight',
3583
- ].includes(prop)) {
3584
- continue;
3585
- }
3586
- try {
3587
- if (typeof prototype[prop] !== 'function') {
3588
- continue;
3589
- }
3590
- const restoreHandler = patch(prototype, prop, function (original) {
3591
- return function (...args) {
3592
- const result = original.apply(this, args);
3593
- saveWebGLVar(result, win, this);
3594
- if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
3595
- const recordArgs = serializeArgs([...args], win, this);
3596
- const mutation = {
3597
- type,
3598
- property: prop,
3599
- args: recordArgs,
3600
- };
3601
- cb(this.canvas, mutation);
3602
- }
3603
- return result;
3604
- };
3605
- });
3606
- handlers.push(restoreHandler);
3607
- }
3608
- catch (_a) {
3609
- const hookHandler = hookSetter(prototype, prop, {
3610
- set(v) {
3611
- cb(this.canvas, {
3612
- type,
3613
- property: prop,
3614
- args: [v],
3615
- setter: true,
3616
- });
3617
- },
3618
- });
3619
- handlers.push(hookHandler);
3620
- }
3621
- }
3622
- return handlers;
3623
- }
3624
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, mirror) {
3625
- const handlers = [];
3626
- handlers.push(...patchGLPrototype(win.WebGLRenderingContext.prototype, CanvasContext.WebGL, cb, blockClass, blockSelector, mirror, win));
3627
- if (typeof win.WebGL2RenderingContext !== 'undefined') {
3628
- handlers.push(...patchGLPrototype(win.WebGL2RenderingContext.prototype, CanvasContext.WebGL2, cb, blockClass, blockSelector, mirror, win));
3629
- }
3630
- return () => {
3631
- handlers.forEach((h) => h());
3632
- };
3633
- }
3634
-
3635
- var WorkerClass = null;
3636
-
3637
- try {
3638
- var WorkerThreads =
3639
- typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
3640
- typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
3641
- typeof require === 'function' && require('worker_threads');
3642
- WorkerClass = WorkerThreads.Worker;
3643
- } catch(e) {} // eslint-disable-line
3644
-
3645
- function decodeBase64$1(base64, enableUnicode) {
3646
- return Buffer.from(base64, 'base64').toString(enableUnicode ? 'utf16' : 'utf8');
3647
- }
3648
-
3649
- function createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg) {
3650
- var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
3651
- var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
3652
- var source = decodeBase64$1(base64, enableUnicode);
3653
- var start = source.indexOf('\n', 10) + 1;
3654
- var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
3655
- return function WorkerFactory(options) {
3656
- return new WorkerClass(body, Object.assign({}, options, { eval: true }));
3657
- };
3658
- }
3659
-
3660
- function decodeBase64(base64, enableUnicode) {
3661
- var binaryString = atob(base64);
3662
- if (enableUnicode) {
3663
- var binaryView = new Uint8Array(binaryString.length);
3664
- for (var i = 0, n = binaryString.length; i < n; ++i) {
3665
- binaryView[i] = binaryString.charCodeAt(i);
3666
- }
3667
- return String.fromCharCode.apply(null, new Uint16Array(binaryView.buffer));
3668
- }
3669
- return binaryString;
3670
- }
3671
-
3672
- function createURL(base64, sourcemapArg, enableUnicodeArg) {
3673
- var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
3674
- var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
3675
- var source = decodeBase64(base64, enableUnicode);
3676
- var start = source.indexOf('\n', 10) + 1;
3677
- var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
3678
- var blob = new Blob([body], { type: 'application/javascript' });
3679
- return URL.createObjectURL(blob);
3680
- }
3681
-
3682
- function createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg) {
3683
- var url;
3684
- return function WorkerFactory(options) {
3685
- url = url || createURL(base64, sourcemapArg, enableUnicodeArg);
3686
- return new Worker(url, options);
3687
- };
3688
- }
3689
-
3690
- var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
3691
-
3692
- function isNodeJS() {
3693
- return kIsNodeJS;
3694
- }
3695
-
3696
- function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
3697
- if (isNodeJS()) {
3698
- return createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg);
3699
- }
3700
- return createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg);
3701
- }
3702
-
3703
- var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwoKICAgIC8qISAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICAgIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLg0KDQogICAgUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55DQogICAgcHVycG9zZSB3aXRoIG9yIHdpdGhvdXQgZmVlIGlzIGhlcmVieSBncmFudGVkLg0KDQogICAgVEhFIFNPRlRXQVJFIElTIFBST1ZJREVEICJBUyBJUyIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEgNCiAgICBSRUdBUkQgVE8gVEhJUyBTT0ZUV0FSRSBJTkNMVURJTkcgQUxMIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkNCiAgICBBTkQgRklUTkVTUy4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUiBCRSBMSUFCTEUgRk9SIEFOWSBTUEVDSUFMLCBESVJFQ1QsDQogICAgSU5ESVJFQ1QsIE9SIENPTlNFUVVFTlRJQUwgREFNQUdFUyBPUiBBTlkgREFNQUdFUyBXSEFUU09FVkVSIFJFU1VMVElORyBGUk9NDQogICAgTE9TUyBPRiBVU0UsIERBVEEgT1IgUFJPRklUUywgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJBQ1QsIE5FR0xJR0VOQ0UgT1INCiAgICBPVEhFUiBUT1JUSU9VUyBBQ1RJT04sIEFSSVNJTkcgT1VUIE9GIE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgVVNFIE9SDQogICAgUEVSRk9STUFOQ0UgT0YgVEhJUyBTT0ZUV0FSRS4NCiAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiAqLw0KDQogICAgZnVuY3Rpb24gX19hd2FpdGVyKHRoaXNBcmcsIF9hcmd1bWVudHMsIFAsIGdlbmVyYXRvcikgew0KICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgeyByZXR1cm4gdmFsdWUgaW5zdGFuY2VvZiBQID8gdmFsdWUgOiBuZXcgUChmdW5jdGlvbiAocmVzb2x2ZSkgeyByZXNvbHZlKHZhbHVlKTsgfSk7IH0NCiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7DQogICAgICAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWQodmFsdWUpIHsgdHJ5IHsgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgeyB0cnkgeyBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgeyByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsgfQ0KICAgICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOw0KICAgICAgICB9KTsNCiAgICB9CgogICAgLyoKICAgICAqIGJhc2U2NC1hcnJheWJ1ZmZlciAxLjAuMSA8aHR0cHM6Ly9naXRodWIuY29tL25pa2xhc3ZoL2Jhc2U2NC1hcnJheWJ1ZmZlcj4KICAgICAqIENvcHlyaWdodCAoYykgMjAyMSBOaWtsYXMgdm9uIEhlcnR6ZW4gPGh0dHBzOi8vaGVydHplbi5jb20+CiAgICAgKiBSZWxlYXNlZCB1bmRlciBNSVQgTGljZW5zZQogICAgICovCiAgICB2YXIgY2hhcnMgPSAnQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyc7CiAgICAvLyBVc2UgYSBsb29rdXAgdGFibGUgdG8gZmluZCB0aGUgaW5kZXguCiAgICB2YXIgbG9va3VwID0gdHlwZW9mIFVpbnQ4QXJyYXkgPT09ICd1bmRlZmluZWQnID8gW10gOiBuZXcgVWludDhBcnJheSgyNTYpOwogICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjaGFycy5sZW5ndGg7IGkrKykgewogICAgICAgIGxvb2t1cFtjaGFycy5jaGFyQ29kZUF0KGkpXSA9IGk7CiAgICB9CiAgICB2YXIgZW5jb2RlID0gZnVuY3Rpb24gKGFycmF5YnVmZmVyKSB7CiAgICAgICAgdmFyIGJ5dGVzID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlidWZmZXIpLCBpLCBsZW4gPSBieXRlcy5sZW5ndGgsIGJhc2U2NCA9ICcnOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkgKz0gMykgewogICAgICAgICAgICBiYXNlNjQgKz0gY2hhcnNbYnl0ZXNbaV0gPj4gMl07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1soKGJ5dGVzW2ldICYgMykgPDwgNCkgfCAoYnl0ZXNbaSArIDFdID4+IDQpXTsKICAgICAgICAgICAgYmFzZTY0ICs9IGNoYXJzWygoYnl0ZXNbaSArIDFdICYgMTUpIDw8IDIpIHwgKGJ5dGVzW2kgKyAyXSA+PiA2KV07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1tieXRlc1tpICsgMl0gJiA2M107CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gJSAzID09PSAyKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDEpICsgJz0nOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChsZW4gJSAzID09PSAxKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDIpICsgJz09JzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJhc2U2NDsKICAgIH07CgogICAgY29uc3QgbGFzdEJsb2JNYXAgPSBuZXcgTWFwKCk7DQogICAgY29uc3QgdHJhbnNwYXJlbnRCbG9iTWFwID0gbmV3IE1hcCgpOw0KICAgIGZ1bmN0aW9uIGdldFRyYW5zcGFyZW50QmxvYkZvcih3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucykgew0KICAgICAgICByZXR1cm4gX19hd2FpdGVyKHRoaXMsIHZvaWQgMCwgdm9pZCAwLCBmdW5jdGlvbiogKCkgew0KICAgICAgICAgICAgY29uc3QgaWQgPSBgJHt3aWR0aH0tJHtoZWlnaHR9YDsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgaWYgKHRyYW5zcGFyZW50QmxvYk1hcC5oYXMoaWQpKQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJhbnNwYXJlbnRCbG9iTWFwLmdldChpZCk7DQogICAgICAgICAgICAgICAgY29uc3Qgb2Zmc2NyZWVuID0gbmV3IE9mZnNjcmVlbkNhbnZhcyh3aWR0aCwgaGVpZ2h0KTsNCiAgICAgICAgICAgICAgICBvZmZzY3JlZW4uZ2V0Q29udGV4dCgnMmQnKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGFycmF5QnVmZmVyID0geWllbGQgYmxvYi5hcnJheUJ1ZmZlcigpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGJhc2U2NCA9IGVuY29kZShhcnJheUJ1ZmZlcik7DQogICAgICAgICAgICAgICAgdHJhbnNwYXJlbnRCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICcnOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9DQogICAgY29uc3Qgd29ya2VyID0gc2VsZjsNCiAgICB3b3JrZXIub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsNCiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24qICgpIHsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgY29uc3QgeyBpZCwgYml0bWFwLCB3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucyB9ID0gZS5kYXRhOw0KICAgICAgICAgICAgICAgIGNvbnN0IHRyYW5zcGFyZW50QmFzZTY0ID0gZ2V0VHJhbnNwYXJlbnRCbG9iRm9yKHdpZHRoLCBoZWlnaHQsIGRhdGFVUkxPcHRpb25zKTsNCiAgICAgICAgICAgICAgICBjb25zdCBvZmZzY3JlZW4gPSBuZXcgT2Zmc2NyZWVuQ2FudmFzKHdpZHRoLCBoZWlnaHQpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGN0eCA9IG9mZnNjcmVlbi5nZXRDb250ZXh0KCcyZCcpOw0KICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UoYml0bWFwLCAwLCAwKTsNCiAgICAgICAgICAgICAgICBiaXRtYXAuY2xvc2UoKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSBibG9iLnR5cGU7DQogICAgICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB5aWVsZCBibG9iLmFycmF5QnVmZmVyKCk7DQogICAgICAgICAgICAgICAgY29uc3QgYmFzZTY0ID0gZW5jb2RlKGFycmF5QnVmZmVyKTsNCiAgICAgICAgICAgICAgICBpZiAoIWxhc3RCbG9iTWFwLmhhcyhpZCkgJiYgKHlpZWxkIHRyYW5zcGFyZW50QmFzZTY0KSA9PT0gYmFzZTY0KSB7DQogICAgICAgICAgICAgICAgICAgIGxhc3RCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdvcmtlci5wb3N0TWVzc2FnZSh7IGlkIH0pOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBpZiAobGFzdEJsb2JNYXAuZ2V0KGlkKSA9PT0gYmFzZTY0KQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQgfSk7DQogICAgICAgICAgICAgICAgd29ya2VyLnBvc3RNZXNzYWdlKHsNCiAgICAgICAgICAgICAgICAgICAgaWQsDQogICAgICAgICAgICAgICAgICAgIHR5cGUsDQogICAgICAgICAgICAgICAgICAgIGJhc2U2NCwNCiAgICAgICAgICAgICAgICAgICAgd2lkdGgsDQogICAgICAgICAgICAgICAgICAgIGhlaWdodCwNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgICAgICBsYXN0QmxvYk1hcC5zZXQoaWQsIGJhc2U2NCk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlIHsNCiAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQ6IGUuZGF0YS5pZCB9KTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfSk7DQogICAgfTsKCn0pKCk7Cgo=', null, false);
3704
-
3705
- class CanvasManager {
3706
- constructor(options) {
3707
- this.pendingCanvasMutations = new Map();
3708
- this.rafStamps = { latestId: 0, invokeId: null };
3709
- this.frozen = false;
3710
- this.locked = false;
3711
- this.processMutation = (target, mutation) => {
3712
- const newFrame = this.rafStamps.invokeId &&
3713
- this.rafStamps.latestId !== this.rafStamps.invokeId;
3714
- if (newFrame || !this.rafStamps.invokeId)
3715
- this.rafStamps.invokeId = this.rafStamps.latestId;
3716
- if (!this.pendingCanvasMutations.has(target)) {
3717
- this.pendingCanvasMutations.set(target, []);
3718
- }
3719
- this.pendingCanvasMutations.get(target).push(mutation);
3720
- };
3721
- const { sampling = 'all', win, blockClass, blockSelector, recordCanvas, dataURLOptions, } = options;
3722
- this.mutationCb = options.mutationCb;
3723
- this.mirror = options.mirror;
3724
- if (recordCanvas && sampling === 'all')
3725
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
3726
- if (recordCanvas && typeof sampling === 'number')
3727
- this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
3728
- dataURLOptions,
3729
- });
3730
- }
3731
- reset() {
3732
- this.pendingCanvasMutations.clear();
3733
- this.resetObservers && this.resetObservers();
3734
- }
3735
- freeze() {
3736
- this.frozen = true;
3737
- }
3738
- unfreeze() {
3739
- this.frozen = false;
3740
- }
3741
- lock() {
3742
- this.locked = true;
3743
- }
3744
- unlock() {
3745
- this.locked = false;
3746
- }
3747
- initCanvasFPSObserver(fps, win, blockClass, blockSelector, options) {
3748
- const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
3749
- const snapshotInProgressMap = new Map();
3750
- const worker = new WorkerFactory();
3751
- worker.onmessage = (e) => {
3752
- const { id } = e.data;
3753
- snapshotInProgressMap.set(id, false);
3754
- if (!('base64' in e.data))
3755
- return;
3756
- const { base64, type, width, height } = e.data;
3757
- this.mutationCb({
3758
- id,
3759
- type: CanvasContext['2D'],
3760
- commands: [
3761
- {
3762
- property: 'clearRect',
3763
- args: [0, 0, width, height],
3764
- },
3765
- {
3766
- property: 'drawImage',
3767
- args: [
3768
- {
3769
- rr_type: 'ImageBitmap',
3770
- args: [
3771
- {
3772
- rr_type: 'Blob',
3773
- data: [{ rr_type: 'ArrayBuffer', base64 }],
3774
- type,
3775
- },
3776
- ],
3777
- },
3778
- 0,
3779
- 0,
3780
- ],
3781
- },
3782
- ],
3783
- });
3784
- };
3785
- const timeBetweenSnapshots = 1000 / fps;
3786
- let lastSnapshotTime = 0;
3787
- let rafId;
3788
- const getCanvas = () => {
3789
- const matchedCanvas = [];
3790
- win.document.querySelectorAll('canvas').forEach((canvas) => {
3791
- if (!isBlocked(canvas, blockClass, blockSelector, true)) {
3792
- matchedCanvas.push(canvas);
3793
- }
3794
- });
3795
- return matchedCanvas;
3796
- };
3797
- const takeCanvasSnapshots = (timestamp) => {
3798
- if (lastSnapshotTime &&
3799
- timestamp - lastSnapshotTime < timeBetweenSnapshots) {
3800
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3801
- return;
3802
- }
3803
- lastSnapshotTime = timestamp;
3804
- getCanvas()
3805
- .forEach((canvas) => __awaiter(this, void 0, void 0, function* () {
3806
- var _a;
3807
- const id = this.mirror.getId(canvas);
3808
- if (snapshotInProgressMap.get(id))
3809
- return;
3810
- snapshotInProgressMap.set(id, true);
3811
- if (['webgl', 'webgl2'].includes(canvas.__context)) {
3812
- const context = canvas.getContext(canvas.__context);
3813
- if (((_a = context === null || context === void 0 ? void 0 : context.getContextAttributes()) === null || _a === void 0 ? void 0 : _a.preserveDrawingBuffer) === false) {
3814
- context === null || context === void 0 ? void 0 : context.clear(context.COLOR_BUFFER_BIT);
3815
- }
3816
- }
3817
- const bitmap = yield createImageBitmap(canvas);
3818
- worker.postMessage({
3819
- id,
3820
- bitmap,
3821
- width: canvas.width,
3822
- height: canvas.height,
3823
- dataURLOptions: options.dataURLOptions,
3824
- }, [bitmap]);
3825
- }));
3826
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3827
- };
3828
- rafId = requestAnimationFrame(takeCanvasSnapshots);
3829
- this.resetObservers = () => {
3830
- canvasContextReset();
3831
- cancelAnimationFrame(rafId);
3832
- };
3833
- }
3834
- initCanvasMutationObserver(win, blockClass, blockSelector) {
3835
- this.startRAFTimestamping();
3836
- this.startPendingCanvasMutationFlusher();
3837
- const canvasContextReset = initCanvasContextObserver(win, blockClass, blockSelector);
3838
- const canvas2DReset = initCanvas2DMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector);
3839
- const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(this.processMutation.bind(this), win, blockClass, blockSelector, this.mirror);
3840
- this.resetObservers = () => {
3841
- canvasContextReset();
3842
- canvas2DReset();
3843
- canvasWebGL1and2Reset();
3844
- };
3845
- }
3846
- startPendingCanvasMutationFlusher() {
3847
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
3848
- }
3849
- startRAFTimestamping() {
3850
- const setLatestRAFTimestamp = (timestamp) => {
3851
- this.rafStamps.latestId = timestamp;
3852
- requestAnimationFrame(setLatestRAFTimestamp);
3853
- };
3854
- requestAnimationFrame(setLatestRAFTimestamp);
3855
- }
3856
- flushPendingCanvasMutations() {
3857
- this.pendingCanvasMutations.forEach((values, canvas) => {
3858
- const id = this.mirror.getId(canvas);
3859
- this.flushPendingCanvasMutationFor(canvas, id);
3860
- });
3861
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
3862
- }
3863
- flushPendingCanvasMutationFor(canvas, id) {
3864
- if (this.frozen || this.locked) {
3865
- return;
3866
- }
3867
- const valuesWithType = this.pendingCanvasMutations.get(canvas);
3868
- if (!valuesWithType || id === -1)
3869
- return;
3870
- const values = valuesWithType.map((value) => {
3871
- const rest = __rest(value, ["type"]);
3872
- return rest;
3873
- });
3874
- const { type } = valuesWithType[0];
3875
- this.mutationCb({ id, type, commands: values });
3876
- this.pendingCanvasMutations.delete(canvas);
3877
- }
3878
- }
3879
-
3880
- class StylesheetManager {
3881
- constructor(options) {
3882
- this.trackedLinkElements = new WeakSet();
3883
- this.styleMirror = new StyleSheetMirror();
3884
- this.mutationCb = options.mutationCb;
3885
- this.adoptedStyleSheetCb = options.adoptedStyleSheetCb;
3886
- }
3887
- attachLinkElement(linkEl, childSn) {
3888
- if ('_cssText' in childSn.attributes)
3889
- this.mutationCb({
3890
- adds: [],
3891
- removes: [],
3892
- texts: [],
3893
- attributes: [
3894
- {
3895
- id: childSn.id,
3896
- attributes: childSn
3897
- .attributes,
3898
- },
3899
- ],
3900
- });
3901
- this.trackLinkElement(linkEl);
3902
- }
3903
- trackLinkElement(linkEl) {
3904
- if (this.trackedLinkElements.has(linkEl))
3905
- return;
3906
- this.trackedLinkElements.add(linkEl);
3907
- this.trackStylesheetInLinkElement(linkEl);
3908
- }
3909
- adoptStyleSheets(sheets, hostId) {
3910
- if (sheets.length === 0)
3911
- return;
3912
- const adoptedStyleSheetData = {
3913
- id: hostId,
3914
- styleIds: [],
3915
- };
3916
- const styles = [];
3917
- for (const sheet of sheets) {
3918
- let styleId;
3919
- if (!this.styleMirror.has(sheet)) {
3920
- styleId = this.styleMirror.add(sheet);
3921
- const rules = Array.from(sheet.rules || CSSRule);
3922
- styles.push({
3923
- styleId,
3924
- rules: rules.map((r, index) => {
3925
- return {
3926
- rule: getCssRuleString(r),
3927
- index,
3928
- };
3929
- }),
3930
- });
3931
- }
3932
- else
3933
- styleId = this.styleMirror.getId(sheet);
3934
- adoptedStyleSheetData.styleIds.push(styleId);
3935
- }
3936
- if (styles.length > 0)
3937
- adoptedStyleSheetData.styles = styles;
3938
- this.adoptedStyleSheetCb(adoptedStyleSheetData);
3939
- }
3940
- reset() {
3941
- this.styleMirror.reset();
3942
- this.trackedLinkElements = new WeakSet();
3943
- }
3944
- trackStylesheetInLinkElement(linkEl) {
3945
- }
3946
- }
3947
-
3948
- function wrapEvent(e) {
3949
- return Object.assign(Object.assign({}, e), { timestamp: Date.now() });
3950
- }
3951
- let wrappedEmit;
3952
- let takeFullSnapshot;
3953
- let canvasManager;
3954
- let recording = false;
3955
- const mirror = createMirror();
3956
- function record(options = {}) {
3957
- const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, ignoreClass = 'rr-ignore', maskTextClass = 'rr-mask', maskTextSelector = null, inlineStylesheet = true, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, dataURLOptions = {}, mousemoveWait, recordCanvas = false, recordCrossOriginIframes = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, ignoreCSSAttributes = new Set([]), } = options;
3958
- const inEmittingFrame = recordCrossOriginIframes
3959
- ? window.parent === window
3960
- : true;
3961
- let passEmitsToParent = false;
3962
- if (!inEmittingFrame) {
3963
- try {
3964
- window.parent.document;
3965
- passEmitsToParent = false;
3966
- }
3967
- catch (e) {
3968
- passEmitsToParent = true;
3969
- }
3970
- }
3971
- if (inEmittingFrame && !emit) {
3972
- throw new Error('emit function is required');
3973
- }
3974
- if (mousemoveWait !== undefined && sampling.mousemove === undefined) {
3975
- sampling.mousemove = mousemoveWait;
3976
- }
3977
- mirror.reset();
3978
- const maskInputOptions = maskAllInputs === true
3979
- ? {
3980
- color: true,
3981
- date: true,
3982
- 'datetime-local': true,
3983
- email: true,
3984
- month: true,
3985
- number: true,
3986
- range: true,
3987
- search: true,
3988
- tel: true,
3989
- text: true,
3990
- time: true,
3991
- url: true,
3992
- week: true,
3993
- textarea: true,
3994
- select: true,
3995
- password: true,
3996
- }
3997
- : _maskInputOptions !== undefined
3998
- ? _maskInputOptions
3999
- : { password: true };
4000
- const slimDOMOptions = _slimDOMOptions === true || _slimDOMOptions === 'all'
4001
- ? {
4002
- script: true,
4003
- comment: true,
4004
- headFavicon: true,
4005
- headWhitespace: true,
4006
- headMetaSocial: true,
4007
- headMetaRobots: true,
4008
- headMetaHttpEquiv: true,
4009
- headMetaVerification: true,
4010
- headMetaAuthorship: _slimDOMOptions === 'all',
4011
- headMetaDescKeywords: _slimDOMOptions === 'all',
4012
- }
4013
- : _slimDOMOptions
4014
- ? _slimDOMOptions
4015
- : {};
4016
- polyfill();
4017
- let lastFullSnapshotEvent;
4018
- let incrementalSnapshotCount = 0;
4019
- const eventProcessor = (e) => {
4020
- for (const plugin of plugins || []) {
4021
- if (plugin.eventProcessor) {
4022
- e = plugin.eventProcessor(e);
4023
- }
4024
- }
4025
- if (packFn) {
4026
- e = packFn(e);
4027
- }
4028
- return e;
4029
- };
4030
- wrappedEmit = (e, isCheckout) => {
4031
- var _a;
4032
- if (((_a = mutationBuffers[0]) === null || _a === void 0 ? void 0 : _a.isFrozen()) &&
4033
- e.type !== EventType.FullSnapshot &&
4034
- !(e.type === EventType.IncrementalSnapshot &&
4035
- e.data.source === IncrementalSource.Mutation)) {
4036
- mutationBuffers.forEach((buf) => buf.unfreeze());
4037
- }
4038
- if (inEmittingFrame) {
4039
- emit === null || emit === void 0 ? void 0 : emit(eventProcessor(e), isCheckout);
4040
- }
4041
- else if (passEmitsToParent) {
4042
- const message = {
4043
- type: 'rrweb',
4044
- event: eventProcessor(e),
4045
- isCheckout,
4046
- };
4047
- window.parent.postMessage(message, '*');
4048
- }
4049
- if (e.type === EventType.FullSnapshot) {
4050
- lastFullSnapshotEvent = e;
4051
- incrementalSnapshotCount = 0;
4052
- }
4053
- else if (e.type === EventType.IncrementalSnapshot) {
4054
- if (e.data.source === IncrementalSource.Mutation &&
4055
- e.data.isAttachIframe) {
4056
- return;
4057
- }
4058
- incrementalSnapshotCount++;
4059
- const exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
4060
- const exceedTime = checkoutEveryNms &&
4061
- e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
4062
- if (exceedCount || exceedTime) {
4063
- takeFullSnapshot(true);
4064
- }
4065
- }
4066
- };
4067
- const wrappedMutationEmit = (m) => {
4068
- wrappedEmit(wrapEvent({
4069
- type: EventType.IncrementalSnapshot,
4070
- data: Object.assign({ source: IncrementalSource.Mutation }, m),
4071
- }));
4072
- };
4073
- const wrappedScrollEmit = (p) => wrappedEmit(wrapEvent({
4074
- type: EventType.IncrementalSnapshot,
4075
- data: Object.assign({ source: IncrementalSource.Scroll }, p),
4076
- }));
4077
- const wrappedCanvasMutationEmit = (p) => wrappedEmit(wrapEvent({
4078
- type: EventType.IncrementalSnapshot,
4079
- data: Object.assign({ source: IncrementalSource.CanvasMutation }, p),
4080
- }));
4081
- const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
4082
- type: EventType.IncrementalSnapshot,
4083
- data: Object.assign({ source: IncrementalSource.AdoptedStyleSheet }, a),
4084
- }));
4085
- const stylesheetManager = new StylesheetManager({
4086
- mutationCb: wrappedMutationEmit,
4087
- adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
4088
- });
4089
- const iframeManager = new IframeManager({
4090
- mirror,
4091
- mutationCb: wrappedMutationEmit,
4092
- stylesheetManager: stylesheetManager,
4093
- recordCrossOriginIframes,
4094
- wrappedEmit,
4095
- });
4096
- for (const plugin of plugins || []) {
4097
- if (plugin.getMirror)
4098
- plugin.getMirror({
4099
- nodeMirror: mirror,
4100
- crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
4101
- crossOriginIframeStyleMirror: iframeManager.crossOriginIframeStyleMirror,
4102
- });
4103
- }
4104
- canvasManager = new CanvasManager({
4105
- recordCanvas,
4106
- mutationCb: wrappedCanvasMutationEmit,
4107
- win: window,
4108
- blockClass,
4109
- blockSelector,
4110
- mirror,
4111
- sampling: sampling.canvas,
4112
- dataURLOptions,
4113
- });
4114
- const shadowDomManager = new ShadowDomManager({
4115
- mutationCb: wrappedMutationEmit,
4116
- scrollCb: wrappedScrollEmit,
4117
- bypassOptions: {
4118
- blockClass,
4119
- blockSelector,
4120
- maskTextClass,
4121
- maskTextSelector,
4122
- inlineStylesheet,
4123
- maskInputOptions,
4124
- dataURLOptions,
4125
- maskTextFn,
4126
- maskInputFn,
4127
- recordCanvas,
4128
- inlineImages,
4129
- sampling,
4130
- slimDOMOptions,
4131
- iframeManager,
4132
- stylesheetManager,
4133
- canvasManager,
4134
- keepIframeSrcFn,
4135
- },
4136
- mirror,
4137
- });
4138
- takeFullSnapshot = (isCheckout = false) => {
4139
- var _a, _b, _c, _d, _e, _f;
4140
- wrappedEmit(wrapEvent({
4141
- type: EventType.Meta,
4142
- data: {
4143
- href: window.location.href,
4144
- width: getWindowWidth(),
4145
- height: getWindowHeight(),
4146
- },
4147
- }), isCheckout);
4148
- stylesheetManager.reset();
4149
- mutationBuffers.forEach((buf) => buf.lock());
4150
- const node = snapshot(document, {
4151
- mirror,
4152
- blockClass,
4153
- blockSelector,
4154
- maskTextClass,
4155
- maskTextSelector,
4156
- inlineStylesheet,
4157
- maskAllInputs: maskInputOptions,
4158
- maskTextFn,
4159
- slimDOM: slimDOMOptions,
4160
- dataURLOptions,
4161
- recordCanvas,
4162
- inlineImages,
4163
- onSerialize: (n) => {
4164
- if (isSerializedIframe(n, mirror)) {
4165
- iframeManager.addIframe(n);
4166
- }
4167
- if (isSerializedStylesheet(n, mirror)) {
4168
- stylesheetManager.trackLinkElement(n);
4169
- }
4170
- if (hasShadowRoot(n)) {
4171
- shadowDomManager.addShadowRoot(n.shadowRoot, document);
4172
- }
4173
- },
4174
- onIframeLoad: (iframe, childSn) => {
4175
- iframeManager.attachIframe(iframe, childSn);
4176
- shadowDomManager.observeAttachShadow(iframe);
4177
- },
4178
- onStylesheetLoad: (linkEl, childSn) => {
4179
- stylesheetManager.attachLinkElement(linkEl, childSn);
4180
- },
4181
- keepIframeSrcFn,
4182
- });
4183
- if (!node) {
4184
- return console.warn('Failed to snapshot the document');
4185
- }
4186
- wrappedEmit(wrapEvent({
4187
- type: EventType.FullSnapshot,
4188
- data: {
4189
- node,
4190
- initialOffset: {
4191
- left: window.pageXOffset !== undefined
4192
- ? window.pageXOffset
4193
- : (document === null || document === void 0 ? void 0 : document.documentElement.scrollLeft) ||
4194
- ((_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.scrollLeft) ||
4195
- ((_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.scrollLeft) ||
4196
- 0,
4197
- top: window.pageYOffset !== undefined
4198
- ? window.pageYOffset
4199
- : (document === null || document === void 0 ? void 0 : document.documentElement.scrollTop) ||
4200
- ((_e = (_d = document === null || document === void 0 ? void 0 : document.body) === null || _d === void 0 ? void 0 : _d.parentElement) === null || _e === void 0 ? void 0 : _e.scrollTop) ||
4201
- ((_f = document === null || document === void 0 ? void 0 : document.body) === null || _f === void 0 ? void 0 : _f.scrollTop) ||
4202
- 0,
4203
- },
4204
- },
4205
- }));
4206
- mutationBuffers.forEach((buf) => buf.unlock());
4207
- if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
4208
- stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
4209
- };
4210
- try {
4211
- const handlers = [];
4212
- handlers.push(on('DOMContentLoaded', () => {
4213
- wrappedEmit(wrapEvent({
4214
- type: EventType.DomContentLoaded,
4215
- data: {},
4216
- }));
4217
- }));
4218
- const observe = (doc) => {
4219
- var _a;
4220
- return initObservers({
4221
- mutationCb: wrappedMutationEmit,
4222
- mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
4223
- type: EventType.IncrementalSnapshot,
4224
- data: {
4225
- source,
4226
- positions,
4227
- },
4228
- })),
4229
- mouseInteractionCb: (d) => wrappedEmit(wrapEvent({
4230
- type: EventType.IncrementalSnapshot,
4231
- data: Object.assign({ source: IncrementalSource.MouseInteraction }, d),
4232
- })),
4233
- scrollCb: wrappedScrollEmit,
4234
- viewportResizeCb: (d) => wrappedEmit(wrapEvent({
4235
- type: EventType.IncrementalSnapshot,
4236
- data: Object.assign({ source: IncrementalSource.ViewportResize }, d),
4237
- })),
4238
- inputCb: (v) => wrappedEmit(wrapEvent({
4239
- type: EventType.IncrementalSnapshot,
4240
- data: Object.assign({ source: IncrementalSource.Input }, v),
4241
- })),
4242
- mediaInteractionCb: (p) => wrappedEmit(wrapEvent({
4243
- type: EventType.IncrementalSnapshot,
4244
- data: Object.assign({ source: IncrementalSource.MediaInteraction }, p),
4245
- })),
4246
- styleSheetRuleCb: (r) => wrappedEmit(wrapEvent({
4247
- type: EventType.IncrementalSnapshot,
4248
- data: Object.assign({ source: IncrementalSource.StyleSheetRule }, r),
4249
- })),
4250
- styleDeclarationCb: (r) => wrappedEmit(wrapEvent({
4251
- type: EventType.IncrementalSnapshot,
4252
- data: Object.assign({ source: IncrementalSource.StyleDeclaration }, r),
4253
- })),
4254
- canvasMutationCb: wrappedCanvasMutationEmit,
4255
- fontCb: (p) => wrappedEmit(wrapEvent({
4256
- type: EventType.IncrementalSnapshot,
4257
- data: Object.assign({ source: IncrementalSource.Font }, p),
4258
- })),
4259
- selectionCb: (p) => {
4260
- wrappedEmit(wrapEvent({
4261
- type: EventType.IncrementalSnapshot,
4262
- data: Object.assign({ source: IncrementalSource.Selection }, p),
4263
- }));
4264
- },
4265
- blockClass,
4266
- ignoreClass,
4267
- maskTextClass,
4268
- maskTextSelector,
4269
- maskInputOptions,
4270
- inlineStylesheet,
4271
- sampling,
4272
- recordCanvas,
4273
- inlineImages,
4274
- userTriggeredOnInput,
4275
- collectFonts,
4276
- doc,
4277
- maskInputFn,
4278
- maskTextFn,
4279
- keepIframeSrcFn,
4280
- blockSelector,
4281
- slimDOMOptions,
4282
- dataURLOptions,
4283
- mirror,
4284
- iframeManager,
4285
- stylesheetManager,
4286
- shadowDomManager,
4287
- canvasManager,
4288
- ignoreCSSAttributes,
4289
- plugins: ((_a = plugins === null || plugins === void 0 ? void 0 : plugins.filter((p) => p.observer)) === null || _a === void 0 ? void 0 : _a.map((p) => ({
4290
- observer: p.observer,
4291
- options: p.options,
4292
- callback: (payload) => wrappedEmit(wrapEvent({
4293
- type: EventType.Plugin,
4294
- data: {
4295
- plugin: p.name,
4296
- payload,
4297
- },
4298
- })),
4299
- }))) || [],
4300
- }, hooks);
4301
- };
4302
- iframeManager.addLoadListener((iframeEl) => {
4303
- handlers.push(observe(iframeEl.contentDocument));
4304
- });
4305
- const init = () => {
4306
- takeFullSnapshot();
4307
- handlers.push(observe(document));
4308
- recording = true;
4309
- };
4310
- if (document.readyState === 'interactive' ||
4311
- document.readyState === 'complete') {
4312
- init();
4313
- }
4314
- else {
4315
- handlers.push(on('load', () => {
4316
- wrappedEmit(wrapEvent({
4317
- type: EventType.Load,
4318
- data: {},
4319
- }));
4320
- init();
4321
- }, window));
4322
- }
4323
- return () => {
4324
- handlers.forEach((h) => h());
4325
- recording = false;
4326
- };
4327
- }
4328
- catch (error) {
4329
- console.warn(error);
4330
- }
4331
- }
4332
- record.addCustomEvent = (tag, payload) => {
4333
- if (!recording) {
4334
- throw new Error('please add custom event after start recording');
4335
- }
4336
- wrappedEmit(wrapEvent({
4337
- type: EventType.Custom,
4338
- data: {
4339
- tag,
4340
- payload,
4341
- },
4342
- }));
4343
- };
4344
- record.freezePage = () => {
4345
- mutationBuffers.forEach((buf) => buf.freeze());
4346
- };
4347
- record.takeFullSnapshot = (isCheckout) => {
4348
- if (!recording) {
4349
- throw new Error('please take full snapshot after start recording');
4350
- }
4351
- takeFullSnapshot(isCheckout);
4352
- };
4353
- record.mirror = mirror;
4354
-
4355
436
  var ANON_ID_KEY = 'co_anon_id';
4356
437
  var SESSION_ID_KEY = 'co_session_id';
4357
438
  function getAnonymousId() {
@@ -4478,33 +559,32 @@ function _doAuthorize2() {
4478
559
  });
4479
560
  case 3:
4480
561
  res = _context2.sent;
4481
- console.log("Auth here: ", res);
4482
562
  if (res.ok) {
4483
- _context2.next = 8;
563
+ _context2.next = 7;
4484
564
  break;
4485
565
  }
4486
566
  console.error('[CoreOutline] Authorization failed:', res.status);
4487
567
  return _context2.abrupt("return", false);
4488
- case 8:
4489
- _context2.next = 10;
568
+ case 7:
569
+ _context2.next = 9;
4490
570
  return res.json();
4491
- case 10:
571
+ case 9:
4492
572
  data = _context2.sent;
4493
573
  _token = data.access_token;
4494
574
  _organizationId = data.organization_id;
4495
575
  expiresIn = data.expires_in || 24 * 3600;
4496
576
  _scheduleTokenRefresh(expiresIn);
4497
577
  return _context2.abrupt("return", true);
4498
- case 18:
4499
- _context2.prev = 18;
578
+ case 17:
579
+ _context2.prev = 17;
4500
580
  _context2.t0 = _context2["catch"](0);
4501
581
  console.error('[CoreOutline] Authorization error:', _context2.t0);
4502
582
  return _context2.abrupt("return", false);
4503
- case 22:
583
+ case 21:
4504
584
  case "end":
4505
585
  return _context2.stop();
4506
586
  }
4507
- }, _callee2, null, [[0, 18]]);
587
+ }, _callee2, null, [[0, 17]]);
4508
588
  }));
4509
589
  return _doAuthorize2.apply(this, arguments);
4510
590
  }
@@ -4536,13 +616,19 @@ function _ensureFreshToken2() {
4536
616
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4537
617
  while (1) switch (_context4.prev = _context4.next) {
4538
618
  case 0:
619
+ if (!_token) {
620
+ _context4.next = 2;
621
+ break;
622
+ }
623
+ return _context4.abrupt("return");
624
+ case 2:
4539
625
  if (!(_warehouseId && _dataSourceId && _dataSourceSecret)) {
4540
- _context4.next = 3;
626
+ _context4.next = 5;
4541
627
  break;
4542
628
  }
4543
- _context4.next = 3;
629
+ _context4.next = 5;
4544
630
  return _doAuthorize(_warehouseId, _dataSourceId, _dataSourceSecret);
4545
- case 3:
631
+ case 5:
4546
632
  case "end":
4547
633
  return _context4.stop();
4548
634
  }
@@ -4551,12 +637,12 @@ function _ensureFreshToken2() {
4551
637
  return _ensureFreshToken2.apply(this, arguments);
4552
638
  }
4553
639
  function trackEvent(eventType, payload) {
4554
- // if (!_token) return;
4555
-
640
+ if (!_token) return;
4556
641
  var event = _objectSpread2({
4557
642
  event_id: v4(),
4558
643
  event_type: eventType,
4559
- event_ts: new Date().toISOString()
644
+ event_ts: new Date().toISOString(),
645
+ account_id: _dataSourceId
4560
646
  }, payload);
4561
647
  _buffer.push(event);
4562
648
  if (!_flushInterval) {
@@ -4575,15 +661,18 @@ function _flush() {
4575
661
  _context5.next = 2;
4576
662
  return _ensureFreshToken();
4577
663
  case 2:
4578
- // if (!_token || _buffer.length === 0) return;
4579
- console.log(_token);
664
+ if (!(!_token || _buffer.length === 0)) {
665
+ _context5.next = 4;
666
+ break;
667
+ }
668
+ return _context5.abrupt("return");
669
+ case 4:
4580
670
  events = _buffer.splice(0, _buffer.length);
4581
671
  body = JSON.stringify({
4582
672
  warehouse_id: _warehouseId,
4583
673
  organization_id: _organizationId,
4584
674
  events: events
4585
675
  });
4586
- console.log("Flushing here: ", body);
4587
676
  fetch("".concat(INGEST_BASE, "/api/ingest/events"), {
4588
677
  method: 'POST',
4589
678
  headers: {
@@ -4614,9 +703,12 @@ function _sendRrwebBatch() {
4614
703
  _context6.next = 2;
4615
704
  return _ensureFreshToken();
4616
705
  case 2:
4617
- // if (!_token || !chunks || chunks.length === 0) return;
4618
- console.log(_token);
4619
- console.log("RRWeb here: ", chunks);
706
+ if (!(!_token || !chunks || chunks.length === 0)) {
707
+ _context6.next = 4;
708
+ break;
709
+ }
710
+ return _context6.abrupt("return");
711
+ case 4:
4620
712
  _context6.prev = 4;
4621
713
  _context6.next = 7;
4622
714
  return fetch("".concat(INGEST_BASE, "/api/ingest/rrweb"), {