Skip to content

Commit

Permalink
Add setter for stylesheet
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Dec 6, 2022
1 parent 8c3c59d commit 205ad8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/HTMLTextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class HTMLTextStyle extends TextStyle
private _overrides: string[] = [];

/** Global rules or stylesheet, useful for creating rules for rendering */
public stylesheet = '';
private _stylesheet = '';

/**
* Convert a TextStyle to HTMLTextStyle
Expand Down Expand Up @@ -282,7 +282,21 @@ class HTMLTextStyle extends TextStyle
font-weight: ${font.weight};
font-style: ${font.style};
}`
), this.stylesheet);
), this._stylesheet);
}

/** Internal stylesheet contents, useful for creating rules for rendering */
public get stylesheet(): string
{
return this._stylesheet;
}
public set stylesheet(value: string)
{
if (this._stylesheet !== value)
{
this._stylesheet = value;
this.styleID++;
}
}

/** Convert numerical colors into hex-strings */
Expand Down
3 changes: 3 additions & 0 deletions test/HTMLTextStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ describe('HTMLTextStyle', () =>
it('should converto CSS', () =>
{
const style = new HTMLTextStyle();
const id = style.styleID;

style.stylesheet = `p { color: red; }`;

expect(style.toGlobalCSS()).toMatchSnapshot();
expect(style.styleID).toBe(id + 1);
});
});

Expand Down

0 comments on commit 205ad8a

Please sign in to comment.