-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
733 lines (643 loc) · 29.7 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
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fourier Artist</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="description" content="Discover the art of Fourier transformations with Fourier Artist in p5.js. Redraw complex representations using sinusoidal waves, simplifying and reusing data for a captivating and unique artistic experience.">
<meta name="keywords" content="Fourier transformations, p5.js, art, creative coding, sinusoidal waves, data visualization">
<meta name="author" content="Abbas Majidov">
<link rel="icon" href="static/examples/redcircle.png" type="image/png">
</head>
<body>
<div class="all" id="app">
<div id="main-loading" v-if="loading">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div class="row justify-content-center align-items-center h-100 position-relative">
<div class="col-12 p-3 d-md-none d-flex justify-content-between mobile-nav position-absolute top-0">
<div class="p-2" :class='step === 1 ? "selected-step": "non-selected-step"' @click='step = 1'>Import image</div>
<div class="p-2" :class='step === 2 ? "selected-step": "non-selected-step"' @click='step = 2'>Options</div>
<div class="p-2" :class='step === 3 ? "selected-step": "non-selected-step"' @click='step = 3'>Coordinates</div>
</div>
<div class="col-md-5 control-panel" ref="cpanel" :style="{'--control-panel-width': controlPanel.width}"
:class="svg ? (controlPanel.toggle ? 'l-2' : 'l-1') : ''" @transitionstart="svg ? loading = false : false" @transitionend="controlPanel.toggle === null && svg ? controlPanel.toggle = false : false">
<div class="row">
<!-- Navigation -->
<div id="nav" :class="controlPanel.toggle !== null ? 'col-11' : 'col-12'">
<div class="row">
<div class='nav-panel d-none d-md-flex col-md-4 position-relative p-0 p-3 flex-column justify-content-between'>
<ol>
<li :class='step === 1 ? "selected-step": "non-selected-step"' @click='step = 1'>
Import image
</li>
<li :class='step === 2 ? "selected-step": "non-selected-step"' @click='step = 2'>
Options
</li>
<li :class='step === 3 ? "selected-step": "non-selected-step"' @click='step = 3'>
Get Coordinates
</li>
</ol>
<div>
<h4>Fourier artist</h4>
<p class="text-muted">Redraw image, with fourier complex number.
<br /><small><a href='https://linkedin.com/in/absmj'>Abbas Majidov</a> @ <a
href='https://www.bankrespublika.com'>Bank Respublika</a></small>
</p>
<img src="static/examples/p5js.svg" alt="This is p5.js project" class="img-fluid" style="width: 5em;">
<hr>
<p class="fw-bold" :class='step === 4 ? "selected-step": "non-selected-step"' @click='step = 4'>
why this exists, thanks & credits
</p>
</div>
</div>
<div class="active-step-panel col-12 col-md-8 p-0">
<!-- Svg input -->
<div class='step-1 p-3' :class='step === 1 ? "d-block" : "d-none"'>
<h2>Import image</h2>
<hr>
<div v-show="svg">
<div class="d-flex justify-content-center align-items-center d-none" id="svg-content"></div>
<div class="d-flex justify-content-center align-items-center" id="svg-content-org"></div>
<hr>
</div>
<label for="file-upload" class="custom-file-upload">
Select File
</label>
<input id="file-upload" type="file" @change="handleFile" />
<hr>
<p>Find more image at the <a data-bs-toggle="modal" @click="selectedApi=1"
data-bs-target="#api-modal">Wikimedia Commons</a> or <a data-bs-toggle="modal"
@click="selectedApi=0" data-bs-target="#api-modal">Noun
Project [only svg]</a>
</p>
<div :style='{stroke: error ? "#EB1E32" : "#F037A5"}' ref="svgHolder" id='svg-holder'></div>
<hr>
<div class="form-floating">
<small for="floatingTextarea2">or paste the SVG text file below and try making changes</small>
<textarea id="coord-content" v-model="svg" class="form-control"
style="height: 200px">{{svg}}</textarea>
</div>
<hr>
<h5>...or try an example</h5>
<hr>
<div class='example-container'>
<div class='example-container'>
<button v-for="(example, key) in examples" :key="key" @click="getExample(example)" class='dot-button' :class="example.name == exampleName ? 'selected-dot-button' : ''"><img class="img-fluid" style="height: 3em;" :src="example.url" :alt="example.name"></button>
</div>
</div>
</div>
<div class='step-2' :class="step==2?'d-block':'d-none'">
<h2 class="p-3 m-0" x>Options</h2>
<hr>
<fieldset id="options" :disabled="!svg">
<div class="row">
<label class="col-8 col-form-label" for="">Number of points:</label>
<div class="col-4">
<input class='form-control' type='text' v-model='svgInstance.waveCount' />
</div>
<div class="col-12">
<input class="form-range" type='range' min='1' max='5000' v-model='svgInstance.waveCount' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Scale:</label>
<div class="col-4">
<input class='form-control' type='text' v-model='svgInstance.scale' />
</div>
<div class="col-12">
<input class="form-range" type='range' min='0.1' max='10' step="0.1"
v-model.number='svgInstance.scale' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">TranslateX:</label>
<div class="col-4">
<input class='form-control' type='text' v-model.number='svgInstance.transformX' />
</div>
<div class="col-12">
<input class="form-range" type='range' min='1' :max='svgInstance.canvas.width'
:min='-svgInstance.canvas.width' step="1" v-model.number='svgInstance.transformX' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">TranslateY:</label>
<div class="col-4">
<input class='form-control' type='text' v-model.number='svgInstance.transformY' />
</div>
<div class="col-12">
<input class="form-range" type='range' min='1' :min='-svgInstance.canvas.height'
:max='svgInstance.canvas.height' step="1" v-model.number='svgInstance.transformY' />
</div>
</div>
<hr>
<div class="row">
<div class="col-12">
<div class="form-check">
<input class='form-check-input' type="checkbox" v-model='svgInstance.seperate' />
<label class="form-check-label" for="">Seperate</label>
</div>
<div class="form-check">
<input class='form-check-input' type="checkbox" v-model='options.show.grid' />
<label class="form-check-label" for="">Grid</label>
</div>
<div class="form-check">
<input class='form-check-input' type="checkbox" v-model='options.show.axis' />
<label class="form-check-label" for="">Coordinate axis</label>
</div>
<div class="form-check">
<input class='form-check-input' type="checkbox" v-model='options.show.coordinate' />
<label class="form-check-label" for="">Show coordinates</label>
</div>
</div>
</div>
<hr>
<div class="row">
<label class="col-6 col-form-label" for="">Drawing type:</label>
<div class="col-6 d-flex align-items-center">
<label class="form-check-label" for="flexCheckDefault">
Line
</label>
<div class="form-check form-switch justify-content-between m-0 ms-2">
<input class="form-check-input" type="checkbox" role="switch" v-model="options.dots.active"
id="flexCheckDefault">
</div>
<label class="form-check-label" for="flexCheckDefault">
Dots
</label>
</div>
</div>
<hr>
<div v-if="options.dots.active" class="row">
<label class="col-8 col-form-label" for="">Dot radius:</label>
<div class="col-12">
<input class="form-range" type='range' min='1' max='25' step="1"
v-model='options.dots.radius' />
</div>
</div>
<div class="row">
<label class="col-8 col-form-label" for="">Background color:</label>
<div class="col-4">
<input :value="options.background" class='color-picker' type="color"
@change='options.background = $event.target.value' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Color:</label>
<div class="col-4">
<input :value="options.color" class='color-picker' type="color"
@change='options.color = $event.target.value' />
</div>
<div class="col-12">
<div class="d-grid gap-2">
<a @click='options.color="random"' class="btn btn-primary fw-bold">
<span :style="{color:confetti()}">C</span>
<span :style="{color:confetti()}">o</span>
<span :style="{color:confetti()}">n</span>
<span :style="{color:confetti()}">f</span>
<span :style="{color:confetti()}">e</span>
<span :style="{color:confetti()}">t</span>
<span :style="{color:confetti()}">t</span>
<span :style="{color:confetti()}">i</span>
<span :style="{color:confetti()}">!</span>
</a>
</div>
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Ellipse opacity:</label>
<div class="col-12">
<input class="form-range" type='range' min='0'
max='100' step="1" v-model.number='options.ellipseStroke.opacity' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Line opacity:</label>
<div class="col-12">
<input class="form-range" type='range' min='0'
max='100' step="1" v-model.number='options.lineStroke.opacity' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Ellipse color:</label>
<div class="col-4">
<input :value="options.ellipseStroke.color" class='color-picker' type="color"
@change='options.ellipseStroke.color = $event.target.value' />
</div>
</div>
<hr>
<div class="row">
<label class="col-8 col-form-label" for="">Line color:</label>
<div class="col-4">
<input :value="options.lineStroke.color" class='color-picker' type="color"
@change='options.lineStroke.color = $event.target.value' />
</div>
</div>
</fieldset>
</div>
<!-- Svg input -->
<div class='step-3 p-3' :class='step === 3 && svg ? "d-block" : "d-none"'>
<h2>Coordinates</h2>
<hr>
<label v-if="svg" @click="downloadJSON" for="file-download" class="custom-file-upload">
JSON
</label>
<hr>
<div v-if="svg" class="form-floating">
<textarea readonly ref="coord-content" class="form-control"
style="height: 500px">{{pathCoordinates}}</textarea>
</div>
</div>
<div class="step-4 p-3" :class="step == 4 ? 'd-block' : 'd-none'">
<div>
<h4>Inspiration</h4>
<figure>
<blockquote class="blockquote">
<p>Why is the square of "i" a negative number...</p>
</blockquote>
<figcaption class="blockquote-footer">
In middle school mathematics, we are introduced to the number "i"; But why does this number
differ from other numbers...
</figcaption>
</figure>
<hr>
<p>
Starting with a simple question, I once again witnessed how fascinating and versatile mathematics
is as a result of the investigation. Especially in the calculations involving coordinates, the
application of this number leads to the creation of different representations and intricate
fractals in urban settings.
</p>
<h4>Fourier Transformations</h4>
<hr>
<p>
Here, representations are "redrawn" using Fourier transformations. Fourier transformations are
applied to separate information into sinusoidal waves, simplifying and reusing the data. See: <a
href="https://www.jezzamon.com/fourier/index.html">An Interactive Introduction to Fourier
Transforms</a>
</p>
<hr>
<h5>Thanks...</h5>
<hr>
<div>
<p class="p-0 m-0">Typically, this is created by <a href='https://twitter.com/alizauf'>Aliza
Aufrichtig</a> @ <a href='https://www.spotify.com'>Spotify</a>,</p>
<p class="p-0 m-0"><a href='https://twitter.com/shiffman'>Daniel Shiffman</a> @ <a
href='https://thecodingtrain.com'>Coding Train</a></p>
<p class="p-0 m-0"><a href='https://twitter.com/jezzamonn'>Jez Swanson</a> @ <a
href='https://www.jezzamon.com'>Google</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-if="svg" :class="controlPanel.toggle !== null ? 'col-1' : ''">
<button type="button" @click="controlPanel.toggle ^= 1" class="btn btn-sm btn-dark toggle-btn">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor"
class="bi bi-filter-circle-fill" viewBox="0 0 16 16">
<path
d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16M3.5 5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1 0-1M5 8.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m2 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5" />
</svg>
</button>
</div>
</div>
</div>
<div id='canvasHolder' class='col-12 h-100'></div>
</div>
<div id="api-modal" class="modal fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" v-html="getApi.title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body position-relative">
<div class="row g-2">
<div class="col-10">
<input type="search" id="query" name="query" v-model="getApi.query" class="form-control"
aria-describedby="passwordHelpBlock">
</div>
<div class="col-2">
<div class="d-grid gap-2">
<button :disabled="getApi.loading" @click="search()" class="btn btn-primary">Search</button>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-check mt-2">
<input :disabled="!getApi.supportPng" id="only-svg" class='form-check-input' type="checkbox" v-model='getApi.onlySvg' />
<label class="form-check-label" for="only-svg">Only SVG images</label>
<br>
<small>For the best results, we recommend trying SVG files.</small>
</div>
</div>
</div>
<hr>
<div :class="getApi.samples.length > 0 ? 'position-absolute' : ''" id="loading" v-if="getApi.loading">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div v-if="getApi.samples.length > 0" class="row g-3 justify-content-center">
<div v-for="sample in getApi.samples" :key="sample.id" class="col-auto">
<div class="card" style="width: 12rem;">
<img :src="sample.thumbnail_url" class="card-img-top" :alt="sample.attribution">
<div class="card-body">
<h6 class="card-title">{{sample.attribution.replace(/^(.{15})(.*)/, '$1...')}}</h6>
<p class="card-text">{{sample.creator.name}}</p>
<div class="d-grid gap-2">
<button :disabled="getApi.loading || sample.id == getApi.selected" class="btn btn-primary"
@click="select(sample.id, sample.creator.name)">Select</button>
</div>
</div>
</div>
</div>
<hr>
<div class="d-flex justify-content-center">
<button :disabled="getApi.loading" @click="searchFromCommonsApi(true)" class="btn btn-primary">Load
more...</button>
</div>
</div>
</div>
<div class="modal-footer justify-content-start">
<p v-html="getApi.info"></p>
</div>
</div>
</div>
</div>
<div class="toast-container position-fixed d-flex justify-content-end bottom-0 p-4 w-100">
<div id="error-toast" class="toast align-items-center text-bg-danger" role="alert" aria-live="assertive"
aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
{{error}}
</div>
<button type="button" class="btn-close btn-close-white me-2 me-2 m-auto" data-bs-dismiss="toast"
aria-label="Close"></button>
</div>
</div>
</div>
</div>
</body>
<script src="helpers/util.js"></script>
<script src="main.js"></script>
<script src="api.js"></script>
<script src="static/examples/index.js"></script>
<script src="vue.global.js"></script>
<script src="bootstrap.bundle.min.js"></script>
<script src="helpers/pathologist.js"></script>
<script src="libraries/p5.min.js"></script>
<script src="helpers/d3-array.js"></script>
<script src="helpers/ct.js"></script>
<script src="helpers/complex.js"></script>
<script src="helpers/coordinates.js"></script>
<script src="sketch.js"></script>
<script defer src="libraries/imagetracer.js"></script>
<script>
const { createApp, ref } = Vue;
const app = createApp({
setup() {
const api = ref(apiList)
const loading = ref(false)
const selectedApi = ref(0)
const toast = ref(null)
const step = ref(1)
const svg = ref(null)
const coordinates = ref([])
const error = ref(null)
const svgTextError = ref(null)
const svgInstance = ref(sketchData)
const modal = ref(null)
const page = ref(0)
const exampleName =ref(null)
const controlPanel = ref({
width: 'auto',
height: 'auto',
toggle: null
})
return { loading, step, examples, exampleName, svg, coordinates, error, svgTextError, svgInstance, api, selectedApi, toast, modal, page, options, controlPanel }
},
computed: {
getApi() {
return this.api[this.selectedApi]
},
pathCoordinates() {
return !this.svgInstance.seperate ?
this.svgInstance.pathCoordinates[0].map(k => ({ x: k[0], y: k[1] })) :
this.svgInstance.pathCoordinates.map(i => i.map(k => ({ x: k[0], y: k[1] })))
}
},
watch: {
svg(newVal, oldValue) {
sketch.coordinates(newVal);
//scaling and centerize
sketch.data.scale = sketch.optimize.scale(sketch.data.canvas, sketch.data.svg)
sketch.data.waveCount = sketch.optimize.numberOfDots(sketch.data.waveCount) || sketch.data.waveCount
const c = sketch.optimize.center(sketch.data.canvas, sketch.data.svg)
sketch.data.transformX = c.x
sketch.data.transformY = c.y
sketch.calculation().mount()
this.controlPanel.toggle = false
},
svgInstance: {
handler(val) {
sketch.calculation().mount()
},
deep: true
},
options: {
handler(val) {
sketch.update('options', val)
},
deep: true
},
error(v) {
if (!v) {
this.toast.hide()
} else {
this.toast.show()
}
},
step() {
if(!this.controlPanel.toggle) this.controlPanel.toggle = true
}
},
mounted() {
this.modal = new bootstrap.Modal(document.getElementById("api-modal"))
this.toast = bootstrap.Toast.getOrCreateInstance(document.getElementById('error-toast'))
this.controlPanel.width = this.$refs.cpanel.offsetWidth + 'px';
this.controlPanel.height = this.$refs.cpanel.offsetHeight + 'px';
sketch.mount()
},
methods: {
handleFile(e) {
try {
const reader = new FileReader()
reader.onload = data => {
if (data) {
if (e.target.files[0].type == 'image/png') {
ImageTracer.imageToSVG(data.target.result, (svgString) => {
this.svg = svgString
}, { scale: 10 });
} else {
this.svg = data.target.result;
}
} else throw new Error("File content is empty or isn't readable")
}
reader.onerror = e => {
throw new Error(e)
}
reader[e.target.files[0].type == 'image/png' ? 'readAsDataURL' : 'readAsText'](e.target.files[0])
} catch (e) {
this.error = e.message
}
},
b64DecodeUnicode(str) {
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
},
async search(more = false) {
await this[this.getApi.search](more)
},
async select(id) {
await this[this.getApi.get](id)
},
async searchFromNounApi(more) {
try {
this.error = null;
this.getApi.loading = true;
const request = await fetch(`https://kale.eu5.org/index.php?api=${this.getApi.name}&action=search`, {
method: 'POST',
body: JSON.stringify({ query: this.getApi.buildQuery })
})
const response = await request.json()
if (!request.ok) throw new Error(response.message);
if (more)
this.getApi.samples.push(...response.icons)
else
this.getApi.samples = response.icons
} catch (e) {
this.error = e.message ?? e
} finally {
this.getApi.loading = false
}
},
async selectFromNounApi(id) {
try {
this.error = null
this.getApi.loading = true;
this.getApi.selected = id;
const request = await fetch(`https://kale.eu5.org/index.php?api=${this.getApi.name}&action=get`, {
method: 'POST',
body: JSON.stringify({ id: this.getApi.selected })
})
const response = await request.json()
if (!request.ok) throw new Error(response.message);
const getApiSvg = await fetch(response.icon.icon_url)
const svgData = await getApiSvg.text()
this.svg = svgData
this.modal.hide()
} catch (e) {
this.error = e.message ?? e
} finally {
this.getApi.loading = false;
}
},
async searchFromCommonsApi(more) {
try {
this.page += 1
this.error = null
this.getApi.loading = true
const request = await fetch(`https://kale.eu5.org/index.php?api=${this.getApi.name}&action=search&page=${this.page}`, {
method: 'POST',
body: JSON.stringify({ query: this.getApi.buildQuery })
})
const response = await request.json()
if (!request.ok) throw new Error(response.message);
if (more)
this.getApi.samples.push(...response)
else
this.getApi.samples = response
} catch (e) {
console.log(e)
this.error = e.message ?? e
} finally {
this.getApi.loading = false
}
},
async selectFromCommonsApi(url, type) {
try {
this.error = null
this.getApi.loading = true;
this.getApi.selected = url;
console.log(url)
const getApiSvg = await fetch(url)
if(!/svg/.test(type)) {
const imageData = await getApiSvg.blob()
ImageTracer.imageToSVG(URL.createObjectURL(imageData), (svgString) => {
this.svg = svgString
}, { scale: 10 });
} else {
const svg = await getImage.text()
this.svg = svg
}
this.modal.hide()
} catch (e) {
this.error = e.message ?? e
} finally {
this.getApi.loading = false;
}
},
async getExample(example) {
try {
this.loading = true;
this.error = null;
this.exampleName = example.name
example.selected = true;
const getImage = await fetch(example.url)
if(/image/.test(example.type)) {
const imageData = await getImage.blob()
ImageTracer.imageToSVG(URL.createObjectURL(imageData), (svgString) => {
this.svg = svgString
}, { scale: 10 });
} else {
// console.log(1)
const svg = await getImage.text()
this.svg = svg
}
} catch (e) {
this.error = e.message ?? e
} finally {
// this.loading = false
}
},
confetti() {
return `rgb(${Math.round(Math.random() * 255)}, ${Math.round(Math.random() * 255)}, ${Math.round(Math.random() * 255)})`;
},
downloadJSON() {
const blob = new Blob([this.$refs['coord-content'].value], { type: 'application/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'coordinates.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
},
})
app.mount('#app')
</script>
</html>