album-viewer
Version:
The `album-viewer` web component fetches and displays albums from a specified [Bandcamp](https://bandcamp.com) artist
384 lines (383 loc) • 13.1 kB
JavaScript
import { css as U, LitElement as A, html as C } from "lit";
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const v = (i) => (t, e) => {
e !== void 0 ? e.addInitializer(() => {
customElements.define(i, t);
}) : customElements.define(i, t);
};
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const u = globalThis, E = u.ShadowRoot && (u.ShadyCSS === void 0 || u.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, P = Symbol(), b = /* @__PURE__ */ new WeakMap();
let O = class {
constructor(t, e, s) {
if (this._$cssResult$ = !0, s !== P) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = t, this.t = e;
}
get styleSheet() {
let t = this.o;
const e = this.t;
if (E && t === void 0) {
const s = e !== void 0 && e.length === 1;
s && (t = b.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && b.set(e, t));
}
return t;
}
toString() {
return this.cssText;
}
};
const R = (i) => new O(typeof i == "string" ? i : i + "", void 0, P), M = (i, t) => {
if (E) i.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
else for (const e of t) {
const s = document.createElement("style"), r = u.litNonce;
r !== void 0 && s.setAttribute("nonce", r), s.textContent = e.cssText, i.appendChild(s);
}
}, S = E ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((t) => {
let e = "";
for (const s of t.cssRules) e += s.cssText;
return R(e);
})(i) : i;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: j, defineProperty: T, getOwnPropertyDescriptor: x, getOwnPropertyNames: z, getOwnPropertySymbols: D, getPrototypeOf: L } = Object, h = globalThis, g = h.trustedTypes, k = g ? g.emptyScript : "", $ = h.reactiveElementPolyfillSupport, d = (i, t) => i, f = { toAttribute(i, t) {
switch (t) {
case Boolean:
i = i ? k : null;
break;
case Object:
case Array:
i = i == null ? i : JSON.stringify(i);
}
return i;
}, fromAttribute(i, t) {
let e = i;
switch (t) {
case Boolean:
e = i !== null;
break;
case Number:
e = i === null ? null : Number(i);
break;
case Object:
case Array:
try {
e = JSON.parse(i);
} catch {
e = null;
}
}
return e;
} }, _ = (i, t) => !j(i, t), w = { attribute: !0, type: String, converter: f, reflect: !1, hasChanged: _ };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), h.litPropertyMetadata ?? (h.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
class l extends HTMLElement {
static addInitializer(t) {
this._$Ei(), (this.l ?? (this.l = [])).push(t);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(t, e = w) {
if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) {
const s = Symbol(), r = this.getPropertyDescriptor(t, s, e);
r !== void 0 && T(this.prototype, t, r);
}
}
static getPropertyDescriptor(t, e, s) {
const { get: r, set: n } = x(this.prototype, t) ?? { get() {
return this[e];
}, set(o) {
this[e] = o;
} };
return { get() {
return r == null ? void 0 : r.call(this);
}, set(o) {
const a = r == null ? void 0 : r.call(this);
n.call(this, o), this.requestUpdate(t, a, s);
}, configurable: !0, enumerable: !0 };
}
static getPropertyOptions(t) {
return this.elementProperties.get(t) ?? w;
}
static _$Ei() {
if (this.hasOwnProperty(d("elementProperties"))) return;
const t = L(this);
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(d("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(d("properties"))) {
const e = this.properties, s = [...z(e), ...D(e)];
for (const r of s) this.createProperty(r, e[r]);
}
const t = this[Symbol.metadata];
if (t !== null) {
const e = litPropertyMetadata.get(t);
if (e !== void 0) for (const [s, r] of e) this.elementProperties.set(s, r);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [e, s] of this.elementProperties) {
const r = this._$Eu(e, s);
r !== void 0 && this._$Eh.set(r, e);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(t) {
const e = [];
if (Array.isArray(t)) {
const s = new Set(t.flat(1 / 0).reverse());
for (const r of s) e.unshift(S(r));
} else t !== void 0 && e.push(S(t));
return e;
}
static _$Eu(t, e) {
const s = e.attribute;
return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
}
_$Ev() {
var t;
this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (t = this.constructor.l) == null || t.forEach((e) => e(this));
}
addController(t) {
var e;
(this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t), this.renderRoot !== void 0 && this.isConnected && ((e = t.hostConnected) == null || e.call(t));
}
removeController(t) {
var e;
(e = this._$EO) == null || e.delete(t);
}
_$E_() {
const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
for (const s of e.keys()) this.hasOwnProperty(s) && (t.set(s, this[s]), delete this[s]);
t.size > 0 && (this._$Ep = t);
}
createRenderRoot() {
const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return M(t, this.constructor.elementStyles), t;
}
connectedCallback() {
var t;
this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostConnected) == null ? void 0 : s.call(e);
});
}
enableUpdating(t) {
}
disconnectedCallback() {
var t;
(t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostDisconnected) == null ? void 0 : s.call(e);
});
}
attributeChangedCallback(t, e, s) {
this._$AK(t, s);
}
_$EC(t, e) {
var n;
const s = this.constructor.elementProperties.get(t), r = this.constructor._$Eu(t, s);
if (r !== void 0 && s.reflect === !0) {
const o = (((n = s.converter) == null ? void 0 : n.toAttribute) !== void 0 ? s.converter : f).toAttribute(e, s.type);
this._$Em = t, o == null ? this.removeAttribute(r) : this.setAttribute(r, o), this._$Em = null;
}
}
_$AK(t, e) {
var n;
const s = this.constructor, r = s._$Eh.get(t);
if (r !== void 0 && this._$Em !== r) {
const o = s.getPropertyOptions(r), a = typeof o.converter == "function" ? { fromAttribute: o.converter } : ((n = o.converter) == null ? void 0 : n.fromAttribute) !== void 0 ? o.converter : f;
this._$Em = r, this[r] = a.fromAttribute(e, o.type), this._$Em = null;
}
}
requestUpdate(t, e, s) {
if (t !== void 0) {
if (s ?? (s = this.constructor.getPropertyOptions(t)), !(s.hasChanged ?? _)(this[t], e)) return;
this.P(t, e, s);
}
this.isUpdatePending === !1 && (this._$ES = this._$ET());
}
P(t, e, s) {
this._$AL.has(t) || this._$AL.set(t, e), s.reflect === !0 && this._$Em !== t && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t);
}
async _$ET() {
this.isUpdatePending = !0;
try {
await this._$ES;
} catch (e) {
Promise.reject(e);
}
const t = this.scheduleUpdate();
return t != null && await t, !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 [n, o] of this._$Ep) this[n] = o;
this._$Ep = void 0;
}
const r = this.constructor.elementProperties;
if (r.size > 0) for (const [n, o] of r) o.wrapped !== !0 || this._$AL.has(n) || this[n] === void 0 || this.P(n, this[n], o);
}
let t = !1;
const e = this._$AL;
try {
t = this.shouldUpdate(e), t ? (this.willUpdate(e), (s = this._$EO) == null || s.forEach((r) => {
var n;
return (n = r.hostUpdate) == null ? void 0 : n.call(r);
}), this.update(e)) : this._$EU();
} catch (r) {
throw t = !1, this._$EU(), r;
}
t && this._$AE(e);
}
willUpdate(t) {
}
_$AE(t) {
var e;
(e = this._$EO) == null || e.forEach((s) => {
var r;
return (r = s.hostUpdated) == null ? void 0 : r.call(s);
}), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
}
_$EU() {
this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(t) {
return !0;
}
update(t) {
this._$Ej && (this._$Ej = this._$Ej.forEach((e) => this._$EC(e, this[e]))), this._$EU();
}
updated(t) {
}
firstUpdated(t) {
}
}
l.elementStyles = [], l.shadowRootOptions = { mode: "open" }, l[d("elementProperties")] = /* @__PURE__ */ new Map(), l[d("finalized")] = /* @__PURE__ */ new Map(), $ == null || $({ ReactiveElement: l }), (h.reactiveElementVersions ?? (h.reactiveElementVersions = [])).push("2.0.4");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const N = { attribute: !0, type: String, converter: f, reflect: !1, hasChanged: _ }, q = (i = N, t, e) => {
const { kind: s, metadata: r } = e;
let n = globalThis.litPropertyMetadata.get(r);
if (n === void 0 && globalThis.litPropertyMetadata.set(r, n = /* @__PURE__ */ new Map()), n.set(e.name, i), s === "accessor") {
const { name: o } = e;
return { set(a) {
const y = t.get.call(this);
t.set.call(this, a), this.requestUpdate(o, y, i);
}, init(a) {
return a !== void 0 && this.P(o, void 0, i), a;
} };
}
if (s === "setter") {
const { name: o } = e;
return function(a) {
const y = this[o];
t.call(this, a), this.requestUpdate(o, y, i);
};
}
throw Error("Unsupported decorator location: " + s);
};
function m(i) {
return (t, e) => typeof e == "object" ? q(i, t, e) : ((s, r, n) => {
const o = r.hasOwnProperty(n);
return r.constructor.createProperty(n, o ? { ...s, wrapped: !0 } : s), o ? Object.getOwnPropertyDescriptor(r, n) : void 0;
})(i, t, e);
}
const B = "https://api.music.devboi.xyz/v1/album-viewer", W = (i, t, e = "large", s = "ffffff", r = "0687f5") => `https://bandcamp.com/EmbeddedPlayer/${i}=${t}/size=${e}/bgcol=${s}/linkcol=${r}/transparent=true/`;
var H = Object.defineProperty, I = Object.getOwnPropertyDescriptor, p = (i, t, e, s) => {
for (var r = s > 1 ? void 0 : s ? I(t, e) : t, n = i.length - 1, o; n >= 0; n--)
(o = i[n]) && (r = (s ? o(t, e, r) : o(r)) || r);
return s && r && H(t, e, r), r;
};
let c = class extends A {
constructor() {
super(...arguments), this.name = "", this.iframeWidth = "350px", this.iframeHeight = "442px", this.iframeBorder = "0";
}
firstUpdated() {
this.fetchAlbumData();
}
async fetchAlbumData() {
const i = `${B}/?name=${this.name}`;
try {
const t = await fetch(i, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if (!t.ok)
throw new Error("Network response was not ok");
const e = await t.json();
this.displayAlbums(e);
} catch (t) {
console.error("Failed to fetch album data:", t);
}
}
displayAlbums(i) {
var e;
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".album-viewer");
i.forEach((s) => {
const r = s.type, n = document.createElement("iframe");
n.style.border = this.iframeBorder, n.style.width = this.iframeWidth, n.style.height = this.iframeHeight, n.src = W(r, s.id), t == null || t.appendChild(n);
});
}
render() {
return C`
<pre class="album-viewer">
<!-- Album Data will be injected here -->
</pre>
`;
}
};
c.styles = U`
.album-viewer {
display: flex;
justify-content: top;
overflow-x: auto;
}
`;
p([
m({ type: String })
], c.prototype, "name", 2);
p([
m({ type: String })
], c.prototype, "iframeWidth", 2);
p([
m({ type: String })
], c.prototype, "iframeHeight", 2);
p([
m({ type: String })
], c.prototype, "iframeBorder", 2);
c = p([
v("album-viewer")
], c);
export {
c as AlbumViewer
};