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.cjs CHANGED
@@ -10214,57 +10214,36 @@ const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldTex
10214
10214
  const [isShow, setIsShow] = React.useState(false);
10215
10215
  const _a = style || {}, { lineClamp } = _a, textStyle = __rest(_a, ["lineClamp"]);
10216
10216
  const textLineClamp = Number(lineClamp || 2);
10217
- const multiRow = React.useRef(null);
10218
- React.useRef();
10217
+ const realRef = React.useRef(null);
10218
+ const clampRef = React.useRef(null);
10219
+ const observerRef = React.useRef();
10219
10220
  const handleClick = () => {
10220
10221
  setIsShowMore(!isShowMore);
10221
10222
  };
10222
10223
  const checkOverflow = React.useCallback(() => {
10223
- if (!multiRow.current || !isPost || !text)
10224
+ if (!realRef.current || !clampRef.current || !isPost || !text || isShowMore)
10224
10225
  return;
10225
- // 强制同步布局(消除浏览器优化导致的误差)
10226
- const triggerReflow = (el) => el.offsetHeight;
10227
- // 分三步精确测量
10228
10226
  requestAnimationFrame(() => {
10229
- // 第一步:获取干净状态
10230
- const el = multiRow.current;
10231
- triggerReflow(el);
10232
- // 第二步:测量无约束状态的真实高度
10233
- const originalStyle = el.style.cssText;
10234
- el.style.webkitLineClamp = 'unset';
10235
- el.style.display = 'block';
10236
- triggerReflow(el);
10237
- const realHeight = el.getBoundingClientRect().height;
10238
- // 第三步:恢复约束状态
10239
- el.style.cssText = originalStyle;
10240
- triggerReflow(el);
10241
- const clampHeight = el.getBoundingClientRect().height;
10242
- // 精准比较(考虑亚像素渲染)
10227
+ const realHeight = realRef.current.getBoundingClientRect().height;
10228
+ const clampHeight = clampRef.current.getBoundingClientRect().height;
10243
10229
  const isActuallyClamped = realHeight > clampHeight + 1;
10244
- // 防抖处理
10245
- console.log('[精确测量]', { realHeight, clampHeight, isActuallyClamped });
10246
10230
  setIsShow(isActuallyClamped);
10247
10231
  });
10248
- }, [isPost, text, textLineClamp]);
10232
+ }, [isPost, text, isShowMore]);
10249
10233
  // 增强版监听(同时监听字体加载)
10250
10234
  React.useEffect(() => {
10251
- const el = multiRow.current;
10252
- if (!el)
10235
+ if (!realRef.current)
10253
10236
  return;
10254
- const fontCheck = () => {
10255
- document.fonts.ready.then(checkOverflow);
10237
+ observerRef.current = new ResizeObserver(checkOverflow);
10238
+ observerRef.current.observe(realRef.current);
10239
+ checkOverflow();
10240
+ return () => {
10241
+ var _a;
10242
+ (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
10256
10243
  };
10257
- const observer = new ResizeObserver((entries) => {
10258
- entries.forEach((entry) => {
10259
- if (entry.contentBoxSize) ;
10260
- });
10261
- });
10262
- fontCheck();
10263
- observer.observe(el);
10264
- return () => observer.disconnect();
10265
10244
  }, [checkOverflow]);
10266
- return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
10267
- React.createElement("div", { ref: multiRow, style: Object.assign(Object.assign({}, (!isShowMore &&
10245
+ return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)', overflow: 'hidden', position: 'relative' }), hidden: !text || text === '' },
10246
+ React.createElement("div", { ref: clampRef, style: Object.assign(Object.assign({}, (!isShowMore &&
10268
10247
  isPost && {
10269
10248
  WebkitLineClamp: textLineClamp,
10270
10249
  lineClamp: textLineClamp,
@@ -10273,6 +10252,19 @@ const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldTex
10273
10252
  display: '-webkit-box',
10274
10253
  WebkitBoxOrient: 'vertical'
10275
10254
  })), { 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) } }),
10255
+ React.createElement("div", { ref: realRef, style: {
10256
+ wordBreak: 'break-word',
10257
+ textRendering: 'geometricPrecision',
10258
+ fontKerning: 'none',
10259
+ textSizeAdjust: '100%',
10260
+ boxSizing: 'border-box',
10261
+ contain: 'content',
10262
+ visibility: 'hidden',
10263
+ position: 'absolute',
10264
+ opacity: 0,
10265
+ clipPath: 'inset(100%)',
10266
+ transform: 'translateX(-9999px)'
10267
+ }, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10276
10268
  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: {
10277
10269
  __html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
10278
10270
  } }))));