pb-sxp-ui 1.15.24 → 1.15.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10192,57 +10192,36 @@ const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldTex
10192
10192
  const [isShow, setIsShow] = useState(false);
10193
10193
  const _a = style || {}, { lineClamp } = _a, textStyle = __rest(_a, ["lineClamp"]);
10194
10194
  const textLineClamp = Number(lineClamp || 2);
10195
- const multiRow = useRef(null);
10196
- useRef();
10195
+ const realRef = useRef(null);
10196
+ const clampRef = useRef(null);
10197
+ const observerRef = useRef();
10197
10198
  const handleClick = () => {
10198
10199
  setIsShowMore(!isShowMore);
10199
10200
  };
10200
10201
  const checkOverflow = useCallback(() => {
10201
- if (!multiRow.current || !isPost || !text)
10202
+ if (!realRef.current || !clampRef.current || !isPost || !text || isShowMore)
10202
10203
  return;
10203
- // 强制同步布局(消除浏览器优化导致的误差)
10204
- const triggerReflow = (el) => el.offsetHeight;
10205
- // 分三步精确测量
10206
10204
  requestAnimationFrame(() => {
10207
- // 第一步:获取干净状态
10208
- const el = multiRow.current;
10209
- triggerReflow(el);
10210
- // 第二步:测量无约束状态的真实高度
10211
- const originalStyle = el.style.cssText;
10212
- el.style.webkitLineClamp = 'unset';
10213
- el.style.display = 'block';
10214
- triggerReflow(el);
10215
- const realHeight = el.getBoundingClientRect().height;
10216
- // 第三步:恢复约束状态
10217
- el.style.cssText = originalStyle;
10218
- triggerReflow(el);
10219
- const clampHeight = el.getBoundingClientRect().height;
10220
- // 精准比较(考虑亚像素渲染)
10205
+ const realHeight = realRef.current.getBoundingClientRect().height;
10206
+ const clampHeight = clampRef.current.getBoundingClientRect().height;
10221
10207
  const isActuallyClamped = realHeight > clampHeight + 1;
10222
- // 防抖处理
10223
- console.log('[精确测量]', { realHeight, clampHeight, isActuallyClamped });
10224
10208
  setIsShow(isActuallyClamped);
10225
10209
  });
10226
- }, [isPost, text, textLineClamp]);
10210
+ }, [isPost, text, isShowMore]);
10227
10211
  // 增强版监听(同时监听字体加载)
10228
10212
  useEffect(() => {
10229
- const el = multiRow.current;
10230
- if (!el)
10213
+ if (!realRef.current)
10231
10214
  return;
10232
- const fontCheck = () => {
10233
- document.fonts.ready.then(checkOverflow);
10215
+ observerRef.current = new ResizeObserver(checkOverflow);
10216
+ observerRef.current.observe(realRef.current);
10217
+ checkOverflow();
10218
+ return () => {
10219
+ var _a;
10220
+ (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
10234
10221
  };
10235
- const observer = new ResizeObserver((entries) => {
10236
- entries.forEach((entry) => {
10237
- if (entry.contentBoxSize) ;
10238
- });
10239
- });
10240
- fontCheck();
10241
- observer.observe(el);
10242
- return () => observer.disconnect();
10243
10222
  }, [checkOverflow]);
10244
- return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
10245
- React.createElement("div", { ref: multiRow, style: Object.assign(Object.assign({}, (!isShowMore &&
10223
+ return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)', overflow: 'hidden', position: 'relative' }), hidden: !text || text === '' },
10224
+ React.createElement("div", { ref: clampRef, style: Object.assign(Object.assign({}, (!isShowMore &&
10246
10225
  isPost && {
10247
10226
  WebkitLineClamp: textLineClamp,
10248
10227
  lineClamp: textLineClamp,
@@ -10251,6 +10230,19 @@ const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldTex
10251
10230
  display: '-webkit-box',
10252
10231
  WebkitBoxOrient: 'vertical'
10253
10232
  })), { wordBreak: 'break-word', textRendering: 'geometricPrecision', fontKerning: 'none', textSizeAdjust: '100%', boxSizing: 'border-box', contain: 'content' }), dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10233
+ React.createElement("div", { ref: realRef, style: {
10234
+ wordBreak: 'break-word',
10235
+ textRendering: 'geometricPrecision',
10236
+ fontKerning: 'none',
10237
+ textSizeAdjust: '100%',
10238
+ boxSizing: 'border-box',
10239
+ contain: 'content',
10240
+ visibility: 'hidden',
10241
+ position: 'absolute',
10242
+ opacity: 0,
10243
+ clipPath: 'inset(100%)',
10244
+ transform: 'translateX(-9999px)'
10245
+ }, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10254
10246
  text && isPost && isShow && (React.createElement("button", { "aria-label": isShowMore ? unfoldText || 'show less' : foldText || 'show more', style: { textDecoration: 'underline', cursor: 'pointer' }, onClick: onClick !== null && onClick !== void 0 ? onClick : handleClick, dangerouslySetInnerHTML: {
10255
10247
  __html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
10256
10248
  } }))));