worldorbit 3.0.7 → 3.2.0

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 (40) hide show
  1. package/dist/browser/core/dist/atlas-edit.js +5 -1
  2. package/dist/browser/core/dist/atlas-validate.js +1 -1
  3. package/dist/browser/core/dist/draft-parse.js +16 -9
  4. package/dist/browser/core/dist/draft.d.ts +1 -0
  5. package/dist/browser/core/dist/draft.js +4 -2
  6. package/dist/browser/core/dist/format.js +5 -3
  7. package/dist/browser/core/dist/load.js +7 -2
  8. package/dist/browser/core/dist/normalize.js +36 -0
  9. package/dist/browser/core/dist/parse.js +54 -0
  10. package/dist/browser/core/dist/scene.js +1 -0
  11. package/dist/browser/core/dist/types.d.ts +21 -1
  12. package/dist/unpkg/core/dist/atlas-edit.js +5 -1
  13. package/dist/unpkg/core/dist/atlas-validate.js +1 -1
  14. package/dist/unpkg/core/dist/draft-parse.js +16 -9
  15. package/dist/unpkg/core/dist/draft.d.ts +1 -0
  16. package/dist/unpkg/core/dist/draft.js +4 -2
  17. package/dist/unpkg/core/dist/format.js +5 -3
  18. package/dist/unpkg/core/dist/load.js +7 -2
  19. package/dist/unpkg/core/dist/normalize.js +36 -0
  20. package/dist/unpkg/core/dist/parse.js +54 -0
  21. package/dist/unpkg/core/dist/scene.js +1 -0
  22. package/dist/unpkg/core/dist/types.d.ts +21 -1
  23. package/dist/unpkg/worldorbit-core.min.js +9 -9
  24. package/dist/unpkg/worldorbit-editor.min.js +219 -219
  25. package/dist/unpkg/worldorbit-markdown.min.js +19 -19
  26. package/dist/unpkg/worldorbit-viewer.min.js +203 -203
  27. package/dist/unpkg/worldorbit.js +118 -14
  28. package/dist/unpkg/worldorbit.min.js +191 -191
  29. package/package.json +1 -1
  30. package/packages/core/dist/atlas-edit.js +5 -1
  31. package/packages/core/dist/atlas-validate.js +1 -1
  32. package/packages/core/dist/draft-parse.js +16 -9
  33. package/packages/core/dist/draft.d.ts +1 -0
  34. package/packages/core/dist/draft.js +4 -2
  35. package/packages/core/dist/format.js +5 -3
  36. package/packages/core/dist/load.js +7 -2
  37. package/packages/core/dist/normalize.js +36 -0
  38. package/packages/core/dist/parse.js +54 -0
  39. package/packages/core/dist/scene.js +1 -0
  40. package/packages/core/dist/types.d.ts +21 -1
@@ -4,9 +4,14 @@ import { getIndent, tokenizeLineDetailed } from "./tokenize.js";
4
4
  export function parseWorldOrbit(source) {
5
5
  const lines = source.split(/\r?\n/);
6
6
  const objects = [];
7
+ let themeNode = null;
7
8
  let currentObject = null;
8
9
  let inInfoBlock = false;
10
+ let inThemeBlock = false;
9
11
  let infoIndent = null;
12
+ let themeIndent = null;
13
+ let themeBlockIndent = null;
14
+ let currentThemeBlock = null;
10
15
  for (let index = 0; index < lines.length; index++) {
11
16
  const rawLine = lines[index];
12
17
  const lineNumber = index + 1;
@@ -23,12 +28,49 @@ export function parseWorldOrbit(source) {
23
28
  }
24
29
  if (indent === 0) {
25
30
  inInfoBlock = false;
31
+ inThemeBlock = false;
26
32
  infoIndent = null;
33
+ themeIndent = null;
34
+ themeBlockIndent = null;
35
+ currentThemeBlock = null;
36
+ if (tokens.length >= 1 && tokens[0].value === "theme") {
37
+ inThemeBlock = true;
38
+ themeIndent = 0;
39
+ themeNode = {
40
+ type: "theme",
41
+ preset: tokens.length >= 2 ? tokens[1].value : null,
42
+ blocks: [],
43
+ location: { line: lineNumber, column: tokens[0].column },
44
+ };
45
+ continue;
46
+ }
27
47
  const objectNode = parseObjectHeader(tokens, lineNumber);
28
48
  objects.push(objectNode);
29
49
  currentObject = objectNode;
30
50
  continue;
31
51
  }
52
+ if (inThemeBlock) {
53
+ if (tokens.length >= 2 && tokens[0].value === "preset" && (!themeBlockIndent || indent <= themeBlockIndent)) {
54
+ if (themeNode) {
55
+ themeNode.preset = tokens[1].value;
56
+ }
57
+ continue;
58
+ }
59
+ if (currentThemeBlock && themeBlockIndent !== null && indent > themeBlockIndent) {
60
+ currentThemeBlock.fields.push(parseThemeField(tokens, lineNumber));
61
+ }
62
+ else {
63
+ themeBlockIndent = indent;
64
+ currentThemeBlock = {
65
+ type: "theme-block",
66
+ target: tokens[0].value,
67
+ fields: [],
68
+ location: { line: lineNumber, column: tokens[0].column },
69
+ };
70
+ themeNode?.blocks.push(currentThemeBlock);
71
+ }
72
+ continue;
73
+ }
32
74
  if (!currentObject) {
33
75
  throw new WorldOrbitError("Indented line without parent object", lineNumber, indent + 1);
34
76
  }
@@ -49,6 +91,7 @@ export function parseWorldOrbit(source) {
49
91
  }
50
92
  return {
51
93
  type: "document",
94
+ theme: themeNode,
52
95
  objects,
53
96
  };
54
97
  }
@@ -120,6 +163,17 @@ function parseField(tokens, line) {
120
163
  location: { line, column: tokens[0].column },
121
164
  };
122
165
  }
