cssom-papandreou
Advanced tools
Comparing version 0.2.4-patch1 to 0.2.6-patch1
@@ -27,4 +27,6 @@ //.CommonJS | ||
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSFontFaceRule.cpp | ||
CSSOM.CSSFontFaceRule.prototype.__defineGetter__("cssText", function() { | ||
return "@font-face {" + this.style.cssText + "}"; | ||
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", { | ||
get: function() { | ||
return "@font-face {" + this.style.cssText + "}"; | ||
} | ||
}); | ||
@@ -31,0 +33,0 @@ |
@@ -25,103 +25,105 @@ //.CommonJS | ||
CSSOM.CSSImportRule.prototype.type = 3; | ||
CSSOM.CSSImportRule.prototype.__defineGetter__("cssText", function() { | ||
var mediaText = this.media.mediaText; | ||
return "@import url(" + this.href + ")" + (mediaText ? " " + mediaText : "") + ";"; | ||
}); | ||
CSSOM.CSSImportRule.prototype.__defineSetter__("cssText", function(cssText) { | ||
var i = 0; | ||
Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", { | ||
get: function() { | ||
var mediaText = this.media.mediaText; | ||
return "@import url(" + this.href + ")" + (mediaText ? " " + mediaText : "") + ";"; | ||
}, | ||
set: function(cssText) { | ||
var i = 0; | ||
/** | ||
* @import url(partial.css) screen, handheld; | ||
* || | | ||
* after-import media | ||
* | | ||
* url | ||
*/ | ||
var state = ''; | ||
/** | ||
* @import url(partial.css) screen, handheld; | ||
* || | | ||
* after-import media | ||
* | | ||
* url | ||
*/ | ||
var state = ''; | ||
var buffer = ''; | ||
var index; | ||
var mediaText = ''; | ||
for (var character; character = cssText.charAt(i); i++) { | ||
var buffer = ''; | ||
var index; | ||
var mediaText = ''; | ||
for (var character; character = cssText.charAt(i); i++) { | ||
switch (character) { | ||
case ' ': | ||
case '\t': | ||
case '\r': | ||
case '\n': | ||
case '\f': | ||
if (state === 'after-import') { | ||
state = 'url'; | ||
} else { | ||
buffer += character; | ||
} | ||
break; | ||
switch (character) { | ||
case ' ': | ||
case '\t': | ||
case '\r': | ||
case '\n': | ||
case '\f': | ||
if (state === 'after-import') { | ||
state = 'url'; | ||
} else { | ||
buffer += character; | ||
} | ||
break; | ||
case '@': | ||
if (!state && cssText.indexOf('@import', i) === i) { | ||
state = 'after-import'; | ||
i += 'import'.length; | ||
buffer = ''; | ||
} | ||
break; | ||
case '@': | ||
if (!state && cssText.indexOf('@import', i) === i) { | ||
state = 'after-import'; | ||
i += 'import'.length; | ||
buffer = ''; | ||
} | ||
break; | ||
case 'u': | ||
if (state === 'url' && cssText.indexOf('url(', i) === i) { | ||
index = cssText.indexOf(')', i + 1); | ||
if (index === -1) { | ||
throw i + ': ")" not found'; | ||
} | ||
i += 'url('.length; | ||
var url = cssText.slice(i, index); | ||
if (url[0] === url[url.length - 1]) { | ||
if (url[0] === '"' || url[0] === "'") { | ||
url = url.slice(1, -1); | ||
} | ||
} | ||
this.href = url; | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case 'u': | ||
if (state === 'url' && cssText.indexOf('url(', i) === i) { | ||
index = cssText.indexOf(')', i + 1); | ||
if (index === -1) { | ||
throw i + ': ")" not found'; | ||
} | ||
i += 'url('.length; | ||
var url = cssText.slice(i, index); | ||
if (url[0] === url[url.length - 1]) { | ||
if (url[0] === '"' || url[0] === "'") { | ||
url = url.slice(1, -1); | ||
} | ||
} | ||
this.href = url; | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case '"': | ||
if (state === 'url') { | ||
index = cssText.indexOf('"', i + 1); | ||
if (!index) { | ||
throw i + ": '\"' not found"; | ||
} | ||
this.href = cssText.slice(i + 1, index); | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case '"': | ||
if (state === 'url') { | ||
index = cssText.indexOf('"', i + 1); | ||
if (!index) { | ||
throw i + ": '\"' not found"; | ||
} | ||
this.href = cssText.slice(i + 1, index); | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case "'": | ||
if (state === 'url') { | ||
index = cssText.indexOf("'", i + 1); | ||
if (!index) { | ||
throw i + ': "\'" not found'; | ||
} | ||
this.href = cssText.slice(i + 1, index); | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case "'": | ||
if (state === 'url') { | ||
index = cssText.indexOf("'", i + 1); | ||
if (!index) { | ||
throw i + ': "\'" not found'; | ||
} | ||
this.href = cssText.slice(i + 1, index); | ||
i = index; | ||
state = 'media'; | ||
} | ||
break; | ||
case ';': | ||
if (state === 'media') { | ||
if (buffer) { | ||
this.media.mediaText = buffer.trim(); | ||
} | ||
} | ||
break; | ||
case ';': | ||
if (state === 'media') { | ||
if (buffer) { | ||
this.media.mediaText = buffer.trim(); | ||
} | ||
} | ||
break; | ||
default: | ||
if (state === 'media') { | ||
buffer += character; | ||
} | ||
break; | ||
} | ||
} | ||
default: | ||
if (state === 'media') { | ||
buffer += character; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
@@ -128,0 +130,0 @@ |
@@ -28,4 +28,6 @@ //.CommonJS | ||
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframeRule.cpp | ||
CSSOM.CSSKeyframeRule.prototype.__defineGetter__("cssText", function() { | ||
return this.keyText + " { " + this.style.cssText + " } "; | ||
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "cssText", { | ||
get: function() { | ||
return this.keyText + " {" + this.style.cssText + "} "; | ||
} | ||
}); | ||
@@ -32,0 +34,0 @@ |
@@ -26,8 +26,10 @@ //.CommonJS | ||
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp | ||
CSSOM.CSSKeyframesRule.prototype.__defineGetter__("cssText", function() { | ||
var cssTexts = []; | ||
for (var i=0, length=this.cssRules.length; i < length; i++) { | ||
cssTexts.push(" " + this.cssRules[i].cssText); | ||
} | ||
return "@" + (this._vendorPrefix || '') + "keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}"; | ||
Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", { | ||
get: function() { | ||
var cssTexts = []; | ||
for (var i=0, length=this.cssRules.length; i < length; i++) { | ||
cssTexts.push(" " + this.cssRules[i].cssText); | ||
} | ||
return "@" + (this._vendorPrefix || '') + "keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}"; | ||
} | ||
}); | ||
@@ -34,0 +36,0 @@ |
@@ -28,8 +28,10 @@ //.CommonJS | ||
// http://opensource.apple.com/source/WebCore/WebCore-658.28/css/CSSMediaRule.cpp | ||
CSSOM.CSSMediaRule.prototype.__defineGetter__("cssText", function() { | ||
var cssTexts = []; | ||
for (var i=0, length=this.cssRules.length; i < length; i++) { | ||
cssTexts.push(this.cssRules[i].cssText); | ||
} | ||
return "@media " + this.media.mediaText + " {" + cssTexts.join("") + "}"; | ||
Object.defineProperty(CSSOM.CSSMediaRule.prototype, "cssText", { | ||
get: function() { | ||
var cssTexts = []; | ||
for (var i=0, length=this.cssRules.length; i < length; i++) { | ||
cssTexts.push(this.cssRules[i].cssText); | ||
} | ||
return "@media " + this.media.mediaText + " {" + cssTexts.join("") + "}"; | ||
} | ||
}); | ||
@@ -36,0 +38,0 @@ |
@@ -25,19 +25,20 @@ //.CommonJS | ||
CSSOM.CSSStyleRule.prototype.__defineGetter__("cssText", function() { | ||
var text; | ||
if (this.selectorText) { | ||
text = this.selectorText + " {" + this.style.cssText + "}"; | ||
} else { | ||
text = ""; | ||
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", { | ||
get: function() { | ||
var text; | ||
if (this.selectorText) { | ||
text = this.selectorText + " {" + this.style.cssText + "}"; | ||
} else { | ||
text = ""; | ||
} | ||
return text; | ||
}, | ||
set: function(cssText) { | ||
var rule = CSSOM.CSSStyleRule.parse(cssText); | ||
this.style = rule.style; | ||
this.selectorText = rule.selectorText; | ||
} | ||
return text; | ||
}); | ||
CSSOM.CSSStyleRule.prototype.__defineSetter__("cssText", function(cssText) { | ||
var rule = CSSOM.CSSStyleRule.parse(cssText); | ||
this.style = rule.style; | ||
this.selectorText = rule.selectorText; | ||
}); | ||
/** | ||
@@ -44,0 +45,0 @@ * NON-STANDARD |
@@ -44,3 +44,4 @@ //.CommonJS | ||
} | ||
this.cssRules.splice(index, 0, CSSOM.CSSStyleRule.parse(rule)); | ||
var cssRule = CSSOM.parse(rule).cssRules[0]; | ||
this.cssRules.splice(index, 0, cssRule); | ||
return index; | ||
@@ -116,2 +117,3 @@ }; | ||
exports.CSSStyleSheet = CSSOM.CSSStyleSheet; | ||
CSSOM.parse = require('./parse').parse; // Cannot be included sooner due to the mutual dependency between parse.js and CSSStyleSheet.js | ||
///CommonJS |
@@ -14,3 +14,7 @@ 'use strict'; | ||
exports.CSSKeyframeRule = require('./CSSKeyframeRule').CSSKeyframeRule; | ||
exports.MatcherList = require('./MatcherList').MatcherList; | ||
exports.CSSDocumentRule = require('./CSSDocumentRule').CSSDocumentRule; | ||
exports.CSSValue = require('./CSSValue').CSSValue; | ||
exports.CSSValueExpression = require('./CSSValueExpression').CSSValueExpression; | ||
exports.parse = require('./parse').parse; | ||
exports.clone = require('./clone').clone; |
114
lib/parse.js
//.CommonJS | ||
var CSSOM = { | ||
CSSStyleSheet: require("./CSSStyleSheet").CSSStyleSheet, | ||
CSSRule: require("./CSSRule").CSSRule, | ||
CSSStyleRule: require("./CSSStyleRule").CSSStyleRule, | ||
CSSImportRule: require("./CSSImportRule").CSSImportRule, | ||
CSSMediaRule: require("./CSSMediaRule").CSSMediaRule, | ||
CSSFontFaceRule: require("./CSSFontFaceRule").CSSFontFaceRule, | ||
CSSStyleDeclaration: require('./CSSStyleDeclaration').CSSStyleDeclaration, | ||
CSSKeyframeRule: require('./CSSKeyframeRule').CSSKeyframeRule, | ||
CSSKeyframesRule: require('./CSSKeyframesRule').CSSKeyframesRule | ||
}; | ||
var CSSOM = {}; | ||
///CommonJS | ||
@@ -24,10 +14,10 @@ | ||
/** | ||
"before-selector" or | ||
"selector" or | ||
"atRule" or | ||
"atBlock" or | ||
"before-name" or | ||
"name" or | ||
"before-value" or | ||
"value" | ||
"before-selector" or | ||
"selector" or | ||
"atRule" or | ||
"atBlock" or | ||
"before-name" or | ||
"name" or | ||
"before-value" or | ||
"value" | ||
*/ | ||
@@ -45,3 +35,4 @@ var state = "before-selector"; | ||
"importRule": true, | ||
"atBlock": true | ||
"atBlock": true, | ||
'documentRule-begin': true | ||
}; | ||
@@ -51,9 +42,9 @@ | ||
// @type CSSStyleSheet|CSSMediaRule|CSSFontFaceRule|CSSKeyframesRule | ||
// @type CSSStyleSheet|CSSMediaRule|CSSFontFaceRule|CSSKeyframesRule|CSSDocumentRule | ||
var currentScope = styleSheet; | ||
// @type CSSMediaRule|CSSKeyframesRule | ||
// @type CSSMediaRule|CSSKeyframesRule|CSSDocumentRule | ||
var parentRule; | ||
var selector, name, value, priority="", styleRule, mediaRule, importRule, fontFaceRule, keyframesRule, keyframeRule; | ||
var selector, name, value, priority="", styleRule, mediaRule, importRule, fontFaceRule, keyframesRule, keyframeRule, documentRule; | ||
@@ -89,6 +80,9 @@ var atKeyframesRegExp = /@(-(?:\w+-)+)?keyframes/g; | ||
case '"': | ||
index = token.indexOf('"', i + 1) + 1; | ||
if (!index) { | ||
parseError('Unmatched "'); | ||
} | ||
index = i + 1; | ||
do { | ||
index = token.indexOf('"', index) + 1; | ||
if (!index) { | ||
parseError('Unmatched "'); | ||
} | ||
} while (token[index - 2] === '\\') | ||
buffer += token.slice(i, index); | ||
@@ -107,6 +101,9 @@ i = index - 1; | ||
case "'": | ||
index = token.indexOf("'", i + 1) + 1; | ||
if (!index) { | ||
parseError("Unmatched '"); | ||
} | ||
index = i + 1; | ||
do { | ||
index = token.indexOf("'", index) + 1; | ||
if (!index) { | ||
parseError("Unmatched '"); | ||
} | ||
} while (token[index - 2] === '\\') | ||
buffer += token.slice(i, index); | ||
@@ -145,3 +142,10 @@ i = index - 1; | ||
case "@": | ||
if (token.indexOf("@media", i) === i) { | ||
if (token.indexOf("@-moz-document", i) === i) { | ||
state = "documentRule-begin"; | ||
documentRule = new CSSOM.CSSDocumentRule; | ||
documentRule.__starts = i; | ||
i += "-moz-document".length; | ||
buffer = ""; | ||
break; | ||
} else if (token.indexOf("@media", i) === i) { | ||
state = "atBlock"; | ||
@@ -218,2 +222,12 @@ mediaRule = new CSSOM.CSSMediaRule; | ||
state = "before-name"; | ||
} else if (state === "documentRule-begin") { | ||
// FIXME: what if this '{' is in the url text of the match function? | ||
documentRule.matcher.matcherText = buffer.trim(); | ||
if (parentRule) { | ||
documentRule.parentRule = parentRule; | ||
} | ||
currentScope = parentRule = documentRule; | ||
documentRule.parentStyleSheet = styleSheet; | ||
buffer = ""; | ||
state = "before-selector"; | ||
} | ||
@@ -234,11 +248,24 @@ break; | ||
if (state === 'value') { | ||
index = token.indexOf(')', i + 1); | ||
if (index === -1) { | ||
parseError('Unmatched "("'); | ||
// ie css expression mode | ||
if (buffer.trim() == 'expression') { | ||
var info = (new CSSOM.CSSValueExpression(token, i)).parse(); | ||
if (info.error) { | ||
parseError(info.error); | ||
} else { | ||
buffer += info.expression; | ||
i = info.idx; | ||
} | ||
} else { | ||
index = token.indexOf(')', i + 1); | ||
if (index === -1) { | ||
parseError('Unmatched "("'); | ||
} | ||
buffer += token.slice(i, index + 1); | ||
i = index; | ||
} | ||
buffer += token.slice(i, index + 1); | ||
i = index; | ||
} else { | ||
buffer += character; | ||
} | ||
break; | ||
@@ -330,3 +357,3 @@ | ||
case "selector": | ||
// End of media rule. | ||
// End of media/document rule. | ||
if (!parentRule) { | ||
@@ -374,2 +401,13 @@ parseError("Unexpected }"); | ||
exports.parse = CSSOM.parse; | ||
// The following modules cannot be included sooner due to the mutual dependency with parse.js | ||
CSSOM.CSSStyleSheet = require("./CSSStyleSheet").CSSStyleSheet; | ||
CSSOM.CSSStyleRule = require("./CSSStyleRule").CSSStyleRule; | ||
CSSOM.CSSImportRule = require("./CSSImportRule").CSSImportRule; | ||
CSSOM.CSSMediaRule = require("./CSSMediaRule").CSSMediaRule; | ||
CSSOM.CSSFontFaceRule = require("./CSSFontFaceRule").CSSFontFaceRule; | ||
CSSOM.CSSStyleDeclaration = require('./CSSStyleDeclaration').CSSStyleDeclaration; | ||
CSSOM.CSSKeyframeRule = require('./CSSKeyframeRule').CSSKeyframeRule; | ||
CSSOM.CSSKeyframesRule = require('./CSSKeyframesRule').CSSKeyframesRule; | ||
CSSOM.CSSValueExpression = require('./CSSValueExpression').CSSValueExpression; | ||
CSSOM.CSSDocumentRule = require('./CSSDocumentRule').CSSDocumentRule; | ||
///CommonJS |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["CSS", "CSSOM", "parser", "styleSheet"], | ||
"version": "0.2.4-patch1", | ||
"version": "0.2.6-patch1", | ||
"homepage": "https://github.com/NV/CSSOM", | ||
@@ -8,0 +8,0 @@ "author": "Nikita Vasilyev <me@elv1s.ru>", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
46065
23
1596
0
35
0