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,364 @@
|
|
|
1
|
+
import { upgradeDocumentToDraftV2, upgradeDocumentToV2 } from "./draft.js";
|
|
2
|
+
const CANONICAL_FIELD_ORDER = [
|
|
3
|
+
"title",
|
|
4
|
+
"view",
|
|
5
|
+
"scale",
|
|
6
|
+
"units",
|
|
7
|
+
"kind",
|
|
8
|
+
"class",
|
|
9
|
+
"tags",
|
|
10
|
+
"color",
|
|
11
|
+
"image",
|
|
12
|
+
"hidden",
|
|
13
|
+
"orbit",
|
|
14
|
+
"distance",
|
|
15
|
+
"semiMajor",
|
|
16
|
+
"eccentricity",
|
|
17
|
+
"period",
|
|
18
|
+
"angle",
|
|
19
|
+
"inclination",
|
|
20
|
+
"phase",
|
|
21
|
+
"at",
|
|
22
|
+
"surface",
|
|
23
|
+
"free",
|
|
24
|
+
"radius",
|
|
25
|
+
"mass",
|
|
26
|
+
"density",
|
|
27
|
+
"gravity",
|
|
28
|
+
"temperature",
|
|
29
|
+
"albedo",
|
|
30
|
+
"atmosphere",
|
|
31
|
+
"inner",
|
|
32
|
+
"outer",
|
|
33
|
+
"on",
|
|
34
|
+
"source",
|
|
35
|
+
"cycle",
|
|
36
|
+
];
|
|
37
|
+
export function formatDocument(document, options = {}) {
|
|
38
|
+
const schema = options.schema ?? "auto";
|
|
39
|
+
const useDraft = schema === "2.0" ||
|
|
40
|
+
schema === "2.0-draft" ||
|
|
41
|
+
document.version === "2.0" ||
|
|
42
|
+
document.version === "2.0-draft";
|
|
43
|
+
if (useDraft) {
|
|
44
|
+
if (schema === "2.0-draft") {
|
|
45
|
+
const legacyDraftDocument = document.version === "2.0-draft"
|
|
46
|
+
? document
|
|
47
|
+
: document.version === "2.0"
|
|
48
|
+
? {
|
|
49
|
+
...document,
|
|
50
|
+
version: "2.0-draft",
|
|
51
|
+
}
|
|
52
|
+
: upgradeDocumentToDraftV2(document);
|
|
53
|
+
return formatDraftDocument(legacyDraftDocument);
|
|
54
|
+
}
|
|
55
|
+
const atlasDocument = document.version === "2.0"
|
|
56
|
+
? document
|
|
57
|
+
: document.version === "2.0-draft"
|
|
58
|
+
? {
|
|
59
|
+
...document,
|
|
60
|
+
version: "2.0",
|
|
61
|
+
}
|
|
62
|
+
: upgradeDocumentToV2(document);
|
|
63
|
+
return formatAtlasDocument(atlasDocument);
|
|
64
|
+
}
|
|
65
|
+
const lines = [];
|
|
66
|
+
const stableDocument = document;
|
|
67
|
+
if (stableDocument.system) {
|
|
68
|
+
lines.push(...formatSystem(stableDocument.system));
|
|
69
|
+
}
|
|
70
|
+
const sortedObjects = [...stableDocument.objects].sort(compareObjects);
|
|
71
|
+
for (const object of sortedObjects) {
|
|
72
|
+
if (lines.length > 0) {
|
|
73
|
+
lines.push("");
|
|
74
|
+
}
|
|
75
|
+
lines.push(...formatObject(object));
|
|
76
|
+
}
|
|
77
|
+
return lines.join("\n");
|
|
78
|
+
}
|
|
79
|
+
export function formatAtlasDocument(document) {
|
|
80
|
+
const lines = ["schema 2.0", ""];
|
|
81
|
+
if (document.system) {
|
|
82
|
+
lines.push(...formatAtlasSystem(document.system));
|
|
83
|
+
}
|
|
84
|
+
const sortedObjects = [...document.objects].sort(compareObjects);
|
|
85
|
+
if (sortedObjects.length > 0 && lines.at(-1) !== "") {
|
|
86
|
+
lines.push("");
|
|
87
|
+
}
|
|
88
|
+
sortedObjects.forEach((object, index) => {
|
|
89
|
+
if (index > 0) {
|
|
90
|
+
lines.push("");
|
|
91
|
+
}
|
|
92
|
+
lines.push(...formatAtlasObject(object));
|
|
93
|
+
});
|
|
94
|
+
return lines.join("\n");
|
|
95
|
+
}
|
|
96
|
+
export function formatDraftDocument(document) {
|
|
97
|
+
const legacy = document.version === "2.0-draft"
|
|
98
|
+
? document
|
|
99
|
+
: {
|
|
100
|
+
...document,
|
|
101
|
+
version: "2.0-draft",
|
|
102
|
+
};
|
|
103
|
+
const lines = ["schema 2.0-draft", ""];
|
|
104
|
+
if (legacy.system) {
|
|
105
|
+
lines.push(...formatAtlasSystem(legacy.system));
|
|
106
|
+
}
|
|
107
|
+
const sortedObjects = [...legacy.objects].sort(compareObjects);
|
|
108
|
+
if (sortedObjects.length > 0 && lines.at(-1) !== "") {
|
|
109
|
+
lines.push("");
|
|
110
|
+
}
|
|
111
|
+
sortedObjects.forEach((object, index) => {
|
|
112
|
+
if (index > 0) {
|
|
113
|
+
lines.push("");
|
|
114
|
+
}
|
|
115
|
+
lines.push(...formatAtlasObject(object));
|
|
116
|
+
});
|
|
117
|
+
return lines.join("\n");
|
|
118
|
+
}
|
|
119
|
+
function formatSystem(system) {
|
|
120
|
+
return formatLines("system", system.id, system.properties, null, system.info);
|
|
121
|
+
}
|
|
122
|
+
function formatAtlasSystem(system) {
|
|
123
|
+
const lines = [`system ${system.id}`];
|
|
124
|
+
if (system.title) {
|
|
125
|
+
lines.push(` title ${quoteIfNeeded(system.title)}`);
|
|
126
|
+
}
|
|
127
|
+
lines.push("");
|
|
128
|
+
lines.push("defaults");
|
|
129
|
+
lines.push(` view ${system.defaults.view}`);
|
|
130
|
+
if (system.defaults.scale) {
|
|
131
|
+
lines.push(` scale ${quoteIfNeeded(system.defaults.scale)}`);
|
|
132
|
+
}
|
|
133
|
+
if (system.defaults.units) {
|
|
134
|
+
lines.push(` units ${quoteIfNeeded(system.defaults.units)}`);
|
|
135
|
+
}
|
|
136
|
+
if (system.defaults.preset) {
|
|
137
|
+
lines.push(` preset ${system.defaults.preset}`);
|
|
138
|
+
}
|
|
139
|
+
if (system.defaults.theme) {
|
|
140
|
+
lines.push(` theme ${quoteIfNeeded(system.defaults.theme)}`);
|
|
141
|
+
}
|
|
142
|
+
if (Object.keys(system.atlasMetadata).length > 0) {
|
|
143
|
+
lines.push("");
|
|
144
|
+
lines.push("atlas");
|
|
145
|
+
lines.push(" metadata");
|
|
146
|
+
for (const [key, value] of Object.entries(system.atlasMetadata).sort(([left], [right]) => left.localeCompare(right))) {
|
|
147
|
+
lines.push(` ${key} ${quoteIfNeeded(value)}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const viewpoint of system.viewpoints) {
|
|
151
|
+
lines.push("");
|
|
152
|
+
lines.push(...formatAtlasViewpoint(viewpoint));
|
|
153
|
+
}
|
|
154
|
+
for (const annotation of system.annotations) {
|
|
155
|
+
lines.push("");
|
|
156
|
+
lines.push(...formatAtlasAnnotation(annotation));
|
|
157
|
+
}
|
|
158
|
+
return lines;
|
|
159
|
+
}
|
|
160
|
+
function formatObject(object) {
|
|
161
|
+
return formatLines(object.type, object.id, object.properties, object.placement, object.info);
|
|
162
|
+
}
|
|
163
|
+
function formatAtlasObject(object) {
|
|
164
|
+
return formatLines(`object ${object.type}`, object.id, object.properties, object.placement, object.info);
|
|
165
|
+
}
|
|
166
|
+
function formatLines(objectType, id, properties, placement, info) {
|
|
167
|
+
const lines = [`${objectType} ${id}`];
|
|
168
|
+
const fieldLines = [...formatPlacement(placement), ...formatProperties(properties)];
|
|
169
|
+
for (const fieldLine of fieldLines) {
|
|
170
|
+
lines.push(` ${fieldLine}`);
|
|
171
|
+
}
|
|
172
|
+
const infoEntries = Object.entries(info).sort(([left], [right]) => left.localeCompare(right));
|
|
173
|
+
if (infoEntries.length > 0) {
|
|
174
|
+
if (fieldLines.length > 0) {
|
|
175
|
+
lines.push("");
|
|
176
|
+
}
|
|
177
|
+
lines.push(" info");
|
|
178
|
+
for (const [key, value] of infoEntries) {
|
|
179
|
+
lines.push(` ${key} ${quoteIfNeeded(value)}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return lines;
|
|
183
|
+
}
|
|
184
|
+
function formatPlacement(placement) {
|
|
185
|
+
if (!placement)
|
|
186
|
+
return [];
|
|
187
|
+
switch (placement.mode) {
|
|
188
|
+
case "orbit":
|
|
189
|
+
return [
|
|
190
|
+
`orbit ${placement.target}`,
|
|
191
|
+
...formatOptionalUnit("distance", placement.distance),
|
|
192
|
+
...formatOptionalUnit("semiMajor", placement.semiMajor),
|
|
193
|
+
...formatOptionalNumber("eccentricity", placement.eccentricity),
|
|
194
|
+
...formatOptionalUnit("period", placement.period),
|
|
195
|
+
...formatOptionalUnit("angle", placement.angle),
|
|
196
|
+
...formatOptionalUnit("inclination", placement.inclination),
|
|
197
|
+
...formatOptionalUnit("phase", placement.phase),
|
|
198
|
+
];
|
|
199
|
+
case "at":
|
|
200
|
+
return [`at ${formatAtReference(placement.reference)}`];
|
|
201
|
+
case "surface":
|
|
202
|
+
return [`surface ${placement.target}`];
|
|
203
|
+
case "free":
|
|
204
|
+
return [`free ${placement.distance ? formatUnitValue(placement.distance) : placement.descriptor ?? ""}`.trim()];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function formatProperties(properties) {
|
|
208
|
+
return Object.keys(properties)
|
|
209
|
+
.sort(compareFieldKeys)
|
|
210
|
+
.map((key) => `${key} ${formatValue(properties[key])}`);
|
|
211
|
+
}
|
|
212
|
+
function formatAtlasViewpoint(viewpoint) {
|
|
213
|
+
const lines = [`viewpoint ${viewpoint.id}`, ` label ${quoteIfNeeded(viewpoint.label)}`];
|
|
214
|
+
if (viewpoint.focusObjectId) {
|
|
215
|
+
lines.push(` focus ${viewpoint.focusObjectId}`);
|
|
216
|
+
}
|
|
217
|
+
if (viewpoint.selectedObjectId && viewpoint.selectedObjectId !== viewpoint.focusObjectId) {
|
|
218
|
+
lines.push(` select ${viewpoint.selectedObjectId}`);
|
|
219
|
+
}
|
|
220
|
+
if (viewpoint.summary) {
|
|
221
|
+
lines.push(` summary ${quoteIfNeeded(viewpoint.summary)}`);
|
|
222
|
+
}
|
|
223
|
+
if (viewpoint.projection) {
|
|
224
|
+
lines.push(` projection ${viewpoint.projection}`);
|
|
225
|
+
}
|
|
226
|
+
if (viewpoint.preset) {
|
|
227
|
+
lines.push(` preset ${viewpoint.preset}`);
|
|
228
|
+
}
|
|
229
|
+
if (viewpoint.zoom !== null) {
|
|
230
|
+
lines.push(` zoom ${viewpoint.zoom}`);
|
|
231
|
+
}
|
|
232
|
+
if (viewpoint.rotationDeg !== 0) {
|
|
233
|
+
lines.push(` rotation ${viewpoint.rotationDeg}`);
|
|
234
|
+
}
|
|
235
|
+
const layerTokens = formatDraftLayers(viewpoint.layers);
|
|
236
|
+
if (layerTokens.length > 0) {
|
|
237
|
+
lines.push(` layers ${layerTokens.join(" ")}`);
|
|
238
|
+
}
|
|
239
|
+
if (viewpoint.filter) {
|
|
240
|
+
lines.push(" filter");
|
|
241
|
+
if (viewpoint.filter.query) {
|
|
242
|
+
lines.push(` query ${quoteIfNeeded(viewpoint.filter.query)}`);
|
|
243
|
+
}
|
|
244
|
+
if (viewpoint.filter.objectTypes.length > 0) {
|
|
245
|
+
lines.push(` objectTypes ${viewpoint.filter.objectTypes.join(" ")}`);
|
|
246
|
+
}
|
|
247
|
+
if (viewpoint.filter.tags.length > 0) {
|
|
248
|
+
lines.push(` tags ${viewpoint.filter.tags.map(quoteIfNeeded).join(" ")}`);
|
|
249
|
+
}
|
|
250
|
+
if (viewpoint.filter.groupIds.length > 0) {
|
|
251
|
+
lines.push(` groups ${viewpoint.filter.groupIds.join(" ")}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return lines;
|
|
255
|
+
}
|
|
256
|
+
function formatAtlasAnnotation(annotation) {
|
|
257
|
+
const lines = [`annotation ${annotation.id}`, ` label ${quoteIfNeeded(annotation.label)}`];
|
|
258
|
+
if (annotation.targetObjectId) {
|
|
259
|
+
lines.push(` target ${annotation.targetObjectId}`);
|
|
260
|
+
}
|
|
261
|
+
lines.push(` body ${quoteIfNeeded(annotation.body)}`);
|
|
262
|
+
if (annotation.tags.length > 0) {
|
|
263
|
+
lines.push(` tags ${annotation.tags.map(quoteIfNeeded).join(" ")}`);
|
|
264
|
+
}
|
|
265
|
+
return lines;
|
|
266
|
+
}
|
|
267
|
+
function formatValue(value) {
|
|
268
|
+
if (Array.isArray(value)) {
|
|
269
|
+
return value.map((item) => quoteIfNeeded(item)).join(" ");
|
|
270
|
+
}
|
|
271
|
+
if (typeof value === "boolean") {
|
|
272
|
+
return value ? "true" : "false";
|
|
273
|
+
}
|
|
274
|
+
if (typeof value === "number") {
|
|
275
|
+
return String(value);
|
|
276
|
+
}
|
|
277
|
+
if (typeof value === "string") {
|
|
278
|
+
return quoteIfNeeded(value);
|
|
279
|
+
}
|
|
280
|
+
return formatUnitValue(value);
|
|
281
|
+
}
|
|
282
|
+
function formatUnitValue(value) {
|
|
283
|
+
return `${value.value}${value.unit ?? ""}`;
|
|
284
|
+
}
|
|
285
|
+
function formatOptionalUnit(key, value) {
|
|
286
|
+
return value ? [`${key} ${formatUnitValue(value)}`] : [];
|
|
287
|
+
}
|
|
288
|
+
function formatOptionalNumber(key, value) {
|
|
289
|
+
return value === undefined ? [] : [`${key} ${value}`];
|
|
290
|
+
}
|
|
291
|
+
function formatAtReference(reference) {
|
|
292
|
+
switch (reference.kind) {
|
|
293
|
+
case "lagrange":
|
|
294
|
+
return reference.secondary
|
|
295
|
+
? `${reference.primary}-${reference.secondary}:${reference.point}`
|
|
296
|
+
: `${reference.primary}:${reference.point}`;
|
|
297
|
+
case "anchor":
|
|
298
|
+
return `${reference.objectId}:${reference.anchor}`;
|
|
299
|
+
case "named":
|
|
300
|
+
return reference.name;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function formatDraftLayers(layers) {
|
|
304
|
+
const tokens = [];
|
|
305
|
+
const orbitFront = layers["orbits-front"];
|
|
306
|
+
const orbitBack = layers["orbits-back"];
|
|
307
|
+
if (orbitFront !== undefined || orbitBack !== undefined) {
|
|
308
|
+
tokens.push(orbitFront !== false || orbitBack !== false
|
|
309
|
+
? "orbits"
|
|
310
|
+
: "-orbits");
|
|
311
|
+
}
|
|
312
|
+
for (const key of ["background", "guides", "objects", "labels", "metadata"]) {
|
|
313
|
+
if (layers[key] !== undefined) {
|
|
314
|
+
tokens.push(layers[key] ? key : `-${key}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return tokens;
|
|
318
|
+
}
|
|
319
|
+
function compareFieldKeys(left, right) {
|
|
320
|
+
const leftIndex = CANONICAL_FIELD_ORDER.indexOf(left);
|
|
321
|
+
const rightIndex = CANONICAL_FIELD_ORDER.indexOf(right);
|
|
322
|
+
if (leftIndex === -1 && rightIndex === -1)
|
|
323
|
+
return left.localeCompare(right);
|
|
324
|
+
if (leftIndex === -1)
|
|
325
|
+
return 1;
|
|
326
|
+
if (rightIndex === -1)
|
|
327
|
+
return -1;
|
|
328
|
+
return leftIndex - rightIndex;
|
|
329
|
+
}
|
|
330
|
+
function compareObjects(left, right) {
|
|
331
|
+
const leftIndex = objectTypeIndex(left.type);
|
|
332
|
+
const rightIndex = objectTypeIndex(right.type);
|
|
333
|
+
if (leftIndex !== rightIndex)
|
|
334
|
+
return leftIndex - rightIndex;
|
|
335
|
+
return left.id.localeCompare(right.id);
|
|
336
|
+
}
|
|
337
|
+
function objectTypeIndex(objectType) {
|
|
338
|
+
switch (objectType) {
|
|
339
|
+
case "star":
|
|
340
|
+
return 0;
|
|
341
|
+
case "planet":
|
|
342
|
+
return 1;
|
|
343
|
+
case "moon":
|
|
344
|
+
return 2;
|
|
345
|
+
case "belt":
|
|
346
|
+
return 3;
|
|
347
|
+
case "asteroid":
|
|
348
|
+
return 4;
|
|
349
|
+
case "comet":
|
|
350
|
+
return 5;
|
|
351
|
+
case "ring":
|
|
352
|
+
return 6;
|
|
353
|
+
case "structure":
|
|
354
|
+
return 7;
|
|
355
|
+
case "phenomenon":
|
|
356
|
+
return 8;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function quoteIfNeeded(value) {
|
|
360
|
+
if (!/\s/.test(value) && !value.includes('"')) {
|
|
361
|
+
return value;
|
|
362
|
+
}
|
|
363
|
+
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
364
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./schema.js";
|
|
4
|
+
export { tokenizeLine, tokenizeLineDetailed } from "./tokenize.js";
|
|
5
|
+
export { parseWorldOrbit } from "./parse.js";
|
|
6
|
+
export { normalizeDocument } from "./normalize.js";
|
|
7
|
+
export { validateDocument } from "./validate.js";
|
|
8
|
+
export { createDiagnostic, diagnosticFromError, normalizeWithDiagnostics, parseWithDiagnostics, validateDocumentWithDiagnostics, } from "./diagnostics.js";
|
|
9
|
+
export { renderDocumentToScene, rotatePoint } from "./scene.js";
|
|
10
|
+
export { formatAtlasDocument, formatDocument, formatDraftDocument } from "./format.js";
|
|
11
|
+
export { materializeAtlasDocument, materializeDraftDocument, upgradeDocumentToDraftV2, upgradeDocumentToV2, } from "./draft.js";
|
|
12
|
+
export { parseWorldOrbitAtlas, parseWorldOrbitDraft } from "./draft-parse.js";
|
|
13
|
+
export { cloneAtlasDocument, createEmptyAtlasDocument, getAtlasDocumentNode, listAtlasDocumentPaths, removeAtlasDocumentNode, resolveAtlasDiagnosticPath, resolveAtlasDiagnostics, updateAtlasDocumentNode, upsertAtlasDocumentNode, validateAtlasDocumentWithDiagnostics, } from "./atlas-edit.js";
|
|
14
|
+
export { detectWorldOrbitSchemaVersion, loadWorldOrbitSource, loadWorldOrbitSourceWithDiagnostics, } from "./load.js";
|
|
15
|
+
export { extractWorldOrbitBlocks } from "./markdown.js";
|
|
16
|
+
import type { AstDocument, FormatDocumentOptions, FormattableWorldOrbitDocument, RenderScene, WorldOrbitDocument } from "./types.js";
|
|
17
|
+
export interface ParseResult {
|
|
18
|
+
ast: AstDocument;
|
|
19
|
+
document: WorldOrbitDocument;
|
|
20
|
+
}
|
|
21
|
+
export interface RenderResult extends ParseResult {
|
|
22
|
+
scene: RenderScene;
|
|
23
|
+
}
|
|
24
|
+
export declare function parse(source: string): ParseResult;
|
|
25
|
+
export declare function render(source: string): RenderResult;
|
|
26
|
+
export declare function load(source: string): import("./types.js").LoadedWorldOrbitSource;
|
|
27
|
+
export declare function parseSafe(source: string): import("./types.js").DiagnosticResult<import("./diagnostics.js").ParsedWorldOrbitDocument>;
|
|
28
|
+
export declare function stringify(document: FormattableWorldOrbitDocument, options?: FormatDocumentOptions): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./schema.js";
|
|
4
|
+
export { tokenizeLine, tokenizeLineDetailed } from "./tokenize.js";
|
|
5
|
+
export { parseWorldOrbit } from "./parse.js";
|
|
6
|
+
export { normalizeDocument } from "./normalize.js";
|
|
7
|
+
export { validateDocument } from "./validate.js";
|
|
8
|
+
export { createDiagnostic, diagnosticFromError, normalizeWithDiagnostics, parseWithDiagnostics, validateDocumentWithDiagnostics, } from "./diagnostics.js";
|
|
9
|
+
export { renderDocumentToScene, rotatePoint } from "./scene.js";
|
|
10
|
+
export { formatAtlasDocument, formatDocument, formatDraftDocument } from "./format.js";
|
|
11
|
+
export { materializeAtlasDocument, materializeDraftDocument, upgradeDocumentToDraftV2, upgradeDocumentToV2, } from "./draft.js";
|
|
12
|
+
export { parseWorldOrbitAtlas, parseWorldOrbitDraft } from "./draft-parse.js";
|
|
13
|
+
export { cloneAtlasDocument, createEmptyAtlasDocument, getAtlasDocumentNode, listAtlasDocumentPaths, removeAtlasDocumentNode, resolveAtlasDiagnosticPath, resolveAtlasDiagnostics, updateAtlasDocumentNode, upsertAtlasDocumentNode, validateAtlasDocumentWithDiagnostics, } from "./atlas-edit.js";
|
|
14
|
+
export { detectWorldOrbitSchemaVersion, loadWorldOrbitSource, loadWorldOrbitSourceWithDiagnostics, } from "./load.js";
|
|
15
|
+
export { extractWorldOrbitBlocks } from "./markdown.js";
|
|
16
|
+
import { parseWithDiagnostics } from "./diagnostics.js";
|
|
17
|
+
import { formatDocument } from "./format.js";
|
|
18
|
+
import { loadWorldOrbitSource } from "./load.js";
|
|
19
|
+
import { normalizeDocument } from "./normalize.js";
|
|
20
|
+
import { parseWorldOrbit } from "./parse.js";
|
|
21
|
+
import { renderDocumentToScene } from "./scene.js";
|
|
22
|
+
import { validateDocument } from "./validate.js";
|
|
23
|
+
export function parse(source) {
|
|
24
|
+
const ast = parseWorldOrbit(source);
|
|
25
|
+
const document = normalizeDocument(ast);
|
|
26
|
+
validateDocument(document);
|
|
27
|
+
return { ast, document };
|
|
28
|
+
}
|
|
29
|
+
export function render(source) {
|
|
30
|
+
const result = parse(source);
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
scene: renderDocumentToScene(result.document),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function load(source) {
|
|
37
|
+
return loadWorldOrbitSource(source);
|
|
38
|
+
}
|
|
39
|
+
export function parseSafe(source) {
|
|
40
|
+
return parseWithDiagnostics(source);
|
|
41
|
+
}
|
|
42
|
+
export function stringify(document, options = {}) {
|
|
43
|
+
return formatDocument(document, options);
|
|
44
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DiagnosticResult, LoadedWorldOrbitSource, WorldOrbitAnyDocumentVersion } from "./types.js";
|
|
2
|
+
export declare function detectWorldOrbitSchemaVersion(source: string): WorldOrbitAnyDocumentVersion;
|
|
3
|
+
export declare function loadWorldOrbitSource(source: string): LoadedWorldOrbitSource;
|
|
4
|
+
export declare function loadWorldOrbitSourceWithDiagnostics(source: string): DiagnosticResult<LoadedWorldOrbitSource>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { diagnosticFromError } from "./diagnostics.js";
|
|
2
|
+
import { materializeAtlasDocument } from "./draft.js";
|
|
3
|
+
import { parseWorldOrbitAtlas } from "./draft-parse.js";
|
|
4
|
+
import { WorldOrbitError } from "./errors.js";
|
|
5
|
+
import { normalizeDocument } from "./normalize.js";
|
|
6
|
+
import { parseWorldOrbit } from "./parse.js";
|
|
7
|
+
import { validateDocument } from "./validate.js";
|
|
8
|
+
const ATLAS_SCHEMA_PATTERN = /^schema\s+2(?:\.0)?$/i;
|
|
9
|
+
const LEGACY_DRAFT_SCHEMA_PATTERN = /^schema\s+2\.0-draft$/i;
|
|
10
|
+
export function detectWorldOrbitSchemaVersion(source) {
|
|
11
|
+
for (const line of source.split(/\r?\n/)) {
|
|
12
|
+
const trimmed = line.trim();
|
|
13
|
+
if (!trimmed) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (LEGACY_DRAFT_SCHEMA_PATTERN.test(trimmed)) {
|
|
17
|
+
return "2.0-draft";
|
|
18
|
+
}
|
|
19
|
+
if (ATLAS_SCHEMA_PATTERN.test(trimmed)) {
|
|
20
|
+
return "2.0";
|
|
21
|
+
}
|
|
22
|
+
return "1.0";
|
|
23
|
+
}
|
|
24
|
+
return "1.0";
|
|
25
|
+
}
|
|
26
|
+
export function loadWorldOrbitSource(source) {
|
|
27
|
+
const result = loadWorldOrbitSourceWithDiagnostics(source);
|
|
28
|
+
if (!result.ok || !result.value) {
|
|
29
|
+
const diagnostic = result.diagnostics[0];
|
|
30
|
+
throw new WorldOrbitError(diagnostic?.message ?? "Failed to load WorldOrbit source", diagnostic?.line, diagnostic?.column);
|
|
31
|
+
}
|
|
32
|
+
return result.value;
|
|
33
|
+
}
|
|
34
|
+
export function loadWorldOrbitSourceWithDiagnostics(source) {
|
|
35
|
+
const schemaVersion = detectWorldOrbitSchemaVersion(source);
|
|
36
|
+
if (schemaVersion === "2.0" || schemaVersion === "2.0-draft") {
|
|
37
|
+
return loadAtlasSourceWithDiagnostics(source, schemaVersion);
|
|
38
|
+
}
|
|
39
|
+
let ast;
|
|
40
|
+
try {
|
|
41
|
+
ast = parseWorldOrbit(source);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
value: null,
|
|
47
|
+
diagnostics: [diagnosticFromError(error, "parse")],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let document;
|
|
51
|
+
try {
|
|
52
|
+
document = normalizeDocument(ast);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
value: null,
|
|
58
|
+
diagnostics: [diagnosticFromError(error, "normalize")],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
validateDocument(document);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
value: null,
|
|
68
|
+
diagnostics: [diagnosticFromError(error, "validate")],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
ok: true,
|
|
73
|
+
value: {
|
|
74
|
+
schemaVersion,
|
|
75
|
+
ast,
|
|
76
|
+
document,
|
|
77
|
+
atlasDocument: null,
|
|
78
|
+
draftDocument: null,
|
|
79
|
+
diagnostics: [],
|
|
80
|
+
},
|
|
81
|
+
diagnostics: [],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function loadAtlasSourceWithDiagnostics(source, schemaVersion) {
|
|
85
|
+
let atlasDocument;
|
|
86
|
+
try {
|
|
87
|
+
atlasDocument = parseWorldOrbitAtlas(source);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
value: null,
|
|
93
|
+
diagnostics: [diagnosticFromError(error, "parse", "load.atlas.failed")],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
let document;
|
|
97
|
+
try {
|
|
98
|
+
document = materializeAtlasDocument(atlasDocument);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
ok: false,
|
|
103
|
+
value: null,
|
|
104
|
+
diagnostics: [diagnosticFromError(error, "normalize", "load.atlas.materialize.failed")],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
validateDocument(document);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
value: null,
|
|
114
|
+
diagnostics: [diagnosticFromError(error, "validate", "load.atlas.validate.failed")],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const loaded = {
|
|
118
|
+
schemaVersion,
|
|
119
|
+
ast: null,
|
|
120
|
+
document,
|
|
121
|
+
atlasDocument,
|
|
122
|
+
draftDocument: atlasDocument,
|
|
123
|
+
diagnostics: [...atlasDocument.diagnostics],
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
value: loaded,
|
|
128
|
+
diagnostics: [...atlasDocument.diagnostics],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const FENCE_PATTERN = /^```worldorbit(?:\s+(.*))?\s*$/;
|
|
2
|
+
export function extractWorldOrbitBlocks(markdown) {
|
|
3
|
+
const lines = markdown.split(/\r?\n/);
|
|
4
|
+
const blocks = [];
|
|
5
|
+
let active = false;
|
|
6
|
+
let activeInfo = null;
|
|
7
|
+
let activeStartLine = 0;
|
|
8
|
+
let buffer = [];
|
|
9
|
+
lines.forEach((line, index) => {
|
|
10
|
+
const lineNumber = index + 1;
|
|
11
|
+
if (!active) {
|
|
12
|
+
const match = line.match(FENCE_PATTERN);
|
|
13
|
+
if (match) {
|
|
14
|
+
active = true;
|
|
15
|
+
activeInfo = match[1] ?? null;
|
|
16
|
+
activeStartLine = lineNumber;
|
|
17
|
+
buffer = [];
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (line.trim() === "```") {
|
|
22
|
+
blocks.push({
|
|
23
|
+
source: buffer.join("\n"),
|
|
24
|
+
info: activeInfo,
|
|
25
|
+
startLine: activeStartLine,
|
|
26
|
+
endLine: lineNumber,
|
|
27
|
+
});
|
|
28
|
+
active = false;
|
|
29
|
+
activeInfo = null;
|
|
30
|
+
activeStartLine = 0;
|
|
31
|
+
buffer = [];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
buffer.push(line);
|
|
35
|
+
});
|
|
36
|
+
return blocks;
|
|
37
|
+
}
|