oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1package savestatus
2
3import _ "embed"
4
5//go:embed status.html
6var markup string
7
8//go:embed status.css
9var css []byte
10
11//go:embed status.mjs
12var javascript []byte
13
14// Data is one save status. Placement is "inline" (the default),
15// "floating" or "subtitle" (Mode).
16type Data struct {
17 State, Placement string
18 Saved, Saving, Retrying, Failed, Label string
19}
20
21func (d Data) CurrentState() string {
22 switch d.State {
23 case "saved", "saving", "retrying", "failed":
24 return d.State
25 default:
26 return "idle"
27 }
28}
29
30func (d Data) CurrentText() string {
31 switch d.CurrentState() {
32 case "saved":
33 return d.Saved
34 case "saving":
35 return d.Saving
36 case "retrying":
37 return d.Retrying
38 case "failed":
39 return d.Failed
40 default:
41 return ""
42 }
43}
44
45// Mode is the placement as estilo-save-status's value: "floating" (the
46// corner toast), "inline subtitle" (the line under a large title, Docs
47// on a phone) or "inline", the default, for anything else.
48func (d Data) Mode() string {
49 switch d.Placement {
50 case "floating":
51 return "floating"
52 case "subtitle":
53 return "inline subtitle"
54 }
55 return "inline"
56}
57
58func Template() string { return markup }
59func CSS() []byte { return append([]byte(nil), css...) }
60func JS() []byte { return append([]byte(nil), javascript...) }
61