worldorbit 2.5.1-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.
Files changed (117) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +468 -0
  3. package/dist/browser/core/dist/index.js +4009 -0
  4. package/dist/browser/markdown/dist/index.js +3951 -0
  5. package/dist/browser/viewer/dist/index.js +5981 -0
  6. package/dist/constants.d.ts +8 -0
  7. package/dist/constants.js +84 -0
  8. package/dist/errors.d.ts +7 -0
  9. package/dist/errors.js +16 -0
  10. package/dist/index.d.ts +18 -0
  11. package/dist/index.js +25 -0
  12. package/dist/normalize.d.ts +2 -0
  13. package/dist/normalize.js +243 -0
  14. package/dist/parse.d.ts +2 -0
  15. package/dist/parse.js +126 -0
  16. package/dist/render.d.ts +6 -0
  17. package/dist/render.js +683 -0
  18. package/dist/tokenize.d.ts +4 -0
  19. package/dist/tokenize.js +68 -0
  20. package/dist/types.d.ts +208 -0
  21. package/dist/types.js +1 -0
  22. package/dist/unpkg/core/dist/index.js +4081 -0
  23. package/dist/unpkg/markdown/dist/index.js +3979 -0
  24. package/dist/unpkg/viewer/dist/index.js +6038 -0
  25. package/dist/unpkg/worldorbit-core.min.js +12 -0
  26. package/dist/unpkg/worldorbit-markdown.min.js +95 -0
  27. package/dist/unpkg/worldorbit-viewer.min.js +251 -0
  28. package/dist/unpkg/worldorbit.d.ts +2 -0
  29. package/dist/unpkg/worldorbit.esm.js +2 -0
  30. package/dist/unpkg/worldorbit.js +8524 -0
  31. package/dist/unpkg/worldorbit.min.js +255 -0
  32. package/dist/validate.d.ts +2 -0
  33. package/dist/validate.js +31 -0
  34. package/dist/viewer-state.d.ts +16 -0
  35. package/dist/viewer-state.js +130 -0
  36. package/dist/viewer.d.ts +2 -0
  37. package/dist/viewer.js +434 -0
  38. package/package.json +68 -0
  39. package/packages/core/README.md +17 -0
  40. package/packages/core/dist/atlas-edit.d.ts +11 -0
  41. package/packages/core/dist/atlas-edit.js +273 -0
  42. package/packages/core/dist/atlas-utils.d.ts +22 -0
  43. package/packages/core/dist/atlas-utils.js +189 -0
  44. package/packages/core/dist/atlas-validate.d.ts +2 -0
  45. package/packages/core/dist/atlas-validate.js +285 -0
  46. package/packages/core/dist/diagnostics.d.ts +10 -0
  47. package/packages/core/dist/diagnostics.js +109 -0
  48. package/packages/core/dist/draft-parse.d.ts +3 -0
  49. package/packages/core/dist/draft-parse.js +1275 -0
  50. package/packages/core/dist/draft.d.ts +18 -0
  51. package/packages/core/dist/draft.js +387 -0
  52. package/packages/core/dist/errors.d.ts +7 -0
  53. package/packages/core/dist/errors.js +16 -0
  54. package/packages/core/dist/format.d.ts +4 -0
  55. package/packages/core/dist/format.js +520 -0
  56. package/packages/core/dist/index.d.ts +28 -0
  57. package/packages/core/dist/index.js +44 -0
  58. package/packages/core/dist/load.d.ts +4 -0
  59. package/packages/core/dist/load.js +175 -0
  60. package/packages/core/dist/markdown.d.ts +2 -0
  61. package/packages/core/dist/markdown.js +37 -0
  62. package/packages/core/dist/normalize.d.ts +2 -0
  63. package/packages/core/dist/normalize.js +311 -0
  64. package/packages/core/dist/parse.d.ts +2 -0
  65. package/packages/core/dist/parse.js +133 -0
  66. package/packages/core/dist/scene.d.ts +3 -0
  67. package/packages/core/dist/scene.js +1565 -0
  68. package/packages/core/dist/schema.d.ts +8 -0
  69. package/packages/core/dist/schema.js +298 -0
  70. package/packages/core/dist/tokenize.d.ts +4 -0
  71. package/packages/core/dist/tokenize.js +68 -0
  72. package/packages/core/dist/types.d.ts +476 -0
  73. package/packages/core/dist/types.js +1 -0
  74. package/packages/core/dist/validate.d.ts +2 -0
  75. package/packages/core/dist/validate.js +56 -0
  76. package/packages/editor/dist/editor.d.ts +2 -0
  77. package/packages/editor/dist/editor.js +3042 -0
  78. package/packages/editor/dist/index.d.ts +2 -0
  79. package/packages/editor/dist/index.js +1 -0
  80. package/packages/editor/dist/types.d.ts +53 -0
  81. package/packages/editor/dist/types.js +1 -0
  82. package/packages/markdown/README.md +9 -0
  83. package/packages/markdown/dist/html.d.ts +3 -0
  84. package/packages/markdown/dist/html.js +57 -0
  85. package/packages/markdown/dist/index.d.ts +4 -0
  86. package/packages/markdown/dist/index.js +3 -0
  87. package/packages/markdown/dist/rehype.d.ts +10 -0
  88. package/packages/markdown/dist/rehype.js +49 -0
  89. package/packages/markdown/dist/remark.d.ts +9 -0
  90. package/packages/markdown/dist/remark.js +28 -0
  91. package/packages/markdown/dist/types.d.ts +11 -0
  92. package/packages/markdown/dist/types.js +1 -0
  93. package/packages/viewer/README.md +13 -0
  94. package/packages/viewer/dist/atlas-state.d.ts +12 -0
  95. package/packages/viewer/dist/atlas-state.js +257 -0
  96. package/packages/viewer/dist/atlas-viewer.d.ts +2 -0
  97. package/packages/viewer/dist/atlas-viewer.js +482 -0
  98. package/packages/viewer/dist/custom-element.d.ts +1 -0
  99. package/packages/viewer/dist/custom-element.js +64 -0
  100. package/packages/viewer/dist/embed.d.ts +20 -0
  101. package/packages/viewer/dist/embed.js +138 -0
  102. package/packages/viewer/dist/index.d.ts +9 -0
  103. package/packages/viewer/dist/index.js +8 -0
  104. package/packages/viewer/dist/minimap.d.ts +3 -0
  105. package/packages/viewer/dist/minimap.js +63 -0
  106. package/packages/viewer/dist/render.d.ts +6 -0
  107. package/packages/viewer/dist/render.js +641 -0
  108. package/packages/viewer/dist/theme.d.ts +4 -0
  109. package/packages/viewer/dist/theme.js +102 -0
  110. package/packages/viewer/dist/tooltip.d.ts +3 -0
  111. package/packages/viewer/dist/tooltip.js +189 -0
  112. package/packages/viewer/dist/types.d.ts +263 -0
  113. package/packages/viewer/dist/types.js +1 -0
  114. package/packages/viewer/dist/viewer-state.d.ts +19 -0
  115. package/packages/viewer/dist/viewer-state.js +162 -0
  116. package/packages/viewer/dist/viewer.d.ts +2 -0
  117. package/packages/viewer/dist/viewer.js +1175 -0
