1 |
- {"ast":null,"code":"\"use client\";\n\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport CSSMotion from 'rc-motion';\nimport raf from \"rc-util/es/raf\";\nimport { composeRef } from \"rc-util/es/ref\";\nimport { unstableSetRender } from '../../config-provider/UnstableContext';\nimport { TARGET_CLS } from './interface';\nimport { getTargetWaveColor } from './util';\nfunction validateNum(value) {\n return Number.isNaN(value) ? 0 : value;\n}\nconst WaveEffect = props => {\n const {\n className,\n target,\n component,\n registerUnmount\n } = props;\n const divRef = React.useRef(null);\n // ====================== Refs ======================\n const unmountRef = React.useRef(null);\n React.useEffect(() => {\n unmountRef.current = registerUnmount();\n }, []);\n // ===================== Effect =====================\n const [color, setWaveColor] = React.useState(null);\n const [borderRadius, setBorderRadius] = React.useState([]);\n const [left, setLeft] = React.useState(0);\n const [top, setTop] = React.useState(0);\n const [width, setWidth] = React.useState(0);\n const [height, setHeight] = React.useState(0);\n const [enabled, setEnabled] = React.useState(false);\n const waveStyle = {\n left,\n top,\n width,\n height,\n borderRadius: borderRadius.map(radius => `${radius}px`).join(' ')\n };\n if (color) {\n waveStyle['--wave-color'] = color;\n }\n function syncPos() {\n const nodeStyle = getComputedStyle(target);\n // Get wave color from target\n setWaveColor(getTargetWaveColor(target));\n const isStatic = nodeStyle.position === 'static';\n // Rect\n const {\n borderLeftWidth,\n borderTopWidth\n } = nodeStyle;\n setLeft(isStatic ? target.offsetLeft : validateNum(-parseFloat(borderLeftWidth)));\n setTop(isStatic ? target.offsetTop : validateNum(-parseFloat(borderTopWidth)));\n setWidth(target.offsetWidth);\n setHeight(target.offsetHeight);\n // Get border radius\n const {\n borderTopLeftRadius,\n borderTopRightRadius,\n borderBottomLeftRadius,\n borderBottomRightRadius\n } = nodeStyle;\n setBorderRadius([borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius].map(radius => validateNum(parseFloat(radius))));\n }\n React.useEffect(() => {\n if (target) {\n // We need delay to check position here\n // since UI may change after click\n const id = raf(() => {\n syncPos();\n setEnabled(true);\n });\n // Add resize observer to follow size\n let resizeObserver;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(syncPos);\n resizeObserver.observe(target);\n }\n return () => {\n raf.cancel(id);\n resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();\n };\n }\n }, []);\n if (!enabled) {\n return null;\n }\n const isSmallComponent = (component === 'Checkbox' || component === 'Radio') && (target === null || target === void 0 ? void 0 : target.classList.contains(TARGET_CLS));\n return /*#__PURE__*/React.createElement(CSSMotion, {\n visible: true,\n motionAppear: true,\n motionName: \"wave-motion\",\n motionDeadline: 5000,\n onAppearEnd: (_, event) => {\n var _a, _b;\n if (event.deadline || event.propertyName === 'opacity') {\n const holder = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;\n (_b = unmountRef.current) === null || _b === void 0 ? void 0 : _b.call(unmountRef).then(() => {\n holder === null || holder === void 0 ? void 0 : holder.remove();\n });\n }\n return false;\n }\n }, ({\n className: motionClassName\n }, ref) => (/*#__PURE__*/React.createElement(\"div\", {\n ref: composeRef(divRef, ref),\n className: classNames(className, motionClassName, {\n 'wave-quick': isSmallComponent\n }),\n style: waveStyle\n })));\n};\nconst showWaveEffect = (target, info) => {\n var _a;\n const {\n component\n } = info;\n // Skip for unchecked checkbox\n if (component === 'Checkbox' && !((_a = target.querySelector('input')) === null || _a === void 0 ? void 0 : _a.checked)) {\n return;\n }\n // Create holder\n const holder = document.createElement('div');\n holder.style.position = 'absolute';\n holder.style.left = '0px';\n holder.style.top = '0px';\n target === null || target === void 0 ? void 0 : target.insertBefore(holder, target === null || target === void 0 ? void 0 : target.firstChild);\n const reactRender = unstableSetRender();\n let unmountCallback = null;\n function registerUnmount() {\n return unmountCallback;\n }\n unmountCallback = reactRender(/*#__PURE__*/React.createElement(WaveEffect, Object.assign({}, info, {\n target: target,\n registerUnmount: registerUnmount\n })), holder);\n};\nexport default showWaveEffect;","map":{"version":3,"names":["React","classNames","CSSMotion","raf","composeRef","unstableSetRender","TARGET_CLS","getTargetWaveColor","validateNum","value","Number","isNaN","WaveEffect","props","className","target","component","registerUnmount","divRef","useRef","unmountRef","useEffect","current","color","setWaveColor","useState","borderRadius","setBorderRadius","left","setLeft","top","setTop","width","setWidth","height","setHeight","enabled","setEnabled","waveStyle","map","radius","join","syncPos","nodeStyle","getComputedStyle","isStatic","position","borderLeftWidth","borderTopWidth","offsetLeft","parseFloat","offsetTop","offsetWidth","offsetHeight","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","id","resizeObserver","ResizeObserver","observe","cancel","disconnect","isSmallComponent","classList","contains","createElement","visible","motionAppear","motionName","motionDeadline","onAppearEnd","_","event","_a","_b","deadline","propertyName","holder","parentElement","call","then","remove","motionClassName","ref","style","showWaveEffect","info","querySelector","checked","document","insertBefore","firstChild","reactRender","unmountCallback","Object","assign"],"sources":["/Users/max_liu/max_liu/company/tools_auto_pt/node_modules/antd/es/_util/wave/WaveEffect.js"],"sourcesContent":["\"use client\";\n\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport CSSMotion from 'rc-motion';\nimport raf from \"rc-util/es/raf\";\nimport { composeRef } from \"rc-util/es/ref\";\nimport { unstableSetRender } from '../../config-provider/UnstableContext';\nimport { TARGET_CLS } from './interface';\nimport { getTargetWaveColor } from './util';\nfunction validateNum(value) {\n return Number.isNaN(value) ? 0 : value;\n}\nconst WaveEffect = props => {\n const {\n className,\n target,\n component,\n registerUnmount\n } = props;\n const divRef = React.useRef(null);\n // ====================== Refs ======================\n const unmountRef = React.useRef(null);\n React.useEffect(() => {\n unmountRef.current = registerUnmount();\n }, []);\n // ===================== Effect =====================\n const [color, setWaveColor] = React.useState(null);\n const [borderRadius, setBorderRadius] = React.useState([]);\n const [left, setLeft] = React.useState(0);\n const [top, setTop] = React.useState(0);\n const [width, setWidth] = React.useState(0);\n const [height, setHeight] = React.useState(0);\n const [enabled, setEnabled] = React.useState(false);\n const waveStyle = {\n left,\n top,\n width,\n height,\n borderRadius: borderRadius.map(radius => `${radius}px`).join(' ')\n };\n if (color) {\n waveStyle['--wave-color'] = color;\n }\n function syncPos() {\n const nodeStyle = getComputedStyle(target);\n // Get wave color from target\n setWaveColor(getTargetWaveColor(target));\n const isStatic = nodeStyle.position === 'static';\n // Rect\n const {\n borderLeftWidth,\n borderTopWidth\n } = nodeStyle;\n setLeft(isStatic ? target.offsetLeft : validateNum(-parseFloat(borderLeftWidth)));\n setTop(isStatic ? target.offsetTop : validateNum(-parseFloat(borderTopWidth)));\n setWidth(target.offsetWidth);\n setHeight(target.offsetHeight);\n // Get border radius\n const {\n borderTopLeftRadius,\n borderTopRightRadius,\n borderBottomLeftRadius,\n borderBottomRightRadius\n } = nodeStyle;\n setBorderRadius([borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius].map(radius => validateNum(parseFloat(radius))));\n }\n React.useEffect(() => {\n if (target) {\n // We need delay to check position here\n // since UI may change after click\n const id = raf(() => {\n syncPos();\n setEnabled(true);\n });\n // Add resize observer to follow size\n let resizeObserver;\n if (typeof ResizeObserver !== 'undefined') {\n resizeObserver = new ResizeObserver(syncPos);\n resizeObserver.observe(target);\n }\n return () => {\n raf.cancel(id);\n resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();\n };\n }\n }, []);\n if (!enabled) {\n return null;\n }\n const isSmallComponent = (component === 'Checkbox' || component === 'Radio') && (target === null || target === void 0 ? void 0 : target.classList.contains(TARGET_CLS));\n return /*#__PURE__*/React.createElement(CSSMotion, {\n visible: true,\n motionAppear: true,\n motionName: \"wave-motion\",\n motionDeadline: 5000,\n onAppearEnd: (_, event) => {\n var _a, _b;\n if (event.deadline || event.propertyName === 'opacity') {\n const holder = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;\n (_b = unmountRef.current) === null || _b === void 0 ? void 0 : _b.call(unmountRef).then(() => {\n holder === null || holder === void 0 ? void 0 : holder.remove();\n });\n }\n return false;\n }\n }, ({\n className: motionClassName\n }, ref) => (/*#__PURE__*/React.createElement(\"div\", {\n ref: composeRef(divRef, ref),\n className: classNames(className, motionClassName, {\n 'wave-quick': isSmallComponent\n }),\n style: waveStyle\n })));\n};\nconst showWaveEffect = (target, info) => {\n var _a;\n const {\n component\n } = info;\n // Skip for unchecked checkbox\n if (component === 'Checkbox' && !((_a = target.querySelector('input')) === null || _a === void 0 ? void 0 : _a.checked)) {\n return;\n }\n // Create holder\n const holder = document.createElement('div');\n holder.style.position = 'absolute';\n holder.style.left = '0px';\n holder.style.top = '0px';\n target === null || target === void 0 ? void 0 : target.insertBefore(holder, target === null || target === void 0 ? void 0 : target.firstChild);\n const reactRender = unstableSetRender();\n let unmountCallback = null;\n function registerUnmount() {\n return unmountCallback;\n }\n unmountCallback = reactRender(/*#__PURE__*/React.createElement(WaveEffect, Object.assign({}, info, {\n target: target,\n registerUnmount: registerUnmount\n })), holder);\n};\nexport default showWaveEffect;"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,SAAS,MAAM,WAAW;AACjC,OAAOC,GAAG,MAAM,gBAAgB;AAChC,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,iBAAiB,QAAQ,uCAAuC;AACzE,SAASC,UAAU,QAAQ,aAAa;AACxC,SAASC,kBAAkB,QAAQ,QAAQ;AAC3C,SAASC,WAAWA,CAACC,KAAK,EAAE;EAC1B,OAAOC,MAAM,CAACC,KAAK,CAACF,KAAK,CAAC,GAAG,CAAC,GAAGA,KAAK;AACxC;AACA,MAAMG,UAAU,GAAGC,KAAK,IAAI;EAC1B,MAAM;IACJC,SAAS;IACTC,MAAM;IACNC,SAAS;IACTC;EACF,CAAC,GAAGJ,KAAK;EACT,MAAMK,MAAM,GAAGlB,KAAK,CAACmB,MAAM,CAAC,IAAI,CAAC;EACjC;EACA,MAAMC,UAAU,GAAG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