UNPKG

@formdown/ui

Version:

Pure HTML renderer for Formdown syntax

1,477 lines (1,471 loc) 219 kB
var mr = Object.defineProperty; var br = (n, e, t) => e in n ? mr(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var $ = (n, e, t) => br(n, typeof e != "symbol" ? e + "" : e, t); /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const Ee = globalThis, Ne = Ee.ShadowRoot && (Ee.ShadyCSS === void 0 || Ee.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, We = Symbol(), dt = /* @__PURE__ */ new WeakMap(); let Ft = class { constructor(e, t, r) { if (this._$cssResult$ = !0, r !== We) 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 (Ne && e === void 0) { const r = t !== void 0 && t.length === 1; r && (e = dt.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), r && dt.set(t, e)); } return e; } toString() { return this.cssText; } }; const yr = (n) => new Ft(typeof n == "string" ? n : n + "", void 0, We), wr = (n, ...e) => { const t = n.length === 1 ? n[0] : e.reduce((r, i, s) => r + ((a) => { if (a._$cssResult$ === !0) return a.cssText; if (typeof a == "number") return a; throw Error("Value passed to 'css' function must be a 'css' function result: " + a + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security."); })(i) + n[s + 1], n[0]); return new Ft(t, n, We); }, xr = (n, e) => { if (Ne) n.adoptedStyleSheets = e.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet); else for (const t of e) { const r = document.createElement("style"), i = Ee.litNonce; i !== void 0 && r.setAttribute("nonce", i), r.textContent = t.cssText, n.appendChild(r); } }, pt = Ne ? (n) => n : (n) => n instanceof CSSStyleSheet ? ((e) => { let t = ""; for (const r of e.cssRules) t += r.cssText; return yr(t); })(n) : n; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const { is: vr, defineProperty: $r, getOwnPropertyDescriptor: kr, getOwnPropertyNames: Er, getOwnPropertySymbols: Ar, getPrototypeOf: Sr } = Object, N = globalThis, ft = N.trustedTypes, _r = ft ? ft.emptyScript : "", De = N.reactiveElementPolyfillSupport, he = (n, e) => n, Se = { toAttribute(n, e) { switch (e) { case Boolean: n = n ? _r : null; break; case Object: case Array: n = n == null ? n : JSON.stringify(n); } return n; }, fromAttribute(n, e) { let t = n; switch (e) { case Boolean: t = n !== null; break; case Number: t = n === null ? null : Number(n); break; case Object: case Array: try { t = JSON.parse(n); } catch { t = null; } } return t; } }, Ge = (n, e) => !vr(n, e), gt = { attribute: !0, type: String, converter: Se, reflect: !1, useDefault: !1, hasChanged: Ge }; Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), N.litPropertyMetadata ?? (N.litPropertyMetadata = /* @__PURE__ */ new WeakMap()); let ee = class 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 = gt) { if (t.state && (t.attribute = !1), this._$Ei(), this.prototype.hasOwnProperty(e) && ((t = Object.create(t)).wrapped = !0), this.elementProperties.set(e, t), !t.noAccessor) { const r = Symbol(), i = this.getPropertyDescriptor(e, r, t); i !== void 0 && $r(this.prototype, e, i); } } static getPropertyDescriptor(e, t, r) { const { get: i, set: s } = kr(this.prototype, e) ?? { get() { return this[t]; }, set(a) { this[t] = a; } }; return { get: i, set(a) { const o = i == null ? void 0 : i.call(this); s == null || s.call(this, a), this.requestUpdate(e, o, r); }, configurable: !0, enumerable: !0 }; } static getPropertyOptions(e) { return this.elementProperties.get(e) ?? gt; } static _$Ei() { if (this.hasOwnProperty(he("elementProperties"))) return; const e = Sr(this); e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties); } static finalize() { if (this.hasOwnProperty(he("finalized"))) return; if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(he("properties"))) { const t = this.properties, r = [...Er(t), ...Ar(t)]; for (const i of r) this.createProperty(i, t[i]); } const e = this[Symbol.metadata]; if (e !== null) { const t = litPropertyMetadata.get(e); if (t !== void 0) for (const [r, i] of t) this.elementProperties.set(r, i); } this._$Eh = /* @__PURE__ */ new Map(); for (const [t, r] of this.elementProperties) { const i = this._$Eu(t, r); i !== void 0 && this._$Eh.set(i, t); } this.elementStyles = this.finalizeStyles(this.styles); } static finalizeStyles(e) { const t = []; if (Array.isArray(e)) { const r = new Set(e.flat(1 / 0).reverse()); for (const i of r) t.unshift(pt(i)); } else e !== void 0 && t.push(pt(e)); return t; } static _$Eu(e, t) { const r = t.attribute; return r === !1 ? void 0 : typeof r == "string" ? r : 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 r of t.keys()) this.hasOwnProperty(r) && (e.set(r, this[r]), delete this[r]); e.size > 0 && (this._$Ep = e); } createRenderRoot() { const e = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions); return xr(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 r; return (r = t.hostConnected) == null ? void 0 : r.call(t); }); } enableUpdating(e) { } disconnectedCallback() { var e; (e = this._$EO) == null || e.forEach((t) => { var r; return (r = t.hostDisconnected) == null ? void 0 : r.call(t); }); } attributeChangedCallback(e, t, r) { this._$AK(e, r); } _$ET(e, t) { var s; const r = this.constructor.elementProperties.get(e), i = this.constructor._$Eu(e, r); if (i !== void 0 && r.reflect === !0) { const a = (((s = r.converter) == null ? void 0 : s.toAttribute) !== void 0 ? r.converter : Se).toAttribute(t, r.type); this._$Em = e, a == null ? this.removeAttribute(i) : this.setAttribute(i, a), this._$Em = null; } } _$AK(e, t) { var s, a; const r = this.constructor, i = r._$Eh.get(e); if (i !== void 0 && this._$Em !== i) { const o = r.getPropertyOptions(i), l = typeof o.converter == "function" ? { fromAttribute: o.converter } : ((s = o.converter) == null ? void 0 : s.fromAttribute) !== void 0 ? o.converter : Se; this._$Em = i; const c = l.fromAttribute(t, o.type); this[i] = c ?? ((a = this._$Ej) == null ? void 0 : a.get(i)) ?? c, this._$Em = null; } } requestUpdate(e, t, r) { var i; if (e !== void 0) { const s = this.constructor, a = this[e]; if (r ?? (r = s.getPropertyOptions(e)), !((r.hasChanged ?? Ge)(a, t) || r.useDefault && r.reflect && a === ((i = this._$Ej) == null ? void 0 : i.get(e)) && !this.hasAttribute(s._$Eu(e, r)))) return; this.C(e, t, r); } this.isUpdatePending === !1 && (this._$ES = this._$EP()); } C(e, t, { useDefault: r, reflect: i, wrapped: s }, a) { r && !(this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Map())).has(e) && (this._$Ej.set(e, a ?? t ?? this[e]), s !== !0 || a !== void 0) || (this._$AL.has(e) || (this.hasUpdated || r || (t = void 0), this._$AL.set(e, t)), i === !0 && this._$Em !== e && (this._$Eq ?? (this._$Eq = /* @__PURE__ */ new Set())).add(e)); } async _$EP() { 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 r; if (!this.isUpdatePending) return; if (!this.hasUpdated) { if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) { for (const [s, a] of this._$Ep) this[s] = a; this._$Ep = void 0; } const i = this.constructor.elementProperties; if (i.size > 0) for (const [s, a] of i) { const { wrapped: o } = a, l = this[s]; o !== !0 || this._$AL.has(s) || l === void 0 || this.C(s, void 0, a, l); } } let e = !1; const t = this._$AL; try { e = this.shouldUpdate(t), e ? (this.willUpdate(t), (r = this._$EO) == null || r.forEach((i) => { var s; return (s = i.hostUpdate) == null ? void 0 : s.call(i); }), this.update(t)) : this._$EM(); } catch (i) { throw e = !1, this._$EM(), i; } e && this._$AE(t); } willUpdate(e) { } _$AE(e) { var t; (t = this._$EO) == null || t.forEach((r) => { var i; return (i = r.hostUpdated) == null ? void 0 : i.call(r); }), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(e)), this.updated(e); } _$EM() { this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1; } get updateComplete() { return this.getUpdateComplete(); } getUpdateComplete() { return this._$ES; } shouldUpdate(e) { return !0; } update(e) { this._$Eq && (this._$Eq = this._$Eq.forEach((t) => this._$ET(t, this[t]))), this._$EM(); } updated(e) { } firstUpdated(e) { } }; ee.elementStyles = [], ee.shadowRootOptions = { mode: "open" }, ee[he("elementProperties")] = /* @__PURE__ */ new Map(), ee[he("finalized")] = /* @__PURE__ */ new Map(), De == null || De({ ReactiveElement: ee }), (N.reactiveElementVersions ?? (N.reactiveElementVersions = [])).push("2.1.1"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const ue = globalThis, _e = ue.trustedTypes, mt = _e ? _e.createPolicy("lit-html", { createHTML: (n) => n }) : void 0, Ct = "$lit$", j = `lit$${Math.random().toFixed(9).slice(2)}$`, Rt = "?" + j, Tr = `<${Rt}>`, K = document, fe = () => K.createComment(""), ge = (n) => n === null || typeof n != "object" && typeof n != "function", Ze = Array.isArray, Fr = (n) => Ze(n) || typeof (n == null ? void 0 : n[Symbol.iterator]) == "function", Pe = `[ \f\r]`, oe = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, bt = /-->/g, yt = />/g, W = RegExp(`>|${Pe}(?:([^\\s"'>=/]+)(${Pe}*=${Pe}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`, "g"), wt = /'/g, xt = /"/g, Mt = /^(?:script|style|textarea|title)$/i, Cr = (n) => (e, ...t) => ({ _$litType$: n, strings: e, values: t }), $e = Cr(1), te = Symbol.for("lit-noChange"), S = Symbol.for("lit-nothing"), vt = /* @__PURE__ */ new WeakMap(), Z = K.createTreeWalker(K, 129); function It(n, e) { if (!Ze(n) || !n.hasOwnProperty("raw")) throw Error("invalid template strings array"); return mt !== void 0 ? mt.createHTML(e) : e; } const Rr = (n, e) => { const t = n.length - 1, r = []; let i, s = e === 2 ? "<svg>" : e === 3 ? "<math>" : "", a = oe; for (let o = 0; o < t; o++) { const l = n[o]; let c, h, d = -1, u = 0; for (; u < l.length && (a.lastIndex = u, h = a.exec(l), h !== null); ) u = a.lastIndex, a === oe ? h[1] === "!--" ? a = bt : h[1] !== void 0 ? a = yt : h[2] !== void 0 ? (Mt.test(h[2]) && (i = RegExp("</" + h[2], "g")), a = W) : h[3] !== void 0 && (a = W) : a === W ? h[0] === ">" ? (a = i ?? oe, d = -1) : h[1] === void 0 ? d = -2 : (d = a.lastIndex - h[2].length, c = h[1], a = h[3] === void 0 ? W : h[3] === '"' ? xt : wt) : a === xt || a === wt ? a = W : a === bt || a === yt ? a = oe : (a = W, i = void 0); const p = a === W && n[o + 1].startsWith("/>") ? " " : ""; s += a === oe ? l + Tr : d >= 0 ? (r.push(c), l.slice(0, d) + Ct + l.slice(d) + j + p) : l + j + (d === -2 ? o : p); } return [It(n, s + (n[t] || "<?>") + (e === 2 ? "</svg>" : e === 3 ? "</math>" : "")), r]; }; class me { constructor({ strings: e, _$litType$: t }, r) { let i; this.parts = []; let s = 0, a = 0; const o = e.length - 1, l = this.parts, [c, h] = Rr(e, t); if (this.el = me.createElement(c, r), Z.currentNode = this.el.content, t === 2 || t === 3) { const d = this.el.content.firstChild; d.replaceWith(...d.childNodes); } for (; (i = Z.nextNode()) !== null && l.length < o; ) { if (i.nodeType === 1) { if (i.hasAttributes()) for (const d of i.getAttributeNames()) if (d.endsWith(Ct)) { const u = h[a++], p = i.getAttribute(d).split(j), f = /([.?@])?(.*)/.exec(u); l.push({ type: 1, index: s, name: f[2], strings: p, ctor: f[1] === "." ? Ir : f[1] === "?" ? Lr : f[1] === "@" ? Dr : Me }), i.removeAttribute(d); } else d.startsWith(j) && (l.push({ type: 6, index: s }), i.removeAttribute(d)); if (Mt.test(i.tagName)) { const d = i.textContent.split(j), u = d.length - 1; if (u > 0) { i.textContent = _e ? _e.emptyScript : ""; for (let p = 0; p < u; p++) i.append(d[p], fe()), Z.nextNode(), l.push({ type: 2, index: ++s }); i.append(d[u], fe()); } } } else if (i.nodeType === 8) if (i.data === Rt) l.push({ type: 2, index: s }); else { let d = -1; for (; (d = i.data.indexOf(j, d + 1)) !== -1; ) l.push({ type: 7, index: s }), d += j.length - 1; } s++; } } static createElement(e, t) { const r = K.createElement("template"); return r.innerHTML = e, r; } } function re(n, e, t = n, r) { var a, o; if (e === te) return e; let i = r !== void 0 ? (a = t._$Co) == null ? void 0 : a[r] : t._$Cl; const s = ge(e) ? void 0 : e._$litDirective$; return (i == null ? void 0 : i.constructor) !== s && ((o = i == null ? void 0 : i._$AO) == null || o.call(i, !1), s === void 0 ? i = void 0 : (i = new s(n), i._$AT(n, t, r)), r !== void 0 ? (t._$Co ?? (t._$Co = []))[r] = i : t._$Cl = i), i !== void 0 && (e = re(n, i._$AS(n, e.values), i, r)), e; } class Mr { constructor(e, t) { this._$AV = [], this._$AN = void 0, this._$AD = e, this._$AM = t; } get parentNode() { return this._$AM.parentNode; } get _$AU() { return this._$AM._$AU; } u(e) { const { el: { content: t }, parts: r } = this._$AD, i = ((e == null ? void 0 : e.creationScope) ?? K).importNode(t, !0); Z.currentNode = i; let s = Z.nextNode(), a = 0, o = 0, l = r[0]; for (; l !== void 0; ) { if (a === l.index) { let c; l.type === 2 ? c = new be(s, s.nextSibling, this, e) : l.type === 1 ? c = new l.ctor(s, l.name, l.strings, this, e) : l.type === 6 && (c = new Pr(s, this, e)), this._$AV.push(c), l = r[++o]; } a !== (l == null ? void 0 : l.index) && (s = Z.nextNode(), a++); } return Z.currentNode = K, i; } p(e) { let t = 0; for (const r of this._$AV) r !== void 0 && (r.strings !== void 0 ? (r._$AI(e, r, t), t += r.strings.length - 2) : r._$AI(e[t])), t++; } } class be { get _$AU() { var e; return ((e = this._$AM) == null ? void 0 : e._$AU) ?? this._$Cv; } constructor(e, t, r, i) { this.type = 2, this._$AH = S, this._$AN = void 0, this._$AA = e, this._$AB = t, this._$AM = r, this.options = i, this._$Cv = (i == null ? void 0 : i.isConnected) ?? !0; } get parentNode() { let e = this._$AA.parentNode; const t = this._$AM; return t !== void 0 && (e == null ? void 0 : e.nodeType) === 11 && (e = t.parentNode), e; } get startNode() { return this._$AA; } get endNode() { return this._$AB; } _$AI(e, t = this) { e = re(this, e, t), ge(e) ? e === S || e == null || e === "" ? (this._$AH !== S && this._$AR(), this._$AH = S) : e !== this._$AH && e !== te && this._(e) : e._$litType$ !== void 0 ? this.$(e) : e.nodeType !== void 0 ? this.T(e) : Fr(e) ? this.k(e) : this._(e); } O(e) { return this._$AA.parentNode.insertBefore(e, this._$AB); } T(e) { this._$AH !== e && (this._$AR(), this._$AH = this.O(e)); } _(e) { this._$AH !== S && ge(this._$AH) ? this._$AA.nextSibling.data = e : this.T(K.createTextNode(e)), this._$AH = e; } $(e) { var s; const { values: t, _$litType$: r } = e, i = typeof r == "number" ? this._$AC(e) : (r.el === void 0 && (r.el = me.createElement(It(r.h, r.h[0]), this.options)), r); if (((s = this._$AH) == null ? void 0 : s._$AD) === i) this._$AH.p(t); else { const a = new Mr(i, this), o = a.u(this.options); a.p(t), this.T(o), this._$AH = a; } } _$AC(e) { let t = vt.get(e.strings); return t === void 0 && vt.set(e.strings, t = new me(e)), t; } k(e) { Ze(this._$AH) || (this._$AH = [], this._$AR()); const t = this._$AH; let r, i = 0; for (const s of e) i === t.length ? t.push(r = new be(this.O(fe()), this.O(fe()), this, this.options)) : r = t[i], r._$AI(s), i++; i < t.length && (this._$AR(r && r._$AB.nextSibling, i), t.length = i); } _$AR(e = this._$AA.nextSibling, t) { var r; for ((r = this._$AP) == null ? void 0 : r.call(this, !1, !0, t); e !== this._$AB; ) { const i = e.nextSibling; e.remove(), e = i; } } setConnected(e) { var t; this._$AM === void 0 && (this._$Cv = e, (t = this._$AP) == null || t.call(this, e)); } } class Me { get tagName() { return this.element.tagName; } get _$AU() { return this._$AM._$AU; } constructor(e, t, r, i, s) { this.type = 1, this._$AH = S, this._$AN = void 0, this.element = e, this.name = t, this._$AM = i, this.options = s, r.length > 2 || r[0] !== "" || r[1] !== "" ? (this._$AH = Array(r.length - 1).fill(new String()), this.strings = r) : this._$AH = S; } _$AI(e, t = this, r, i) { const s = this.strings; let a = !1; if (s === void 0) e = re(this, e, t, 0), a = !ge(e) || e !== this._$AH && e !== te, a && (this._$AH = e); else { const o = e; let l, c; for (e = s[0], l = 0; l < s.length - 1; l++) c = re(this, o[r + l], t, l), c === te && (c = this._$AH[l]), a || (a = !ge(c) || c !== this._$AH[l]), c === S ? e = S : e !== S && (e += (c ?? "") + s[l + 1]), this._$AH[l] = c; } a && !i && this.j(e); } j(e) { e === S ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, e ?? ""); } } class Ir extends Me { constructor() { super(...arguments), this.type = 3; } j(e) { this.element[this.name] = e === S ? void 0 : e; } } class Lr extends Me { constructor() { super(...arguments), this.type = 4; } j(e) { this.element.toggleAttribute(this.name, !!e && e !== S); } } class Dr extends Me { constructor(e, t, r, i, s) { super(e, t, r, i, s), this.type = 5; } _$AI(e, t = this) { if ((e = re(this, e, t, 0) ?? S) === te) return; const r = this._$AH, i = e === S && r !== S || e.capture !== r.capture || e.once !== r.once || e.passive !== r.passive, s = e !== S && (r === S || i); i && this.element.removeEventListener(this.name, this, r), s && this.element.addEventListener(this.name, this, e), this._$AH = e; } handleEvent(e) { var t; typeof this._$AH == "function" ? this._$AH.call(((t = this.options) == null ? void 0 : t.host) ?? this.element, e) : this._$AH.handleEvent(e); } } class Pr { constructor(e, t, r) { this.element = e, this.type = 6, this._$AN = void 0, this._$AM = t, this.options = r; } get _$AU() { return this._$AM._$AU; } _$AI(e) { re(this, e); } } const Oe = ue.litHtmlPolyfillSupport; Oe == null || Oe(me, be), (ue.litHtmlVersions ?? (ue.litHtmlVersions = [])).push("3.3.1"); const Or = (n, e, t) => { const r = (t == null ? void 0 : t.renderBefore) ?? e; let i = r._$litPart$; if (i === void 0) { const s = (t == null ? void 0 : t.renderBefore) ?? null; r._$litPart$ = i = new be(e.insertBefore(fe(), s), s, void 0, t ?? {}); } return i._$AI(n), i; }; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const Q = globalThis; class de extends ee { constructor() { super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0; } createRenderRoot() { var t; const e = super.createRenderRoot(); return (t = this.renderOptions).renderBefore ?? (t.renderBefore = e.firstChild), e; } update(e) { const t = this.render(); this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(e), this._$Do = Or(t, this.renderRoot, this.renderOptions); } connectedCallback() { var e; super.connectedCallback(), (e = this._$Do) == null || e.setConnected(!0); } disconnectedCallback() { var e; super.disconnectedCallback(), (e = this._$Do) == null || e.setConnected(!1); } render() { return te; } } var Tt; de._$litElement$ = !0, de.finalized = !0, (Tt = Q.litElementHydrateSupport) == null || Tt.call(Q, { LitElement: de }); const ze = Q.litElementPolyfillSupport; ze == null || ze({ LitElement: de }); (Q.litElementVersions ?? (Q.litElementVersions = [])).push("4.2.1"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const zr = (n) => (e, t) => { t !== void 0 ? t.addInitializer(() => { customElements.define(n, e); }) : customElements.define(n, e); }; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const Hr = { attribute: !0, type: String, converter: Se, reflect: !1, hasChanged: Ge }, Vr = (n = Hr, e, t) => { const { kind: r, metadata: i } = t; let s = globalThis.litPropertyMetadata.get(i); if (s === void 0 && globalThis.litPropertyMetadata.set(i, s = /* @__PURE__ */ new Map()), r === "setter" && ((n = Object.create(n)).wrapped = !0), s.set(t.name, n), r === "accessor") { const { name: a } = t; return { set(o) { const l = e.get.call(this); e.set.call(this, o), this.requestUpdate(a, l, n); }, init(o) { return o !== void 0 && this.C(a, void 0, n, o), o; } }; } if (r === "setter") { const { name: a } = t; return function(o) { const l = this[a]; e.call(this, o), this.requestUpdate(a, l, n); }; } throw Error("Unsupported decorator location: " + r); }; function ie(n) { return (e, t) => typeof t == "object" ? Vr(n, e, t) : ((r, i, s) => { const a = i.hasOwnProperty(s); return i.constructor.createProperty(s, r), a ? Object.getOwnPropertyDescriptor(i, s) : void 0; })(n, e, t); } class Br { constructor(e = {}, t) { this.options = e, this.hooks = /* @__PURE__ */ new Map(), this.eventEmitter = t; } /** * Register a hook */ register(e) { const t = this.hooks.get(e.name) || []; t.push(e), t.sort((r, i) => i.priority - r.priority), this.hooks.set(e.name, t), this.emit("hook-registered", { hook: e.name, priority: e.priority }), this.options.debug && console.debug(`[Formdown] Hook registered: ${e.name} (priority: ${e.priority})`); } /** * Unregister a specific hook handler */ unregister(e, t) { const r = this.hooks.get(e) || [], i = r.filter((s) => s.handler !== t); i.length !== r.length && (this.hooks.set(e, i), this.emit("hook-unregistered", { hook: e }), this.options.debug && console.debug(`[Formdown] Hook unregistered: ${e}`)); } /** * Execute hooks asynchronously */ async execute(e, t, ...r) { const i = this.hooks.get(e) || [], s = []; this.emit("hooks-executing", { hook: e, count: i.length }); for (const a of i) { let o = null; try { o = this.options.timeout ? this.createTimeoutPromise(this.options.timeout) : null; const l = Promise.resolve(a.handler(t, ...r)), c = o ? await Promise.race([l, o.promise]) : await l; o == null || o.cleanup(), c !== void 0 && s.push(c), this.emit("hook-executed", { hook: e, success: !0 }); } catch (l) { o == null || o.cleanup(), this.handleHookError(e, l); } } return this.emit("hooks-completed", { hook: e, results: s.length }), s; } /** * Execute hooks synchronously */ executeSync(e, t, ...r) { const i = this.hooks.get(e) || [], s = []; this.emit("hooks-executing", { hook: e, count: i.length }); for (const a of i) try { const o = a.handler(t, ...r); o !== void 0 && s.push(o), this.emit("hook-executed", { hook: e, success: !0 }); } catch (o) { this.handleHookError(e, o); } return this.emit("hooks-completed", { hook: e, results: s.length }), s; } /** * Clear hooks */ clear(e) { e ? (this.hooks.delete(e), this.emit("hooks-cleared", { hook: e })) : (this.hooks.clear(), this.emit("hooks-cleared", { all: !0 })), this.options.debug && console.debug(`[Formdown] Hooks cleared: ${e || "all"}`); } /** * Get registered hooks for a specific name */ getHooks(e) { return [...this.hooks.get(e) || []]; } /** * Get all registered hook names */ getHookNames() { return Array.from(this.hooks.keys()); } /** * Get total number of registered hooks */ getHookCount() { return Array.from(this.hooks.values()).reduce((e, t) => e + t.length, 0); } /** * Create a timeout promise for hook execution */ createTimeoutPromise(e) { let t; return { promise: new Promise((s, a) => { t = setTimeout(() => { a(new Error(`Hook execution timeout after ${e}ms`)); }, e); }), cleanup: () => { clearTimeout(t); } }; } /** * Handle hook execution errors */ handleHookError(e, t) { const r = `Hook execution failed: ${e} - ${t.message || t}`; switch (this.emit("hook-error", { hook: e, error: r }), this.options.errorStrategy) { case "ignore": break; case "warn": console.warn(`[Formdown] ${r}`); break; case "throw": default: throw new Error(r); } } /** * Emit events if event emitter is available */ emit(e, t) { if (this.eventEmitter) { const r = { type: e, data: t, timestamp: Date.now() }; this.eventEmitter.emit(e, r); } } } class qr { constructor(e, t = {}, r, i) { this.hookManager = e, this.options = t, this.eventEmitter = r, this.fieldTypeRegistry = i, this.plugins = /* @__PURE__ */ new Map(), this.fieldTypes = /* @__PURE__ */ new Map(), this.validators = /* @__PURE__ */ new Map(), this.renderers = /* @__PURE__ */ new Map(), this.themes = /* @__PURE__ */ new Map(), this.initialized = !1; } /** * Register a plugin */ async register(e) { var t; if (this.plugins.has(e.metadata.name)) throw new Error(`Plugin '${e.metadata.name}' is already registered`); if (await this.validateDependencies(e), this.plugins.set(e.metadata.name, e), e.hooks) for (const r of e.hooks) this.hookManager.register(r); if (e.fieldTypes) for (const r of e.fieldTypes) this.fieldTypes.set(r.type, r), (t = this.fieldTypeRegistry) == null || t.register(r); if (e.validators) for (const r of e.validators) this.validators.set(r.name, r); if (e.renderers) for (const r of e.renderers) this.renderers.set(r.template, r); if (e.themes) for (const r of e.themes) this.themes.set(r.name, r); if (this.emit("plugin-registered", { plugin: e.metadata.name, version: e.metadata.version }), this.options.debug && console.debug(`[Formdown] Plugin registered: ${e.metadata.name} v${e.metadata.version}`), this.initialized && e.initialize) try { await e.initialize(), this.emit("plugin-initialized", { plugin: e.metadata.name }); } catch (r) { this.handlePluginError(e.metadata.name, "initialization", r); } } /** * Unregister a plugin */ async unregister(e) { var r; const t = this.plugins.get(e); if (t) { if (t.destroy) try { await t.destroy(), this.emit("plugin-destroyed", { plugin: e }); } catch (i) { this.handlePluginError(e, "cleanup", i); } if (t.hooks) for (const i of t.hooks) this.hookManager.unregister(i.name, i.handler); if (t.fieldTypes) for (const i of t.fieldTypes) this.fieldTypes.delete(i.type), (r = this.fieldTypeRegistry) == null || r.unregister(i.type); if (t.validators) for (const i of t.validators) this.validators.delete(i.name); if (t.renderers) for (const i of t.renderers) this.renderers.delete(i.template); if (t.themes) for (const i of t.themes) this.themes.delete(i.name); this.plugins.delete(e), this.emit("plugin-unregistered", { plugin: e }), this.options.debug && console.debug(`[Formdown] Plugin unregistered: ${e}`); } } /** * Get a plugin by name */ get(e) { return this.plugins.get(e); } /** * Get all registered plugins */ getAll() { return Array.from(this.plugins.values()); } /** * Check if a plugin is registered */ isRegistered(e) { return this.plugins.has(e); } /** * Initialize all plugins */ async initialize() { if (this.initialized) return; this.emit("plugins-initializing", { count: this.plugins.size }); const e = []; for (const t of this.plugins.values()) t.initialize && e.push(Promise.resolve(t.initialize()).catch((r) => this.handlePluginError(t.metadata.name, "initialization", r))); await Promise.all(e), this.initialized = !0, this.emit("plugins-initialized", { count: this.plugins.size }), this.options.debug && console.debug(`[Formdown] ${this.plugins.size} plugins initialized`); } /** * Destroy all plugins */ async destroy() { if (!this.initialized) return; this.emit("plugins-destroying", { count: this.plugins.size }); const e = []; for (const t of this.plugins.values()) t.destroy && e.push(Promise.resolve(t.destroy()).catch((r) => this.handlePluginError(t.metadata.name, "cleanup", r))); await Promise.all(e), this.plugins.clear(), this.fieldTypes.clear(), this.validators.clear(), this.renderers.clear(), this.themes.clear(), this.initialized = !1, this.emit("plugins-destroyed", { count: 0 }), this.options.debug && console.debug("[Formdown] All plugins destroyed and cleared"); } /** * Get registered field type plugins */ getFieldTypes() { return new Map(this.fieldTypes); } /** * Get a specific field type plugin */ getFieldType(e) { return this.fieldTypes.get(e); } /** * Check if a field type is registered */ hasFieldType(e) { return this.fieldTypes.has(e); } /** * Get registered validation plugins */ getValidators() { return new Map(this.validators); } /** * Get registered renderer plugins */ getRenderers() { return new Map(this.renderers); } /** * Get registered theme plugins */ getThemes() { return new Map(this.themes); } /** * Validate plugin dependencies */ async validateDependencies(e) { if (e.metadata.dependencies) { for (const t of e.metadata.dependencies) if (!this.isRegistered(t)) throw new Error(`Plugin '${e.metadata.name}' requires dependency '${t}' which is not registered`); } } /** * Handle plugin errors */ handlePluginError(e, t, r) { const i = `Plugin ${t} failed: ${e} - ${r.message || r}`; switch (this.emit("plugin-error", { plugin: e, operation: t, error: i }), this.options.errorStrategy) { case "ignore": break; case "warn": console.warn(`[Formdown] ${i}`); break; case "throw": default: throw new Error(i); } } /** * Emit events if event emitter is available */ emit(e, t) { this.eventEmitter && this.eventEmitter.emit(e, t); } } class Ur { constructor() { this.listeners = /* @__PURE__ */ new Map(); } /** * Register an event listener */ on(e, t) { this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t); } /** * Unregister an event listener */ off(e, t) { const r = this.listeners.get(e); r && (r.delete(t), r.size === 0 && this.listeners.delete(e)); } /** * Emit an event to all registered listeners */ emit(e, t) { const r = this.listeners.get(e); if (!r) return; const i = { type: e, data: t, timestamp: Date.now() }; for (const s of r) try { s(i); } catch (a) { console.error(`[Formdown] Event listener error in '${e}':`, a); } } /** * Register a one-time event listener */ once(e, t) { const r = (i) => { t(i), this.off(i.type, r); }; this.on(e, r); } /** * Remove all listeners for an event or all events */ removeAllListeners(e) { e ? this.listeners.delete(e) : this.listeners.clear(); } /** * Get listener count for an event */ listenerCount(e) { var t; return ((t = this.listeners.get(e)) == null ? void 0 : t.size) || 0; } /** * Get all registered event names */ eventNames() { return Array.from(this.listeners.keys()); } } class jr { constructor() { this.fieldTypes = /* @__PURE__ */ new Map(), this.styleCache = /* @__PURE__ */ new Map(), this.scriptCache = /* @__PURE__ */ new Map(); } /** * Register a field type plugin */ register(e) { if (this.fieldTypes.has(e.type)) throw new Error(`Field type '${e.type}' is already registered`); this.fieldTypes.set(e.type, e), e.styles && this.styleCache.set(e.type, e.styles), e.clientScript && this.scriptCache.set(e.type, e.clientScript); } /** * Unregister a field type plugin */ unregister(e) { this.fieldTypes.delete(e), this.styleCache.delete(e), this.scriptCache.delete(e); } /** * Get a field type plugin */ get(e) { return this.fieldTypes.get(e); } /** * Check if a field type is registered */ has(e) { return this.fieldTypes.has(e); } /** * Get all registered field types */ getAll() { return new Map(this.fieldTypes); } /** * Parse field content using registered field type parsers */ parseField(e, t) { for (const r of this.fieldTypes.values()) if (r.parser) { const i = r.parser(e, t); if (i) return r.defaultAttributes && (i.attributes = { ...r.defaultAttributes, ...i.attributes }), i; } return null; } /** * Generate HTML for a field using registered generators */ generateFieldHTML(e, t) { const r = this.fieldTypes.get(e.type); return r != null && r.generator ? r.generator(e, t) : null; } /** * Validate field using registered validators */ validateField(e, t) { const r = this.fieldTypes.get(e.type); return r != null && r.validator ? r.validator(e, t) : []; } /** * Process field data using registered data processors */ processFieldData(e, t, r) { var a, o, l, c; const i = this.fieldTypes.get(e.type), s = i == null ? void 0 : i.dataProcessor; if (!s) return t; switch (r) { case "input": return ((a = s.processInput) == null ? void 0 : a.call(s, t, e)) ?? t; case "output": return ((o = s.processOutput) == null ? void 0 : o.call(s, t, e)) ?? t; case "serialize": return ((l = s.serialize) == null ? void 0 : l.call(s, t, e)) ?? t; case "deserialize": return ((c = s.deserialize) == null ? void 0 : c.call(s, t, e)) ?? t; default: return t; } } /** * Validate field data format using registered data processors */ validateFieldData(e, t) { const r = this.fieldTypes.get(e.type), i = r == null ? void 0 : r.dataProcessor; return i != null && i.validate ? i.validate(t, e) : { valid: !0 }; } /** * Generate JSON schema for a field using registered schema generators */ generateFieldSchema(e) { const t = this.fieldTypes.get(e.type); return t != null && t.schemaGenerator ? t.schemaGenerator(e) : null; } /** * Get all CSS styles for registered field types */ getAllStyles() { return Array.from(this.styleCache.values()).join(` `); } /** * Get styles for specific field types */ getStylesForTypes(e) { return e.map((t) => this.styleCache.get(t)).filter(Boolean).join(` `); } /** * Get all client scripts for registered field types */ getAllScripts() { return Array.from(this.scriptCache.values()).join(` `); } /** * Get scripts for specific field types */ getScriptsForTypes(e) { return e.map((t) => this.scriptCache.get(t)).filter(Boolean).join(` `); } /** * Get registry statistics */ getStats() { return { registeredTypes: Array.from(this.fieldTypes.keys()), totalTypes: this.fieldTypes.size, typesWithStyles: Array.from(this.styleCache.keys()), typesWithScripts: Array.from(this.scriptCache.keys()) }; } /** * Clear all registered field types */ clear() { this.fieldTypes.clear(), this.styleCache.clear(), this.scriptCache.clear(); } } const Nr = { type: "range", parser: (n, e) => { const t = [ /@(\w+)(?:\(([^)]+)\))?\s*:\s*\[range\](.*)/, // Standard: @field: [range] or @field(Label): [range] /@(\w+)(?:\(([^)]+)\))?\s*:\s*\[range\s+([^\]]+)\](.*)/ // With attributes: @field: [range min=0 max=100] ]; for (const r of t) { const i = n.match(r); if (i) { const [, s, a, o = "", l = ""] = i, c = Wr((o || "") + (l || "")); return { name: s, type: "range", label: a || c.label || Gr(s), required: c.required || !1, attributes: { min: c.min || 0, max: c.max || 100, step: c.step || 1, value: c.value || Math.floor(((c.min || 0) + (c.max || 100)) / 2), showValue: c.showValue !== !1, unit: c.unit || "", ...c } }; } } return null; }, validator: (n, e) => { var i, s, a; const t = [], r = Number(e); if (n.required && (e == null || e === "") && t.push({ type: "required", message: `${n.label} is required` }), e != null && e !== "") if (isNaN(r)) t.push({ type: "type", message: `${n.label} must be a number` }); else { const o = ((i = n.attributes) == null ? void 0 : i.min) || 0, l = ((s = n.attributes) == null ? void 0 : s.max) || 100; r < o && t.push({ type: "min", value: o, message: `${n.label} must be at least ${o}` }), r > l && t.push({ type: "max", value: l, message: `${n.label} must be at most ${l}` }); const c = ((a = n.attributes) == null ? void 0 : a.step) || 1; c > 0 && (r - o) % c !== 0 && t.push({ type: "step", value: c, message: `${n.label} must be a multiple of ${c}` }); } return t; }, generator: (n, e) => { var M; const { name: t, label: r, required: i, attributes: s = {} } = n, { min: a = 0, max: o = 100, step: l = 1, value: c = Math.floor((a + o) / 2), showValue: h = !0, unit: d = "" } = s, u = t, p = `${t}-output`, f = (M = e.metadata) == null ? void 0 : M.formId, g = { type: "range", id: u, name: t, min: a, max: o, step: l, value: c, ...i && { required: !0 }, ...f && { form: f }, ...Object.fromEntries(Object.entries(s).filter(([x]) => !["min", "max", "step", "value", "showValue", "unit", "label"].includes(x))) }, m = Object.entries(g).map(([x, V]) => typeof V == "boolean" ? V ? x : "" : `${x}="${V}"`).filter(Boolean).join(" "), T = h ? `<output id="${p}" for="${u}" class="formdown-range-output">${c}${d}</output>` : ""; return ` <div class="formdown-field formdown-range-field"> <label for="${u}">${r}${i ? " *" : ""}</label> <div class="formdown-range-container"> <input ${m} oninput="document.getElementById('${p}').textContent = this.value + '${d}'"> ${T} </div> </div>`; }, dataProcessor: { processInput: (n, e) => { const t = Number(n); return isNaN(t) ? null : t; }, processOutput: (n, e) => { var r; if (n == null) return ""; const t = ((r = e.attributes) == null ? void 0 : r.unit) || ""; return `${n}${t}`; }, validate: (n, e) => { const t = Number(n); return n != null && n !== "" && isNaN(t) ? { valid: !1, error: "Value must be a number" } : { valid: !0 }; }, serialize: (n, e) => String(n), deserialize: (n, e) => { const t = Number(n); return isNaN(t) ? null : t; } }, schemaGenerator: (n) => { var t, r, i; const e = { type: "number", minimum: ((t = n.attributes) == null ? void 0 : t.min) || 0, maximum: ((r = n.attributes) == null ? void 0 : r.max) || 100 }; return (i = n.attributes) != null && i.step && (e.multipleOf = n.attributes.step), n.required && (e.required = !0), n.label && (e.title = n.label), e; }, styles: ` .formdown-range-field .formdown-range-container { display: flex; align-items: center; gap: 12px; } .formdown-range-field input[type="range"] { flex: 1; min-width: 100px; } .formdown-range-output { min-width: 60px; text-align: center; font-weight: 600; padding: 4px 8px; background: #f5f5f5; border-radius: 4px; font-family: monospace; } .formdown-range-field label { display: block; margin-bottom: 8px; font-weight: 500; } `, clientScript: ` // Enhanced range field interactions document.addEventListener('DOMContentLoaded', function() { const rangeFields = document.querySelectorAll('.formdown-range-field input[type="range"]'); rangeFields.forEach(function(input) { // Add keyboard navigation enhancement input.addEventListener('keydown', function(e) { const step = parseFloat(this.step) || 1; const currentValue = parseFloat(this.value); if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') { e.preventDefault(); this.value = Math.max(parseFloat(this.min), currentValue - step); this.dispatchEvent(new Event('input', { bubbles: true })); } else if (e.key === 'ArrowRight' || e.key === 'ArrowUp') { e.preventDefault(); this.value = Math.min(parseFloat(this.max), currentValue + step); this.dispatchEvent(new Event('input', { bubbles: true })); } }); // Add visual feedback on interaction input.addEventListener('input', function() { this.classList.add('active'); setTimeout(() => this.classList.remove('active'), 150); }); }); }); `, defaultAttributes: { min: 0, max: 100, step: 1, showValue: !0 } }; function Wr(n) { const e = {}, t = n.match(/min=(\d+)/); t && (e.min = parseInt(t[1])); const r = n.match(/max=(\d+)/); r && (e.max = parseInt(r[1])); const i = n.match(/step=(\d+\.?\d*)/); i && (e.step = parseFloat(i[1])); const s = n.match(/value=(\d+\.?\d*)/); s && (e.value = parseFloat(s[1])); const a = n.match(/unit="([^"]*)"/); a && (e.unit = a[1]), n.includes("hideValue") && (e.showValue = !1), n.includes("required") && (e.required = !0); const o = n.match(/label="([^"]*)"/); return o && (e.label = o[1]), e; } function Gr(n) { return n.split(/[_-]/).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" "); } const Zr = { type: "text", parser: (n) => { const e = n.match(/@(\w+):\s*\[text\](.*)/); if (!e) return null; const [, t, r] = e, i = Qe(r); return { name: t, type: "text", label: i.label || t, required: i.required || !1, placeholder: i.placeholder, pattern: i.pattern, attributes: i }; }, validator: (n, e) => { const t = []; return n.required && (!e || e.trim() === "") && t.push({ type: "required", message: `${n.label} is required` }), n.pattern && e && !new RegExp(n.pattern).test(e) && t.push({ type: "pattern", value: n.pattern, message: `${n.label} does not match the required pattern` }), t; }, generator: (n) => `<input ${[ 'type="text"', `name="${n.name}"`, `id="${n.name}"`, n.placeholder ? `placeholder="${n.placeholder}"` : "", n.required ? "required" : "", n.pattern ? `pattern="${n.pattern}"` : "" ].filter(Boolean).join(" ")} />` }, Qr = { type: "email", parser: (n) => { const e = n.match(/@(\w+):\s*\[email\](.*)/); if (!e) return null; const [, t, r] = e, i = Qe(r); return { name: t, type: "email", label: i.label || t, required: i.required || !1, placeholder: i.placeholder, attributes: i }; }, validator: (n, e) => { const t = []; return n.required && (!e || e.trim() === "") && t.push({ type: "required", message: `${n.label} is required` }), e && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e) && t.push({ type: "pattern", message: `${n.label} must be a valid email address` }), t; }, generator: (n) => `<input ${[ 'type="email"', `name="${n.name}"`, `id="${n.name}"`, n.placeholder ? `placeholder="${n.placeholder}"` : "", n.required ? "required" : "" ].filter(Boolean).join(" ")} />` }, Kr = { type: "select", parser: (n) => { const e = n.match(/@(\w+):\s*\[select\](.*)/); if (!e) return null; const [, t, r] = e, i = Qe(r), s = ti(r); return { name: t, type: "select", label: i.label || t, required: i.required || !1, options: s, allowOther: i.allowOther || !1, attributes: i }; }, generator: (n) => { const e = [ `name="${n.name}"`, `id="${n.name}"`, n.required ? "required" : "" ].filter(Boolean).join(" "), t = (n.options || []).map((r) => `<option value="${r}">${r}</option>`).join(` `); return `<select ${e}> ${t} </select>`; } }, Yr = { name: "required", validate: (n) => n != null && n !== "", getMessage: (n, e) => n.message || `${e.label} is required` }, Jr = { name: "pattern", validate: (n, e) => !n || !e.value ? !0 : new RegExp(e.value).test(n), getMessage: (n, e) => n.message || `${e.label} does not match the required pattern` }, Xr = { name: "minlength", validate: (n, e) => n ? n.length >= (e.value || 0) : !0, getMessage: (n, e) => n.message || `${e.label} must be at least ${n.value} characters long` }, ei = { metadata: { name: "formdown-core", version: "1.0.0", description: "Built-in field types and validators for Formdown", author: "Formdown Team" }, fieldTypes: [ Zr, Qr, Kr, Nr ], validators: [ Yr, Jr, Xr ] }; function Qe(n) { const e = {}; n.includes("required") && (e.required = !0); const t = n.match(/placeholder="([^"]*)"/); t && (e.placeholder = t[1]); const r = n.match(/label="([^"]*)"/); r && (e.label = r[1]); const i = n.match(/pattern="([^"]*)"/); return i && (e.pattern = i[1]), n.includes("allowOther") && (e.allowOther = !0), e; } function ti(n) { const e = n.match(/options=\[([^\]]*)\]/); return e ? e[1].split(",").map((t) => t.trim().replace(/"/g, "")).filter(Boolean) : []; } class ri { constructor(e = {}) { this.initialized = !1; const t = { async: !0, timeout: 1e3, // Reduced from 5000 to prevent test hangs errorStrategy: "warn", debug: !1, ...e }; this.eventEmitter = new Ur(), this.hookManager = new Br(t, this.eventEmitter), this.fieldTypeRegistry = new jr(), this.pluginManager = new qr(this.hookManager, t, this.eventEmitter, this.fieldTypeRegistry), this.context = { hooks: this.hookManager, plugins: this.pluginManager, fieldTypes: this.fieldTypeRegistry, options: t }, this.setupErrorHandling(); } /** * Initialize the extension system */ async initialize() { if (!this.initialized) { this.eventEmitter.emit("extension-system-initializing"); try { await this.pluginManager.register(ei), await this.pluginManager.initia