36 lines
1.8 KiB
JavaScript
36 lines
1.8 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
const w = /* @__PURE__ */ new Set(["children", "localName", "ref", "style", "className"]), m = /* @__PURE__ */ new WeakMap(), y = (r, u, a, i, d) => {
|
|
const f = d == null ? void 0 : d[u];
|
|
f === void 0 ? (r[u] = a, a == null && u in HTMLElement.prototype && r.removeAttribute(u)) : a !== i && ((l, c, o) => {
|
|
let s = m.get(l);
|
|
s === void 0 && m.set(l, s = /* @__PURE__ */ new Map());
|
|
let t = s.get(c);
|
|
o !== void 0 ? t === void 0 ? (s.set(c, t = { handleEvent: o }), l.addEventListener(c, t)) : t.handleEvent = o : t !== void 0 && (s.delete(c), l.removeEventListener(c, t));
|
|
})(r, f, a);
|
|
}, h = ({ react: r, tagName: u, elementClass: a, events: i, displayName: d }) => {
|
|
const f = new Set(Object.keys(i ?? {})), l = r.forwardRef((c, o) => {
|
|
const s = r.useRef(/* @__PURE__ */ new Map()), t = r.useRef(null), p = {}, v = {};
|
|
for (const [e, n] of Object.entries(c)) w.has(e) ? p[e === "className" ? "class" : e] = n : f.has(e) || e in a.prototype ? v[e] = n : p[e] = n;
|
|
return r.useLayoutEffect(() => {
|
|
if (t.current === null) return;
|
|
const e = /* @__PURE__ */ new Map();
|
|
for (const n in v) y(t.current, n, c[n], s.current.get(n), i), s.current.delete(n), e.set(n, c[n]);
|
|
for (const [n, E] of s.current) y(t.current, n, void 0, E, i);
|
|
s.current = e;
|
|
}), r.useLayoutEffect(() => {
|
|
var e;
|
|
(e = t.current) == null || e.removeAttribute("defer-hydration");
|
|
}, []), p.suppressHydrationWarning = !0, r.createElement(u, { ...p, ref: r.useCallback((e) => {
|
|
t.current = e, typeof o == "function" ? o(e) : o !== null && (o.current = e);
|
|
}, [o]) });
|
|
});
|
|
return l.displayName = d ?? a.name, l;
|
|
};
|
|
export {
|
|
h as o
|
|
};
|