@margoengine/inspector 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +623 -3
- package/dist/animation.d.ts +53 -0
- package/dist/animation.js +234 -0
- package/dist/color-D6qetPCJ.js +10 -0
- package/dist/color.d.ts +4 -0
- package/dist/debug-geometry-D61TEkP9.js +61 -0
- package/dist/debug-geometry.d.ts +15 -0
- package/dist/edit-state-Dm3G17js.js +4 -0
- package/dist/edit-state.d.ts +3 -0
- package/dist/edit.d.ts +105 -0
- package/dist/edit.js +379 -0
- package/dist/errors-D8rc8kzg.js +7 -0
- package/dist/frame-panel.d.ts +16 -0
- package/dist/frame.d.ts +264 -0
- package/dist/frame.js +881 -0
- package/dist/gizmo.d.ts +49 -0
- package/dist/gizmo.js +131 -0
- package/dist/gl.d.ts +89 -0
- package/dist/gl.js +284 -0
- package/dist/history.d.ts +65 -0
- package/dist/history.js +66 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +490 -0
- package/dist/mesh-debug.d.ts +115 -0
- package/dist/mesh-debug.js +501 -0
- package/dist/mesh-source-BSQA_1GQ.js +31 -0
- package/dist/packages.d.ts +98 -0
- package/dist/packages.js +337 -0
- package/dist/remote-relay.d.ts +25 -0
- package/dist/remote-relay.js +64 -0
- package/dist/remote.d.ts +175 -0
- package/dist/remote.js +349 -0
- package/dist/resources.d.ts +30 -0
- package/dist/resources.js +42 -0
- package/dist/shaders.d.ts +122 -0
- package/dist/shaders.js +285 -0
- package/dist/snapshot.d.ts +47 -0
- package/dist/snapshot.js +90 -0
- package/dist/textures.d.ts +127 -0
- package/dist/textures.js +380 -0
- package/dist/tools.d.ts +101 -0
- package/dist/tools.js +220 -0
- package/dist/tweak.d.ts +86 -0
- package/dist/tweak.js +291 -0
- package/dist/view-rect-CTC0iGjf.js +23 -0
- package/dist/visibility-7_j5J9Nv.js +7 -0
- package/package.json +149 -6
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
|
|
4
|
+
import { EditHistory } from './history.js';
|
|
5
|
+
/** What an editable value is: a number, a switch, a linear RGB colour or an xyz vector. */
|
|
6
|
+
export type PropertyKind = 'number' | 'boolean' | 'color' | 'vector';
|
|
7
|
+
/** A property value: a number, a switch, or three numbers (a linear RGB colour or a vector). */
|
|
8
|
+
export type PropertyValue = number | boolean | readonly number[];
|
|
9
|
+
/** One editable value of a package object. `get` reads it live; `set` writes it (no range check: use `editProperty`). */
|
|
10
|
+
export interface PackageProperty {
|
|
11
|
+
key: string;
|
|
12
|
+
kind: PropertyKind;
|
|
13
|
+
/** Lowest and highest value a number (or every vector component) may take. */
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
get(): PropertyValue;
|
|
17
|
+
set(value: PropertyValue): void;
|
|
18
|
+
/** False while an optional field is unset and `get` reads its default; an undo back to that state unsets it again. */
|
|
19
|
+
isSet?(): boolean;
|
|
20
|
+
}
|
|
21
|
+
/** An object of another package found on the engine (by shape: no package is imported), with its editable values. */
|
|
22
|
+
export interface PackageObject {
|
|
23
|
+
/** Stable while the object lives, such as `light:clustered:0` or `effect:bloom`. */
|
|
24
|
+
id: string;
|
|
25
|
+
group: 'light' | 'material' | 'shadows' | 'effect' | 'object';
|
|
26
|
+
label: string;
|
|
27
|
+
target: object;
|
|
28
|
+
properties: PackageProperty[];
|
|
29
|
+
/** Why the values are shown but cannot be edited, when they cannot. */
|
|
30
|
+
readOnly?: string;
|
|
31
|
+
}
|
|
32
|
+
type Range = readonly [number, number];
|
|
33
|
+
/**
|
|
34
|
+
* The plain numbers, switches and 3-vectors of an object: its own writable fields, and the accessors with a setter of
|
|
35
|
+
* its class (a `@margoengine/materials` Material's `roughness`, an effect's `enabled`). Keys starting with `_` and
|
|
36
|
+
* `name` are left out.
|
|
37
|
+
*/
|
|
38
|
+
export declare function describeObject(target: object, ranges?: Record<string, Range>, own?: boolean): PackageProperty[];
|
|
39
|
+
/** Options of `findPackageObjects` and `PackageEditor`. */
|
|
40
|
+
export interface PackageObjectsOptions {
|
|
41
|
+
/** Further objects to edit (a `@margoengine/materials` Material, an app's settings), listed under `object`, by label. */
|
|
42
|
+
objects?: Record<string, object>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The lights, glTF materials, shadows and post effects attached to `engine`, found by shape without importing their
|
|
46
|
+
* packages: core's sun and ambient, every light in a `clustered*` plugin's `list`, the PBR materials of the scene's
|
|
47
|
+
* glTF/FBX nodes, the `shadows`/`virtual-shadows`/`clustered:shadows` plugins and every other plugin with an `options`
|
|
48
|
+
* object or a settable accessor (bloom, SSAO, tonemapping...).
|
|
49
|
+
*/
|
|
50
|
+
export declare function findPackageObjects(handle: EngineKernel | Engine, options?: PackageObjectsOptions): PackageObject[];
|
|
51
|
+
/**
|
|
52
|
+
* Writes `value` into `object`'s property `key`, checked against its kind and range, and records it in `history` (one
|
|
53
|
+
* undoable step; repeated edits of one property within the history's window merge, as a slider drag). Returns false
|
|
54
|
+
* when the value is already set.
|
|
55
|
+
* @throws TypeError for an unknown key or a value of the wrong kind; RangeError for a number out of range; MargoError
|
|
56
|
+
* `'state'` for a read-only object.
|
|
57
|
+
*/
|
|
58
|
+
export declare function editProperty(object: PackageObject, key: string, value: PropertyValue, history?: EditHistory): boolean;
|
|
59
|
+
/** Options of `PackageEditor.attach`. */
|
|
60
|
+
export interface PackageEditorOptions extends PackageObjectsOptions {
|
|
61
|
+
/** Element for the panel. Default `document.body`. */
|
|
62
|
+
parent?: HTMLElement;
|
|
63
|
+
/** Undo history to record edits in (pass `inspector.history` to share the Inspector's). Default a new one. */
|
|
64
|
+
history?: EditHistory;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A DOM panel that edits every package object `findPackageObjects` finds, grouped by kind, with undo. An engine
|
|
68
|
+
* plugin: `PackageEditor.attach(engine)`; it lists objects again when plugins, lights or meshes come and go.
|
|
69
|
+
*/
|
|
70
|
+
export declare class PackageEditor implements EnginePlugin {
|
|
71
|
+
readonly name = "inspector:packages";
|
|
72
|
+
readonly element: HTMLElement;
|
|
73
|
+
readonly history: EditHistory;
|
|
74
|
+
private engine?;
|
|
75
|
+
private readonly body;
|
|
76
|
+
private readonly options;
|
|
77
|
+
private readonly inputs;
|
|
78
|
+
private objects;
|
|
79
|
+
private signature;
|
|
80
|
+
private timer?;
|
|
81
|
+
private disposed;
|
|
82
|
+
static attach(engine: EngineKernel, options?: PackageEditorOptions): PackageEditor;
|
|
83
|
+
constructor(options?: PackageEditorOptions);
|
|
84
|
+
setup(engine: Engine): void;
|
|
85
|
+
/** The objects listed now. */
|
|
86
|
+
get list(): readonly PackageObject[];
|
|
87
|
+
/** Lists the objects again when what is attached changed, and shows every value as it is now. */
|
|
88
|
+
refresh(): void;
|
|
89
|
+
/** `editProperty` on a listed object, by id, recorded in this editor's history. */
|
|
90
|
+
set(id: string, key: string, value: PropertyValue): boolean;
|
|
91
|
+
private build;
|
|
92
|
+
private control;
|
|
93
|
+
/** Shows every listed value as it is now (after an undo, or a change made in code). */
|
|
94
|
+
private sync;
|
|
95
|
+
dispose(): void;
|
|
96
|
+
[Symbol.dispose](): void;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
package/dist/packages.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const a=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { n as e } from "./errors-D8rc8kzg.js";
|
|
5
|
+
import { r as t } from "./mesh-source-BSQA_1GQ.js";
|
|
6
|
+
import { EditHistory as n } from "./history.js";
|
|
7
|
+
import { n as r, t as i } from "./color-D6qetPCJ.js";
|
|
8
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
9
|
+
//#region src/packages.ts
|
|
10
|
+
var o = [-Infinity, Infinity], s = [0, Infinity], c = [0, 1], l = [0, Math.PI / 2], u = {
|
|
11
|
+
intensity: s,
|
|
12
|
+
range: s,
|
|
13
|
+
decay: s,
|
|
14
|
+
outerAngle: l,
|
|
15
|
+
innerAngle: l,
|
|
16
|
+
angle: l,
|
|
17
|
+
penumbra: c,
|
|
18
|
+
width: s,
|
|
19
|
+
height: s
|
|
20
|
+
}, d = {
|
|
21
|
+
bloom: {
|
|
22
|
+
strength: [
|
|
23
|
+
.8,
|
|
24
|
+
0,
|
|
25
|
+
4
|
|
26
|
+
],
|
|
27
|
+
threshold: [
|
|
28
|
+
1,
|
|
29
|
+
0,
|
|
30
|
+
100
|
|
31
|
+
],
|
|
32
|
+
exposure: [
|
|
33
|
+
0,
|
|
34
|
+
-10,
|
|
35
|
+
10
|
|
36
|
+
],
|
|
37
|
+
radius: [
|
|
38
|
+
.5,
|
|
39
|
+
0,
|
|
40
|
+
1
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
shadows: {
|
|
44
|
+
distance: [
|
|
45
|
+
500,
|
|
46
|
+
0,
|
|
47
|
+
Infinity
|
|
48
|
+
],
|
|
49
|
+
lambda: [
|
|
50
|
+
.5,
|
|
51
|
+
0,
|
|
52
|
+
1
|
|
53
|
+
],
|
|
54
|
+
lightSize: [
|
|
55
|
+
.02,
|
|
56
|
+
0,
|
|
57
|
+
Infinity
|
|
58
|
+
],
|
|
59
|
+
bias: [
|
|
60
|
+
5e-4,
|
|
61
|
+
0,
|
|
62
|
+
Infinity
|
|
63
|
+
],
|
|
64
|
+
normalBias: [
|
|
65
|
+
.02,
|
|
66
|
+
0,
|
|
67
|
+
Infinity
|
|
68
|
+
],
|
|
69
|
+
casterMargin: [
|
|
70
|
+
100,
|
|
71
|
+
0,
|
|
72
|
+
Infinity
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}, f = (e) => (Array.isArray(e) || e instanceof Float32Array) && e.length === 3 && Array.from(e).every(Number.isFinite), p = (e, t) => typeof t == "boolean" ? "boolean" : typeof t == "number" && Number.isFinite(t) ? "number" : f(t) ? /colou?r/i.test(e) ? "color" : "vector" : null;
|
|
76
|
+
function m(e, t, n, r = o, i) {
|
|
77
|
+
return {
|
|
78
|
+
key: t,
|
|
79
|
+
kind: n,
|
|
80
|
+
min: r[0],
|
|
81
|
+
max: r[1],
|
|
82
|
+
isSet: () => e[t] !== void 0,
|
|
83
|
+
get: () => {
|
|
84
|
+
let n = e[t];
|
|
85
|
+
return n === void 0 ? i : f(n) ? Array.from(n) : n;
|
|
86
|
+
},
|
|
87
|
+
set: (n) => {
|
|
88
|
+
let r = e[t];
|
|
89
|
+
if (n === void 0) delete e[t];
|
|
90
|
+
else if (f(r) && Array.isArray(n)) for (let e = 0; e < 3; e++) r[e] = n[e];
|
|
91
|
+
else e[t] = Array.isArray(n) ? [...n] : n;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function h(e, t, n, r, i = o) {
|
|
96
|
+
let a = r === "number" || r === "boolean" ? 1 : 3;
|
|
97
|
+
return {
|
|
98
|
+
key: n,
|
|
99
|
+
kind: r,
|
|
100
|
+
min: i[0],
|
|
101
|
+
max: i[1],
|
|
102
|
+
get: () => r === "boolean" ? e[t] >= .5 : a === 1 ? e[t] : Array.from(e.slice(t, t + 3)),
|
|
103
|
+
set: (n) => {
|
|
104
|
+
if (typeof n == "boolean") e[t] = +n;
|
|
105
|
+
else if (typeof n == "number") e[t] = n;
|
|
106
|
+
else for (let r = 0; r < 3; r++) e[t + r] = n[r];
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function g(e, t = {}, n = !0) {
|
|
111
|
+
let r = [], i = /* @__PURE__ */ new Set(), a = e, o = (e) => {
|
|
112
|
+
if (i.has(e) || e.startsWith("_") || e === "name") return;
|
|
113
|
+
i.add(e);
|
|
114
|
+
let n;
|
|
115
|
+
try {
|
|
116
|
+
n = a[e];
|
|
117
|
+
} catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let o = p(e, n);
|
|
121
|
+
o && r.push(m(a, e, o, t[e]));
|
|
122
|
+
};
|
|
123
|
+
if (n) for (let [t, n] of Object.entries(Object.getOwnPropertyDescriptors(e))) n.enumerable && (n.writable || n.set) && o(t);
|
|
124
|
+
for (let t = Object.getPrototypeOf(e); t && t !== Object.prototype; t = Object.getPrototypeOf(t)) for (let [e, n] of Object.entries(Object.getOwnPropertyDescriptors(t))) n.get && n.set && o(e);
|
|
125
|
+
return r;
|
|
126
|
+
}
|
|
127
|
+
function _(e, t, n) {
|
|
128
|
+
let r = g(n, u);
|
|
129
|
+
return "color" in n || r.unshift(m(n, "color", "color", o, [
|
|
130
|
+
1,
|
|
131
|
+
1,
|
|
132
|
+
1
|
|
133
|
+
])), "intensity" in n || r.splice(1, 0, m(n, "intensity", "number", s, 1)), {
|
|
134
|
+
id: e,
|
|
135
|
+
group: "light",
|
|
136
|
+
label: t,
|
|
137
|
+
target: n,
|
|
138
|
+
properties: r
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function v(e) {
|
|
142
|
+
let { direction: t, radiance: n, ambient: r } = e.lighting;
|
|
143
|
+
return {
|
|
144
|
+
id: "light:sun",
|
|
145
|
+
group: "light",
|
|
146
|
+
label: "Sun and ambient (core)",
|
|
147
|
+
target: e.lighting,
|
|
148
|
+
properties: [
|
|
149
|
+
h(t, 0, "direction", "vector"),
|
|
150
|
+
h(t, 3, "intensity", "number", s),
|
|
151
|
+
h(n, 0, "color", "color"),
|
|
152
|
+
h(n, 3, "ambientStrength", "number", s),
|
|
153
|
+
h(r, 0, "ambientColor", "color")
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function y(e, t) {
|
|
158
|
+
let n = t.base;
|
|
159
|
+
return {
|
|
160
|
+
id: e,
|
|
161
|
+
group: "material",
|
|
162
|
+
label: `Material ${t.name || e.slice(9)} (gltf/pbr)`,
|
|
163
|
+
target: t,
|
|
164
|
+
properties: [
|
|
165
|
+
h(n, 0, "baseColor", "color", c),
|
|
166
|
+
h(n, 3, "opacity", "number", c),
|
|
167
|
+
h(t.factors, 0, "roughness", "number", c),
|
|
168
|
+
h(t.factors, 1, "metallic", "number", c),
|
|
169
|
+
h(t.factors, 2, "normalScale", "number"),
|
|
170
|
+
h(t.factors, 3, "occlusionStrength", "number", c),
|
|
171
|
+
h(t.emission, 0, "emissive", "color", s),
|
|
172
|
+
h(t.settings, 1, "alphaCutoff", "number", s),
|
|
173
|
+
h(t.settings, 2, "doubleSided", "boolean"),
|
|
174
|
+
m(t, "wireframe", "boolean", o, !1)
|
|
175
|
+
],
|
|
176
|
+
readOnly: t.shading?.version === void 0 ? void 0 : "Its shading (@margoengine/materials) owns these values: edit that Material (pass it in `objects`)."
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function b(e, t) {
|
|
180
|
+
let n = e.options, r = d[e.name] ?? {}, i = [];
|
|
181
|
+
if (n && typeof n == "object" && !Array.isArray(n)) {
|
|
182
|
+
let e = n;
|
|
183
|
+
for (let [t, [n, a, o]] of Object.entries(r)) (e[t] === void 0 || typeof e[t] == "number") && i.push(m(e, t, "number", [a, o], n));
|
|
184
|
+
for (let e of g(n, {})) e.key in r || i.push(e);
|
|
185
|
+
}
|
|
186
|
+
return i.push(...g(e, {}, !1)), {
|
|
187
|
+
id: `${t}:${e.name}`,
|
|
188
|
+
group: t,
|
|
189
|
+
label: `${e.name} (${t === "shadows" ? "shadows" : "effect"})`,
|
|
190
|
+
target: e,
|
|
191
|
+
properties: i
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function x(e, n = {}) {
|
|
195
|
+
let r = a(e), i = [v(r)];
|
|
196
|
+
for (let e of r.plugins.values()) {
|
|
197
|
+
let t = e.list;
|
|
198
|
+
e.name.startsWith("clustered") && Array.isArray(t) && t.forEach((t, n) => {
|
|
199
|
+
t && typeof t == "object" && i.push(_(`light:${e.name}:${n}`, `${e.name} light ${n}`, t));
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
let o = /* @__PURE__ */ new Map();
|
|
203
|
+
for (let e of r.scene.meshes.values()) {
|
|
204
|
+
let n = t(e);
|
|
205
|
+
if (n?.kind === "pbr") for (let e of n.source.primitives) {
|
|
206
|
+
let t = e.material;
|
|
207
|
+
if (!o.has(t) && Array.isArray(t.base) && Array.isArray(t.factors)) {
|
|
208
|
+
let e = `material:${o.size}`;
|
|
209
|
+
o.set(t, e), i.push(y(e, t));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (let e of r.plugins.values()) {
|
|
214
|
+
if (e.name.startsWith("clustered") && !e.name.endsWith("shadows") || e.name.startsWith("inspector")) continue;
|
|
215
|
+
let t = b(e, /shadows$/.test(e.name) ? "shadows" : "effect");
|
|
216
|
+
t.properties.length && i.push(t);
|
|
217
|
+
}
|
|
218
|
+
for (let [e, t] of Object.entries(n.objects ?? {})) i.push({
|
|
219
|
+
id: `object:${e}`,
|
|
220
|
+
group: "object",
|
|
221
|
+
label: e,
|
|
222
|
+
target: t,
|
|
223
|
+
properties: g(t)
|
|
224
|
+
});
|
|
225
|
+
return i;
|
|
226
|
+
}
|
|
227
|
+
var S = (e, t) => Array.isArray(e) && Array.isArray(t) ? e.every((e, n) => e === t[n]) : e === t;
|
|
228
|
+
function C(t, n, r, i) {
|
|
229
|
+
let a = t.properties.find((e) => e.key === n);
|
|
230
|
+
if (!a) throw TypeError(`${t.label} has no property ${n}; pick one of its properties`);
|
|
231
|
+
if (t.readOnly) throw e("state", `${t.label} is read only: ${t.readOnly}`);
|
|
232
|
+
let o = a.kind === "boolean" ? typeof r == "boolean" ? [] : null : a.kind === "number" ? typeof r == "number" ? [r] : null : Array.isArray(r) && r.length === 3 ? r : null;
|
|
233
|
+
if (!o) throw TypeError(`${t.label} ${n} takes a ${a.kind}; pass one`);
|
|
234
|
+
for (let e of o) {
|
|
235
|
+
if (!Number.isFinite(e)) throw RangeError(`${t.label} ${n} must be finite; pass a number`);
|
|
236
|
+
if (e < (a.min ?? -Infinity) || e > (a.max ?? Infinity)) throw RangeError(`${t.label} ${n} must be ${a.min} to ${a.max}; pass a value in range`);
|
|
237
|
+
}
|
|
238
|
+
let s = a.get();
|
|
239
|
+
if (S(s, r)) return !1;
|
|
240
|
+
let c = Array.isArray(s) ? [...s] : s, l = Array.isArray(r) ? [...r] : r, u = a.isSet?.() === !1;
|
|
241
|
+
return a.set(l), i?.record({
|
|
242
|
+
label: `Set ${t.label} ${n}`,
|
|
243
|
+
key: `${t.id}:${n}`,
|
|
244
|
+
undo: () => a.set(u ? void 0 : c),
|
|
245
|
+
redo: () => a.set(l)
|
|
246
|
+
}), !0;
|
|
247
|
+
}
|
|
248
|
+
var w = "\n:host{position:fixed;left:12px;top:12px;width:300px;max-width:calc(100vw - 24px);max-height:calc(100dvh - 24px);overflow:auto;z-index:10001;display:block;color:#202226;background:#fafbfc;border:1px solid #b9bec7;border-radius:4px;font:12px/1.4 system-ui;letter-spacing:0}\n*{box-sizing:border-box}h2{font-size:14px;margin:0;padding:10px 12px;border-bottom:1px solid #d5d9df}details{border-bottom:1px solid #d5d9df;padding:6px 12px}summary{cursor:pointer;font-weight:600}\nlabel{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:28px}input{font:inherit;min-width:0}input[type=number]{width:72px}.axes{display:flex;gap:4px}.axes input{width:56px}\ninput[type=checkbox]{accent-color:#087e67}input[type=color]{width:48px;height:24px;padding:0}input:disabled{opacity:.5}.note{color:#5d636b;margin:4px 0}\n", T = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
249
|
+
static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
250
|
+
let r = new t(n);
|
|
251
|
+
return a(e).use(r), r;
|
|
252
|
+
}
|
|
253
|
+
constructor(e = {}) {
|
|
254
|
+
this.name = "inspector:packages", this.inputs = /* @__PURE__ */ new Map(), this.objects = [], this.signature = "", this.disposed = !1, this.options = e, this.history = e.history ?? new n();
|
|
255
|
+
let t = e.parent ?? document.body, r = t.ownerDocument;
|
|
256
|
+
this.element = r.createElement("div"), this.element.dataset.margoPackageEditor = "";
|
|
257
|
+
let i = this.element.attachShadow({ mode: "open" }), a = r.createElement("style"), o = r.createElement("h2");
|
|
258
|
+
a.textContent = w, o.textContent = "Package objects", this.body = r.createElement("div"), i.append(a, o, this.body), t.append(this.element), this.history.onChange(() => this.sync());
|
|
259
|
+
}
|
|
260
|
+
setup(t) {
|
|
261
|
+
if (this.disposed || this.engine) throw e("attached", "PackageEditor is disposed or already attached; create a new PackageEditor");
|
|
262
|
+
this.engine = t, this.refresh(), this.timer = setInterval(() => this.refresh(), 500);
|
|
263
|
+
}
|
|
264
|
+
get list() {
|
|
265
|
+
return this.objects;
|
|
266
|
+
}
|
|
267
|
+
refresh() {
|
|
268
|
+
if (!this.engine || this.disposed) return;
|
|
269
|
+
let e = x(this.engine, this.options), t = e.map((e) => e.id + ":" + e.properties.map((e) => e.key).join(",")).join("|");
|
|
270
|
+
t !== this.signature && (this.signature = t, this.objects = e, this.build()), this.sync();
|
|
271
|
+
}
|
|
272
|
+
set(e, t, n) {
|
|
273
|
+
let r = this.objects.find((t) => t.id === e);
|
|
274
|
+
if (!r) throw TypeError(`No package object ${e}; pick an id from list`);
|
|
275
|
+
let i = C(r, t, n, this.history);
|
|
276
|
+
return this.sync(), i;
|
|
277
|
+
}
|
|
278
|
+
build() {
|
|
279
|
+
let e = this.element.ownerDocument;
|
|
280
|
+
this.inputs.clear(), this.body.replaceChildren();
|
|
281
|
+
for (let t of this.objects) {
|
|
282
|
+
let n = e.createElement("details"), r = e.createElement("summary");
|
|
283
|
+
if (r.textContent = t.label, n.dataset.object = t.id, n.append(r), t.readOnly) {
|
|
284
|
+
let r = e.createElement("p");
|
|
285
|
+
r.className = "note", r.textContent = t.readOnly, n.append(r);
|
|
286
|
+
}
|
|
287
|
+
for (let e of t.properties) n.append(this.control(t, e));
|
|
288
|
+
this.body.append(n);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
control(e, t) {
|
|
292
|
+
let n = this.element.ownerDocument, i = n.createElement("label"), a = n.createElement("span"), o = (t) => {
|
|
293
|
+
let r = n.createElement("input");
|
|
294
|
+
return r.type = t, r.disabled = !!e.readOnly, t === "number" && (r.step = "any"), r;
|
|
295
|
+
};
|
|
296
|
+
a.textContent = t.key;
|
|
297
|
+
let s;
|
|
298
|
+
if (t.kind === "vector") {
|
|
299
|
+
let e = n.createElement("span");
|
|
300
|
+
e.className = "axes", s = [
|
|
301
|
+
0,
|
|
302
|
+
1,
|
|
303
|
+
2
|
|
304
|
+
].map((n) => {
|
|
305
|
+
let r = o("number");
|
|
306
|
+
return r.setAttribute("aria-label", `${t.key} ${"xyz"[n]}`), e.append(r), r;
|
|
307
|
+
}), i.append(a, e);
|
|
308
|
+
} else s = [o(t.kind === "boolean" ? "checkbox" : t.kind === "color" ? "color" : "number")], i.append(a, s[0]);
|
|
309
|
+
let c = () => t.kind === "boolean" ? s[0].checked : t.kind === "color" ? r(s[0].value) : t.kind === "number" ? Number(s[0].value) : s.map((e) => Number(e.value));
|
|
310
|
+
for (let n of s) n.addEventListener(t.kind === "boolean" ? "change" : "input", () => {
|
|
311
|
+
try {
|
|
312
|
+
C(e, t.key, c(), this.history), n.setCustomValidity("");
|
|
313
|
+
} catch (e) {
|
|
314
|
+
n.setCustomValidity(e.message);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return this.inputs.set(`${e.id}:${t.key}`, {
|
|
318
|
+
input: s,
|
|
319
|
+
property: t
|
|
320
|
+
}), i;
|
|
321
|
+
}
|
|
322
|
+
sync() {
|
|
323
|
+
let e = this.element.shadowRoot?.activeElement;
|
|
324
|
+
for (let { input: t, property: n } of this.inputs.values()) {
|
|
325
|
+
let r = n.get();
|
|
326
|
+
t.includes(e) || (n.kind === "boolean" ? t[0].checked = r : n.kind === "color" ? t[0].value = i(r) : n.kind === "number" ? t[0].value = String(r) : t.forEach((e, t) => e.value = String(r[t])));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
dispose() {
|
|
330
|
+
this.disposed || (this.disposed = !0, clearInterval(this.timer), this.element.remove(), this.inputs.clear(), this.objects = [], this.engine?.sceneOf(this)?.removePlugin(this.name));
|
|
331
|
+
}
|
|
332
|
+
[Symbol.dispose]() {
|
|
333
|
+
this.dispose();
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
export { T as PackageEditor, g as describeObject, C as editProperty, x as findPackageObjects };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" preserve="true" />
|
|
2
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
3
|
+
/** `createRemoteRelay` options. */
|
|
4
|
+
export interface RemoteRelayOptions {
|
|
5
|
+
/** Interface to listen on. Default `127.0.0.1` (this machine only); `0.0.0.0` lets a phone on the LAN reach it. */
|
|
6
|
+
host?: string;
|
|
7
|
+
/** Port, 0 for any free one. Default 0. */
|
|
8
|
+
port?: number;
|
|
9
|
+
/** The secret both pages pass. Default 32 random bytes, base64url. At least 16 characters. */
|
|
10
|
+
token?: string;
|
|
11
|
+
/** Largest message in bytes, 1 to 16,000,000. Default 16,000,000 (a canvas PNG fits). */
|
|
12
|
+
maxBytes?: number;
|
|
13
|
+
}
|
|
14
|
+
/** A running relay. */
|
|
15
|
+
export interface RemoteRelay extends AsyncDisposable {
|
|
16
|
+
/** The URL to give `relayTransport` (a LAN address when listening on every interface). */
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly token: string;
|
|
19
|
+
readonly port: number;
|
|
20
|
+
/** Open streams per role. */
|
|
21
|
+
streams(role: 'target' | 'viewer'): number;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** Starts the relay. Development only: anyone with the token can read and edit the target's scene. */
|
|
25
|
+
export declare function createRemoteRelay(options?: RemoteRelayOptions): Promise<RemoteRelay>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { randomBytes as e, timingSafeEqual as t } from "node:crypto";
|
|
2
|
+
import { createServer as n } from "node:http";
|
|
3
|
+
import { networkInterfaces as r } from "node:os";
|
|
4
|
+
//#region src/remote-relay.ts
|
|
5
|
+
var i = ["target", "viewer"];
|
|
6
|
+
async function a(a = {}) {
|
|
7
|
+
let { host: o = "127.0.0.1", port: s = 0, token: c = e(32).toString("base64url"), maxBytes: l = 16e6 } = a;
|
|
8
|
+
if (typeof c != "string" || c.length < 16) throw TypeError("createRemoteRelay token must be 16 or more characters; pass a longer secret or omit it");
|
|
9
|
+
if (!Number.isInteger(s) || s < 0 || s > 65535) throw RangeError("createRemoteRelay port must be 0 to 65535; pass a port number or 0");
|
|
10
|
+
if (!Number.isInteger(l) || l < 1 || l > 16e6) throw RangeError("createRemoteRelay maxBytes must be 1 to 16000000; pass a byte count in range");
|
|
11
|
+
let u = Buffer.from(`Bearer ${c}`), d = {
|
|
12
|
+
target: /* @__PURE__ */ new Set(),
|
|
13
|
+
viewer: /* @__PURE__ */ new Set()
|
|
14
|
+
}, f = (e, t) => {
|
|
15
|
+
t.setHeader("Access-Control-Allow-Origin", e.headers.origin ?? "*"), t.setHeader("Vary", "Origin"), t.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Margo-Role"), t.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
16
|
+
}, p = n((e, n) => {
|
|
17
|
+
f(e, n);
|
|
18
|
+
let r = (e, t = "") => n.writeHead(e, { "Content-Type": "text/plain" }).end(t);
|
|
19
|
+
if (e.method === "OPTIONS") return r(204);
|
|
20
|
+
let a = Buffer.from(String(e.headers.authorization ?? ""));
|
|
21
|
+
if (a.length !== u.length || !t(a, u)) return r(401, "Wrong or missing token; pass the relay token in the Authorization header");
|
|
22
|
+
let o = e.headers["x-margo-role"];
|
|
23
|
+
if (!i.includes(o)) return r(400, "Missing role; send X-Margo-Role: target or viewer");
|
|
24
|
+
let s = new URL(e.url ?? "/", "http://relay").pathname;
|
|
25
|
+
if (e.method === "GET" && s === "/events") {
|
|
26
|
+
n.writeHead(200, {
|
|
27
|
+
"Content-Type": "application/x-ndjson; charset=utf-8",
|
|
28
|
+
"Cache-Control": "no-store",
|
|
29
|
+
"X-Content-Type-Options": "nosniff"
|
|
30
|
+
}), n.flushHeaders(), d[o].add(n);
|
|
31
|
+
let e = setInterval(() => n.write("\n"), 15e3);
|
|
32
|
+
n.on("close", () => {
|
|
33
|
+
clearInterval(e), d[o].delete(n);
|
|
34
|
+
});
|
|
35
|
+
} else if (e.method === "POST" && s === "/send") {
|
|
36
|
+
let t = [], n = 0;
|
|
37
|
+
e.on("data", (i) => {
|
|
38
|
+
n += i.length, n > l ? (r(413, `Message over ${l} bytes; lower the canvas resolution or raise maxBytes`), e.destroy()) : t.push(i);
|
|
39
|
+
}), e.on("end", () => {
|
|
40
|
+
if (n > l) return;
|
|
41
|
+
let e = Buffer.concat(t).toString("utf8").replace(/[\r\n]+/g, " ");
|
|
42
|
+
for (let t of d[o === "target" ? "viewer" : "target"]) t.write(`${e}\n`);
|
|
43
|
+
r(204);
|
|
44
|
+
});
|
|
45
|
+
} else r(404, "Use GET /events or POST /send");
|
|
46
|
+
});
|
|
47
|
+
await new Promise((e, t) => {
|
|
48
|
+
p.once("error", t), p.listen(s, o, () => e());
|
|
49
|
+
});
|
|
50
|
+
let m = p.address().port, h = `http://${(o === "0.0.0.0" ? Object.values(r()).flat().find((e) => e && e.family === "IPv4" && !e.internal)?.address : void 0) ?? (o === "0.0.0.0" ? "127.0.0.1" : o.includes(":") ? `[${o}]` : o)}:${m}`, g = async () => {
|
|
51
|
+
for (let e of i) for (let t of d[e]) t.end();
|
|
52
|
+
p.closeAllConnections(), await new Promise((e) => p.close(() => e()));
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
url: h,
|
|
56
|
+
token: c,
|
|
57
|
+
port: m,
|
|
58
|
+
streams: (e) => d[e].size,
|
|
59
|
+
close: g,
|
|
60
|
+
[Symbol.asyncDispose]: g
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { a as createRemoteRelay };
|