import TextFormat from "./TextFormat"; import EventDispatcher from "../events/EventDispatcher"; declare namespace openfl.text { /** * The StyleSheet class lets you create a StyleSheet object that contains text formatting rules * for font size, color, and other styles. You can then apply styles defined by a style sheet to * a TextField object that contains HTML- or XML-formatted text. The text in the TextField object * is automatically formatted according to the tag styles defined by the StyleSheet object. You * can use text styles to define new formatting tags, redefine built-in HTML tags, or create style * classes that you can apply to certain HTML tags. * * To apply styles to a TextField object, assign the StyleSheet object to a TextField object's * `styleSheet` property. * * *Note:* A text field with a style sheet is not editable. In other words, a text field with the * type property set to TextFieldType.INPUT applies the StyleSheet to the default text for the text * field, but the content will no longer be editable by the user. Consider using the TextFormat * class to assign styles to input text fields. * * Flash Player supports a subset of properties in the original CSS1 specification * ([https://www.w3.org/TR/REC-CSS1](www.w3.org/TR/REC-CSS1)). The following table shows the * supported Cascading Style Sheet (CSS) properties and values, as well as their corresponding * Haxe property names. (Each Haxe property name is derived from the corresponding * CSS property name; if the name contains a hyphen, the hyphen is omitted and the subsequent * character is capitalized.) * * | CSS property | Haxe property | Usage and supported values | * | --- | --- | --- | * | `color` | `color` | Only hexadecimal color values are supported. Named colors (such as blue) are not supported. Colors are written in the following format: `#FF0000`. | * | `display` | `display` | Supported values are `inline`, `block`, and `none`. | * | `font-family` | `fontFamily` | A comma-separated list of fonts to use, in descending order of desirability. Any font family name can be used. If you specify a generic font name, it is converted to an appropriate device font. The following font conversions are available: `mono` is converted to `_typewriter`, `sans-serif` is converted to `_sans`, and `serif` is converted to `_serif`. | * | `font-size` | `fontSize` | Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. | * | `font-style` | `fontStyle` | Recognized values are `normal` and `italic`. | * | `font-weight` | `fontWeight` | Recognized values are `normal` and `bold`. | * | `kerning` | `kerning` | Recognized values are `true` and `false`. Kerning is supported for embedded fonts only. Certain fonts, such as Courier New, do not support kerning. The kerning property is only supported in SWF files created in Windows, not in SWF files created on the Macintosh. However, these SWF files can be played in non-Windows versions of Flash Player and the kerning still applies. | * | `leading` | `leading` | The amount of space that is uniformly distributed between lines. The value specifies the number of pixels that are added after each line. A negative value condenses the space between lines. Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. | * | `letter-spacing` | `letterSpacing` | The amount of space that is uniformly distributed between characters. The value specifies the number of pixels that are added after each character. A negative value condenses the space between characters. Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. | * | `margin-left` | `marginLeft` | Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. | * | `text-align` | `textAlign` | Recognized values are `left`, `center`, `right`, and `justify`. | * | `text-decoration` | `textDecoration` | Recognized values are `none` and `underline`. | * | `text-indent` | `textIndent` | Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. | * * @see [Formatting text](https://books.openfl.org/openfl-developers-guide/using-the-textfield-class/formatting-text.html) * @see `openfl.text.TextField` * */ export class StyleSheet extends EventDispatcher { /** * Creates a new StyleSheet object. * */ constructor(); /** * An array that contains the names (as strings) of all of the styles registered in this style sheet. * */ get styleNames(): Array; /** * Removes all styles from the style sheet object. * */ clear(): void; /** * Returns a copy of the style object associated with the style named `styleName`. * If there is no style object associated with `styleName`, `null` is returned. * * @param styleName A string that specifies the name of the style to retrieve. * @return An object. * */ getStyle(styleName: string): any; /** * Parses the CSS in `CSSText` and loads the style sheet with it. If a style * in `CSSText` is already in `styleSheet`, the properties in `styleSheet` are * retained, and only the ones in `CSSText` are added or changed in `styleSheet`. * * To extend the native CSS parsing capability, you can override this method * by creating a subclass of the StyleSheet class. * * @param CSSText The CSS text to parse (a string). * */ parseCSS(CSSText: string): void; /** * Adds a new style with the specified name to the style sheet object. If * the named style does not already exist in the style sheet, it is added. * If the named style already exists in the style sheet, it is replaced. * If the styleObject parameter is null, the named style is removed. * * Flash Player creates a copy of the style object that you pass to this method. * * For a list of supported styles, see the table in the description for the * StyleSheet class. * * @param styleName A string that specifies the name of the style to add to the style sheet. * @param styleObject An object that describes the style, or `null`. * */ setStyle(styleName: string, styleObject: any): void; /** * Extends the CSS parsing capability. Advanced developers can override this * method by extending the StyleSheet class. * * @param formatObject An object that describes the style, containing style rules as properties of the object, or `null`. * @return A TextFormat object containing the result of the mapping of CSS rules to text format properties. * */ transform(formatObject: any): TextFormat; } } export default openfl.text.StyleSheet;