-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.html
497 lines (433 loc) · 14.1 KB
/
ui.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html>
<head>
<style>
/* reset */
/* https://github.com/mayank99/reset.css */
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:where([hidden]:not([hidden='until-found'])) {
display: none !important;
}
:where(html) {
-webkit-text-size-adjust: none;
color-scheme: dark light;
}
@supports not (min-block-size: 100dvb) {
:where(html) {
block-size: 100%;
}
}
@media (prefers-reduced-motion: no-preference) {
:where(html:focus-within) {
scroll-behavior: smooth;
}
}
:where(body) {
block-size: 100%;
block-size: 100dvb;
line-height: 1.5;
font-family: system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
:where(input, button, textarea, select) {
font: inherit;
color: inherit;
}
:where(textarea) {
resize: vertical;
resize: block;
}
:where(button, label, select, summary, [role='button'], [role='option']) {
cursor: pointer;
}
:where(:disabled) {
cursor: not-allowed;
}
:where(label:has(> input:disabled), label:has(+ input:disabled)) {
cursor: not-allowed;
}
:where(button) {
border-style: solid;
}
:where(a) {
text-underline-offset: 0.2ex;
}
:where(ul, ol) {
list-style: none;
}
:where(img, svg, video, canvas, audio, iframe, embed, object) {
display: block;
}
:where(img, picture, svg) {
max-inline-size: 100%;
block-size: auto;
}
:where(p, h1, h2, h3, h4, h5, h6) {
overflow-wrap: break-word;
}
:where(h1, h2, h3) {
line-height: calc(1em + 0.5rem);
}
:where(hr) {
border: none;
border-block-start: 1px solid;
color: inherit;
block-size: 0;
overflow: visible;
}
:where(:focus-visible) {
outline: 2px solid var(--focus-color, Highlight);
outline-offset: 2px;
}
:where(
.visually-hidden:not(
:focus,
:active,
:focus-within,
.not-visually-hidden
)
) {
clip-path: inset(50%) !important;
height: 1px !important;
width: 1px !important;
overflow: hidden !important;
position: absolute !important;
white-space: nowrap !important;
border: 0 !important;
}
/* styles */
body {
color: #0f1419;
}
.container {
padding: 20px;
}
.main {
/*
width: 300px;
display: flex;
flex-direction: column;
gap: 16px;
*/
display: grid;
grid-template-columns: 272px 272px;
/* grid-template-rows: 272px 272px; */
gap: 16px;
}
.column {
padding: 16px;
background-color: #f1f5f9;
border-radius: 4px;
display: flex;
flex-direction: column;
justify-content: space-between;
gap: 24px;
}
.column.-import {
grid-row: 1 / 3;
}
.column.-export {
grid-column: 2 / 3;
}
.column.-delete {
grid-column: 2 / 3;
}
.column-contents {
display: flex;
flex-direction: column;
gap: 8px;
}
.title {
font-size: 20px;
margin-bottom: 20px;
}
.subtitle {
font-size: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.icon {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.label {
font-size: 14px;
}
.file {
font-size: 10px;
}
.button {
/* MIT License https://raw.githubusercontent.com/themesberg/flowbite/main/LICENSE.md */
-webkit-text-size-adjust: 100%;
tab-size: 4;
-webkit-font-smoothing: antialiased;
border: 0 solid #e5e7eb;
box-sizing: border-box;
--tw-border-spacing-x: 0;
--tw-border-spacing-y: 0;
--tw-translate-x: 0;
--tw-translate-y: 0;
--tw-rotate: 0;
--tw-skew-x: 0;
--tw-skew-y: 0;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-scroll-snap-strictness: proximity;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgba(63, 131, 248, 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
font-family: inherit;
margin: 0;
text-transform: none;
cursor: pointer;
-webkit-appearance: button;
background-image: none;
border-radius: 4px;
border-width: 1px;
--tw-border-opacity: 1;
border-color: rgb(229 231 235 / var(--tw-border-opacity));
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
padding-left: 1.25rem;
padding-right: 1.25rem;
padding-bottom: 0.625rem;
padding-top: 0.625rem;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.button.-red {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
--tw-bg-opacity: 1;
background-color: rgb(200 30 30 / var(--tw-bg-opacity));
}
.example {
padding: 4px;
}
.example-title {
font-size: 14px;
}
.example-code {
margin-top: 8px;
font-size: 14px;
padding: 8px;
color: white;
background-color: black;
}
@media (prefers-color-scheme: dark) {
body {
color: #ffffff;
background-color: #0f1419;
}
svg {
filter: invert(1);
}
.column {
background-color: #1e293b;
}
.button {
--tw-border-opacity: 1;
border-color: rgb(75 85 99 / var(--tw-border-opacity));
--tw-bg-opacity: 1;
background-color: rgb(31 41 55 / var(--tw-bg-opacity));
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
}
</style>
</head>
<body>
<div class="container">
<h1 class="title">Color Palette Management with JSON</h1>
<main class="main">
<div class="column -import">
<div class="column-contents">
<h2 class="subtitle">
<div class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. -->
<path
d="M128 64c0-35.3 28.7-64 64-64H352V128c0 17.7 14.3 32 32 32H512V448c0 35.3-28.7 64-64 64H192c-35.3 0-64-28.7-64-64V336H302.1l-39 39c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l39 39H128V64zm0 224v48H24c-13.3 0-24-10.7-24-24s10.7-24 24-24H128zM512 128H384V0L512 128z"
/>
</svg>
</div>
<span>Import colors</span>
</h2>
<label for="importFormat" class="label"
>Select import format:</label
>
<select id="importFormat">
<option value="nested">Nested (hierarchical)</option>
<option value="flat">Flat (with '/')</option>
</select>
<div class="example">
<details open id="nested">
<summary class="example-title">Example JSON: Nested</summary>
<pre class="example-code">
{
"foo": {
"bar": "#000000",
"baz": "rgba(0, 0, 0, 1)"
}
}
</pre
>
</details>
<details open id="flat" style="display: none">
<summary class="example-title">Example JSON: Flat</summary>
<pre class="example-code">
{
"foo/bar": "#000000",
"foo/baz": "rgba(0, 0, 0, 1)",
}
</pre
>
</details>
</div>
<label for="fileInput" class="label">Select JSON file:</label>
<input type="file" id="fileInput" class="file" />
</div>
<button id="importButton" class="button">Import Color Styles</button>
</div>
<div class="column -export">
<div class="column-contents">
<h2 class="subtitle">
<div class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
<!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. -->
<path
d="M0 64C0 28.7 28.7 0 64 0H224V128c0 17.7 14.3 32 32 32H384V288H216c-13.3 0-24 10.7-24 24s10.7 24 24 24H384V448c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64zM384 336V288H494.1l-39-39c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l80 80c9.4 9.4 9.4 24.6 0 33.9l-80 80c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l39-39H384zm0-208H256V0L384 128z"
/>
</svg>
</div>
<span>Export colors</span>
</h2>
<label for="exportFormat" class="label">Export format:</label>
<select id="exportFormat">
<option value="nested">Nested (hierarchical)</option>
<option value="flat">Flat (with '/')</option>
</select>
<label for="colorFormat" class="label">Color format:</label>
<select id="colorFormat">
<option value="hex">Hex</option>
<option value="rgba">RGBA</option>
</select>
</div>
<button id="exportButton" class="button">Export Color Styles</button>
</div>
<div class="column -delete">
<div class="column-contents">
<h2 class="subtitle">
<div class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<!--! Font Awesome Pro 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path
d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"
/>
</svg>
</div>
<span>Delete colors</span>
</h2>
</div>
<button id="deleteButton" class="button -red">
Delete All Color Styles
</button>
</div>
</main>
</div>
<script>
document
.getElementById('importFormat')
.addEventListener('change', (event) => {
const importFormat = event.target.value;
const flat = document.getElementById('flat');
const nested = document.getElementById('nested');
if (importFormat === 'flat') {
flat.style.display = 'flex';
nested.style.display = 'none';
} else {
flat.style.display = 'none';
nested.style.display = 'flex';
}
});
document
.getElementById('importButton')
.addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const importFormat = document.getElementById('importFormat').value;
if (file) {
const reader = new FileReader();
reader.onload = async (event) => {
const contents = event.target.result;
window.parent.postMessage(
{
pluginMessage: {
type: 'importColors',
contents,
importFormat,
},
},
'*',
);
};
reader.readAsText(file);
} else {
window.alert('JSON file is not registered. Please select a file.');
}
});
document.getElementById('exportButton').addEventListener('click', () => {
const exportFormat = document.getElementById('exportFormat').value;
const colorFormat = document.getElementById('colorFormat').value;
window.parent.postMessage(
{
pluginMessage: { type: 'exportColors', exportFormat, colorFormat },
},
'*',
);
});
document.getElementById('deleteButton').addEventListener('click', () => {
if (window.confirm('All Color Styles will be removed. Are you sure?')) {
window.parent.postMessage(
{
pluginMessage: { type: 'deleteColors' },
},
'*',
);
}
});
window.addEventListener('message', (event) => {
const message = event.data.pluginMessage;
if (message.type === 'exportedColors') {
const exportedStyles = message.exportedStyles;
const dataStr =
'data:text/json;charset=utf-8,' +
encodeURIComponent(JSON.stringify(exportedStyles, null, 2));
const downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute('href', dataStr);
downloadAnchorNode.setAttribute('download', 'exported-styles.json');
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
});
</script>
</body>
</html>