Comparing version 0.2.5 to 0.3.0
@@ -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,2 +44,3 @@ //.CommonJS | ||
var cssRule = CSSOM.parse(rule).cssRules[0]; | ||
cssRule.parentStyleSheet = this; | ||
this.cssRules.splice(index, 0, cssRule); | ||
@@ -46,0 +47,0 @@ return index; |
@@ -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; |
@@ -14,10 +14,10 @@ //.CommonJS | ||
/** | ||
"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" | ||
*/ | ||
@@ -35,3 +35,4 @@ var state = "before-selector"; | ||
"importRule": true, | ||
"atBlock": true | ||
"atBlock": true, | ||
'documentRule-begin': true | ||
}; | ||
@@ -41,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; | ||
@@ -79,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); | ||
@@ -97,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); | ||
@@ -135,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"; | ||
@@ -208,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"; | ||
} | ||
@@ -224,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; | ||
@@ -294,3 +331,3 @@ | ||
case "selector": | ||
// End of media rule. | ||
// End of media/document rule. | ||
if (!parentRule) { | ||
@@ -347,2 +384,4 @@ parseError("Unexpected }"); | ||
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.5", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/NV/CSSOM", | ||
@@ -13,21 +13,11 @@ "author": "Nikita Vasilyev <me@elv1s.ru>", | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/NV/CSSOM/issues" | ||
}, | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"bugs": "https://github.com/NV/CSSOM/issues", | ||
"main": "./lib/index.js", | ||
"engines": { | ||
"node": ">=0.2.0" | ||
}, | ||
"devDependencies": { | ||
"jake": "0.2.x" | ||
"jake": "~0.7.3" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://creativecommons.org/licenses/MIT/" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "http://creativecommons.org/licenses/MIT/" | ||
}, | ||
"scripts": { | ||
@@ -34,0 +24,0 @@ "prepublish": "jake lib/index.js" |
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
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
43590
23
1541
37
0
1
1