{"version":3,"file":"formatted.mjs","names":[],"sources":["../../../src/expression/types/formatted.ts"],"sourcesContent":["import type {Color} from '../../expression/types/color';\nimport type {ResolvedImage} from '../types/resolved_image';\n\nexport const VERTICAL_ALIGN_OPTIONS = ['bottom', 'center', 'top'] as const;\nexport type VerticalAlign = (typeof VERTICAL_ALIGN_OPTIONS)[number];\n\nexport class FormattedSection {\n    text: string;\n    image: ResolvedImage | null;\n    scale: number | null;\n    fontStack: string | null;\n    textColor: Color | null;\n    verticalAlign: VerticalAlign | null;\n\n    constructor(\n        text: string,\n        image: ResolvedImage | null,\n        scale: number | null,\n        fontStack: string | null,\n        textColor: Color | null,\n        verticalAlign: VerticalAlign | null\n    ) {\n        this.text = text;\n        this.image = image;\n        this.scale = scale;\n        this.fontStack = fontStack;\n        this.textColor = textColor;\n        this.verticalAlign = verticalAlign;\n    }\n}\n\nexport class Formatted {\n    sections: Array<FormattedSection>;\n\n    constructor(sections: Array<FormattedSection>) {\n        this.sections = sections;\n    }\n\n    static fromString(unformatted: string): Formatted {\n        return new Formatted([new FormattedSection(unformatted, null, null, null, null, null)]);\n    }\n\n    isEmpty(): boolean {\n        if (this.sections.length === 0) return true;\n        return !this.sections.some(\n            (section) =>\n                section.text.length !== 0 || (section.image && section.image.name.length !== 0)\n        );\n    }\n\n    static factory(text: Formatted | string): Formatted {\n        if (text instanceof Formatted) {\n            return text;\n        } else {\n            return Formatted.fromString(text);\n        }\n    }\n\n    toString(): string {\n        if (this.sections.length === 0) return '';\n        return this.sections.map((section) => section.text).join('');\n    }\n}\n"],"mappings":";AAGA,MAAa,yBAAyB;CAAC;CAAU;CAAU;AAAK;AAGhE,IAAa,mBAAb,MAA8B;CAQ1B,YACI,MACA,OACA,OACA,WACA,WACA,eACF;EACE,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,YAAY;EACjB,KAAK,YAAY;EACjB,KAAK,gBAAgB;CACzB;AACJ;AAEA,IAAa,YAAb,MAAa,UAAU;CAGnB,YAAY,UAAmC;EAC3C,KAAK,WAAW;CACpB;CAEA,OAAO,WAAW,aAAgC;EAC9C,OAAO,IAAI,UAAU,CAAC,IAAI,iBAAiB,aAAa,MAAM,MAAM,MAAM,MAAM,IAAI,CAAC,CAAC;CAC1F;CAEA,UAAmB;EACf,IAAI,KAAK,SAAS,WAAW,GAAG,OAAO;EACvC,OAAO,CAAC,KAAK,SAAS,MACjB,YACG,QAAQ,KAAK,WAAW,KAAM,QAAQ,SAAS,QAAQ,MAAM,KAAK,WAAW,CACrF;CACJ;CAEA,OAAO,QAAQ,MAAqC;EAChD,IAAI,gBAAgB,WAChB,OAAO;OAEP,OAAO,UAAU,WAAW,IAAI;CAExC;CAEA,WAAmB;EACf,IAAI,KAAK,SAAS,WAAW,GAAG,OAAO;EACvC,OAAO,KAAK,SAAS,KAAK,YAAY,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE;CAC/D;AACJ"}