@treasuryspatial/viewer-orchestrator 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boot.d.ts +3 -0
- package/dist/boot.d.ts.map +1 -0
- package/dist/boot.js +86 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/merge.d.ts +7 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +26 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +29 -0
package/dist/boot.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot.d.ts","sourceRoot":"","sources":["../src/boot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAqB,MAAM,SAAS,CAAC;AAOrE,eAAO,MAAM,gBAAgB,QAAO,kBAAkB,EA0ErD,CAAC"}
|
package/dist/boot.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const advancePhase = (state, next) => ({
|
|
2
|
+
...state,
|
|
3
|
+
...next,
|
|
4
|
+
});
|
|
5
|
+
export const buildBootModules = () => [
|
|
6
|
+
{
|
|
7
|
+
id: "boot:error",
|
|
8
|
+
kind: "bootstrap",
|
|
9
|
+
priority: 0,
|
|
10
|
+
apply: (state, context) => {
|
|
11
|
+
if (!context.error)
|
|
12
|
+
return state;
|
|
13
|
+
return advancePhase(state, { phase: "ERROR", error: context.error });
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "boot:viewer",
|
|
18
|
+
kind: "viewer",
|
|
19
|
+
priority: 10,
|
|
20
|
+
apply: (state, context) => {
|
|
21
|
+
if (!context.viewer)
|
|
22
|
+
return state;
|
|
23
|
+
return advancePhase(state, { phase: "VIEWER_READY" });
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "boot:tools",
|
|
28
|
+
kind: "tools",
|
|
29
|
+
priority: 20,
|
|
30
|
+
apply: (state, context) => {
|
|
31
|
+
if (!context.tools || context.tools.length === 0)
|
|
32
|
+
return state;
|
|
33
|
+
return advancePhase(state, { phase: "TOOLS_READY" });
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "boot:tool",
|
|
38
|
+
kind: "tools",
|
|
39
|
+
priority: 30,
|
|
40
|
+
apply: (state, context) => {
|
|
41
|
+
if (!context.activeToolId)
|
|
42
|
+
return state;
|
|
43
|
+
return advancePhase(state, { phase: "TOOLS_READY", activeToolId: context.activeToolId });
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "boot:overrides",
|
|
48
|
+
kind: "presets",
|
|
49
|
+
priority: 40,
|
|
50
|
+
apply: (state, context) => {
|
|
51
|
+
if (!context.activeToolId || !context.runtimePresetId)
|
|
52
|
+
return state;
|
|
53
|
+
return advancePhase(state, {
|
|
54
|
+
phase: "OVERRIDES_APPLIED",
|
|
55
|
+
activeToolId: context.activeToolId,
|
|
56
|
+
runtimePresetId: context.runtimePresetId,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "boot:geometry",
|
|
62
|
+
kind: "geometry",
|
|
63
|
+
priority: 50,
|
|
64
|
+
apply: (state, context) => {
|
|
65
|
+
if (!context.geometryReady)
|
|
66
|
+
return state;
|
|
67
|
+
return advancePhase(state, {
|
|
68
|
+
phase: "GEOMETRY_READY",
|
|
69
|
+
activeToolId: context.activeToolId ?? state.activeToolId,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "boot:ready",
|
|
75
|
+
kind: "ui",
|
|
76
|
+
priority: 60,
|
|
77
|
+
apply: (state, context) => {
|
|
78
|
+
if (!context.geometryReady)
|
|
79
|
+
return state;
|
|
80
|
+
return advancePhase(state, {
|
|
81
|
+
phase: "READY",
|
|
82
|
+
activeToolId: context.activeToolId ?? state.activeToolId,
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export { mergeRenderPreset } from "./merge";
|
|
3
|
+
export { buildBootModules } from "./boot";
|
|
4
|
+
import type { ViewerOrchestrator, ViewerOrchestratorOptions } from "./types";
|
|
5
|
+
export declare function createViewerOrchestrator(options: ViewerOrchestratorOptions): ViewerOrchestrator;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,KAAK,EAKV,kBAAkB,EAClB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAWjB,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CA4D/F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export { mergeRenderPreset } from "./merge";
|
|
3
|
+
export { buildBootModules } from "./boot";
|
|
4
|
+
const emitEvent = (timeline, onEvent, event) => {
|
|
5
|
+
timeline.push(event);
|
|
6
|
+
onEvent?.(event);
|
|
7
|
+
};
|
|
8
|
+
export function createViewerOrchestrator(options) {
|
|
9
|
+
const { viewer, presets, onEvent } = options;
|
|
10
|
+
let state = { phase: "IDLE" };
|
|
11
|
+
const timeline = [];
|
|
12
|
+
const context = {
|
|
13
|
+
viewer,
|
|
14
|
+
presets,
|
|
15
|
+
};
|
|
16
|
+
const updateState = (next, detail) => {
|
|
17
|
+
state = next;
|
|
18
|
+
emitEvent(timeline, onEvent, {
|
|
19
|
+
phase: state.phase,
|
|
20
|
+
ts: Date.now(),
|
|
21
|
+
detail,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
updateState(state, { reason: "init" });
|
|
25
|
+
return {
|
|
26
|
+
getState: () => ({ ...state }),
|
|
27
|
+
getTimeline: () => [...timeline],
|
|
28
|
+
applyModules: (modules) => {
|
|
29
|
+
const sorted = [...modules].sort((a, b) => a.priority - b.priority);
|
|
30
|
+
sorted.forEach((module) => {
|
|
31
|
+
try {
|
|
32
|
+
state = module.apply(state, context);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
state = { phase: "ERROR", error: error?.message ?? "orchestrator module error" };
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
updateState(state, { moduleCount: sorted.length });
|
|
39
|
+
},
|
|
40
|
+
setRuntimePreset: (preset) => {
|
|
41
|
+
viewer.setRuntimePreset(preset);
|
|
42
|
+
updateState({
|
|
43
|
+
...state,
|
|
44
|
+
runtimePresetId: preset.id ?? "__runtime__",
|
|
45
|
+
}, { action: "setRuntimePreset" });
|
|
46
|
+
},
|
|
47
|
+
setContext: (partial) => {
|
|
48
|
+
Object.assign(context, partial);
|
|
49
|
+
updateState({
|
|
50
|
+
...state,
|
|
51
|
+
activeToolId: context.activeToolId ?? state.activeToolId,
|
|
52
|
+
runtimePresetId: context.runtimePresetId ?? state.runtimePresetId,
|
|
53
|
+
}, { action: "setContext" });
|
|
54
|
+
},
|
|
55
|
+
dispose: () => {
|
|
56
|
+
updateState({ phase: "IDLE" }, { action: "dispose" });
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RenderPresetDefinition } from "@treasuryspatial/viewer-kit";
|
|
2
|
+
/**
|
|
3
|
+
* Merge render preset definitions with a predictable override order.
|
|
4
|
+
* Arrays are overwritten (not concatenated) to preserve explicit overrides.
|
|
5
|
+
*/
|
|
6
|
+
export declare const mergeRenderPreset: (base: RenderPresetDefinition, ...overrides: Array<RenderPresetDefinition | undefined | null>) => RenderPresetDefinition;
|
|
7
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAiB1E;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,sBAAsB,EAC5B,GAAG,WAAW,KAAK,CAAC,sBAAsB,GAAG,SAAS,GAAG,IAAI,CAAC,KAC7D,sBAOF,CAAC"}
|
package/dist/merge.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
|
+
const mergeRecords = (target, source) => {
|
|
3
|
+
const next = { ...target };
|
|
4
|
+
Object.entries(source).forEach(([key, value]) => {
|
|
5
|
+
if (isRecord(value) && isRecord(next[key])) {
|
|
6
|
+
next[key] = mergeRecords(next[key], value);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
next[key] = value;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return next;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Merge render preset definitions with a predictable override order.
|
|
16
|
+
* Arrays are overwritten (not concatenated) to preserve explicit overrides.
|
|
17
|
+
*/
|
|
18
|
+
export const mergeRenderPreset = (base, ...overrides) => {
|
|
19
|
+
let result = { ...base };
|
|
20
|
+
overrides.forEach((override) => {
|
|
21
|
+
if (!override)
|
|
22
|
+
return;
|
|
23
|
+
result = mergeRecords(result, override);
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PresetCatalog, RenderPresetDefinition, ViewerHandle } from "@treasuryspatial/viewer-kit";
|
|
2
|
+
import type { PluginManifest, ToolManifest } from "@treasuryspatial/plugin-manifest";
|
|
3
|
+
import type { UiManifest } from "@treasuryspatial/ui-manifest";
|
|
4
|
+
export type OrchestratorPhase = "IDLE" | "BOOTSTRAP_READY" | "VIEWER_READY" | "TOOLS_READY" | "OVERRIDES_APPLIED" | "GEOMETRY_READY" | "READY" | "ERROR";
|
|
5
|
+
export type OrchestratorEvent = {
|
|
6
|
+
phase: OrchestratorPhase;
|
|
7
|
+
ts: number;
|
|
8
|
+
detail?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export type OrchestratorState = {
|
|
11
|
+
phase: OrchestratorPhase;
|
|
12
|
+
activeToolId?: string;
|
|
13
|
+
runtimePresetId?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
export type OrchestratorModuleKind = "bootstrap" | "viewer" | "tools" | "lighting" | "environment" | "materials" | "presets" | "postfx" | "camera" | "geometry" | "ui";
|
|
17
|
+
export type OrchestratorContext = {
|
|
18
|
+
viewer: ViewerHandle;
|
|
19
|
+
presets: PresetCatalog;
|
|
20
|
+
uiManifest?: UiManifest;
|
|
21
|
+
tools?: ToolManifest[];
|
|
22
|
+
plugins?: Record<string, PluginManifest>;
|
|
23
|
+
activeToolId?: string;
|
|
24
|
+
runtimePresetId?: string;
|
|
25
|
+
geometryReady?: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
export type OrchestratorModule = {
|
|
29
|
+
id: string;
|
|
30
|
+
kind: OrchestratorModuleKind;
|
|
31
|
+
priority: number;
|
|
32
|
+
apply: (state: OrchestratorState, context: OrchestratorContext) => OrchestratorState;
|
|
33
|
+
dispose?: (context: OrchestratorContext) => void;
|
|
34
|
+
};
|
|
35
|
+
export type ViewerOrchestratorOptions = {
|
|
36
|
+
viewer: ViewerHandle;
|
|
37
|
+
presets: PresetCatalog;
|
|
38
|
+
onEvent?: (event: OrchestratorEvent) => void;
|
|
39
|
+
};
|
|
40
|
+
export type ViewerOrchestrator = {
|
|
41
|
+
getState: () => OrchestratorState;
|
|
42
|
+
getTimeline: () => OrchestratorEvent[];
|
|
43
|
+
applyModules: (modules: OrchestratorModule[]) => void;
|
|
44
|
+
setRuntimePreset: (preset: RenderPresetDefinition) => void;
|
|
45
|
+
setContext: (partial: Partial<OrchestratorContext>) => void;
|
|
46
|
+
dispose: () => void;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,iBAAiB,GACjB,cAAc,GACd,aAAa,GACb,mBAAmB,GACnB,gBAAgB,GAChB,OAAO,GACP,OAAO,CAAC;AAEZ,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,iBAAiB,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,iBAAiB,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B,WAAW,GACX,QAAQ,GACR,OAAO,G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AAC,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@treasuryspatial/viewer-orchestrator",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"typecheck": "tsc -b --pretty false --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@treasuryspatial/plugin-manifest": "^0.1.3",
|
|
26
|
+
"@treasuryspatial/ui-manifest": "^0.1.3",
|
|
27
|
+
"@treasuryspatial/viewer-kit": "^0.2.0"
|
|
28
|
+
}
|
|
29
|
+
}
|