oficina / estilo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package chrome
2
3import (
4 "fmt"
5 "strings"
6 "time"
7)
8
9// LinkLifetime is how long an emailed sign-in link works. It is
10// keymaildev/signin's LinkTTL default, which every sign-in in the suite
11// inherits: rastrillo's auth, Home's own flow and the keymail path all
12// leave LinkTTL unset (checked 2026-10-01 at signin v0.1.1, rastrillo
13// main 2fafa12 and v0.23.0, and Home 7a0f19c). The copy below says the
14// number, so a sign-in that changes its lifetime must change this too, or
15// the door and the email tell people something false.
16const LinkLifetime = 15 * time.Minute
17
18// DoorCopy is the door's words: the sign-in form, the check-your-email
19// state, the signed-out page and the sign-in email. English is the
20// suite's one copy set; a locale replaces the whole set through
21// SignIn.Copy and SignInNotice.Copy, never a word at a time, so no app
22// can drift from the others by overriding one line.
23//
24// The words are the copy deck in §9.2 of the shared-chrome spec
25// (docs/superpowers/specs/2026-09-23-shared-chrome.md, on estilo's
26// spec/shared-chrome branch), with Paul's later rulings noted where they
27// apply. "§9.2" and "§10" below are that document's sections.
28//
29// Translations are estilo's follow-up, never an app's. English is the
30// only set today. When the suite needs another locale, estilo adds its
31// whole DoorCopy here, beside English, with a way to pick one by locale,
32// and every app gets it on its next re-pin. An app passes Copy only a set
33// estilo publishes; it never writes or edits one, or the one copy set
34// fragments again the first time an app translates its own door.
35//
36// Slots are tokens, not Printf verbs: {app} is the app's name, and {link}
37// (the email body only) is the sign-in link. A translation may drop or
38// move a slot, or carry a literal "%", and still render as written.
39type DoorCopy struct {
40 // The form: heading (also the tab title's page), address label, the
41 // one help line under the field, and the submit.
42 Heading, AddressLabel, Help, Submit string
43 // The sent state, which replaces the form: heading (and tab title),
44 // body, and the link back to the form.
45 SentHeading, SentBody, Again string
46 // The signed-out page: the tab title's page, the heading, the body
47 // ({app} is the app's name), the Sign in button and the quiet
48 // "Forget me on this device" under it.
49 SignedOutPage, SignedOutHeading, SignedOutBody, SignIn, Forget string
50 // The sign-in email: subject ({app}) and body ({app} and {link}).
51 EmailSubject, EmailBody string
52}
53
54// linkMinutes is LinkLifetime in words, so the number lives in one place.
55var linkMinutes = fmt.Sprintf("%d minutes", int(LinkLifetime/time.Minute))
56
57// English is the door's copy set (shared-chrome spec §9.2). The submit
58// is "Sign in": Paul, 2026-10-01, ruled out "Email me a link". The hub is
59// never named ("Home"); the suite is Oficina (Paul, 2026-09-23).
60var English = DoorCopy{
61 Heading: "Sign in",
62 AddressLabel: "Email address",
63 Help: "We’ll email you a link that signs you in. It works once and expires in " + linkMinutes + ".",
64 Submit: "Sign in",
65 SentHeading: "Check your email",
66 SentBody: "If that address can sign in here, we’ve sent it a link. It works once and expires in " + linkMinutes + ".",
67 Again: "Use a different address",
68 SignedOutPage: "Signed out",
69 SignedOutHeading: "You’re signed out",
70 SignedOutBody: "You’ve signed out of {app} on this device.",
71 SignIn: "Sign in",
72 Forget: "Forget me on this device",
73 EmailSubject: "Sign in to {app}",
74 EmailBody: "Here’s your link to sign in to {app}:\n\n{link}\n\nIt works once and expires in " + linkMinutes + ". If you didn’t ask for it, you can ignore this email.",
75}
76
77// signedOutBody names the app; with none it names the suite, as the hub's
78// own signed-out page does.
79func (c DoorCopy) signedOutBody(app string) string {
80 if app == "" {
81 app = "Oficina"
82 }
83 return fill(c.SignedOutBody, app, "")
84}
85
86// fill puts the app's name and the link into a copy string's {app} and
87// {link} slots, in one pass: a name or link that itself contains a token
88// is not filled again.
89func fill(s, app, link string) string {
90 return strings.NewReplacer("{app}", app, "{link}", link).Replace(s)
91}
92
93func copyOf(c *DoorCopy) DoorCopy {
94 if c == nil {
95 return English
96 }
97 return *c
98}
99
100// Title is a page's tab title: "<Page> · <App>" (shared-chrome spec
101// §10), or whichever half is set when one is empty.
102func Title(page, app string) string {
103 page, app = strings.TrimSpace(page), strings.TrimSpace(app)
104 switch {
105 case page == "":
106 return app
107 case app == "":
108 return page
109 }
110 return page + " · " + app
111}
112
113// The form's words, read by estilo-signin.
114func (s SignIn) Heading() string { return copyOf(s.Copy).Heading }
115func (s SignIn) AddressLabel() string { return copyOf(s.Copy).AddressLabel }
116func (s SignIn) Help() string { return copyOf(s.Copy).Help }
117func (s SignIn) Submit() string { return copyOf(s.Copy).Submit }
118
119// Page is the sign-in page's part of the tab title ("Sign in"), for a
120// layout that appends the app's name itself; Title is the whole title.
121func (s SignIn) Page() string { return s.Heading() }
122func (s SignIn) Title() string { return Title(s.Page(), s.App) }
123
124// Sent is this door's check-your-email state: the door's heading and
125// body, and "Use a different address" linking to again (the form,
126// keeping the return; empty drops the link).
127func (n SignInNotice) Sent(again string) SignInNotice {
128 c := copyOf(n.Copy)
129 n.Heading, n.Body, n.page, n.Link = c.SentHeading, c.SentBody, c.SentHeading, nil
130 if again != "" {
131 n.Link = &Link{Href: again, Label: c.Again}
132 }
133 return n
134}
135
136// SignedOut is this door's signed-out page: "You’re signed out", the
137// sentence naming the app, and the primary Sign in linking to signin.
138func (n SignInNotice) SignedOut(signin string) SignInNotice {
139 c := copyOf(n.Copy)
140 n.Heading, n.Body, n.page, n.Link = c.SignedOutHeading, c.signedOutBody(n.App), c.SignedOutPage, nil
141 if signin != "" {
142 n.Link = &Link{Href: signin, Label: c.SignIn}
143 }
144 return n
145}
146
147// Forgetting adds "Forget me on this device" to a signed-out page, under
148// its Sign in: a POST to action, rastrillo auth's Forget, carrying
149// returnTo as return_to when it is set, and hidden as written. A shared
150// computer's way to leave nothing behind (smart-door spec, "Signed out").
151// An empty action adds nothing.
152func (n SignInNotice) Forgetting(action, returnTo string, hidden ...Hidden) SignInNotice {
153 n.Forget = nil
154 if action != "" {
155 n.Forget = &ForgetForm{Action: action, Return: returnTo, Label: copyOf(n.Copy).Forget, Hidden: hidden}
156 }
157 return n
158}
159
160// Page is the notice's part of the tab title: the door's own for Sent and
161// SignedOut ("Check your email", "Signed out"), otherwise the heading.
162func (n SignInNotice) Page() string {
163 if n.page != "" {
164 return n.page
165 }
166 return n.Heading
167}
168
169// Title is the notice's whole tab title, "<Page> · <App>".
170func (n SignInNotice) Title() string { return Title(n.Page(), n.App) }
171
172// SignInEmail is this copy set's sign-in email for app: subject and body
173// around link.
174func (c DoorCopy) SignInEmail(app, link string) (subject, body string) {
175 return c.MailSubject(app), c.MailBody(app)(link)
176}
177
178// MailSubject is the sign-in email's subject, "Sign in to <App>" in
179// English. (Not EmailSubject: that is the field it reads.)
180func (c DoorCopy) MailSubject(app string) string { return fill(c.EmailSubject, app, "") }
181
182// MailBody renders the sign-in email's body around the link.
183func (c DoorCopy) MailBody(app string) func(link string) string {
184 return func(link string) string { return fill(c.EmailBody, app, link) }
185}
186
187// SignInEmail is the sign-in email for app in English: subject and body
188// around link.
189func SignInEmail(app, link string) (subject, body string) { return English.SignInEmail(app, link) }
190
191// EmailSubject is the sign-in email's subject in English, "Sign in to
192// <App>": what rastrillo's auth.Config.Subject takes.
193func EmailSubject(app string) string { return English.MailSubject(app) }
194
195// EmailBody renders the English sign-in email's body around the link: the
196// shape keymaildev/signin's Flow.Body and rastrillo's auth.Config.Body
197// take.
198func EmailBody(app string) func(link string) string { return English.MailBody(app) }
199