PromoCursed/node_modules/.cache/babel-loader/1354443a672abc688034c30e92bf63b4e659441ecf14168814b92c19a1e77b28.json

1 line
27 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport toArray from \"rc-util/es/Children/toArray\";\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nconst MeasureText = /*#__PURE__*/React.forwardRef((_ref, ref) => {\n let {\n style,\n children\n } = _ref;\n const spanRef = React.useRef(null);\n React.useImperativeHandle(ref, () => ({\n isExceed: () => {\n const span = spanRef.current;\n return span.scrollHeight > span.clientHeight;\n },\n getHeight: () => spanRef.current.clientHeight\n }));\n return /*#__PURE__*/React.createElement(\"span\", {\n \"aria-hidden\": true,\n ref: spanRef,\n style: Object.assign({\n position: 'fixed',\n display: 'block',\n left: 0,\n top: 0,\n pointerEvents: 'none',\n backgroundColor: 'rgba(255, 0, 0, 0.65)'\n }, style)\n }, children);\n});\nfunction cuttable(node) {\n const type = typeof node;\n return type === 'string' || type === 'number';\n}\nfunction getNodesLen(nodeList) {\n let totalLen = 0;\n nodeList.forEach(node => {\n if (cuttable(node)) {\n totalLen += String(node).length;\n } else {\n totalLen += 1;\n }\n });\n return totalLen;\n}\nfunction sliceNodes(nodeList, len) {\n let currLen = 0;\n const currentNodeList = [];\n for (let i = 0; i < nodeList.length; i += 1) {\n // Match to return\n if (currLen === len) {\n return currentNodeList;\n }\n const node = nodeList[i];\n const canCut = cuttable(node);\n const nodeLen = canCut ? String(node).length : 1;\n const nextLen = currLen + nodeLen;\n // Exceed but current not which means we need cut this\n // This will not happen on validate ReactElement\n if (nextLen > len) {\n const restLen = len - currLen;\n currentNodeList.push(String(node).slice(0, restLen));\n return currentNodeList;\n }\n currentNodeList.push(node);\n currLen = nextLen;\n }\n return nodeList;\n}\n// Measure for the `text` is exceed the `rows` or not\nconst STATUS_MEASURE_NONE = 0;\nconst STATUS_MEASURE_PREPARE = 1;\nconst STATUS_MEASURE_START = 2;\nconst STATUS_MEASURE_NEED_ELLIPSIS = 3;\nconst STATUS_MEASURE_NO_NEED_ELLIPSIS = 4;\nconst lineClipStyle = {\n display: '-webkit-box',\n overflow: 'hidden',\n WebkitBoxOrient: 'vertical'\n};\nexport default function EllipsisMeasure(props) {\n const {\n enableMeasure,\n width,\n text,\n children,\n rows,\n expanded,\n miscDeps,\n onEllipsis\n } = props;\n const nodeList = React.useMemo(() => toArray(text), [text]);\n const nodeLen = React.useMemo(() => getNodesLen(nodeList), [text]);\n // ========================= Full Content =========================\n // Used for measure only, which means it's always render as no need ellipsis\n const fullContent = React.useMemo(() => children(nodeList, false), [text]);\n // ========================= Cut Content ==========================\n const [ellipsisCutIndex, setEllipsisCutIndex] = React.useState(null);\n const cutMidRef = React.useRef(null);\n // ========================= NeedEllipsis =========================\n const measureWhiteSpaceRef = React.useRef(null);\n const needEllipsisRef = React.useRef(null);\n // Measure for `rows-1` height, to avoid operation exceed the line height\n const descRowsEllipsisRef = React.useRef(null);\n const symbolRowEllipsisRef = React.useRef(null);\n const [canEllipsis, setCanEllipsis] = React.useState(false);\n const [needEllipsis, setNeedEllipsis] = React.useState(STATUS_MEASURE_NONE);\n const [ellipsisHeight, setEllipsisHeight] = React.useState(0);\n const [parentWhiteSpace, setParentWhiteSpace] = React.useState(null);\n // Trigger start measure\n useLayoutEffect(() => {\n if (enableMeasure && width && nodeLen) {\n setNeedEllipsis(STATUS_MEASURE_PREPARE);\n } else {\n setNeedEllipsis(STATUS_MEASURE_NONE);\n }\n }, [width, text, rows, enableMeasure, nodeList]);\n // Measure process\n useLayoutEffe