@highlight-run/rrweb 1.2.0 → 2.0.1

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.
Files changed (185) hide show
  1. package/dist/plugins/console-record.js +655 -0
  2. package/dist/plugins/console-record.min.js +1 -1
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +293 -0
  5. package/dist/plugins/console-replay.min.js +16 -0
  6. package/dist/plugins/console-replay.min.js.map +1 -0
  7. package/dist/plugins/sequential-id-record.js +33 -0
  8. package/dist/plugins/sequential-id-record.min.js +2 -0
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -0
  10. package/dist/plugins/sequential-id-replay.js +37 -0
  11. package/dist/plugins/sequential-id-replay.min.js +2 -0
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -0
  13. package/dist/record/rrweb-record-pack.js +747 -0
  14. package/dist/record/rrweb-record-pack.min.js +16 -0
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -0
  16. package/dist/record/rrweb-record.js +3318 -0
  17. package/dist/record/rrweb-record.min.js +16 -0
  18. package/dist/record/rrweb-record.min.js.map +1 -0
  19. package/dist/replay/rrweb-replay-unpack.js +4626 -0
  20. package/dist/replay/rrweb-replay-unpack.min.css +2 -0
  21. package/dist/replay/rrweb-replay-unpack.min.css.map +1 -0
  22. package/dist/replay/rrweb-replay-unpack.min.js +30 -0
  23. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -0
  24. package/dist/replay/rrweb-replay.js +4216 -0
  25. package/dist/replay/rrweb-replay.min.css +2 -0
  26. package/dist/replay/rrweb-replay.min.css.map +1 -0
  27. package/dist/replay/rrweb-replay.min.js +30 -0
  28. package/dist/replay/rrweb-replay.min.js.map +1 -0
  29. package/dist/rrweb-all.js +8708 -0
  30. package/dist/rrweb-all.min.css +2 -0
  31. package/dist/rrweb-all.min.css.map +1 -0
  32. package/dist/rrweb-all.min.js +30 -0
  33. package/dist/rrweb-all.min.js.map +1 -0
  34. package/dist/rrweb.js +7294 -0
  35. package/dist/rrweb.min.css +2 -0
  36. package/dist/rrweb.min.css.map +1 -0
  37. package/dist/rrweb.min.js +2 -2
  38. package/dist/rrweb.min.js.map +1 -1
  39. package/es/rrweb/ext/@xstate/fsm/es/index.js +17 -0
  40. package/es/rrweb/ext/base64-arraybuffer/dist/base64-arraybuffer.es5.js +49 -0
  41. package/es/rrweb/ext/fflate/esm/browser.js +777 -0
  42. package/es/rrweb/ext/mitt/dist/mitt.es.js +63 -0
  43. package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +78 -0
  44. package/es/rrweb/packages/rrweb/src/entries/all.js +13 -0
  45. package/es/rrweb/packages/rrweb/src/index.js +12 -0
  46. package/es/rrweb/packages/rrweb/src/packer/base.js +3 -0
  47. package/es/rrweb/packages/rrweb/src/packer/pack.js +10 -0
  48. package/es/rrweb/packages/rrweb/src/packer/unpack.js +29 -0
  49. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +179 -0
  50. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +134 -0
  51. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +141 -0
  52. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +111 -0
  53. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +23 -0
  54. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +28 -0
  55. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +32 -0
  56. package/es/rrweb/packages/rrweb/src/record/index.js +381 -0
  57. package/es/rrweb/packages/rrweb/src/record/mutation.js +532 -0
  58. package/es/rrweb/packages/rrweb/src/record/observer.js +665 -0
  59. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +78 -0
  60. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +93 -0
  61. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +30 -0
  62. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +116 -0
  63. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +78 -0
  64. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +45 -0
  65. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +25 -0
  66. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +35 -0
  67. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +124 -0
  68. package/es/rrweb/packages/rrweb/src/replay/index.js +1864 -0
  69. package/es/rrweb/packages/rrweb/src/replay/machine.js +321 -0
  70. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +221 -0
  71. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +8 -0
  72. package/es/rrweb/packages/rrweb/src/replay/timer.js +96 -0
  73. package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +121 -0
  74. package/es/rrweb/packages/rrweb/src/types.js +75 -0
  75. package/es/rrweb/packages/rrweb/src/utils.js +509 -0
  76. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1697 -0
  77. package/lib/plugins/console-record.js +650 -0
  78. package/lib/plugins/console-replay.js +288 -0
  79. package/lib/plugins/sequential-id-record.js +28 -0
  80. package/lib/plugins/sequential-id-replay.js +32 -0
  81. package/lib/record/rrweb-record-pack.js +742 -0
  82. package/lib/record/rrweb-record.js +3315 -0
  83. package/lib/replay/rrweb-replay-unpack.js +4621 -0
  84. package/lib/replay/rrweb-replay.js +4211 -0
  85. package/lib/rrweb-all.js +8703 -0
  86. package/lib/rrweb.js +7289 -0
  87. package/package.json +41 -43
  88. package/typings/entries/all.d.ts +6 -0
  89. package/{dist → typings}/entries/record-pack.d.ts +0 -0
  90. package/{dist → typings}/entries/replay-unpack.d.ts +0 -0
  91. package/{dist → typings}/index.d.ts +1 -2
  92. package/{dist → typings}/packer/base.d.ts +0 -0
  93. package/{dist → typings}/packer/index.d.ts +0 -0
  94. package/{dist → typings}/packer/pack.d.ts +0 -0
  95. package/{dist → typings}/packer/unpack.d.ts +0 -0
  96. package/{dist → typings}/plugins/console/record/error-stack-parser.d.ts +0 -0
  97. package/{dist → typings}/plugins/console/record/index.d.ts +3 -2
  98. package/{dist → typings}/plugins/console/record/stringify.d.ts +0 -0
  99. package/{dist → typings}/plugins/console/replay/index.d.ts +2 -2
  100. package/{dist → typings}/plugins/sequential-id/record/index.d.ts +0 -0
  101. package/{dist → typings}/plugins/sequential-id/replay/index.d.ts +0 -0
  102. package/{dist → typings}/record/iframe-manager.d.ts +1 -1
  103. package/{dist → typings}/record/index.d.ts +0 -0
  104. package/{dist → typings}/record/mutation.d.ts +5 -8
  105. package/typings/record/observer.d.ts +7 -0
  106. package/{dist → typings}/record/observers/canvas/2d.d.ts +0 -0
  107. package/{dist → typings}/record/observers/canvas/canvas-manager.d.ts +0 -0
  108. package/{dist → typings}/record/observers/canvas/canvas.d.ts +0 -0
  109. package/{dist → typings}/record/observers/canvas/serialize-args.d.ts +1 -1
  110. package/{dist → typings}/record/observers/canvas/webgl.d.ts +0 -0
  111. package/typings/record/observers/canvas/webgl2.d.ts +2 -0
  112. package/typings/record/shadow-dom-manager.d.ts +21 -0
  113. package/{dist → typings}/replay/canvas/2d.d.ts +0 -0
  114. package/{dist → typings}/replay/canvas/index.d.ts +0 -0
  115. package/{dist → typings}/replay/canvas/webgl.d.ts +0 -0
  116. package/{dist → typings}/replay/index.d.ts +1 -0
  117. package/{dist → typings}/replay/machine.d.ts +0 -0
  118. package/{dist → typings}/replay/smoothscroll.d.ts +0 -0
  119. package/{dist → typings}/replay/styles/inject-style.d.ts +0 -0
  120. package/{dist → typings}/replay/timer.d.ts +0 -0
  121. package/{dist → typings}/replay/virtual-styles.d.ts +1 -1
  122. package/{dist → typings}/rrdom/index.d.ts +0 -0
  123. package/{dist → typings}/rrdom/tree-node.d.ts +0 -0
  124. package/{dist → typings}/types.d.ts +7 -8
  125. package/{dist → typings}/utils.d.ts +3 -4
  126. package/CHANGELOG.md +0 -26
  127. package/README.md +0 -124
  128. package/README.zh_CN.md +0 -122
  129. package/dist/entries/all.d.ts +0 -4
  130. package/dist/index.css +0 -82
  131. package/dist/index.css.map +0 -1
  132. package/dist/index.js +0 -3
  133. package/dist/index.js.LICENSE.txt +0 -14
  134. package/dist/index.js.map +0 -1
  135. package/dist/plugins/entries/all.d.ts +0 -4
  136. package/dist/plugins/entries/record-pack.d.ts +0 -2
  137. package/dist/plugins/entries/replay-unpack.d.ts +0 -2
  138. package/dist/plugins/index.d.ts +0 -9
  139. package/dist/plugins/packer/base.d.ts +0 -7
  140. package/dist/plugins/packer/index.d.ts +0 -2
  141. package/dist/plugins/packer/pack.d.ts +0 -2
  142. package/dist/plugins/packer/unpack.d.ts +0 -2
  143. package/dist/plugins/plugins/console/record/error-stack-parser.d.ts +0 -37
  144. package/dist/plugins/plugins/console/record/index.d.ts +0 -41
  145. package/dist/plugins/plugins/console/record/stringify.d.ts +0 -2
  146. package/dist/plugins/plugins/console/replay/index.d.ts +0 -9
  147. package/dist/plugins/plugins/sequential-id/record/index.d.ts +0 -6
  148. package/dist/plugins/plugins/sequential-id/replay/index.d.ts +0 -7
  149. package/dist/plugins/record/iframe-manager.d.ts +0 -13
  150. package/dist/plugins/record/index.d.ts +0 -9
  151. package/dist/plugins/record/mutation.d.ts +0 -45
  152. package/dist/plugins/record/observer.d.ts +0 -11
  153. package/dist/plugins/record/observers/canvas/2d.d.ts +0 -2
  154. package/dist/plugins/record/observers/canvas/canvas-manager.d.ts +0 -32
  155. package/dist/plugins/record/observers/canvas/canvas.d.ts +0 -2
  156. package/dist/plugins/record/observers/canvas/serialize-args.d.ts +0 -6
  157. package/dist/plugins/record/observers/canvas/webgl.d.ts +0 -2
  158. package/dist/plugins/record/shadow-dom-manager.d.ts +0 -34
  159. package/dist/plugins/replay/canvas/2d.d.ts +0 -9
  160. package/dist/plugins/replay/canvas/index.d.ts +0 -9
  161. package/dist/plugins/replay/canvas/webgl.d.ts +0 -11
  162. package/dist/plugins/replay/index.d.ts +0 -82
  163. package/dist/plugins/replay/machine.d.ts +0 -85
  164. package/dist/plugins/replay/smoothscroll.d.ts +0 -1
  165. package/dist/plugins/replay/styles/inject-style.d.ts +0 -2
  166. package/dist/plugins/replay/timer.d.ts +0 -19
  167. package/dist/plugins/replay/virtual-styles.d.ts +0 -43
  168. package/dist/plugins/rrdom/index.d.ts +0 -1
  169. package/dist/plugins/rrdom/tree-node.d.ts +0 -20
  170. package/dist/plugins/snapshot/css.d.ts +0 -92
  171. package/dist/plugins/snapshot/index.d.ts +0 -5
  172. package/dist/plugins/snapshot/rebuild.d.ts +0 -19
  173. package/dist/plugins/snapshot/snapshot.d.ts +0 -49
  174. package/dist/plugins/snapshot/types.d.ts +0 -99
  175. package/dist/plugins/snapshot/utils.d.ts +0 -11
  176. package/dist/plugins/types.d.ts +0 -509
  177. package/dist/plugins/utils.d.ts +0 -71
  178. package/dist/record/observer.d.ts +0 -11
  179. package/dist/record/shadow-dom-manager.d.ts +0 -34
  180. package/dist/snapshot/css.d.ts +0 -92
  181. package/dist/snapshot/index.d.ts +0 -5
  182. package/dist/snapshot/rebuild.d.ts +0 -19
  183. package/dist/snapshot/snapshot.d.ts +0 -49
  184. package/dist/snapshot/types.d.ts +0 -99
  185. package/dist/snapshot/utils.d.ts +0 -11
