r-scale-screen
Version:
react 大屏自适应组件
753 lines (749 loc) • 24.4 kB
JavaScript
import Fe, { useRef as or, useState as ur, useEffect as sr } from "react";
var X = {}, lr = {
get exports() {
return X;
},
set exports(l) {
X = l;
}
}, U = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ke;
function cr() {
if (ke)
return U;
ke = 1;
var l = Fe, b = Symbol.for("react.element"), m = Symbol.for("react.fragment"), E = Object.prototype.hasOwnProperty, C = l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, D = { key: !0, ref: !0, __self: !0, __source: !0 };
function x(f, u, O) {
var h, g = {}, w = null, j = null;
O !== void 0 && (w = "" + O), u.key !== void 0 && (w = "" + u.key), u.ref !== void 0 && (j = u.ref);
for (h in u)
E.call(u, h) && !D.hasOwnProperty(h) && (g[h] = u[h]);
if (f && f.defaultProps)
for (h in u = f.defaultProps, u)
g[h] === void 0 && (g[h] = u[h]);
return { $$typeof: b, type: f, key: w, ref: j, props: g, _owner: C.current };
}
return U.Fragment = m, U.jsx = x, U.jsxs = x, U;
}
var z = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var De;
function fr() {
return De || (De = 1, process.env.NODE_ENV !== "production" && function() {
var l = Fe, b = Symbol.for("react.element"), m = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), D = Symbol.for("react.profiler"), x = Symbol.for("react.provider"), f = Symbol.for("react.context"), u = Symbol.for("react.forward_ref"), O = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), g = Symbol.for("react.memo"), w = Symbol.for("react.lazy"), j = Symbol.for("react.offscreen"), I = Symbol.iterator, Z = "@@iterator";
function H(e) {
if (e === null || typeof e != "object")
return null;
var r = I && e[I] || e[Z];
return typeof r == "function" ? r : null;
}
var R = l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function v(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
Q("error", e, t);
}
}
function Q(e, r, t) {
{
var n = R.ReactDebugCurrentFrame, o = n.getStackAddendum();
o !== "" && (r += "%s", t = t.concat([o]));
var s = t.map(function(i) {
return String(i);
});
s.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, s);
}
}
var _ = !1, Y = !1, M = !1, L = !1, F = !1, P;
P = Symbol.for("react.module.reference");
function W(e) {
return !!(typeof e == "string" || typeof e == "function" || e === E || e === D || F || e === C || e === O || e === h || L || e === j || _ || Y || M || typeof e == "object" && e !== null && (e.$$typeof === w || e.$$typeof === g || e.$$typeof === x || e.$$typeof === f || e.$$typeof === u || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === P || e.getModuleId !== void 0));
}
function We(e, r, t) {
var n = e.displayName;
if (n)
return n;
var o = r.displayName || r.name || "";
return o !== "" ? t + "(" + o + ")" : t;
}
function se(e) {
return e.displayName || "Context";
}
function S(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case E:
return "Fragment";
case m:
return "Portal";
case D:
return "Profiler";
case C:
return "StrictMode";
case O:
return "Suspense";
case h:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case f:
var r = e;
return se(r) + ".Consumer";
case x:
var t = e;
return se(t._context) + ".Provider";
case u:
return We(e, e.render, "ForwardRef");
case g:
var n = e.displayName || null;
return n !== null ? n : S(e.type) || "Memo";
case w: {
var o = e, s = o._payload, i = o._init;
try {
return S(i(s));
} catch {
return null;
}
}
}
return null;
}
var k = Object.assign, N = 0, le, ce, fe, de, ve, he, pe;
function ge() {
}
ge.__reactDisabledLog = !0;
function $e() {
{
if (N === 0) {
le = console.log, ce = console.info, fe = console.warn, de = console.error, ve = console.group, he = console.groupCollapsed, pe = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: ge,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
N++;
}
}
function Ae() {
{
if (N--, N === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: k({}, e, {
value: le
}),
info: k({}, e, {
value: ce
}),
warn: k({}, e, {
value: fe
}),
error: k({}, e, {
value: de
}),
group: k({}, e, {
value: ve
}),
groupCollapsed: k({}, e, {
value: he
}),
groupEnd: k({}, e, {
value: pe
})
});
}
N < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var ee = R.ReactCurrentDispatcher, re;
function B(e, r, t) {
{
if (re === void 0)
try {
throw Error();
} catch (o) {
var n = o.stack.trim().match(/\n( *(at )?)/);
re = n && n[1] || "";
}
return `
` + re + e;
}
}
var te = !1, q;
{
var Ie = typeof WeakMap == "function" ? WeakMap : Map;
q = new Ie();
}
function ye(e, r) {
if (!e || te)
return "";
{
var t = q.get(e);
if (t !== void 0)
return t;
}
var n;
te = !0;
var o = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var s;
s = ee.current, ee.current = null, $e();
try {
if (r) {
var i = function() {
throw Error();
};
if (Object.defineProperty(i.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(i, []);
} catch (T) {
n = T;
}
Reflect.construct(e, [], i);
} else {
try {
i.call();
} catch (T) {
n = T;
}
e.call(i.prototype);
}
} else {
try {
throw Error();
} catch (T) {
n = T;
}
e();
}
} catch (T) {
if (T && n && typeof T.stack == "string") {
for (var a = T.stack.split(`
`), p = n.stack.split(`
`), c = a.length - 1, d = p.length - 1; c >= 1 && d >= 0 && a[c] !== p[d]; )
d--;
for (; c >= 1 && d >= 0; c--, d--)
if (a[c] !== p[d]) {
if (c !== 1 || d !== 1)
do
if (c--, d--, d < 0 || a[c] !== p[d]) {
var y = `
` + a[c].replace(" at new ", " at ");
return e.displayName && y.includes("<anonymous>") && (y = y.replace("<anonymous>", e.displayName)), typeof e == "function" && q.set(e, y), y;
}
while (c >= 1 && d >= 0);
break;
}
}
} finally {
te = !1, ee.current = s, Ae(), Error.prepareStackTrace = o;
}
var A = e ? e.displayName || e.name : "", je = A ? B(A) : "";
return typeof e == "function" && q.set(e, je), je;
}
function Ye(e, r, t) {
return ye(e, !1);
}
function Me(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function J(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return ye(e, Me(e));
if (typeof e == "string")
return B(e);
switch (e) {
case O:
return B("Suspense");
case h:
return B("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case u:
return Ye(e.render);
case g:
return J(e.type, r, t);
case w: {
var n = e, o = n._payload, s = n._init;
try {
return J(s(o), r, t);
} catch {
}
}
}
return "";
}
var G = Object.prototype.hasOwnProperty, be = {}, me = R.ReactDebugCurrentFrame;
function K(e) {
if (e) {
var r = e._owner, t = J(e.type, e._source, r ? r.type : null);
me.setExtraStackFrame(t);
} else
me.setExtraStackFrame(null);
}
function Le(e, r, t, n, o) {
{
var s = Function.call.bind(G);
for (var i in e)
if (s(e, i)) {
var a = void 0;
try {
if (typeof e[i] != "function") {
var p = Error((n || "React class") + ": " + t + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw p.name = "Invariant Violation", p;
}
a = e[i](r, i, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (c) {
a = c;
}
a && !(a instanceof Error) && (K(o), v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, i, typeof a), K(null)), a instanceof Error && !(a.message in be) && (be[a.message] = !0, K(o), v("Failed %s type: %s", t, a.message), K(null));
}
}
}
var Ne = Array.isArray;
function ne(e) {
return Ne(e);
}
function Ve(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Ue(e) {
try {
return Ee(e), !1;
} catch {
return !0;
}
}
function Ee(e) {
return "" + e;
}
function Re(e) {
if (Ue(e))
return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ve(e)), Ee(e);
}
var V = R.ReactCurrentOwner, ze = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, _e, we, ae;
ae = {};
function He(e) {
if (G.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Be(e) {
if (G.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function qe(e, r) {
if (typeof e.ref == "string" && V.current && r && V.current.stateNode !== r) {
var t = S(V.current.type);
ae[t] || (v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', S(V.current.type), e.ref), ae[t] = !0);
}
}
function Je(e, r) {
{
var t = function() {
_e || (_e = !0, v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function Ge(e, r) {
{
var t = function() {
we || (we = !0, v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var Ke = function(e, r, t, n, o, s, i) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: b,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: i,
// Record the component responsible for creating this element.
_owner: s
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: o
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function Xe(e, r, t, n, o) {
{
var s, i = {}, a = null, p = null;
t !== void 0 && (Re(t), a = "" + t), Be(r) && (Re(r.key), a = "" + r.key), He(r) && (p = r.ref, qe(r, o));
for (s in r)
G.call(r, s) && !ze.hasOwnProperty(s) && (i[s] = r[s]);
if (e && e.defaultProps) {
var c = e.defaultProps;
for (s in c)
i[s] === void 0 && (i[s] = c[s]);
}
if (a || p) {
var d = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && Je(i, d), p && Ge(i, d);
}
return Ke(e, a, p, o, n, V.current, i);
}
}
var ie = R.ReactCurrentOwner, Se = R.ReactDebugCurrentFrame;
function $(e) {
if (e) {
var r = e._owner, t = J(e.type, e._source, r ? r.type : null);
Se.setExtraStackFrame(t);
} else
Se.setExtraStackFrame(null);
}
var oe;
oe = !1;
function ue(e) {
return typeof e == "object" && e !== null && e.$$typeof === b;
}
function Te() {
{
if (ie.current) {
var e = S(ie.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function Ze(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var xe = {};
function Qe(e) {
{
var r = Te();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function Oe(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = Qe(r);
if (xe[t])
return;
xe[t] = !0;
var n = "";
e && e._owner && e._owner !== ie.current && (n = " It was passed a child from " + S(e._owner.type) + "."), $(e), v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), $(null);
}
}
function Pe(e, r) {
{
if (typeof e != "object")
return;
if (ne(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
ue(n) && Oe(n, r);
}
else if (ue(e))
e._store && (e._store.validated = !0);
else if (e) {
var o = H(e);
if (typeof o == "function" && o !== e.entries)
for (var s = o.call(e), i; !(i = s.next()).done; )
ue(i.value) && Oe(i.value, r);
}
}
}
function er(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === u || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === g))
t = r.propTypes;
else
return;
if (t) {
var n = S(r);
Le(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !oe) {
oe = !0;
var o = S(r);
v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", o || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function rr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
$(e), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), $(null);
break;
}
}
e.ref !== null && ($(e), v("Invalid attribute `ref` supplied to `React.Fragment`."), $(null));
}
}
function Ce(e, r, t, n, o, s) {
{
var i = W(e);
if (!i) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var p = Ze(o);
p ? a += p : a += Te();
var c;
e === null ? c = "null" : ne(e) ? c = "array" : e !== void 0 && e.$$typeof === b ? (c = "<" + (S(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a);
}
var d = Xe(e, r, t, o, s);
if (d == null)
return d;
if (i) {
var y = r.children;
if (y !== void 0)
if (n)
if (ne(y)) {
for (var A = 0; A < y.length; A++)
Pe(y[A], e);
Object.freeze && Object.freeze(y);
} else
v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Pe(y, e);
}
return e === E ? rr(d) : er(d), d;
}
}
function tr(e, r, t) {
return Ce(e, r, t, !0);
}
function nr(e, r, t) {
return Ce(e, r, t, !1);
}
var ar = nr, ir = tr;
z.Fragment = E, z.jsx = ar, z.jsxs = ir;
}()), z;
}
(function(l) {
process.env.NODE_ENV === "production" ? l.exports = cr() : l.exports = fr();
})(lr);
function dr(l) {
return Promise.resolve().then(l);
}
function vr(l, b) {
let m;
return function(...E) {
m && clearTimeout(m), m = setTimeout(
() => {
typeof l == "function" && l.apply(null, E), clearTimeout(m);
},
b > 0 ? b : 100
);
};
}
function pr(l) {
const {
width: b,
height: m,
autoScale: E = !0,
bodyOverflowHidden: C = !0,
delay: D = 500
} = l;
let x;
const f = or(null), [u, O] = ur({
width: b,
height: m,
originalHeight: 0,
originalWidth: 0
}), h = {
box: {
overflow: "hidden",
backgroundSize: "100% 100%",
backgroundColor: "#000",
width: "100vw",
height: "100vh"
},
wrapper: {
transitionProperty: "all",
transitionTimingFunction: "cubic-bezier(0.4, 0, 0.2, 1)",
transitionDuration: "500ms",
position: "relative",
overflow: "hidden",
zIndex: 100,
transformOrigin: "left top"
}
};
let g;
function w() {
C && (x = document.body.style.overflow, document.body.style.overflow = "hidden");
}
function j() {
return new Promise((_) => {
dr(() => {
O({
...u,
originalWidth: window.screen.width,
originalHeight: window.screen.height
}), _();
});
});
}
function I() {
u.width && u.height ? (f.current.style.width = `${u.width}px`, f.current.style.height = `${u.height}px`) : (f.current.style.width = `${u.originalWidth}px`, f.current.style.height = `${u.originalHeight}px`);
}
function Z(_) {
if (!E)
return;
const Y = f.current.clientWidth, M = f.current.clientHeight, L = document.body.clientWidth, F = document.body.clientHeight;
f.current.style.transform = `scale(${_},${_})`;
let P = Math.max((L - Y * _) / 2, 0), W = Math.max((F - M * _) / 2, 0);
typeof l.autoScale == "object" && (!l.autoScale.x && (P = 0), !l.autoScale.y && (W = 0)), f.current.style.margin = `${W}px ${P}px`;
}
function H() {
const _ = document.body.clientWidth, Y = document.body.clientHeight, M = u.width || u.originalWidth, L = u.height || u.originalHeight, F = _ / +M, P = Y / +L;
if (l.fullScreen)
return f.current.style.transform = `scale(${F},${P})`, !1;
const W = Math.min(F, P);
Z(W);
}
const R = vr(async () => {
f.current && (await j(), I(), H());
}, D);
function v() {
g = new MutationObserver(() => {
R();
}), g.observe(f.current, {
attributes: !0,
attributeFilter: ["style"],
attributeOldValue: !0
});
}
async function Q() {
w(), v(), await j(), I(), H(), window.addEventListener("resize", R);
}
return sr(() => (Q(), () => {
g.disconnect(), window.removeEventListener("resize", R), C && (document.body.style.overflow = x);
}), []), /* @__PURE__ */ X.jsx(
"div",
{
style: { ...h.box, ...l.boxStyle },
className: "react-screen-box",
children: /* @__PURE__ */ X.jsx(
"div",
{
className: "screen-wrapper",
style: { ...h.wrapper, ...l.wrapperStyle },
ref: f,
children: l.children
}
)
}
);
}
export {
pr as default
};