"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Annotation
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextStyle = exports.TextStyleSettings = void 0;
/** A description of the formatting to be applied to a [[TextBlockComponent]].
 * Named instances of these settings can be stored as [[TextStyle]]s in a [Workspace]($backend).
 * @note This is an immutable type. Use [[clone]] to create a modified copy.
 * @see [[TextStyleSettingsProps]] for documentation of each of the settings.
 * @beta
 */
class TextStyleSettings {
    constructor(props, defaults) {
        if (!defaults) {
            defaults = TextStyleSettings.defaultProps;
        }
        this.color = props.color ?? defaults.color;
        this.fontName = props.fontName ?? defaults.fontName;
        this.lineHeight = props.lineHeight ?? defaults.lineHeight;
        this.lineSpacingFactor = props.lineSpacingFactor ?? defaults.lineSpacingFactor;
        this.isBold = props.isBold ?? defaults.isBold;
        this.isItalic = props.isItalic ?? defaults.isItalic;
        this.isUnderlined = props.isUnderlined ?? defaults.isUnderlined;
        this.stackedFractionScale = props.stackedFractionScale ?? defaults.stackedFractionScale;
        this.stackedFractionType = props.stackedFractionType ?? defaults.stackedFractionType;
        this.subScriptOffsetFactor = props.subScriptOffsetFactor ?? defaults.subScriptOffsetFactor;
        this.subScriptScale = props.subScriptScale ?? defaults.subScriptScale;
        this.superScriptOffsetFactor = props.superScriptOffsetFactor ?? defaults.superScriptOffsetFactor;
        this.superScriptScale = props.superScriptScale ?? defaults.superScriptScale;
        this.widthFactor = props.widthFactor ?? defaults.widthFactor;
    }
    /** Create a copy of these settings, modified according to the properties defined by `alteredProps`. */
    clone(alteredProps) {
        return alteredProps ? new TextStyleSettings(alteredProps, this) : this;
    }
    /** Create settings from their JSON representation. */
    static fromJSON(props) {
        return props ? new TextStyleSettings(props) : TextStyleSettings.defaults;
    }
    toJSON() {
        return { ...this };
    }
    equals(other) {
        return this.color === other.color && this.fontName === other.fontName
            && this.lineHeight === other.lineHeight && this.lineSpacingFactor === other.lineSpacingFactor && this.widthFactor === other.widthFactor
            && this.isBold === other.isBold && this.isItalic === other.isItalic && this.isUnderlined === other.isUnderlined
            && this.stackedFractionType === other.stackedFractionType && this.stackedFractionScale === other.stackedFractionScale
            && this.subScriptOffsetFactor === other.subScriptOffsetFactor && this.subScriptScale === other.subScriptScale
            && this.superScriptOffsetFactor === other.superScriptOffsetFactor && this.superScriptScale === other.superScriptScale;
    }
}
exports.TextStyleSettings = TextStyleSettings;
/** A fully-populated JSON representation of the default settings. */
TextStyleSettings.defaultProps = {
    color: "subcategory",
    fontName: "",
    lineHeight: 1,
    lineSpacingFactor: 0.5,
    isBold: false,
    isItalic: false,
    isUnderlined: false,
    stackedFractionScale: 0.7,
    stackedFractionType: "horizontal",
    subScriptOffsetFactor: -0.15,
    subScriptScale: 2 / 3,
    superScriptOffsetFactor: 0.5,
    superScriptScale: 2 / 3,
    widthFactor: 1,
};
/** Settings initialized to all default values. */
TextStyleSettings.defaults = new TextStyleSettings({});
Object.freeze(TextStyleSettings.defaultProps);
Object.freeze(TextStyleSettings.defaults);
/** A named, immutable [[TextStyleSettings]] stored in a [Workspace]($backend).
 * @see [[TextBlockComponent.styleName]] to define the text style for a component of a [[TextBlock]].
 * @note This is an immutable type. Use [[clone]] to create a modified copy.
 * @beta
 */
class TextStyle {
    constructor(name, settings) {
        this.name = name;
        this.settings = settings;
    }
    /** Create a style from its JSON representation. */
    static fromJSON(json) {
        return TextStyle.create(json.name, TextStyleSettings.fromJSON(json.settings));
    }
    /** Create a new style. */
    static create(name, settings) {
        return new TextStyle(name, settings);
    }
    /** Create a copy of this style with the same name, and settings modified according to the properties defined by `alteredSettings`. */
    clone(alteredSettings) {
        return TextStyle.create(this.name, this.settings.clone(alteredSettings));
    }
    equals(other) {
        return this.name === other.name && this.settings.equals(other.settings);
    }
}
exports.TextStyle = TextStyle;
//# sourceMappingURL=TextStyle.js.map