mevebu 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ // Converts JSON to YAML with a vendored writer. Block style by default, flow
2
+ // style on request.
3
+ import { bench, stack, panel, textArea, output, notice, chipRow, downloadButton, copyButton, actions, toolcard } from "../core.js";
4
+ import { dump } from "../vendor/js-yaml.mjs";
5
+
6
+ const EXAMPLE = '{\n "service": "api",\n "replicas": 2,\n "ports": [8080, 8443],\n "labels": { "tier": "backend" }\n}';
7
+
8
+ export function mount(slot) {
9
+ const source = textArea({ rows: 14, "aria-label": "JSON", value: EXAMPLE });
10
+ const result = output({ tag: "textarea", rows: 12 });
11
+ const error = notice("error");
12
+ let style = "block";
13
+
14
+ const chips = chipRow(
15
+ [{ value: "block", label: "Block" }, { value: "flow", label: "Flow" }],
16
+ { value: "block", label: "Style", onChange: (value) => { style = value; run(); } },
17
+ );
18
+
19
+ function run() {
20
+ error.write("");
21
+ if (!source.value.trim()) {
22
+ result.value = "";
23
+ return;
24
+ }
25
+ let value;
26
+ try {
27
+ value = JSON.parse(source.value);
28
+ } catch (caught) {
29
+ result.value = "";
30
+ error.write(caught.message);
31
+ return;
32
+ }
33
+ result.value = dump(value, {
34
+ indent: 2,
35
+ lineWidth: -1,
36
+ noRefs: true,
37
+ flowLevel: style === "flow" ? 0 : -1,
38
+ });
39
+ }
40
+
41
+ source.addEventListener("input", run);
42
+
43
+ const card = toolcard({
44
+ body: bench(
45
+ stack(panel("Style", chips), panel("JSON", source), error),
46
+ stack(panel("YAML", result)),
47
+ ),
48
+ foot: actions(
49
+ downloadButton(() => result.value, "data.yaml", "Download", "text/yaml"),
50
+ copyButton(() => result.value, "Copy YAML", "fill"),
51
+ ),
52
+ });
53
+ slot.append(card.node);
54
+ run();
55
+
56
+ return {};
57
+ }
58
+
59
+ export default { mount };
@@ -0,0 +1,103 @@
1
+ // Compacts XML by dropping indentation between tags. CDATA, comments,
2
+ // processing instructions and attribute values are copied unchanged.
3
+ import { el, bench, stack, panel, textArea, output, notice, copyButton, actions, toolcard } from "../core.js";
4
+ import { bytes } from "../js-tokens.js";
5
+
6
+ const EXAMPLE = '<?xml version="1.0"?>\n<config>\n <server host="localhost" port="8080">\n <name>api</name>\n </server>\n <note><![CDATA[keep this spacing]]></note>\n</config>';
7
+
8
+ const tile = (key, value) =>
9
+ el("div", { class: "grid gap-0.5 rounded-r1 border border-orbit bg-deck-2 px-3.5 py-3" },
10
+ el("span", { class: "wrap-anywhere text-xl font-bold tracking-[-0.02em] tabular-nums" }, value),
11
+ el("span", { class: "text-2xs font-semibold text-ink-3" }, key));
12
+
13
+ function minify(source) {
14
+ let out = "";
15
+ let i = 0;
16
+
17
+ while (i < source.length) {
18
+ if (source.startsWith("<![CDATA[", i)) {
19
+ const end = source.indexOf("]]>", i + 9);
20
+ if (end === -1) return { error: "Unclosed CDATA section." };
21
+ out += source.slice(i, end + 3);
22
+ i = end + 3;
23
+ continue;
24
+ }
25
+ if (source.startsWith("<!--", i)) {
26
+ const end = source.indexOf("-->", i + 4);
27
+ if (end === -1) return { error: "Unclosed comment." };
28
+ out += source.slice(i, end + 3);
29
+ i = end + 3;
30
+ continue;
31
+ }
32
+ if (source[i] === "<") {
33
+ let j = i + 1;
34
+ let quote = null;
35
+ while (j < source.length) {
36
+ const ch = source[j];
37
+ if (quote) {
38
+ if (ch === quote) quote = null;
39
+ } else if (ch === '"' || ch === "'") {
40
+ quote = ch;
41
+ } else if (ch === ">") {
42
+ break;
43
+ }
44
+ j++;
45
+ }
46
+ if (j >= source.length) return { error: "Unclosed tag." };
47
+ out += source.slice(i, j + 1);
48
+ i = j + 1;
49
+ continue;
50
+ }
51
+
52
+ let j = source.indexOf("<", i);
53
+ if (j === -1) j = source.length;
54
+ const text = source.slice(i, j);
55
+ if (!/^\s+$/.test(text) || !text.includes("\n")) out += text;
56
+ i = j;
57
+ }
58
+
59
+ return { text: out };
60
+ }
61
+
62
+ export function mount(slot) {
63
+ const source = textArea({ rows: 14, "aria-label": "XML", value: EXAMPLE });
64
+ const result = output({ tag: "textarea", rows: 12 });
65
+ const stats = el("div", { class: "grid gap-2.5 [grid-template-columns:repeat(auto-fit,minmax(120px,1fr))]" });
66
+ const error = notice("error");
67
+
68
+ function run() {
69
+ error.write("");
70
+ stats.replaceChildren();
71
+ if (!source.value.trim()) {
72
+ result.value = "";
73
+ return;
74
+ }
75
+ const output = minify(source.value);
76
+ if (output.error) {
77
+ result.value = "";
78
+ error.write(output.error);
79
+ return;
80
+ }
81
+ const before = bytes(source.value);
82
+ const after = bytes(output.text);
83
+ const saved = before ? Math.max(0, Math.round((1 - after / before) * 100)) : 0;
84
+ result.value = output.text;
85
+ stats.append(tile("Before", `${before} B`), tile("After", `${after} B`), tile("Saved", `${saved}%`));
86
+ }
87
+
88
+ source.addEventListener("input", run);
89
+
90
+ const card = toolcard({
91
+ body: bench(
92
+ stack(panel("XML", source), error),
93
+ stack(panel("Minified", result), stats),
94
+ ),
95
+ foot: actions(copyButton(() => result.value, "Copy XML", "fill")),
96
+ });
97
+ slot.append(card.node);
98
+ run();
99
+
100
+ return {};
101
+ }
102
+
103
+ export default { mount };
@@ -0,0 +1,46 @@
1
+ // Converts YAML to JSON with a vendored parser. Anchors are resolved and the
2
+ // key order is kept.
3
+ import { bench, stack, panel, textArea, output, notice, downloadButton, copyButton, actions, toolcard } from "../core.js";
4
+ import { load } from "../vendor/js-yaml.mjs";
5
+
6
+ const EXAMPLE = "service: api\nreplicas: 2\nports:\n - 8080\n - 8443\nlabels:\n tier: backend";
7
+
8
+ export function mount(slot) {
9
+ const source = textArea({ rows: 14, "aria-label": "YAML", value: EXAMPLE });
10
+ const result = output({ tag: "textarea", rows: 12 });
11
+ const error = notice("error");
12
+ function run() {
13
+ error.write("");
14
+ if (!source.value.trim()) {
15
+ result.value = "";
16
+ return;
17
+ }
18
+ try {
19
+ result.value = JSON.stringify(load(source.value), null, 2);
20
+ } catch (caught) {
21
+ result.value = "";
22
+ const line = caught.mark?.line;
23
+ const where = typeof line === "number" ? `Line ${line + 1}: ` : "";
24
+ error.write(`${where}${caught.reason ?? caught.message}`);
25
+ }
26
+ }
27
+
28
+ source.addEventListener("input", run);
29
+
30
+ const card = toolcard({
31
+ body: bench(
32
+ stack(panel("YAML", source), error),
33
+ stack(panel("JSON", result)),
34
+ ),
35
+ foot: actions(
36
+ downloadButton(() => result.value, "data.json", "Download", "application/json"),
37
+ copyButton(() => result.value, "Copy JSON", "fill"),
38
+ ),
39
+ });
40
+ slot.append(card.node);
41
+ run();
42
+
43
+ return {};
44
+ }
45
+
46
+ export default { mount };
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (C) 2011-2015 by Vitaly Puzrin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.