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 +29 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -37
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +6 -6
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +1 -1
- package/dist/pb-ui.js +29 -37
- package/dist/pb-ui.js.map +1 -1
- package/dist/pb-ui.min.js +6 -6
- package/dist/pb-ui.min.js.map +1 -1
- package/es/core/components/SxpPageRender/ExpandableText.js +28 -30
- package/lib/core/components/SxpPageRender/ExpandableText.js +28 -30
- package/package.json +1 -1
package/dist/pb-ui.js
CHANGED
@@ -10207,57 +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
|
10211
|
-
React.useRef();
|
10210
|
+
const realRef = React.useRef(null);
|
10211
|
+
const clampRef = React.useRef(null);
|
10212
|
+
const observerRef = React.useRef();
|
10212
10213
|
const handleClick = () => {
|
10213
10214
|
setIsShowMore(!isShowMore);
|
10214
10215
|
};
|
10215
10216
|
const checkOverflow = React.useCallback(() => {
|
10216
|
-
if (!
|
10217
|
+
if (!realRef.current || !clampRef.current || !isPost || !text || isShowMore)
|
10217
10218
|
return;
|
10218
|
-
// 强制同步布局(消除浏览器优化导致的误差)
|
10219
|
-
const triggerReflow = (el) => el.offsetHeight;
|
10220
|
-
// 分三步精确测量
|
10221
10219
|
requestAnimationFrame(() => {
|
10222
|
-
|
10223
|
-
const
|
10224
|
-
triggerReflow(el);
|
10225
|
-
// 第二步:测量无约束状态的真实高度
|
10226
|
-
const originalStyle = el.style.cssText;
|
10227
|
-
el.style.webkitLineClamp = 'unset';
|
10228
|
-
el.style.display = 'block';
|
10229
|
-
triggerReflow(el);
|
10230
|
-
const realHeight = el.getBoundingClientRect().height;
|
10231
|
-
// 第三步:恢复约束状态
|
10232
|
-
el.style.cssText = originalStyle;
|
10233
|
-
triggerReflow(el);
|
10234
|
-
const clampHeight = el.getBoundingClientRect().height;
|
10235
|
-
// 精准比较(考虑亚像素渲染)
|
10220
|
+
const realHeight = realRef.current.getBoundingClientRect().height;
|
10221
|
+
const clampHeight = clampRef.current.getBoundingClientRect().height;
|
10236
10222
|
const isActuallyClamped = realHeight > clampHeight + 1;
|
10237
|
-
// 防抖处理
|
10238
|
-
console.log('[精确测量]', { realHeight, clampHeight, isActuallyClamped });
|
10239
10223
|
setIsShow(isActuallyClamped);
|
10240
10224
|
});
|
10241
|
-
}, [isPost, text,
|
10225
|
+
}, [isPost, text, isShowMore]);
|
10242
10226
|
// 增强版监听(同时监听字体加载)
|
10243
10227
|
React.useEffect(() => {
|
10244
|
-
|
10245
|
-
if (!el)
|
10228
|
+
if (!realRef.current)
|
10246
10229
|
return;
|
10247
|
-
|
10248
|
-
|
10230
|
+
observerRef.current = new ResizeObserver(checkOverflow);
|
10231
|
+
observerRef.current.observe(realRef.current);
|
10232
|
+
checkOverflow();
|
10233
|
+
return () => {
|
10234
|
+
var _a;
|
10235
|
+
(_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
|
10249
10236
|
};
|
10250
|
-
const observer = new ResizeObserver((entries) => {
|
10251
|
-
entries.forEach((entry) => {
|
10252
|
-
if (entry.contentBoxSize) ;
|
10253
|
-
});
|
10254
|
-
});
|
10255
|
-
fontCheck();
|
10256
|
-
observer.observe(el);
|
10257
|
-
return () => observer.disconnect();
|
10258
10237
|
}, [checkOverflow]);
|
10259
|
-
return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
|
10260
|
-
React.createElement("div", { ref:
|
10238
|
+
return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)', overflow: 'hidden', position: 'relative' }), hidden: !text || text === '' },
|
10239
|
+
React.createElement("div", { ref: clampRef, style: Object.assign(Object.assign({}, (!isShowMore &&
|
10261
10240
|
isPost && {
|
10262
10241
|
WebkitLineClamp: textLineClamp,
|
10263
10242
|
lineClamp: textLineClamp,
|
@@ -10266,6 +10245,19 @@
|
|
10266
10245
|
display: '-webkit-box',
|
10267
10246
|
WebkitBoxOrient: 'vertical'
|
10268
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
|
+
transform: 'translateX(-9999px)'
|
10260
|
+
}, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
|
10269
10261
|
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: {
|
10270
10262
|
__html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
|
10271
10263
|
} }))));
|