Provides a managed dynamic style sheet / element useful in configuring global CSS variables. When creating an instance of TJSStyleManager you must provide a "document key" / string for the style element added. The style element can be accessed via document[docKey].

Instances of TJSStyleManager can also be versioned by supplying a positive integer greater than or equal to 1 via the 'version' option. This version number is assigned to the associated style element. When a TJSStyleManager instance is created and there is an existing instance with a version that is lower than the current instance all CSS rules are removed letting the higher version to take precedence. This isn't a perfect system and requires thoughtful construction of CSS variables exposed, but allows multiple independently compiled TRL packages to load the latest CSS variables. It is recommended to always set overwrite option of TJSStyleManager.setProperty and TJSStyleManager.setProperties to false when loading initial values.

Constructors

  • Parameters

    • Optionalopts: {
          docKey: string;
          document?: Document;
          selector?: string;
          version?: number;
      }

      Options.

      • docKey: string

        Required key providing a link to a specific style sheet element.

      • Optionaldocument?: Document

        Target document to load styles into.

      • Optionalselector?: string

        Selector element.

      • Optionalversion?: number

        An integer representing the version / level of styles being managed.

    Returns TJSStyleManager

Accessors

  • get cssText(): string
  • Returns string

    Provides an accessor to get the cssText for the style sheet.

  • get version(): number
  • Returns number

    Returns the version of this instance.

Methods

  • Provides a copy constructor to duplicate an existing TJSStyleManager instance into a new document.

    Note: This is used to support the PopOut module.

    Parameters

    • Optionaldocument: Document

      Target browser document to clone into.

    Returns TJSStyleManager

    New style manager instance.

  • Returns {}

    • Gets a particular CSS variable.

      Parameters

      • key: string

        CSS variable property key.

      Returns string

      Returns CSS variable value.

    • Removes the property keys specified. If keys is an iterable list then all property keys in the list are removed.

      Parameters

      • keys: Iterable<string, any, any>

        The property keys to remove.

      Returns void

    • Removes a particular CSS variable.

      Parameters

      • key: string

        CSS variable property key.

      Returns string

      CSS variable value when removed.

    • Set rules by property / value; useful for CSS variables.

      Parameters

      • rules: {
            [key: string]: string;
        }

        An object with property / value string pairs to load.

        • [key: string]: string
      • Optionaloverwrite: boolean

        When true overwrites any existing values.

      Returns void

    • Sets a particular property.

      Parameters

      • key: string

        CSS variable property key.

      • value: string

        CSS variable value.

      • Optionaloverwrite: boolean

        Overwrite any existing value.

      Returns void