新乡民调(来自息县民调) - 主标

rrweb.js 98KB

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