react-wrap-balancer
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -39,3 +39,2 @@ import React from 'react'; | ||
nonce?: string; | ||
children?: React.ReactNode; | ||
} | ||
@@ -56,4 +55,4 @@ type BalancerProps<ElementType extends React.ElementType> = BalancerOwnProps<ElementType> & Omit<React.ComponentPropsWithoutRef<ElementType>, keyof BalancerOwnProps>; | ||
}>; | ||
declare const Balancer: <ElementType extends React.ElementType<any> = React.ElementType<any>>({ ratio, preferNative, nonce, children, ...props }: BalancerProps<ElementType>) => JSX.Element; | ||
declare const Balancer: React.ForwardRefExoticComponent<Omit<BalancerProps<React.ElementType<any>>, "ref"> & React.RefAttributes<unknown>>; | ||
export { Balancer, Provider, Balancer as default }; | ||
export { Balancer, BalancerOwnProps, Provider, Balancer as default }; |
"use client" | ||
var w=Object.create;var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var t in n)m(e,t,{get:n[t],enumerable:!0})},_=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of M(n))!W.call(e,o)&&o!==t&&m(e,o,{get:()=>n[o],enumerable:!(r=I(n,o))||r.enumerable});return e};var R=(e,n,t)=>(t=e!=null?w(P(e)):{},_(n||!e||!e.__esModule?m(t,"default",{value:e,enumerable:!0}):t,e)),L=e=>_(m({},"__esModule",{value:!0}),e);var K={};$(K,{Balancer:()=>O,Provider:()=>C,default:()=>H});module.exports=L(K);var l=R(require("react"));var u=R(require("react")),b=typeof window=="undefined",y=b?u.default.useEffect:u.default.useLayoutEffect,Y=0,v=()=>++Y,S=!1;function A(){let[e,n]=u.default.useState(S?v:void 0);return y(()=>{e===void 0&&n(v()),S=!0},[]),e===void 0?e:`rwb-${e.toString(32)}`}function T(){return u.default.useMemo(()=>"useId"in u.default?u.default.useId:A,[])()}var E="__wrap_b",d="__wrap_n",g="__wrap_o",h=(e,n,t)=>{t=t||document.querySelector(`[data-br="${e}"]`);let r=t.parentElement,o=f=>t.style.maxWidth=f+"px";t.style.maxWidth="";let c=r.clientWidth,a=r.clientHeight,s=c/2-.25,i=c+.5,p;if(c){for(o(s),s=Math.max(t.scrollWidth,s);s+1<i;)p=Math.round((s+i)/2),o(p),r.clientHeight===a?i=p:s=p;o(i*n+c*(1-n))}t.__wrap_o||(typeof ResizeObserver!="undefined"?(t.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+t.dataset.brr,t)})).observe(r):process.env.NODE_ENV==="development"&&console.warn("The browser you are using does not support the ResizeObserver API. Please consider add polyfill for this API to avoid potential layout shifts or upgrade your browser. Read more: https://github.com/shuding/react-wrap-balancer#browser-support-information"))},N=h.toString(),V='(self.CSS&&CSS.supports("text-wrap","balance")?1:2)',x=(e,n,t="")=>(t&&(t=`self.${d}!=1&&${t}`),l.default.createElement("script",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:(e?"":`self.${d}=self.${d}||${V};self.${E}=${N};`)+t},nonce:n})),B=l.default.createContext({preferNative:!0,hasProvider:!1}),C=({preferNative:e=!0,nonce:n,children:t})=>{let r=l.default.useMemo(()=>({preferNative:e,hasProvider:!0}),[e]);return l.default.createElement(B.Provider,{value:r},x(!1,n),t)},O=({ratio:e=1,preferNative:n,nonce:t,children:r,...o})=>{let c=T(),a=l.default.useRef(),s=l.default.useContext(B),i=n!=null?n:s.preferNative,p=o.as||"span";return y(()=>{i&&self[d]===1||a.current&&(self[E]=h)(0,e,a.current)},[r,i,e]),y(()=>{if(!(i&&self[d]===1))return()=>{if(!a.current)return;let f=a.current[g];f&&(f.disconnect(),delete a.current[g])}},[i]),process.env.NODE_ENV==="development"&&r&&!Array.isArray(r)&&typeof r=="object"&&"type"in r&&typeof r.type=="string"&&r.type!=="span"&&console.warn(`<Balancer> should not wrap <${r.type}> inside. Instead, it should directly wrap text or inline nodes. | ||
var P=Object.create;var m=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var Y=(e,n)=>{for(var t in n)m(e,t,{get:n[t],enumerable:!0})},v=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of W(n))!L.call(e,o)&&o!==t&&m(e,o,{get:()=>n[o],enumerable:!(r=M(n,o))||r.enumerable});return e};var R=(e,n,t)=>(t=e!=null?P($(e)):{},v(n||!e||!e.__esModule?m(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>v(m({},"__esModule",{value:!0}),e);var D={};Y(D,{Balancer:()=>I,Provider:()=>K,default:()=>z});module.exports=A(D);var i=R(require("react"));var p=R(require("react")),b=typeof window=="undefined",y=b?p.default.useEffect:p.default.useLayoutEffect,H=0,S=()=>++H,T=!1;function N(){let[e,n]=p.default.useState(T?S:void 0);return y(()=>{e===void 0&&n(S()),T=!0},[]),e===void 0?e:`rwb-${e.toString(32)}`}function g(){return p.default.useMemo(()=>"useId"in p.default?p.default.useId:N,[])()}var E="__wrap_b",f="__wrap_n",h="__wrap_o",x=(e,n,t)=>{t=t||document.querySelector(`[data-br="${e}"]`);let r=t==null?void 0:t.parentElement;if(!r)return;let o=u=>t.style.maxWidth=u+"px";t.style.maxWidth="";let l=r.clientWidth,d=r.clientHeight,s=l/2-.25,a=l+.5,c;if(l){for(o(s),s=Math.max(t.scrollWidth,s);s+1<a;)c=Math.round((s+a)/2),o(c),r.clientHeight===d?a=c:s=c;o(a*n+l*(1-n))}t.__wrap_o||(typeof ResizeObserver!="undefined"?(t.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+t.dataset.brr,t)})).observe(r):process.env.NODE_ENV==="development"&&console.warn("The browser you are using does not support the ResizeObserver API. Please consider add polyfill for this API to avoid potential layout shifts or upgrade your browser. Read more: https://github.com/shuding/react-wrap-balancer#browser-support-information"))},V=x.toString(),C='(self.CSS&&CSS.supports("text-wrap","balance")?1:2)',B=(e,n,t="")=>(t&&(t=`self.${f}!=1&&${t}`),i.default.createElement("script",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:(e?"":`self.${f}=self.${f}||${C};self.${E}=${V};`)+t},nonce:n})),O=i.default.createContext({preferNative:!0,hasProvider:!1}),K=({preferNative:e=!0,nonce:n,children:t})=>{let r=i.default.useMemo(()=>({preferNative:e,hasProvider:!0}),[e]);return i.default.createElement(O.Provider,{value:r},B(!1,n),t)},I=i.default.forwardRef(({ratio:e=1,preferNative:n,nonce:t,children:r,as:o,...l},d)=>{let s=g(),a=i.default.useRef(),c=i.default.useContext(O),u=n!=null?n:c.preferNative,w=o||"span";return i.default.useImperativeHandle(d,()=>a.current,[]),y(()=>{u&&self[f]===1||a.current&&(self[E]=x)(0,e,a.current)},[r,u,e]),y(()=>{if(!(u&&self[f]===1))return()=>{if(!a.current)return;let _=a.current[h];_&&(_.disconnect(),delete a.current[h])}},[u]),process.env.NODE_ENV==="development"&&r&&!Array.isArray(r)&&typeof r=="object"&&"type"in r&&typeof r.type=="string"&&r.type!=="span"&&console.warn(`<Balancer> should not wrap <${r.type}> inside. Instead, it should directly wrap text or inline nodes. | ||
@@ -7,3 +7,3 @@ Try changing this: | ||
To: | ||
<${r.type}><Balancer>content</Balancer></${r.type}>`),l.default.createElement(l.default.Fragment,null,l.default.createElement(p,{...o,"data-br":c,"data-brr":e,ref:a,style:{display:"inline-block",verticalAlign:"top",textDecoration:"inherit",textWrap:i?"balance":"initial"},suppressHydrationWarning:!0},r),x(s.hasProvider,t,`self.${E}("${c}",${e})`))};if(!b&&process.env.NODE_ENV!=="production"){let e=document.querySelector("[data-next-hide-fouc]");if(e){let n=r=>{for(let o of r)for(let c of Array.from(o.removedNodes)){if(c!==e)continue;t.disconnect();let a=document.querySelectorAll("[data-br]");for(let s of Array.from(a))self[E](0,+s.dataset.brr,s)}},t=new MutationObserver(n);t.observe(document.head,{childList:!0})}}var H=O;0&&(module.exports={Balancer,Provider}); | ||
<${r.type}><Balancer>content</Balancer></${r.type}>`),i.default.createElement(i.default.Fragment,null,i.default.createElement(w,{...l,"data-br":s,"data-brr":e,ref:a,style:{display:"inline-block",verticalAlign:"top",textDecoration:"inherit",textWrap:u?"balance":"initial"},suppressHydrationWarning:!0},r),B(c.hasProvider,t,`self.${E}("${s}",${e})`))});if(!b&&process.env.NODE_ENV!=="production"){let e=document.querySelector("[data-next-hide-fouc]");if(e){let n=r=>{for(let o of r)for(let l of Array.from(o.removedNodes)){if(l!==e)continue;t.disconnect();let d=document.querySelectorAll("[data-br]");for(let s of Array.from(d))self[E](0,+s.dataset.brr,s)}},t=new MutationObserver(n);t.observe(document.head,{childList:!0})}}var z=I;0&&(module.exports={Balancer,Provider}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-wrap-balancer", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Simple React component that makes titles more readable.", | ||
@@ -17,7 +17,2 @@ "repository": { | ||
], | ||
"scripts": { | ||
"build": "tsup src/index.tsx", | ||
"dev": "tsup src/index.tsx --watch", | ||
"dev:website": "turbo run dev --filter=website..." | ||
}, | ||
"keywords": [ | ||
@@ -41,3 +36,8 @@ "react", | ||
"react": ">=16.8.0 || ^17.0.0 || ^18" | ||
}, | ||
"scripts": { | ||
"build": "tsup src/index.tsx", | ||
"dev": "tsup src/index.tsx --watch", | ||
"dev:website": "turbo run dev --filter=website..." | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45474
89