@visactor/vtable
Version:
canvas table width high performance
60 lines (54 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.clearPageSelection = exports.Env = void 0;
class Env {
static get mode() {
return Env._mode || (Env._mode = defaultMode()), Env._mode;
}
static set mode(mode) {
Env._mode = mode;
}
static RegisterCreateCanvas(func) {
Env.CreateCanvas = func;
}
static RegisterLoadImage(func) {
Env.LoadImage = func;
}
static GetCreateCanvasFunc() {
return Env.CreateCanvas ? Env.CreateCanvas : "worker" === Env.mode ? (width = 200, height = 200) => new OffscreenCanvas(width, height) : void 0;
}
static RegisterRequestAnimationFrame(func) {
Env.RequestAnimationFrame = func();
}
static GetRequestAnimationFrame() {
if (Env.RequestAnimationFrame) return Env.RequestAnimationFrame;
}
static RegisterCancelAnimationFrame(func) {
Env.CancelAnimationFrame = func();
}
static GetCancelAnimationFrame() {
if (Env.CancelAnimationFrame) return Env.CancelAnimationFrame;
}
}
function defaultMode() {
let mode = "browser";
try {
"node" === window.type ? mode = "node" : "undefined" == typeof window || window.performance ? "undefined" == typeof window && (mode = "node") : mode = "miniApp";
} catch (err) {
mode = "node";
}
return mode;
}
function clearPageSelection() {
try {
const selection = window.getSelection();
if (selection) {
if ("function" == typeof selection.removeAllRanges) return void selection.removeAllRanges();
if ("function" == typeof selection.empty) return void selection.empty();
if ("function" == typeof selection.collapse) return void selection.collapse(document.body, 0);
}
} catch (error) {}
}
exports.Env = Env, Env.dpr = 0, exports.clearPageSelection = clearPageSelection;
//# sourceMappingURL=env.js.map