UNPKG

1.65 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.renderComponent = exports.wrap = void 0;
7const parse_js_1 = __importDefault(require("./parse.js"));
8const static_js_1 = require("./static.js");
9function wrap(tag, content) {
10 return `<${tag}>${content}</${tag.split(" ")[0]}>`;
11}
12exports.wrap = wrap;
13function renderComponent(jsonPart) {
14 let classlist = "";
15 let text = "";
16 for (const key of Object.keys(jsonPart)) {
17 if (key === "text") {
18 text += jsonPart.text;
19 continue;
20 }
21 if (static_js_1.Classes.hasOwnProperty(key)) {
22 classlist += " mc-" + static_js_1.Classes[key];
23 continue;
24 }
25 if (key === "color") {
26 classlist += " mc-" + jsonPart[key];
27 continue;
28 }
29 if (key === "extra") {
30 for (const jsonPartExtra of jsonPart.extra) {
31 text += renderComponent(jsonPartExtra);
32 }
33 }
34 }
35 classlist = classlist.replace(/dark_acqua/gm, "dark_aqua");
36 return wrap(`span${classlist.trim() !== "" ? ` class="${classlist.trim()}"` : ""}`, text);
37}
38exports.renderComponent = renderComponent;
39function render(input, delimiter = "§") {
40 let json = (0, parse_js_1.default)(input, delimiter);
41 json = JSON.parse(JSON.stringify(json)
42 .split("\\n")
43 .join("<br>"));
44 return wrap("span class=\"mc\"", renderComponent(json));
45}
46exports.default = render;
47//# sourceMappingURL=render.js.map
\No newline at end of file