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.
Files changed (113) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +250 -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/test.html +1 -0
  25. package/dist/unpkg/viewer/dist/index.js +6038 -0
  26. package/dist/unpkg/worldorbit-core.min.js +5 -0
  27. package/dist/unpkg/worldorbit-markdown.min.js +81 -0
  28. package/dist/unpkg/worldorbit-viewer.min.js +232 -0
  29. package/dist/unpkg/worldorbit.d.ts +2 -0
  30. package/dist/unpkg/worldorbit.js +2 -0
  31. package/dist/unpkg/worldorbit.min.js +236 -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 +64 -0
  39. package/packages/core/README.md +13 -0
  40. package/packages/core/dist/atlas-edit.d.ts +11 -0
  41. package/packages/core/dist/atlas-edit.js +210 -0
  42. package/packages/core/dist/diagnostics.d.ts +10 -0
  43. package/packages/core/dist/diagnostics.js +109 -0
  44. package/packages/core/dist/draft-parse.d.ts +3 -0
  45. package/packages/core/dist/draft-parse.js +642 -0
  46. package/packages/core/dist/draft.d.ts +15 -0
  47. package/packages/core/dist/draft.js +343 -0
  48. package/packages/core/dist/errors.d.ts +7 -0
  49. package/packages/core/dist/errors.js +16 -0
  50. package/packages/core/dist/format.d.ts +4 -0
  51. package/packages/core/dist/format.js +364 -0
  52. package/packages/core/dist/index.d.ts +28 -0
  53. package/packages/core/dist/index.js +44 -0
  54. package/packages/core/dist/load.d.ts +4 -0
  55. package/packages/core/dist/load.js +130 -0
  56. package/packages/core/dist/markdown.d.ts +2 -0
  57. package/packages/core/dist/markdown.js +37 -0
  58. package/packages/core/dist/normalize.d.ts +2 -0
  59. package/packages/core/dist/normalize.js +304 -0
  60. package/packages/core/dist/parse.d.ts +2 -0
  61. package/packages/core/dist/parse.js +133 -0
  62. package/packages/core/dist/scene.d.ts +3 -0
  63. package/packages/core/dist/scene.js +1484 -0
  64. package/packages/core/dist/schema.d.ts +8 -0
  65. package/packages/core/dist/schema.js +298 -0
  66. package/packages/core/dist/tokenize.d.ts +4 -0
  67. package/packages/core/dist/tokenize.js +68 -0
  68. package/packages/core/dist/types.d.ts +382 -0
  69. package/packages/core/dist/types.js +1 -0
  70. package/packages/core/dist/validate.d.ts +2 -0
  71. package/packages/core/dist/validate.js +56 -0
  72. package/packages/editor/dist/editor.d.ts +2 -0
  73. package/packages/editor/dist/editor.js +2620 -0
  74. package/packages/editor/dist/index.d.ts +2 -0
  75. package/packages/editor/dist/index.js +1 -0
  76. package/packages/editor/dist/types.d.ts +53 -0
  77. package/packages/editor/dist/types.js +1 -0
  78. package/packages/markdown/README.md +9 -0
  79. package/packages/markdown/dist/html.d.ts +3 -0
  80. package/packages/markdown/dist/html.js +57 -0
  81. package/packages/markdown/dist/index.d.ts +4 -0
  82. package/packages/markdown/dist/index.js +3 -0
  83. package/packages/markdown/dist/rehype.d.ts +10 -0
  84. package/packages/markdown/dist/rehype.js +49 -0
  85. package/packages/markdown/dist/remark.d.ts +9 -0
  86. package/packages/markdown/dist/remark.js +28 -0
  87. package/packages/markdown/dist/types.d.ts +11 -0
  88. package/packages/markdown/dist/types.js +1 -0
  89. package/packages/viewer/README.md +12 -0
  90. package/packages/viewer/dist/atlas-state.d.ts +12 -0
  91. package/packages/viewer/dist/atlas-state.js +251 -0
  92. package/packages/viewer/dist/atlas-viewer.d.ts +2 -0
  93. package/packages/viewer/dist/atlas-viewer.js +448 -0
  94. package/packages/viewer/dist/custom-element.d.ts +1 -0
  95. package/packages/viewer/dist/custom-element.js +64 -0
  96. package/packages/viewer/dist/embed.d.ts +20 -0
  97. package/packages/viewer/dist/embed.js +138 -0
  98. package/packages/viewer/dist/index.d.ts +9 -0
  99. package/packages/viewer/dist/index.js +8 -0
  100. package/packages/viewer/dist/minimap.d.ts +3 -0
  101. package/packages/viewer/dist/minimap.js +63 -0
  102. package/packages/viewer/dist/render.d.ts +6 -0
  103. package/packages/viewer/dist/render.js +585 -0
  104. package/packages/viewer/dist/theme.d.ts +4 -0
  105. package/packages/viewer/dist/theme.js +98 -0
  106. package/packages/viewer/dist/tooltip.d.ts +3 -0
  107. package/packages/viewer/dist/tooltip.js +154 -0
  108. package/packages/viewer/dist/types.d.ts +256 -0
  109. package/packages/viewer/dist/types.js +1 -0
  110. package/packages/viewer/dist/viewer-state.d.ts +19 -0
  111. package/packages/viewer/dist/viewer-state.js +162 -0
  112. package/packages/viewer/dist/viewer.d.ts +2 -0
  113. package/packages/viewer/dist/viewer.js +1156 -0
