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,210 @@
|
|
|
1
|
+
import { materializeAtlasDocument } from "./draft.js";
|
|
2
|
+
import { validateDocumentWithDiagnostics } from "./diagnostics.js";
|
|
3
|
+
export function createEmptyAtlasDocument(systemId = "WorldOrbit") {
|
|
4
|
+
return {
|
|
5
|
+
format: "worldorbit",
|
|
6
|
+
version: "2.0",
|
|
7
|
+
sourceVersion: "1.0",
|
|
8
|
+
system: {
|
|
9
|
+
type: "system",
|
|
10
|
+
id: systemId,
|
|
11
|
+
title: systemId,
|
|
12
|
+
defaults: {
|
|
13
|
+
view: "topdown",
|
|
14
|
+
scale: null,
|
|
15
|
+
units: null,
|
|
16
|
+
preset: null,
|
|
17
|
+
theme: null,
|
|
18
|
+
},
|
|
19
|
+
atlasMetadata: {},
|
|
20
|
+
viewpoints: [],
|
|
21
|
+
annotations: [],
|
|
22
|
+
},
|
|
23
|
+
objects: [],
|
|
24
|
+
diagnostics: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function cloneAtlasDocument(document) {
|
|
28
|
+
return structuredClone(document);
|
|
29
|
+
}
|
|
30
|
+
export function listAtlasDocumentPaths(document) {
|
|
31
|
+
const paths = [{ kind: "system" }, { kind: "defaults" }];
|
|
32
|
+
if (document.system) {
|
|
33
|
+
for (const key of Object.keys(document.system.atlasMetadata).sort()) {
|
|
34
|
+
paths.push({ kind: "metadata", key });
|
|
35
|
+
}
|
|
36
|
+
for (const viewpoint of [...document.system.viewpoints].sort(compareIdLike)) {
|
|
37
|
+
paths.push({ kind: "viewpoint", id: viewpoint.id });
|
|
38
|
+
}
|
|
39
|
+
for (const annotation of [...document.system.annotations].sort(compareIdLike)) {
|
|
40
|
+
paths.push({ kind: "annotation", id: annotation.id });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const object of [...document.objects].sort(compareIdLike)) {
|
|
44
|
+
paths.push({ kind: "object", id: object.id });
|
|
45
|
+
}
|
|
46
|
+
return paths;
|
|
47
|
+
}
|
|
48
|
+
export function getAtlasDocumentNode(document, path) {
|
|
49
|
+
switch (path.kind) {
|
|
50
|
+
case "system":
|
|
51
|
+
return document.system;
|
|
52
|
+
case "defaults":
|
|
53
|
+
return document.system?.defaults ?? null;
|
|
54
|
+
case "metadata":
|
|
55
|
+
return path.key ? (document.system?.atlasMetadata[path.key] ?? null) : null;
|
|
56
|
+
case "object":
|
|
57
|
+
return path.id ? findObject(document, path.id) : null;
|
|
58
|
+
case "viewpoint":
|
|
59
|
+
return path.id ? findViewpoint(document.system, path.id) : null;
|
|
60
|
+
case "annotation":
|
|
61
|
+
return path.id ? findAnnotation(document.system, path.id) : null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function upsertAtlasDocumentNode(document, path, value) {
|
|
65
|
+
const next = cloneAtlasDocument(document);
|
|
66
|
+
const system = ensureSystem(next);
|
|
67
|
+
switch (path.kind) {
|
|
68
|
+
case "system":
|
|
69
|
+
next.system = value;
|
|
70
|
+
return next;
|
|
71
|
+
case "defaults":
|
|
72
|
+
system.defaults = {
|
|
73
|
+
...system.defaults,
|
|
74
|
+
...value,
|
|
75
|
+
};
|
|
76
|
+
return next;
|
|
77
|
+
case "metadata":
|
|
78
|
+
if (!path.key) {
|
|
79
|
+
throw new Error('Metadata updates require a "key" value.');
|
|
80
|
+
}
|
|
81
|
+
if (value === null || value === undefined || value === "") {
|
|
82
|
+
delete system.atlasMetadata[path.key];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
system.atlasMetadata[path.key] = String(value);
|
|
86
|
+
}
|
|
87
|
+
return next;
|
|
88
|
+
case "object":
|
|
89
|
+
if (!path.id) {
|
|
90
|
+
throw new Error('Object updates require an "id" value.');
|
|
91
|
+
}
|
|
92
|
+
upsertById(next.objects, value);
|
|
93
|
+
return next;
|
|
94
|
+
case "viewpoint":
|
|
95
|
+
if (!path.id) {
|
|
96
|
+
throw new Error('Viewpoint updates require an "id" value.');
|
|
97
|
+
}
|
|
98
|
+
upsertById(system.viewpoints, value);
|
|
99
|
+
return next;
|
|
100
|
+
case "annotation":
|
|
101
|
+
if (!path.id) {
|
|
102
|
+
throw new Error('Annotation updates require an "id" value.');
|
|
103
|
+
}
|
|
104
|
+
upsertById(system.annotations, value);
|
|
105
|
+
return next;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function updateAtlasDocumentNode(document, path, updater) {
|
|
109
|
+
return upsertAtlasDocumentNode(document, path, updater(getAtlasDocumentNode(document, path)));
|
|
110
|
+
}
|
|
111
|
+
export function removeAtlasDocumentNode(document, path) {
|
|
112
|
+
const next = cloneAtlasDocument(document);
|
|
113
|
+
const system = ensureSystem(next);
|
|
114
|
+
switch (path.kind) {
|
|
115
|
+
case "metadata":
|
|
116
|
+
if (path.key) {
|
|
117
|
+
delete system.atlasMetadata[path.key];
|
|
118
|
+
}
|
|
119
|
+
return next;
|
|
120
|
+
case "object":
|
|
121
|
+
if (path.id) {
|
|
122
|
+
next.objects = next.objects.filter((object) => object.id !== path.id);
|
|
123
|
+
}
|
|
124
|
+
return next;
|
|
125
|
+
case "viewpoint":
|
|
126
|
+
if (path.id) {
|
|
127
|
+
system.viewpoints = system.viewpoints.filter((viewpoint) => viewpoint.id !== path.id);
|
|
128
|
+
}
|
|
129
|
+
return next;
|
|
130
|
+
case "annotation":
|
|
131
|
+
if (path.id) {
|
|
132
|
+
system.annotations = system.annotations.filter((annotation) => annotation.id !== path.id);
|
|
133
|
+
}
|
|
134
|
+
return next;
|
|
135
|
+
default:
|
|
136
|
+
return next;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function resolveAtlasDiagnostics(document, diagnostics) {
|
|
140
|
+
return diagnostics.map((diagnostic) => ({
|
|
141
|
+
diagnostic,
|
|
142
|
+
path: resolveAtlasDiagnosticPath(document, diagnostic),
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
export function resolveAtlasDiagnosticPath(document, diagnostic) {
|
|
146
|
+
if (diagnostic.objectId && findObject(document, diagnostic.objectId)) {
|
|
147
|
+
return {
|
|
148
|
+
kind: "object",
|
|
149
|
+
id: diagnostic.objectId,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (diagnostic.field?.startsWith("viewpoint.")) {
|
|
153
|
+
const parts = diagnostic.field.split(".");
|
|
154
|
+
if (parts[1] && findViewpoint(document.system, parts[1])) {
|
|
155
|
+
return {
|
|
156
|
+
kind: "viewpoint",
|
|
157
|
+
id: parts[1],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (diagnostic.field?.startsWith("annotation.")) {
|
|
162
|
+
const parts = diagnostic.field.split(".");
|
|
163
|
+
if (parts[1] && findAnnotation(document.system, parts[1])) {
|
|
164
|
+
return {
|
|
165
|
+
kind: "annotation",
|
|
166
|
+
id: parts[1],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (diagnostic.field && diagnostic.field in ensureSystem(document).atlasMetadata) {
|
|
171
|
+
return {
|
|
172
|
+
kind: "metadata",
|
|
173
|
+
key: diagnostic.field,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
export function validateAtlasDocumentWithDiagnostics(document) {
|
|
179
|
+
const materialized = materializeAtlasDocument(document);
|
|
180
|
+
const result = validateDocumentWithDiagnostics(materialized);
|
|
181
|
+
return resolveAtlasDiagnostics(document, result.diagnostics);
|
|
182
|
+
}
|
|
183
|
+
function ensureSystem(document) {
|
|
184
|
+
if (document.system) {
|
|
185
|
+
return document.system;
|
|
186
|
+
}
|
|
187
|
+
document.system = createEmptyAtlasDocument().system;
|
|
188
|
+
return document.system;
|
|
189
|
+
}
|
|
190
|
+
function findObject(document, objectId) {
|
|
191
|
+
return document.objects.find((object) => object.id === objectId) ?? null;
|
|
192
|
+
}
|
|
193
|
+
function findViewpoint(system, viewpointId) {
|
|
194
|
+
return system?.viewpoints.find((viewpoint) => viewpoint.id === viewpointId) ?? null;
|
|
195
|
+
}
|
|
196
|
+
function findAnnotation(system, annotationId) {
|
|
197
|
+
return system?.annotations.find((annotation) => annotation.id === annotationId) ?? null;
|
|
198
|
+
}
|
|
199
|
+
function upsertById(items, value) {
|
|
200
|
+
const index = items.findIndex((item) => item.id === value.id);
|
|
201
|
+
if (index === -1) {
|
|
202
|
+
items.push(value);
|
|
203
|
+
items.sort(compareIdLike);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
items[index] = value;
|
|
207
|
+
}
|
|
208
|
+
function compareIdLike(left, right) {
|
|
209
|
+
return left.id.localeCompare(right.id);
|
|
210
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AstDocument, DiagnosticResult, WorldOrbitDiagnostic, WorldOrbitDiagnosticSource, WorldOrbitDocument } from "./types.js";
|
|
2
|
+
export interface ParsedWorldOrbitDocument {
|
|
3
|
+
ast: AstDocument;
|
|
4
|
+
document: WorldOrbitDocument;
|
|
5
|
+
}
|
|
6
|
+
export declare function createDiagnostic(diagnostic: WorldOrbitDiagnostic): WorldOrbitDiagnostic;
|
|
7
|
+
export declare function diagnosticFromError(error: unknown, source: WorldOrbitDiagnosticSource, code?: string): WorldOrbitDiagnostic;
|
|
8
|
+
export declare function parseWithDiagnostics(source: string): DiagnosticResult<ParsedWorldOrbitDocument>;
|
|
9
|
+
export declare function normalizeWithDiagnostics(ast: AstDocument): DiagnosticResult<WorldOrbitDocument>;
|
|
10
|
+
export declare function validateDocumentWithDiagnostics(document: WorldOrbitDocument): DiagnosticResult<WorldOrbitDocument>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { WorldOrbitError } from "./errors.js";
|
|
2
|
+
import { normalizeDocument } from "./normalize.js";
|
|
3
|
+
import { parseWorldOrbit } from "./parse.js";
|
|
4
|
+
import { validateDocument } from "./validate.js";
|
|
5
|
+
export function createDiagnostic(diagnostic) {
|
|
6
|
+
return { ...diagnostic };
|
|
7
|
+
}
|
|
8
|
+
export function diagnosticFromError(error, source, code = `${source}.failed`) {
|
|
9
|
+
if (error instanceof WorldOrbitError) {
|
|
10
|
+
return {
|
|
11
|
+
code,
|
|
12
|
+
severity: "error",
|
|
13
|
+
source,
|
|
14
|
+
message: error.message,
|
|
15
|
+
line: error.line,
|
|
16
|
+
column: error.column,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
return {
|
|
21
|
+
code,
|
|
22
|
+
severity: "error",
|
|
23
|
+
source,
|
|
24
|
+
message: error.message,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
code,
|
|
29
|
+
severity: "error",
|
|
30
|
+
source,
|
|
31
|
+
message: String(error),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function parseWithDiagnostics(source) {
|
|
35
|
+
let ast;
|
|
36
|
+
try {
|
|
37
|
+
ast = parseWorldOrbit(source);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const diagnostic = diagnosticFromError(error, "parse");
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
value: null,
|
|
44
|
+
diagnostics: [diagnostic],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
let document;
|
|
48
|
+
try {
|
|
49
|
+
document = normalizeDocument(ast);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
value: null,
|
|
55
|
+
diagnostics: [diagnosticFromError(error, "normalize")],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
validateDocument(document);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
value: null,
|
|
65
|
+
diagnostics: [diagnosticFromError(error, "validate")],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
value: {
|
|
71
|
+
ast,
|
|
72
|
+
document,
|
|
73
|
+
},
|
|
74
|
+
diagnostics: [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function normalizeWithDiagnostics(ast) {
|
|
78
|
+
try {
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
value: normalizeDocument(ast),
|
|
82
|
+
diagnostics: [],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
value: null,
|
|
89
|
+
diagnostics: [diagnosticFromError(error, "normalize")],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function validateDocumentWithDiagnostics(document) {
|
|
94
|
+
try {
|
|
95
|
+
validateDocument(document);
|
|
96
|
+
return {
|
|
97
|
+
ok: true,
|
|
98
|
+
value: document,
|
|
99
|
+
diagnostics: [],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
value: null,
|
|
106
|
+
diagnostics: [diagnosticFromError(error, "validate")],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|