awv3
Version:
⚡ AWV3 embedded CAD
136 lines (112 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Timestamp = exports.Performance = undefined;
var _trunc = require('babel-runtime/core-js/math/trunc');
var _trunc2 = _interopRequireDefault(_trunc);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
exports.url = url;
exports.queryDom = queryDom;
exports.setPrefixedValue = setPrefixedValue;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function url(param) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == param) {
return sParameterName[1];
}
}
}
function queryDom(item) {
if (typeof item === 'string' || item instanceof String) item = document.querySelector(item);
return item;
}
function setPrefixedValue(elm, prop, value, fallback) {
var prefixes = ['-moz-', '-webkit-', '-o-', '-ms-', '-khtml-'],
i,
v,
starting;
// Clear
elm.style[prop] = "";
starting = elm.style[prop];
// Try raw first
try {
elm.style[prop] = value;
if (elm.style[prop] !== starting) return;
} catch (e) {}
// Try prefixes
for (i = 0; i < prefixes.length; ++i) {
v = prefixes[i] + value;
try {
elm.style[prop] = v;
if (elm.style[prop] !== starting) return;
} catch (e2) {}
}
elm.style[prop] = fallback;
}
var Performance = exports.Performance = function () {
function Performance() {
(0, _classCallCheck3.default)(this, Performance);
this.stamp = undefined;
this.total = undefined;
}
(0, _createClass3.default)(Performance, [{
key: 'begin',
value: function begin() {
this.stamp = performance.now();
return this;
}
}, {
key: 'end',
value: function end() {
this.stamp = performance.now() - this.stamp;
if (!this.total || this.stamp > this.total) this.total = this.stamp;
return this;
}
}, {
key: 'printCurrent',
value: function printCurrent() {
console.log(this.stamp);
return this;
}
}, {
key: 'printTotal',
value: function printTotal() {
console.log(this.total);
return this;
}
}, {
key: 'clear',
value: function clear() {
this.total = undefined;
return this;
}
}]);
return Performance;
}();
//absolute timestamp with high relative resolution
var Timestamp = exports.Timestamp = function () {
var startPerfo = performance.now();
var startTime = Date.now();
function padString(str, pad) {
str = str.toString();
return String(pad + str).slice(-pad.length);
};
return {
get: function get() {
var diffPerfo = performance.now() - startPerfo;
var absTime = startTime + diffPerfo;
var minutes = (0, _trunc2.default)(absTime / 60000) % 60;
var seconds = (0, _trunc2.default)(absTime / 1000) % 60;
var micro = (0, _trunc2.default)(absTime * 1000) % 1000000;
var str = padString(minutes, '00') + ':' + padString(seconds, '00') + '.' + padString(micro, '000000');
return str;
}
};
}();