@catchlight/editor-web 0.0.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +26 -2
  4. package/THIRD-PARTY-NOTICES.md +331 -0
  5. package/dist/editor/CatchlightEditor.d.ts +21 -0
  6. package/dist/editor/CatchlightEditor.js +720 -0
  7. package/dist/editor/dialogs.d.ts +18 -0
  8. package/dist/editor/dialogs.js +71 -0
  9. package/dist/editor/import-panel.d.ts +6 -0
  10. package/dist/editor/import-panel.js +98 -0
  11. package/dist/editor/logo.svg +11 -0
  12. package/dist/editor/notification.d.ts +4 -0
  13. package/dist/editor/notification.js +24 -0
  14. package/dist/editor/stage.d.ts +13 -0
  15. package/dist/editor/stage.js +23 -0
  16. package/dist/editor/test/setup.d.ts +5 -0
  17. package/dist/editor/test/setup.js +5 -0
  18. package/dist/index.d.ts +11 -0
  19. package/dist/index.js +10 -0
  20. package/dist/lib/animations-panel.d.ts +10 -0
  21. package/dist/lib/animations-panel.js +48 -0
  22. package/dist/lib/authoring.d.ts +17 -0
  23. package/dist/lib/authoring.js +116 -0
  24. package/dist/lib/binding-grid.d.ts +19 -0
  25. package/dist/lib/binding-grid.js +92 -0
  26. package/dist/lib/bindings.d.ts +21 -0
  27. package/dist/lib/bindings.js +100 -0
  28. package/dist/lib/camera.d.ts +21 -0
  29. package/dist/lib/camera.js +61 -0
  30. package/dist/lib/controls-panel.d.ts +36 -0
  31. package/dist/lib/controls-panel.js +201 -0
  32. package/dist/lib/controls.d.ts +103 -0
  33. package/dist/lib/controls.js +163 -0
  34. package/dist/lib/editing.d.ts +126 -0
  35. package/dist/lib/editing.js +415 -0
  36. package/dist/lib/editor-context.d.ts +15 -0
  37. package/dist/lib/editor-context.js +23 -0
  38. package/dist/lib/expressions-panel.d.ts +10 -0
  39. package/dist/lib/expressions-panel.js +120 -0
  40. package/dist/lib/file-open.d.ts +11 -0
  41. package/dist/lib/file-open.js +25 -0
  42. package/dist/lib/file-save.d.ts +29 -0
  43. package/dist/lib/file-save.js +68 -0
  44. package/dist/lib/gizmo.d.ts +13 -0
  45. package/dist/lib/gizmo.js +247 -0
  46. package/dist/lib/image-markup.d.ts +12 -0
  47. package/dist/lib/image-markup.js +153 -0
  48. package/dist/lib/index.d.ts +71 -0
  49. package/dist/lib/index.js +44 -0
  50. package/dist/lib/inspector.d.ts +19 -0
  51. package/dist/lib/inspector.js +161 -0
  52. package/dist/lib/latest.d.ts +3 -0
  53. package/dist/lib/latest.js +9 -0
  54. package/dist/lib/layer-import.d.ts +38 -0
  55. package/dist/lib/layer-import.js +187 -0
  56. package/dist/lib/mesh-editor.d.ts +13 -0
  57. package/dist/lib/mesh-editor.js +337 -0
  58. package/dist/lib/model-panels.d.ts +23 -0
  59. package/dist/lib/model-panels.js +180 -0
  60. package/dist/lib/node-actions.d.ts +42 -0
  61. package/dist/lib/node-actions.js +115 -0
  62. package/dist/lib/node-drag.d.ts +18 -0
  63. package/dist/lib/node-drag.js +65 -0
  64. package/dist/lib/node-patch.d.ts +8 -0
  65. package/dist/lib/node-patch.js +10 -0
  66. package/dist/lib/node-tree.d.ts +36 -0
  67. package/dist/lib/node-tree.js +221 -0
  68. package/dist/lib/official.d.ts +82 -0
  69. package/dist/lib/official.js +197 -0
  70. package/dist/lib/param-actions.d.ts +48 -0
  71. package/dist/lib/param-actions.js +106 -0
  72. package/dist/lib/param-list.d.ts +36 -0
  73. package/dist/lib/param-list.js +73 -0
  74. package/dist/lib/param-slider.d.ts +44 -0
  75. package/dist/lib/param-slider.js +149 -0
  76. package/dist/lib/pose.d.ts +13 -0
  77. package/dist/lib/pose.js +32 -0
  78. package/dist/lib/posing-panel.d.ts +40 -0
  79. package/dist/lib/posing-panel.js +154 -0
  80. package/dist/lib/presence.d.ts +27 -0
  81. package/dist/lib/presence.js +98 -0
  82. package/dist/lib/properties-panel.d.ts +13 -0
  83. package/dist/lib/properties-panel.js +63 -0
  84. package/dist/lib/recording-panel.d.ts +4 -0
  85. package/dist/lib/recording-panel.js +161 -0
  86. package/dist/lib/replica.d.ts +18 -0
  87. package/dist/lib/replica.js +34 -0
  88. package/dist/lib/review.d.ts +113 -0
  89. package/dist/lib/review.js +529 -0
  90. package/dist/lib/rigging.d.ts +10 -0
  91. package/dist/lib/rigging.js +116 -0
  92. package/dist/lib/selection.d.ts +3 -0
  93. package/dist/lib/selection.js +2 -0
  94. package/dist/lib/session-list.d.ts +16 -0
  95. package/dist/lib/session-list.js +7 -0
  96. package/dist/lib/sessions.d.ts +8 -0
  97. package/dist/lib/sessions.js +29 -0
  98. package/dist/lib/test/harness.d.ts +32 -0
  99. package/dist/lib/test/harness.js +139 -0
  100. package/dist/lib/test/setup.d.ts +4 -0
  101. package/dist/lib/test/setup.js +5 -0
  102. package/dist/lib/versions.d.ts +69 -0
  103. package/dist/lib/versions.js +250 -0
  104. package/dist/lib/viewport.d.ts +57 -0
  105. package/dist/lib/viewport.js +315 -0
  106. package/dist/lib/workspace-layout.d.ts +24 -0
  107. package/dist/lib/workspace-layout.js +145 -0
  108. package/dist/lib/workspace.d.ts +29 -0
  109. package/dist/lib/workspace.js +263 -0
  110. package/dist/theme.css +4577 -0
  111. package/package.json +32 -6
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { BINDING_TARGETS, BINDING_LABELS, INTERPOLATE_MODES, bindingsOfParam, useBindings, valueAtKey, } from "./bindings.js";
4
+ import { useParamActions } from "./param-actions.js";
5
+ import { ParamKeysRoot } from "./param-slider.js";
6
+ import { useParams } from "./replica.js";
7
+ export function BindingGridRoot({ session, node, param, onError, ...rest }) {
8
+ const actions = useParamActions(session);
9
+ const params = useParams(session);
10
+ const all = useBindings(session, node);
11
+ const bindings = bindingsOfParam(all, param);
12
+ const [selected, setSelected] = useState(undefined);
13
+ const [target, setTarget] = useState(BINDING_TARGETS[0] ?? "tx");
14
+ const [copying, setCopying] = useState(undefined);
15
+ const [secondary, setSecondary] = useState("");
16
+ if (node === undefined || param === undefined) {
17
+ return _jsx("div", { "data-catchlight-binding-grid": "", "data-empty": "", ...rest });
18
+ }
19
+ const paramInfo = (id) => params.find((p) => p.id === id);
20
+ const pose = (binding, x, y) => {
21
+ const along = paramInfo(binding.param);
22
+ if (along)
23
+ session.setParam(binding.param, valueAtKey(along, x, binding.key_positions[0]));
24
+ const up = binding.param_y ? paramInfo(binding.param_y) : undefined;
25
+ if (up && binding.param_y)
26
+ session.setParam(binding.param_y, valueAtKey(up, y, binding.key_positions[1]));
27
+ };
28
+ const click = (binding, x, y) => {
29
+ const at = { binding: keyOf(binding), x, y };
30
+ // An armed copy lands on the cell that ends it; anywhere else cancels.
31
+ if (copying) {
32
+ setCopying(undefined);
33
+ if (copying.binding === at.binding) {
34
+ report(onError, actions.copyKey(node, binding.target, paramsOf(binding), [copying.x, copying.y], [x, y]));
35
+ return;
36
+ }
37
+ }
38
+ setSelected(at);
39
+ pose(binding, x, y);
40
+ };
41
+ const commit = (binding, x, y, text) => {
42
+ // A deform cell holds a vertex list, which scalar inputs cannot edit.
43
+ if (binding.target === "deform")
44
+ return;
45
+ const value = Number(text);
46
+ const was = binding.keys[y]?.[x];
47
+ if (text.trim() === "" || !Number.isFinite(value) || value === was)
48
+ return;
49
+ report(onError, actions.setKey(node, binding.target, paramsOf(binding), [x, y], value));
50
+ };
51
+ return (_jsxs("div", { "data-catchlight-binding-grid": "", "data-node": node, "data-copying": copying ? "" : undefined, ...rest, children: [_jsxs("div", { "data-catchlight-binding-add": "", children: [_jsx("select", { "data-catchlight-binding-target": "", "aria-label": "Binding target", value: target, onChange: (event) => setTarget(event.currentTarget.value), children: BINDING_TARGETS.map((name) => (_jsx("option", { value: name, children: BINDING_LABELS[name] }, name))) }), _jsxs("select", { "aria-label": "Second driving param", value: secondary, onChange: (e) => setSecondary(e.currentTarget.value), children: [_jsx("option", { value: "", children: "One param" }), params
52
+ .filter((p) => p.id !== param)
53
+ .map((p) => (_jsxs("option", { value: p.id, children: ["\u00D7 ", p.name] }, p.id)))] }), _jsx("button", { type: "button", "data-catchlight-binding-add-submit": "", onClick: () => report(onError, actions.addBinding(node, target, {
54
+ param,
55
+ param_y: secondary || null,
56
+ })), children: "Bind" })] }), bindings.map((binding) => {
57
+ const id = keyOf(binding);
58
+ return (_jsxs("div", { "data-catchlight-binding": "", "data-target": binding.target, "data-param": binding.param, "data-param-y": binding.param_y ?? undefined, children: [_jsxs("div", { "data-catchlight-binding-head": "", children: [_jsxs("span", { "data-catchlight-binding-name": "", children: [BINDING_LABELS[binding.target], binding.param_y && _jsxs("small", { children: [" \u00D7 ", paramInfo(binding.param_y)?.name] })] }), _jsx("select", { "data-catchlight-binding-interpolate": "", "aria-label": `${binding.target} interpolation`, value: binding.interpolate, onChange: (event) => report(onError, actions.interpolate(node, binding.target, paramsOf(binding), event.currentTarget.value)), children: INTERPOLATE_MODES.map((mode) => (_jsx("option", { value: mode, children: mode }, mode))) }), _jsx("button", { type: "button", "data-catchlight-binding-invert": "", title: "Negate every authored value", onClick: () => report(onError, actions.invert(node, binding.target, paramsOf(binding))), children: "Invert" }), _jsx("button", { type: "button", "data-catchlight-binding-delete": "", title: `Delete the ${binding.target} binding`, onClick: () => report(onError, actions.deleteBinding(node, binding.target, paramsOf(binding))), children: "\u00D7" })] }), [binding.param, ...(binding.param_y ? [binding.param_y] : [])].map((axis) => {
59
+ const parameter = paramInfo(axis);
60
+ return parameter && (_jsxs("div", { "data-catchlight-binding-axis": "", children: [_jsx("span", { children: parameter.name }), _jsx(ParamKeysRoot, { session: session, param: parameter, binding: binding, node: node, onError: onError })] }, axis));
61
+ }), binding.keys.map((row, y) => (_jsx("div", { "data-catchlight-binding-row": "", "data-y": y, children: row.map((value, x) => {
62
+ const authored = binding.authored[y]?.[x] === true;
63
+ const isSelected = selected?.binding === id && selected.x === x && selected.y === y;
64
+ return (_jsx("input", { type: "number", step: "any", "data-catchlight-binding-cell": "", "data-cell": `${x},${y}`, "data-set": authored ? "" : undefined, "data-unset": authored ? undefined : "", "data-selected": isSelected ? "" : undefined, "aria-label": `${binding.target} cell ${x},${y}`, title: `${paramInfo(binding.param)?.name ?? binding.param}: ${valueAtKey(paramInfo(binding.param), x, binding.key_positions[0])}${binding.param_y ? ` · ${paramInfo(binding.param_y)?.name}: ${valueAtKey(paramInfo(binding.param_y), y, binding.key_positions[1])}` : ""}${binding.target.startsWith("r") ? " · radians" : ""}${authored ? " · authored key" : " · interpolated"}`, placeholder: binding.target === "deform" ? (authored ? "Set" : "—") : "Auto", readOnly: binding.target === "deform", defaultValue: value === null ? "" : String(value), onClick: () => click(binding, x, y), onBlur: (event) => commit(binding, x, y, event.currentTarget.value), onKeyDown: commitOnEnter }, `${x}:${value ?? "-"}:${String(authored)}`));
65
+ }) }, y))), selected?.binding === id ? (_jsxs("div", { "data-catchlight-binding-cell-actions": "", children: [_jsx("button", { type: "button", "data-catchlight-binding-reset": "", title: "Author the identity value here", onClick: () => report(onError, actions.resetKey(node, binding.target, paramsOf(binding), [
66
+ selected.x,
67
+ selected.y,
68
+ ])), children: "Reset" }), _jsx("button", { type: "button", "data-catchlight-binding-unset": "", title: "Un-author this cell", onClick: () => report(onError, actions.unsetKey(node, binding.target, paramsOf(binding), [
69
+ selected.x,
70
+ selected.y,
71
+ ])), children: "Unset" }), _jsx("button", { type: "button", "data-catchlight-binding-copy": "", "data-armed": copying ? "" : undefined, title: "Copy this cell's value into the next cell clicked", onClick: () => setCopying(copying ? undefined : selected), children: copying ? "Pick a cell" : "Copy to…" })] })) : null] }, id));
72
+ })] }));
73
+ }
74
+ export const BindingGrid = { Root: BindingGridRoot };
75
+ function keyOf(binding) {
76
+ return `${binding.target}|${binding.param}|${binding.param_y ?? ""}`;
77
+ }
78
+ function paramsOf(binding) {
79
+ return { param: binding.param, param_y: binding.param_y ?? null };
80
+ }
81
+ function commitOnEnter(event) {
82
+ if (event.key === "Enter")
83
+ event.currentTarget.blur();
84
+ }
85
+ function report(onError, work) {
86
+ void work.catch((cause) => {
87
+ if (onError)
88
+ onError(cause);
89
+ else
90
+ console.warn("catchlight: the binding edit failed", cause);
91
+ });
92
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Binding reads, the target and interpolation tables a binding panel picks
3
+ * from, and key-position arithmetic. `deform` is deliberately absent from the
4
+ * targets: deform offsets have their own authoring controls.
5
+ */
6
+ import type { BindingInfo, Interpolate, NodeId, ParamInfo, ScalarTarget, Session } from "@catchlight/editor-core";
7
+ export declare const BINDING_TARGETS: readonly ScalarTarget[];
8
+ export declare const BINDING_LABELS: Record<ScalarTarget | "deform", string>;
9
+ export declare const INTERPOLATE_MODES: readonly Interpolate[];
10
+ /** `[]` when nothing is selected or the node is gone. */
11
+ export declare function useBindings(session: Session, node: NodeId | undefined): BindingInfo[];
12
+ /** Bindings `param` drives along either axis; a two-param binding appears under both. */
13
+ export declare function bindingsOfParam(bindings: BindingInfo[], param: string | undefined): BindingInfo[];
14
+ /** Key positions are normalized 0..1 over `[min, max]`; an out-of-range index answers the default. */
15
+ export declare function valueAtKey(param: ParamInfo, index: number, positions: readonly number[]): number;
16
+ export declare function normalizedValue(param: ParamInfo, value: number): number;
17
+ /** Matches within a tolerance, since the value comes from a continuous slider. */
18
+ export declare function keyIndexNear(param: ParamInfo, value: number, positions: readonly number[], within?: number): number | undefined;
19
+ /** As in Rust recording, the nearest key within 1e-5 normalized units absorbs
20
+ * pose round-trip error; an exact key wins over another key within that tolerance. */
21
+ export declare function bindingCellAt(binding: Pick<BindingInfo, "key_positions">, position: readonly [number, number]): [number, number] | undefined;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Binding reads, the target and interpolation tables a binding panel picks
3
+ * from, and key-position arithmetic. `deform` is deliberately absent from the
4
+ * targets: deform offsets have their own authoring controls.
5
+ */
6
+ import { useMemo } from "react";
7
+ import { useRevision } from "./replica.js";
8
+ export const BINDING_TARGETS = [
9
+ "tx",
10
+ "ty",
11
+ "tz",
12
+ "sx",
13
+ "sy",
14
+ "rx",
15
+ "ry",
16
+ "rz",
17
+ "z_order",
18
+ "opacity",
19
+ "tintr",
20
+ "tintg",
21
+ "tintb",
22
+ "screentintr",
23
+ "screentintg",
24
+ "screentintb",
25
+ ];
26
+ export const BINDING_LABELS = {
27
+ tx: "Position X",
28
+ ty: "Position Y",
29
+ tz: "Depth",
30
+ sx: "Scale X",
31
+ sy: "Scale Y",
32
+ rx: "Rotation X",
33
+ ry: "Rotation Y",
34
+ rz: "Rotation Z",
35
+ z_order: "Draw order",
36
+ opacity: "Opacity",
37
+ tintr: "Tint red",
38
+ tintg: "Tint green",
39
+ tintb: "Tint blue",
40
+ screentintr: "Screen red",
41
+ screentintg: "Screen green",
42
+ screentintb: "Screen blue",
43
+ deform: "Mesh deform",
44
+ };
45
+ export const INTERPOLATE_MODES = ["nearest", "stepped", "linear", "cubic"];
46
+ /** `[]` when nothing is selected or the node is gone. */
47
+ export function useBindings(session, node) {
48
+ const revision = useRevision(session);
49
+ return useMemo(() => (node === undefined ? [] : session.bindings(node)), [session, revision, node]);
50
+ }
51
+ /** Bindings `param` drives along either axis; a two-param binding appears under both. */
52
+ export function bindingsOfParam(bindings, param) {
53
+ if (param === undefined)
54
+ return [];
55
+ return bindings.filter((b) => b.param === param || b.param_y === param);
56
+ }
57
+ /** Key positions are normalized 0..1 over `[min, max]`; an out-of-range index answers the default. */
58
+ export function valueAtKey(param, index, positions) {
59
+ const position = positions[index];
60
+ if (position === undefined)
61
+ return param.default;
62
+ return param.min + position * (param.max - param.min);
63
+ }
64
+ export function normalizedValue(param, value) {
65
+ const span = param.max - param.min;
66
+ if (span === 0)
67
+ return 0;
68
+ return Math.min(1, Math.max(0, (value - param.min) / span));
69
+ }
70
+ /** Matches within a tolerance, since the value comes from a continuous slider. */
71
+ export function keyIndexNear(param, value, positions, within = 0.005) {
72
+ const at = normalizedValue(param, value);
73
+ let best;
74
+ let distance = within;
75
+ positions.forEach((position, index) => {
76
+ const gap = Math.abs(position - at);
77
+ if (gap <= distance) {
78
+ distance = gap;
79
+ best = index;
80
+ }
81
+ });
82
+ return best;
83
+ }
84
+ /** As in Rust recording, the nearest key within 1e-5 normalized units absorbs
85
+ * pose round-trip error; an exact key wins over another key within that tolerance. */
86
+ export function bindingCellAt(binding, position) {
87
+ const indices = binding.key_positions.map((axis, i) => {
88
+ let nearest = -1;
89
+ let distance = Infinity;
90
+ axis.forEach((value, index) => {
91
+ const gap = Math.abs(value - position[i]);
92
+ if (gap <= 0.00001 && gap < distance) {
93
+ nearest = index;
94
+ distance = gap;
95
+ }
96
+ });
97
+ return nearest;
98
+ });
99
+ return indices.every((index) => index >= 0) ? [indices[0], indices[1] ?? 0] : undefined;
100
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Canvas pixels against world units. World space is Y-up, screen space Y-down;
3
+ * one screen height is `camera.height` world units on both axes.
4
+ */
5
+ import type { Camera, Size } from "@catchlight/player";
6
+ export { DEFAULT_CAMERA, fitCamera } from "@catchlight/player";
7
+ export type { Bounds, Size } from "@catchlight/player";
8
+ export type Point = [number, number];
9
+ /** World units per CSS pixel. */
10
+ export declare function worldPerPixel(camera: Camera, size: Size): number;
11
+ export declare function worldAt(camera: Camera, size: Size, screen: Point): Point;
12
+ /** World point to canvas CSS pixels, for placing HTML overlays. */
13
+ export declare function screenAt(camera: Camera, size: Size, world: Point): Point;
14
+ /** Scales by `factor`, keeping the world point under `screen` fixed. */
15
+ export declare function zoomAbout(camera: Camera, size: Size, screen: Point, factor: number): Camera;
16
+ /** Measured from the gesture's start, not the last move, so skipped cameras cannot drift. */
17
+ export declare function panTo(start: Camera, from: Point, size: Size, to: Point): Camera;
18
+ /** `deltaMode` is pixels, lines or pages; a trackpad sends many small pixel deltas. */
19
+ export declare function wheelNotches(deltaY: number, deltaMode: number): number;
20
+ /** Zoom-out factor per notch; `deltaY > 0` shows more world. */
21
+ export declare const ZOOM_PER_NOTCH = 1.1;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Canvas pixels against world units. World space is Y-up, screen space Y-down;
3
+ * one screen height is `camera.height` world units on both axes.
4
+ */
5
+ import { clampHeight } from "@catchlight/player";
6
+ export { DEFAULT_CAMERA, fitCamera } from "@catchlight/player";
7
+ /** World units per CSS pixel. */
8
+ export function worldPerPixel(camera, size) {
9
+ return camera.height / Math.max(size.height, 1);
10
+ }
11
+ export function worldAt(camera, size, screen) {
12
+ const scale = worldPerPixel(camera, size);
13
+ return [
14
+ camera.center[0] + (screen[0] - size.width / 2) * scale,
15
+ camera.center[1] - (screen[1] - size.height / 2) * scale,
16
+ ];
17
+ }
18
+ /** World point to canvas CSS pixels, for placing HTML overlays. */
19
+ export function screenAt(camera, size, world) {
20
+ const scale = worldPerPixel(camera, size);
21
+ return [
22
+ size.width / 2 + (world[0] - camera.center[0]) / scale,
23
+ size.height / 2 - (world[1] - camera.center[1]) / scale,
24
+ ];
25
+ }
26
+ /** Scales by `factor`, keeping the world point under `screen` fixed. */
27
+ export function zoomAbout(camera, size, screen, factor) {
28
+ const height = clampHeight(camera.height * factor);
29
+ const anchor = worldAt(camera, size, screen);
30
+ const scale = height / Math.max(size.height, 1);
31
+ return {
32
+ center: [
33
+ anchor[0] - (screen[0] - size.width / 2) * scale,
34
+ anchor[1] + (screen[1] - size.height / 2) * scale,
35
+ ],
36
+ height,
37
+ };
38
+ }
39
+ /** Measured from the gesture's start, not the last move, so skipped cameras cannot drift. */
40
+ export function panTo(start, from, size, to) {
41
+ const scale = worldPerPixel(start, size);
42
+ return {
43
+ center: [
44
+ start.center[0] - (to[0] - from[0]) * scale,
45
+ start.center[1] + (to[1] - from[1]) * scale,
46
+ ],
47
+ height: start.height,
48
+ };
49
+ }
50
+ /** `deltaMode` is pixels, lines or pages; a trackpad sends many small pixel deltas. */
51
+ export function wheelNotches(deltaY, deltaMode) {
52
+ if (deltaMode === 1)
53
+ return deltaY / LINES_PER_NOTCH;
54
+ if (deltaMode === 2)
55
+ return deltaY;
56
+ return deltaY / PIXELS_PER_NOTCH;
57
+ }
58
+ /** Zoom-out factor per notch; `deltaY > 0` shows more world. */
59
+ export const ZOOM_PER_NOTCH = 1.1;
60
+ const LINES_PER_NOTCH = 3;
61
+ const PIXELS_PER_NOTCH = 100;
@@ -0,0 +1,36 @@
1
+ import type { ControlMappingInfo, NodeId, Session } from "@catchlight/editor-core";
2
+ import type { ErrorHandler } from "./authoring.js";
3
+ /** Headings in order, each with the name prefixes it collects. */
4
+ export declare const CONTROL_GROUPS: readonly (readonly [string, readonly string[]])[];
5
+ export interface ControlEntry {
6
+ name: string;
7
+ /** Runs 0..1 rather than -1..1. */
8
+ oneSided: boolean;
9
+ standard: boolean;
10
+ mapping: ControlMappingInfo | undefined;
11
+ }
12
+ /**
13
+ * The standard controls under their headings, in the standard's order, then
14
+ * any mapped control outside the standard under Other.
15
+ */
16
+ export declare function groupControls(controls: readonly {
17
+ name: string;
18
+ one_sided: boolean;
19
+ }[], mappings: readonly ControlMappingInfo[]): {
20
+ title: string;
21
+ entries: ControlEntry[];
22
+ }[];
23
+ /**
24
+ * The humanoid controls: map each onto a param and try it live. A live value is
25
+ * per tab and authors nothing; mapping is an edit. Below them, the zones and
26
+ * landmarks a camera frames: each marked from `selected`, the node selected in
27
+ * the editor.
28
+ */
29
+ export declare function ControlsPanel({ session, onError, selected, onSelectNode, }: {
30
+ session: Session;
31
+ onError: ErrorHandler;
32
+ selected?: NodeId | undefined;
33
+ onSelectNode?: (node: NodeId) => void;
34
+ }): import("react").JSX.Element;
35
+ /** `full_body` reads as "Full body". */
36
+ export declare function nameLabel(name: string): string;
@@ -0,0 +1,201 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from "react";
3
+ import { EmptyState, IconButton, NumberField, round } from "./controls.js";
4
+ import { ExtensionWarnings, HUMANOID, NonstandardDialog, UnreadNotice, WarningMark, useExtensionWarnings, useHumanoid, useOfficialCommand, useLiveInputs, warningsOn, } from "./official.js";
5
+ import { useNodeInfo, useParams, useTree } from "./replica.js";
6
+ /** Headings in order, each with the name prefixes it collects. */
7
+ export const CONTROL_GROUPS = [
8
+ ["Head", ["head_"]],
9
+ ["Body", ["body_", "leg_"]],
10
+ ["Eyes", ["eye_"]],
11
+ ["Brows", ["brow_"]],
12
+ ["Cheeks", ["cheek_", "blush"]],
13
+ ["Mouth", ["mouth_", "teeth_", "lip_", "tongue_"]],
14
+ ];
15
+ /**
16
+ * The standard controls under their headings, in the standard's order, then
17
+ * any mapped control outside the standard under Other.
18
+ */
19
+ export function groupControls(controls, mappings) {
20
+ const mapped = new Map(mappings.map((m) => [m.control, m]));
21
+ const groups = CONTROL_GROUPS.map(([title]) => ({ title, entries: [] }));
22
+ const other = [];
23
+ for (const control of controls) {
24
+ const entry = {
25
+ name: control.name,
26
+ oneSided: control.one_sided,
27
+ standard: true,
28
+ mapping: mapped.get(control.name),
29
+ };
30
+ const at = CONTROL_GROUPS.findIndex(([, prefixes]) => prefixes.some((p) => control.name.startsWith(p)));
31
+ (at < 0 ? other : groups[at].entries).push(entry);
32
+ }
33
+ const standard = new Set(controls.map((c) => c.name));
34
+ for (const m of mappings)
35
+ if (!standard.has(m.control))
36
+ other.push({ name: m.control, oneSided: false, standard: false, mapping: m });
37
+ return [...groups, { title: "Other", entries: other }].filter((g) => g.entries.length);
38
+ }
39
+ /**
40
+ * The humanoid controls: map each onto a param and try it live. A live value is
41
+ * per tab and authors nothing; mapping is an edit. Below them, the zones and
42
+ * landmarks a camera frames: each marked from `selected`, the node selected in
43
+ * the editor.
44
+ */
45
+ export function ControlsPanel({ session, onError, selected, onSelectNode, }) {
46
+ const read = useHumanoid(session);
47
+ const { warnings, params: warned } = useExtensionWarnings(session, HUMANOID);
48
+ const params = useParams(session);
49
+ const inputs = useLiveInputs(session);
50
+ const command = useOfficialCommand(session, onError);
51
+ const [mappedOnly, setMappedOnly] = useState(false);
52
+ // Names outside the standard the person chose to keep, sent as such from then on.
53
+ const [kept, setKept] = useState(new Set());
54
+ const tree = useTree(session);
55
+ const names = useMemo(() => nodeNames(tree), [tree]);
56
+ if (read.unread !== undefined)
57
+ return (_jsx("div", { "data-catchlight-controls-panel": "", children: _jsx(UnreadNotice, { what: "humanoid control mappings", why: read.unread }) }));
58
+ const groups = groupControls(read.body.controls, read.body.mappings);
59
+ const total = groups.reduce((n, g) => n + g.entries.length, 0);
60
+ const showing = groups
61
+ .map((g) => ({ ...g, entries: g.entries.filter((e) => !mappedOnly || e.mapping) }))
62
+ .filter((g) => g.entries.length);
63
+ const map = (control, param, stops) => void command.run({
64
+ cmd: "humanoid_map",
65
+ control,
66
+ param,
67
+ ...(stops ? { stops } : {}),
68
+ nonstandard: kept.has(control),
69
+ });
70
+ return (_jsxs("div", { "data-catchlight-controls-panel": "", children: [_jsxs("div", { "data-catchlight-panel-tools": "", children: [_jsxs("label", { "data-catchlight-toggle": "", children: [_jsx("input", { type: "checkbox", checked: mappedOnly, onChange: (e) => setMappedOnly(e.currentTarget.checked) }), "Mapped only"] }), _jsxs("span", { "data-catchlight-control-count": "", role: "status", children: [read.body.mappings.length, " of ", total, " mapped"] })] }), _jsx(ExtensionWarnings, { warnings: warnings }), _jsx("div", { "data-catchlight-control-cards": "", "aria-busy": command.busy || undefined, children: showing.map((group) => (_jsxs("section", { "data-catchlight-control-group": "", "aria-label": group.title, children: [_jsx("h3", { children: group.title }), group.entries.map((entry) => (_jsx(ControlCard, { session: session, entry: entry, params: params, value: inputs.controls[entry.name], warnings: entry.mapping ? warningsOn(warned, [entry.mapping.param]) : [], onMap: (param, stops) => map(entry.name, param, stops), onUnmap: () => void command.run({ cmd: "humanoid_unmap", control: entry.name }) }, entry.name)))] }, group.title))) }), mappedOnly && !showing.length && (_jsx(EmptyState, { icon: "link", title: "No controls mapped yet", children: "Pick a param for a control to map it, or show every control to see what is left." })), _jsx(ZoneMarks, { standard: read.body.standard_zones, zones: read.body.zones, names: names, selected: selected, busy: command.busy, onMark: (zone, nodes) => void command.run({
71
+ cmd: "humanoid_mark_zone",
72
+ zone,
73
+ nodes,
74
+ nonstandard: kept.has(`zone ${zone}`),
75
+ }), onUnmark: (zone) => void command.run({ cmd: "humanoid_unmark_zone", zone }), ...(onSelectNode ? { onSelectNode } : {}) }, `zones ${session.id}`), _jsx(LandmarkMarks, { session: session, standard: read.body.standard_landmarks, landmarks: read.body.landmarks, names: names, selected: selected, busy: command.busy, onMark: (landmark, part, vertex) => void command.run({
76
+ cmd: "humanoid_mark_landmark",
77
+ landmark,
78
+ part,
79
+ vertex,
80
+ nonstandard: kept.has(`landmark ${landmark}`),
81
+ }), onUnmark: (landmark) => void command.run({ cmd: "humanoid_unmark_landmark", landmark }), ...(onSelectNode ? { onSelectNode } : {}) }, `landmarks ${session.id}`), _jsx(NonstandardDialog, { asking: command.asking, onCancel: command.dismiss, onKeep: () => {
82
+ const asked = command.asking?.command;
83
+ const name = asked?.cmd === "humanoid_map"
84
+ ? asked.control
85
+ : asked?.cmd === "humanoid_mark_zone"
86
+ ? `zone ${asked.zone}`
87
+ : asked?.cmd === "humanoid_mark_landmark"
88
+ ? `landmark ${asked.landmark}`
89
+ : undefined;
90
+ if (name !== undefined)
91
+ setKept((k) => new Set([...k, name]));
92
+ command.keep();
93
+ } })] }));
94
+ }
95
+ function ControlCard({ session, entry, params, value, warnings, onMap, onUnmap, }) {
96
+ const { name, mapping, oneSided } = entry;
97
+ const stops = mapping?.stops;
98
+ const missing = mapping && !params.some((p) => p.id === mapping.param);
99
+ const setStop = (index, to) => {
100
+ if (!mapping || !stops)
101
+ return;
102
+ const next = [...stops];
103
+ next[index] = to;
104
+ onMap(mapping.param, next);
105
+ };
106
+ return (_jsxs("div", { "data-catchlight-control-card": "", "data-control": name, "data-mapped": mapping ? "" : undefined, "data-live": value !== undefined ? "" : undefined, "data-nonstandard": entry.standard ? undefined : "", "data-warned": warnings.length ? "" : undefined, children: [_jsxs("div", { "data-catchlight-control-head": "", children: [_jsx("span", { "data-catchlight-control-name": "", title: name, children: name }), _jsx(WarningMark, { warnings: warnings }), _jsxs("select", { "aria-label": `${name} param`, value: mapping?.param ?? "", onChange: (e) => {
107
+ const param = e.currentTarget.value;
108
+ if (!param)
109
+ onUnmap();
110
+ else
111
+ onMap(param);
112
+ }, children: [_jsx("option", { value: "", children: "Unmapped" }), missing && _jsxs("option", { value: mapping.param, children: [mapping.param, " (removed)"] }), params.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id)))] })] }), _jsxs("div", { "data-catchlight-control-value-row": "", children: [_jsx("input", { type: "range", "data-catchlight-control-slider": "", "aria-label": `${name} live input`, min: oneSided ? 0 : -1, max: 1, step: 0.01, value: value ?? 0, disabled: !mapping, onInput: (e) => session.setControl(name, Number(e.currentTarget.value)), onChange: noop }), _jsx("output", { "data-catchlight-control-value": "", "aria-label": `${name} live value`, children: value === undefined ? "–" : round(value).toFixed(2) }), _jsx(IconButton, { icon: "close", label: `Clear ${name} live value`, disabled: value === undefined, onClick: () => session.setControl(name, undefined) })] }), stops && (_jsx("div", { "data-catchlight-control-stops": "", children: ["−1", "0", "+1"].map((at, i) => (_jsx(NumberField, { label: `${name} stop at ${at}`, prefix: at, value: stops[i], onCommit: (v) => setStop(i, v) }, at))) }))] }));
113
+ }
114
+ /** `full_body` reads as "Full body". */
115
+ export function nameLabel(name) {
116
+ const words = name.replaceAll("_", " ");
117
+ return words.charAt(0).toUpperCase() + words.slice(1);
118
+ }
119
+ function nodeNames(tree) {
120
+ const names = new Map();
121
+ const visit = (node) => {
122
+ names.set(node.id, node.name);
123
+ node.children.forEach(visit);
124
+ };
125
+ visit(tree);
126
+ return names;
127
+ }
128
+ /** The keys to show: the standard ones, any other marked, then those added here. */
129
+ function useKeyRows(standard, marked) {
130
+ const [added, setAdded] = useState([]);
131
+ return {
132
+ keys: [...new Set([...standard, ...marked, ...added])],
133
+ add: (key) => setAdded((a) => [...a, key]),
134
+ drop: (key) => setAdded((a) => a.filter((k) => k !== key)),
135
+ added: (key) => added.includes(key),
136
+ };
137
+ }
138
+ /** Adds a row for a key; nothing is marked, or checked, until the row is set. */
139
+ function AddKey({ what, example, shown, onAdd, }) {
140
+ const [typed, setTyped] = useState("");
141
+ const key = typed.trim();
142
+ return (_jsxs("form", { "data-catchlight-add-key": "", onSubmit: (e) => {
143
+ e.preventDefault();
144
+ if (!key || shown.includes(key))
145
+ return;
146
+ onAdd(key);
147
+ setTyped("");
148
+ }, children: [_jsx("input", { type: "text", "aria-label": `Custom ${what} key`, placeholder: example, title: `A key of your own has a dot, such as ${example}`, autoCapitalize: "none", spellCheck: false, value: typed, onChange: (e) => setTyped(e.currentTarget.value) }), _jsxs("button", { type: "submit", disabled: !key || shown.includes(key), children: ["Add ", what] })] }));
149
+ }
150
+ /**
151
+ * The standard zones, then any other, each with the nodes it is marked as.
152
+ * Use selection replaces it with the selected node; Add extends it.
153
+ */
154
+ function ZoneMarks({ standard, zones, names, selected, busy, onMark, onUnmark, onSelectNode, }) {
155
+ const marked = new Map(zones.map((z) => [z.zone, z.nodes]));
156
+ const rows = useKeyRows(standard, [...marked.keys()]);
157
+ const pick = selected !== undefined && names.has(selected) ? selected : undefined;
158
+ return (_jsxs("section", { "data-catchlight-zones": "", "aria-label": "Zones", "aria-busy": busy || undefined, children: [_jsx("header", { children: _jsx("h3", { children: "Zones" }) }), _jsx("p", { "data-catchlight-hint": "", children: "A zone covers every part at or under its nodes, for a camera to frame. An unmarked full body is every part." }), rows.keys.map((name) => {
159
+ const nodes = marked.get(name);
160
+ const label = standard.includes(name) ? nameLabel(name) : name;
161
+ return (_jsxs("div", { "data-catchlight-body-mark": "", "data-zone": name, "data-marked": nodes ? "" : undefined, "data-nonstandard": standard.includes(name) ? undefined : "", children: [_jsx("span", { "data-catchlight-body-mark-name": "", children: label }), _jsx("span", { "data-catchlight-body-mark-nodes": "", children: nodes ? (nodes.map((node) => (_jsx(NodeChip, { node: node, names: names, selected: selected, ...(onSelectNode ? { onSelectNode } : {}) }, node)))) : (_jsx("span", { "data-catchlight-body-mark-unmarked": "", children: name === "full_body" ? "Every part" : "Not marked" })) }), _jsx("button", { type: "button", "aria-label": `Set ${label} to the selected node`, title: pick ? `Mark ${label} as ${names.get(pick)}` : "Select a node to mark it", disabled: !pick, onClick: () => pick && onMark(name, [pick]), children: "Use selection" }), _jsx("button", { type: "button", "aria-label": `Add the selected node to ${label}`, disabled: !pick || !nodes || nodes.includes(pick), onClick: () => pick && nodes && onMark(name, [...nodes, pick]), children: "Add" }), _jsx(IconButton, { icon: "close", label: `Clear ${label}`, disabled: !nodes && !rows.added(name), onClick: () => {
162
+ rows.drop(name);
163
+ if (nodes)
164
+ onUnmark(name);
165
+ } })] }, name));
166
+ }), _jsx(AddKey, { what: "zone", example: "mystudio.tail", shown: rows.keys, onAdd: rows.add })] }));
167
+ }
168
+ /**
169
+ * The standard landmarks, then any other, each with the part and
170
+ * vertex it is pinned to. A landmark is set on the selected part at the
171
+ * vertex index typed beside it.
172
+ */
173
+ function LandmarkMarks({ session, standard, landmarks, names, selected, busy, onMark, onUnmark, onSelectNode, }) {
174
+ const info = useNodeInfo(session, selected);
175
+ const part = info?.kind === "part" ? info : undefined;
176
+ const marked = new Map(landmarks.map((l) => [l.landmark, l]));
177
+ const rows = useKeyRows(standard, [...marked.keys()]);
178
+ return (_jsxs("section", { "data-catchlight-landmarks": "", "aria-label": "Landmarks", "aria-busy": busy || undefined, children: [_jsx("header", { children: _jsx("h3", { children: "Landmarks" }) }), _jsx("p", { "data-catchlight-hint": "", children: "A landmark is a vertex of a part, so it moves with the art. Select a part and type the vertex index to set one." }), rows.keys.map((name) => (_jsx(LandmarkRow, { name: name, standard: standard.includes(name), mark: marked.get(name), added: rows.added(name), names: names, selected: selected, part: part ? { id: part.id, vertices: part.vertex_count ?? 0 } : undefined, onMark: (at, vertex) => onMark(name, at, vertex), onClear: () => {
179
+ rows.drop(name);
180
+ if (marked.has(name))
181
+ onUnmark(name);
182
+ }, ...(onSelectNode ? { onSelectNode } : {}) }, name))), _jsx(AddKey, { what: "landmark", example: "mystudio.tail_tip", shown: rows.keys, onAdd: rows.add })] }));
183
+ }
184
+ function LandmarkRow({ name, standard, mark, added, names, selected, part, onMark, onClear, onSelectNode, }) {
185
+ const label = standard ? nameLabel(name) : name;
186
+ const slot = mark?.slot ?? undefined;
187
+ const [typed, setTyped] = useState("");
188
+ const vertex = typed.trim() === "" ? NaN : Number(typed);
189
+ const valid = !!part && Number.isInteger(vertex) && vertex >= 0 && vertex < part.vertices;
190
+ return (_jsxs("div", { "data-catchlight-body-mark": "", "data-landmark": name, "data-marked": mark ? "" : undefined, "data-nonstandard": standard ? undefined : "", children: [_jsx("span", { "data-catchlight-body-mark-name": "", children: label }), _jsx("span", { "data-catchlight-body-mark-nodes": "", children: slot ? (_jsxs(_Fragment, { children: [_jsx(NodeChip, { node: slot.part, names: names, selected: selected, ...(onSelectNode ? { onSelectNode } : {}) }), _jsx("span", { "data-catchlight-landmark-vertex": "", title: slot.slot, children: slot.vertex == null ? "slot empty" : `vertex ${slot.vertex}` })] })) : (_jsx("span", { "data-catchlight-body-mark-unmarked": "", children: mark ? "Slot removed" : "Not marked" })) }), _jsx("input", { type: "number", "data-catchlight-landmark-vertex-input": "", "aria-label": `${label} vertex index`, placeholder: "vertex", min: 0, max: part ? Math.max(part.vertices - 1, 0) : undefined, step: 1, value: typed, disabled: !part, onChange: (e) => setTyped(e.currentTarget.value) }), _jsx("button", { type: "button", "aria-label": `Set ${label} on the selected part`, title: !part
191
+ ? "Select a part to pin it to"
192
+ : valid
193
+ ? `Pin ${label} to vertex ${vertex} of ${names.get(part.id) ?? part.id}`
194
+ : `Type a vertex index from 0 to ${part.vertices - 1}`, disabled: !valid, onClick: () => part && valid && onMark(part.id, vertex), children: "Set" }), _jsx(IconButton, { icon: "close", label: `Clear ${label}`, disabled: !mark && !added, onClick: onClear })] }));
195
+ }
196
+ function NodeChip({ node, names, selected, onSelectNode, }) {
197
+ return (_jsx("button", { type: "button", "data-catchlight-body-mark-node": "", "data-selected": node === selected ? "" : undefined, title: node, disabled: !onSelectNode, onClick: () => onSelectNode?.(node), children: names.get(node) ?? node }));
198
+ }
199
+ // React requires a controlled input's `onChange`; the native input event is
200
+ // handled once, through `onInput`.
201
+ function noop() { }