sendproof-core 0.1.0.alpha.1

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.
Files changed (229) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +55 -0
  4. data/lib/sendproof/assets.rb +70 -0
  5. data/lib/sendproof/attribution.rb +98 -0
  6. data/lib/sendproof/capture.rb +66 -0
  7. data/lib/sendproof/clock.rb +54 -0
  8. data/lib/sendproof/configuration.rb +241 -0
  9. data/lib/sendproof/data_store.rb +34 -0
  10. data/lib/sendproof/dynamodb/store.rb +183 -0
  11. data/lib/sendproof/dynamodb.rb +17 -0
  12. data/lib/sendproof/elasticsearch/store.rb +24 -0
  13. data/lib/sendproof/elasticsearch.rb +17 -0
  14. data/lib/sendproof/firestore/interceptor.rb +38 -0
  15. data/lib/sendproof/firestore/store.rb +150 -0
  16. data/lib/sendproof/firestore.rb +99 -0
  17. data/lib/sendproof/handler.rb +23 -0
  18. data/lib/sendproof/identity.rb +37 -0
  19. data/lib/sendproof/limits.rb +113 -0
  20. data/lib/sendproof/middleware.rb +68 -0
  21. data/lib/sendproof/mongo/engine.rb +692 -0
  22. data/lib/sendproof/mongo/guarded.rb +100 -0
  23. data/lib/sendproof/mongo/plain.rb +45 -0
  24. data/lib/sendproof/mongo/store.rb +54 -0
  25. data/lib/sendproof/mongo/subscriber.rb +21 -0
  26. data/lib/sendproof/mongo.rb +41 -0
  27. data/lib/sendproof/mongoid/store.rb +58 -0
  28. data/lib/sendproof/mongoid.rb +65 -0
  29. data/lib/sendproof/observed_request.rb +108 -0
  30. data/lib/sendproof/opensearch/store.rb +21 -0
  31. data/lib/sendproof/opensearch.rb +17 -0
  32. data/lib/sendproof/operation_matcher.rb +28 -0
  33. data/lib/sendproof/pool_hooks.rb +80 -0
  34. data/lib/sendproof/preview_request.rb +44 -0
  35. data/lib/sendproof/preview_transport.rb +331 -0
  36. data/lib/sendproof/protocol.rb +81 -0
  37. data/lib/sendproof/provider.rb +83 -0
  38. data/lib/sendproof/recorder.rb +298 -0
  39. data/lib/sendproof/redaction.rb +98 -0
  40. data/lib/sendproof/redis/commands.rb +76 -0
  41. data/lib/sendproof/redis/store.rb +205 -0
  42. data/lib/sendproof/redis.rb +18 -0
  43. data/lib/sendproof/search/middleware.rb +39 -0
  44. data/lib/sendproof/search/store.rb +213 -0
  45. data/lib/sendproof/search.rb +82 -0
  46. data/lib/sendproof/stores/classify.rb +346 -0
  47. data/lib/sendproof/stores/guard.rb +127 -0
  48. data/lib/sendproof/stores/tables.rb +1328 -0
  49. data/lib/sendproof/stores.rb +12 -0
  50. data/lib/sendproof/trace_store.rb +110 -0
  51. data/lib/sendproof/transaction_control.rb +187 -0
  52. data/lib/sendproof/ui/action-bar.js +91 -0
  53. data/lib/sendproof/ui/api.js +239 -0
  54. data/lib/sendproof/ui/app.css +848 -0
  55. data/lib/sendproof/ui/app.js +742 -0
  56. data/lib/sendproof/ui/autofill.js +137 -0
  57. data/lib/sendproof/ui/code-copy.js +71 -0
  58. data/lib/sendproof/ui/code-picker.js +149 -0
  59. data/lib/sendproof/ui/commands.js +197 -0
  60. data/lib/sendproof/ui/components.js +77 -0
  61. data/lib/sendproof/ui/context-bar.js +82 -0
  62. data/lib/sendproof/ui/copy.js +92 -0
  63. data/lib/sendproof/ui/coverage-popover.js +35 -0
  64. data/lib/sendproof/ui/crumb-fit.js +80 -0
  65. data/lib/sendproof/ui/deprecation.js +164 -0
  66. data/lib/sendproof/ui/display-settings.js +175 -0
  67. data/lib/sendproof/ui/doc-diff.js +209 -0
  68. data/lib/sendproof/ui/docs-view.js +347 -0
  69. data/lib/sendproof/ui/favicon.png +0 -0
  70. data/lib/sendproof/ui/favicon.svg +1 -0
  71. data/lib/sendproof/ui/field-help.js +52 -0
  72. data/lib/sendproof/ui/field-modules.js +23 -0
  73. data/lib/sendproof/ui/fields/controls.js +179 -0
  74. data/lib/sendproof/ui/fields/dom.js +36 -0
  75. data/lib/sendproof/ui/fields/infer.js +71 -0
  76. data/lib/sendproof/ui/fields/lookup-source.js +63 -0
  77. data/lib/sendproof/ui/fields/lookup.js +285 -0
  78. data/lib/sendproof/ui/fields/render.js +496 -0
  79. data/lib/sendproof/ui/fields/select.js +175 -0
  80. data/lib/sendproof/ui/fields/validate.js +363 -0
  81. data/lib/sendproof/ui/fields/validation-formats.js +164 -0
  82. data/lib/sendproof/ui/fields/validation-references.js +68 -0
  83. data/lib/sendproof/ui/fields/validation-values.js +137 -0
  84. data/lib/sendproof/ui/generate-menu.js +44 -0
  85. data/lib/sendproof/ui/generate.js +184 -0
  86. data/lib/sendproof/ui/header-editor.js +777 -0
  87. data/lib/sendproof/ui/headers.js +188 -0
  88. data/lib/sendproof/ui/highlight.js +257 -0
  89. data/lib/sendproof/ui/history-popover.js +24 -0
  90. data/lib/sendproof/ui/i18n.js +253 -0
  91. data/lib/sendproof/ui/icons.js +87 -0
  92. data/lib/sendproof/ui/index.html +70 -0
  93. data/lib/sendproof/ui/issues.js +187 -0
  94. data/lib/sendproof/ui/json-view.js +166 -0
  95. data/lib/sendproof/ui/lang-icons.js +62 -0
  96. data/lib/sendproof/ui/layout.js +262 -0
  97. data/lib/sendproof/ui/listbox.js +334 -0
  98. data/lib/sendproof/ui/locales/ar-capture.js +366 -0
  99. data/lib/sendproof/ui/locales/ar-stores.js +116 -0
  100. data/lib/sendproof/ui/locales/ar.js +561 -0
  101. data/lib/sendproof/ui/locales/cs-capture.js +442 -0
  102. data/lib/sendproof/ui/locales/cs-stores.js +116 -0
  103. data/lib/sendproof/ui/locales/cs.js +689 -0
  104. data/lib/sendproof/ui/locales/da-capture.js +347 -0
  105. data/lib/sendproof/ui/locales/da-stores.js +116 -0
  106. data/lib/sendproof/ui/locales/da.js +522 -0
  107. data/lib/sendproof/ui/locales/de-capture.js +347 -0
  108. data/lib/sendproof/ui/locales/de-stores.js +116 -0
  109. data/lib/sendproof/ui/locales/de.js +519 -0
  110. data/lib/sendproof/ui/locales/el-capture.js +347 -0
  111. data/lib/sendproof/ui/locales/el-stores.js +116 -0
  112. data/lib/sendproof/ui/locales/el.js +520 -0
  113. data/lib/sendproof/ui/locales/en-capture.js +349 -0
  114. data/lib/sendproof/ui/locales/en-stores.js +95 -0
  115. data/lib/sendproof/ui/locales/en.js +522 -0
  116. data/lib/sendproof/ui/locales/es-capture.js +353 -0
  117. data/lib/sendproof/ui/locales/es-stores.js +116 -0
  118. data/lib/sendproof/ui/locales/es.js +525 -0
  119. data/lib/sendproof/ui/locales/fa-capture.js +348 -0
  120. data/lib/sendproof/ui/locales/fa-stores.js +116 -0
  121. data/lib/sendproof/ui/locales/fa.js +521 -0
  122. data/lib/sendproof/ui/locales/fi-capture.js +347 -0
  123. data/lib/sendproof/ui/locales/fi-stores.js +116 -0
  124. data/lib/sendproof/ui/locales/fi.js +523 -0
  125. data/lib/sendproof/ui/locales/fr-capture.js +353 -0
  126. data/lib/sendproof/ui/locales/fr-stores.js +116 -0
  127. data/lib/sendproof/ui/locales/fr.js +525 -0
  128. data/lib/sendproof/ui/locales/he-capture.js +358 -0
  129. data/lib/sendproof/ui/locales/he-stores.js +116 -0
  130. data/lib/sendproof/ui/locales/he.js +529 -0
  131. data/lib/sendproof/ui/locales/hi-capture.js +348 -0
  132. data/lib/sendproof/ui/locales/hi-stores.js +116 -0
  133. data/lib/sendproof/ui/locales/hi.js +523 -0
  134. data/lib/sendproof/ui/locales/id-capture.js +347 -0
  135. data/lib/sendproof/ui/locales/id-stores.js +116 -0
  136. data/lib/sendproof/ui/locales/id.js +521 -0
  137. data/lib/sendproof/ui/locales/it-capture.js +361 -0
  138. data/lib/sendproof/ui/locales/it-stores.js +116 -0
  139. data/lib/sendproof/ui/locales/it.js +523 -0
  140. data/lib/sendproof/ui/locales/ja-capture.js +346 -0
  141. data/lib/sendproof/ui/locales/ja-stores.js +116 -0
  142. data/lib/sendproof/ui/locales/ja.js +521 -0
  143. data/lib/sendproof/ui/locales/ko-capture.js +346 -0
  144. data/lib/sendproof/ui/locales/ko-stores.js +116 -0
  145. data/lib/sendproof/ui/locales/ko.js +522 -0
  146. data/lib/sendproof/ui/locales/nb-capture.js +349 -0
  147. data/lib/sendproof/ui/locales/nb-stores.js +116 -0
  148. data/lib/sendproof/ui/locales/nb.js +521 -0
  149. data/lib/sendproof/ui/locales/nl-capture.js +355 -0
  150. data/lib/sendproof/ui/locales/nl-stores.js +116 -0
  151. data/lib/sendproof/ui/locales/nl.js +520 -0
  152. data/lib/sendproof/ui/locales/pl-capture.js +432 -0
  153. data/lib/sendproof/ui/locales/pl-stores.js +116 -0
  154. data/lib/sendproof/ui/locales/pl.js +528 -0
  155. data/lib/sendproof/ui/locales/pt-BR-capture.js +350 -0
  156. data/lib/sendproof/ui/locales/pt-BR-stores.js +116 -0
  157. data/lib/sendproof/ui/locales/pt-BR.js +523 -0
  158. data/lib/sendproof/ui/locales/pt-PT-capture.js +350 -0
  159. data/lib/sendproof/ui/locales/pt-PT-stores.js +116 -0
  160. data/lib/sendproof/ui/locales/pt-PT.js +523 -0
  161. data/lib/sendproof/ui/locales/ru-capture.js +437 -0
  162. data/lib/sendproof/ui/locales/ru-stores.js +116 -0
  163. data/lib/sendproof/ui/locales/ru.js +624 -0
  164. data/lib/sendproof/ui/locales/sv-capture.js +349 -0
  165. data/lib/sendproof/ui/locales/sv-stores.js +116 -0
  166. data/lib/sendproof/ui/locales/sv.js +518 -0
  167. data/lib/sendproof/ui/locales/th-capture.js +347 -0
  168. data/lib/sendproof/ui/locales/th-stores.js +116 -0
  169. data/lib/sendproof/ui/locales/th.js +521 -0
  170. data/lib/sendproof/ui/locales/tr-capture.js +348 -0
  171. data/lib/sendproof/ui/locales/tr-stores.js +116 -0
  172. data/lib/sendproof/ui/locales/tr.js +521 -0
  173. data/lib/sendproof/ui/locales/uk-capture.js +442 -0
  174. data/lib/sendproof/ui/locales/uk-stores.js +116 -0
  175. data/lib/sendproof/ui/locales/uk.js +630 -0
  176. data/lib/sendproof/ui/locales/vi-capture.js +346 -0
  177. data/lib/sendproof/ui/locales/vi-stores.js +116 -0
  178. data/lib/sendproof/ui/locales/vi.js +523 -0
  179. data/lib/sendproof/ui/locales/zh-Hans-capture.js +347 -0
  180. data/lib/sendproof/ui/locales/zh-Hans-stores.js +116 -0
  181. data/lib/sendproof/ui/locales/zh-Hans.js +523 -0
  182. data/lib/sendproof/ui/locales/zh-Hant-capture.js +346 -0
  183. data/lib/sendproof/ui/locales/zh-Hant-stores.js +116 -0
  184. data/lib/sendproof/ui/locales/zh-Hant.js +522 -0
  185. data/lib/sendproof/ui/manifest.json +866 -0
  186. data/lib/sendproof/ui/markdown.js +39 -0
  187. data/lib/sendproof/ui/model-view.js +182 -0
  188. data/lib/sendproof/ui/navigation.js +233 -0
  189. data/lib/sendproof/ui/operation-header.js +76 -0
  190. data/lib/sendproof/ui/operations.js +7 -0
  191. data/lib/sendproof/ui/overview-view.js +63 -0
  192. data/lib/sendproof/ui/personas.js +59 -0
  193. data/lib/sendproof/ui/popover.js +71 -0
  194. data/lib/sendproof/ui/preview-false.js +108 -0
  195. data/lib/sendproof/ui/request-editor.js +496 -0
  196. data/lib/sendproof/ui/response-metadata.js +354 -0
  197. data/lib/sendproof/ui/response-viewer.js +618 -0
  198. data/lib/sendproof/ui/result-blocked.js +155 -0
  199. data/lib/sendproof/ui/result-capture.js +25 -0
  200. data/lib/sendproof/ui/result-database.js +185 -0
  201. data/lib/sendproof/ui/result-effects.js +176 -0
  202. data/lib/sendproof/ui/result-headers.js +106 -0
  203. data/lib/sendproof/ui/result-logs.js +408 -0
  204. data/lib/sendproof/ui/result-states.js +213 -0
  205. data/lib/sendproof/ui/results.js +371 -0
  206. data/lib/sendproof/ui/router.js +118 -0
  207. data/lib/sendproof/ui/schema-model.js +336 -0
  208. data/lib/sendproof/ui/schema-tree.js +344 -0
  209. data/lib/sendproof/ui/schema.js +397 -0
  210. data/lib/sendproof/ui/security.js +31 -0
  211. data/lib/sendproof/ui/seeded-menu.js +69 -0
  212. data/lib/sendproof/ui/settings.js +93 -0
  213. data/lib/sendproof/ui/shortcuts-sheet.js +73 -0
  214. data/lib/sendproof/ui/shortcuts.js +190 -0
  215. data/lib/sendproof/ui/sidebar.js +289 -0
  216. data/lib/sendproof/ui/signin.js +259 -0
  217. data/lib/sendproof/ui/snippets.js +530 -0
  218. data/lib/sendproof/ui/store-marks.js +47 -0
  219. data/lib/sendproof/ui/stores.js +131 -0
  220. data/lib/sendproof/ui/styles.css +971 -0
  221. data/lib/sendproof/ui/toggletip.js +53 -0
  222. data/lib/sendproof/ui/uuid.js +10 -0
  223. data/lib/sendproof/ui/view.js +122 -0
  224. data/lib/sendproof/ui/views.css +653 -0
  225. data/lib/sendproof/version.rb +9 -0
  226. data/lib/sendproof/workbench.rb +102 -0
  227. data/lib/sendproof-core.rb +3 -0
  228. data/lib/sendproof.rb +121 -0
  229. metadata +292 -0