@@ -0,0 +1,121 @@
1
+ import { __spreadArray, __read } from '../../ext/tslib/tslib.es6.js';
2
+
3
+ var StyleRuleType;
4
+ (function (StyleRuleType) {
5
+ StyleRuleType[StyleRuleType["Insert"] = 0] = "Insert";
6
+ StyleRuleType[StyleRuleType["Remove"] = 1] = "Remove";
7
+ StyleRuleType[StyleRuleType["Snapshot"] = 2] = "Snapshot";
8
+ StyleRuleType[StyleRuleType["SetProperty"] = 3] = "SetProperty";
9
+ StyleRuleType[StyleRuleType["RemoveProperty"] = 4] = "RemoveProperty";
10
+ })(StyleRuleType || (StyleRuleType = {}));
11
+ function getNestedRule(rules, position) {
12
+ var rule = rules[position[0]];
13
+ if (position.length === 1) {
14
+ return rule;
15
+ }
16
+ else {
17
+ return getNestedRule(rule.cssRules[position[1]]
18
+ .cssRules, position.slice(2));
19
+ }
20
+ }
21
+ function getPositionsAndIndex(nestedIndex) {
22
+ var positions = __spreadArray([], __read(nestedIndex), false);
23
+ var index = positions.pop();
24
+ return { positions: positions, index: index };
25
+ }
26
+ function applyVirtualStyleRulesToNode(storedRules, styleNode) {
27
+ var sheet = styleNode.sheet;
28
+ if (!sheet) {
29
+ return;
30
+ }
31
+ storedRules.forEach(function (rule) {
32
+ if (rule.type === StyleRuleType.Insert) {
33
+ try {
34
+ if (Array.isArray(rule.index)) {
35
+ var _a = getPositionsAndIndex(rule.index), positions = _a.positions, index = _a.index;
36
+ var nestedRule = getNestedRule(sheet.cssRules, positions);
37
+ nestedRule.insertRule(rule.cssText, index);
38
+ }
39
+ else {
40
+ sheet.insertRule(rule.cssText, rule.index);
41
+ }
42
+ }
43
+ catch (e) {
44
+ }
45
+ }
46
+ else if (rule.type === StyleRuleType.Remove) {
47
+ try {
48
+ if (Array.isArray(rule.index)) {
49
+ var _b = getPositionsAndIndex(rule.index), positions = _b.positions, index = _b.index;
50
+ var nestedRule = getNestedRule(sheet.cssRules, positions);
51
+ nestedRule.deleteRule(index || 0);
52
+ }
53
+ else {
54
+ sheet.deleteRule(rule.index);
55
+ }
56
+ }
57
+ catch (e) {
58
+ }
59
+ }
60
+ else if (rule.type === StyleRuleType.Snapshot) {
61
+ restoreSnapshotOfStyleRulesToNode(rule.cssTexts, styleNode);
62
+ }
63
+ else if (rule.type === StyleRuleType.SetProperty) {
64
+ var nativeRule = getNestedRule(sheet.cssRules, rule.index);
65
+ nativeRule.style.setProperty(rule.property, rule.value, rule.priority);
66
+ }
67
+ else if (rule.type === StyleRuleType.RemoveProperty) {
68
+ var nativeRule = getNestedRule(sheet.cssRules, rule.index);
69
+ nativeRule.style.removeProperty(rule.property);
70
+ }
71
+ });
72
+ }
73
+ function restoreSnapshotOfStyleRulesToNode(cssTexts, styleNode) {
74
+ var _a;
75
+ try {
76
+ var existingRules = Array.from(((_a = styleNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) || []).map(function (rule) { return rule.cssText; });
77
+ var existingRulesReversed = Object.entries(existingRules).reverse();
78
+ var lastMatch_1 = existingRules.length;
79
+ existingRulesReversed.forEach(function (_a) {
80
+ var _b;
81
+ var _c = __read(_a, 2), index = _c[0], rule = _c[1];
82
+ var indexOf = cssTexts.indexOf(rule);
83
+ if (indexOf === -1 || indexOf > lastMatch_1) {
84
+ try {
85
+ (_b = styleNode.sheet) === null || _b === void 0 ? void 0 : _b.deleteRule(Number(index));
86
+ }
87
+ catch (e) {
88
+ }
89
+ }
90
+ lastMatch_1 = indexOf;
91
+ });
92
+ cssTexts.forEach(function (cssText, index) {
93
+ var _a, _b, _c;
94
+ try {
95
+ if (((_b = (_a = styleNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules[index]) === null || _b === void 0 ? void 0 : _b.cssText) !== cssText) {
96
+ (_c = styleNode.sheet) === null || _c === void 0 ? void 0 : _c.insertRule(cssText, index);
97
+ }
98
+ }
99
+ catch (e) {
100
+ }
101
+ });
102
+ }
103
+ catch (e) {
104
+ }
105
+ }
106
+ function storeCSSRules(parentElement, virtualStyleRulesMap) {
107
+ var _a;
108
+ try {
109
+ var cssTexts = Array.from(((_a = parentElement.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) || []).map(function (rule) { return rule.cssText; });
110
+ virtualStyleRulesMap.set(parentElement, [
111
+ {
112
+ type: StyleRuleType.Snapshot,
113
+ cssTexts: cssTexts,
114
+ },
115
+ ]);
116
+ }
117
+ catch (e) {
118
+ }
119
+ }
120
+
121
+ export { StyleRuleType, applyVirtualStyleRulesToNode, getNestedRule, getPositionsAndIndex, storeCSSRules };
@@ -0,0 +1,75 @@
1
+ var EventType;
2
+ (function (EventType) {
3
+ EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
4
+ EventType[EventType["Load"] = 1] = "Load";
5
+ EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
6
+ EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
7
+ EventType[EventType["Meta"] = 4] = "Meta";
8
+ EventType[EventType["Custom"] = 5] = "Custom";
9
+ EventType[EventType["Plugin"] = 6] = "Plugin";
10
+ })(EventType || (EventType = {}));
11
+ var IncrementalSource;
12
+ (function (IncrementalSource) {
13
+ IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
14
+ IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
15
+ IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
16
+ IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
17
+ IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
18
+ IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
19
+ IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
20
+ IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
21
+ IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
22
+ IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
23
+ IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
24
+ IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
25
+ IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
26
+ IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
27
+ })(IncrementalSource || (IncrementalSource = {}));
28
+ var MouseInteractions;
29
+ (function (MouseInteractions) {
30
+ MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
31
+ MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
32
+ MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
33
+ MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
34
+ MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
35
+ MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
36
+ MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
37
+ MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
38
+ MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
39
+ MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
40
+ MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
41
+ })(MouseInteractions || (MouseInteractions = {}));
42
+ var CanvasContext;
43
+ (function (CanvasContext) {
44
+ CanvasContext[CanvasContext["2D"] = 0] = "2D";
45
+ CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
46
+ CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
47
+ })(CanvasContext || (CanvasContext = {}));
48
+ var MediaInteractions;
49
+ (function (MediaInteractions) {
50
+ MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
51
+ MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
52
+ MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
53
+ MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
54
+ })(MediaInteractions || (MediaInteractions = {}));
55
+ var ReplayerEvents;
56
+ (function (ReplayerEvents) {
57
+ ReplayerEvents["Start"] = "start";
58
+ ReplayerEvents["Pause"] = "pause";
59
+ ReplayerEvents["Resume"] = "resume";
60
+ ReplayerEvents["Resize"] = "resize";
61
+ ReplayerEvents["Finish"] = "finish";
62
+ ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
63
+ ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
64
+ ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
65
+ ReplayerEvents["SkipStart"] = "skip-start";
66
+ ReplayerEvents["SkipEnd"] = "skip-end";
67
+ ReplayerEvents["MouseInteraction"] = "mouse-interaction";
68
+ ReplayerEvents["EventCast"] = "event-cast";
69
+ ReplayerEvents["CustomEvent"] = "custom-event";
70
+ ReplayerEvents["Flush"] = "flush";
71
+ ReplayerEvents["StateChange"] = "state-change";
72
+ ReplayerEvents["PlayBack"] = "play-back";
73
+ })(ReplayerEvents || (ReplayerEvents = {}));
74
+
75
+ export { CanvasContext, EventType, IncrementalSource, MediaInteractions, MouseInteractions, ReplayerEvents };
@@ -0,0 +1,509 @@
1
+ import { __values } from '../ext/tslib/tslib.es6.js';
2
+ import { IncrementalSource } from './types.js';
3
+ import { IGNORED_NODE, isShadowRoot, NodeType } from '../../rrweb-snapshot/es/rrweb-snapshot.js';
4
+
5
+ function on(type, fn, target) {
6
+ if (target === void 0) { target = document; }
7
+ var options = { capture: true, passive: true };
8
+ target.addEventListener(type, fn, options);
9
+ return function () { return target.removeEventListener(type, fn, options); };
10
+ }
11
+ function createMirror() {
12
+ return {
13
+ map: {},
14
+ getId: function (n) {
15
+ if (!n || !n.__sn) {
16
+ return -1;
17
+ }
18
+ return n.__sn.id;
19
+ },
20
+ getNode: function (id) {
21
+ return this.map[id] || null;
22
+ },
23
+ removeNodeFromMap: function (n) {
24
+ var _this = this;
25
+ var id = n.__sn && n.__sn.id;
26
+ delete this.map[id];
27
+ if (n.childNodes) {
28
+ n.childNodes.forEach(function (child) {
29
+ return _this.removeNodeFromMap(child);
30
+ });
31
+ }
32
+ },
33
+ has: function (id) {
34
+ return this.map.hasOwnProperty(id);
35
+ },
36
+ reset: function () {
37
+ this.map = {};
38
+ },
39
+ };
40
+ }
41
+ var DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
42
+ '\r\n' +
43
+ 'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
44
+ '\r\n' +
45
+ 'or you can use record.mirror to access the mirror instance during recording.';
46
+ var _mirror = {
47
+ map: {},
48
+ getId: function () {
49
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
50
+ return -1;
51
+ },
52
+ getNode: function () {
53
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
54
+ return null;
55
+ },
56
+ removeNodeFromMap: function () {
57
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
58
+ },
59
+ has: function () {
60
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
61
+ return false;
62
+ },
63
+ reset: function () {
64
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
65
+ },
66
+ };
67
+ if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
68
+ _mirror = new Proxy(_mirror, {
69
+ get: function (target, prop, receiver) {
70
+ if (prop === 'map') {
71
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
72
+ }
73
+ return Reflect.get(target, prop, receiver);
74
+ },
75
+ });
76
+ }
77
+ function throttle(func, wait, options) {
78
+ if (options === void 0) { options = {}; }
79
+ var timeout = null;
80
+ var previous = 0;
81
+ return function (arg) {
82
+ var now = Date.now();
83
+ if (!previous && options.leading === false) {
84
+ previous = now;
85
+ }
86
+ var remaining = wait - (now - previous);
87
+ var context = this;
88
+ var args = arguments;
89
+ if (remaining <= 0 || remaining > wait) {
90
+ if (timeout) {
91
+ clearTimeout(timeout);
92
+ timeout = null;
93
+ }
94
+ previous = now;
95
+ func.apply(context, args);
96
+ }
97
+ else if (!timeout && options.trailing !== false) {
98
+ timeout = setTimeout(function () {
99
+ previous = options.leading === false ? 0 : Date.now();
100
+ timeout = null;
101
+ func.apply(context, args);
102
+ }, remaining);
103
+ }
104
+ };
105
+ }
106
+ function hookSetter(target, key, d, isRevoked, win) {
107
+ if (win === void 0) { win = window; }
108
+ var original = win.Object.getOwnPropertyDescriptor(target, key);
109
+ win.Object.defineProperty(target, key, isRevoked
110
+ ? d
111
+ : {
112
+ set: function (value) {
113
+ var _this = this;
114
+ setTimeout(function () {
115
+ d.set.call(_this, value);
116
+ }, 0);
117
+ if (original && original.set) {
118
+ original.set.call(this, value);
119
+ }
120
+ },
121
+ });
122
+ return function () { return hookSetter(target, key, original || {}, true); };
123
+ }
124
+ function patch(source, name, replacement) {
125
+ try {
126
+ if (!(name in source)) {
127
+ return function () { };
128
+ }
129
+ var original_1 = source[name];
130
+ var wrapped = replacement(original_1);
131
+ if (typeof wrapped === 'function') {
132
+ wrapped.prototype = wrapped.prototype || {};
133
+ Object.defineProperties(wrapped, {
134
+ __rrweb_original__: {
135
+ enumerable: false,
136
+ value: original_1,
137
+ },
138
+ });
139
+ }
140
+ source[name] = wrapped;
141
+ return function () {
142
+ source[name] = original_1;
143
+ };
144
+ }
145
+ catch (_a) {
146
+ return function () { };
147
+ }
148
+ }
149
+ function getWindowHeight() {
150
+ return (window.innerHeight ||
151
+ (document.documentElement && document.documentElement.clientHeight) ||
152
+ (document.body && document.body.clientHeight));
153
+ }
154
+ function getWindowWidth() {
155
+ return (window.innerWidth ||
156
+ (document.documentElement && document.documentElement.clientWidth) ||
157
+ (document.body && document.body.clientWidth));
158
+ }
159
+ var isCanvasNode = function (node) {
160
+ try {
161
+ if (node instanceof HTMLElement) {
162
+ return node.tagName === 'CANVAS';
163
+ }
164
+ }
165
+ catch (_a) {
166
+ return false;
167
+ }
168
+ return false;
169
+ };
170
+ function isBlocked(node, blockClass) {
171
+ if (!node) {
172
+ return false;
173
+ }
174
+ if (node.nodeType === node.ELEMENT_NODE) {
175
+ var needBlock_1 = false;
176
+ if (typeof blockClass === 'string') {
177
+ if (node.closest !== undefined) {
178
+ return node.closest('.' + blockClass) !== null;
179
+ }
180
+ else {
181
+ needBlock_1 = node.classList.contains(blockClass);
182
+ }
183
+ }
184
+ else {
185
+ node.classList.forEach(function (className) {
186
+ if (blockClass.test(className)) {
187
+ needBlock_1 = true;
188
+ }
189
+ });
190
+ }
191
+ return needBlock_1 || isBlocked(node.parentNode, blockClass);
192
+ }
193
+ if (node.nodeType === node.TEXT_NODE) {
194
+ return isBlocked(node.parentNode, blockClass);
195
+ }
196
+ return isBlocked(node.parentNode, blockClass);
197
+ }
198
+ function isIgnored(n) {
199
+ if ('__sn' in n) {
200
+ return n.__sn.id === IGNORED_NODE;
201
+ }
202
+ return false;
203
+ }
204
+ function isAncestorRemoved(target, mirror) {
205
+ if (isShadowRoot(target)) {
206
+ return false;
207
+ }
208
+ var id = mirror.getId(target);
209
+ if (!mirror.has(id)) {
210
+ return true;
211
+ }
212
+ if (target.parentNode &&
213
+ target.parentNode.nodeType === target.DOCUMENT_NODE) {
214
+ return false;
215
+ }
216
+ if (!target.parentNode) {
217
+ return true;
218
+ }
219
+ return isAncestorRemoved(target.parentNode, mirror);
220
+ }
221
+ function isTouchEvent(event) {
222
+ return Boolean(event.changedTouches);
223
+ }
224
+ function polyfill(win) {
225
+ if (win === void 0) { win = window; }
226
+ if ('NodeList' in win && !win.NodeList.prototype.forEach) {
227
+ win.NodeList.prototype.forEach = Array.prototype
228
+ .forEach;
229
+ }
230
+ if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
231
+ win.DOMTokenList.prototype.forEach = Array.prototype
232
+ .forEach;
233
+ }
234
+ if (!Node.prototype.contains) {
235
+ Node.prototype.contains = function contains(node) {
236
+ if (!(0 in arguments)) {
237
+ throw new TypeError('1 argument is required');
238
+ }
239
+ do {
240
+ if (this === node) {
241
+ return true;
242
+ }
243
+ } while ((node = node && node.parentNode));
244
+ return false;
245
+ };
246
+ }
247
+ }
248
+ var TreeIndex = (function () {
249
+ function TreeIndex() {
250
+ this.reset();
251
+ }
252
+ TreeIndex.prototype.add = function (mutation) {
253
+ var parentTreeNode = this.indexes.get(mutation.parentId);
254
+ var treeNode = {
255
+ id: mutation.node.id,
256
+ mutation: mutation,
257
+ children: [],
258
+ texts: [],
259
+ attributes: [],
260
+ };
261
+ if (!parentTreeNode) {
262
+ this.tree[treeNode.id] = treeNode;
263
+ }
264
+ else {
265
+ treeNode.parent = parentTreeNode;
266
+ parentTreeNode.children[treeNode.id] = treeNode;
267
+ }
268
+ this.indexes.set(treeNode.id, treeNode);
269
+ };
270
+ TreeIndex.prototype.remove = function (mutation, mirror) {
271
+ var _this = this;
272
+ var parentTreeNode = this.indexes.get(mutation.parentId);
273
+ var treeNode = this.indexes.get(mutation.id);
274
+ var deepRemoveFromMirror = function (id) {
275
+ _this.removeIdSet.add(id);
276
+ var node = mirror.getNode(id);
277
+ node === null || node === void 0 ? void 0 : node.childNodes.forEach(function (childNode) {
278
+ if ('__sn' in childNode) {
279
+ deepRemoveFromMirror(childNode.__sn.id);
280
+ }
281
+ });
282
+ };
283
+ var deepRemoveFromTreeIndex = function (node) {
284
+ _this.removeIdSet.add(node.id);
285
+ Object.values(node.children).forEach(function (n) { return deepRemoveFromTreeIndex(n); });
286
+ var _treeNode = _this.indexes.get(node.id);
287
+ if (_treeNode) {
288
+ var _parentTreeNode = _treeNode.parent;
289
+ if (_parentTreeNode) {
290
+ delete _treeNode.parent;
291
+ delete _parentTreeNode.children[_treeNode.id];
292
+ _this.indexes.delete(mutation.id);
293
+ }
294
+ }
295
+ };
296
+ if (!treeNode) {
297
+ this.removeNodeMutations.push(mutation);
298
+ deepRemoveFromMirror(mutation.id);
299
+ }
300
+ else if (!parentTreeNode) {
301
+ delete this.tree[treeNode.id];
302
+ this.indexes.delete(treeNode.id);
303
+ deepRemoveFromTreeIndex(treeNode);
304
+ }
305
+ else {
306
+ delete treeNode.parent;
307
+ delete parentTreeNode.children[treeNode.id];
308
+ this.indexes.delete(mutation.id);
309
+ deepRemoveFromTreeIndex(treeNode);
310
+ }
311
+ };
312
+ TreeIndex.prototype.text = function (mutation) {
313
+ var treeNode = this.indexes.get(mutation.id);
314
+ if (treeNode) {
315
+ treeNode.texts.push(mutation);
316
+ }
317
+ else {
318
+ this.textMutations.push(mutation);
319
+ }
320
+ };
321
+ TreeIndex.prototype.attribute = function (mutation) {
322
+ var treeNode = this.indexes.get(mutation.id);
323
+ if (treeNode) {
324
+ treeNode.attributes.push(mutation);
325
+ }
326
+ else {
327
+ this.attributeMutations.push(mutation);
328
+ }
329
+ };
330
+ TreeIndex.prototype.scroll = function (d) {
331
+ this.scrollMap.set(d.id, d);
332
+ };
333
+ TreeIndex.prototype.input = function (d) {
334
+ this.inputMap.set(d.id, d);
335
+ };
336
+ TreeIndex.prototype.flush = function () {
337
+ var e_1, _a, e_2, _b;
338
+ var _this = this;
339
+ var _c = this, tree = _c.tree, removeNodeMutations = _c.removeNodeMutations, textMutations = _c.textMutations, attributeMutations = _c.attributeMutations;
340
+ var batchMutationData = {
341
+ source: IncrementalSource.Mutation,
342
+ removes: removeNodeMutations,
343
+ texts: textMutations,
344
+ attributes: attributeMutations,
345
+ adds: [],
346
+ };
347
+ var walk = function (treeNode, removed) {
348
+ if (removed) {
349
+ _this.removeIdSet.add(treeNode.id);
350
+ }
351
+ batchMutationData.texts = batchMutationData.texts
352
+ .concat(removed ? [] : treeNode.texts)
353
+ .filter(function (m) { return !_this.removeIdSet.has(m.id); });
354
+ batchMutationData.attributes = batchMutationData.attributes
355
+ .concat(removed ? [] : treeNode.attributes)
356
+ .filter(function (m) { return !_this.removeIdSet.has(m.id); });
357
+ if (!_this.removeIdSet.has(treeNode.id) &&
358
+ !_this.removeIdSet.has(treeNode.mutation.parentId) &&
359
+ !removed) {
360
+ batchMutationData.adds.push(treeNode.mutation);
361
+ if (treeNode.children) {
362
+ Object.values(treeNode.children).forEach(function (n) { return walk(n, false); });
363
+ }
364
+ }
365
+ else {
366
+ Object.values(treeNode.children).forEach(function (n) { return walk(n, true); });
367
+ }
368
+ };
369
+ Object.values(tree).forEach(function (n) { return walk(n, false); });
370
+ try {
371
+ for (var _d = __values(this.scrollMap.keys()), _e = _d.next(); !_e.done; _e = _d.next()) {
372
+ var id = _e.value;
373
+ if (this.removeIdSet.has(id)) {
374
+ this.scrollMap.delete(id);
375
+ }
376
+ }
377
+ }
378
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
379
+ finally {
380
+ try {
381
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
382
+ }
383
+ finally { if (e_1) throw e_1.error; }
384
+ }
385
+ try {
386
+ for (var _f = __values(this.inputMap.keys()), _g = _f.next(); !_g.done; _g = _f.next()) {
387
+ var id = _g.value;
388
+ if (this.removeIdSet.has(id)) {
389
+ this.inputMap.delete(id);
390
+ }
391
+ }
392
+ }
393
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
394
+ finally {
395
+ try {
396
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
397
+ }
398
+ finally { if (e_2) throw e_2.error; }
399
+ }
400
+ var scrollMap = new Map(this.scrollMap);
401
+ var inputMap = new Map(this.inputMap);
402
+ this.reset();
403
+ return {
404
+ mutationData: batchMutationData,
405
+ scrollMap: scrollMap,
406
+ inputMap: inputMap,
407
+ };
408
+ };
409
+ TreeIndex.prototype.reset = function () {
410
+ this.tree = [];
411
+ this.indexes = new Map();
412
+ this.removeNodeMutations = [];
413
+ this.textMutations = [];
414
+ this.attributeMutations = [];
415
+ this.removeIdSet = new Set();
416
+ this.scrollMap = new Map();
417
+ this.inputMap = new Map();
418
+ };
419
+ TreeIndex.prototype.idRemoved = function (id) {
420
+ return this.removeIdSet.has(id);
421
+ };
422
+ return TreeIndex;
423
+ }());
424
+ function queueToResolveTrees(queue) {
425
+ var e_3, _a;
426
+ var queueNodeMap = {};
427
+ var putIntoMap = function (m, parent) {
428
+ var nodeInTree = {
429
+ value: m,
430
+ parent: parent,
431
+ children: [],
432
+ };
433
+ queueNodeMap[m.node.id] = nodeInTree;
434
+ return nodeInTree;
435
+ };
436
+ var queueNodeTrees = [];
437
+ try {
438
+ for (var queue_1 = __values(queue), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
439
+ var mutation = queue_1_1.value;
440
+ var nextId = mutation.nextId, parentId = mutation.parentId;
441
+ if (nextId && nextId in queueNodeMap) {
442
+ var nextInTree = queueNodeMap[nextId];
443
+ if (nextInTree.parent) {
444
+ var idx = nextInTree.parent.children.indexOf(nextInTree);
445
+ nextInTree.parent.children.splice(idx, 0, putIntoMap(mutation, nextInTree.parent));
446
+ }
447
+ else {
448
+ var idx = queueNodeTrees.indexOf(nextInTree);
449
+ queueNodeTrees.splice(idx, 0, putIntoMap(mutation, null));
450
+ }
451
+ continue;
452
+ }
453
+ if (parentId in queueNodeMap) {
454
+ var parentInTree = queueNodeMap[parentId];
455
+ parentInTree.children.push(putIntoMap(mutation, parentInTree));
456
+ continue;
457
+ }
458
+ queueNodeTrees.push(putIntoMap(mutation, null));
459
+ }
460
+ }
461
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
462
+ finally {
463
+ try {
464
+ if (queue_1_1 && !queue_1_1.done && (_a = queue_1.return)) _a.call(queue_1);
465
+ }
466
+ finally { if (e_3) throw e_3.error; }
467
+ }
468
+ return queueNodeTrees;
469
+ }
470
+ function iterateResolveTree(tree, cb) {
471
+ cb(tree.value);
472
+ for (var i = tree.children.length - 1; i >= 0; i--) {
473
+ iterateResolveTree(tree.children[i], cb);
474
+ }
475
+ }
476
+ function isIframeINode(node) {
477
+ if ('__sn' in node) {
478
+ return (node.__sn.type === NodeType.Element && node.__sn.tagName === 'iframe');
479
+ }
480
+ return false;
481
+ }
482
+ function getBaseDimension(node, rootIframe) {
483
+ var _a, _b;
484
+ var frameElement = (_b = (_a = node.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.frameElement;
485
+ if (!frameElement || frameElement === rootIframe) {
486
+ return {
487
+ x: 0,
488
+ y: 0,
489
+ relativeScale: 1,
490
+ absoluteScale: 1,
491
+ };
492
+ }
493
+ var frameDimension = frameElement.getBoundingClientRect();
494
+ var frameBaseDimension = getBaseDimension(frameElement, rootIframe);
495
+ var relativeScale = frameDimension.height / frameElement.clientHeight;
496
+ return {
497
+ x: frameDimension.x * frameBaseDimension.relativeScale +
498
+ frameBaseDimension.x,
499
+ y: frameDimension.y * frameBaseDimension.relativeScale +
500
+ frameBaseDimension.y,
501
+ relativeScale: relativeScale,
502
+ absoluteScale: frameBaseDimension.absoluteScale * relativeScale,
503
+ };
504
+ }
505
+ function hasShadowRoot(n) {
506
+ return Boolean(n === null || n === void 0 ? void 0 : n.shadowRoot);
507
+ }
508
+
509
+ export { TreeIndex, _mirror, createMirror, getBaseDimension, getWindowHeight, getWindowWidth, hasShadowRoot, hookSetter, isAncestorRemoved, isBlocked, isCanvasNode, isIframeINode, isIgnored, isTouchEvent, iterateResolveTree, on, patch, polyfill, queueToResolveTrees, throttle };