diff --git a/src/file/styles/factory.ts b/src/file/styles/factory.ts index 0b5faf048d..a45f37d6b4 100644 --- a/src/file/styles/factory.ts +++ b/src/file/styles/factory.ts @@ -9,6 +9,7 @@ import { Heading4Style, Heading5Style, Heading6Style, + HyperlinkStyle, ListParagraph, TitleStyle, } from "./style"; @@ -54,6 +55,8 @@ export class DefaultStylesFactory { // listParagraph.addParagraphProperty(); styles.push(listParagraph); + const hyperLinkStyle = new HyperlinkStyle(); + styles.push(hyperLinkStyle); return styles; } } diff --git a/src/file/styles/style/index.ts b/src/file/styles/style/index.ts index 7436fbb22a..85640a2f29 100644 --- a/src/file/styles/style/index.ts +++ b/src/file/styles/style/index.ts @@ -3,7 +3,7 @@ import * as paragraph from "../../paragraph"; import * as formatting from "../../paragraph/run/formatting"; import { RunProperties } from "../../paragraph/run/properties"; -import { BasedOn, Name, Next, QuickFormat } from "./components"; +import { BasedOn, Name, Next, QuickFormat, UiPriority, UnhideWhenUsed } from "./components"; export interface IStyleAttributes { type?: string; @@ -249,3 +249,43 @@ export class ListParagraph extends ParagraphStyle { this.root.push(new QuickFormat()); } } + +export class CharacterStyle extends Style { + private readonly runProperties: RunProperties; + + constructor(styleId: string, name?: string) { + super({ type: "character", styleId: styleId }, name); + this.runProperties = new RunProperties(); + this.root.push(this.runProperties); + this.root.push(new UiPriority("99")); + this.root.push(new UnhideWhenUsed("")); + } + + public basedOn(parentId: string): CharacterStyle { + this.root.push(new BasedOn(parentId)); + return this; + } + + public addRunProperty(property: XmlComponent): void { + this.runProperties.push(property); + } + + public color(color: string): CharacterStyle { + this.addRunProperty(new formatting.Color(color)); + return this; + } + + public underline(underlineType?: string, color?: string): CharacterStyle { + this.addRunProperty(new formatting.Underline(underlineType, color)); + return this; + } +} + +export class HyperlinkStyle extends CharacterStyle { + constructor() { + super("Hyperlink", "Hyperlink"); + this.basedOn("DefaultParagraphFont") + .color("0563C1") + .underline("single"); + } +}