@@ -0,0 +1,82 @@
1
+ // The head row of the main column, the same in Try it, Docs, Models and the overview: where you
2
+ // are (breadcrumbs) at the start, how to switch views or go back at the end. It is exactly one
3
+ // tab tall, so it lines up with the sidebar tabs and the right column's head row.
4
+ //
5
+ // Operation: Payments › Create payment [Try it | Docs]
6
+ // From an op: Payments › Create payment › Payment [← Back to Create payment ⌥←]
7
+ // with followed $refs: … › Payment › Counterparty [← Back to Payment ⌥←]
8
+ // From Models: Models › Resources › Payment (no Back control)
9
+ //
10
+ // Earlier crumbs are links. On a phone CSS shows only the last crumb and the Back button. A row
11
+ // that is short of room wraps the view switch to a second line rather than squeezing the crumbs
12
+ // (see .ctx-bar in styles.css).
13
+ import { esc, icon } from './components.js';
14
+ import { t } from './i18n.js';
15
+ import { shortcutAttrs, shortcutHint, shortcutLong } from './shortcuts.js';
16
+ import { formatRoute, backTarget } from './router.js';
17
+ import { modelGroupOf } from './schema-model.js';
18
+
19
+ /** The Try it | Docs segmented switch. `view` is "try" or "docs". D toggles it. */
20
+ export function viewSwitch(view) {
21
+ return `<div class="segmented view-switch" role="group" aria-label="${esc(t('op.view'))}">
22
+ <button type="button" data-action="view-try" aria-pressed="${view === 'try'}" ${view === 'try' ? '' : shortcutAttrs('docs')}>${icon('flask', true)}${esc(t('op.tryIt'))}</button>
23
+ <button type="button" data-action="view-docs" aria-pressed="${view === 'docs'}" ${view === 'docs' ? '' : shortcutAttrs('docs')}>${icon('book', true)}${esc(t('op.docs'))}</button>
24
+ </div>`;
25
+ }
26
+
27
+ /** The ordered list of crumbs. Each is `{ label, href?, attrs?, here? }`; spec text carries lang="en". */
28
+ function crumbList(c) {
29
+ const link = (label, href, attrs = '', lang = true) => ({ label, href, attrs, lang });
30
+ if (c.kind === 'overview') return [{ label: t('overview.crumb'), here: true }];
31
+ if (c.kind === 'op') {
32
+ return [link(c.op.group, '#', `data-crumb-tag="${esc(c.op.group)}"`), { label: c.op.title, here: true, lang: true }];
33
+ }
34
+ // A model page.
35
+ const route = c.route;
36
+ const trail = (route.via ?? []).map((name, index) => link(name, formatRoute({ ...route, name, via: route.via.slice(0, index) }), `data-crumb-route`));
37
+ if (c.from) {
38
+ const fromRoute = { kind: route.from.kind, id: route.from.id };
39
+ return [
40
+ link(c.from.group, '#', `data-crumb-tag="${esc(c.from.group)}"`),
41
+ link(c.from.title, formatRoute(fromRoute), 'data-crumb-route'),
42
+ ...trail,
43
+ { label: route.name, here: true, lang: true },
44
+ ];
45
+ }
46
+ const group = modelGroupOf(route.name, c.document);
47
+ return [
48
+ link(t('side.models'), '#', 'data-crumb-models', false),
49
+ link(t('models.group.' + group), '#', `data-crumb-model-group="${esc(group)}"`, false),
50
+ ...trail,
51
+ { label: route.name, here: true, lang: true },
52
+ ];
53
+ }
54
+
55
+ /**
56
+ * The one Back control of a model page opened from an operation, labelled with where it goes
57
+ * ("Back to Payment") and the shortcut. Models picked in the Models tab have no Back.
58
+ */
59
+ function backButton(c) {
60
+ const target = c.route.kind === 'model' ? backTarget(c.route) : null;
61
+ if (!target) return '';
62
+ const name = target.label.kind === 'model' ? target.label.name : c.from?.title ?? target.label.id;
63
+ const label = t('back.to', { name });
64
+ return `<button type="button" class="btn btn-ghost btn-xs back-btn" data-action="model-back" ${shortcutAttrs('model-back')} title="${esc(`${label} (${shortcutLong('model-back')})`)}">${icon('arrow-left', true)}<span class="back-label" lang="en">${esc(label)}</span>${shortcutHint('model-back')}</button>`;
65
+ }
66
+
67
+ /**
68
+ * The head row markup.
69
+ * @param {{ kind: 'overview'|'op'|'model', view?: 'try'|'docs', op?: object, route?: object, from?: object, document?: object }} c
70
+ * `from` is the operation a model was opened from.
71
+ */
72
+ export function contextBar(c) {
73
+ const list = crumbList(c);
74
+ // Every crumb carries its full text as a title: a long name ends in an ellipsis when the row is
75
+ // short of room, and the title (hover, long-press, assistive technology) still gives all of it.
76
+ const crumbs = list.map(item => item.here
77
+ ? `<li><span aria-current="page"${item.lang ? ' lang="en"' : ''} title="${esc(item.label)}">${esc(item.label)}</span></li>`
78
+ : `<li><a href="${esc(item.href)}" ${item.attrs}${item.lang ? ' lang="en"' : ''} title="${esc(item.label)}">${esc(item.label)}</a></li>`).join('');
79
+ const end = c.kind === 'op' ? viewSwitch(c.view) : c.kind === 'model' ? backButton(c) : '';
80
+ // `--parents` tells the stylesheet how much room the earlier crumbs need (see .ctx-bar in styles.css).
81
+ return `<div class="ctx-bar"><nav class="crumbs" aria-label="${esc(t('crumbs'))}" style="--parents:${list.length - 1}"><ol>${crumbs}</ol></nav><div class="end">${end}</div></div>`;
82
+ }
@@ -0,0 +1,92 @@
1
+ // The one clipboard path. Success shows a check and a "Copied" bubble on the button for 1.5 s
2
+ // and announces it politely; nothing reflows. If the browser blocks the clipboard, an inline
3
+ // notice appears where the copy was, the text is selected so ⌘C works, and no pane is replaced.
4
+ import { icon, inlineNote } from './components.js';
5
+ import { t, th } from './i18n.js';
6
+ import { shortcutHint } from './shortcuts.js';
7
+
8
+ const FEEDBACK_MS = 1500;
9
+ const timers = new WeakMap();
10
+
11
+ async function write(text) {
12
+ try {
13
+ await navigator.clipboard.writeText(text);
14
+ return true;
15
+ } catch {
16
+ // Embedded views and iframes can deny the async API; the legacy command may still work.
17
+ const area = document.createElement('textarea');
18
+ area.value = text;
19
+ area.setAttribute('readonly', '');
20
+ Object.assign(area.style, { position: 'fixed', insetBlockStart: '-100vh', opacity: '0' });
21
+ document.body.append(area);
22
+ area.select();
23
+ let copied = false;
24
+ try { copied = document.execCommand('copy'); } catch { copied = false; }
25
+ area.remove();
26
+ return copied;
27
+ }
28
+ }
29
+
30
+ function announce(text) {
31
+ const region = document.querySelector('[data-request-announcement]');
32
+ if (!region) return;
33
+ region.textContent = '';
34
+ requestAnimationFrame(() => { region.textContent = text; });
35
+ }
36
+
37
+ function showCopied(button) {
38
+ if (!button) return;
39
+ clearTimeout(timers.get(button));
40
+ button.classList.add('is-copied');
41
+ if (button.classList.contains('btn-icon') && !button.querySelector('.copied-bubble')) {
42
+ button.insertAdjacentHTML('beforeend', `<span class="copied-bubble" aria-hidden="true">${icon('check', true)}${t('copy.copied')}</span>`);
43
+ }
44
+ timers.set(button, setTimeout(() => {
45
+ button.classList.remove('is-copied');
46
+ button.querySelector('.copied-bubble')?.remove();
47
+ }, FEEDBACK_MS));
48
+ }
49
+
50
+ /** Selects the text of an element so the user can copy it with the keyboard. */
51
+ function selectContents(target) {
52
+ if (!target) return;
53
+ const selection = getSelection();
54
+ const range = document.createRange();
55
+ range.selectNodeContents(target);
56
+ selection.removeAllRanges();
57
+ selection.addRange(range);
58
+ target.classList.add('is-selected');
59
+ document.addEventListener('selectionchange', function clear() {
60
+ if (!selection.containsNode(target, true)) {
61
+ target.classList.remove('is-selected');
62
+ document.removeEventListener('selectionchange', clear);
63
+ }
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Copies text and shows feedback.
69
+ * - button: the copy button that gets the check and bubble.
70
+ * - what: a short noun for announcements, such as "URL" ("URL copied").
71
+ * - select: the element whose text is selected if the clipboard is blocked.
72
+ * - notice: where the inline failure notice is inserted (before this element).
73
+ */
74
+ export async function copyText(text, { button, what, select, notice } = {}) {
75
+ const noticeHost = notice ?? select;
76
+ noticeHost?.parentElement?.querySelector(':scope > [data-copy-failure]')?.remove();
77
+ if (await write(String(text ?? ''))) {
78
+ showCopied(button);
79
+ announce(what ? t('copy.copiedWhat', { what }) : t('copy.copied'));
80
+ return true;
81
+ }
82
+ const message = th('copy.failed', { what: what ? what.toLowerCase() : t('copy.text'), key: shortcutHint('copy') });
83
+ if (noticeHost) {
84
+ noticeHost.insertAdjacentHTML('beforebegin', inlineNote(message, { tone: 'danger', flush: !!noticeHost.closest('.viewer'), glyph: 'alert', role: 'alert', dismiss: true }));
85
+ const note = noticeHost.previousElementSibling;
86
+ note.dataset.copyFailure = '';
87
+ note.querySelector('[data-dismiss-note]')?.addEventListener('click', () => note.remove());
88
+ }
89
+ selectContents(select);
90
+ if (!noticeHost) announce(t('copy.failedShort'));
91
+ return false;
92
+ }
@@ -0,0 +1,35 @@
1
+ // The environment chip's panel (docs/plans/data-stores.md, "Coverage disclosure"): every store
2
+ // the binding hooked, from discovery's `dataStores`, with what Preview does to it, and the plain
3
+ // statement that stores and clients the binding never saw are not covered. Opened from the top
4
+ // bar's environment chip, which is a button only when discovery lists stores.
5
+ import { esc, icon } from './components.js';
6
+ import { t } from './i18n.js';
7
+ import { openPopoverAt } from './popover.js';
8
+ import { dataStores, sqlSystem, storeMark, storeName } from './stores.js';
9
+
10
+ /** The rows: the SQL database first (it always rolls back), then each hooked store. */
11
+ export function coverageRows(capabilities = {}) {
12
+ const database = typeof capabilities.database === 'string' ? capabilities.database : capabilities.database?.name;
13
+ const rows = database ? [{ system: sqlSystem(capabilities), name: database, mode: 'preview', reason: '' }] : [];
14
+ return [...rows, ...dataStores(capabilities)];
15
+ }
16
+
17
+ /** The panel's markup, also used by tests. */
18
+ export function coverageMarkup(capabilities = {}) {
19
+ const row = store => `<li class="cov-row">
20
+ ${storeMark(store.system, 20)}
21
+ <span class="stack"><span class="main">${esc(storeName(store.system))}${store.name ? ` <code class="ltr">${esc(store.name)}</code>` : ''}</span>
22
+ <span class="sub">${store.reason ? `<span lang="en">${esc(store.reason)}</span>` : esc(t(store.mode === 'preview' ? 'cov.preview' : 'cov.guard'))}</span></span>
23
+ <span class="mode-pill is-${store.mode}">${icon(store.mode === 'preview' ? 'undo' : 'ban', true)}${esc(t(store.mode === 'preview' ? 'cov.mode.preview' : 'cov.mode.guard'))}</span>
24
+ </li>`;
25
+ return `<div class="pop cov-pop" role="dialog" aria-labelledby="coverage-title">
26
+ <div class="pop-head"><span id="coverage-title">${esc(t('cov.title', { env: capabilities.environment || '' }))}</span></div>
27
+ <ul class="cov-list">${coverageRows(capabilities).map(row).join('')}</ul>
28
+ <p class="cov-foot">${icon('shield', true)}<span>${esc(t('cov.limit'))}</span></p>
29
+ </div>`;
30
+ }
31
+
32
+ /** Opens the panel under the environment chip. */
33
+ export function openCoverage(anchor, { capabilities }) {
34
+ openPopoverAt(anchor, coverageMarkup(capabilities), { align: 'start', kind: 'coverage', focus: false });
35
+ }
@@ -0,0 +1,80 @@
1
+ // Fits the head row's earlier crumbs to their text, in every browser.
2
+ //
3
+ // An earlier crumb may be squeezed down to a readable stub (--crumb-parent-min, 5rem; see .ctx-bar
4
+ // in app.css) but must never reserve more room than its own text needs, or a short crumb leaves a
5
+ // gap before the next chevron. CSS cannot say "min(5rem, my natural width)" (min() takes no
6
+ // max-content, and calc-size() is not in Firefox or Safari), so this measures each earlier crumb's
7
+ // natural width and sets it as `--nat` on its <li>; the stylesheet's
8
+ // `min-inline-size: min(var(--crumb-parent-min), var(--nat, var(--crumb-parent-min)))` does the rest.
9
+ // Until a crumb is measured the flat stub applies, which is the same layout minus the gap.
10
+ //
11
+ // The width of a label can change without its box changing (a clamped crumb at a larger text
12
+ // size), so observing the labels is not enough. The head row is re-measured whenever one is added
13
+ // (every page and locale switch renders it afresh), when density, language or direction change on
14
+ // <html>, when the root font size changes (a probe one rem wide is observed, which also catches the
15
+ // browser's own text-size setting and zoom), when a web font finishes loading, and when the window
16
+ // resizes (a phone hides the earlier crumbs, which have no width then).
17
+
18
+ const SELECTOR = '.ctx-bar .crumbs li:not(:last-child)';
19
+
20
+ /** The outer inline size an earlier crumb's text needs: its label plus the link's padding and negative margin. */
21
+ function naturalWidth(item) {
22
+ const label = item.firstElementChild;
23
+ if (!label) return undefined;
24
+ const range = document.createRange();
25
+ range.selectNodeContents(label);
26
+ const style = getComputedStyle(label);
27
+ const sides = ['paddingInlineStart', 'paddingInlineEnd', 'marginInlineStart', 'marginInlineEnd'];
28
+ const extra = sides.reduce((sum, side) => sum + (parseFloat(style[side]) || 0), 0);
29
+ return range.getBoundingClientRect().width + extra;
30
+ }
31
+
32
+ /**
33
+ * Measures every earlier crumb under `root` and sets `--nat` on it. All reads come before any write,
34
+ * so the row lays out once. A crumb that is not shown (a phone hides them) keeps no measurement.
35
+ * @param {ParentNode} [root]
36
+ */
37
+ export function fitCrumbs(root = document) {
38
+ const items = [...root.querySelectorAll(SELECTOR)];
39
+ const widths = items.map(item => item.getClientRects().length ? naturalWidth(item) : undefined);
40
+ items.forEach((item, index) => {
41
+ // Round up to a whole pixel so subpixel text never ends in an ellipsis for want of 0.3px.
42
+ if (widths[index] === undefined) item.style.removeProperty('--nat');
43
+ else item.style.setProperty('--nat', `${Math.ceil(widths[index])}px`);
44
+ });
45
+ }
46
+
47
+ const addsHeadRow = mutation => [...mutation.addedNodes].some(node =>
48
+ node.nodeType === 1 && (node.matches('.ctx-bar') || node.querySelector('.ctx-bar')));
49
+
50
+ /**
51
+ * Keeps the measurements current for the life of the page. Call once at startup.
52
+ * @returns {() => void} stops watching
53
+ */
54
+ export function watchCrumbs() {
55
+ let queued = false;
56
+ const schedule = () => {
57
+ if (queued) return;
58
+ queued = true;
59
+ requestAnimationFrame(() => { queued = false; fitCrumbs(); });
60
+ };
61
+ const rows = new MutationObserver(mutations => { if (mutations.some(addsHeadRow)) schedule(); });
62
+ rows.observe(document.body, { childList: true, subtree: true });
63
+ // Density, script font, language and direction all live on <html>.
64
+ const root = new MutationObserver(schedule);
65
+ root.observe(document.documentElement, { attributes: true, attributeFilter: ['style', 'class', 'lang', 'dir', 'data-density'] });
66
+ // A box one rem wide: it resizes exactly when the root font size does (text size, zoom, density).
67
+ const probe = Object.assign(document.createElement('span'), { ariaHidden: 'true' });
68
+ probe.style.cssText = 'position:fixed;inset-block-start:0;inset-inline-start:0;inline-size:1rem;block-size:0;visibility:hidden;pointer-events:none';
69
+ document.body.append(probe);
70
+ const rem = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : undefined;
71
+ rem?.observe(probe);
72
+ document.fonts?.addEventListener?.('loadingdone', schedule);
73
+ addEventListener('resize', schedule);
74
+ schedule();
75
+ return () => {
76
+ rows.disconnect(); root.disconnect(); rem?.disconnect(); probe.remove();
77
+ document.fonts?.removeEventListener?.('loadingdone', schedule);
78
+ removeEventListener('resize', schedule);
79
+ };
80
+ }
@@ -0,0 +1,164 @@
1
+ // Deprecated operations (mocks 88–90, m23): one notice in Try it and Docs that names the
2
+ // replacement, says when the operation stops working, and offers one action that opens the
3
+ // replacement with the matching parameters carried over.
4
+ //
5
+ // x-replaced-by an operationId string, or a list of { operationId, parameters, description }
6
+ // where parameters map the replacement's parameters to OpenAPI runtime
7
+ // expressions ($request.path.id), as an OpenAPI Link object does
8
+ // x-sunset the date the operation stops working; else the last response's Sunset header
9
+ // (RFC 8594); else "No sunset date in the spec"
10
+ import { dereference } from './api.js';
11
+ import { esc, icon, method } from './components.js';
12
+ import { current, formatDate, formatList, t, th } from './i18n.js';
13
+ import { shortcutAttrs } from './shortcuts.js';
14
+
15
+ /** Sunset headers seen in responses, by operation, for operations whose spec has no x-sunset. */
16
+ const seenSunset = new Map();
17
+
18
+ /** Remembers a response's Sunset header (an HTTP-date) for its operation. */
19
+ export function noteSunsetHeader(operation, headers) {
20
+ const value = typeof headers?.get === 'function' ? headers.get('sunset') : Object.entries(headers ?? {}).find(([name]) => name.toLowerCase() === 'sunset')?.[1];
21
+ const date = value ? new Date(value) : undefined;
22
+ if (operation && date && Number.isFinite(date.valueOf())) seenSunset.set(operation, date.toISOString().slice(0, 10));
23
+ }
24
+
25
+ const PARAMETER = /^\$request\.(path|query|header)\.(.+)$/;
26
+
27
+ /**
28
+ * What replaces a deprecated operation: [{ op, description, carry: [{ to, from, in }] }].
29
+ * Without a mapping, parameters carry over by the same name, or by the same format and lookup.
30
+ */
31
+ export function replacements(op, ops, document) {
32
+ const raw = op.operation['x-replaced-by'];
33
+ const list = !raw ? [] : Array.isArray(raw) ? raw : [raw];
34
+ const parameters = target => (target.parameters || []).map(item => dereference(item, document)).filter(item => item?.name);
35
+ const own = parameters(op);
36
+ return list.map(item => {
37
+ const entry = typeof item === 'string' ? { operationId: item } : item || {};
38
+ const target = ops.find(candidate => candidate.operation.operationId === entry.operationId);
39
+ if (!target) return undefined;
40
+ const theirs = parameters(target);
41
+ let carry;
42
+ if (entry.parameters && typeof entry.parameters === 'object') {
43
+ carry = Object.entries(entry.parameters).flatMap(([to, expression]) => {
44
+ const match = PARAMETER.exec(String(expression));
45
+ const destination = theirs.find(parameter => parameter.name === to);
46
+ const source = match && own.find(parameter => parameter.in === match[1] && parameter.name === match[2]);
47
+ return destination && source ? [{ to: destination.name, toIn: destination.in, from: source.name, fromIn: source.in }] : [];
48
+ });
49
+ } else {
50
+ const lookupOf = parameter => (parameter.schema && dereference(parameter.schema, document))?.['x-lookup']?.url;
51
+ const formatOf = parameter => (parameter.schema && dereference(parameter.schema, document))?.format;
52
+ carry = theirs.flatMap(destination => {
53
+ const source = own.find(parameter => parameter.name === destination.name && parameter.in !== 'header')
54
+ ?? own.find(parameter => parameter.in !== 'header' && formatOf(parameter) && formatOf(parameter) === formatOf(destination) && lookupOf(parameter) && lookupOf(parameter) === lookupOf(destination));
55
+ return source ? [{ to: destination.name, toIn: destination.in, from: source.name, fromIn: source.in }] : [];
56
+ });
57
+ }
58
+ return { op: target, description: entry.description, carry };
59
+ }).filter(Boolean);
60
+ }
61
+
62
+ /** The values to open a replacement with, from the deprecated operation's current inputs. */
63
+ export function carriedValues(replacement, values = {}) {
64
+ const out = {};
65
+ for (const { to, toIn, from, fromIn } of replacement.carry) {
66
+ const value = values[`${fromIn}:${from}`];
67
+ if (value !== undefined && value !== '') out[`${toIn}:${to}`] = value;
68
+ }
69
+ return out;
70
+ }
71
+
72
+ /** When the operation stops working: { iso, long, short, relative, past } or undefined. */
73
+ export function sunsetOf(op) {
74
+ const iso = op.operation['x-sunset'] ? String(op.operation['x-sunset']).slice(0, 10) : seenSunset.get(op);
75
+ if (!iso || !/^\d{4}-\d{2}-\d{2}$/.test(iso)) return undefined;
76
+ const today = new Date();
77
+ const days = Math.round((Date.parse(iso + 'T00:00:00Z') - Date.UTC(today.getFullYear(), today.getMonth(), today.getDate())) / 864e5);
78
+ const months = Math.round(days / 30.44);
79
+ const rtf = new Intl.RelativeTimeFormat(current().locale, { numeric: 'auto' });
80
+ const relative = Math.abs(days) < 45 ? rtf.format(days, 'day') : Math.abs(months) < 24 ? rtf.format(months, 'month') : rtf.format(Math.round(days / 365.25), 'year');
81
+ return {
82
+ iso, relative, past: days < 0,
83
+ long: formatDate(iso, { day: 'numeric', month: 'long', year: 'numeric' }),
84
+ short: formatDate(iso, { day: 'numeric', month: 'short', year: 'numeric' }),
85
+ };
86
+ }
87
+
88
+ /**
89
+ * The notice. `where` is 'try' ("Open Get balance") or 'docs' ("Try Get balance"); `index`
90
+ * finds an operation's position for the action's data-op attribute.
91
+ */
92
+ export function deprecationNotice(op, { ops, document, where = 'try', index = item => ops.indexOf(item) }) {
93
+ const reps = replacements(op, ops, document);
94
+ const sunset = sunsetOf(op);
95
+ const first = reps[0];
96
+ const code = text => `<code>${esc(text)}</code>`;
97
+ const carry = first?.carry.length ? formatList(first.carry.map(({ to, from }) => '\u0000' + (to === from ? code(from) : th('dep.carryAs', { from: code(from), to: code(to) })) + '\u0000'))
98
+ .replace(/\u0000([^\u0000]*)\u0000/g, '$1') : '';
99
+ const when = sunset
100
+ ? `<span class="dep-sunset">${th(sunset.past ? 'dep.sunsetPast' : 'dep.sunset', { date: `<time datetime="${sunset.iso}">${esc(sunset.long)}</time>`, relative: esc(sunset.relative) })}</span>`
101
+ : `<span class="dep-sunset">${esc(t('dep.noSunset'))}</span>`;
102
+ // An explicit message from the spec (x-deprecation) leads; the replacements follow it.
103
+ const message = op.operation['x-deprecation'] || op.operation['x-deprecated-message'];
104
+ const said = message ? `<p class="dep-lede" lang="en">${esc(message)}</p>` : '';
105
+ const body = said + (reps.length ? `<p class="dep-lede">${esc(t('dep.useInstead'))}</p>
106
+ <ul class="dep-list">${reps.map(item => `<li><a class="dep-op" href="#${where === 'docs' ? 'docs' : 'op'}/${encodeURIComponent(item.op.operation.operationId)}" data-op="${index(item.op)}"${where === 'docs' ? ' data-op-view="docs"' : ''}>${method(item.op.method)}<span lang="en">${esc(item.op.title)}</span></a>${item.description ? `<span class="dep-why" lang="en">${esc(item.description)}</span>` : ''}</li>`).join('')}</ul>
107
+ <div class="dep-actions"><button type="button" class="btn btn-sm" data-replace-op="${index(first.op)}" ${shortcutAttrs('open-replacement')}><span>${th(where === 'docs' ? 'dep.try' : 'dep.open', { name: `<span lang="en">${esc(first.op.title)}</span>` })}</span>${icon('arrow-right', true)}</button>${carry ? `<span class="dep-carry">${th('dep.carries', { list: carry })}</span>` : ''}</div>`
108
+ : message ? '' : `<p class="dep-lede">${esc(t('dep.noReplacement'))}</p>`);
109
+ return `<section class="dep" role="note" aria-labelledby="dep-h-${where}">
110
+ <div class="dep-head">${icon('warn', true)}<strong id="dep-h-${where}">${esc(t('dep.title'))}</strong>${when}</div>
111
+ ${body}
112
+ </section>`;
113
+ }
114
+
115
+ /** The sidebar tooltip of a deprecated row: "Deprecated · sunset 30 Jun 2027 · Use Get balance or List balances." */
116
+ export function deprecationTip(op, ops, document) {
117
+ const { head, use } = deprecationTipParts(op, ops, document);
118
+ return [head, use].filter(Boolean).join(' · ');
119
+ }
120
+
121
+ /** The tooltip's two lines: "Deprecated · sunset 30 Jun 2027" and "Use Get balance or List balances." */
122
+ export function deprecationTipParts(op, ops, document) {
123
+ const sunset = sunsetOf(op);
124
+ const names = replacements(op, ops, document).map(item => item.op.title);
125
+ return {
126
+ head: [t('dep.title'), sunset ? t('dep.sunsetShort', { date: sunset.short }) : ''].filter(Boolean).join(' · '),
127
+ use: names.length ? t('dep.tipUse', { list: formatList(names, 'disjunction') }) : '',
128
+ };
129
+ }
130
+
131
+ let tipsBound = false;
132
+
133
+ /**
134
+ * Shows the tooltip of a deprecated sidebar row on hover and keyboard focus, beside the row (the
135
+ * inline-end side, mirrored in RTL). The row's accessible description carries the same text.
136
+ */
137
+ export function bindDeprecationTips() {
138
+ if (tipsBound || typeof document === 'undefined') return;
139
+ tipsBound = true;
140
+ let tip;
141
+ const hide = () => { tip?.remove(); tip = undefined; };
142
+ const show = row => {
143
+ hide();
144
+ const [title, ...rest] = row.dataset.depTip.split(' · ');
145
+ const use = row.dataset.depUse || '';
146
+ tip = document.createElement('div');
147
+ tip.className = 'tooltip dep-tip';
148
+ tip.setAttribute('role', 'tooltip');
149
+ tip.id = 'dep-tip';
150
+ tip.innerHTML = `<div class="row">${icon('warn', true)}<strong>${esc(title)}</strong>${rest.length ? `<span class="dim">· ${esc(rest.join(' · '))}</span>` : ''}</div>${use ? `<div class="sub">${esc(use)}</div>` : ''}`;
151
+ document.body.append(tip);
152
+ const box = row.getBoundingClientRect();
153
+ const rtl = getComputedStyle(row).direction === 'rtl';
154
+ tip.style.position = 'fixed';
155
+ tip.style.left = `${Math.max(8, Math.min(rtl ? box.left - tip.offsetWidth - 8 : box.right + 8, innerWidth - tip.offsetWidth - 8))}px`;
156
+ tip.style.top = `${Math.max(8, box.top + box.height / 2 - tip.offsetHeight / 2)}px`;
157
+ row.setAttribute('aria-describedby', tip.id);
158
+ };
159
+ document.addEventListener('pointerover', event => { const row = event.target.closest?.('.nav-item[data-dep-tip]'); if (row && event.pointerType !== 'touch') show(row); });
160
+ document.addEventListener('pointerout', event => { if (event.target.closest?.('.nav-item[data-dep-tip]') && !event.relatedTarget?.closest?.('.nav-item[data-dep-tip]')) hide(); });
161
+ document.addEventListener('focusin', event => { const row = event.target.closest?.('.nav-item[data-dep-tip]'); if (row) show(row); else hide(); });
162
+ document.addEventListener('keydown', event => { if (event.key === 'Escape' && tip) hide(); });
163
+ document.addEventListener('scroll', hide, true);
164
+ }
@@ -0,0 +1,175 @@
1
+ // Display settings (mock: overlays.js "display"), opened from the top bar or with ⌘,: density,
2
+ // theme, a note on text size, language and, for Arabic and Persian, the digits to use. Each
3
+ // change applies at once; nothing in the layout moves except sizes.
4
+ //
5
+ // The language picker (mocks 107, 108, m25) is a listbox beside the panel: 34 languages in six
6
+ // groups, each by its autonym with the English name and region, a check on the current one, and
7
+ // that language's own number and date format. Search covers autonyms, English names, regions and
8
+ // codes. A right-to-left language previews a real field, mirrored, while it's the active row.
9
+ import { esc, icon } from './components.js';
10
+ import { catalogueFor, LANGUAGES, loadLanguage, t, th, tIn } from './i18n.js';
11
+ import { getSettings, updateSettings } from './settings.js';
12
+ import { shortcutHint } from './shortcuts.js';
13
+ import { openPopoverAt } from './popover.js';
14
+ import { openListbox } from './listbox.js';
15
+
16
+ /** A language's own number and date format: "1.250,00 · 23.11.2026". */
17
+ function sample(language, digits = getSettings().digits) {
18
+ const native = ['ar', 'fa'].includes(language.catalogue);
19
+ const locale = native ? `${language.id}-u-nu-${digits === 'arab' ? (language.catalogue === 'fa' ? 'arabext' : 'arab') : 'latn'}` : language.id;
20
+ try {
21
+ return `${new Intl.NumberFormat(locale, { minimumFractionDigits: 2 }).format(1250)} · ${new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' }).format(new Date('2026-11-23T00:00:00Z'))}`;
22
+ } catch { return ''; }
23
+ }
24
+
25
+ /** The English name of a language's region, for search and the second line: "Netherlands". */
26
+ function regionEnglish(language) {
27
+ const region = language.id.split('-')[1];
28
+ try { return region && region.length === 2 ? new Intl.DisplayNames(['en'], { type: 'region' }).of(region) : ''; } catch { return ''; }
29
+ }
30
+
31
+ /**
32
+ * The RTL preview: a real radio field in the language about to be picked, mirrored, with that
33
+ * language's own strings (its catalogue is loaded when the row becomes active).
34
+ */
35
+ function rtlPreview(language) {
36
+ const say = key => esc(tIn(language.id, key));
37
+ const options = ['Open', 'Frozen', 'Closed'].map((value, index) => `<span class="rg-opt" role="presentation" aria-checked="${index === 0}"><span class="rg-dot"></span><span data-label="${value}" lang="en">${value}</span></span>`).join('');
38
+ return `<div class="lang-preview" role="group" aria-label="${esc(t('lang.preview'))}">
39
+ <div class="lp-h">${icon('eye', true)}${esc(t('lang.previewRtl'))}</div>
40
+ <div class="lp-box" dir="rtl" lang="${esc(language.id)}" aria-hidden="true">
41
+ <div class="field" data-kind="radio"><div class="label"><span class="name" lang="en">status</span><span class="info-btn">${icon('info')}</span><span class="opt">${say('field.optional')}</span><span class="end"><span class="field-clear">${say('field.clear')}</span><span class="type">AccountStatus</span></span></div>
42
+ <div class="rg">${options}</div>
43
+ <p class="f-desc" lang="en">Only accounts with this status.</p>
44
+ <div class="assist"><span class="msg"><span class="field-hint">${esc(tIn(language.id, 'field.sends', { value: '\u0000' })).replace('\u0000', '<code>status=Open</code>')}</span></span></div></div>
45
+ </div>
46
+ </div>`;
47
+ }
48
+
49
+ /** Opens the language picker for the Language control in Display settings. */
50
+ function openLanguagePicker(control, panel, { onLanguage }) {
51
+ const settings = getSettings();
52
+ const items = LANGUAGES.map(language => {
53
+ const english = [language.english !== language.autonym ? language.english : '', regionEnglish(language)].filter(Boolean).join(' · ');
54
+ return {
55
+ value: language.id, label: language.autonym, group: esc(t('lang.group.' + language.group)), lang: language.id,
56
+ html: `<bdi>${esc(language.autonym)}</bdi>`,
57
+ description: english || language.english, descriptionLang: 'en',
58
+ keywords: [language.id, language.english, language.region, regionEnglish(language)],
59
+ end: `${language.dir === 'rtl' ? `<span class="rtl-tag" title="${esc(t('lang.rtlTitle'))}">${esc(t('lang.rtl'))}</span>` : ''}${language.review ? `<span class="review-tag" title="${esc(t('lang.reviewTitle'))}">${esc(t('lang.review'))}</span>` : ''}<span class="sample">${esc(sample(language))}</span>`,
60
+ };
61
+ });
62
+ let shown;
63
+ const box = openListbox(control, {
64
+ label: t('lang.label'), items, value: settings.language, search: true, className: 'lang-pop',
65
+ searchLabel: t('lang.search', { n: LANGUAGES.length }),
66
+ sheet: { title: esc(t('lang.label')), sub: esc(t('lang.sub')) },
67
+ foot: `<span>${esc(t('lang.foot'))}</span><span class="spacer"></span><span>${shortcutHint('escape')}</span>`,
68
+ place: { align: 'end', width: 'auto' },
69
+ onActive: item => {
70
+ const language = LANGUAGES.find(entry => entry.id === item?.value);
71
+ if (!language || language.dir !== 'rtl') { if (shown) { shown = undefined; box?.setAfter(''); } return; }
72
+ shown = language.id;
73
+ const draw = () => { if (shown === language.id) box?.setAfter(rtlPreview(language)); };
74
+ if (catalogueFor(language.id)) draw(); else loadLanguage(language.id).then(draw);
75
+ },
76
+ onPick: async item => {
77
+ await loadLanguage(item.value);
78
+ updateSettings({ language: item.value });
79
+ onLanguage?.();
80
+ },
81
+ });
82
+ // A submenu of Display settings: it opens beside the panel, top-aligned, so the list and the
83
+ // RTL preview have the panel's whole height rather than the space under the Language row.
84
+ const pop = box.pop;
85
+ const area = panel.getBoundingClientRect();
86
+ if (!pop.classList.contains('is-sheet') && innerWidth > 900) {
87
+ const rtl = document.documentElement.dir === 'rtl';
88
+ const left = rtl ? area.right + 8 : area.left - pop.offsetWidth - 8;
89
+ if (left >= 12 && left + pop.offsetWidth <= innerWidth - 12) {
90
+ Object.assign(pop.style, { top: area.top + 'px', bottom: '', left: left + 'px' });
91
+ const list = pop.querySelector('.lb-list');
92
+ list.style.maxBlockSize = '';
93
+ const over = pop.getBoundingClientRect().bottom - (innerHeight - 12);
94
+ if (over > 0) list.style.maxBlockSize = Math.max(160, list.offsetHeight - over) + 'px';
95
+ }
96
+ }
97
+ return box;
98
+ }
99
+
100
+ const radios = (name, label, options, value) =>
101
+ `<div class="segmented" role="radiogroup" aria-label="${esc(label)}">${options.map(([id, text, glyph]) =>
102
+ `<button type="button" role="radio" data-setting="${name}" data-value="${id}" aria-checked="${id === value}" tabindex="${id === value ? 0 : -1}">${glyph ? icon(glyph, true) : ''}${esc(text)}</button>`).join('')}</div>`;
103
+
104
+ function panel() {
105
+ const settings = getSettings();
106
+ const language = LANGUAGES.find(item => item.id === settings.language) || LANGUAGES[0];
107
+ const nativeDigits = ['ar', 'fa'].includes(language.catalogue);
108
+ return `<div class="pop settings" role="dialog" aria-labelledby="display-title" id="display-settings">
109
+ <div class="pop-head"><span id="display-title">${esc(t('shell.display'))}</span><span class="spacer"></span>${shortcutHint('display')}</div>
110
+ <div class="row">
111
+ <div class="row-h">${esc(t('display.density'))}<span class="faint">${esc(t('display.densityNote'))}</span></div>
112
+ ${radios('density', t('display.density'), [['compact', t('display.compact')], ['default', t('display.default')], ['comfortable', t('display.comfortable')]], settings.density)}
113
+ <p class="note">${esc(t('display.densityHelp'))}</p>
114
+ </div>
115
+ <div class="row">
116
+ <div class="row-h">${esc(t('display.theme'))}</div>
117
+ ${radios('theme', t('display.theme'), [['system', t('display.system'), 'monitor'], ['light', t('display.light'), 'sun'], ['dark', t('display.dark'), 'moon']], settings.theme)}
118
+ </div>
119
+ <div class="row">
120
+ <div class="row-h">${esc(t('display.textSize'))}<span class="faint" data-text-size></span></div>
121
+ <p class="note">${th('display.textSizeHelp', { in: shortcutHint('zoom-in'), out: shortcutHint('zoom-out') })}</p>
122
+ </div>
123
+ <div class="row">
124
+ <div class="row-h"><span id="display-language-label">${esc(t('display.language'))}</span><span class="faint">${esc(t('display.languageNote'))}</span></div>
125
+ <div class="control sel lang-btn" id="display-language" role="combobox" tabindex="0" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="display-language-label display-language-value">
126
+ <span class="sel-value" id="display-language-value"><bdi lang="${esc(language.id)}">${esc(language.name)}</bdi><span class="sub">${esc(sample(language))}</span></span>
127
+ <span class="sel-trigger" aria-hidden="true">${icon('chevron-down', true)}</span></div>
128
+ </div>
129
+ ${nativeDigits ? `<div class="row">
130
+ <div class="row-h">${esc(t('display.digits'))}</div>
131
+ ${radios('digits', t('display.digits'), [['latn', `${t('display.latin')} 123`], ['arab', `${t('display.arabicIndic')} ${language.catalogue === 'fa' ? '۱۲۳' : '١٢٣'}`]], settings.digits)}
132
+ <p class="note">${esc(t('display.digitsHelp'))}</p>
133
+ </div>` : ''}
134
+ </div>`;
135
+ }
136
+
137
+ /** Opens Display settings under its top-bar button. `onLanguage` re-renders the workbench. */
138
+ export function openDisplaySettings(anchor, { onLanguage } = {}) {
139
+ const pop = openPopoverAt(anchor, panel(), { align: 'end', kind: 'display' });
140
+ const percent = Math.round(parseFloat(getComputedStyle(document.documentElement).fontSize) / 16 * 100);
141
+ pop.querySelector('[data-text-size]').textContent = `${percent}%`;
142
+ pop.addEventListener('click', event => {
143
+ const radio = event.target.closest('[role="radio"]');
144
+ if (!radio) return;
145
+ choose(radio);
146
+ });
147
+ pop.addEventListener('keydown', event => {
148
+ const radio = event.target.closest('[role="radio"]');
149
+ if (!radio || !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key)) return;
150
+ const group = [...radio.parentElement.children];
151
+ const forward = (event.key === 'ArrowRight') !== (document.documentElement.dir === 'rtl') || event.key === 'ArrowDown';
152
+ const next = group[(group.indexOf(radio) + (forward ? 1 : -1) + group.length) % group.length];
153
+ event.preventDefault();
154
+ choose(next);
155
+ });
156
+ const languageControl = pop.querySelector('#display-language');
157
+ const openPicker = () => openLanguagePicker(languageControl, pop, { onLanguage });
158
+ languageControl.addEventListener('click', openPicker);
159
+ languageControl.addEventListener('keydown', event => {
160
+ if (languageControl.getAttribute('aria-expanded') === 'true') return;
161
+ if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) { event.preventDefault(); openPicker(); }
162
+ });
163
+
164
+ function choose(radio) {
165
+ const name = radio.dataset.setting;
166
+ updateSettings({ [name]: radio.dataset.value });
167
+ if (name === 'digits') { onLanguage?.(); return; }
168
+ for (const item of radio.parentElement.children) {
169
+ const selected = item === radio;
170
+ item.setAttribute('aria-checked', String(selected));
171
+ item.tabIndex = selected ? 0 : -1;
172
+ }
173
+ radio.focus();
174
+ }
175
+ }