react-cheminfo 0.36.0 → 0.38.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.
Files changed (115) hide show
  1. package/README.md +77 -1
  2. package/bin/check-seo.mjs +43 -1
  3. package/lib/core.d.ts +1 -0
  4. package/lib/core.d.ts.map +1 -1
  5. package/lib/core.js +1 -0
  6. package/lib/core.js.map +1 -1
  7. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  8. package/lib/ecosystem/core/sites.js +17 -0
  9. package/lib/ecosystem/core/sites.js.map +1 -1
  10. package/lib/ecosystem/core/types.d.ts +1 -1
  11. package/lib/ecosystem/core/types.d.ts.map +1 -1
  12. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  13. package/lib/ecosystem/ui/glyphs.js +4 -0
  14. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  15. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  16. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  17. package/lib/locales/de.json +9 -1
  18. package/lib/locales/en.json +9 -1
  19. package/lib/locales/es.json +9 -1
  20. package/lib/locales/fr.json +9 -1
  21. package/lib/locales/it.json +9 -1
  22. package/lib/number/core/index.d.ts +1 -1
  23. package/lib/number/core/index.d.ts.map +1 -1
  24. package/lib/number/core/index.js +1 -1
  25. package/lib/number/core/index.js.map +1 -1
  26. package/lib/number/core/numberText.d.ts +13 -0
  27. package/lib/number/core/numberText.d.ts.map +1 -1
  28. package/lib/number/core/numberText.js +20 -0
  29. package/lib/number/core/numberText.js.map +1 -1
  30. package/lib/range/core/index.d.ts +4 -0
  31. package/lib/range/core/index.d.ts.map +1 -0
  32. package/lib/range/core/index.js +3 -0
  33. package/lib/range/core/index.js.map +1 -0
  34. package/lib/range/core/rangeBounds.d.ts +79 -0
  35. package/lib/range/core/rangeBounds.d.ts.map +1 -0
  36. package/lib/range/core/rangeBounds.js +110 -0
  37. package/lib/range/core/rangeBounds.js.map +1 -0
  38. package/lib/range/core/rangeHistogram.d.ts +13 -0
  39. package/lib/range/core/rangeHistogram.d.ts.map +1 -0
  40. package/lib/range/core/rangeHistogram.js +39 -0
  41. package/lib/range/core/rangeHistogram.js.map +1 -0
  42. package/lib/range/ui/RangeHistogram.d.ts +20 -0
  43. package/lib/range/ui/RangeHistogram.d.ts.map +1 -0
  44. package/lib/range/ui/RangeHistogram.js +18 -0
  45. package/lib/range/ui/RangeHistogram.js.map +1 -0
  46. package/lib/range/ui/RangeSlider.d.ts +77 -0
  47. package/lib/range/ui/RangeSlider.d.ts.map +1 -0
  48. package/lib/range/ui/RangeSlider.js +60 -0
  49. package/lib/range/ui/RangeSlider.js.map +1 -0
  50. package/lib/range/ui/RangeValue.d.ts +41 -0
  51. package/lib/range/ui/RangeValue.d.ts.map +1 -0
  52. package/lib/range/ui/RangeValue.js +73 -0
  53. package/lib/range/ui/RangeValue.js.map +1 -0
  54. package/lib/range/ui/index.d.ts +3 -0
  55. package/lib/range/ui/index.d.ts.map +1 -0
  56. package/lib/range/ui/index.js +2 -0
  57. package/lib/range/ui/index.js.map +1 -0
  58. package/lib/seo/core/documentMeta.d.ts +16 -0
  59. package/lib/seo/core/documentMeta.d.ts.map +1 -1
  60. package/lib/seo/core/documentMeta.js +18 -0
  61. package/lib/seo/core/documentMeta.js.map +1 -1
  62. package/lib/seo/core/index.d.ts +3 -1
  63. package/lib/seo/core/index.d.ts.map +1 -1
  64. package/lib/seo/core/index.js +2 -1
  65. package/lib/seo/core/index.js.map +1 -1
  66. package/lib/seo/core/noscript.d.ts +8 -0
  67. package/lib/seo/core/noscript.d.ts.map +1 -1
  68. package/lib/seo/core/noscript.js +10 -3
  69. package/lib/seo/core/noscript.js.map +1 -1
  70. package/lib/seo/core/pageMeta.d.ts +10 -2
  71. package/lib/seo/core/pageMeta.d.ts.map +1 -1
  72. package/lib/seo/core/pageMeta.js +12 -3
  73. package/lib/seo/core/pageMeta.js.map +1 -1
  74. package/lib/seo/core/siteFiles.d.ts +32 -3
  75. package/lib/seo/core/siteFiles.d.ts.map +1 -1
  76. package/lib/seo/core/siteFiles.js +13 -4
  77. package/lib/seo/core/siteFiles.js.map +1 -1
  78. package/lib/seo/core/startDocumentMeta.js +8 -7
  79. package/lib/seo/core/startDocumentMeta.js.map +1 -1
  80. package/lib/seo/vite/prerender.d.ts +26 -4
  81. package/lib/seo/vite/prerender.d.ts.map +1 -1
  82. package/lib/seo/vite/prerender.js +100 -30
  83. package/lib/seo/vite/prerender.js.map +1 -1
  84. package/lib/ui.d.ts +1 -0
  85. package/lib/ui.d.ts.map +1 -1
  86. package/lib/ui.js +1 -0
  87. package/lib/ui.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/core.ts +1 -0
  90. package/src/ecosystem/core/sites.ts +17 -0
  91. package/src/ecosystem/core/types.ts +1 -0
  92. package/src/ecosystem/ui/glyphs.tsx +16 -0
  93. package/src/locales/de.json +9 -1
  94. package/src/locales/en.json +9 -1
  95. package/src/locales/es.json +9 -1
  96. package/src/locales/fr.json +9 -1
  97. package/src/locales/it.json +9 -1
  98. package/src/number/core/index.ts +1 -0
  99. package/src/number/core/numberText.ts +20 -0
  100. package/src/range/core/index.ts +11 -0
  101. package/src/range/core/rangeBounds.ts +143 -0
  102. package/src/range/core/rangeHistogram.ts +38 -0
  103. package/src/range/ui/RangeHistogram.tsx +49 -0
  104. package/src/range/ui/RangeSlider.tsx +209 -0
  105. package/src/range/ui/RangeValue.tsx +166 -0
  106. package/src/range/ui/index.ts +2 -0
  107. package/src/seo/core/documentMeta.ts +22 -0
  108. package/src/seo/core/index.ts +8 -1
  109. package/src/seo/core/noscript.ts +20 -2
  110. package/src/seo/core/pageMeta.ts +29 -5
  111. package/src/seo/core/siteFiles.ts +45 -10
  112. package/src/seo/core/startDocumentMeta.ts +9 -9
  113. package/src/seo/vite/prerender.ts +160 -36
  114. package/src/ui.ts +1 -0
  115. package/styles/chrome.css +135 -0
