@freact/core
Advanced tools
| export declare function raise(err: string): never; |
+196
-206
| function f(s, e, ...t) { | ||
| const n = e && Object.hasOwn(e, "key"), o = e?.key; | ||
| if (delete e?.key, s === N) | ||
| return n && (t.key = o), t.length > 0 ? t : void 0; | ||
| const h = { | ||
| const n = e && Object.hasOwn(e, "key"), l = e?.key; | ||
| if (delete e?.key, s === D) | ||
| return n && (t.key = l), t.length > 0 ? t : void 0; | ||
| const p = { | ||
| type: s, | ||
@@ -11,5 +11,8 @@ props: { | ||
| }; | ||
| return t.length > 0 && (h.props.children = t.length > 1 ? t : t[0]), n && (h.key = o), h; | ||
| return t.length > 0 && (p.props.children = t.length > 1 ? t : t[0]), n && (p.key = l), p; | ||
| } | ||
| const r = { | ||
| function v(s) { | ||
| throw new Error(s); | ||
| } | ||
| const i = { | ||
| root: null, | ||
@@ -19,22 +22,21 @@ data: null, | ||
| }; | ||
| function I(s, e) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useMemo hook"); | ||
| const t = r.data.hookData, n = r.index++; | ||
| function G(s, e) { | ||
| (!i.root || !i.data) && v("Missing context data inside useMemo hook"); | ||
| const t = i.data.hookData, n = i.index++; | ||
| if (!Object.hasOwn(t, n)) | ||
| t[n] = { val: s(), deps: e }; | ||
| else { | ||
| let o = t[n].deps.length === e.length; | ||
| if (o) { | ||
| for (let h = 0; h < e.length; h++) | ||
| if (!Object.is(t[n].deps[h], e[h])) { | ||
| o = !1; | ||
| let l = t[n].deps.length === e.length; | ||
| if (l) { | ||
| for (let p = 0; p < e.length; p++) | ||
| if (!Object.is(t[n].deps[p], e[p])) { | ||
| l = !1; | ||
| break; | ||
| } | ||
| } | ||
| o || (t[n].val = s(), t[n].deps = e); | ||
| l || (t[n].val = s(), t[n].deps = e); | ||
| } | ||
| return t[n].val; | ||
| } | ||
| const K = (s, e) => { | ||
| const W = (s, e) => { | ||
| const t = Object.keys(e); | ||
@@ -49,22 +51,21 @@ if (t.length !== Object.keys(s).length) | ||
| return !1; | ||
| for (let o = 0; o < e.children.length; o++) | ||
| if (!Object.is(e.children[o], s.children[o])) | ||
| for (let l = 0; l < e.children.length; l++) | ||
| if (!Object.is(e.children[l], s.children[l])) | ||
| return !1; | ||
| } | ||
| for (const o of t) | ||
| if (o !== "children" && !Object.is(s[o], e[o])) | ||
| for (const l of t) | ||
| if (l !== "children" && !Object.is(s[l], e[l])) | ||
| return !1; | ||
| return !0; | ||
| }; | ||
| function U(s, e = K) { | ||
| function $(s, e = W) { | ||
| let t = !1; | ||
| return (n) => (t = e( | ||
| r.data?.self.value.__context?.prevProps ?? {}, | ||
| i.data?.self.value.__context?.prevProps ?? {}, | ||
| n | ||
| ) ? t : !t, I(() => f(s, n), [t])); | ||
| ) ? t : !t, G(() => f(s, n), [t])); | ||
| } | ||
| function W(s, e) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useEffect hook"); | ||
| const t = r.data.hookData, n = r.index++; | ||
| function V(s, e) { | ||
| (!i.root || !i.data) && v("Missing context data inside useEffect hook"); | ||
| const t = i.data.hookData, n = i.index++; | ||
| if (!Object.hasOwn(t, n)) | ||
@@ -75,33 +76,27 @@ t[n] = { | ||
| deps: e ?? null | ||
| }, r.data.fx.push(t[n]); | ||
| }, i.data.fx.push(t[n]); | ||
| else { | ||
| let o = !!t[n].deps && t[n].deps?.length === e?.length; | ||
| if (o) { | ||
| for (let h = 0; h < e.length; h++) | ||
| if (!Object.is(t[n].deps[h], e[h])) { | ||
| o = !1; | ||
| let l = !!t[n].deps && t[n].deps?.length === e?.length; | ||
| if (l) { | ||
| for (let p = 0; p < e.length; p++) | ||
| if (!Object.is(t[n].deps[p], e[p])) { | ||
| l = !1; | ||
| break; | ||
| } | ||
| } | ||
| o || (t[n].effect = s, t[n].deps = e ?? null); | ||
| l || (t[n].effect = s, t[n].deps = e ?? null); | ||
| } | ||
| } | ||
| function V(s) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useContext hook"); | ||
| const e = r.data.hookData, t = r.index++, n = r.data.self; | ||
| function q(s) { | ||
| (!i.root || !i.data) && v("Missing context data inside useContext hook"); | ||
| const e = i.data.hookData, t = i.index++, n = i.data.self; | ||
| if (!Object.hasOwn(e, t)) { | ||
| let o = r.data.parent?.value; | ||
| for (; o && o.type !== s.Provider; ) | ||
| o = o.__context?.parent?.value; | ||
| if (o) { | ||
| if (!o.__context?.providerData) | ||
| throw new Error("Provider doesn't contain ProviderData. How?"); | ||
| o.__context.providerData.subs.add(n), e[t] = o.__context.providerData; | ||
| } else | ||
| e[t] = { val: s.__defaultValue }; | ||
| let l = i.data.parent?.value; | ||
| for (; l && l.type !== s.Provider; ) | ||
| l = l.__context?.parent?.value; | ||
| l ? (l.__context?.providerData || v("Provider doesn't contain ProviderData. How?"), l.__context.providerData.subs.add(n), e[t] = l.__context.providerData) : e[t] = { val: s.__defaultValue }; | ||
| } | ||
| return W(() => () => e[t].subs?.delete(n), []), e[t].val; | ||
| return V(() => () => e[t].subs?.delete(n), []), e[t].val; | ||
| } | ||
| class q { | ||
| class H { | ||
| // @ts-ignore | ||
@@ -113,53 +108,48 @@ __defaultValue; | ||
| Provider = ({ value: e, children: t }) => { | ||
| const n = D({ val: e, subs: /* @__PURE__ */ new Set() }), o = D(!0); | ||
| return o.current && (r.data.providerData = n.current, o.current = !1), Object.is(n.current.val, e) || (n.current.val = e, n.current.subs.forEach((h) => { | ||
| r.root?.__internalAddPending(h); | ||
| })), f(N, null, t); | ||
| const n = m({ val: e, subs: /* @__PURE__ */ new Set() }), l = m(!0); | ||
| return l.current && (i.data.providerData = n.current, l.current = !1), Object.is(n.current.val, e) || (n.current.val = e, n.current.subs.forEach((p) => { | ||
| i.root?.__internalAddPending(p); | ||
| })), f(D, null, t); | ||
| }; | ||
| Consumer = ({ children: e }) => { | ||
| const t = V(this); | ||
| return f(N, null, e(t)); | ||
| const t = q(this); | ||
| return f(D, null, e(t)); | ||
| }; | ||
| } | ||
| function $(s) { | ||
| return new q(s); | ||
| function B(s) { | ||
| return new H(s); | ||
| } | ||
| function B(s, e) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useCallback hook"); | ||
| return I(() => s, e); | ||
| function F(s, e) { | ||
| return (!i.root || !i.data) && v("Missing context data inside useCallback hook"), G(() => s, e); | ||
| } | ||
| function F(s, e, t) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useReducer hook"); | ||
| const n = r.data.hookData, o = r.index++, h = r.root, y = r.data.self; | ||
| if (!Object.hasOwn(n, o)) { | ||
| const v = (R) => { | ||
| const x = s(n[o].val, R); | ||
| Object.is(x, n[o].val) || (n[o].val = x, h.__internalAddPending(y), h.__internalUpdate()); | ||
| function z(s, e, t) { | ||
| (!i.root || !i.data) && v("Missing context data inside useReducer hook"); | ||
| const n = i.data.hookData, l = i.index++, p = i.root, y = i.data.self; | ||
| if (!Object.hasOwn(n, l)) { | ||
| const b = (L) => { | ||
| const x = s(n[l].val, L); | ||
| Object.is(x, n[l].val) || (n[l].val = x, p.__internalAddPending(y), p.__internalUpdate()); | ||
| }; | ||
| n[o] = { | ||
| n[l] = { | ||
| val: t ? t(e) : e, | ||
| dispatch: v | ||
| dispatch: b | ||
| }; | ||
| } | ||
| return [n[o].val, n[o].dispatch]; | ||
| return [n[l].val, n[l].dispatch]; | ||
| } | ||
| function D(s) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useRef hook"); | ||
| const e = r.data.hookData, t = r.index++; | ||
| function m(s) { | ||
| (!i.root || !i.data) && v("Missing context data inside useRef hook"); | ||
| const e = i.data.hookData, t = i.index++; | ||
| return Object.hasOwn(e, t) || (e[t] = { current: s }), e[t]; | ||
| } | ||
| function z(s) { | ||
| if (!r.root || !r.data) | ||
| throw new Error("Missing context data inside useState hook"); | ||
| const e = r.data.hookData, t = r.index++, n = r.root, o = r.data.self; | ||
| function J(s) { | ||
| (!i.root || !i.data) && v("Missing context data inside useState hook"); | ||
| const e = i.data.hookData, t = i.index++, n = i.root, l = i.data.self; | ||
| if (!Object.hasOwn(e, t)) { | ||
| const h = (y) => { | ||
| const v = typeof y == "function" ? y(e[t].val) : y; | ||
| Object.is(v, e[t].val) || (e[t].val = v, n.__internalAddPending(o), n.__internalUpdate()); | ||
| const p = (y) => { | ||
| const b = typeof y == "function" ? y(e[t].val) : y; | ||
| Object.is(b, e[t].val) || (e[t].val = b, n.__internalAddPending(l), n.__internalUpdate()); | ||
| }; | ||
| e[t] = { | ||
| setter: h, | ||
| setter: p, | ||
| val: typeof s != "function" ? s : s() | ||
@@ -171,3 +161,3 @@ }; | ||
| var a = /* @__PURE__ */ ((s) => (s[s.LITERAL = 0] = "LITERAL", s[s.FRAGMENT = 1] = "FRAGMENT", s[s.ELEMENT = 2] = "ELEMENT", s[s.COMPONENT = 4] = "COMPONENT", s[s.NODRAW = 5] = "NODRAW", s))(a || {}); | ||
| function m(s) { | ||
| function S(s) { | ||
| for (const e of s.fx) | ||
@@ -182,20 +172,20 @@ e.effect && e.cb?.(); | ||
| } | ||
| function S(s) { | ||
| function P(s) { | ||
| return Object.hasOwn(s.props, "children") ? Array.isArray(s.props.children) ? s.props.children : [s.props.children] : []; | ||
| } | ||
| function T(s) { | ||
| function C(s) { | ||
| return typeof s != "object" || s === null || !Object.hasOwn(s, "key") || typeof s.key != "bigint" && typeof s.key != "boolean" && typeof s.key != "number" && typeof s.key != "string" && typeof s.key != "symbol" && typeof s.key != "object" ? null : s.key; | ||
| } | ||
| function C(s) { | ||
| function R(s) { | ||
| return typeof s == "object" && s !== null ? Array.isArray(s) ? a.FRAGMENT : typeof s.type == "function" ? a.COMPONENT : a.ELEMENT : typeof s == "string" || typeof s == "number" || typeof s == "bigint" ? a.LITERAL : a.NODRAW; | ||
| } | ||
| function L(s, e, t) { | ||
| function N(s, e, t) { | ||
| const n = typeof e == "object" ? e : document.createTextNode(`${e}`); | ||
| s.childNodes.length > 0 ? s.insertBefore(n, s.childNodes[t]) : s.appendChild(n); | ||
| } | ||
| function w(s) { | ||
| function M(s) { | ||
| const e = Array.isArray(s) ? [...s] : [s]; | ||
| for (let t = 0; t < e.length; t++) { | ||
| const n = e[t]; | ||
| switch (C(n)) { | ||
| switch (R(n)) { | ||
| case a.COMPONENT: { | ||
@@ -210,3 +200,3 @@ e[t] = { | ||
| case a.ELEMENT: { | ||
| const o = { | ||
| const l = { | ||
| type: n.type, | ||
@@ -216,8 +206,8 @@ props: { ...n.props }, | ||
| }; | ||
| Object.hasOwn(n, "key") && (o.key = n.key), n.props.children && (o.props.children = w(o.props.children)), e[t] = o; | ||
| Object.hasOwn(n, "key") && (l.key = n.key), n.props.children && (l.props.children = M(l.props.children)), e[t] = l; | ||
| break; | ||
| } | ||
| case a.FRAGMENT: { | ||
| const o = w(n); | ||
| Object.hasOwn(n, "key") && (o.key = n.key), o.__vnode = n, e[t] = o; | ||
| const l = M(n); | ||
| Object.hasOwn(n, "key") && (l.key = n.key), l.__vnode = n, e[t] = l; | ||
| break; | ||
@@ -229,14 +219,14 @@ } | ||
| } | ||
| function P(s, e) { | ||
| const t = r.data, n = r.index; | ||
| r.data = s, r.index = 0, e(), r.data = t, r.index = n; | ||
| function I(s, e) { | ||
| const t = i.data, n = i.index; | ||
| i.data = s, i.index = 0, e(), i.data = t, i.index = n; | ||
| } | ||
| function G(s, e) { | ||
| function K(s, e) { | ||
| for (const t of Object.keys(e)) | ||
| typeof e[t] == "object" ? G(s[t], e[t]) : s[t] = e[t]; | ||
| typeof e[t] == "object" ? K(s[t], e[t]) : s[t] = e[t]; | ||
| } | ||
| function M(s, e, t) { | ||
| e === "class" && (e = "className"), typeof t == "object" ? G(s[e], t) : s[e] = t; | ||
| function w(s, e, t) { | ||
| e === "class" && (e = "className"), typeof t == "object" ? K(s[e], t) : s[e] = t; | ||
| } | ||
| class H { | ||
| class U { | ||
| #s; | ||
@@ -248,62 +238,64 @@ #t = /* @__PURE__ */ new Set(); | ||
| } | ||
| #e(e, t, n, o) { | ||
| const h = /* @__PURE__ */ new Set([...Object.keys(t.props), ...Object.keys(e.props)]); | ||
| for (const l of h) | ||
| if (l !== "children") { | ||
| if (l === "ref") { | ||
| Object.hasOwn(e.props, l) && (e.props[l].current = null), Object.hasOwn(t.props, l) && (t.props[l].current = n); | ||
| #e(e, t, n, l) { | ||
| for (const o of Object.keys(t.props)) | ||
| (t.props[o] === void 0 || t.props[o] === null) && delete t.props[o]; | ||
| const p = /* @__PURE__ */ new Set([...Object.keys(t.props), ...Object.keys(e.props)]); | ||
| for (const o of p) | ||
| if (o !== "children") { | ||
| if (o === "ref") { | ||
| Object.hasOwn(e.props, o) && (e.props[o].current = null), Object.hasOwn(t.props, o) && (t.props[o].current = n); | ||
| continue; | ||
| } | ||
| if (!Object.hasOwn(t.props, l)) | ||
| l.slice(0, 2) === "on" && typeof e.props[l] == "function" ? n.removeEventListener(l.slice(2).toLowerCase(), e.props[l]) : n[l] = ""; | ||
| else if (!Object.hasOwn(e.props, l)) | ||
| l.slice(0, 2) === "on" && typeof t.props[l] == "function" ? n.addEventListener(l.slice(2).toLowerCase(), t.props[l]) : M(n, l, t.props[l]); | ||
| else if (l.slice(0, 2) === "on") { | ||
| if (t.props[l] === e.props[l]) | ||
| if (!Object.hasOwn(t.props, o)) | ||
| o.slice(0, 2) === "on" && typeof e.props[o] == "function" ? n.removeEventListener(o.slice(2).toLowerCase(), e.props[o]) : n[o] = ""; | ||
| else if (!Object.hasOwn(e.props, o)) | ||
| o.slice(0, 2) === "on" && typeof t.props[o] == "function" ? n.addEventListener(o.slice(2).toLowerCase(), t.props[o]) : w(n, o, t.props[o]); | ||
| else if (o.slice(0, 2) === "on") { | ||
| if (t.props[o] === e.props[o]) | ||
| continue; | ||
| const p = l.slice(2).toLowerCase(); | ||
| typeof e.props[l] == "function" ? n.removeEventListener(p, e.props[l]) : M(n, l, ""), typeof t.props[l] == "function" ? n.addEventListener(p, t.props[l]) : M(n, l, t.props[l]); | ||
| } else if (l === "value" || l === "checked") | ||
| n[l] !== t.props[l] && M(n, l, t.props[l]); | ||
| const h = o.slice(2).toLowerCase(); | ||
| typeof e.props[o] == "function" ? n.removeEventListener(h, e.props[o]) : w(n, o, ""), typeof t.props[o] == "function" ? n.addEventListener(h, t.props[o]) : w(n, o, t.props[o]); | ||
| } else if (o === "value" || o === "checked") | ||
| n[o] !== t.props[o] && w(n, o, t.props[o]); | ||
| else { | ||
| if (t.props[l] === e.props[l]) | ||
| if (t.props[o] === e.props[o]) | ||
| continue; | ||
| M(n, l, t.props[l]); | ||
| w(n, o, t.props[o]); | ||
| } | ||
| } | ||
| const y = S(e), v = S(t), R = Math.max(y.length, v.length), x = /* @__PURE__ */ new Map(), c = o ?? { value: 0 }; | ||
| let j = c.value; | ||
| for (let l = 0; l < y.length; l++) { | ||
| const p = y[l], E = v[l], b = T(p), k = T(E), O = C(p), _ = j; | ||
| if (j = O === a.FRAGMENT || O === a.COMPONENT ? p.__domEnd : j + 1, b === null || b === k) | ||
| const y = P(e), b = P(t), L = Math.max(y.length, b.length), x = /* @__PURE__ */ new Map(), c = l ?? { value: 0 }; | ||
| let A = c.value; | ||
| for (let o = 0; o < y.length; o++) { | ||
| const h = y[o], O = b[o], k = C(h), g = C(O), E = R(h), _ = A; | ||
| if (A = E === a.FRAGMENT || E === a.COMPONENT ? h.__domEnd : A + 1, k === null || k === g) | ||
| continue; | ||
| const i = []; | ||
| for (let u = _; u < j; u++) | ||
| i.push(n.childNodes[u]); | ||
| x.set(b, [p, i]), y[l] = void 0; | ||
| const r = []; | ||
| for (let u = _; u < A; u++) | ||
| r.push(n.childNodes[u]); | ||
| x.set(k, [h, r]), y[o] = void 0; | ||
| } | ||
| for (const [l, [p, E]] of x) | ||
| for (const b of E) | ||
| n.removeChild(b); | ||
| for (let l = 0; l < R; l++) { | ||
| const p = v[l]; | ||
| let E = y[l]; | ||
| const b = T(E), k = T(p); | ||
| if (k !== null && k !== b && x.has(k)) { | ||
| const [d, g] = x.get(k); | ||
| x.delete(k), b === null && this.#e( | ||
| f(null, null, E), | ||
| for (const [o, [h, O]] of x) | ||
| for (const k of O) | ||
| n.removeChild(k); | ||
| for (let o = 0; o < L; o++) { | ||
| const h = b[o]; | ||
| let O = y[o]; | ||
| const k = C(O), g = C(h); | ||
| if (g !== null && g !== k && x.has(g)) { | ||
| const [d, j] = x.get(g); | ||
| x.delete(g), k === null && this.#e( | ||
| f(null, null, O), | ||
| f(null, null), | ||
| n, | ||
| c | ||
| ), y[l] = d, E = d; | ||
| for (let A = 0; A < g.length; A++) | ||
| L(n, g[A], c.value + A); | ||
| ), y[o] = d, O = d; | ||
| for (let T = 0; T < j.length; T++) | ||
| N(n, j[T], c.value + T); | ||
| } | ||
| const O = C(E), _ = C(p), i = p, u = E; | ||
| const E = R(O), _ = R(h), r = h, u = O; | ||
| if (_ !== a.NODRAW) { | ||
| if (O !== a.NODRAW) | ||
| if (O !== _ || (_ === a.ELEMENT || _ === a.COMPONENT) && i.type !== u.type) | ||
| if (E !== a.NODRAW) | ||
| if (E !== _ || (_ === a.ELEMENT || _ === a.COMPONENT) && r.type !== u.type) | ||
| this.#e( | ||
| f(null, null, E), | ||
| f(null, null, O), | ||
| f(null, null), | ||
@@ -314,3 +306,3 @@ n, | ||
| f(null, null), | ||
| f(null, null, p), | ||
| f(null, null, h), | ||
| n, | ||
@@ -321,7 +313,7 @@ c | ||
| if (_ === a.ELEMENT || _ === a.COMPONENT || _ === a.FRAGMENT) { | ||
| if (Object.is(u.__vnode, i.__vnode)) { | ||
| i.__vnode = u.__vnode, (_ === a.COMPONENT || _ === a.FRAGMENT) && (i.__domStart = u.__domStart, i.__domEnd = u.__domEnd), _ === a.COMPONENT && (i.__context = u.__context, i.__context.self.value = i, i.__ref = u.__ref), c.value = _ === a.ELEMENT ? c.value + 1 : u.__domEnd; | ||
| if (Object.is(u.__vnode, r.__vnode)) { | ||
| r.__vnode = u.__vnode, (_ === a.COMPONENT || _ === a.FRAGMENT) && (r.__domStart = u.__domStart, r.__domEnd = u.__domEnd), _ === a.COMPONENT && (r.__context = u.__context, r.__context.self.value = r, r.__ref = u.__ref), c.value = _ === a.ELEMENT ? c.value + 1 : u.__domEnd; | ||
| continue; | ||
| } | ||
| } else if (Object.is(E, p)) { | ||
| } else if (Object.is(O, h)) { | ||
| c.value++; | ||
@@ -331,3 +323,3 @@ continue; | ||
| if (_ === a.LITERAL) | ||
| n.childNodes[c.value++].textContent = `${p}`; | ||
| n.childNodes[c.value++].textContent = `${h}`; | ||
| else if (_ === a.ELEMENT) { | ||
@@ -337,9 +329,9 @@ const d = n.childNodes[c.value++]; | ||
| u, | ||
| i, | ||
| r, | ||
| d | ||
| ); | ||
| } else | ||
| _ === a.COMPONENT ? (this.#t.delete(u.__context.self), P(u.__context, () => { | ||
| const d = w(i.type(i.props)); | ||
| i.__domStart = c.value, i.__context = u.__context, i.__context.self.value = i, i.__ref = n, this.#e( | ||
| _ === a.COMPONENT ? (this.#t.delete(u.__context.self), I(u.__context, () => { | ||
| const d = M(r.type(r.props)); | ||
| r.__domStart = c.value, r.__context = u.__context, r.__context.self.value = r, r.__ref = n, this.#e( | ||
| f(null, null, u.__context.prevTree), | ||
@@ -349,53 +341,53 @@ f(null, null, d), | ||
| c | ||
| ), i.__context.prevTree = d, i.__domEnd = c.value, m(i.__context); | ||
| })) : (i.__domStart = c.value, this.#e( | ||
| f(null, null, ...E), | ||
| f(null, null, ...p), | ||
| ), r.__context.prevTree = d, r.__domEnd = c.value, S(r.__context); | ||
| })) : (r.__domStart = c.value, this.#e( | ||
| f(null, null, ...O), | ||
| f(null, null, ...h), | ||
| n, | ||
| c | ||
| ), i.__domEnd = c.value); | ||
| ), r.__domEnd = c.value); | ||
| } | ||
| else if (_ === a.LITERAL) | ||
| L(n, p, c.value++); | ||
| N(n, h, c.value++); | ||
| else if (_ === a.FRAGMENT) | ||
| i.__domStart = c.value, this.#e( | ||
| r.__domStart = c.value, this.#e( | ||
| f(null, null), | ||
| f(null, null, ...p), | ||
| f(null, null, ...h), | ||
| n, | ||
| c | ||
| ), i.__domEnd = c.value; | ||
| else if (typeof i.type == "string") { | ||
| const d = document.createElement(i.type); | ||
| this.#e(f(i.type, {}), i, d), L(n, d, c.value++); | ||
| } else if (i.type !== null) { | ||
| ), r.__domEnd = c.value; | ||
| else if (typeof r.type == "string") { | ||
| const d = document.createElement(r.type); | ||
| this.#e(f(r.type, {}), r, d), N(n, d, c.value++); | ||
| } else if (r.type !== null) { | ||
| const d = { | ||
| hookData: [], | ||
| fx: [], | ||
| self: { value: i }, | ||
| prevProps: i.props, | ||
| self: { value: r }, | ||
| prevProps: r.props, | ||
| prevTree: null, | ||
| parent: r.data?.self ?? null | ||
| parent: i.data?.self ?? null | ||
| }; | ||
| P(d, () => { | ||
| const g = w(i.type(i.props)); | ||
| i.__domStart = c.value, i.__context = d, i.__ref = n, this.#e( | ||
| I(d, () => { | ||
| const j = M(r.type(r.props)); | ||
| r.__domStart = c.value, r.__context = d, r.__ref = n, this.#e( | ||
| f(null, null), | ||
| f(null, null, g), | ||
| f(null, null, j), | ||
| n, | ||
| c | ||
| ), i.__domEnd = c.value, d.prevTree = g, m(i.__context); | ||
| ), r.__domEnd = c.value, d.prevTree = j, S(r.__context); | ||
| }); | ||
| } | ||
| } else if (O !== a.NODRAW) | ||
| if (O === a.FRAGMENT) | ||
| } else if (E !== a.NODRAW) | ||
| if (E === a.FRAGMENT) | ||
| this.#e( | ||
| f(null, null, ...E), | ||
| f(null, null, p), | ||
| f(null, null, ...O), | ||
| f(null, null, h), | ||
| n, | ||
| c | ||
| ); | ||
| else if (O === a.COMPONENT) { | ||
| else if (E === a.COMPONENT) { | ||
| this.#t.delete(u.__context.self), this.#e( | ||
| f(null, null, u.__context.prevTree), | ||
| f(null, null, p), | ||
| f(null, null, h), | ||
| n, | ||
@@ -407,3 +399,3 @@ c | ||
| } else | ||
| O === a.ELEMENT && (y.length > 0 && this.#e( | ||
| E === a.ELEMENT && (y.length > 0 && this.#e( | ||
| u, | ||
@@ -422,3 +414,3 @@ f(null, null), | ||
| this.#n || (this.#n = !0, requestIdleCallback(() => { | ||
| r.root = this; | ||
| i.root = this; | ||
| for (const e of this.#t) { | ||
@@ -428,3 +420,3 @@ const t = { value: e.value.__domStart }; | ||
| f(null, null, e.value), | ||
| w(f(null, null, e.value)), | ||
| M(f(null, null, e.value)), | ||
| e.value.__ref, | ||
@@ -438,5 +430,5 @@ t | ||
| render(e) { | ||
| r.root = this, this.#e( | ||
| i.root = this, this.#e( | ||
| f(null, null), | ||
| w(f(null, null, e)), | ||
| M(f(null, null, e)), | ||
| this.#s | ||
@@ -446,22 +438,20 @@ ); | ||
| } | ||
| function J(s) { | ||
| function Q(s) { | ||
| const e = document.querySelector(s); | ||
| if (!e) | ||
| throw new Error("Root element doesn't exist"); | ||
| return new H(e); | ||
| return e || v("Root element doesn't exist"), new U(e); | ||
| } | ||
| const N = Symbol.for("freact.fragment"); | ||
| const D = Symbol.for("freact.fragment"); | ||
| export { | ||
| N as Fragment, | ||
| $ as createContext, | ||
| J as createRoot, | ||
| D as Fragment, | ||
| B as createContext, | ||
| Q as createRoot, | ||
| f as h, | ||
| U as memo, | ||
| B as useCallback, | ||
| V as useContext, | ||
| W as useEffect, | ||
| I as useMemo, | ||
| F as useReducer, | ||
| D as useRef, | ||
| z as useState | ||
| $ as memo, | ||
| F as useCallback, | ||
| q as useContext, | ||
| V as useEffect, | ||
| G as useMemo, | ||
| z as useReducer, | ||
| m as useRef, | ||
| J as useState | ||
| }; |
@@ -1,1 +0,1 @@ | ||
| var Freact=function(y){"use strict";function c(s,e,...t){const n=e&&Object.hasOwn(e,"key"),o=e?.key;if(delete e?.key,s===C)return n&&(t.key=o),t.length>0?t:void 0;const h={type:s,props:{...e}};return t.length>0&&(h.props.children=t.length>1?t:t[0]),n&&(h.key=o),h}const r={root:null,data:null,index:0};function m(s,e){if(!r.root||!r.data)throw new Error("Missing context data inside useMemo hook");const t=r.data.hookData,n=r.index++;if(!Object.hasOwn(t,n))t[n]={val:s(),deps:e};else{let o=t[n].deps.length===e.length;if(o){for(let h=0;h<e.length;h++)if(!Object.is(t[n].deps[h],e[h])){o=!1;break}}o||(t[n].val=s(),t[n].deps=e)}return t[n].val}const q=(s,e)=>{const t=Object.keys(e);if(t.length!==Object.keys(s).length)return!1;const n=Object.hasOwn(e,"children");if(Object.hasOwn(s,"children")!==n)return!1;if(n){if(s.children.length!==e.children.length)return!1;for(let o=0;o<e.children.length;o++)if(!Object.is(e.children[o],s.children[o]))return!1}for(const o of t)if(o!=="children"&&!Object.is(s[o],e[o]))return!1;return!0};function F(s,e=q){let t=!1;return n=>(t=e(r.data?.self.value.__context?.prevProps??{},n)?t:!t,m(()=>c(s,n),[t]))}function P(s,e){if(!r.root||!r.data)throw new Error("Missing context data inside useEffect hook");const t=r.data.hookData,n=r.index++;if(!Object.hasOwn(t,n))t[n]={effect:s,cb:null,deps:e??null},r.data.fx.push(t[n]);else{let o=!!t[n].deps&&t[n].deps?.length===e?.length;if(o){for(let h=0;h<e.length;h++)if(!Object.is(t[n].deps[h],e[h])){o=!1;break}}o||(t[n].effect=s,t[n].deps=e??null)}}function I(s){if(!r.root||!r.data)throw new Error("Missing context data inside useContext hook");const e=r.data.hookData,t=r.index++,n=r.data.self;if(!Object.hasOwn(e,t)){let o=r.data.parent?.value;for(;o&&o.type!==s.Provider;)o=o.__context?.parent?.value;if(o){if(!o.__context?.providerData)throw new Error("Provider doesn't contain ProviderData. How?");o.__context.providerData.subs.add(n),e[t]=o.__context.providerData}else e[t]={val:s.__defaultValue}}return P(()=>()=>e[t].subs?.delete(n),[]),e[t].val}class H{__defaultValue;constructor(e){this.__defaultValue=e}Provider=({value:e,children:t})=>{const n=N({val:e,subs:new Set}),o=N(!0);return o.current&&(r.data.providerData=n.current,o.current=!1),Object.is(n.current.val,e)||(n.current.val=e,n.current.subs.forEach(h=>{r.root?.__internalAddPending(h)})),c(C,null,t)};Consumer=({children:e})=>{const t=I(this);return c(C,null,e(t))}}function U(s){return new H(s)}function $(s,e){if(!r.root||!r.data)throw new Error("Missing context data inside useCallback hook");return m(()=>s,e)}function B(s,e,t){if(!r.root||!r.data)throw new Error("Missing context data inside useReducer hook");const n=r.data.hookData,o=r.index++,h=r.root,E=r.data.self;if(!Object.hasOwn(n,o)){const b=S=>{const k=s(n[o].val,S);Object.is(k,n[o].val)||(n[o].val=k,h.__internalAddPending(E),h.__internalUpdate())};n[o]={val:t?t(e):e,dispatch:b}}return[n[o].val,n[o].dispatch]}function N(s){if(!r.root||!r.data)throw new Error("Missing context data inside useRef hook");const e=r.data.hookData,t=r.index++;return Object.hasOwn(e,t)||(e[t]={current:s}),e[t]}function z(s){if(!r.root||!r.data)throw new Error("Missing context data inside useState hook");const e=r.data.hookData,t=r.index++,n=r.root,o=r.data.self;if(!Object.hasOwn(e,t)){const h=E=>{const b=typeof E=="function"?E(e[t].val):E;Object.is(b,e[t].val)||(e[t].val=b,n.__internalAddPending(o),n.__internalUpdate())};e[t]={setter:h,val:typeof s!="function"?s:s()}}return[e[t].val,e[t].setter]}var a=(s=>(s[s.LITERAL=0]="LITERAL",s[s.FRAGMENT=1]="FRAGMENT",s[s.ELEMENT=2]="ELEMENT",s[s.COMPONENT=4]="COMPONENT",s[s.NODRAW=5]="NODRAW",s))(a||{});function G(s){for(const e of s.fx)e.effect&&e.cb?.();for(const e of s.fx){if(!e.effect)continue;const t=e.effect();e.effect=null,typeof t=="function"&&(e.cb=t)}}function K(s){return Object.hasOwn(s.props,"children")?Array.isArray(s.props.children)?s.props.children:[s.props.children]:[]}function T(s){return typeof s!="object"||s===null||!Object.hasOwn(s,"key")||typeof s.key!="bigint"&&typeof s.key!="boolean"&&typeof s.key!="number"&&typeof s.key!="string"&&typeof s.key!="symbol"&&typeof s.key!="object"?null:s.key}function A(s){return typeof s=="object"&&s!==null?Array.isArray(s)?a.FRAGMENT:typeof s.type=="function"?a.COMPONENT:a.ELEMENT:typeof s=="string"||typeof s=="number"||typeof s=="bigint"?a.LITERAL:a.NODRAW}function D(s,e,t){const n=typeof e=="object"?e:document.createTextNode(`${e}`);s.childNodes.length>0?s.insertBefore(n,s.childNodes[t]):s.appendChild(n)}function g(s){const e=Array.isArray(s)?[...s]:[s];for(let t=0;t<e.length;t++){const n=e[t];switch(A(n)){case a.COMPONENT:{e[t]={type:n.type,props:{...n.props},__vnode:n},Object.hasOwn(n,"key")&&(e[t].key=n.key);break}case a.ELEMENT:{const o={type:n.type,props:{...n.props},__vnode:n};Object.hasOwn(n,"key")&&(o.key=n.key),n.props.children&&(o.props.children=g(o.props.children)),e[t]=o;break}case a.FRAGMENT:{const o=g(n);Object.hasOwn(n,"key")&&(o.key=n.key),o.__vnode=n,e[t]=o;break}}}return Array.isArray(s)?e:e[0]}function W(s,e){const t=r.data,n=r.index;r.data=s,r.index=0,e(),r.data=t,r.index=n}function V(s,e){for(const t of Object.keys(e))typeof e[t]=="object"?V(s[t],e[t]):s[t]=e[t]}function M(s,e,t){e==="class"&&(e="className"),typeof t=="object"?V(s[e],t):s[e]=t}class J{#s;#t=new Set;#n=!1;constructor(e){this.#s=e,e.innerHTML=""}#e(e,t,n,o){const h=new Set([...Object.keys(t.props),...Object.keys(e.props)]);for(const l of h)if(l!=="children"){if(l==="ref"){Object.hasOwn(e.props,l)&&(e.props[l].current=null),Object.hasOwn(t.props,l)&&(t.props[l].current=n);continue}if(!Object.hasOwn(t.props,l))l.slice(0,2)==="on"&&typeof e.props[l]=="function"?n.removeEventListener(l.slice(2).toLowerCase(),e.props[l]):n[l]="";else if(!Object.hasOwn(e.props,l))l.slice(0,2)==="on"&&typeof t.props[l]=="function"?n.addEventListener(l.slice(2).toLowerCase(),t.props[l]):M(n,l,t.props[l]);else if(l.slice(0,2)==="on"){if(t.props[l]===e.props[l])continue;const _=l.slice(2).toLowerCase();typeof e.props[l]=="function"?n.removeEventListener(_,e.props[l]):M(n,l,""),typeof t.props[l]=="function"?n.addEventListener(_,t.props[l]):M(n,l,t.props[l])}else if(l==="value"||l==="checked")n[l]!==t.props[l]&&M(n,l,t.props[l]);else{if(t.props[l]===e.props[l])continue;M(n,l,t.props[l])}}const E=K(e),b=K(t),S=Math.max(E.length,b.length),k=new Map,f=o??{value:0};let R=f.value;for(let l=0;l<E.length;l++){const _=E[l],O=b[l],x=T(_),w=T(O),v=A(_),d=R;if(R=v===a.FRAGMENT||v===a.COMPONENT?_.__domEnd:R+1,x===null||x===w)continue;const i=[];for(let u=d;u<R;u++)i.push(n.childNodes[u]);k.set(x,[_,i]),E[l]=void 0}for(const[l,[_,O]]of k)for(const x of O)n.removeChild(x);for(let l=0;l<S;l++){const _=b[l];let O=E[l];const x=T(O),w=T(_);if(w!==null&&w!==x&&k.has(w)){const[p,j]=k.get(w);k.delete(w),x===null&&this.#e(c(null,null,O),c(null,null),n,f),E[l]=p,O=p;for(let L=0;L<j.length;L++)D(n,j[L],f.value+L)}const v=A(O),d=A(_),i=_,u=O;if(d!==a.NODRAW){if(v!==a.NODRAW)if(v!==d||(d===a.ELEMENT||d===a.COMPONENT)&&i.type!==u.type)this.#e(c(null,null,O),c(null,null),n,f),this.#e(c(null,null),c(null,null,_),n,f);else{if(d===a.ELEMENT||d===a.COMPONENT||d===a.FRAGMENT){if(Object.is(u.__vnode,i.__vnode)){i.__vnode=u.__vnode,(d===a.COMPONENT||d===a.FRAGMENT)&&(i.__domStart=u.__domStart,i.__domEnd=u.__domEnd),d===a.COMPONENT&&(i.__context=u.__context,i.__context.self.value=i,i.__ref=u.__ref),f.value=d===a.ELEMENT?f.value+1:u.__domEnd;continue}}else if(Object.is(O,_)){f.value++;continue}if(d===a.LITERAL)n.childNodes[f.value++].textContent=`${_}`;else if(d===a.ELEMENT){const p=n.childNodes[f.value++];this.#e(u,i,p)}else d===a.COMPONENT?(this.#t.delete(u.__context.self),W(u.__context,()=>{const p=g(i.type(i.props));i.__domStart=f.value,i.__context=u.__context,i.__context.self.value=i,i.__ref=n,this.#e(c(null,null,u.__context.prevTree),c(null,null,p),n,f),i.__context.prevTree=p,i.__domEnd=f.value,G(i.__context)})):(i.__domStart=f.value,this.#e(c(null,null,...O),c(null,null,..._),n,f),i.__domEnd=f.value)}else if(d===a.LITERAL)D(n,_,f.value++);else if(d===a.FRAGMENT)i.__domStart=f.value,this.#e(c(null,null),c(null,null,..._),n,f),i.__domEnd=f.value;else if(typeof i.type=="string"){const p=document.createElement(i.type);this.#e(c(i.type,{}),i,p),D(n,p,f.value++)}else if(i.type!==null){const p={hookData:[],fx:[],self:{value:i},prevProps:i.props,prevTree:null,parent:r.data?.self??null};W(p,()=>{const j=g(i.type(i.props));i.__domStart=f.value,i.__context=p,i.__ref=n,this.#e(c(null,null),c(null,null,j),n,f),i.__domEnd=f.value,p.prevTree=j,G(i.__context)})}}else if(v!==a.NODRAW)if(v===a.FRAGMENT)this.#e(c(null,null,...O),c(null,null,_),n,f);else if(v===a.COMPONENT){this.#t.delete(u.__context.self),this.#e(c(null,null,u.__context.prevTree),c(null,null,_),n,f);for(const p of u.__context.fx)p.cb?.()}else v===a.ELEMENT&&(E.length>0&&this.#e(u,c(null,null),n.childNodes[f.value]),Object.hasOwn(u.props,"ref")&&(u.props.ref.current=null)),n.childNodes[f.value].remove()}}__internalAddPending(e){this.#t.add(e)}__internalUpdate(){this.#n||(this.#n=!0,requestIdleCallback(()=>{r.root=this;for(const e of this.#t){const t={value:e.value.__domStart};this.#t.delete(e),this.#e(c(null,null,e.value),g(c(null,null,e.value)),e.value.__ref,t)}this.#n=!1}))}render(e){r.root=this,this.#e(c(null,null),g(c(null,null,e)),this.#s)}}function Q(s){const e=document.querySelector(s);if(!e)throw new Error("Root element doesn't exist");return new J(e)}const C=Symbol.for("freact.fragment");return y.Fragment=C,y.createContext=U,y.createRoot=Q,y.h=c,y.memo=F,y.useCallback=$,y.useContext=I,y.useEffect=P,y.useMemo=m,y.useReducer=B,y.useRef=N,y.useState=z,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"}),y}({}); | ||
| var Freact=function(y){"use strict";function c(s,e,...t){const n=e&&Object.hasOwn(e,"key"),o=e?.key;if(delete e?.key,s===R)return n&&(t.key=o),t.length>0?t:void 0;const p={type:s,props:{...e}};return t.length>0&&(p.props.children=t.length>1?t:t[0]),n&&(p.key=o),p}function v(s){throw new Error(s)}const i={root:null,data:null,index:0};function N(s,e){(!i.root||!i.data)&&v("Missing context data inside useMemo hook");const t=i.data.hookData,n=i.index++;if(!Object.hasOwn(t,n))t[n]={val:s(),deps:e};else{let o=t[n].deps.length===e.length;if(o){for(let p=0;p<e.length;p++)if(!Object.is(t[n].deps[p],e[p])){o=!1;break}}o||(t[n].val=s(),t[n].deps=e)}return t[n].val}const F=(s,e)=>{const t=Object.keys(e);if(t.length!==Object.keys(s).length)return!1;const n=Object.hasOwn(e,"children");if(Object.hasOwn(s,"children")!==n)return!1;if(n){if(s.children.length!==e.children.length)return!1;for(let o=0;o<e.children.length;o++)if(!Object.is(e.children[o],s.children[o]))return!1}for(const o of t)if(o!=="children"&&!Object.is(s[o],e[o]))return!1;return!0};function H(s,e=F){let t=!1;return n=>(t=e(i.data?.self.value.__context?.prevProps??{},n)?t:!t,N(()=>c(s,n),[t]))}function I(s,e){(!i.root||!i.data)&&v("Missing context data inside useEffect hook");const t=i.data.hookData,n=i.index++;if(!Object.hasOwn(t,n))t[n]={effect:s,cb:null,deps:e??null},i.data.fx.push(t[n]);else{let o=!!t[n].deps&&t[n].deps?.length===e?.length;if(o){for(let p=0;p<e.length;p++)if(!Object.is(t[n].deps[p],e[p])){o=!1;break}}o||(t[n].effect=s,t[n].deps=e??null)}}function G(s){(!i.root||!i.data)&&v("Missing context data inside useContext hook");const e=i.data.hookData,t=i.index++,n=i.data.self;if(!Object.hasOwn(e,t)){let o=i.data.parent?.value;for(;o&&o.type!==s.Provider;)o=o.__context?.parent?.value;o?(o.__context?.providerData||v("Provider doesn't contain ProviderData. How?"),o.__context.providerData.subs.add(n),e[t]=o.__context.providerData):e[t]={val:s.__defaultValue}}return I(()=>()=>e[t].subs?.delete(n),[]),e[t].val}class U{__defaultValue;constructor(e){this.__defaultValue=e}Provider=({value:e,children:t})=>{const n=D({val:e,subs:new Set}),o=D(!0);return o.current&&(i.data.providerData=n.current,o.current=!1),Object.is(n.current.val,e)||(n.current.val=e,n.current.subs.forEach(p=>{i.root?.__internalAddPending(p)})),c(R,null,t)};Consumer=({children:e})=>{const t=G(this);return c(R,null,e(t))}}function $(s){return new U(s)}function B(s,e){return(!i.root||!i.data)&&v("Missing context data inside useCallback hook"),N(()=>s,e)}function z(s,e,t){(!i.root||!i.data)&&v("Missing context data inside useReducer hook");const n=i.data.hookData,o=i.index++,p=i.root,O=i.data.self;if(!Object.hasOwn(n,o)){const k=P=>{const x=s(n[o].val,P);Object.is(x,n[o].val)||(n[o].val=x,p.__internalAddPending(O),p.__internalUpdate())};n[o]={val:t?t(e):e,dispatch:k}}return[n[o].val,n[o].dispatch]}function D(s){(!i.root||!i.data)&&v("Missing context data inside useRef hook");const e=i.data.hookData,t=i.index++;return Object.hasOwn(e,t)||(e[t]={current:s}),e[t]}function J(s){(!i.root||!i.data)&&v("Missing context data inside useState hook");const e=i.data.hookData,t=i.index++,n=i.root,o=i.data.self;if(!Object.hasOwn(e,t)){const p=O=>{const k=typeof O=="function"?O(e[t].val):O;Object.is(k,e[t].val)||(e[t].val=k,n.__internalAddPending(o),n.__internalUpdate())};e[t]={setter:p,val:typeof s!="function"?s:s()}}return[e[t].val,e[t].setter]}var a=(s=>(s[s.LITERAL=0]="LITERAL",s[s.FRAGMENT=1]="FRAGMENT",s[s.ELEMENT=2]="ELEMENT",s[s.COMPONENT=4]="COMPONENT",s[s.NODRAW=5]="NODRAW",s))(a||{});function K(s){for(const e of s.fx)e.effect&&e.cb?.();for(const e of s.fx){if(!e.effect)continue;const t=e.effect();e.effect=null,typeof t=="function"&&(e.cb=t)}}function W(s){return Object.hasOwn(s.props,"children")?Array.isArray(s.props.children)?s.props.children:[s.props.children]:[]}function A(s){return typeof s!="object"||s===null||!Object.hasOwn(s,"key")||typeof s.key!="bigint"&&typeof s.key!="boolean"&&typeof s.key!="number"&&typeof s.key!="string"&&typeof s.key!="symbol"&&typeof s.key!="object"?null:s.key}function C(s){return typeof s=="object"&&s!==null?Array.isArray(s)?a.FRAGMENT:typeof s.type=="function"?a.COMPONENT:a.ELEMENT:typeof s=="string"||typeof s=="number"||typeof s=="bigint"?a.LITERAL:a.NODRAW}function S(s,e,t){const n=typeof e=="object"?e:document.createTextNode(`${e}`);s.childNodes.length>0?s.insertBefore(n,s.childNodes[t]):s.appendChild(n)}function j(s){const e=Array.isArray(s)?[...s]:[s];for(let t=0;t<e.length;t++){const n=e[t];switch(C(n)){case a.COMPONENT:{e[t]={type:n.type,props:{...n.props},__vnode:n},Object.hasOwn(n,"key")&&(e[t].key=n.key);break}case a.ELEMENT:{const o={type:n.type,props:{...n.props},__vnode:n};Object.hasOwn(n,"key")&&(o.key=n.key),n.props.children&&(o.props.children=j(o.props.children)),e[t]=o;break}case a.FRAGMENT:{const o=j(n);Object.hasOwn(n,"key")&&(o.key=n.key),o.__vnode=n,e[t]=o;break}}}return Array.isArray(s)?e:e[0]}function V(s,e){const t=i.data,n=i.index;i.data=s,i.index=0,e(),i.data=t,i.index=n}function q(s,e){for(const t of Object.keys(e))typeof e[t]=="object"?q(s[t],e[t]):s[t]=e[t]}function T(s,e,t){e==="class"&&(e="className"),typeof t=="object"?q(s[e],t):s[e]=t}class Q{#s;#t=new Set;#n=!1;constructor(e){this.#s=e,e.innerHTML=""}#e(e,t,n,o){for(const l of Object.keys(t.props))(t.props[l]===void 0||t.props[l]===null)&&delete t.props[l];const p=new Set([...Object.keys(t.props),...Object.keys(e.props)]);for(const l of p)if(l!=="children"){if(l==="ref"){Object.hasOwn(e.props,l)&&(e.props[l].current=null),Object.hasOwn(t.props,l)&&(t.props[l].current=n);continue}if(!Object.hasOwn(t.props,l))l.slice(0,2)==="on"&&typeof e.props[l]=="function"?n.removeEventListener(l.slice(2).toLowerCase(),e.props[l]):n[l]="";else if(!Object.hasOwn(e.props,l))l.slice(0,2)==="on"&&typeof t.props[l]=="function"?n.addEventListener(l.slice(2).toLowerCase(),t.props[l]):T(n,l,t.props[l]);else if(l.slice(0,2)==="on"){if(t.props[l]===e.props[l])continue;const h=l.slice(2).toLowerCase();typeof e.props[l]=="function"?n.removeEventListener(h,e.props[l]):T(n,l,""),typeof t.props[l]=="function"?n.addEventListener(h,t.props[l]):T(n,l,t.props[l])}else if(l==="value"||l==="checked")n[l]!==t.props[l]&&T(n,l,t.props[l]);else{if(t.props[l]===e.props[l])continue;T(n,l,t.props[l])}}const O=W(e),k=W(t),P=Math.max(O.length,k.length),x=new Map,f=o??{value:0};let L=f.value;for(let l=0;l<O.length;l++){const h=O[l],E=k[l],g=A(h),M=A(E),b=C(h),_=L;if(L=b===a.FRAGMENT||b===a.COMPONENT?h.__domEnd:L+1,g===null||g===M)continue;const r=[];for(let u=_;u<L;u++)r.push(n.childNodes[u]);x.set(g,[h,r]),O[l]=void 0}for(const[l,[h,E]]of x)for(const g of E)n.removeChild(g);for(let l=0;l<P;l++){const h=k[l];let E=O[l];const g=A(E),M=A(h);if(M!==null&&M!==g&&x.has(M)){const[d,w]=x.get(M);x.delete(M),g===null&&this.#e(c(null,null,E),c(null,null),n,f),O[l]=d,E=d;for(let m=0;m<w.length;m++)S(n,w[m],f.value+m)}const b=C(E),_=C(h),r=h,u=E;if(_!==a.NODRAW){if(b!==a.NODRAW)if(b!==_||(_===a.ELEMENT||_===a.COMPONENT)&&r.type!==u.type)this.#e(c(null,null,E),c(null,null),n,f),this.#e(c(null,null),c(null,null,h),n,f);else{if(_===a.ELEMENT||_===a.COMPONENT||_===a.FRAGMENT){if(Object.is(u.__vnode,r.__vnode)){r.__vnode=u.__vnode,(_===a.COMPONENT||_===a.FRAGMENT)&&(r.__domStart=u.__domStart,r.__domEnd=u.__domEnd),_===a.COMPONENT&&(r.__context=u.__context,r.__context.self.value=r,r.__ref=u.__ref),f.value=_===a.ELEMENT?f.value+1:u.__domEnd;continue}}else if(Object.is(E,h)){f.value++;continue}if(_===a.LITERAL)n.childNodes[f.value++].textContent=`${h}`;else if(_===a.ELEMENT){const d=n.childNodes[f.value++];this.#e(u,r,d)}else _===a.COMPONENT?(this.#t.delete(u.__context.self),V(u.__context,()=>{const d=j(r.type(r.props));r.__domStart=f.value,r.__context=u.__context,r.__context.self.value=r,r.__ref=n,this.#e(c(null,null,u.__context.prevTree),c(null,null,d),n,f),r.__context.prevTree=d,r.__domEnd=f.value,K(r.__context)})):(r.__domStart=f.value,this.#e(c(null,null,...E),c(null,null,...h),n,f),r.__domEnd=f.value)}else if(_===a.LITERAL)S(n,h,f.value++);else if(_===a.FRAGMENT)r.__domStart=f.value,this.#e(c(null,null),c(null,null,...h),n,f),r.__domEnd=f.value;else if(typeof r.type=="string"){const d=document.createElement(r.type);this.#e(c(r.type,{}),r,d),S(n,d,f.value++)}else if(r.type!==null){const d={hookData:[],fx:[],self:{value:r},prevProps:r.props,prevTree:null,parent:i.data?.self??null};V(d,()=>{const w=j(r.type(r.props));r.__domStart=f.value,r.__context=d,r.__ref=n,this.#e(c(null,null),c(null,null,w),n,f),r.__domEnd=f.value,d.prevTree=w,K(r.__context)})}}else if(b!==a.NODRAW)if(b===a.FRAGMENT)this.#e(c(null,null,...E),c(null,null,h),n,f);else if(b===a.COMPONENT){this.#t.delete(u.__context.self),this.#e(c(null,null,u.__context.prevTree),c(null,null,h),n,f);for(const d of u.__context.fx)d.cb?.()}else b===a.ELEMENT&&(O.length>0&&this.#e(u,c(null,null),n.childNodes[f.value]),Object.hasOwn(u.props,"ref")&&(u.props.ref.current=null)),n.childNodes[f.value].remove()}}__internalAddPending(e){this.#t.add(e)}__internalUpdate(){this.#n||(this.#n=!0,requestIdleCallback(()=>{i.root=this;for(const e of this.#t){const t={value:e.value.__domStart};this.#t.delete(e),this.#e(c(null,null,e.value),j(c(null,null,e.value)),e.value.__ref,t)}this.#n=!1}))}render(e){i.root=this,this.#e(c(null,null),j(c(null,null,e)),this.#s)}}function X(s){const e=document.querySelector(s);return e||v("Root element doesn't exist"),new Q(e)}const R=Symbol.for("freact.fragment");return y.Fragment=R,y.createContext=$,y.createRoot=X,y.h=c,y.memo=H,y.useCallback=B,y.useContext=G,y.useEffect=I,y.useMemo=N,y.useReducer=z,y.useRef=D,y.useState=J,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"}),y}({}); |
@@ -1,1 +0,1 @@ | ||
| (function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.Freact={}))})(this,function(_){"use strict";function a(o,e,...t){const n=e&&Object.hasOwn(e,"key"),s=e?.key;if(delete e?.key,o===C)return n&&(t.key=s),t.length>0?t:void 0;const h={type:o,props:{...e}};return t.length>0&&(h.props.children=t.length>1?t:t[0]),n&&(h.key=s),h}const r={root:null,data:null,index:0};function m(o,e){if(!r.root||!r.data)throw new Error("Missing context data inside useMemo hook");const t=r.data.hookData,n=r.index++;if(!Object.hasOwn(t,n))t[n]={val:o(),deps:e};else{let s=t[n].deps.length===e.length;if(s){for(let h=0;h<e.length;h++)if(!Object.is(t[n].deps[h],e[h])){s=!1;break}}s||(t[n].val=o(),t[n].deps=e)}return t[n].val}const q=(o,e)=>{const t=Object.keys(e);if(t.length!==Object.keys(o).length)return!1;const n=Object.hasOwn(e,"children");if(Object.hasOwn(o,"children")!==n)return!1;if(n){if(o.children.length!==e.children.length)return!1;for(let s=0;s<e.children.length;s++)if(!Object.is(e.children[s],o.children[s]))return!1}for(const s of t)if(s!=="children"&&!Object.is(o[s],e[s]))return!1;return!0};function F(o,e=q){let t=!1;return n=>(t=e(r.data?.self.value.__context?.prevProps??{},n)?t:!t,m(()=>a(o,n),[t]))}function P(o,e){if(!r.root||!r.data)throw new Error("Missing context data inside useEffect hook");const t=r.data.hookData,n=r.index++;if(!Object.hasOwn(t,n))t[n]={effect:o,cb:null,deps:e??null},r.data.fx.push(t[n]);else{let s=!!t[n].deps&&t[n].deps?.length===e?.length;if(s){for(let h=0;h<e.length;h++)if(!Object.is(t[n].deps[h],e[h])){s=!1;break}}s||(t[n].effect=o,t[n].deps=e??null)}}function I(o){if(!r.root||!r.data)throw new Error("Missing context data inside useContext hook");const e=r.data.hookData,t=r.index++,n=r.data.self;if(!Object.hasOwn(e,t)){let s=r.data.parent?.value;for(;s&&s.type!==o.Provider;)s=s.__context?.parent?.value;if(s){if(!s.__context?.providerData)throw new Error("Provider doesn't contain ProviderData. How?");s.__context.providerData.subs.add(n),e[t]=s.__context.providerData}else e[t]={val:o.__defaultValue}}return P(()=>()=>e[t].subs?.delete(n),[]),e[t].val}class H{__defaultValue;constructor(e){this.__defaultValue=e}Provider=({value:e,children:t})=>{const n=N({val:e,subs:new Set}),s=N(!0);return s.current&&(r.data.providerData=n.current,s.current=!1),Object.is(n.current.val,e)||(n.current.val=e,n.current.subs.forEach(h=>{r.root?.__internalAddPending(h)})),a(C,null,t)};Consumer=({children:e})=>{const t=I(this);return a(C,null,e(t))}}function U(o){return new H(o)}function $(o,e){if(!r.root||!r.data)throw new Error("Missing context data inside useCallback hook");return m(()=>o,e)}function B(o,e,t){if(!r.root||!r.data)throw new Error("Missing context data inside useReducer hook");const n=r.data.hookData,s=r.index++,h=r.root,E=r.data.self;if(!Object.hasOwn(n,s)){const b=S=>{const k=o(n[s].val,S);Object.is(k,n[s].val)||(n[s].val=k,h.__internalAddPending(E),h.__internalUpdate())};n[s]={val:t?t(e):e,dispatch:b}}return[n[s].val,n[s].dispatch]}function N(o){if(!r.root||!r.data)throw new Error("Missing context data inside useRef hook");const e=r.data.hookData,t=r.index++;return Object.hasOwn(e,t)||(e[t]={current:o}),e[t]}function z(o){if(!r.root||!r.data)throw new Error("Missing context data inside useState hook");const e=r.data.hookData,t=r.index++,n=r.root,s=r.data.self;if(!Object.hasOwn(e,t)){const h=E=>{const b=typeof E=="function"?E(e[t].val):E;Object.is(b,e[t].val)||(e[t].val=b,n.__internalAddPending(s),n.__internalUpdate())};e[t]={setter:h,val:typeof o!="function"?o:o()}}return[e[t].val,e[t].setter]}var c=(o=>(o[o.LITERAL=0]="LITERAL",o[o.FRAGMENT=1]="FRAGMENT",o[o.ELEMENT=2]="ELEMENT",o[o.COMPONENT=4]="COMPONENT",o[o.NODRAW=5]="NODRAW",o))(c||{});function G(o){for(const e of o.fx)e.effect&&e.cb?.();for(const e of o.fx){if(!e.effect)continue;const t=e.effect();e.effect=null,typeof t=="function"&&(e.cb=t)}}function K(o){return Object.hasOwn(o.props,"children")?Array.isArray(o.props.children)?o.props.children:[o.props.children]:[]}function T(o){return typeof o!="object"||o===null||!Object.hasOwn(o,"key")||typeof o.key!="bigint"&&typeof o.key!="boolean"&&typeof o.key!="number"&&typeof o.key!="string"&&typeof o.key!="symbol"&&typeof o.key!="object"?null:o.key}function A(o){return typeof o=="object"&&o!==null?Array.isArray(o)?c.FRAGMENT:typeof o.type=="function"?c.COMPONENT:c.ELEMENT:typeof o=="string"||typeof o=="number"||typeof o=="bigint"?c.LITERAL:c.NODRAW}function D(o,e,t){const n=typeof e=="object"?e:document.createTextNode(`${e}`);o.childNodes.length>0?o.insertBefore(n,o.childNodes[t]):o.appendChild(n)}function g(o){const e=Array.isArray(o)?[...o]:[o];for(let t=0;t<e.length;t++){const n=e[t];switch(A(n)){case c.COMPONENT:{e[t]={type:n.type,props:{...n.props},__vnode:n},Object.hasOwn(n,"key")&&(e[t].key=n.key);break}case c.ELEMENT:{const s={type:n.type,props:{...n.props},__vnode:n};Object.hasOwn(n,"key")&&(s.key=n.key),n.props.children&&(s.props.children=g(s.props.children)),e[t]=s;break}case c.FRAGMENT:{const s=g(n);Object.hasOwn(n,"key")&&(s.key=n.key),s.__vnode=n,e[t]=s;break}}}return Array.isArray(o)?e:e[0]}function W(o,e){const t=r.data,n=r.index;r.data=o,r.index=0,e(),r.data=t,r.index=n}function V(o,e){for(const t of Object.keys(e))typeof e[t]=="object"?V(o[t],e[t]):o[t]=e[t]}function M(o,e,t){e==="class"&&(e="className"),typeof t=="object"?V(o[e],t):o[e]=t}class J{#o;#t=new Set;#n=!1;constructor(e){this.#o=e,e.innerHTML=""}#e(e,t,n,s){const h=new Set([...Object.keys(t.props),...Object.keys(e.props)]);for(const l of h)if(l!=="children"){if(l==="ref"){Object.hasOwn(e.props,l)&&(e.props[l].current=null),Object.hasOwn(t.props,l)&&(t.props[l].current=n);continue}if(!Object.hasOwn(t.props,l))l.slice(0,2)==="on"&&typeof e.props[l]=="function"?n.removeEventListener(l.slice(2).toLowerCase(),e.props[l]):n[l]="";else if(!Object.hasOwn(e.props,l))l.slice(0,2)==="on"&&typeof t.props[l]=="function"?n.addEventListener(l.slice(2).toLowerCase(),t.props[l]):M(n,l,t.props[l]);else if(l.slice(0,2)==="on"){if(t.props[l]===e.props[l])continue;const d=l.slice(2).toLowerCase();typeof e.props[l]=="function"?n.removeEventListener(d,e.props[l]):M(n,l,""),typeof t.props[l]=="function"?n.addEventListener(d,t.props[l]):M(n,l,t.props[l])}else if(l==="value"||l==="checked")n[l]!==t.props[l]&&M(n,l,t.props[l]);else{if(t.props[l]===e.props[l])continue;M(n,l,t.props[l])}}const E=K(e),b=K(t),S=Math.max(E.length,b.length),k=new Map,f=s??{value:0};let R=f.value;for(let l=0;l<E.length;l++){const d=E[l],O=b[l],x=T(d),w=T(O),v=A(d),p=R;if(R=v===c.FRAGMENT||v===c.COMPONENT?d.__domEnd:R+1,x===null||x===w)continue;const i=[];for(let u=p;u<R;u++)i.push(n.childNodes[u]);k.set(x,[d,i]),E[l]=void 0}for(const[l,[d,O]]of k)for(const x of O)n.removeChild(x);for(let l=0;l<S;l++){const d=b[l];let O=E[l];const x=T(O),w=T(d);if(w!==null&&w!==x&&k.has(w)){const[y,j]=k.get(w);k.delete(w),x===null&&this.#e(a(null,null,O),a(null,null),n,f),E[l]=y,O=y;for(let L=0;L<j.length;L++)D(n,j[L],f.value+L)}const v=A(O),p=A(d),i=d,u=O;if(p!==c.NODRAW){if(v!==c.NODRAW)if(v!==p||(p===c.ELEMENT||p===c.COMPONENT)&&i.type!==u.type)this.#e(a(null,null,O),a(null,null),n,f),this.#e(a(null,null),a(null,null,d),n,f);else{if(p===c.ELEMENT||p===c.COMPONENT||p===c.FRAGMENT){if(Object.is(u.__vnode,i.__vnode)){i.__vnode=u.__vnode,(p===c.COMPONENT||p===c.FRAGMENT)&&(i.__domStart=u.__domStart,i.__domEnd=u.__domEnd),p===c.COMPONENT&&(i.__context=u.__context,i.__context.self.value=i,i.__ref=u.__ref),f.value=p===c.ELEMENT?f.value+1:u.__domEnd;continue}}else if(Object.is(O,d)){f.value++;continue}if(p===c.LITERAL)n.childNodes[f.value++].textContent=`${d}`;else if(p===c.ELEMENT){const y=n.childNodes[f.value++];this.#e(u,i,y)}else p===c.COMPONENT?(this.#t.delete(u.__context.self),W(u.__context,()=>{const y=g(i.type(i.props));i.__domStart=f.value,i.__context=u.__context,i.__context.self.value=i,i.__ref=n,this.#e(a(null,null,u.__context.prevTree),a(null,null,y),n,f),i.__context.prevTree=y,i.__domEnd=f.value,G(i.__context)})):(i.__domStart=f.value,this.#e(a(null,null,...O),a(null,null,...d),n,f),i.__domEnd=f.value)}else if(p===c.LITERAL)D(n,d,f.value++);else if(p===c.FRAGMENT)i.__domStart=f.value,this.#e(a(null,null),a(null,null,...d),n,f),i.__domEnd=f.value;else if(typeof i.type=="string"){const y=document.createElement(i.type);this.#e(a(i.type,{}),i,y),D(n,y,f.value++)}else if(i.type!==null){const y={hookData:[],fx:[],self:{value:i},prevProps:i.props,prevTree:null,parent:r.data?.self??null};W(y,()=>{const j=g(i.type(i.props));i.__domStart=f.value,i.__context=y,i.__ref=n,this.#e(a(null,null),a(null,null,j),n,f),i.__domEnd=f.value,y.prevTree=j,G(i.__context)})}}else if(v!==c.NODRAW)if(v===c.FRAGMENT)this.#e(a(null,null,...O),a(null,null,d),n,f);else if(v===c.COMPONENT){this.#t.delete(u.__context.self),this.#e(a(null,null,u.__context.prevTree),a(null,null,d),n,f);for(const y of u.__context.fx)y.cb?.()}else v===c.ELEMENT&&(E.length>0&&this.#e(u,a(null,null),n.childNodes[f.value]),Object.hasOwn(u.props,"ref")&&(u.props.ref.current=null)),n.childNodes[f.value].remove()}}__internalAddPending(e){this.#t.add(e)}__internalUpdate(){this.#n||(this.#n=!0,requestIdleCallback(()=>{r.root=this;for(const e of this.#t){const t={value:e.value.__domStart};this.#t.delete(e),this.#e(a(null,null,e.value),g(a(null,null,e.value)),e.value.__ref,t)}this.#n=!1}))}render(e){r.root=this,this.#e(a(null,null),g(a(null,null,e)),this.#o)}}function Q(o){const e=document.querySelector(o);if(!e)throw new Error("Root element doesn't exist");return new J(e)}const C=Symbol.for("freact.fragment");_.Fragment=C,_.createContext=U,_.createRoot=Q,_.h=a,_.memo=F,_.useCallback=$,_.useContext=I,_.useEffect=P,_.useMemo=m,_.useReducer=B,_.useRef=N,_.useState=z,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}); | ||
| (function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.Freact={}))})(this,function(_){"use strict";function a(s,e,...t){const n=e&&Object.hasOwn(e,"key"),l=e?.key;if(delete e?.key,s===R)return n&&(t.key=l),t.length>0?t:void 0;const p={type:s,props:{...e}};return t.length>0&&(p.props.children=t.length>1?t:t[0]),n&&(p.key=l),p}function v(s){throw new Error(s)}const i={root:null,data:null,index:0};function N(s,e){(!i.root||!i.data)&&v("Missing context data inside useMemo hook");const t=i.data.hookData,n=i.index++;if(!Object.hasOwn(t,n))t[n]={val:s(),deps:e};else{let l=t[n].deps.length===e.length;if(l){for(let p=0;p<e.length;p++)if(!Object.is(t[n].deps[p],e[p])){l=!1;break}}l||(t[n].val=s(),t[n].deps=e)}return t[n].val}const F=(s,e)=>{const t=Object.keys(e);if(t.length!==Object.keys(s).length)return!1;const n=Object.hasOwn(e,"children");if(Object.hasOwn(s,"children")!==n)return!1;if(n){if(s.children.length!==e.children.length)return!1;for(let l=0;l<e.children.length;l++)if(!Object.is(e.children[l],s.children[l]))return!1}for(const l of t)if(l!=="children"&&!Object.is(s[l],e[l]))return!1;return!0};function H(s,e=F){let t=!1;return n=>(t=e(i.data?.self.value.__context?.prevProps??{},n)?t:!t,N(()=>a(s,n),[t]))}function I(s,e){(!i.root||!i.data)&&v("Missing context data inside useEffect hook");const t=i.data.hookData,n=i.index++;if(!Object.hasOwn(t,n))t[n]={effect:s,cb:null,deps:e??null},i.data.fx.push(t[n]);else{let l=!!t[n].deps&&t[n].deps?.length===e?.length;if(l){for(let p=0;p<e.length;p++)if(!Object.is(t[n].deps[p],e[p])){l=!1;break}}l||(t[n].effect=s,t[n].deps=e??null)}}function G(s){(!i.root||!i.data)&&v("Missing context data inside useContext hook");const e=i.data.hookData,t=i.index++,n=i.data.self;if(!Object.hasOwn(e,t)){let l=i.data.parent?.value;for(;l&&l.type!==s.Provider;)l=l.__context?.parent?.value;l?(l.__context?.providerData||v("Provider doesn't contain ProviderData. How?"),l.__context.providerData.subs.add(n),e[t]=l.__context.providerData):e[t]={val:s.__defaultValue}}return I(()=>()=>e[t].subs?.delete(n),[]),e[t].val}class U{__defaultValue;constructor(e){this.__defaultValue=e}Provider=({value:e,children:t})=>{const n=D({val:e,subs:new Set}),l=D(!0);return l.current&&(i.data.providerData=n.current,l.current=!1),Object.is(n.current.val,e)||(n.current.val=e,n.current.subs.forEach(p=>{i.root?.__internalAddPending(p)})),a(R,null,t)};Consumer=({children:e})=>{const t=G(this);return a(R,null,e(t))}}function $(s){return new U(s)}function B(s,e){return(!i.root||!i.data)&&v("Missing context data inside useCallback hook"),N(()=>s,e)}function z(s,e,t){(!i.root||!i.data)&&v("Missing context data inside useReducer hook");const n=i.data.hookData,l=i.index++,p=i.root,O=i.data.self;if(!Object.hasOwn(n,l)){const k=P=>{const x=s(n[l].val,P);Object.is(x,n[l].val)||(n[l].val=x,p.__internalAddPending(O),p.__internalUpdate())};n[l]={val:t?t(e):e,dispatch:k}}return[n[l].val,n[l].dispatch]}function D(s){(!i.root||!i.data)&&v("Missing context data inside useRef hook");const e=i.data.hookData,t=i.index++;return Object.hasOwn(e,t)||(e[t]={current:s}),e[t]}function J(s){(!i.root||!i.data)&&v("Missing context data inside useState hook");const e=i.data.hookData,t=i.index++,n=i.root,l=i.data.self;if(!Object.hasOwn(e,t)){const p=O=>{const k=typeof O=="function"?O(e[t].val):O;Object.is(k,e[t].val)||(e[t].val=k,n.__internalAddPending(l),n.__internalUpdate())};e[t]={setter:p,val:typeof s!="function"?s:s()}}return[e[t].val,e[t].setter]}var c=(s=>(s[s.LITERAL=0]="LITERAL",s[s.FRAGMENT=1]="FRAGMENT",s[s.ELEMENT=2]="ELEMENT",s[s.COMPONENT=4]="COMPONENT",s[s.NODRAW=5]="NODRAW",s))(c||{});function K(s){for(const e of s.fx)e.effect&&e.cb?.();for(const e of s.fx){if(!e.effect)continue;const t=e.effect();e.effect=null,typeof t=="function"&&(e.cb=t)}}function W(s){return Object.hasOwn(s.props,"children")?Array.isArray(s.props.children)?s.props.children:[s.props.children]:[]}function A(s){return typeof s!="object"||s===null||!Object.hasOwn(s,"key")||typeof s.key!="bigint"&&typeof s.key!="boolean"&&typeof s.key!="number"&&typeof s.key!="string"&&typeof s.key!="symbol"&&typeof s.key!="object"?null:s.key}function C(s){return typeof s=="object"&&s!==null?Array.isArray(s)?c.FRAGMENT:typeof s.type=="function"?c.COMPONENT:c.ELEMENT:typeof s=="string"||typeof s=="number"||typeof s=="bigint"?c.LITERAL:c.NODRAW}function S(s,e,t){const n=typeof e=="object"?e:document.createTextNode(`${e}`);s.childNodes.length>0?s.insertBefore(n,s.childNodes[t]):s.appendChild(n)}function j(s){const e=Array.isArray(s)?[...s]:[s];for(let t=0;t<e.length;t++){const n=e[t];switch(C(n)){case c.COMPONENT:{e[t]={type:n.type,props:{...n.props},__vnode:n},Object.hasOwn(n,"key")&&(e[t].key=n.key);break}case c.ELEMENT:{const l={type:n.type,props:{...n.props},__vnode:n};Object.hasOwn(n,"key")&&(l.key=n.key),n.props.children&&(l.props.children=j(l.props.children)),e[t]=l;break}case c.FRAGMENT:{const l=j(n);Object.hasOwn(n,"key")&&(l.key=n.key),l.__vnode=n,e[t]=l;break}}}return Array.isArray(s)?e:e[0]}function V(s,e){const t=i.data,n=i.index;i.data=s,i.index=0,e(),i.data=t,i.index=n}function q(s,e){for(const t of Object.keys(e))typeof e[t]=="object"?q(s[t],e[t]):s[t]=e[t]}function T(s,e,t){e==="class"&&(e="className"),typeof t=="object"?q(s[e],t):s[e]=t}class Q{#s;#t=new Set;#n=!1;constructor(e){this.#s=e,e.innerHTML=""}#e(e,t,n,l){for(const o of Object.keys(t.props))(t.props[o]===void 0||t.props[o]===null)&&delete t.props[o];const p=new Set([...Object.keys(t.props),...Object.keys(e.props)]);for(const o of p)if(o!=="children"){if(o==="ref"){Object.hasOwn(e.props,o)&&(e.props[o].current=null),Object.hasOwn(t.props,o)&&(t.props[o].current=n);continue}if(!Object.hasOwn(t.props,o))o.slice(0,2)==="on"&&typeof e.props[o]=="function"?n.removeEventListener(o.slice(2).toLowerCase(),e.props[o]):n[o]="";else if(!Object.hasOwn(e.props,o))o.slice(0,2)==="on"&&typeof t.props[o]=="function"?n.addEventListener(o.slice(2).toLowerCase(),t.props[o]):T(n,o,t.props[o]);else if(o.slice(0,2)==="on"){if(t.props[o]===e.props[o])continue;const d=o.slice(2).toLowerCase();typeof e.props[o]=="function"?n.removeEventListener(d,e.props[o]):T(n,o,""),typeof t.props[o]=="function"?n.addEventListener(d,t.props[o]):T(n,o,t.props[o])}else if(o==="value"||o==="checked")n[o]!==t.props[o]&&T(n,o,t.props[o]);else{if(t.props[o]===e.props[o])continue;T(n,o,t.props[o])}}const O=W(e),k=W(t),P=Math.max(O.length,k.length),x=new Map,f=l??{value:0};let L=f.value;for(let o=0;o<O.length;o++){const d=O[o],E=k[o],g=A(d),M=A(E),b=C(d),h=L;if(L=b===c.FRAGMENT||b===c.COMPONENT?d.__domEnd:L+1,g===null||g===M)continue;const r=[];for(let u=h;u<L;u++)r.push(n.childNodes[u]);x.set(g,[d,r]),O[o]=void 0}for(const[o,[d,E]]of x)for(const g of E)n.removeChild(g);for(let o=0;o<P;o++){const d=k[o];let E=O[o];const g=A(E),M=A(d);if(M!==null&&M!==g&&x.has(M)){const[y,w]=x.get(M);x.delete(M),g===null&&this.#e(a(null,null,E),a(null,null),n,f),O[o]=y,E=y;for(let m=0;m<w.length;m++)S(n,w[m],f.value+m)}const b=C(E),h=C(d),r=d,u=E;if(h!==c.NODRAW){if(b!==c.NODRAW)if(b!==h||(h===c.ELEMENT||h===c.COMPONENT)&&r.type!==u.type)this.#e(a(null,null,E),a(null,null),n,f),this.#e(a(null,null),a(null,null,d),n,f);else{if(h===c.ELEMENT||h===c.COMPONENT||h===c.FRAGMENT){if(Object.is(u.__vnode,r.__vnode)){r.__vnode=u.__vnode,(h===c.COMPONENT||h===c.FRAGMENT)&&(r.__domStart=u.__domStart,r.__domEnd=u.__domEnd),h===c.COMPONENT&&(r.__context=u.__context,r.__context.self.value=r,r.__ref=u.__ref),f.value=h===c.ELEMENT?f.value+1:u.__domEnd;continue}}else if(Object.is(E,d)){f.value++;continue}if(h===c.LITERAL)n.childNodes[f.value++].textContent=`${d}`;else if(h===c.ELEMENT){const y=n.childNodes[f.value++];this.#e(u,r,y)}else h===c.COMPONENT?(this.#t.delete(u.__context.self),V(u.__context,()=>{const y=j(r.type(r.props));r.__domStart=f.value,r.__context=u.__context,r.__context.self.value=r,r.__ref=n,this.#e(a(null,null,u.__context.prevTree),a(null,null,y),n,f),r.__context.prevTree=y,r.__domEnd=f.value,K(r.__context)})):(r.__domStart=f.value,this.#e(a(null,null,...E),a(null,null,...d),n,f),r.__domEnd=f.value)}else if(h===c.LITERAL)S(n,d,f.value++);else if(h===c.FRAGMENT)r.__domStart=f.value,this.#e(a(null,null),a(null,null,...d),n,f),r.__domEnd=f.value;else if(typeof r.type=="string"){const y=document.createElement(r.type);this.#e(a(r.type,{}),r,y),S(n,y,f.value++)}else if(r.type!==null){const y={hookData:[],fx:[],self:{value:r},prevProps:r.props,prevTree:null,parent:i.data?.self??null};V(y,()=>{const w=j(r.type(r.props));r.__domStart=f.value,r.__context=y,r.__ref=n,this.#e(a(null,null),a(null,null,w),n,f),r.__domEnd=f.value,y.prevTree=w,K(r.__context)})}}else if(b!==c.NODRAW)if(b===c.FRAGMENT)this.#e(a(null,null,...E),a(null,null,d),n,f);else if(b===c.COMPONENT){this.#t.delete(u.__context.self),this.#e(a(null,null,u.__context.prevTree),a(null,null,d),n,f);for(const y of u.__context.fx)y.cb?.()}else b===c.ELEMENT&&(O.length>0&&this.#e(u,a(null,null),n.childNodes[f.value]),Object.hasOwn(u.props,"ref")&&(u.props.ref.current=null)),n.childNodes[f.value].remove()}}__internalAddPending(e){this.#t.add(e)}__internalUpdate(){this.#n||(this.#n=!0,requestIdleCallback(()=>{i.root=this;for(const e of this.#t){const t={value:e.value.__domStart};this.#t.delete(e),this.#e(a(null,null,e.value),j(a(null,null,e.value)),e.value.__ref,t)}this.#n=!1}))}render(e){i.root=this,this.#e(a(null,null),j(a(null,null,e)),this.#s)}}function X(s){const e=document.querySelector(s);return e||v("Root element doesn't exist"),new Q(e)}const R=Symbol.for("freact.fragment");_.Fragment=R,_.createContext=$,_.createRoot=X,_.h=a,_.memo=H,_.useCallback=B,_.useContext=G,_.useEffect=I,_.useMemo=N,_.useReducer=z,_.useRef=D,_.useState=J,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}); |
+1
-1
| { | ||
| "name": "@freact/core", | ||
| "version": "0.0.14", | ||
| "version": "0.0.15", | ||
| "author": "Fry", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
83926
0.25%36
2.86%773
-1.15%