Home

cfg-playground @1081d6d230fffa4747c413b2d1434cf831db09ef - refs - log -
-
https://git.jolheiser.com/cfg-playground.git
cfg playground
cfg-playground / static / index.html
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>cfg</title>
  <link rel="stylesheet" href="/tailwind.css" />
</head>

<body class="latte dark:mocha bg-base/50 dark:bg-base/95 text-text">
  <div class="flex h-screen">
    <div class="flex-1 flex flex-col p-4">
      <h2 class="text-2xl font-bold mb-4">Input</h2>
      <select id="from" class="bg-base dark:bg-base/50 w-full mb-2 p-2 border rounded">
        <option value="json">json(c)</option>
        <option value="jsonnet">jsonnet</option>
        <option value="yaml">yaml</option>
        <option value="toml">toml</option>
        <option value="nix">nix</option>
        <option value="dhall">dhall</option>
        <option value="kdl">kdl</option>
      </select>
      <textarea id="input" class="bg-base dark:bg-base/50 flex-1 p-2 border rounded"
        placeholder="Paste your config here..."></textarea>
    </div>
    <div class="flex-1 flex flex-col p-4">
      <h2 class="text-2xl font-bold mb-4">Output</h2>
      <select id="to" class="bg-base dark:bg-base/50 w-full mb-2 p-2 border rounded">
        <option value="json">json</option>
        <option value="yaml">yaml</option>
        <option value="toml">toml</option>
        <option value="nix">nix</option>
        <option value="kdl">kdl</option>
      </select>
      <textarea id="output" class="bg-base dark:bg-base/50 flex-1 p-2 border rounded"
        placeholder="Converted output will appear here..." readonly></textarea>
    </div>
  </div>
  <button id="copy" class="hidden fixed bottom-4 right-4 rounded bg-text hover:bg-text/50">📋</button>

  <script>
    const $inputFormat = document.getElementById('from');
    const $outputFormat = document.getElementById('to');
    const $inputText = document.getElementById('input');
    const $outputText = document.getElementById('output');
    const $copyButton = document.getElementById('copy');

    $inputFormat.addEventListener("input", convert);
    $outputFormat.addEventListener("input", convert);
    $inputText.addEventListener("input", convert);

    $inputText.addEventListener("keydown", function (event) {
      if (event.keyCode == 9) {
        event.preventDefault();
        const start = this.selectionStart;
        const end = this.selectionEnd;
        this.value = this.value.substring(0, start) + "  " + this.value.substring(end);
        this.selectionStart = this.selectionEnd = start + 2;
      }
    });

    if (navigator.clipboard && navigator.clipboard.writeText) $copyButton.classList.remove("hidden");
    $copyButton.addEventListener("click", () => {
      navigator.clipboard.writeText($outputText.value);
    });

    function convert() {
      fetch('/convert', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          from: $inputFormat.value,
          to: $outputFormat.value,
          input: $inputText.value,
        }),
      })
        .then(response => response.text())
        .then(data => {
          $outputText.value = data;
        })
        .catch(error => {
          console.error('Error:', error);
          $outputText.value = 'An error occurred during conversion.';
        });
    }
  </script>
</body>

</html>