css-styled
Advanced tools
Comparing version 0.2.3 to 0.2.4
import { InjectOptions } from "./types"; | ||
export declare function getHash(str: string): any; | ||
export declare function getShadowRoot(parentElement: HTMLElement | SVGElement): Node; | ||
export declare function replaceStyle(className: string, css: string, options: Partial<InjectOptions>): string; | ||
export declare function injectStyle(className: string, css: string, options: Partial<InjectOptions>, shadowRoot?: Node): HTMLStyleElement; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/css-styled.git | ||
version: 0.2.3 | ||
version: 0.2.4 | ||
*/ | ||
@@ -44,2 +44,21 @@ 'use strict'; | ||
} | ||
function replaceStyle(className, css, options) { | ||
if (options.original) { | ||
return css; | ||
} | ||
return css.replace(/([^}{\s}][^}{]*){/mg, function (all, selector) { | ||
return utils.splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf("@") === 0) { | ||
return subSelector; | ||
} else if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
function injectStyle(className, css, options, shadowRoot) { | ||
@@ -54,19 +73,3 @@ var style = document.createElement("style"); | ||
var styleCSS = css; | ||
if (!options.original) { | ||
styleCSS = css.replace(/([^}{]*){/mg, function (all, selector) { | ||
return utils.splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
style.innerHTML = styleCSS; | ||
style.innerHTML = replaceStyle(className, css, options); | ||
(shadowRoot || document.head || document.body).appendChild(style); | ||
@@ -73,0 +76,0 @@ return style; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/css-styled.git | ||
version: 0.2.3 | ||
version: 0.2.4 | ||
*/ | ||
@@ -42,2 +42,21 @@ import { splitComma } from '@daybrush/utils'; | ||
} | ||
function replaceStyle(className, css, options) { | ||
if (options.original) { | ||
return css; | ||
} | ||
return css.replace(/([^}{\s}][^}{]*){/mg, function (all, selector) { | ||
return splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf("@") === 0) { | ||
return subSelector; | ||
} else if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
function injectStyle(className, css, options, shadowRoot) { | ||
@@ -52,19 +71,3 @@ var style = document.createElement("style"); | ||
var styleCSS = css; | ||
if (!options.original) { | ||
styleCSS = css.replace(/([^}{]*){/mg, function (all, selector) { | ||
return splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
style.innerHTML = styleCSS; | ||
style.innerHTML = replaceStyle(className, css, options); | ||
(shadowRoot || document.head || document.body).appendChild(style); | ||
@@ -71,0 +74,0 @@ return style; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/css-styled.git | ||
version: 0.2.3 | ||
version: 0.2.4 | ||
*/ | ||
@@ -143,2 +143,21 @@ (function (global, factory) { | ||
} | ||
function replaceStyle(className, css, options) { | ||
if (options.original) { | ||
return css; | ||
} | ||
return css.replace(/([^}{\s}][^}{]*){/mg, function (all, selector) { | ||
return splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf("@") === 0) { | ||
return subSelector; | ||
} else if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
function injectStyle(className, css, options, shadowRoot) { | ||
@@ -153,19 +172,3 @@ var style = document.createElement("style"); | ||
var styleCSS = css; | ||
if (!options.original) { | ||
styleCSS = css.replace(/([^}{]*){/mg, function (all, selector) { | ||
return splitComma(selector).map(function (subSelector) { | ||
if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return "" + subSelector.replace(/\:host/g, "." + className); | ||
} | ||
return "." + className + " " + subSelector; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
style.innerHTML = styleCSS; | ||
style.innerHTML = replaceStyle(className, css, options); | ||
(shadowRoot || document.head || document.body).appendChild(style); | ||
@@ -172,0 +175,0 @@ return style; |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/css-styled.git | ||
version: 0.2.3 | ||
version: 0.2.4 | ||
*/ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).styled=n()}(this,function(){"use strict";var e=function(e){for(var n=5381,t=e.length;t;)n=33*n^e.charCodeAt(--t);return n>>>0},d=['"',"'",'\\"',"\\'"];function c(e,n,t,r){for(var o=t;o<r;++o){var i=n[o].trim();if(i===e)return o;var u=o;if("("===i?u=c(")",n,o+1,r):-1<d.indexOf(i)&&(u=c(i,n,o+1,r)),-1===u)break;o=u}return-1}function a(e){return function(e,n){for(var t=new RegExp("(\\s*"+(n||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=e.split(t).filter(Boolean),o=r.length,i=[],u=[],f=0;f<o;++f){var l=r[f].trim(),a=f;if("("===l)a=c(")",r,f+1,o);else{if(")"===l)throw new Error("invalid format");if(-1<d.indexOf(l))a=c(l,r,f+1,o);else if(l===n){u.length&&(i.push(u.join("")),u=[]);continue}}-1===a&&(a=o-1),u.push(r.slice(f,a+1).join("")),f=a}return u.length&&i.push(u.join("")),i}(e,",")}return function(i){var u,f="rCS"+e(i).toString(36),l=0;return{className:f,inject:function(e,n){void 0===n&&(n={});var t,r=function(e){if(e&&e.getRootNode){var n=e.getRootNode();if(11===n.nodeType)return n}}(e),o=0===l;return(r||o)&&(t=function(t,e,n,r){var o=document.createElement("style");o.setAttribute("type","text/css"),o.setAttribute("data-styled-id",t),n.nonce&&o.setAttribute("nonce",n.nonce);var i=e;return n.original||(i=e.replace(/([^}{]*){/gm,function(e,n){return a(n).map(function(e){return-1<e.indexOf(":global")?e.replace(/\:global/g,""):-1<e.indexOf(":host")?""+e.replace(/\:host/g,"."+t):"."+t+" "+e}).join(", ")+"{"})),o.innerHTML=i,(r||document.head||document.body).appendChild(o),o}(f,i,n,r)),o&&(u=t),r||++l,{destroy:function(){r?(e.removeChild(t),t=null):(0<l&&--l,0===l&&u&&(u.parentNode.removeChild(u),u=null))}}}}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).styled=n()}(this,function(){"use strict";var e=function(e){for(var n=5381,t=e.length;t;)n=33*n^e.charCodeAt(--t);return n>>>0},a=['"',"'",'\\"',"\\'"];function c(e,n,t,r){for(var o=t;o<r;++o){var i=n[o].trim();if(i===e)return o;var u=o;if("("===i?u=c(")",n,o+1,r):-1<a.indexOf(i)&&(u=c(i,n,o+1,r)),-1===u)break;o=u}return-1}function f(e){return function(e,n){for(var t=new RegExp("(\\s*"+(n||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=e.split(t).filter(Boolean),o=r.length,i=[],u=[],f=0;f<o;++f){var d=r[f].trim(),l=f;if("("===d)l=c(")",r,f+1,o);else{if(")"===d)throw new Error("invalid format");if(-1<a.indexOf(d))l=c(d,r,f+1,o);else if(d===n){u.length&&(i.push(u.join("")),u=[]);continue}}-1===l&&(l=o-1),u.push(r.slice(f,l+1).join("")),f=l}return u.length&&i.push(u.join("")),i}(e,",")}function l(e,n,t,r){var o,i,u=document.createElement("style");return u.setAttribute("type","text/css"),u.setAttribute("data-styled-id",e),t.nonce&&u.setAttribute("nonce",t.nonce),u.innerHTML=(o=e,i=n,t.original?i:i.replace(/([^}{\s}][^}{]*){/gm,function(e,n){return f(n).map(function(e){return 0===e.indexOf("@")?e:-1<e.indexOf(":global")?e.replace(/\:global/g,""):-1<e.indexOf(":host")?""+e.replace(/\:host/g,"."+o):"."+o+" "+e}).join(", ")+"{"})),(r||document.head||document.body).appendChild(u),u}return function(i){var u,f="rCS"+e(i).toString(36),d=0;return{className:f,inject:function(e,n){void 0===n&&(n={});var t,r=function(e){if(e&&e.getRootNode){var n=e.getRootNode();if(11===n.nodeType)return n}}(e),o=0===d;return(r||o)&&(t=l(f,i,n,r)),o&&(u=t),r||++d,{destroy:function(){r?(e.removeChild(t),t=null):(0<d&&--d,0===d&&u&&(u.parentNode.removeChild(u),u=null))}}}}}}); | ||
//# sourceMappingURL=styled.min.js.map |
{ | ||
"name": "css-styled", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "This component is a lightweight, simple line style component.", | ||
@@ -14,6 +14,8 @@ "main": "./dist/styled.cjs.js", | ||
"doc": "rm -rf ./doc && jsdoc -c jsdoc.json", | ||
"test": "jest --watchAll", | ||
"coverage": "jest --coverage && print-coveralls --sort=desc", | ||
"prerelease": "npm run build && prerelease --dirs=dist", | ||
"release": "npm run build && release --dirs=dist", | ||
"release:init": "npm run build && release -i --dirs=dist", | ||
"packages": "pvu --path=packages --update=react-css-styled" | ||
"packages": "pvu --path=packages --update=react-css-styled --build=react-css-styled --publish=react-css-styled" | ||
}, | ||
@@ -38,5 +40,9 @@ "repository": { | ||
"@daybrush/release": "^0.2.4", | ||
"@types/jest": "^26.0.13", | ||
"daybrush-jsdoc-template": "^1.6.0", | ||
"jest": "^26.4.2", | ||
"print-coveralls": "^1.2.2", | ||
"print-sizes": "^0.1.0", | ||
"pvu": "^0.4.1", | ||
"ts-jest": "^26.3.0", | ||
"tslint": "^5.20.1", | ||
@@ -43,0 +49,0 @@ "typescript": "^3.7.4" |
@@ -18,2 +18,19 @@ import stringHash from "string-hash"; | ||
} | ||
export function replaceStyle(className: string, css: string, options: Partial<InjectOptions>) { | ||
if (options.original) { | ||
return css; | ||
} | ||
return css.replace(/([^}{\s}][^}{]*){/mg, (all, selector) => { | ||
return splitComma(selector).map(subSelector => { | ||
if (subSelector.indexOf("@") === 0) { | ||
return subSelector; | ||
} else if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return `${subSelector.replace(/\:host/g, `.${className}`)}`; | ||
} | ||
return `.${className} ${subSelector}`; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
export function injectStyle(className: string, css: string, options: Partial<InjectOptions>, shadowRoot?: Node) { | ||
@@ -28,16 +45,3 @@ const style = document.createElement("style"); | ||
} | ||
let styleCSS = css; | ||
if (!options.original) { | ||
styleCSS = css.replace(/([^}{]*){/mg, (all, selector) => { | ||
return splitComma(selector).map(subSelector => { | ||
if (subSelector.indexOf(":global") > -1) { | ||
return subSelector.replace(/\:global/g, ""); | ||
} else if (subSelector.indexOf(":host") > -1) { | ||
return `${subSelector.replace(/\:host/g, `.${className}`)}`; | ||
} | ||
return `.${className} ${subSelector}`; | ||
}).join(", ") + "{"; | ||
}); | ||
} | ||
style.innerHTML = styleCSS; | ||
style.innerHTML = replaceStyle(className, css, options); | ||
@@ -44,0 +48,0 @@ (shadowRoot || document.head || document.body).appendChild(style); |
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
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
51256
25
693
12