react-cheminfo 0.4.1 → 0.6.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 +182 -34
- package/lib/ecosystem/core/sites.d.ts +1 -1
- package/lib/ecosystem/core/sites.d.ts.map +1 -1
- package/lib/ecosystem/core/sites.js +10 -0
- package/lib/ecosystem/core/sites.js.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +3 -0
- package/lib/ecosystem/ui/glyphs.js.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts +5 -0
- package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalCanvas.js +4 -3
- package/lib/orbital/ui/AtomicOrbitalCanvas.js.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalViewer.d.ts +5 -0
- package/lib/orbital/ui/AtomicOrbitalViewer.d.ts.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalViewer.js.map +1 -1
- package/lib/orbital/ui/axesGeometry.d.ts +27 -0
- package/lib/orbital/ui/axesGeometry.d.ts.map +1 -0
- package/lib/orbital/ui/axesGeometry.js +74 -0
- package/lib/orbital/ui/axesGeometry.js.map +1 -0
- package/lib/orbital/ui/camera.d.ts +7 -0
- package/lib/orbital/ui/camera.d.ts.map +1 -1
- package/lib/orbital/ui/camera.js +8 -1
- package/lib/orbital/ui/camera.js.map +1 -1
- package/lib/orbital/ui/renderAxes.d.ts +53 -0
- package/lib/orbital/ui/renderAxes.d.ts.map +1 -0
- package/lib/orbital/ui/renderAxes.js +110 -0
- package/lib/orbital/ui/renderAxes.js.map +1 -0
- package/lib/orbital/ui/viewer.d.ts +16 -0
- package/lib/orbital/ui/viewer.d.ts.map +1 -1
- package/lib/orbital/ui/viewer.js +24 -2
- package/lib/orbital/ui/viewer.js.map +1 -1
- package/lib/seo/core/documentMeta.d.ts +2 -2
- package/lib/seo/core/documentMeta.js +4 -3
- package/lib/seo/core/documentMeta.js.map +1 -1
- package/lib/seo/core/index.d.ts +13 -4
- package/lib/seo/core/index.d.ts.map +1 -1
- package/lib/seo/core/index.js +8 -3
- package/lib/seo/core/index.js.map +1 -1
- package/lib/seo/core/noscript.d.ts +97 -0
- package/lib/seo/core/noscript.d.ts.map +1 -0
- package/lib/seo/core/noscript.js +93 -0
- package/lib/seo/core/noscript.js.map +1 -0
- package/lib/seo/core/pageMeta.d.ts +30 -14
- package/lib/seo/core/pageMeta.d.ts.map +1 -1
- package/lib/seo/core/pageMeta.js +40 -43
- package/lib/seo/core/pageMeta.js.map +1 -1
- package/lib/seo/core/robots.d.ts +55 -0
- package/lib/seo/core/robots.d.ts.map +1 -0
- package/lib/seo/core/robots.js +70 -0
- package/lib/seo/core/robots.js.map +1 -0
- package/lib/seo/core/routes.d.ts +73 -5
- package/lib/seo/core/routes.d.ts.map +1 -1
- package/lib/seo/core/routes.js +142 -16
- package/lib/seo/core/routes.js.map +1 -1
- package/lib/seo/core/siteFiles.d.ts +39 -43
- package/lib/seo/core/siteFiles.d.ts.map +1 -1
- package/lib/seo/core/siteFiles.js +53 -69
- package/lib/seo/core/siteFiles.js.map +1 -1
- package/lib/seo/core/startDocumentMeta.d.ts +44 -0
- package/lib/seo/core/startDocumentMeta.d.ts.map +1 -0
- package/lib/seo/core/startDocumentMeta.js +47 -0
- package/lib/seo/core/startDocumentMeta.js.map +1 -0
- package/lib/seo/core/structuredData.d.ts +48 -0
- package/lib/seo/core/structuredData.d.ts.map +1 -0
- package/lib/seo/core/structuredData.js +41 -0
- package/lib/seo/core/structuredData.js.map +1 -0
- package/lib/seo/core/template.d.ts +48 -0
- package/lib/seo/core/template.d.ts.map +1 -0
- package/lib/seo/core/template.js +53 -0
- package/lib/seo/core/template.js.map +1 -0
- package/lib/seo/vite/ogCard.d.ts +9 -1
- package/lib/seo/vite/ogCard.d.ts.map +1 -1
- package/lib/seo/vite/ogCard.js +14 -4
- package/lib/seo/vite/ogCard.js.map +1 -1
- package/lib/seo/vite/prerender.d.ts +38 -7
- package/lib/seo/vite/prerender.d.ts.map +1 -1
- package/lib/seo/vite/prerender.js +68 -30
- package/lib/seo/vite/prerender.js.map +1 -1
- package/package.json +1 -1
- package/src/ecosystem/core/sites.ts +11 -0
- package/src/ecosystem/ui/glyphs.tsx +19 -0
- package/src/orbital/ui/AtomicOrbitalCanvas.tsx +9 -2
- package/src/orbital/ui/AtomicOrbitalViewer.tsx +5 -0
- package/src/orbital/ui/axesGeometry.ts +91 -0
- package/src/orbital/ui/camera.ts +9 -1
- package/src/orbital/ui/renderAxes.ts +190 -0
- package/src/orbital/ui/viewer.ts +32 -2
- package/src/seo/core/documentMeta.ts +5 -5
- package/src/seo/core/index.ts +19 -12
- package/src/seo/core/noscript.ts +195 -0
- package/src/seo/core/pageMeta.ts +54 -53
- package/src/seo/core/robots.ts +114 -0
- package/src/seo/core/routes.ts +181 -14
- package/src/seo/core/siteFiles.ts +58 -96
- package/src/seo/core/startDocumentMeta.ts +77 -0
- package/src/seo/core/structuredData.ts +80 -0
- package/src/seo/core/template.ts +54 -0
- package/src/seo/vite/ogCard.ts +15 -5
- package/src/seo/vite/prerender.ts +105 -58
|
@@ -56,6 +56,11 @@ export interface AtomicOrbitalViewerProps {
|
|
|
56
56
|
* @default false
|
|
57
57
|
*/
|
|
58
58
|
spinning?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* How fast it turns, in molstar's own spin unit. Lower is slower.
|
|
61
|
+
* @default 0.3
|
|
62
|
+
*/
|
|
63
|
+
spinSpeed?: number;
|
|
59
64
|
/**
|
|
60
65
|
* How the field is produced. Supply a worker-backed sampler to keep the main
|
|
61
66
|
* thread free; the default runs in process.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometry of the cartesian frame: three rods through the origin and the
|
|
3
|
+
* three letters that name them.
|
|
4
|
+
*
|
|
5
|
+
* It is arithmetic over positions, which is why it is here rather than in
|
|
6
|
+
* `renderAxes.ts` — that module is about representations, exactly as
|
|
7
|
+
* `volumeField.ts` is to `renderVolume.ts`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { addCylinder } from 'molstar/lib/mol-geo/geometry/mesh/builder/cylinder.js';
|
|
11
|
+
import { MeshBuilder } from 'molstar/lib/mol-geo/geometry/mesh/mesh-builder.js';
|
|
12
|
+
import type { Mesh } from 'molstar/lib/mol-geo/geometry/mesh/mesh.js';
|
|
13
|
+
import { TextBuilder } from 'molstar/lib/mol-geo/geometry/text/text-builder.js';
|
|
14
|
+
import type { Text } from 'molstar/lib/mol-geo/geometry/text/text.js';
|
|
15
|
+
import { Vec3 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
16
|
+
|
|
17
|
+
/** How far a rod, and a label, sit from the origin as fractions of the reach. */
|
|
18
|
+
export const ROD_LENGTH = 1.06;
|
|
19
|
+
export const LABEL_SIZE = 0.1;
|
|
20
|
+
|
|
21
|
+
/** Rod radius, as a fraction of the reach. */
|
|
22
|
+
const ROD_RADIUS = 0.006;
|
|
23
|
+
|
|
24
|
+
/** Arrowhead length as a fraction of the rod's half-length. */
|
|
25
|
+
const HEAD_LENGTH = 0.06;
|
|
26
|
+
|
|
27
|
+
/** Arrowhead radius as a multiple of the rod's. */
|
|
28
|
+
const HEAD_FLARE = 4;
|
|
29
|
+
|
|
30
|
+
/** x, y and z, in the order their labels are given in. */
|
|
31
|
+
const AXIS_DIRECTIONS = [
|
|
32
|
+
Vec3.create(1, 0, 0),
|
|
33
|
+
Vec3.create(0, 1, 0),
|
|
34
|
+
Vec3.create(0, 0, 1),
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Three rods through the origin, each with an arrowhead on its positive end.
|
|
39
|
+
* @param reach - How far the orbital reaches, in scene units.
|
|
40
|
+
* @returns The mesh, one group per axis.
|
|
41
|
+
*/
|
|
42
|
+
export function buildAxisRods(reach: number): Mesh {
|
|
43
|
+
const state = MeshBuilder.createState(1024, 512);
|
|
44
|
+
const length = reach * ROD_LENGTH;
|
|
45
|
+
const radius = reach * ROD_RADIUS;
|
|
46
|
+
const head = length * HEAD_LENGTH;
|
|
47
|
+
for (const [axis, direction] of AXIS_DIRECTIONS.entries()) {
|
|
48
|
+
state.currentGroup = axis;
|
|
49
|
+
const start = Vec3.scale(Vec3.zero(), direction, -length);
|
|
50
|
+
const neck = Vec3.scale(Vec3.zero(), direction, length - head);
|
|
51
|
+
const tip = Vec3.scale(Vec3.zero(), direction, length);
|
|
52
|
+
addCylinder(state, start, neck, 1, {
|
|
53
|
+
radiusTop: radius,
|
|
54
|
+
radiusBottom: radius,
|
|
55
|
+
topCap: true,
|
|
56
|
+
bottomCap: true,
|
|
57
|
+
radialSegments: 12,
|
|
58
|
+
});
|
|
59
|
+
addCylinder(state, neck, tip, 1, {
|
|
60
|
+
radiusTop: 0,
|
|
61
|
+
radiusBottom: radius * HEAD_FLARE,
|
|
62
|
+
topCap: true,
|
|
63
|
+
bottomCap: true,
|
|
64
|
+
radialSegments: 16,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return MeshBuilder.getMesh(state);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One label just beyond each arrowhead.
|
|
72
|
+
* @param at - Distance from the origin the labels sit at, in scene units.
|
|
73
|
+
* @param labels - What the axes are called, in x, y, z order.
|
|
74
|
+
* @returns The text geometry, one group per axis.
|
|
75
|
+
*/
|
|
76
|
+
export function buildAxisLabels(at: number, labels: readonly string[]): Text {
|
|
77
|
+
const builder = TextBuilder.create({}, 3, 3);
|
|
78
|
+
for (const [axis, direction] of AXIS_DIRECTIONS.entries()) {
|
|
79
|
+
const position = Vec3.scale(Vec3.zero(), direction, at);
|
|
80
|
+
builder.add(
|
|
81
|
+
labels[axis] ?? '',
|
|
82
|
+
position[0] as number,
|
|
83
|
+
position[1] as number,
|
|
84
|
+
position[2] as number,
|
|
85
|
+
0,
|
|
86
|
+
1,
|
|
87
|
+
axis,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return builder.getText();
|
|
91
|
+
}
|
package/src/orbital/ui/camera.ts
CHANGED
|
@@ -10,6 +10,14 @@ import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
|
10
10
|
/** Transition length used when the caller does not pick one, milliseconds. */
|
|
11
11
|
export const DEFAULT_CAMERA_DURATION = 250;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Turn rate used when the caller does not pick one, in molstar's own spin unit.
|
|
15
|
+
*
|
|
16
|
+
* A lobe has to stay in one place long enough to be read; molstar's own 1 turns
|
|
17
|
+
* an orbital fast enough that the phases blur into each other.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_SPIN_SPEED = 0.3;
|
|
20
|
+
|
|
13
21
|
/**
|
|
14
22
|
* Fraction of the bounding sphere kept as breathing room around the orbital.
|
|
15
23
|
*
|
|
@@ -113,7 +121,7 @@ export function frameOrbital(
|
|
|
113
121
|
export function setSpin(
|
|
114
122
|
plugin: PluginContext,
|
|
115
123
|
spinning: boolean,
|
|
116
|
-
speed =
|
|
124
|
+
speed = DEFAULT_SPIN_SPEED,
|
|
117
125
|
): void {
|
|
118
126
|
plugin.canvas3d?.setProps({
|
|
119
127
|
trackball: {
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cartesian frame an atomic orbital is read against.
|
|
3
|
+
*
|
|
4
|
+
* A `3d_xz` is only `3d_xz` because of where its lobes sit relative to x and
|
|
5
|
+
* z, and a lone isosurface on a blank canvas says nothing about that: the
|
|
6
|
+
* student is looking at four identical lobes and has to take the label's word
|
|
7
|
+
* for it. Three labelled axes through the nucleus are what turn the picture
|
|
8
|
+
* back into the diagram their textbook draws.
|
|
9
|
+
*
|
|
10
|
+
* The axes are neutral grey on purpose. The phase palette already owns colour
|
|
11
|
+
* here — blue against red, or blue against amber — so the usual red/green/blue
|
|
12
|
+
* axis convention would compete with the one thing the surface is saying, and
|
|
13
|
+
* the labels tell the three apart anyway.
|
|
14
|
+
*
|
|
15
|
+
* Like the isosurfaces, the representations live outside the state tree and
|
|
16
|
+
* are tracked per plugin.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Mesh } from 'molstar/lib/mol-geo/geometry/mesh/mesh.js';
|
|
20
|
+
import { Text } from 'molstar/lib/mol-geo/geometry/text/text.js';
|
|
21
|
+
import { Shape } from 'molstar/lib/mol-model/shape.js';
|
|
22
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
23
|
+
import type { Representation } from 'molstar/lib/mol-repr/representation.js';
|
|
24
|
+
// Lowercased on import: it is a factory, not a constructor.
|
|
25
|
+
import { ShapeRepresentation as shapeRepresentation } from 'molstar/lib/mol-repr/shape/representation.js';
|
|
26
|
+
import { Color } from 'molstar/lib/mol-util/color/color.js';
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
LABEL_SIZE,
|
|
30
|
+
ROD_LENGTH,
|
|
31
|
+
buildAxisLabels,
|
|
32
|
+
buildAxisRods,
|
|
33
|
+
} from './axesGeometry.ts';
|
|
34
|
+
|
|
35
|
+
/** How the cartesian frame is drawn. */
|
|
36
|
+
export interface AxesStyle {
|
|
37
|
+
/**
|
|
38
|
+
* Colour of the three rods, as `#rrggbb`.
|
|
39
|
+
* @default '#64748b'
|
|
40
|
+
*/
|
|
41
|
+
colour?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Colour of the three labels, as `#rrggbb`.
|
|
44
|
+
* @default '#334155'
|
|
45
|
+
*/
|
|
46
|
+
labelColour?: string;
|
|
47
|
+
/**
|
|
48
|
+
* What the axes are called, in x, y, z order.
|
|
49
|
+
* @default ['x', 'y', 'z']
|
|
50
|
+
*/
|
|
51
|
+
labels?: readonly [string, string, string];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Draw a labelled x, y, z frame through the origin, replacing any previous one.
|
|
56
|
+
* @param plugin - The molstar context.
|
|
57
|
+
* @param reach - How far the orbital reaches, in scene units — what
|
|
58
|
+
* `renderSampledVolume` returned.
|
|
59
|
+
* @param style - See {@link AxesStyle}.
|
|
60
|
+
* @returns How far the frame reaches, labels included, in scene units: what a
|
|
61
|
+
* camera has to frame for the whole of it to be on screen.
|
|
62
|
+
* @throws {Error} When the canvas is not ready.
|
|
63
|
+
*/
|
|
64
|
+
export async function renderOrbitalAxes(
|
|
65
|
+
plugin: PluginContext,
|
|
66
|
+
reach: number,
|
|
67
|
+
style: AxesStyle = {},
|
|
68
|
+
): Promise<number> {
|
|
69
|
+
const canvas3d = plugin.canvas3d;
|
|
70
|
+
if (canvas3d === undefined) {
|
|
71
|
+
throw new Error('renderOrbitalAxes: the molstar canvas is not ready.');
|
|
72
|
+
}
|
|
73
|
+
const {
|
|
74
|
+
colour = '#64748b',
|
|
75
|
+
labelColour = '#334155',
|
|
76
|
+
labels = ['x', 'y', 'z'],
|
|
77
|
+
} = style;
|
|
78
|
+
clearOrbitalAxes(plugin);
|
|
79
|
+
if (reach <= 0) return 0;
|
|
80
|
+
|
|
81
|
+
const labelSize = reach * LABEL_SIZE;
|
|
82
|
+
const labelAt = reach * ROD_LENGTH + labelSize;
|
|
83
|
+
const drawn = await Promise.all([
|
|
84
|
+
createRods(plugin, buildAxisRods(reach), colour),
|
|
85
|
+
createLabels(
|
|
86
|
+
plugin,
|
|
87
|
+
buildAxisLabels(labelAt, labels),
|
|
88
|
+
labelColour,
|
|
89
|
+
labelSize,
|
|
90
|
+
),
|
|
91
|
+
]);
|
|
92
|
+
representations.set(plugin, drawn);
|
|
93
|
+
for (const representation of drawn) canvas3d.add(representation);
|
|
94
|
+
// add() only queues; nothing appears until the queue is committed.
|
|
95
|
+
canvas3d.commit();
|
|
96
|
+
return labelAt + labelSize / 2;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Remove the frame, leaving anything else on the canvas.
|
|
101
|
+
* @param plugin - The molstar context.
|
|
102
|
+
*/
|
|
103
|
+
export function clearOrbitalAxes(plugin: PluginContext): void {
|
|
104
|
+
const previous = representations.get(plugin);
|
|
105
|
+
if (previous === undefined) return;
|
|
106
|
+
representations.delete(plugin);
|
|
107
|
+
for (const representation of previous) {
|
|
108
|
+
plugin.canvas3d?.remove(representation);
|
|
109
|
+
}
|
|
110
|
+
plugin.canvas3d?.commit();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The rods, as a representation the canvas can hold.
|
|
115
|
+
* @param plugin - The molstar context.
|
|
116
|
+
* @param mesh - The rod mesh.
|
|
117
|
+
* @param colour - Rod colour, as `#rrggbb`.
|
|
118
|
+
* @returns The representation.
|
|
119
|
+
*/
|
|
120
|
+
async function createRods(
|
|
121
|
+
plugin: PluginContext,
|
|
122
|
+
mesh: Mesh,
|
|
123
|
+
colour: string,
|
|
124
|
+
): Promise<Representation.Any> {
|
|
125
|
+
const value = Color.fromHexStyle(colour);
|
|
126
|
+
const representation = shapeRepresentation(
|
|
127
|
+
(_ctx, data: Mesh) =>
|
|
128
|
+
Shape.create(
|
|
129
|
+
'orbital axes',
|
|
130
|
+
{},
|
|
131
|
+
data,
|
|
132
|
+
() => value,
|
|
133
|
+
() => 1,
|
|
134
|
+
() => 'axis',
|
|
135
|
+
),
|
|
136
|
+
Mesh.Utils,
|
|
137
|
+
);
|
|
138
|
+
await plugin.runTask(
|
|
139
|
+
// Unlit: a shaded rod reads as a cylinder in front of the surface, while a
|
|
140
|
+
// flat one reads as the axis line a textbook draws.
|
|
141
|
+
representation.createOrUpdate({ alpha: 1, ignoreLight: true }, mesh),
|
|
142
|
+
);
|
|
143
|
+
representation.setState({ pickable: false });
|
|
144
|
+
return representation;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The labels, as a representation the canvas can hold.
|
|
149
|
+
* @param plugin - The molstar context.
|
|
150
|
+
* @param text - The label geometry.
|
|
151
|
+
* @param colour - Label colour, as `#rrggbb`.
|
|
152
|
+
* @param size - Label height, in scene units.
|
|
153
|
+
* @returns The representation.
|
|
154
|
+
*/
|
|
155
|
+
async function createLabels(
|
|
156
|
+
plugin: PluginContext,
|
|
157
|
+
text: Text,
|
|
158
|
+
colour: string,
|
|
159
|
+
size: number,
|
|
160
|
+
): Promise<Representation.Any> {
|
|
161
|
+
const value = Color.fromHexStyle(colour);
|
|
162
|
+
const representation = shapeRepresentation(
|
|
163
|
+
(_ctx, data: Text) =>
|
|
164
|
+
Shape.create(
|
|
165
|
+
'orbital axis labels',
|
|
166
|
+
{},
|
|
167
|
+
data,
|
|
168
|
+
() => value,
|
|
169
|
+
() => 1,
|
|
170
|
+
() => 'axis label',
|
|
171
|
+
),
|
|
172
|
+
Text.Utils,
|
|
173
|
+
);
|
|
174
|
+
await plugin.runTask(
|
|
175
|
+
representation.createOrUpdate(
|
|
176
|
+
{
|
|
177
|
+
sizeFactor: size,
|
|
178
|
+
background: false,
|
|
179
|
+
attachment: 'middle-center',
|
|
180
|
+
fontWeight: 'bold',
|
|
181
|
+
},
|
|
182
|
+
text,
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
representation.setState({ pickable: false });
|
|
186
|
+
return representation;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** One frame per plugin, outside the state tree like the isosurfaces. */
|
|
190
|
+
const representations = new WeakMap<PluginContext, Representation.Any[]>();
|
package/src/orbital/ui/viewer.ts
CHANGED
|
@@ -22,7 +22,14 @@ import { Color } from 'molstar/lib/mol-util/color/color.js';
|
|
|
22
22
|
import type { OrbitalGrid } from '../core/grid.ts';
|
|
23
23
|
import type { OrbitalContour } from '../core/isovalue.ts';
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_CAMERA_DURATION,
|
|
27
|
+
DEFAULT_SPIN_SPEED,
|
|
28
|
+
frameOrbital,
|
|
29
|
+
setSpin,
|
|
30
|
+
} from './camera.ts';
|
|
31
|
+
import type { AxesStyle } from './renderAxes.ts';
|
|
32
|
+
import { clearOrbitalAxes, renderOrbitalAxes } from './renderAxes.ts';
|
|
26
33
|
import type { VolumeStyle } from './renderVolume.ts';
|
|
27
34
|
import { clearSampledVolume, renderSampledVolume } from './renderVolume.ts';
|
|
28
35
|
|
|
@@ -105,6 +112,29 @@ export class OrbitalViewer {
|
|
|
105
112
|
);
|
|
106
113
|
}
|
|
107
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Draw the labelled x, y, z frame through the origin, replacing any previous
|
|
117
|
+
* one.
|
|
118
|
+
* @param reach - How far the orbital reaches, in scene units, as
|
|
119
|
+
* `showOrbital` returned it.
|
|
120
|
+
* @param style - See {@link AxesStyle}.
|
|
121
|
+
* @returns How far the frame reaches, labels included, for the camera to
|
|
122
|
+
* frame; `undefined` once the viewer has been disposed.
|
|
123
|
+
*/
|
|
124
|
+
showAxes(reach: number, style?: AxesStyle): Promise<number | undefined> {
|
|
125
|
+
return this.#run((plugin) => renderOrbitalAxes(plugin, reach, style));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Remove the frame.
|
|
130
|
+
* @returns Nothing, once the axes are gone.
|
|
131
|
+
*/
|
|
132
|
+
hideAxes(): Promise<void> {
|
|
133
|
+
return this.#run((plugin) => {
|
|
134
|
+
clearOrbitalAxes(plugin);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
108
138
|
/**
|
|
109
139
|
* Remove the isosurface pair.
|
|
110
140
|
* @returns Nothing, once the surfaces are gone.
|
|
@@ -138,7 +168,7 @@ export class OrbitalViewer {
|
|
|
138
168
|
* @param speed - molstar's own spin unit.
|
|
139
169
|
* @returns Nothing, once the spin has been switched.
|
|
140
170
|
*/
|
|
141
|
-
setSpin(spinning: boolean, speed =
|
|
171
|
+
setSpin(spinning: boolean, speed = DEFAULT_SPIN_SPEED): Promise<void> {
|
|
142
172
|
return this.#run((plugin) => {
|
|
143
173
|
setSpin(plugin, spinning, speed);
|
|
144
174
|
});
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export function writeDocumentMeta(meta: DocumentMeta): void {
|
|
12
12
|
if (typeof document === 'undefined') return;
|
|
13
|
-
documentTitle(meta.title);
|
|
14
|
-
if (meta.description
|
|
15
|
-
if (meta.canonical
|
|
13
|
+
if (meta.title) documentTitle(meta.title);
|
|
14
|
+
if (meta.description) metaDescription(meta.description);
|
|
15
|
+
if (meta.canonical) canonicalLink(meta.canonical);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -58,8 +58,8 @@ export interface DocumentMeta {
|
|
|
58
58
|
title: string;
|
|
59
59
|
/**
|
|
60
60
|
* One sentence describing this page, in the words someone would search for.
|
|
61
|
-
* Left out, the description the page was served with stays as it is
|
|
62
|
-
* is what every crawler but a rendering one has already read.
|
|
61
|
+
* Left out or empty, the description the page was served with stays as it is
|
|
62
|
+
* — which is what every crawler but a rendering one has already read.
|
|
63
63
|
* @default undefined
|
|
64
64
|
*/
|
|
65
65
|
description?: string;
|
package/src/seo/core/index.ts
CHANGED
|
@@ -4,23 +4,30 @@ export {
|
|
|
4
4
|
documentTitle,
|
|
5
5
|
writeDocumentMeta,
|
|
6
6
|
} from './documentMeta.ts';
|
|
7
|
+
export type {
|
|
8
|
+
NoscriptEcosystem,
|
|
9
|
+
NoscriptHrefs,
|
|
10
|
+
NoscriptOptions,
|
|
11
|
+
NoscriptRoute,
|
|
12
|
+
NoscriptText,
|
|
13
|
+
} from './noscript.ts';
|
|
14
|
+
export { noscriptIndex } from './noscript.ts';
|
|
7
15
|
export type { PageMetaOptions } from './pageMeta.ts';
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
pageDocumentMeta,
|
|
12
|
-
} from './pageMeta.ts';
|
|
16
|
+
export { injectPageMeta, pageDocumentMeta, pageHeadTags } from './pageMeta.ts';
|
|
17
|
+
export type { RobotsDisallow } from './robots.ts';
|
|
18
|
+
export { robotsTxt } from './robots.ts';
|
|
13
19
|
export type { RouteMeta } from './routes.ts';
|
|
14
20
|
export {
|
|
21
|
+
assertRoutes,
|
|
15
22
|
homeRoute,
|
|
16
23
|
pageMetaFor,
|
|
17
24
|
routeFor,
|
|
18
25
|
trimTrailingSlash,
|
|
19
26
|
} from './routes.ts';
|
|
20
|
-
export type { SiteFilesOptions
|
|
21
|
-
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from './
|
|
27
|
+
export type { SiteFilesOptions } from './siteFiles.ts';
|
|
28
|
+
export { sitemapXml } from './siteFiles.ts';
|
|
29
|
+
export type { StartDocumentMetaOptions } from './startDocumentMeta.ts';
|
|
30
|
+
export { startDocumentMeta } from './startDocumentMeta.ts';
|
|
31
|
+
export type { StructuredDataOptions } from './structuredData.ts';
|
|
32
|
+
export { structuredDataScript } from './structuredData.ts';
|
|
33
|
+
export { PAGE_BODY_MARKER, PAGE_HEAD_MARKER, fill } from './template.ts';
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A readable page for a visitor, or a crawler, with no JavaScript.
|
|
3
|
+
*
|
|
4
|
+
* The body of our sites is an empty root element, so this is the only crawl
|
|
5
|
+
* path through them that costs nothing to render — and it is honest: it says
|
|
6
|
+
* the tool needs JavaScript, and links the addresses it answers.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { siteById, siteDisplayName } from '../../ecosystem/core/lookup.ts';
|
|
10
|
+
import type { EcosystemSite, SiteId } from '../../ecosystem/core/sites.ts';
|
|
11
|
+
import { ECOSYSTEM_SITES, siteUrl } from '../../ecosystem/core/sites.ts';
|
|
12
|
+
import { joinBasePath } from '../../router/core/basePath.ts';
|
|
13
|
+
import { escapeAttribute, escapeText } from '../../share/core/escape.ts';
|
|
14
|
+
|
|
15
|
+
import type { RouteMeta } from './routes.ts';
|
|
16
|
+
import type { SiteFilesOptions } from './siteFiles.ts';
|
|
17
|
+
import { mountPathOf, resolveSite } from './siteFiles.ts';
|
|
18
|
+
|
|
19
|
+
/** How the addresses of the site's own pages are written. */
|
|
20
|
+
export type NoscriptHrefs = 'absolute' | 'relative';
|
|
21
|
+
|
|
22
|
+
/** A page the block links, and the pages listed under it. */
|
|
23
|
+
export interface NoscriptRoute extends RouteMeta {
|
|
24
|
+
/**
|
|
25
|
+
* Pages listed under this one, as a list nested in its item — the sections of
|
|
26
|
+
* an exercise set under the set itself.
|
|
27
|
+
* @default undefined — the item carries no list
|
|
28
|
+
*/
|
|
29
|
+
children?: readonly NoscriptRoute[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Which of the family's other sites are listed, and how. */
|
|
33
|
+
export interface NoscriptEcosystem {
|
|
34
|
+
/**
|
|
35
|
+
* The sites listed, in the order they are named. The site writing the block
|
|
36
|
+
* is never one of them, whether or not it is named: the list is headed *Our
|
|
37
|
+
* other tools*.
|
|
38
|
+
* @default every other site in the family, in the family's own order
|
|
39
|
+
*/
|
|
40
|
+
sites?: readonly SiteId[];
|
|
41
|
+
/**
|
|
42
|
+
* Whether each host is followed by ` — ` and the site's one-line tagline.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
taglines?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The prose of the block, where the site says more than its record does. */
|
|
49
|
+
export interface NoscriptText {
|
|
50
|
+
/**
|
|
51
|
+
* The heading the block opens with.
|
|
52
|
+
* @default the site's display name
|
|
53
|
+
*/
|
|
54
|
+
heading?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The paragraph under it, taken as written. It is the one place a reader with
|
|
57
|
+
* no JavaScript is told what the tool is, so it may say more than the tagline
|
|
58
|
+
* — but it still has to say that the tool needs JavaScript.
|
|
59
|
+
* @default the tagline, followed by the sentence naming the requirement
|
|
60
|
+
*/
|
|
61
|
+
intro?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the family's other sites are listed under the site's own pages, and
|
|
64
|
+
* which of them. A crawler that runs no script has no other path from one of
|
|
65
|
+
* our tools to the next, so a site that lists none leaves it with none.
|
|
66
|
+
* `true` lists every other site with its tagline; an object names the sites,
|
|
67
|
+
* or drops the taglines, or both.
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
ecosystem?: boolean | NoscriptEcosystem;
|
|
71
|
+
/**
|
|
72
|
+
* How the site's own addresses are written. `'absolute'` writes them from the
|
|
73
|
+
* root of the host, under the mount the origin names. `'relative'` writes
|
|
74
|
+
* `./exercises` and `./`, which the page resolves against its own `<base>` —
|
|
75
|
+
* the only shape that works for an image whose mount is chosen at container
|
|
76
|
+
* startup, because it bakes no mount into the build at all. The `<base>` such
|
|
77
|
+
* a deployment stamps in ends with a slash, or a relative address resolves
|
|
78
|
+
* one directory too high.
|
|
79
|
+
* @default 'absolute'
|
|
80
|
+
*/
|
|
81
|
+
hrefs?: NoscriptHrefs;
|
|
82
|
+
/**
|
|
83
|
+
* The pages the block links, when they are not the site's whole route table.
|
|
84
|
+
* A crawl path is a menu: a site whose table carries an entry per tutorial
|
|
85
|
+
* step lists the tutorial, not its hundred and thirty-seven steps.
|
|
86
|
+
* @default every route the site answers
|
|
87
|
+
*/
|
|
88
|
+
routes?: readonly NoscriptRoute[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** What the block says, and which addresses it links. */
|
|
92
|
+
export interface NoscriptOptions
|
|
93
|
+
extends Omit<SiteFilesOptions, 'routes'>, Omit<NoscriptText, 'routes'> {
|
|
94
|
+
/** The addresses it links, each with the label it is linked under. */
|
|
95
|
+
routes: readonly NoscriptRoute[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The `noscript` block, ready to put in the body.
|
|
100
|
+
*
|
|
101
|
+
* An absolute address is written under the mount the deployment named, so a
|
|
102
|
+
* build published as one tool among several on a shared host links its own
|
|
103
|
+
* pages rather than the root of the host it shares.
|
|
104
|
+
* @param options - The site, the pages it links, and the prose that opens the
|
|
105
|
+
* block.
|
|
106
|
+
* @returns The block.
|
|
107
|
+
* @throws {Error} When the deployment named an origin that is not an absolute
|
|
108
|
+
* address.
|
|
109
|
+
*/
|
|
110
|
+
export function noscriptIndex(options: NoscriptOptions): string {
|
|
111
|
+
const site = resolveSite(options.site);
|
|
112
|
+
const hrefs = options.hrefs ?? 'absolute';
|
|
113
|
+
const mount = hrefs === 'absolute' ? mountPathOf(options) : '';
|
|
114
|
+
const heading = escapeText(options.heading ?? siteDisplayName(site));
|
|
115
|
+
const intro = escapeText(
|
|
116
|
+
options.intro ??
|
|
117
|
+
`${site.tagline} This tool needs JavaScript; these are the pages it offers:`,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return `<noscript>
|
|
121
|
+
<h1>${heading}</h1>
|
|
122
|
+
<p>${intro}</p>${pageList(options.routes, mount, hrefs, ' ')}${familyList(site.id, options.ecosystem)}
|
|
123
|
+
</noscript>`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function pageList(
|
|
127
|
+
routes: readonly NoscriptRoute[],
|
|
128
|
+
mount: string,
|
|
129
|
+
hrefs: NoscriptHrefs,
|
|
130
|
+
indent: string,
|
|
131
|
+
): string {
|
|
132
|
+
// A list with no item is not a list: `<ul>` holds at least one `<li>`.
|
|
133
|
+
if (routes.length === 0) return '';
|
|
134
|
+
const items = routes
|
|
135
|
+
.map((route) => pageItem(route, mount, hrefs, `${indent} `))
|
|
136
|
+
.join('\n');
|
|
137
|
+
return `\n${indent}<ul>\n${items}\n${indent}</ul>`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function pageItem(
|
|
141
|
+
route: NoscriptRoute,
|
|
142
|
+
mount: string,
|
|
143
|
+
hrefs: NoscriptHrefs,
|
|
144
|
+
indent: string,
|
|
145
|
+
): string {
|
|
146
|
+
const href = escapeAttribute(pageHref(route.path, mount, hrefs));
|
|
147
|
+
const label = escapeText(labelOf(route));
|
|
148
|
+
const note =
|
|
149
|
+
route.note === undefined || route.note.trim() === ''
|
|
150
|
+
? ''
|
|
151
|
+
: ` — ${escapeText(route.note)}`;
|
|
152
|
+
const children = route.children ?? [];
|
|
153
|
+
const link = `<a href="${href}">${label}</a>${note}`;
|
|
154
|
+
if (children.length === 0) return `${indent}<li>${link}</li>`;
|
|
155
|
+
return `${indent}<li>${link}${pageList(children, mount, hrefs, `${indent} `)}
|
|
156
|
+
${indent}</li>`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function pageHref(path: string, mount: string, hrefs: NoscriptHrefs): string {
|
|
160
|
+
if (hrefs === 'absolute') return joinBasePath(mount, path);
|
|
161
|
+
return `./${path.startsWith('/') ? path.slice(1) : path}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function labelOf(route: NoscriptRoute): string {
|
|
165
|
+
const short = route.short;
|
|
166
|
+
return short !== undefined && short.trim() !== '' ? short : route.title;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function familyList(
|
|
170
|
+
current: SiteId,
|
|
171
|
+
ecosystem: boolean | NoscriptEcosystem | undefined,
|
|
172
|
+
): string {
|
|
173
|
+
if (ecosystem === undefined || ecosystem === false) return '';
|
|
174
|
+
const listed = ecosystem === true ? {} : ecosystem;
|
|
175
|
+
const taglines = listed.taglines ?? true;
|
|
176
|
+
const items: string[] = [];
|
|
177
|
+
for (const site of familySites(listed.sites)) {
|
|
178
|
+
if (site.id === current) continue;
|
|
179
|
+
const tagline = taglines ? ` — ${escapeText(site.tagline)}` : '';
|
|
180
|
+
items.push(
|
|
181
|
+
` <li><a href="${escapeAttribute(siteUrl(site))}">${escapeText(site.host)}</a>${tagline}</li>`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (items.length === 0) return '';
|
|
185
|
+
return `
|
|
186
|
+
<h2>Our other tools</h2>
|
|
187
|
+
<ul>
|
|
188
|
+
${items.join('\n')}
|
|
189
|
+
</ul>`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function familySites(sites: readonly SiteId[] | undefined): EcosystemSite[] {
|
|
193
|
+
if (sites === undefined) return [...ECOSYSTEM_SITES];
|
|
194
|
+
return sites.map((id) => siteById(id));
|
|
195
|
+
}
|