56 lines
1.8 KiB
Plaintext
56 lines
1.8 KiB
Plaintext
<div class="container has-text-centered">
|
|
<p class="title">
|
|
Wasm Base64 Converter
|
|
</p>
|
|
<div vg-if="c.TextToB64">
|
|
<textarea vg-content='c.PlainText' @keyup="c.ToB64(event)" placeholder="Plaintext" rows="4" cols="50"></textarea>
|
|
<div style="margin-bottom: 0.5rem;"></div>
|
|
<textarea vg-content='c.B64String' placeholder="Base64" rows="4" cols="50"></textarea>
|
|
</div>
|
|
<div vg-if="c.B64ToText">
|
|
<textarea vg-content='c.B64String' @keyup="c.ToString(event)" placeholder="Base64" rows="4" cols="50"></textarea>
|
|
<div style="margin-bottom: 0.5rem;"></div>
|
|
<textarea vg-content='c.PlainText' placeholder="Plaintext" rows="4" cols="50"></textarea>
|
|
</div>
|
|
<a class="button is-light" @click="c.Swap(event)" style="margin-top: 0.5rem;">
|
|
<span class="iconify" data-icon="heroicons-solid:refresh"></span> Swap
|
|
</a>
|
|
</div>
|
|
|
|
|
|
<script type="application/x-go">
|
|
|
|
import (
|
|
"encoding/base64"
|
|
)
|
|
|
|
type Base64 struct {
|
|
B64String string `vugu:"data"`
|
|
PlainText string `vugu:"data"`
|
|
TextToB64 bool `vugu:"data"`
|
|
B64ToText bool `vugu:"data"`
|
|
}
|
|
|
|
func (c *Base64) Init() {
|
|
c.TextToB64 = true
|
|
}
|
|
|
|
func (c *Base64) ToB64(event vugu.DOMEvent) {
|
|
plaintext := event.PropString("target", "value")
|
|
b64String := base64.StdEncoding.EncodeToString([]byte(plaintext))
|
|
c.PlainText = plaintext
|
|
c.B64String = b64String
|
|
}
|
|
|
|
func (c *Base64) ToString(event vugu.DOMEvent) {
|
|
b64String := event.PropString("target", "value")
|
|
plain, _ := base64.StdEncoding.DecodeString(b64String)
|
|
c.PlainText = string(plain)
|
|
c.B64String = b64String
|
|
}
|
|
|
|
func (c *Base64) Swap(event vugu.DOMEvent) {
|
|
c.TextToB64, c.B64ToText = !c.TextToB64, !c.B64ToText
|
|
}
|
|
|
|
</script> |