@mark1russell7/visuals 0.1.0 → 0.2.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 +154 -6
- package/build/{motion-Ba4IIfAV.js → extent-CALhBZU-.js} +86 -132
- package/build/extent-CALhBZU-.js.map +1 -0
- package/build/globe.d.ts +192 -0
- package/build/globe.d.ts.map +1 -0
- package/build/globe.js +1046 -0
- package/build/globe.js.map +1 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +3 -1
- package/build/marks.d.ts +192 -0
- package/build/marks.d.ts.map +1 -0
- package/build/marks.js +231 -0
- package/build/marks.js.map +1 -0
- package/build/motion-0tsT6sY4.js +132 -0
- package/build/motion-0tsT6sY4.js.map +1 -0
- package/build/stage-CtWLSoV-.d.ts +126 -0
- package/build/stage-CtWLSoV-.d.ts.map +1 -0
- package/build/{theme-eOmfx75p.d.ts → theme-CKXd_emk.d.ts} +28 -12
- package/build/theme-CKXd_emk.d.ts.map +1 -0
- package/build/three.d.ts +2 -126
- package/build/three.js +34 -21
- package/build/three.js.map +1 -1
- package/package.json +15 -3
- package/build/motion-Ba4IIfAV.js.map +0 -1
- package/build/theme-eOmfx75p.d.ts.map +0 -1
- package/build/three.d.ts.map +0 -1
|
@@ -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,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAO,QAAQ,KAAK;AAC7B;;AAGA,MAAa,eAAgE;CAAC;CAAQ;CAAQ;CAAY;AAAQ;;;;;AASlH,SAAgB,WAAW,OAAsC;CAC/D,OAAO,UAAU,OAAO,SAAS,UAAU,SAAS,aAAa,UAAU,SAAS,WAAW;AACjG;;;;;AAkBA,MAAa,iBAA6D;CACxE,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAK;CACnD,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAE;CAChD,UAAU;EAAE,QAAQ;EAAK,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;CAC/D,QAAQ;EAAE,QAAQ;EAAM,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;AAChE;;;;;AAMA,SAAgB,UAAU,OAAmB,SAAiB,GAAS;CACrE,MAAM,UAAU,eAAe;CAC/B,OAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,MAAM,IAAI,GAAG,UAAqC;EACpF,MAAM,QAAQ,QAAQ,QAAS,QAAQ,IAAI,KAAK,KAAM,QAAQ;EAC9D,OAAO,CAAC,SAAS,QAAQ,SAAS,KAAK,IAAI,KAAK,GAAG,SAAS,QAAQ,SAAS,KAAK,IAAI,KAAK,CAAC;CAC9F,CAAC;AACH;;;;;;;;;;;;;;;;;AC/CA,MAAa,mBAA2I;CACtJ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAsBA,MAAa,sBAAsB;;;;;;;AAQnC,SAA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AuGxH,SAAgB,aAAa,OAA0B;CACrD,OAAO,OAAO,MAAM,MAAM,KAAK,MAAM,MAAM;AAC7C;;AAGA,SAAgB,gBAAgB,OAAkB,QAAgB,KAAqB;CACrF,MAAM,SAAS,YAAY,MAAM,SAAS,SAAS,MAAO,MAAM,IAAI;CACpE,MAAM,OAAO,YAAY,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"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { m as speedAt, p as placeBetween } from "./extent-CALhBZU-.js";
|
|
2
|
+
// src/keys.ts
|
|
3
|
+
/** The angle of one step of an arrow key, in radians, for a camera far from the surface. */
|
|
4
|
+
const KEY_TURN = Math.PI / 24;
|
|
5
|
+
/** The factor of the height of a camera above the surface for one step of the key `+`. */
|
|
6
|
+
const KEY_ZOOM = .85;
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the action of a key on a stage, or `undefined` for a key with no action.
|
|
9
|
+
*
|
|
10
|
+
* The arrow keys turn the camera around the target. The keys `+` and `-` change the height above the surface.
|
|
11
|
+
* The keys `Home` and `0` show the home view. Near the surface, a step of an arrow key is smaller.
|
|
12
|
+
* The result has no limits: the stage puts the place in its limits.
|
|
13
|
+
*/
|
|
14
|
+
function keyAction(key, now, options) {
|
|
15
|
+
const surface = options.surface ?? 0;
|
|
16
|
+
const turn = KEY_TURN * speedAt(now.distance, surface);
|
|
17
|
+
const zoom = (factor) => ({
|
|
18
|
+
...now,
|
|
19
|
+
distance: surface + (now.distance - surface) * factor
|
|
20
|
+
});
|
|
21
|
+
switch (key) {
|
|
22
|
+
case "ArrowLeft": return {
|
|
23
|
+
type: "place",
|
|
24
|
+
place: {
|
|
25
|
+
...now,
|
|
26
|
+
azimuth: now.azimuth - turn
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
case "ArrowRight": return {
|
|
30
|
+
type: "place",
|
|
31
|
+
place: {
|
|
32
|
+
...now,
|
|
33
|
+
azimuth: now.azimuth + turn
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
case "ArrowUp": return {
|
|
37
|
+
type: "place",
|
|
38
|
+
place: {
|
|
39
|
+
...now,
|
|
40
|
+
polar: now.polar - turn
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
case "ArrowDown": return {
|
|
44
|
+
type: "place",
|
|
45
|
+
place: {
|
|
46
|
+
...now,
|
|
47
|
+
polar: now.polar + turn
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
case "+":
|
|
51
|
+
case "=": return {
|
|
52
|
+
type: "place",
|
|
53
|
+
place: zoom(KEY_ZOOM)
|
|
54
|
+
};
|
|
55
|
+
case "-":
|
|
56
|
+
case "_": return {
|
|
57
|
+
type: "place",
|
|
58
|
+
place: zoom(1 / KEY_ZOOM)
|
|
59
|
+
};
|
|
60
|
+
case "Home":
|
|
61
|
+
case "0": return {
|
|
62
|
+
type: "view",
|
|
63
|
+
view: options.home
|
|
64
|
+
};
|
|
65
|
+
default: {
|
|
66
|
+
const view = key.length === 1 ? options.views?.[key.toLowerCase()] : void 0;
|
|
67
|
+
return view === void 0 ? void 0 : {
|
|
68
|
+
type: "view",
|
|
69
|
+
view
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// src/highlight.ts
|
|
75
|
+
/** The highlights of a stage with no pointer on it and no selected record. */
|
|
76
|
+
const NO_HIGHLIGHTS = {
|
|
77
|
+
hovered: void 0,
|
|
78
|
+
selected: void 0,
|
|
79
|
+
highlighted: /* @__PURE__ */ new Set()
|
|
80
|
+
};
|
|
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
|
+
}
|
|
86
|
+
/** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */
|
|
87
|
+
const CLICK_DISTANCE = 4;
|
|
88
|
+
/**
|
|
89
|
+
* This function tells if a pointer that went down and up made a click. A pointer that moved more than `limit` made a drag.
|
|
90
|
+
* The positions and the limit are in CSS pixels.
|
|
91
|
+
*/
|
|
92
|
+
function isClick(down, up, limit = 4) {
|
|
93
|
+
return Math.hypot(up.x - down.x, up.y - down.y) <= limit;
|
|
94
|
+
}
|
|
95
|
+
// src/motion.ts
|
|
96
|
+
/**
|
|
97
|
+
* This function gives a part of a move with a slow start and a slow end. `part` goes from 0 to 1.
|
|
98
|
+
* The result goes from 0 to 1, and it is 0.5 at the middle.
|
|
99
|
+
*/
|
|
100
|
+
function easeInOut(part) {
|
|
101
|
+
const clamped = Math.min(Math.max(part, 0), 1);
|
|
102
|
+
return clamped < .5 ? 4 * clamped * clamped * clamped : 1 - (-2 * clamped + 2) ** 3 / 2;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* This function gives the place of a camera at the time `now` of a move, in milliseconds.
|
|
106
|
+
* 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.
|
|
107
|
+
*/
|
|
108
|
+
function moveAt(move, now, surface = 0) {
|
|
109
|
+
const part = move.duration > 0 ? Math.min(Math.max((now - move.start) / move.duration, 0), 1) : 1;
|
|
110
|
+
if (part >= 1) return {
|
|
111
|
+
place: move.to,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
place: placeBetween(move.from, move.to, easeInOut(part), surface),
|
|
116
|
+
done: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* This function moves a value one step to its goal. Each step goes a constant part of the way that remains.
|
|
121
|
+
*
|
|
122
|
+
* `seconds` is the time of the step, and `time` is the time in which the value goes most of the way, in seconds.
|
|
123
|
+
* 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.
|
|
124
|
+
*/
|
|
125
|
+
function approach(value, goal, seconds, time, snap = .01) {
|
|
126
|
+
if (!(seconds > 0) || !(time > 0)) return goal;
|
|
127
|
+
const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));
|
|
128
|
+
return Math.abs(goal - next) < snap ? goal : next;
|
|
129
|
+
}
|
|
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
|
+
|
|
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;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raycaster } from "three";
|
|
3
|
+
/** The record under the pointer: its name, and the value that the content gives for it. */
|
|
4
|
+
interface StagePick<P> {
|
|
5
|
+
/** The name of the record. The highlights of the stage use this name. */
|
|
6
|
+
readonly record: string;
|
|
7
|
+
/** The value of the record for the page, for example its kind and its source. */
|
|
8
|
+
readonly value: P;
|
|
9
|
+
}
|
|
10
|
+
/** One picture of a stage, for the step of its content. */
|
|
11
|
+
interface StageFrame {
|
|
12
|
+
readonly camera: PerspectiveCamera;
|
|
13
|
+
/** The time since the last picture, in seconds. */
|
|
14
|
+
readonly seconds: number;
|
|
15
|
+
/**
|
|
16
|
+
* This value is true for the first picture of a content, and for a person who asks for less motion.
|
|
17
|
+
* Each change then has no time: the content sets each value to its goal immediately.
|
|
18
|
+
*/
|
|
19
|
+
readonly settle: boolean;
|
|
20
|
+
/** The height of the picture, in CSS pixels. */
|
|
21
|
+
readonly height: number;
|
|
22
|
+
/** The vertical angle of the picture, in degrees. */
|
|
23
|
+
readonly fieldOfView: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The content of a stage: the three.js objects of one scene, and what the stage asks of them.
|
|
27
|
+
* `P` is the type of the value of a pick, and `T` is the type of the theme.
|
|
28
|
+
*/
|
|
29
|
+
interface StageContent<P, T extends StageTheme = StageTheme> {
|
|
30
|
+
/** The three.js objects of the content. The stage adds them to its world, and removes them. */
|
|
31
|
+
readonly objects: readonly Object3D[];
|
|
32
|
+
/** The space that the content fills. */
|
|
33
|
+
readonly extent: StageExtent;
|
|
34
|
+
/** This function tells if the content has a record with a name. */
|
|
35
|
+
has(record: string): boolean;
|
|
36
|
+
/** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */
|
|
37
|
+
pick(ray: Raycaster): StagePick<P> | undefined;
|
|
38
|
+
/** This function gives each part its colors, from the theme and the highlight of its record. */
|
|
39
|
+
paint(theme: T, highlight: (record: string) => Highlight): void;
|
|
40
|
+
/**
|
|
41
|
+
* This function changes the parts that depend on the camera or on the time, before each picture.
|
|
42
|
+
* It gives true while a part continues to change. The stage then makes the next picture.
|
|
43
|
+
*/
|
|
44
|
+
step?(frame: StageFrame): boolean;
|
|
45
|
+
/** This function releases the memory of the graphics card that the content uses. */
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
/** The lights of a stage. A content with materials that use no light ignores them. */
|
|
49
|
+
interface StageLights {
|
|
50
|
+
/** The strength of the light from above and below. */
|
|
51
|
+
readonly sky: number;
|
|
52
|
+
/** The strength of the light from one direction. */
|
|
53
|
+
readonly sun: number;
|
|
54
|
+
/** The position that the light from one direction comes from. */
|
|
55
|
+
readonly from: {
|
|
56
|
+
readonly x: number;
|
|
57
|
+
readonly y: number;
|
|
58
|
+
readonly z: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The options of a stage. */
|
|
62
|
+
interface StageOptions<P, T extends StageTheme = StageTheme> {
|
|
63
|
+
/** The first content. The stage disposes each content that it gets. */
|
|
64
|
+
readonly content: StageContent<P, T>;
|
|
65
|
+
readonly theme: T;
|
|
66
|
+
/** The name of the picture for a screen reader. */
|
|
67
|
+
readonly label: string;
|
|
68
|
+
/** The views of the stage, each with a name. */
|
|
69
|
+
readonly views: Readonly<Record<string, StageView>>;
|
|
70
|
+
/** The name of the first view. The keys `Home` and `0` show it. */
|
|
71
|
+
readonly home: string;
|
|
72
|
+
/** The name of the view of a key, for example `{ t: "top" }`. A letter has no case. */
|
|
73
|
+
readonly keys?: Readonly<Record<string, string>> | undefined;
|
|
74
|
+
/** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. The default is 32. */
|
|
75
|
+
readonly fieldOfView?: number | undefined;
|
|
76
|
+
/** The smallest and the largest polar angle of the camera, in radians. The default keeps the camera above the plane of the target. */
|
|
77
|
+
readonly polar?: {
|
|
78
|
+
readonly min?: number | undefined;
|
|
79
|
+
readonly max?: number | undefined;
|
|
80
|
+
} | undefined;
|
|
81
|
+
/** This value is true if a person can move the target with a drag of the second button. The default is true. */
|
|
82
|
+
readonly pan?: boolean | undefined;
|
|
83
|
+
readonly lights?: StageLights | undefined;
|
|
84
|
+
/** The stage starts this function when the pointer goes to a different record, or to no record. */
|
|
85
|
+
readonly onHover?: ((pick: P | undefined) => void) | undefined;
|
|
86
|
+
/** The stage starts this function when a person selects a record with the pointer, or selects no record. */
|
|
87
|
+
readonly onSelect?: ((pick: P | undefined) => void) | undefined;
|
|
88
|
+
}
|
|
89
|
+
/** A stage in a page: one canvas with a camera that a person moves, and one content. */
|
|
90
|
+
interface Stage<P, T extends StageTheme = StageTheme> {
|
|
91
|
+
/** The canvas of the stage. It is in the container. */
|
|
92
|
+
readonly canvas: HTMLCanvasElement;
|
|
93
|
+
/** This function shows a different content, and disposes the old content. The view stays if a person moved it. */
|
|
94
|
+
setContent(content: StageContent<P, T>): void;
|
|
95
|
+
/** This function changes the colors. */
|
|
96
|
+
setTheme(theme: T): void;
|
|
97
|
+
/** This function moves the camera to a view: a name of the options, or a view function. `animate` has the default true. */
|
|
98
|
+
setView(view: string | StageView, animate?: boolean): void;
|
|
99
|
+
/** This function gives the place of the camera. */
|
|
100
|
+
place(): Place;
|
|
101
|
+
/** This function highlights records by their names, as the pointer does. An empty list removes the highlights. */
|
|
102
|
+
highlight(records: readonly string[]): void;
|
|
103
|
+
/** This function selects one record by its name, or no record. It does not start `onSelect`. */
|
|
104
|
+
select(record: string | undefined): void;
|
|
105
|
+
/** This function paints the content again and makes a new picture. Use it after a change of the content. */
|
|
106
|
+
refresh(): void;
|
|
107
|
+
/** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */
|
|
108
|
+
dispose(): void;
|
|
109
|
+
}
|
|
110
|
+
/** The default vertical angle of the picture, in degrees. */
|
|
111
|
+
declare const FIELD_OF_VIEW = 32;
|
|
112
|
+
/** The default lights: a strong light from above and below, and a light from the front left. */
|
|
113
|
+
declare const STAGE_LIGHTS: StageLights;
|
|
114
|
+
/**
|
|
115
|
+
* This function makes a stage in a container of a page. The stage fills the container, so give the container a size.
|
|
116
|
+
*
|
|
117
|
+
* A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.
|
|
118
|
+
* A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,
|
|
119
|
+
* and `Home` shows the first view. The stage makes a picture only after a change.
|
|
120
|
+
*
|
|
121
|
+
* The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.
|
|
122
|
+
* The page then shows a different picture of the same data.
|
|
123
|
+
*/
|
|
124
|
+
declare function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined;
|
|
125
|
+
export { StageFrame as a, StagePick as c, StageContent as i, createStage as l, STAGE_LIGHTS as n, StageLights as o, Stage as r, StageOptions as s, FIELD_OF_VIEW as t };
|
|
126
|
+
//# sourceMappingURL=stage-CtWLSoV-.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-CtWLSoV-.d.ts","names":[],"sources":["../src/stage/stage.ts"],"mappings":";;;UAUiB,UAAU;;WAEhB;;WAEA,OAAO;;;UAID;WACN,QAAQ;;WAER;;;;;WAKA;;WAEA;;WAEA;;;;;;UAOM,aAAa,GAAG,UAAU,aAAa;;WAE7C,kBAAkB;;WAElB,QAAQ;;EAEjB,IAAI;;EAEJ,KAAK,KAAK,YAAY,UAAU;;EAEhC,MAAM,OAAO,GAAG,YAAY,mBAAmB;;;;;EAK/C,MAAM,OAAO;;EAEb;;;UAIe;;WAEN;;WAEA;;WAEA;aAAiB;aAAoB;aAAoB;;;;UAInD,aAAa,GAAG,UAAU,aAAa;;WAE7C,SAAS,aAAa,GAAG;WACzB,OAAO;;WAEP;;WAEA,OAAO,SAAS,eAAe;;WAE/B;;WAEA,OAAO,SAAS;;WAEhB;;WAEA;aAAmB;aAAmC;;;WAEtD;WACA,SAAS;;WAET,YAAY,MAAM;;WAElB,aAAa,MAAM;;;UAIb,MAAM,GAAG,UAAU,aAAa;;WAEtC,QAAQ;;EAEjB,WAAW,SAAS,aAAa,GAAG;;EAEpC,SAAS,OAAO;;EAEhB,QAAQ,eAAe,WAAW;;EAElC,SAAS;;EAET,UAAU;;EAEV,OAAO;;EAEP;;EAEA;;;cAIW;;cAGA,cAAc;;;;;;;;;;;iBA6BX,YAAY,GAAG,UAAU,aAAa,YAAY,WAAW,aAAa,SAAS,aAAa,GAAG,KAAK,MAAM,GAAG"}
|
|
@@ -125,6 +125,22 @@ declare function fitView(angles: ViewAngles, margin?: number): StageView;
|
|
|
125
125
|
* `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.
|
|
126
126
|
*/
|
|
127
127
|
declare function capView(angles: ViewAngles, angle: number, margin?: number): StageView;
|
|
128
|
+
/**
|
|
129
|
+
* This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.
|
|
130
|
+
*
|
|
131
|
+
* The middle is the center of the box of the points. `margin` is the space around the points, as a factor of the height above the ball.
|
|
132
|
+
* A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.
|
|
133
|
+
*/
|
|
134
|
+
declare function ballView(points: readonly Point3[], margin?: number): StageView;
|
|
135
|
+
/** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */
|
|
136
|
+
declare function reachOf(extent: StageExtent): number;
|
|
137
|
+
/**
|
|
138
|
+
* This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.
|
|
139
|
+
*
|
|
140
|
+
* A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.
|
|
141
|
+
* The result is not less than the nearest depth of the limits, and it is in front of all the content.
|
|
142
|
+
*/
|
|
143
|
+
declare function nearDepth(limits: StageLimits, extent: StageExtent, distance: number): number;
|
|
128
144
|
/**
|
|
129
145
|
* This function gives the limits of the camera of a stage for a picture.
|
|
130
146
|
*
|
|
@@ -135,21 +151,21 @@ declare function stageLimits(frame: ViewFrame, views: readonly StageView[], pola
|
|
|
135
151
|
readonly min: number;
|
|
136
152
|
readonly max: number;
|
|
137
153
|
}): StageLimits;
|
|
138
|
-
/** The
|
|
139
|
-
type
|
|
140
|
-
/** The records of a stage that have a
|
|
141
|
-
interface
|
|
154
|
+
/** 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. */
|
|
155
|
+
type Highlight = 0 | 1 | 2;
|
|
156
|
+
/** The records of a stage that have a highlight. Each record has a name. */
|
|
157
|
+
interface Highlights {
|
|
142
158
|
/** The name of the record under the pointer. */
|
|
143
159
|
readonly hovered: string | undefined;
|
|
144
160
|
/** The name of the selected record. */
|
|
145
161
|
readonly selected: string | undefined;
|
|
146
|
-
/** The names of the records that the page
|
|
147
|
-
readonly
|
|
162
|
+
/** The names of the records that the page highlights. */
|
|
163
|
+
readonly highlighted: ReadonlySet<string>;
|
|
148
164
|
}
|
|
149
|
-
/** The
|
|
150
|
-
declare const
|
|
151
|
-
/** This function gives the
|
|
152
|
-
declare function
|
|
165
|
+
/** The highlights of a stage with no pointer on it and no selected record. */
|
|
166
|
+
declare const NO_HIGHLIGHTS: Highlights;
|
|
167
|
+
/** This function gives the highlight of a record. The selected record has the highest highlight. */
|
|
168
|
+
declare function highlightOf(highlights: Highlights, record: string): Highlight;
|
|
153
169
|
/** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */
|
|
154
170
|
declare const CLICK_DISTANCE = 4;
|
|
155
171
|
/**
|
|
@@ -173,5 +189,5 @@ interface StageTheme {
|
|
|
173
189
|
/** The color of the light from below. */
|
|
174
190
|
readonly ground: string;
|
|
175
191
|
}
|
|
176
|
-
export {
|
|
177
|
-
//# sourceMappingURL=theme-
|
|
192
|
+
export { turnBetween as A, ViewAxes as C, fitDistance as D, clampPlace as E, viewOf as M, placeBetween as O, ViewAngles as S, capDistance as T, reachOf as _, NO_HIGHLIGHTS as a, Place as b, FIT_MARGIN as c, StageView as d, ViewFrame as f, nearDepth as g, fitView as h, Highlights as i, viewAxes as j, speedAt as k, StageExtent as l, capView as m, CLICK_DISTANCE as n, highlightOf as o, ballView as p, Highlight as r, isClick as s, StageTheme as t, StageLimits as u, stageLimits as v, cameraPosition as w, PlaceLimits as x, surfaceOf as y };
|
|
193
|
+
//# sourceMappingURL=theme-CKXd_emk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-CKXd_emk.d.ts","names":[],"sources":["../src/view.ts","../src/extent.ts","../src/highlight.ts","../src/theme.ts"],"mappings":";;;;;UAMiB;;WAEN;;WAEA;;;UAIM,cAAc;WACpB,QAAQ;WACR;;;UAIM;;WAEN,MAAM;;WAEN,OAAO;;WAEP,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIK,SAAS,MAAM,aAAa;;;;;;;;iBAwB5B,YAAY,iBAAiB,UAAU,QAAQ,QAAQ,MAAM,YAAY,aAAa;;;;;;;;;iBAsBtF,YAAY,gBAAgB,eAAe,aAAa;;iBAaxD,eAAe,QAAQ,QAAQ,MAAM,YAAY,mBAAmB;;iBAMpE,OAAO,QAAQ,QAAQ,QAAQ,SAAS;WAAwB;;;iBAUhE,YAAY,cAAc;;iBAO1B,WAAW,OAAO,OAAO,QAAQ,cAAc;;;;;;;;iBAgB/C,QAAQ,kBAAkB;;;;;;;iBAW1B,aAAa,MAAM,OAAO,IAAI,OAAO,cAAc,mBAAsB;;UCnJxE;;WAEN,kBAAkB;;WAElB,QAAQ;;;;;WAKR;;WAEA;;WAEA;;;UAIM;WACN,QAAQ;;WAER;;WAEA;;;KAIC,aAAa,OAAO,cAAc;;UAG7B,oBAAoB;WAC1B;WACA;;;cAIE;;iBAGG,UAAU,QAAQ;;;;;iBASlB,QAAQ,QAAQ,YAAY,kBAA8B;;;;;;;iBAa1D,QAAQ,QAAQ,YAAY,eAAe,kBAA8B;;;;;;;iBAczE,SAAS,iBAAiB,UAAU,kBAA8B;;iBA0ClE,QAAQ,QAAQ;;;;;;;iBAYhB,UAAU,QAAQ,aAAa,QAAQ,aAAa;;;;;;;iBAWpD,YAAY,OAAO,WAAW,gBAAgB,aAAa;WAAkB;WAAsB;IAAgB;;KC9IvH;;UAGK;;WAEN;;WAEA;;WAEA,aAAa;;;cAIX,eAAe;;iBAGZ,YAAY,YAAY,YAAY,iBAAiB;;cAMxD;;;;;iBAMG,QAAQ;WAAiB;WAAoB;GAAa;WAAe;WAAoB;GAAa;;;;;UCzBzG;;WAEN;;WAEA"}
|
package/build/three.d.ts
CHANGED
|
@@ -1,126 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/** The record under the pointer: its name, and the value that the content gives for it. */
|
|
4
|
-
interface StagePick<P> {
|
|
5
|
-
/** The name of the record. The marks of the stage use this name. */
|
|
6
|
-
readonly record: string;
|
|
7
|
-
/** The value of the record for the page, for example its kind and its source. */
|
|
8
|
-
readonly value: P;
|
|
9
|
-
}
|
|
10
|
-
/** One picture of a stage, for the step of its content. */
|
|
11
|
-
interface StageFrame {
|
|
12
|
-
readonly camera: PerspectiveCamera;
|
|
13
|
-
/** The time since the last picture, in seconds. */
|
|
14
|
-
readonly seconds: number;
|
|
15
|
-
/**
|
|
16
|
-
* This value is true for the first picture of a content, and for a person who asks for less motion.
|
|
17
|
-
* Each change then has no time: the content sets each value to its goal immediately.
|
|
18
|
-
*/
|
|
19
|
-
readonly settle: boolean;
|
|
20
|
-
/** The height of the picture, in CSS pixels. */
|
|
21
|
-
readonly height: number;
|
|
22
|
-
/** The vertical angle of the picture, in degrees. */
|
|
23
|
-
readonly fieldOfView: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The content of a stage: the three.js objects of one scene, and what the stage asks of them.
|
|
27
|
-
* `P` is the type of the value of a pick, and `T` is the type of the theme.
|
|
28
|
-
*/
|
|
29
|
-
interface StageContent<P, T extends StageTheme = StageTheme> {
|
|
30
|
-
/** The three.js objects of the content. The stage adds them to its world, and removes them. */
|
|
31
|
-
readonly objects: readonly Object3D[];
|
|
32
|
-
/** The space that the content fills. */
|
|
33
|
-
readonly extent: StageExtent;
|
|
34
|
-
/** This function tells if the content has a record with a name. */
|
|
35
|
-
has(record: string): boolean;
|
|
36
|
-
/** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */
|
|
37
|
-
pick(ray: Raycaster): StagePick<P> | undefined;
|
|
38
|
-
/** This function gives each part its colors, from the theme and the mark of its record. */
|
|
39
|
-
paint(theme: T, mark: (record: string) => Mark): void;
|
|
40
|
-
/**
|
|
41
|
-
* This function changes the parts that depend on the camera or on the time, before each picture.
|
|
42
|
-
* It gives true while a part continues to change. The stage then makes the next picture.
|
|
43
|
-
*/
|
|
44
|
-
step?(frame: StageFrame): boolean;
|
|
45
|
-
/** This function releases the memory of the graphics card that the content uses. */
|
|
46
|
-
dispose(): void;
|
|
47
|
-
}
|
|
48
|
-
/** The lights of a stage. A content with materials that use no light ignores them. */
|
|
49
|
-
interface StageLights {
|
|
50
|
-
/** The strength of the light from above and below. */
|
|
51
|
-
readonly sky: number;
|
|
52
|
-
/** The strength of the light from one direction. */
|
|
53
|
-
readonly sun: number;
|
|
54
|
-
/** The position that the light from one direction comes from. */
|
|
55
|
-
readonly from: {
|
|
56
|
-
readonly x: number;
|
|
57
|
-
readonly y: number;
|
|
58
|
-
readonly z: number;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/** The options of a stage. */
|
|
62
|
-
interface StageOptions<P, T extends StageTheme = StageTheme> {
|
|
63
|
-
/** The first content. The stage disposes each content that it gets. */
|
|
64
|
-
readonly content: StageContent<P, T>;
|
|
65
|
-
readonly theme: T;
|
|
66
|
-
/** The name of the picture for a screen reader. */
|
|
67
|
-
readonly label: string;
|
|
68
|
-
/** The views of the stage, each with a name. */
|
|
69
|
-
readonly views: Readonly<Record<string, StageView>>;
|
|
70
|
-
/** The name of the first view. The keys `Home` and `0` show it. */
|
|
71
|
-
readonly home: string;
|
|
72
|
-
/** The name of the view of a key, for example `{ t: "top" }`. A letter has no case. */
|
|
73
|
-
readonly keys?: Readonly<Record<string, string>> | undefined;
|
|
74
|
-
/** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. The default is 32. */
|
|
75
|
-
readonly fieldOfView?: number | undefined;
|
|
76
|
-
/** The smallest and the largest polar angle of the camera, in radians. The default keeps the camera above the plane of the target. */
|
|
77
|
-
readonly polar?: {
|
|
78
|
-
readonly min?: number | undefined;
|
|
79
|
-
readonly max?: number | undefined;
|
|
80
|
-
} | undefined;
|
|
81
|
-
/** This value is true if a person can move the target with a drag of the second button. The default is true. */
|
|
82
|
-
readonly pan?: boolean | undefined;
|
|
83
|
-
readonly lights?: StageLights | undefined;
|
|
84
|
-
/** The stage starts this function when the pointer goes to a different record, or to no record. */
|
|
85
|
-
readonly onHover?: ((pick: P | undefined) => void) | undefined;
|
|
86
|
-
/** The stage starts this function when a person selects a record with the pointer, or selects no record. */
|
|
87
|
-
readonly onSelect?: ((pick: P | undefined) => void) | undefined;
|
|
88
|
-
}
|
|
89
|
-
/** A stage in a page: one canvas with a camera that a person moves, and one content. */
|
|
90
|
-
interface Stage<P, T extends StageTheme = StageTheme> {
|
|
91
|
-
/** The canvas of the stage. It is in the container. */
|
|
92
|
-
readonly canvas: HTMLCanvasElement;
|
|
93
|
-
/** This function shows a different content, and disposes the old content. The view stays if a person moved it. */
|
|
94
|
-
setContent(content: StageContent<P, T>): void;
|
|
95
|
-
/** This function changes the colors. */
|
|
96
|
-
setTheme(theme: T): void;
|
|
97
|
-
/** This function moves the camera to a view: a name of the options, or a view function. `animate` has the default true. */
|
|
98
|
-
setView(view: string | StageView, animate?: boolean): void;
|
|
99
|
-
/** This function gives the place of the camera. */
|
|
100
|
-
place(): Place;
|
|
101
|
-
/** This function marks records by their names, as the pointer does. An empty list removes the marks. */
|
|
102
|
-
highlight(records: readonly string[]): void;
|
|
103
|
-
/** This function selects one record by its name, or no record. It does not start `onSelect`. */
|
|
104
|
-
select(record: string | undefined): void;
|
|
105
|
-
/** This function paints the content again and makes a new picture. Use it after a change of the content. */
|
|
106
|
-
refresh(): void;
|
|
107
|
-
/** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */
|
|
108
|
-
dispose(): void;
|
|
109
|
-
}
|
|
110
|
-
/** The default vertical angle of the picture, in degrees. */
|
|
111
|
-
export declare const FIELD_OF_VIEW = 32;
|
|
112
|
-
/** The default lights: a strong light from above and below, and a light from the front left. */
|
|
113
|
-
export declare const STAGE_LIGHTS: StageLights;
|
|
114
|
-
/**
|
|
115
|
-
* This function makes a stage in a container of a page. The stage fills the container, so give the container a size.
|
|
116
|
-
*
|
|
117
|
-
* A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.
|
|
118
|
-
* A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,
|
|
119
|
-
* and `Home` shows the first view. The stage makes a picture only after a change.
|
|
120
|
-
*
|
|
121
|
-
* The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.
|
|
122
|
-
* The page then shows a different picture of the same data.
|
|
123
|
-
*/
|
|
124
|
-
export declare function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined;
|
|
125
|
-
export type { Stage, StageContent, StageFrame, StageLights, StageOptions, StagePick };
|
|
126
|
-
//# sourceMappingURL=three.d.ts.map
|
|
1
|
+
import { a as StageFrame, c as StagePick, i as StageContent, l as createStage, n as STAGE_LIGHTS, o as StageLights, r as Stage, s as StageOptions, t as FIELD_OF_VIEW } from "./stage-CtWLSoV-.js";
|
|
2
|
+
export { FIELD_OF_VIEW, STAGE_LIGHTS, type Stage, type StageContent, type StageFrame, type StageLights, type StageOptions, type StagePick, createStage };
|