@basaltkit/deploy-ui 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -64,6 +64,7 @@ repository must not be able to repoint it. The file holds no secret.
64
64
  {
65
65
  "version": 1,
66
66
  "actor": "alice",
67
+ "locale": "pt",
67
68
  "targets": [
68
69
  { "name": "staging", "ssh": "deploy@203.0.113.10", "dir": "/srv/myapp" },
69
70
  { "name": "production", "ssh": "myapp-prod", "port": 2222, "dir": "/srv/myapp", "node": "/usr/local/bin/node", "protected": true }
@@ -81,6 +82,7 @@ repository must not be able to repoint it. The file holds no secret.
81
82
  | `config` | optional `--config` path, relative to the checkout |
82
83
  | `protected` | deploy and rollback need the target's name typed |
83
84
  | `actor` | recorded with each release (`--actor`); default: your OS user name |
85
+ | `locale` | the page's language, `en` or `pt`, as you last picked it; default: your browser's language |
84
86
 
85
87
  Every field has a closed grammar (no leading `-`, no spaces, no `..`); an
86
88
  unknown field is refused, not ignored. The UI refuses a targets file that is a
@@ -95,16 +97,22 @@ since then, nothing is sent, and the page shows the new values.
95
97
 
96
98
  Per target: **check the connection**; **status** (current release, process,
97
99
  lock, active and last run, a hold); **plan** (findings, what a run would do, the
98
- questions it would ask); the **`.env` form** (secrets in password fields, never
100
+ questions it would ask, and the commits that will go out); the **`.env` form** (secrets in password fields, never
99
101
  stored, emptied after sending); **deploy** — detached by default, so a closed
100
102
  laptop lid does not stop it, or attended; the **live log**, which re-attaches
101
103
  after a dropped connection without a gap or a duplicate (even one cut
102
104
  mid-line); **cancel** (a second cancel, separately confirmed, stops it at
103
105
  once; the server decides which one it is, so a cancel already sent from a
104
106
  terminal counts); **rollback**, to the last
105
- healthy release or one picked from **history** (the last 10 releases); and
107
+ healthy release or one picked from **history** (the last 10 releases, each
108
+ with its subject and, one click away, the commits it brought in), with the
109
+ commits that would leave production listed before you confirm; and
106
110
  "Write .env only" for a first setup.
107
111
 
112
+ The page speaks **English and Portuguese**: your browser's language until you
113
+ pick one in the sidebar, then the one kept in the targets file. Only its own
114
+ words are translated; what the server's deploy prints is shown as it came.
115
+
108
116
  Each action is one `ssh` invocation of the app's own, lockfile-pinned
109
117
  `node node_modules/@basaltkit/deploy/dist/bin.js <command> --json=1`, with
110
118
  `--via=ui` so the release record says how it was made. `install`, `bootstrap`
@@ -1,3 +1,4 @@
1
+ import { t } from './i18n.js';
1
2
  /**
2
3
  * The page's calls to its local server: POST, JSON, the session token as a
3
4
  * bearer header (never a cookie: cookies are not port-scoped). Streams are
@@ -112,7 +113,7 @@ export class Api {
112
113
  const crypto = this.options.crypto;
113
114
  const serverKey = this.options.serverKey;
114
115
  if (!serverKey || !crypto?.subtle)
115
- throw this.stop('unverified', 'this page cannot check its local server (no server key, or no WebCrypto): nothing is sent');
116
+ throw this.stop('unverified', t('api.cannotCheck'));
116
117
  const nonce = toBase64Url(crypto.getRandomValues(new Uint8Array(32)));
117
118
  let proof;
118
119
  try {
@@ -121,7 +122,7 @@ export class Api {
121
122
  catch (error) {
122
123
  if (error instanceof ServerGone)
123
124
  throw error;
124
- throw this.stop('unverified', 'the local server refused to prove it is this UI: it is not the one this page was opened from');
125
+ throw this.stop('unverified', t('api.refusedProof'));
125
126
  }
126
127
  let valid = false;
127
128
  if (typeof proof === 'string' && /^[A-Za-z0-9_-]{43}$/.test(proof)) {
@@ -129,7 +130,7 @@ export class Api {
129
130
  valid = await crypto.subtle.verify('HMAC', key, fromBase64Url(proof), new TextEncoder().encode(`${PROOF_CONTEXT}${nonce}`));
130
131
  }
131
132
  if (!valid)
132
- throw this.stop('unverified', 'the local server could not prove it is this UI: another program may be listening on its port');
133
+ throw this.stop('unverified', t('api.wrongProof'));
133
134
  }
134
135
  /** A call; one that carries answers checks the server first. */
135
136
  async post(route, body = {}) {
@@ -171,7 +172,7 @@ export class Api {
171
172
  // The page's own bug is not the server going away.
172
173
  if (handlerFailed || signal?.aborted)
173
174
  throw error;
174
- throw this.stop('unreachable', 'the deploy UI stopped while this stream was open');
175
+ throw this.stop('unreachable', t('api.streamStopped'));
175
176
  }
176
177
  }
177
178
  async send(route, body) {
@@ -190,7 +191,7 @@ export class Api {
190
191
  catch (error) {
191
192
  if (signal?.aborted)
192
193
  throw error;
193
- throw this.stop('unreachable', 'the deploy UI is not running any more (it stopped after its idle time, from Quit, or with Ctrl-C)');
194
+ throw this.stop('unreachable', t('api.notRunning'));
194
195
  }
195
196
  }
196
197
  stop(why, message) {
@@ -1,6 +1,7 @@
1
1
  import { ApiError } from './api.js';
2
2
  import { confirmDialog } from './dialog.js';
3
3
  import { button, el, emptyState, quiet, replace } from './dom.js';
4
+ import { getLocale, isLocale, LOCALES, setLocale, t } from './i18n.js';
4
5
  import { icon } from './icons.js';
5
6
  import { describe } from './reply.js';
6
7
  import { renderHistory } from './view-history.js';
@@ -21,7 +22,20 @@ export function forgetSession(storage) {
21
22
  // No storage: nothing kept.
22
23
  }
23
24
  }
24
- const SCREENS = [['status', 'Status', 'status'], ['plan', 'Plan & deploy', 'plan'], ['history', 'History', 'history'], ['run', 'Run', 'run'], ['targets', 'Targets', 'targets']];
25
+ const SCREENS = [['status', 'screen.status', 'status'], ['plan', 'screen.plan', 'plan'], ['history', 'screen.history', 'history'], ['run', 'screen.run', 'run'], ['targets', 'screen.targets', 'targets']];
26
+ /**
27
+ * The page's fixed shell (page.ts) in the current language: the document's
28
+ * `lang`, the screens' landmark and the local-only note.
29
+ */
30
+ export function applyShell(doc) {
31
+ doc.documentElement.lang = getLocale();
32
+ doc.getElementById('nav')?.setAttribute('aria-label', t('shell.screens'));
33
+ const note = doc.querySelector('.local-note');
34
+ note?.setAttribute('title', t('shell.localOnlyTitle'));
35
+ const label = doc.querySelector('.local-label');
36
+ if (label)
37
+ replace(label, t('shell.localOnly'));
38
+ }
25
39
  /** Per-target state the screens render; every server string in it is shown as text only. */
26
40
  export class App {
27
41
  api;
@@ -37,6 +51,10 @@ export class App {
37
51
  statusBusy = false;
38
52
  planBusy = false;
39
53
  stopped = false;
54
+ /** The rollback target each previewed rollback showed, by run id: the run says when the deploy chose another. */
55
+ previewedRollbacks = new Map();
56
+ /** The commits between two releases never change: read once per target and pair. */
57
+ ranges = new Map();
40
58
  constructor(api, shell, storage) {
41
59
  this.api = api;
42
60
  this.shell = shell;
@@ -54,7 +72,7 @@ export class App {
54
72
  this.stopped = true;
55
73
  this.run?.stop();
56
74
  forgetSession(this.storage);
57
- replace(this.shell.main, el('div', { class: 'stopped' }, emptyState('power', 'Disconnected', 'This page sends nothing from here on.'), el('div', { class: 'banner err', role: 'alert' }, icon('error', 'icon banner-icon'), el('div', { class: 'banner-body' }, el('strong', { class: 'banner-title' }, error.why === 'unverified' ? 'This page no longer talks to your deploy UI.' : 'The deploy UI has stopped.'), el('p', {}, error.message), el('p', {}, 'Nothing was sent. Detached runs go on on the server. Start basalt-deploy-ui again and open the URL it prints.')))));
75
+ replace(this.shell.main, el('div', { class: 'stopped' }, emptyState('power', t('gone.title'), t('gone.sendsNothing')), el('div', { class: 'banner err', role: 'alert' }, icon('error', 'icon banner-icon'), el('div', { class: 'banner-body' }, el('strong', { class: 'banner-title' }, error.why === 'unverified' ? t('gone.unverified') : t('gone.stopped')), el('p', {}, error.message), el('p', {}, t('gone.help'))))));
58
76
  replace(this.shell.nav);
59
77
  this.clearBar();
60
78
  replace(this.shell.session);
@@ -66,8 +84,10 @@ export class App {
66
84
  return this.planReply?.result;
67
85
  }
68
86
  async start() {
69
- replace(this.shell.session, el('button', { type: 'button', class: 'ghost danger', on: { click: () => { void this.quit(); } } }, icon('power'), 'Quit'));
70
87
  await this.loadTargets();
88
+ if (this.targets.locale && this.targets.locale !== getLocale())
89
+ this.useLocale(this.targets.locale);
90
+ this.renderSession();
71
91
  const first = this.targets.targets[0];
72
92
  if (first) {
73
93
  this.select(first.name);
@@ -77,6 +97,37 @@ export class App {
77
97
  else
78
98
  this.show('targets');
79
99
  }
100
+ /** The switcher and Quit, at the foot of the sidebar. */
101
+ renderSession() {
102
+ const select = el('select', { id: 'locale-select', aria: { label: t('language') }, on: { change: (event) => {
103
+ const value = event.target.value;
104
+ if (isLocale(value))
105
+ void this.chooseLocale(value);
106
+ } } }, ...LOCALES.map((locale) => {
107
+ const option = el('option', { value: locale }, t(`language.${locale}`));
108
+ option.lang = locale;
109
+ option.selected = locale === getLocale();
110
+ return option;
111
+ }));
112
+ replace(this.shell.session, el('div', { class: 'locale' }, icon('globe'), select), el('button', { type: 'button', class: 'ghost danger', on: { click: () => { void this.quit(); } } }, icon('power'), t('quit')));
113
+ }
114
+ /** Every screen again in another language; nothing is asked of the server. */
115
+ useLocale(locale) {
116
+ setLocale(locale);
117
+ applyShell(this.shell.main.ownerDocument);
118
+ }
119
+ /** The operator's choice: the page switches at once, and the targets file keeps it for the next start (best effort). */
120
+ async chooseLocale(locale) {
121
+ this.useLocale(locale);
122
+ this.renderSession();
123
+ this.refresh();
124
+ try {
125
+ this.targets = await this.api.post('targets/save', { locale });
126
+ }
127
+ catch {
128
+ // Not saved: this tab still speaks it.
129
+ }
130
+ }
80
131
  async loadTargets() {
81
132
  this.targets = await this.api.post('targets');
82
133
  if (this.current && !this.targets.targets.some((t) => t.name === this.current?.name))
@@ -114,30 +165,30 @@ export class App {
114
165
  if (screen === 'targets')
115
166
  return replace(main, renderTargets(this));
116
167
  if (!this.current)
117
- return replace(main, emptyState('targets', 'No target selected', 'Add a target first.', el('span', { class: 'row' }, button('Targets', () => this.show('targets'), { class: 'primary' }))));
168
+ return replace(main, emptyState('targets', t('app.noTarget'), t('app.addTargetFirst'), el('span', { class: 'row' }, button(t('screen.targets'), () => this.show('targets'), { class: 'primary' }))));
118
169
  if (screen === 'status')
119
170
  return replace(main, renderStatus(this));
120
171
  if (screen === 'plan')
121
172
  return replace(main, renderPlan(this));
122
173
  if (screen === 'history')
123
174
  return replace(main, renderHistory(this));
124
- replace(main, this.run ? this.run.element : el('section', { aria: { label: 'Run' } }, emptyState('run', 'Nothing running here', 'No run in this tab yet: start one from Plan & deploy, or attach from Status.')));
175
+ replace(main, this.run ? this.run.element : el('section', { aria: { label: t('screen.run') } }, emptyState('run', t('app.nothingRunning'), t('app.nothingRunningText'))));
125
176
  }
126
177
  /** Re-renders the current screen (after a state change). */
127
178
  refresh() {
128
179
  this.show(this.screen);
129
180
  }
130
181
  renderNav() {
131
- const select = el('select', { id: 'target-select', aria: { label: 'Target' }, on: { change: (event) => { this.select(event.target.value); this.refresh(); if (this.current)
182
+ const select = el('select', { id: 'target-select', aria: { label: t('target') }, on: { change: (event) => { this.select(event.target.value); this.refresh(); if (this.current)
132
183
  void this.refreshStatus(); } } }, ...this.targets.targets.map((t) => {
133
184
  const option = el('option', { value: t.name }, t.name);
134
185
  option.selected = t.name === this.current?.name;
135
186
  return option;
136
187
  }));
137
- replace(this.shell.nav, this.targets.targets.length > 0 ? el('div', { class: 'nav-target' }, el('label', { class: 'section-label', for: 'target-select' }, 'Target'), select) : null, el('div', { class: 'nav-list' }, ...SCREENS.map(([screen, label, name]) => el('button', {
188
+ replace(this.shell.nav, this.targets.targets.length > 0 ? el('div', { class: 'nav-target' }, el('label', { class: 'section-label', for: 'target-select' }, t('target')), select) : null, el('div', { class: 'nav-list' }, ...SCREENS.map(([screen, label, name]) => el('button', {
138
189
  type: 'button', class: 'nav-item', ...(screen === this.screen ? { aria: { current: 'page' } } : {}),
139
190
  on: { click: () => this.show(screen) },
140
- }, icon(name), label))));
191
+ }, icon(name), t(label)))));
141
192
  }
142
193
  /**
143
194
  * "Am I about to deploy production?": name, destination, the server's host
@@ -145,29 +196,29 @@ export class App {
145
196
  * screen readers and copy, drawn as rules.
146
197
  */
147
198
  renderBar() {
148
- const t = this.current;
149
- if (!t)
199
+ const target = this.current;
200
+ if (!target)
150
201
  return this.clearBar();
151
202
  const status = this.status;
152
203
  const sep = () => el('span', { class: 'ctx-sep', aria: { hidden: 'true' } }, ' · ');
153
204
  const item = (name, value, label) => [sep(),
154
205
  el('span', { class: 'ctx-item' }, icon(name), label ? el('span', { class: 'ctx-label' }, label) : null, label ? ' ' : null, el('span', { class: 'ctx-val' }, value))];
155
- this.shell.bar.classList.toggle('is-protected', t.protected === true);
156
- replace(this.shell.bar, el('span', { class: 'ctx-target' }, el('strong', { class: 'ctx-name' }, t.name), t.protected ? el('span', { class: 'badge badge-protected', title: 'Deploy and rollback ask for the name to be typed' }, icon('shield'), quiet(' '), 'PROTECTED') : null), ...item('terminal', `${t.ssh}${t.port ? `:${t.port}` : ''}`), ...item('folder', t.dir), ...(this.hello ? [...item('server', this.hello.host, 'host'), ...item('tag', this.hello.version, 'deploy')] : []), ...(status ? item('app', status.app, 'app') : []));
206
+ this.shell.bar.classList.toggle('is-protected', target.protected === true);
207
+ replace(this.shell.bar, el('span', { class: 'ctx-target' }, el('strong', { class: 'ctx-name' }, target.name), target.protected ? el('span', { class: 'badge badge-protected', title: t('protected.title') }, icon('shield'), quiet(' '), t('protected.badge')) : null), ...item('terminal', `${target.ssh}${target.port ? `:${target.port}` : ''}`), ...item('folder', target.dir), ...(this.hello ? [...item('server', this.hello.host, t('ctx.host')), ...item('tag', this.hello.version, t('ctx.deploy'))] : []), ...(status ? item('app', status.app, t('ctx.app')) : []));
157
208
  }
158
209
  clearBar() {
159
210
  this.shell.bar.classList.remove('is-protected');
160
211
  replace(this.shell.bar);
161
212
  }
162
213
  async refreshStatus() {
163
- const t = this.current;
164
- if (!t)
214
+ const target = this.current;
215
+ if (!target)
165
216
  return;
166
217
  this.statusBusy = true;
167
218
  if (this.screen === 'status')
168
219
  this.refresh();
169
220
  try {
170
- this.statusReply = await this.api.post('status', { target: t.name });
221
+ this.statusReply = await this.api.post('status', { target: target.name });
171
222
  if (this.statusReply.hello)
172
223
  this.hello = this.statusReply.hello;
173
224
  }
@@ -177,18 +228,18 @@ export class App {
177
228
  finally {
178
229
  this.statusBusy = false;
179
230
  }
180
- if (this.current?.name === t.name)
231
+ if (this.current?.name === target.name)
181
232
  this.refresh();
182
233
  }
183
234
  async runPlan() {
184
- const t = this.current;
185
- if (!t)
235
+ const target = this.current;
236
+ if (!target)
186
237
  return;
187
238
  this.planBusy = true;
188
239
  this.planReply = undefined;
189
240
  this.refresh();
190
241
  try {
191
- this.planReply = await this.api.post('plan', { target: t.name });
242
+ this.planReply = await this.api.post('plan', { target: target.name });
192
243
  if (this.planReply.hello)
193
244
  this.hello = this.planReply.hello;
194
245
  }
@@ -198,9 +249,28 @@ export class App {
198
249
  finally {
199
250
  this.planBusy = false;
200
251
  }
201
- if (this.current?.name === t.name)
252
+ if (this.current?.name === target.name)
202
253
  this.refresh();
203
254
  }
255
+ /** The commits between two releases of the current target (read-only on the server). */
256
+ commits(from, to) {
257
+ const target = this.current;
258
+ const key = `${target.name}\u0000${from}\u0000${to}`;
259
+ let reply = this.ranges.get(key);
260
+ if (!reply) {
261
+ reply = this.api.post('commits', { target: target.name, from, to });
262
+ // A failure is not remembered: the next click asks again.
263
+ reply.then((r) => { if (!r.ok)
264
+ this.ranges.delete(key); }, () => this.ranges.delete(key));
265
+ this.ranges.set(key, reply);
266
+ }
267
+ return reply;
268
+ }
269
+ /** What a rollback would take out of production, now (never cached: the releases move). */
270
+ rollbackPreview(to) {
271
+ const target = this.current;
272
+ return this.api.post('commits', { target: target.name, rollback: true, ...(to ? { to } : {}) });
273
+ }
204
274
  /** A run to watch: a new view, attached from the seq this tab last saw (or 0). */
205
275
  watch(runId, title, fromStart = false) {
206
276
  if (this.run?.runId === runId && !this.run.ended && this.run.following) {
@@ -208,8 +278,7 @@ export class App {
208
278
  return this.run;
209
279
  }
210
280
  this.run?.stop();
211
- const t = this.current;
212
- this.run = new RunView(this, t, title, runId);
281
+ this.run = new RunView(this, this.current, title, runId);
213
282
  this.show('run');
214
283
  void this.run.attach(fromStart ? 0 : this.run.resumeSeq());
215
284
  return this.run;
@@ -217,8 +286,7 @@ export class App {
217
286
  /** An attended stream (env, an attended run): it stops if this page closes. */
218
287
  attended(title, route, body) {
219
288
  this.run?.stop();
220
- const t = this.current;
221
- this.run = new RunView(this, t, title, undefined);
289
+ this.run = new RunView(this, this.current, title, undefined);
222
290
  this.show('run');
223
291
  void this.run.streamAttended(route, body);
224
292
  return this.run;
@@ -226,12 +294,9 @@ export class App {
226
294
  async quit() {
227
295
  const watching = this.run?.following === true;
228
296
  const ok = await confirmDialog({
229
- title: 'Quit the deploy UI?',
230
- lines: [
231
- 'The local server stops and this page stops working.',
232
- watching ? 'A run is being watched: detached runs go on on the server (re-attach later); an attended one stops at its next step.' : 'Detached runs go on on the server.',
233
- ],
234
- confirmLabel: 'Quit',
297
+ title: t('quit.title'),
298
+ lines: [t('quit.line'), watching ? t('quit.watching') : t('quit.detached')],
299
+ confirmLabel: t('quit'),
235
300
  });
236
301
  if (!ok)
237
302
  return;
@@ -244,7 +309,7 @@ export class App {
244
309
  }
245
310
  this.stopped = true;
246
311
  forgetSession(this.storage);
247
- replace(this.shell.main, el('div', { class: 'stopped' }, emptyState('power', 'Stopped', 'The deploy UI has stopped. You can close this tab.', 'Detached runs go on on the server; start basalt-deploy-ui again to re-attach.')));
312
+ replace(this.shell.main, el('div', { class: 'stopped' }, emptyState('power', t('quit.stopped'), t('quit.stoppedText'), t('quit.stoppedHelp'))));
248
313
  replace(this.shell.nav);
249
314
  this.clearBar();
250
315
  replace(this.shell.session);
@@ -1,4 +1,5 @@
1
1
  import { append, button, el } from './dom.js';
2
+ import { t } from './i18n.js';
2
3
  import { icon } from './icons.js';
3
4
  /**
4
5
  * A native modal `<dialog>` (focus stays inside, Escape cancels). Resolves
@@ -18,7 +19,7 @@ export function confirmDialog(options, host = document.body) {
18
19
  resolve(answer);
19
20
  };
20
21
  const confirm = button(options.confirmLabel, () => finish(true), { class: options.danger ? 'danger' : 'primary' });
21
- const dismiss = button('Cancel', () => finish(false));
22
+ const dismiss = button(t('cancel'), () => finish(false));
22
23
  let typed;
23
24
  if (options.typeToConfirm !== undefined) {
24
25
  const expected = options.typeToConfirm;
@@ -28,7 +29,7 @@ export function confirmDialog(options, host = document.body) {
28
29
  on: { input: () => { confirm.disabled = typed.value !== expected; } },
29
30
  });
30
31
  }
31
- append(dialog, el('div', { class: 'dialog-head' }, el('span', { class: 'dialog-icon' }, icon(options.danger ? 'alert' : 'info')), el('h2', { id: 'confirm-title' }, options.title)), el('div', { class: 'dialog-body' }, options.context ? el('p', { class: 'dialog-context' }, options.context) : null, options.typeToConfirm !== undefined ? el('p', { class: 'dialog-protected' }, el('span', { class: 'badge badge-protected' }, icon('shield'), 'PROTECTED'), ' This target is protected.') : null, ...options.lines.filter((line) => line !== null && line !== undefined && line !== false && line !== '').map((line) => el('p', {}, line)), typed ? el('div', { class: 'field' }, el('label', { for: 'confirm-name' }, 'Type ', el('code', {}, options.typeToConfirm), ' to confirm'), typed) : null), el('div', { class: 'dialog-actions' }, dismiss, confirm));
32
+ append(dialog, el('div', { class: 'dialog-head' }, el('span', { class: 'dialog-icon' }, icon(options.danger ? 'alert' : 'info')), el('h2', { id: 'confirm-title' }, options.title)), el('div', { class: 'dialog-body' }, options.context ? el('p', { class: 'dialog-context' }, options.context) : null, options.typeToConfirm !== undefined ? el('p', { class: 'dialog-protected' }, el('span', { class: 'badge badge-protected' }, icon('shield'), t('protected.badge')), t('dialog.protected')) : null, ...options.lines.filter((line) => line !== null && line !== undefined && line !== false && line !== '').map((line) => el('p', {}, line)), typed ? el('div', { class: 'field' }, el('label', { for: 'confirm-name' }, t('dialog.typeTo'), el('code', {}, options.typeToConfirm), t('dialog.toConfirm')), typed) : null), el('div', { class: 'dialog-actions' }, dismiss, confirm));
32
33
  dialog.addEventListener('cancel', (event) => { event.preventDefault(); finish(false); });
33
34
  dialog.addEventListener('keydown', (event) => { if (event.key === 'Escape')
34
35
  finish(false); });
@@ -24,6 +24,8 @@ export function el(tag, props = {}, ...children) {
24
24
  node.required = true;
25
25
  if (props.hidden)
26
26
  node.hidden = true;
27
+ if (props.colspan !== undefined)
28
+ node.setAttribute('colspan', String(props.colspan));
27
29
  if (props.spellcheck !== undefined)
28
30
  node.spellcheck = props.spellcheck;
29
31
  for (const [key, value] of Object.entries(props.aria ?? {}))
@@ -0,0 +1,14 @@
1
+ /** Identity helper that pins a catalog's key/value types for `t()`. */
2
+ export function defineMessages(messages) {
3
+ return messages;
4
+ }
5
+ const interpolate = (template, params) => template.replace(/\{(\w+)\}/g, (_match, key) => params[key] === undefined ? `{${key}}` : String(params[key]));
6
+ /** Resolves a message value to a string for a locale, applying plurals + params. */
7
+ export function render(value, locale, params) {
8
+ if (typeof value === 'string')
9
+ return interpolate(value, params);
10
+ const count = Number(params['count'] ?? 0);
11
+ const category = new Intl.PluralRules(locale).select(count);
12
+ const template = value[category] ?? value.other ?? '';
13
+ return interpolate(template, params);
14
+ }