166
+ function parseThemeField(tokens, line) {
167
+ if (tokens.length < 2) {
168
+ throw new WorldOrbitError("Invalid theme field line", line, tokens[0]?.column ?? 1);
169
+ }
170
+ return {
171
+ type: "field",
172
+ key: tokens[0].value,
173
+ values: tokens.slice(1).map((token) => token.value),
174
+ location: { line, column: tokens[0].column },
175
+ };
176
+ }
123
177
  function parseInfoEntry(tokens, line) {
124
178
  if (tokens.length < 2) {
125
179
  throw new WorldOrbitError("Invalid info entry", line, tokens[0]?.column ?? 1);
@@ -1064,6 +1064,7 @@ function parseViewpointGroups(value, document, relationships, objectMap) {
1064
1064
  return splitListValue(value).map((entry) => {
1065
1065
  if (document.schemaVersion === "2.1" ||
1066
1066
  document.schemaVersion === "2.5" ||
1067
+ document.schemaVersion === "2.6" ||
1067
1068
  document.groups.some((group) => group.id === entry)) {
1068
1069
  return entry;
1069
1070
  }
@@ -2,7 +2,7 @@ export type WorldOrbitObjectType = "system" | "star" | "planet" | "moon" | "belt
2
2
  export type PlacementMode = "orbit" | "at" | "surface" | "free";
3
3
  export type Unit = "au" | "km" | "m" | "ly" | "pc" | "kpc" | "re" | "rj" | "sol" | "me" | "mj" | "s" | "min" | "h" | "d" | "y" | "ky" | "my" | "gy" | "K" | "deg";
4
4
  export type WorldOrbitDocumentVersion = "1.0";
5
- export type WorldOrbitAtlasDocumentVersion = "2.0" | "2.1" | "2.5";
5
+ export type WorldOrbitAtlasDocumentVersion = "2.0" | "2.1" | "2.5" | "2.6";
6
6
  export type WorldOrbitDraftDocumentVersion = "2.0-draft";
7
7
  export type WorldOrbitAnyDocumentVersion = WorldOrbitDocumentVersion | WorldOrbitAtlasDocumentVersion | WorldOrbitDraftDocumentVersion;
8
8
  export type ViewProjection = "topdown" | "isometric" | "orthographic" | "perspective";
@@ -34,8 +34,21 @@ export interface TokenizeOptions {
34
34
  line?: number;
35
35
  columnOffset?: number;
36
36
  }
37
+ export interface AstThemeNode {
38
+ type: "theme";
39
+ preset: string | null;
40
+ blocks: AstThemeBlockNode[];
41
+ location: AstSourceLocation;
42
+ }
43
+ export interface AstThemeBlockNode {
44
+ type: "theme-block";
45
+ target: string;
46
+ fields: AstFieldNode[];
47
+ location: AstSourceLocation;
48
+ }
37
49
  export interface AstDocument {
38
50
  type: "document";
51
+ theme: AstThemeNode | null;
39
52
  objects: AstObjectNode[];
40
53
  }
41
54
  export interface AstObjectNode {
@@ -59,10 +72,15 @@ export interface AstInfoEntryNode {
59
72
  value: string;
60
73
  location: AstSourceLocation;
61
74
  }
75
+ export interface NormalizedTheme {
76
+ preset: string | null;
77
+ styles: Record<string, Record<string, NormalizedValue>>;
78
+ }
62
79
  export interface WorldOrbitDocument {
63
80
  format: "worldorbit";
64
81
  version: WorldOrbitDocumentVersion;
65
82
  schemaVersion: WorldOrbitAnyDocumentVersion;
83
+ theme: NormalizedTheme | null;
66
84
  system: WorldOrbitSystem | null;
67
85
  groups: WorldOrbitGroup[];
68
86
  relations: WorldOrbitRelation[];
@@ -74,6 +92,7 @@ export interface WorldOrbitAtlasDocument {
74
92
  version: WorldOrbitAtlasDocumentVersion;
75
93
  schemaVersion: WorldOrbitAtlasDocumentVersion;
76
94
  sourceVersion: WorldOrbitDocumentVersion;
95
+ theme: NormalizedTheme | null;
77
96
  system: WorldOrbitAtlasSystem | null;
78
97
  groups: WorldOrbitGroup[];
79
98
  relations: WorldOrbitRelation[];
@@ -86,6 +105,7 @@ export interface WorldOrbitDraftDocument {
86
105
  version: WorldOrbitDraftDocumentVersion;
87
106
  schemaVersion: WorldOrbitDraftDocumentVersion;
88
107
  sourceVersion: WorldOrbitDocumentVersion;
108
+ theme: NormalizedTheme | null;
89
109
  system: WorldOrbitAtlasSystem | null;
90
110
  groups: WorldOrbitGroup[];
91
111
  relations: WorldOrbitRelation[];