@@ -0,0 +1,520 @@
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.1" ||
41
+ schema === "2.0-draft" ||
42
+ document.version === "2.0" ||
43
+ document.version === "2.1" ||
44
+ document.version === "2.0-draft";
45
+ if (useDraft) {
46
+ if (schema === "2.0-draft") {
47
+ const legacyDraftDocument = document.version === "2.0-draft"
48
+ ? document
49
+ : document.version === "2.0" || document.version === "2.1"
50
+ ? {
51
+ ...document,
52
+ version: "2.0-draft",
53
+ schemaVersion: "2.0-draft",
54
+ }
55
+ : upgradeDocumentToDraftV2(document);
56
+ return formatDraftDocument(legacyDraftDocument);
57
+ }
58
+ const atlasDocument = document.version === "2.0" || document.version === "2.1"
59
+ ? document
60
+ : document.version === "2.0-draft"
61
+ ? {
62
+ ...document,
63
+ version: "2.0",
64
+ schemaVersion: "2.0",
65
+ }
66
+ : upgradeDocumentToV2(document);
67
+ if (schema === "2.1" && atlasDocument.version !== "2.1") {
68
+ return formatAtlasDocument({
69
+ ...atlasDocument,
70
+ version: "2.1",
71
+ schemaVersion: "2.1",
72
+ });
73
+ }
74
+ return formatAtlasDocument(atlasDocument);
75
+ }
76
+ const lines = [];
77
+ const stableDocument = document;
78
+ if (stableDocument.system) {
79
+ lines.push(...formatSystem(stableDocument.system));
80
+ }
81
+ const sortedObjects = [...stableDocument.objects].sort(compareObjects);
82
+ for (const object of sortedObjects) {
83
+ if (lines.length > 0) {
84
+ lines.push("");
85
+ }
86
+ lines.push(...formatObject(object));
87
+ }
88
+ return lines.join("\n");
89
+ }
90
+ export function formatAtlasDocument(document) {
91
+ const lines = [`schema ${document.version}`, ""];
92
+ if (document.system) {
93
+ lines.push(...formatAtlasSystem(document.system));
94
+ }
95
+ for (const group of [...document.groups].sort(compareIdLike)) {
96
+ lines.push("");
97
+ lines.push(...formatAtlasGroup(group));
98
+ }
99
+ for (const relation of [...document.relations].sort(compareIdLike)) {
100
+ lines.push("");
101
+ lines.push(...formatAtlasRelation(relation));
102
+ }
103
+ const sortedObjects = [...document.objects].sort(compareObjects);
104
+ if (sortedObjects.length > 0 && lines.at(-1) !== "") {
105
+ lines.push("");
106
+ }
107
+ sortedObjects.forEach((object, index) => {
108
+ if (index > 0) {
109
+ lines.push("");
110
+ }
111
+ lines.push(...formatAtlasObject(object));
112
+ });
113
+ return lines.join("\n");
114
+ }
115
+ export function formatDraftDocument(document) {
116
+ const legacy = document.version === "2.0-draft"
117
+ ? document
118
+ : {
119
+ ...document,
120
+ version: "2.0-draft",
121
+ schemaVersion: "2.0-draft",
122
+ };
123
+ const lines = ["schema 2.0-draft", ""];
124
+ if (legacy.system) {
125
+ lines.push(...formatAtlasSystem(legacy.system));
126
+ }
127
+ for (const group of [...legacy.groups].sort(compareIdLike)) {
128
+ lines.push("");
129
+ lines.push(...formatAtlasGroup(group));
130
+ }
131
+ for (const relation of [...legacy.relations].sort(compareIdLike)) {
132
+ lines.push("");
133
+ lines.push(...formatAtlasRelation(relation));
134
+ }
135
+ const sortedObjects = [...legacy.objects].sort(compareObjects);
136
+ if (sortedObjects.length > 0 && lines.at(-1) !== "") {
137
+ lines.push("");
138
+ }
139
+ sortedObjects.forEach((object, index) => {
140
+ if (index > 0) {
141
+ lines.push("");
142
+ }
143
+ lines.push(...formatAtlasObject(object));
144
+ });
145
+ return lines.join("\n");
146
+ }
147
+ function formatSystem(system) {
148
+ return formatLines("system", system.id, system.properties, null, system.info);
149
+ }
150
+ function formatLines(objectType, id, properties, placement, info) {
151
+ const lines = [`${objectType} ${id}`];
152
+ const fieldLines = [...formatPlacement(placement), ...formatProperties(properties)];
153
+ for (const fieldLine of fieldLines) {
154
+ lines.push(` ${fieldLine}`);
155
+ }
156
+ const infoEntries = Object.entries(info).sort(([left], [right]) => left.localeCompare(right));
157
+ if (infoEntries.length > 0) {
158
+ if (fieldLines.length > 0) {
159
+ lines.push("");
160
+ }
161
+ lines.push(" info");
162
+ for (const [key, value] of infoEntries) {
163
+ lines.push(` ${key} ${quoteIfNeeded(value)}`);
164
+ }
165
+ }
166
+ return lines;
167
+ }
168
+ function formatAtlasSystem(system) {
169
+ const lines = [`system ${system.id}`];
170
+ if (system.title) {
171
+ lines.push(` title ${quoteIfNeeded(system.title)}`);
172
+ }
173
+ if (system.description) {
174
+ lines.push(` description ${quoteIfNeeded(system.description)}`);
175
+ }
176
+ if (system.epoch) {
177
+ lines.push(` epoch ${quoteIfNeeded(system.epoch)}`);
178
+ }
179
+ if (system.referencePlane) {
180
+ lines.push(` referencePlane ${quoteIfNeeded(system.referencePlane)}`);
181
+ }
182
+ lines.push("");
183
+ lines.push("defaults");
184
+ lines.push(` view ${system.defaults.view}`);
185
+ if (system.defaults.scale) {
186
+ lines.push(` scale ${quoteIfNeeded(system.defaults.scale)}`);
187
+ }
188
+ if (system.defaults.units) {
189
+ lines.push(` units ${quoteIfNeeded(system.defaults.units)}`);
190
+ }
191
+ if (system.defaults.preset) {
192
+ lines.push(` preset ${system.defaults.preset}`);
193
+ }
194
+ if (system.defaults.theme) {
195
+ lines.push(` theme ${quoteIfNeeded(system.defaults.theme)}`);
196
+ }
197
+ if (Object.keys(system.atlasMetadata).length > 0) {
198
+ lines.push("");
199
+ lines.push("atlas");
200
+ lines.push(" metadata");
201
+ for (const [key, value] of Object.entries(system.atlasMetadata).sort(([left], [right]) => left.localeCompare(right))) {
202
+ lines.push(` ${key} ${quoteIfNeeded(value)}`);
203
+ }
204
+ }
205
+ for (const viewpoint of system.viewpoints) {
206
+ lines.push("");
207
+ lines.push(...formatAtlasViewpoint(viewpoint));
208
+ }
209
+ for (const annotation of system.annotations) {
210
+ lines.push("");
211
+ lines.push(...formatAtlasAnnotation(annotation));
212
+ }
213
+ return lines;
214
+ }
215
+ function formatObject(object) {
216
+ return formatWorldOrbitObject(object.type, object.id, object);
217
+ }
218
+ function formatAtlasObject(object) {
219
+ return formatWorldOrbitObject(`object ${object.type}`, object.id, object);
220
+ }
221
+ function formatWorldOrbitObject(objectType, id, object) {
222
+ const lines = [`${objectType} ${id}`];
223
+ const fieldLines = [
224
+ ...formatPlacement(object.placement),
225
+ ...formatProperties(object.properties),
226
+ ...formatObjectMetadata(object),
227
+ ];
228
+ for (const fieldLine of fieldLines) {
229
+ lines.push(` ${fieldLine}`);
230
+ }
231
+ const infoEntries = Object.entries(object.info).sort(([left], [right]) => left.localeCompare(right));
232
+ if (infoEntries.length > 0) {
233
+ if (fieldLines.length > 0) {
234
+ lines.push("");
235
+ }
236
+ lines.push(" info");
237
+ for (const [key, value] of infoEntries) {
238
+ lines.push(` ${key} ${quoteIfNeeded(value)}`);
239
+ }
240
+ }
241
+ for (const blockName of ["climate", "habitability", "settlement"]) {
242
+ const blockEntries = Object.entries(object.typedBlocks?.[blockName] ?? {}).sort(([left], [right]) => left.localeCompare(right));
243
+ if (blockEntries.length > 0) {
244
+ lines.push("");
245
+ lines.push(` ${blockName}`);
246
+ for (const [key, value] of blockEntries) {
247
+ lines.push(` ${key} ${quoteIfNeeded(value)}`);
248
+ }
249
+ }
250
+ }
251
+ return lines;
252
+ }
253
+ function formatPlacement(placement) {
254
+ if (!placement)
255
+ return [];
256
+ switch (placement.mode) {
257
+ case "orbit":
258
+ return [
259
+ `orbit ${placement.target}`,
260
+ ...formatOptionalUnit("distance", placement.distance),
261
+ ...formatOptionalUnit("semiMajor", placement.semiMajor),
262
+ ...formatOptionalNumber("eccentricity", placement.eccentricity),
263
+ ...formatOptionalUnit("period", placement.period),
264
+ ...formatOptionalUnit("angle", placement.angle),
265
+ ...formatOptionalUnit("inclination", placement.inclination),
266
+ ...formatOptionalUnit("phase", placement.phase),
267
+ ];
268
+ case "at":
269
+ return [`at ${formatAtReference(placement.reference)}`];
270
+ case "surface":
271
+ return [`surface ${placement.target}`];
272
+ case "free":
273
+ return [`free ${placement.distance ? formatUnitValue(placement.distance) : placement.descriptor ?? ""}`.trim()];
274
+ }
275
+ }
276
+ function formatProperties(properties) {
277
+ return Object.keys(properties)
278
+ .sort(compareFieldKeys)
279
+ .map((key) => `${key} ${formatValue(properties[key])}`);
280
+ }
281
+ function formatObjectMetadata(object) {
282
+ const lines = [];
283
+ if (object.groups?.length) {
284
+ lines.push(`groups ${object.groups.join(" ")}`);
285
+ }
286
+ if (object.epoch) {
287
+ lines.push(`epoch ${quoteIfNeeded(object.epoch)}`);
288
+ }
289
+ if (object.referencePlane) {
290
+ lines.push(`referencePlane ${quoteIfNeeded(object.referencePlane)}`);
291
+ }
292
+ if (object.tidalLock !== undefined) {
293
+ lines.push(`tidalLock ${object.tidalLock ? "true" : "false"}`);
294
+ }
295
+ if (object.renderHints?.renderLabel !== undefined) {
296
+ lines.push(`renderLabel ${object.renderHints.renderLabel ? "true" : "false"}`);
297
+ }
298
+ if (object.renderHints?.renderOrbit !== undefined) {
299
+ lines.push(`renderOrbit ${object.renderHints.renderOrbit ? "true" : "false"}`);
300
+ }
301
+ if (object.renderHints?.renderPriority !== undefined) {
302
+ lines.push(`renderPriority ${object.renderHints.renderPriority}`);
303
+ }
304
+ if (object.resonance) {
305
+ lines.push(`resonance ${object.resonance.targetObjectId} ${object.resonance.ratio}`);
306
+ }
307
+ for (const rule of object.deriveRules ?? []) {
308
+ lines.push(`derive ${rule.field} ${rule.strategy}`);
309
+ }
310
+ for (const rule of object.validationRules ?? []) {
311
+ lines.push(`validate ${rule.rule}`);
312
+ }
313
+ if (object.lockedFields?.length) {
314
+ lines.push(`locked ${object.lockedFields.join(" ")}`);
315
+ }
316
+ for (const tolerance of object.tolerances ?? []) {
317
+ lines.push(`tolerance ${tolerance.field} ${formatValue(tolerance.value)}`);
318
+ }
319
+ return lines;
320
+ }
321
+ function formatAtlasViewpoint(viewpoint) {
322
+ const lines = [`viewpoint ${viewpoint.id}`, ` label ${quoteIfNeeded(viewpoint.label)}`];
323
+ if (viewpoint.focusObjectId) {
324
+ lines.push(` focus ${viewpoint.focusObjectId}`);
325
+ }
326
+ if (viewpoint.selectedObjectId && viewpoint.selectedObjectId !== viewpoint.focusObjectId) {
327
+ lines.push(` select ${viewpoint.selectedObjectId}`);
328
+ }
329
+ if (viewpoint.summary) {
330
+ lines.push(` summary ${quoteIfNeeded(viewpoint.summary)}`);
331
+ }
332
+ if (viewpoint.projection) {
333
+ lines.push(` projection ${viewpoint.projection}`);
334
+ }
335
+ if (viewpoint.preset) {
336
+ lines.push(` preset ${viewpoint.preset}`);
337
+ }
338
+ if (viewpoint.zoom !== null) {
339
+ lines.push(` zoom ${viewpoint.zoom}`);
340
+ }
341
+ if (viewpoint.rotationDeg !== 0) {
342
+ lines.push(` rotation ${viewpoint.rotationDeg}`);
343
+ }
344
+ const layerTokens = formatDraftLayers(viewpoint.layers);
345
+ if (layerTokens.length > 0) {
346
+ lines.push(` layers ${layerTokens.join(" ")}`);
347
+ }
348
+ if (viewpoint.filter) {
349
+ lines.push(" filter");
350
+ if (viewpoint.filter.query) {
351
+ lines.push(` query ${quoteIfNeeded(viewpoint.filter.query)}`);
352
+ }
353
+ if (viewpoint.filter.objectTypes.length > 0) {
354
+ lines.push(` objectTypes ${viewpoint.filter.objectTypes.join(" ")}`);
355
+ }
356
+ if (viewpoint.filter.tags.length > 0) {
357
+ lines.push(` tags ${viewpoint.filter.tags.map(quoteIfNeeded).join(" ")}`);
358
+ }
359
+ if (viewpoint.filter.groupIds.length > 0) {
360
+ lines.push(` groups ${viewpoint.filter.groupIds.join(" ")}`);
361
+ }
362
+ }
363
+ return lines;
364
+ }
365
+ function formatAtlasAnnotation(annotation) {
366
+ const lines = [`annotation ${annotation.id}`, ` label ${quoteIfNeeded(annotation.label)}`];
367
+ if (annotation.targetObjectId) {
368
+ lines.push(` target ${annotation.targetObjectId}`);
369
+ }
370
+ lines.push(` body ${quoteIfNeeded(annotation.body)}`);
371
+ if (annotation.tags.length > 0) {
372
+ lines.push(` tags ${annotation.tags.map(quoteIfNeeded).join(" ")}`);
373
+ }
374
+ return lines;
375
+ }
376
+ function formatAtlasGroup(group) {
377
+ const lines = [`group ${group.id}`, ` label ${quoteIfNeeded(group.label)}`];
378
+ if (group.summary) {
379
+ lines.push(` summary ${quoteIfNeeded(group.summary)}`);
380
+ }
381
+ if (group.color) {
382
+ lines.push(` color ${quoteIfNeeded(group.color)}`);
383
+ }
384
+ if (group.tags.length > 0) {
385
+ lines.push(` tags ${group.tags.map(quoteIfNeeded).join(" ")}`);
386
+ }
387
+ if (group.hidden) {
388
+ lines.push(" hidden true");
389
+ }
390
+ return lines;
391
+ }
392
+ function formatAtlasRelation(relation) {
393
+ const lines = [`relation ${relation.id}`];
394
+ if (relation.from) {
395
+ lines.push(` from ${quoteIfNeeded(relation.from)}`);
396
+ }
397
+ if (relation.to) {
398
+ lines.push(` to ${quoteIfNeeded(relation.to)}`);
399
+ }
400
+ if (relation.kind) {
401
+ lines.push(` kind ${quoteIfNeeded(relation.kind)}`);
402
+ }
403
+ if (relation.label) {
404
+ lines.push(` label ${quoteIfNeeded(relation.label)}`);
405
+ }
406
+ if (relation.summary) {
407
+ lines.push(` summary ${quoteIfNeeded(relation.summary)}`);
408
+ }
409
+ if (relation.tags.length > 0) {
410
+ lines.push(` tags ${relation.tags.map(quoteIfNeeded).join(" ")}`);
411
+ }
412
+ if (relation.color) {
413
+ lines.push(` color ${quoteIfNeeded(relation.color)}`);
414
+ }
415
+ if (relation.hidden) {
416
+ lines.push(" hidden true");
417
+ }
418
+ return lines;
419
+ }
420
+ function formatValue(value) {
421
+ if (Array.isArray(value)) {
422
+ return value.map((item) => quoteIfNeeded(item)).join(" ");
423
+ }
424
+ if (typeof value === "boolean") {
425
+ return value ? "true" : "false";
426
+ }
427
+ if (typeof value === "number") {
428
+ return String(value);
429
+ }
430
+ if (typeof value === "string") {
431
+ return quoteIfNeeded(value);
432
+ }
433
+ return formatUnitValue(value);
434
+ }
435
+ function formatUnitValue(value) {
436
+ return `${value.value}${value.unit ?? ""}`;
437
+ }
438
+ function formatOptionalUnit(key, value) {
439
+ return value ? [`${key} ${formatUnitValue(value)}`] : [];
440
+ }
441
+ function formatOptionalNumber(key, value) {
442
+ return value === undefined ? [] : [`${key} ${value}`];
443
+ }
444
+ function formatAtReference(reference) {
445
+ switch (reference.kind) {
446
+ case "lagrange":
447
+ return reference.secondary
448
+ ? `${reference.primary}-${reference.secondary}:${reference.point}`
449
+ : `${reference.primary}:${reference.point}`;
450
+ case "anchor":
451
+ return `${reference.objectId}:${reference.anchor}`;
452
+ case "named":
453
+ return reference.name;
454
+ }
455
+ }
456
+ function formatDraftLayers(layers) {
457
+ const tokens = [];
458
+ const orbitFront = layers["orbits-front"];
459
+ const orbitBack = layers["orbits-back"];
460
+ if (orbitFront !== undefined || orbitBack !== undefined) {
461
+ tokens.push(orbitFront !== false || orbitBack !== false
462
+ ? "orbits"
463
+ : "-orbits");
464
+ }
465
+ for (const key of ["background", "guides", "relations", "objects", "labels", "metadata"]) {
466
+ if (layers[key] !== undefined) {
467
+ tokens.push(layers[key] ? key : `-${key}`);
468
+ }
469
+ }
470
+ return tokens;
471
+ }
472
+ function compareFieldKeys(left, right) {
473
+ const leftIndex = CANONICAL_FIELD_ORDER.indexOf(left);
474
+ const rightIndex = CANONICAL_FIELD_ORDER.indexOf(right);
475
+ if (leftIndex === -1 && rightIndex === -1)
476
+ return left.localeCompare(right);
477
+ if (leftIndex === -1)
478
+ return 1;
479
+ if (rightIndex === -1)
480
+ return -1;
481
+ return leftIndex - rightIndex;
482
+ }
483
+ function compareObjects(left, right) {
484
+ const leftIndex = objectTypeIndex(left.type);
485
+ const rightIndex = objectTypeIndex(right.type);
486
+ if (leftIndex !== rightIndex)
487
+ return leftIndex - rightIndex;
488
+ return left.id.localeCompare(right.id);
489
+ }
490
+ function compareIdLike(left, right) {
491
+ return left.id.localeCompare(right.id);
492
+ }
493
+ function objectTypeIndex(objectType) {
494
+ switch (objectType) {
495
+ case "star":
496
+ return 0;
497
+ case "planet":
498
+ return 1;
499
+ case "moon":
500
+ return 2;
501
+ case "belt":
502
+ return 3;
503
+ case "asteroid":
504
+ return 4;
505
+ case "comet":
506
+ return 5;
507
+ case "ring":
508
+ return 6;
509
+ case "structure":
510
+ return 7;
511
+ case "phenomenon":
512
+ return 8;
513
+ }
514
+ }
515
+ function quoteIfNeeded(value) {
516
+ if (!/\s/.test(value) && !value.includes('"')) {
517
+ return value;
518
+ }
519
+ return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
520
+ }
@@ -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>;