pax_global_header 0000666 0000000 0000000 00000000064 12237322307 0014513 g ustar 00root root 0000000 0000000 52 comment=f6f9f848081409e8628416bc5521f4cf8e74b39a
CSSOM-0.3.0/ 0000775 0000000 0000000 00000000000 12237322307 0012377 5 ustar 00root root 0000000 0000000 CSSOM-0.3.0/.gitignore 0000664 0000000 0000000 00000000054 12237322307 0014366 0 ustar 00root root 0000000 0000000 /lib/index.js
/build/
/node_modules/
*.swp
CSSOM-0.3.0/.gitmodules 0000664 0000000 0000000 00000000400 12237322307 0014546 0 ustar 00root root 0000000 0000000 [submodule "spec/vendor/objectDiff"]
path = spec/vendor/objectDiff
url = git://github.com/NV/objectDiff.js.git
[submodule "spec/vendor/jasmine-html-reporter"]
path = spec/vendor/jasmine-html-reporter
url = git://github.com/NV/jasmine-html-reporter.git
CSSOM-0.3.0/.npmignore 0000664 0000000 0000000 00000000060 12237322307 0014372 0 ustar 00root root 0000000 0000000 docs/
src/
test/
spec/
Jakefile.js
README.mdown
CSSOM-0.3.0/Jakefile.js 0000664 0000000 0000000 00000002120 12237322307 0014442 0 ustar 00root root 0000000 0000000 var PATH = require("path");
var FS = require("fs");
function readFile(path) {
var abs_path = PATH.join(__dirname, path);
return FS.readFileSync(abs_path, "utf8");
}
function stripCommonJS(text) {
return text.replace(/\/\/\.CommonJS(?:.|\n)*?\/\/\/CommonJS/g, "");
}
desc("Packages lib files into the one huge");
task("default", ["build/CSSOM.js"]);
directory("build");
file("build/CSSOM.js", ["src/files.js", "src/CSSOM.js", "build"], function() {
var parts = [readFile("src/CSSOM.js")];
require("./src/files").files.forEach(function(path) {
var text = readFile("lib/" + path + ".js");
parts.push(stripCommonJS(text).trimLeft());
});
FS.writeFileSync("build/CSSOM.js", parts.join(""));
process.stdout.write("build/CSSOM.js is done\n");
});
desc("Creates index file for npm package");
task("lib", ["lib/index.js"]);
file("lib/index.js", ["src/files.js"], function() {
FS.writeFileSync("lib/index.js", "'use strict';\n\n" + require('./src/files').files.map(function(fileName) {
return "exports." + fileName + " = require('./" + fileName + "')." + fileName + ";\n";
}).join(""));
});
CSSOM-0.3.0/MIT-LICENSE.txt 0000664 0000000 0000000 00000002036 12237322307 0014652 0 ustar 00root root 0000000 0000000 Copyright (c) Nikita Vasilyev
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
CSSOM-0.3.0/README.mdown 0000664 0000000 0000000 00000001622 12237322307 0014403 0 ustar 00root root 0000000 0000000 # CSSOM
CSSOM.js is a CSS parser written in pure JavaScript. It also a partial implementation of [CSS Object Model](http://dev.w3.org/csswg/cssom/).
CSSOM.parse("body {color: black}")
-> {
cssRules: [
{
selectorText: "body",
style: {
0: "color",
color: "black",
length: 1
}
}
]
}
## [Parser demo](http://nv.github.com/CSSOM/docs/parse.html)
Works well in Google Chrome 6+, Safari 5+, Firefox 3.6+, Opera 10.63+.
Doesn't work in IE < 9 because of unsupported getters/setters.
To use CSSOM.js in the browser you might want to build a one-file version with [Jake](http://github.com/mde/jake):
➤ jake
build/CSSOM.js is done
To use it with Node.js:
npm install cssom
## [Specs](http://nv.github.com/CSSOM/spec/)
## [Who uses CSSOM.js](https://github.com/NV/CSSOM/wiki/Who-uses-CSSOM.js)
CSSOM-0.3.0/docs/ 0000775 0000000 0000000 00000000000 12237322307 0013327 5 ustar 00root root 0000000 0000000 CSSOM-0.3.0/docs/parse.css 0000664 0000000 0000000 00000002325 12237322307 0015155 0 ustar 00root root 0000000 0000000 html, body {
background: #333;
color: #EEE;
font: 12px sans-serif;
margin: 0;
height: 100%;
}
body {
padding-bottom: 1.7em;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
table {
width: 100%;
table-layout: fixed;
margin: 0 auto;
}
td {
vertical-align: top;
}
h1 {
font: normal 1em sans-serif;
display: inline;
}
pre {
margin-top: 0;
padding: 3px .5em;
font: 12px/15px monospace;
}
#labels {
color: #FFE992;
width: 66%;
}
#labels td {
width: 50%;
text-align: center;
}
#labels td::before {
content: '↱ ';
color: #998e62;
position: relative;
top: .4em;
}
#labels td::after {
content: ' ↴';
color: #998e62;
position: relative;
top: .4em;
}
#content {
width: 100%;
height: 100%;
}
#content td {
width: 33%;
}
#content td + td {
padding-left: 1%;
}
#output span {
color: #666;
}
.style-cell textarea {
width: 99%;
height: 100%;
font: 12px/15px monospace;
white-space: pre-wrap;
padding: 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.serialized-cell {
border-left: 1px solid #363636;
}
#message {
visibility: hidden;
}
.error #message {
visibility: visible;
position: absolute;
top: 0;
left: 34%;
padding: 1em;
background: black;
color: #e34343;
font-size: 24px;
}
CSSOM-0.3.0/docs/parse.html 0000664 0000000 0000000 00000001243 12237322307 0015327 0 ustar 00root root 0000000 0000000
CSSOM.js parse method
CSSOM-0.3.0/docs/parse.js 0000664 0000000 0000000 00000011116 12237322307 0014777 0 ustar 00root root 0000000 0000000 if (!Array.isArray) {
Array.isArray = function(array) {
return {}.toString.call(array) === '[object Array]';
};
}
function byId(id) {
return document.getElementById(id);
}
/**
* @param {number} depth
* @return {string}
*/
function makeIndent(depth) {
var INDENT = ' ';
if (depth === 1) {
return INDENT;
} else if (depth < 1) {
return '';
}
if (depth in makeIndent.cache) {
return makeIndent.cache[depth];
} else {
var result = INDENT;
for (var i = depth; --i;) {
result += INDENT;
}
makeIndent.cache[depth] = result;
return result;
}
}
makeIndent.cache = {};
/**
* stringifyObjectKey('color') -> 'color'
* stringifyObjectKey('background-color') -> '"background-color"'
* @param {string} key
* @return {string}
*/
function stringifyObjectKey(key) {
return /^[a-z0-9_$]+$/i.test(key) ?
key :
JSON.stringify(key);
}
/**
* @param {Object} object
* @return {DocumentFragment}
*/
function inspect(object) {
var root = document.createDocumentFragment();
_inspect(root, object, 0);
return root;
/**
* @param {DocumentFragment} root
* @param {Object} object
* @param {number} depth
*/
function _inspect(root, object, depth) {
switch (typeof object) {
case 'object':
if (!object) {
//null
root.appendChild(document.createTextNode('null'));
break;
}
depth++;
var indent = document.createTextNode(makeIndent(depth));
var span = document.createElement('span');
span.textContent = ',\n';
var comma = span;
if (Array.isArray(object)) {
var length = object.length;
if (length === 0) {
span = span.cloneNode(false);
span.textContent = '[]';
root.appendChild(span);
} else {
span = span.cloneNode(false);
span.textContent = '[\n';
root.appendChild(span);
for (var i = 0; i < length; i++) {
root.appendChild(indent.cloneNode(true));
_inspect(root, object[i], depth);
if (i < length - 1) {
root.appendChild(comma.cloneNode(true));
}
}
span = span.cloneNode(false);
span.textContent = '\n' + makeIndent(depth - 1) + ']';
root.appendChild(span);
}
} else {
var keys = Object.keys(object);
length = keys.length;
if (length === 0) {
span = span.cloneNode(false);
span.textContent = '{}';
root.appendChild(span);
} else {
span = span.cloneNode(false);
span.textContent = '{\n';
root.appendChild(span);
var colon = span.cloneNode(false);
colon.textContent = ': ';
for (i = 0; i < length; i++) {
var key = keys[i];
root.appendChild(indent.cloneNode(true));
root.appendChild(document.createTextNode(stringifyObjectKey(key)));
root.appendChild(colon.cloneNode(true));
_inspect(root, object[key], depth);
if (i < length - 1) {
root.appendChild(comma.cloneNode(true));
}
}
span = span.cloneNode(false);
span.textContent = '\n' + makeIndent(depth - 1) + '}';
root.appendChild(span);
}
}
break;
case 'string':
root.appendChild(document.createTextNode(JSON.stringify(object)));
break;
default:
root.appendChild(document.createTextNode(object.toString()));
}
}
}
var errors = [];
if (!("__defineGetter__" in {})) {
errors.push("Object.prototype.__defineGetter__ isn’t supported");
}
if (errors.length) {
byId("message").innerHTML = errors.join("
");
document.body.className = "error";
throw errors.join("\n\n");
}
var style = byId("style");
var output = byId("output");
var serialized = byId("serialized");
function outputUpdated() {
var value = style.value;
if (value !== style.prevValue) {
style.prevValue = value;
var css = CSSOM.parse(value);
uncircularOwnProperties(css);
output.innerHTML = '';
output.appendChild(inspect(css));
serialized.innerHTML = css.toString();
}
}
/**
* @return {boolean} update happend or not
*/
function hashChanged() {
var hash = location.hash;
var splitted = hash.split("=");
if (splitted.length < 2) {
return false;
}
var name = splitted[0];
var value = splitted[1];
if (name === "#css") {
style.value = decodeURIComponent(value);
outputUpdated();
return true;
}
return false;
}
window.onload = function() {
hashChanged() || outputUpdated();
};
window.onhashchange = hashChanged;
style.onkeyup = style.onpaste = function changed(){
outputUpdated();
};
style.onchange = function updateLocation() {
if (style.value.length < 1024) {
location.hash = "css=" + encodeURIComponent(style.value);
} else {
// Huge location.hash slows down the browser :(
location.hash = 'css_is_too_big';
}
};
CSSOM-0.3.0/lib/ 0000775 0000000 0000000 00000000000 12237322307 0013145 5 ustar 00root root 0000000 0000000 CSSOM-0.3.0/lib/CSSDocumentRule.js 0000664 0000000 0000000 00000002142 12237322307 0016461 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSRule: require("./CSSRule").CSSRule,
MatcherList: require("./MatcherList").MatcherList
};
///CommonJS
/**
* @constructor
* @see https://developer.mozilla.org/en/CSS/@-moz-document
*/
CSSOM.CSSDocumentRule = function CSSDocumentRule() {
CSSOM.CSSRule.call(this);
this.matcher = new CSSOM.MatcherList;
this.cssRules = [];
};
CSSOM.CSSDocumentRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSDocumentRule.prototype.constructor = CSSOM.CSSDocumentRule;
CSSOM.CSSDocumentRule.prototype.type = 10;
//FIXME
//CSSOM.CSSDocumentRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
//CSSOM.CSSDocumentRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
Object.defineProperty(CSSOM.CSSDocumentRule.prototype, "cssText", {
get: function() {
var cssTexts = [];
for (var i=0, length=this.cssRules.length; i < length; i++) {
cssTexts.push(this.cssRules[i].cssText);
}
return "@-moz-document " + this.matcher.matcherText + " {" + cssTexts.join("") + "}";
}
});
//.CommonJS
exports.CSSDocumentRule = CSSOM.CSSDocumentRule;
///CommonJS
CSSOM-0.3.0/lib/CSSFontFaceRule.js 0000664 0000000 0000000 00000002045 12237322307 0016372 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
CSSRule: require("./CSSRule").CSSRule
};
///CommonJS
/**
* @constructor
* @see http://dev.w3.org/csswg/cssom/#css-font-face-rule
*/
CSSOM.CSSFontFaceRule = function CSSFontFaceRule() {
CSSOM.CSSRule.call(this);
this.style = new CSSOM.CSSStyleDeclaration;
this.style.parentRule = this;
};
CSSOM.CSSFontFaceRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSFontFaceRule.prototype.constructor = CSSOM.CSSFontFaceRule;
CSSOM.CSSFontFaceRule.prototype.type = 5;
//FIXME
//CSSOM.CSSFontFaceRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
//CSSOM.CSSFontFaceRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSFontFaceRule.cpp
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", {
get: function() {
return "@font-face {" + this.style.cssText + "}";
}
});
//.CommonJS
exports.CSSFontFaceRule = CSSOM.CSSFontFaceRule;
///CommonJS
CSSOM-0.3.0/lib/CSSImportRule.js 0000664 0000000 0000000 00000006411 12237322307 0016160 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSRule: require("./CSSRule").CSSRule,
CSSStyleSheet: require("./CSSStyleSheet").CSSStyleSheet,
MediaList: require("./MediaList").MediaList
};
///CommonJS
/**
* @constructor
* @see http://dev.w3.org/csswg/cssom/#cssimportrule
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSImportRule
*/
CSSOM.CSSImportRule = function CSSImportRule() {
CSSOM.CSSRule.call(this);
this.href = "";
this.media = new CSSOM.MediaList;
this.styleSheet = new CSSOM.CSSStyleSheet;
};
CSSOM.CSSImportRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSImportRule.prototype.constructor = CSSOM.CSSImportRule;
CSSOM.CSSImportRule.prototype.type = 3;
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 = '';
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;
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 '"':
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;
default:
if (state === 'media') {
buffer += character;
}
break;
}
}
}
});
//.CommonJS
exports.CSSImportRule = CSSOM.CSSImportRule;
///CommonJS
CSSOM-0.3.0/lib/CSSKeyframeRule.js 0000664 0000000 0000000 00000002107 12237322307 0016447 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSRule: require("./CSSRule").CSSRule,
CSSStyleDeclaration: require('./CSSStyleDeclaration').CSSStyleDeclaration
};
///CommonJS
/**
* @constructor
* @see http://www.w3.org/TR/css3-animations/#DOM-CSSKeyframeRule
*/
CSSOM.CSSKeyframeRule = function CSSKeyframeRule() {
CSSOM.CSSRule.call(this);
this.keyText = '';
this.style = new CSSOM.CSSStyleDeclaration;
this.style.parentRule = this;
};
CSSOM.CSSKeyframeRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSKeyframeRule.prototype.constructor = CSSOM.CSSKeyframeRule;
CSSOM.CSSKeyframeRule.prototype.type = 9;
//FIXME
//CSSOM.CSSKeyframeRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
//CSSOM.CSSKeyframeRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframeRule.cpp
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "cssText", {
get: function() {
return this.keyText + " {" + this.style.cssText + "} ";
}
});
//.CommonJS
exports.CSSKeyframeRule = CSSOM.CSSKeyframeRule;
///CommonJS
CSSOM-0.3.0/lib/CSSKeyframesRule.js 0000664 0000000 0000000 00000002227 12237322307 0016635 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSRule: require("./CSSRule").CSSRule
};
///CommonJS
/**
* @constructor
* @see http://www.w3.org/TR/css3-animations/#DOM-CSSKeyframesRule
*/
CSSOM.CSSKeyframesRule = function CSSKeyframesRule() {
CSSOM.CSSRule.call(this);
this.name = '';
this.cssRules = [];
};
CSSOM.CSSKeyframesRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSKeyframesRule.prototype.constructor = CSSOM.CSSKeyframesRule;
CSSOM.CSSKeyframesRule.prototype.type = 8;
//FIXME
//CSSOM.CSSKeyframesRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
//CSSOM.CSSKeyframesRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
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}";
}
});
//.CommonJS
exports.CSSKeyframesRule = CSSOM.CSSKeyframesRule;
///CommonJS
CSSOM-0.3.0/lib/CSSMediaRule.js 0000664 0000000 0000000 00000002254 12237322307 0015726 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSRule: require("./CSSRule").CSSRule,
MediaList: require("./MediaList").MediaList
};
///CommonJS
/**
* @constructor
* @see http://dev.w3.org/csswg/cssom/#cssmediarule
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSMediaRule
*/
CSSOM.CSSMediaRule = function CSSMediaRule() {
CSSOM.CSSRule.call(this);
this.media = new CSSOM.MediaList;
this.cssRules = [];
};
CSSOM.CSSMediaRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSMediaRule.prototype.constructor = CSSOM.CSSMediaRule;
CSSOM.CSSMediaRule.prototype.type = 4;
//FIXME
//CSSOM.CSSMediaRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
//CSSOM.CSSMediaRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
// http://opensource.apple.com/source/WebCore/WebCore-658.28/css/CSSMediaRule.cpp
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("") + "}";
}
});
//.CommonJS
exports.CSSMediaRule = CSSOM.CSSMediaRule;
///CommonJS
CSSOM-0.3.0/lib/CSSRule.js 0000664 0000000 0000000 00000001502 12237322307 0014761 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {};
///CommonJS
/**
* @constructor
* @see http://dev.w3.org/csswg/cssom/#the-cssrule-interface
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule
*/
CSSOM.CSSRule = function CSSRule() {
this.parentRule = null;
this.parentStyleSheet = null;
};
CSSOM.CSSRule.STYLE_RULE = 1;
CSSOM.CSSRule.IMPORT_RULE = 3;
CSSOM.CSSRule.MEDIA_RULE = 4;
CSSOM.CSSRule.FONT_FACE_RULE = 5;
CSSOM.CSSRule.PAGE_RULE = 6;
CSSOM.CSSRule.WEBKIT_KEYFRAMES_RULE = 8;
CSSOM.CSSRule.WEBKIT_KEYFRAME_RULE = 9;
// Obsolete in CSSOM http://dev.w3.org/csswg/cssom/
//CSSOM.CSSRule.UNKNOWN_RULE = 0;
//CSSOM.CSSRule.CHARSET_RULE = 2;
// Never implemented
//CSSOM.CSSRule.VARIABLES_RULE = 7;
CSSOM.CSSRule.prototype = {
constructor: CSSOM.CSSRule
//FIXME
};
//.CommonJS
exports.CSSRule = CSSOM.CSSRule;
///CommonJS
CSSOM-0.3.0/lib/CSSStyleDeclaration.js 0000664 0000000 0000000 00000007007 12237322307 0017326 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {};
///CommonJS
/**
* @constructor
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration
*/
CSSOM.CSSStyleDeclaration = function CSSStyleDeclaration(){
this.length = 0;
this.parentRule = null;
// NON-STANDARD
this._importants = {};
};
CSSOM.CSSStyleDeclaration.prototype = {
constructor: CSSOM.CSSStyleDeclaration,
/**
*
* @param {string} name
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-getPropertyValue
* @return {string} the value of the property if it has been explicitly set for this declaration block.
* Returns the empty string if the property has not been set.
*/
getPropertyValue: function(name) {
return this[name] || "";
},
/**
*
* @param {string} name
* @param {string} value
* @param {string} [priority=null] "important" or null
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-setProperty
*/
setProperty: function(name, value, priority) {
if (this[name]) {
// Property already exist. Overwrite it.
var index = Array.prototype.indexOf.call(this, name);
if (index < 0) {
this[this.length] = name;
this.length++;
}
} else {
// New property.
this[this.length] = name;
this.length++;
}
this[name] = value;
this._importants[name] = priority;
},
/**
*
* @param {string} name
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-removeProperty
* @return {string} the value of the property if it has been explicitly set for this declaration block.
* Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property.
*/
removeProperty: function(name) {
if (!(name in this)) {
return "";
}
var index = Array.prototype.indexOf.call(this, name);
if (index < 0) {
return "";
}
var prevValue = this[name];
this[name] = "";
// That's what WebKit and Opera do
Array.prototype.splice.call(this, index, 1);
// That's what Firefox does
//this[index] = ""
return prevValue;
},
getPropertyCSSValue: function() {
//FIXME
},
/**
*
* @param {String} name
*/
getPropertyPriority: function(name) {
return this._importants[name] || "";
},
/**
* element.style.overflow = "auto"
* element.style.getPropertyShorthand("overflow-x")
* -> "overflow"
*/
getPropertyShorthand: function() {
//FIXME
},
isPropertyImplicit: function() {
//FIXME
},
// Doesn't work in IE < 9
get cssText(){
var properties = [];
for (var i=0, length=this.length; i < length; ++i) {
var name = this[i];
var value = this.getPropertyValue(name);
var priority = this.getPropertyPriority(name);
if (priority) {
priority = " !" + priority;
}
properties[i] = name + ": " + value + priority + ";";
}
return properties.join(" ");
},
set cssText(cssText){
var i, name;
for (i = this.length; i--;) {
name = this[i];
this[name] = "";
}
Array.prototype.splice.call(this, 0, this.length);
this._importants = {};
var dummyRule = CSSOM.parse('#bogus{' + cssText + '}').cssRules[0].style;
var length = dummyRule.length;
for (i = 0; i < length; ++i) {
name = dummyRule[i];
this.setProperty(dummyRule[i], dummyRule.getPropertyValue(name), dummyRule.getPropertyPriority(name));
}
}
};
//.CommonJS
exports.CSSStyleDeclaration = CSSOM.CSSStyleDeclaration;
CSSOM.parse = require('./parse').parse; // Cannot be included sooner due to the mutual dependency between parse.js and CSSStyleDeclaration.js
///CommonJS
CSSOM-0.3.0/lib/CSSStyleRule.js 0000664 0000000 0000000 00000007052 12237322307 0016010 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
CSSRule: require("./CSSRule").CSSRule
};
///CommonJS
/**
* @constructor
* @see http://dev.w3.org/csswg/cssom/#cssstylerule
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleRule
*/
CSSOM.CSSStyleRule = function CSSStyleRule() {
CSSOM.CSSRule.call(this);
this.selectorText = "";
this.style = new CSSOM.CSSStyleDeclaration;
this.style.parentRule = this;
};
CSSOM.CSSStyleRule.prototype = new CSSOM.CSSRule;
CSSOM.CSSStyleRule.prototype.constructor = CSSOM.CSSStyleRule;
CSSOM.CSSStyleRule.prototype.type = 1;
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;
}
});
/**
* NON-STANDARD
* lightweight version of parse.js.
* @param {string} ruleText
* @return CSSStyleRule
*/
CSSOM.CSSStyleRule.parse = function(ruleText) {
var i = 0;
var state = "selector";
var index;
var j = i;
var buffer = "";
var SIGNIFICANT_WHITESPACE = {
"selector": true,
"value": true
};
var styleRule = new CSSOM.CSSStyleRule;
var selector, name, value, priority="";
for (var character; character = ruleText.charAt(i); i++) {
switch (character) {
case " ":
case "\t":
case "\r":
case "\n":
case "\f":
if (SIGNIFICANT_WHITESPACE[state]) {
// Squash 2 or more white-spaces in the row into 1
switch (ruleText.charAt(i - 1)) {
case " ":
case "\t":
case "\r":
case "\n":
case "\f":
break;
default:
buffer += " ";
break;
}
}
break;
// String
case '"':
j = i + 1;
index = ruleText.indexOf('"', j) + 1;
if (!index) {
throw '" is missing';
}
buffer += ruleText.slice(i, index);
i = index - 1;
break;
case "'":
j = i + 1;
index = ruleText.indexOf("'", j) + 1;
if (!index) {
throw "' is missing";
}
buffer += ruleText.slice(i, index);
i = index - 1;
break;
// Comment
case "/":
if (ruleText.charAt(i + 1) === "*") {
i += 2;
index = ruleText.indexOf("*/", i);
if (index === -1) {
throw new SyntaxError("Missing */");
} else {
i = index + 1;
}
} else {
buffer += character;
}
break;
case "{":
if (state === "selector") {
styleRule.selectorText = buffer.trim();
buffer = "";
state = "name";
}
break;
case ":":
if (state === "name") {
name = buffer.trim();
buffer = "";
state = "value";
} else {
buffer += character;
}
break;
case "!":
if (state === "value" && ruleText.indexOf("!important", i) === i) {
priority = "important";
i += "important".length;
} else {
buffer += character;
}
break;
case ";":
if (state === "value") {
styleRule.style.setProperty(name, buffer.trim(), priority);
priority = "";
buffer = "";
state = "name";
} else {
buffer += character;
}
break;
case "}":
if (state === "value") {
styleRule.style.setProperty(name, buffer.trim(), priority);
priority = "";
buffer = "";
} else if (state === "name") {
break;
} else {
buffer += character;
}
state = "selector";
break;
default:
buffer += character;
break;
}
}
return styleRule;
};
//.CommonJS
exports.CSSStyleRule = CSSOM.CSSStyleRule;
///CommonJS
CSSOM-0.3.0/lib/CSSStyleSheet.js 0000664 0000000 0000000 00000004564 12237322307 0016156 0 ustar 00root root 0000000 0000000 //.CommonJS
var CSSOM = {
StyleSheet: require("./StyleSheet").StyleSheet,
CSSStyleRule: require("./CSSStyleRule").CSSStyleRule
};
///CommonJS
/**
* @constructor
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet
*/
CSSOM.CSSStyleSheet = function CSSStyleSheet() {
CSSOM.StyleSheet.call(this);
this.cssRules = [];
};
CSSOM.CSSStyleSheet.prototype = new CSSOM.StyleSheet;
CSSOM.CSSStyleSheet.prototype.constructor = CSSOM.CSSStyleSheet;
/**
* Used to insert a new rule into the style sheet. The new rule now becomes part of the cascade.
*
* sheet = new Sheet("body {margin: 0}")
* sheet.toString()
* -> "body{margin:0;}"
* sheet.insertRule("img {border: none}", 0)
* -> 0
* sheet.toString()
* -> "img{border:none;}body{margin:0;}"
*
* @param {string} rule
* @param {number} index
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet-insertRule
* @return {number} The index within the style sheet's rule collection of the newly inserted rule.
*/
CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
if (index < 0 || index > this.cssRules.length) {
throw new RangeError("INDEX_SIZE_ERR");
}
var cssRule = CSSOM.parse(rule).cssRules[0];
cssRule.parentStyleSheet = this;
this.cssRules.splice(index, 0, cssRule);
return index;
};
/**
* Used to delete a rule from the style sheet.
*
* sheet = new Sheet("img{border:none} body{margin:0}")
* sheet.toString()
* -> "img{border:none;}body{margin:0;}"
* sheet.deleteRule(0)
* sheet.toString()
* -> "body{margin:0;}"
*
* @param {number} index within the style sheet's rule list of the rule to remove.
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet-deleteRule
*/
CSSOM.CSSStyleSheet.prototype.deleteRule = function(index) {
if (index < 0 || index >= this.cssRules.length) {
throw new RangeError("INDEX_SIZE_ERR");
}
this.cssRules.splice(index, 1);
};
/**
* NON-STANDARD
* @return {string} serialize stylesheet
*/
CSSOM.CSSStyleSheet.prototype.toString = function() {
var result = "";
var rules = this.cssRules;
for (var i=0; i