IT戦記

プログラミング、起業などについて書いているプログラマーのブログです😚

DOM 2 Style の JavaScript オブジェクト

CSS のデータを扱う JavaScript を書きたくて作った

いろいろと使えそうなので晒しておきます
まだ、インタフェースだけですよ><

var JSCSS = {};

// http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-StyleSheet
JSCSS.StyleSheet = function(type, disabled, ownerNode, parentStyleSheet, href, title, media) {
    this.type = type;
    this.disabled = disabled;
    this.ownerNode = ownerNode;
    this.parentStyleSheet = parentStyleSheet;
    this.href = href;
    this.title = title;
    this.media = media;
};
JSCSS.StyleSheet.prototype = {
    type : null,
    disabled : null,
    ownerNode : null,
    parentStyleSheet : null,
    href : null,
    title : null,
    media : null,
    constructor: JSCSS.StyleSheet
};

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet
JSCSS.CSSStyleSheet = function(type, disabled, ownerNode, parentStyleSheet, href, title, media, ownerRule, cssRules) {
    JSCSS.StyleSheet.apply(arguments, this);
    this.ownerRule = ownerRule;
    this.cssRules = cssRules;
};
JSCSS.CSSStyleSheet.prototype = new JSCSS.StyleSheet(null, null, null, null, null, null, null);
JSCSS.CSSStyleSheet.prototype.ownerRule = null;
JSCSS.CSSStyleSheet.prototype.cssRules = null;
JSCSS.CSSStyleSheet.prototype.insertRule = function(rule, index) {
    this.cssRules.splice(index, 0, rule);
    return index;
};
JSCSS.CSSStyleSheet.prototype.deleteRule = function(index) {
    this.cssRules.splice(index, 1);
};
JSCSS.CSSStyleSheet.prototype.constructor = JSCSS.CSSStyleSheet;

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRuleList
JSCSS.CSSRuleList = function() {
    var self = [];
    self.item = JSCSS.CSSRuleList.prototype.item;
    self.constructor = JSCSS.CSSRuleList;
    return self;
};
JSCSS.CSSRuleList.prototype = {
    item: function(index) {
        return this[index];
    }
}


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule
JSCSS.CSSRule = function(type, cssText, parentStyleSheet, parentRule) {
    this.type = type;
    this.cssText = cssText;
    this.parentStyleSheet = parentStyleSheet;
    this.parentRule = parentRule;
};
JSCSS.CSSRule.prototype = {
    UNKNOWN_RULE: 0,
    STYLE_RULE: 1,
    CHARSET_RULE: 2,
    IMPORT_RULE: 3,
    MEDIA_RULE: 4,
    FONT_FACE_RULE: 5,
    PAGE_RULE: 6,
    type: null,
    cssText: null,
    parentStyleSheet: null,
    parentRule: null,
    constructor: JSCSS.CSSRule
};
JSCSS.CSSRule.UNKNOWN_RULE = JSCSS.CSSRule.prototype.UNKNOWN_RULE;
JSCSS.CSSRule.STYLE_RULE = JSCSS.CSSRule.prototype.STYLE_RULE;
JSCSS.CSSRule.CHARSET_RULE = JSCSS.CSSRule.prototype.CHARSET_RULE;
JSCSS.CSSRule.IMPORT_RULE = JSCSS.CSSRule.prototype.IMPORT_RULE;
JSCSS.CSSRule.MEDIA_RULE = JSCSS.CSSRule.prototype.MEDIA_RULE;
JSCSS.CSSRule.FONT_FACE_RULE = JSCSS.CSSRule.prototype.FONT_FACE_RULE;
JSCSS.CSSRule.PAGE_RULE = JSCSS.CSSRule.prototype.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleRule
JSCSS.CSSStyleRule = function(type, cssText, parentStyleSheet, parentRule, selectorText, style) {
    JSCSS.CSSRule.apply(arguments, this);
    this.selectorText = selectorText;
    this.style = style;
};
JSCSS.CSSStyleRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSStyleRule.prototype.selectorText = null;
JSCSS.CSSStyleRule.prototype.style = null;
JSCSS.CSSStyleRule.prototype.constructor = JSCSS.CSSStyleRule;
JSCSS.CSSStyleRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSStyleRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSStyleRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSStyleRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSStyleRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSStyleRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSStyleRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSMediaRule
JSCSS.CSSMediaRule = function(type, cssText, parentStyleSheet, parentRule, media, cssRules) {
    JSCSS.CSSRule.apply(arguments, this);
    this.media = media;
    this.cssRules = cssRules;
};
JSCSS.CSSMediaRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSMediaRule.prototype.media = null;
JSCSS.CSSMediaRule.prototype.cssRules = null;
JSCSS.CSSMediaRule.prototype.insertRule = function(rule, index) {
    this.cssRules.splice(index, 0, rule);
    return index;
};
JSCSS.CSSMediaRule.prototype.deleteRule = function(index) {
    this.cssRules.splice(index, 1);
};
JSCSS.CSSMediaRule.prototype.constructor = JSCSS.CSSMediaRule;
JSCSS.CSSMediaRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSMediaRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSMediaRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSMediaRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSMediaRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSMediaRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSMediaRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSFontFaceRule
JSCSS.CSSFontFaceRule = function(type, cssText, parentStyleSheet, parentRule, style) {
    JSCSS.CSSRule.apply(arguments, this);
    this.style = style;
};
JSCSS.CSSFontFaceRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSFontFaceRule.prototype.style = null;
JSCSS.CSSFontFaceRule.prototype.constructor = JSCSS.CSSFontFaceRule;
JSCSS.CSSFontFaceRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSFontFaceRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSFontFaceRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSFontFaceRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSFontFaceRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSFontFaceRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSFontFaceRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSPageRule
JSCSS.CSSPageRule = function(type, cssText, parentStyleSheet, parentRule, selectorText, style) {
    JSCSS.CSSRule.apply(arguments, this);
    this.selectorText = selectorText;
    this.style = style;
};
JSCSS.CSSPageRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSPageRule.prototype.selectorText = null;
JSCSS.CSSPageRule.prototype.style = null;
JSCSS.CSSPageRule.prototype.constructor = JSCSS.CSSPageRule;
JSCSS.CSSPageRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSPageRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSPageRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSPageRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSPageRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSPageRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSPageRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSImportRule
JSCSS.CSSImportRule = function(type, cssText, parentStyleSheet, parentRule, href, media, styleSheet) {
    JSCSS.CSSRule.apply(arguments, this);
    this.href = href;
    this.media = media;
    this.styleSheet = styleSheet;
};
JSCSS.CSSImportRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSImportRule.prototype.href = null;
JSCSS.CSSImportRule.prototype.media = null;
JSCSS.CSSImportRule.prototype.styleSheet = null;
JSCSS.CSSImportRule.prototype.constructor = JSCSS.CSSImportRule;
JSCSS.CSSImportRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSImportRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSImportRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSImportRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSImportRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSImportRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSImportRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSCharsetRule
JSCSS.CSSCharsetRule = function(type, cssText, parentStyleSheet, parentRule, encoding) {
    JSCSS.CSSRule.apply(arguments, this);
    this.encoding = encoding;
};
JSCSS.CSSCharsetRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSCharsetRule.prototype.encoding = null;
JSCSS.CSSCharsetRule.prototype.constructor = JSCSS.CSSCharsetRule;
JSCSS.CSSCharsetRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSCharsetRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSCharsetRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSCharsetRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSCharsetRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSCharsetRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSCharsetRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSUnknownRule
JSCSS.CSSUnknownRule = function(type, cssText, parentStyleSheet, parentRule) {
    JSCSS.CSSRule.apply(arguments, this);
};
JSCSS.CSSUnknownRule.prototype = new JSCSS.CSSRule(null, null, null, null);
JSCSS.CSSUnknownRule.prototype.constructor = JSCSS.CSSUnknownRule;
JSCSS.CSSUnknownRule.UNKNOWN_RULE = JSCSS.CSSRule.UNKNOWN_RULE;
JSCSS.CSSUnknownRule.STYLE_RULE = JSCSS.CSSRule.STYLE_RULE;
JSCSS.CSSUnknownRule.CHARSET_RULE = JSCSS.CSSRule.CHARSET_RULE;
JSCSS.CSSUnknownRule.IMPORT_RULE = JSCSS.CSSRule.IMPORT_RULE;
JSCSS.CSSUnknownRule.MEDIA_RULE = JSCSS.CSSRule.MEDIA_RULE;
JSCSS.CSSUnknownRule.FONT_FACE_RULE = JSCSS.CSSRule.FONT_FACE_RULE;
JSCSS.CSSUnknownRule.PAGE_RULE = JSCSS.CSSRule.PAGE_RULE;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration
JSCSS.CSSStyleDeclaration = function(cssText, parentRule) {
    this.cssText = cssText;
    this.parentRule = parentRule;
};
JSCSS.CSSStyleDeclaration.prototype = {
    cssText: null,
    parentRule: null,
    length: 0,
    item: function(index) {
        return this[index];
    },
    getPropertyValue: function(propertyName) {
        return this[propertyName];
    },
    getPropertyCSSValue: function(propertyName) {
        return this.cssValues[propertyName];
    },
    removePropertyCSSValue: function(propertyName) {
        delete this.cssValue[peropertyName];
        // TODO: length
        // TODO: return 
    },
    getPropertyPriority: function(propertyName) {
        return this.cssPriority[propertyName];
    },
    setPriority: function(propertyName, value, priority) {
        // TODO
    },
    constructor: JSCSS.CSSStyleDeclaration
};


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSValue
JSCSS.CSSValue = function(cssText, cssValueType) {
    this.cssText = cssText;
    this.cssValueType = cssValueType;
};
JSCSS.CSSValue.prototype = {
    CSS_INHERIT: 0,
    CSS_PRIMITIVE_VALUE: 1,
    CSS_VALUE_LIST: 2,
    CSS_CUSTOM: 3,
    cssText: null,
    cssValueType: null,
    constructor: JSCSS.CSSValue
};
JSCSS.CSSValue.CSS_INHERIT = JSCSS.CSSValue.prototype.CSS_INHERIT
JSCSS.CSSValue.CSS_PRIMITIVE_VALUE = JSCSS.CSSValue.prototype.CSS_PRIMITIVE_VALUE
JSCSS.CSSValue.CSS_VALUE_LIST = JSCSS.CSSValue.prototype.CSS_VALUE_LIST
JSCSS.CSSValue.CSS_CUSTOM = JSCSS.CSSValue.prototype.CSS_CUSTOM


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSPrimitiveValue
JSCSS.CSSPrimitiveValue = function(cssText, cssValueType, primitiveType) {
    JSCSS.CSSValue.apply(arguments, this);
};
JSCSS.CSSPrimitiveValue.prototype = new JSCSS.CSSValue(null, null);
JSCSS.PrimitiveValue.prorotype.setFloatValue = function(unitType, floatValue) {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.getFloatValue = function(unitType) {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.setStringValue = function(stringType, stringValue) {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.getStringValue = function() {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.getCounterValue = function() {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.getRectValue = function() {
    // TODO
};
JSCSS.PrimitiveValue.prorotype.getRGBColorValue = function() {
    // TODO
};
JSCSS.CSSPrimitiveValue.prototype.primitiveType = null;
JSCSS.CSSPrimitiveValue.prototype.CSS_UNKNOWN = JSCSS.CSSPrimitiveValue.CSS_UNKNOWN = 0;
JSCSS.CSSPrimitiveValue.prototype.CSS_NUMBER = JSCSS.CSSPrimitiveValue.CSS_NUMBER = 1;
JSCSS.CSSPrimitiveValue.prototype.CSS_PERCENTAGE = JSCSS.CSSPrimitiveValue.CSS_PERCENTAGE = 2;
JSCSS.CSSPrimitiveValue.prototype.CSS_EMS = JSCSS.CSSPrimitiveValue.CSS_EMS = 3;
JSCSS.CSSPrimitiveValue.prototype.CSS_EXS = JSCSS.CSSPrimitiveValue.CSS_EXS = 4;
JSCSS.CSSPrimitiveValue.prototype.CSS_PX = JSCSS.CSSPrimitiveValue.CSS_PX = 5;
JSCSS.CSSPrimitiveValue.prototype.CSS_CM = JSCSS.CSSPrimitiveValue.CSS_CM = 6;
JSCSS.CSSPrimitiveValue.prototype.CSS_MM = JSCSS.CSSPrimitiveValue.CSS_MM = 7;
JSCSS.CSSPrimitiveValue.prototype.CSS_IN = JSCSS.CSSPrimitiveValue.CSS_IN = 8;
JSCSS.CSSPrimitiveValue.prototype.CSS_PT = JSCSS.CSSPrimitiveValue.CSS_PT = 9;
JSCSS.CSSPrimitiveValue.prototype.CSS_PC = JSCSS.CSSPrimitiveValue.CSS_PC = 10;
JSCSS.CSSPrimitiveValue.prototype.CSS_DEG = JSCSS.CSSPrimitiveValue.CSS_DEG = 11;
JSCSS.CSSPrimitiveValue.prototype.CSS_RAD = JSCSS.CSSPrimitiveValue.CSS_RAD = 12;
JSCSS.CSSPrimitiveValue.prototype.CSS_GRAD = JSCSS.CSSPrimitiveValue.CSS_GRAD = 13;
JSCSS.CSSPrimitiveValue.prototype.CSS_MS = JSCSS.CSSPrimitiveValue.CSS_MS = 14;
JSCSS.CSSPrimitiveValue.prototype.CSS_S = JSCSS.CSSPrimitiveValue.CSS_S = 15;
JSCSS.CSSPrimitiveValue.prototype.CSS_HZ = JSCSS.CSSPrimitiveValue.CSS_HZ = 16;
JSCSS.CSSPrimitiveValue.prototype.CSS_KHZ = JSCSS.CSSPrimitiveValue.CSS_KHZ = 17;
JSCSS.CSSPrimitiveValue.prototype.CSS_DIMENSION = JSCSS.CSSPrimitiveValue.CSS_DIMENSION = 18;
JSCSS.CSSPrimitiveValue.prototype.CSS_STRING = JSCSS.CSSPrimitiveValue.CSS_STRING = 19;
JSCSS.CSSPrimitiveValue.prototype.CSS_URI = JSCSS.CSSPrimitiveValue.CSS_URI = 20;
JSCSS.CSSPrimitiveValue.prototype.CSS_IDENT = JSCSS.CSSPrimitiveValue.CSS_IDENT = 21;
JSCSS.CSSPrimitiveValue.prototype.CSS_ATTR = JSCSS.CSSPrimitiveValue.CSS_ATTR = 22;
JSCSS.CSSPrimitiveValue.prototype.CSS_COUNTER = JSCSS.CSSPrimitiveValue.CSS_COUNTER = 23;
JSCSS.CSSPrimitiveValue.prototype.CSS_RECT = JSCSS.CSSPrimitiveValue.CSS_RECT = 24;
JSCSS.CSSPrimitiveValue.prototype.CSS_RGBCOLOR = JSCSS.CSSPrimitiveValue.CSS_RGBCOLOR = 25;


// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSValueList
JSCSS.CSSValueList = function(cssText, cssValueType, primitiveType) {
    var self = [];
    JSCSS.CSSValue.apply(arguments, self);
    for (var name in JSCSS.CSSValueList.prototype) {
        self[name] = JSCSS.CSSValueList.prototype[name];
    }
    return self;
};
JSCSS.CSSValueList.prototype = new JSCSS.CSSValue(null, null);
JSCSS.CSSValueList.prototype.item = function(index) {
    return this[index];
};
JSCSS.CSSValueList.prototype.constructor = JSCSS.CSSValueList;
JSCSS.CSSValueList.CSS_INHERIT = JSCSS.CSSValue.CSS_INHERIT
JSCSS.CSSValueList.CSS_PRIMITIVE_VALUE = JSCSS.CSSValue.CSS_PRIMITIVE_VALUE
JSCSS.CSSValueList.CSS_VALUE_LIST = JSCSS.CSSValue.CSS_VALUE_LIST
JSCSS.CSSValueList.CSS_CUSTOM = JSCSS.CSSValue.CSS_CUSTOM

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-RGBColor
JSCSS.RGBColor = function(red, green, blue) {
    this.red = red;
    this.green = green;
    this.blue = blue;
};
JSCSS.RGBColor.prototype = {
    red: null,
    green: null,
    blue: null,
    constructor: JSCSS.RGBColor
};

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-Rect
JSCSS.Rect = function(top, right, bottom, left) {
    this.top = top;
    this.right = right;
    this.bottom = bottom;
    this.left = left;
};
JSCSS.Rect.prototype = {
    top: null,
    right: null,
    bottom: null,
    left: null,
    constructor: JSCSS.Rect
};

// http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-Counter
JSCSS.Counter = function() {
    this.identifier = identifier;
    this.listStyle = listStyle;
    this.separator = separator;
};
JSCSS.Counter.prototype = {
    identifier: null,
    listStyle: null,
    separator: null,
    constructor: JSCSS.Counter
};