2.1.3 • Published 7 months ago

@xmcl/text-component v2.1.3

Weekly downloads
69
License
MIT
Repository
github
Last release
7 months ago

Text-component Module

npm version Downloads Install size npm Build Status

Provide functions to parse Minecraft text component.

Usage

TextComponent

Create TextComponent from string OR Minecraft's formatted string, like '§cThis is red':

import { TextComponent, fromFormattedString } from "@xmcl/text-component";
const formattedString: string;
const fromFormatted: TextComponent = fromFormattedString(formattedString);

Render the TextComponent to css:

import { TextComponent, render, RenderNode } from "@xmcl/text-component";
const yourComponent: TextComponent;
const node: RenderNode = render(yourComponent);

node.text; // the text of the node
node.style; // style of the node
node.children; // children

// you can render in dom like this:

function renderToDom(node: RenderNode) {
    const span = document.createElement('span');
    span.style = node.style;
    span.textContent = node.text;
    for (const child of node.children) {
        span.appendChild(renderToDom(child));
    }
} 

Iterate the TextComponent and its children:

import { TextComponent, flat } from "@xmcl/text-component";
const yourComponent: TextComponent;
const selfAndAllChildren: Array<TextComponent> = flat(yourComponent);
2.1.3

7 months ago

2.1.2

1 year ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1-alpha.1

4 years ago

2.0.1-alpha.0

4 years ago

2.0.0-alpha.0

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago