UNPKG

@filbert-js/browser-stylesheet

Version:
2 lines (1 loc) 1.22 kB
import{TYPES_CSS as e,TYPES_GLOBAL as t,TYPES_KEYFRAMES as n}from"@filbert-js/types";import{StyleSheet as r}from"@filbert-js/stylesheet";import{createParser as o}from"@filbert-js/css-parser";var i=o(),c=function(){return![typeof window,typeof document].includes("undefined")};function u(e){var t=e.append;return e.append=function(n){"string"==typeof n?e.textContent=n:t.call(e,n)},e.getChildById=function(e){return document.getElementById(e)},e.isBeforeChild=function(e,t){for(var n=this.children,r=-1,o=-1,i=0;i<n.length;i++){var c=n[i];c===e&&(o=i),c===t&&(r=i)}return r<o},e}var d=function(o){void 0===o&&(o={});var d,l,s=(d=c()?u(document.head):void 0,(l={})[t]={},l[e]={},l[n]={},c()&&Array.from(document.querySelectorAll('[data-type="styled-css"]')).reduce(function(e,t){var n=t.getAttribute("id");return e[t.getAttribute("styled-type")][n]=t.textContent,e},l),{getRoot:function(){return d},createElement:function(e){return u(document.createElement(e))},findElementByStyleId:function(e){return document.querySelector("."+e)},css:l});return new r(Object.assign({},{getRoot:s.getRoot,createElement:s.createElement,findElementByStyleId:s.findElementByStyleId,cssParser:i,css:s.css},o))};export{d as createStylesheet};