UNPKG

dap-design-system

Version:

Official design system for the DÁP (dap.gov.hu)

64 lines (63 loc) 2.21 kB
import { noChange as w } from "../lit-html.js"; import { directive as V, Directive as $, PartType as A } from "../directive.js"; import { getCommittedValue as D, setChildPartValue as h, insertPart as m, removePart as g, setCommittedValue as M } from "../directive-helpers.js"; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const k = (s, f, c) => { const p = /* @__PURE__ */ new Map(); for (let e = f; e <= c; e++) p.set(s[e], e); return p; }, E = V(class extends $ { constructor(s) { if (super(s), s.type !== A.CHILD) throw Error("repeat() can only be used in text expressions"); } dt(s, f, c) { let p; c === void 0 ? c = f : f !== void 0 && (p = f); const e = [], n = []; let l = 0; for (const a of s) e[l] = p ? p(a, l) : l, n[l] = c(a, l), l++; return { values: n, keys: e }; } render(s, f, c) { return this.dt(s, f, c).values; } update(s, [f, c, p]) { var C; const e = D(s), { values: n, keys: l } = this.dt(f, c, p); if (!Array.isArray(e)) return this.ut = l, n; const a = (C = this.ut) != null ? C : this.ut = [], u = []; let v, x, t = 0, o = e.length - 1, r = 0, i = n.length - 1; for (; t <= o && r <= i; ) if (e[t] === null) t++; else if (e[o] === null) o--; else if (a[t] === l[r]) u[r] = h(e[t], n[r]), t++, r++; else if (a[o] === l[i]) u[i] = h(e[o], n[i]), o--, i--; else if (a[t] === l[i]) u[i] = h(e[t], n[i]), m(s, u[i + 1], e[t]), t++, i--; else if (a[o] === l[r]) u[r] = h(e[o], n[r]), m(s, e[t], e[o]), o--, r++; else if (v === void 0 && (v = k(l, r, i), x = k(a, t, o)), v.has(a[t])) if (v.has(a[o])) { const d = x.get(l[r]), y = d !== void 0 ? e[d] : null; if (y === null) { const P = m(s, e[t]); h(P, n[r]), u[r] = P; } else u[r] = h(y, n[r]), m(s, e[t], y), e[d] = null; r++; } else g(e[o]), o--; else g(e[t]), t++; for (; r <= i; ) { const d = m(s, u[i + 1]); h(d, n[r]), u[r++] = d; } for (; t <= o; ) { const d = e[t++]; d !== null && g(d); } return this.ut = l, M(s, u), w; } }); export { E as repeat }; //# sourceMappingURL=repeat.js.map