@createlumina/text-component
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Text-component Module

Version made for Lumina projects. Original credits goes to Voxelum/minecraft-launcher-core-node

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 '@createlumina/text-component';
const formattedString: string;
const fromFormatted: TextComponent = fromFormattedString(formattedString);

Render the TextComponent to css:

import { TextComponent, render, RenderNode } from '@createlumina/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 '@createlumina/text-component';
const yourComponent: TextComponent;
const selfAndAllChildren: Array<TextComponent> = flat(yourComponent);

Package Sidebar

Install

npm i @createlumina/text-component

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

74.9 kB

Total Files

9

Last publish

Collaborators

  • padowyt2