pixi-glyphs 4.0.3 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/Glyphs.d.ts +3 -0
- package/dist/pixi-glyphs.js +66 -2
- package/dist/pixi-glyphs.js.map +1 -1
- package/dist/pixi-glyphs.m.js +66 -2
- package/dist/pixi-glyphs.m.js.map +1 -1
- package/dist/pixi-glyphs.modern.js +66 -2
- package/dist/pixi-glyphs.modern.js.map +1 -1
- package/dist/pixi-glyphs.umd.js +66 -2
- package/dist/pixi-glyphs.umd.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,7 @@ The style objects are modified versions (supersets) of `PIXI.TextStyle` (referre
|
|
|
93
93
|
- `lineThroughThickness` - Sets the thickness of the line-through. Default is `1`.
|
|
94
94
|
- `lineThroughOffset` - Positions the line-through above or below the default location. Default is `0`.
|
|
95
95
|
- `adjustBaseline` - Adjusts the position of the text above or below the baseline. Default is `0`. Also see the `adjustFontBaseline` property in the options.
|
|
96
|
+
- `highlightColor` - Adds a background highlight color behind the text. Can be a hex number like `0xFFEB3B` or a hex string like `"#FFEB3B"`. The highlight appears as a continuous solid color box behind the text with no borders, spanning across spaces between words for a seamless highlight effect. When the same highlight color is applied to consecutive text segments, they will be rendered as a single continuous highlight box. Perfect for emphasizing important text, creating visual hierarchy, inline code blocks, or implementing syntax highlighting. Example: `<highlight>This entire phrase is highlighted</highlight>` will create one continuous highlight box.
|
|
96
97
|
- `color` - An alias for `fill`. It's recommended you just use either `fill` or `color`, but if both are set, `fill` will be used. If tags are nested, `color` on an inner tag can override `fill` in an outer tag.
|
|
97
98
|
|
|
98
99
|
Additionally, the following changes have been made to the default style values:
|
package/dist/Glyphs.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export default class Glyphs<TextType extends PixiTextTypes = PIXI.Text> extends
|
|
|
39
39
|
private _debugGraphics;
|
|
40
40
|
private _textContainer;
|
|
41
41
|
get textContainer(): PIXI.Container;
|
|
42
|
+
private _highlightContainer;
|
|
43
|
+
get highlightContainer(): PIXI.Container;
|
|
42
44
|
private _decorationContainer;
|
|
43
45
|
get decorationContainer(): PIXI.Container;
|
|
44
46
|
private _spriteContainer;
|
|
@@ -58,6 +60,7 @@ export default class Glyphs<TextType extends PixiTextTypes = PIXI.Text> extends
|
|
|
58
60
|
draw(): void;
|
|
59
61
|
protected createDrawingForTextDecoration(textDecoration: TextDecorationMetrics): PIXI.Graphics;
|
|
60
62
|
protected createTextField(text: string, style: TextStyleExtended): TextType;
|
|
63
|
+
protected createHighlightBox(highlightColor: any, x: number, y: number, width: number, height: number): PIXI.Graphics | null;
|
|
61
64
|
protected createTextFieldForToken(token: TextSegmentToken): TextType;
|
|
62
65
|
toDebugString(): string;
|
|
63
66
|
drawDebug(): void;
|
package/dist/pixi-glyphs.js
CHANGED
|
@@ -1492,6 +1492,9 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1492
1492
|
get textContainer() {
|
|
1493
1493
|
return this._textContainer;
|
|
1494
1494
|
}
|
|
1495
|
+
get highlightContainer() {
|
|
1496
|
+
return this._highlightContainer;
|
|
1497
|
+
}
|
|
1495
1498
|
get decorationContainer() {
|
|
1496
1499
|
return this._decorationContainer;
|
|
1497
1500
|
}
|
|
@@ -1515,12 +1518,14 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1515
1518
|
this._spriteTemplates = {};
|
|
1516
1519
|
this._debugGraphics = void 0;
|
|
1517
1520
|
this._textContainer = void 0;
|
|
1521
|
+
this._highlightContainer = void 0;
|
|
1518
1522
|
this._decorationContainer = void 0;
|
|
1519
1523
|
this._spriteContainer = void 0;
|
|
1520
1524
|
this._debugContainer = void 0;
|
|
1521
1525
|
this.logWarning = (code, message) => logWarning(this.options.errorHandler, this.options.supressConsole, this)(code, message);
|
|
1522
1526
|
this._textContainer = new PIXI__namespace.Container();
|
|
1523
1527
|
this._spriteContainer = new PIXI__namespace.Container();
|
|
1528
|
+
this._highlightContainer = new PIXI__namespace.Container();
|
|
1524
1529
|
this._decorationContainer = new PIXI__namespace.Container();
|
|
1525
1530
|
this._debugContainer = new PIXI__namespace.Container();
|
|
1526
1531
|
this._debugGraphics = new PIXI__namespace.Graphics();
|
|
@@ -1597,6 +1602,12 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1597
1602
|
this._options = {};
|
|
1598
1603
|
}
|
|
1599
1604
|
resetChildren() {
|
|
1605
|
+
if (this._highlightContainer) {
|
|
1606
|
+
this._highlightContainer.removeChildren();
|
|
1607
|
+
this.removeChild(this._highlightContainer);
|
|
1608
|
+
}
|
|
1609
|
+
this._highlightContainer = new PIXI__namespace.Container();
|
|
1610
|
+
this.addChild(this._highlightContainer);
|
|
1600
1611
|
if (this._textContainer) {
|
|
1601
1612
|
this._textContainer.removeChildren();
|
|
1602
1613
|
this.removeChild(this._textContainer);
|
|
@@ -1712,16 +1723,47 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1712
1723
|
}
|
|
1713
1724
|
draw() {
|
|
1714
1725
|
this.resetChildren();
|
|
1715
|
-
if (this.textContainer === null || this.spriteContainer === null) {
|
|
1716
|
-
throw new Error("Somehow the textContainer or
|
|
1726
|
+
if (this.textContainer === null || this.spriteContainer === null || this.highlightContainer === null) {
|
|
1727
|
+
throw new Error("Somehow the textContainer, spriteContainer, or highlightContainer is null. This shouldn't be possible. Perhaps you've destroyed this object?");
|
|
1717
1728
|
}
|
|
1718
1729
|
const textContainer = this.textContainer;
|
|
1719
1730
|
const spriteContainer = this.spriteContainer;
|
|
1731
|
+
const highlightContainer = this.highlightContainer;
|
|
1720
1732
|
const {
|
|
1721
1733
|
drawWhitespace
|
|
1722
1734
|
} = this.options;
|
|
1723
1735
|
const tokensFlat = this.tokensFlat;
|
|
1724
1736
|
const tokens = drawWhitespace ? tokensFlat : tokensFlat.filter(isNotWhitespaceToken);
|
|
1737
|
+
let i = 0;
|
|
1738
|
+
while (i < tokensFlat.length) {
|
|
1739
|
+
const token = tokensFlat[i];
|
|
1740
|
+
if (isTextToken(token) && token.style.highlightColor !== undefined) {
|
|
1741
|
+
const highlightColor = token.style.highlightColor;
|
|
1742
|
+
let startX = token.bounds.x;
|
|
1743
|
+
let minY = token.bounds.y;
|
|
1744
|
+
let maxY = token.bounds.y + token.bounds.height;
|
|
1745
|
+
let endX = token.bounds.x + token.bounds.width;
|
|
1746
|
+
let j = i + 1;
|
|
1747
|
+
while (j < tokensFlat.length) {
|
|
1748
|
+
const nextToken = tokensFlat[j];
|
|
1749
|
+
if (isTextToken(nextToken) && nextToken.style.highlightColor === highlightColor && Math.abs(nextToken.bounds.y - token.bounds.y) < 5) {
|
|
1750
|
+
endX = nextToken.bounds.x + nextToken.bounds.width;
|
|
1751
|
+
minY = Math.min(minY, nextToken.bounds.y);
|
|
1752
|
+
maxY = Math.max(maxY, nextToken.bounds.y + nextToken.bounds.height);
|
|
1753
|
+
j++;
|
|
1754
|
+
} else {
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
const highlight = this.createHighlightBox(highlightColor, startX, minY, endX - startX, maxY - minY);
|
|
1759
|
+
if (highlight) {
|
|
1760
|
+
highlightContainer.addChild(highlight);
|
|
1761
|
+
}
|
|
1762
|
+
i = j;
|
|
1763
|
+
} else {
|
|
1764
|
+
i++;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1725
1767
|
let drewDecorations = false;
|
|
1726
1768
|
let displayObject;
|
|
1727
1769
|
tokens.forEach((t, index) => {
|
|
@@ -1825,6 +1867,28 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1825
1867
|
});
|
|
1826
1868
|
return textField;
|
|
1827
1869
|
}
|
|
1870
|
+
createHighlightBox(highlightColor, x, y, width, height) {
|
|
1871
|
+
if (!highlightColor || width <= 0 || height <= 0) {
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
const highlight = new PIXI__namespace.Graphics();
|
|
1875
|
+
let color = highlightColor;
|
|
1876
|
+
if (typeof color === "string") {
|
|
1877
|
+
if (color.indexOf("#") === 0) {
|
|
1878
|
+
color = "0x" + color.substring(1);
|
|
1879
|
+
color = parseInt(color, 16);
|
|
1880
|
+
} else {
|
|
1881
|
+
this.logWarning("invalid-highlight-color", "Sorry, at this point, only hex colors are supported for highlightColor. Please use either a hex number like 0x66FF33 or a string like '#66FF33'");
|
|
1882
|
+
color = 0xFFFF00;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
highlight.rect(0, 0, width, height).fill({
|
|
1886
|
+
color: color
|
|
1887
|
+
});
|
|
1888
|
+
highlight.x = x;
|
|
1889
|
+
highlight.y = y;
|
|
1890
|
+
return highlight;
|
|
1891
|
+
}
|
|
1828
1892
|
createTextFieldForToken(token) {
|
|
1829
1893
|
const {
|
|
1830
1894
|
textTransform = ""
|