analysis-renderer
Version:
svelte + vite + webComponent, dashboard card
273 lines (272 loc) • 6.22 kB
JavaScript
function d() {
}
function E(t) {
return t();
}
function M() {
return /* @__PURE__ */ Object.create(null);
}
function _(t) {
t.forEach(E);
}
function x(t) {
return typeof t == "function";
}
function q(t, e) {
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
}
function z(t) {
return Object.keys(t).length === 0;
}
function g(t, e) {
t.appendChild(e);
}
function O(t, e, n) {
t.insertBefore(e, n || null);
}
function A(t) {
t.parentNode && t.parentNode.removeChild(t);
}
function B(t) {
return document.createElement(t);
}
function $(t) {
return document.createTextNode(t);
}
function P() {
return $(" ");
}
function V(t, e, n, o) {
return t.addEventListener(e, n, o), () => t.removeEventListener(e, n, o);
}
function D(t) {
return Array.from(t.childNodes);
}
function N(t, e) {
e = "" + e, t.wholeText !== e && (t.data = e);
}
function F(t) {
const e = {};
for (const n of t)
e[n.name] = n.value;
return e;
}
let v;
function h(t) {
v = t;
}
const a = [], S = [], p = [], H = [], G = Promise.resolve();
let k = !1;
function I() {
k || (k = !0, G.then(b));
}
function w(t) {
p.push(t);
}
const y = /* @__PURE__ */ new Set();
let f = 0;
function b() {
if (f !== 0)
return;
const t = v;
do {
try {
for (; f < a.length; ) {
const e = a[f];
f++, h(e), J(e.$$);
}
} catch (e) {
throw a.length = 0, f = 0, e;
}
for (h(null), a.length = 0, f = 0; S.length; )
S.pop()();
for (let e = 0; e < p.length; e += 1) {
const n = p[e];
y.has(n) || (y.add(n), n());
}
p.length = 0;
} while (a.length);
for (; H.length; )
H.pop()();
k = !1, y.clear(), h(t);
}
function J(t) {
if (t.fragment !== null) {
t.update(), _(t.before_update);
const e = t.dirty;
t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(w);
}
}
const K = /* @__PURE__ */ new Set();
function Q(t, e) {
t && t.i && (K.delete(t), t.i(e));
}
function U(t, e, n, o) {
const { fragment: u, after_update: s } = t.$$;
u && u.m(e, n), o || w(() => {
const c = t.$$.on_mount.map(E).filter(x);
t.$$.on_destroy ? t.$$.on_destroy.push(...c) : _(c), t.$$.on_mount = [];
}), s.forEach(w);
}
function W(t, e) {
const n = t.$$;
n.fragment !== null && (_(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []);
}
function X(t, e) {
t.$$.dirty[0] === -1 && (a.push(t), I(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31;
}
function Y(t, e, n, o, u, s, c, m = [-1]) {
const i = v;
h(t);
const r = t.$$ = {
fragment: null,
ctx: [],
// state
props: s,
update: d,
not_equal: u,
bound: M(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(e.context || (i ? i.$$.context : [])),
// everything else
callbacks: M(),
dirty: m,
skip_bound: !1,
root: e.target || i.$$.root
};
c && c(r.root);
let C = !1;
if (r.ctx = n ? n(t, e.props || {}, (l, j, ...L) => {
const T = L.length ? L[0] : j;
return r.ctx && u(r.ctx[l], r.ctx[l] = T) && (!r.skip_bound && r.bound[l] && r.bound[l](T), C && X(t, l)), j;
}) : [], r.update(), C = !0, _(r.before_update), r.fragment = o ? o(r.ctx) : !1, e.target) {
if (e.hydrate) {
const l = D(e.target);
r.fragment && r.fragment.l(l), l.forEach(A);
} else
r.fragment && r.fragment.c();
e.intro && Q(t.$$.fragment), U(t, e.target, e.anchor, e.customElement), b();
}
h(i);
}
let R;
typeof HTMLElement == "function" && (R = class extends HTMLElement {
constructor() {
super(), this.attachShadow({ mode: "open" });
}
connectedCallback() {
const { on_mount: t } = this.$$;
this.$$.on_disconnect = t.map(E).filter(x);
for (const e in this.$$.slotted)
this.appendChild(this.$$.slotted[e]);
}
attributeChangedCallback(t, e, n) {
this[t] = n;
}
disconnectedCallback() {
_(this.$$.on_disconnect);
}
$destroy() {
W(this, 1), this.$destroy = d;
}
$on(t, e) {
if (!x(e))
return d;
const n = this.$$.callbacks[t] || (this.$$.callbacks[t] = []);
return n.push(e), () => {
const o = n.indexOf(e);
o !== -1 && n.splice(o, 1);
};
}
$set(t) {
this.$$set && !z(t) && (this.$$.skip_bound = !0, this.$$set(t), this.$$.skip_bound = !1);
}
});
function Z(t) {
let e, n, o, u, s, c, m;
return {
c() {
e = B("button"), n = $("count is "), o = $(
/*count*/
t[1]
), u = P(), s = $(
/*url*/
t[0]
), this.c = d;
},
m(i, r) {
O(i, e, r), g(e, n), g(e, o), g(e, u), g(e, s), c || (m = V(
e,
"click",
/*increment*/
t[2]
), c = !0);
},
p(i, [r]) {
r & /*count*/
2 && N(
o,
/*count*/
i[1]
), r & /*url*/
1 && N(
s,
/*url*/
i[0]
);
},
i: d,
o: d,
d(i) {
i && A(e), c = !1, m();
}
};
}
function tt(t, e, n) {
let o = 0, { url: u } = e;
const s = () => {
n(1, o += 1);
};
return t.$$set = (c) => {
"url" in c && n(0, u = c.url);
}, t.$$.update = () => {
t.$$.dirty & /*url*/
1 && u && fetch(u).then((c) => c.json()).then((c) => console.log(c)), t.$$.dirty & /*count*/
2 && o > 10 && (alert("不能超过10次"), n(1, o = 10));
}, [u, o, s];
}
class et extends R {
constructor(e) {
super(), this.shadowRoot.innerHTML = "<style>button{color:aqua;font-size:20px;font-weight:500;padding:8px 12px;border:1px solid #ddd;margin:auto}</style>", Y(
this,
{
target: this.shadowRoot,
props: F(this.attributes),
customElement: !0
},
tt,
Z,
q,
{ url: 0 },
null
), e && (e.target && O(e.target, this, e.anchor), e.props && (this.$set(e.props), b()));
}
static get observedAttributes() {
return ["url"];
}
get url() {
return this.$$.ctx[0];
}
set url(e) {
this.$$set({ url: e }), b();
}
}
customElements.define("my-custom-counter", et);
export {
et as Counter
};