@formdown/ui
Version:
Pure HTML renderer for Formdown syntax
1,475 lines (1,469 loc) • 221 kB
JavaScript
var br = Object.defineProperty;
var yr = (i, e, t) => e in i ? br(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var $ = (i, e, t) => yr(i, 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(), ft = /* @__PURE__ */ new WeakMap();
let Rt = 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 = ft.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), r && ft.set(t, e));
}
return e;
}
toString() {
return this.cssText;
}
};
const wr = (i) => new Rt(typeof i == "string" ? i : i + "", void 0, We), xr = (i, ...e) => {
const t = i.length === 1 ? i[0] : e.reduce((r, n, 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.");
})(n) + i[s + 1], i[0]);
return new Rt(t, i, We);
}, vr = (i, e) => {
if (Ne) i.adoptedStyleSheets = e.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet);
else for (const t of e) {
const r = document.createElement("style"), n = Ee.litNonce;
n !== void 0 && r.setAttribute("nonce", n), r.textContent = t.cssText, i.appendChild(r);
}
}, mt = Ne ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((e) => {
let t = "";
for (const r of e.cssRules) t += r.cssText;
return wr(t);
})(i) : i;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: $r, defineProperty: kr, getOwnPropertyDescriptor: Er, getOwnPropertyNames: Ar, getOwnPropertySymbols: Sr, getPrototypeOf: _r } = Object, j = globalThis, gt = j.trustedTypes, Tr = gt ? gt.emptyScript : "", De = j.reactiveElementPolyfillSupport, de = (i, e) => i, Se = { toAttribute(i, e) {
switch (e) {
case Boolean:
i = i ? Tr : 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;
} }, Ge = (i, e) => !$r(i, e), bt = { attribute: !0, type: String, converter: Se, reflect: !1, useDefault: !1, hasChanged: Ge };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), j.litPropertyMetadata ?? (j.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 = bt) {
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(), n = this.getPropertyDescriptor(e, r, t);
n !== void 0 && kr(this.prototype, e, n);
}
}
static getPropertyDescriptor(e, t, r) {
const { get: n, set: s } = Er(this.prototype, e) ?? { get() {
return this[t];
}, set(a) {
this[t] = a;
} };
return { get: n, set(a) {
const o = n == null ? void 0 : n.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) ?? bt;
}
static _$Ei() {
if (this.hasOwnProperty(de("elementProperties"))) return;
const e = _r(this);
e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(de("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(de("properties"))) {
const t = this.properties, r = [...Ar(t), ...Sr(t)];
for (const n of r) this.createProperty(n, t[n]);
}
const e = this[Symbol.metadata];
if (e !== null) {
const t = litPropertyMetadata.get(e);
if (t !== void 0) for (const [r, n] of t) this.elementProperties.set(r, n);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [t, r] of this.elementProperties) {
const n = this._$Eu(t, r);
n !== void 0 && this._$Eh.set(n, 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 n of r) t.unshift(mt(n));
} else e !== void 0 && t.push(mt(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 vr(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), n = this.constructor._$Eu(e, r);
if (n !== 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(n) : this.setAttribute(n, a), this._$Em = null;
}
}
_$AK(e, t) {
var s, a;
const r = this.constructor, n = r._$Eh.get(e);
if (n !== void 0 && this._$Em !== n) {
const o = r.getPropertyOptions(n), l = typeof o.converter == "function" ? { fromAttribute: o.converter } : ((s = o.converter) == null ? void 0 : s.fromAttribute) !== void 0 ? o.converter : Se;
this._$Em = n, this[n] = l.fromAttribute(t, o.type) ?? ((a = this._$Ej) == null ? void 0 : a.get(n)) ?? null, this._$Em = null;
}
}
requestUpdate(e, t, r) {
var n;
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 === ((n = this._$Ej) == null ? void 0 : n.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: n, 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)), n === !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 n = this.constructor.elementProperties;
if (n.size > 0) for (const [s, a] of n) {
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((n) => {
var s;
return (s = n.hostUpdate) == null ? void 0 : s.call(n);
}), this.update(t)) : this._$EM();
} catch (n) {
throw e = !1, this._$EM(), n;
}
e && this._$AE(t);
}
willUpdate(e) {
}
_$AE(e) {
var t;
(t = this._$EO) == null || t.forEach((r) => {
var n;
return (n = r.hostUpdated) == null ? void 0 : n.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[de("elementProperties")] = /* @__PURE__ */ new Map(), ee[de("finalized")] = /* @__PURE__ */ new Map(), De == null || De({ ReactiveElement: ee }), (j.reactiveElementVersions ?? (j.reactiveElementVersions = [])).push("2.1.0");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const he = globalThis, _e = he.trustedTypes, yt = _e ? _e.createPolicy("lit-html", { createHTML: (i) => i }) : void 0, Ct = "$lit$", U = `lit$${Math.random().toFixed(9).slice(2)}$`, Lt = "?" + U, Fr = `<${Lt}>`, Y = document, fe = () => Y.createComment(""), me = (i) => i === null || typeof i != "object" && typeof i != "function", Ze = Array.isArray, Mr = (i) => Ze(i) || typeof (i == null ? void 0 : i[Symbol.iterator]) == "function", Pe = `[
\f\r]`, oe = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, wt = /-->/g, xt = />/g, N = RegExp(`>|${Pe}(?:([^\\s"'>=/]+)(${Pe}*=${Pe}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`, "g"), vt = /'/g, $t = /"/g, It = /^(?:script|style|textarea|title)$/i, Rr = (i) => (e, ...t) => ({ _$litType$: i, strings: e, values: t }), $e = Rr(1), te = Symbol.for("lit-noChange"), T = Symbol.for("lit-nothing"), kt = /* @__PURE__ */ new WeakMap(), G = Y.createTreeWalker(Y, 129);
function Dt(i, e) {
if (!Ze(i) || !i.hasOwnProperty("raw")) throw Error("invalid template strings array");
return yt !== void 0 ? yt.createHTML(e) : e;
}
const Cr = (i, e) => {
const t = i.length - 1, r = [];
let n, s = e === 2 ? "<svg>" : e === 3 ? "<math>" : "", a = oe;
for (let o = 0; o < t; o++) {
const l = i[o];
let c, d, u = -1, h = 0;
for (; h < l.length && (a.lastIndex = h, d = a.exec(l), d !== null); ) h = a.lastIndex, a === oe ? d[1] === "!--" ? a = wt : d[1] !== void 0 ? a = xt : d[2] !== void 0 ? (It.test(d[2]) && (n = RegExp("</" + d[2], "g")), a = N) : d[3] !== void 0 && (a = N) : a === N ? d[0] === ">" ? (a = n ?? oe, u = -1) : d[1] === void 0 ? u = -2 : (u = a.lastIndex - d[2].length, c = d[1], a = d[3] === void 0 ? N : d[3] === '"' ? $t : vt) : a === $t || a === vt ? a = N : a === wt || a === xt ? a = oe : (a = N, n = void 0);
const p = a === N && i[o + 1].startsWith("/>") ? " " : "";
s += a === oe ? l + Fr : u >= 0 ? (r.push(c), l.slice(0, u) + Ct + l.slice(u) + U + p) : l + U + (u === -2 ? o : p);
}
return [Dt(i, s + (i[t] || "<?>") + (e === 2 ? "</svg>" : e === 3 ? "</math>" : "")), r];
};
class ge {
constructor({ strings: e, _$litType$: t }, r) {
let n;
this.parts = [];
let s = 0, a = 0;
const o = e.length - 1, l = this.parts, [c, d] = Cr(e, t);
if (this.el = ge.createElement(c, r), G.currentNode = this.el.content, t === 2 || t === 3) {
const u = this.el.content.firstChild;
u.replaceWith(...u.childNodes);
}
for (; (n = G.nextNode()) !== null && l.length < o; ) {
if (n.nodeType === 1) {
if (n.hasAttributes()) for (const u of n.getAttributeNames()) if (u.endsWith(Ct)) {
const h = d[a++], p = n.getAttribute(u).split(U), f = /([.?@])?(.*)/.exec(h);
l.push({ type: 1, index: s, name: f[2], strings: p, ctor: f[1] === "." ? Ir : f[1] === "?" ? Dr : f[1] === "@" ? Pr : Ce }), n.removeAttribute(u);
} else u.startsWith(U) && (l.push({ type: 6, index: s }), n.removeAttribute(u));
if (It.test(n.tagName)) {
const u = n.textContent.split(U), h = u.length - 1;
if (h > 0) {
n.textContent = _e ? _e.emptyScript : "";
for (let p = 0; p < h; p++) n.append(u[p], fe()), G.nextNode(), l.push({ type: 2, index: ++s });
n.append(u[h], fe());
}
}
} else if (n.nodeType === 8) if (n.data === Lt) l.push({ type: 2, index: s });
else {
let u = -1;
for (; (u = n.data.indexOf(U, u + 1)) !== -1; ) l.push({ type: 7, index: s }), u += U.length - 1;
}
s++;
}
}
static createElement(e, t) {
const r = Y.createElement("template");
return r.innerHTML = e, r;
}
}
function re(i, e, t = i, r) {
var a, o;
if (e === te) return e;
let n = r !== void 0 ? (a = t._$Co) == null ? void 0 : a[r] : t._$Cl;
const s = me(e) ? void 0 : e._$litDirective$;
return (n == null ? void 0 : n.constructor) !== s && ((o = n == null ? void 0 : n._$AO) == null || o.call(n, !1), s === void 0 ? n = void 0 : (n = new s(i), n._$AT(i, t, r)), r !== void 0 ? (t._$Co ?? (t._$Co = []))[r] = n : t._$Cl = n), n !== void 0 && (e = re(i, n._$AS(i, e.values), n, r)), e;
}
class Lr {
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, n = ((e == null ? void 0 : e.creationScope) ?? Y).importNode(t, !0);
G.currentNode = n;
let s = G.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 zr(s, this, e)), this._$AV.push(c), l = r[++o];
}
a !== (l == null ? void 0 : l.index) && (s = G.nextNode(), a++);
}
return G.currentNode = Y, n;
}
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, n) {
this.type = 2, this._$AH = T, this._$AN = void 0, this._$AA = e, this._$AB = t, this._$AM = r, this.options = n, this._$Cv = (n == null ? void 0 : n.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), me(e) ? e === T || e == null || e === "" ? (this._$AH !== T && this._$AR(), this._$AH = T) : e !== this._$AH && e !== te && this._(e) : e._$litType$ !== void 0 ? this.$(e) : e.nodeType !== void 0 ? this.T(e) : Mr(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 !== T && me(this._$AH) ? this._$AA.nextSibling.data = e : this.T(Y.createTextNode(e)), this._$AH = e;
}
$(e) {
var s;
const { values: t, _$litType$: r } = e, n = typeof r == "number" ? this._$AC(e) : (r.el === void 0 && (r.el = ge.createElement(Dt(r.h, r.h[0]), this.options)), r);
if (((s = this._$AH) == null ? void 0 : s._$AD) === n) this._$AH.p(t);
else {
const a = new Lr(n, this), o = a.u(this.options);
a.p(t), this.T(o), this._$AH = a;
}
}
_$AC(e) {
let t = kt.get(e.strings);
return t === void 0 && kt.set(e.strings, t = new ge(e)), t;
}
k(e) {
Ze(this._$AH) || (this._$AH = [], this._$AR());
const t = this._$AH;
let r, n = 0;
for (const s of e) n === t.length ? t.push(r = new be(this.O(fe()), this.O(fe()), this, this.options)) : r = t[n], r._$AI(s), n++;
n < t.length && (this._$AR(r && r._$AB.nextSibling, n), t.length = n);
}
_$AR(e = this._$AA.nextSibling, t) {
var r;
for ((r = this._$AP) == null ? void 0 : r.call(this, !1, !0, t); e && e !== this._$AB; ) {
const n = e.nextSibling;
e.remove(), e = n;
}
}
setConnected(e) {
var t;
this._$AM === void 0 && (this._$Cv = e, (t = this._$AP) == null || t.call(this, e));
}
}
class Ce {
get tagName() {
return this.element.tagName;
}
get _$AU() {
return this._$AM._$AU;
}
constructor(e, t, r, n, s) {
this.type = 1, this._$AH = T, this._$AN = void 0, this.element = e, this.name = t, this._$AM = n, this.options = s, r.length > 2 || r[0] !== "" || r[1] !== "" ? (this._$AH = Array(r.length - 1).fill(new String()), this.strings = r) : this._$AH = T;
}
_$AI(e, t = this, r, n) {
const s = this.strings;
let a = !1;
if (s === void 0) e = re(this, e, t, 0), a = !me(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 = !me(c) || c !== this._$AH[l]), c === T ? e = T : e !== T && (e += (c ?? "") + s[l + 1]), this._$AH[l] = c;
}
a && !n && this.j(e);
}
j(e) {
e === T ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, e ?? "");
}
}
class Ir extends Ce {
constructor() {
super(...arguments), this.type = 3;
}
j(e) {
this.element[this.name] = e === T ? void 0 : e;
}
}
class Dr extends Ce {
constructor() {
super(...arguments), this.type = 4;
}
j(e) {
this.element.toggleAttribute(this.name, !!e && e !== T);
}
}
class Pr extends Ce {
constructor(e, t, r, n, s) {
super(e, t, r, n, s), this.type = 5;
}
_$AI(e, t = this) {
if ((e = re(this, e, t, 0) ?? T) === te) return;
const r = this._$AH, n = e === T && r !== T || e.capture !== r.capture || e.once !== r.once || e.passive !== r.passive, s = e !== T && (r === T || n);
n && 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 zr {
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 ze = he.litHtmlPolyfillSupport;
ze == null || ze(ge, be), (he.litHtmlVersions ?? (he.litHtmlVersions = [])).push("3.3.0");
const Or = (i, e, t) => {
const r = (t == null ? void 0 : t.renderBefore) ?? e;
let n = r._$litPart$;
if (n === void 0) {
const s = (t == null ? void 0 : t.renderBefore) ?? null;
r._$litPart$ = n = new be(e.insertBefore(fe(), s), s, void 0, t ?? {});
}
return n._$AI(i), n;
};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const Z = globalThis;
class ue 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 Mt;
ue._$litElement$ = !0, ue.finalized = !0, (Mt = Z.litElementHydrateSupport) == null || Mt.call(Z, { LitElement: ue });
const Oe = Z.litElementPolyfillSupport;
Oe == null || Oe({ LitElement: ue });
(Z.litElementVersions ?? (Z.litElementVersions = [])).push("4.2.0");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const Br = (i) => (e, t) => {
t !== void 0 ? t.addInitializer(() => {
customElements.define(i, e);
}) : customElements.define(i, 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 = (i = Hr, e, t) => {
const { kind: r, metadata: n } = t;
let s = globalThis.litPropertyMetadata.get(n);
if (s === void 0 && globalThis.litPropertyMetadata.set(n, s = /* @__PURE__ */ new Map()), r === "setter" && ((i = Object.create(i)).wrapped = !0), s.set(t.name, i), r === "accessor") {
const { name: a } = t;
return { set(o) {
const l = e.get.call(this);
e.set.call(this, o), this.requestUpdate(a, l, i);
}, init(o) {
return o !== void 0 && this.C(a, void 0, i, o), o;
} };
}
if (r === "setter") {
const { name: a } = t;
return function(o) {
const l = this[a];
e.call(this, o), this.requestUpdate(a, l, i);
};
}
throw Error("Unsupported decorator location: " + r);
};
function ne(i) {
return (e, t) => typeof t == "object" ? Vr(i, e, t) : ((r, n, s) => {
const a = n.hasOwnProperty(s);
return n.constructor.createProperty(s, r), a ? Object.getOwnPropertyDescriptor(n, s) : void 0;
})(i, e, t);
}
class qr {
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, n) => n.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) || [], n = r.filter((s) => s.handler !== t);
n.length !== r.length && (this.hooks.set(e, n), this.emit("hook-unregistered", { hook: e }), this.options.debug && console.debug(`[Formdown] Hook unregistered: ${e}`));
}
/**
* Execute hooks asynchronously
*/
async execute(e, t, ...r) {
const n = this.hooks.get(e) || [], s = [];
this.emit("hooks-executing", { hook: e, count: n.length });
for (const a of n) {
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 n = this.hooks.get(e) || [], s = [];
this.emit("hooks-executing", { hook: e, count: n.length });
for (const a of n)
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 Ur {
constructor(e, t = {}, r, n) {
this.hookManager = e, this.options = t, this.eventEmitter = r, this.fieldTypeRegistry = n, 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 (n) {
this.handlePluginError(e, "cleanup", n);
}
if (t.hooks)
for (const n of t.hooks)
this.hookManager.unregister(n.name, n.handler);
if (t.fieldTypes)
for (const n of t.fieldTypes)
this.fieldTypes.delete(n.type), (r = this.fieldTypeRegistry) == null || r.unregister(n.type);
if (t.validators)
for (const n of t.validators)
this.validators.delete(n.name);
if (t.renderers)
for (const n of t.renderers)
this.renderers.delete(n.template);
if (t.themes)
for (const n of t.themes)
this.themes.delete(n.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 n = `Plugin ${t} failed: ${e} - ${r.message || r}`;
switch (this.emit("plugin-error", {
plugin: e,
operation: t,
error: n
}), this.options.errorStrategy) {
case "ignore":
break;
case "warn":
console.warn(`[Formdown] ${n}`);
break;
case "throw":
default:
throw new Error(n);
}
}
/**
* Emit events if event emitter is available
*/
emit(e, t) {
this.eventEmitter && this.eventEmitter.emit(e, t);
}
}
class jr {
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 n = {
type: e,
data: t,
timestamp: Date.now()
};
for (const s of r)
try {
s(n);
} catch (a) {
console.error(`[Formdown] Event listener error in '${e}':`, a);
}
}
/**
* Register a one-time event listener
*/
once(e, t) {
const r = (n) => {
t(n), this.off(n.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 Nr {
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 n = r.parser(e, t);
if (n)
return r.defaultAttributes && (n.attributes = {
...r.defaultAttributes,
...n.attributes
}), n;
}
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 n = this.fieldTypes.get(e.type), s = n == null ? void 0 : n.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), n = r == null ? void 0 : r.dataProcessor;
return n != null && n.validate ? n.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 Wr = {
type: "range",
parser: (i, 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 n = i.match(r);
if (n) {
const [, s, a, o = "", l = ""] = n, c = Gr((o || "") + (l || ""));
return {
name: s,
type: "range",
label: a || c.label || Zr(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: (i, e) => {
var n, s, a;
const t = [], r = Number(e);
if (i.required && (e == null || e === "") && t.push({
type: "required",
message: `${i.label} is required`
}), e != null && e !== "")
if (isNaN(r))
t.push({
type: "type",
message: `${i.label} must be a number`
});
else {
const o = Number((n = i.attributes) == null ? void 0 : n.min) || 0, l = Number((s = i.attributes) == null ? void 0 : s.max) || 100;
r < o && t.push({
type: "min",
value: o,
message: `${i.label} must be at least ${o}`
}), r > l && t.push({
type: "max",
value: l,
message: `${i.label} must be at most ${l}`
});
const c = Number((a = i.attributes) == null ? void 0 : a.step) || 1;
c > 0 && (r - o) % c !== 0 && t.push({
type: "step",
value: c,
message: `${i.label} must be a multiple of ${c}`
});
}
return t;
},
generator: (i, e) => {
var _;
const { name: t, label: r, required: n, attributes: s = {} } = i, a = Number(s.min) || 0, o = Number(s.max) || 100, l = Number(s.step) || 1, c = s.value !== void 0 ? Number(s.value) : Math.floor((a + o) / 2), d = s.showValue !== !1, u = String(s.unit ?? ""), h = t, p = `${t}-output`, f = (_ = e.metadata) == null ? void 0 : _.formId, m = {
type: "range",
id: h,
name: t,
min: a,
max: o,
step: l,
value: c,
...n && { required: !0 },
...f && { form: f },
...Object.fromEntries(Object.entries(s).filter(([b]) => !["min", "max", "step", "value", "showValue", "unit", "label"].includes(b)))
}, g = Object.entries(m).map(([b, L]) => typeof L == "boolean" ? L ? b : "" : `${b}="${L}"`).filter(Boolean).join(" "), A = d ? `<output id="${p}" for="${h}" class="formdown-range-output">${c}${u}</output>` : "";
return `
<div class="formdown-field formdown-range-field">
<label for="${h}">${r}${n ? " *" : ""}</label>
<div class="formdown-range-container">
<input ${g} data-formdown-range-output="${p}" data-formdown-range-unit="${u}">
${A}
</div>
</div>`;
},
dataProcessor: {
processInput: (i, e) => {
const t = Number(i);
return isNaN(t) ? null : t;
},
processOutput: (i, e) => {
var r;
if (i == null)
return "";
const t = ((r = e.attributes) == null ? void 0 : r.unit) || "";
return `${i}${t}`;
},
validate: (i, e) => {
const t = Number(i);
return i != null && i !== "" && isNaN(t) ? { valid: !1, error: "Value must be a number" } : { valid: !0 };
},
serialize: (i, e) => String(i),
deserialize: (i, e) => {
const t = Number(i);
return isNaN(t) ? null : t;
}
},
schemaGenerator: (i) => {
var t, r, n;
const e = {
type: "number",
minimum: ((t = i.attributes) == null ? void 0 : t.min) || 0,
maximum: ((r = i.attributes) == null ? void 0 : r.max) || 100
};
return (n = i.attributes) != null && n.step && (e.multipleOf = i.attributes.step), i.required && (e.required = !0), i.label && (e.title = i.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 Gr(i) {
const e = {}, t = i.match(/min=(\d+)/);
t && (e.min = parseInt(t[1]));
const r = i.match(/max=(\d+)/);
r && (e.max = parseInt(r[1]));
const n = i.match(/step=(\d+\.?\d*)/);
n && (e.step = parseFloat(n[1]));
const s = i.match(/value=(\d+\.?\d*)/);
s && (e.value = parseFloat(s[1]));
const a = i.match(/unit="([^"]*)"/);
a && (e.unit = a[1]), i.includes("hideValue") && (e.showValue = !1), i.includes("required") && (e.required = !0);
const o = i.match(/label="([^"]*)"/);
return o && (e.label = o[1]), e;
}
function Zr(i) {
return i.split(/[_-]/).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
}
const Qr = {
type: "text",
parser: (i) => {
const e = i.match(/@(\w+):\s*\[text\](.*)/);
if (!e)
return null;
const [, t, r] = e, n = Qe(r);
return {
name: t,
type: "text",
label: n.label || t,
required: n.required || !1,
placeholder: n.placeholder,
pattern: n.pattern,
attributes: n
};
},
validator: (i, e) => {
const t = [];
return i.required && (!e || e.trim() === "") && t.push({
type: "required",
message: `${i.label} is required`
}), i.pattern && e && !new RegExp(i.pattern).test(e) && t.push({
type: "pattern",
value: i.pattern,
message: `${i.label} does not match the required pattern`
}), t;
},
generator: (i) => `<input ${[
'type="text"',
`name="${i.name}"`,
`id="${i.name}"`,
i.placeholder ? `placeholder="${i.placeholder}"` : "",
i.required ? "required" : "",
i.pattern ? `pattern="${i.pattern}"` : ""
].filter(Boolean).join(" ")} />`
}, Yr = {
type: "email",
parser: (i) => {
const e = i.match(/@(\w+):\s*\[email\](.*)/);
if (!e)
return null;
const [, t, r] = e, n = Qe(r);
return {
name: t,
type: "email",
label: n.label || t,
required: n.required || !1,
placeholder: n.placeholder,
attributes: n
};
},
validator: (i, e) => {
const t = [];
return i.required && (!e || e.trim() === "") && t.push({
type: "required",
message: `${i.label} is required`
}), e && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e) && t.push({
type: "pattern",
message: `${i.label} must be a valid email address`
}), t;
},
generator: (i) => `<input ${[
'type="email"',
`name="${i.name}"`,
`id="${i.name}"`,
i.placeholder ? `placeholder="${i.placeholder}"` : "",
i.required ? "required" : ""
].filter(Boolean).join(" ")} />`
}, Kr = {
type: "select",
parser: (i) => {
const e = i.match(/@(\w+):\s*\[select\](.*)/);
if (!e)
return null;
const [, t, r] = e, n = Qe(r), s = rn(r);
return {
name: t,
type: "select",
label: n.label || t,
required: n.required || !1,
options: s,
allowOther: n.allowOther || !1,
attributes: n
};
},
generator: (i) => {
const e = [
`name="${i.name}"`,
`id="${i.name}"`,
i.required ? "required" : ""
].filter(Boolean).join(" "), t = (i.options || []).map((r) => `<option value="${r}">${r}</option>`).join(`
`);
return `<select ${e}>
${t}
</select>`;
}
}, Jr = {
name: "required",
validate: (i) => i != null && i !== "",
getMessage: (i, e) => i.message || `${e.label} is required`
}, Xr = {
name: "pattern",
validate: (i, e) => !i || !e.value ? !0 : new RegExp(e.value).test(i),
getMessage: (i, e) => i.message || `${e.label} does not match the required pattern`
}, en = {
name: "minlength",
validate: (i, e) => i ? i.length >= (e.value || 0) : !0,
getMessage: (i, e) => i.message || `${e.label} must be at least ${i.value} characters long`
}, tn = {
metadata: {
name: "formdown-core",
version: "1.0.0",
description: "Built-in field types and validators for Formdown",
author: "Formdown Team"
},
fieldTypes: [
Qr,
Yr,
Kr,
Wr
],
validators: [
Jr,
Xr,
en
]
};
function Qe(i) {
const e = {};
i.includes("required") && (e.required = !0);
const t = i.match(/placeholder="([^"]*)"/);
t && (e.placeholder = t[1]);
const r = i.match(/label="([^"]*)"/);
r && (e.label = r[1]);
const n = i.match(/pattern="([^"]*)"/);
return n && (e.pattern = n[1]), i.includes("allowOther") && (e.allowOther = !0), e;
}
function rn(i) {
const e = i.match(/options=\[([^\]]*)\]/);
return e ? e[1].split(",").map((t) => t.trim().replace(/"/g, "")).filter(Boolean) : [];
}
class nn {
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 jr(), this.hookManager = new qr(t, this.eventEmitter), this.fieldTypeRegistry = new Nr(), this.pluginManager = new Ur(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 {
aw