-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
375 lines (307 loc) · 13.4 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<title>Micro Editor ColorScheme</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<body>
<div id="vue_app" class="container-fluid bg-body-secondary fs-6 min-vh-100" data-bs-theme="dark">
<div class="row">
<!-- Left column -->
<div class="col mt-3">
<!-- Add new scheme -->
<div class="card mb-3">
<div class="card-header">
<h5 class="card-title mb-0">Add new</h5>
</div>
<div class="card-body">
<div class="form-group row">
<div class="col-md-1">
<input type="checkbox" class="form-check-input form-control form-control-sm"
v-model="new_color_link.is_active">
</div>
<div class="col-md-3">
<input type="text" class="form-control form-control-sm" v-model="new_color_link.link_name">
</div>
<div class="col-md-2">
<select name="text_decoration" class="form-control form-control-sm"
v-model="new_color_link.text_decoration">
<option value="">Empty</option>
<option value="bold">Bold</option>
<option value="italic">Italic</option>
<option value="underline">Underline</option>
</select>
</div>
<div class="col-md-2">
<input type="text" data-jscolor="{}" class="form-control form-control-sm"
v-model="new_color_link.font_color">
</div>
<div class="col-md-2">
<input type="text" data-jscolor="{}" class="form-control form-control-sm bg"
v-model="new_color_link.bg_color">
</div>
<div class="col-md-2">
<button class="form-control form-control-sm btn-primary" v-on:click="addNewScheme">Add</button>
</div>
</div>
<!-- End Adding form -->
</div>
</div>
<div class="card mb-3">
<div class="card-body">
<label for="schemeName">ColorScheme Name</label>
<input type="text" class="form-control" id="schemeName" v-model="scheme_name">
</div>
</div>
<div class="card mb-3">
<div class="card-header">
<h5 class="card-title mb-0">Options</h5>
</div>
<div class="card-body" id="formSchemeOptions">
<!-- Editing form -->
<div class="form-group row p-2" v-for="(cl, index) in color_links" :key="cl.link_name" :set="test_text = getTestText(index)" v-bind:style="{ 'color': cl.font_color, 'background-color': cl.bg_color }">
<div class="mb-2" v-bind:id="'goto_' + cl.link_name">
<i v-if="cl.text_decoration === 'italic'">
{{test_text}}
</i>
<b v-else-if="cl.text_decoration === 'bold'">
{{test_text}}
</b>
<u v-else-if="cl.text_decoration === 'underline'">
{{test_text}}
</u>
<span v-else>
{{test_text}}
</span>
</div>
<div class="col-md">
<input type="checkbox" class="form-check-input form-control form-control-sm" v-model="cl.is_active">
</div>
<div class="col-md-3">
<input type="text" class="form-control form-control-sm" v-model="cl.link_name">
</div>
<div class="col-md-2">
<select name="text_decoration" class="form-control form-control-sm" v-model="cl.text_decoration">
<option value="">Empty</option>
<option value="bold">Bold</option>
<option value="italic">Italic</option>
<option value="underline">Underline</option>
</select>
</div>
<div class="col-md-3">
<input type="text" data-jscolor="{}" class="form-control form-control-sm" v-model="cl.font_color">
</div>
<div class="col-md-3">
<input type="text" data-jscolor="{}" class="form-control form-control-sm bg" v-model="cl.bg_color">
</div>
<!-- <div class="col-md-1">
<button class="form-control form-control-sm bg-danger" v-on:click="deleteScheme(index)">X</button>
</div> -->
</div>
<!-- End Editing form -->
</div>
</div>
</div>
<!-- Right column -->
<div class="col mt-3">
<!-- <compact-picker v-model="test_color" /> -->
<div class="card mb-3">
<div class="card-header">
<h5 class="card-title mb-0">Code</h5>
</div>
<div class="card-body">
<code class="fs-18" id="schemeResult" v-on:click="copySchemeText">
<div># Color Scheme: {{ scheme_name }}</div>
<div># https://andertm.github.io/micro-editor-colorscheme/</div>
<div v-for="cl in color_links" :key="cl.link_name">
<a style="color: inherit" class="text-decoration-none" v-bind:href="'#goto_' + cl.link_name"> {{ !cl.is_active ? '#' : '' }}color-link {{ cl.link_name }} "{{ cl.text_decoration ? cl.text_decoration + ' ' : '' }}{{ cl.font_color ? cl.font_color + ',' : '' }}{{ cl.bg_color ? cl.bg_color : '' }}"</a>
</div>
</code>
</div>
<div class="card-footer text-center">
<button class="btn btn-primary" v-on:click="copySchemeText">Copy</button>
</div>
</div>
<div class="card mb-3">
<div class="card-header">
<h5 class="card-title mb-0">Import scheme</h5>
</div>
<div class="card-body">
<div class="card-text">
<textarea id="importScheme" class="form-control" rows="7">color-link default "#000000,#FFFFFF"</textarea>
</div>
</div>
<div class="card-footer text-center">
<div class="form-group row">
<div class="col-md-6">
<select name="scheme_files" class="form-select form-control-sm" v-model="scheme_file_selected" v-on:change="fetchScheme(scheme_file_selected)">
<option v-for="sf in scheme_files" v-on:change="fetchScheme(sf)">{{sf}}</option>
</select>
</div>
<div class="col-md-6">
<button class="form-control form-control-sm btn btn-primary " v-on:click="parseAndImportScheme">
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" class="bi bi-cloud-download" viewBox="0 0 16 16">
<path d="M4.406 1.342A5.53 5.53 0 0 1 8 0c2.69 0 4.923 2 5.166 4.579C14.758 4.804 16 6.137 16 7.773 16 9.569 14.502 11 12.687 11H10a.5.5 0 0 1 0-1h2.688C13.979 10 15 8.988 15 7.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 2.825 10.328 1 8 1a4.53 4.53 0 0 0-2.941 1.1c-.757.652-1.153 1.438-1.153 2.055v.448l-.445.049C2.064 4.805 1 5.952 1 7.318 1 8.785 2.23 10 3.781 10h5a.5.5 0 0 1 0 1H3.781C1.708 11 0 9.366 0 7.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"/>
<path d="M7.646 15.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 14.293V5.5a.5.5 0 0 0-1 0v8.793l-2.146-2.147a.5.5 0 0 0-.708.708l3 3z"/>
</svg>
Import
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="./js/bootstrap.bundle.min.js"></script>
<script src="./js/vue.global.prod.v.3.3.4.js"></script>
<!-- <script src="./js/vue-color.min.js"></script> -->
<script src="./js/jscolor.2.5.1-min.js"></script>
<script>
jscolor.presets.default = {
required:false,
palette: ['#FFFFFF', '#000000',
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
'brightblack', 'brightred', 'brightgreen', 'brightyellow', 'brightblue', 'brightmagenta', 'brightcyan', 'brightwhite'],
}
</script>
<script>
function parse_scheme(schemeStr) {
schemeArray = [];
schemeStr.trim().split("\n").forEach(el => {
el = el.trim();
// # color-link error-message.test "bold #000000,#FFFFFF"
let regexp = /(?<gIsActive>#\s*)?color-link\s*(?<gColorName>.*\s)\"(?<gTextDecor>bold|italic|underline\s*)?(?<gFontColor>.*,)?(?<gBgColor>.*)?\"/gi;
let matchAll = Array.from(el.toLowerCase().matchAll(regexp))
if (matchAll.length) {
let schemeMatch = matchAll[0]['groups']
scheme = {
'is_active': schemeMatch.gIsActive !== undefined && schemeMatch.gIsActive.search('#') >= 0 ? false : true, // #
'link_name': schemeMatch.gColorName !== undefined && schemeMatch.gColorName ? schemeMatch.gColorName.trim() : '',
'text_decoration': schemeMatch.gTextDecor !== undefined && schemeMatch.gTextDecor ? scheme.text_decoration = schemeMatch.gTextDecor.trim() : '', // bold, italic, or underline
'font_color': schemeMatch.gFontColor !== undefined && schemeMatch.gFontColor ? schemeMatch.gFontColor.replace(',', '').trim().toUpperCase() : '',
'bg_color': schemeMatch.gBgColor !== undefined && schemeMatch.gBgColor ? schemeMatch.gBgColor.replace(',', '').trim().toUpperCase() : '',
};
schemeArray.push(scheme);
}
});
return schemeArray;
}
</script>
<script>
const { createApp, ref, reactive } = Vue
//const { Compact } = VueColor
const ColorLinks = [{
'is_active': true, // #
'link_name': 'default',
'text_decoration': '', // '', bold, italic, or underline
'font_color': '#FFFFFF',
'bg_color': '#000000',
}]
const ColorLinksAppSettings = {
/* components: {
'compact-picker': Compact
}, */
data() {
return {
scheme_name: ref('micro-theme-demo-tc'),
color_links: reactive(ColorLinks),
new_color_link: { ...ColorLinks[0] },
scheme_files: reactive([]),
scheme_file_selected: reactive('test-scheme.micro'),
//test_color: '#194d33',
}
},
/* watch: {
color_links: {
handler(newVal, oldVal) {
jscolor.install()
},
deep: true,
immediate: true,
}
}, */
methods: {
addNewScheme() {
for (let key in this.new_color_link) {
if (typeof this.new_color_link[key] == 'string') {
this.new_color_link[key] = String(this.new_color_link[key]).trim()
//console.log(this.new_color_link[key])
}
}
let is_exists_index = this.color_links.findIndex((scheme) => scheme.link_name == this.new_color_link.link_name)
if (is_exists_index >= 0) {
// update existing
this.color_links[is_exists_index] = { ...this.new_color_link }
} else {
// adding new
this.color_links.push({ ...this.new_color_link })
}
//jscolor.install()
},
parseAndImportScheme() {
let importSchemeEl = document.getElementById('importScheme');
schemeArray = parse_scheme(importSchemeEl.value)
//console.log(schemeArray)
this.color_links = [...schemeArray]
},
copySchemeText() {
el = document.getElementById('schemeResult')
navigator.clipboard.writeText(el.innerText)
console.log('Copied scheme text');
},
getTestText(index) {
const c = this.color_links[index]
return `Testing text '${c.link_name}'. Font-color: ${c.font_color}. Background: ${c.bg_color}`
},
deleteScheme(index) {
console.log({'deleteScheme - index': index})
delete this.color_links[index]
},
fetchSchemesFile() {
fetch('./scheme_files.json')
.then(data => data.json())
.then(data => {
//console.log(data)
this.scheme_files = data
})
},
fetchScheme(schemeName) {
//console.log('fetchScheme')
fetch('./colorschemes/' + schemeName)
.then(data => data.text())
.then(data => {
this.scheme_name = schemeName.replace('.micro', '')
let importSchemeEl = document.getElementById('importScheme');
importSchemeEl.innerHTML = data;
this.parseAndImportScheme()
});
},
},
computed: {
/* schemeCounts: function () {
return this.color_links.length
} */
},
mounted() {
console.log('mounted');
this.fetchSchemesFile();
/* fetch('/test-scheme.micro')
.then(data => {
data = data.text()
let importSchemeEl = document.getElementById('importScheme');
importSchemeEl.innerHTML = data;
this.parseAndImportScheme();
}); */
},
updated() {
console.log('updated')
jscolor.install()
},
}
const ColorLinksApp = createApp(ColorLinksAppSettings).mount('#vue_app')
</script>
</body>
</html>