@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
37 lines (36 loc) • 1.35 kB
JavaScript
import { useRef as o, useEffect as i } from "react";
const s = /[\x00-\x1F]/g;
let c = null, r = null;
function d(e) {
return c || (c = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu, r = /* @__PURE__ */ new Map([["ſt", "ſt"]])), e.replace(
c,
(f, u, t) => u ? u.normalize("NFKC") : (r == null ? void 0 : r.get(t)) || ""
);
}
function p(e, f = !1) {
return s.test(e) ? f ? e.replace(s, (u) => u === "\0" ? "" : " ") : e.replace(/\x00/g, "") : e;
}
const x = (e) => {
const f = o(!1), u = o(null);
i(() => {
if (!e || f.current)
return;
const t = (n) => {
var l;
const b = document.getSelection();
if (!b)
return;
const a = b.toString();
a && ((l = n.clipboardData) == null || l.setData(
"text/plain",
p(d(a))
), n.preventDefault(), n.stopPropagation());
};
return e.addEventListener("copy", t), u.current = e, f.current = !0, () => {
u.current && (u.current.removeEventListener("copy", t), f.current = !1);
};
}, [e]);
};
export {
x as useCopyText
};