UNPKG

29.8 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "tslib", "./Reporter", "./html/icons"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 var tslib_1 = require("tslib");
13 var Reporter_1 = tslib_1.__importStar(require("./Reporter"));
14 var icons_1 = require("./html/icons");
15 var Html = (function (_super) {
16 tslib_1.__extends(Html, _super);
17 function Html(executor, options) {
18 if (options === void 0) { options = {}; }
19 var _this = _super.call(this, executor, options) || this;
20 _this._summaryNodes = [];
21 _this._suiteCount = 0;
22 _this._testCount = 0;
23 _this._testsInSuite = 0;
24 _this._testIndex = 0;
25 _this._processedTests = {};
26 _this._passedFilter = null;
27 _this._skippedFilter = null;
28 _this._indentLevel = 0;
29 _this._runningSuites = {};
30 _this.document = options.document || window.document;
31 _this.location = options.location || window.location;
32 _this._fragment = _this.document.createDocumentFragment();
33 return _this;
34 }
35 Html.prototype._generateSummary = function (suite) {
36 var document = this.document;
37 if (this._summaryNodes.length === 0) {
38 return;
39 }
40 var duration = suite.timeElapsed;
41 var numSkippedTests = suite.numTests - (suite.numFailedTests + suite.numPassedTests);
42 var percentPassed = Math.round((1 - suite.numFailedTests / suite.numTests) * 100);
43 var rowInfo = [
44 this._suiteCount,
45 this._testCount,
46 formatDuration(duration),
47 numSkippedTests,
48 suite.numFailedTests,
49 percentPassed + '%'
50 ];
51 for (var i = 0; i < rowInfo.length; ++i) {
52 this._summaryNodes[i].appendChild(document.createTextNode(rowInfo[i]));
53 }
54 if (suite.numFailedTests > 0) {
55 this._passedFilter = this._createToggleFilter('hidePassed', 'Hide passed tests');
56 }
57 if (suite.numSkippedTests > 0) {
58 this._skippedFilter = this._createToggleFilter('hideSkipped', 'Hide skipped tests');
59 }
60 };
61 Html.prototype._createToggleFilter = function (className, label) {
62 var document = this.document;
63 var toggleFilter = document.createElement('div');
64 toggleFilter.className = "toggleFilter";
65 var toggle = document.createElement('input');
66 toggle.type = 'checkbox';
67 var toggleLabel = document.createElement('label');
68 toggleLabel.appendChild(toggle);
69 toggleLabel.appendChild(document.createTextNode(label));
70 toggleFilter.appendChild(toggleLabel);
71 toggle.onclick = function () {
72 if (toggle.checked) {
73 addClass(document.body, className);
74 }
75 else {
76 removeClass(document.body, className);
77 }
78 };
79 return toggleFilter;
80 };
81 Html.prototype._injectCSS = function () {
82 var document = this.document;
83 var style = document.createElement('style');
84 style.innerHTML = 'body { visibility: hidden; }';
85 var link = document.createElement('link');
86 link.rel = 'stylesheet';
87 link.href = this.executor.config.internPath + "lib/reporters/html/html.css";
88 document.head.appendChild(style);
89 document.head.appendChild(link);
90 };
91 Html.prototype._getIndentLevel = function (node) {
92 var child = node.children[1];
93 var indent = child.className.split(' ').filter(function (name) {
94 return name.indexOf('indent') >= 0;
95 })[0];
96 return indent ? parseInt(indent.slice('indent'.length), 10) : 0;
97 };
98 Html.prototype._setCollapsed = function (node, shouldCollapse) {
99 var indentDelta;
100 var initialIndent = this._getIndentLevel(node);
101 var collapsed = containsClass(node, 'collapsed');
102 if (shouldCollapse === collapsed) {
103 return;
104 }
105 shouldCollapse = shouldCollapse == null ? !collapsed : shouldCollapse;
106 if (shouldCollapse) {
107 addClass(node, 'collapsed');
108 }
109 else {
110 removeClass(node, 'collapsed');
111 }
112 while ((node = node.nextSibling)) {
113 indentDelta = this._getIndentLevel(node) - initialIndent;
114 if (indentDelta <= 0) {
115 break;
116 }
117 if (containsClass(node, 'suite')) {
118 addClass(node, 'collapsed');
119 }
120 node.style.display =
121 !shouldCollapse && indentDelta === 1 ? '' : 'none';
122 }
123 };
124 Html.prototype.error = function (error) {
125 var document = this.document;
126 var htmlError = this.formatError(error)
127 .replace(/&/g, '&amp;')
128 .replace(/</g, '&lt;');
129 var errorNode = document.createElement('pre');
130 errorNode.style.cssText = 'color: red; font-family: sans-serif;';
131 errorNode.innerHTML =
132 '<h1>Fatal error</h1>' +
133 '<pre style="padding: 1em; background-color: #f0f0f0;">' +
134 htmlError +
135 '</pre>';
136 document.body.appendChild(errorNode);
137 };
138 Html.prototype.runStart = function () {
139 var _this = this;
140 var document = this.document;
141 this._reportContainer = document.createElement('div');
142 var headerNode = document.createElement('h1');
143 var summaryHeaders = [
144 'Suites',
145 'Tests',
146 'Duration',
147 'Skipped',
148 'Failed',
149 'Success Rate'
150 ];
151 var summaryIcons = {
152 suites: icons_1.suitesIcon,
153 tests: icons_1.testsIcon,
154 duration: icons_1.timeIcon,
155 skipped: icons_1.skipIcon,
156 failed: icons_1.failIcon
157 };
158 var fragment = this._fragment;
159 var headerTitle = document.createElement('span');
160 headerTitle.className = 'headerTitle';
161 headerTitle.innerHTML = 'Intern Test Report';
162 headerNode.className = 'reportHeader';
163 var headerLogo = document.createElement('img');
164 headerLogo.className = 'headerLogo';
165 headerLogo.src =
166 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIIAAACACAMAAADwF' +
167 'UHEAAADAFBMVEUAAAAAAAAAAABVVVVAQEBmZmZVVVVtbW1gYGBVVVVmZmZdXV1q' +
168 'ampiYmJtbW1mZmZwcHBpaWljY2Nra2tmZmZtbW1oaGhvb29qampwcHBsbGxoaGh' +
169 'tbW1qampvb29ra2twcHBsbGxxcXFtbW1qampubm5ra2tvb29sbGxwcHBtbW1xcX' +
170 'Fubm5sbGxvb29tbW1wcHBtbW1wcHBubm5xcXFvb29tbW1vb29tbW1wcHBubm5wc' +
171 'HBvb29xcXFvb29tbW1wcHBubm5wcHBubm5xcXFvb29xcXFvb29ubm5wcHBubm5w' +
172 'cHBvb29xcXFvb29xcXFwcHBubm5wcHBwcHBvb29xcXFvb29ubm5xcXFwcHBvb29' +
173 'wcHBwcHBvb29xcXFwcHBubm5wcHBvb29wcHBvb29xcXFvb29xcXFwcHBvb29wcH' +
174 'Bvb29wcHBvb29xcXFwcHBxcXFwcHBvb29wc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DwEM0BTYVn4thpmvpN02W' +
190 'qVpaXNYlPM0koW+cy0BepYG5Ca1lDLMrXyEenS6GFiTiSxttTIFJsvFFB5TIEdg' +
191 '919+/3+/zu5x/9/AnF3nw+aI/C2qcs27T1RXlVdW1r45ZY/TxwYAi8yDF68v47O' +
192 '6velPxAKrxi06iz11HyYeC08LPSJA3Sv9t27/OA5IXPPswmKpgbCMwKfOcMmOpU' +
193 'UBA8YcYTNUDwzFK2s3UoLm6c0yQ+tKfoEm2//bWhNt+xm85mXt0MrMjxZweYrfh' +
194 'StKfYrtsDWCLSiwEy2wKk70JomN7D5GlKMaEW/Y0vsikarCI0b8+zLb11kS5SNw' +
195 'M/Uc2LGJ6f4c9Q9jhbzHzhjSwlbQbofWiJk3OZLbC1b26K52ozZcImt6etOaJae' +
196 'WRVsbUe7oukGZFvoAad6oYmi11roGSW3oikMz12mx5QPxdV12E5PqhiAq+lzmp5' +
197 '1IQ7uxZXS00r7wp3uF+l5xbHQF1hAbzgaBV2Z9I78UOiIrqOXfOQPbRn0mhVwEN' +
198 'StXw8jhEmPjb7nnoenv1lFz3saNuGPvvGdheSlVZG44k56Xv2dkALHf2SizXehU' +
199 'Pmn1dALyn4BXJ9eSnuzoVpH78gfsqGejrZDMY6+cwGKAvrOeUix9KHjkCbQh/ZB' +
200 'eok+9CqkDPrQBEgr6EMxkNLoO/lQzKHvzIQigT5jiYEijj6TA1VQA33lAVh9Sx8' +
201 '57gerV+kjs2DzEH3jfFvYRFjoEy+h0R76QmV7NEqmL6TAToyFraD0wNbXXvj9/f' +
202 'H94uKGjkneWEn3SsNgL48/h7lwU+qEW8PgqMN2ujUDDpLopIFNdGrl1IHB0NSd7' +
203 'hS1gYP2NbTTUMGm2ngN9PgtoDvj4GQtr/jvGTbV5Sega/DXdGc3nMXT5p//YaPK' +
204 'woPnqeuTPtA1sZaNyg8fLqeDhji4+J6Kug/MVDXsfLZPWwhBNyZmV9OFZcsA6PL' +
205 '7C61MO6b1CIEQ0mPaDhN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lpChQ/UJgHbZMpVEIVZaaWNEi' +
221 'VFCbDTjdKIyEZTlODuSOkKDOFh6BtGKXeUO2mlkEQ+lAaBjuGYgpLoEimhjehSK' +
222 'Rg6QRtIdUU5kE1mhp2QZpHoToE9rIoHIcisIguqqOh+JBCHvRkU8iD1S66sAyGl' +
223 'EchGw7upTQEigE1dJYARWQ1hXnQk0jBEgvV9SV09iKkbhYKiXDQporCTqjG19NR' +
224 'ClRLKPWGnigzhXdhNaySjt42QHqXgjkKjtZS+g1UI8/TjulxqG4wUfgG+nIoWPr' +
225 'D6qYi2rGkGCD1t1DIgZNudRS+DYKq08oG2mzrC6vNlO6HvoGUco2wapdWTZt/DI' +
226 'PCmEtpIJwtp/QObG6YnXvOwgsFC/vBZg6lXLizkVIGruj49MdnGlh5MHM4rDIob' +
227 'YSLDlWU5sJOQBDs3GemNBjudK+nNAn2jCFoNIlSfXe4mk3JPBU6RlVSWgv30inV' +
228 'joOOcSZK6dDyHhWv+kPL9HpKB0Lgnv9nlCwpBmgwpFgofeYPLSEFVHwaCxcRb1B' +
229 'xNgZXc+1RKjZ3hovOW6g4ei20xZylom5ZFBwEP19OhWkorq5PJRXVi8PhIHxxNR' +
230 'UVfaCnx/dUVbwxOghWxjsyT1NVNhJN0f8kVf/7MeeVeU+MHd47yoiAX68oo+rkr' +
231 'dB3zce0ubRjZcqTk+evyC6lzaFYNM11eXRiMf2fNnnXwR3jEuraFo6mCnqbut4O' +
232 'wlUMzqWmwrFojlFF1HRgFJrggcN0UTzVH81zFzXdhCYxjlhynHZK1zwYjOZ6kJp' +
233 'mocl+OWfNnsLTxUfy178Ub0QLzKCmt+A926kpF14TXUdNX8JrVlDbTnjL3RZqex' +
234 '1e0qmEOh6HdwTvoo76aHhFu93U8z68ouPX1DUE3jCoiLqWwwuML9ZT13fB8Lxue' +
235 '6iv/BZ4XFhaLfVVDoOnGRKL6caZOHiY38Pf0J1dneFZxoTDdKd2gREeFTnrKN36' +
236 'vBc8asQGE906eB88KWLm93Qvf6wBnuM3cl0t3apdNxyeYxi69Azd25ccCY/xv3P' +
237 'ZCbplyXshFh4TmbDuAt0qeT+xAzwlMD41z0x3Tm1KuskAjwl8ZEcJ9Z3LefmhLv' +
238 'C89oMn/mnzIRMdnM1dPfOujvAqY+y9z2V9UVx16KPX504Y0A4t9BN3u2Vcrggrb' +
239 'wAAAABJRU5ErkJggg==';
240 headerNode.appendChild(headerLogo);
241 headerNode.appendChild(headerTitle);
242 fragment.appendChild(headerNode);
243 this._reportContainer.className = 'internReportContainer';
244 this._fragment.appendChild(this._reportContainer);
245 var summaryTableNode = document.createElement('div');
246 summaryTableNode.className = 'summary';
247 this._summaryNode = document.createElement('div');
248 for (var i = 0; i < summaryHeaders.length; i++) {
249 var cellNode = document.createElement('div');
250 var cellName = summaryHeaders[i]
251 .toLowerCase()
252 .replace(/\s(.)/g, function (_, char) { return char.toUpperCase(); });
253 cellNode.className = 'summaryContent';
254 addClass(cellNode, cellName);
255 if (summaryIcons[cellName]) {
256 var cellIcon = createSvgNode(summaryIcons[cellName], cellName);
257 cellNode.appendChild(cellIcon);
258 }
259 var cellTitle = document.createElement('span');
260 cellTitle.className = 'summaryTitle';
261 cellTitle.appendChild(document.createTextNode(summaryHeaders[i]));
262 var cellData = document.createElement('div');
263 cellData.className = 'summaryData';
264 this._summaryNodes[i] = document.createElement('span');
265 this._summaryNode.appendChild(this._summaryNodes[i]);
266 cellData.appendChild(this._summaryNodes[i]);
267 cellNode.appendChild(cellTitle);
268 cellNode.appendChild(cellData);
269 summaryTableNode.appendChild(cellNode);
270 }
271 this._reportContainer.appendChild(summaryTableNode);
272 this._reportControls = document.createElement('div');
273 this._reportControls.className = 'reportControls';
274 this._reportControls.appendChild(document.createElement('div'));
275 this._reportControls.appendChild(document.createElement('div'));
276 this._reportContainer.appendChild(this._reportControls);
277 var reportTableNode = document.createElement('table');
278 reportTableNode.className = 'report';
279 this._reportNode = document.createElement('tbody');
280 reportTableNode.appendChild(this._reportNode);
281 this._reportContainer.appendChild(reportTableNode);
282 this._reportNode.addEventListener('click', function (event) {
283 var target = event.target;
284 if (!target || target.tagName === 'A') {
285 return;
286 }
287 while (target && target.tagName !== 'TR') {
288 target = target.parentElement;
289 }
290 if (target) {
291 _this._setCollapsed(target);
292 }
293 });
294 };
295 Html.prototype.suiteStart = function (suite) {
296 if (!suite.hasParent) {
297 return;
298 }
299 this._testsInSuite = suite.tests.length;
300 this._testIndex = 0;
301 this._processedTests = {};
302 this._suiteCount++;
303 var document = this.document;
304 var rowNode = document.createElement('tr');
305 rowNode.className = 'suite';
306 var statusCell = document.createElement('td');
307 addClass(statusCell, 'column-status');
308 var statusContent = document.createElement('div');
309 addClass(statusContent, 'statusContent');
310 statusCell.appendChild(statusContent);
311 rowNode.appendChild(statusCell);
312 var idCell = document.createElement('td');
313 idCell.className = 'column-id';
314 addClass(idCell, 'title');
315 var idText = document.createElement('div');
316 idText.className = 'truncateText';
317 idText.appendChild(this.createLinkNode(suite));
318 idCell.appendChild(idText);
319 rowNode.appendChild(idCell);
320 this._reportNode.appendChild(rowNode);
321 if (this._indentLevel) {
322 addClass(idCell, "indent" + Math.min(this._indentLevel, 5));
323 addClass(rowNode, 'indent');
324 }
325 this._runningSuites[suite.id] = { node: rowNode };
326 ++this._indentLevel;
327 };
328 Html.prototype.suiteEnd = function (suite) {
329 var _this = this;
330 var document = this.document;
331 var numTests = suite.numTests;
332 var numFailedTests = suite.numFailedTests;
333 var numPassedTests = suite.numPassedTests;
334 var numSkippedTests = numTests - (numFailedTests + numPassedTests);
335 var hasSuiteFailures = suite.numSkippedTests !== numSkippedTests;
336 var allTestsSkipped = numTests === numSkippedTests;
337 if (!suite.hasParent) {
338 this._generateSummary(suite);
339 for (var i = 0; i < document.styleSheets.length; i++) {
340 document.styleSheets[i].disabled = true;
341 }
342 require('./html/html.styl');
343 document.body.innerHTML = '';
344 document.body.className = '';
345 document.body.appendChild(this._fragment);
346 var expandToggle = document.createElement('div');
347 expandToggle.className = 'linkButton';
348 expandToggle.textContent = 'Expand/collapse all';
349 var reportControls = this._reportControls;
350 reportControls.firstElementChild.appendChild(expandToggle);
351 expandToggle.addEventListener('click', function () {
352 var reportNode = _this._reportNode;
353 var shouldExpand = reportNode.querySelector('.collapsed') != null;
354 var suites = reportNode.querySelectorAll('.suite');
355 for (var i = 0; i < suites.length; i++) {
356 _this._setCollapsed(suites[i], !shouldExpand);
357 }
358 });
359 if (this._passedFilter) {
360 reportControls.lastElementChild.appendChild(this._passedFilter);
361 }
362 else {
363 var failedNode = document.querySelector('.failed');
364 addClass(failedNode, 'success');
365 }
366 if (this._skippedFilter) {
367 reportControls.lastElementChild.appendChild(this._skippedFilter);
368 }
369 var successRateNode = document.querySelector('.successRate');
370 if (suite.numFailedTests > 0) {
371 var icon_1 = createSvgNode(icons_1.failIcon);
372 successRateNode.insertBefore(icon_1, successRateNode.firstChild);
373 addClass(successRateNode, 'failed');
374 }
375 else {
376 var icon_2 = createSvgNode(icons_1.passIcon);
377 successRateNode.insertBefore(icon_2, successRateNode.firstChild);
378 }
379 if (hasSuiteFailures) {
380 var skippedNode = document.querySelector('.summaryContent.skipped');
381 addClass(skippedNode, 'failed');
382 }
383 return;
384 }
385 var rowNode = this._runningSuites[suite.id].node;
386 var rowStatus = allTestsSkipped
387 ? 'skipped'
388 : numFailedTests > 0 || hasSuiteFailures
389 ? 'failed'
390 : 'passed';
391 addClass(rowNode, rowStatus);
392 var icon = createSvgNode(rowStatus === 'skipped' ? icons_1.skipIcon : icons_1.suitesIcon);
393 var statusCell = rowNode.querySelector('.column-status');
394 var statusContent = statusCell.firstElementChild;
395 statusContent.appendChild(icon);
396 this._setCollapsed(rowNode, numFailedTests === 0 && !hasSuiteFailures);
397 var cellNode = document.createElement('td');
398 if (numPassedTests > 0) {
399 cellNode.appendChild(document.createTextNode('Passed: '));
400 var testsPassed = document.createElement('span');
401 testsPassed.className = 'success';
402 testsPassed.innerHTML = "" + numPassedTests;
403 cellNode.appendChild(testsPassed);
404 }
405 if (numFailedTests > 0) {
406 cellNode.appendChild(document.createTextNode('Failed: '));
407 var testsFailed = document.createElement('span');
408 testsFailed.className = 'failed';
409 testsFailed.innerHTML = "" + numFailedTests;
410 cellNode.appendChild(testsFailed);
411 }
412 if (numSkippedTests > 0) {
413 cellNode.appendChild(document.createTextNode('Skipped: '));
414 var testsSkipped = document.createElement('span');
415 testsSkipped.innerHTML = "" + numSkippedTests;
416 cellNode.appendChild(testsSkipped);
417 }
418 if (suite.error) {
419 var suiteError = document.createElement('span');
420 suiteError.className = 'failed';
421 suiteError.innerHTML = 'Suite error!';
422 cellNode.appendChild(suiteError);
423 }
424 cellNode.className = 'column-info';
425 rowNode.appendChild(cellNode);
426 cellNode = document.createElement('td');
427 cellNode.className = 'column-time numeric duration';
428 cellNode.appendChild(document.createTextNode(formatDuration(suite.timeElapsed)));
429 rowNode.appendChild(cellNode);
430 --this._indentLevel;
431 if (!this._indentLevel) {
432 this._testCount += numTests;
433 }
434 this._runningSuites[suite.id] = null;
435 };
436 Html.prototype.testEnd = function (test) {
437 if (test.id in this._processedTests) {
438 return;
439 }
440 this._processedTests[test.id] = true;
441 this._testIndex++;
442 var document = this.document;
443 var rowNode = document.createElement('tr');
444 rowNode.className = 'testResult';
445 var statusCell = document.createElement('td');
446 statusCell.className = 'column-status';
447 var statusContent = document.createElement('div');
448 statusContent.className = 'statusContent';
449 statusCell.appendChild(statusContent);
450 rowNode.appendChild(statusCell);
451 var idCell = document.createElement('td');
452 idCell.className = 'column-id';
453 if (this._indentLevel) {
454 addClass(idCell, "indent" + this._indentLevel);
455 }
456 var idText = document.createElement('div');
457 idText.className = 'truncateText';
458 idText.appendChild(this.createLinkNode(test));
459 idCell.appendChild(idText);
460 rowNode.appendChild(idCell);
461 var infoCell = document.createElement('td');
462 infoCell.className = 'column-info';
463 var statusIcon;
464 if (test.error) {
465 addClass(rowNode, 'failed');
466 var errorNode = document.createElement('div');
467 errorNode.className = 'testError';
468 var errorText = document.createElement('pre');
469 addClass(errorText, 'scrollText');
470 errorText.textContent = this.formatError(test.error);
471 errorNode.appendChild(errorText);
472 infoCell.appendChild(errorNode);
473 statusIcon = createSvgNode(icons_1.failIcon);
474 }
475 else if (test.skipped != null) {
476 addClass(rowNode, 'skipped');
477 infoCell.appendChild(document.createTextNode(test.skipped || ''));
478 statusIcon = createSvgNode(icons_1.skipIcon);
479 }
480 else {
481 addClass(rowNode, 'passed');
482 statusIcon = createSvgNode(icons_1.passIcon);
483 }
484 statusContent.appendChild(statusIcon);
485 if (this._testIndex === this._testsInSuite) {
486 addClass(rowNode, 'lastTest');
487 }
488 rowNode.appendChild(infoCell);
489 var timeNode = document.createElement('td');
490 timeNode.className = 'numeric';
491 addClass(timeNode, 'duration');
492 timeNode.appendChild(document.createTextNode(test.skipped ? 'Skipped' : formatDuration(test.timeElapsed)));
493 rowNode.appendChild(timeNode);
494 this._reportNode.appendChild(rowNode);
495 };
496 Html.prototype.createLinkNode = function (obj) {
497 var document = this.document;
498 var location = this.location;
499 var params = new URLSearchParams(location.search.slice(1) || undefined);
500 params.delete('grep');
501 params.append('grep', obj.id);
502 var a = document.createElement('a');
503 a.href = location.origin + location.pathname + ("?" + params.toString());
504 a.title = obj.name;
505 a.appendChild(document.createTextNode(obj.name));
506 return a;
507 };
508 tslib_1.__decorate([
509 Reporter_1.eventHandler()
510 ], Html.prototype, "error", null);
511 tslib_1.__decorate([
512 Reporter_1.eventHandler()
513 ], Html.prototype, "runStart", null);
514 tslib_1.__decorate([
515 Reporter_1.eventHandler()
516 ], Html.prototype, "suiteStart", null);
517 tslib_1.__decorate([
518 Reporter_1.eventHandler()
519 ], Html.prototype, "suiteEnd", null);
520 tslib_1.__decorate([
521 Reporter_1.eventHandler()
522 ], Html.prototype, "testEnd", null);
523 return Html;
524 }(Reporter_1.default));
525 exports.default = Html;
526 function containsClass(node, cls) {
527 var classes = node.className.split(/\s+/);
528 return classes.indexOf(cls) !== -1;
529 }
530 function addClass(node, cls) {
531 if (node.classList) {
532 node.classList.add(cls);
533 }
534 else {
535 var classes = getClassName(node).split(/\s+/);
536 if (classes.indexOf(cls) !== -1) {
537 return;
538 }
539 classes.push(cls);
540 setClassName(node, classes.join(' '));
541 }
542 }
543 function removeClass(node, cls) {
544 if (node.classList) {
545 node.classList.remove(cls);
546 }
547 else {
548 var classes = getClassName(node).split(/\s+/);
549 var index = classes.indexOf(cls);
550 if (index === -1) {
551 return;
552 }
553 classes.splice(index, 1);
554 setClassName(node, classes.join(' '));
555 }
556 }
557 function getClassName(node) {
558 return node.getAttribute('class') || '';
559 }
560 function setClassName(node, cls) {
561 node.setAttribute('class', cls);
562 }
563 function pad(value, size) {
564 var padded = String(value);
565 while (padded.length < size) {
566 padded = '0' + padded;
567 }
568 return padded;
569 }
570 function formatDuration(duration) {
571 var hours = Math.floor(duration / 3600000);
572 var minutes = Math.floor(duration / 60000) - hours * 60;
573 var seconds = Math.floor(duration / 1000) - hours * 3600 - minutes * 60;
574 var milliseconds = duration - hours * 3600000 - minutes * 60000 - seconds * 1000;
575 var formattedValue = '';
576 if (hours) {
577 formattedValue = hours + ':';
578 minutes = pad(minutes, 2);
579 }
580 formattedValue +=
581 minutes + ':' + pad(seconds, 2) + '.' + pad(milliseconds, 3);
582 return formattedValue;
583 }
584 function createSvgNode(svg, extraClass) {
585 var div = document.createElement('div');
586 div.className = 'icon';
587 div.innerHTML = svg;
588 var icon = div.firstElementChild;
589 addClass(icon, 'icon');
590 if (extraClass) {
591 addClass(icon, extraClass);
592 }
593 return icon;
594 }
595});
596//# sourceMappingURL=Html.js.map
\No newline at end of file