@catchlight/editor-web 0.0.0-stage → 0.5.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 +27 -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 +24 -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 +162 -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 +9 -0
  37. package/dist/lib/editor-context.js +13 -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 +4573 -0
  111. package/package.json +41 -4
@@ -0,0 +1,18 @@
1
+ import type { Session } from "@catchlight/editor-core";
2
+ import type { IconName } from "../lib/index.js";
3
+ export interface PaletteAction {
4
+ name: string;
5
+ detail: string;
6
+ icon: IconName;
7
+ key?: string;
8
+ run: () => unknown;
9
+ disabled?: boolean;
10
+ }
11
+ export declare function CommandPalette({ session, actions, onClose, }: {
12
+ session: Session | undefined;
13
+ actions: PaletteAction[];
14
+ onClose: () => void;
15
+ }): import("react").JSX.Element;
16
+ export declare function Shortcuts({ onClose }: {
17
+ onClose: () => void;
18
+ }): import("react").JSX.Element;
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { EmptyState, Icon, Modal, flattenTree, kindIcons, kindLabels, useSelection, useEditing, } from "../lib/index.js";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ export function CommandPalette({ session, actions, onClose, }) {
5
+ const [query, setQuery] = useState("");
6
+ const [active, setActive] = useState(0);
7
+ const { select } = useSelection();
8
+ const editing = useEditing();
9
+ const id = useId();
10
+ const list = useRef(null);
11
+ useEffect(() => {
12
+ list.current
13
+ ?.querySelector("[data-active]")
14
+ ?.scrollIntoView({ block: "nearest" });
15
+ }, [active, query]);
16
+ const nodes = session
17
+ ? flattenTree(session.tree()).map((n) => ({
18
+ name: n.name,
19
+ detail: kindLabels[n.kind],
20
+ icon: kindIcons[n.kind],
21
+ run: () => (editing ? editing.guard(() => select(n.id)) : select(n.id)),
22
+ }))
23
+ : [];
24
+ const results = [...actions, ...nodes].filter((a) => !a.disabled &&
25
+ `${a.name} ${a.detail}`.toLowerCase().includes(query.toLowerCase()));
26
+ return (_jsx(Modal, { title: "Command palette", onClose: onClose, children: _jsxs("div", { "data-catchlight-palette": "", children: [_jsxs("label", { "data-catchlight-search": "", children: [_jsx(Icon, { name: "search" }), _jsx("input", { autoFocus: true, role: "combobox", "aria-controls": `${id}-results`, "aria-expanded": "true", "aria-autocomplete": "list", "aria-activedescendant": results.length ? `${id}-${active}` : undefined, "aria-label": "Search commands and nodes", placeholder: "Search commands, tools, and nodes\u2026", value: query, onChange: (e) => {
27
+ setQuery(e.currentTarget.value);
28
+ setActive(0);
29
+ }, onKeyDown: (e) => {
30
+ if (e.key === "ArrowDown") {
31
+ e.preventDefault();
32
+ setActive((i) => Math.max(0, Math.min(results.length - 1, i + 1)));
33
+ }
34
+ if (e.key === "ArrowUp") {
35
+ e.preventDefault();
36
+ setActive((i) => Math.max(0, i - 1));
37
+ }
38
+ if (e.key === "Enter" && results[active]) {
39
+ e.preventDefault();
40
+ onClose();
41
+ results[active]?.run();
42
+ }
43
+ } })] }), _jsxs("div", { ref: list, id: `${id}-results`, role: "listbox", "aria-label": "Commands and nodes", "data-catchlight-palette-results": "", children: [results.map((action, i) => (_jsxs("button", { type: "button", role: "option", id: `${id}-${i}`, "aria-selected": i === active, tabIndex: -1, "data-active": i === active ? "" : undefined, onMouseEnter: () => setActive(i), onClick: () => {
44
+ onClose();
45
+ action.run();
46
+ }, children: [_jsx(Icon, { name: action.icon }), _jsxs("span", { children: [_jsx("strong", { children: action.name }), _jsx("small", { children: action.detail })] }), action.key && _jsx("kbd", { children: action.key })] }, `${i}:${action.name}`))), !results.length && (_jsx(EmptyState, { icon: "search", title: "No matches", children: "Try a node name or an action like \u201Cfit\u201D or \u201Csave\u201D." }))] }), _jsxs("small", { "data-catchlight-palette-hint": "", children: [_jsx("kbd", { children: "\u2191" }), _jsx("kbd", { children: "\u2193" }), " navigate ", _jsx("kbd", { children: "\u21B5" }), " choose ", _jsx("kbd", { children: "esc" }), " close"] })] }) }));
47
+ }
48
+ export function Shortcuts({ onClose }) {
49
+ return (_jsxs(Modal, { title: "Keyboard shortcuts", onClose: onClose, children: [_jsx("p", { "data-catchlight-hint": "", children: "Use Ctrl on Windows and Linux, or \u2318 on macOS." }), _jsx("div", { "data-catchlight-shortcuts": "", children: [
50
+ ["Select and move", "V"],
51
+ ["Hand tool", "H"],
52
+ ["Pan temporarily", "Space + drag"],
53
+ ["Fit the model", "F"],
54
+ ["Focus mode", "Shift F"],
55
+ ["Edit mesh on artwork", "M"],
56
+ ["Open / toggle recording", "R"],
57
+ ["Grid overlay", "G"],
58
+ ["Comment for your agent", "C"],
59
+ ["Find a command or node", "Ctrl / ⌘ K"],
60
+ ["Save model", "Ctrl / ⌘ S"],
61
+ ["Save version", "Ctrl / ⌘ Alt S"],
62
+ ["Open model", "Ctrl / ⌘ O"],
63
+ ["Undo / redo", "Ctrl / ⌘ Z / Shift Z"],
64
+ ["Duplicate selection", "Ctrl / ⌘ D"],
65
+ ["Delete selection", "Delete"],
66
+ ["Nudge selection on canvas", "↑ ↓ ← →"],
67
+ ["Larger nudge", "Shift + arrow"],
68
+ ["Rename a tree node", "F2 / double-click"],
69
+ ["Cancel / clear selection", "Escape"],
70
+ ].map(([label, keys]) => (_jsxs("div", { children: [_jsx("span", { children: label }), _jsx("kbd", { children: keys })] }, label))) })] }));
71
+ }
@@ -0,0 +1,6 @@
1
+ import type { LayerImport } from "../lib/index.js";
2
+ export declare function ImportPanel({ layerImport, onImport, onClose, }: {
3
+ layerImport: LayerImport;
4
+ onImport: () => void;
5
+ onClose: () => void;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Icon, Modal, useEditor } from "../lib/index.js";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ const STEPS = [
5
+ ["blush", "Separate blush", "Lets the blush fade in and out."],
6
+ ["hair_shadow", "Hair shadow", "The front hair shades the face and moves with it."],
7
+ ["clothing_shadows", "Clothing shadows", "Each garment shades what it overlaps."],
8
+ ["tune_hair", "Tune hair motion", "Keeps hair from folding as it swings. Slower to import."],
9
+ ];
10
+ const ART = [
11
+ ["mouth_sheet", "Mouth shapes", "A sheet of nine mouths, for talking and expressions.", "mouth-sheet"],
12
+ ["closed_eyes", "Closed eyes", "The same face with its eyes shut, for blinking.", "closed-eyes"],
13
+ ];
14
+ const SOURCES = [
15
+ ["none", "Off"],
16
+ ["draw", "Draw with GPT"],
17
+ ["file", "Use my image"],
18
+ ];
19
+ export function ImportPanel({ layerImport, onImport, onClose, }) {
20
+ const { layers, options, art, busy, reading, rigging, error, refreshImageModel } = layerImport;
21
+ const folder = useRef(null);
22
+ useEffect(() => {
23
+ void refreshImageModel();
24
+ }, [refreshImageModel]);
25
+ const attached = (name) => layers?.artwork.some(([held]) => held === name) ?? false;
26
+ const images = layers?.artwork.filter(([name]) => name.startsWith("texture:")).length ?? 0;
27
+ const draws = ART.filter(([kind]) => art[kind].source === "draw");
28
+ const toDraw = draws.filter(([kind]) => !art[kind].drawn).length;
29
+ const keyMissing = toDraw > 0 && layerImport.imageModel?.key === "missing";
30
+ return (_jsx(Modal, { title: "Import from layers", onClose: onClose, wide: true, children: _jsxs("div", { "data-catchlight-import": "", "aria-busy": busy, children: [_jsxs("section", { children: [_jsx("h3", { children: "Layers" }), _jsx("p", { "data-catchlight-hint": "", children: "The layers See-through splits a character drawing into: its colour PSD, or its folder of PNGs with info.json." }), _jsxs("div", { "data-catchlight-import-files": "", children: [_jsx(PickButton, { label: layers ? "Choose another PSD…" : "Choose PSD…", accept: ".psd", disabled: busy, onPick: (files) => void layerImport.chooseLayers(files) }), _jsxs("button", { type: "button", disabled: busy, onClick: () => folder.current?.click(), children: [_jsx(Icon, { name: "group", width: "14", height: "14" }), "Choose folder\u2026"] }), _jsx("input", { ref: (input) => {
31
+ folder.current = input;
32
+ input?.setAttribute("webkitdirectory", "");
33
+ }, type: "file", multiple: true, "aria-label": "Layer folder", "data-catchlight-hidden-file": "", onChange: (e) => {
34
+ const files = Array.from(e.currentTarget.files ?? []);
35
+ e.currentTarget.value = "";
36
+ if (files.length > 0)
37
+ void layerImport.chooseLayers(files);
38
+ } }), layers && (_jsxs("span", { "data-catchlight-import-chosen": "", children: [_jsx(Icon, { name: "check", width: "14", height: "14" }), layers.title, images > 0 && ` (${images} layers)`] }))] }), ["drawing", "head"].map((name) => (_jsxs("div", { "data-catchlight-import-row": "", children: [_jsxs("span", { children: [_jsx("strong", { children: name === "drawing" ? "Original drawing" : "Head cut-out" }), _jsx("small", { children: name === "drawing"
39
+ ? "Optional. Restores details the layers lost. Same size as the layers."
40
+ : "Optional. See-through's head.png, which helps restore the ears." })] }), attached(name) ? (_jsx("button", { type: "button", disabled: busy, onClick: () => void layerImport.choosePicture(name, undefined), children: "Remove" })) : (_jsx(PickButton, { label: "Choose\u2026", name: name === "drawing" ? "Choose the original drawing" : "Choose the head cut-out", accept: ".png", disabled: busy || !layers, onPick: ([file]) => void layerImport.choosePicture(name, file) }))] }, name)))] }), _jsxs("section", { children: [_jsx("h3", { children: "Rigging" }), STEPS.map(([name, label, detail]) => (_jsxs("label", { "data-catchlight-import-row": "", children: [_jsxs("span", { children: [_jsx("strong", { children: label }), _jsx("small", { children: detail })] }), _jsx("input", { type: "checkbox", checked: options[name], disabled: busy, onChange: (e) => layerImport.setOption(name, e.currentTarget.checked) })] }, name)))] }), _jsxs("section", { children: [_jsx("h3", { children: "Expressions" }), ART.map(([kind, label, detail, file]) => (_jsx(ArtOption, { layerImport: layerImport, kind: kind, label: label, detail: detail, file: file }, kind))), draws.length > 0 && _jsx(ImageModelSettings, { layerImport: layerImport })] }), error && _jsx("p", { "data-catchlight-import-error": "", role: "alert", children: error }), _jsxs("div", { "data-catchlight-dialog-actions": "", children: [_jsx("span", { "data-catchlight-hint": "", role: "status", children: rigging
41
+ ? "Building the rig. This can take a minute, and the page may pause."
42
+ : reading
43
+ ? "Reading files."
44
+ : busy
45
+ ? "Drawing. Each picture can take a few minutes; you can close this panel."
46
+ : keyMissing
47
+ ? "Save an OpenAI API key to draw, or turn drawing off."
48
+ : toDraw > 0 &&
49
+ `Draws ${toDraw} ${toDraw === 1 ? "picture" : "pictures"} first. OpenAI charges for each.` }), _jsx("button", { type: "button", "data-primary": "", disabled: !layers || busy || keyMissing, onClick: onImport, children: rigging ? "Building…" : reading ? "Reading…" : busy ? "Drawing…" : "Import" })] })] }) }));
50
+ }
51
+ function ArtOption({ layerImport, kind, label, detail, file, }) {
52
+ const id = useId();
53
+ const { layers, art, busy, reading, rigging, imageModel } = layerImport;
54
+ const { source, drawn, picked, drawing, error } = art[kind];
55
+ const picture = source === "draw" ? drawn : source === "file" ? picked : undefined;
56
+ const ready = layers && !reading && !rigging && !drawing && imageModel && imageModel.key !== "missing";
57
+ return (_jsxs("div", { "data-catchlight-import-art": "", role: "group", "aria-labelledby": id, children: [_jsxs("div", { "data-catchlight-import-row": "", children: [_jsxs("span", { children: [_jsx("strong", { id: id, children: label }), _jsx("small", { children: detail })] }), _jsx("select", { "aria-label": label, value: source, disabled: busy, onChange: (e) => layerImport.setArtSource(kind, e.currentTarget.value), children: SOURCES.map(([value, name]) => (_jsx("option", { value: value, children: name }, value))) })] }), source !== "none" && (_jsxs("div", { "data-catchlight-import-picture": "", children: [picture && _jsx(Picture, { bytes: picture, label: label, file: file }), source === "draw" ? (_jsxs("button", { type: "button", disabled: !ready, onClick: () => void layerImport.drawArt(kind), children: [_jsx(Icon, { name: "spark", width: "14", height: "14" }), drawing ? "Drawing…" : drawn ? "Draw again" : "Draw now"] })) : (_jsx(PickButton, { label: picked ? "Choose another…" : "Choose image…", name: `Choose the ${label.toLowerCase()} image`, accept: ".png,.jpg,.jpeg", disabled: busy, onPick: ([image]) => image && void layerImport.chooseArt(kind, image) }))] })), error && _jsx("p", { "data-catchlight-import-error": "", role: "alert", children: error })] }));
58
+ }
59
+ function ImageModelSettings({ layerImport }) {
60
+ const editor = useEditor();
61
+ const { imageModel, busy, changeImageModel } = layerImport;
62
+ const key = useRef(null);
63
+ const [model, setModel] = useState();
64
+ if (!imageModel)
65
+ return null;
66
+ const place = editor.backendKind() === "in-tab"
67
+ ? "in this browser. It is sent only to OpenAI"
68
+ : "in your user settings on the computer running the editor. It is sent only to its OpenAI service";
69
+ return (_jsxs("div", { "data-catchlight-import-model": "", children: [_jsxs("label", { "data-catchlight-form-label": "", children: ["OpenAI image model", _jsx("input", { value: model ?? imageModel.model, disabled: busy, spellCheck: false, onChange: (e) => setModel(e.currentTarget.value), onBlur: () => {
70
+ if (model !== undefined && model !== imageModel.model)
71
+ void changeImageModel({ model });
72
+ setModel(undefined);
73
+ } })] }), imageModel.key === "environment" ? (_jsx("p", { "data-catchlight-hint": "", children: "Using the API key in OPENAI_API_KEY." })) : imageModel.key === "saved" ? (_jsxs("div", { "data-catchlight-import-row": "", children: [_jsxs("span", { children: [_jsx("strong", { children: "OpenAI API key saved" }), _jsxs("small", { children: ["Kept ", place, "."] })] }), _jsx("button", { type: "button", disabled: busy, onClick: () => void changeImageModel({ removeKey: true }), children: "Remove" })] })) : (_jsxs("form", { onSubmit: (e) => {
74
+ e.preventDefault();
75
+ if (key.current)
76
+ void changeImageModel({ key: key.current.value });
77
+ }, children: [_jsxs("label", { "data-catchlight-form-label": "", children: ["OpenAI API key", _jsx("input", { ref: key, type: "password", autoComplete: "off", required: true, disabled: busy })] }), _jsx("button", { type: "submit", disabled: busy, children: "Save key" }), _jsxs("small", { children: ["Kept ", place, "."] })] }))] }));
78
+ }
79
+ function PickButton({ label, name = label, accept, disabled, onPick, }) {
80
+ const input = useRef(null);
81
+ return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", "aria-label": name, disabled: disabled, onClick: () => input.current?.click(), children: [_jsx(Icon, { name: "upload", width: "14", height: "14" }), label] }), _jsx("input", { ref: input, type: "file", accept: accept, tabIndex: -1, "aria-hidden": "true", "data-catchlight-hidden-file": "", onChange: (e) => {
82
+ const files = Array.from(e.currentTarget.files ?? []);
83
+ e.currentTarget.value = "";
84
+ if (files.length > 0)
85
+ onPick(files);
86
+ } })] }));
87
+ }
88
+ function Picture({ bytes, label, file }) {
89
+ const [url, setUrl] = useState();
90
+ useEffect(() => {
91
+ const made = URL.createObjectURL(new Blob([bytes]));
92
+ setUrl(made);
93
+ return () => URL.revokeObjectURL(made);
94
+ }, [bytes]);
95
+ if (!url)
96
+ return null;
97
+ return (_jsxs(_Fragment, { children: [_jsx("img", { src: url, alt: label }), _jsx("a", { href: url, download: `${file}.png`, children: "Save image" })] }));
98
+ }
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="128 128 768 768">
2
+ <circle cx="512" cy="512" r="384" fill="url(#glow)"/>
3
+ <path transform="matrix(0.588742,-0.880715,0.9237,0.617476,-157.941508,443.755766)" d="M320.012,261.766C390.927,259.944 471.166,301.29 479.828,339.735C487.668,374.535 437.295,397.996 348.763,394.497C288.075,392.099 216.42,377.126 211.236,337.507C207.079,305.737 251.252,263.533 320.012,261.766Z" fill="#fff"/>
4
+ <defs>
5
+ <radialGradient id="glow" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(319,286,-286,319,481,471)">
6
+ <stop offset="0" stop-color="#9bd3fd"/>
7
+ <stop offset="0.62" stop-color="#72bffb"/>
8
+ <stop offset="1" stop-color="#68b7f7"/>
9
+ </radialGradient>
10
+ </defs>
11
+ </svg>
@@ -0,0 +1,4 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function Notification({ children }: {
3
+ children: ReactNode;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** Follows the active native dialog into the top layer so a failure stays visible. */
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { createPortal } from "react-dom";
5
+ export function Notification({ children }) {
6
+ const anchor = useRef(null);
7
+ const [dialog, setDialog] = useState(null);
8
+ useEffect(() => {
9
+ const root = anchor.current?.closest(".catchlight");
10
+ if (!root)
11
+ return;
12
+ const refresh = () => setDialog(root.querySelector("dialog[open]"));
13
+ const observer = new MutationObserver(refresh);
14
+ observer.observe(root, {
15
+ childList: true,
16
+ subtree: true,
17
+ attributes: true,
18
+ attributeFilter: ["open"],
19
+ });
20
+ refresh();
21
+ return () => observer.disconnect();
22
+ }, []);
23
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchor, hidden: true }), dialog ? createPortal(children, dialog) : children] }));
24
+ }
@@ -0,0 +1,13 @@
1
+ import type { Session } from "@catchlight/editor-core";
2
+ import type { ViewportCamera } from "../lib/index.js";
3
+ import type { RefObject } from "react";
4
+ export declare function Stage({ session, view, meshView, tool, grid, canvas, onError, }: {
5
+ session: Session | undefined;
6
+ view: ViewportCamera;
7
+ meshView: ViewportCamera;
8
+ tool: "select" | "hand";
9
+ grid: boolean;
10
+ canvas: RefObject<HTMLCanvasElement | null>;
11
+ onError: (cause: unknown) => void;
12
+ }): import("react").JSX.Element;
13
+ export declare function Environment(): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Viewport, MeshCanvas, useEditing, SelectionOverlay, useCanvasSelection, useEditor, useSelection, } from "../lib/index.js";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ export function Stage({ session, view, meshView, tool, grid, canvas, onError, }) {
5
+ const edit = useEditing();
6
+ const { node } = useSelection();
7
+ const drag = useCanvasSelection(session, onError);
8
+ const [size, setSize] = useState({ width: 0, height: 0 });
9
+ const resized = useCallback((next) => {
10
+ setSize(next);
11
+ view.onResize(next);
12
+ }, [view.onResize]);
13
+ return (_jsxs("div", { "data-catchlight-stage": "", "data-empty": session ? undefined : "", "data-tool": tool, "data-mode": edit?.mode, "data-dragging": drag.dragging ? "" : undefined, children: [_jsx(Viewport.Root, { ref: canvas, session: session, camera: view.camera, onCameraChange: view.onCameraChange, onFit: view.onFit, onResize: resized, onError: onError, panMode: tool === "hand", tabIndex: 0, "aria-label": "Model canvas", ...drag.handlers }), edit?.mode === "mesh" && edit.mesh && (_jsx(MeshCanvas, { camera: meshView.camera, onCameraChange: meshView.onCameraChange, onFit: meshView.onFit, onResize: meshView.onResize, panMode: tool === "hand" }, `${session?.id}:${node}`)), grid && edit?.mode !== "mesh" && _jsx("div", { "data-catchlight-grid-overlay": "" }), session &&
14
+ node &&
15
+ tool === "select" &&
16
+ edit?.mode !== "mesh" &&
17
+ (edit?.mode !== "record" || edit.recording) && (_jsx(SelectionOverlay, { session: session, node: node, camera: view.camera, size: size, mesh: edit?.mode === "record" && edit.recordTool === "shape", onError: onError }, `${session.id}:${node}`))] }));
18
+ }
19
+ export function Environment() {
20
+ const editor = useEditor();
21
+ const [tier, setTier] = useState(editor.gpuTier());
22
+ useEffect(() => editor.onGpuChanged(() => setTier(editor.gpuTier())), [editor]);
23
+ return (_jsxs("span", { "data-catchlight-environment": "", children: [_jsx("i", {}), _jsx("span", { "data-catchlight-backend": "", title: "Where edits are applied", children: editor.backendKind() }), _jsx("span", { children: "\u00B7" }), _jsx("span", { "data-catchlight-tier": "", title: "Graphics backend", children: tier ?? "Starting graphics…" })] }));
24
+ }
@@ -0,0 +1,5 @@
1
+ /** Its own module so the DOM exists before `react-dom` loads. */
2
+ declare global {
3
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
4
+ }
5
+ export {};
@@ -0,0 +1,5 @@
1
+ /** Its own module so the DOM exists before `react-dom` loads. */
2
+ import { GlobalRegistrator } from "@happy-dom/global-registrator";
3
+ if (!globalThis.document)
4
+ GlobalRegistrator.register();
5
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@catchlight/editor-web`: the assembled editor with its default theme, and
3
+ * the hooks and unstyled parts it is made of. Theme through the `--cl-*` custom
4
+ * properties on `.catchlight`; rules live in `@layer catchlight`, so any
5
+ * unlayered host rule wins.
6
+ */
7
+ export { CatchlightEditor } from "./editor/CatchlightEditor.js";
8
+ export type { CatchlightEditorProps } from "./editor/CatchlightEditor.js";
9
+ /** Hosts must `import "@catchlight/editor-web/theme.css"`; `CatchlightEditor` is unstyled without it. */
10
+ export declare const themeStylesheet = "@catchlight/editor-web/theme.css";
11
+ export * from "./lib/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@catchlight/editor-web`: the assembled editor with its default theme, and
3
+ * the hooks and unstyled parts it is made of. Theme through the `--cl-*` custom
4
+ * properties on `.catchlight`; rules live in `@layer catchlight`, so any
5
+ * unlayered host rule wins.
6
+ */
7
+ export { CatchlightEditor } from "./editor/CatchlightEditor.js";
8
+ /** Hosts must `import "@catchlight/editor-web/theme.css"`; `CatchlightEditor` is unstyled without it. */
9
+ export const themeStylesheet = "@catchlight/editor-web/theme.css";
10
+ export * from "./lib/index.js";
@@ -0,0 +1,10 @@
1
+ import type { ClipInfo, Session } from "@catchlight/editor-core";
2
+ import type { ErrorHandler } from "./authoring.js";
3
+ /** What a clip's lanes drive, by kind, as in "3 params, 2 controls, 1 viseme". */
4
+ export declare function describeLanes(clip: ClipInfo): string;
5
+ export declare function clipSeconds(clip: ClipInfo): number;
6
+ /** The model's animations, each played in this tab only. */
7
+ export declare function AnimationsPanel({ session, onError }: {
8
+ session: Session;
9
+ onError: ErrorHandler;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { EmptyState, Icon } from "./controls.js";
3
+ import { ANIMATIONS, ExtensionWarnings, UnreadNotice, WarningMark, plural, useClips, useExtensionWarnings, usePlayhead, usePlayingClip, warningsOn, } from "./official.js";
4
+ /** What a clip's lanes drive, by kind, as in "3 params, 2 controls, 1 viseme". */
5
+ export function describeLanes(clip) {
6
+ const count = { param: 0, control: 0, expression: 0, viseme: 0 };
7
+ for (const lane of clip.lanes)
8
+ count[lane.target.kind] += 1;
9
+ const parts = [
10
+ count.param && plural(count.param, "param"),
11
+ count.control && plural(count.control, "control"),
12
+ count.expression && plural(count.expression, "expression"),
13
+ count.viseme && plural(count.viseme, "viseme"),
14
+ ].filter(Boolean);
15
+ return parts.length ? parts.join(", ") : "No lanes";
16
+ }
17
+ export function clipSeconds(clip) {
18
+ return clip.length * clip.timestep;
19
+ }
20
+ /** The model's animations, each played in this tab only. */
21
+ export function AnimationsPanel({ session, onError }) {
22
+ const read = useClips(session);
23
+ const { warnings, params: warned } = useExtensionWarnings(session, ANIMATIONS);
24
+ const playing = usePlayingClip(session);
25
+ if (read.unread !== undefined)
26
+ return (_jsx("div", { "data-catchlight-animations-panel": "", children: _jsx(UnreadNotice, { what: "animations", why: read.unread }) }));
27
+ const { clips } = read.body;
28
+ return (_jsxs("div", { "data-catchlight-animations-panel": "", children: [_jsx(ExtensionWarnings, { warnings: warnings }), !clips.length ? (_jsx(EmptyState, { icon: "film", title: "No animations", children: "Animations come from an import or the command line. Once the model has one, play it here." })) : (_jsx("ul", { "data-catchlight-clips": "", "aria-label": "Animations", children: clips.map((clip) => {
29
+ const on = playing === clip.name;
30
+ const marks = warningsOn(warned, clip.lanes.flatMap((l) => (l.target.kind === "param" ? [l.target.param] : [])));
31
+ return (_jsxs("li", { "data-catchlight-clip": "", "data-name": clip.name, "data-playing": on ? "" : undefined, "data-warned": marks.length ? "" : undefined, children: [_jsx("button", { type: "button", "data-catchlight-clip-play": "", "aria-pressed": on, "aria-label": on ? `Stop ${clip.name}` : `Play ${clip.name}`, title: on ? "Stop" : "Play", onClick: () => {
32
+ if (on)
33
+ session.stop();
34
+ else if (!session.play(clip.name))
35
+ onError(new Error(`The animation “${clip.name}” could not be played.`));
36
+ }, children: _jsx(Icon, { name: on ? "stop" : "play", width: "13", height: "13" }) }), _jsx("span", { "data-catchlight-clip-name": "", title: clip.name, children: clip.name }), _jsx(WarningMark, { warnings: marks }), _jsx("span", { "data-catchlight-clip-lanes": "", children: describeLanes(clip) }), on ? (_jsx(Playhead, { session: session, clip: clip })) : (_jsx("span", { "data-catchlight-clip-duration": "", children: seconds(clipSeconds(clip)) }))] }, clip.name));
37
+ }) }))] }));
38
+ }
39
+ /** Re-renders every frame while the clip plays, apart from the list around it. */
40
+ function Playhead({ session, clip }) {
41
+ const at = usePlayhead(session);
42
+ if (!at || at.name !== clip.name)
43
+ return null;
44
+ return (_jsxs("span", { "data-catchlight-clip-playhead": "", "aria-label": `${clip.name} playhead`, children: [seconds(at.time), " / ", seconds(clipSeconds(clip)), _jsxs("small", { children: ["frame ", Math.floor(at.frame)] })] }));
45
+ }
46
+ function seconds(s) {
47
+ return `${s.toFixed(2)} s`;
48
+ }
@@ -0,0 +1,17 @@
1
+ import type { NodeId, NodeKind, ResponseBody, Session, SessionEditCommand, SessionReplicaQueryCommand, StatusInfo, TreeNode } from "@catchlight/editor-core";
2
+ import type { IconName } from "./controls.js";
3
+ export type ErrorHandler = (cause: unknown) => void;
4
+ /** Responses are ordered by request and cannot overwrite a newer session's status. */
5
+ export declare function useSessionStatus(session: Session | undefined): StatusInfo | undefined;
6
+ export declare function useCommand(session: Session, onError: ErrorHandler): {
7
+ run: (command: SessionEditCommand, attachments?: readonly (readonly [string, Uint8Array])[]) => Promise<ResponseBody | undefined>;
8
+ busy: boolean;
9
+ };
10
+ export declare function useModelQuery<R extends ResponseBody["result"]>(session: Session, command: SessionReplicaQueryCommand, result: R): Extract<ResponseBody, {
11
+ result: R;
12
+ }>;
13
+ export declare function flattenTree(root: TreeNode): TreeNode[];
14
+ export declare const kindLabels: Record<NodeKind, string>;
15
+ export declare const kindIcons: Record<NodeKind, IconName>;
16
+ /** A part whose image cannot be read is removed. Multiple images import in tree order. */
17
+ export declare function importArtwork(session: Session, files: readonly File[], parent: NodeId): Promise<NodeId | undefined>;
@@ -0,0 +1,116 @@
1
+ /** Queries key on their arguments too, so a changed selection reads immediately. */
2
+ import { COMMAND_BYTES } from "@catchlight/editor-core";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { useRevision } from "./replica.js";
5
+ /** Responses are ordered by request and cannot overwrite a newer session's status. */
6
+ export function useSessionStatus(session) {
7
+ const [status, setStatus] = useState();
8
+ useEffect(() => {
9
+ setStatus(undefined);
10
+ if (!session)
11
+ return;
12
+ let request = 0, live = true;
13
+ const refresh = () => {
14
+ const current = ++request;
15
+ void session
16
+ .queryServer({ cmd: "session_get" })
17
+ .then((body) => {
18
+ if (live && current === request && body.result === "status")
19
+ setStatus(body.status);
20
+ })
21
+ .catch(() => {
22
+ if (live && current === request)
23
+ setStatus(undefined);
24
+ });
25
+ };
26
+ const unsubscribe = session.subscribe(refresh);
27
+ refresh();
28
+ return () => {
29
+ live = false;
30
+ unsubscribe();
31
+ };
32
+ }, [session]);
33
+ return status;
34
+ }
35
+ export function useCommand(session, onError) {
36
+ const [pending, setPending] = useState(0);
37
+ const live = useRef({ session, onError });
38
+ live.current = { session, onError };
39
+ const run = useCallback(async (command, attachments) => {
40
+ setPending((n) => n + 1);
41
+ try {
42
+ return attachments || COMMAND_BYTES[command.cmd]
43
+ ? await live.current.session.sendWith(command, attachments ?? [])
44
+ : await live.current.session.send(command);
45
+ }
46
+ catch (cause) {
47
+ live.current.onError(cause);
48
+ return undefined;
49
+ }
50
+ finally {
51
+ setPending((n) => n - 1);
52
+ }
53
+ }, []);
54
+ return { run, busy: pending > 0 };
55
+ }
56
+ export function useModelQuery(session, command, result) {
57
+ const rev = useRevision(session);
58
+ const key = JSON.stringify(command);
59
+ return useMemo(() => {
60
+ const body = session.query(JSON.parse(key));
61
+ if (body.result !== result)
62
+ throw new Error(`Could not read ${result}.`);
63
+ return body;
64
+ }, [session, rev, key, result]);
65
+ }
66
+ export function flattenTree(root) {
67
+ return [root, ...root.children.flatMap(flattenTree)];
68
+ }
69
+ export const kindLabels = {
70
+ group: "Group",
71
+ part: "Part",
72
+ composite: "Composite",
73
+ mesh_group: "Mesh group",
74
+ motion_response: "Motion response",
75
+ };
76
+ export const kindIcons = {
77
+ group: "group",
78
+ part: "part",
79
+ composite: "composite",
80
+ mesh_group: "mesh",
81
+ motion_response: "response",
82
+ };
83
+ /** A part whose image cannot be read is removed. Multiple images import in tree order. */
84
+ export async function importArtwork(session, files, parent) {
85
+ let last;
86
+ for (const file of files) {
87
+ if (!/\.(png|tga)$/i.test(file.name))
88
+ throw new Error("Choose PNG or TGA artwork. Open a .clm file to load a complete model.");
89
+ const created = await session.send({
90
+ cmd: "node_add",
91
+ parent,
92
+ kind: "part",
93
+ name: file.name.replace(/\.[^.]+$/, ""),
94
+ });
95
+ if (created.result !== "node")
96
+ throw new Error("The image part could not be created.");
97
+ try {
98
+ await session.sendWith({
99
+ cmd: "texture_add",
100
+ node: created.node,
101
+ encoding: /\.tga$/i.test(file.name) ? "tga" : "png",
102
+ }, [["texture", new Uint8Array(await file.arrayBuffer())]]);
103
+ await session.send({
104
+ cmd: "mesh_generate",
105
+ node: created.node,
106
+ mode: { mode: "grid", cols: 2, rows: 2 },
107
+ });
108
+ last = created.node;
109
+ }
110
+ catch (cause) {
111
+ await session.send({ cmd: "node_delete", node: created.node });
112
+ throw cause;
113
+ }
114
+ }
115
+ return last;
116
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * One param's bindings on one node, as grids of keypoints over each binding's
3
+ * own key positions. `data-set`/`data-unset` mark authored cells; unset cells
4
+ * are derived at puppet build. Clicking a cell poses, it does not edit.
5
+ */
6
+ import type { NodeId, ParamId, Session } from "@catchlight/editor-core";
7
+ import type { ComponentProps } from "react";
8
+ type ErrorSink = ((cause: unknown) => void) | undefined;
9
+ export interface BindingGridRootProps extends Omit<ComponentProps<"div">, "children" | "onError"> {
10
+ session: Session;
11
+ node: NodeId | undefined;
12
+ param: ParamId | undefined;
13
+ onError?: ErrorSink;
14
+ }
15
+ export declare function BindingGridRoot({ session, node, param, onError, ...rest }: BindingGridRootProps): import("react").JSX.Element;
16
+ export declare const BindingGrid: {
17
+ Root: typeof BindingGridRoot;
18
+ };
19
+ export {};