@galihru/orbinexsim 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Galih Ridho Utomo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @galihru/orbinexsim
2
+
3
+ OrbinexSim adalah wrapper tingkat tinggi agar kamu bisa pakai Orbinex desktop + AR tanpa menulis ribuan baris kode.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @galihru/orbinexsim
9
+ ```
10
+
11
+ ## Pemakaian Paling Ringkas
12
+
13
+ ```ts
14
+ import { createOrbinexSim } from "@galihru/orbinexsim";
15
+
16
+ const sim = createOrbinexSim("#app", {
17
+ mode: "desktop",
18
+ model: "Bumi",
19
+ autoRequestAccess: true,
20
+ });
21
+
22
+ // pindah ke AR kapan saja
23
+ await sim.launchAr({ camera: true, motionSensors: true });
24
+ ```
25
+
26
+ ## API Inti
27
+
28
+ - `createOrbinexSim(target, options)`
29
+ - `sim.setMode("desktop" | "ar")`
30
+ - `sim.setModel("Bumi")`
31
+ - `sim.launchAr({ camera: true })`
32
+ - `sim.requestAccess({ camera: true, geolocation: true })`
33
+ - `sim.buildQuickReport(radiusMeters)`
34
+
35
+ ## Catatan
36
+
37
+ - Module ini menggunakan `@galihru/orbinex` untuk kalkulasi dasar orbit.
38
+ - Untuk mode AR, browser/user tetap bisa menolak permission kamera/sensor.
39
+ - Default host viewer: `https://galihru.github.io/OrbinexSimulation/`
40
+
41
+ ## Publish
42
+
43
+ ```bash
44
+ npm run build
45
+ npm publish --access public
46
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ OrbinexSim: () => OrbinexSim,
24
+ constants: () => import_orbinex.constants,
25
+ createOrbinexSim: () => createOrbinexSim,
26
+ orbitSampleFromAu: () => orbitSampleFromAu,
27
+ requestRuntimePermissions: () => requestRuntimePermissions
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ var import_orbinex = require("@galihru/orbinex");
31
+ var DEFAULT_BASE_URL = "https://galihru.github.io/OrbinexSimulation/";
32
+ async function requestCameraPermission() {
33
+ if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia !== "function") {
34
+ return "unsupported";
35
+ }
36
+ try {
37
+ const stream = await navigator.mediaDevices.getUserMedia({
38
+ video: {
39
+ facingMode: "environment"
40
+ },
41
+ audio: false
42
+ });
43
+ stream.getTracks().forEach((track) => track.stop());
44
+ return "granted";
45
+ } catch {
46
+ return "denied";
47
+ }
48
+ }
49
+ async function requestMicrophonePermission() {
50
+ if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia !== "function") {
51
+ return "unsupported";
52
+ }
53
+ try {
54
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
55
+ stream.getTracks().forEach((track) => track.stop());
56
+ return "granted";
57
+ } catch {
58
+ return "denied";
59
+ }
60
+ }
61
+ async function requestGeolocationPermission() {
62
+ if (!navigator.geolocation || !window.isSecureContext) {
63
+ return "unsupported";
64
+ }
65
+ return new Promise((resolve) => {
66
+ navigator.geolocation.getCurrentPosition(
67
+ () => resolve("granted"),
68
+ () => resolve("denied"),
69
+ {
70
+ timeout: 7e3,
71
+ enableHighAccuracy: false,
72
+ maximumAge: 0
73
+ }
74
+ );
75
+ });
76
+ }
77
+ async function requestMotionSensorPermission() {
78
+ const motionApi = window.DeviceMotionEvent;
79
+ if (!motionApi || typeof motionApi.requestPermission !== "function") {
80
+ return "unsupported";
81
+ }
82
+ try {
83
+ const result = await motionApi.requestPermission();
84
+ return result === "granted" ? "granted" : "denied";
85
+ } catch {
86
+ return "denied";
87
+ }
88
+ }
89
+ function resolveContainer(target) {
90
+ if (typeof target !== "string") {
91
+ return target;
92
+ }
93
+ const found = document.querySelector(target);
94
+ if (!found) {
95
+ throw new Error(`Container not found for selector: ${target}`);
96
+ }
97
+ return found;
98
+ }
99
+ function normalizeBaseUrl(baseUrl) {
100
+ const trimmed = baseUrl.trim();
101
+ if (!trimmed) {
102
+ return DEFAULT_BASE_URL;
103
+ }
104
+ return trimmed.endsWith("/") ? trimmed : `${trimmed}/`;
105
+ }
106
+ function ensureIframeStyle(iframe, width, height) {
107
+ iframe.style.width = width;
108
+ iframe.style.height = height;
109
+ iframe.style.border = "0";
110
+ iframe.style.display = "block";
111
+ iframe.style.background = "#000";
112
+ }
113
+ var OrbinexSim = class {
114
+ constructor(target, options = {}) {
115
+ this.container = resolveContainer(target);
116
+ this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
117
+ this.mode = options.mode ?? "desktop";
118
+ this.model = options.model ?? "Bumi";
119
+ this.iframe = document.createElement("iframe");
120
+ this.iframe.title = "Orbinex Simulation";
121
+ this.iframe.allow = "camera; microphone; geolocation; accelerometer; gyroscope; magnetometer; xr-spatial-tracking; fullscreen";
122
+ this.iframe.referrerPolicy = "strict-origin-when-cross-origin";
123
+ if (options.iframeClassName) {
124
+ this.iframe.className = options.iframeClassName;
125
+ }
126
+ ensureIframeStyle(this.iframe, options.width ?? "100%", options.height ?? "72vh");
127
+ this.iframe.src = this.buildUrl();
128
+ if (options.autoAppend !== false) {
129
+ this.mount();
130
+ }
131
+ if (options.autoRequestAccess) {
132
+ void this.requestAccess({
133
+ camera: true,
134
+ geolocation: true,
135
+ motionSensors: true
136
+ });
137
+ }
138
+ }
139
+ mount() {
140
+ if (!this.iframe.isConnected) {
141
+ this.container.appendChild(this.iframe);
142
+ }
143
+ }
144
+ destroy() {
145
+ this.iframe.remove();
146
+ }
147
+ getElement() {
148
+ return this.iframe;
149
+ }
150
+ setMode(mode) {
151
+ this.mode = mode;
152
+ this.refresh();
153
+ }
154
+ setModel(model) {
155
+ this.model = model || "Bumi";
156
+ this.refresh();
157
+ }
158
+ setBaseUrl(baseUrl) {
159
+ this.baseUrl = normalizeBaseUrl(baseUrl);
160
+ this.refresh();
161
+ }
162
+ openInNewTab() {
163
+ return window.open(this.buildUrl(), "_blank", "noopener,noreferrer");
164
+ }
165
+ async requestAccess(options = {}) {
166
+ const wantsCamera = options.camera ?? false;
167
+ const wantsMic = options.microphone ?? false;
168
+ const wantsGeo = options.geolocation ?? false;
169
+ const wantsMotion = options.motionSensors ?? false;
170
+ const unsupported = "unsupported";
171
+ const [camera, microphone, geolocation, motionSensors] = await Promise.all([
172
+ wantsCamera ? requestCameraPermission() : Promise.resolve(unsupported),
173
+ wantsMic ? requestMicrophonePermission() : Promise.resolve(unsupported),
174
+ wantsGeo ? requestGeolocationPermission() : Promise.resolve(unsupported),
175
+ wantsMotion ? requestMotionSensorPermission() : Promise.resolve(unsupported)
176
+ ]);
177
+ return {
178
+ camera,
179
+ microphone,
180
+ geolocation,
181
+ motionSensors
182
+ };
183
+ }
184
+ async launchAr(options = {}) {
185
+ const model = options.model ?? this.model;
186
+ const permissions = await this.requestAccess({
187
+ camera: options.camera ?? true,
188
+ microphone: options.microphone ?? false,
189
+ geolocation: options.geolocation ?? false,
190
+ motionSensors: options.motionSensors ?? true
191
+ });
192
+ this.setModel(model);
193
+ this.setMode("ar");
194
+ return permissions;
195
+ }
196
+ createOrbitPreviewSample(radiusMeters, primaryMassKg = import_orbinex.constants.solarMassKg) {
197
+ return (0, import_orbinex.createOrbitSample)(primaryMassKg, radiusMeters);
198
+ }
199
+ buildQuickReport(radiusMeters) {
200
+ const sample = this.createOrbitPreviewSample(radiusMeters);
201
+ return [
202
+ `radius=${radiusMeters.toFixed(0)}m`,
203
+ `speed=${sample.circularSpeedMps.toFixed(2)}m/s`,
204
+ `periodDays=${sample.orbitalPeriodDays.toFixed(2)}`
205
+ ].join(" | ");
206
+ }
207
+ refresh() {
208
+ this.iframe.src = this.buildUrl();
209
+ }
210
+ buildUrl() {
211
+ const path = this.mode === "ar" ? "ar-view.html" : "";
212
+ const url = new URL(path, this.baseUrl);
213
+ url.searchParams.set("from", "orbinexsim");
214
+ url.searchParams.set("model", this.model);
215
+ if (this.mode === "desktop") {
216
+ url.searchParams.set("desktop", "1");
217
+ }
218
+ return url.toString();
219
+ }
220
+ };
221
+ function createOrbinexSim(target, options = {}) {
222
+ return new OrbinexSim(target, options);
223
+ }
224
+ async function requestRuntimePermissions(options) {
225
+ const simulator = document.createElement("div");
226
+ const instance = new OrbinexSim(simulator, { autoAppend: false });
227
+ return instance.requestAccess(options);
228
+ }
229
+ function orbitSampleFromAu(au) {
230
+ return (0, import_orbinex.createOrbitSample)(import_orbinex.constants.solarMassKg, Math.max(au, 1e-3) * import_orbinex.constants.auMeters);
231
+ }
232
+ // Annotate the CommonJS export names for ESM import in node:
233
+ 0 && (module.exports = {
234
+ OrbinexSim,
235
+ constants,
236
+ createOrbinexSim,
237
+ orbitSampleFromAu,
238
+ requestRuntimePermissions
239
+ });
@@ -0,0 +1,56 @@
1
+ import { OrbitSample } from '@galihru/orbinex';
2
+ export { constants } from '@galihru/orbinex';
3
+
4
+ type OrbinexMode = "desktop" | "ar";
5
+ type PermissionResult = "granted" | "denied" | "unsupported";
6
+ interface PermissionRequestOptions {
7
+ camera?: boolean;
8
+ microphone?: boolean;
9
+ geolocation?: boolean;
10
+ motionSensors?: boolean;
11
+ }
12
+ interface PermissionRequestSummary {
13
+ camera: PermissionResult;
14
+ microphone: PermissionResult;
15
+ geolocation: PermissionResult;
16
+ motionSensors: PermissionResult;
17
+ }
18
+ interface OrbinexSimOptions {
19
+ baseUrl?: string;
20
+ mode?: OrbinexMode;
21
+ model?: string;
22
+ width?: string;
23
+ height?: string;
24
+ autoAppend?: boolean;
25
+ autoRequestAccess?: boolean;
26
+ iframeClassName?: string;
27
+ }
28
+ interface LaunchArOptions extends PermissionRequestOptions {
29
+ model?: string;
30
+ }
31
+ declare class OrbinexSim {
32
+ private readonly container;
33
+ private readonly iframe;
34
+ private baseUrl;
35
+ private mode;
36
+ private model;
37
+ constructor(target: string | HTMLElement, options?: OrbinexSimOptions);
38
+ mount(): void;
39
+ destroy(): void;
40
+ getElement(): HTMLIFrameElement;
41
+ setMode(mode: OrbinexMode): void;
42
+ setModel(model: string): void;
43
+ setBaseUrl(baseUrl: string): void;
44
+ openInNewTab(): Window | null;
45
+ requestAccess(options?: PermissionRequestOptions): Promise<PermissionRequestSummary>;
46
+ launchAr(options?: LaunchArOptions): Promise<PermissionRequestSummary>;
47
+ createOrbitPreviewSample(radiusMeters: number, primaryMassKg?: 1.98847e+30): OrbitSample;
48
+ buildQuickReport(radiusMeters: number): string;
49
+ private refresh;
50
+ private buildUrl;
51
+ }
52
+ declare function createOrbinexSim(target: string | HTMLElement, options?: OrbinexSimOptions): OrbinexSim;
53
+ declare function requestRuntimePermissions(options: PermissionRequestOptions): Promise<PermissionRequestSummary>;
54
+ declare function orbitSampleFromAu(au: number): OrbitSample;
55
+
56
+ export { type LaunchArOptions, type OrbinexMode, OrbinexSim, type OrbinexSimOptions, type PermissionRequestOptions, type PermissionRequestSummary, type PermissionResult, createOrbinexSim, orbitSampleFromAu, requestRuntimePermissions };
@@ -0,0 +1,56 @@
1
+ import { OrbitSample } from '@galihru/orbinex';
2
+ export { constants } from '@galihru/orbinex';
3
+
4
+ type OrbinexMode = "desktop" | "ar";
5
+ type PermissionResult = "granted" | "denied" | "unsupported";
6
+ interface PermissionRequestOptions {
7
+ camera?: boolean;
8
+ microphone?: boolean;
9
+ geolocation?: boolean;
10
+ motionSensors?: boolean;
11
+ }
12
+ interface PermissionRequestSummary {
13
+ camera: PermissionResult;
14
+ microphone: PermissionResult;
15
+ geolocation: PermissionResult;
16
+ motionSensors: PermissionResult;
17
+ }
18
+ interface OrbinexSimOptions {
19
+ baseUrl?: string;
20
+ mode?: OrbinexMode;
21
+ model?: string;
22
+ width?: string;
23
+ height?: string;
24
+ autoAppend?: boolean;
25
+ autoRequestAccess?: boolean;
26
+ iframeClassName?: string;
27
+ }
28
+ interface LaunchArOptions extends PermissionRequestOptions {
29
+ model?: string;
30
+ }
31
+ declare class OrbinexSim {
32
+ private readonly container;
33
+ private readonly iframe;
34
+ private baseUrl;
35
+ private mode;
36
+ private model;
37
+ constructor(target: string | HTMLElement, options?: OrbinexSimOptions);
38
+ mount(): void;
39
+ destroy(): void;
40
+ getElement(): HTMLIFrameElement;
41
+ setMode(mode: OrbinexMode): void;
42
+ setModel(model: string): void;
43
+ setBaseUrl(baseUrl: string): void;
44
+ openInNewTab(): Window | null;
45
+ requestAccess(options?: PermissionRequestOptions): Promise<PermissionRequestSummary>;
46
+ launchAr(options?: LaunchArOptions): Promise<PermissionRequestSummary>;
47
+ createOrbitPreviewSample(radiusMeters: number, primaryMassKg?: 1.98847e+30): OrbitSample;
48
+ buildQuickReport(radiusMeters: number): string;
49
+ private refresh;
50
+ private buildUrl;
51
+ }
52
+ declare function createOrbinexSim(target: string | HTMLElement, options?: OrbinexSimOptions): OrbinexSim;
53
+ declare function requestRuntimePermissions(options: PermissionRequestOptions): Promise<PermissionRequestSummary>;
54
+ declare function orbitSampleFromAu(au: number): OrbitSample;
55
+
56
+ export { type LaunchArOptions, type OrbinexMode, OrbinexSim, type OrbinexSimOptions, type PermissionRequestOptions, type PermissionRequestSummary, type PermissionResult, createOrbinexSim, orbitSampleFromAu, requestRuntimePermissions };
package/dist/index.js ADDED
@@ -0,0 +1,210 @@
1
+ // src/index.ts
2
+ import { constants, createOrbitSample } from "@galihru/orbinex";
3
+ var DEFAULT_BASE_URL = "https://galihru.github.io/OrbinexSimulation/";
4
+ async function requestCameraPermission() {
5
+ if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia !== "function") {
6
+ return "unsupported";
7
+ }
8
+ try {
9
+ const stream = await navigator.mediaDevices.getUserMedia({
10
+ video: {
11
+ facingMode: "environment"
12
+ },
13
+ audio: false
14
+ });
15
+ stream.getTracks().forEach((track) => track.stop());
16
+ return "granted";
17
+ } catch {
18
+ return "denied";
19
+ }
20
+ }
21
+ async function requestMicrophonePermission() {
22
+ if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia !== "function") {
23
+ return "unsupported";
24
+ }
25
+ try {
26
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
27
+ stream.getTracks().forEach((track) => track.stop());
28
+ return "granted";
29
+ } catch {
30
+ return "denied";
31
+ }
32
+ }
33
+ async function requestGeolocationPermission() {
34
+ if (!navigator.geolocation || !window.isSecureContext) {
35
+ return "unsupported";
36
+ }
37
+ return new Promise((resolve) => {
38
+ navigator.geolocation.getCurrentPosition(
39
+ () => resolve("granted"),
40
+ () => resolve("denied"),
41
+ {
42
+ timeout: 7e3,
43
+ enableHighAccuracy: false,
44
+ maximumAge: 0
45
+ }
46
+ );
47
+ });
48
+ }
49
+ async function requestMotionSensorPermission() {
50
+ const motionApi = window.DeviceMotionEvent;
51
+ if (!motionApi || typeof motionApi.requestPermission !== "function") {
52
+ return "unsupported";
53
+ }
54
+ try {
55
+ const result = await motionApi.requestPermission();
56
+ return result === "granted" ? "granted" : "denied";
57
+ } catch {
58
+ return "denied";
59
+ }
60
+ }
61
+ function resolveContainer(target) {
62
+ if (typeof target !== "string") {
63
+ return target;
64
+ }
65
+ const found = document.querySelector(target);
66
+ if (!found) {
67
+ throw new Error(`Container not found for selector: ${target}`);
68
+ }
69
+ return found;
70
+ }
71
+ function normalizeBaseUrl(baseUrl) {
72
+ const trimmed = baseUrl.trim();
73
+ if (!trimmed) {
74
+ return DEFAULT_BASE_URL;
75
+ }
76
+ return trimmed.endsWith("/") ? trimmed : `${trimmed}/`;
77
+ }
78
+ function ensureIframeStyle(iframe, width, height) {
79
+ iframe.style.width = width;
80
+ iframe.style.height = height;
81
+ iframe.style.border = "0";
82
+ iframe.style.display = "block";
83
+ iframe.style.background = "#000";
84
+ }
85
+ var OrbinexSim = class {
86
+ constructor(target, options = {}) {
87
+ this.container = resolveContainer(target);
88
+ this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
89
+ this.mode = options.mode ?? "desktop";
90
+ this.model = options.model ?? "Bumi";
91
+ this.iframe = document.createElement("iframe");
92
+ this.iframe.title = "Orbinex Simulation";
93
+ this.iframe.allow = "camera; microphone; geolocation; accelerometer; gyroscope; magnetometer; xr-spatial-tracking; fullscreen";
94
+ this.iframe.referrerPolicy = "strict-origin-when-cross-origin";
95
+ if (options.iframeClassName) {
96
+ this.iframe.className = options.iframeClassName;
97
+ }
98
+ ensureIframeStyle(this.iframe, options.width ?? "100%", options.height ?? "72vh");
99
+ this.iframe.src = this.buildUrl();
100
+ if (options.autoAppend !== false) {
101
+ this.mount();
102
+ }
103
+ if (options.autoRequestAccess) {
104
+ void this.requestAccess({
105
+ camera: true,
106
+ geolocation: true,
107
+ motionSensors: true
108
+ });
109
+ }
110
+ }
111
+ mount() {
112
+ if (!this.iframe.isConnected) {
113
+ this.container.appendChild(this.iframe);
114
+ }
115
+ }
116
+ destroy() {
117
+ this.iframe.remove();
118
+ }
119
+ getElement() {
120
+ return this.iframe;
121
+ }
122
+ setMode(mode) {
123
+ this.mode = mode;
124
+ this.refresh();
125
+ }
126
+ setModel(model) {
127
+ this.model = model || "Bumi";
128
+ this.refresh();
129
+ }
130
+ setBaseUrl(baseUrl) {
131
+ this.baseUrl = normalizeBaseUrl(baseUrl);
132
+ this.refresh();
133
+ }
134
+ openInNewTab() {
135
+ return window.open(this.buildUrl(), "_blank", "noopener,noreferrer");
136
+ }
137
+ async requestAccess(options = {}) {
138
+ const wantsCamera = options.camera ?? false;
139
+ const wantsMic = options.microphone ?? false;
140
+ const wantsGeo = options.geolocation ?? false;
141
+ const wantsMotion = options.motionSensors ?? false;
142
+ const unsupported = "unsupported";
143
+ const [camera, microphone, geolocation, motionSensors] = await Promise.all([
144
+ wantsCamera ? requestCameraPermission() : Promise.resolve(unsupported),
145
+ wantsMic ? requestMicrophonePermission() : Promise.resolve(unsupported),
146
+ wantsGeo ? requestGeolocationPermission() : Promise.resolve(unsupported),
147
+ wantsMotion ? requestMotionSensorPermission() : Promise.resolve(unsupported)
148
+ ]);
149
+ return {
150
+ camera,
151
+ microphone,
152
+ geolocation,
153
+ motionSensors
154
+ };
155
+ }
156
+ async launchAr(options = {}) {
157
+ const model = options.model ?? this.model;
158
+ const permissions = await this.requestAccess({
159
+ camera: options.camera ?? true,
160
+ microphone: options.microphone ?? false,
161
+ geolocation: options.geolocation ?? false,
162
+ motionSensors: options.motionSensors ?? true
163
+ });
164
+ this.setModel(model);
165
+ this.setMode("ar");
166
+ return permissions;
167
+ }
168
+ createOrbitPreviewSample(radiusMeters, primaryMassKg = constants.solarMassKg) {
169
+ return createOrbitSample(primaryMassKg, radiusMeters);
170
+ }
171
+ buildQuickReport(radiusMeters) {
172
+ const sample = this.createOrbitPreviewSample(radiusMeters);
173
+ return [
174
+ `radius=${radiusMeters.toFixed(0)}m`,
175
+ `speed=${sample.circularSpeedMps.toFixed(2)}m/s`,
176
+ `periodDays=${sample.orbitalPeriodDays.toFixed(2)}`
177
+ ].join(" | ");
178
+ }
179
+ refresh() {
180
+ this.iframe.src = this.buildUrl();
181
+ }
182
+ buildUrl() {
183
+ const path = this.mode === "ar" ? "ar-view.html" : "";
184
+ const url = new URL(path, this.baseUrl);
185
+ url.searchParams.set("from", "orbinexsim");
186
+ url.searchParams.set("model", this.model);
187
+ if (this.mode === "desktop") {
188
+ url.searchParams.set("desktop", "1");
189
+ }
190
+ return url.toString();
191
+ }
192
+ };
193
+ function createOrbinexSim(target, options = {}) {
194
+ return new OrbinexSim(target, options);
195
+ }
196
+ async function requestRuntimePermissions(options) {
197
+ const simulator = document.createElement("div");
198
+ const instance = new OrbinexSim(simulator, { autoAppend: false });
199
+ return instance.requestAccess(options);
200
+ }
201
+ function orbitSampleFromAu(au) {
202
+ return createOrbitSample(constants.solarMassKg, Math.max(au, 1e-3) * constants.auMeters);
203
+ }
204
+ export {
205
+ OrbinexSim,
206
+ constants,
207
+ createOrbinexSim,
208
+ orbitSampleFromAu,
209
+ requestRuntimePermissions
210
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@galihru/orbinexsim",
3
+ "version": "0.1.0",
4
+ "description": "High-level Orbinex simulation + AR wrapper with one-call setup.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Galih Ridho Utomo",
8
+ "homepage": "https://github.com/galihru/OrbinexSimulation/tree/main/orbinexsim-npm#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/galihru/OrbinexSimulation.git",
12
+ "directory": "orbinexsim-npm"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/galihru/OrbinexSimulation/issues"
16
+ },
17
+ "keywords": [
18
+ "orbinex",
19
+ "ar",
20
+ "threejs",
21
+ "simulation",
22
+ "astronomy",
23
+ "webxr"
24
+ ],
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "require": "./dist/index.cjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsup src/index.ts --dts --format esm,cjs --clean",
42
+ "lint": "tsc --noEmit",
43
+ "prepublishOnly": "npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@galihru/orbinex": "^0.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^5.9.3"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }