@mt-kit/vue-directives
Version:
578 lines (553 loc) • 20.4 kB
JavaScript
function B(e) {
const t = new Date(e), n = t.getFullYear(), o = t.getMonth() + 1 < 10 ? `0${t.getMonth() + 1}` : t.getMonth() + 1, r = t.getDate() < 10 ? `0${t.getDate()}` : t.getDate(), i = t.getHours() < 10 ? `0${t.getHours()}` : t.getHours(), s = t.getMinutes() < 10 ? `0${t.getMinutes()}` : t.getMinutes(), c = t.getSeconds() < 10 ? `0${t.getSeconds()}` : t.getSeconds();
return `${n}-${o}-${r} ${i}:${s}:${c}`;
}
function ve(e) {
e.directive("conversion-time", {
mounted(t) {
const n = t.textContent;
let o = Number.parseInt(n);
JSON.stringify(o).length === 10 && (o = o * 1e3), t.textContent = B(o);
}
});
}
var G = Object.defineProperty, P = (e, t, n) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, w = (e, t, n) => P(e, typeof t != "symbol" ? t + "" : t, n);
function V(e) {
return e instanceof Element || e != null && typeof e == "object" && "nodeType" in e && typeof e.nodeType == "number" && "nodeName" in e && typeof e.nodeName == "string";
}
var C = function() {
if (typeof Map < "u")
return Map;
function e(t, n) {
var o = -1;
return t.some(function(r, i) {
return r[0] === n ? (o = i, !0) : !1;
}), o;
}
return (
/** @class */
function() {
function t() {
this.__entries__ = [];
}
return Object.defineProperty(t.prototype, "size", {
/**
* @returns {boolean}
*/
get: function() {
return this.__entries__.length;
},
enumerable: !0,
configurable: !0
}), t.prototype.get = function(n) {
var o = e(this.__entries__, n), r = this.__entries__[o];
return r && r[1];
}, t.prototype.set = function(n, o) {
var r = e(this.__entries__, n);
~r ? this.__entries__[r][1] = o : this.__entries__.push([n, o]);
}, t.prototype.delete = function(n) {
var o = this.__entries__, r = e(o, n);
~r && o.splice(r, 1);
}, t.prototype.has = function(n) {
return !!~e(this.__entries__, n);
}, t.prototype.clear = function() {
this.__entries__.splice(0);
}, t.prototype.forEach = function(n, o) {
o === void 0 && (o = null);
for (var r = 0, i = this.__entries__; r < i.length; r++) {
var s = i[r];
n.call(o, s[1], s[0]);
}
}, t;
}()
);
}(), x = typeof window < "u" && typeof document < "u" && window.document === document, f = function() {
return typeof global < "u" && global.Math === Math ? global : typeof self < "u" && self.Math === Math ? self : typeof window < "u" && window.Math === Math ? window : Function("return this")();
}(), J = function() {
return typeof requestAnimationFrame == "function" ? requestAnimationFrame.bind(f) : function(e) {
return setTimeout(function() {
return e(Date.now());
}, 1e3 / 60);
};
}(), K = 2;
function Q(e, t) {
var n = !1, o = !1, r = 0;
function i() {
n && (n = !1, e()), o && c();
}
function s() {
J(i);
}
function c() {
var a = Date.now();
if (n) {
if (a - r < K)
return;
o = !0;
} else
n = !0, o = !1, setTimeout(s, t);
r = a;
}
return c;
}
var U = 20, Z = ["top", "right", "bottom", "left", "width", "height", "size", "weight"], ee = typeof MutationObserver < "u", te = (
/** @class */
function() {
function e() {
this.connected_ = !1, this.mutationEventsAdded_ = !1, this.mutationsObserver_ = null, this.observers_ = [], this.onTransitionEnd_ = this.onTransitionEnd_.bind(this), this.refresh = Q(this.refresh.bind(this), U);
}
return e.prototype.addObserver = function(t) {
~this.observers_.indexOf(t) || this.observers_.push(t), this.connected_ || this.connect_();
}, e.prototype.removeObserver = function(t) {
var n = this.observers_, o = n.indexOf(t);
~o && n.splice(o, 1), !n.length && this.connected_ && this.disconnect_();
}, e.prototype.refresh = function() {
var t = this.updateObservers_();
t && this.refresh();
}, e.prototype.updateObservers_ = function() {
var t = this.observers_.filter(function(n) {
return n.gatherActive(), n.hasActive();
});
return t.forEach(function(n) {
return n.broadcastActive();
}), t.length > 0;
}, e.prototype.connect_ = function() {
!x || this.connected_ || (document.addEventListener("transitionend", this.onTransitionEnd_), window.addEventListener("resize", this.refresh), ee ? (this.mutationsObserver_ = new MutationObserver(this.refresh), this.mutationsObserver_.observe(document, {
attributes: !0,
childList: !0,
characterData: !0,
subtree: !0
})) : (document.addEventListener("DOMSubtreeModified", this.refresh), this.mutationEventsAdded_ = !0), this.connected_ = !0);
}, e.prototype.disconnect_ = function() {
!x || !this.connected_ || (document.removeEventListener("transitionend", this.onTransitionEnd_), window.removeEventListener("resize", this.refresh), this.mutationsObserver_ && this.mutationsObserver_.disconnect(), this.mutationEventsAdded_ && document.removeEventListener("DOMSubtreeModified", this.refresh), this.mutationsObserver_ = null, this.mutationEventsAdded_ = !1, this.connected_ = !1);
}, e.prototype.onTransitionEnd_ = function(t) {
var n = t.propertyName, o = n === void 0 ? "" : n, r = Z.some(function(i) {
return !!~o.indexOf(i);
});
r && this.refresh();
}, e.getInstance = function() {
return this.instance_ || (this.instance_ = new e()), this.instance_;
}, e.instance_ = null, e;
}()
), D = function(e, t) {
for (var n = 0, o = Object.keys(t); n < o.length; n++) {
var r = o[n];
Object.defineProperty(e, r, {
value: t[r],
enumerable: !1,
writable: !1,
configurable: !0
});
}
return e;
}, d = function(e) {
var t = e && e.ownerDocument && e.ownerDocument.defaultView;
return t || f;
}, S = m(0, 0, 0, 0);
function p(e) {
return parseFloat(e) || 0;
}
function L(e) {
for (var t = [], n = 1; n < arguments.length; n++)
t[n - 1] = arguments[n];
return t.reduce(function(o, r) {
var i = e["border-" + r + "-width"];
return o + p(i);
}, 0);
}
function ne(e) {
for (var t = ["top", "right", "bottom", "left"], n = {}, o = 0, r = t; o < r.length; o++) {
var i = r[o], s = e["padding-" + i];
n[i] = p(s);
}
return n;
}
function oe(e) {
var t = e.getBBox();
return m(0, 0, t.width, t.height);
}
function re(e) {
var t = e.clientWidth, n = e.clientHeight;
if (!t && !n)
return S;
var o = d(e).getComputedStyle(e), r = ne(o), i = r.left + r.right, s = r.top + r.bottom, c = p(o.width), a = p(o.height);
if (o.boxSizing === "border-box" && (Math.round(c + i) !== t && (c -= L(o, "left", "right") + i), Math.round(a + s) !== n && (a -= L(o, "top", "bottom") + s)), !se(e)) {
var u = Math.round(c + i) - t, l = Math.round(a + s) - n;
Math.abs(u) !== 1 && (c -= u), Math.abs(l) !== 1 && (a -= l);
}
return m(r.left, r.top, c, a);
}
var ie = /* @__PURE__ */ function() {
return typeof SVGGraphicsElement < "u" ? function(e) {
return e instanceof d(e).SVGGraphicsElement;
} : function(e) {
return e instanceof d(e).SVGElement && typeof e.getBBox == "function";
};
}();
function se(e) {
return e === d(e).document.documentElement;
}
function ae(e) {
return x ? ie(e) ? oe(e) : re(e) : S;
}
function ce(e) {
var t = e.x, n = e.y, o = e.width, r = e.height, i = typeof DOMRectReadOnly < "u" ? DOMRectReadOnly : Object, s = Object.create(i.prototype);
return D(s, {
x: t,
y: n,
width: o,
height: r,
top: n,
right: t + o,
bottom: r + n,
left: t
}), s;
}
function m(e, t, n, o) {
return { x: e, y: t, width: n, height: o };
}
var ue = (
/** @class */
function() {
function e(t) {
this.broadcastWidth = 0, this.broadcastHeight = 0, this.contentRect_ = m(0, 0, 0, 0), this.target = t;
}
return e.prototype.isActive = function() {
var t = ae(this.target);
return this.contentRect_ = t, t.width !== this.broadcastWidth || t.height !== this.broadcastHeight;
}, e.prototype.broadcastRect = function() {
var t = this.contentRect_;
return this.broadcastWidth = t.width, this.broadcastHeight = t.height, t;
}, e;
}()
), le = (
/** @class */
/* @__PURE__ */ function() {
function e(t, n) {
var o = ce(n);
D(this, { target: t, contentRect: o });
}
return e;
}()
), de = (
/** @class */
function() {
function e(t, n, o) {
if (this.activeObservations_ = [], this.observations_ = new C(), typeof t != "function")
throw new TypeError("The callback provided as parameter 1 is not a function.");
this.callback_ = t, this.controller_ = n, this.callbackCtx_ = o;
}
return e.prototype.observe = function(t) {
if (!arguments.length)
throw new TypeError("1 argument required, but only 0 present.");
if (!(typeof Element > "u" || !(Element instanceof Object))) {
if (!(t instanceof d(t).Element))
throw new TypeError('parameter 1 is not of type "Element".');
var n = this.observations_;
n.has(t) || (n.set(t, new ue(t)), this.controller_.addObserver(this), this.controller_.refresh());
}
}, e.prototype.unobserve = function(t) {
if (!arguments.length)
throw new TypeError("1 argument required, but only 0 present.");
if (!(typeof Element > "u" || !(Element instanceof Object))) {
if (!(t instanceof d(t).Element))
throw new TypeError('parameter 1 is not of type "Element".');
var n = this.observations_;
n.has(t) && (n.delete(t), n.size || this.controller_.removeObserver(this));
}
}, e.prototype.disconnect = function() {
this.clearActive(), this.observations_.clear(), this.controller_.removeObserver(this);
}, e.prototype.gatherActive = function() {
var t = this;
this.clearActive(), this.observations_.forEach(function(n) {
n.isActive() && t.activeObservations_.push(n);
});
}, e.prototype.broadcastActive = function() {
if (this.hasActive()) {
var t = this.callbackCtx_, n = this.activeObservations_.map(function(o) {
return new le(o.target, o.broadcastRect());
});
this.callback_.call(t, n, t), this.clearActive();
}
}, e.prototype.clearActive = function() {
this.activeObservations_.splice(0);
}, e.prototype.hasActive = function() {
return this.activeObservations_.length > 0;
}, e;
}()
), R = typeof WeakMap < "u" ? /* @__PURE__ */ new WeakMap() : new C(), H = (
/** @class */
/* @__PURE__ */ function() {
function e(t) {
if (!(this instanceof e))
throw new TypeError("Cannot call a class as a function.");
if (!arguments.length)
throw new TypeError("1 argument required, but only 0 present.");
var n = te.getInstance(), o = new de(t, n, this);
R.set(this, o);
}
return e;
}()
);
[
"observe",
"unobserve",
"disconnect"
].forEach(function(e) {
H.prototype[e] = function() {
var t;
return (t = R.get(this))[e].apply(t, arguments);
};
});
(function() {
return typeof f.ResizeObserver < "u" ? f.ResizeObserver : H;
})();
function he(e, t, n) {
if (!V(e))
throw new Error(`Element(${e})not DOM.`);
const o = e;
let r = {
offsetX: 0,
offsetY: 0
};
const i = (a) => {
o.style.position = "relative";
const u = a.clientX, l = a.clientY, {
offsetX: v,
offsetY: b
} = r, h = o.getBoundingClientRect(), O = h.left, k = h.top, j = h.width, N = h.height, {
clientWidth: q
} = document.documentElement, {
clientHeight: F
} = document.documentElement, M = (T) => {
let g = v + T.clientX - u, y = b + T.clientY - l;
const W = -O + v, Y = -k + b, I = q - O - j + v, X = F - k - N + b;
t || (g = Math.min(Math.max(g, W), I), y = Math.min(Math.max(y, Y), X)), r = {
offsetX: g,
offsetY: y
}, o.style.transform = `translate(${r.offsetX || 0}px, ${r.offsetY || 0}px)`;
}, $ = () => {
document.removeEventListener("mousemove", M), document.removeEventListener("mouseup", $);
};
document.addEventListener("mousemove", M), document.addEventListener("mouseup", $);
}, s = () => {
o.addEventListener("mousedown", i);
}, c = () => {
o.removeEventListener("mousedown", i), o.style.position = "static";
};
return new IntersectionObserver((a) => {
if (a[0].intersectionRatio <= 0) {
c();
return;
}
s();
}).observe(o), r;
}
function fe(e = !1) {
return `
<style>
:host {
${e ? `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;` : ""}
--monospace: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--red: #ff5555;
--yellow: #e2aa53;
--purple: #cfa4ff;
--cyan: #2dd9da;
--dim: #c9c9c9;
${e ? `
--window-background: #181818;
--window-color: #d8d8d8;` : ""}
}
.backdrop {
${e ? `
position: fixed;
z-index: 99999;
top: 0;
left: 0;` : ""}
width: 100%;
height: 100%;
overflow-y: scroll;
margin: 0;
${e ? "background: rgba(0, 0, 0, 0.66);" : ""}
background: rgba(0, 0, 0, 0.66);
}
.window {
font-family: var(--monospace);
line-height: 1.5;
${e ? "width: 800px;" : "width: 100%"}
color: var(--window-color);
${e ? "margin: 30px auto;" : ""}
padding: 25px 40px;
position: relative;
background: var(--window-background);
border-radius: 6px 6px 8px 8px;
overflow: hidden;
border-top: 8px solid var(--red);
direction: ltr;
text-align: left;
}
pre {
font-family: var(--monospace);
font-size: 16px;
margin-top: 0;
margin-bottom: 1em;
overflow-x: scroll;
scrollbar-width: none;
}
pre::-webkit-scrollbar {
display: none;
}
pre.frame::-webkit-scrollbar {
display: block;
height: 5px;
}
pre.frame::-webkit-scrollbar-thumb {
background: #999;
border-radius: 5px;
}
pre.frame {
scrollbar-width: thin;
}
.message {
line-height: 1.3;
font-weight: 600;
white-space: pre-wrap;
}
.message-body {
color: var(--red);
}
.plugin {
color: var(--purple);
}
.file {
color: var(--cyan);
margin-bottom: 0;
white-space: pre-wrap;
word-break: break-all;
}
.frame {
color: var(--yellow);
}
.stack {
font-size: 13px;
color: var(--dim);
}
.tip {
font-size: 13px;
color: #999;
border-top: 1px dotted #999;
padding-top: 13px;
line-height: 1.8;
}
code {
font-size: 13px;
font-family: var(--monospace);
color: var(--yellow);
}
.file-link {
text-decoration: underline;
cursor: pointer;
}
a {
color: var(--dim);
}
kbd {
line-height: 1.5;
font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 0.75rem;
font-weight: 700;
background-color: rgb(38, 40, 44);
color: rgb(166, 167, 171);
padding: 0.15rem 0.3rem;
border-radius: 0.25rem;
border-width: 0.0625rem 0.0625rem 0.1875rem;
border-style: solid;
border-color: rgb(54, 57, 64);
border-image: initial;
}
</style>
<div class="backdrop" part="backdrop">
<div class="window" part="window">
<pre class="message" part="message"><span class="plugin" part="plugin"></span><span class="message-body" part="message-body"></span></pre>
<pre class="file" part="file"></pre>
<pre class="frame" part="frame"></pre>
<pre class="stack" part="stack"></pre>
<div class="tip" part="tip">
Click outside, press <kbd>Esc</kbd> key, or fix the code to dismiss.
</div>
</div>
</div>
`;
}
const A = /(?:[a-z]:\\|\/).*?:\d+:\d+/gi, _ = /^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm, {
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
HTMLElement: pe = class {
}
} = globalThis;
let me = class extends pe {
constructor(e, t = !1, n = !0) {
var o, r, i;
super(), w(this, "root"), w(this, "closeOnEsc"), w(this, "dialog"), this.root = this.attachShadow({
mode: "open"
}), this.root.innerHTML = fe(t), this.dialog = t, t || this.closeText(), _.lastIndex = 0;
const s = e.frame && _.test(e.frame), c = s ? e.message.replaceAll(_, "") : e.message;
e.plugin && this.text(".plugin", `[plugin:${e.plugin}] `), this.text(".message-body", c.trim());
const [a] = (((o = e.loc) == null ? void 0 : o.file) || e.id || "unknown file").split("?");
e.loc ? this.text(".file", `${a}:${e.loc.line}:${e.loc.column}`, n) : e.id && this.text(".file", a), s && this.text(".frame", ((r = e.frame) == null ? void 0 : r.trim()) || ""), this.text(".stack", e.stack, n), (i = this.root.querySelector(".window")) == null || i.addEventListener("click", (u) => {
u.stopPropagation();
}), this.addEventListener("click", () => {
this.close();
}), this.closeOnEsc = (u) => {
(u.key === "Escape" || u.code === "Escape") && this.close();
}, document.addEventListener("keydown", this.closeOnEsc);
}
text(e, t, n = !1) {
const o = this.root.querySelector(e);
if (n) {
let r = 0, i;
for (A.lastIndex = 0; i = A.exec(t); ) {
const {
0: s,
index: c
} = i;
if (c != null) {
const a = t.slice(r, c), u = document.location.protocol + s;
o.append(document.createTextNode(a));
const l = document.createElement("a");
l.textContent = s, l.className = "file-link", l.href = u, l.target = "_blank", o.append(l), r += a.length + s.length;
}
}
} else
o.textContent = t;
}
closeText() {
const e = this.root.querySelector(".tip");
e.style.display = "none";
}
close() {
var e;
this.dialog && ((e = this.parentNode) == null || e.removeChild(this), document.removeEventListener("keydown", this.closeOnEsc));
}
};
const z = "imitation-vue-error", {
customElements: E
} = globalThis;
E && !E.get(z) && E.define(z, me);
customElements.get("imitation-vue-error");
function be(e) {
e.directive("directiveDraggable", {
mounted(t, n) {
he(t, n.value);
}
});
}
export {
ve as directiveConversionTime,
be as directiveDraggable
};