Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aesthetic-utils

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aesthetic-utils - npm Package Compare versions

Comparing version 2.0.0-alpha.6 to 2.0.0-rc.0

77

esm/purgeStyles.js
import toArray from './toArray';
export default function purgeStyles(styles) {
var NON_GLOBAL_PREFIX = /^(#|\.|@)/;
function containsNestedRules(rule) {
return typeof CSSStyleSheet !== 'undefined' && rule instanceof CSSStyleSheet || typeof CSSMediaRule !== 'undefined' && rule instanceof CSSMediaRule || typeof CSSSupportsRule !== 'undefined' && rule instanceof CSSSupportsRule;
}
function deleteRule(parent, ruleToDelete) {
Array.from(parent.cssRules).some(function (rule, index) {
if (rule === ruleToDelete && parent.cssRules[index]) {
if (typeof parent.deleteRule === 'function') {
parent.deleteRule(index);
} else {
delete parent.cssRules[index];
}
return true;
}
return false;
});
if (process.env.NODE_ENV === 'test') {
parent.cssRules = parent.cssRules.filter(Boolean);
}
if (parent.cssRules.length === 0 && parent instanceof CSSRule) {
if (containsNestedRules(parent.parentRule)) {
deleteRule(parent.parentRule, parent);
}
if (containsNestedRules(parent.parentStyleSheet)) {
deleteRule(parent.parentStyleSheet, parent);
}
}
}
function purgeRules(parent, onlyGlobals) {
if (onlyGlobals === void 0) {
onlyGlobals = false;
}
if (!parent.cssRules) {
return;
}
var rulesToDelete = [];
Array.from(parent.cssRules).forEach(function (rule) {
if (containsNestedRules(rule)) {
purgeRules(rule);
}
if (onlyGlobals && NON_GLOBAL_PREFIX.test(rule.cssText)) {
return;
}
rulesToDelete.push(rule);
});
rulesToDelete.forEach(function (rule) {
deleteRule(parent, rule);
});
}
export default function purgeStyles(styles, onlyGlobals) {
if (onlyGlobals === void 0) {
onlyGlobals = false;
}
toArray(styles).forEach(function (style) {
style.textContent = '';
var sheet = style.sheet;
if (sheet && sheet.cssRules) {
Array.from(sheet.cssRules).forEach(function (rule, index) {
if (sheet.cssRules[index]) {
sheet.deleteRule(index);
}
});
if (containsNestedRules(style.sheet)) {
purgeRules(style.sheet, onlyGlobals);
}
});
}

2

lib/purgeStyles.d.ts

@@ -1,2 +0,2 @@

export default function purgeStyles(styles: HTMLStyleElement | HTMLStyleElement[]): void;
export default function purgeStyles(styles: HTMLStyleElement | HTMLStyleElement[], onlyGlobals?: boolean): void;
//# sourceMappingURL=purgeStyles.d.ts.map

@@ -10,15 +10,76 @@ "use strict";

function purgeStyles(styles) {
var NON_GLOBAL_PREFIX = /^(#|\.|@)/;
function containsNestedRules(rule) {
return typeof CSSStyleSheet !== 'undefined' && rule instanceof CSSStyleSheet || typeof CSSMediaRule !== 'undefined' && rule instanceof CSSMediaRule || typeof CSSSupportsRule !== 'undefined' && rule instanceof CSSSupportsRule;
}
function deleteRule(parent, ruleToDelete) {
Array.from(parent.cssRules).some(function (rule, index) {
if (rule === ruleToDelete && parent.cssRules[index]) {
if (typeof parent.deleteRule === 'function') {
parent.deleteRule(index);
} else {
delete parent.cssRules[index];
}
return true;
}
return false;
});
if (process.env.NODE_ENV === 'test') {
parent.cssRules = parent.cssRules.filter(Boolean);
}
if (parent.cssRules.length === 0 && parent instanceof CSSRule) {
if (containsNestedRules(parent.parentRule)) {
deleteRule(parent.parentRule, parent);
}
if (containsNestedRules(parent.parentStyleSheet)) {
deleteRule(parent.parentStyleSheet, parent);
}
}
}
function purgeRules(parent, onlyGlobals) {
if (onlyGlobals === void 0) {
onlyGlobals = false;
}
if (!parent.cssRules) {
return;
}
var rulesToDelete = [];
Array.from(parent.cssRules).forEach(function (rule) {
if (containsNestedRules(rule)) {
purgeRules(rule);
}
if (onlyGlobals && NON_GLOBAL_PREFIX.test(rule.cssText)) {
return;
}
rulesToDelete.push(rule);
});
rulesToDelete.forEach(function (rule) {
deleteRule(parent, rule);
});
}
function purgeStyles(styles, onlyGlobals) {
if (onlyGlobals === void 0) {
onlyGlobals = false;
}
(0, _toArray.default)(styles).forEach(function (style) {
style.textContent = '';
var sheet = style.sheet;
if (sheet && sheet.cssRules) {
Array.from(sheet.cssRules).forEach(function (rule, index) {
if (sheet.cssRules[index]) {
sheet.deleteRule(index);
}
});
if (containsNestedRules(style.sheet)) {
purgeRules(style.sheet, onlyGlobals);
}
});
}
{
"name": "aesthetic-utils",
"version": "2.0.0-alpha.6",
"version": "2.0.0-rc.0",
"description": "Utility functions for Aesthetic.",

@@ -22,3 +22,3 @@ "keywords": [

},
"gitHead": "8a8e92b75a056555209a0690098d0fa855fd1cf3"
"gitHead": "fffc4bd0af4e34bc4efceb1d39f2a3dbf3b58545"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc