worldorbit 2.5.2
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.md +5 -0
- package/README.md +250 -0
- package/dist/browser/core/dist/index.js +4009 -0
- package/dist/browser/markdown/dist/index.js +3951 -0
- package/dist/browser/viewer/dist/index.js +5981 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +84 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +16 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +25 -0
- package/dist/normalize.d.ts +2 -0
- package/dist/normalize.js +243 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +126 -0
- package/dist/render.d.ts +6 -0
- package/dist/render.js +683 -0
- package/dist/tokenize.d.ts +4 -0
- package/dist/tokenize.js +68 -0
- package/dist/types.d.ts +208 -0
- package/dist/types.js +1 -0
- package/dist/unpkg/core/dist/index.js +4081 -0
- package/dist/unpkg/markdown/dist/index.js +3979 -0
- package/dist/unpkg/test.html +1 -0
- package/dist/unpkg/viewer/dist/index.js +6038 -0
- package/dist/unpkg/worldorbit-core.min.js +5 -0
- package/dist/unpkg/worldorbit-markdown.min.js +81 -0
- package/dist/unpkg/worldorbit-viewer.min.js +232 -0
- package/dist/unpkg/worldorbit.d.ts +2 -0
- package/dist/unpkg/worldorbit.js +2 -0
- package/dist/unpkg/worldorbit.min.js +236 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +31 -0
- package/dist/viewer-state.d.ts +16 -0
- package/dist/viewer-state.js +130 -0
- package/dist/viewer.d.ts +2 -0
- package/dist/viewer.js +434 -0
- package/package.json +64 -0
- package/packages/core/README.md +13 -0
- package/packages/core/dist/atlas-edit.d.ts +11 -0
- package/packages/core/dist/atlas-edit.js +210 -0
- package/packages/core/dist/diagnostics.d.ts +10 -0
- package/packages/core/dist/diagnostics.js +109 -0
- package/packages/core/dist/draft-parse.d.ts +3 -0
- package/packages/core/dist/draft-parse.js +642 -0
- package/packages/core/dist/draft.d.ts +15 -0
- package/packages/core/dist/draft.js +343 -0
- package/packages/core/dist/errors.d.ts +7 -0
- package/packages/core/dist/errors.js +16 -0
- package/packages/core/dist/format.d.ts +4 -0
- package/packages/core/dist/format.js +364 -0
- package/packages/core/dist/index.d.ts +28 -0
- package/packages/core/dist/index.js +44 -0
- package/packages/core/dist/load.d.ts +4 -0
- package/packages/core/dist/load.js +130 -0
- package/packages/core/dist/markdown.d.ts +2 -0
- package/packages/core/dist/markdown.js +37 -0
- package/packages/core/dist/normalize.d.ts +2 -0
- package/packages/core/dist/normalize.js +304 -0
- package/packages/core/dist/parse.d.ts +2 -0
- package/packages/core/dist/parse.js +133 -0
- package/packages/core/dist/scene.d.ts +3 -0
- package/packages/core/dist/scene.js +1484 -0
- package/packages/core/dist/schema.d.ts +8 -0
- package/packages/core/dist/schema.js +298 -0
- package/packages/core/dist/tokenize.d.ts +4 -0
- package/packages/core/dist/tokenize.js +68 -0
- package/packages/core/dist/types.d.ts +382 -0
- package/packages/core/dist/types.js +1 -0
- package/packages/core/dist/validate.d.ts +2 -0
- package/packages/core/dist/validate.js +56 -0
- package/packages/editor/dist/editor.d.ts +2 -0
- package/packages/editor/dist/editor.js +2620 -0
- package/packages/editor/dist/index.d.ts +2 -0
- package/packages/editor/dist/index.js +1 -0
- package/packages/editor/dist/types.d.ts +53 -0
- package/packages/editor/dist/types.js +1 -0
- package/packages/markdown/README.md +9 -0
- package/packages/markdown/dist/html.d.ts +3 -0
- package/packages/markdown/dist/html.js +57 -0
- package/packages/markdown/dist/index.d.ts +4 -0
- package/packages/markdown/dist/index.js +3 -0
- package/packages/markdown/dist/rehype.d.ts +10 -0
- package/packages/markdown/dist/rehype.js +49 -0
- package/packages/markdown/dist/remark.d.ts +9 -0
- package/packages/markdown/dist/remark.js +28 -0
- package/packages/markdown/dist/types.d.ts +11 -0
- package/packages/markdown/dist/types.js +1 -0
- package/packages/viewer/README.md +12 -0
- package/packages/viewer/dist/atlas-state.d.ts +12 -0
- package/packages/viewer/dist/atlas-state.js +251 -0
- package/packages/viewer/dist/atlas-viewer.d.ts +2 -0
- package/packages/viewer/dist/atlas-viewer.js +448 -0
- package/packages/viewer/dist/custom-element.d.ts +1 -0
- package/packages/viewer/dist/custom-element.js +64 -0
- package/packages/viewer/dist/embed.d.ts +20 -0
- package/packages/viewer/dist/embed.js +138 -0
- package/packages/viewer/dist/index.d.ts +9 -0
- package/packages/viewer/dist/index.js +8 -0
- package/packages/viewer/dist/minimap.d.ts +3 -0
- package/packages/viewer/dist/minimap.js +63 -0
- package/packages/viewer/dist/render.d.ts +6 -0
- package/packages/viewer/dist/render.js +585 -0
- package/packages/viewer/dist/theme.d.ts +4 -0
- package/packages/viewer/dist/theme.js +98 -0
- package/packages/viewer/dist/tooltip.d.ts +3 -0
- package/packages/viewer/dist/tooltip.js +154 -0
- package/packages/viewer/dist/types.d.ts +256 -0
- package/packages/viewer/dist/types.js +1 -0
- package/packages/viewer/dist/viewer-state.d.ts +19 -0
- package/packages/viewer/dist/viewer-state.js +162 -0
- package/packages/viewer/dist/viewer.d.ts +2 -0
- package/packages/viewer/dist/viewer.js +1156 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createWorldOrbitEditor } from "./editor.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AtlasDocumentPath, AtlasResolvedDiagnostic, WorldOrbitAtlasDocument, WorldOrbitAtlasSystem, WorldOrbitAtlasViewpoint, WorldOrbitObject } from "@worldorbit/core";
|
|
2
|
+
export interface WorldOrbitEditorSelection {
|
|
3
|
+
path: AtlasDocumentPath | null;
|
|
4
|
+
}
|
|
5
|
+
export interface WorldOrbitEditorSnapshot {
|
|
6
|
+
source: string;
|
|
7
|
+
atlasDocument: WorldOrbitAtlasDocument;
|
|
8
|
+
diagnostics: AtlasResolvedDiagnostic[];
|
|
9
|
+
selection: WorldOrbitEditorSelection | null;
|
|
10
|
+
}
|
|
11
|
+
export interface WorldOrbitEditorOptions {
|
|
12
|
+
source?: string;
|
|
13
|
+
atlasDocument?: WorldOrbitAtlasDocument;
|
|
14
|
+
showTextPane?: boolean;
|
|
15
|
+
showInspector?: boolean;
|
|
16
|
+
showPreview?: boolean;
|
|
17
|
+
viewerWidth?: number;
|
|
18
|
+
viewerHeight?: number;
|
|
19
|
+
shortcuts?: boolean;
|
|
20
|
+
onChange?: (snapshot: WorldOrbitEditorSnapshot) => void;
|
|
21
|
+
onDiagnosticsChange?: (diagnostics: AtlasResolvedDiagnostic[]) => void;
|
|
22
|
+
onSelectionChange?: (selection: WorldOrbitEditorSelection | null) => void;
|
|
23
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface WorldOrbitEditor {
|
|
26
|
+
setSource(source: string): void;
|
|
27
|
+
setAtlasDocument(document: WorldOrbitAtlasDocument): void;
|
|
28
|
+
getSource(): string;
|
|
29
|
+
getAtlasDocument(): WorldOrbitAtlasDocument;
|
|
30
|
+
getDiagnostics(): AtlasResolvedDiagnostic[];
|
|
31
|
+
getSelection(): WorldOrbitEditorSelection | null;
|
|
32
|
+
isDirty(): boolean;
|
|
33
|
+
markSaved(): void;
|
|
34
|
+
selectPath(path: AtlasDocumentPath | null): void;
|
|
35
|
+
canUndo(): boolean;
|
|
36
|
+
canRedo(): boolean;
|
|
37
|
+
undo(): boolean;
|
|
38
|
+
redo(): boolean;
|
|
39
|
+
addObject(type?: WorldOrbitObject["type"]): string;
|
|
40
|
+
addViewpoint(): string;
|
|
41
|
+
addAnnotation(): string;
|
|
42
|
+
addMetadata(key?: string, value?: string): string;
|
|
43
|
+
removeSelection(): boolean;
|
|
44
|
+
exportSvg(): string;
|
|
45
|
+
exportEmbedMarkup(): string;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
48
|
+
export interface WorldOrbitEditorFormState {
|
|
49
|
+
selection: WorldOrbitEditorSelection | null;
|
|
50
|
+
system: WorldOrbitAtlasSystem | null;
|
|
51
|
+
viewpoints: WorldOrbitAtlasViewpoint[];
|
|
52
|
+
objects: WorldOrbitObject[];
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @worldorbit/markdown
|
|
2
|
+
|
|
3
|
+
WorldOrbit markdown contains build-time integration for fenced `worldorbit` blocks in Unified, Remark, and Rehype pipelines.
|
|
4
|
+
|
|
5
|
+
Main exports:
|
|
6
|
+
|
|
7
|
+
- `renderWorldOrbitBlock(source, options?)`
|
|
8
|
+
- `remarkWorldOrbit(options?)`
|
|
9
|
+
- `rehypeWorldOrbit(options?)`
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { loadWorldOrbitSource, renderDocumentToScene, } from "@worldorbit/core";
|
|
2
|
+
import { createEmbedPayload, createWorldOrbitEmbedMarkup, renderSceneToSvg, } from "@worldorbit/viewer";
|
|
3
|
+
export function renderWorldOrbitBlock(source, options = {}) {
|
|
4
|
+
try {
|
|
5
|
+
const loaded = loadWorldOrbitSource(source);
|
|
6
|
+
const scene = renderDocumentToScene(loaded.document, resolveSourceRenderOptions(loaded, options));
|
|
7
|
+
if ((options.mode ?? "static") === "interactive") {
|
|
8
|
+
return createWorldOrbitEmbedMarkup(createEmbedPayload(scene, "interactive", {
|
|
9
|
+
initialViewpointId: options.initialViewpointId,
|
|
10
|
+
initialSelectionObjectId: options.initialSelectionObjectId,
|
|
11
|
+
initialFilter: options.initialFilter ?? null,
|
|
12
|
+
atlasState: options.atlasState ?? null,
|
|
13
|
+
minimap: options.minimap,
|
|
14
|
+
}), {
|
|
15
|
+
className: options.className ?? "worldorbit-block worldorbit-interactive",
|
|
16
|
+
theme: options.theme,
|
|
17
|
+
layers: options.layers,
|
|
18
|
+
subtitle: options.subtitle,
|
|
19
|
+
preset: options.preset,
|
|
20
|
+
initialViewpointId: options.initialViewpointId,
|
|
21
|
+
initialSelectionObjectId: options.initialSelectionObjectId,
|
|
22
|
+
initialFilter: options.initialFilter ?? null,
|
|
23
|
+
atlasState: options.atlasState ?? null,
|
|
24
|
+
minimap: options.minimap,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return `<figure class="${escapeAttribute(options.className ?? "worldorbit-block worldorbit-static")}">${renderSceneToSvg(scene, options)}</figure>`;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (options.strict) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
return renderWorldOrbitError(error instanceof Error ? error.message : String(error));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function renderWorldOrbitError(message) {
|
|
37
|
+
return `<pre class="worldorbit-error">WorldOrbit error: ${escapeHtml(message)}</pre>`;
|
|
38
|
+
}
|
|
39
|
+
function escapeHtml(value) {
|
|
40
|
+
return value
|
|
41
|
+
.replaceAll("&", "&")
|
|
42
|
+
.replaceAll("<", "<")
|
|
43
|
+
.replaceAll(">", ">");
|
|
44
|
+
}
|
|
45
|
+
function escapeAttribute(value) {
|
|
46
|
+
return escapeHtml(value).replaceAll("\"", """);
|
|
47
|
+
}
|
|
48
|
+
function resolveSourceRenderOptions(loaded, options) {
|
|
49
|
+
const atlasDocument = loaded.atlasDocument ?? loaded.draftDocument;
|
|
50
|
+
if (options.preset || !atlasDocument?.system?.defaults.preset) {
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...options,
|
|
55
|
+
preset: atlasDocument.system.defaults.preset,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorldOrbitMarkdownOptions } from "./types.js";
|
|
2
|
+
interface HastNode {
|
|
3
|
+
type: string;
|
|
4
|
+
tagName?: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
properties?: Record<string, unknown>;
|
|
7
|
+
children?: HastNode[];
|
|
8
|
+
}
|
|
9
|
+
export declare function rehypeWorldOrbit(options?: WorldOrbitMarkdownOptions): (tree: HastNode) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { renderWorldOrbitBlock } from "./html.js";
|
|
2
|
+
export function rehypeWorldOrbit(options = {}) {
|
|
3
|
+
return function transform(tree) {
|
|
4
|
+
visitHastNodes(tree, (node, index, parent) => {
|
|
5
|
+
if (!parent || index === -1 || node.type !== "element" || node.tagName !== "pre") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const codeElement = node.children?.[0];
|
|
9
|
+
if (!codeElement || codeElement.type !== "element" || codeElement.tagName !== "code") {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const classNames = normalizeClassNames(codeElement.properties?.className);
|
|
13
|
+
if (!classNames.includes("language-worldorbit")) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const source = collectText(codeElement);
|
|
17
|
+
parent.children[index] = {
|
|
18
|
+
type: "raw",
|
|
19
|
+
value: renderWorldOrbitBlock(source, options),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function visitHastNodes(node, visitor, parent = null) {
|
|
25
|
+
const children = node.children ?? [];
|
|
26
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
27
|
+
const child = children[index];
|
|
28
|
+
visitor(child, index, node);
|
|
29
|
+
visitHastNodes(child, visitor, node);
|
|
30
|
+
}
|
|
31
|
+
if (!parent) {
|
|
32
|
+
visitor(node, -1, null);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function normalizeClassNames(value) {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return value.map((entry) => String(entry));
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
return value.split(/\s+/).filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
function collectText(node) {
|
|
45
|
+
if (node.type === "text") {
|
|
46
|
+
return node.value ?? "";
|
|
47
|
+
}
|
|
48
|
+
return (node.children ?? []).map((child) => collectText(child)).join("");
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorldOrbitMarkdownOptions } from "./types.js";
|
|
2
|
+
interface MdNode {
|
|
3
|
+
type: string;
|
|
4
|
+
lang?: string | null;
|
|
5
|
+
value?: string;
|
|
6
|
+
children?: MdNode[];
|
|
7
|
+
}
|
|
8
|
+
export declare function remarkWorldOrbit(options?: WorldOrbitMarkdownOptions): (tree: MdNode) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { renderWorldOrbitBlock } from "./html.js";
|
|
2
|
+
export function remarkWorldOrbit(options = {}) {
|
|
3
|
+
return function transform(tree) {
|
|
4
|
+
visitMdNodes(tree, (node, index, parent) => {
|
|
5
|
+
if (!parent || index === -1 || node.type !== "code" || !isWorldOrbitLanguage(node.lang)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
parent.children[index] = {
|
|
9
|
+
type: "html",
|
|
10
|
+
value: renderWorldOrbitBlock(node.value ?? "", options),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function visitMdNodes(node, visitor, parent = null) {
|
|
16
|
+
const children = node.children ?? [];
|
|
17
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
18
|
+
const child = children[index];
|
|
19
|
+
visitor(child, index, node);
|
|
20
|
+
visitMdNodes(child, visitor, node);
|
|
21
|
+
}
|
|
22
|
+
if (!parent) {
|
|
23
|
+
visitor(node, -1, null);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isWorldOrbitLanguage(language) {
|
|
27
|
+
return (language ?? "").trim().toLowerCase() === "worldorbit";
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SvgRenderOptions, ViewerAtlasState, ViewerFilter, WorldOrbitEmbedMode } from "@worldorbit/viewer";
|
|
2
|
+
export interface WorldOrbitMarkdownOptions extends SvgRenderOptions {
|
|
3
|
+
mode?: WorldOrbitEmbedMode;
|
|
4
|
+
strict?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
initialViewpointId?: string;
|
|
7
|
+
initialSelectionObjectId?: string;
|
|
8
|
+
initialFilter?: ViewerFilter | null;
|
|
9
|
+
atlasState?: ViewerAtlasState | null;
|
|
10
|
+
minimap?: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @worldorbit/viewer
|
|
2
|
+
|
|
3
|
+
WorldOrbit viewer contains scene-to-SVG rendering, theme presets, browser interactivity, and embed hydration helpers.
|
|
4
|
+
|
|
5
|
+
Main exports:
|
|
6
|
+
|
|
7
|
+
- `renderSceneToSvg(scene, options?)`
|
|
8
|
+
- `renderDocumentToSvg(document, options?)`
|
|
9
|
+
- `renderSourceToSvg(source, options?)`
|
|
10
|
+
- `createInteractiveViewer(container, options)`
|
|
11
|
+
- `createWorldOrbitEmbedMarkup(payload, options?)`
|
|
12
|
+
- `mountWorldOrbitEmbeds(root?, options?)`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RenderScene, RenderSceneViewpoint } from "@worldorbit/core";
|
|
2
|
+
import type { ViewerAtlasState, ViewerBookmark, ViewerFilter, ViewerLayerOptions, ViewerRenderOptions, ViewerSearchResult, ViewerState } from "./types.js";
|
|
3
|
+
export declare function normalizeViewerFilter(filter: ViewerFilter | null | undefined): ViewerFilter | null;
|
|
4
|
+
export declare function isViewerFilterActive(filter: ViewerFilter | null | undefined): boolean;
|
|
5
|
+
export declare function computeVisibleObjectIds(scene: RenderScene, filter: ViewerFilter | null | undefined): Set<string>;
|
|
6
|
+
export declare function searchSceneObjects(scene: RenderScene, query: string, limit?: number): ViewerSearchResult[];
|
|
7
|
+
export declare function createAtlasStateSnapshot(viewerState: ViewerState, renderOptions: ViewerRenderOptions, filter: ViewerFilter | null, viewpointId: string | null): ViewerAtlasState;
|
|
8
|
+
export declare function serializeViewerAtlasState(state: ViewerAtlasState): string;
|
|
9
|
+
export declare function deserializeViewerAtlasState(serialized: string): ViewerAtlasState;
|
|
10
|
+
export declare function createViewerBookmark(name: string, label: string | undefined, atlasState: ViewerAtlasState): ViewerBookmark;
|
|
11
|
+
export declare function sceneViewpointToLayerOptions(viewpoint: RenderSceneViewpoint | null | undefined): ViewerLayerOptions | undefined;
|
|
12
|
+
export declare function viewpointToViewerFilter(viewpoint: RenderSceneViewpoint | null | undefined): ViewerFilter | null;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
export function normalizeViewerFilter(filter) {
|
|
2
|
+
if (!filter) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
const normalized = {
|
|
6
|
+
query: filter.query?.trim() || undefined,
|
|
7
|
+
objectTypes: dedupeList(filter.objectTypes ?? []),
|
|
8
|
+
tags: dedupeList((filter.tags ?? []).map((tag) => tag.trim()).filter(Boolean)),
|
|
9
|
+
groupIds: dedupeList((filter.groupIds ?? []).map((groupId) => groupId.trim()).filter(Boolean)),
|
|
10
|
+
includeAncestors: filter.includeAncestors ?? true,
|
|
11
|
+
};
|
|
12
|
+
return isViewerFilterActive(normalized) ? normalized : null;
|
|
13
|
+
}
|
|
14
|
+
export function isViewerFilterActive(filter) {
|
|
15
|
+
return Boolean(filter &&
|
|
16
|
+
(filter.query?.trim() ||
|
|
17
|
+
filter.objectTypes?.length ||
|
|
18
|
+
filter.tags?.length ||
|
|
19
|
+
filter.groupIds?.length));
|
|
20
|
+
}
|
|
21
|
+
export function computeVisibleObjectIds(scene, filter) {
|
|
22
|
+
const normalized = normalizeViewerFilter(filter);
|
|
23
|
+
const visible = new Set();
|
|
24
|
+
for (const object of scene.objects) {
|
|
25
|
+
if (object.hidden) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (matchesObjectFilter(object, normalized)) {
|
|
29
|
+
visible.add(object.objectId);
|
|
30
|
+
if (normalized?.includeAncestors !== false) {
|
|
31
|
+
for (const ancestorId of object.ancestorIds) {
|
|
32
|
+
visible.add(ancestorId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!normalized) {
|
|
38
|
+
return new Set(scene.objects.filter((object) => !object.hidden).map((object) => object.objectId));
|
|
39
|
+
}
|
|
40
|
+
return visible;
|
|
41
|
+
}
|
|
42
|
+
export function searchSceneObjects(scene, query, limit = 12) {
|
|
43
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
44
|
+
if (!normalizedQuery) {
|
|
45
|
+
return scene.objects
|
|
46
|
+
.filter((object) => !object.hidden)
|
|
47
|
+
.slice()
|
|
48
|
+
.sort((left, right) => left.label.localeCompare(right.label))
|
|
49
|
+
.slice(0, limit)
|
|
50
|
+
.map((object) => createSearchResult(object, 1));
|
|
51
|
+
}
|
|
52
|
+
return scene.objects
|
|
53
|
+
.filter((object) => !object.hidden)
|
|
54
|
+
.map((object) => ({
|
|
55
|
+
object,
|
|
56
|
+
score: scoreSearchMatch(object, normalizedQuery),
|
|
57
|
+
}))
|
|
58
|
+
.filter((entry) => entry.score > 0)
|
|
59
|
+
.sort((left, right) => right.score - left.score || left.object.label.localeCompare(right.object.label))
|
|
60
|
+
.slice(0, limit)
|
|
61
|
+
.map((entry) => createSearchResult(entry.object, entry.score));
|
|
62
|
+
}
|
|
63
|
+
export function createAtlasStateSnapshot(viewerState, renderOptions, filter, viewpointId) {
|
|
64
|
+
return {
|
|
65
|
+
version: "2.0",
|
|
66
|
+
viewpointId,
|
|
67
|
+
viewerState: { ...viewerState },
|
|
68
|
+
renderOptions: {
|
|
69
|
+
preset: renderOptions.preset,
|
|
70
|
+
projection: renderOptions.projection,
|
|
71
|
+
layers: renderOptions.layers ? { ...renderOptions.layers } : undefined,
|
|
72
|
+
scaleModel: renderOptions.scaleModel ? { ...renderOptions.scaleModel } : undefined,
|
|
73
|
+
},
|
|
74
|
+
filter: normalizeViewerFilter(filter),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function serializeViewerAtlasState(state) {
|
|
78
|
+
return encodeURIComponent(JSON.stringify(state));
|
|
79
|
+
}
|
|
80
|
+
export function deserializeViewerAtlasState(serialized) {
|
|
81
|
+
const raw = JSON.parse(decodeURIComponent(serialized));
|
|
82
|
+
return {
|
|
83
|
+
version: "2.0",
|
|
84
|
+
viewpointId: raw.viewpointId ?? null,
|
|
85
|
+
viewerState: {
|
|
86
|
+
scale: raw.viewerState?.scale ?? 1,
|
|
87
|
+
rotationDeg: raw.viewerState?.rotationDeg ?? 0,
|
|
88
|
+
translateX: raw.viewerState?.translateX ?? 0,
|
|
89
|
+
translateY: raw.viewerState?.translateY ?? 0,
|
|
90
|
+
selectedObjectId: raw.viewerState?.selectedObjectId ?? null,
|
|
91
|
+
},
|
|
92
|
+
renderOptions: {
|
|
93
|
+
preset: raw.renderOptions?.preset,
|
|
94
|
+
projection: raw.renderOptions?.projection,
|
|
95
|
+
layers: raw.renderOptions?.layers ? { ...raw.renderOptions.layers } : undefined,
|
|
96
|
+
scaleModel: raw.renderOptions?.scaleModel
|
|
97
|
+
? { ...raw.renderOptions.scaleModel }
|
|
98
|
+
: undefined,
|
|
99
|
+
},
|
|
100
|
+
filter: normalizeViewerFilter(raw.filter ?? null),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function createViewerBookmark(name, label, atlasState) {
|
|
104
|
+
const normalizedName = name.trim() || "bookmark";
|
|
105
|
+
return {
|
|
106
|
+
id: normalizedName
|
|
107
|
+
.toLowerCase()
|
|
108
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
109
|
+
.replace(/^-+|-+$/g, "") || "bookmark",
|
|
110
|
+
label: label?.trim() || normalizedName,
|
|
111
|
+
atlasState: {
|
|
112
|
+
...atlasState,
|
|
113
|
+
viewerState: { ...atlasState.viewerState },
|
|
114
|
+
renderOptions: {
|
|
115
|
+
...atlasState.renderOptions,
|
|
116
|
+
layers: atlasState.renderOptions.layers ? { ...atlasState.renderOptions.layers } : undefined,
|
|
117
|
+
scaleModel: atlasState.renderOptions.scaleModel
|
|
118
|
+
? { ...atlasState.renderOptions.scaleModel }
|
|
119
|
+
: undefined,
|
|
120
|
+
},
|
|
121
|
+
filter: atlasState.filter ? { ...atlasState.filter } : null,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function sceneViewpointToLayerOptions(viewpoint) {
|
|
126
|
+
if (!viewpoint) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const hasLayerState = Object.keys(viewpoint.layers).length > 0;
|
|
130
|
+
if (!hasLayerState) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
background: viewpoint.layers.background,
|
|
135
|
+
guides: viewpoint.layers.guides,
|
|
136
|
+
orbits: viewpoint.layers["orbits-front"] === undefined && viewpoint.layers["orbits-back"] === undefined
|
|
137
|
+
? undefined
|
|
138
|
+
: viewpoint.layers["orbits-front"] !== false || viewpoint.layers["orbits-back"] !== false,
|
|
139
|
+
objects: viewpoint.layers.objects,
|
|
140
|
+
labels: viewpoint.layers.labels,
|
|
141
|
+
metadata: viewpoint.layers.metadata,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function viewpointToViewerFilter(viewpoint) {
|
|
145
|
+
if (!viewpoint?.filter) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return normalizeViewerFilter({
|
|
149
|
+
query: viewpoint.filter.query ?? undefined,
|
|
150
|
+
objectTypes: viewpoint.filter.objectTypes,
|
|
151
|
+
tags: viewpoint.filter.tags,
|
|
152
|
+
groupIds: viewpoint.filter.groupIds,
|
|
153
|
+
includeAncestors: true,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function createSearchResult(object, score) {
|
|
157
|
+
return {
|
|
158
|
+
objectId: object.objectId,
|
|
159
|
+
label: object.label,
|
|
160
|
+
type: object.object.type,
|
|
161
|
+
score,
|
|
162
|
+
groupId: object.groupId,
|
|
163
|
+
parentId: object.parentId,
|
|
164
|
+
tags: Array.isArray(object.object.properties.tags)
|
|
165
|
+
? object.object.properties.tags.filter((entry) => typeof entry === "string")
|
|
166
|
+
: [],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function matchesObjectFilter(object, filter) {
|
|
170
|
+
if (!filter) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
if (filter.objectTypes?.length && !filter.objectTypes.includes(object.object.type)) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
if (filter.groupIds?.length && (!object.groupId || !filter.groupIds.includes(object.groupId))) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (filter.tags?.length) {
|
|
180
|
+
const objectTags = Array.isArray(object.object.properties.tags)
|
|
181
|
+
? object.object.properties.tags.filter((entry) => typeof entry === "string")
|
|
182
|
+
: [];
|
|
183
|
+
if (!filter.tags.every((tag) => objectTags.includes(tag))) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (filter.query?.trim()) {
|
|
188
|
+
const haystack = buildSearchText(object.object, object.label).toLowerCase();
|
|
189
|
+
const tokens = filter.query
|
|
190
|
+
.toLowerCase()
|
|
191
|
+
.split(/\s+/)
|
|
192
|
+
.filter(Boolean);
|
|
193
|
+
if (!tokens.every((token) => haystack.includes(token))) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
function scoreSearchMatch(object, query) {
|
|
200
|
+
const id = object.objectId.toLowerCase();
|
|
201
|
+
const label = object.label.toLowerCase();
|
|
202
|
+
const haystack = buildSearchText(object.object, object.label).toLowerCase();
|
|
203
|
+
let score = 0;
|
|
204
|
+
if (id === query || label === query) {
|
|
205
|
+
score += 120;
|
|
206
|
+
}
|
|
207
|
+
else if (id.startsWith(query) || label.startsWith(query)) {
|
|
208
|
+
score += 96;
|
|
209
|
+
}
|
|
210
|
+
else if (id.includes(query) || label.includes(query)) {
|
|
211
|
+
score += 72;
|
|
212
|
+
}
|
|
213
|
+
const tokens = query.split(/\s+/).filter(Boolean);
|
|
214
|
+
if (tokens.every((token) => haystack.includes(token))) {
|
|
215
|
+
score += 32;
|
|
216
|
+
}
|
|
217
|
+
if (object.object.type === query) {
|
|
218
|
+
score += 24;
|
|
219
|
+
}
|
|
220
|
+
const tags = Array.isArray(object.object.properties.tags)
|
|
221
|
+
? object.object.properties.tags.filter((entry) => typeof entry === "string")
|
|
222
|
+
: [];
|
|
223
|
+
if (tags.some((tag) => tag.toLowerCase() === query)) {
|
|
224
|
+
score += 18;
|
|
225
|
+
}
|
|
226
|
+
return score;
|
|
227
|
+
}
|
|
228
|
+
function buildSearchText(object, label) {
|
|
229
|
+
const infoValues = Object.values(object.info);
|
|
230
|
+
const propertyValues = Object.values(object.properties)
|
|
231
|
+
.flatMap((value) => {
|
|
232
|
+
if (Array.isArray(value)) {
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
if (typeof value === "object" && value && "value" in value) {
|
|
236
|
+
return [String(value.value), String(value.unit ?? "")];
|
|
237
|
+
}
|
|
238
|
+
return [String(value)];
|
|
239
|
+
})
|
|
240
|
+
.filter(Boolean);
|
|
241
|
+
return [
|
|
242
|
+
object.id,
|
|
243
|
+
label,
|
|
244
|
+
object.type,
|
|
245
|
+
...propertyValues,
|
|
246
|
+
...infoValues,
|
|
247
|
+
].join(" ");
|
|
248
|
+
}
|
|
249
|
+
function dedupeList(values) {
|
|
250
|
+
return [...new Set(values)];
|
|
251
|
+
}
|