1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.renderComponent = exports.wrap = void 0;
|
7 | const parse_js_1 = __importDefault(require("./parse.js"));
|
8 | const static_js_1 = require("./static.js");
|
9 | function wrap(tag, content) {
|
10 | return `<${tag}>${content}</${tag.split(" ")[0]}>`;
|
11 | }
|
12 | exports.wrap = wrap;
|
13 | function 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 | }
|
38 | exports.renderComponent = renderComponent;
|
39 | function 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 | }
|
46 | exports.default = render;
|
47 |
|
\ | No newline at end of file |