@@ -0,0 +1,162 @@
1
+ import { rotatePoint, } from "@worldorbit/core";
2
+ export const DEFAULT_VIEWER_STATE = {
3
+ scale: 1,
4
+ rotationDeg: 0,
5
+ translateX: 0,
6
+ translateY: 0,
7
+ selectedObjectId: null,
8
+ };
9
+ export function normalizeRotation(rotationDeg) {
10
+ let normalized = rotationDeg % 360;
11
+ if (normalized > 180) {
12
+ normalized -= 360;
13
+ }
14
+ if (normalized <= -180) {
15
+ normalized += 360;
16
+ }
17
+ return normalized;
18
+ }
19
+ export function clampScale(scale, constraints) {
20
+ return Math.min(Math.max(scale, constraints.minScale), constraints.maxScale);
21
+ }
22
+ export function panViewerState(state, dx, dy) {
23
+ return {
24
+ ...state,
25
+ translateX: state.translateX + dx,
26
+ translateY: state.translateY + dy,
27
+ };
28
+ }
29
+ export function rotateViewerState(state, deltaDeg) {
30
+ return {
31
+ ...state,
32
+ rotationDeg: normalizeRotation(state.rotationDeg + deltaDeg),
33
+ };
34
+ }
35
+ export function zoomViewerStateAt(scene, state, factor, anchor, constraints) {
36
+ if (!Number.isFinite(factor) || factor <= 0) {
37
+ return state;
38
+ }
39
+ const center = getSceneCenter(scene);
40
+ const nextScale = clampScale(state.scale * factor, constraints);
41
+ if (nextScale === state.scale) {
42
+ return state;
43
+ }
44
+ const zoomRatio = nextScale / state.scale;
45
+ const anchorDx = anchor.x - center.x;
46
+ const anchorDy = anchor.y - center.y;
47
+ return {
48
+ ...state,
49
+ scale: nextScale,
50
+ translateX: (1 - zoomRatio) * anchorDx + zoomRatio * state.translateX,
51
+ translateY: (1 - zoomRatio) * anchorDy + zoomRatio * state.translateY,
52
+ };
53
+ }
54
+ export function fitViewerState(scene, state, constraints) {
55
+ const center = getSceneCenter(scene);
56
+ const rotatedBounds = rotateBounds(scene.contentBounds, center, state.rotationDeg);
57
+ const availableWidth = Math.max(scene.width - constraints.fitPadding * 2, 1);
58
+ const availableHeight = Math.max(scene.height - constraints.fitPadding * 2, 1);
59
+ const safeWidth = Math.max(rotatedBounds.width, 1);
60
+ const safeHeight = Math.max(rotatedBounds.height, 1);
61
+ const nextScale = clampScale(Math.min(availableWidth / safeWidth, availableHeight / safeHeight), constraints);
62
+ const rotatedCenter = rotatePoint({
63
+ x: scene.contentBounds.centerX,
64
+ y: scene.contentBounds.centerY,
65
+ }, center, state.rotationDeg);
66
+ return {
67
+ ...state,
68
+ scale: nextScale,
69
+ translateX: center.x - (center.x + (rotatedCenter.x - center.x) * nextScale),
70
+ translateY: center.y - (center.y + (rotatedCenter.y - center.y) * nextScale),
71
+ };
72
+ }
73
+ export function focusViewerState(scene, state, objectId, constraints) {
74
+ const target = scene.objects.find((object) => object.objectId === objectId && !object.hidden);
75
+ if (!target) {
76
+ return state;
77
+ }
78
+ const center = getSceneCenter(scene);
79
+ const nextScale = clampScale(Math.max(state.scale, 1.8), constraints);
80
+ const rotatedPoint = rotatePoint({ x: target.x, y: target.y }, center, state.rotationDeg);
81
+ return {
82
+ ...state,
83
+ scale: nextScale,
84
+ translateX: center.x - (center.x + (rotatedPoint.x - center.x) * nextScale),
85
+ translateY: center.y - (center.y + (rotatedPoint.y - center.y) * nextScale),
86
+ selectedObjectId: objectId,
87
+ };
88
+ }
89
+ export function composeViewerTransform(scene, state) {
90
+ const center = getSceneCenter(scene);
91
+ return `translate(${state.translateX} ${state.translateY}) translate(${center.x} ${center.y}) rotate(${state.rotationDeg}) scale(${state.scale}) translate(${-center.x} ${-center.y})`;
92
+ }
93
+ export function invertViewerPoint(scene, state, point) {
94
+ const center = getSceneCenter(scene);
95
+ const translated = {
96
+ x: point.x - state.translateX,
97
+ y: point.y - state.translateY,
98
+ };
99
+ const centered = {
100
+ x: translated.x - center.x,
101
+ y: translated.y - center.y,
102
+ };
103
+ const scaled = {
104
+ x: centered.x / Math.max(state.scale, 0.0001),
105
+ y: centered.y / Math.max(state.scale, 0.0001),
106
+ };
107
+ const unrotated = rotatePoint({ x: scaled.x, y: scaled.y }, { x: 0, y: 0 }, -state.rotationDeg);
108
+ return {
109
+ x: center.x + unrotated.x,
110
+ y: center.y + unrotated.y,
111
+ };
112
+ }
113
+ export function getViewerVisibleBounds(scene, state) {
114
+ const corners = [
115
+ { x: 0, y: 0 },
116
+ { x: scene.width, y: 0 },
117
+ { x: scene.width, y: scene.height },
118
+ { x: 0, y: scene.height },
119
+ ].map((point) => invertViewerPoint(scene, state, point));
120
+ const minX = Math.min(...corners.map((corner) => corner.x));
121
+ const minY = Math.min(...corners.map((corner) => corner.y));
122
+ const maxX = Math.max(...corners.map((corner) => corner.x));
123
+ const maxY = Math.max(...corners.map((corner) => corner.y));
124
+ return {
125
+ minX,
126
+ minY,
127
+ maxX,
128
+ maxY,
129
+ width: maxX - minX,
130
+ height: maxY - minY,
131
+ centerX: minX + (maxX - minX) / 2,
132
+ centerY: minY + (maxY - minY) / 2,
133
+ };
134
+ }
135
+ export function getSceneCenter(scene) {
136
+ return {
137
+ x: scene.width / 2,
138
+ y: scene.height / 2,
139
+ };
140
+ }
141
+ function rotateBounds(bounds, center, rotationDeg) {
142
+ const corners = [
143
+ { x: bounds.minX, y: bounds.minY },
144
+ { x: bounds.maxX, y: bounds.minY },
145
+ { x: bounds.maxX, y: bounds.maxY },
146
+ { x: bounds.minX, y: bounds.maxY },
147
+ ].map((corner) => rotatePoint(corner, center, rotationDeg));
148
+ const minX = Math.min(...corners.map((corner) => corner.x));
149
+ const minY = Math.min(...corners.map((corner) => corner.y));
150
+ const maxX = Math.max(...corners.map((corner) => corner.x));
151
+ const maxY = Math.max(...corners.map((corner) => corner.y));
152
+ return {
153
+ minX,
154
+ minY,
155
+ maxX,
156
+ maxY,
157
+ width: maxX - minX,
158
+ height: maxY - minY,
159
+ centerX: minX + (maxX - minX) / 2,
160
+ centerY: minY + (maxY - minY) / 2,
161
+ };
162
+ }
@@ -0,0 +1,2 @@
1
+ import type { InteractiveViewerOptions, WorldOrbitViewer } from "./types.js";
2
+ export declare function createInteractiveViewer(container: HTMLElement, options: InteractiveViewerOptions): WorldOrbitViewer;