Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
html.HTMLElement.prototype.__defineGetter__('style', function() {
if (typeof this._style === 'string') {
// currently, cssom's parse doesn't really work if you pass in
// {state: 'name'}, so instead we just build a dummy sheet.
var styleSheet = cssom.parse('dummy{' + this._style + '}');
this._style = new cssstyle.CSSStyleDeclaration();
if (styleSheet.cssRules.length > 0 && styleSheet.cssRules[0].style) {
var newStyle = styleSheet.cssRules[0].style;
for (var i = 0; i < newStyle.length; ++i) {
var prop = newStyle[i];
this._style.setProperty(
prop,
newStyle.getPropertyValue(prop),
newStyle.getPropertyPriority(prop));
}
}
}
if (!this._style) {
this._style = new cssstyle.CSSStyleDeclaration();
}
if (!this.getAttributeNode('style')) {
defineGetter(html.HTMLElement.prototype, 'style', function() {
if (typeof this._style === 'string') {
// currently, cssom's parse doesn't really work if you pass in
// {state: 'name'}, so instead we just build a dummy sheet.
var styleSheet = cssom.parse('dummy{' + this._style + '}');
this._style = new cssstyle.CSSStyleDeclaration();
if (styleSheet.cssRules.length > 0 && styleSheet.cssRules[0].style) {
var newStyle = styleSheet.cssRules[0].style;
for (var i = 0; i < newStyle.length; ++i) {
var prop = newStyle[i];
this._style.setProperty(
prop,
newStyle.getPropertyValue(prop),
newStyle.getPropertyPriority(prop));
}
}
}
if (!this._style) {
this._style = new cssstyle.CSSStyleDeclaration();
}
if (!this.getAttributeNode('style')) {
getComputedStyle: function(node) {
var s = node.style,
cs = new CSSStyleDeclaration(),
forEach = Array.prototype.forEach;
function setPropertiesFromRule(rule) {
var selectors = rule.selectorText.split(/\s*,\s*/);
var matched = false;
selectors.forEach(function (selectorText) {
if (!matched && matchesDontThrow(node, selectorText)) {
matched = true;
forEach.call(rule.style, function (property) {
cs.setProperty(property, rule.style.getPropertyValue(property), rule.style.getPropertyPriority(property));
});
}
});
}
forEach.call(node.ownerDocument.styleSheets, function (sheet) {
getComputedStyle: function (node) {
var s = node.style,
cs = new CSSStyleDeclaration(),
forEach = Array.prototype.forEach;
function setPropertiesFromRule(rule) {
if (!rule.selectorText) {
return;
}
var selectors = rule.selectorText.split(cssSelectorSplitRE);
var matched = false;
selectors.forEach(function (selectorText) {
if (selectorText !== "" && selectorText !== "," && !matched && matchesDontThrow(node, selectorText)) {
matched = true;
forEach.call(rule.style, function (property) {
cs.setProperty(property, rule.style.getPropertyValue(property), rule.style.getPropertyPriority(property));
});
}
getComputedStyle: function(node) {
var s = node.style,
cs = new CSSStyleDeclaration(),
forEach = Array.prototype.forEach;
function setPropertiesFromRule(rule) {
if (!rule.selectorText) {
return;
}
var selectors = rule.selectorText.split(cssSelectorSplitRE);
var matched = false;
selectors.forEach(function (selectorText) {
if (selectorText !== '' && selectorText !== ',' && !matched && matchesDontThrow(node, selectorText)) {
matched = true;
forEach.call(rule.style, function (property) {
cs.setProperty(property, rule.style.getPropertyValue(property), rule.style.getPropertyPriority(property));
});
}
getComputedStyle: function(node) {
var s = node.style,
cs = new CSSStyleDeclaration(),
forEach = Array.prototype.forEach;
function setPropertiesFromRule(rule) {
if (!rule.selectorText) {
return;
}
var selectors = rule.selectorText.split(/\s*,\s*/);
var matched = false;
selectors.forEach(function (selectorText) {
if (!matched && matchesDontThrow(node, selectorText)) {
matched = true;
forEach.call(rule.style, function (property) {
cs.setProperty(property, rule.style.getPropertyValue(property), rule.style.getPropertyPriority(property));
});
}
export function css2style (css = {}) {
const style = new CSSStyleDeclaration();
for (const k of Object.keys(css)) {
style[k] = css[k];
}
return style;
}
_initElementCSSInlineStyle() {
this._settingCssText = false;
this._style = new cssstyle.CSSStyleDeclaration(newCssText => {
if (!this._settingCssText) {
this._settingCssText = true;
this.setAttributeNS(null, "style", newCssText);
this._settingCssText = false;
}
});
}
get style() {
_initElementCSSInlineStyle() {
this._style = new cssstyle.CSSStyleDeclaration(newCssText => {
if (!this._settingCssText) {
this._settingCssText = true;
this.setAttribute("style", newCssText);
this._settingCssText = false;
}
});
}
get style() {
_initElementCSSInlineStyle() {
this._style = new cssstyle.CSSStyleDeclaration(newCssText => {
if (!this._settingCssText) {
this._settingCssText = true;
this.setAttribute("style", newCssText);
this._settingCssText = false;
}
});
}
get style() {