Няма описание

rrweb.js 98KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930
  1. /*! *****************************************************************************
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  4. this file except in compliance with the License. You may obtain a copy of the
  5. License at http://www.apache.org/licenses/LICENSE-2.0
  6. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. var __assign = function() {
  14. __assign = Object.assign || function __assign(t) {
  15. for (var s, i = 1, n = arguments.length; i < n; i++) {
  16. s = arguments[i];
  17. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  18. }
  19. return t;
  20. };
  21. return __assign.apply(this, arguments);
  22. };
  23. function __values(o) {
  24. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  25. if (m) return m.call(o);
  26. return {
  27. next: function () {
  28. if (o && i >= o.length) o = void 0;
  29. return { value: o && o[i++], done: !o };
  30. }
  31. };
  32. }
  33. function __read(o, n) {
  34. var m = typeof Symbol === "function" && o[Symbol.iterator];
  35. if (!m) return o;
  36. var i = m.call(o), r, ar = [], e;
  37. try {
  38. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  39. }
  40. catch (error) { e = { error: error }; }
  41. finally {
  42. try {
  43. if (r && !r.done && (m = i["return"])) m.call(i);
  44. }
  45. finally { if (e) throw e.error; }
  46. }
  47. return ar;
  48. }
  49. function __spread() {
  50. for (var ar = [], i = 0; i < arguments.length; i++)
  51. ar = ar.concat(__read(arguments[i]));
  52. return ar;
  53. }
  54. var NodeType;
  55. (function (NodeType) {
  56. NodeType[NodeType["Document"] = 0] = "Document";
  57. NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
  58. NodeType[NodeType["Element"] = 2] = "Element";
  59. NodeType[NodeType["Text"] = 3] = "Text";
  60. NodeType[NodeType["CDATA"] = 4] = "CDATA";
  61. NodeType[NodeType["Comment"] = 5] = "Comment";
  62. })(NodeType || (NodeType = {}));
  63. var _id = 1;
  64. function genId() {
  65. return _id++;
  66. }
  67. function getCssRulesString(s) {
  68. try {
  69. var rules = s.rules || s.cssRules;
  70. return rules
  71. ? Array.from(rules).reduce(function (prev, cur) { return prev + getCssRuleString(cur); }, '')
  72. : null;
  73. }
  74. catch (error) {
  75. return null;
  76. }
  77. }
  78. function getCssRuleString(rule) {
  79. return isCSSImportRule(rule)
  80. ? getCssRulesString(rule.styleSheet) || ''
  81. : rule.cssText;
  82. }
  83. function isCSSImportRule(rule) {
  84. return 'styleSheet' in rule;
  85. }
  86. function extractOrigin(url) {
  87. var origin;
  88. if (url.indexOf('//') > -1) {
  89. origin = url
  90. .split('/')
  91. .slice(0, 3)
  92. .join('/');
  93. }
  94. else {
  95. origin = url.split('/')[0];
  96. }
  97. origin = origin.split('?')[0];
  98. return origin;
  99. }
  100. var URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm;
  101. var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
  102. var DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64).*,(.*)/i;
  103. function absoluteToStylesheet(cssText, href) {
  104. return cssText.replace(URL_IN_CSS_REF, function (origin, path1, path2, path3) {
  105. var filePath = path1 || path2 || path3;
  106. if (!filePath) {
  107. return origin;
  108. }
  109. if (!RELATIVE_PATH.test(filePath)) {
  110. return "url('" + filePath + "')";
  111. }
  112. if (DATA_URI.test(filePath)) {
  113. return "url(" + filePath + ")";
  114. }
  115. if (filePath[0] === '/') {
  116. return "url('" + (extractOrigin(href) + filePath) + "')";
  117. }
  118. var stack = href.split('/');
  119. var parts = filePath.split('/');
  120. stack.pop();
  121. for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
  122. var part = parts_1[_i];
  123. if (part === '.') {
  124. continue;
  125. }
  126. else if (part === '..') {
  127. stack.pop();
  128. }
  129. else {
  130. stack.push(part);
  131. }
  132. }
  133. return "url('" + stack.join('/') + "')";
  134. });
  135. }
  136. function getAbsoluteSrcsetString(doc, attributeValue) {
  137. if (attributeValue.trim() === '') {
  138. return attributeValue;
  139. }
  140. var srcsetValues = attributeValue.split(',');
  141. var resultingSrcsetString = srcsetValues
  142. .map(function (srcItem) {
  143. var trimmedSrcItem = srcItem.trimLeft().trimRight();
  144. var urlAndSize = trimmedSrcItem.split(' ');
  145. if (urlAndSize.length === 2) {
  146. var absUrl = absoluteToDoc(doc, urlAndSize[0]);
  147. return absUrl + " " + urlAndSize[1];
  148. }
  149. else if (urlAndSize.length === 1) {
  150. var absUrl = absoluteToDoc(doc, urlAndSize[0]);
  151. return "" + absUrl;
  152. }
  153. return '';
  154. })
  155. .join(',');
  156. return resultingSrcsetString;
  157. }
  158. function absoluteToDoc(doc, attributeValue) {
  159. if (attributeValue.trim() === '') {
  160. return attributeValue;
  161. }
  162. var a = doc.createElement('a');
  163. a.href = attributeValue;
  164. return a.href;
  165. }
  166. function isSVGElement(el) {
  167. return el.tagName === 'svg' || el instanceof SVGElement;
  168. }
  169. function transformAttribute(doc, name, value) {
  170. if (name === 'src' || name === 'href') {
  171. return absoluteToDoc(doc, value);
  172. }
  173. else if (name === 'srcset') {
  174. return getAbsoluteSrcsetString(doc, value);
  175. }
  176. else if (name === 'style') {
  177. return absoluteToStylesheet(value, location.href);
  178. }
  179. else {
  180. return value;
  181. }
  182. }
  183. function serializeNode(n, doc, blockClass, inlineStylesheet, maskAllInputs) {
  184. switch (n.nodeType) {
  185. case n.DOCUMENT_NODE:
  186. return {
  187. type: NodeType.Document,
  188. childNodes: []
  189. };
  190. case n.DOCUMENT_TYPE_NODE:
  191. return {
  192. type: NodeType.DocumentType,
  193. name: n.name,
  194. publicId: n.publicId,
  195. systemId: n.systemId
  196. };
  197. case n.ELEMENT_NODE:
  198. var needBlock_1 = false;
  199. if (typeof blockClass === 'string') {
  200. needBlock_1 = n.classList.contains(blockClass);
  201. }
  202. else {
  203. n.classList.forEach(function (className) {
  204. if (blockClass.test(className)) {
  205. needBlock_1 = true;
  206. }
  207. });
  208. }
  209. var tagName = n.tagName.toLowerCase();
  210. var attributes_1 = {};
  211. for (var _i = 0, _a = Array.from(n.attributes); _i < _a.length; _i++) {
  212. var _b = _a[_i], name = _b.name, value = _b.value;
  213. attributes_1[name] = transformAttribute(doc, name, value);
  214. }
  215. if (tagName === 'link' && inlineStylesheet) {
  216. var stylesheet = Array.from(doc.styleSheets).find(function (s) {
  217. return s.href === n.href;
  218. });
  219. var cssText = getCssRulesString(stylesheet);
  220. if (cssText) {
  221. delete attributes_1.rel;
  222. delete attributes_1.href;
  223. attributes_1._cssText = absoluteToStylesheet(cssText, stylesheet.href);
  224. }
  225. }
  226. if (tagName === 'style' &&
  227. n.sheet &&
  228. !(n.innerText ||
  229. n.textContent ||
  230. '').trim().length) {
  231. var cssText = getCssRulesString(n
  232. .sheet);
  233. if (cssText) {
  234. attributes_1._cssText = absoluteToStylesheet(cssText, location.href);
  235. }
  236. }
  237. if (tagName === 'input' ||
  238. tagName === 'textarea' ||
  239. tagName === 'select') {
  240. var value = n.value;
  241. if (attributes_1.type !== 'radio' &&
  242. attributes_1.type !== 'checkbox' &&
  243. value) {
  244. attributes_1.value = maskAllInputs ? '*'.repeat(value.length) : value;
  245. }
  246. else if (n.checked) {
  247. attributes_1.checked = n.checked;
  248. }
  249. }
  250. if (tagName === 'option') {
  251. var selectValue = n.parentElement;
  252. if (attributes_1.value === selectValue.value) {
  253. attributes_1.selected = n.selected;
  254. }
  255. }
  256. if (tagName === 'canvas') {
  257. attributes_1.rr_dataURL = n.toDataURL();
  258. }
  259. if (needBlock_1) {
  260. var _c = n.getBoundingClientRect(), width = _c.width, height = _c.height;
  261. attributes_1.rr_width = width + "px";
  262. attributes_1.rr_height = height + "px";
  263. }
  264. return {
  265. type: NodeType.Element,
  266. tagName: tagName,
  267. attributes: attributes_1,
  268. childNodes: [],
  269. isSVG: isSVGElement(n) || undefined,
  270. needBlock: needBlock_1
  271. };
  272. case n.TEXT_NODE:
  273. var parentTagName = n.parentNode && n.parentNode.tagName;
  274. var textContent = n.textContent;
  275. var isStyle = parentTagName === 'STYLE' ? true : undefined;
  276. if (isStyle && textContent) {
  277. textContent = absoluteToStylesheet(textContent, location.href);
  278. }
  279. if (parentTagName === 'SCRIPT') {
  280. textContent = 'SCRIPT_PLACEHOLDER';
  281. }
  282. return {
  283. type: NodeType.Text,
  284. textContent: textContent || '',
  285. isStyle: isStyle
  286. };
  287. case n.CDATA_SECTION_NODE:
  288. return {
  289. type: NodeType.CDATA,
  290. textContent: ''
  291. };
  292. case n.COMMENT_NODE:
  293. return {
  294. type: NodeType.Comment,
  295. textContent: n.textContent || ''
  296. };
  297. default:
  298. return false;
  299. }
  300. }
  301. function serializeNodeWithId(n, doc, map, blockClass, skipChild, inlineStylesheet, maskAllInputs) {
  302. if (skipChild === void 0) { skipChild = false; }
  303. if (inlineStylesheet === void 0) { inlineStylesheet = true; }
  304. if (maskAllInputs === void 0) { maskAllInputs = false; }
  305. var _serializedNode = serializeNode(n, doc, blockClass, inlineStylesheet, maskAllInputs);
  306. if (!_serializedNode) {
  307. console.warn(n, 'not serialized');
  308. return null;
  309. }
  310. var id;
  311. if ('__sn' in n) {
  312. id = n.__sn.id;
  313. }
  314. else {
  315. id = genId();
  316. }
  317. var serializedNode = Object.assign(_serializedNode, { id: id });
  318. n.__sn = serializedNode;
  319. map[id] = n;
  320. var recordChild = !skipChild;
  321. if (serializedNode.type === NodeType.Element) {
  322. recordChild = recordChild && !serializedNode.needBlock;
  323. delete serializedNode.needBlock;
  324. }
  325. if ((serializedNode.type === NodeType.Document ||
  326. serializedNode.type === NodeType.Element) &&
  327. recordChild) {
  328. for (var _i = 0, _a = Array.from(n.childNodes); _i < _a.length; _i++) {
  329. var childN = _a[_i];
  330. var serializedChildNode = serializeNodeWithId(childN, doc, map, blockClass, skipChild, inlineStylesheet, maskAllInputs);
  331. if (serializedChildNode) {
  332. serializedNode.childNodes.push(serializedChildNode);
  333. }
  334. }
  335. }
  336. return serializedNode;
  337. }
  338. function snapshot(n, blockClass, inlineStylesheet, maskAllInputs) {
  339. if (blockClass === void 0) { blockClass = 'rr-block'; }
  340. if (inlineStylesheet === void 0) { inlineStylesheet = true; }
  341. if (maskAllInputs === void 0) { maskAllInputs = false; }
  342. var idNodeMap = {};
  343. return [
  344. serializeNodeWithId(n, n, idNodeMap, blockClass, false, inlineStylesheet, maskAllInputs),
  345. idNodeMap,
  346. ];
  347. }
  348. var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
  349. function parse(css, options) {
  350. if (options === void 0) { options = {}; }
  351. var lineno = 1;
  352. var column = 1;
  353. function updatePosition(str) {
  354. var lines = str.match(/\n/g);
  355. if (lines) {
  356. lineno += lines.length;
  357. }
  358. var i = str.lastIndexOf('\n');
  359. column = i === -1 ? column + str.length : str.length - i;
  360. }
  361. function position() {
  362. var start = { line: lineno, column: column };
  363. return function (node) {
  364. node.position = new Position(start);
  365. whitespace();
  366. return node;
  367. };
  368. }
  369. var Position = (function () {
  370. function Position(start) {
  371. this.start = start;
  372. this.end = { line: lineno, column: column };
  373. this.source = options.source;
  374. }
  375. return Position;
  376. }());
  377. Position.prototype.content = css;
  378. var errorsList = [];
  379. function error(msg) {
  380. var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
  381. err.reason = msg;
  382. err.filename = options.source;
  383. err.line = lineno;
  384. err.column = column;
  385. err.source = css;
  386. if (options.silent) {
  387. errorsList.push(err);
  388. }
  389. else {
  390. throw err;
  391. }
  392. }
  393. function stylesheet() {
  394. var rulesList = rules();
  395. return {
  396. type: 'stylesheet',
  397. stylesheet: {
  398. source: options.source,
  399. rules: rulesList,
  400. parsingErrors: errorsList
  401. }
  402. };
  403. }
  404. function open() {
  405. return match(/^{\s*/);
  406. }
  407. function close() {
  408. return match(/^}/);
  409. }
  410. function rules() {
  411. var node;
  412. var rules = [];
  413. whitespace();
  414. comments(rules);
  415. while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
  416. if (node !== false) {
  417. rules.push(node);
  418. comments(rules);
  419. }
  420. }
  421. return rules;
  422. }
  423. function match(re) {
  424. var m = re.exec(css);
  425. if (!m) {
  426. return;
  427. }
  428. var str = m[0];
  429. updatePosition(str);
  430. css = css.slice(str.length);
  431. return m;
  432. }
  433. function whitespace() {
  434. match(/^\s*/);
  435. }
  436. function comments(rules) {
  437. if (rules === void 0) { rules = []; }
  438. var c;
  439. while ((c = comment())) {
  440. if (c !== false) {
  441. rules.push(c);
  442. }
  443. c = comment();
  444. }
  445. return rules;
  446. }
  447. function comment() {
  448. var pos = position();
  449. if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
  450. return;
  451. }
  452. var i = 2;
  453. while ('' !== css.charAt(i) &&
  454. ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
  455. ++i;
  456. }
  457. i += 2;
  458. if ('' === css.charAt(i - 1)) {
  459. return error('End of comment missing');
  460. }
  461. var str = css.slice(2, i - 2);
  462. column += 2;
  463. updatePosition(str);
  464. css = css.slice(i);
  465. column += 2;
  466. return pos({
  467. type: 'comment',
  468. comment: str
  469. });
  470. }
  471. function selector() {
  472. var m = match(/^([^{]+)/);
  473. if (!m) {
  474. return;
  475. }
  476. return trim(m[0])
  477. .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
  478. .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
  479. return m.replace(/,/g, '\u200C');
  480. })
  481. .split(/\s*(?![^(]*\)),\s*/)
  482. .map(function (s) {
  483. return s.replace(/\u200C/g, ',');
  484. });
  485. }
  486. function declaration() {
  487. var pos = position();
  488. var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
  489. if (!propMatch) {
  490. return;
  491. }
  492. var prop = trim(propMatch[0]);
  493. if (!match(/^:\s*/)) {
  494. return error("property missing ':'");
  495. }
  496. var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
  497. var ret = pos({
  498. type: 'declaration',
  499. property: prop.replace(commentre, ''),
  500. value: val ? trim(val[0]).replace(commentre, '') : ''
  501. });
  502. match(/^[;\s]*/);
  503. return ret;
  504. }
  505. function declarations() {
  506. var decls = [];
  507. if (!open()) {
  508. return error("missing '{'");
  509. }
  510. comments(decls);
  511. var decl;
  512. while ((decl = declaration())) {
  513. if (decl !== false) {
  514. decls.push(decl);
  515. comments(decls);
  516. }
  517. decl = declaration();
  518. }
  519. if (!close()) {
  520. return error("missing '}'");
  521. }
  522. return decls;
  523. }
  524. function keyframe() {
  525. var m;
  526. var vals = [];
  527. var pos = position();
  528. while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
  529. vals.push(m[1]);
  530. match(/^,\s*/);
  531. }
  532. if (!vals.length) {
  533. return;
  534. }
  535. return pos({
  536. type: 'keyframe',
  537. values: vals,
  538. declarations: declarations()
  539. });
  540. }
  541. function atkeyframes() {
  542. var pos = position();
  543. var m = match(/^@([-\w]+)?keyframes\s*/);
  544. if (!m) {
  545. return;
  546. }
  547. var vendor = m[1];
  548. m = match(/^([-\w]+)\s*/);
  549. if (!m) {
  550. return error('@keyframes missing name');
  551. }
  552. var name = m[1];
  553. if (!open()) {
  554. return error("@keyframes missing '{'");
  555. }
  556. var frame;
  557. var frames = comments();
  558. while ((frame = keyframe())) {
  559. frames.push(frame);
  560. frames = frames.concat(comments());
  561. }
  562. if (!close()) {
  563. return error("@keyframes missing '}'");
  564. }
  565. return pos({
  566. type: 'keyframes',
  567. name: name,
  568. vendor: vendor,
  569. keyframes: frames
  570. });
  571. }
  572. function atsupports() {
  573. var pos = position();
  574. var m = match(/^@supports *([^{]+)/);
  575. if (!m) {
  576. return;
  577. }
  578. var supports = trim(m[1]);
  579. if (!open()) {
  580. return error("@supports missing '{'");
  581. }
  582. var style = comments().concat(rules());
  583. if (!close()) {
  584. return error("@supports missing '}'");
  585. }
  586. return pos({
  587. type: 'supports',
  588. supports: supports,
  589. rules: style
  590. });
  591. }
  592. function athost() {
  593. var pos = position();
  594. var m = match(/^@host\s*/);
  595. if (!m) {
  596. return;
  597. }
  598. if (!open()) {
  599. return error("@host missing '{'");
  600. }
  601. var style = comments().concat(rules());
  602. if (!close()) {
  603. return error("@host missing '}'");
  604. }
  605. return pos({
  606. type: 'host',
  607. rules: style
  608. });
  609. }
  610. function atmedia() {
  611. var pos = position();
  612. var m = match(/^@media *([^{]+)/);
  613. if (!m) {
  614. return;
  615. }
  616. var media = trim(m[1]);
  617. if (!open()) {
  618. return error("@media missing '{'");
  619. }
  620. var style = comments().concat(rules());
  621. if (!close()) {
  622. return error("@media missing '}'");
  623. }
  624. return pos({
  625. type: 'media',
  626. media: media,
  627. rules: style
  628. });
  629. }
  630. function atcustommedia() {
  631. var pos = position();
  632. var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
  633. if (!m) {
  634. return;
  635. }
  636. return pos({
  637. type: 'custom-media',
  638. name: trim(m[1]),
  639. media: trim(m[2])
  640. });
  641. }
  642. function atpage() {
  643. var pos = position();
  644. var m = match(/^@page */);
  645. if (!m) {
  646. return;
  647. }
  648. var sel = selector() || [];
  649. if (!open()) {
  650. return error("@page missing '{'");
  651. }
  652. var decls = comments();
  653. var decl;
  654. while ((decl = declaration())) {
  655. decls.push(decl);
  656. decls = decls.concat(comments());
  657. }
  658. if (!close()) {
  659. return error("@page missing '}'");
  660. }
  661. return pos({
  662. type: 'page',
  663. selectors: sel,
  664. declarations: decls
  665. });
  666. }
  667. function atdocument() {
  668. var pos = position();
  669. var m = match(/^@([-\w]+)?document *([^{]+)/);
  670. if (!m) {
  671. return;
  672. }
  673. var vendor = trim(m[1]);
  674. var doc = trim(m[2]);
  675. if (!open()) {
  676. return error("@document missing '{'");
  677. }
  678. var style = comments().concat(rules());
  679. if (!close()) {
  680. return error("@document missing '}'");
  681. }
  682. return pos({
  683. type: 'document',
  684. document: doc,
  685. vendor: vendor,
  686. rules: style
  687. });
  688. }
  689. function atfontface() {
  690. var pos = position();
  691. var m = match(/^@font-face\s*/);
  692. if (!m) {
  693. return;
  694. }
  695. if (!open()) {
  696. return error("@font-face missing '{'");
  697. }
  698. var decls = comments();
  699. var decl;
  700. while ((decl = declaration())) {
  701. decls.push(decl);
  702. decls = decls.concat(comments());
  703. }
  704. if (!close()) {
  705. return error("@font-face missing '}'");
  706. }
  707. return pos({
  708. type: 'font-face',
  709. declarations: decls
  710. });
  711. }
  712. var atimport = _compileAtrule('import');
  713. var atcharset = _compileAtrule('charset');
  714. var atnamespace = _compileAtrule('namespace');
  715. function _compileAtrule(name) {
  716. var re = new RegExp('^@' + name + '\\s*([^;]+);');
  717. return function () {
  718. var pos = position();
  719. var m = match(re);
  720. if (!m) {
  721. return;
  722. }
  723. var ret = { type: name };
  724. ret[name] = m[1].trim();
  725. return pos(ret);
  726. };
  727. }
  728. function atrule() {
  729. if (css[0] !== '@') {
  730. return;
  731. }
  732. return (atkeyframes() ||
  733. atmedia() ||
  734. atcustommedia() ||
  735. atsupports() ||
  736. atimport() ||
  737. atcharset() ||
  738. atnamespace() ||
  739. atdocument() ||
  740. atpage() ||
  741. athost() ||
  742. atfontface());
  743. }
  744. function rule() {
  745. var pos = position();
  746. var sel = selector();
  747. if (!sel) {
  748. return error('selector missing');
  749. }
  750. comments();
  751. return pos({
  752. type: 'rule',
  753. selectors: sel,
  754. declarations: declarations()
  755. });
  756. }
  757. return addParent(stylesheet());
  758. }
  759. function trim(str) {
  760. return str ? str.replace(/^\s+|\s+$/g, '') : '';
  761. }
  762. function addParent(obj, parent) {
  763. var isNode = obj && typeof obj.type === 'string';
  764. var childParent = isNode ? obj : parent;
  765. for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
  766. var k = _a[_i];
  767. var value = obj[k];
  768. if (Array.isArray(value)) {
  769. value.forEach(function (v) {
  770. addParent(v, childParent);
  771. });
  772. }
  773. else if (value && typeof value === 'object') {
  774. addParent(value, childParent);
  775. }
  776. }
  777. if (isNode) {
  778. Object.defineProperty(obj, 'parent', {
  779. configurable: true,
  780. writable: true,
  781. enumerable: false,
  782. value: parent || null
  783. });
  784. }
  785. return obj;
  786. }
  787. var tagMap = {
  788. script: 'noscript',
  789. altglyph: 'altGlyph',
  790. altglyphdef: 'altGlyphDef',
  791. altglyphitem: 'altGlyphItem',
  792. animatecolor: 'animateColor',
  793. animatemotion: 'animateMotion',
  794. animatetransform: 'animateTransform',
  795. clippath: 'clipPath',
  796. feblend: 'feBlend',
  797. fecolormatrix: 'feColorMatrix',
  798. fecomponenttransfer: 'feComponentTransfer',
  799. fecomposite: 'feComposite',
  800. feconvolvematrix: 'feConvolveMatrix',
  801. fediffuselighting: 'feDiffuseLighting',
  802. fedisplacementmap: 'feDisplacementMap',
  803. fedistantlight: 'feDistantLight',
  804. fedropshadow: 'feDropShadow',
  805. feflood: 'feFlood',
  806. fefunca: 'feFuncA',
  807. fefuncb: 'feFuncB',
  808. fefuncg: 'feFuncG',
  809. fefuncr: 'feFuncR',
  810. fegaussianblur: 'feGaussianBlur',
  811. feimage: 'feImage',
  812. femerge: 'feMerge',
  813. femergenode: 'feMergeNode',
  814. femorphology: 'feMorphology',
  815. feoffset: 'feOffset',
  816. fepointlight: 'fePointLight',
  817. fespecularlighting: 'feSpecularLighting',
  818. fespotlight: 'feSpotLight',
  819. fetile: 'feTile',
  820. feturbulence: 'feTurbulence',
  821. foreignobject: 'foreignObject',
  822. glyphref: 'glyphRef',
  823. lineargradient: 'linearGradient',
  824. radialgradient: 'radialGradient'
  825. };
  826. function getTagName(n) {
  827. var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
  828. if (tagName === 'link' && n.attributes._cssText) {
  829. tagName = 'style';
  830. }
  831. return tagName;
  832. }
  833. var HOVER_SELECTOR = /([^\\]):hover/g;
  834. function addHoverClass(cssText) {
  835. var ast = parse(cssText, { silent: true });
  836. if (!ast.stylesheet) {
  837. return cssText;
  838. }
  839. ast.stylesheet.rules.forEach(function (rule) {
  840. if ('selectors' in rule) {
  841. (rule.selectors || []).forEach(function (selector) {
  842. if (HOVER_SELECTOR.test(selector)) {
  843. var newSelector = selector.replace(HOVER_SELECTOR, '$1.\\:hover');
  844. cssText = cssText.replace(selector, selector + ", " + newSelector);
  845. }
  846. });
  847. }
  848. });
  849. return cssText;
  850. }
  851. function buildNode(n, doc, HACK_CSS) {
  852. switch (n.type) {
  853. case NodeType.Document:
  854. return doc.implementation.createDocument(null, '', null);
  855. case NodeType.DocumentType:
  856. return doc.implementation.createDocumentType(n.name, n.publicId, n.systemId);
  857. case NodeType.Element:
  858. var tagName = getTagName(n);
  859. var node_1;
  860. if (n.isSVG) {
  861. node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
  862. }
  863. else {
  864. node_1 = doc.createElement(tagName);
  865. }
  866. var _loop_1 = function (name) {
  867. if (!n.attributes.hasOwnProperty(name)) {
  868. return "continue";
  869. }
  870. var value = n.attributes[name];
  871. value = typeof value === 'boolean' ? '' : value;
  872. if (!name.startsWith('rr_')) {
  873. var isTextarea = tagName === 'textarea' && name === 'value';
  874. var isRemoteOrDynamicCss = tagName === 'style' && name === '_cssText';
  875. if (isRemoteOrDynamicCss && HACK_CSS) {
  876. value = addHoverClass(value);
  877. }
  878. if (isTextarea || isRemoteOrDynamicCss) {
  879. var child = doc.createTextNode(value);
  880. for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
  881. var c = _a[_i];
  882. if (c.nodeType === node_1.TEXT_NODE) {
  883. node_1.removeChild(c);
  884. }
  885. }
  886. node_1.appendChild(child);
  887. return "continue";
  888. }
  889. if (tagName === 'iframe' && name === 'src') {
  890. return "continue";
  891. }
  892. try {
  893. if (n.isSVG && name === 'xlink:href') {
  894. node_1.setAttributeNS('http://www.w3.org/1999/xlink', name, value);
  895. }
  896. else {
  897. node_1.setAttribute(name, value);
  898. }
  899. }
  900. catch (error) {
  901. }
  902. }
  903. else {
  904. if (tagName === 'canvas' && name === 'rr_dataURL') {
  905. var image_1 = document.createElement('img');
  906. image_1.src = value;
  907. image_1.onload = function () {
  908. var ctx = node_1.getContext('2d');
  909. if (ctx) {
  910. ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
  911. }
  912. };
  913. }
  914. if (name === 'rr_width') {
  915. node_1.style.width = value;
  916. }
  917. if (name === 'rr_height') {
  918. node_1.style.height = value;
  919. }
  920. }
  921. };
  922. for (var name in n.attributes) {
  923. _loop_1(name);
  924. }
  925. return node_1;
  926. case NodeType.Text:
  927. return doc.createTextNode(n.isStyle && HACK_CSS ? addHoverClass(n.textContent) : n.textContent);
  928. case NodeType.CDATA:
  929. return doc.createCDATASection(n.textContent);
  930. case NodeType.Comment:
  931. return doc.createComment(n.textContent);
  932. default:
  933. return null;
  934. }
  935. }
  936. function buildNodeWithSN(n, doc, map, skipChild, HACK_CSS) {
  937. if (skipChild === void 0) { skipChild = false; }
  938. if (HACK_CSS === void 0) { HACK_CSS = true; }
  939. var node = buildNode(n, doc, HACK_CSS);
  940. if (!node) {
  941. return null;
  942. }
  943. if (n.type === NodeType.Document) {
  944. doc.close();
  945. doc.open();
  946. node = doc;
  947. }
  948. node.__sn = n;
  949. map[n.id] = node;
  950. if ((n.type === NodeType.Document || n.type === NodeType.Element) &&
  951. !skipChild) {
  952. for (var _i = 0, _a = n.childNodes; _i < _a.length; _i++) {
  953. var childN = _a[_i];
  954. var childNode = buildNodeWithSN(childN, doc, map, false, HACK_CSS);
  955. if (!childNode) {
  956. console.warn('Failed to rebuild', childN);
  957. }
  958. else {
  959. node.appendChild(childNode);
  960. }
  961. }
  962. }
  963. return node;
  964. }
  965. function rebuild(n, doc, HACK_CSS) {
  966. if (HACK_CSS === void 0) { HACK_CSS = true; }
  967. var idNodeMap = {};
  968. return [buildNodeWithSN(n, doc, idNodeMap, false, HACK_CSS), idNodeMap];
  969. }
  970. function on(type, fn, target) {
  971. if (target === void 0) { target = document; }
  972. var options = { capture: true, passive: true };
  973. target.addEventListener(type, fn, options);
  974. return function () { return target.removeEventListener(type, fn, options); };
  975. }
  976. var mirror = {
  977. map: {},
  978. getId: function (n) {
  979. if (!n.__sn) {
  980. return -1;
  981. }
  982. return n.__sn.id;
  983. },
  984. getNode: function (id) {
  985. return mirror.map[id] || null;
  986. },
  987. removeNodeFromMap: function (n) {
  988. var id = n.__sn && n.__sn.id;
  989. delete mirror.map[id];
  990. if (n.childNodes) {
  991. n.childNodes.forEach(function (child) {
  992. return mirror.removeNodeFromMap(child);
  993. });
  994. }
  995. },
  996. has: function (id) {
  997. return mirror.map.hasOwnProperty(id);
  998. }
  999. };
  1000. function throttle(func, wait, options) {
  1001. if (options === void 0) { options = {}; }
  1002. var timeout = null;
  1003. var previous = 0;
  1004. return function (arg) {
  1005. var now = Date.now();
  1006. if (!previous && options.leading === false) {
  1007. previous = now;
  1008. }
  1009. var remaining = wait - (now - previous);
  1010. var context = this;
  1011. var args = arguments;
  1012. if (remaining <= 0 || remaining > wait) {
  1013. if (timeout) {
  1014. window.clearTimeout(timeout);
  1015. timeout = null;
  1016. }
  1017. previous = now;
  1018. func.apply(context, args);
  1019. }
  1020. else if (!timeout && options.trailing !== false) {
  1021. timeout = window.setTimeout(function () {
  1022. previous = options.leading === false ? 0 : Date.now();
  1023. timeout = null;
  1024. func.apply(context, args);
  1025. }, remaining);
  1026. }
  1027. };
  1028. }
  1029. function hookSetter(target, key, d, isRevoked) {
  1030. var original = Object.getOwnPropertyDescriptor(target, key);
  1031. Object.defineProperty(target, key, isRevoked
  1032. ? d
  1033. : {
  1034. set: function (value) {
  1035. var _this = this;
  1036. setTimeout(function () {
  1037. d.set.call(_this, value);
  1038. }, 0);
  1039. if (original && original.set) {
  1040. original.set.call(this, value);
  1041. }
  1042. }
  1043. });
  1044. return function () { return hookSetter(target, key, original || {}, true); };
  1045. }
  1046. function getWindowHeight() {
  1047. return (window.innerHeight ||
  1048. (document.documentElement && document.documentElement.clientHeight) ||
  1049. (document.body && document.body.clientHeight));
  1050. }
  1051. function getWindowWidth() {
  1052. return (window.innerWidth ||
  1053. (document.documentElement && document.documentElement.clientWidth) ||
  1054. (document.body && document.body.clientWidth));
  1055. }
  1056. function isBlocked(node, blockClass) {
  1057. if (!node) {
  1058. return false;
  1059. }
  1060. if (node.nodeType === node.ELEMENT_NODE) {
  1061. var needBlock_1 = false;
  1062. if (typeof blockClass === 'string') {
  1063. needBlock_1 = node.classList.contains(blockClass);
  1064. }
  1065. else {
  1066. node.classList.forEach(function (className) {
  1067. if (blockClass.test(className)) {
  1068. needBlock_1 = true;
  1069. }
  1070. });
  1071. }
  1072. return needBlock_1 || isBlocked(node.parentNode, blockClass);
  1073. }
  1074. return isBlocked(node.parentNode, blockClass);
  1075. }
  1076. function isAncestorRemoved(target) {
  1077. var id = mirror.getId(target);
  1078. if (!mirror.has(id)) {
  1079. return true;
  1080. }
  1081. if (target.parentNode &&
  1082. target.parentNode.nodeType === target.DOCUMENT_NODE) {
  1083. return false;
  1084. }
  1085. if (!target.parentNode) {
  1086. return true;
  1087. }
  1088. return isAncestorRemoved(target.parentNode);
  1089. }
  1090. function isTouchEvent(event) {
  1091. return Boolean(event.changedTouches);
  1092. }
  1093. function polyfill() {
  1094. if ('NodeList' in window && !NodeList.prototype.forEach) {
  1095. NodeList.prototype.forEach = Array.prototype
  1096. .forEach;
  1097. }
  1098. }
  1099. var EventType;
  1100. (function (EventType) {
  1101. EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
  1102. EventType[EventType["Load"] = 1] = "Load";
  1103. EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
  1104. EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
  1105. EventType[EventType["Meta"] = 4] = "Meta";
  1106. EventType[EventType["Custom"] = 5] = "Custom";
  1107. })(EventType || (EventType = {}));
  1108. var IncrementalSource;
  1109. (function (IncrementalSource) {
  1110. IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
  1111. IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
  1112. IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
  1113. IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
  1114. IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
  1115. IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
  1116. IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
  1117. })(IncrementalSource || (IncrementalSource = {}));
  1118. var MouseInteractions;
  1119. (function (MouseInteractions) {
  1120. MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
  1121. MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
  1122. MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
  1123. MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
  1124. MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
  1125. MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
  1126. MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
  1127. MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
  1128. MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
  1129. MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
  1130. })(MouseInteractions || (MouseInteractions = {}));
  1131. var ReplayerEvents;
  1132. (function (ReplayerEvents) {
  1133. ReplayerEvents["Start"] = "start";
  1134. ReplayerEvents["Pause"] = "pause";
  1135. ReplayerEvents["Resume"] = "resume";
  1136. ReplayerEvents["Resize"] = "resize";
  1137. ReplayerEvents["Finish"] = "finish";
  1138. ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
  1139. ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
  1140. ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
  1141. ReplayerEvents["SkipStart"] = "skip-start";
  1142. ReplayerEvents["SkipEnd"] = "skip-end";
  1143. ReplayerEvents["MouseInteraction"] = "mouse-interaction";
  1144. })(ReplayerEvents || (ReplayerEvents = {}));
  1145. function deepDelete(addsSet, n) {
  1146. addsSet["delete"](n);
  1147. n.childNodes.forEach(function (childN) { return deepDelete(addsSet, childN); });
  1148. }
  1149. function isParentRemoved(removes, n) {
  1150. var parentNode = n.parentNode;
  1151. if (!parentNode) {
  1152. return false;
  1153. }
  1154. var parentId = mirror.getId(parentNode);
  1155. if (removes.some(function (r) { return r.id === parentId; })) {
  1156. return true;
  1157. }
  1158. return isParentRemoved(removes, parentNode);
  1159. }
  1160. function isAncestorInSet(set, n) {
  1161. var parentNode = n.parentNode;
  1162. if (!parentNode) {
  1163. return false;
  1164. }
  1165. if (set.has(parentNode)) {
  1166. return true;
  1167. }
  1168. return isAncestorInSet(set, parentNode);
  1169. }
  1170. var moveKey = function (id, parentId) { return id + "@" + parentId; };
  1171. function isINode(n) {
  1172. return '__sn' in n;
  1173. }
  1174. function initMutationObserver(cb, blockClass, inlineStylesheet, maskAllInputs) {
  1175. var observer = new MutationObserver(function (mutations) {
  1176. var e_1, _a, e_2, _b;
  1177. var texts = [];
  1178. var attributes = [];
  1179. var removes = [];
  1180. var adds = [];
  1181. var addedSet = new Set();
  1182. var movedSet = new Set();
  1183. var droppedSet = new Set();
  1184. var movedMap = {};
  1185. var genAdds = function (n, target) {
  1186. if (isBlocked(n, blockClass)) {
  1187. return;
  1188. }
  1189. if (isINode(n)) {
  1190. movedSet.add(n);
  1191. var targetId = null;
  1192. if (target && isINode(target)) {
  1193. targetId = target.__sn.id;
  1194. }
  1195. if (targetId) {
  1196. movedMap[moveKey(n.__sn.id, targetId)] = true;
  1197. }
  1198. }
  1199. else {
  1200. addedSet.add(n);
  1201. droppedSet["delete"](n);
  1202. }
  1203. n.childNodes.forEach(function (childN) { return genAdds(childN); });
  1204. };
  1205. mutations.forEach(function (mutation) {
  1206. var type = mutation.type, target = mutation.target, oldValue = mutation.oldValue, addedNodes = mutation.addedNodes, removedNodes = mutation.removedNodes, attributeName = mutation.attributeName;
  1207. switch (type) {
  1208. case 'characterData': {
  1209. var value = target.textContent;
  1210. if (!isBlocked(target, blockClass) && value !== oldValue) {
  1211. texts.push({
  1212. value: value,
  1213. node: target
  1214. });
  1215. }
  1216. break;
  1217. }
  1218. case 'attributes': {
  1219. var value = target.getAttribute(attributeName);
  1220. if (isBlocked(target, blockClass) || value === oldValue) {
  1221. return;
  1222. }
  1223. var item = attributes.find(function (a) { return a.node === target; });
  1224. if (!item) {
  1225. item = {
  1226. node: target,
  1227. attributes: {}
  1228. };
  1229. attributes.push(item);
  1230. }
  1231. item.attributes[attributeName] = transformAttribute(document, attributeName, value);
  1232. break;
  1233. }
  1234. case 'childList': {
  1235. addedNodes.forEach(function (n) { return genAdds(n, target); });
  1236. removedNodes.forEach(function (n) {
  1237. var nodeId = mirror.getId(n);
  1238. var parentId = mirror.getId(target);
  1239. if (isBlocked(n, blockClass)) {
  1240. return;
  1241. }
  1242. if (addedSet.has(n)) {
  1243. deepDelete(addedSet, n);
  1244. droppedSet.add(n);
  1245. }
  1246. else if (addedSet.has(target) && nodeId === -1) ;
  1247. else if (isAncestorRemoved(target)) ;
  1248. else if (movedSet.has(n) && movedMap[moveKey(nodeId, parentId)]) {
  1249. deepDelete(movedSet, n);
  1250. }
  1251. else {
  1252. removes.push({
  1253. parentId: parentId,
  1254. id: nodeId
  1255. });
  1256. }
  1257. mirror.removeNodeFromMap(n);
  1258. });
  1259. break;
  1260. }
  1261. default:
  1262. break;
  1263. }
  1264. });
  1265. var addQueue = [];
  1266. var pushAdd = function (n) {
  1267. var parentId = mirror.getId(n.parentNode);
  1268. if (parentId === -1) {
  1269. return addQueue.push(n);
  1270. }
  1271. adds.push({
  1272. parentId: parentId,
  1273. previousId: !n.previousSibling
  1274. ? n.previousSibling
  1275. : mirror.getId(n.previousSibling),
  1276. nextId: !n.nextSibling
  1277. ? n.nextSibling
  1278. : mirror.getId(n.nextSibling),
  1279. node: serializeNodeWithId(n, document, mirror.map, blockClass, true, inlineStylesheet, maskAllInputs)
  1280. });
  1281. };
  1282. try {
  1283. for (var movedSet_1 = __values(movedSet), movedSet_1_1 = movedSet_1.next(); !movedSet_1_1.done; movedSet_1_1 = movedSet_1.next()) {
  1284. var n = movedSet_1_1.value;
  1285. pushAdd(n);
  1286. }
  1287. }
  1288. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1289. finally {
  1290. try {
  1291. if (movedSet_1_1 && !movedSet_1_1.done && (_a = movedSet_1["return"])) _a.call(movedSet_1);
  1292. }
  1293. finally { if (e_1) throw e_1.error; }
  1294. }
  1295. try {
  1296. for (var addedSet_1 = __values(addedSet), addedSet_1_1 = addedSet_1.next(); !addedSet_1_1.done; addedSet_1_1 = addedSet_1.next()) {
  1297. var n = addedSet_1_1.value;
  1298. if (!isAncestorInSet(droppedSet, n) && !isParentRemoved(removes, n)) {
  1299. pushAdd(n);
  1300. }
  1301. else if (isAncestorInSet(movedSet, n)) {
  1302. pushAdd(n);
  1303. }
  1304. else {
  1305. droppedSet.add(n);
  1306. }
  1307. }
  1308. }
  1309. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  1310. finally {
  1311. try {
  1312. if (addedSet_1_1 && !addedSet_1_1.done && (_b = addedSet_1["return"])) _b.call(addedSet_1);
  1313. }
  1314. finally { if (e_2) throw e_2.error; }
  1315. }
  1316. while (addQueue.length) {
  1317. if (addQueue.every(function (n) { return mirror.getId(n.parentNode) === -1; })) {
  1318. break;
  1319. }
  1320. pushAdd(addQueue.shift());
  1321. }
  1322. var payload = {
  1323. texts: texts
  1324. .map(function (text) { return ({
  1325. id: mirror.getId(text.node),
  1326. value: text.value
  1327. }); })
  1328. .filter(function (text) { return mirror.has(text.id); }),
  1329. attributes: attributes
  1330. .map(function (attribute) { return ({
  1331. id: mirror.getId(attribute.node),
  1332. attributes: attribute.attributes
  1333. }); })
  1334. .filter(function (attribute) { return mirror.has(attribute.id); }),
  1335. removes: removes,
  1336. adds: adds
  1337. };
  1338. if (!payload.texts.length &&
  1339. !payload.attributes.length &&
  1340. !payload.removes.length &&
  1341. !payload.adds.length) {
  1342. return;
  1343. }
  1344. cb(payload);
  1345. });
  1346. observer.observe(document, {
  1347. attributes: true,
  1348. attributeOldValue: true,
  1349. characterData: true,
  1350. characterDataOldValue: true,
  1351. childList: true,
  1352. subtree: true
  1353. });
  1354. return observer;
  1355. }
  1356. function initMoveObserver(cb, mousemoveWait) {
  1357. var positions = [];
  1358. var timeBaseline;
  1359. var wrappedCb = throttle(function (isTouch) {
  1360. var totalOffset = Date.now() - timeBaseline;
  1361. cb(positions.map(function (p) {
  1362. p.timeOffset -= totalOffset;
  1363. return p;
  1364. }), isTouch ? IncrementalSource.TouchMove : IncrementalSource.MouseMove);
  1365. positions = [];
  1366. timeBaseline = null;
  1367. }, 500);
  1368. var updatePosition = throttle(function (evt) {
  1369. var target = evt.target;
  1370. var _a = isTouchEvent(evt)
  1371. ? evt.changedTouches[0]
  1372. : evt, clientX = _a.clientX, clientY = _a.clientY;
  1373. if (!timeBaseline) {
  1374. timeBaseline = Date.now();
  1375. }
  1376. positions.push({
  1377. x: clientX,
  1378. y: clientY,
  1379. id: mirror.getId(target),
  1380. timeOffset: Date.now() - timeBaseline
  1381. });
  1382. wrappedCb(isTouchEvent(evt));
  1383. }, mousemoveWait, {
  1384. trailing: false
  1385. });
  1386. var handlers = [
  1387. on('mousemove', updatePosition),
  1388. on('touchmove', updatePosition),
  1389. ];
  1390. return function () {
  1391. handlers.forEach(function (h) { return h(); });
  1392. };
  1393. }
  1394. function initMouseInteractionObserver(cb, blockClass) {
  1395. var handlers = [];
  1396. var getHandler = function (eventKey) {
  1397. return function (event) {
  1398. if (isBlocked(event.target, blockClass)) {
  1399. return;
  1400. }
  1401. var id = mirror.getId(event.target);
  1402. var _a = isTouchEvent(event)
  1403. ? event.changedTouches[0]
  1404. : event, clientX = _a.clientX, clientY = _a.clientY;
  1405. cb({
  1406. type: MouseInteractions[eventKey],
  1407. id: id,
  1408. x: clientX,
  1409. y: clientY
  1410. });
  1411. };
  1412. };
  1413. Object.keys(MouseInteractions)
  1414. .filter(function (key) { return Number.isNaN(Number(key)) && !key.endsWith('_Departed'); })
  1415. .forEach(function (eventKey) {
  1416. var eventName = eventKey.toLowerCase();
  1417. var handler = getHandler(eventKey);
  1418. handlers.push(on(eventName, handler));
  1419. });
  1420. return function () {
  1421. handlers.forEach(function (h) { return h(); });
  1422. };
  1423. }
  1424. function initScrollObserver(cb, blockClass) {
  1425. var updatePosition = throttle(function (evt) {
  1426. if (!evt.target || isBlocked(evt.target, blockClass)) {
  1427. return;
  1428. }
  1429. var id = mirror.getId(evt.target);
  1430. if (evt.target === document) {
  1431. var scrollEl = (document.scrollingElement || document.documentElement);
  1432. cb({
  1433. id: id,
  1434. x: scrollEl.scrollLeft,
  1435. y: scrollEl.scrollTop
  1436. });
  1437. }
  1438. else {
  1439. cb({
  1440. id: id,
  1441. x: evt.target.scrollLeft,
  1442. y: evt.target.scrollTop
  1443. });
  1444. }
  1445. }, 100);
  1446. return on('scroll', updatePosition);
  1447. }
  1448. function initViewportResizeObserver(cb) {
  1449. var updateDimension = throttle(function () {
  1450. var height = getWindowHeight();
  1451. var width = getWindowWidth();
  1452. cb({
  1453. width: Number(width),
  1454. height: Number(height)
  1455. });
  1456. }, 200);
  1457. return on('resize', updateDimension, window);
  1458. }
  1459. var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
  1460. var MASK_TYPES = [
  1461. 'color',
  1462. 'date',
  1463. 'datetime-local',
  1464. 'email',
  1465. 'month',
  1466. 'number',
  1467. 'range',
  1468. 'search',
  1469. 'tel',
  1470. 'text',
  1471. 'time',
  1472. 'url',
  1473. 'week',
  1474. ];
  1475. var lastInputValueMap = new WeakMap();
  1476. function initInputObserver(cb, blockClass, ignoreClass, maskAllInputs) {
  1477. function eventHandler(event) {
  1478. var target = event.target;
  1479. if (!target ||
  1480. !target.tagName ||
  1481. INPUT_TAGS.indexOf(target.tagName) < 0 ||
  1482. isBlocked(target, blockClass)) {
  1483. return;
  1484. }
  1485. var type = target.type;
  1486. if (type === 'password' ||
  1487. target.classList.contains(ignoreClass)) {
  1488. return;
  1489. }
  1490. var text = target.value;
  1491. var isChecked = false;
  1492. var hasTextInput = MASK_TYPES.includes(type) || target.tagName === 'TEXTAREA';
  1493. if (type === 'radio' || type === 'checkbox') {
  1494. isChecked = target.checked;
  1495. }
  1496. else if (hasTextInput && maskAllInputs) {
  1497. text = '*'.repeat(text.length);
  1498. }
  1499. cbWithDedup(target, { text: text, isChecked: isChecked });
  1500. var name = target.name;
  1501. if (type === 'radio' && name && isChecked) {
  1502. document
  1503. .querySelectorAll("input[type=\"radio\"][name=\"" + name + "\"]")
  1504. .forEach(function (el) {
  1505. if (el !== target) {
  1506. cbWithDedup(el, {
  1507. text: el.value,
  1508. isChecked: !isChecked
  1509. });
  1510. }
  1511. });
  1512. }
  1513. }
  1514. function cbWithDedup(target, v) {
  1515. var lastInputValue = lastInputValueMap.get(target);
  1516. if (!lastInputValue ||
  1517. lastInputValue.text !== v.text ||
  1518. lastInputValue.isChecked !== v.isChecked) {
  1519. lastInputValueMap.set(target, v);
  1520. var id = mirror.getId(target);
  1521. cb(__assign({}, v, { id: id }));
  1522. }
  1523. }
  1524. var handlers = [
  1525. 'input',
  1526. 'change',
  1527. ].map(function (eventName) { return on(eventName, eventHandler); });
  1528. var propertyDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
  1529. var hookProperties = [
  1530. [HTMLInputElement.prototype, 'value'],
  1531. [HTMLInputElement.prototype, 'checked'],
  1532. [HTMLSelectElement.prototype, 'value'],
  1533. [HTMLTextAreaElement.prototype, 'value'],
  1534. ];
  1535. if (propertyDescriptor && propertyDescriptor.set) {
  1536. handlers.push.apply(handlers, __spread(hookProperties.map(function (p) {
  1537. return hookSetter(p[0], p[1], {
  1538. set: function () {
  1539. eventHandler({ target: this });
  1540. }
  1541. });
  1542. })));
  1543. }
  1544. return function () {
  1545. handlers.forEach(function (h) { return h(); });
  1546. };
  1547. }
  1548. function mergeHooks(o, hooks) {
  1549. var mutationCb = o.mutationCb, mousemoveCb = o.mousemoveCb, mouseInteractionCb = o.mouseInteractionCb, scrollCb = o.scrollCb, viewportResizeCb = o.viewportResizeCb, inputCb = o.inputCb;
  1550. o.mutationCb = function () {
  1551. var p = [];
  1552. for (var _i = 0; _i < arguments.length; _i++) {
  1553. p[_i] = arguments[_i];
  1554. }
  1555. if (hooks.mutation) {
  1556. hooks.mutation.apply(hooks, __spread(p));
  1557. }
  1558. mutationCb.apply(void 0, __spread(p));
  1559. };
  1560. o.mousemoveCb = function () {
  1561. var p = [];
  1562. for (var _i = 0; _i < arguments.length; _i++) {
  1563. p[_i] = arguments[_i];
  1564. }
  1565. if (hooks.mousemove) {
  1566. hooks.mousemove.apply(hooks, __spread(p));
  1567. }
  1568. mousemoveCb.apply(void 0, __spread(p));
  1569. };
  1570. o.mouseInteractionCb = function () {
  1571. var p = [];
  1572. for (var _i = 0; _i < arguments.length; _i++) {
  1573. p[_i] = arguments[_i];
  1574. }
  1575. if (hooks.mouseInteraction) {
  1576. hooks.mouseInteraction.apply(hooks, __spread(p));
  1577. }
  1578. mouseInteractionCb.apply(void 0, __spread(p));
  1579. };
  1580. o.scrollCb = function () {
  1581. var p = [];
  1582. for (var _i = 0; _i < arguments.length; _i++) {
  1583. p[_i] = arguments[_i];
  1584. }
  1585. if (hooks.scroll) {
  1586. hooks.scroll.apply(hooks, __spread(p));
  1587. }
  1588. scrollCb.apply(void 0, __spread(p));
  1589. };
  1590. o.viewportResizeCb = function () {
  1591. var p = [];
  1592. for (var _i = 0; _i < arguments.length; _i++) {
  1593. p[_i] = arguments[_i];
  1594. }
  1595. if (hooks.viewportResize) {
  1596. hooks.viewportResize.apply(hooks, __spread(p));
  1597. }
  1598. viewportResizeCb.apply(void 0, __spread(p));
  1599. };
  1600. o.inputCb = function () {
  1601. var p = [];
  1602. for (var _i = 0; _i < arguments.length; _i++) {
  1603. p[_i] = arguments[_i];
  1604. }
  1605. if (hooks.input) {
  1606. hooks.input.apply(hooks, __spread(p));
  1607. }
  1608. inputCb.apply(void 0, __spread(p));
  1609. };
  1610. }
  1611. function initObservers(o, hooks) {
  1612. if (hooks === void 0) { hooks = {}; }
  1613. mergeHooks(o, hooks);
  1614. var mutationObserver = initMutationObserver(o.mutationCb, o.blockClass, o.inlineStylesheet, o.maskAllInputs);
  1615. var mousemoveHandler = initMoveObserver(o.mousemoveCb, o.mousemoveWait);
  1616. var mouseInteractionHandler = initMouseInteractionObserver(o.mouseInteractionCb, o.blockClass);
  1617. var scrollHandler = initScrollObserver(o.scrollCb, o.blockClass);
  1618. var viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb);
  1619. var inputHandler = initInputObserver(o.inputCb, o.blockClass, o.ignoreClass, o.maskAllInputs);
  1620. return function () {
  1621. mutationObserver.disconnect();
  1622. mousemoveHandler();
  1623. mouseInteractionHandler();
  1624. scrollHandler();
  1625. viewportResizeHandler();
  1626. inputHandler();
  1627. };
  1628. }
  1629. function wrapEvent(e) {
  1630. return __assign({}, e, { timestamp: Date.now() });
  1631. }
  1632. var wrappedEmit;
  1633. function record(options) {
  1634. if (options === void 0) { options = {}; }
  1635. var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _a = options.blockClass, blockClass = _a === void 0 ? 'rr-block' : _a, _b = options.ignoreClass, ignoreClass = _b === void 0 ? 'rr-ignore' : _b, _c = options.inlineStylesheet, inlineStylesheet = _c === void 0 ? true : _c, _d = options.maskAllInputs, maskAllInputs = _d === void 0 ? false : _d, hooks = options.hooks, _e = options.mousemoveWait, mousemoveWait = _e === void 0 ? 50 : _e;
  1636. if (!emit) {
  1637. throw new Error('emit function is required');
  1638. }
  1639. polyfill();
  1640. var lastFullSnapshotEvent;
  1641. var incrementalSnapshotCount = 0;
  1642. wrappedEmit = function (e, isCheckout) {
  1643. emit(e, isCheckout);
  1644. if (e.type === EventType.FullSnapshot) {
  1645. lastFullSnapshotEvent = e;
  1646. incrementalSnapshotCount = 0;
  1647. }
  1648. else if (e.type === EventType.IncrementalSnapshot) {
  1649. incrementalSnapshotCount++;
  1650. var exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
  1651. var exceedTime = checkoutEveryNms &&
  1652. e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
  1653. if (exceedCount || exceedTime) {
  1654. takeFullSnapshot(true);
  1655. }
  1656. }
  1657. };
  1658. function takeFullSnapshot(isCheckout) {
  1659. if (isCheckout === void 0) { isCheckout = false; }
  1660. wrappedEmit(wrapEvent({
  1661. type: EventType.Meta,
  1662. data: {
  1663. href: window.location.href,
  1664. width: getWindowWidth(),
  1665. height: getWindowHeight()
  1666. }
  1667. }), isCheckout);
  1668. var _a = __read(snapshot(document, blockClass, inlineStylesheet, maskAllInputs), 2), node = _a[0], idNodeMap = _a[1];
  1669. if (!node) {
  1670. return console.warn('Failed to snapshot the document');
  1671. }
  1672. mirror.map = idNodeMap;
  1673. wrappedEmit(wrapEvent({
  1674. type: EventType.FullSnapshot,
  1675. data: {
  1676. node: node,
  1677. initialOffset: {
  1678. left: document.documentElement.scrollLeft,
  1679. top: document.documentElement.scrollTop
  1680. }
  1681. }
  1682. }));
  1683. }
  1684. try {
  1685. var handlers_1 = [];
  1686. handlers_1.push(on('DOMContentLoaded', function () {
  1687. wrappedEmit(wrapEvent({
  1688. type: EventType.DomContentLoaded,
  1689. data: {}
  1690. }));
  1691. }));
  1692. var init_1 = function () {
  1693. takeFullSnapshot();
  1694. handlers_1.push(initObservers({
  1695. mutationCb: function (m) {
  1696. return wrappedEmit(wrapEvent({
  1697. type: EventType.IncrementalSnapshot,
  1698. data: __assign({ source: IncrementalSource.Mutation }, m)
  1699. }));
  1700. },
  1701. mousemoveCb: function (positions, source) {
  1702. return wrappedEmit(wrapEvent({
  1703. type: EventType.IncrementalSnapshot,
  1704. data: {
  1705. source: source,
  1706. positions: positions
  1707. }
  1708. }));
  1709. },
  1710. mouseInteractionCb: function (d) {
  1711. return wrappedEmit(wrapEvent({
  1712. type: EventType.IncrementalSnapshot,
  1713. data: __assign({ source: IncrementalSource.MouseInteraction }, d)
  1714. }));
  1715. },
  1716. scrollCb: function (p) {
  1717. return wrappedEmit(wrapEvent({
  1718. type: EventType.IncrementalSnapshot,
  1719. data: __assign({ source: IncrementalSource.Scroll }, p)
  1720. }));
  1721. },
  1722. viewportResizeCb: function (d) {
  1723. return wrappedEmit(wrapEvent({
  1724. type: EventType.IncrementalSnapshot,
  1725. data: __assign({ source: IncrementalSource.ViewportResize }, d)
  1726. }));
  1727. },
  1728. inputCb: function (v) {
  1729. return wrappedEmit(wrapEvent({
  1730. type: EventType.IncrementalSnapshot,
  1731. data: __assign({ source: IncrementalSource.Input }, v)
  1732. }));
  1733. },
  1734. blockClass: blockClass,
  1735. ignoreClass: ignoreClass,
  1736. maskAllInputs: maskAllInputs,
  1737. inlineStylesheet: inlineStylesheet,
  1738. mousemoveWait: mousemoveWait
  1739. }, hooks));
  1740. };
  1741. if (document.readyState === 'interactive' ||
  1742. document.readyState === 'complete') {
  1743. init_1();
  1744. }
  1745. else {
  1746. handlers_1.push(on('load', function () {
  1747. wrappedEmit(wrapEvent({
  1748. type: EventType.Load,
  1749. data: {}
  1750. }));
  1751. init_1();
  1752. }, window));
  1753. }
  1754. return function () {
  1755. handlers_1.forEach(function (h) { return h(); });
  1756. };
  1757. }
  1758. catch (error) {
  1759. console.warn(error);
  1760. }
  1761. }
  1762. record.addCustomEvent = function (tag, payload) {
  1763. if (!wrappedEmit) {
  1764. throw new Error('please add custom event after start recording');
  1765. }
  1766. wrappedEmit(wrapEvent({
  1767. type: EventType.Custom,
  1768. data: {
  1769. tag: tag,
  1770. payload: payload
  1771. }
  1772. }));
  1773. };
  1774. //
  1775. // An event handler can take an optional event argument
  1776. // and should not return a value
  1777. // An array of all currently registered event handlers for a type
  1778. // A map of event types and their corresponding event handlers.
  1779. /** Mitt: Tiny (~200b) functional event emitter / pubsub.
  1780. * @name mitt
  1781. * @returns {Mitt}
  1782. */
  1783. function mitt(all ) {
  1784. all = all || Object.create(null);
  1785. return {
  1786. /**
  1787. * Register an event handler for the given type.
  1788. *
  1789. * @param {String} type Type of event to listen for, or `"*"` for all events
  1790. * @param {Function} handler Function to call in response to given event
  1791. * @memberOf mitt
  1792. */
  1793. on: function on(type , handler ) {
  1794. (all[type] || (all[type] = [])).push(handler);
  1795. },
  1796. /**
  1797. * Remove an event handler for the given type.
  1798. *
  1799. * @param {String} type Type of event to unregister `handler` from, or `"*"`
  1800. * @param {Function} handler Handler function to remove
  1801. * @memberOf mitt
  1802. */
  1803. off: function off(type , handler ) {
  1804. if (all[type]) {
  1805. all[type].splice(all[type].indexOf(handler) >>> 0, 1);
  1806. }
  1807. },
  1808. /**
  1809. * Invoke all handlers for the given type.
  1810. * If present, `"*"` handlers are invoked after type-matched handlers.
  1811. *
  1812. * @param {String} type The event type to invoke
  1813. * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
  1814. * @memberOf mitt
  1815. */
  1816. emit: function emit(type , evt ) {
  1817. (all[type] || []).slice().map(function (handler) { handler(evt); });
  1818. (all['*'] || []).slice().map(function (handler) { handler(type, evt); });
  1819. }
  1820. };
  1821. }
  1822. var mittProxy = /*#__PURE__*/Object.freeze({
  1823. default: mitt
  1824. });
  1825. function createCommonjsModule(fn, module) {
  1826. return module = { exports: {} }, fn(module, module.exports), module.exports;
  1827. }
  1828. var smoothscroll = createCommonjsModule(function (module, exports) {
  1829. /* smoothscroll v0.4.4 - 2019 - Dustan Kasten, Jeremias Menichelli - MIT License */
  1830. (function () {
  1831. // polyfill
  1832. function polyfill() {
  1833. // aliases
  1834. var w = window;
  1835. var d = document;
  1836. // return if scroll behavior is supported and polyfill is not forced
  1837. if (
  1838. 'scrollBehavior' in d.documentElement.style &&
  1839. w.__forceSmoothScrollPolyfill__ !== true
  1840. ) {
  1841. return;
  1842. }
  1843. // globals
  1844. var Element = w.HTMLElement || w.Element;
  1845. var SCROLL_TIME = 468;
  1846. // object gathering original scroll methods
  1847. var original = {
  1848. scroll: w.scroll || w.scrollTo,
  1849. scrollBy: w.scrollBy,
  1850. elementScroll: Element.prototype.scroll || scrollElement,
  1851. scrollIntoView: Element.prototype.scrollIntoView
  1852. };
  1853. // define timing method
  1854. var now =
  1855. w.performance && w.performance.now
  1856. ? w.performance.now.bind(w.performance)
  1857. : Date.now;
  1858. /**
  1859. * indicates if a the current browser is made by Microsoft
  1860. * @method isMicrosoftBrowser
  1861. * @param {String} userAgent
  1862. * @returns {Boolean}
  1863. */
  1864. function isMicrosoftBrowser(userAgent) {
  1865. var userAgentPatterns = ['MSIE ', 'Trident/', 'Edge/'];
  1866. return new RegExp(userAgentPatterns.join('|')).test(userAgent);
  1867. }
  1868. /*
  1869. * IE has rounding bug rounding down clientHeight and clientWidth and
  1870. * rounding up scrollHeight and scrollWidth causing false positives
  1871. * on hasScrollableSpace
  1872. */
  1873. var ROUNDING_TOLERANCE = isMicrosoftBrowser(w.navigator.userAgent) ? 1 : 0;
  1874. /**
  1875. * changes scroll position inside an element
  1876. * @method scrollElement
  1877. * @param {Number} x
  1878. * @param {Number} y
  1879. * @returns {undefined}
  1880. */
  1881. function scrollElement(x, y) {
  1882. this.scrollLeft = x;
  1883. this.scrollTop = y;
  1884. }
  1885. /**
  1886. * returns result of applying ease math function to a number
  1887. * @method ease
  1888. * @param {Number} k
  1889. * @returns {Number}
  1890. */
  1891. function ease(k) {
  1892. return 0.5 * (1 - Math.cos(Math.PI * k));
  1893. }
  1894. /**
  1895. * indicates if a smooth behavior should be applied
  1896. * @method shouldBailOut
  1897. * @param {Number|Object} firstArg
  1898. * @returns {Boolean}
  1899. */
  1900. function shouldBailOut(firstArg) {
  1901. if (
  1902. firstArg === null ||
  1903. typeof firstArg !== 'object' ||
  1904. firstArg.behavior === undefined ||
  1905. firstArg.behavior === 'auto' ||
  1906. firstArg.behavior === 'instant'
  1907. ) {
  1908. // first argument is not an object/null
  1909. // or behavior is auto, instant or undefined
  1910. return true;
  1911. }
  1912. if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {
  1913. // first argument is an object and behavior is smooth
  1914. return false;
  1915. }
  1916. // throw error when behavior is not supported
  1917. throw new TypeError(
  1918. 'behavior member of ScrollOptions ' +
  1919. firstArg.behavior +
  1920. ' is not a valid value for enumeration ScrollBehavior.'
  1921. );
  1922. }
  1923. /**
  1924. * indicates if an element has scrollable space in the provided axis
  1925. * @method hasScrollableSpace
  1926. * @param {Node} el
  1927. * @param {String} axis
  1928. * @returns {Boolean}
  1929. */
  1930. function hasScrollableSpace(el, axis) {
  1931. if (axis === 'Y') {
  1932. return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;
  1933. }
  1934. if (axis === 'X') {
  1935. return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;
  1936. }
  1937. }
  1938. /**
  1939. * indicates if an element has a scrollable overflow property in the axis
  1940. * @method canOverflow
  1941. * @param {Node} el
  1942. * @param {String} axis
  1943. * @returns {Boolean}
  1944. */
  1945. function canOverflow(el, axis) {
  1946. var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];
  1947. return overflowValue === 'auto' || overflowValue === 'scroll';
  1948. }
  1949. /**
  1950. * indicates if an element can be scrolled in either axis
  1951. * @method isScrollable
  1952. * @param {Node} el
  1953. * @param {String} axis
  1954. * @returns {Boolean}
  1955. */
  1956. function isScrollable(el) {
  1957. var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');
  1958. var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
  1959. return isScrollableY || isScrollableX;
  1960. }
  1961. /**
  1962. * finds scrollable parent of an element
  1963. * @method findScrollableParent
  1964. * @param {Node} el
  1965. * @returns {Node} el
  1966. */
  1967. function findScrollableParent(el) {
  1968. while (el !== d.body && isScrollable(el) === false) {
  1969. el = el.parentNode || el.host;
  1970. }
  1971. return el;
  1972. }
  1973. /**
  1974. * self invoked function that, given a context, steps through scrolling
  1975. * @method step
  1976. * @param {Object} context
  1977. * @returns {undefined}
  1978. */
  1979. function step(context) {
  1980. var time = now();
  1981. var value;
  1982. var currentX;
  1983. var currentY;
  1984. var elapsed = (time - context.startTime) / SCROLL_TIME;
  1985. // avoid elapsed times higher than one
  1986. elapsed = elapsed > 1 ? 1 : elapsed;
  1987. // apply easing to elapsed time
  1988. value = ease(elapsed);
  1989. currentX = context.startX + (context.x - context.startX) * value;
  1990. currentY = context.startY + (context.y - context.startY) * value;
  1991. context.method.call(context.scrollable, currentX, currentY);
  1992. // scroll more if we have not reached our destination
  1993. if (currentX !== context.x || currentY !== context.y) {
  1994. w.requestAnimationFrame(step.bind(w, context));
  1995. }
  1996. }
  1997. /**
  1998. * scrolls window or element with a smooth behavior
  1999. * @method smoothScroll
  2000. * @param {Object|Node} el
  2001. * @param {Number} x
  2002. * @param {Number} y
  2003. * @returns {undefined}
  2004. */
  2005. function smoothScroll(el, x, y) {
  2006. var scrollable;
  2007. var startX;
  2008. var startY;
  2009. var method;
  2010. var startTime = now();
  2011. // define scroll context
  2012. if (el === d.body) {
  2013. scrollable = w;
  2014. startX = w.scrollX || w.pageXOffset;
  2015. startY = w.scrollY || w.pageYOffset;
  2016. method = original.scroll;
  2017. } else {
  2018. scrollable = el;
  2019. startX = el.scrollLeft;
  2020. startY = el.scrollTop;
  2021. method = scrollElement;
  2022. }
  2023. // scroll looping over a frame
  2024. step({
  2025. scrollable: scrollable,
  2026. method: method,
  2027. startTime: startTime,
  2028. startX: startX,
  2029. startY: startY,
  2030. x: x,
  2031. y: y
  2032. });
  2033. }
  2034. // ORIGINAL METHODS OVERRIDES
  2035. // w.scroll and w.scrollTo
  2036. w.scroll = w.scrollTo = function() {
  2037. // avoid action when no arguments are passed
  2038. if (arguments[0] === undefined) {
  2039. return;
  2040. }
  2041. // avoid smooth behavior if not required
  2042. if (shouldBailOut(arguments[0]) === true) {
  2043. original.scroll.call(
  2044. w,
  2045. arguments[0].left !== undefined
  2046. ? arguments[0].left
  2047. : typeof arguments[0] !== 'object'
  2048. ? arguments[0]
  2049. : w.scrollX || w.pageXOffset,
  2050. // use top prop, second argument if present or fallback to scrollY
  2051. arguments[0].top !== undefined
  2052. ? arguments[0].top
  2053. : arguments[1] !== undefined
  2054. ? arguments[1]
  2055. : w.scrollY || w.pageYOffset
  2056. );
  2057. return;
  2058. }
  2059. // LET THE SMOOTHNESS BEGIN!
  2060. smoothScroll.call(
  2061. w,
  2062. d.body,
  2063. arguments[0].left !== undefined
  2064. ? ~~arguments[0].left
  2065. : w.scrollX || w.pageXOffset,
  2066. arguments[0].top !== undefined
  2067. ? ~~arguments[0].top
  2068. : w.scrollY || w.pageYOffset
  2069. );
  2070. };
  2071. // w.scrollBy
  2072. w.scrollBy = function() {
  2073. // avoid action when no arguments are passed
  2074. if (arguments[0] === undefined) {
  2075. return;
  2076. }
  2077. // avoid smooth behavior if not required
  2078. if (shouldBailOut(arguments[0])) {
  2079. original.scrollBy.call(
  2080. w,
  2081. arguments[0].left !== undefined
  2082. ? arguments[0].left
  2083. : typeof arguments[0] !== 'object' ? arguments[0] : 0,
  2084. arguments[0].top !== undefined
  2085. ? arguments[0].top
  2086. : arguments[1] !== undefined ? arguments[1] : 0
  2087. );
  2088. return;
  2089. }
  2090. // LET THE SMOOTHNESS BEGIN!
  2091. smoothScroll.call(
  2092. w,
  2093. d.body,
  2094. ~~arguments[0].left + (w.scrollX || w.pageXOffset),
  2095. ~~arguments[0].top + (w.scrollY || w.pageYOffset)
  2096. );
  2097. };
  2098. // Element.prototype.scroll and Element.prototype.scrollTo
  2099. Element.prototype.scroll = Element.prototype.scrollTo = function() {
  2100. // avoid action when no arguments are passed
  2101. if (arguments[0] === undefined) {
  2102. return;
  2103. }
  2104. // avoid smooth behavior if not required
  2105. if (shouldBailOut(arguments[0]) === true) {
  2106. // if one number is passed, throw error to match Firefox implementation
  2107. if (typeof arguments[0] === 'number' && arguments[1] === undefined) {
  2108. throw new SyntaxError('Value could not be converted');
  2109. }
  2110. original.elementScroll.call(
  2111. this,
  2112. // use left prop, first number argument or fallback to scrollLeft
  2113. arguments[0].left !== undefined
  2114. ? ~~arguments[0].left
  2115. : typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft,
  2116. // use top prop, second argument or fallback to scrollTop
  2117. arguments[0].top !== undefined
  2118. ? ~~arguments[0].top
  2119. : arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop
  2120. );
  2121. return;
  2122. }
  2123. var left = arguments[0].left;
  2124. var top = arguments[0].top;
  2125. // LET THE SMOOTHNESS BEGIN!
  2126. smoothScroll.call(
  2127. this,
  2128. this,
  2129. typeof left === 'undefined' ? this.scrollLeft : ~~left,
  2130. typeof top === 'undefined' ? this.scrollTop : ~~top
  2131. );
  2132. };
  2133. // Element.prototype.scrollBy
  2134. Element.prototype.scrollBy = function() {
  2135. // avoid action when no arguments are passed
  2136. if (arguments[0] === undefined) {
  2137. return;
  2138. }
  2139. // avoid smooth behavior if not required
  2140. if (shouldBailOut(arguments[0]) === true) {
  2141. original.elementScroll.call(
  2142. this,
  2143. arguments[0].left !== undefined
  2144. ? ~~arguments[0].left + this.scrollLeft
  2145. : ~~arguments[0] + this.scrollLeft,
  2146. arguments[0].top !== undefined
  2147. ? ~~arguments[0].top + this.scrollTop
  2148. : ~~arguments[1] + this.scrollTop
  2149. );
  2150. return;
  2151. }
  2152. this.scroll({
  2153. left: ~~arguments[0].left + this.scrollLeft,
  2154. top: ~~arguments[0].top + this.scrollTop,
  2155. behavior: arguments[0].behavior
  2156. });
  2157. };
  2158. // Element.prototype.scrollIntoView
  2159. Element.prototype.scrollIntoView = function() {
  2160. // avoid smooth behavior if not required
  2161. if (shouldBailOut(arguments[0]) === true) {
  2162. original.scrollIntoView.call(
  2163. this,
  2164. arguments[0] === undefined ? true : arguments[0]
  2165. );
  2166. return;
  2167. }
  2168. // LET THE SMOOTHNESS BEGIN!
  2169. var scrollableParent = findScrollableParent(this);
  2170. var parentRects = scrollableParent.getBoundingClientRect();
  2171. var clientRects = this.getBoundingClientRect();
  2172. if (scrollableParent !== d.body) {
  2173. // reveal element inside parent
  2174. smoothScroll.call(
  2175. this,
  2176. scrollableParent,
  2177. scrollableParent.scrollLeft + clientRects.left - parentRects.left,
  2178. scrollableParent.scrollTop + clientRects.top - parentRects.top
  2179. );
  2180. // reveal parent in viewport unless is fixed
  2181. if (w.getComputedStyle(scrollableParent).position !== 'fixed') {
  2182. w.scrollBy({
  2183. left: parentRects.left,
  2184. top: parentRects.top,
  2185. behavior: 'smooth'
  2186. });
  2187. }
  2188. } else {
  2189. // reveal element in viewport
  2190. w.scrollBy({
  2191. left: clientRects.left,
  2192. top: clientRects.top,
  2193. behavior: 'smooth'
  2194. });
  2195. }
  2196. };
  2197. }
  2198. {
  2199. // commonjs
  2200. module.exports = { polyfill: polyfill };
  2201. }
  2202. }());
  2203. });
  2204. var smoothscroll_1 = smoothscroll.polyfill;
  2205. var Timer = (function () {
  2206. function Timer(config, actions) {
  2207. if (actions === void 0) { actions = []; }
  2208. this.timeOffset = 0;
  2209. this.actions = actions;
  2210. this.config = config;
  2211. }
  2212. Timer.prototype.addAction = function (action) {
  2213. var index = this.findActionIndex(action);
  2214. this.actions.splice(index, 0, action);
  2215. };
  2216. Timer.prototype.addActions = function (actions) {
  2217. var _a;
  2218. (_a = this.actions).push.apply(_a, __spread(actions));
  2219. };
  2220. Timer.prototype.start = function () {
  2221. this.actions.sort(function (a1, a2) { return a1.delay - a2.delay; });
  2222. this.timeOffset = 0;
  2223. var lastTimestamp = performance.now();
  2224. var _a = this, actions = _a.actions, config = _a.config;
  2225. var self = this;
  2226. function check(time) {
  2227. self.timeOffset += (time - lastTimestamp) * config.speed;
  2228. lastTimestamp = time;
  2229. while (actions.length) {
  2230. var action = actions[0];
  2231. if (self.timeOffset >= action.delay) {
  2232. actions.shift();
  2233. action.doAction();
  2234. }
  2235. else {
  2236. break;
  2237. }
  2238. }
  2239. if (actions.length > 0 || self.config.liveMode) {
  2240. self.raf = requestAnimationFrame(check);
  2241. }
  2242. }
  2243. this.raf = requestAnimationFrame(check);
  2244. };
  2245. Timer.prototype.clear = function () {
  2246. if (this.raf) {
  2247. cancelAnimationFrame(this.raf);
  2248. }
  2249. this.actions.length = 0;
  2250. };
  2251. Timer.prototype.findActionIndex = function (action) {
  2252. var start = 0;
  2253. var end = this.actions.length - 1;
  2254. while (start <= end) {
  2255. var mid = Math.floor((start + end) / 2);
  2256. if (this.actions[mid].delay < action.delay) {
  2257. start = mid + 1;
  2258. }
  2259. else if (this.actions[mid].delay > action.delay) {
  2260. end = mid - 1;
  2261. }
  2262. else {
  2263. return mid;
  2264. }
  2265. }
  2266. return start;
  2267. };
  2268. return Timer;
  2269. }());
  2270. var rules = function (blockClass) { return [
  2271. "iframe, ." + blockClass + " { background: #ccc }",
  2272. 'noscript { display: none !important; }',
  2273. ]; };
  2274. var SKIP_TIME_THRESHOLD = 10 * 1000;
  2275. var SKIP_TIME_INTERVAL = 5 * 1000;
  2276. var mitt$1 = mitt || mittProxy;
  2277. var REPLAY_CONSOLE_PREFIX = '[replayer]';
  2278. var Replayer = (function () {
  2279. function Replayer(events, config) {
  2280. this.events = [];
  2281. this.emitter = mitt$1();
  2282. this.baselineTime = 0;
  2283. this.noramlSpeed = -1;
  2284. this.missingNodeRetryMap = {};
  2285. if (events.length < 2) {
  2286. throw new Error('Replayer need at least 2 events.');
  2287. }
  2288. this.events = events;
  2289. this.handleResize = this.handleResize.bind(this);
  2290. var defaultConfig = {
  2291. speed: 1,
  2292. root: document.body,
  2293. loadTimeout: 0,
  2294. skipInactive: false,
  2295. showWarning: true,
  2296. showDebug: false,
  2297. blockClass: 'rr-block',
  2298. liveMode: false,
  2299. insertStyleRules: []
  2300. };
  2301. this.config = Object.assign({}, defaultConfig, config);
  2302. this.timer = new Timer(this.config);
  2303. smoothscroll_1();
  2304. polyfill();
  2305. this.setupDom();
  2306. this.emitter.on('resize', this.handleResize);
  2307. }
  2308. Replayer.prototype.on = function (event, handler) {
  2309. this.emitter.on(event, handler);
  2310. };
  2311. Replayer.prototype.setConfig = function (config) {
  2312. var _this = this;
  2313. Object.keys(config).forEach(function (key) {
  2314. _this.config[key] = config[key];
  2315. });
  2316. if (!this.config.skipInactive) {
  2317. this.noramlSpeed = -1;
  2318. }
  2319. };
  2320. Replayer.prototype.getMetaData = function () {
  2321. var firstEvent = this.events[0];
  2322. var lastEvent = this.events[this.events.length - 1];
  2323. return {
  2324. totalTime: lastEvent.timestamp - firstEvent.timestamp
  2325. };
  2326. };
  2327. Replayer.prototype.getCurrentTime = function () {
  2328. return this.timer.timeOffset + this.getTimeOffset();
  2329. };
  2330. Replayer.prototype.getTimeOffset = function () {
  2331. return this.baselineTime - this.events[0].timestamp;
  2332. };
  2333. Replayer.prototype.play = function (timeOffset) {
  2334. var e_1, _a;
  2335. if (timeOffset === void 0) { timeOffset = 0; }
  2336. this.timer.clear();
  2337. this.baselineTime = this.events[0].timestamp + timeOffset;
  2338. var actions = new Array();
  2339. try {
  2340. for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
  2341. var event = _c.value;
  2342. var isSync = event.timestamp < this.baselineTime;
  2343. var castFn = this.getCastFn(event, isSync);
  2344. if (isSync) {
  2345. castFn();
  2346. }
  2347. else {
  2348. actions.push({ doAction: castFn, delay: this.getDelay(event) });
  2349. }
  2350. }
  2351. }
  2352. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2353. finally {
  2354. try {
  2355. if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
  2356. }
  2357. finally { if (e_1) throw e_1.error; }
  2358. }
  2359. this.timer.addActions(actions);
  2360. this.timer.start();
  2361. this.emitter.emit(ReplayerEvents.Start);
  2362. };
  2363. Replayer.prototype.pause = function () {
  2364. this.timer.clear();
  2365. this.emitter.emit(ReplayerEvents.Pause);
  2366. };
  2367. Replayer.prototype.resume = function (timeOffset) {
  2368. var e_2, _a;
  2369. if (timeOffset === void 0) { timeOffset = 0; }
  2370. this.timer.clear();
  2371. this.baselineTime = this.events[0].timestamp + timeOffset;
  2372. var actions = new Array();
  2373. try {
  2374. for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
  2375. var event = _c.value;
  2376. if (event.timestamp <= this.lastPlayedEvent.timestamp ||
  2377. event === this.lastPlayedEvent) {
  2378. continue;
  2379. }
  2380. var castFn = this.getCastFn(event);
  2381. actions.push({
  2382. doAction: castFn,
  2383. delay: this.getDelay(event)
  2384. });
  2385. }
  2386. }
  2387. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  2388. finally {
  2389. try {
  2390. if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
  2391. }
  2392. finally { if (e_2) throw e_2.error; }
  2393. }
  2394. this.timer.addActions(actions);
  2395. this.timer.start();
  2396. this.emitter.emit(ReplayerEvents.Resume);
  2397. };
  2398. Replayer.prototype.addEvent = function (event) {
  2399. var castFn = this.getCastFn(event, true);
  2400. castFn();
  2401. };
  2402. Replayer.prototype.setupDom = function () {
  2403. this.wrapper = document.createElement('div');
  2404. this.wrapper.classList.add('replayer-wrapper');
  2405. this.config.root.appendChild(this.wrapper);
  2406. this.mouse = document.createElement('div');
  2407. this.mouse.classList.add('replayer-mouse');
  2408. this.wrapper.appendChild(this.mouse);
  2409. this.iframe = document.createElement('iframe');
  2410. this.iframe.setAttribute('sandbox', 'allow-same-origin');
  2411. this.iframe.setAttribute('scrolling', 'no');
  2412. this.iframe.setAttribute('style', 'pointer-events: none');
  2413. this.wrapper.appendChild(this.iframe);
  2414. };
  2415. Replayer.prototype.handleResize = function (dimension) {
  2416. this.iframe.width = dimension.width + "px";
  2417. this.iframe.height = dimension.height + "px";
  2418. };
  2419. Replayer.prototype.getDelay = function (event) {
  2420. if (event.type === EventType.IncrementalSnapshot &&
  2421. event.data.source === IncrementalSource.MouseMove) {
  2422. var firstOffset = event.data.positions[0].timeOffset;
  2423. var firstTimestamp = event.timestamp + firstOffset;
  2424. event.delay = firstTimestamp - this.baselineTime;
  2425. return firstTimestamp - this.baselineTime;
  2426. }
  2427. event.delay = event.timestamp - this.baselineTime;
  2428. return event.timestamp - this.baselineTime;
  2429. };
  2430. Replayer.prototype.getCastFn = function (event, isSync) {
  2431. var _this = this;
  2432. if (isSync === void 0) { isSync = false; }
  2433. var castFn;
  2434. switch (event.type) {
  2435. case EventType.DomContentLoaded:
  2436. case EventType.Load:
  2437. break;
  2438. case EventType.Meta:
  2439. castFn = function () {
  2440. return _this.emitter.emit(ReplayerEvents.Resize, {
  2441. width: event.data.width,
  2442. height: event.data.height
  2443. });
  2444. };
  2445. break;
  2446. case EventType.FullSnapshot:
  2447. castFn = function () {
  2448. _this.rebuildFullSnapshot(event);
  2449. _this.iframe.contentWindow.scrollTo(event.data.initialOffset);
  2450. };
  2451. break;
  2452. case EventType.IncrementalSnapshot:
  2453. castFn = function () {
  2454. var e_3, _a;
  2455. _this.applyIncremental(event, isSync);
  2456. if (event === _this.nextUserInteractionEvent) {
  2457. _this.nextUserInteractionEvent = null;
  2458. _this.restoreSpeed();
  2459. }
  2460. if (_this.config.skipInactive && !_this.nextUserInteractionEvent) {
  2461. try {
  2462. for (var _b = __values(_this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
  2463. var _event = _c.value;
  2464. if (_event.timestamp <= event.timestamp) {
  2465. continue;
  2466. }
  2467. if (_this.isUserInteraction(_event)) {
  2468. if (_event.delay - event.delay >
  2469. SKIP_TIME_THRESHOLD * _this.config.speed) {
  2470. _this.nextUserInteractionEvent = _event;
  2471. }
  2472. break;
  2473. }
  2474. }
  2475. }
  2476. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  2477. finally {
  2478. try {
  2479. if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
  2480. }
  2481. finally { if (e_3) throw e_3.error; }
  2482. }
  2483. if (_this.nextUserInteractionEvent) {
  2484. _this.noramlSpeed = _this.config.speed;
  2485. var skipTime = _this.nextUserInteractionEvent.delay - event.delay;
  2486. var payload = {
  2487. speed: Math.min(Math.round(skipTime / SKIP_TIME_INTERVAL), 360)
  2488. };
  2489. _this.setConfig(payload);
  2490. _this.emitter.emit(ReplayerEvents.SkipStart, payload);
  2491. }
  2492. }
  2493. };
  2494. break;
  2495. default:
  2496. }
  2497. var wrappedCastFn = function () {
  2498. if (castFn) {
  2499. castFn();
  2500. }
  2501. _this.lastPlayedEvent = event;
  2502. if (event === _this.events[_this.events.length - 1]) {
  2503. _this.restoreSpeed();
  2504. _this.emitter.emit(ReplayerEvents.Finish);
  2505. }
  2506. };
  2507. return wrappedCastFn;
  2508. };
  2509. Replayer.prototype.rebuildFullSnapshot = function (event) {
  2510. if (Object.keys(this.missingNodeRetryMap).length) {
  2511. console.warn('Found unresolved missing node map', this.missingNodeRetryMap);
  2512. }
  2513. this.missingNodeRetryMap = {};
  2514. mirror.map = rebuild(event.data.node, this.iframe.contentDocument)[1];
  2515. var styleEl = document.createElement('style');
  2516. var _a = this.iframe.contentDocument, documentElement = _a.documentElement, head = _a.head;
  2517. documentElement.insertBefore(styleEl, head);
  2518. var injectStylesRules = rules(this.config.blockClass).concat(this.config.insertStyleRules);
  2519. for (var idx = 0; idx < injectStylesRules.length; idx++) {
  2520. styleEl.sheet.insertRule(injectStylesRules[idx], idx);
  2521. }
  2522. this.emitter.emit(ReplayerEvents.FullsnapshotRebuilded);
  2523. this.waitForStylesheetLoad();
  2524. };
  2525. Replayer.prototype.waitForStylesheetLoad = function () {
  2526. var _this = this;
  2527. var head = this.iframe.contentDocument.head;
  2528. if (head) {
  2529. var unloadSheets_1 = new Set();
  2530. var timer_1;
  2531. head
  2532. .querySelectorAll('link[rel="stylesheet"]')
  2533. .forEach(function (css) {
  2534. if (!css.sheet) {
  2535. if (unloadSheets_1.size === 0) {
  2536. _this.pause();
  2537. _this.emitter.emit(ReplayerEvents.LoadStylesheetStart);
  2538. timer_1 = window.setTimeout(function () {
  2539. _this.resume(_this.getCurrentTime());
  2540. timer_1 = -1;
  2541. }, _this.config.loadTimeout);
  2542. }
  2543. unloadSheets_1.add(css);
  2544. css.addEventListener('load', function () {
  2545. unloadSheets_1["delete"](css);
  2546. if (unloadSheets_1.size === 0 && timer_1 !== -1) {
  2547. _this.resume(_this.getCurrentTime());
  2548. _this.emitter.emit(ReplayerEvents.LoadStylesheetEnd);
  2549. if (timer_1) {
  2550. window.clearTimeout(timer_1);
  2551. }
  2552. }
  2553. });
  2554. }
  2555. });
  2556. }
  2557. };
  2558. Replayer.prototype.applyIncremental = function (e, isSync) {
  2559. var _this = this;
  2560. var d = e.data;
  2561. switch (d.source) {
  2562. case IncrementalSource.Mutation: {
  2563. d.removes.forEach(function (mutation) {
  2564. var target = mirror.getNode(mutation.id);
  2565. if (!target) {
  2566. return _this.warnNodeNotFound(d, mutation.id);
  2567. }
  2568. var parent = mirror.getNode(mutation.parentId);
  2569. if (!parent) {
  2570. return _this.warnNodeNotFound(d, mutation.parentId);
  2571. }
  2572. mirror.removeNodeFromMap(target);
  2573. if (parent) {
  2574. parent.removeChild(target);
  2575. }
  2576. });
  2577. var missingNodeMap_1 = __assign({}, this.missingNodeRetryMap);
  2578. var queue_1 = [];
  2579. var appendNode_1 = function (mutation) {
  2580. var parent = mirror.getNode(mutation.parentId);
  2581. if (!parent) {
  2582. return queue_1.push(mutation);
  2583. }
  2584. var target = buildNodeWithSN(mutation.node, _this.iframe.contentDocument, mirror.map, true);
  2585. var previous = null;
  2586. var next = null;
  2587. if (mutation.previousId) {
  2588. previous = mirror.getNode(mutation.previousId);
  2589. }
  2590. if (mutation.nextId) {
  2591. next = mirror.getNode(mutation.nextId);
  2592. }
  2593. if (mutation.previousId === -1 || mutation.nextId === -1) {
  2594. missingNodeMap_1[mutation.node.id] = {
  2595. node: target,
  2596. mutation: mutation
  2597. };
  2598. return;
  2599. }
  2600. if (previous &&
  2601. previous.nextSibling &&
  2602. previous.nextSibling.parentNode) {
  2603. parent.insertBefore(target, previous.nextSibling);
  2604. }
  2605. else if (next && next.parentNode) {
  2606. parent.insertBefore(target, next);
  2607. }
  2608. else {
  2609. parent.appendChild(target);
  2610. }
  2611. if (mutation.previousId || mutation.nextId) {
  2612. _this.resolveMissingNode(missingNodeMap_1, parent, target, mutation);
  2613. }
  2614. };
  2615. d.adds.forEach(function (mutation) {
  2616. appendNode_1(mutation);
  2617. });
  2618. while (queue_1.length) {
  2619. if (queue_1.every(function (m) { return !Boolean(mirror.getNode(m.parentId)); })) {
  2620. return queue_1.forEach(function (m) { return _this.warnNodeNotFound(d, m.node.id); });
  2621. }
  2622. var mutation = queue_1.shift();
  2623. appendNode_1(mutation);
  2624. }
  2625. if (Object.keys(missingNodeMap_1).length) {
  2626. Object.assign(this.missingNodeRetryMap, missingNodeMap_1);
  2627. }
  2628. d.texts.forEach(function (mutation) {
  2629. var target = mirror.getNode(mutation.id);
  2630. if (!target) {
  2631. return _this.warnNodeNotFound(d, mutation.id);
  2632. }
  2633. target.textContent = mutation.value;
  2634. });
  2635. d.attributes.forEach(function (mutation) {
  2636. var target = mirror.getNode(mutation.id);
  2637. if (!target) {
  2638. return _this.warnNodeNotFound(d, mutation.id);
  2639. }
  2640. for (var attributeName in mutation.attributes) {
  2641. if (typeof attributeName === 'string') {
  2642. var value = mutation.attributes[attributeName];
  2643. if (value !== null) {
  2644. target.setAttribute(attributeName, value);
  2645. }
  2646. else {
  2647. target.removeAttribute(attributeName);
  2648. }
  2649. }
  2650. }
  2651. });
  2652. break;
  2653. }
  2654. case IncrementalSource.MouseMove:
  2655. if (isSync) {
  2656. var lastPosition = d.positions[d.positions.length - 1];
  2657. this.moveAndHover(d, lastPosition.x, lastPosition.y, lastPosition.id);
  2658. }
  2659. else {
  2660. d.positions.forEach(function (p) {
  2661. var action = {
  2662. doAction: function () {
  2663. _this.moveAndHover(d, p.x, p.y, p.id);
  2664. },
  2665. delay: p.timeOffset + e.timestamp - _this.baselineTime
  2666. };
  2667. _this.timer.addAction(action);
  2668. });
  2669. }
  2670. break;
  2671. case IncrementalSource.MouseInteraction: {
  2672. if (d.id === -1) {
  2673. break;
  2674. }
  2675. var event = new Event(MouseInteractions[d.type].toLowerCase());
  2676. var target = mirror.getNode(d.id);
  2677. if (!target) {
  2678. return this.debugNodeNotFound(d, d.id);
  2679. }
  2680. this.emitter.emit(ReplayerEvents.MouseInteraction, {
  2681. type: d.type,
  2682. target: target
  2683. });
  2684. switch (d.type) {
  2685. case MouseInteractions.Blur:
  2686. if (target.blur) {
  2687. target.blur();
  2688. }
  2689. break;
  2690. case MouseInteractions.Focus:
  2691. if (target.focus) {
  2692. target.focus({
  2693. preventScroll: true
  2694. });
  2695. }
  2696. break;
  2697. case MouseInteractions.Click:
  2698. case MouseInteractions.TouchStart:
  2699. case MouseInteractions.TouchEnd:
  2700. if (!isSync) {
  2701. this.moveAndHover(d, d.x, d.y, d.id);
  2702. this.mouse.classList.remove('active');
  2703. void this.mouse.offsetWidth;
  2704. this.mouse.classList.add('active');
  2705. }
  2706. break;
  2707. default:
  2708. target.dispatchEvent(event);
  2709. }
  2710. break;
  2711. }
  2712. case IncrementalSource.Scroll: {
  2713. if (d.id === -1) {
  2714. break;
  2715. }
  2716. var target = mirror.getNode(d.id);
  2717. if (!target) {
  2718. return this.debugNodeNotFound(d, d.id);
  2719. }
  2720. if (target === this.iframe.contentDocument) {
  2721. this.iframe.contentWindow.scrollTo({
  2722. top: d.y,
  2723. left: d.x,
  2724. behavior: isSync ? 'auto' : 'smooth'
  2725. });
  2726. }
  2727. else {
  2728. try {
  2729. target.scrollTop = d.y;
  2730. target.scrollLeft = d.x;
  2731. }
  2732. catch (error) {
  2733. }
  2734. }
  2735. break;
  2736. }
  2737. case IncrementalSource.ViewportResize:
  2738. this.emitter.emit(ReplayerEvents.Resize, {
  2739. width: d.width,
  2740. height: d.height
  2741. });
  2742. break;
  2743. case IncrementalSource.Input: {
  2744. if (d.id === -1) {
  2745. break;
  2746. }
  2747. var target = mirror.getNode(d.id);
  2748. if (!target) {
  2749. return this.debugNodeNotFound(d, d.id);
  2750. }
  2751. try {
  2752. target.checked = d.isChecked;
  2753. target.value = d.text;
  2754. }
  2755. catch (error) {
  2756. }
  2757. break;
  2758. }
  2759. default:
  2760. }
  2761. };
  2762. Replayer.prototype.resolveMissingNode = function (map, parent, target, targetMutation) {
  2763. var previousId = targetMutation.previousId, nextId = targetMutation.nextId;
  2764. var previousInMap = previousId && map[previousId];
  2765. var nextInMap = nextId && map[nextId];
  2766. if (previousInMap) {
  2767. var _a = previousInMap, node = _a.node, mutation = _a.mutation;
  2768. parent.insertBefore(node, target);
  2769. delete map[mutation.node.id];
  2770. delete this.missingNodeRetryMap[mutation.node.id];
  2771. if (mutation.previousId || mutation.nextId) {
  2772. this.resolveMissingNode(map, parent, node, mutation);
  2773. }
  2774. }
  2775. if (nextInMap) {
  2776. var _b = nextInMap, node = _b.node, mutation = _b.mutation;
  2777. parent.insertBefore(node, target.nextSibling);
  2778. delete map[mutation.node.id];
  2779. delete this.missingNodeRetryMap[mutation.node.id];
  2780. if (mutation.previousId || mutation.nextId) {
  2781. this.resolveMissingNode(map, parent, node, mutation);
  2782. }
  2783. }
  2784. };
  2785. Replayer.prototype.moveAndHover = function (d, x, y, id) {
  2786. this.mouse.style.left = x + "px";
  2787. this.mouse.style.top = y + "px";
  2788. var target = mirror.getNode(id);
  2789. if (!target) {
  2790. return this.debugNodeNotFound(d, id);
  2791. }
  2792. this.hoverElements(target);
  2793. };
  2794. Replayer.prototype.hoverElements = function (el) {
  2795. this.iframe
  2796. .contentDocument.querySelectorAll('.\\:hover')
  2797. .forEach(function (hoveredEl) {
  2798. hoveredEl.classList.remove(':hover');
  2799. });
  2800. var currentEl = el;
  2801. while (currentEl) {
  2802. currentEl.classList.add(':hover');
  2803. currentEl = currentEl.parentElement;
  2804. }
  2805. };
  2806. Replayer.prototype.isUserInteraction = function (event) {
  2807. if (event.type !== EventType.IncrementalSnapshot) {
  2808. return false;
  2809. }
  2810. return (event.data.source > IncrementalSource.Mutation &&
  2811. event.data.source <= IncrementalSource.Input);
  2812. };
  2813. Replayer.prototype.restoreSpeed = function () {
  2814. if (this.noramlSpeed === -1) {
  2815. return;
  2816. }
  2817. var payload = { speed: this.noramlSpeed };
  2818. this.setConfig(payload);
  2819. this.emitter.emit(ReplayerEvents.SkipEnd, payload);
  2820. this.noramlSpeed = -1;
  2821. };
  2822. Replayer.prototype.warnNodeNotFound = function (d, id) {
  2823. if (!this.config.showWarning) {
  2824. return;
  2825. }
  2826. console.warn(REPLAY_CONSOLE_PREFIX, "Node with id '" + id + "' not found in", d);
  2827. };
  2828. Replayer.prototype.debugNodeNotFound = function (d, id) {
  2829. if (!this.config.showDebug) {
  2830. return;
  2831. }
  2832. console.log(REPLAY_CONSOLE_PREFIX, "Node with id '" + id + "' not found in", d);
  2833. };
  2834. return Replayer;
  2835. }());
  2836. var addCustomEvent = record.addCustomEvent;
  2837. export { record, addCustomEvent, Replayer, mirror, EventType, IncrementalSource, MouseInteractions, ReplayerEvents };