dap-design-system
Version:
Official design system for the DÁP (dap.gov.hu)
96 lines (95 loc) • 2.54 kB
JavaScript
import { noChange as f } from "../../lit-html/lit-html.js";
import { AsyncDirective as y } from "../../lit-html/async-directive.js";
import { PartType as s, directive as C } from "../../lit-html/directive.js";
let r = null, u = () => {
};
const l = new Promise((t) => {
u = t;
}), N = {
type: "3rdParty",
/**
* initialize the i18next instance to use
* @param {import('i18next').i18n} i18nextInstance to use
*/
init(t) {
T(t);
}
}, T = (t) => {
r = t, u(r);
}, i = /* @__PURE__ */ new Map(), m = () => {
i.forEach((t, e) => {
(e.isConnected === !1 || h(e) === !1) && i.delete(e);
});
};
setInterval(m, 1e4);
let c = !1;
const d = () => {
i.forEach((t, e) => {
if (e.isConnected && h(e)) {
const n = p(t.keys, t.options);
e.setValue(n);
}
});
};
function p(t, e) {
if (!r)
return "";
c === !1 && (r.on("languageChanged", d), r.store.on("added", d), c = !0);
const n = r.t(t, e);
return typeof n == "string" ? n : "";
}
const h = (t) => {
const e = (
/** @type {import('lit-html/directive.js').Part} */
t.part
);
if (e.type === s.ATTRIBUTE) return e.element.isConnected;
if (e.type === s.CHILD) return e.parentNode ? e.parentNode.isConnected : !1;
if (e.type === s.PROPERTY || e.type === s.BOOLEAN_ATTRIBUTE || e.type === s.EVENT || e.type === s.ELEMENT) return e.element.isConnected;
throw new Error("Unsupported Part");
};
class E extends y {
/** @abstract */
render() {
}
/** @param {import('lit-html/directive.js').PartInfo} part */
constructor(e) {
super(e), this.value = "", this.part = e;
}
/**
* @param {string | string[]} [keys] - translation key
* @param {?any} [options] - i18next translation options
* @returns {string|Symbol} translated string
*/
translate(e, n) {
let o = n;
i.set(this, { keys: e, options: o }), typeof n == "function" && (o = n());
const a = p(e, o);
return this.isConnected === !1 || a === void 0 || this.value === a ? f : a;
}
/** clean up the registry */
disconnected() {
i.delete(this);
}
}
class g extends E {
/**
* @param {string | string[]} [keys] - translation key
* @param {any} [options] - i18next translation options
* @returns {string|Symbol} translated string
*/
render(e, n) {
return l == null || l.then(() => {
this.setValue(this.translate(e, n));
}), f;
}
}
const P = C(g);
export {
N as initLitI18n,
i as registry,
m as registryCleanup,
T as setI18n,
P as translate
};
//# sourceMappingURL=lit-i18n.js.map