text-overflow-processor-react
Version:
10 lines • 16.9 kB
JavaScript
module.exports=function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t){e.exports=require("react")},function(e,t,n){"use strict";e.exports=n(2)},function(e,t,n){"use strict";
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var i=n(0),o=Symbol.for("react.element"),s=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,l=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var i,s={},c=null,a=null;for(i in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(a=t.ref),t)r.call(t,i)&&!u.hasOwnProperty(i)&&(s[i]=t[i]);if(e&&e.defaultProps)for(i in t=e.defaultProps)void 0===s[i]&&(s[i]=t[i]);return{$$typeof:o,type:e,key:c,ref:a,props:s,_owner:l.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return j}));var i=n(1),o=n(0),s=Object.defineProperty,r=(e,t,n)=>((e,t,n)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),l=new Map,u=new WeakMap,c=0,a=void 0;function d(e){return Object.keys(e).sort().filter(t=>void 0!==e[t]).map(t=>{return`${t}_${"root"===t?(n=e.root,n?(u.has(n)||(c+=1,u.set(n,c.toString())),u.get(n)):"0"):e[t]}`;var n}).toString()}function f(e,t,n={},i=a){if(void 0===window.IntersectionObserver&&void 0!==i){const o=e.getBoundingClientRect();return t(i,{isIntersecting:i,target:e,intersectionRatio:"number"==typeof n.threshold?n.threshold:0,time:0,boundingClientRect:o,intersectionRect:o,rootBounds:o}),()=>{}}const{id:o,observer:s,elements:r}=function(e){const t=d(e);let n=l.get(t);if(!n){const i=new Map;let o;const s=new IntersectionObserver(t=>{t.forEach(t=>{var n;const s=t.isIntersecting&&o.some(e=>t.intersectionRatio>=e);e.trackVisibility&&void 0===t.isVisible&&(t.isVisible=s),null==(n=i.get(t.target))||n.forEach(e=>{e(s,t)})})},e);o=s.thresholds||(Array.isArray(e.threshold)?e.threshold:[e.threshold||0]),n={id:t,observer:s,elements:i},l.set(t,n)}return n}(n),u=r.get(e)||[];return r.has(e)||r.set(e,u),u.push(t),s.observe(e),function(){u.splice(u.indexOf(t),1),0===u.length&&(r.delete(e),s.unobserve(e)),0===r.size&&(s.disconnect(),l.delete(o))}}o.Component;var h=function(e,t,n,i,o,s,r,l,u){void 0===i&&(i=12),void 0===o&&(o=400),void 0===s&&(s=!0),void 0===r&&(r=""),void 0===l&&(l=""),void 0===u&&(u=null);var c="",a="",d="",f=0,h=0,p=0,v=!1;if(!e||n<i||"string"!=typeof e)return e;var b=e.split(""),O=document.createElement("span"),y="position:absolute;visibility:hidden;padding:0;white-space:nowrap;overflow-x:auto;font-size:".concat(i,"px;font-weight:").concat(o,";");O.style.cssText=y+r,O.setAttribute("class",l),u?u.appendChild(O):document.body.appendChild(O);for(var S=0,m=b.length;S<m;S++){var g=b[S],w="\n"===g,x="\n"===b[S-1],j=0;a=d,d+=g,O.innerHTML=d,w&&(h+=j=x?t:t-f%t);var N=O.offsetWidth+h;if(w&&N===n&&(v=!0),N>n){if(w&&!v){v=!0,p=j-(N-n),f=n,c=d;continue}if(s){O.innerHTML="...";var C=O.offsetWidth,J="...";if(p>=C)J=a.slice(0,-1)+"...";else for(var M=0,k=a.split("").length;M<k;M++){var T=-(M+1),L=a.slice(T);if(O.innerHTML=L,O.offsetWidth+p>=C){J=a.slice(0,T)+"...";break}}c=J}else c=a;break}p=w?j:0,f=N,c=d}return u?u.removeChild(O):document.body.removeChild(O),c},p=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t="";for(var n in e)e[n]&&(t+="".concat(n," "));return t.trim()},v=function(e){return"string"==typeof e?e:""};var b=function(e){var t=e.text,n=e.reRenderDependencies,i=e.type,s=e.className,r=e.style,l=e.buttonClassName,u=e.buttonStyle,c=e.isClickOriginalEvent,a=e.isDefaultFold,d=e.unfoldButtonText,f=e.foldButtonText,h=e.isShowAllContent,p=e.isMustButton,b=e.isMustNoButton,O=e.lineHeight,y=e.isRenderShowAllDOM,S=e.ellipsisLineClamp,m=e.isJsComputed,g=e.fontSize,w=e.fontClassName,x=e.fontStyle,j=e.textEndSlot,N=e.extraOccupiedW,C=e.shadowFoldShowH,J=e.shadowFoldButtonPlacement,M=e.isShadowLayer,k=e.shadowClassName,T=e.shadowStyle,L=e.isListenVisible;return Object(o.useMemo)((function(){if(!Array.isArray(n))return[t];if(Array.isArray(n)&&!n.length)return[];var e=[];switch(!0){case n.includes("all"):e=[t,i,s,null===JSON||void 0===JSON?void 0:JSON.stringify(r),l,null===JSON||void 0===JSON?void 0:JSON.stringify(u),c,a,v(d),v(f),h,p,b,O,y,S,m,g,w,null===JSON||void 0===JSON?void 0:JSON.stringify(x),v(j),N,C,J,M,k,null===JSON||void 0===JSON?void 0:JSON.stringify(T),L];break;default:n.includes("text")&&e.push(t),n.includes("type")&&e.push(i),n.includes("className")&&e.push(s),n.includes("style")&&e.push(null===JSON||void 0===JSON?void 0:JSON.stringify(r)),n.includes("buttonClassName")&&e.push(l),n.includes("buttonStyle")&&e.push(null===JSON||void 0===JSON?void 0:JSON.stringify(u)),n.includes("isClickOriginalEvent")&&e.push(c),n.includes("isDefaultFold")&&e.push(a),n.includes("unfoldButtonText")&&e.push(v(d)),n.includes("foldButtonText")&&e.push(v(f)),n.includes("isShowAllContent")&&e.push(h),n.includes("isMustButton")&&e.push(p),n.includes("isMustNoButton")&&e.push(b),n.includes("lineHeight")&&e.push(O),n.includes("isRenderShowAllDOM")&&e.push(y),n.includes("ellipsisLineClamp")&&e.push(S),n.includes("isJsComputed")&&e.push(m),n.includes("fontSize")&&e.push(g),n.includes("fontClassName")&&e.push(w),n.includes("fontStyle")&&e.push(null===JSON||void 0===JSON?void 0:JSON.stringify(x)),n.includes("textEndSlot")&&e.push(v(j)),n.includes("extraOccupiedW")&&e.push(N),n.includes("shadowFoldShowH")&&e.push(C),n.includes("shadowFoldButtonPlacement")&&e.push(J),n.includes("isShadowLayer")&&e.push(M),n.includes("shadowClassName")&&e.push(k),n.includes("shadowStyle")&&e.push(null===JSON||void 0===JSON?void 0:JSON.stringify(T)),n.includes("isListenVisible")&&e.push(L)}return e}),[null===JSON||void 0===JSON?void 0:JSON.stringify(n)])},O=["ellipsis","shadow"],y={ellipsisLineClamp:2,isJsComputed:!1,renderToString:null,fontSize:12,fontClassName:"",fontStyle:{},textEndSlot:null,extraOccupiedW:0},S={shadowFoldShowH:76,shadowFoldButtonPlacement:"outer",isShadowLayer:!0,shadowClassName:"",shadowStyle:{}},m={reRenderDependencies:["text"],type:"ellipsis",ellipsisOption:y,shadowOption:S,buttonClassName:"",buttonStyle:{},isClickOriginalEvent:!1,isDefaultFold:!0,unfoldButtonText:"Show Less",foldButtonText:"Show All",isShowAllContent:!1,isMustButton:!1,isMustNoButton:!1,lineHeight:24,isRenderShowAllDOM:!1,isListenVisible:!1},g=["font-size","font-weight","font-style","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-stretch","font-size-adjust","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","initial-letter","inline-size","line-height","line-height-step","letter-spacing","text-transform","text-indent","text-combine-upright","text-emphasis","text-emphasis-position","text-emphasis-style","text-orientation","text-rendering","text-size-adjust","word-spacing"],w=["font-size","letter-spacing","word-spacing","text-indent","line-height-step","inline-size"],x=function(){return(x=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var j=Object(o.memo)((function(e){var t,n,s=e.text,r=void 0===s?"":s,l=e.className,u=void 0===l?"":l,c=e.style,a=void 0===c?{}:c,d=e.onClick,j=void 0===d?null:d,N=e.onFoldChange,C=void 0===N?null:N,J=e.option,M=(void 0===J?m:J)||m,k=M.reRenderDependencies,T=void 0===k?["text"]:k,L=M.type,B=void 0===L?"ellipsis":L,R=M.ellipsisOption,_=void 0===R?y:R,E=M.shadowOption,A=void 0===E?S:E,H=M.buttonClassName,F=void 0===H?"":H,D=M.buttonStyle,V=void 0===D?{}:D,z=M.isClickOriginalEvent,P=void 0!==z&&z,W=M.isDefaultFold,I=void 0===W||W,$=M.unfoldButtonText,U=void 0===$?"Show Less":$,q=M.foldButtonText,Y=void 0===q?"Show All":q,Z=M.isShowAllContent,G=void 0!==Z&&Z,K=M.isMustButton,Q=void 0!==K&&K,X=M.isMustNoButton,ee=void 0!==X&&X,te=M.lineHeight,ne=void 0===te?24:te,ie=M.isRenderShowAllDOM,oe=void 0!==ie&&ie,se=M.isListenVisible,re=void 0!==se&&se,le=_||y,ue=le.ellipsisLineClamp,ce=void 0===ue?2:ue,ae=le.isJsComputed,de=void 0!==ae&&ae,fe=le.renderToString,he=void 0===fe?null:fe,pe=le.fontSize,ve=void 0===pe?12:pe,be=le.fontClassName,Oe=void 0===be?"":be,ye=le.fontStyle,Se=void 0===ye?{}:ye,me=le.textEndSlot,ge=void 0===me?null:me,we=le.extraOccupiedW,xe=void 0===we?0:we,je=A||S,Ne=je.shadowFoldShowH,Ce=void 0===Ne?76:Ne,Je=je.shadowFoldButtonPlacement,Me=void 0===Je?"outer":Je,ke=je.isShadowLayer,Te=void 0===ke||ke,Le=je.shadowClassName,Be=void 0===Le?"":Le,Re=je.shadowStyle,_e=void 0===Re?{}:Re,Ee=Object(o.useState)(!0),Ae=Ee[0],He=Ee[1],Fe=Object(o.useState)(!0),De=Fe[0],Ve=Fe[1],ze=Object(o.useState)(!1),Pe=ze[0],We=ze[1],Ie=Object(o.useState)(!1),$e=Ie[0],Ue=Ie[1],qe=Object(o.useState)(0),Ye=qe[0],Ze=qe[1],Ge=Object(o.useRef)(null),Ke=Object(o.useRef)(null),Qe=Object(o.useRef)(null),Xe=Object(o.useRef)(76),et=Object(o.useState)(0),tt=et[0],nt=et[1],it=Object(o.useState)(0),ot=it[0],st=it[1],rt=Object(o.useRef)({finalText:"",isFold:!0}),lt=function({threshold:e,delay:t,trackVisibility:n,rootMargin:i,root:s,triggerOnce:r,skip:l,initialInView:u,fallbackInView:c,onChange:a}={}){var d;const[h,p]=o.useState(null),v=o.useRef(a),[b,O]=o.useState({inView:!!u,entry:void 0});v.current=a,o.useEffect(()=>{if(l||!h)return;let o;return o=f(h,(e,t)=>{O({inView:e,entry:t}),v.current&&v.current(e,t),t.isIntersecting&&r&&o&&(o(),o=void 0)},{root:s,rootMargin:i,threshold:e,trackVisibility:n,delay:t},c),()=>{o&&o()}},[Array.isArray(e)?e.toString():e,h,s,i,r,l,n,c,t]);const y=null==(d=b.entry)?void 0:d.target,S=o.useRef(void 0);h||!y||r||l||S.current===y||(S.current=y,O({inView:!!u,entry:void 0}));const m=[p,b.inView,b.entry];return m.ref=m[0],m.inView=m[1],m.entry=m[2],m}({threshold:.1,skip:!re}),ut=lt.ref,ct=lt.inView,at=Object(o.useMemo)((function(){var e="";if(Se&&"[object Object]"===Object.prototype.toString.call(Se)&&"{}"!==(null===JSON||void 0===JSON?void 0:JSON.stringify(Se))){var t=new RegExp("[A-Z]","g");for(var n in Se){var i=n.replaceAll(t,(function(e){return"-"+e.toLowerCase()})),o=Se[n];if(g.includes(i)){var s=w.includes(i)&&"number"==typeof o;e+="".concat(i,":").concat(o).concat(s?"px":"",";")}}}return e}),[null===JSON||void 0===JSON?void 0:JSON.stringify(Se)]),dt=Object(o.useMemo)((function(){var e="",t=!1;if(tt&&de){var n=tt*ce,o=document.createElement("span");o.style.cssText="position:absolute;visibility:hidden;",o.innerHTML="".concat(Y&&(null==he?void 0:he(Object(i.jsx)(i.Fragment,{children:Y})))||""),Ke.current?Ke.current.appendChild(o):document.body.appendChild(o);var s=o.offsetWidth||0;Ke.current?Ke.current.removeChild(o):document.body.removeChild(o);var l=h(r,tt,n-xe,ve,400,!0,at,Oe,Ke.current),u=n-s;if(t=l.endsWith("..."))if(!Y&&!Q||ee)e=l;else e=h(r,tt,u-xe,ve,400,!0,at,Oe,Ke.current);else if(Y&&Q&&!ee){var c=h(r,tt,u-xe,ve,400,!0,at,Oe,Ke.current);e=(t=c.endsWith("..."))?c:r}else e=r}return Pe&&!De&&t||(de&&(Ve(t),!Q&&!ee&&We(t),Q&&We(!0),ee&&We(!1)),rt.current={finalText:e,isFold:t}),rt.current}),[r,tt,ot,ce,v(Y),ve,at,Oe,Q,ee,de,xe]),ft=Object(o.useMemo)((function(){return"ellipsis"===B&&Pe&&De&&!de}),[B,Pe,De,de]),ht=Object(o.useMemo)((function(){return Te&&Pe&&De}),[Te,Pe,De]),pt=Object(o.useMemo)((function(){return De?Y:U}),[De,v(U),v(Y)]),vt=Object(o.useMemo)((function(){var e={display:Pe?"inline-block":"none",lineHeight:ne+"px"};return"[object Object]"!==Object.prototype.toString.call(V)?(console.error("buttonStyle格式不正确!"),e):x(x({},e),V||{})}),[Pe,ne,null===JSON||void 0===JSON?void 0:JSON.stringify(V)]),bt=Object(o.useMemo)((function(){return ee&&De&&ge&&Object(i.jsx)("span",x({className:"click-btn",style:{display:"inline-block",lineHeight:ne+"px"}},{children:ge}))}),[ee,De,v(ge),ne]),Ot=Object(o.useMemo)((function(){var e={top:"inner"===Me&&De?0:Ce-20};return ht&&Object(i.jsx)("span",{className:"shadow ".concat(Be),style:x(x({},e),_e||{})})}),[De,ht,Me,Ce,Be,null===JSON||void 0===JSON?void 0:JSON.stringify(_e)]),yt=Object(o.useCallback)((function(){var e,t,n,i,o=null===(e=Qe.current)||void 0===e?void 0:e.childNodes,s=0;if(o)for(var r=0,l=o.length;r<l;r++){var u=o[r];s+=(null==u?void 0:u.offsetHeight)||0}var c="shadow"===B&&(null===(t=Qe.current)||void 0===t?void 0:t.offsetHeight)>Xe.current,a=(null===(n=Qe.current)||void 0===n?void 0:n.offsetHeight)>(null===(i=Ke.current)||void 0===i?void 0:i.clientHeight);return s?c&&s>Xe.current||a:c||a}),[]),St=Object(o.useCallback)((function(){Ze(Date.now())}),[]),mt=Object(o.useCallback)((function(e){Pe&&!De&&de&&Ke.current&&st(Date.now()),j&&j(e,De),j&&P&&Ve(!De),j||Ve(!De)}),[De,P,Pe,de]);return Object(o.useEffect)((function(){!function(){if(B&&O.includes(B)){if(G)return We(!!Q),void Ve(!1);Xe.current=Ce,de||(yt()?(Ve(!!I),We(!0)):(Ve(!1),We(!1))),Q&&We(!0),ee&&We(!1),de&&Ke.current&&nt(Ke.current.getBoundingClientRect().width||0),He(!1)}else console.error("文案处理类型type不在可选范围!")}()}),b({text:r,reRenderDependencies:T,type:B,className:u,style:a,buttonClassName:F,buttonStyle:V,isClickOriginalEvent:P,isDefaultFold:I,unfoldButtonText:U,foldButtonText:Y,isShowAllContent:G,isMustButton:Q,isMustNoButton:ee,lineHeight:ne,isRenderShowAllDOM:oe,ellipsisLineClamp:ce,isJsComputed:de,fontSize:ve,fontClassName:Oe,fontStyle:Se,textEndSlot:ge,extraOccupiedW:xe,shadowFoldShowH:Ce,shadowFoldButtonPlacement:Me,isShadowLayer:Te,shadowClassName:Be,shadowStyle:_e,isListenVisible:re})),Object(o.useEffect)((function(){null==C||C(De,Ae)}),[De,Ae]),Object(o.useEffect)((function(){return window.addEventListener("resize",St),function(){window.removeEventListener("resize",St)}}),[]),Object(o.useEffect)((function(){var e;Ye&&!G&&(null===(e=Ke.current)||void 0===e?void 0:e.clientHeight)&&(Ue(!0),Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout((function(){if(de&&Ke.current)nt(Ke.current.getBoundingClientRect().width||0);else{var e=yt();Pe&&!De&&e||(!Q&&!ee&&We(e),Ve(e))}Ue(!1),clearTimeout(Ge.current),Ge.current=null}),200))}),[Ye,ct]),Object(i.jsxs)("section",x({className:"text-overflow-processor-content ".concat(u),style:a,ref:ut},{children:[oe&&Object(i.jsx)("p",{className:"all-text text-overflow-processor-off",style:{display:"none"},dangerouslySetInnerHTML:{__html:r}}),Object(i.jsxs)("p",x({ref:Ke,className:p({"text-overflow-processor-on":!0,"p-shadow-info":"shadow"===B,"p-ellipsis-info":"ellipsis"===B,"text-show-less":De&&"shadow"!==B,"text-show-all":!De}),style:{display:de?"inline-block":"ellipsis"===B&&$e?"-webkit-box":"",WebkitLineClamp:ce,lineHeight:ne+"px",textAlign:ft?"justify":"inherit"}},{children:["shadow"===B&&Object(i.jsxs)(i.Fragment,{children:[Object(i.jsx)("span",{ref:Qe,className:p({text:!0,"text-show-btn-box":Pe,"text-show-all-box":!De}),style:{height:!De||$e||Ae?"auto":Ce},dangerouslySetInnerHTML:{__html:r}}),!$e&&Object(i.jsxs)(i.Fragment,{children:[("outer"===Me||!De)&&Ot,Object(i.jsxs)("span",x({className:p((t={"click-btn":!0,"click-btn-inner":"inner"===Me&&De},t[F]=!!F,t)),style:vt},{children:["inner"===Me&&De&&Ot,Object(i.jsx)("label",x({className:"click-btn-label",onClick:mt},{children:pt}))]}))]})]}),"ellipsis"===B?Object(i.jsxs)(i.Fragment,{children:[ee&&!ge||!Pe||Object(i.jsx)("i",{className:"click-btn-before",style:{height:"calc(100% - ".concat(ne,"px)")}}),Object(i.jsxs)("span",x({className:p((n={"click-btn":!0},n[F]=!!F,n)),style:vt},{children:[ge&&De&&ge,!$e&&Object(i.jsx)("label",x({onClick:mt},{children:pt}))]})),bt,Object(i.jsxs)("span",x({ref:Qe,className:"text-box"},{children:[Object(i.jsx)("span",{className:"text",dangerouslySetInnerHTML:{__html:de&&De?dt.finalText||"":r}}),ge&&!De&&ge]}))]}):null]}))]}))}))}]);