# StyleHelper

`com.jsmacrosce.jsmacros.client.api.helper.StyleHelper`

**Since:** 1.6.5

Exposes the formatting and click/hover events stored on a text style.  

[TextHelper.visit(com.jsmacrosce.jsmacros.core.MethodWrapper)](TextHelper.md#com.jsmacrosce.jsmacros.client.api.helper.TextHelper_visit-MethodWrapper-) supplies a style for each
visited text run. These accessors report properties stored on that style, not formatting
inherited from surrounding text.  

Decoration accessors return booleans. For colours, [getColorIndex()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getColorIndex-) and
[getColorValue()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getColorValue-) return `-1` when there is no legacy named colour; use
[getCustomColor()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getCustomColor-) for the packed RGB of either colour kind, or `-1` when unset.  
[hasColor()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasColor-) and [hasCustomColor()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasCustomColor-) distinguish unset, legacy, and custom colours.  

Click and hover accessors expose the action separately from its value. JsMacros-registered
clicks report `"custom"`; retrieve their runnable with [getCustomClickValue()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getCustomClickValue-).  
```js
// a style is per run, so visit walks the text and gives one to each run
const text = Chat.createTextHelperFromString("some styled line");  
text.visit(JavaWrapper.methodToJava(function (style, run) {
  if (style.hasColor()) {
    if (style.hasCustomColor()) {
      // an arbitrary rgb colour, packed as 0xRRGGBB
      Chat.log(`${run} is colour #${style.getCustomColor().toString(16)}`);  
    } else {
      // one of the sixteen legacy named colours
      Chat.log(`${run} is ${style.getColorName()}, index ${style.getColorIndex()}`);  
    }
  }
  if (style.underlined()) {
    Chat.log(`${run} is underlined`);  
  }
  const click = style.getClickAction();  
  if (click !== null) {
    Chat.log(`${run} click does ${click} ${style.getClickValue()}`);  
  }
}));  
```

## Constructors

### new StyleHelper {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_constructor-Style-}

```js
new StyleHelper(Style base)
```

Wraps the supplied raw text style reference without copying or parsing it.

**Parameters:**
- `base`: raw text style to wrap

## Methods

### bold {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_bold-}

```js
bold(): boolean
```

Returns whether this style has its bold flag set; inherited formatting is not included.

**Returns:** `true` if this run is bold, `false` otherwise

**Since:** 1.6.5

### getClickAction {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickAction-}

```js
getClickAction(): String
```

Returns the click action's enum name, or `null` when no click event is set. Built-in
action names are uppercase; JsMacros-registered clicks return `"custom"` and their
runnable is available from [getCustomClickValue()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getCustomClickValue-). Other action values are available
from [getClickValue()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickValue-).

**Returns:** the click action's enum constant name in upper case, `"custom"` for a
JsMacros-registered command, or `null` if this run has no click action

**Since:** 1.6.5

### getClickValue {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickValue-}

```js
getClickValue(): String
```

the text argument for a click action, or `null` when the action has no text value.  
[getClickAction()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickAction-) identifies the action. A page number is returned as a decimal
string; the `"custom"` and `SHOW_DIALOG` actions have no text value.

**Returns:** the click action's argument as a string, or `null` if there is no click
action or the action is `"custom"` or `SHOW_DIALOG`

**Since:** 1.6.5

### getColorIndex {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getColorIndex-}

```js
getColorIndex(): int
```

Returns this style's legacy colour index. Custom RGB colours are not assigned a legacy
index.

**Returns:** the legacy colour index, or `-1` if no colour is set or it is an arbitrary rgb colour

**Since:** 1.8.4

### getColorName {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getColorName-}

```js
getColorName(): String
```

Returns the serialized colour of this style, or `null` if unset. Legacy colours
serialize by name and custom colours as hash-prefixed hexadecimal RGB.

**Returns:** the color name of this style or `null` if it has no color.

**Since:** 1.8.4

### getColorValue {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getColorValue-}

```js
getColorValue(): int
```

Returns the RGB value associated with a legacy named colour; custom RGB colours and
unset colours return `-1`.

**Returns:** the color value of this style or `-1` if it doesn't have one.

**Since:** 1.8.4

### getCustomClickValue {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getCustomClickValue-}

```js
getCustomClickValue(): Runnable
```

the runnable stored by a JsMacros-registered click, or `null` for other click events.  
[getClickAction()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickAction-) reports `"custom"` for that event.

**Returns:** the runnable to call for a `"custom"` click, or `null` if this run's
click action is not `"custom"`

**Since:** 1.6.5

### getCustomColor {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getCustomColor-}

```js
getCustomColor(): int
```

Returns this style's colour as packed `0xRRGGBB`, whether custom or legacy, or
`-1` if unset. Use [hasCustomColor()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasCustomColor-) to distinguish custom from legacy.

**Returns:** the packed rgb value of this run's colour, or `-1` if it has no colour

**Since:** 1.6.5

### getFormatting {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getFormatting-}

```js
getFormatting(): FormattingHelper
```

Returns the legacy formatting for this style's colour. An arbitrary RGB colour returns
`null`; when no colour is set, this method throws [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html).

**Returns:** the legacy formatting, or `null` for an arbitrary rgb colour

**Since:** 1.8.4

### getHoverAction {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getHoverAction-}

```js
getHoverAction(): String
```

the serialized name of this run's hover action, or `null` if it has no hover event.  
Unlike [getClickAction()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getClickAction-), this name is lowercase (for example,  
`show_item`). The action's value is returned by [getHoverValue()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getHoverValue-).

**Returns:** the hover action's name, or `null` if this run has no hover action

**Since:** 1.6.5

### getHoverValue {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getHoverValue-}

```js
getHoverValue(): Object
```

the value shown by this run's hover event, or `null` when there is no recognized event.  

The type of the answer depends on what [getHoverAction()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getHoverAction-) said, and there are
three shapes: a `show_text` hover gives a [TextHelper](TextHelper.md) for the text shown;  
a `show_item` hover gives an [ItemStackHelper](inventory/ItemStackHelper.md) for the item shown; and a
`show_entity` hover gives a *list* of [TextHelper](TextHelper.md), one per line of the
entity tooltip. A run with no hover gives `null`, as does any hover action the game
does not recognise.  

The result has different shapes, so use [getHoverAction()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getHoverAction-) to distinguish them.  
For `show_item`, it is an [ItemStackHelper](inventory/ItemStackHelper.md) wrapping the item value.  

```js
const text = Chat.createTextHelperFromString("hover me");  
text.visit(JavaWrapper.methodToJava(function (style, run) {
  const action = style.getHoverAction();  
  if (action === null) {
    return;  
  }
  const value = style.getHoverValue();  
  if (value === null) {
    return;  
  }
  if (action === "show_text") {
    // a single text helper
    Chat.log(`hover text: ${value.getString()}`);  
  } else if (action === "show_entity") {
    // a list of text helpers, one per tooltip line
    for (const line of value) {
      Chat.log(`tooltip: ${line.getString()}`);  
    }
  } else {
    // a single item helper
    Chat.log(`hover item: ${value.getItemId()}`);  
  }
}));  
```

**Returns:** a [TextHelper](TextHelper.md) for a `show_text` hover, an [ItemStackHelper](inventory/ItemStackHelper.md) for
a `show_item` hover, a list of [TextHelper](TextHelper.md) for a `show_entity` hover,  
or `null` if there is no recognized hover action

**Since:** 1.6.5

### getInsertion {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_getInsertion-}

```js
getInsertion(): String
```

the text inserted for this run, or `null` if it has no insertion.

**Returns:** the insertion text, or `null` if this run has none

**Since:** 1.6.5

### hasColor {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasColor-}

```js
hasColor(): boolean
```

Whether this style has a colour set.

**Returns:** `true` if a colour is set, `false` otherwise

**Since:** 1.6.5

### hasCustomColor {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasCustomColor-}

```js
hasCustomColor(): boolean
```

Returns whether this style has a custom RGB colour. Returns `false` when unset; use
[hasColor()](#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_hasColor-) to distinguish unset from a legacy colour.

**Returns:** `true` if this run has a colour that is not one of the legacy named ones

**Since:** 1.6.5

### italic {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_italic-}

```js
italic(): boolean
```

Returns whether this style has its italic flag set; inherited formatting is not included.

**Returns:** `true` if this run is italic, `false` otherwise

**Since:** 1.6.5

### obfuscated {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_obfuscated-}

```js
obfuscated(): boolean
```

Returns whether this style has its obfuscated flag set; inherited formatting is not included.

**Returns:** `true` if this run is obfuscated, `false` otherwise

**Since:** 1.6.5

### strikethrough {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_strikethrough-}

```js
strikethrough(): boolean
```

Returns whether this style has its strikethrough flag set; inherited formatting is not included.

**Returns:** `true` if this run is struck through, `false` otherwise

**Since:** 1.6.5

### toString {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_toString-}

```js
toString(): String
```

Returns a diagnostic summary of the wrapped style's stored properties.

**Returns:** a diagnostic representation of the wrapped style

### underlined {#com.jsmacrosce.jsmacros.client.api.helper.StyleHelper_underlined-}

```js
underlined(): boolean
```

Returns whether this style has its underline flag set; inherited formatting is not included.

**Returns:** `true` if this run is underlined, `false` otherwise

**Since:** 1.6.5
