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