@mark1russell7/visuals 0.1.1 → 0.2.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.
package/build/marks.js ADDED
@@ -0,0 +1,231 @@
1
+ import { addPoints3, cross3, dot3, length3, scalePoint3 } from "@mark1russell7/layout-contract";
2
+ // src/marks/levels.ts
3
+ /** These are the levels of a mark, from the lowest to the highest. */
4
+ const LEVELS = [
5
+ "unknown",
6
+ "ok",
7
+ "near",
8
+ "over"
9
+ ];
10
+ /**
11
+ * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.
12
+ * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.
13
+ */
14
+ function levelRank(level) {
15
+ return LEVELS.indexOf(level);
16
+ }
17
+ /** These are the shapes of the sign of a level. */
18
+ const LEVEL_SHAPES = [
19
+ "ring",
20
+ "disc",
21
+ "triangle",
22
+ "square"
23
+ ];
24
+ /**
25
+ * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.
26
+ * The level `unknown` has a ring, and so has a record with no level.
27
+ */
28
+ function levelShape(level) {
29
+ return level === "ok" ? "disc" : level === "near" ? "triangle" : level === "over" ? "square" : "ring";
30
+ }
31
+ /**
32
+ * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.
33
+ * A triangle and a square with the radius of the disc look small, so they are larger.
34
+ */
35
+ const SHAPE_OUTLINES = {
36
+ ring: {
37
+ radius: 1,
38
+ sides: 40,
39
+ start: 0,
40
+ hole: .52
41
+ },
42
+ disc: {
43
+ radius: 1,
44
+ sides: 40,
45
+ start: 0,
46
+ hole: 0
47
+ },
48
+ triangle: {
49
+ radius: 1.3,
50
+ sides: 3,
51
+ start: Math.PI / 2,
52
+ hole: 0
53
+ },
54
+ square: {
55
+ radius: 1.25,
56
+ sides: 4,
57
+ start: Math.PI / 4,
58
+ hole: 0
59
+ }
60
+ };
61
+ /**
62
+ * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.
63
+ * The center of the sign is the origin, and `radius` is the radius of a disc.
64
+ */
65
+ function shapeRing(shape, radius = 1) {
66
+ const outline = SHAPE_OUTLINES[shape];
67
+ return Array.from({ length: outline.sides }, (_, index) => {
68
+ const angle = outline.start + index * 2 * Math.PI / outline.sides;
69
+ return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];
70
+ });
71
+ }
72
+ // src/marks/check.ts
73
+ /**
74
+ * These are the codes of the faults of a mark:
75
+ * - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.
76
+ * - `level`: the level of the mark is not known.
77
+ * - `name`: a record name or the kind is empty.
78
+ * - `label`: the label is empty, or it has more than one line.
79
+ * - `number`: a number is not finite.
80
+ * - `direction`: a direction is not a unit vector.
81
+ * - `angle`: the column step of a field is not at a right angle to the direction out of its plane.
82
+ * - `size`: a size, a width or a cell is not more than 0.
83
+ * - `grid`: the number of the columns or of the rows of a field is not a whole number of 1 or more.
84
+ * - `values`: a field does not have one value for each cell.
85
+ * - `scale`: the `min` of the scale of a field is not less than its `max`.
86
+ * - `path`: a run has fewer than 2 points.
87
+ */
88
+ const MARK_FAULT_CODES = [
89
+ "type",
90
+ "level",
91
+ "name",
92
+ "label",
93
+ "number",
94
+ "direction",
95
+ "angle",
96
+ "size",
97
+ "grid",
98
+ "values",
99
+ "scale",
100
+ "path"
101
+ ];
102
+ /**
103
+ * The tolerance of a direction. A unit vector has the length 1 with this tolerance.
104
+ * Two directions are at a right angle when their dot product is 0 with this tolerance.
105
+ */
106
+ const DIRECTION_TOLERANCE = 1e-6;
107
+ /**
108
+ * This function gives the faults of a list of marks, in the sequence of the list. A list with no fault gives an empty list.
109
+ * It examines the values that the types do not hold: finite numbers, unit vectors, sizes, the grid of a field and the names.
110
+ * A producer of marks uses it as a gate in its tests, and a viewer uses it on a list that it did not make.
111
+ * It does not examine the form of a mark: read a list from JSON through a schema first.
112
+ */
113
+ function checkMarks(marks) {
114
+ const faults = [];
115
+ marks.forEach((mark, index) => {
116
+ const fault = (code, part, message) => {
117
+ faults.push({
118
+ code,
119
+ index,
120
+ record: mark.record,
121
+ part,
122
+ message
123
+ });
124
+ };
125
+ const finite = (part, value) => {
126
+ if (Number.isFinite(value)) return true;
127
+ fault("number", part, `${part} is not a finite number: ${String(value)}`);
128
+ return false;
129
+ };
130
+ const point = (part, value) => {
131
+ const x = finite(`${part}.x`, value.x);
132
+ const y = finite(`${part}.y`, value.y);
133
+ const z = finite(`${part}.z`, value.z);
134
+ return x && y && z;
135
+ };
136
+ const direction = (part, value) => {
137
+ if (!point(part, value)) return false;
138
+ const length = length3(value);
139
+ if (Math.abs(length - 1) <= 1e-6) return true;
140
+ fault("direction", part, `${part} is not a unit vector: its length is ${String(length)}`);
141
+ return false;
142
+ };
143
+ const frame = (part, value) => {
144
+ const at = point(`${part}.at`, value.at);
145
+ const out = direction(`${part}.out`, value.out);
146
+ return at && out;
147
+ };
148
+ const positive = (part, value) => {
149
+ if (finite(part, value) && value <= 0) fault("size", part, `${part} is not more than 0: ${String(value)}`);
150
+ };
151
+ const count = (part, value) => {
152
+ if (Number.isInteger(value) && value >= 1) return true;
153
+ fault("grid", part, `${part} is not a whole number of 1 or more: ${String(value)}`);
154
+ return false;
155
+ };
156
+ if (mark.record === "") fault("name", "record", "the mark has no record name");
157
+ if (mark.kind === "") fault("name", "kind", "the mark has no kind");
158
+ if (!LEVELS.includes(mark.level)) fault("level", "level", `the level is not known: ${String(mark.level)}`);
159
+ if (mark.label.trim() === "") fault("label", "label", "the mark has no label");
160
+ else if (/[\r\n]/.test(mark.label)) fault("label", "label", "the label has more than one line");
161
+ switch (mark.type) {
162
+ case "point":
163
+ frame("frame", mark.frame);
164
+ if (mark.size !== void 0) positive("size", mark.size);
165
+ break;
166
+ case "run":
167
+ if (mark.path.length < 2) fault("path", "path", `the path has ${String(mark.path.length)} points, and a run needs 2 or more`);
168
+ mark.path.forEach((step, at) => frame(`path[${String(at)}]`, step));
169
+ positive("width", mark.width);
170
+ break;
171
+ case "link":
172
+ for (const [name, end] of [["from", mark.from], ["to", mark.to]]) {
173
+ if (end.record === "") fault("name", `${name}.record`, `the end ${name} has no record name`);
174
+ point(`${name}.at`, end.at);
175
+ }
176
+ break;
177
+ case "field": {
178
+ const hasFrame = frame("frame", mark.frame);
179
+ const hasAcross = direction("across", mark.across);
180
+ if (hasFrame && hasAcross) {
181
+ const dot = dot3(mark.frame.out, mark.across);
182
+ if (Math.abs(dot) > 1e-6) fault("angle", "across", `across is not at a right angle to frame.out: their dot product is ${String(dot)}`);
183
+ }
184
+ positive("cell", mark.cell);
185
+ const hasColumns = count("columns", mark.columns);
186
+ const hasRows = count("rows", mark.rows);
187
+ if (hasColumns && hasRows && mark.values.length !== mark.columns * mark.rows) fault("values", "values", `the field has ${String(mark.values.length)} values, and ${String(mark.columns)} columns of ${String(mark.rows)} rows need ${String(mark.columns * mark.rows)}`);
188
+ const bad = mark.values.flatMap((value, at) => value === null || Number.isFinite(value) ? [] : [at]);
189
+ const first = bad[0];
190
+ if (first !== void 0) fault("number", `values[${String(first)}]`, `${String(bad.length)} of the values are not finite numbers, the first is values[${String(first)}]: ${String(mark.values[first])}`);
191
+ const hasMin = finite("scale.min", mark.scale.min);
192
+ const hasMax = finite("scale.max", mark.scale.max);
193
+ if (hasMin && hasMax && mark.scale.min >= mark.scale.max) fault("scale", "scale", `scale.min is not less than scale.max: ${String(mark.scale.min)} and ${String(mark.scale.max)}`);
194
+ break;
195
+ }
196
+ case "meter":
197
+ finite("value", mark.value);
198
+ finite("limit", mark.limit);
199
+ break;
200
+ default: fault("type", "type", `the type is not known: ${String(mark.type)}`);
201
+ }
202
+ });
203
+ return faults;
204
+ }
205
+ // src/marks/mark.ts
206
+ /** These are the types of a mark. */
207
+ const MARK_TYPES = [
208
+ "point",
209
+ "run",
210
+ "link",
211
+ "field",
212
+ "meter"
213
+ ];
214
+ /** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */
215
+ function fieldRowStep(field) {
216
+ return cross3(field.frame.out, field.across);
217
+ }
218
+ /** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */
219
+ function fieldCellCenter(field, column, row) {
220
+ const across = scalePoint3(field.across, (column + .5) * field.cell);
221
+ const down = scalePoint3(fieldRowStep(field), (row + .5) * field.cell);
222
+ return addPoints3(field.frame.at, addPoints3(across, down));
223
+ }
224
+ /** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */
225
+ function fieldValue(field, column, row) {
226
+ if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;
227
+ return field.values[row * field.columns + column] ?? null;
228
+ }
229
+ export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
230
+
231
+ //# sourceMappingURL=marks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marks.js","names":[],"sources":["../src/marks/levels.ts","../src/marks/check.ts","../src/marks/mark.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\n\n/** These are the levels of a mark, from the lowest to the highest. */\nexport const LEVELS: readonly [\"unknown\", \"ok\", \"near\", \"over\"] = [\"unknown\", \"ok\", \"near\", \"over\"];\n\n/**\n * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.\n * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.\n */\nexport type Level = (typeof LEVELS)[number];\n\n/**\n * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.\n * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.\n */\nexport function levelRank(level: Level): number {\n return LEVELS.indexOf(level);\n}\n\n/** These are the shapes of the sign of a level. */\nexport const LEVEL_SHAPES: readonly [\"ring\", \"disc\", \"triangle\", \"square\"] = [\"ring\", \"disc\", \"triangle\", \"square\"];\n\n/** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */\nexport type LevelShape = (typeof LEVEL_SHAPES)[number];\n\n/**\n * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.\n * The level `unknown` has a ring, and so has a record with no level.\n */\nexport function levelShape(level: Level | undefined): LevelShape {\n return level === \"ok\" ? \"disc\" : level === \"near\" ? \"triangle\" : level === \"over\" ? \"square\" : \"ring\";\n}\n\n/** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */\nexport interface ShapeOutline {\n /** The radius of the circle through the corners, for a disc with the radius 1. */\n readonly radius: number;\n /** The number of the sides. */\n readonly sides: number;\n /** The angle of the first corner, in radians, counter-clockwise from the x axis. */\n readonly start: number;\n /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */\n readonly hole: number;\n}\n\n/**\n * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.\n * A triangle and a square with the radius of the disc look small, so they are larger.\n */\nexport const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>> = {\n ring: { radius: 1, sides: 40, start: 0, hole: 0.52 },\n disc: { radius: 1, sides: 40, start: 0, hole: 0 },\n triangle: { radius: 1.3, sides: 3, start: Math.PI / 2, hole: 0 },\n square: { radius: 1.25, sides: 4, start: Math.PI / 4, hole: 0 },\n};\n\n/**\n * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.\n * The center of the sign is the origin, and `radius` is the radius of a disc.\n */\nexport function shapeRing(shape: LevelShape, radius: number = 1): Ring {\n const outline = SHAPE_OUTLINES[shape];\n return Array.from({ length: outline.sides }, (_, index): readonly [number, number] => {\n const angle = outline.start + (index * 2 * Math.PI) / outline.sides;\n return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];\n });\n}\n","import { dot3, length3, type Point3 } from \"@mark1russell7/layout-contract\";\nimport { LEVELS } from \"./levels.ts\";\nimport type { Frame, Mark } from \"./mark.ts\";\n\n/**\n * These are the codes of the faults of a mark:\n * - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.\n * - `level`: the level of the mark is not known.\n * - `name`: a record name or the kind is empty.\n * - `label`: the label is empty, or it has more than one line.\n * - `number`: a number is not finite.\n * - `direction`: a direction is not a unit vector.\n * - `angle`: the column step of a field is not at a right angle to the direction out of its plane.\n * - `size`: a size, a width or a cell is not more than 0.\n * - `grid`: the number of the columns or of the rows of a field is not a whole number of 1 or more.\n * - `values`: a field does not have one value for each cell.\n * - `scale`: the `min` of the scale of a field is not less than its `max`.\n * - `path`: a run has fewer than 2 points.\n */\nexport const MARK_FAULT_CODES: readonly [\"type\", \"level\", \"name\", \"label\", \"number\", \"direction\", \"angle\", \"size\", \"grid\", \"values\", \"scale\", \"path\"] = [\n \"type\",\n \"level\",\n \"name\",\n \"label\",\n \"number\",\n \"direction\",\n \"angle\",\n \"size\",\n \"grid\",\n \"values\",\n \"scale\",\n \"path\",\n];\n\n/** A code of a fault of a mark. */\nexport type MarkFaultCode = (typeof MARK_FAULT_CODES)[number];\n\n/** One fault of a mark of a list. */\nexport interface MarkFault {\n readonly code: MarkFaultCode;\n /** The index of the mark in the list. */\n readonly index: number;\n /** The record name of the mark. */\n readonly record: string;\n /** The part of the mark with the fault, for example `path[2].out`. */\n readonly part: string;\n /** The fault in plain words, with the values. */\n readonly message: string;\n}\n\n/**\n * The tolerance of a direction. A unit vector has the length 1 with this tolerance.\n * Two directions are at a right angle when their dot product is 0 with this tolerance.\n */\nexport const DIRECTION_TOLERANCE = 1e-6;\n\n/**\n * This function gives the faults of a list of marks, in the sequence of the list. A list with no fault gives an empty list.\n * It examines the values that the types do not hold: finite numbers, unit vectors, sizes, the grid of a field and the names.\n * A producer of marks uses it as a gate in its tests, and a viewer uses it on a list that it did not make.\n * It does not examine the form of a mark: read a list from JSON through a schema first.\n */\nexport function checkMarks(marks: readonly Mark[]): readonly MarkFault[] {\n const faults: MarkFault[] = [];\n marks.forEach((mark, index) => {\n const fault = (code: MarkFaultCode, part: string, message: string): void => {\n faults.push({ code, index, record: mark.record, part, message });\n };\n const finite = (part: string, value: number): boolean => {\n if (Number.isFinite(value)) return true;\n fault(\"number\", part, `${part} is not a finite number: ${String(value)}`);\n return false;\n };\n const point = (part: string, value: Point3): boolean => {\n const x = finite(`${part}.x`, value.x);\n const y = finite(`${part}.y`, value.y);\n const z = finite(`${part}.z`, value.z);\n return x && y && z;\n };\n const direction = (part: string, value: Point3): boolean => {\n if (!point(part, value)) return false;\n const length = length3(value);\n if (Math.abs(length - 1) <= DIRECTION_TOLERANCE) return true;\n fault(\"direction\", part, `${part} is not a unit vector: its length is ${String(length)}`);\n return false;\n };\n const frame = (part: string, value: Frame): boolean => {\n const at = point(`${part}.at`, value.at);\n const out = direction(`${part}.out`, value.out);\n return at && out;\n };\n const positive = (part: string, value: number): void => {\n if (finite(part, value) && value <= 0) fault(\"size\", part, `${part} is not more than 0: ${String(value)}`);\n };\n const count = (part: string, value: number): boolean => {\n if (Number.isInteger(value) && value >= 1) return true;\n fault(\"grid\", part, `${part} is not a whole number of 1 or more: ${String(value)}`);\n return false;\n };\n\n if (mark.record === \"\") fault(\"name\", \"record\", \"the mark has no record name\");\n if (mark.kind === \"\") fault(\"name\", \"kind\", \"the mark has no kind\");\n if (!(LEVELS as readonly string[]).includes(mark.level)) fault(\"level\", \"level\", `the level is not known: ${String(mark.level)}`);\n if (mark.label.trim() === \"\") fault(\"label\", \"label\", \"the mark has no label\");\n else if (/[\\r\\n]/.test(mark.label)) fault(\"label\", \"label\", \"the label has more than one line\");\n\n switch (mark.type) {\n case \"point\":\n frame(\"frame\", mark.frame);\n if (mark.size !== undefined) positive(\"size\", mark.size);\n break;\n case \"run\":\n if (mark.path.length < 2) fault(\"path\", \"path\", `the path has ${String(mark.path.length)} points, and a run needs 2 or more`);\n mark.path.forEach((step, at) => frame(`path[${String(at)}]`, step));\n positive(\"width\", mark.width);\n break;\n case \"link\":\n for (const [name, end] of [\n [\"from\", mark.from],\n [\"to\", mark.to],\n ] as const) {\n if (end.record === \"\") fault(\"name\", `${name}.record`, `the end ${name} has no record name`);\n point(`${name}.at`, end.at);\n }\n break;\n case \"field\": {\n const hasFrame = frame(\"frame\", mark.frame);\n const hasAcross = direction(\"across\", mark.across);\n if (hasFrame && hasAcross) {\n const dot = dot3(mark.frame.out, mark.across);\n if (Math.abs(dot) > DIRECTION_TOLERANCE) fault(\"angle\", \"across\", `across is not at a right angle to frame.out: their dot product is ${String(dot)}`);\n }\n positive(\"cell\", mark.cell);\n const hasColumns = count(\"columns\", mark.columns);\n const hasRows = count(\"rows\", mark.rows);\n if (hasColumns && hasRows && mark.values.length !== mark.columns * mark.rows) {\n fault(\"values\", \"values\", `the field has ${String(mark.values.length)} values, and ${String(mark.columns)} columns of ${String(mark.rows)} rows need ${String(mark.columns * mark.rows)}`);\n }\n // A field can have many cells, so the values give one fault, not one fault for each cell.\n const bad = mark.values.flatMap((value, at) => (value === null || Number.isFinite(value) ? [] : [at]));\n const first = bad[0];\n if (first !== undefined) {\n fault(\"number\", `values[${String(first)}]`, `${String(bad.length)} of the values are not finite numbers, the first is values[${String(first)}]: ${String(mark.values[first])}`);\n }\n const hasMin = finite(\"scale.min\", mark.scale.min);\n const hasMax = finite(\"scale.max\", mark.scale.max);\n if (hasMin && hasMax && mark.scale.min >= mark.scale.max) {\n fault(\"scale\", \"scale\", `scale.min is not less than scale.max: ${String(mark.scale.min)} and ${String(mark.scale.max)}`);\n }\n break;\n }\n case \"meter\":\n finite(\"value\", mark.value);\n finite(\"limit\", mark.limit);\n break;\n default:\n fault(\"type\", \"type\", `the type is not known: ${String((mark as { readonly type: unknown }).type)}`);\n }\n });\n return faults;\n}\n","import { addPoints3, cross3, scalePoint3, type Point3 } from \"@mark1russell7/layout-contract\";\nimport type { Level } from \"./levels.ts\";\n\n/** A point of a surface, and the direction out of the surface. */\nexport interface Frame {\n /** The point. */\n readonly at: Point3;\n /** The unit vector out of the surface at the point. */\n readonly out: Point3;\n}\n\n/** These are the types of a mark. */\nexport const MARK_TYPES: readonly [\"point\", \"run\", \"link\", \"field\", \"meter\"] = [\"point\", \"run\", \"link\", \"field\", \"meter\"];\n\n/** A type of a mark. */\nexport type MarkType = (typeof MARK_TYPES)[number];\n\n/**\n * The parts that each mark has. A mark has no shape and no color.\n * A viewer gets the shape from the level, and the color from the level and its theme. Thus a mark does not use color alone.\n */\nexport interface MarkBase {\n /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */\n readonly record: string;\n /** A word of the producer for the legend and the filter, for example `outlet`. */\n readonly kind: string;\n /** The level of the mark. The producer calculates it. */\n readonly level: Level;\n /** One line of text: the name of the mark for a person and for a screen reader. */\n readonly label: string;\n}\n\n/** A mark at one point of a surface, for example an outlet, a tap or a lamp. */\nexport interface PointMark extends MarkBase {\n readonly type: \"point\";\n /** The point, and the direction out of its surface. */\n readonly frame: Frame;\n /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */\n readonly size?: number | undefined;\n}\n\n/** A mark along a path on surfaces, for example a cable, a pipe or a duct. */\nexport interface RunMark extends MarkBase {\n readonly type: \"run\";\n /** The points of the path, in sequence. Each point has its own direction, so a run can go across surfaces. A path has 2 or more points. */\n readonly path: readonly Frame[];\n /** The width of the run, in the unit of the space. */\n readonly width: number;\n}\n\n/** One end of a link. */\nexport interface LinkEnd {\n /** The name of the record at this end. A viewer shows the link when the record of one end is selected or under the pointer. */\n readonly record: string;\n /** The point of this end. */\n readonly at: Point3;\n}\n\n/** A mark between two records, for example a power line from an outlet to a computer. */\nexport interface LinkMark extends MarkBase {\n readonly type: \"link\";\n readonly from: LinkEnd;\n readonly to: LinkEnd;\n}\n\n/** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */\nexport interface FieldScale {\n /** The value of the first color. It is less than `max`. */\n readonly min: number;\n /** The value of the last color. */\n readonly max: number;\n /** The text of the unit of the values, for example `lx`. */\n readonly unit: string;\n}\n\n/** A grid of values on a plane, for example the light on a floor or the heat of a wall. */\nexport interface FieldMark extends MarkBase {\n readonly type: \"field\";\n /** The corner of the first cell, and the direction out of the plane. */\n readonly frame: Frame;\n /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */\n readonly across: Point3;\n /** The length of a side of a cell, in the unit of the space. */\n readonly cell: number;\n /** The number of the columns. */\n readonly columns: number;\n /** The number of the rows. */\n readonly rows: number;\n /**\n * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.\n * A cell with no value has `null`, because JSON has no NaN.\n */\n readonly values: readonly (number | null)[];\n readonly scale: FieldScale;\n}\n\n/**\n * A value against a limit, for example the load of a circuit. A meter has no place.\n * A page draws it in a panel, and a 3D view ignores it.\n */\nexport interface MeterMark extends MarkBase {\n readonly type: \"meter\";\n readonly value: number;\n readonly limit: number;\n /** The text of the unit of the value and of the limit, for example `W`. */\n readonly unit: string;\n}\n\n/**\n * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.\n * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.\n */\nexport type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;\n\n/** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */\nexport function fieldRowStep(field: FieldMark): Point3 {\n return cross3(field.frame.out, field.across);\n}\n\n/** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */\nexport function fieldCellCenter(field: FieldMark, column: number, row: number): Point3 {\n const across = scalePoint3(field.across, (column + 0.5) * field.cell);\n const down = scalePoint3(fieldRowStep(field), (row + 0.5) * field.cell);\n return addPoints3(field.frame.at, addPoints3(across, down));\n}\n\n/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */\nexport function fieldValue(field: FieldMark, column: number, row: number): number | null {\n if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;\n return field.values[row * field.columns + column] ?? null;\n}\n"],"mappings":";;;AAGA,MAAa,SAAqD;CAAC;CAAW;CAAM;CAAQ;AAAM;;;;;AAYlG,SAA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Y,aAAa,KAAK,IAAI,MAAM,MAAO,MAAM,IAAI;CACtE,OAAO,WAAW,MAAM,MAAM,IAAI,WAAW,QAAQ,IAAI,CAAC;AAC5D;;AAGA,SAAgB,WAAW,OAAkB,QAAgB,KAA4B;CACvF,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,CAAC,OAAO,UAAU,GAAG,KAAK,SAAS,KAAK,MAAM,KAAK,UAAU,MAAM,WAAW,OAAO,MAAM,MAAM,OAAO;CACzI,OAAO,MAAM,OAAO,MAAM,MAAM,UAAU,WAAW;AACvD"}
@@ -71,17 +71,17 @@ function keyAction(key, now, options) {
71
71
  }
