csstext_as2.js 777 0 0 25767 11166132256 6760 0// document.styleSheets[0].cssRules[0].style.getPropertyPriority("display") public final class TextCSSStyleSheet { private var __stylesheet:StyleSheet; private var __cssRules:Array = null; function TextCSSStyleSheet () { this.__stylesheet = new TextField.StyleSheet(); this.__stylesheet.onLoad = this.__bind(this.__handleLoad); } private function __bind (f:Function) :Function { var that = this; return function (...rest) :* { return f.apply(that, rest); } } private function __handleLoad (success:Boolean) :void { if ($debug) { if (success) { Debug.debug('onload'); } else { Debug.warn('onerror'); } } } /** @access private */ function __update (name:String, style:Object) :void { this.__stylesheet.setStyle(name, style); } public static function applyStyleSheet (lztext:LzText, stylesheet:TextCSSStyleSheet) :void { var tfield:TextField = lztext.sprite.__LZtextclip; tfield.styleSheet = stylesheet.__stylesheet; var text = lztext.text; // force reset lztext.text = ""; lztext.setAttribute("text", text); } public static function removeStyleSheet (lztext:LzText) :void { var tfield:TextField = lztext.sprite.__LZtextclip; tfield.styleSheet = null; var text = lztext.text; // force reset lztext.text = ""; lztext.setAttribute("text", text); } public function parse (cssText:String) :void { this.clear(); if (this.__stylesheet.parseCSS(cssText)) { } else if ($debug) { Debug.warn('parse'); } } public function load (url:String) :void { this.clear(); if (this.__stylesheet.load(cssText)) { } else if ($debug) { Debug.warn('load'); } } public function clear () :void { if (this.__cssRules != null) { var rules:Array = this.__cssRules; for (var i:int = 0; i < rules.length; ++i) { rules[i].remove(); } this.__cssRules = null; } this.__stylesheet.clear(); } public function insertRule (rule:String, index:int = -1) :void { if ($debug) { if (index != -1) { Debug.warn('insertRule - index'); } } var tmp:StyleSheet = new TextField.StyleSheet(); if (tmp.parseCSS(rule)) { var rules:Array = this.__cssRules; var stylesheet:StyleSheet = this.__stylesheet; var names:Array = tmp.getStyleNames(); for (var i:int = 0; i < names.length; ++i) { var name:String = names[i]; var style:Object = tmp.getStyle(name); var oldstyle = stylesheet.getStyle(name); if (oldstyle != null) { // TODO remove first? stylesheet.setStyle(name, null); style = this.__mergeStyles(oldstyle, style); } stylesheet.setStyle(name, style); if (rules != null) { // keep cssRules consistent if (oldstyle != null) { // remove old rule for (var j:int = 0; j < rules.length; ++j) { if (rules[j].selectorText == name) { rules[j].remove(); rules.splice(j, 1); break; } } } rules.push(new TextCSSStyleRule(this, name, style)); } } tmp.clear(); } else if ($debug) { Debug.warn('insertRule - parse'); } } /** @access private */ private function __mergeStyles (a:Object, b:Object) :Object { for (var name:String in b) { a[name] = b[name]; } return a; } public function deleteRule (index:int) :void { var rule:TextCSSStyleRule = this.cssRules[index]; if (rule) { rule.remove(); this.__stylesheet.setStyle(rule.selectorText, null); } } Object.addProperty.call(TextCSSStyleSheet.prototype, "cssRules", function () :Array { if (this.__cssRules == null) { var rules:Array = []; var stylesheet:StyleSheet = this.__stylesheet; var names:Array = stylesheet.getStyleNames(); for (var i:int = 0; i < names.length; ++i) { var name:String = names[i]; var style:Object = stylesheet.getStyle(name); rules.push(new TextCSSStyleRule(this, name, style)); } this.__cssRules = rules; } return this.__cssRules; }, null); // make unenumerable ASSetPropFlags(TextCSSStyleSheet.prototype, ["cssRules"], 1, 0); } public final class TextCSSStyleRule { /** @access private */ private var __parentStyleSheet:TextCSSStyleSheet; /** @access private */ private var __selectorText:String; /** @access private */ private var __cssText:String; /** @access private */ private var __style:TextCSSStyleDeclaration; /** @access private */ function TextCSSStyleRule (stylesheet:TextCSSStyleSheet, selectorText:String, style:Object) { this.__parentStyleSheet = stylesheet; this.__selectorText = selectorText; this.__style = new TextCSSStyleDeclaration(this, style); } function remove () :void { this.__parentStyleSheet = null; } // ".operations, .workflowactions, .header, .menu, .footer { display: none; }" Object.addProperty.call(TextCSSStyleRule.prototype, "cssText", function () :String { return this.selectorText + "{\n" + this.style.cssText + "\n}"; }, function (t:String) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of rule than the current one. // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at this point in the style sheet. // NO_MODIFICATION_ALLOWED_ERR: Raised if the rule is readonly. }); Object.addProperty.call(TextCSSStyleRule.prototype, "parentStyleSheet", function () :TextCSSStyleSheet { return this.__parentStyleSheet; }, null); // ".operations, .workflowactions, .header, .menu, .footer" Object.addProperty.call(TextCSSStyleRule.prototype, "selectorText", function () :String { return this.__selectorText; }, function (s:String) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly. }); Object.addProperty.call(TextCSSStyleRule.prototype, "style", function () :TextCSSStyleDeclaration { return this.__style; }, null); // make unenumerable ASSetPropFlags(TextCSSStyleRule.prototype, ["cssText", "parentStyleSheet", "selectorText", "style"], 1, 0); } public final class TextCSSStyleDeclaration { /** @access private */ private var __parentRule:TextCSSStyleRule; /** @access private */ private var __items:Array; /** @access private */ private var __properties:Object; /** @access private */ function TextCSSStyleDeclaration (parentRule:TextCSSStyleRule, style:Object) { var items:Array = []; for (var item:String in style) { items.push(item); } this.__parentRule = parentRule; this.__items = items; this.__properties = style || {}; } Object.addProperty.call(TextCSSStyleDeclaration.prototype, "parentRule", function () :TextCSSStyleRule { return this.__parentRule; }, null); Object.addProperty.call(TextCSSStyleDeclaration.prototype, "length", function () :int { return this.__items.length; }, null); // "display" public function item (index:int) :String { return this.__items[index] || ""; } // "display: none;" Object.addProperty.call(TextCSSStyleDeclaration.prototype, "cssText", function () :String { var props:Object = this.__properties; var cssText:String = ""; for (var item:String in props) { cssText += item + ": " + props[item] + ";\n"; } // remove trailing \n return cssText.substring(0, cssText.length - 1); }, function (s:String) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or a property is readonly. }); // "none" public function getPropertyValue (propertyName:String) :String { return this.__properties[propertyName] || ""; } // NYI // public function getPropertyCSSValue (propertyName:String) :CSSValue { // } public function removeProperty (propertyName) :String { // raises(DOMException) // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. var value:* = this.__properties[propertyName]; if (value != null) { delete this.__properties[propertyName]; var items:Array = this.__items; for (var i:int = 0; i < items.length; ++i) { if (items[i] == propertyName) { items.splice(i, 1); break; } } this.parentRule.parentStyleSheet.__update(this.parentRule.selectorText, this.__properties); } return value || ""; } public function getPropertyPriority (propertyName:String) :String { return ""; } public function setProperty (propertyName:String, value:String, priority:String = "") :void { // raises(DOMException) // SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. if ($debug) { if (priority != "") { Debug.warn("priority"); } } this.__properties[propertyName] = value; this.parentRule.parentStyleSheet.__update(this.parentRule.selectorText, this.__properties); } // make unenumerable ASSetPropFlags(TextCSSStyleDeclaration.prototype, ["parentRule", "length", "cssText"], 1, 0); } csstext_as3.js 777 0 0 25152 11166136220 6740 0public final class TextCSSStyleSheet { #passthrough (toplevel:true) { import flash.events.Event; import flash.events.IOErrorEvent; import flash.events.SecurityErrorEvent; import flash.net.URLLoader; import flash.net.URLRequest; import flash.text.StyleSheet; import flash.text.TextField; }# #passthrough { private var __stylesheet:StyleSheet; private var __cssRules:Array = null; private var __loader:URLLoader = null; function TextCSSStyleSheet () { this.__stylesheet = new StyleSheet(); } private function __handleComplete (event:Event) :void { if ($debug) { Debug.debug('onload'); } this.parse(event.target.data); } private function __handleError (event:IOErrorEvent) :void { if ($debug) { Debug.warn('onerror'); } } /** @access private */ function __update (name:String, style:Object) :void { this.__stylesheet.setStyle(name, style); } public static function applyStyleSheet (lztext:LzText, stylesheet:TextCSSStyleSheet) :void { var tfield:TextField = (lztext.sprite as LzTextSprite).textfield; tfield.styleSheet = stylesheet.__stylesheet; var text = lztext.text; // force reset lztext.text = ""; lztext.setAttribute("text", text); } public static function removeStyleSheet (lztext:LzText) :void { var tfield:TextField = (lztext.sprite as LzTextSprite).textfield; tfield.styleSheet = null; var text = lztext.text; // force reset lztext.text = ""; lztext.setAttribute("text", text); } public function parse (cssText:String) :void { this.clear(); this.__stylesheet.parseCSS(cssText); } public function load (url:String) :void { var loader:URLLoader = this.__loader; if (loader == null) { this.__loader = loader = new URLLoader(); } loader.addEventListener(Event.COMPLETE, this.__handleComplete); loader.addEventListener(IOErrorEvent.IO_ERROR, this.__handleError); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.__handleError); loader.load(new URLRequest(url)); } public function clear () :void { if (this.__cssRules != null) { var rules:Array = this.__cssRules; for (var i:int = 0; i < rules.length; ++i) { rules[i].remove(); } this.__cssRules = null; } this.__stylesheet.clear(); } public function insertRule (rule:String, index:int = -1) :void { if ($debug) { if (index != -1) { Debug.warn('insertRule - index'); } } var tmp:StyleSheet = new StyleSheet(); if (tmp.parseCSS(rule)) { var rules:Array = this.__cssRules; var stylesheet:StyleSheet = this.__stylesheet; var names:Array = tmp.styleNames; for (var i:int = 0; i < names.length; ++i) { var name:String = names[i]; var style:Object = tmp.getStyle(name); var oldstyle = stylesheet.getStyle(name); if (oldstyle != null) { // TODO remove first? stylesheet.setStyle(name, null); style = this.__mergeStyles(oldstyle, style); } stylesheet.setStyle(name, style); if (rules != null) { // keep cssRules consistent if (oldstyle != null) { // remove old rule for (var j:int = 0; j < rules.length; ++j) { if (rules[j].selectorText == name) { rules[j].remove(); rules.splice(j, 1); break; } } } rules.push(new TextCSSStyleRule(this, name, style)); } } tmp.clear(); } else if ($debug) { Debug.warn('insertRule - parse'); } } /** @access private */ private function __mergeStyles (a:Object, b:Object) :Object { for (var name:String in b) { a[name] = b[name]; } return a; } public function deleteRule (index:int) :void { var rule:TextCSSStyleRule = this.cssRules[index]; if (rule) { rule.remove(); this.__stylesheet.setStyle(rule.selectorText, null); } } public function get cssRules () :Array { if (this.__cssRules == null) { var rules:Array = []; var stylesheet:StyleSheet = this.__stylesheet; var names:Array = stylesheet.styleNames; for (var i:int = 0; i < names.length; ++i) { var name:String = names[i]; var style:Object = stylesheet.getStyle(name); rules.push(new TextCSSStyleRule(this, name, style)); } this.__cssRules = rules; } return this.__cssRules; } }# } public final class TextCSSStyleRule { #passthrough { /** @access private */ private var __parentStyleSheet:TextCSSStyleSheet; /** @access private */ private var __selectorText:String; /** @access private */ private var __cssText:String; /** @access private */ private var __style:TextCSSStyleDeclaration; /** @access private */ function TextCSSStyleRule (stylesheet:TextCSSStyleSheet, selectorText:String, style:Object) { this.__parentStyleSheet = stylesheet; this.__selectorText = selectorText; this.__style = new TextCSSStyleDeclaration(this, style); } function remove () :void { this.__parentStyleSheet = null; } // ".operations, .workflowactions, .header, .menu, .footer { display: none; }" public function get cssText () :String { return this.selectorText + "{\n" + this.style.cssText + "\n}" } public function set cssText (t) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of rule than the current one. // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at this point in the style sheet. // NO_MODIFICATION_ALLOWED_ERR: Raised if the rule is readonly. } public function get parentStyleSheet () :TextCSSStyleSheet { return this.__parentStyleSheet; } // ".operations, .workflowactions, .header, .menu, .footer" public function get selectorText () :String { return this.__selectorText; } public function set selectorText (s:String) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly. } public function get style () :TextCSSStyleDeclaration { return this.__style; } }# } public final class TextCSSStyleDeclaration { #passthrough { /** @access private */ private var __parentRule:TextCSSStyleRule; /** @access private */ private var __items:Array; /** @access private */ private var __properties:Object; /** @access private */ function TextCSSStyleDeclaration (parentRule:TextCSSStyleRule, style:Object) { var items:Array = []; for (var item:String in style) { items.push(item); } this.__parentRule = parentRule; this.__items = items; this.__properties = style; } public function get parentRule () :TextCSSStyleRule { return this.__parentRule; } public function get length () :int { return this.__items.length; } // "display" public function item (index:int) :String { return this.__items[index] || ""; } // "display: none;" public function get cssText () :String { var props:Object = this.__properties; var cssText:String = ""; for (var item:String in props) { cssText += item + ": " + props[item] + ";\n"; } // remove trailing \n return cssText.substring(cssText.length - 1); } public function set cssText (s:String) :void { // raises(DOMException) on setting: // SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or a property is readonly. } // "none" public function getPropertyValue (propertyName:String) :String { return this.__properties[propertyName] || ""; } // NYI // public function getPropertyCSSValue (propertyName:String) :CSSValue { // } public function removeProperty (propertyName) :String { // raises(DOMException) // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. var value:* = this.__properties[propertyName]; if (value != null) { delete this.__properties[propertyName]; var items:Array = this.__items; for (var i:int = 0; i < items.length; ++i) { if (items[i] == propertyName) { items.splice(i, 1); break; } } this.parentRule.parentStyleSheet.__update(this.parentRule.selectorText, this.__properties); } return value || ""; } public function getPropertyPriority (propertyName:String) :String { return ""; } public function setProperty (propertyName:String, value:String, priority:String = "") :void { // raises(DOMException) // SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable. // NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. if ($debug) { if (priority != "") { Debug.warn("priority"); } } this.__properties[propertyName] = value; this.parentRule.parentStyleSheet.__update(this.parentRule.selectorText, this.__properties); } }# } csstext_test.lzx 777 0 0 3555 11166233313 7416 0