@@ -0,0 +1,49 @@
1
+ import type { ReactElement } from 'react';
2
+ import { useId, useMemo } from 'react';
3
+
4
+ import { rangeHistogramPath } from '../core/rangeHistogram.ts';
5
+
6
+ /** What the histogram over a range slider needs. */
7
+ export interface RangeHistogramProps {
8
+ /** One count per bin, the bins splitting the track into equal widths. */
9
+ counts: ArrayLike<number>;
10
+ /** Where the kept part starts, as a fraction of the track. */
11
+ start: number;
12
+ /** Where it ends. */
13
+ end: number;
14
+ }
15
+
16
+ /**
17
+ * How the values are spread along the track, the part the handles keep drawn
18
+ * in the brand colour. The outline is drawn twice, the second copy clipped to
19
+ * the handles, so a drag moves one rectangle and the outline is never redrawn.
20
+ * @param props - See {@link RangeHistogramProps}.
21
+ * @returns The histogram, hidden from a screen reader: the values under the
22
+ * track already say what it keeps.
23
+ */
24
+ export function RangeHistogram(props: RangeHistogramProps): ReactElement {
25
+ const { counts, start, end } = props;
26
+ const clip = `range-histogram-${useId().replaceAll(/\W/g, '')}`;
27
+ const outline = useMemo(() => rangeHistogramPath(counts), [counts]);
28
+
29
+ return (
30
+ <svg
31
+ className="range-slider__histogram"
32
+ viewBox="0 0 1 1"
33
+ preserveAspectRatio="none"
34
+ aria-hidden="true"
35
+ >
36
+ <defs>
37
+ <clipPath id={clip}>
38
+ <rect x={start} y={0} width={Math.max(end - start, 0)} height={1} />
39
+ </clipPath>
40
+ </defs>
41
+ <path className="range-slider__bars" d={outline} />
42
+ <path
43
+ className="range-slider__bars range-slider__bars--kept"
44
+ d={outline}
45
+ clipPath={`url(#${clip})`}
46
+ />
47
+ </svg>
48
+ );
49
+ }
@@ -0,0 +1,209 @@
1
+ import type { NumberRange } from '@blueprintjs/core';
2
+ import { Button, RangeSlider as BlueprintRangeSlider } from '@blueprintjs/core';
3
+ import type { ReactElement } from 'react';
4
+ import { useState } from 'react';
5
+
6
+ import { useChromeT } from '../../i18n/ui/useT.ts';
7
+ import { numberText } from '../../number/core/numberText.ts';
8
+ import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
9
+ import type {
10
+ RangeBounds,
11
+ RangeDomain,
12
+ RangeHandles,
13
+ } from '../core/rangeBounds.ts';
14
+ import {
15
+ OPEN_RANGE,
16
+ isRangeBounded,
17
+ isRangeDomain,
18
+ movedRange,
19
+ rangeHandles,
20
+ sameRange,
21
+ settleHandles,
22
+ } from '../core/rangeBounds.ts';
23
+
24
+ import { RangeHistogram } from './RangeHistogram.tsx';
25
+ import { RangeValue } from './RangeValue.tsx';
26
+
27
+ /** What a `RangeSlider` needs. */
28
+ export interface RangeSliderProps {
29
+ /** The quantity bounded, written over the track and read to a screen reader. */
30
+ label: string;
31
+ /**
32
+ * The unit written after the label, e.g. `g/mol`.
33
+ * @default undefined — nothing is written
34
+ */
35
+ unit?: string;
36
+ /**
37
+ * The two ends of the track, low first: usually the smallest and largest
38
+ * value the data holds. A handle at an end leaves that side open, so a value
39
+ * past the track is never cut by a filter nobody touched.
40
+ */
41
+ domain: RangeDomain;
42
+ /** The range in force; a `null` side is open. */
43
+ value: RangeBounds;
44
+ /**
45
+ * Called when the range settles: a handle released, a value typed, the range
46
+ * cleared. Never while a handle is being dragged, so a page fetching on it
47
+ * fetches once per gesture.
48
+ */
49
+ onChange: (range: RangeBounds) => void;
50
+ /**
51
+ * Called on every step of a drag, for what is cheap to redraw live — a count,
52
+ * a heatmap computed in the page. Nothing that fetches belongs here.
53
+ * @default undefined
54
+ */
55
+ onPreview?: (range: RangeBounds) => void;
56
+ /**
57
+ * The spacing the handles move by, from the low end of the track. Typed
58
+ * values are not held to it.
59
+ * @default 1
60
+ */
61
+ step?: number;
62
+ /**
63
+ * Whether only whole numbers can be typed. A typed decimal is rounded.
64
+ * @default false
65
+ */
66
+ integer?: boolean;
67
+ /**
68
+ * How a value is written under the track.
69
+ * @default the number as it is, with no grouping — a year is not `1,990`
70
+ */
71
+ format?: (value: number) => string;
72
+ /**
73
+ * How the values are spread along the track: one count per bin, the bins
74
+ * splitting the track into equal widths. Drawn over the track, the part the
75
+ * handles keep in the brand colour.
76
+ * @default undefined — no histogram
77
+ */
78
+ histogram?: ArrayLike<number>;
79
+ /** @default false */
80
+ disabled?: boolean;
81
+ /** @default undefined */
82
+ className?: string;
83
+ /**
84
+ * Value of the `data-testid` attribute of the wrapper.
85
+ * @default undefined
86
+ */
87
+ testId?: string;
88
+ }
89
+
90
+ /** The range before a drag began, and where its handles are now. */
91
+ interface Drag {
92
+ from: RangeBounds;
93
+ handles: RangeHandles;
94
+ }
95
+
96
+ /**
97
+ * A range picked with two handles, its two values written under the track
98
+ * where a click turns either into a box to type an exact number.
99
+ *
100
+ * The handles are Blueprint's — the keyboard, the touch screen and the
101
+ * screen reader are already handled there — dressed in the family's colours.
102
+ * What this adds is the meaning of an end: a handle parked at the end of the
103
+ * track is an open side, not a bound at the track's end.
104
+ * @param props - See {@link RangeSliderProps}.
105
+ * @returns The label, the track and the two values.
106
+ */
107
+ export function RangeSlider(props: RangeSliderProps): ReactElement {
108
+ const { label, unit, domain, value, onChange, onPreview } = props;
109
+ const { step = 1, integer = false, format = numberText } = props;
110
+ const { histogram, disabled = false, className, testId } = props;
111
+ const t = useChromeT();
112
+ const [drag, setDrag] = useState<Drag | null>(null);
113
+ const [editing, setEditing] = useState<'min' | 'max' | null>(null);
114
+ const spacing = step > 0 ? step : 1;
115
+ const drawable = isRangeDomain(domain);
116
+ const handles = drag?.handles ?? rangeHandles(value, domain);
117
+ const shown = drag === null ? value : movedRange(drag.from, handles, domain);
118
+
119
+ function move(next: NumberRange) {
120
+ const from = drag?.from ?? value;
121
+ const settled = settleHandles(next, from, spacing, domain);
122
+ setDrag({ from, handles: settled });
123
+ onPreview?.(movedRange(from, settled, domain));
124
+ }
125
+
126
+ function release(next: NumberRange) {
127
+ const from = drag?.from ?? value;
128
+ const settled = settleHandles(next, from, spacing, domain);
129
+ const range = movedRange(from, settled, domain);
130
+ setDrag(null);
131
+ if (!sameRange(range, from)) onChange(range);
132
+ }
133
+
134
+ function type(side: 'min' | 'max', typed: number | undefined) {
135
+ const range = { ...value, [side]: typed ?? null };
136
+ if (!sameRange(range, value)) onChange(range);
137
+ }
138
+
139
+ return (
140
+ <div
141
+ className={joinClassNames('range-slider', className)}
142
+ data-testid={testId}
143
+ >
144
+ <div className="range-slider__head">
145
+ <span className="range-slider__label">
146
+ {label}
147
+ {unit ? <span className="range-slider__unit"> ({unit})</span> : null}
148
+ </span>
149
+ {isRangeBounded(value) && !disabled ? (
150
+ <Button
151
+ variant="minimal"
152
+ size="small"
153
+ icon="cross"
154
+ aria-label={t('range.clear', { label })}
155
+ title={t('range.clear', { label })}
156
+ onClick={() => onChange(OPEN_RANGE)}
157
+ />
158
+ ) : null}
159
+ </div>
160
+ {drawable ? (
161
+ <div className="range-slider__track">
162
+ {histogram === undefined ? null : (
163
+ <RangeHistogram
164
+ counts={histogram}
165
+ start={(handles[0] - domain[0]) / (domain[1] - domain[0])}
166
+ end={(handles[1] - domain[0]) / (domain[1] - domain[0])}
167
+ />
168
+ )}
169
+ <BlueprintRangeSlider
170
+ min={domain[0]}
171
+ max={domain[1]}
172
+ stepSize={spacing}
173
+ labelRenderer={false}
174
+ disabled={disabled}
175
+ value={[handles[0], handles[1]]}
176
+ handleHtmlProps={{
177
+ start: { 'aria-label': t('range.lowest', { label }) },
178
+ end: { 'aria-label': t('range.highest', { label }) },
179
+ }}
180
+ onChange={move}
181
+ onRelease={release}
182
+ />
183
+ </div>
184
+ ) : null}
185
+ <div className="range-slider__values">
186
+ {(['min', 'max'] as const).map((side) => (
187
+ <RangeValue
188
+ key={side}
189
+ side={side}
190
+ bound={shown[side]}
191
+ end={side === 'min' ? domain[0] : domain[1]}
192
+ label={label}
193
+ format={format}
194
+ limit={side === 'min' ? value.max : value.min}
195
+ step={spacing}
196
+ integer={integer}
197
+ disabled={disabled}
198
+ editing={editing === side}
199
+ onEdit={() => setEditing(side)}
200
+ onDone={(typed, cancelled) => {
201
+ setEditing(null);
202
+ if (!cancelled) type(side, typed);
203
+ }}
204
+ />
205
+ ))}
206
+ </div>
207
+ </div>
208
+ );
209
+ }
@@ -0,0 +1,166 @@
1
+ import type { KeyboardEvent, ReactElement } from 'react';
2
+ import { useEffect, useRef, useState } from 'react';
3
+
4
+ import { useChromeT } from '../../i18n/ui/useT.ts';
5
+ import { NumberInput } from '../../number/ui/NumberInput.tsx';
6
+ import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
7
+
8
+ /** What one end of a range slider's row of values needs. */
9
+ export interface RangeValueProps {
10
+ /** Which end this is. */
11
+ side: 'min' | 'max';
12
+ /** The bound on this side, or `null` when the side is open. */
13
+ bound: number | null;
14
+ /** The end of the track on this side, shown faint while the side is open. */
15
+ end: number;
16
+ /** The quantity the slider bounds, for a screen reader. */
17
+ label: string;
18
+ /** How a number is written. */
19
+ format: (value: number) => string;
20
+ /** The bound on the other side, which a typed value may not cross. */
21
+ limit: number | null;
22
+ /** What one press of an arrow key adds in the box. */
23
+ step: number;
24
+ /** Whether only whole numbers are wanted. */
25
+ integer: boolean;
26
+ /** Whether the value can be edited. */
27
+ disabled: boolean;
28
+ /** Whether the box is open for typing. */
29
+ editing: boolean;
30
+ /** Open the box. */
31
+ onEdit: () => void;
32
+ /**
33
+ * Close the box, with what it holds — `undefined` for an emptied box — and
34
+ * whether Escape closed it, in which case nothing typed is kept.
35
+ */
36
+ onDone: (value: number | undefined, cancelled: boolean) => void;
37
+ }
38
+
39
+ /**
40
+ * One end of a range, written under the track: a bound, or the end of the
41
+ * track in faint ink when the side is open. A click turns it into a box, so a
42
+ * value the handles cannot land on is still one click and a few keystrokes
43
+ * away.
44
+ * @param props - See {@link RangeValueProps}.
45
+ * @returns The value, or the box it is typed into.
46
+ */
47
+ export function RangeValue(props: RangeValueProps): ReactElement {
48
+ const { side, bound, end, label, format, disabled, editing, onEdit } = props;
49
+ const t = useChromeT();
50
+ if (editing) {
51
+ const { limit, step, integer, onDone } = props;
52
+ return (
53
+ <RangeValueEditor
54
+ side={side}
55
+ bound={bound}
56
+ end={end}
57
+ label={label}
58
+ format={format}
59
+ limit={limit}
60
+ step={step}
61
+ integer={integer}
62
+ onDone={onDone}
63
+ />
64
+ );
65
+ }
66
+
67
+ const open = bound === null;
68
+ const shown = open ? end : bound;
69
+ const text = Number.isFinite(shown) ? format(shown) : '–';
70
+ const name = open
71
+ ? t(side === 'min' ? 'range.noLowerBound' : 'range.noUpperBound', {
72
+ label,
73
+ })
74
+ : t(side === 'min' ? 'range.lowestIs' : 'range.highestIs', {
75
+ label,
76
+ value: text,
77
+ });
78
+
79
+ return (
80
+ <button
81
+ type="button"
82
+ className={joinClassNames(
83
+ 'range-slider__value',
84
+ open && 'range-slider__value--open',
85
+ )}
86
+ disabled={disabled}
87
+ title={t('range.typeValue')}
88
+ aria-label={name}
89
+ onClick={onEdit}
90
+ >
91
+ {text}
92
+ </button>
93
+ );
94
+ }
95
+
96
+ /** What the box a value is typed into needs. */
97
+ type RangeValueEditorProps = Omit<
98
+ RangeValueProps,
99
+ 'disabled' | 'editing' | 'onEdit'
100
+ >;
101
+
102
+ /**
103
+ * The box a value is typed into. Enter or leaving it keeps what it holds;
104
+ * Escape drops it.
105
+ * @param props - See {@link RangeValueEditorProps}.
106
+ * @returns The box, focused and selected.
107
+ */
108
+ function RangeValueEditor(props: RangeValueEditorProps): ReactElement {
109
+ const { side, bound, end, label, format, limit, step, integer } = props;
110
+ const { onDone } = props;
111
+ const t = useChromeT();
112
+ const [typed, setTyped] = useState<number | undefined>(bound ?? undefined);
113
+ // The box settles its number — rounded, held inside its bounds — as it is
114
+ // left, and that happens in the same blur this wrapper hears afterwards,
115
+ // before any re-render: refs are what carry it across.
116
+ const latest = useRef(typed);
117
+ const cancelled = useRef(false);
118
+ const host = useRef<HTMLSpanElement>(null);
119
+
120
+ useEffect(() => {
121
+ const input = host.current?.querySelector('input');
122
+ input?.focus();
123
+ input?.select();
124
+ }, []);
125
+
126
+ function press(event: KeyboardEvent<HTMLSpanElement>) {
127
+ if (event.key !== 'Enter' && event.key !== 'Escape') return;
128
+ event.preventDefault();
129
+ // An Escape that closes the box must not also close a dialog around it.
130
+ event.stopPropagation();
131
+ cancelled.current = event.key === 'Escape';
132
+ if (event.target instanceof HTMLElement) event.target.blur();
133
+ }
134
+
135
+ return (
136
+ <span
137
+ ref={host}
138
+ className={joinClassNames(
139
+ 'range-slider__editor',
140
+ `range-slider__editor--${side}`,
141
+ )}
142
+ onKeyDown={press}
143
+ onBlur={() => onDone(latest.current, cancelled.current)}
144
+ >
145
+ <NumberInput
146
+ allowEmpty
147
+ size="small"
148
+ buttons={false}
149
+ fill
150
+ value={typed}
151
+ step={step}
152
+ integer={integer}
153
+ min={side === 'max' ? (limit ?? undefined) : undefined}
154
+ max={side === 'min' ? (limit ?? undefined) : undefined}
155
+ placeholder={Number.isFinite(end) ? format(end) : undefined}
156
+ ariaLabel={t(side === 'min' ? 'range.lowest' : 'range.highest', {
157
+ label,
158
+ })}
159
+ onChange={(next) => {
160
+ latest.current = next;
161
+ setTyped(next);
162
+ }}
163
+ />
164
+ </span>
165
+ );
166
+ }
@@ -0,0 +1,2 @@
1
+ export type { RangeSliderProps } from './RangeSlider.tsx';
2
+ export { RangeSlider } from './RangeSlider.tsx';
@@ -15,6 +15,22 @@ export function writeDocumentMeta(meta: DocumentMeta): void {
15
15
  if (meta.title) documentTitle(meta.title);
16
16
  if (meta.description) metaDescription(meta.description);
17
17
  if (meta.canonical) canonicalLink(meta.canonical);
18
+ if (meta.language) documentLanguage(meta.language);
19
+ }
20
+
21
+ /**
22
+ * Say which language the page on screen is in.
23
+ *
24
+ * The file the build wrote already says it, and a click that switches language
25
+ * has to move it with the rest of the head: a page whose `lang` lies is read
26
+ * aloud wrong by a screen reader and offered to the wrong reader by a search
27
+ * engine, and nothing on screen shows it.
28
+ * @param language - The language tag, e.g. `fr`.
29
+ */
30
+ export function documentLanguage(language: string): void {
31
+ if (typeof document === 'undefined') return;
32
+ const root = document.documentElement;
33
+ if (root) root.lang = language;
18
34
  }
