1 line
30 KiB
JSON
1 line
30 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport { useEvent } from 'rc-util';\nimport scrollIntoView from 'scroll-into-view-if-needed';\nimport getScroll from '../_util/getScroll';\nimport scrollTo from '../_util/scrollTo';\nimport { devUseWarning } from '../_util/warning';\nimport Affix from '../affix';\nimport { ConfigContext } from '../config-provider';\nimport useCSSVarCls from '../config-provider/hooks/useCSSVarCls';\nimport AnchorLink from './AnchorLink';\nimport AnchorContext from './context';\nimport useStyle from './style';\nfunction getDefaultContainer() {\n return window;\n}\nfunction getOffsetTop(element, container) {\n if (!element.getClientRects().length) {\n return 0;\n }\n const rect = element.getBoundingClientRect();\n if (rect.width || rect.height) {\n if (container === window) {\n return rect.top - element.ownerDocument.documentElement.clientTop;\n }\n return rect.top - container.getBoundingClientRect().top;\n }\n return rect.top;\n}\nconst sharpMatcherRegex = /#([\\S ]+)$/;\nconst Anchor = props => {\n var _a;\n const {\n rootClassName,\n prefixCls: customPrefixCls,\n className,\n style,\n offsetTop,\n affix = true,\n showInkInFixed = false,\n children,\n items,\n direction: anchorDirection = 'vertical',\n bounds,\n targetOffset,\n onClick,\n onChange,\n getContainer,\n getCurrentAnchor,\n replace\n } = props;\n // =================== Warning =====================\n if (process.env.NODE_ENV !== 'production') {\n const warning = devUseWarning('Anchor');\n warning.deprecated(!children, 'Anchor children', 'items');\n process.env.NODE_ENV !== \"production\" ? warning(!(anchorDirection === 'horizontal' && (items === null || items === void 0 ? void 0 : items.some(n => 'children' in n))), 'usage', '`Anchor items#children` is not supported when `Anchor` direction is horizontal.') : void 0;\n }\n const [links, setLinks] = React.useState([]);\n const [activeLink, setActiveLink] = React.useState(null);\n const activeLinkRef = React.useRef(activeLink);\n const wrapperRef = React.useRef(null);\n const spanLinkNode = React.useRef(null);\n const animating = React.useRef(false);\n const {\n direction,\n anchor,\n getTargetContainer,\n getPrefixCls\n } = React.useContext(ConfigContext);\n const prefixCls = getPrefixCls('anchor', customPrefixCls);\n const rootCls = useCSSVarCls(prefixCls);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);\n const getCurrentContainer = (_a = getContainer !== null && getContainer !== void 0 ? getContainer : getTargetContainer) !== null && _a !== void 0 ? _a : getDefaultContainer;\n const dependencyListItem = JSON.stringify(links);\n const registerLink = useEvent(link => {\n if (!links.includes(link)) {\n setLinks(prev => [].concat(_toConsumableArray(prev), [link]));\n }\n });\n const unregisterLink = useEvent(link => {\n if (links.includes(link)) {\n setLinks(prev => prev.filter(i => i !== link));\n }\n });\n const updateInk = () => {\n var _a;\n const linkNode = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`.${prefixCls}-link-title-active`);\n if (linkNode && spanLinkNode.current) {\n const {\n style: inkStyle\n } = spanLinkNode.current;\n const horizontalAnchor = anchorDirection === 'horizontal';\n inkStyle.top = horizontalAnchor ? '' : `${linkNode.offsetTop + linkNode.clientHeight / 2}px`;\n inkStyle.height = horizontalAnchor ? '' : `${linkNode.clientHeight}px`;\n inkStyle.left = horizontalAnchor ? `${linkNode.offsetLeft}px` : '';\n inkStyle.width = horizontalAnchor ? `${linkNode.clientWidth}px` : '';\n if (horizontalAnchor) {\n scrollIntoView(linkNode, {\n scrollMode: 'if-needed',\n block: 'nearest'\n });\n }\n }\n };\n const getInternalCurrent
|