@pluginjs/styled
Version:
A flexible modern styled js plugin.
7 lines (6 loc) • 4.99 kB
JavaScript
/*!
* @pluginjs/styled v0.8.11 (https://pluginjs.com)
* Copyright 2022 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
import{curryWith as t,camelize as e,dasherize as r}from"@pluginjs/utils";import{isElement as o,isString as i,isNumeric as n,isObject as d,isArray as a,isWindow as p,isDocument as l}from"@pluginjs/is";import{offsetParent as g}from"@pluginjs/dom";var s=t=>{var e=t.ownerDocument.defaultView;return e&&e.opener||(e=window),e},f=t=>/^--/.test(t),h=(t,a,p)=>{if(i(t)&&o(p))a||0===a?f(t)?p.style.setProperty(t,a):(t=e(t,!1),n(a)&&!["animationIterationCount","columnCount","fillOpacity","flexGrow","flexShrink","fontWeight","lineHeight","opacity","order","orphans","widows","zIndex","zoom"].includes(t)&&(a+="px"),p.style[t]=a):p.style.removeProperty(r(t));else if(d(t)){var l;for(l in o(a)&&void 0===p&&(p=a,a=void 0),t)Object.prototype.hasOwnProperty.call(t,l)&&h(l,t[l],p)}return p},u=(t,e)=>{var o;return a(t)?(o={},t.forEach((t=>{o[t]=u(t,e)})),o):(f(t)||(t=r(t)),o=s(e).getComputedStyle(e,"").getPropertyValue(t),n(o)?parseFloat(o):o)},m=t(((t,e,r)=>(o(e)&&void 0===r&&(r=e,e=void 0),"string"==typeof t&&void 0===e?u(t,r):h(t,e,r))),o),v=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(o(t)&&void 0===e&&(e=t,t=!1),p(e))return e.outerHeight;var i=r?parseFloat(u("height",e),10):e.offsetHeight;if(t){var{marginTop:n,marginBottom:d}=u(["marginTop","marginBottom"],e);return(n=r?parseFloat(n,10):parseInt(n,10))+(d=r?parseFloat(d,10):parseInt(d,10))+i}return i},y=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(o(t)&&void 0===e&&(e=t,t=!1),p(e))return e.outerWidth;var i=r?parseFloat(u("width",e),10):e.offsetWidth;if(t){var{marginLeft:n,marginRight:d}=u(["marginLeft","marginRight"],e);return(n=r?parseFloat(n,10):parseInt(n,10))+(d=r?parseFloat(d,10):parseInt(d,10))+i}return i},b=t=>p(t)?t.innerWidth:t.clientWidth,c=t=>p(t)?t.innerHeight:t.clientHeight,W=t=>{if(p(t))return t.innerWidth;if(l(t)){var e=t.documentElement;return Math.max(t.body.scrollWidth,e.scrollWidth,t.body.offsetWidth,e.offsetWidth,e.clientWidth)}var{width:r}=t.getBoundingClientRect(),{paddingLeft:o,paddingRight:i}=u(["paddingLeft","paddingRight"],t);if(r=r-parseInt(o,10)-parseInt(i,10),"border-box"===u("boxSizing",t)){var{borderLeftWidth:n,borderRightWidth:d}=u(["borderLeftWidth","borderRightWidth"],t);r=r-parseInt(n,10)-parseInt(d,10)}return r},H=(t,e)=>{if(1!==e.nodeType)return e;if("border-box"===u("boxSizing",e)){var{paddingLeft:r,paddingRight:o,borderLeftWidth:i,borderRightWidth:n}=u(["paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],e);t+=r+o+i+n}return h("width",t,e)},x=(t,e)=>(o(t)&&void 0===e&&(e=t,t=void 0),void 0===t?W(e):H(t,e)),T=t=>{if(p(t))return t.innerHeight;if(l(t)){var e=t.documentElement;return Math.max(t.body.scrollHeight,e.scrollHeight,t.body.offsetHeight,e.offsetHeight,e.clientHeight)}var{height:r}=t.getBoundingClientRect(),{paddingTop:o,paddingBottom:i}=u(["paddingTop","paddingBottom"],t);if(r=r-parseInt(o,10)-parseInt(i,10),"border-box"===u("boxSizing",t)){var n=u(["borderTopHeight","borderBottomHeight"],t),d=n.borderTopHeight||0,a=n.borderBottomHeight||0;r=r-parseInt(d,10)-parseInt(a,10)}return r},B=(t,e)=>{if(1!==e.nodeType)return e;if("border-box"===u("boxSizing",e)){var{paddingTop:r,paddingBottom:o,borderTopHeight:i,borderBottomHeight:n}=u(["paddingTop","paddingBottom","borderTopHeight","borderBottomHeight"],e);t+=r+o+i+n}return h("height",t,e)},I=(t,e)=>(o(t)&&void 0===e&&(e=t,t=void 0),void 0===t?T(e):B(t,e)),R=t=>{var e=t.getBoundingClientRect(),r=s(t);return{top:e.top+r.pageYOffset,left:e.left+r.pageXOffset}},L=(t,e)=>{var r={},o=w(g(e));return void 0!==t.top&&(r.top=t.top-o.top),void 0!==t.left&&(r.left=t.left-o.left),"static"===u("position",e)&&(r.position="relative"),h(r,e)},w=(t,e)=>(o(t)&&void 0===e&&(e=t,t=void 0),t?L(t,e):R(e)),C=t=>{var e,r={top:0,left:0};if("fixed"===u("position",t))e=t.getBoundingClientRect();else{e=w(t);var o=g(t);o&&o!==t&&1===o.nodeType&&((r=w(o)).top+=parseFloat(o.style.borderTopWidth)||0,r.left+=parseFloat(o.style.borderLeftWidth)||0)}return e.top-=parseFloat(t.style.marginTop)||0,e.left-=parseFloat(t.style.marginLeft)||0,{top:e.top-r.top,left:e.left-r.left}},F={},S=t=>("none"!==t.style.display&&(t.style.display="none"),t),z=t=>{var e,r,o;return"none"===t.style.display&&(t.style.display=""),"none"===getComputedStyle(t,"").getPropertyValue("display")&&(t.style.display=(e=t.nodeName,F[e]||(o=document.createElement(e),document.body.appendChild(o),r=getComputedStyle(o,"").getPropertyValue("display"),o.parentNode.removeChild(o),"none"===r&&(r="block"),F[e]=r),F[e])),t};export{m as css,s as getDefaultView,T as getHeight,R as getOffset,u as getStyle,W as getWidth,I as height,S as hideElement,c as innerHeight,b as innerWidth,f as isCSSVariable,w as offset,v as outerHeight,y as outerWidth,C as position,B as setHeight,L as setOffset,h as setStyle,H as setWidth,z as showElement,x as width};