19
35
 
20
36
  /**
@@ -71,6 +87,12 @@ export interface DocumentMeta {
71
87
  * @default undefined
72
88
  */
73
89
  canonical?: string;
90
+ /**
91
+ * The language the page is written in, for `<html lang>`. Left out, the one
92
+ * the page was served with stays as it is.
93
+ * @default undefined
94
+ */
95
+ language?: string;
74
96
  }
75
97
 
76
98
  function metaDescription(content: string): void {
@@ -1,3 +1,5 @@
1
+ export type { AlternateOptions } from './alternates.ts';
2
+ export { alternateLinkTags } from './alternates.ts';
1
3
  export type { DocumentMeta } from './documentMeta.ts';
2
4
  export { writeDocumentMeta } from './documentMeta.ts';
3
5
  export type {
@@ -9,7 +11,12 @@ export type {
9
11
  } from './noscript.ts';
10
12
  export { noscriptIndex } from './noscript.ts';
11
13
  export type { PageMetaOptions } from './pageMeta.ts';
12
- export { injectPageMeta, pageDocumentMeta, pageHeadTags } from './pageMeta.ts';
14
+ export {
15
+ injectPageMeta,
16
+ pageDocumentMeta,
17
+ pageHeadTags,
18
+ pageLanguage,
19
+ } from './pageMeta.ts';
13
20
  export type { PageContent, PageSection, PageTable } from './pageProse.ts';
14
21
  export { pageProseHtml } from './pageProse.ts';
15
22
  export type { PlainDescriptionOptions } from './plainDescription.ts';
@@ -9,6 +9,9 @@
9
9
  import { siteById, siteDisplayName } from '../../ecosystem/core/lookup.ts';
10
10
  import type { EcosystemSite, SiteId } from '../../ecosystem/core/sites.ts';
11
11
  import { ECOSYSTEM_SITES, siteUrl } from '../../ecosystem/core/sites.ts';
12
+ import { CHROME_CATALOG } from '../../i18n/core/chromeCatalog.ts';
13
+ import type { Language } from '../../i18n/core/languages.ts';
14
+ import { DEFAULT_LANGUAGE } from '../../i18n/core/languages.ts';
12
15
  import { joinBasePath } from '../../router/core/basePath.ts';
13
16
  import { escapeAttribute, escapeText } from '../../share/core/escape.ts';
14
17
 
@@ -70,6 +73,13 @@ export interface NoscriptText {
70
73
  * @default false
71
74
  */
72
75
  ecosystem?: boolean | NoscriptEcosystem;
76
+ /**
77
+ * The language the block is written in, which is what the family list's own
78
+ * heading is translated into. The site's own prose is passed already written;
79
+ * this is only for the words that belong to the chrome.
80
+ * @default the default language
81
+ */
82
+ language?: Language;
73
83
  /**
74
84
  * How the site's own addresses are written. `'absolute'` writes them from the
75
85
  * root of the host, under the mount the origin names. `'relative'` writes
@@ -119,6 +129,7 @@ export interface NoscriptOptions
119
129
  */
120
130
  export function noscriptIndex(options: NoscriptOptions): string {
121
131
  const site = resolveSite(options.site);
132
+ const language = options.language ?? DEFAULT_LANGUAGE;
122
133
  const hrefs = options.hrefs ?? 'absolute';
123
134
  const mount = hrefs === 'absolute' ? mountPathOf(options) : '';
124
135
  const content = options.content;
@@ -135,7 +146,7 @@ export function noscriptIndex(options: NoscriptOptions): string {
135
146
 
136
147
  return `<noscript>
137
148
  <h1>${heading}</h1>${prose}
138
- <p>${intro}</p>${pageList(options.routes, mount, hrefs, ' ')}${familyList(site.id, options.ecosystem)}
149
+ <p>${intro}</p>${pageList(options.routes, mount, hrefs, ' ')}${familyList(site.id, options.ecosystem, language)}
139
150
  </noscript>`;
140
151
  }
141
152
 
@@ -185,6 +196,7 @@ function labelOf(route: NoscriptRoute): string {
185
196
  function familyList(
186
197
  current: string,
187
198
  ecosystem: boolean | NoscriptEcosystem | undefined,
199
+ language: Language,
188
200
  ): string {
189
201
  if (ecosystem === undefined || ecosystem === false) return '';
190
202
  const listed = ecosystem === true ? {} : ecosystem;
@@ -198,8 +210,14 @@ function familyList(
198
210
  );
199
211
  }
200
212
  if (items.length === 0) return '';
213
+ // The chrome's own words, so one translation in this package writes the crawl
214
+ // path of every site of the family rather than eighteen catalogs carrying the
215
+ // same two words.
216
+ const heading = escapeText(
217
+ CHROME_CATALOG.translate('ecosystem.otherTools', language),
218
+ );
201
219
  return `
202
- <h2>Our other tools</h2>
220
+ <h2>${heading}</h2>
203
221
  <ul>
204
222
  ${items.join('\n')}
205
223
  </ul>`;
@@ -38,8 +38,16 @@ const ABSOLUTE_URL = /^[a-z][\d+.a-z-]*:\/\//i;
38
38
  export interface PageMetaOptions {
39
39
  /** The site, named or passed. */
40
40
  site: SiteRecord | SiteId;
41
- /** Every address it answers, each with its title and description. */
42
- routes: readonly RouteMeta[];
41
+ /**
42
+ * Every address it answers, each with its title and description.
43
+ *
44
+ * A translated site passes a function instead, exactly as `cheminfoPrerender`
45
+ * takes it: the language is read off the address first, and that language's
46
+ * table is what the page is titled from. Passed as a value by a site whose
47
+ * prose is per-language, a language switch would leave the title and the
48
+ * description in whichever language the table was built in.
49
+ */
50
+ routes: readonly RouteMeta[] | ((language: Language) => readonly RouteMeta[]);
43
51
  /**
44
52
  * The address being written, query string included: a path, or the absolute
45
53
  * address an app reads off the page it is on.
@@ -148,10 +156,12 @@ export function pageDocumentMeta(
148
156
  ): Required<DocumentMeta> {
149
157
  const site = resolveSite(options.site);
150
158
  const meta = routeMetaOf(options);
159
+ const language = pageLanguage(options);
151
160
  return {
152
161
  title: `${meta.title} — ${siteDisplayName(site)}`,
153
162
  description: meta.description,
154
- canonical: `${originOf(options)}${withLanguagePath(pageLanguage(options), meta.path)}`,
163
+ canonical: `${originOf(options)}${withLanguagePath(language, meta.path)}`,
164
+ language,
155
165
  };
156
166
  }
157
167
 
@@ -173,8 +183,22 @@ export function pageLanguage(options: PageMetaOptions): Language {
173
183
  // route table is written from the site's own root, so the mount the origin
174
184
  // carries is taken off it before the table is read.
175
185
  function routeMetaOf(options: PageMetaOptions): RouteMeta {
176
- const { path } = readLanguagePath(ownPath(options), languagesOf(options));
177
- return pageMetaFor(options.routes, path);
186
+ const { language, path } = readLanguagePath(
187
+ ownPath(options),
188
+ languagesOf(options),
189
+ );
190
+ return pageMetaFor(tableOf(options, language), path);
191
+ }
192
+
193
+ // The table the page is titled from: the one the site passed, or the one its
194
+ // function returns for the language the address names.
195
+ function tableOf(
196
+ options: PageMetaOptions,
197
+ language: Language,
198
+ ): readonly RouteMeta[] {
199
+ return typeof options.routes === 'function'
200
+ ? options.routes(language)
201
+ : options.routes;
178
202
  }
179
203
 
180
204
  // The address from the site's own root, the mount taken off, with the query