|
33 | 33 | border-radius: 4px;
|
34 | 34 | }
|
35 | 35 | .layout-toggle,
|
36 |
| - .sketch-toggle { |
| 36 | + .sketch-toggle, |
| 37 | + .center-toggle, |
| 38 | + .theme-select, |
| 39 | + .dark-theme-select, |
| 40 | + .padding-input, |
| 41 | + .scale-input { |
37 | 42 | display: flex;
|
38 | 43 | gap: 16px;
|
39 | 44 | align-items: center;
|
|
42 | 47 | display: flex;
|
43 | 48 | gap: 12px;
|
44 | 49 | }
|
| 50 | + .input-label, |
| 51 | + .select-label, |
45 | 52 | .radio-label,
|
46 | 53 | .checkbox-label {
|
47 | 54 | display: flex;
|
48 | 55 | gap: 4px;
|
49 | 56 | align-items: center;
|
50 | 57 | cursor: pointer;
|
51 | 58 | }
|
| 59 | + .number-input { |
| 60 | + width: 3rem; |
| 61 | + } |
52 | 62 | button {
|
53 | 63 | padding: 8px 16px;
|
54 | 64 | background: #0066cc;
|
|
96 | 106 | Sketch mode
|
97 | 107 | </label>
|
98 | 108 | </div>
|
| 109 | + <div class="center-toggle"> |
| 110 | + <label class="checkbox-label"> |
| 111 | + <input type="checkbox" id="center" /> |
| 112 | + Center mode |
| 113 | + </label> |
| 114 | + </div> |
| 115 | + <div class="theme-select"> |
| 116 | + <label class="select-label"> |
| 117 | + <select id="theme" name="theme"> |
| 118 | + <option value="-1"></option> |
| 119 | + <option value="0">Default</option> |
| 120 | + <option value="1">Neutral grey</option> |
| 121 | + <option value="3">Flagship Terrastruct</option> |
| 122 | + <option value="4">Cool classics</option> |
| 123 | + <option value="5">Mixed berry blue</option> |
| 124 | + <option value="6">Grape soda</option> |
| 125 | + <option value="7">Aubergine</option> |
| 126 | + <option value="8">Colorblind clear</option> |
| 127 | + <option value="100">Vanilla nitro cola</option> |
| 128 | + <option value="101">Orange creamsicle</option> |
| 129 | + <option value="102">Shirley temple</option> |
| 130 | + <option value="103">Earth tones</option> |
| 131 | + <option value="104">Everglade green</option> |
| 132 | + <option value="105">Buttered toast</option> |
| 133 | + <option value="200">Dark mauve</option> |
| 134 | + <option value="300">Terminal</option> |
| 135 | + <option value="301">Terminal grayscale</option> |
| 136 | + </select> |
| 137 | + Theme ID |
| 138 | + </label> |
| 139 | + </div> |
| 140 | + <div class="dark-theme-select"> |
| 141 | + <label class="select-label"> |
| 142 | + <select id="dark-theme" name="dark-theme"> |
| 143 | + <option value="-1"></option> |
| 144 | + <option value="0">Default</option> |
| 145 | + <option value="1">Neutral grey</option> |
| 146 | + <option value="3">Flagship Terrastruct</option> |
| 147 | + <option value="4">Cool classics</option> |
| 148 | + <option value="5">Mixed berry blue</option> |
| 149 | + <option value="6">Grape soda</option> |
| 150 | + <option value="7">Aubergine</option> |
| 151 | + <option value="8">Colorblind clear</option> |
| 152 | + <option value="100">Vanilla nitro cola</option> |
| 153 | + <option value="101">Orange creamsicle</option> |
| 154 | + <option value="102">Shirley temple</option> |
| 155 | + <option value="103">Earth tones</option> |
| 156 | + <option value="104">Everglade green</option> |
| 157 | + <option value="105">Buttered toast</option> |
| 158 | + <option value="200">Dark mauve</option> |
| 159 | + <option value="300">Terminal</option> |
| 160 | + <option value="301">Terminal grayscale</option> |
| 161 | + </select> |
| 162 | + Dark Theme ID |
| 163 | + </label> |
| 164 | + </div> |
| 165 | + <div class="padding-input"> |
| 166 | + <label class="input-label"> |
| 167 | + <input type="number" id="padding" value="20" step="10" class="number-input" /> |
| 168 | + Padding |
| 169 | + </label> |
| 170 | + </div> |
| 171 | + <div class="scale-input"> |
| 172 | + <label class="input-label"> |
| 173 | + <input type="number" id="scale" value="-1" step="1" class="number-input" /> |
| 174 | + Scale |
| 175 | + </label> |
| 176 | + </div> |
99 | 177 | </div>
|
100 | 178 | <button onclick="compile()">Compile</button>
|
101 | 179 | </div>
|
|
104 | 182 | import { D2 } from "../dist/browser/index.js";
|
105 | 183 | const d2 = new D2();
|
106 | 184 | window.compile = async () => {
|
| 185 | + const notNegative = (value) => { |
| 186 | + if (value < 0) { |
| 187 | + return null; |
| 188 | + } else return value; |
| 189 | + }; |
107 | 190 | const input = document.getElementById("input").value;
|
108 | 191 | const layout = document.querySelector('input[name="layout"]:checked').value;
|
109 | 192 | const sketch = document.getElementById("sketch").checked;
|
| 193 | + const center = document.getElementById("center").checked; |
| 194 | + const themeSelector = document.getElementById("theme"); |
| 195 | + const themeId = notNegative( |
| 196 | + Number(themeSelector.options[themeSelector.selectedIndex].value) |
| 197 | + ); |
| 198 | + const darkThemeSelector = document.getElementById("dark-theme"); |
| 199 | + const darkThemeId = notNegative( |
| 200 | + Number(darkThemeSelector.options[darkThemeSelector.selectedIndex].value) |
| 201 | + ); |
| 202 | + const scale = notNegative(Number(document.getElementById("scale").value)); |
| 203 | + const pad = Number(document.getElementById("padding").value); |
110 | 204 | try {
|
111 |
| - const result = await d2.compile(input, { layout, sketch }); |
112 |
| - const svg = await d2.render(result.diagram, { sketch }); |
| 205 | + const result = await d2.compile(input, { |
| 206 | + layout, |
| 207 | + sketch, |
| 208 | + themeId, |
| 209 | + darkThemeId, |
| 210 | + scale, |
| 211 | + pad, |
| 212 | + center, |
| 213 | + }); |
| 214 | + const svg = await d2.render(result.diagram, { |
| 215 | + sketch, |
| 216 | + themeId, |
| 217 | + darkThemeId, |
| 218 | + scale, |
| 219 | + pad, |
| 220 | + center, |
| 221 | + }); |
113 | 222 | document.getElementById("output").innerHTML = svg;
|
114 | 223 | } catch (err) {
|
115 | 224 | console.error(err);
|
|
0 commit comments