awv3
Version:
⚡ AWV3 embedded CAD
98 lines (82 loc) • 2.5 kB
JavaScript
export 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];
}
}
}
export function queryDom(item) {
if (typeof item === 'string' || item instanceof String) item = document.querySelector(item);
return item;
}
export 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;
}
export class Performance {
constructor() {
this.stamp = undefined;
this.total = undefined;
}
begin() {
this.stamp = performance.now();
return this;
}
end() {
this.stamp = performance.now() - this.stamp;
if (!this.total || this.stamp > this.total) this.total = this.stamp;
return this;
}
printCurrent() {
console.log(this.stamp);
return this;
}
printTotal() {
console.log(this.total);
return this;
}
clear() {
this.total = undefined;
return this;
}
}
//absolute timestamp with high relative resolution
export var 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() {
var diffPerfo = performance.now() - startPerfo;
var absTime = startTime + diffPerfo;
var minutes = Math.trunc(absTime / 60000) % 60;
var seconds = Math.trunc(absTime / 1000) % 60;
var micro = Math.trunc(absTime * 1000) % 1000000;
var str = padString(minutes, '00') + ':' + padString(seconds, '00') + '.' + padString(micro, '000000');
return str;
}
};
})();