UNPKG

@joelmturner/zine-viewer-web-component

Version:
950 lines (934 loc) 34.1 kB
/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const z = globalThis, q = z.ShadowRoot && (z.ShadyCSS === void 0 || z.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, Z = Symbol(), Y = /* @__PURE__ */ new WeakMap(); let ut = class { constructor(t, e, i) { if (this._$cssResult$ = !0, i !== Z) 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 (q && t === void 0) { const i = e !== void 0 && e.length === 1; i && (t = Y.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), i && Y.set(e, t)); } return t; } toString() { return this.cssText; } }; const $t = (s) => new ut(typeof s == "string" ? s : s + "", void 0, Z), mt = (s, ...t) => { const e = s.length === 1 ? s[0] : t.reduce((i, n, o) => i + ((r) => { if (r._$cssResult$ === !0) return r.cssText; if (typeof r == "number") return r; throw Error("Value passed to 'css' function must be a 'css' function result: " + r + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security."); })(n) + s[o + 1], s[0]); return new ut(e, s, Z); }, bt = (s, t) => { if (q) s.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet); else for (const e of t) { const i = document.createElement("style"), n = z.litNonce; n !== void 0 && i.setAttribute("nonce", n), i.textContent = e.cssText, s.appendChild(i); } }, G = q ? (s) => s : (s) => s instanceof CSSStyleSheet ? ((t) => { let e = ""; for (const i of t.cssRules) e += i.cssText; return $t(e); })(s) : s; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const { is: _t, defineProperty: At, getOwnPropertyDescriptor: vt, getOwnPropertyNames: wt, getOwnPropertySymbols: St, getPrototypeOf: Et } = Object, m = globalThis, Q = m.trustedTypes, kt = Q ? Q.emptyScript : "", D = m.reactiveElementPolyfillSupport, x = (s, t) => s, T = { toAttribute(s, t) { switch (t) { case Boolean: s = s ? kt : null; break; case Object: case Array: s = s == null ? s : JSON.stringify(s); } return s; }, fromAttribute(s, t) { let e = s; switch (t) { case Boolean: e = s !== null; break; case Number: e = s === null ? null : Number(s); break; case Object: case Array: try { e = JSON.parse(s); } catch { e = null; } } return e; } }, J = (s, t) => !_t(s, t), X = { attribute: !0, type: String, converter: T, reflect: !1, hasChanged: J }; Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), m.litPropertyMetadata ?? (m.litPropertyMetadata = /* @__PURE__ */ new WeakMap()); class w 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 = X) { if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) { const i = Symbol(), n = this.getPropertyDescriptor(t, i, e); n !== void 0 && At(this.prototype, t, n); } } static getPropertyDescriptor(t, e, i) { const { get: n, set: o } = vt(this.prototype, t) ?? { get() { return this[e]; }, set(r) { this[e] = r; } }; return { get() { return n == null ? void 0 : n.call(this); }, set(r) { const l = n == null ? void 0 : n.call(this); o.call(this, r), this.requestUpdate(t, l, i); }, configurable: !0, enumerable: !0 }; } static getPropertyOptions(t) { return this.elementProperties.get(t) ?? X; } static _$Ei() { if (this.hasOwnProperty(x("elementProperties"))) return; const t = Et(this); t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties); } static finalize() { if (this.hasOwnProperty(x("finalized"))) return; if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(x("properties"))) { const e = this.properties, i = [...wt(e), ...St(e)]; for (const n of i) this.createProperty(n, e[n]); } const t = this[Symbol.metadata]; if (t !== null) { const e = litPropertyMetadata.get(t); if (e !== void 0) for (const [i, n] of e) this.elementProperties.set(i, n); } this._$Eh = /* @__PURE__ */ new Map(); for (const [e, i] of this.elementProperties) { const n = this._$Eu(e, i); n !== void 0 && this._$Eh.set(n, e); } this.elementStyles = this.finalizeStyles(this.styles); } static finalizeStyles(t) { const e = []; if (Array.isArray(t)) { const i = new Set(t.flat(1 / 0).reverse()); for (const n of i) e.unshift(G(n)); } else t !== void 0 && e.push(G(t)); return e; } static _$Eu(t, e) { const i = e.attribute; return i === !1 ? void 0 : typeof i == "string" ? i : 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 i of e.keys()) this.hasOwnProperty(i) && (t.set(i, this[i]), delete this[i]); t.size > 0 && (this._$Ep = t); } createRenderRoot() { const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions); return bt(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 i; return (i = e.hostConnected) == null ? void 0 : i.call(e); }); } enableUpdating(t) { } disconnectedCallback() { var t; (t = this._$EO) == null || t.forEach((e) => { var i; return (i = e.hostDisconnected) == null ? void 0 : i.call(e); }); } attributeChangedCallback(t, e, i) { this._$AK(t, i); } _$EC(t, e) { var o; const i = this.constructor.elementProperties.get(t), n = this.constructor._$Eu(t, i); if (n !== void 0 && i.reflect === !0) { const r = (((o = i.converter) == null ? void 0 : o.toAttribute) !== void 0 ? i.converter : T).toAttribute(e, i.type); this._$Em = t, r == null ? this.removeAttribute(n) : this.setAttribute(n, r), this._$Em = null; } } _$AK(t, e) { var o; const i = this.constructor, n = i._$Eh.get(t); if (n !== void 0 && this._$Em !== n) { const r = i.getPropertyOptions(n), l = typeof r.converter == "function" ? { fromAttribute: r.converter } : ((o = r.converter) == null ? void 0 : o.fromAttribute) !== void 0 ? r.converter : T; this._$Em = n, this[n] = l.fromAttribute(e, r.type), this._$Em = null; } } requestUpdate(t, e, i) { if (t !== void 0) { if (i ?? (i = this.constructor.getPropertyOptions(t)), !(i.hasChanged ?? J)(this[t], e)) return; this.P(t, e, i); } this.isUpdatePending === !1 && (this._$ES = this._$ET()); } P(t, e, i) { this._$AL.has(t) || this._$AL.set(t, e), i.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 i; if (!this.isUpdatePending) return; if (!this.hasUpdated) { if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) { for (const [o, r] of this._$Ep) this[o] = r; this._$Ep = void 0; } const n = this.constructor.elementProperties; if (n.size > 0) for (const [o, r] of n) r.wrapped !== !0 || this._$AL.has(o) || this[o] === void 0 || this.P(o, this[o], r); } let t = !1; const e = this._$AL; try { t = this.shouldUpdate(e), t ? (this.willUpdate(e), (i = this._$EO) == null || i.forEach((n) => { var o; return (o = n.hostUpdate) == null ? void 0 : o.call(n); }), this.update(e)) : this._$EU(); } catch (n) { throw t = !1, this._$EU(), n; } t && this._$AE(e); } willUpdate(t) { } _$AE(t) { var e; (e = this._$EO) == null || e.forEach((i) => { var n; return (n = i.hostUpdated) == null ? void 0 : n.call(i); }), 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) { } } w.elementStyles = [], w.shadowRootOptions = { mode: "open" }, w[x("elementProperties")] = /* @__PURE__ */ new Map(), w[x("finalized")] = /* @__PURE__ */ new Map(), D == null || D({ ReactiveElement: w }), (m.reactiveElementVersions ?? (m.reactiveElementVersions = [])).push("2.0.4"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const C = globalThis, M = C.trustedTypes, tt = M ? M.createPolicy("lit-html", { createHTML: (s) => s }) : void 0, ct = "$lit$", $ = `lit$${Math.random().toFixed(9).slice(2)}$`, pt = "?" + $, Pt = `<${pt}>`, A = document, U = () => A.createComment(""), O = (s) => s === null || typeof s != "object" && typeof s != "function", K = Array.isArray, xt = (s) => K(s) || typeof (s == null ? void 0 : s[Symbol.iterator]) == "function", j = `[ \f\r]`, k = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, et = /-->/g, it = />/g, b = RegExp(`>|${j}(?:([^\\s"'>=/]+)(${j}*=${j}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`, "g"), st = /'/g, nt = /"/g, ft = /^(?:script|style|textarea|title)$/i, Ct = (s) => (t, ...e) => ({ _$litType$: s, strings: t, values: e }), rt = Ct(1), S = Symbol.for("lit-noChange"), c = Symbol.for("lit-nothing"), ot = /* @__PURE__ */ new WeakMap(), _ = A.createTreeWalker(A, 129); function gt(s, t) { if (!K(s) || !s.hasOwnProperty("raw")) throw Error("invalid template strings array"); return tt !== void 0 ? tt.createHTML(t) : t; } const Ht = (s, t) => { const e = s.length - 1, i = []; let n, o = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", r = k; for (let l = 0; l < e; l++) { const a = s[l]; let d, u, h = -1, p = 0; for (; p < a.length && (r.lastIndex = p, u = r.exec(a), u !== null); ) p = r.lastIndex, r === k ? u[1] === "!--" ? r = et : u[1] !== void 0 ? r = it : u[2] !== void 0 ? (ft.test(u[2]) && (n = RegExp("</" + u[2], "g")), r = b) : u[3] !== void 0 && (r = b) : r === b ? u[0] === ">" ? (r = n ?? k, h = -1) : u[1] === void 0 ? h = -2 : (h = r.lastIndex - u[2].length, d = u[1], r = u[3] === void 0 ? b : u[3] === '"' ? nt : st) : r === nt || r === st ? r = b : r === et || r === it ? r = k : (r = b, n = void 0); const y = r === b && s[l + 1].startsWith("/>") ? " " : ""; o += r === k ? a + Pt : h >= 0 ? (i.push(d), a.slice(0, h) + ct + a.slice(h) + $ + y) : a + $ + (h === -2 ? l : y); } return [gt(s, o + (s[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), i]; }; class B { constructor({ strings: t, _$litType$: e }, i) { let n; this.parts = []; let o = 0, r = 0; const l = t.length - 1, a = this.parts, [d, u] = Ht(t, e); if (this.el = B.createElement(d, i), _.currentNode = this.el.content, e === 2 || e === 3) { const h = this.el.content.firstChild; h.replaceWith(...h.childNodes); } for (; (n = _.nextNode()) !== null && a.length < l; ) { if (n.nodeType === 1) { if (n.hasAttributes()) for (const h of n.getAttributeNames()) if (h.endsWith(ct)) { const p = u[r++], y = n.getAttribute(h).split($), R = /([.?@])?(.*)/.exec(p); a.push({ type: 1, index: o, name: R[2], strings: y, ctor: R[1] === "." ? Ot : R[1] === "?" ? Bt : R[1] === "@" ? It : L }), n.removeAttribute(h); } else h.startsWith($) && (a.push({ type: 6, index: o }), n.removeAttribute(h)); if (ft.test(n.tagName)) { const h = n.textContent.split($), p = h.length - 1; if (p > 0) { n.textContent = M ? M.emptyScript : ""; for (let y = 0; y < p; y++) n.append(h[y], U()), _.nextNode(), a.push({ type: 2, index: ++o }); n.append(h[p], U()); } } } else if (n.nodeType === 8) if (n.data === pt) a.push({ type: 2, index: o }); else { let h = -1; for (; (h = n.data.indexOf($, h + 1)) !== -1; ) a.push({ type: 7, index: o }), h += $.length - 1; } o++; } } static createElement(t, e) { const i = A.createElement("template"); return i.innerHTML = t, i; } } function E(s, t, e = s, i) { var r, l; if (t === S) return t; let n = i !== void 0 ? (r = e._$Co) == null ? void 0 : r[i] : e._$Cl; const o = O(t) ? void 0 : t._$litDirective$; return (n == null ? void 0 : n.constructor) !== o && ((l = n == null ? void 0 : n._$AO) == null || l.call(n, !1), o === void 0 ? n = void 0 : (n = new o(s), n._$AT(s, e, i)), i !== void 0 ? (e._$Co ?? (e._$Co = []))[i] = n : e._$Cl = n), n !== void 0 && (t = E(s, n._$AS(s, t.values), n, i)), t; } class Ut { constructor(t, e) { this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e; } get parentNode() { return this._$AM.parentNode; } get _$AU() { return this._$AM._$AU; } u(t) { const { el: { content: e }, parts: i } = this._$AD, n = ((t == null ? void 0 : t.creationScope) ?? A).importNode(e, !0); _.currentNode = n; let o = _.nextNode(), r = 0, l = 0, a = i[0]; for (; a !== void 0; ) { if (r === a.index) { let d; a.type === 2 ? d = new I(o, o.nextSibling, this, t) : a.type === 1 ? d = new a.ctor(o, a.name, a.strings, this, t) : a.type === 6 && (d = new Rt(o, this, t)), this._$AV.push(d), a = i[++l]; } r !== (a == null ? void 0 : a.index) && (o = _.nextNode(), r++); } return _.currentNode = A, n; } p(t) { let e = 0; for (const i of this._$AV) i !== void 0 && (i.strings !== void 0 ? (i._$AI(t, i, e), e += i.strings.length - 2) : i._$AI(t[e])), e++; } } class I { get _$AU() { var t; return ((t = this._$AM) == null ? void 0 : t._$AU) ?? this._$Cv; } constructor(t, e, i, n) { this.type = 2, this._$AH = c, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = i, this.options = n, this._$Cv = (n == null ? void 0 : n.isConnected) ?? !0; } get parentNode() { let t = this._$AA.parentNode; const e = this._$AM; return e !== void 0 && (t == null ? void 0 : t.nodeType) === 11 && (t = e.parentNode), t; } get startNode() { return this._$AA; } get endNode() { return this._$AB; } _$AI(t, e = this) { t = E(this, t, e), O(t) ? t === c || t == null || t === "" ? (this._$AH !== c && this._$AR(), this._$AH = c) : t !== this._$AH && t !== S && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : xt(t) ? this.k(t) : this._(t); } O(t) { return this._$AA.parentNode.insertBefore(t, this._$AB); } T(t) { this._$AH !== t && (this._$AR(), this._$AH = this.O(t)); } _(t) { this._$AH !== c && O(this._$AH) ? this._$AA.nextSibling.data = t : this.T(A.createTextNode(t)), this._$AH = t; } $(t) { var o; const { values: e, _$litType$: i } = t, n = typeof i == "number" ? this._$AC(t) : (i.el === void 0 && (i.el = B.createElement(gt(i.h, i.h[0]), this.options)), i); if (((o = this._$AH) == null ? void 0 : o._$AD) === n) this._$AH.p(e); else { const r = new Ut(n, this), l = r.u(this.options); r.p(e), this.T(l), this._$AH = r; } } _$AC(t) { let e = ot.get(t.strings); return e === void 0 && ot.set(t.strings, e = new B(t)), e; } k(t) { K(this._$AH) || (this._$AH = [], this._$AR()); const e = this._$AH; let i, n = 0; for (const o of t) n === e.length ? e.push(i = new I(this.O(U()), this.O(U()), this, this.options)) : i = e[n], i._$AI(o), n++; n < e.length && (this._$AR(i && i._$AB.nextSibling, n), e.length = n); } _$AR(t = this._$AA.nextSibling, e) { var i; for ((i = this._$AP) == null ? void 0 : i.call(this, !1, !0, e); t && t !== this._$AB; ) { const n = t.nextSibling; t.remove(), t = n; } } setConnected(t) { var e; this._$AM === void 0 && (this._$Cv = t, (e = this._$AP) == null || e.call(this, t)); } } class L { get tagName() { return this.element.tagName; } get _$AU() { return this._$AM._$AU; } constructor(t, e, i, n, o) { this.type = 1, this._$AH = c, this._$AN = void 0, this.element = t, this.name = e, this._$AM = n, this.options = o, i.length > 2 || i[0] !== "" || i[1] !== "" ? (this._$AH = Array(i.length - 1).fill(new String()), this.strings = i) : this._$AH = c; } _$AI(t, e = this, i, n) { const o = this.strings; let r = !1; if (o === void 0) t = E(this, t, e, 0), r = !O(t) || t !== this._$AH && t !== S, r && (this._$AH = t); else { const l = t; let a, d; for (t = o[0], a = 0; a < o.length - 1; a++) d = E(this, l[i + a], e, a), d === S && (d = this._$AH[a]), r || (r = !O(d) || d !== this._$AH[a]), d === c ? t = c : t !== c && (t += (d ?? "") + o[a + 1]), this._$AH[a] = d; } r && !n && this.j(t); } j(t) { t === c ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? ""); } } class Ot extends L { constructor() { super(...arguments), this.type = 3; } j(t) { this.element[this.name] = t === c ? void 0 : t; } } class Bt extends L { constructor() { super(...arguments), this.type = 4; } j(t) { this.element.toggleAttribute(this.name, !!t && t !== c); } } class It extends L { constructor(t, e, i, n, o) { super(t, e, i, n, o), this.type = 5; } _$AI(t, e = this) { if ((t = E(this, t, e, 0) ?? c) === S) return; const i = this._$AH, n = t === c && i !== c || t.capture !== i.capture || t.once !== i.once || t.passive !== i.passive, o = t !== c && (i === c || n); n && this.element.removeEventListener(this.name, this, i), o && this.element.addEventListener(this.name, this, t), this._$AH = t; } handleEvent(t) { var e; typeof this._$AH == "function" ? this._$AH.call(((e = this.options) == null ? void 0 : e.host) ?? this.element, t) : this._$AH.handleEvent(t); } } class Rt { constructor(t, e, i) { this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = i; } get _$AU() { return this._$AM._$AU; } _$AI(t) { E(this, t); } } const F = C.litHtmlPolyfillSupport; F == null || F(B, I), (C.litHtmlVersions ?? (C.litHtmlVersions = [])).push("3.2.1"); const zt = (s, t, e) => { const i = (e == null ? void 0 : e.renderBefore) ?? t; let n = i._$litPart$; if (n === void 0) { const o = (e == null ? void 0 : e.renderBefore) ?? null; i._$litPart$ = n = new I(t.insertBefore(U(), o), o, void 0, e ?? {}); } return n._$AI(s), n; }; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ let H = class extends w { constructor() { super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0; } createRenderRoot() { var e; const t = super.createRenderRoot(); return (e = this.renderOptions).renderBefore ?? (e.renderBefore = t.firstChild), t; } update(t) { const e = this.render(); this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = zt(e, this.renderRoot, this.renderOptions); } connectedCallback() { var t; super.connectedCallback(), (t = this._$Do) == null || t.setConnected(!0); } disconnectedCallback() { var t; super.disconnectedCallback(), (t = this._$Do) == null || t.setConnected(!1); } render() { return S; } }; var dt; H._$litElement$ = !0, H.finalized = !0, (dt = globalThis.litElementHydrateSupport) == null || dt.call(globalThis, { LitElement: H }); const W = globalThis.litElementPolyfillSupport; W == null || W({ LitElement: H }); (globalThis.litElementVersions ?? (globalThis.litElementVersions = [])).push("4.1.1"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const Nt = (s) => (t, e) => { e !== void 0 ? e.addInitializer(() => { customElements.define(s, t); }) : customElements.define(s, t); }; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const Tt = { attribute: !0, type: String, converter: T, reflect: !1, hasChanged: J }, Mt = (s = Tt, t, e) => { const { kind: i, metadata: n } = e; let o = globalThis.litPropertyMetadata.get(n); if (o === void 0 && globalThis.litPropertyMetadata.set(n, o = /* @__PURE__ */ new Map()), o.set(e.name, s), i === "accessor") { const { name: r } = e; return { set(l) { const a = t.get.call(this); t.set.call(this, l), this.requestUpdate(r, a, s); }, init(l) { return l !== void 0 && this.P(r, void 0, s), l; } }; } if (i === "setter") { const { name: r } = e; return function(l) { const a = this[r]; t.call(this, l), this.requestUpdate(r, a, s); }; } throw Error("Unsupported decorator location: " + i); }; function v(s) { return (t, e) => typeof e == "object" ? Mt(s, t, e) : ((i, n, o) => { const r = n.hasOwnProperty(o); return n.constructor.createProperty(o, r ? { ...i, wrapped: !0 } : i), r ? Object.getOwnPropertyDescriptor(n, o) : void 0; })(s, t, e); } /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ function yt(s) { return v({ ...s, state: !0, attribute: !1 }); } function at(s, t) { if (s) try { const e = JSON.parse(s); return Array.isArray(e) ? e.map( (i, n) => Array.isArray(i) ? { imgSrc: i[0], backImgSrc: i[1], index: n } : { imgSrc: i.img, backImgSrc: i.backImg, index: n } ) : V(t); } catch { return V(t); } return V(t); } function V(s) { return Array.from(s.children).map((t, e) => { const i = t.getAttribute("img-src"), n = t.getAttribute("back-img-src"); return { imgSrc: i, backImgSrc: n, index: e }; }); } function ht(s) { return { pageCount: s, currentPage: 0 }; } function Lt(s, t) { return s < t.currentPage; } function P(s) { return s.currentPage < s.pageCount; } function N(s) { return s.currentPage > 0; } function Dt(s) { return P(s) ? { pageCount: s.pageCount, currentPage: s.currentPage + 1 } : null; } function jt(s) { return N(s) ? { pageCount: s.pageCount, currentPage: s.currentPage - 1 } : null; } function Ft(s, t) { const { pageCount: e, currentPage: i } = s, n = t !== "backward", o = []; for (let r = 0; r < e; r++) o.push( n ? Wt(e, i, r) : Vt(e, i, r) ); return o; } function Wt(s, t, e) { return e === 0 && t <= 1 ? s + 1 : e < t ? s - (t - e) : s - e; } function Vt(s, t, e) { return e === s - 1 && t >= s - 1 ? s + 1 : e === t ? s : e < t ? e : s - e; } const lt = { pageWidth: 291, pageHeight: 450 }, qt = { "letter-8up": lt, // half-sheet 5.5×8.5 in — same 11:17 ratio as letter-8up "letter-half": lt, a5: { pageWidth: 148, pageHeight: 210 }, a6: { pageWidth: 105, pageHeight: 148 }, square: { pageWidth: 300, pageHeight: 300 }, "digest-6x9": { pageWidth: 240, pageHeight: 360 } }; function Zt(s) { if (s == null || s.trim() === "") return null; const t = s.trim().toLowerCase(), e = qt[t]; return e ? { ...e } : null; } var Jt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, g = (s, t, e, i) => { for (var n = i > 1 ? void 0 : i ? Kt(t, e) : t, o = s.length - 1, r; o >= 0; o--) (r = s[o]) && (n = (i ? r(t, e, n) : r(n)) || n); return i && n && Jt(t, e, n), n; }; let f = class extends H { constructor() { super(...arguments), this.pagesAttr = "", this.keyboardNavigation = !0, this.keyboardNavigationFocusOnly = !1, this.autoplay = !1, this.autoplayInterval = 2e3, this.size = "", this.book = ht(0), this.stackDirection = "initial", this.prevButton = null, this.nextButton = null, this.keyboardHandler = null, this.autoplayIntervalId = null, this.isHovering = !1; } updateButtons() { !this.prevButton || !this.nextButton || (this.prevButton.disabled = !N(this.book), this.nextButton.disabled = !P(this.book)); } startAutoplay() { this.stopAutoplay(), !(!this.autoplay || this.book.pageCount === 0 || this.isHovering) && (this.autoplayIntervalId = window.setInterval(() => { P(this.book) ? this.flipPageForwardInternal() : this.stopAutoplay(); }, this.autoplayInterval)); } stopAutoplay() { this.autoplayIntervalId !== null && (window.clearInterval(this.autoplayIntervalId), this.autoplayIntervalId = null); } flipPageForwardInternal() { const s = Dt(this.book); s && (this.book = s, this.stackDirection = "forward", this.updateButtons()); } flipPageForward() { P(this.book) && (this.stopAutoplay(), this.flipPageForwardInternal(), this.autoplay && this.startAutoplay()); } flipPageBackward() { if (!N(this.book)) return; this.stopAutoplay(); const s = jt(this.book); s && (this.book = s, this.stackDirection = "backward", this.updateButtons(), this.autoplay && this.startAutoplay()); } resizeContainer() { var h, p; const s = (h = this.shadowRoot) == null ? void 0 : h.querySelector( ".container" ), t = (p = this.shadowRoot) == null ? void 0 : p.querySelector(".wrapper"); if (!s || !t) return; const e = parseInt( getComputedStyle(this).getPropertyValue("--canvas-padding") ), i = parseInt( getComputedStyle(this).getPropertyValue("--page-width") ), n = parseInt( getComputedStyle(this).getPropertyValue("--page-height") ), o = i * 2, r = t.clientWidth - e * 2, l = t.clientHeight - e * 2, a = r / o, d = l / n, u = Math.min(a, d); s.style.width = `${o * u}px`, s.style.height = `${n * u}px`; } syncSizePresetCss() { const s = Zt(this.size); s === null ? (this.style.removeProperty("--page-width"), this.style.removeProperty("--page-height")) : (this.style.setProperty("--page-width", `${s.pageWidth}px`), this.style.setProperty("--page-height", `${s.pageHeight}px`)); } firstUpdated() { var o, r, l, a, d, u; this.syncSizePresetCss(), this.prevButton = (o = this.shadowRoot) == null ? void 0 : o.getElementById( "prev" ), this.nextButton = (r = this.shadowRoot) == null ? void 0 : r.getElementById( "next" ), this.resizeContainer(), new ResizeObserver(() => { this.resizeContainer(); }).observe(this), (l = this.prevButton) == null || l.addEventListener("click", () => this.flipPageBackward()), (a = this.nextButton) == null || a.addEventListener("click", () => this.flipPageForward()), this.keyboardHandler = (h) => { this.keyboardNavigation && (this.keyboardNavigationFocusOnly && !this.matches(":focus-within") || (h.key === "ArrowLeft" ? (h.preventDefault(), this.flipPageBackward()) : h.key === "ArrowRight" && (h.preventDefault(), this.flipPageForward()))); }, window.addEventListener("keydown", this.keyboardHandler); const t = (d = this.shadowRoot) == null ? void 0 : d.querySelector(".wrapper"); t && (t.addEventListener("mouseenter", () => { this.isHovering = !0, this.stopAutoplay(); }), t.addEventListener("mouseleave", () => { this.isHovering = !1, this.autoplay && this.startAutoplay(); })); const e = Array.from( ((u = this.shadowRoot) == null ? void 0 : u.querySelectorAll("img")) || [] ); let i = 0; const n = e.length; n > 0 && (e.forEach((h) => { h.complete ? i++ : (h.addEventListener("load", () => { i++, i === n && this.updateButtons(); }), h.addEventListener("error", () => { i++, i === n && this.updateButtons(); })); }), i === n && this.updateButtons()), this.updateButtons(), this.autoplay && this.startAutoplay(); } willUpdate(s) { super.willUpdate(s), s.has("size") && this.syncSizePresetCss(); const e = at(this.pagesAttr, this).length; (s.has("pagesAttr") || e !== this.book.pageCount) && (this.book = ht(e), this.stackDirection = "initial"); } updated(s) { var t, e; (!this.prevButton || !this.nextButton) && (this.prevButton = (t = this.shadowRoot) == null ? void 0 : t.getElementById( "prev" ), this.nextButton = (e = this.shadowRoot) == null ? void 0 : e.getElementById( "next" )), this.prevButton && this.nextButton && this.book.pageCount > 0 && this.updateButtons(), (s.has("autoplay") || s.has("autoplayInterval")) && (this.autoplay ? this.startAutoplay() : this.stopAutoplay()), s.has("size") && this.resizeContainer(); } disconnectedCallback() { super.disconnectedCallback(), this.keyboardHandler && window.removeEventListener("keydown", this.keyboardHandler), this.stopAutoplay(); } render() { const s = at(this.pagesAttr, this), t = Ft(this.book, this.stackDirection); return rt` <div class="wrapper" tabindex=${this.keyboardNavigationFocusOnly ? "0" : null} > <div class="container"> <div class="zine"> ${s.map( (e) => rt`<div class="page${Lt(e.index, this.book) ? " flipped" : ""}" data-page="${e.index + 1}" style="z-index: ${t[e.index] ?? 0}" > <div class="front"><img src="${e.imgSrc}" /></div> <div class="back"><img src="${e.backImgSrc}" /></div> </div>` )} <button id="prev" ?disabled=${!N(this.book)}></button> <button id="next" ?disabled=${!P(this.book)}></button> </div> </div> </div> `; } }; f.styles = mt` :host { --canvas-bg-color: transparent; --canvas-padding: 25px; --page-width: 291px; --page-height: 450px; --spread-width: calc(var(--page-width) * 2); --page-border-radius: 5%; --page-color: #111; --page-bg-color: transparent; --transition-duration: 1s; display: block; width: 100%; height: 100%; } * { box-sizing: border-box; } .wrapper { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: var(--canvas-padding); } .container { display: flex; justify-content: flex-end; align-items: center; position: relative; margin: 0 auto; background: var(--canvas-bg-color); font-family: Arial, sans-serif; border-radius: var(--page-border-radius); } .zine { position: relative; width: 100%; height: 100%; perspective: calc(var(--page-width) * 5); } .page { position: absolute; right: 0; width: 50%; height: 100%; transform-origin: left; transform-style: preserve-3d; transition: transform var(--transition-duration); } .page.flipped { transform: rotateY(-180deg); } .page > div { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; justify-content: center; align-items: center; font-size: 1.2em; background: var(--page-bg-color); } .front { background-color: #fdf6e3; overflow: hidden; & img { border-radius: 0 var(--page-border-radius) var(--page-border-radius) 0; } } .back { transform: rotateY(180deg); background-color: #eee; overflow: hidden; & img { border-radius: var(--page-border-radius) 0 0 var(--page-border-radius); } } #next, #prev { position: absolute; width: 50%; height: 100%; top: 0; bottom: 0; } #prev { left: 0; right: 50%; } #next { left: 50%; } button { border: none; background-color: transparent; font-size: 16px; cursor: pointer; z-index: 10; } button:disabled { cursor: not-allowed; } img { max-width: 100%; max-height: 100%; object-fit: contain; border: 1px solid #ccc; } `; g([ v({ type: String, attribute: "pages" }) ], f.prototype, "pagesAttr", 2); g([ v({ type: Boolean, attribute: "keyboard-navigation" }) ], f.prototype, "keyboardNavigation", 2); g([ v({ type: Boolean, attribute: "keyboard-navigation-focus-only" }) ], f.prototype, "keyboardNavigationFocusOnly", 2); g([ v({ type: Boolean, attribute: "autoplay" }) ], f.prototype, "autoplay", 2); g([ v({ type: Number, attribute: "autoplay-interval" }) ], f.prototype, "autoplayInterval", 2); g([ v({ type: String, attribute: "size" }) ], f.prototype, "size", 2); g([ yt() ], f.prototype, "book", 2); g([ yt() ], f.prototype, "stackDirection", 2); f = g([ Nt("zine-viewer") ], f); export { f as ZineViewer };