worldorbit 2.5.10 → 2.5.11

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 (35) hide show
  1. package/package.json +1 -1
  2. package/packages/editor/dist/editor.js +8 -2
  3. package/packages/viewer/dist/viewer.js +16 -1
  4. package/packages/core/dist/atlas-edit.d.ts +0 -11
  5. package/packages/core/dist/atlas-edit.js +0 -210
  6. package/packages/core/dist/diagnostics.d.ts +0 -10
  7. package/packages/core/dist/diagnostics.js +0 -109
  8. package/packages/core/dist/draft-parse.d.ts +0 -3
  9. package/packages/core/dist/draft-parse.js +0 -642
  10. package/packages/core/dist/draft.d.ts +0 -15
  11. package/packages/core/dist/draft.js +0 -343
  12. package/packages/core/dist/errors.d.ts +0 -7
  13. package/packages/core/dist/errors.js +0 -16
  14. package/packages/core/dist/format.d.ts +0 -4
  15. package/packages/core/dist/format.js +0 -364
  16. package/packages/core/dist/index.d.ts +0 -28
  17. package/packages/core/dist/index.js +0 -44
  18. package/packages/core/dist/load.d.ts +0 -4
  19. package/packages/core/dist/load.js +0 -130
  20. package/packages/core/dist/markdown.d.ts +0 -2
  21. package/packages/core/dist/markdown.js +0 -37
  22. package/packages/core/dist/normalize.d.ts +0 -2
  23. package/packages/core/dist/normalize.js +0 -304
  24. package/packages/core/dist/parse.d.ts +0 -2
  25. package/packages/core/dist/parse.js +0 -133
  26. package/packages/core/dist/scene.d.ts +0 -3
  27. package/packages/core/dist/scene.js +0 -1500
  28. package/packages/core/dist/schema.d.ts +0 -8
  29. package/packages/core/dist/schema.js +0 -298
  30. package/packages/core/dist/tokenize.d.ts +0 -4
  31. package/packages/core/dist/tokenize.js +0 -68
  32. package/packages/core/dist/types.d.ts +0 -382
  33. package/packages/core/dist/types.js +0 -1
  34. package/packages/core/dist/validate.d.ts +0 -2
  35. package/packages/core/dist/validate.js +0 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worldorbit",
3
- "version": "2.5.10",
3
+ "version": "2.5.11",
4
4
  "description": "A text-based DSL and parser pipeline for orbital worldbuilding",
5
5
  "type": "module",
6
6
  "main": "./dist/unpkg/worldorbit.esm.js",
@@ -466,7 +466,9 @@ export function createWorldOrbitEditor(container, options = {}) {
466
466
  }
467
467
  renderToolbar();
468
468
  renderOutline();
469
- renderInspector();
469
+ if (!inspector?.contains(document.activeElement)) {
470
+ renderInspector();
471
+ }
470
472
  renderStageOverlay();
471
473
  renderStatusBar();
472
474
  updateLiveRegion();
@@ -491,7 +493,11 @@ export function createWorldOrbitEditor(container, options = {}) {
491
493
  renderOutline();
492
494
  renderDiagnostics();
493
495
  renderSourceDiagnostics();
494
- renderInspector();
496
+ // Do not rebuild the inspector DOM if the user is currently typing in it,
497
+ // to prevent losing focus/cursor position and making input glitchy.
498
+ if (!inspector?.contains(document.activeElement)) {
499
+ renderInspector();
500
+ }
495
501
  renderSourcePane();
496
502
  renderPreview(immediatePreview);
497
503
  renderStageOverlay();
@@ -109,6 +109,10 @@ export function createInteractiveViewer(container, options) {
109
109
  if (touchPoints.size === 2) {
110
110
  touchGesture = createTouchGestureState(scene, state, touchPoints);
111
111
  }
112
+ else if (touchPoints.size === 1) {
113
+ dragDistance = 0;
114
+ suppressClick = false;
115
+ }
112
116
  return;
113
117
  }
114
118
  activePointerId = event.pointerId;
@@ -125,7 +129,9 @@ export function createInteractiveViewer(container, options) {
125
129
  if (!behavior.touch || !touchPoints.has(event.pointerId)) {
126
130
  return;
127
131
  }
128
- touchPoints.set(event.pointerId, getViewportPointFromClient(event.clientX, event.clientY));
132
+ const prevPoint = touchPoints.get(event.pointerId);
133
+ const nextPoint = getViewportPointFromClient(event.clientX, event.clientY);
134
+ touchPoints.set(event.pointerId, nextPoint);
129
135
  if (touchPoints.size === 2) {
130
136
  if (!touchGesture) {
131
137
  touchGesture = createTouchGestureState(scene, state, touchPoints);
@@ -137,6 +143,15 @@ export function createInteractiveViewer(container, options) {
137
143
  const deltaY = current.center.y - touchGesture.startViewportCenter.y;
138
144
  updateState(panViewerState(zoomedState, deltaX, deltaY));
139
145
  }
146
+ else if (touchPoints.size === 1) {
147
+ const deltaX = nextPoint.x - prevPoint.x;
148
+ const deltaY = nextPoint.y - prevPoint.y;
149
+ dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
150
+ if (dragDistance > 2) {
151
+ suppressClick = true;
152
+ }
153
+ updateState(panViewerState(state, deltaX, deltaY));
154
+ }
140
155
  return;
141
156
  }
142
157
  if (!behavior.pointer || activePointerId !== event.pointerId || !lastPointerPoint) {
@@ -1,11 +0,0 @@
1
- import type { AtlasDocumentPath, AtlasResolvedDiagnostic, WorldOrbitAtlasDocument, WorldOrbitDiagnostic } from "./types.js";
2
- export declare function createEmptyAtlasDocument(systemId?: string): WorldOrbitAtlasDocument;
3
- export declare function cloneAtlasDocument(document: WorldOrbitAtlasDocument): WorldOrbitAtlasDocument;
4
- export declare function listAtlasDocumentPaths(document: WorldOrbitAtlasDocument): AtlasDocumentPath[];
5
- export declare function getAtlasDocumentNode(document: WorldOrbitAtlasDocument, path: AtlasDocumentPath): unknown;
6
- export declare function upsertAtlasDocumentNode(document: WorldOrbitAtlasDocument, path: AtlasDocumentPath, value: unknown): WorldOrbitAtlasDocument;
7
- export declare function updateAtlasDocumentNode(document: WorldOrbitAtlasDocument, path: AtlasDocumentPath, updater: (value: unknown) => unknown): WorldOrbitAtlasDocument;
8
- export declare function removeAtlasDocumentNode(document: WorldOrbitAtlasDocument, path: AtlasDocumentPath): WorldOrbitAtlasDocument;
9
- export declare function resolveAtlasDiagnostics(document: WorldOrbitAtlasDocument, diagnostics: WorldOrbitDiagnostic[]): AtlasResolvedDiagnostic[];
10
- export declare function resolveAtlasDiagnosticPath(document: WorldOrbitAtlasDocument, diagnostic: WorldOrbitDiagnostic): AtlasDocumentPath | null;
11
- export declare function validateAtlasDocumentWithDiagnostics(document: WorldOrbitAtlasDocument): AtlasResolvedDiagnostic[];
@@ -1,210 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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>;
@@ -1,109 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- import type { WorldOrbitAtlasDocument, WorldOrbitDraftDocument } from "./types.js";
2
- export declare function parseWorldOrbitAtlas(source: string): WorldOrbitAtlasDocument;
3
- export declare function parseWorldOrbitDraft(source: string): WorldOrbitDraftDocument;