UNPKG

solid-intlayer

Version:

Easily internationalize i18n your Solid applications with type-safe multilingual content management.

568 lines (567 loc) 14.8 kB
import { sharedConfig as u, createMemo as E, createRenderEffect as m, splitProps as x, untrack as $ } from "solid-js"; const L = [ "allowfullscreen", "async", "alpha", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "inert", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected", "adauctionheaders", "browsingtopics", "credentialless", "defaultchecked", "defaultmuted", "defaultselected", "defer", "disablepictureinpicture", "disableremoteplayback", "preservespitch", "shadowrootclonable", "shadowrootcustomelementregistry", "shadowrootdelegatesfocus", "shadowrootserializable", "sharedstoragewritable" ], I = /* @__PURE__ */ new Set([ "className", "value", "readOnly", "noValidate", "formNoValidate", "isMap", "noModule", "playsInline", "adAuctionHeaders", "allowFullscreen", "browsingTopics", "defaultChecked", "defaultMuted", "defaultSelected", "disablePictureInPicture", "disableRemotePlayback", "preservesPitch", "shadowRootClonable", "shadowRootCustomElementRegistry", "shadowRootDelegatesFocus", "shadowRootSerializable", "sharedStorageWritable", ...L ]), O = /* @__PURE__ */ new Set(["innerHTML", "textContent", "innerText", "children"]), k = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(null), { className: "class", htmlFor: "for" }), D = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(null), { class: "className", novalidate: { $: "noValidate", FORM: 1 }, formnovalidate: { $: "formNoValidate", BUTTON: 1, INPUT: 1 }, ismap: { $: "isMap", IMG: 1 }, nomodule: { $: "noModule", SCRIPT: 1 }, playsinline: { $: "playsInline", VIDEO: 1 }, readonly: { $: "readOnly", INPUT: 1, TEXTAREA: 1 }, adauctionheaders: { $: "adAuctionHeaders", IFRAME: 1 }, allowfullscreen: { $: "allowFullscreen", IFRAME: 1 }, browsingtopics: { $: "browsingTopics", IMG: 1 }, defaultchecked: { $: "defaultChecked", INPUT: 1 }, defaultmuted: { $: "defaultMuted", AUDIO: 1, VIDEO: 1 }, defaultselected: { $: "defaultSelected", OPTION: 1 }, disablepictureinpicture: { $: "disablePictureInPicture", VIDEO: 1 }, disableremoteplayback: { $: "disableRemotePlayback", AUDIO: 1, VIDEO: 1 }, preservespitch: { $: "preservesPitch", AUDIO: 1, VIDEO: 1 }, shadowrootclonable: { $: "shadowRootClonable", TEMPLATE: 1 }, shadowrootdelegatesfocus: { $: "shadowRootDelegatesFocus", TEMPLATE: 1 }, shadowrootserializable: { $: "shadowRootSerializable", TEMPLATE: 1 }, sharedstoragewritable: { $: "sharedStorageWritable", IFRAME: 1, IMG: 1 } }); function R(i, e) { const t = D[i]; return typeof t == "object" ? t[e] ? t.$ : void 0 : t; } const p = /* @__PURE__ */ new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]), F = /* @__PURE__ */ new Set([ "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", "set", "stop", "svg", "switch", "symbol", "text", "textPath", "tref", "tspan", "use", "view", "vkern" ]), B = { xlink: "http://www.w3.org/1999/xlink", xml: "http://www.w3.org/XML/1998/namespace" }, se = (i) => E(() => i()); function G(i, e, t) { let l = t.length, n = e.length, o = l, f = 0, s = 0, c = e[n - 1].nextSibling, r = null; for (; f < n || s < o; ) { if (e[f] === t[s]) { f++, s++; continue; } for (; e[n - 1] === t[o - 1]; ) n--, o--; if (n === f) { const d = o < l ? s ? t[s - 1].nextSibling : t[o - s] : c; for (; s < o; ) i.insertBefore(t[s++], d); } else if (o === s) for (; f < n; ) (!r || !r.has(e[f])) && e[f].remove(), f++; else if (e[f] === t[o - 1] && t[s] === e[n - 1]) { const d = e[--n].nextSibling; i.insertBefore(t[s++], e[f++].nextSibling), i.insertBefore(t[--o], d), e[n] = t[o]; } else { if (!r) { r = /* @__PURE__ */ new Map(); let h = s; for (; h < o; ) r.set(t[h], h++); } const d = r.get(e[f]); if (d != null) if (s < d && d < o) { let h = f, a = 1, g; for (; ++h < n && h < o && !((g = r.get(e[h])) == null || g !== d + a); ) a++; if (a > d - s) { const A = e[f]; for (; s < d; ) i.insertBefore(t[s++], A); } else i.replaceChild(t[s++], e[f++]); } else f++; else e[f++].remove(); } } } const N = "_$DX_DELEGATE"; function ne(i, e, t, l) { let n; const o = () => { const s = document.createElement("template"); return s.innerHTML = i, s.content.firstChild; }, f = () => (n || (n = o())).cloneNode(!0); return f.cloneNode = f, f; } function V(i, e = window.document) { const t = e[N] || (e[N] = /* @__PURE__ */ new Set()); for (let l = 0, n = i.length; l < n; l++) { const o = i[l]; t.has(o) || (t.add(o), e.addEventListener(o, Q)); } } function T(i, e, t) { y(i) || (t == null ? i.removeAttribute(e) : i.setAttribute(e, t)); } function j(i, e, t, l) { y(i) || (l == null ? i.removeAttributeNS(e, t) : i.setAttributeNS(e, t, l)); } function U(i, e, t) { y(i) || (t ? i.setAttribute(e, "") : i.removeAttribute(e)); } function _(i, e) { y(i) || (e == null ? i.removeAttribute("class") : i.className = e); } function H(i, e, t, l) { if (l) Array.isArray(t) ? (i[`$$${e}`] = t[0], i[`$$${e}Data`] = t[1]) : i[`$$${e}`] = t; else if (Array.isArray(t)) { const n = t[0]; i.addEventListener(e, t[0] = (o) => n.call(i, t[1], o)); } else i.addEventListener(e, t, typeof t != "function" && t); } function K(i, e, t = {}) { const l = Object.keys(e || {}), n = Object.keys(t); let o, f; for (o = 0, f = n.length; o < f; o++) { const s = n[o]; !s || s === "undefined" || e[s] || (P(i, s, !1), delete t[s]); } for (o = 0, f = l.length; o < f; o++) { const s = l[o], c = !!e[s]; !s || s === "undefined" || t[s] === c || !c || (P(i, s, !0), t[s] = c); } return t; } function X(i, e, t) { if (!e) return t ? T(i, "style") : e; const l = i.style; if (typeof e == "string") return l.cssText = e; typeof t == "string" && (l.cssText = t = void 0), t || (t = {}), e || (e = {}); let n, o; for (o in t) e[o] == null && l.removeProperty(o), delete t[o]; for (o in e) n = e[o], n !== t[o] && (l.setProperty(o, n), t[o] = n); return t; } function q(i, e = {}, t, l) { const n = {}; return l || m(() => n.children = w(i, e.children, n.children)), m(() => typeof e.ref == "function" && W(e.ref, i)), m(() => Y(i, e, t, !0, n, !0)), n; } function W(i, e, t) { return $(() => i(e, t)); } function oe(i, e, t, l) { if (typeof e != "function") return w(i, e, l, t); m((n) => w(i, e(), n, t), l); } function Y(i, e, t, l, n = {}, o = !1) { e || (e = {}); for (const f in n) if (!(f in e)) { if (f === "children") continue; n[f] = S(i, f, null, n[f], t, o, e); } for (const f in e) { if (f === "children") continue; const s = e[f]; n[f] = S(i, f, s, n[f], t, o, e); } } function z(i) { let e, t; return !y() || !(e = u.registry.get(t = Z())) ? i() : (u.completed && u.completed.add(e), u.registry.delete(t), e); } function y(i) { return !!u.context && !u.done && (!i || i.isConnected); } function J(i) { return i.toLowerCase().replace(/-([a-z])/g, (e, t) => t.toUpperCase()); } function P(i, e, t) { const l = e.trim().split(/\s+/); for (let n = 0, o = l.length; n < o; n++) i.classList.toggle(l[n], t); } function S(i, e, t, l, n, o, f) { let s, c, r, d, h; if (e === "style") return X(i, t, l); if (e === "classList") return K(i, t, l); if (t === l) return l; if (e === "ref") o || t(i); else if (e.slice(0, 3) === "on:") { const a = e.slice(3); l && i.removeEventListener(a, l, typeof l != "function" && l), t && i.addEventListener(a, t, typeof t != "function" && t); } else if (e.slice(0, 10) === "oncapture:") { const a = e.slice(10); l && i.removeEventListener(a, l, !0), t && i.addEventListener(a, t, !0); } else if (e.slice(0, 2) === "on") { const a = e.slice(2).toLowerCase(), g = p.has(a); if (!g && l) { const A = Array.isArray(l) ? l[0] : l; i.removeEventListener(a, A); } (g || t) && (H(i, a, t, g), g && V([a])); } else if (e.slice(0, 5) === "attr:") T(i, e.slice(5), t); else if (e.slice(0, 5) === "bool:") U(i, e.slice(5), t); else if ((h = e.slice(0, 5) === "prop:") || (r = O.has(e)) || !n && ((d = R(e, i.tagName)) || (c = I.has(e))) || (s = i.nodeName.includes("-") || "is" in f)) { if (h) e = e.slice(5), c = !0; else if (y(i)) return t; e === "class" || e === "className" ? _(i, t) : s && !c && !r ? i[J(e)] = t : i[d || e] = t; } else { const a = n && e.indexOf(":") > -1 && B[e.split(":")[0]]; a ? j(i, a, e, t) : T(i, k[e] || e, t); } return t; } function Q(i) { if (u.registry && u.events && u.events.find(([c, r]) => r === i)) return; let e = i.target; const t = `$$${i.type}`, l = i.target, n = i.currentTarget, o = (c) => Object.defineProperty(i, "target", { configurable: !0, value: c }), f = () => { const c = e[t]; if (c && !e.disabled) { const r = e[`${t}Data`]; if (r !== void 0 ? c.call(e, r, i) : c.call(e, i), i.cancelBubble) return; } return e.host && typeof e.host != "string" && !e.host._$host && e.contains(i.target) && o(e.host), !0; }, s = () => { for (; f() && (e = e._$host || e.parentNode || e.host); ) ; }; if (Object.defineProperty(i, "currentTarget", { configurable: !0, get() { return e || document; } }), u.registry && !u.done && (u.done = _$HY.done = !0), i.composedPath) { const c = i.composedPath(); o(c[0]); for (let r = 0; r < c.length - 2 && (e = c[r], !!f()); r++) { if (e._$host) { e = e._$host, s(); break; } if (e.parentNode === n) break; } } else s(); o(l); } function w(i, e, t, l, n) { const o = y(i); if (o) { !t && (t = [...i.childNodes]); let s = []; for (let c = 0; c < t.length; c++) { const r = t[c]; r.nodeType === 8 && r.data.slice(0, 2) === "!$" ? r.remove() : s.push(r); } t = s; } for (; typeof t == "function"; ) t = t(); if (e === t) return t; const f = typeof e; if (i = i, f === "string" || f === "number") { if (o || f === "number" && (e = e.toString(), e === t)) return t; t !== "" && typeof t == "string" ? t = i.firstChild.data = e : t = i.textContent = e; } else if (e == null || f === "boolean") { if (o) return t; t = b(i, t, l); } else { if (f === "function") return m(() => { let s = e(); for (; typeof s == "function"; ) s = s(); t = w(i, s, t, l); }), () => t; if (Array.isArray(e)) { const s = [], c = t && Array.isArray(t); if (C(s, e, t, n)) return m(() => t = w(i, s, t, l, !0)), () => t; if (o) return s.length ? t = [...i.childNodes] : t; s.length === 0 ? t = b(i, t, l) : c ? t.length === 0 ? M(i, s, l) : G(i, t, s) : (t && b(i), M(i, s)), t = s; } else if (e.nodeType) { if (o && e.parentNode) return t = e; Array.isArray(t) ? b(i, t, null, e) : t == null || t === "" || !i.firstChild ? i.appendChild(e) : i.replaceChild(e, i.firstChild), t = e; } } return t; } function C(i, e, t, l) { let n = !1; for (let o = 0, f = e.length; o < f; o++) { let s = e[o], c = t && t[i.length], r; if (!(s == null || s === !0 || s === !1)) if ((r = typeof s) == "object" && s.nodeType) i.push(s); else if (Array.isArray(s)) n = C(i, s, c) || n; else if (r === "function") if (l) { for (; typeof s == "function"; ) s = s(); n = C(i, Array.isArray(s) ? s : [s], Array.isArray(c) ? c : [c]) || n; } else i.push(s), n = !0; else { const d = String(s); c && c.nodeType === 3 && c.data === d ? i.push(c) : i.push(document.createTextNode(d)); } } return n; } function M(i, e, t = null) { for (let l = 0, n = e.length; l < n; l++) i.insertBefore(e[l], t); } function b(i, e, t, l) { if (t === void 0) return i.textContent = ""; const n = l || document.createTextNode(""); if (e.length) { let o = !1; for (let f = e.length - 1; f >= 0; f--) { const s = e[f]; if (n !== s) { const c = s.parentNode === i; !o && !f ? c ? i.replaceChild(n, s) : i.insertBefore(n, t) : c && s.remove(); } else o = !0; } } else i.insertBefore(n, t); return [n]; } function Z() { return u.getNextContextId(); } const v = "http://www.w3.org/2000/svg"; function ee(i, e = !1, t = void 0) { return e ? document.createElementNS(v, i) : document.createElement(i, { is: t }); } function te(i, e) { const t = E(i); return E(() => { const l = t(); switch (typeof l) { case "function": return $(() => l(e)); case "string": const n = F.has(l), o = u.context ? z() : ee(l, n, $(() => e.is)); return q(o, e, n), o; } }); } function le(i) { const [, e] = x(i, ["component"]); return te(() => i.component, e); } export { le as D, V as d, oe as i, se as m, q as s, ne as t, W as u };