react-wrap-balancer
Advanced tools
Comparing version 0.3.0 to 0.4.0
import React from 'react'; | ||
declare const SYMBOL_KEY = "__wrap_b"; | ||
declare type RelayoutFn = (id: string | number, ratio: number, wrapper?: HTMLElement) => void; | ||
declare const SYMBOL_OBSERVER_KEY = "__wrap_o"; | ||
interface WrapperElement extends HTMLElement { | ||
[SYMBOL_OBSERVER_KEY]?: ResizeObserver | undefined; | ||
} | ||
declare type RelayoutFn = (id: string | number, ratio: number, wrapper?: WrapperElement) => void; | ||
declare global { | ||
@@ -6,0 +10,0 @@ interface Window { |
"use client" | ||
var R=Object.create;var u=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var g=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},m=(e,n,t,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of x(n))!S.call(e,r)&&r!==t&&u(e,r,{get:()=>n[r],enumerable:!(c=L(n,r))||c.enumerable});return e};var H=(e,n,t)=>(t=e!=null?R(M(e)):{},m(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>m(u({},"__esModule",{value:!0}),e);var Y={};g(Y,{Provider:()=>O,default:()=>W});module.exports=T(Y);var s=H(require("react")),f="__wrap_b",b="__wrap_o",y=typeof window=="undefined",_=y?s.default.useEffect:s.default.useLayoutEffect,E=(e,n,t)=>{t=t||document.querySelector(`[data-br="${e}"]`);let c=t.parentElement,r=v=>t.style.maxWidth=v+"px";t.style.maxWidth="";let o=c.clientWidth,l=c.clientHeight,a=o/2,i=o,d;if(o){for(;a+1<i;)d=~~((a+i)/2),r(d),c.clientHeight===l?i=d:a=d;r(i*n+o*(1-n))}t.__wrap_o||(t.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+t.dataset.brr,t)})).observe(c)},B=E.toString(),h=(e,n)=>s.default.createElement("script",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:(e?"":`self.${f}=${B};`)+(n||"")}}),p=s.default.createContext(!1),O=({children:e})=>s.default.createElement(p.Provider,{value:!0},h(!1),e),C=({as:e="span",ratio:n=1,children:t,...c})=>{let r=s.default.useId(),o=s.default.useRef(),l=s.default.useContext(p);return _(()=>{o.current&&(self[f]=E)(0,n,o.current)},[t,n]),_(()=>()=>{if(o.current){let a=o.current[b];a&&(a.disconnect(),delete o.current[b])}},[]),s.default.createElement(s.default.Fragment,null,s.default.createElement(e,{...c,"data-br":r,"data-brr":n,ref:o,style:{display:"inline-block",verticalAlign:"top",textDecoration:"inherit"},suppressHydrationWarning:!0},t),h(l,`self.${f}("${r}",${n})`))};if(!y&&process.env.NODE_ENV!=="production"){let e=document.querySelector("[data-next-hide-fouc]");if(e){let n=c=>{for(let r of c)for(let o of Array.from(r.removedNodes)){if(o!==e)continue;t.disconnect();let l=document.querySelectorAll("[data-br]");for(let a of Array.from(l))self[f](0,+a.dataset.brr,a)}},t=new MutationObserver(n);t.observe(document.head,{childList:!0})}}var W=C;0&&(module.exports={Provider}); | ||
var B=Object.create;var d=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var O=(t,n)=>{for(var e in n)d(t,e,{get:n[e],enumerable:!0})},p=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of S(n))!L.call(t,r)&&r!==e&&d(t,r,{get:()=>n[r],enumerable:!(s=x(n,r))||s.enumerable});return t};var M=(t,n,e)=>(e=t!=null?B(g(t)):{},p(n||!t||!t.__esModule?d(e,"default",{value:t,enumerable:!0}):e,t)),W=t=>p(d({},"__esModule",{value:!0}),t);var H={};O(H,{Provider:()=>$,default:()=>T});module.exports=W(H);var a=M(require("react")),f="__wrap_b",m="__wrap_o",b=typeof window=="undefined",y=b?a.default.useEffect:a.default.useLayoutEffect,E=(t,n,e)=>{e=e||document.querySelector(`[data-br="${t}"]`);let s=e.parentElement,r=R=>e.style.maxWidth=R+"px";e.style.maxWidth="";let o=s.clientWidth,i=s.clientHeight,c=o/2-.25,l=o+.5,u;if(o){for(;c+1<l;)u=Math.round((c+l)/2),r(u),s.clientHeight===i?l=u:c=u;r(l*n+o*(1-n))}e.__wrap_o||(e.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+e.dataset.brr,e)})).observe(s)},h=E.toString(),_=(t,n="")=>a.default.createElement("script",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:(t?"":`self.${f}=${h};`)+n}}),v=a.default.createContext(!1),$=({children:t})=>a.default.createElement(v.Provider,{value:!0},_(!1),t),w=({as:t="span",ratio:n=1,children:e,...s})=>{let r=a.default.useId(),o=a.default.useRef(),i=a.default.useContext(v);return y(()=>{o.current&&(self[f]=E)(0,n,o.current)},[e,n]),y(()=>()=>{if(!o.current)return;let c=o.current[m];!c||(c.disconnect(),delete o.current[m])},[]),process.env.NODE_ENV==="development"&&e&&!Array.isArray(e)&&typeof e=="object"&&"type"in e&&typeof e.type=="string"&&e.type!=="span"&&console.warn(`<Balancer> should not wrap <${e.type}> inside. Instead, it should directly wrap text or inline nodes. | ||
Try changing this: | ||
<Balancer><${e.type}>content</${e.type}></Balancer> | ||
To: | ||
<${e.type}><Balancer>content</Balancer></${e.type}>`),a.default.createElement(a.default.Fragment,null,a.default.createElement(t,{...s,"data-br":r,"data-brr":n,ref:o,style:{display:"inline-block",verticalAlign:"top",textDecoration:"inherit"},suppressHydrationWarning:!0},e),_(i,`self.${f}("${r}",${n})`))};if(!b&&process.env.NODE_ENV!=="production"){let t=document.querySelector("[data-next-hide-fouc]");if(t){let n=s=>{for(let r of s)for(let o of Array.from(r.removedNodes)){if(o!==t)continue;e.disconnect();let i=document.querySelectorAll("[data-br]");for(let c of Array.from(i))self[f](0,+c.dataset.brr,c)}},e=new MutationObserver(n);e.observe(document.head,{childList:!0})}}var T=w;0&&(module.exports={Provider}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-wrap-balancer", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Better text wrapping.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
28231
59
5