72
72
  }
73
73
  }
74
- // src/marks.ts
75
- /** The marks of a stage with no pointer on it and no selected record. */
76
- const NO_MARKS = {
74
+ // src/highlight.ts
75
+ /** The highlights of a stage with no pointer on it and no selected record. */
76
+ const NO_HIGHLIGHTS = {
77
77
  hovered: void 0,
78
78
  selected: void 0,
79
- marked: /* @__PURE__ */ new Set()
79
+ highlighted: /* @__PURE__ */ new Set()
80
80
  };
81
- /** This function gives the mark of a record. The selected record has the highest mark. */
82
- function markOf(marks, record) {
83
- if (record === marks.selected) return 2;
84
- return record === marks.hovered || marks.marked.has(record) ? 1 : 0;
81
+ /** This function gives the highlight of a record. The selected record has the highest highlight. */
82
+ function highlightOf(highlights, record) {
83
+ if (record === highlights.selected) return 2;
84
+ return record === highlights.hovered || highlights.highlighted.has(record) ? 1 : 0;
85
85
  }
86
86
  /** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */
87
87
  const CLICK_DISTANCE = 4;
@@ -127,6 +127,6 @@ function approach(value, goal, seconds, time, snap = .01) {
127
127
  const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));
128
128
  return Math.abs(goal - next) < snap ? goal : next;
129
129
  }
