| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of the
- License at http://www.apache.org/licenses/LICENSE-2.0
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
- MERCHANTABLITY OR NON-INFRINGEMENT.
- See the Apache Version 2.0 License for specific language governing permissions
- and limitations under the License.
- ***************************************************************************** */
- var __assign = function() {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- function __values(o) {
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
- if (m) return m.call(o);
- return {
- next: function () {
- if (o && i >= o.length) o = void 0;
- return { value: o && o[i++], done: !o };
- }
- };
- }
- function __read(o, n) {
- var m = typeof Symbol === "function" && o[Symbol.iterator];
- if (!m) return o;
- var i = m.call(o), r, ar = [], e;
- try {
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
- }
- catch (error) { e = { error: error }; }
- finally {
- try {
- if (r && !r.done && (m = i["return"])) m.call(i);
- }
- finally { if (e) throw e.error; }
- }
- return ar;
- }
- function __spread() {
- for (var ar = [], i = 0; i < arguments.length; i++)
- ar = ar.concat(__read(arguments[i]));
- return ar;
- }
- var NodeType;
- (function (NodeType) {
- NodeType[NodeType["Document"] = 0] = "Document";
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
- NodeType[NodeType["Element"] = 2] = "Element";
- NodeType[NodeType["Text"] = 3] = "Text";
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
- NodeType[NodeType["Comment"] = 5] = "Comment";
- })(NodeType || (NodeType = {}));
- var _id = 1;
- function genId() {
- return _id++;
- }
- function getCssRulesString(s) {
- try {
- var rules = s.rules || s.cssRules;
- return rules
- ? Array.from(rules).reduce(function (prev, cur) { return prev + getCssRuleString(cur); }, '')
- : null;
- }
- catch (error) {
- return null;
- }
- }
- function getCssRuleString(rule) {
- return isCSSImportRule(rule)
- ? getCssRulesString(rule.styleSheet) || ''
- : rule.cssText;
- }
- function isCSSImportRule(rule) {
- return 'styleSheet' in rule;
- }
- function extractOrigin(url) {
- var origin;
- if (url.indexOf('//') > -1) {
- origin = url
- .split('/')
- .slice(0, 3)
- .join('/');
- }
- else {
- origin = url.split('/')[0];
- }
- origin = origin.split('?')[0];
- return origin;
- }
- var URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm;
- var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
- var DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64).*,(.*)/i;
- function absoluteToStylesheet(cssText, href) {
- return cssText.replace(URL_IN_CSS_REF, function (origin, path1, path2, path3) {
- var filePath = path1 || path2 || path3;
- if (!filePath) {
- return origin;
- }
- if (!RELATIVE_PATH.test(filePath)) {
- return "url('" + filePath + "')";
- }
- if (DATA_URI.test(filePath)) {
- return "url(" + filePath + ")";
- }
- if (filePath[0] === '/') {
- return "url('" + (extractOrigin(href) + filePath) + "')";
- }
- var stack = href.split('/');
- var parts = filePath.split('/');
- stack.pop();
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
- var part = parts_1[_i];
- if (part === '.') {
- continue;
- }
- else if (part === '..') {
- stack.pop();
- }
- else {
- stack.push(part);
- }
- }
- return "url('" + stack.join('/') + "')";
- });
- }
- function getAbsoluteSrcsetString(doc, attributeValue) {
- if (attributeValue.trim() === '') {
- return attributeValue;
- }
- var srcsetValues = attributeValue.split(',');
- var resultingSrcsetString = srcsetValues
- .map(function (srcItem) {
- var trimmedSrcItem = srcItem.trimLeft().trimRight();
- var urlAndSize = trimmedSrcItem.split(' ');
- if (urlAndSize.length === 2) {
- var absUrl = absoluteToDoc(doc, urlAndSize[0]);
- return absUrl + " " + urlAndSize[1];
- }
- else if (urlAndSize.length === 1) {
- var absUrl = absoluteToDoc(doc, urlAndSize[0]);
- return "" + absUrl;
- }
- return '';
- })
- .join(',');
- return resultingSrcsetString;
- }
- function absoluteToDoc(doc, attributeValue) {
- if (attributeValue.trim() === '') {
- return attributeValue;
- }
- var a = doc.createElement('a');
- a.href = attributeValue;
- return a.href;
- }
- function isSVGElement(el) {
- return el.tagName === 'svg' || el instanceof SVGElement;
- }
- function transformAttribute(doc, name, value) {
- if (name === 'src' || name === 'href') {
- return absoluteToDoc(doc, value);
- }
- else if (name === 'srcset') {
- return getAbsoluteSrcsetString(doc, value);
- }
- else if (name === 'style') {
- return absoluteToStylesheet(value, location.href);
- }
- else {
- return value;
- }
- }
- function serializeNode(n, doc, blockClass, inlineStylesheet, maskAllInputs) {
- switch (n.nodeType) {
- case n.DOCUMENT_NODE:
- return {
- type: NodeType.Document,
- childNodes: []
- };
- case n.DOCUMENT_TYPE_NODE:
- return {
- type: NodeType.DocumentType,
- name: n.name,
- publicId: n.publicId,
- systemId: n.systemId
- };
- case n.ELEMENT_NODE:
- var needBlock_1 = false;
- if (typeof blockClass === 'string') {
- needBlock_1 = n.classList.contains(blockClass);
- }
- else {
- n.classList.forEach(function (className) {
- if (blockClass.test(className)) {
- needBlock_1 = true;
- }
- });
- }
- var tagName = n.tagName.toLowerCase();
- var attributes_1 = {};
- for (var _i = 0, _a = Array.from(n.attributes); _i < _a.length; _i++) {
- var _b = _a[_i], name = _b.name, value = _b.value;
- attributes_1[name] = transformAttribute(doc, name, value);
- }
- if (tagName === 'link' && inlineStylesheet) {
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
- return s.href === n.href;
- });
- var cssText = getCssRulesString(stylesheet);
- if (cssText) {
- delete attributes_1.rel;
- delete attributes_1.href;
- attributes_1._cssText = absoluteToStylesheet(cssText, stylesheet.href);
- }
- }
- if (tagName === 'style' &&
- n.sheet &&
- !(n.innerText ||
- n.textContent ||
- '').trim().length) {
- var cssText = getCssRulesString(n
- .sheet);
- if (cssText) {
- attributes_1._cssText = absoluteToStylesheet(cssText, location.href);
- }
- }
- if (tagName === 'input' ||
- tagName === 'textarea' ||
- tagName === 'select') {
- var value = n.value;
- if (attributes_1.type !== 'radio' &&
- attributes_1.type !== 'checkbox' &&
- value) {
- attributes_1.value = maskAllInputs ? '*'.repeat(value.length) : value;
- }
- else if (n.checked) {
- attributes_1.checked = n.checked;
- }
- }
- if (tagName === 'option') {
- var selectValue = n.parentElement;
- if (attributes_1.value === selectValue.value) {
- attributes_1.selected = n.selected;
- }
- }
- if (tagName === 'canvas') {
- attributes_1.rr_dataURL = n.toDataURL();
- }
- if (needBlock_1) {
- var _c = n.getBoundingClientRect(), width = _c.width, height = _c.height;
- attributes_1.rr_width = width + "px";
- attributes_1.rr_height = height + "px";
- }
- return {
- type: NodeType.Element,
- tagName: tagName,
- attributes: attributes_1,
- childNodes: [],
- isSVG: isSVGElement(n) || undefined,
- needBlock: needBlock_1
- };
- case n.TEXT_NODE:
- var parentTagName = n.parentNode && n.parentNode.tagName;
- var textContent = n.textContent;
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
- if (isStyle && textContent) {
- textContent = absoluteToStylesheet(textContent, location.href);
- }
- if (parentTagName === 'SCRIPT') {
- textContent = 'SCRIPT_PLACEHOLDER';
- }
- return {
- type: NodeType.Text,
- textContent: textContent || '',
- isStyle: isStyle
- };
- case n.CDATA_SECTION_NODE:
- return {
- type: NodeType.CDATA,
- textContent: ''
- };
- case n.COMMENT_NODE:
- return {
- type: NodeType.Comment,
- textContent: n.textContent || ''
- };
- default:
- return false;
- }
- }
- function serializeNodeWithId(n, doc, map, blockClass, skipChild, inlineStylesheet, maskAllInputs) {
- if (skipChild === void 0) { skipChild = false; }
- if (inlineStylesheet === void 0) { inlineStylesheet = true; }
- if (maskAllInputs === void 0) { maskAllInputs = false; }
- var _serializedNode = serializeNode(n, doc, blockClass, inlineStylesheet, maskAllInputs);
- if (!_serializedNode) {
- console.warn(n, 'not serialized');
- return null;
- }
- var id;
- if ('__sn' in n) {
- id = n.__sn.id;
- }
- else {
- id = genId();
- }
- var serializedNode = Object.assign(_serializedNode, { id: id });
- n.__sn = serializedNode;
- map[id] = n;
- var recordChild = !skipChild;
- if (serializedNode.type === NodeType.Element) {
- recordChild = recordChild && !serializedNode.needBlock;
- delete serializedNode.needBlock;
- }
- if ((serializedNode.type === NodeType.Document ||
- serializedNode.type === NodeType.Element) &&
- recordChild) {
- for (var _i = 0, _a = Array.from(n.childNodes); _i < _a.length; _i++) {
- var childN = _a[_i];
- var serializedChildNode = serializeNodeWithId(childN, doc, map, blockClass, skipChild, inlineStylesheet, maskAllInputs);
- if (serializedChildNode) {
- serializedNode.childNodes.push(serializedChildNode);
- }
- }
- }
- return serializedNode;
- }
- function snapshot(n, blockClass, inlineStylesheet, maskAllInputs) {
- if (blockClass === void 0) { blockClass = 'rr-block'; }
- if (inlineStylesheet === void 0) { inlineStylesheet = true; }
- if (maskAllInputs === void 0) { maskAllInputs = false; }
- var idNodeMap = {};
- return [
- serializeNodeWithId(n, n, idNodeMap, blockClass, false, inlineStylesheet, maskAllInputs),
- idNodeMap,
- ];
- }
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
- function parse(css, options) {
- if (options === void 0) { options = {}; }
- var lineno = 1;
- var column = 1;
- function updatePosition(str) {
- var lines = str.match(/\n/g);
- if (lines) {
- lineno += lines.length;
- }
- var i = str.lastIndexOf('\n');
- column = i === -1 ? column + str.length : str.length - i;
- }
- function position() {
- var start = { line: lineno, column: column };
- return function (node) {
- node.position = new Position(start);
- whitespace();
- return node;
- };
- }
- var Position = (function () {
- function Position(start) {
- this.start = start;
- this.end = { line: lineno, column: column };
- this.source = options.source;
- }
- return Position;
- }());
- Position.prototype.content = css;
- var errorsList = [];
- function error(msg) {
- var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
- err.reason = msg;
- err.filename = options.source;
- err.line = lineno;
- err.column = column;
- err.source = css;
- if (options.silent) {
- errorsList.push(err);
- }
- else {
- throw err;
- }
- }
- function stylesheet() {
- var rulesList = rules();
- return {
- type: 'stylesheet',
- stylesheet: {
- source: options.source,
- rules: rulesList,
- parsingErrors: errorsList
- }
- };
- }
- function open() {
- return match(/^{\s*/);
- }
- function close() {
- return match(/^}/);
- }
- function rules() {
- var node;
- var rules = [];
- whitespace();
- comments(rules);
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
- if (node !== false) {
- rules.push(node);
- comments(rules);
- }
- }
- return rules;
- }
- function match(re) {
- var m = re.exec(css);
- if (!m) {
- return;
- }
- var str = m[0];
- updatePosition(str);
- css = css.slice(str.length);
- return m;
- }
- function whitespace() {
- match(/^\s*/);
- }
- function comments(rules) {
- if (rules === void 0) { rules = []; }
- var c;
- while ((c = comment())) {
- if (c !== false) {
- rules.push(c);
- }
- c = comment();
- }
- return rules;
- }
- function comment() {
- var pos = position();
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
- return;
- }
- var i = 2;
- while ('' !== css.charAt(i) &&
- ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
- ++i;
- }
- i += 2;
- if ('' === css.charAt(i - 1)) {
- return error('End of comment missing');
- }
- var str = css.slice(2, i - 2);
- column += 2;
- updatePosition(str);
- css = css.slice(i);
- column += 2;
- return pos({
- type: 'comment',
- comment: str
- });
- }
- function selector() {
- var m = match(/^([^{]+)/);
- if (!m) {
- return;
- }
- return trim(m[0])
- .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
- .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
- return m.replace(/,/g, '\u200C');
- })
- .split(/\s*(?![^(]*\)),\s*/)
- .map(function (s) {
- return s.replace(/\u200C/g, ',');
- });
- }
- function declaration() {
- var pos = position();
- var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
- if (!propMatch) {
- return;
- }
- var prop = trim(propMatch[0]);
- if (!match(/^:\s*/)) {
- return error("property missing ':'");
- }
- var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
- var ret = pos({
- type: 'declaration',
- property: prop.replace(commentre, ''),
- value: val ? trim(val[0]).replace(commentre, '') : ''
- });
- match(/^[;\s]*/);
- return ret;
- }
- function declarations() {
- var decls = [];
- if (!open()) {
- return error("missing '{'");
- }
- comments(decls);
- var decl;
- while ((decl = declaration())) {
- if (decl !== false) {
- decls.push(decl);
- comments(decls);
- }
- decl = declaration();
- }
- if (!close()) {
- return error("missing '}'");
- }
- return decls;
- }
- function keyframe() {
- var m;
- var vals = [];
- var pos = position();
- while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
- vals.push(m[1]);
- match(/^,\s*/);
- }
- if (!vals.length) {
- return;
- }
- return pos({
- type: 'keyframe',
- values: vals,
- declarations: declarations()
- });
- }
- function atkeyframes() {
- var pos = position();
- var m = match(/^@([-\w]+)?keyframes\s*/);
- if (!m) {
- return;
- }
- var vendor = m[1];
- m = match(/^([-\w]+)\s*/);
- if (!m) {
- return error('@keyframes missing name');
- }
- var name = m[1];
- if (!open()) {
- return error("@keyframes missing '{'");
- }
- var frame;
- var frames = comments();
- while ((frame = keyframe())) {
- frames.push(frame);
- frames = frames.concat(comments());
- }
- if (!close()) {
- return error("@keyframes missing '}'");
- }
- return pos({
- type: 'keyframes',
- name: name,
- vendor: vendor,
- keyframes: frames
- });
- }
- function atsupports() {
- var pos = position();
- var m = match(/^@supports *([^{]+)/);
- if (!m) {
- return;
- }
- var supports = trim(m[1]);
- if (!open()) {
- return error("@supports missing '{'");
- }
- var style = comments().concat(rules());
- if (!close()) {
- return error("@supports missing '}'");
- }
- return pos({
- type: 'supports',
- supports: supports,
- rules: style
- });
- }
- function athost() {
- var pos = position();
- var m = match(/^@host\s*/);
- if (!m) {
- return;
- }
- if (!open()) {
- return error("@host missing '{'");
- }
- var style = comments().concat(rules());
- if (!close()) {
- return error("@host missing '}'");
- }
- return pos({
- type: 'host',
- rules: style
- });
- }
- function atmedia() {
- var pos = position();
- var m = match(/^@media *([^{]+)/);
- if (!m) {
- return;
- }
- var media = trim(m[1]);
- if (!open()) {
- return error("@media missing '{'");
- }
- var style = comments().concat(rules());
- if (!close()) {
- return error("@media missing '}'");
- }
- return pos({
- type: 'media',
- media: media,
- rules: style
- });
- }
- function atcustommedia() {
- var pos = position();
- var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
- if (!m) {
- return;
- }
- return pos({
- type: 'custom-media',
- name: trim(m[1]),
- media: trim(m[2])
- });
- }
- function atpage() {
- var pos = position();
- var m = match(/^@page */);
- if (!m) {
- return;
- }
- var sel = selector() || [];
- if (!open()) {
- return error("@page missing '{'");
- }
- var decls = comments();
- var decl;
- while ((decl = declaration())) {
- decls.push(decl);
- decls = decls.concat(comments());
- }
- if (!close()) {
- return error("@page missing '}'");
- }
- return pos({
- type: 'page',
- selectors: sel,
- declarations: decls
- });
- }
- function atdocument() {
- var pos = position();
- var m = match(/^@([-\w]+)?document *([^{]+)/);
- if (!m) {
- return;
- }
- var vendor = trim(m[1]);
- var doc = trim(m[2]);
- if (!open()) {
- return error("@document missing '{'");
- }
- var style = comments().concat(rules());
- if (!close()) {
- return error("@document missing '}'");
- }
- return pos({
- type: 'document',
- document: doc,
- vendor: vendor,
- rules: style
- });
- }
- function atfontface() {
- var pos = position();
- var m = match(/^@font-face\s*/);
- if (!m) {
- return;
- }
- if (!open()) {
- return error("@font-face missing '{'");
- }
- var decls = comments();
- var decl;
- while ((decl = declaration())) {
- decls.push(decl);
- decls = decls.concat(comments());
- }
- if (!close()) {
- return error("@font-face missing '}'");
- }
- return pos({
- type: 'font-face',
- declarations: decls
- });
- }
- var atimport = _compileAtrule('import');
- var atcharset = _compileAtrule('charset');
- var atnamespace = _compileAtrule('namespace');
- function _compileAtrule(name) {
- var re = new RegExp('^@' + name + '\\s*([^;]+);');
- return function () {
- var pos = position();
- var m = match(re);
- if (!m) {
- return;
- }
- var ret = { type: name };
- ret[name] = m[1].trim();
- return pos(ret);
- };
- }
- function atrule() {
- if (css[0] !== '@') {
- return;
- }
- return (atkeyframes() ||
- atmedia() ||
- atcustommedia() ||
- atsupports() ||
- atimport() ||
- atcharset() ||
- atnamespace() ||
- atdocument() ||
- atpage() ||
- athost() ||
- atfontface());
- }
- function rule() {
- var pos = position();
- var sel = selector();
- if (!sel) {
- return error('selector missing');
- }
- comments();
- return pos({
- type: 'rule',
- selectors: sel,
- declarations: declarations()
- });
- }
- return addParent(stylesheet());
- }
- function trim(str) {
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
- }
- function addParent(obj, parent) {
- var isNode = obj && typeof obj.type === 'string';
- var childParent = isNode ? obj : parent;
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
- var k = _a[_i];
- var value = obj[k];
- if (Array.isArray(value)) {
- value.forEach(function (v) {
- addParent(v, childParent);
- });
- }
- else if (value && typeof value === 'object') {
- addParent(value, childParent);
- }
- }
- if (isNode) {
- Object.defineProperty(obj, 'parent', {
- configurable: true,
- writable: true,
- enumerable: false,
- value: parent || null
- });
- }
- return obj;
- }
- var tagMap = {
- script: 'noscript',
- altglyph: 'altGlyph',
- altglyphdef: 'altGlyphDef',
- altglyphitem: 'altGlyphItem',
- animatecolor: 'animateColor',
- animatemotion: 'animateMotion',
- animatetransform: 'animateTransform',
- clippath: 'clipPath',
- feblend: 'feBlend',
- fecolormatrix: 'feColorMatrix',
- fecomponenttransfer: 'feComponentTransfer',
- fecomposite: 'feComposite',
- feconvolvematrix: 'feConvolveMatrix',
- fediffuselighting: 'feDiffuseLighting',
- fedisplacementmap: 'feDisplacementMap',
- fedistantlight: 'feDistantLight',
- fedropshadow: 'feDropShadow',
- feflood: 'feFlood',
- fefunca: 'feFuncA',
- fefuncb: 'feFuncB',
- fefuncg: 'feFuncG',
- fefuncr: 'feFuncR',
- fegaussianblur: 'feGaussianBlur',
- feimage: 'feImage',
- femerge: 'feMerge',
- femergenode: 'feMergeNode',
- femorphology: 'feMorphology',
- feoffset: 'feOffset',
- fepointlight: 'fePointLight',
- fespecularlighting: 'feSpecularLighting',
- fespotlight: 'feSpotLight',
- fetile: 'feTile',
- feturbulence: 'feTurbulence',
- foreignobject: 'foreignObject',
- glyphref: 'glyphRef',
- lineargradient: 'linearGradient',
- radialgradient: 'radialGradient'
- };
- function getTagName(n) {
- var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
- if (tagName === 'link' && n.attributes._cssText) {
- tagName = 'style';
- }
- return tagName;
- }
- var HOVER_SELECTOR = /([^\\]):hover/g;
- function addHoverClass(cssText) {
- var ast = parse(cssText, { silent: true });
- if (!ast.stylesheet) {
- return cssText;
- }
- ast.stylesheet.rules.forEach(function (rule) {
- if ('selectors' in rule) {
- (rule.selectors || []).forEach(function (selector) {
- if (HOVER_SELECTOR.test(selector)) {
- var newSelector = selector.replace(HOVER_SELECTOR, '$1.\\:hover');
- cssText = cssText.replace(selector, selector + ", " + newSelector);
- }
- });
- }
- });
- return cssText;
- }
- function buildNode(n, doc, HACK_CSS) {
- switch (n.type) {
- case NodeType.Document:
- return doc.implementation.createDocument(null, '', null);
- case NodeType.DocumentType:
- return doc.implementation.createDocumentType(n.name, n.publicId, n.systemId);
- case NodeType.Element:
- var tagName = getTagName(n);
- var node_1;
- if (n.isSVG) {
- node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
- }
- else {
- node_1 = doc.createElement(tagName);
- }
- var _loop_1 = function (name) {
- if (!n.attributes.hasOwnProperty(name)) {
- return "continue";
- }
- var value = n.attributes[name];
- value = typeof value === 'boolean' ? '' : value;
- if (!name.startsWith('rr_')) {
- var isTextarea = tagName === 'textarea' && name === 'value';
- var isRemoteOrDynamicCss = tagName === 'style' && name === '_cssText';
- if (isRemoteOrDynamicCss && HACK_CSS) {
- value = addHoverClass(value);
- }
- if (isTextarea || isRemoteOrDynamicCss) {
- var child = doc.createTextNode(value);
- for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
- var c = _a[_i];
- if (c.nodeType === node_1.TEXT_NODE) {
- node_1.removeChild(c);
- }
- }
- node_1.appendChild(child);
- return "continue";
- }
- if (tagName === 'iframe' && name === 'src') {
- return "continue";
- }
- try {
- if (n.isSVG && name === 'xlink:href') {
- node_1.setAttributeNS('http://www.w3.org/1999/xlink', name, value);
- }
- else {
- node_1.setAttribute(name, value);
- }
- }
- catch (error) {
- }
- }
- else {
- if (tagName === 'canvas' && name === 'rr_dataURL') {
- var image_1 = document.createElement('img');
- image_1.src = value;
- image_1.onload = function () {
- var ctx = node_1.getContext('2d');
- if (ctx) {
- ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
- }
- };
- }
- if (name === 'rr_width') {
- node_1.style.width = value;
- }
- if (name === 'rr_height') {
- node_1.style.height = value;
- }
- }
- };
- for (var name in n.attributes) {
- _loop_1(name);
- }
- return node_1;
- case NodeType.Text:
- return doc.createTextNode(n.isStyle && HACK_CSS ? addHoverClass(n.textContent) : n.textContent);
- case NodeType.CDATA:
- return doc.createCDATASection(n.textContent);
- case NodeType.Comment:
- return doc.createComment(n.textContent);
- default:
- return null;
- }
- }
- function buildNodeWithSN(n, doc, map, skipChild, HACK_CSS) {
- if (skipChild === void 0) { skipChild = false; }
- if (HACK_CSS === void 0) { HACK_CSS = true; }
- var node = buildNode(n, doc, HACK_CSS);
- if (!node) {
- return null;
- }
- if (n.type === NodeType.Document) {
- doc.close();
- doc.open();
- node = doc;
- }
- node.__sn = n;
- map[n.id] = node;
- if ((n.type === NodeType.Document || n.type === NodeType.Element) &&
- !skipChild) {
- for (var _i = 0, _a = n.childNodes; _i < _a.length; _i++) {
- var childN = _a[_i];
- var childNode = buildNodeWithSN(childN, doc, map, false, HACK_CSS);
- if (!childNode) {
- console.warn('Failed to rebuild', childN);
- }
- else {
- node.appendChild(childNode);
- }
- }
- }
- return node;
- }
- function rebuild(n, doc, HACK_CSS) {
- if (HACK_CSS === void 0) { HACK_CSS = true; }
- var idNodeMap = {};
- return [buildNodeWithSN(n, doc, idNodeMap, false, HACK_CSS), idNodeMap];
- }
- function on(type, fn, target) {
- if (target === void 0) { target = document; }
- var options = { capture: true, passive: true };
- target.addEventListener(type, fn, options);
- return function () { return target.removeEventListener(type, fn, options); };
- }
- var mirror = {
- map: {},
- getId: function (n) {
- if (!n.__sn) {
- return -1;
- }
- return n.__sn.id;
- },
- getNode: function (id) {
- return mirror.map[id] || null;
- },
- removeNodeFromMap: function (n) {
- var id = n.__sn && n.__sn.id;
- delete mirror.map[id];
- if (n.childNodes) {
- n.childNodes.forEach(function (child) {
- return mirror.removeNodeFromMap(child);
- });
- }
- },
- has: function (id) {
- return mirror.map.hasOwnProperty(id);
- }
- };
- function throttle(func, wait, options) {
- if (options === void 0) { options = {}; }
- var timeout = null;
- var previous = 0;
- return function (arg) {
- var now = Date.now();
- if (!previous && options.leading === false) {
- previous = now;
- }
- var remaining = wait - (now - previous);
- var context = this;
- var args = arguments;
- if (remaining <= 0 || remaining > wait) {
- if (timeout) {
- window.clearTimeout(timeout);
- timeout = null;
- }
- previous = now;
- func.apply(context, args);
- }
- else if (!timeout && options.trailing !== false) {
- timeout = window.setTimeout(function () {
- previous = options.leading === false ? 0 : Date.now();
- timeout = null;
- func.apply(context, args);
- }, remaining);
- }
- };
- }
- function hookSetter(target, key, d, isRevoked) {
- var original = Object.getOwnPropertyDescriptor(target, key);
- Object.defineProperty(target, key, isRevoked
- ? d
- : {
- set: function (value) {
- var _this = this;
- setTimeout(function () {
- d.set.call(_this, value);
- }, 0);
- if (original && original.set) {
- original.set.call(this, value);
- }
- }
- });
- return function () { return hookSetter(target, key, original || {}, true); };
- }
- function getWindowHeight() {
- return (window.innerHeight ||
- (document.documentElement && document.documentElement.clientHeight) ||
- (document.body && document.body.clientHeight));
- }
- function getWindowWidth() {
- return (window.innerWidth ||
- (document.documentElement && document.documentElement.clientWidth) ||
- (document.body && document.body.clientWidth));
- }
- function isBlocked(node, blockClass) {
- if (!node) {
- return false;
- }
- if (node.nodeType === node.ELEMENT_NODE) {
- var needBlock_1 = false;
- if (typeof blockClass === 'string') {
- needBlock_1 = node.classList.contains(blockClass);
- }
- else {
- node.classList.forEach(function (className) {
- if (blockClass.test(className)) {
- needBlock_1 = true;
- }
- });
- }
- return needBlock_1 || isBlocked(node.parentNode, blockClass);
- }
- return isBlocked(node.parentNode, blockClass);
- }
- function isAncestorRemoved(target) {
- var id = mirror.getId(target);
- if (!mirror.has(id)) {
- return true;
- }
- if (target.parentNode &&
- target.parentNode.nodeType === target.DOCUMENT_NODE) {
- return false;
- }
- if (!target.parentNode) {
- return true;
- }
- return isAncestorRemoved(target.parentNode);
- }
- function isTouchEvent(event) {
- return Boolean(event.changedTouches);
- }
- function polyfill() {
- if ('NodeList' in window && !NodeList.prototype.forEach) {
- NodeList.prototype.forEach = Array.prototype
- .forEach;
- }
- }
- (function (EventType) {
- EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
- EventType[EventType["Load"] = 1] = "Load";
- EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
- EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
- EventType[EventType["Meta"] = 4] = "Meta";
- EventType[EventType["Custom"] = 5] = "Custom";
- })(exports.EventType || (exports.EventType = {}));
- (function (IncrementalSource) {
- IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
- IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
- IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
- IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
- IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
- IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
- IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
- })(exports.IncrementalSource || (exports.IncrementalSource = {}));
- (function (MouseInteractions) {
- MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
- MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
- MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
- MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
- MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
- MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
- MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
- MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
- MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
- MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
- })(exports.MouseInteractions || (exports.MouseInteractions = {}));
- (function (ReplayerEvents) {
- ReplayerEvents["Start"] = "start";
- ReplayerEvents["Pause"] = "pause";
- ReplayerEvents["Resume"] = "resume";
- ReplayerEvents["Resize"] = "resize";
- ReplayerEvents["Finish"] = "finish";
- ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
- ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
- ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
- ReplayerEvents["SkipStart"] = "skip-start";
- ReplayerEvents["SkipEnd"] = "skip-end";
- ReplayerEvents["MouseInteraction"] = "mouse-interaction";
- })(exports.ReplayerEvents || (exports.ReplayerEvents = {}));
- function deepDelete(addsSet, n) {
- addsSet["delete"](n);
- n.childNodes.forEach(function (childN) { return deepDelete(addsSet, childN); });
- }
- function isParentRemoved(removes, n) {
- var parentNode = n.parentNode;
- if (!parentNode) {
- return false;
- }
- var parentId = mirror.getId(parentNode);
- if (removes.some(function (r) { return r.id === parentId; })) {
- return true;
- }
- return isParentRemoved(removes, parentNode);
- }
- function isAncestorInSet(set, n) {
- var parentNode = n.parentNode;
- if (!parentNode) {
- return false;
- }
- if (set.has(parentNode)) {
- return true;
- }
- return isAncestorInSet(set, parentNode);
- }
- var moveKey = function (id, parentId) { return id + "@" + parentId; };
- function isINode(n) {
- return '__sn' in n;
- }
- function initMutationObserver(cb, blockClass, inlineStylesheet, maskAllInputs) {
- var observer = new MutationObserver(function (mutations) {
- var e_1, _a, e_2, _b;
- var texts = [];
- var attributes = [];
- var removes = [];
- var adds = [];
- var addedSet = new Set();
- var movedSet = new Set();
- var droppedSet = new Set();
- var movedMap = {};
- var genAdds = function (n, target) {
- if (isBlocked(n, blockClass)) {
- return;
- }
- if (isINode(n)) {
- movedSet.add(n);
- var targetId = null;
- if (target && isINode(target)) {
- targetId = target.__sn.id;
- }
- if (targetId) {
- movedMap[moveKey(n.__sn.id, targetId)] = true;
- }
- }
- else {
- addedSet.add(n);
- droppedSet["delete"](n);
- }
- n.childNodes.forEach(function (childN) { return genAdds(childN); });
- };
- mutations.forEach(function (mutation) {
- var type = mutation.type, target = mutation.target, oldValue = mutation.oldValue, addedNodes = mutation.addedNodes, removedNodes = mutation.removedNodes, attributeName = mutation.attributeName;
- switch (type) {
- case 'characterData': {
- var value = target.textContent;
- if (!isBlocked(target, blockClass) && value !== oldValue) {
- texts.push({
- value: value,
- node: target
- });
- }
- break;
- }
- case 'attributes': {
- var value = target.getAttribute(attributeName);
- if (isBlocked(target, blockClass) || value === oldValue) {
- return;
- }
- var item = attributes.find(function (a) { return a.node === target; });
- if (!item) {
- item = {
- node: target,
- attributes: {}
- };
- attributes.push(item);
- }
- item.attributes[attributeName] = transformAttribute(document, attributeName, value);
- break;
- }
- case 'childList': {
- addedNodes.forEach(function (n) { return genAdds(n, target); });
- removedNodes.forEach(function (n) {
- var nodeId = mirror.getId(n);
- var parentId = mirror.getId(target);
- if (isBlocked(n, blockClass)) {
- return;
- }
- if (addedSet.has(n)) {
- deepDelete(addedSet, n);
- droppedSet.add(n);
- }
- else if (addedSet.has(target) && nodeId === -1) ;
- else if (isAncestorRemoved(target)) ;
- else if (movedSet.has(n) && movedMap[moveKey(nodeId, parentId)]) {
- deepDelete(movedSet, n);
- }
- else {
- removes.push({
- parentId: parentId,
- id: nodeId
- });
- }
- mirror.removeNodeFromMap(n);
- });
- break;
- }
- default:
- break;
- }
- });
- var addQueue = [];
- var pushAdd = function (n) {
- var parentId = mirror.getId(n.parentNode);
- if (parentId === -1) {
- return addQueue.push(n);
- }
- adds.push({
- parentId: parentId,
- previousId: !n.previousSibling
- ? n.previousSibling
- : mirror.getId(n.previousSibling),
- nextId: !n.nextSibling
- ? n.nextSibling
- : mirror.getId(n.nextSibling),
- node: serializeNodeWithId(n, document, mirror.map, blockClass, true, inlineStylesheet, maskAllInputs)
- });
- };
- try {
- for (var movedSet_1 = __values(movedSet), movedSet_1_1 = movedSet_1.next(); !movedSet_1_1.done; movedSet_1_1 = movedSet_1.next()) {
- var n = movedSet_1_1.value;
- pushAdd(n);
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (movedSet_1_1 && !movedSet_1_1.done && (_a = movedSet_1["return"])) _a.call(movedSet_1);
- }
- finally { if (e_1) throw e_1.error; }
- }
- try {
- for (var addedSet_1 = __values(addedSet), addedSet_1_1 = addedSet_1.next(); !addedSet_1_1.done; addedSet_1_1 = addedSet_1.next()) {
- var n = addedSet_1_1.value;
- if (!isAncestorInSet(droppedSet, n) && !isParentRemoved(removes, n)) {
- pushAdd(n);
- }
- else if (isAncestorInSet(movedSet, n)) {
- pushAdd(n);
- }
- else {
- droppedSet.add(n);
- }
- }
- }
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
- finally {
- try {
- if (addedSet_1_1 && !addedSet_1_1.done && (_b = addedSet_1["return"])) _b.call(addedSet_1);
- }
- finally { if (e_2) throw e_2.error; }
- }
- while (addQueue.length) {
- if (addQueue.every(function (n) { return mirror.getId(n.parentNode) === -1; })) {
- break;
- }
- pushAdd(addQueue.shift());
- }
- var payload = {
- texts: texts
- .map(function (text) { return ({
- id: mirror.getId(text.node),
- value: text.value
- }); })
- .filter(function (text) { return mirror.has(text.id); }),
- attributes: attributes
- .map(function (attribute) { return ({
- id: mirror.getId(attribute.node),
- attributes: attribute.attributes
- }); })
- .filter(function (attribute) { return mirror.has(attribute.id); }),
- removes: removes,
- adds: adds
- };
- if (!payload.texts.length &&
- !payload.attributes.length &&
- !payload.removes.length &&
- !payload.adds.length) {
- return;
- }
- cb(payload);
- });
- observer.observe(document, {
- attributes: true,
- attributeOldValue: true,
- characterData: true,
- characterDataOldValue: true,
- childList: true,
- subtree: true
- });
- return observer;
- }
- function initMoveObserver(cb, mousemoveWait) {
- var positions = [];
- var timeBaseline;
- var wrappedCb = throttle(function (isTouch) {
- var totalOffset = Date.now() - timeBaseline;
- cb(positions.map(function (p) {
- p.timeOffset -= totalOffset;
- return p;
- }), isTouch ? exports.IncrementalSource.TouchMove : exports.IncrementalSource.MouseMove);
- positions = [];
- timeBaseline = null;
- }, 500);
- var updatePosition = throttle(function (evt) {
- var target = evt.target;
- var _a = isTouchEvent(evt)
- ? evt.changedTouches[0]
- : evt, clientX = _a.clientX, clientY = _a.clientY;
- if (!timeBaseline) {
- timeBaseline = Date.now();
- }
- positions.push({
- x: clientX,
- y: clientY,
- id: mirror.getId(target),
- timeOffset: Date.now() - timeBaseline
- });
- wrappedCb(isTouchEvent(evt));
- }, mousemoveWait, {
- trailing: false
- });
- var handlers = [
- on('mousemove', updatePosition),
- on('touchmove', updatePosition),
- ];
- return function () {
- handlers.forEach(function (h) { return h(); });
- };
- }
- function initMouseInteractionObserver(cb, blockClass) {
- var handlers = [];
- var getHandler = function (eventKey) {
- return function (event) {
- if (isBlocked(event.target, blockClass)) {
- return;
- }
- var id = mirror.getId(event.target);
- var _a = isTouchEvent(event)
- ? event.changedTouches[0]
- : event, clientX = _a.clientX, clientY = _a.clientY;
- cb({
- type: exports.MouseInteractions[eventKey],
- id: id,
- x: clientX,
- y: clientY
- });
- };
- };
- Object.keys(exports.MouseInteractions)
- .filter(function (key) { return Number.isNaN(Number(key)) && !key.endsWith('_Departed'); })
- .forEach(function (eventKey) {
- var eventName = eventKey.toLowerCase();
- var handler = getHandler(eventKey);
- handlers.push(on(eventName, handler));
- });
- return function () {
- handlers.forEach(function (h) { return h(); });
- };
- }
- function initScrollObserver(cb, blockClass) {
- var updatePosition = throttle(function (evt) {
- if (!evt.target || isBlocked(evt.target, blockClass)) {
- return;
- }
- var id = mirror.getId(evt.target);
- if (evt.target === document) {
- var scrollEl = (document.scrollingElement || document.documentElement);
- cb({
- id: id,
- x: scrollEl.scrollLeft,
- y: scrollEl.scrollTop
- });
- }
- else {
- cb({
- id: id,
- x: evt.target.scrollLeft,
- y: evt.target.scrollTop
- });
- }
- }, 100);
- return on('scroll', updatePosition);
- }
- function initViewportResizeObserver(cb) {
- var updateDimension = throttle(function () {
- var height = getWindowHeight();
- var width = getWindowWidth();
- cb({
- width: Number(width),
- height: Number(height)
- });
- }, 200);
- return on('resize', updateDimension, window);
- }
- var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
- var MASK_TYPES = [
- 'color',
- 'date',
- 'datetime-local',
- 'email',
- 'month',
- 'number',
- 'range',
- 'search',
- 'tel',
- 'text',
- 'time',
- 'url',
- 'week',
- ];
- var lastInputValueMap = new WeakMap();
- function initInputObserver(cb, blockClass, ignoreClass, maskAllInputs) {
- function eventHandler(event) {
- var target = event.target;
- if (!target ||
- !target.tagName ||
- INPUT_TAGS.indexOf(target.tagName) < 0 ||
- isBlocked(target, blockClass)) {
- return;
- }
- var type = target.type;
- if (type === 'password' ||
- target.classList.contains(ignoreClass)) {
- return;
- }
- var text = target.value;
- var isChecked = false;
- var hasTextInput = MASK_TYPES.includes(type) || target.tagName === 'TEXTAREA';
- if (type === 'radio' || type === 'checkbox') {
- isChecked = target.checked;
- }
- else if (hasTextInput && maskAllInputs) {
- text = '*'.repeat(text.length);
- }
- cbWithDedup(target, { text: text, isChecked: isChecked });
- var name = target.name;
- if (type === 'radio' && name && isChecked) {
- document
- .querySelectorAll("input[type=\"radio\"][name=\"" + name + "\"]")
- .forEach(function (el) {
- if (el !== target) {
- cbWithDedup(el, {
- text: el.value,
- isChecked: !isChecked
- });
- }
- });
- }
- }
- function cbWithDedup(target, v) {
- var lastInputValue = lastInputValueMap.get(target);
- if (!lastInputValue ||
- lastInputValue.text !== v.text ||
- lastInputValue.isChecked !== v.isChecked) {
- lastInputValueMap.set(target, v);
- var id = mirror.getId(target);
- cb(__assign({}, v, { id: id }));
- }
- }
- var handlers = [
- 'input',
- 'change',
- ].map(function (eventName) { return on(eventName, eventHandler); });
- var propertyDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
- var hookProperties = [
- [HTMLInputElement.prototype, 'value'],
- [HTMLInputElement.prototype, 'checked'],
- [HTMLSelectElement.prototype, 'value'],
- [HTMLTextAreaElement.prototype, 'value'],
- ];
- if (propertyDescriptor && propertyDescriptor.set) {
- handlers.push.apply(handlers, __spread(hookProperties.map(function (p) {
- return hookSetter(p[0], p[1], {
- set: function () {
- eventHandler({ target: this });
- }
- });
- })));
- }
- return function () {
- handlers.forEach(function (h) { return h(); });
- };
- }
- function mergeHooks(o, hooks) {
- var mutationCb = o.mutationCb, mousemoveCb = o.mousemoveCb, mouseInteractionCb = o.mouseInteractionCb, scrollCb = o.scrollCb, viewportResizeCb = o.viewportResizeCb, inputCb = o.inputCb;
- o.mutationCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.mutation) {
- hooks.mutation.apply(hooks, __spread(p));
- }
- mutationCb.apply(void 0, __spread(p));
- };
- o.mousemoveCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.mousemove) {
- hooks.mousemove.apply(hooks, __spread(p));
- }
- mousemoveCb.apply(void 0, __spread(p));
- };
- o.mouseInteractionCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.mouseInteraction) {
- hooks.mouseInteraction.apply(hooks, __spread(p));
- }
- mouseInteractionCb.apply(void 0, __spread(p));
- };
- o.scrollCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.scroll) {
- hooks.scroll.apply(hooks, __spread(p));
- }
- scrollCb.apply(void 0, __spread(p));
- };
- o.viewportResizeCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.viewportResize) {
- hooks.viewportResize.apply(hooks, __spread(p));
- }
- viewportResizeCb.apply(void 0, __spread(p));
- };
- o.inputCb = function () {
- var p = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- p[_i] = arguments[_i];
- }
- if (hooks.input) {
- hooks.input.apply(hooks, __spread(p));
- }
- inputCb.apply(void 0, __spread(p));
- };
- }
- function initObservers(o, hooks) {
- if (hooks === void 0) { hooks = {}; }
- mergeHooks(o, hooks);
- var mutationObserver = initMutationObserver(o.mutationCb, o.blockClass, o.inlineStylesheet, o.maskAllInputs);
- var mousemoveHandler = initMoveObserver(o.mousemoveCb, o.mousemoveWait);
- var mouseInteractionHandler = initMouseInteractionObserver(o.mouseInteractionCb, o.blockClass);
- var scrollHandler = initScrollObserver(o.scrollCb, o.blockClass);
- var viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb);
- var inputHandler = initInputObserver(o.inputCb, o.blockClass, o.ignoreClass, o.maskAllInputs);
- return function () {
- mutationObserver.disconnect();
- mousemoveHandler();
- mouseInteractionHandler();
- scrollHandler();
- viewportResizeHandler();
- inputHandler();
- };
- }
- function wrapEvent(e) {
- return __assign({}, e, { timestamp: Date.now() });
- }
- var wrappedEmit;
- function record(options) {
- if (options === void 0) { options = {}; }
- 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;
- if (!emit) {
- throw new Error('emit function is required');
- }
- polyfill();
- var lastFullSnapshotEvent;
- var incrementalSnapshotCount = 0;
- wrappedEmit = function (e, isCheckout) {
- emit(e, isCheckout);
- if (e.type === exports.EventType.FullSnapshot) {
- lastFullSnapshotEvent = e;
- incrementalSnapshotCount = 0;
- }
- else if (e.type === exports.EventType.IncrementalSnapshot) {
- incrementalSnapshotCount++;
- var exceedCount = checkoutEveryNth && incrementalSnapshotCount >= checkoutEveryNth;
- var exceedTime = checkoutEveryNms &&
- e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
- if (exceedCount || exceedTime) {
- takeFullSnapshot(true);
- }
- }
- };
- function takeFullSnapshot(isCheckout) {
- if (isCheckout === void 0) { isCheckout = false; }
- wrappedEmit(wrapEvent({
- type: exports.EventType.Meta,
- data: {
- href: window.location.href,
- width: getWindowWidth(),
- height: getWindowHeight()
- }
- }), isCheckout);
- var _a = __read(snapshot(document, blockClass, inlineStylesheet, maskAllInputs), 2), node = _a[0], idNodeMap = _a[1];
- if (!node) {
- return console.warn('Failed to snapshot the document');
- }
- mirror.map = idNodeMap;
- wrappedEmit(wrapEvent({
- type: exports.EventType.FullSnapshot,
- data: {
- node: node,
- initialOffset: {
- left: document.documentElement.scrollLeft,
- top: document.documentElement.scrollTop
- }
- }
- }));
- }
- try {
- var handlers_1 = [];
- handlers_1.push(on('DOMContentLoaded', function () {
- wrappedEmit(wrapEvent({
- type: exports.EventType.DomContentLoaded,
- data: {}
- }));
- }));
- var init_1 = function () {
- takeFullSnapshot();
- handlers_1.push(initObservers({
- mutationCb: function (m) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: __assign({ source: exports.IncrementalSource.Mutation }, m)
- }));
- },
- mousemoveCb: function (positions, source) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: {
- source: source,
- positions: positions
- }
- }));
- },
- mouseInteractionCb: function (d) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: __assign({ source: exports.IncrementalSource.MouseInteraction }, d)
- }));
- },
- scrollCb: function (p) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: __assign({ source: exports.IncrementalSource.Scroll }, p)
- }));
- },
- viewportResizeCb: function (d) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: __assign({ source: exports.IncrementalSource.ViewportResize }, d)
- }));
- },
- inputCb: function (v) {
- return wrappedEmit(wrapEvent({
- type: exports.EventType.IncrementalSnapshot,
- data: __assign({ source: exports.IncrementalSource.Input }, v)
- }));
- },
- blockClass: blockClass,
- ignoreClass: ignoreClass,
- maskAllInputs: maskAllInputs,
- inlineStylesheet: inlineStylesheet,
- mousemoveWait: mousemoveWait
- }, hooks));
- };
- if (document.readyState === 'interactive' ||
- document.readyState === 'complete') {
- init_1();
- }
- else {
- handlers_1.push(on('load', function () {
- wrappedEmit(wrapEvent({
- type: exports.EventType.Load,
- data: {}
- }));
- init_1();
- }, window));
- }
- return function () {
- handlers_1.forEach(function (h) { return h(); });
- };
- }
- catch (error) {
- console.warn(error);
- }
- }
- record.addCustomEvent = function (tag, payload) {
- if (!wrappedEmit) {
- throw new Error('please add custom event after start recording');
- }
- wrappedEmit(wrapEvent({
- type: exports.EventType.Custom,
- data: {
- tag: tag,
- payload: payload
- }
- }));
- };
- //
- // An event handler can take an optional event argument
- // and should not return a value
-
-
- // An array of all currently registered event handlers for a type
-
-
- // A map of event types and their corresponding event handlers.
-
-
-
-
- /** Mitt: Tiny (~200b) functional event emitter / pubsub.
- * @name mitt
- * @returns {Mitt}
- */
- function mitt(all ) {
- all = all || Object.create(null);
- return {
- /**
- * Register an event handler for the given type.
- *
- * @param {String} type Type of event to listen for, or `"*"` for all events
- * @param {Function} handler Function to call in response to given event
- * @memberOf mitt
- */
- on: function on(type , handler ) {
- (all[type] || (all[type] = [])).push(handler);
- },
- /**
- * Remove an event handler for the given type.
- *
- * @param {String} type Type of event to unregister `handler` from, or `"*"`
- * @param {Function} handler Handler function to remove
- * @memberOf mitt
- */
- off: function off(type , handler ) {
- if (all[type]) {
- all[type].splice(all[type].indexOf(handler) >>> 0, 1);
- }
- },
- /**
- * Invoke all handlers for the given type.
- * If present, `"*"` handlers are invoked after type-matched handlers.
- *
- * @param {String} type The event type to invoke
- * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
- * @memberOf mitt
- */
- emit: function emit(type , evt ) {
- (all[type] || []).slice().map(function (handler) { handler(evt); });
- (all['*'] || []).slice().map(function (handler) { handler(type, evt); });
- }
- };
- }
- var mittProxy = /*#__PURE__*/Object.freeze({
- default: mitt
- });
- function createCommonjsModule(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var smoothscroll = createCommonjsModule(function (module, exports) {
- /* smoothscroll v0.4.4 - 2019 - Dustan Kasten, Jeremias Menichelli - MIT License */
- (function () {
- // polyfill
- function polyfill() {
- // aliases
- var w = window;
- var d = document;
- // return if scroll behavior is supported and polyfill is not forced
- if (
- 'scrollBehavior' in d.documentElement.style &&
- w.__forceSmoothScrollPolyfill__ !== true
- ) {
- return;
- }
- // globals
- var Element = w.HTMLElement || w.Element;
- var SCROLL_TIME = 468;
- // object gathering original scroll methods
- var original = {
- scroll: w.scroll || w.scrollTo,
- scrollBy: w.scrollBy,
- elementScroll: Element.prototype.scroll || scrollElement,
- scrollIntoView: Element.prototype.scrollIntoView
- };
- // define timing method
- var now =
- w.performance && w.performance.now
- ? w.performance.now.bind(w.performance)
- : Date.now;
- /**
- * indicates if a the current browser is made by Microsoft
- * @method isMicrosoftBrowser
- * @param {String} userAgent
- * @returns {Boolean}
- */
- function isMicrosoftBrowser(userAgent) {
- var userAgentPatterns = ['MSIE ', 'Trident/', 'Edge/'];
- return new RegExp(userAgentPatterns.join('|')).test(userAgent);
- }
- /*
- * IE has rounding bug rounding down clientHeight and clientWidth and
- * rounding up scrollHeight and scrollWidth causing false positives
- * on hasScrollableSpace
- */
- var ROUNDING_TOLERANCE = isMicrosoftBrowser(w.navigator.userAgent) ? 1 : 0;
- /**
- * changes scroll position inside an element
- * @method scrollElement
- * @param {Number} x
- * @param {Number} y
- * @returns {undefined}
- */
- function scrollElement(x, y) {
- this.scrollLeft = x;
- this.scrollTop = y;
- }
- /**
- * returns result of applying ease math function to a number
- * @method ease
- * @param {Number} k
- * @returns {Number}
- */
- function ease(k) {
- return 0.5 * (1 - Math.cos(Math.PI * k));
- }
- /**
- * indicates if a smooth behavior should be applied
- * @method shouldBailOut
- * @param {Number|Object} firstArg
- * @returns {Boolean}
- */
- function shouldBailOut(firstArg) {
- if (
- firstArg === null ||
- typeof firstArg !== 'object' ||
- firstArg.behavior === undefined ||
- firstArg.behavior === 'auto' ||
- firstArg.behavior === 'instant'
- ) {
- // first argument is not an object/null
- // or behavior is auto, instant or undefined
- return true;
- }
- if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {
- // first argument is an object and behavior is smooth
- return false;
- }
- // throw error when behavior is not supported
- throw new TypeError(
- 'behavior member of ScrollOptions ' +
- firstArg.behavior +
- ' is not a valid value for enumeration ScrollBehavior.'
- );
- }
- /**
- * indicates if an element has scrollable space in the provided axis
- * @method hasScrollableSpace
- * @param {Node} el
- * @param {String} axis
- * @returns {Boolean}
- */
- function hasScrollableSpace(el, axis) {
- if (axis === 'Y') {
- return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;
- }
- if (axis === 'X') {
- return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;
- }
- }
- /**
- * indicates if an element has a scrollable overflow property in the axis
- * @method canOverflow
- * @param {Node} el
- * @param {String} axis
- * @returns {Boolean}
- */
- function canOverflow(el, axis) {
- var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];
- return overflowValue === 'auto' || overflowValue === 'scroll';
- }
- /**
- * indicates if an element can be scrolled in either axis
- * @method isScrollable
- * @param {Node} el
- * @param {String} axis
- * @returns {Boolean}
- */
- function isScrollable(el) {
- var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');
- var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
- return isScrollableY || isScrollableX;
- }
- /**
- * finds scrollable parent of an element
- * @method findScrollableParent
- * @param {Node} el
- * @returns {Node} el
- */
- function findScrollableParent(el) {
- while (el !== d.body && isScrollable(el) === false) {
- el = el.parentNode || el.host;
- }
- return el;
- }
- /**
- * self invoked function that, given a context, steps through scrolling
- * @method step
- * @param {Object} context
- * @returns {undefined}
- */
- function step(context) {
- var time = now();
- var value;
- var currentX;
- var currentY;
- var elapsed = (time - context.startTime) / SCROLL_TIME;
- // avoid elapsed times higher than one
- elapsed = elapsed > 1 ? 1 : elapsed;
- // apply easing to elapsed time
- value = ease(elapsed);
- currentX = context.startX + (context.x - context.startX) * value;
- currentY = context.startY + (context.y - context.startY) * value;
- context.method.call(context.scrollable, currentX, currentY);
- // scroll more if we have not reached our destination
- if (currentX !== context.x || currentY !== context.y) {
- w.requestAnimationFrame(step.bind(w, context));
- }
- }
- /**
- * scrolls window or element with a smooth behavior
- * @method smoothScroll
- * @param {Object|Node} el
- * @param {Number} x
- * @param {Number} y
- * @returns {undefined}
- */
- function smoothScroll(el, x, y) {
- var scrollable;
- var startX;
- var startY;
- var method;
- var startTime = now();
- // define scroll context
- if (el === d.body) {
- scrollable = w;
- startX = w.scrollX || w.pageXOffset;
- startY = w.scrollY || w.pageYOffset;
- method = original.scroll;
- } else {
- scrollable = el;
- startX = el.scrollLeft;
- startY = el.scrollTop;
- method = scrollElement;
- }
- // scroll looping over a frame
- step({
- scrollable: scrollable,
- method: method,
- startTime: startTime,
- startX: startX,
- startY: startY,
- x: x,
- y: y
- });
- }
- // ORIGINAL METHODS OVERRIDES
- // w.scroll and w.scrollTo
- w.scroll = w.scrollTo = function() {
- // avoid action when no arguments are passed
- if (arguments[0] === undefined) {
- return;
- }
- // avoid smooth behavior if not required
- if (shouldBailOut(arguments[0]) === true) {
- original.scroll.call(
- w,
- arguments[0].left !== undefined
- ? arguments[0].left
- : typeof arguments[0] !== 'object'
- ? arguments[0]
- : w.scrollX || w.pageXOffset,
- // use top prop, second argument if present or fallback to scrollY
- arguments[0].top !== undefined
- ? arguments[0].top
- : arguments[1] !== undefined
- ? arguments[1]
- : w.scrollY || w.pageYOffset
- );
- return;
- }
- // LET THE SMOOTHNESS BEGIN!
- smoothScroll.call(
- w,
- d.body,
- arguments[0].left !== undefined
- ? ~~arguments[0].left
- : w.scrollX || w.pageXOffset,
- arguments[0].top !== undefined
- ? ~~arguments[0].top
- : w.scrollY || w.pageYOffset
- );
- };
- // w.scrollBy
- w.scrollBy = function() {
- // avoid action when no arguments are passed
- if (arguments[0] === undefined) {
- return;
- }
- // avoid smooth behavior if not required
- if (shouldBailOut(arguments[0])) {
- original.scrollBy.call(
- w,
- arguments[0].left !== undefined
- ? arguments[0].left
- : typeof arguments[0] !== 'object' ? arguments[0] : 0,
- arguments[0].top !== undefined
- ? arguments[0].top
- : arguments[1] !== undefined ? arguments[1] : 0
- );
- return;
- }
- // LET THE SMOOTHNESS BEGIN!
- smoothScroll.call(
- w,
- d.body,
- ~~arguments[0].left + (w.scrollX || w.pageXOffset),
- ~~arguments[0].top + (w.scrollY || w.pageYOffset)
- );
- };
- // Element.prototype.scroll and Element.prototype.scrollTo
- Element.prototype.scroll = Element.prototype.scrollTo = function() {
- // avoid action when no arguments are passed
- if (arguments[0] === undefined) {
- return;
- }
- // avoid smooth behavior if not required
- if (shouldBailOut(arguments[0]) === true) {
- // if one number is passed, throw error to match Firefox implementation
- if (typeof arguments[0] === 'number' && arguments[1] === undefined) {
- throw new SyntaxError('Value could not be converted');
- }
- original.elementScroll.call(
- this,
- // use left prop, first number argument or fallback to scrollLeft
- arguments[0].left !== undefined
- ? ~~arguments[0].left
- : typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft,
- // use top prop, second argument or fallback to scrollTop
- arguments[0].top !== undefined
- ? ~~arguments[0].top
- : arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop
- );
- return;
- }
- var left = arguments[0].left;
- var top = arguments[0].top;
- // LET THE SMOOTHNESS BEGIN!
- smoothScroll.call(
- this,
- this,
- typeof left === 'undefined' ? this.scrollLeft : ~~left,
- typeof top === 'undefined' ? this.scrollTop : ~~top
- );
- };
- // Element.prototype.scrollBy
- Element.prototype.scrollBy = function() {
- // avoid action when no arguments are passed
- if (arguments[0] === undefined) {
- return;
- }
- // avoid smooth behavior if not required
- if (shouldBailOut(arguments[0]) === true) {
- original.elementScroll.call(
- this,
- arguments[0].left !== undefined
- ? ~~arguments[0].left + this.scrollLeft
- : ~~arguments[0] + this.scrollLeft,
- arguments[0].top !== undefined
- ? ~~arguments[0].top + this.scrollTop
- : ~~arguments[1] + this.scrollTop
- );
- return;
- }
- this.scroll({
- left: ~~arguments[0].left + this.scrollLeft,
- top: ~~arguments[0].top + this.scrollTop,
- behavior: arguments[0].behavior
- });
- };
- // Element.prototype.scrollIntoView
- Element.prototype.scrollIntoView = function() {
- // avoid smooth behavior if not required
- if (shouldBailOut(arguments[0]) === true) {
- original.scrollIntoView.call(
- this,
- arguments[0] === undefined ? true : arguments[0]
- );
- return;
- }
- // LET THE SMOOTHNESS BEGIN!
- var scrollableParent = findScrollableParent(this);
- var parentRects = scrollableParent.getBoundingClientRect();
- var clientRects = this.getBoundingClientRect();
- if (scrollableParent !== d.body) {
- // reveal element inside parent
- smoothScroll.call(
- this,
- scrollableParent,
- scrollableParent.scrollLeft + clientRects.left - parentRects.left,
- scrollableParent.scrollTop + clientRects.top - parentRects.top
- );
- // reveal parent in viewport unless is fixed
- if (w.getComputedStyle(scrollableParent).position !== 'fixed') {
- w.scrollBy({
- left: parentRects.left,
- top: parentRects.top,
- behavior: 'smooth'
- });
- }
- } else {
- // reveal element in viewport
- w.scrollBy({
- left: clientRects.left,
- top: clientRects.top,
- behavior: 'smooth'
- });
- }
- };
- }
- {
- // commonjs
- module.exports = { polyfill: polyfill };
- }
- }());
- });
- var smoothscroll_1 = smoothscroll.polyfill;
- var Timer = (function () {
- function Timer(config, actions) {
- if (actions === void 0) { actions = []; }
- this.timeOffset = 0;
- this.actions = actions;
- this.config = config;
- }
- Timer.prototype.addAction = function (action) {
- var index = this.findActionIndex(action);
- this.actions.splice(index, 0, action);
- };
- Timer.prototype.addActions = function (actions) {
- var _a;
- (_a = this.actions).push.apply(_a, __spread(actions));
- };
- Timer.prototype.start = function () {
- this.actions.sort(function (a1, a2) { return a1.delay - a2.delay; });
- this.timeOffset = 0;
- var lastTimestamp = performance.now();
- var _a = this, actions = _a.actions, config = _a.config;
- var self = this;
- function check(time) {
- self.timeOffset += (time - lastTimestamp) * config.speed;
- lastTimestamp = time;
- while (actions.length) {
- var action = actions[0];
- if (self.timeOffset >= action.delay) {
- actions.shift();
- action.doAction();
- }
- else {
- break;
- }
- }
- if (actions.length > 0 || self.config.liveMode) {
- self.raf = requestAnimationFrame(check);
- }
- }
- this.raf = requestAnimationFrame(check);
- };
- Timer.prototype.clear = function () {
- if (this.raf) {
- cancelAnimationFrame(this.raf);
- }
- this.actions.length = 0;
- };
- Timer.prototype.findActionIndex = function (action) {
- var start = 0;
- var end = this.actions.length - 1;
- while (start <= end) {
- var mid = Math.floor((start + end) / 2);
- if (this.actions[mid].delay < action.delay) {
- start = mid + 1;
- }
- else if (this.actions[mid].delay > action.delay) {
- end = mid - 1;
- }
- else {
- return mid;
- }
- }
- return start;
- };
- return Timer;
- }());
- var rules = function (blockClass) { return [
- "iframe, ." + blockClass + " { background: #ccc }",
- 'noscript { display: none !important; }',
- ]; };
- var SKIP_TIME_THRESHOLD = 10 * 1000;
- var SKIP_TIME_INTERVAL = 5 * 1000;
- var mitt$1 = mitt || mittProxy;
- var REPLAY_CONSOLE_PREFIX = '[replayer]';
- var Replayer = (function () {
- function Replayer(events, config) {
- this.events = [];
- this.emitter = mitt$1();
- this.baselineTime = 0;
- this.noramlSpeed = -1;
- this.missingNodeRetryMap = {};
- if (events.length < 2) {
- throw new Error('Replayer need at least 2 events.');
- }
- this.events = events;
- this.handleResize = this.handleResize.bind(this);
- var defaultConfig = {
- speed: 1,
- root: document.body,
- loadTimeout: 0,
- skipInactive: false,
- showWarning: true,
- showDebug: false,
- blockClass: 'rr-block',
- liveMode: false,
- insertStyleRules: []
- };
- this.config = Object.assign({}, defaultConfig, config);
- this.timer = new Timer(this.config);
- smoothscroll_1();
- polyfill();
- this.setupDom();
- this.emitter.on('resize', this.handleResize);
- }
- Replayer.prototype.on = function (event, handler) {
- this.emitter.on(event, handler);
- };
- Replayer.prototype.setConfig = function (config) {
- var _this = this;
- Object.keys(config).forEach(function (key) {
- _this.config[key] = config[key];
- });
- if (!this.config.skipInactive) {
- this.noramlSpeed = -1;
- }
- };
- Replayer.prototype.getMetaData = function () {
- var firstEvent = this.events[0];
- var lastEvent = this.events[this.events.length - 1];
- return {
- totalTime: lastEvent.timestamp - firstEvent.timestamp
- };
- };
- Replayer.prototype.getCurrentTime = function () {
- return this.timer.timeOffset + this.getTimeOffset();
- };
- Replayer.prototype.getTimeOffset = function () {
- return this.baselineTime - this.events[0].timestamp;
- };
- Replayer.prototype.play = function (timeOffset) {
- var e_1, _a;
- if (timeOffset === void 0) { timeOffset = 0; }
- this.timer.clear();
- this.baselineTime = this.events[0].timestamp + timeOffset;
- var actions = new Array();
- try {
- for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
- var event = _c.value;
- var isSync = event.timestamp < this.baselineTime;
- var castFn = this.getCastFn(event, isSync);
- if (isSync) {
- castFn();
- }
- else {
- actions.push({ doAction: castFn, delay: this.getDelay(event) });
- }
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
- }
- finally { if (e_1) throw e_1.error; }
- }
- this.timer.addActions(actions);
- this.timer.start();
- this.emitter.emit(exports.ReplayerEvents.Start);
- };
- Replayer.prototype.pause = function () {
- this.timer.clear();
- this.emitter.emit(exports.ReplayerEvents.Pause);
- };
- Replayer.prototype.resume = function (timeOffset) {
- var e_2, _a;
- if (timeOffset === void 0) { timeOffset = 0; }
- this.timer.clear();
- this.baselineTime = this.events[0].timestamp + timeOffset;
- var actions = new Array();
- try {
- for (var _b = __values(this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
- var event = _c.value;
- if (event.timestamp <= this.lastPlayedEvent.timestamp ||
- event === this.lastPlayedEvent) {
- continue;
- }
- var castFn = this.getCastFn(event);
- actions.push({
- doAction: castFn,
- delay: this.getDelay(event)
- });
- }
- }
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
- finally {
- try {
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
- }
- finally { if (e_2) throw e_2.error; }
- }
- this.timer.addActions(actions);
- this.timer.start();
- this.emitter.emit(exports.ReplayerEvents.Resume);
- };
- Replayer.prototype.addEvent = function (event) {
- var castFn = this.getCastFn(event, true);
- castFn();
- };
- Replayer.prototype.setupDom = function () {
- this.wrapper = document.createElement('div');
- this.wrapper.classList.add('replayer-wrapper');
- this.config.root.appendChild(this.wrapper);
- this.mouse = document.createElement('div');
- this.mouse.classList.add('replayer-mouse');
- this.wrapper.appendChild(this.mouse);
- this.iframe = document.createElement('iframe');
- this.iframe.setAttribute('sandbox', 'allow-same-origin');
- this.iframe.setAttribute('scrolling', 'no');
- this.iframe.setAttribute('style', 'pointer-events: none');
- this.wrapper.appendChild(this.iframe);
- };
- Replayer.prototype.handleResize = function (dimension) {
- this.iframe.width = dimension.width + "px";
- this.iframe.height = dimension.height + "px";
- };
- Replayer.prototype.getDelay = function (event) {
- if (event.type === exports.EventType.IncrementalSnapshot &&
- event.data.source === exports.IncrementalSource.MouseMove) {
- var firstOffset = event.data.positions[0].timeOffset;
- var firstTimestamp = event.timestamp + firstOffset;
- event.delay = firstTimestamp - this.baselineTime;
- return firstTimestamp - this.baselineTime;
- }
- event.delay = event.timestamp - this.baselineTime;
- return event.timestamp - this.baselineTime;
- };
- Replayer.prototype.getCastFn = function (event, isSync) {
- var _this = this;
- if (isSync === void 0) { isSync = false; }
- var castFn;
- switch (event.type) {
- case exports.EventType.DomContentLoaded:
- case exports.EventType.Load:
- break;
- case exports.EventType.Meta:
- castFn = function () {
- return _this.emitter.emit(exports.ReplayerEvents.Resize, {
- width: event.data.width,
- height: event.data.height
- });
- };
- break;
- case exports.EventType.FullSnapshot:
- castFn = function () {
- _this.rebuildFullSnapshot(event);
- _this.iframe.contentWindow.scrollTo(event.data.initialOffset);
- };
- break;
- case exports.EventType.IncrementalSnapshot:
- castFn = function () {
- var e_3, _a;
- _this.applyIncremental(event, isSync);
- if (event === _this.nextUserInteractionEvent) {
- _this.nextUserInteractionEvent = null;
- _this.restoreSpeed();
- }
- if (_this.config.skipInactive && !_this.nextUserInteractionEvent) {
- try {
- for (var _b = __values(_this.events), _c = _b.next(); !_c.done; _c = _b.next()) {
- var _event = _c.value;
- if (_event.timestamp <= event.timestamp) {
- continue;
- }
- if (_this.isUserInteraction(_event)) {
- if (_event.delay - event.delay >
- SKIP_TIME_THRESHOLD * _this.config.speed) {
- _this.nextUserInteractionEvent = _event;
- }
- break;
- }
- }
- }
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
- finally {
- try {
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
- }
- finally { if (e_3) throw e_3.error; }
- }
- if (_this.nextUserInteractionEvent) {
- _this.noramlSpeed = _this.config.speed;
- var skipTime = _this.nextUserInteractionEvent.delay - event.delay;
- var payload = {
- speed: Math.min(Math.round(skipTime / SKIP_TIME_INTERVAL), 360)
- };
- _this.setConfig(payload);
- _this.emitter.emit(exports.ReplayerEvents.SkipStart, payload);
- }
- }
- };
- break;
- default:
- }
- var wrappedCastFn = function () {
- if (castFn) {
- castFn();
- }
- _this.lastPlayedEvent = event;
- if (event === _this.events[_this.events.length - 1]) {
- _this.restoreSpeed();
- _this.emitter.emit(exports.ReplayerEvents.Finish);
- }
- };
- return wrappedCastFn;
- };
- Replayer.prototype.rebuildFullSnapshot = function (event) {
- if (Object.keys(this.missingNodeRetryMap).length) {
- console.warn('Found unresolved missing node map', this.missingNodeRetryMap);
- }
- this.missingNodeRetryMap = {};
- mirror.map = rebuild(event.data.node, this.iframe.contentDocument)[1];
- var styleEl = document.createElement('style');
- var _a = this.iframe.contentDocument, documentElement = _a.documentElement, head = _a.head;
- documentElement.insertBefore(styleEl, head);
- var injectStylesRules = rules(this.config.blockClass).concat(this.config.insertStyleRules);
- for (var idx = 0; idx < injectStylesRules.length; idx++) {
- styleEl.sheet.insertRule(injectStylesRules[idx], idx);
- }
- this.emitter.emit(exports.ReplayerEvents.FullsnapshotRebuilded);
- this.waitForStylesheetLoad();
- };
- Replayer.prototype.waitForStylesheetLoad = function () {
- var _this = this;
- var head = this.iframe.contentDocument.head;
- if (head) {
- var unloadSheets_1 = new Set();
- var timer_1;
- head
- .querySelectorAll('link[rel="stylesheet"]')
- .forEach(function (css) {
- if (!css.sheet) {
- if (unloadSheets_1.size === 0) {
- _this.pause();
- _this.emitter.emit(exports.ReplayerEvents.LoadStylesheetStart);
- timer_1 = window.setTimeout(function () {
- _this.resume(_this.getCurrentTime());
- timer_1 = -1;
- }, _this.config.loadTimeout);
- }
- unloadSheets_1.add(css);
- css.addEventListener('load', function () {
- unloadSheets_1["delete"](css);
- if (unloadSheets_1.size === 0 && timer_1 !== -1) {
- _this.resume(_this.getCurrentTime());
- _this.emitter.emit(exports.ReplayerEvents.LoadStylesheetEnd);
- if (timer_1) {
- window.clearTimeout(timer_1);
- }
- }
- });
- }
- });
- }
- };
- Replayer.prototype.applyIncremental = function (e, isSync) {
- var _this = this;
- var d = e.data;
- switch (d.source) {
- case exports.IncrementalSource.Mutation: {
- d.removes.forEach(function (mutation) {
- var target = mirror.getNode(mutation.id);
- if (!target) {
- return _this.warnNodeNotFound(d, mutation.id);
- }
- var parent = mirror.getNode(mutation.parentId);
- if (!parent) {
- return _this.warnNodeNotFound(d, mutation.parentId);
- }
- mirror.removeNodeFromMap(target);
- if (parent) {
- parent.removeChild(target);
- }
- });
- var missingNodeMap_1 = __assign({}, this.missingNodeRetryMap);
- var queue_1 = [];
- var appendNode_1 = function (mutation) {
- var parent = mirror.getNode(mutation.parentId);
- if (!parent) {
- return queue_1.push(mutation);
- }
- var target = buildNodeWithSN(mutation.node, _this.iframe.contentDocument, mirror.map, true);
- var previous = null;
- var next = null;
- if (mutation.previousId) {
- previous = mirror.getNode(mutation.previousId);
- }
- if (mutation.nextId) {
- next = mirror.getNode(mutation.nextId);
- }
- if (mutation.previousId === -1 || mutation.nextId === -1) {
- missingNodeMap_1[mutation.node.id] = {
- node: target,
- mutation: mutation
- };
- return;
- }
- if (previous &&
- previous.nextSibling &&
- previous.nextSibling.parentNode) {
- parent.insertBefore(target, previous.nextSibling);
- }
- else if (next && next.parentNode) {
- parent.insertBefore(target, next);
- }
- else {
- parent.appendChild(target);
- }
- if (mutation.previousId || mutation.nextId) {
- _this.resolveMissingNode(missingNodeMap_1, parent, target, mutation);
- }
- };
- d.adds.forEach(function (mutation) {
- appendNode_1(mutation);
- });
- while (queue_1.length) {
- if (queue_1.every(function (m) { return !Boolean(mirror.getNode(m.parentId)); })) {
- return queue_1.forEach(function (m) { return _this.warnNodeNotFound(d, m.node.id); });
- }
- var mutation = queue_1.shift();
- appendNode_1(mutation);
- }
- if (Object.keys(missingNodeMap_1).length) {
- Object.assign(this.missingNodeRetryMap, missingNodeMap_1);
- }
- d.texts.forEach(function (mutation) {
- var target = mirror.getNode(mutation.id);
- if (!target) {
- return _this.warnNodeNotFound(d, mutation.id);
- }
- target.textContent = mutation.value;
- });
- d.attributes.forEach(function (mutation) {
- var target = mirror.getNode(mutation.id);
- if (!target) {
- return _this.warnNodeNotFound(d, mutation.id);
- }
- for (var attributeName in mutation.attributes) {
- if (typeof attributeName === 'string') {
- var value = mutation.attributes[attributeName];
- if (value !== null) {
- target.setAttribute(attributeName, value);
- }
- else {
- target.removeAttribute(attributeName);
- }
- }
- }
- });
- break;
- }
- case exports.IncrementalSource.MouseMove:
- if (isSync) {
- var lastPosition = d.positions[d.positions.length - 1];
- this.moveAndHover(d, lastPosition.x, lastPosition.y, lastPosition.id);
- }
- else {
- d.positions.forEach(function (p) {
- var action = {
- doAction: function () {
- _this.moveAndHover(d, p.x, p.y, p.id);
- },
- delay: p.timeOffset + e.timestamp - _this.baselineTime
- };
- _this.timer.addAction(action);
- });
- }
- break;
- case exports.IncrementalSource.MouseInteraction: {
- if (d.id === -1) {
- break;
- }
- var event = new Event(exports.MouseInteractions[d.type].toLowerCase());
- var target = mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
- }
- this.emitter.emit(exports.ReplayerEvents.MouseInteraction, {
- type: d.type,
- target: target
- });
- switch (d.type) {
- case exports.MouseInteractions.Blur:
- if (target.blur) {
- target.blur();
- }
- break;
- case exports.MouseInteractions.Focus:
- if (target.focus) {
- target.focus({
- preventScroll: true
- });
- }
- break;
- case exports.MouseInteractions.Click:
- case exports.MouseInteractions.TouchStart:
- case exports.MouseInteractions.TouchEnd:
- if (!isSync) {
- this.moveAndHover(d, d.x, d.y, d.id);
- this.mouse.classList.remove('active');
- void this.mouse.offsetWidth;
- this.mouse.classList.add('active');
- }
- break;
- default:
- target.dispatchEvent(event);
- }
- break;
- }
- case exports.IncrementalSource.Scroll: {
- if (d.id === -1) {
- break;
- }
- var target = mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
- }
- if (target === this.iframe.contentDocument) {
- this.iframe.contentWindow.scrollTo({
- top: d.y,
- left: d.x,
- behavior: isSync ? 'auto' : 'smooth'
- });
- }
- else {
- try {
- target.scrollTop = d.y;
- target.scrollLeft = d.x;
- }
- catch (error) {
- }
- }
- break;
- }
- case exports.IncrementalSource.ViewportResize:
- this.emitter.emit(exports.ReplayerEvents.Resize, {
- width: d.width,
- height: d.height
- });
- break;
- case exports.IncrementalSource.Input: {
- if (d.id === -1) {
- break;
- }
- var target = mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
- }
- try {
- target.checked = d.isChecked;
- target.value = d.text;
- }
- catch (error) {
- }
- break;
- }
- default:
- }
- };
- Replayer.prototype.resolveMissingNode = function (map, parent, target, targetMutation) {
- var previousId = targetMutation.previousId, nextId = targetMutation.nextId;
- var previousInMap = previousId && map[previousId];
- var nextInMap = nextId && map[nextId];
- if (previousInMap) {
- var _a = previousInMap, node = _a.node, mutation = _a.mutation;
- parent.insertBefore(node, target);
- delete map[mutation.node.id];
- delete this.missingNodeRetryMap[mutation.node.id];
- if (mutation.previousId || mutation.nextId) {
- this.resolveMissingNode(map, parent, node, mutation);
- }
- }
- if (nextInMap) {
- var _b = nextInMap, node = _b.node, mutation = _b.mutation;
- parent.insertBefore(node, target.nextSibling);
- delete map[mutation.node.id];
- delete this.missingNodeRetryMap[mutation.node.id];
- if (mutation.previousId || mutation.nextId) {
- this.resolveMissingNode(map, parent, node, mutation);
- }
- }
- };
- Replayer.prototype.moveAndHover = function (d, x, y, id) {
- this.mouse.style.left = x + "px";
- this.mouse.style.top = y + "px";
- var target = mirror.getNode(id);
- if (!target) {
- return this.debugNodeNotFound(d, id);
- }
- this.hoverElements(target);
- };
- Replayer.prototype.hoverElements = function (el) {
- this.iframe
- .contentDocument.querySelectorAll('.\\:hover')
- .forEach(function (hoveredEl) {
- hoveredEl.classList.remove(':hover');
- });
- var currentEl = el;
- while (currentEl) {
- currentEl.classList.add(':hover');
- currentEl = currentEl.parentElement;
- }
- };
- Replayer.prototype.isUserInteraction = function (event) {
- if (event.type !== exports.EventType.IncrementalSnapshot) {
- return false;
- }
- return (event.data.source > exports.IncrementalSource.Mutation &&
- event.data.source <= exports.IncrementalSource.Input);
- };
- Replayer.prototype.restoreSpeed = function () {
- if (this.noramlSpeed === -1) {
- return;
- }
- var payload = { speed: this.noramlSpeed };
- this.setConfig(payload);
- this.emitter.emit(exports.ReplayerEvents.SkipEnd, payload);
- this.noramlSpeed = -1;
- };
- Replayer.prototype.warnNodeNotFound = function (d, id) {
- if (!this.config.showWarning) {
- return;
- }
- console.warn(REPLAY_CONSOLE_PREFIX, "Node with id '" + id + "' not found in", d);
- };
- Replayer.prototype.debugNodeNotFound = function (d, id) {
- if (!this.config.showDebug) {
- return;
- }
- console.log(REPLAY_CONSOLE_PREFIX, "Node with id '" + id + "' not found in", d);
- };
- return Replayer;
- }());
- var addCustomEvent = record.addCustomEvent;
- exports.record = record;
- exports.addCustomEvent = addCustomEvent;
- exports.Replayer = Replayer;
- exports.mirror = mirror;
|