Skip to content

InlineStyle

Create an inline CSS style with protection levels.

Diagram

100%Ctrl + wheel to zoom

Constructor

ts
new InlineStyle(styleObject: { [key: string]: string }, protectionLevel?: ProtectionLevel)
ArgumentTypeDescription
styleObject{ [key: string]: string }CSS properties.
protectionLevelProtectionLevelValidation strictness.

Properties

PropertyTypeDescription
textstringInline CSS string.
ansistringANSI sequence representation (when available).

Methods

.generate()

Generates the inline CSS string.

.addStyleWithObject(styleObject: object)

Adds styles from an object. Returns this.

ArgumentTypeDescription
styleObjectobjectCSS properties to merge.

.addStyleWithInlineCSS(inlineCSS: string)

Adds styles from an inline CSS string. Returns this.

ArgumentTypeDescription
inlineCSSstringInline CSS to merge.

.removeStyle(styles: string[] | string)

Removes styles by name. Returns this.

ArgumentTypeDescription
styles`string[]string`

.applyTo(element: HTMLElement)

Applies the style to a DOM element. Returns this.

ArgumentTypeDescription
elementHTMLElementTarget element.

Example

ts
const style = new InlineStyle({ color: "red", fontSize: "16px" }, "boundary");
style.addStyleWithObject({ backgroundColor: "blue" }).removeStyle("fontSize").applyTo(document.getElementById("myElement"));