130
- export { NO_MARKS as a, KEY_TURN as c, CLICK_DISTANCE as i, KEY_ZOOM as l, easeInOut as n, isClick as o, moveAt as r, markOf as s, approach as t, keyAction as u };
130
+ export { NO_HIGHLIGHTS as a, KEY_TURN as c, CLICK_DISTANCE as i, KEY_ZOOM as l, easeInOut as n, highlightOf as o, moveAt as r, isClick as s, approach as t, keyAction as u };
131
131
 
132
- //# sourceMappingURL=motion-BwDDtx3D.js.map
132
+ //# sourceMappingURL=motion-0tsT6sY4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion-0tsT6sY4.js","names":[],"sources":["../src/keys.ts","../src/highlight.ts","../src/motion.ts"],"sourcesContent":["import { speedAt, type Place } from \"./view.ts\";\n\n/** The angle of one step of an arrow key, in radians, for a camera far from the surface. */\nexport const KEY_TURN: number = Math.PI / 24;\n\n/** The factor of the height of a camera above the surface for one step of the key `+`. */\nexport const KEY_ZOOM = 0.85;\n\n/** What a key does on a stage: it moves the camera to a place, or it shows a view. */\nexport type KeyAction = { readonly type: \"place\"; readonly place: Place } | { readonly type: \"view\"; readonly view: string };\n\n/** The keys of a stage. */\nexport interface KeyOptions {\n /** The name of the view of the keys `Home` and `0`. */\n readonly home: string;\n /** The name of the view of each other key, for example `{ t: \"top\" }`. A letter has no case. */\n readonly views?: Readonly<Record<string, string>> | undefined;\n /** The radius of the ball around the target that the camera stays out of, or 0 for no ball. */\n readonly surface?: number | undefined;\n}\n\n/**\n * This function gives the action of a key on a stage, or `undefined` for a key with no action.\n *\n * The arrow keys turn the camera around the target. The keys `+` and `-` change the height above the surface.\n * The keys `Home` and `0` show the home view. Near the surface, a step of an arrow key is smaller.\n * The result has no limits: the stage puts the place in its limits.\n */\nexport function keyAction(key: string, now: Place, options: KeyOptions): KeyAction | undefined {\n const surface = options.surface ?? 0;\n const turn = KEY_TURN * speedAt(now.distance, surface);\n const zoom = (factor: number): Place => ({ ...now, distance: surface + (now.distance - surface) * factor });\n switch (key) {\n case \"ArrowLeft\":\n return { type: \"place\", place: { ...now, azimuth: now.azimuth - turn } };\n case \"ArrowRight\":\n return { type: \"place\", place: { ...now, azimuth: now.azimuth + turn } };\n case \"ArrowUp\":\n return { type: \"place\", place: { ...now, polar: now.polar - turn } };\n case \"ArrowDown\":\n return { type: \"place\", place: { ...now, polar: now.polar + turn } };\n case \"+\":\n case \"=\":\n return { type: \"place\", place: zoom(KEY_ZOOM) };\n case \"-\":\n case \"_\":\n return { type: \"place\", place: zoom(1 / KEY_ZOOM) };\n case \"Home\":\n case \"0\":\n return { type: \"view\", view: options.home };\n default: {\n const view = key.length === 1 ? options.views?.[key.toLowerCase()] : undefined;\n return view === undefined ? undefined : { type: \"view\", view };\n }\n }\n}\n","/** The highlight of a record. 0 is no highlight. 1 is a record under the pointer or in the highlighted list. 2 is the selected record. */\nexport type Highlight = 0 | 1 | 2;\n\n/** The records of a stage that have a highlight. Each record has a name. */\nexport interface Highlights {\n /** The name of the record under the pointer. */\n readonly hovered: string | undefined;\n /** The name of the selected record. */\n readonly selected: string | undefined;\n /** The names of the records that the page highlights. */\n readonly highlighted: ReadonlySet<string>;\n}\n\n/** The highlights of a stage with no pointer on it and no selected record. */\nexport const NO_HIGHLIGHTS: Highlights = { hovered: undefined, selected: undefined, highlighted: new Set() };\n\n/** This function gives the highlight of a record. The selected record has the highest highlight. */\nexport function highlightOf(highlights: Highlights, record: string): Highlight {\n if (record === highlights.selected) return 2;\n return record === highlights.hovered || highlights.highlighted.has(record) ? 1 : 0;\n}\n\n/** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */\nexport const CLICK_DISTANCE = 4;\n\n/**\n * This function tells if a pointer that went down and up made a click. A pointer that moved more than `limit` made a drag.\n * The positions and the limit are in CSS pixels.\n */\nexport function isClick(down: { readonly x: number; readonly y: number }, up: { readonly x: number; readonly y: number }, limit: number = CLICK_DISTANCE): boolean {\n return Math.hypot(up.x - down.x, up.y - down.y) <= limit;\n}\n","import { placeBetween, type Place } from \"./view.ts\";\n\n/** A move of a camera from one place to a different place. */\nexport interface Move {\n readonly from: Place;\n readonly to: Place;\n /** The time of the start of the move, in milliseconds. */\n readonly start: number;\n /** The time that the move takes, in milliseconds. */\n readonly duration: number;\n}\n\n/** The place of a camera at one time of a move. */\nexport interface MoveStep {\n readonly place: Place;\n /** This value is true at the end of the move, and after it. */\n readonly done: boolean;\n}\n\n/**\n * This function gives a part of a move with a slow start and a slow end. `part` goes from 0 to 1.\n * The result goes from 0 to 1, and it is 0.5 at the middle.\n */\nexport function easeInOut(part: number): number {\n const clamped = Math.min(Math.max(part, 0), 1);\n return clamped < 0.5 ? 4 * clamped * clamped * clamped : 1 - (-2 * clamped + 2) ** 3 / 2;\n}\n\n/**\n * This function gives the place of a camera at the time `now` of a move, in milliseconds.\n * A move with no duration is at its end immediately. `surface` is the radius of the ball around the target, or 0 for no ball.\n */\nexport function moveAt(move: Move, now: number, surface: number = 0): MoveStep {\n const part = move.duration > 0 ? Math.min(Math.max((now - move.start) / move.duration, 0), 1) : 1;\n if (part >= 1) return { place: move.to, done: true };\n return { place: placeBetween(move.from, move.to, easeInOut(part), surface), done: false };\n}\n\n/**\n * This function moves a value one step to its goal. Each step goes a constant part of the way that remains.\n *\n * `seconds` is the time of the step, and `time` is the time in which the value goes most of the way, in seconds.\n * A step with no time gives the goal. A value nearer to the goal than `snap` becomes the goal, so the steps have an end.\n */\nexport function approach(value: number, goal: number, seconds: number, time: number, snap: number = 0.01): number {\n if (!(seconds > 0) || !(time > 0)) return goal;\n const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));\n return Math.abs(goal - next) < snap ? goal : next;\n}\n"],"mappings":";;;AAGA,MAAa,WAAmB,KAAK,KAAK;;AAG1C,MAAa,WAAW;;;;;;;;AAsBxB,SAAgB,UAAU,KAAa,KAAY,SAA4C;CAC7F,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,WAAW,QAAQ,IAAI,UAAU,OAAO;CACrD,MAAM,QAAQ,YAA2B;EAAE,GAAG;EAAK,UAAU,WAAW,IAAI,WAAW,WAAW;CAAO;CACzG,QAAQ,KAAR;EACE,KAAK,aACH,OAAO;GAAE,MAAM;GAAS,OAAO;IAAE,GAAG;IAAK,SAAS,IA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AM,IAAI,UAAU,UAAU,UAAU,KAAK,KAAK,UAAU,MAAM,IAAI;AACzF;;;;;AAMA,SAAgB,OAAO,MAAY,KAAa,UAAkB,GAAa;CAC7E,MAAM,OAAO,KAAK,WAAW,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC,GAAG,CAAC,IAAI;CAChG,IAAI,QAAQ,GAAG,OAAO;EAAE,OAAO,KAAK;EAAI,MAAM;CAAK;CACnD,OAAO;EAAE,OAAO,aAAa,KAAK,MAAM,KAAK,IAAI,UAAU,IAAI,GAAG,OAAO;EAAG,MAAM;CAAM;AAC1F;;;;;;;AAQA,SAAgB,SAAS,OAAe,MAAc,SAAiB,MAAc,OAAe,KAAc;CAChH,IAAI,EAAE,UAAU,MAAM,EAAE,OAAO,IAAI,OAAO;CAC1C,MAAM,OAAO,SAAS,OAAO,UAAU,IAAI,KAAK,IAAI,IAAI,UAAU,IAAI;CACtE,OAAO,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO,OAAO;AAC/C"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * A range of time, with its two ends. Each time of this file is a number in one unit that the page chooses, for example milliseconds.
3
+ * A range is also a lifetime that has an end.
4
+ */
5
+ interface TimeSpan {
6
+ readonly from: number;
7
+ /** The end of the range. It is not before `from`. */
8
+ readonly to: number;
9
+ }
10
+ /** The time in which a part of a content is in the picture. */
11
+ interface Lifetime {
12
+ /** The first time of the part. */
13
+ readonly from: number;
14
+ /** The first time after the part. A part with no `to` has no end. */
15
+ readonly to?: number | undefined;
16
+ }
17
+ /** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */
18
+ declare function isLive(life: Lifetime, at: number): boolean;
19
+ /**
20
+ * This function gives the times at which a picture changes: each start and each end of a lifetime.
21
+ * The result has each time once, from the first time to the last time. A time that is not finite is not in the result.
22
+ */
23
+ declare function changeTimes(lives: Iterable<Lifetime>): readonly number[];
24
+ /** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */
25
+ declare function spanOfTimes(times: readonly number[]): TimeSpan | undefined;
26
+ /** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */
27
+ declare function changeAfter(times: readonly number[], at: number): number | undefined;
28
+ /** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */
29
+ declare function changeBefore(times: readonly number[], at: number): number | undefined;
30
+ /**
31
+ * This function gives the count of the times of a sorted list that are not after `at`.
32
+ * The picture of two times with the same count is the same picture, so a page draws again only after a new count.
33
+ */
34
+ declare function changeIndex(times: readonly number[], at: number): number;
35
+ /** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */
36
+ declare function spanPart(span: TimeSpan, at: number): number;
37
+ /** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */
38
+ declare function spanTime(span: TimeSpan, part: number): number;
39
+ /** The state of a replay: a control shows the picture of one time of a range, and it can go through the range. */
40
+ interface Replay {
41
+ readonly span: TimeSpan;
42
+ /** The time of the picture. It is in the range. */
43
+ readonly at: number;
44
+ /** This value is true while the time goes forward. */
45
+ readonly playing: boolean;
46
+ /** The speed, as a factor. A replay with the speed 1 goes through the range in the duration that `replayAdvance` gets. */
47
+ readonly speed: number;
48
+ }
49
+ /** The time in which a replay with the speed 1 goes through its range, in milliseconds. */
50
+ declare const REPLAY_DURATION = 2e4;
51
+ /** The speeds of a replay that a control offers, from the slowest to the fastest. */
52
+ declare const REPLAY_SPEEDS: readonly number[];
53
+ /** The part of a range that the keys `PageUp` and `PageDown` go. */
54
+ declare const REPLAY_PAGE = .1;
55
+ /** The part of a range that an arrow key goes when the replay has no times of change. */
56
+ declare const REPLAY_STEP = .01;
57
+ /**
58
+ * This function gives a replay that does not go. With no time, the picture is at the end of the range.
59
+ * The end of a range is the present for a content that shows live data.
60
+ */
61
+ declare function replayOf(span: TimeSpan, at?: number): Replay;
62
+ /** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */
63
+ declare function replaySeek(replay: Replay, at: number): Replay;
64
+ /** This function starts a replay. A replay at the end of its range starts again from the start of the range. */
65
+ declare function replayPlay(replay: Replay): Replay;
66
+ /** This function stops a replay at its time. */
67
+ declare function replayPause(replay: Replay): Replay;
68
+ /** This function starts a replay that does not go, and it stops a replay that goes. */
69
+ declare function replayToggle(replay: Replay): Replay;
70
+ /**
71
+ * This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.
72
+ * The replay stops at the end of its range. A replay that does not go stays the same value.
73
+ */
74
+ declare function replayAdvance(replay: Replay, elapsed: number, duration?: number): Replay;
75
+ /**
76
+ * This function gives a replay with the next speed of a list. After the last speed comes the first speed.
77
+ * A speed that is not in the list gets the first speed that is higher, or the first speed of the list.
78
+ */
79
+ declare function replayNextSpeed(replay: Replay, speeds?: readonly number[]): Replay;
80
+ /**
81
+ * This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.
82
+ * Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.
83
+ */
84
+ declare function replaySpan(replay: Replay, span: TimeSpan): Replay;
85
+ /**
86
+ * This function gives the replay after a key of a slider, or `undefined` for a key with no action.
87
+ *
88
+ * The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.
89
+ * The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.
90
+ * Each of these keys stops a replay that goes, because the person sets the time.
91
+ * The key Space starts a replay that does not go, and it stops a replay that goes.
92
+ */
93
+ declare function replayKey(key: string, replay: Replay, times?: readonly number[]): Replay | undefined;
94
+ export { spanPart as C, spanOfTimes as S, replayPause as _, REPLAY_STEP as a, replaySpan as b, changeAfter as c, changeTimes as d, isLive as f, replayOf as g, replayNextSpeed as h, REPLAY_SPEEDS as i, changeBefore as l, replayKey as m, REPLAY_DURATION as n, Replay as o, replayAdvance as p, REPLAY_PAGE as r, TimeSpan as s, Lifetime as t, changeIndex as u, replayPlay as v, spanTime as w, replayToggle as x, replaySeek as y };
95
+ //# sourceMappingURL=replay-DvGYPe7T.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-DvGYPe7T.d.ts","names":[],"sources":["../src/replay.ts"],"mappings":";;;;UAIiB;WACN;;WAEA;;;UAIM;;WAEN;;WAEA;;;iBAIK,OAAO,MAAM,UAAU;;;;;iBAQvB,YAAY,OAAO,SAAS;;iBAU5B,YAAY,2BAA2B;;iBAOvC,YAAY,0BAA0B;;iBAKtC,aAAa,0BAA0B;;;;;iBAQvC,YAAY,0BAA0B;;iBAKtC,SAAS,MAAM,UAAU;;iBAMzB,SAAS,MAAM,UAAU;;UAKxB;WACN,MAAM;;WAEN;;WAEA;;WAEA;;;cAIE;;cAGA;;cAGA;;cAGA;;;;;iBAMG,SAAS,MAAM,UAAU,cAAuB;;iBAKhD,WAAW,QAAQ,QAAQ,aAAa;;iBAMxC,WAAW,QAAQ,SAAS;;iBAM5B,YAAY,QAAQ,SAAS;;iBAK7B,aAAa,QAAQ,SAAS;;;;;iBAQ9B,cAAc,QAAQ,QAAQ,iBAAiB,oBAAqC;;;;;iBAWpF,gBAAgB,QAAQ,QAAQ,6BAA4C;;;;;iBAS5E,WAAW,QAAQ,QAAQ,MAAM,WAAW;;;;;;;;;iBAc5C,UAAU,aAAa,QAAQ,QAAQ,4BAAgC"}
@@ -0,0 +1,172 @@
1
+ // src/replay.ts
2
+ /** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */
3
+ function isLive(life, at) {
4
+ return life.from <= at && (life.to === void 0 || at < life.to);
5
+ }
6
+ /**
7
+ * This function gives the times at which a picture changes: each start and each end of a lifetime.
8
+ * The result has each time once, from the first time to the last time. A time that is not finite is not in the result.
9
+ */
10
+ function changeTimes(lives) {
11
+ const times = /* @__PURE__ */ new Set();
12
+ for (const life of lives) {
13
+ if (Number.isFinite(life.from)) times.add(life.from);
14
+ if (life.to !== void 0 && Number.isFinite(life.to)) times.add(life.to);
15
+ }
16
+ return [...times].sort((a, b) => a - b);
17
+ }
18
+ /** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */
19
+ function spanOfTimes(times) {
20
+ const from = times[0];
21
+ const to = times[times.length - 1];
22
+ return from === void 0 || to === void 0 ? void 0 : {
23
+ from,
24
+ to
25
+ };
26
+ }
27
+ /** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */
28
+ function changeAfter(times, at) {
29
+ return times.find((time) => time > at);
30
+ }
31
+ /** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */
32
+ function changeBefore(times, at) {
33
+ return times.findLast((time) => time < at);
34
+ }
35
+ /**
36
+ * This function gives the count of the times of a sorted list that are not after `at`.
37
+ * The picture of two times with the same count is the same picture, so a page draws again only after a new count.
38
+ */
39
+ function changeIndex(times, at) {
40
+ return times.findLastIndex((time) => time <= at) + 1;
41
+ }
42
+ /** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */
43
+ function spanPart(span, at) {
44
+ const length = span.to - span.from;
45
+ return length > 0 ? Math.min(Math.max((at - span.from) / length, 0), 1) : 0;
46
+ }
47
+ /** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */
48
+ function spanTime(span, part) {
49
+ return span.from + (span.to - span.from) * Math.min(Math.max(part, 0), 1);
50
+ }
51
+ /** The time in which a replay with the speed 1 goes through its range, in milliseconds. */
52
+ const REPLAY_DURATION = 2e4;
53
+ /** The speeds of a replay that a control offers, from the slowest to the fastest. */
54
+ const REPLAY_SPEEDS = [
55
+ .5,
56
+ 1,
57
+ 2,
58
+ 4
59
+ ];
60
+ /** The part of a range that the keys `PageUp` and `PageDown` go. */
61
+ const REPLAY_PAGE = .1;
62
+ /** The part of a range that an arrow key goes when the replay has no times of change. */
63
+ const REPLAY_STEP = .01;
64
+ /**
65
+ * This function gives a replay that does not go. With no time, the picture is at the end of the range.
66
+ * The end of a range is the present for a content that shows live data.
67
+ */
68
+ function replayOf(span, at = span.to) {
69
+ return {
70
+ span,
71
+ at: Math.min(Math.max(at, span.from), span.to),
72
+ playing: false,
73
+ speed: 1
74
+ };
75
+ }
76
+ /** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */
77
+ function replaySeek(replay, at) {
78
+ const next = Math.min(Math.max(at, replay.span.from), replay.span.to);
79
+ return next === replay.at ? replay : {
80
+ ...replay,
81
+ at: next
82
+ };
83
+ }
84
+ /** This function starts a replay. A replay at the end of its range starts again from the start of the range. */
85
+ function replayPlay(replay) {
86
+ if (replay.playing || !(replay.span.to > replay.span.from)) return replay;
87
+ return {
88
+ ...replay,
89
+ at: replay.at >= replay.span.to ? replay.span.from : replay.at,
90
+ playing: true
91
+ };
92
+ }
93
+ /** This function stops a replay at its time. */
94
+ function replayPause(replay) {
95
+ return replay.playing ? {
96
+ ...replay,
97
+ playing: false
98
+ } : replay;
99
+ }
100
+ /** This function starts a replay that does not go, and it stops a replay that goes. */
101
+ function replayToggle(replay) {
102
+ return replay.playing ? replayPause(replay) : replayPlay(replay);
103
+ }
104
+ /**
105
+ * This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.
106
+ * The replay stops at the end of its range. A replay that does not go stays the same value.
107
+ */
108
+ function replayAdvance(replay, elapsed, duration = REPLAY_DURATION) {
109
+ if (!replay.playing || !(elapsed > 0)) return replay;
110
+ const length = replay.span.to - replay.span.from;
111
+ const next = duration > 0 ? replay.at + elapsed / duration * length * replay.speed : replay.span.to;
112
+ return next >= replay.span.to ? {
113
+ ...replay,
114
+ at: replay.span.to,
115
+ playing: false
116
+ } : {
117
+ ...replay,
118
+ at: next
119
+ };
120
+ }
121
+ /**
122
+ * This function gives a replay with the next speed of a list. After the last speed comes the first speed.
123
+ * A speed that is not in the list gets the first speed that is higher, or the first speed of the list.
124
+ */
125
+ function replayNextSpeed(replay, speeds = REPLAY_SPEEDS) {
126
+ const next = speeds.find((speed) => speed > replay.speed) ?? speeds[0];
127
+ return next === void 0 || next === replay.speed ? replay : {
128
+ ...replay,
129
+ speed: next
130
+ };
131
+ }
132
+ /**
133
+ * This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.
134
+ * Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.
135
+ */
136
+ function replaySpan(replay, span) {
137
+ const at = replay.at >= replay.span.to ? span.to : Math.min(Math.max(replay.at, span.from), span.to);
138
+ return {
139
+ ...replay,
140
+ span,
141
+ at,
142
+ playing: replay.playing && span.to > span.from
143
+ };
144
+ }
145
+ /**
146
+ * This function gives the replay after a key of a slider, or `undefined` for a key with no action.
147
+ *
148
+ * The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.
149
+ * The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.
150
+ * Each of these keys stops a replay that goes, because the person sets the time.
151
+ * The key Space starts a replay that does not go, and it stops a replay that goes.
152
+ */
153
+ function replayKey(key, replay, times = []) {
154
+ const { span } = replay;
155
+ const length = span.to - span.from;
156
+ const to = (at) => replaySeek(replayPause(replay), at);
157
+ switch (key) {
158
+ case "ArrowRight":
159
+ case "ArrowUp": return to(times.length > 0 ? changeAfter(times, replay.at) ?? span.to : replay.at + length * REPLAY_STEP);
160
+ case "ArrowLeft":
161
+ case "ArrowDown": return to(times.length > 0 ? changeBefore(times, replay.at) ?? span.from : replay.at - length * REPLAY_STEP);
162
+ case "PageUp": return to(replay.at + length * REPLAY_PAGE);
163
+ case "PageDown": return to(replay.at - length * REPLAY_PAGE);
164
+ case "Home": return to(span.from);
165
+ case "End": return to(span.to);
166
+ case " ": return replayToggle(replay);
167
+ default: return;
168
+ }
169
+ }
170
+ export { replaySpan as _, changeAfter as a, spanPart as b, changeTimes as c, replayKey as d, replayNextSpeed as f, replaySeek as g, replayPlay as h, REPLAY_STEP as i, isLive as l, replayPause as m, REPLAY_PAGE as n, changeBefore as o, replayOf as p, REPLAY_SPEEDS as r, changeIndex as s, REPLAY_DURATION as t, replayAdvance as u, replayToggle as v, spanTime as x, spanOfTimes as y };
171
+
172
+ //# sourceMappingURL=replay-YdWMyFko.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-YdWMyFko.js","names":[],"sources":["../src/replay.ts"],"sourcesContent":["/**\n * A range of time, with its two ends. Each time of this file is a number in one unit that the page chooses, for example milliseconds.\n * A range is also a lifetime that has an end.\n */\nexport interface TimeSpan {\n readonly from: number;\n /** The end of the range. It is not before `from`. */\n readonly to: number;\n}\n\n/** The time in which a part of a content is in the picture. */\nexport interface Lifetime {\n /** The first time of the part. */\n readonly from: number;\n /** The first time after the part. A part with no `to` has no end. */\n readonly to?: number | undefined;\n}\n\n/** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */\nexport function isLive(life: Lifetime, at: number): boolean {\n return life.from <= at && (life.to === undefined || at < life.to);\n}\n\n/**\n * This function gives the times at which a picture changes: each start and each end of a lifetime.\n * The result has each time once, from the first time to the last time. A time that is not finite is not in the result.\n */\nexport function changeTimes(lives: Iterable<Lifetime>): readonly number[] {\n const times = new Set<number>();\n for (const life of lives) {\n if (Number.isFinite(life.from)) times.add(life.from);\n if (life.to !== undefined && Number.isFinite(life.to)) times.add(life.to);\n }\n return [...times].sort((a, b) => a - b);\n}\n\n/** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */\nexport function spanOfTimes(times: readonly number[]): TimeSpan | undefined {\n const from = times[0];\n const to = times[times.length - 1];\n return from === undefined || to === undefined ? undefined : { from, to };\n}\n\n/** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */\nexport function changeAfter(times: readonly number[], at: number): number | undefined {\n return times.find((time) => time > at);\n}\n\n/** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */\nexport function changeBefore(times: readonly number[], at: number): number | undefined {\n return times.findLast((time) => time < at);\n}\n\n/**\n * This function gives the count of the times of a sorted list that are not after `at`.\n * The picture of two times with the same count is the same picture, so a page draws again only after a new count.\n */\nexport function changeIndex(times: readonly number[], at: number): number {\n return times.findLastIndex((time) => time <= at) + 1;\n}\n\n/** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */\nexport function spanPart(span: TimeSpan, at: number): number {\n const length = span.to - span.from;\n return length > 0 ? Math.min(Math.max((at - span.from) / length, 0), 1) : 0;\n}\n\n/** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */\nexport function spanTime(span: TimeSpan, part: number): number {\n return span.from + (span.to - span.from) * Math.min(Math.max(part, 0), 1);\n}\n\n/** The state of a replay: a control shows the picture of one time of a range, and it can go through the range. */\nexport interface Replay {\n readonly span: TimeSpan;\n /** The time of the picture. It is in the range. */\n readonly at: number;\n /** This value is true while the time goes forward. */\n readonly playing: boolean;\n /** The speed, as a factor. A replay with the speed 1 goes through the range in the duration that `replayAdvance` gets. */\n readonly speed: number;\n}\n\n/** The time in which a replay with the speed 1 goes through its range, in milliseconds. */\nexport const REPLAY_DURATION = 20_000;\n\n/** The speeds of a replay that a control offers, from the slowest to the fastest. */\nexport const REPLAY_SPEEDS: readonly number[] = [0.5, 1, 2, 4];\n\n/** The part of a range that the keys `PageUp` and `PageDown` go. */\nexport const REPLAY_PAGE = 0.1;\n\n/** The part of a range that an arrow key goes when the replay has no times of change. */\nexport const REPLAY_STEP = 0.01;\n\n/**\n * This function gives a replay that does not go. With no time, the picture is at the end of the range.\n * The end of a range is the present for a content that shows live data.\n */\nexport function replayOf(span: TimeSpan, at: number = span.to): Replay {\n return { span, at: Math.min(Math.max(at, span.from), span.to), playing: false, speed: 1 };\n}\n\n/** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */\nexport function replaySeek(replay: Replay, at: number): Replay {\n const next = Math.min(Math.max(at, replay.span.from), replay.span.to);\n return next === replay.at ? replay : { ...replay, at: next };\n}\n\n/** This function starts a replay. A replay at the end of its range starts again from the start of the range. */\nexport function replayPlay(replay: Replay): Replay {\n if (replay.playing || !(replay.span.to > replay.span.from)) return replay;\n return { ...replay, at: replay.at >= replay.span.to ? replay.span.from : replay.at, playing: true };\n}\n\n/** This function stops a replay at its time. */\nexport function replayPause(replay: Replay): Replay {\n return replay.playing ? { ...replay, playing: false } : replay;\n}\n\n/** This function starts a replay that does not go, and it stops a replay that goes. */\nexport function replayToggle(replay: Replay): Replay {\n return replay.playing ? replayPause(replay) : replayPlay(replay);\n}\n\n/**\n * This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.\n * The replay stops at the end of its range. A replay that does not go stays the same value.\n */\nexport function replayAdvance(replay: Replay, elapsed: number, duration: number = REPLAY_DURATION): Replay {\n if (!replay.playing || !(elapsed > 0)) return replay;\n const length = replay.span.to - replay.span.from;\n const next = duration > 0 ? replay.at + (elapsed / duration) * length * replay.speed : replay.span.to;\n return next >= replay.span.to ? { ...replay, at: replay.span.to, playing: false } : { ...replay, at: next };\n}\n\n/**\n * This function gives a replay with the next speed of a list. After the last speed comes the first speed.\n * A speed that is not in the list gets the first speed that is higher, or the first speed of the list.\n */\nexport function replayNextSpeed(replay: Replay, speeds: readonly number[] = REPLAY_SPEEDS): Replay {\n const next = speeds.find((speed) => speed > replay.speed) ?? speeds[0];\n return next === undefined || next === replay.speed ? replay : { ...replay, speed: next };\n}\n\n/**\n * This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.\n * Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.\n */\nexport function replaySpan(replay: Replay, span: TimeSpan): Replay {\n const atEnd = replay.at >= replay.span.to;\n const at = atEnd ? span.to : Math.min(Math.max(replay.at, span.from), span.to);\n return { ...replay, span, at, playing: replay.playing && span.to > span.from };\n}\n\n/**\n * This function gives the replay after a key of a slider, or `undefined` for a key with no action.\n *\n * The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.\n * The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.\n * Each of these keys stops a replay that goes, because the person sets the time.\n * The key Space starts a replay that does not go, and it stops a replay that goes.\n */\nexport function replayKey(key: string, replay: Replay, times: readonly number[] = []): Replay | undefined {\n const { span } = replay;\n const length = span.to - span.from;\n const to = (at: number): Replay => replaySeek(replayPause(replay), at);\n switch (key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n return to(times.length > 0 ? (changeAfter(times, replay.at) ?? span.to) : replay.at + length * REPLAY_STEP);\n case \"ArrowLeft\":\n case \"ArrowDown\":\n return to(times.length > 0 ? (changeBefore(times, replay.at) ?? span.from) : replay.at - length * REPLAY_STEP);\n case \"PageUp\":\n return to(replay.at + length * REPLAY_PAGE);\n case \"PageDown\":\n return to(replay.at - length * REPLAY_PAGE);\n case \"Home\":\n return to(span.from);\n case \"End\":\n return to(span.to);\n case \" \":\n return replayToggle(replay);\n default:\n return undefined;\n }\n}\n"],"mappings":";;AAmBA,SAAgB,OAAO,MAAgB,IAAqB;CAC1D,OAAO,KAAK,QAAQ,OAAO,KAAK,OAAO,KAAA,KAAa,KAAK,KAAK;AAChE;;;;;AAMA,SAAgB,YAAY,OAA8C;CACxE,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,OAAO,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,KAAK,IAAI;EACnD,IAAI,KAAK,OAAO,KAAA,KAAa,OAAO,SAAS,KAAK,EAAE,GAAG,MAAM,IAAI,KAAK,EAAE;CAC1E;CACA,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;AACxC;;AAGA,SAAgB,YAAY,OAAgD;CAC1E,MAAM,OAAO,MAAM;CACnB,MAAM,KAAK,MAAM,MAAM,SAAS;CAChC,OAAO,SAAS,KAAA,KAAa,OAAO,KAAA,IAAY,KAAA,IAAY;EAAE;EAAM;CAAG;AACzE;;AAGA,SAAgB,YAAY,OAA0B,IAAgC;CACpF,OAAO,MAAM,MAAM,SAAS,OAAO,EAAE;AACvC;;AAGA,SA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