158 lines
5.6 KiB
JavaScript
158 lines
5.6 KiB
JavaScript
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/_util/wave/WaveEffect.tsx
|
|
var WaveEffect_exports = {};
|
|
__export(WaveEffect_exports, {
|
|
default: () => WaveEffect_default
|
|
});
|
|
module.exports = __toCommonJS(WaveEffect_exports);
|
|
var import_classnames = __toESM(require("classnames"));
|
|
var import_rc_motion = __toESM(require("rc-motion"));
|
|
var import_render = require("rc-util/lib/React/render");
|
|
var import_raf = __toESM(require("rc-util/lib/raf"));
|
|
var React = __toESM(require("react"));
|
|
var import_util = require("./util");
|
|
var import_interface = require("./interface");
|
|
function validateNum(value) {
|
|
return Number.isNaN(value) ? 0 : value;
|
|
}
|
|
var WaveEffect = (props) => {
|
|
const { className, target, component } = props;
|
|
const divRef = React.useRef(null);
|
|
const [color, setWaveColor] = React.useState(null);
|
|
const [borderRadius, setBorderRadius] = React.useState([]);
|
|
const [left, setLeft] = React.useState(0);
|
|
const [top, setTop] = React.useState(0);
|
|
const [width, setWidth] = React.useState(0);
|
|
const [height, setHeight] = React.useState(0);
|
|
const [enabled, setEnabled] = React.useState(false);
|
|
const waveStyle = {
|
|
left,
|
|
top,
|
|
width,
|
|
height,
|
|
borderRadius: borderRadius.map((radius) => `${radius}px`).join(" ")
|
|
};
|
|
if (color) {
|
|
waveStyle["--wave-color"] = color;
|
|
}
|
|
function syncPos() {
|
|
const nodeStyle = getComputedStyle(target);
|
|
setWaveColor((0, import_util.getTargetWaveColor)(target));
|
|
const isStatic = nodeStyle.position === "static";
|
|
const { borderLeftWidth, borderTopWidth } = nodeStyle;
|
|
setLeft(isStatic ? target.offsetLeft : validateNum(-parseFloat(borderLeftWidth)));
|
|
setTop(isStatic ? target.offsetTop : validateNum(-parseFloat(borderTopWidth)));
|
|
setWidth(target.offsetWidth);
|
|
setHeight(target.offsetHeight);
|
|
const {
|
|
borderTopLeftRadius,
|
|
borderTopRightRadius,
|
|
borderBottomLeftRadius,
|
|
borderBottomRightRadius
|
|
} = nodeStyle;
|
|
setBorderRadius(
|
|
[
|
|
borderTopLeftRadius,
|
|
borderTopRightRadius,
|
|
borderBottomRightRadius,
|
|
borderBottomLeftRadius
|
|
].map((radius) => validateNum(parseFloat(radius)))
|
|
);
|
|
}
|
|
React.useEffect(() => {
|
|
if (target) {
|
|
const id = (0, import_raf.default)(() => {
|
|
syncPos();
|
|
setEnabled(true);
|
|
});
|
|
let resizeObserver;
|
|
if (typeof ResizeObserver !== "undefined") {
|
|
resizeObserver = new ResizeObserver(syncPos);
|
|
resizeObserver.observe(target);
|
|
}
|
|
return () => {
|
|
import_raf.default.cancel(id);
|
|
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
};
|
|
}
|
|
}, []);
|
|
if (!enabled) {
|
|
return null;
|
|
}
|
|
const isSmallComponent = (component === "Checkbox" || component === "Radio") && (target == null ? void 0 : target.classList.contains(import_interface.TARGET_CLS));
|
|
return /* @__PURE__ */ React.createElement(
|
|
import_rc_motion.default,
|
|
{
|
|
visible: true,
|
|
motionAppear: true,
|
|
motionName: "wave-motion",
|
|
motionDeadline: 5e3,
|
|
onAppearEnd: (_, event) => {
|
|
var _a;
|
|
if (event.deadline || event.propertyName === "opacity") {
|
|
const holder = (_a = divRef.current) == null ? void 0 : _a.parentElement;
|
|
(0, import_render.unmount)(holder).then(() => {
|
|
holder == null ? void 0 : holder.remove();
|
|
});
|
|
}
|
|
return false;
|
|
}
|
|
},
|
|
({ className: motionClassName }) => /* @__PURE__ */ React.createElement(
|
|
"div",
|
|
{
|
|
ref: divRef,
|
|
className: (0, import_classnames.default)(
|
|
className,
|
|
{
|
|
"wave-quick": isSmallComponent
|
|
},
|
|
motionClassName
|
|
),
|
|
style: waveStyle
|
|
}
|
|
)
|
|
);
|
|
};
|
|
var showWaveEffect = (target, info) => {
|
|
var _a;
|
|
const { component } = info;
|
|
if (component === "Checkbox" && !((_a = target.querySelector("input")) == null ? void 0 : _a.checked)) {
|
|
return;
|
|
}
|
|
const holder = document.createElement("div");
|
|
holder.style.position = "absolute";
|
|
holder.style.left = "0px";
|
|
holder.style.top = "0px";
|
|
target == null ? void 0 : target.insertBefore(holder, target == null ? void 0 : target.firstChild);
|
|
(0, import_render.render)(/* @__PURE__ */ React.createElement(WaveEffect, { ...info, target }), holder);
|
|
};
|
|
var WaveEffect_default = showWaveEffect;
|