devboi-test-component
Version:
An example of how to make and publish a web component using Lit & Vite
351 lines (350 loc) • 12.1 kB
JavaScript
import { LitElement as w, html as b } from "lit";
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const U = (i) => (e, t) => {
t !== void 0 ? t.addInitializer(() => {
customElements.define(i, e);
}) : customElements.define(i, e);
};
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const d = globalThis, $ = d.ShadowRoot && (d.ShadyCSS === void 0 || d.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, O = Symbol(), E = /* @__PURE__ */ new WeakMap();
let R = class {
constructor(e, t, s) {
if (this._$cssResult$ = !0, s !== O) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = e, this.t = t;
}
get styleSheet() {
let e = this.o;
const t = this.t;
if ($ && e === void 0) {
const s = t !== void 0 && t.length === 1;
s && (e = E.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), s && E.set(t, e));
}
return e;
}
toString() {
return this.cssText;
}
};
const M = (i) => new R(typeof i == "string" ? i : i + "", void 0, O), N = (i, e) => {
if ($) i.adoptedStyleSheets = e.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet);
else for (const t of e) {
const s = document.createElement("style"), r = d.litNonce;
r !== void 0 && s.setAttribute("nonce", r), s.textContent = t.cssText, i.appendChild(s);
}
}, S = $ ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((e) => {
let t = "";
for (const s of e.cssRules) t += s.cssText;
return M(t);
})(i) : i;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: T, defineProperty: j, getOwnPropertyDescriptor: z, getOwnPropertyNames: D, getOwnPropertySymbols: x, getPrototypeOf: L } = Object, h = globalThis, g = h.trustedTypes, q = g ? g.emptyScript : "", f = h.reactiveElementPolyfillSupport, l = (i, e) => i, p = { toAttribute(i, e) {
switch (e) {
case Boolean:
i = i ? q : null;
break;
case Object:
case Array:
i = i == null ? i : JSON.stringify(i);
}
return i;
}, fromAttribute(i, e) {
let t = i;
switch (e) {
case Boolean:
t = i !== null;
break;
case Number:
t = i === null ? null : Number(i);
break;
case Object:
case Array:
try {
t = JSON.parse(i);
} catch {
t = null;
}
}
return t;
} }, _ = (i, e) => !T(i, e), P = { attribute: !0, type: String, converter: p, reflect: !1, hasChanged: _ };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), h.litPropertyMetadata ?? (h.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
class c extends HTMLElement {
static addInitializer(e) {
this._$Ei(), (this.l ?? (this.l = [])).push(e);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(e, t = P) {
if (t.state && (t.attribute = !1), this._$Ei(), this.elementProperties.set(e, t), !t.noAccessor) {
const s = Symbol(), r = this.getPropertyDescriptor(e, s, t);
r !== void 0 && j(this.prototype, e, r);
}
}
static getPropertyDescriptor(e, t, s) {
const { get: r, set: o } = z(this.prototype, e) ?? { get() {
return this[t];
}, set(n) {
this[t] = n;
} };
return { get() {
return r == null ? void 0 : r.call(this);
}, set(n) {
const a = r == null ? void 0 : r.call(this);
o.call(this, n), this.requestUpdate(e, a, s);
}, configurable: !0, enumerable: !0 };
}
static getPropertyOptions(e) {
return this.elementProperties.get(e) ?? P;
}
static _$Ei() {
if (this.hasOwnProperty(l("elementProperties"))) return;
const e = L(this);
e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(l("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(l("properties"))) {
const t = this.properties, s = [...D(t), ...x(t)];
for (const r of s) this.createProperty(r, t[r]);
}
const e = this[Symbol.metadata];
if (e !== null) {
const t = litPropertyMetadata.get(e);
if (t !== void 0) for (const [s, r] of t) this.elementProperties.set(s, r);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [t, s] of this.elementProperties) {
const r = this._$Eu(t, s);
r !== void 0 && this._$Eh.set(r, t);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(e) {
const t = [];
if (Array.isArray(e)) {
const s = new Set(e.flat(1 / 0).reverse());
for (const r of s) t.unshift(S(r));
} else e !== void 0 && t.push(S(e));
return t;
}
static _$Eu(e, t) {
const s = t.attribute;
return s === !1 ? void 0 : typeof s == "string" ? s : typeof e == "string" ? e.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
}
_$Ev() {
var e;
this._$ES = new Promise((t) => this.enableUpdating = t), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (e = this.constructor.l) == null || e.forEach((t) => t(this));
}
addController(e) {
var t;
(this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(e), this.renderRoot !== void 0 && this.isConnected && ((t = e.hostConnected) == null || t.call(e));
}
removeController(e) {
var t;
(t = this._$EO) == null || t.delete(e);
}
_$E_() {
const e = /* @__PURE__ */ new Map(), t = this.constructor.elementProperties;
for (const s of t.keys()) this.hasOwnProperty(s) && (e.set(s, this[s]), delete this[s]);
e.size > 0 && (this._$Ep = e);
}
createRenderRoot() {
const e = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return N(e, this.constructor.elementStyles), e;
}
connectedCallback() {
var e;
this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (e = this._$EO) == null || e.forEach((t) => {
var s;
return (s = t.hostConnected) == null ? void 0 : s.call(t);
});
}
enableUpdating(e) {
}
disconnectedCallback() {
var e;
(e = this._$EO) == null || e.forEach((t) => {
var s;
return (s = t.hostDisconnected) == null ? void 0 : s.call(t);
});
}
attributeChangedCallback(e, t, s) {
this._$AK(e, s);
}
_$EC(e, t) {
var o;
const s = this.constructor.elementProperties.get(e), r = this.constructor._$Eu(e, s);
if (r !== void 0 && s.reflect === !0) {
const n = (((o = s.converter) == null ? void 0 : o.toAttribute) !== void 0 ? s.converter : p).toAttribute(t, s.type);
this._$Em = e, n == null ? this.removeAttribute(r) : this.setAttribute(r, n), this._$Em = null;
}
}
_$AK(e, t) {
var o;
const s = this.constructor, r = s._$Eh.get(e);
if (r !== void 0 && this._$Em !== r) {
const n = s.getPropertyOptions(r), a = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((o = n.converter) == null ? void 0 : o.fromAttribute) !== void 0 ? n.converter : p;
this._$Em = r, this[r] = a.fromAttribute(t, n.type), this._$Em = null;
}
}
requestUpdate(e, t, s) {
if (e !== void 0) {
if (s ?? (s = this.constructor.getPropertyOptions(e)), !(s.hasChanged ?? _)(this[e], t)) return;
this.P(e, t, s);
}
this.isUpdatePending === !1 && (this._$ES = this._$ET());
}
P(e, t, s) {
this._$AL.has(e) || this._$AL.set(e, t), s.reflect === !0 && this._$Em !== e && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(e);
}
async _$ET() {
this.isUpdatePending = !0;
try {
await this._$ES;
} catch (t) {
Promise.reject(t);
}
const e = this.scheduleUpdate();
return e != null && await e, !this.isUpdatePending;
}
scheduleUpdate() {
return this.performUpdate();
}
performUpdate() {
var s;
if (!this.isUpdatePending) return;
if (!this.hasUpdated) {
if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
for (const [o, n] of this._$Ep) this[o] = n;
this._$Ep = void 0;
}
const r = this.constructor.elementProperties;
if (r.size > 0) for (const [o, n] of r) n.wrapped !== !0 || this._$AL.has(o) || this[o] === void 0 || this.P(o, this[o], n);
}
let e = !1;
const t = this._$AL;
try {
e = this.shouldUpdate(t), e ? (this.willUpdate(t), (s = this._$EO) == null || s.forEach((r) => {
var o;
return (o = r.hostUpdate) == null ? void 0 : o.call(r);
}), this.update(t)) : this._$EU();
} catch (r) {
throw e = !1, this._$EU(), r;
}
e && this._$AE(t);
}
willUpdate(e) {
}
_$AE(e) {
var t;
(t = this._$EO) == null || t.forEach((s) => {
var r;
return (r = s.hostUpdated) == null ? void 0 : r.call(s);
}), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(e)), this.updated(e);
}
_$EU() {
this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(e) {
return !0;
}
update(e) {
this._$Ej && (this._$Ej = this._$Ej.forEach((t) => this._$EC(t, this[t]))), this._$EU();
}
updated(e) {
}
firstUpdated(e) {
}
}
c.elementStyles = [], c.shadowRootOptions = { mode: "open" }, c[l("elementProperties")] = /* @__PURE__ */ new Map(), c[l("finalized")] = /* @__PURE__ */ new Map(), f == null || f({ ReactiveElement: c }), (h.reactiveElementVersions ?? (h.reactiveElementVersions = [])).push("2.0.4");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const B = { attribute: !0, type: String, converter: p, reflect: !1, hasChanged: _ }, I = (i = B, e, t) => {
const { kind: s, metadata: r } = t;
let o = globalThis.litPropertyMetadata.get(r);
if (o === void 0 && globalThis.litPropertyMetadata.set(r, o = /* @__PURE__ */ new Map()), o.set(t.name, i), s === "accessor") {
const { name: n } = t;
return { set(a) {
const u = e.get.call(this);
e.set.call(this, a), this.requestUpdate(n, u, i);
}, init(a) {
return a !== void 0 && this.P(n, void 0, i), a;
} };
}
if (s === "setter") {
const { name: n } = t;
return function(a) {
const u = this[n];
e.call(this, a), this.requestUpdate(n, u, i);
};
}
throw Error("Unsupported decorator location: " + s);
};
function C(i) {
return (e, t) => typeof t == "object" ? I(i, e, t) : ((s, r, o) => {
const n = r.hasOwnProperty(o);
return r.constructor.createProperty(o, n ? { ...s, wrapped: !0 } : s), n ? Object.getOwnPropertyDescriptor(r, o) : void 0;
})(i, e, t);
}
var J = Object.defineProperty, K = Object.getOwnPropertyDescriptor, v = (i, e, t, s) => {
for (var r = s > 1 ? void 0 : s ? K(e, t) : e, o = i.length - 1, n; o >= 0; o--)
(n = i[o]) && (r = (s ? n(e, t, r) : n(r)) || r);
return s && r && J(e, t, r), r;
};
let m = class extends w {
constructor() {
super(...arguments), this.oneName = "Default Company Name";
}
render() {
return b`<pre>${this.oneName}</pre>`;
}
};
v([
C({ type: String })
], m.prototype, "oneName", 2);
m = v([
U("one-element")
], m);
var W = Object.defineProperty, k = Object.getOwnPropertyDescriptor, A = (i, e, t, s) => {
for (var r = s > 1 ? void 0 : s ? k(e, t) : e, o = i.length - 1, n; o >= 0; o--)
(n = i[o]) && (r = (s ? n(e, t, r) : n(r)) || r);
return s && r && W(e, t, r), r;
};
let y = class extends w {
constructor() {
super(...arguments), this.twoName = "Default Company Name";
}
render() {
return b`<pre>${this.twoName}</pre>`;
}
};
A([
C({ type: String })
], y.prototype, "twoName", 2);
y = A([
U("two-element")
], y);