pb-sxp-ui 1.15.23 → 1.15.25

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/pb-ui.js CHANGED
@@ -10207,34 +10207,36 @@
10207
10207
  const [isShow, setIsShow] = React.useState(false);
10208
10208
  const _a = style || {}, { lineClamp } = _a, textStyle = __rest(_a, ["lineClamp"]);
10209
10209
  const textLineClamp = Number(lineClamp || 2);
10210
- const multiRow = React.useRef(null);
10210
+ const realRef = React.useRef(null);
10211
+ const clampRef = React.useRef(null);
10211
10212
  const observerRef = React.useRef();
10212
10213
  const handleClick = () => {
10213
10214
  setIsShowMore(!isShowMore);
10214
10215
  };
10215
10216
  const checkOverflow = React.useCallback(() => {
10216
- if (!multiRow.current || !isPost)
10217
+ if (!realRef.current || !clampRef.current || !isPost || !text || isShowMore)
10217
10218
  return;
10218
- const lineHeight = parseInt(getComputedStyle(multiRow.current).lineHeight) || 20;
10219
- const maxHeight = lineHeight * textLineClamp;
10220
- // 添加1px容错,解决部分机型计算误差
10221
- setIsShow(multiRow.current.scrollHeight > maxHeight + 1);
10222
- }, [isPost, text, textLineClamp]);
10219
+ requestAnimationFrame(() => {
10220
+ const realHeight = realRef.current.getBoundingClientRect().height;
10221
+ const clampHeight = clampRef.current.getBoundingClientRect().height;
10222
+ const isActuallyClamped = realHeight > clampHeight + 1;
10223
+ setIsShow(isActuallyClamped);
10224
+ });
10225
+ }, [isPost, text, isShowMore]);
10226
+ // 增强版监听(同时监听字体加载)
10223
10227
  React.useEffect(() => {
10224
- if (!multiRow.current)
10228
+ if (!realRef.current)
10225
10229
  return;
10226
- // 使用ResizeObserver监听尺寸变化
10227
10230
  observerRef.current = new ResizeObserver(checkOverflow);
10228
- observerRef.current.observe(multiRow.current);
10229
- // 初始检查
10231
+ observerRef.current.observe(realRef.current);
10230
10232
  checkOverflow();
10231
10233
  return () => {
10232
10234
  var _a;
10233
10235
  (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
10234
10236
  };
10235
10237
  }, [checkOverflow]);
10236
- return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
10237
- React.createElement("div", { ref: multiRow, style: Object.assign(Object.assign({}, (!isShowMore &&
10238
+ return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)', overflow: 'hidden' }), hidden: !text || text === '' },
10239
+ React.createElement("div", { ref: clampRef, style: Object.assign(Object.assign({}, (!isShowMore &&
10238
10240
  isPost && {
10239
10241
  WebkitLineClamp: textLineClamp,
10240
10242
  lineClamp: textLineClamp,
@@ -10242,7 +10244,19 @@
10242
10244
  overflow: 'hidden',
10243
10245
  display: '-webkit-box',
10244
10246
  WebkitBoxOrient: 'vertical'
10245
- })), { wordBreak: 'break-word' }), dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10247
+ })), { 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) } }),
10248
+ React.createElement("div", { ref: realRef, style: {
10249
+ wordBreak: 'break-word',
10250
+ textRendering: 'geometricPrecision',
10251
+ fontKerning: 'none',
10252
+ textSizeAdjust: '100%',
10253
+ boxSizing: 'border-box',
10254
+ contain: 'content',
10255
+ visibility: 'hidden',
10256
+ position: 'absolute',
10257
+ opacity: 0,
10258
+ clipPath: 'inset(100%)'
10259
+ }, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10246
10260
  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: {
10247
10261
  __html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
10248
10262
  } }))));
@@ -20181,4 +20195,3 @@ Made in Italy` })));
20181
20195
  Object.defineProperty(exports, '__esModule', { value: true });
20182
20196
 
20183
20197
  }));
20184
- //# sourceMappingURL=pb-ui.js.map