@plasius/gpu-xr 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/dist/index.js ADDED
@@ -0,0 +1,281 @@
1
+ // src/index.js
2
+ var DEFAULT_VR_SESSION_INIT = Object.freeze({
3
+ requiredFeatures: ["local-floor"],
4
+ optionalFeatures: ["bounded-floor", "hand-tracking", "layers"]
5
+ });
6
+ var xrSessionModes = Object.freeze([
7
+ "inline",
8
+ "immersive-vr",
9
+ "immersive-ar"
10
+ ]);
11
+ var xrReferenceSpaceTypes = Object.freeze([
12
+ "viewer",
13
+ "local",
14
+ "local-floor",
15
+ "bounded-floor",
16
+ "unbounded"
17
+ ]);
18
+ function toStringArray(values) {
19
+ if (!Array.isArray(values)) {
20
+ return [];
21
+ }
22
+ return values.filter((value) => typeof value === "string").map((value) => value.trim()).filter(Boolean);
23
+ }
24
+ function dedupeStrings(values) {
25
+ return [...new Set(toStringArray(values))];
26
+ }
27
+ function readNavigator(navigatorOverride) {
28
+ const currentNavigator = navigatorOverride ?? globalThis.navigator;
29
+ if (!currentNavigator || typeof currentNavigator !== "object") {
30
+ throw new Error(
31
+ "WebXR navigator unavailable. Provide a browser navigator with navigator.xr."
32
+ );
33
+ }
34
+ return currentNavigator;
35
+ }
36
+ function readXrSystem(navigatorOverride) {
37
+ const currentNavigator = readNavigator(navigatorOverride);
38
+ const xr = currentNavigator.xr;
39
+ if (!xr || typeof xr !== "object") {
40
+ throw new Error(
41
+ "WebXR runtime unavailable. navigator.xr is missing in this environment."
42
+ );
43
+ }
44
+ return xr;
45
+ }
46
+ function assertSessionMode(mode) {
47
+ if (!xrSessionModes.includes(mode)) {
48
+ const available = xrSessionModes.join(", ");
49
+ throw new Error(
50
+ `Unknown XR session mode "${mode}". Available modes: ${available}.`
51
+ );
52
+ }
53
+ }
54
+ function mergeXrSessionInit(base = {}, override = {}) {
55
+ const requiredFeatures = dedupeStrings([
56
+ ...toStringArray(base.requiredFeatures),
57
+ ...toStringArray(override.requiredFeatures)
58
+ ]);
59
+ const optionalFeatures = dedupeStrings([
60
+ ...toStringArray(base.optionalFeatures),
61
+ ...toStringArray(override.optionalFeatures)
62
+ ]);
63
+ const merged = {
64
+ ...base,
65
+ ...override,
66
+ requiredFeatures,
67
+ optionalFeatures
68
+ };
69
+ if (requiredFeatures.length === 0) {
70
+ delete merged.requiredFeatures;
71
+ }
72
+ if (optionalFeatures.length === 0) {
73
+ delete merged.optionalFeatures;
74
+ }
75
+ return merged;
76
+ }
77
+ async function isXrModeSupported(mode = "immersive-vr", options = {}) {
78
+ assertSessionMode(mode);
79
+ const { navigator: navigatorOverride } = options;
80
+ let xr;
81
+ try {
82
+ xr = readXrSystem(navigatorOverride);
83
+ } catch {
84
+ return false;
85
+ }
86
+ if (typeof xr.isSessionSupported !== "function") {
87
+ return false;
88
+ }
89
+ try {
90
+ return Boolean(await xr.isSessionSupported(mode));
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+ async function requestXrSession(options = {}) {
96
+ const {
97
+ mode = "immersive-vr",
98
+ sessionInit = {},
99
+ baseSessionInit = DEFAULT_VR_SESSION_INIT,
100
+ navigator: navigatorOverride
101
+ } = options;
102
+ assertSessionMode(mode);
103
+ const xr = readXrSystem(navigatorOverride);
104
+ if (typeof xr.requestSession !== "function") {
105
+ throw new Error("WebXR requestSession API unavailable.");
106
+ }
107
+ const init = mergeXrSessionInit(baseSessionInit, sessionInit);
108
+ return xr.requestSession(mode, init);
109
+ }
110
+ function createXrStore(initialState = {}) {
111
+ const listeners = /* @__PURE__ */ new Set();
112
+ let state = {
113
+ activeSession: null,
114
+ mode: null,
115
+ isEntering: false,
116
+ lastError: null,
117
+ supportedModes: {},
118
+ ...initialState
119
+ };
120
+ const notify = () => {
121
+ for (const listener of listeners) {
122
+ listener(state);
123
+ }
124
+ };
125
+ return {
126
+ getSnapshot() {
127
+ return state;
128
+ },
129
+ subscribe(listener) {
130
+ listeners.add(listener);
131
+ return () => {
132
+ listeners.delete(listener);
133
+ };
134
+ },
135
+ set(partialState) {
136
+ state = {
137
+ ...state,
138
+ ...partialState
139
+ };
140
+ notify();
141
+ },
142
+ reset() {
143
+ state = {
144
+ activeSession: null,
145
+ mode: null,
146
+ isEntering: false,
147
+ lastError: null,
148
+ supportedModes: {},
149
+ ...initialState
150
+ };
151
+ notify();
152
+ }
153
+ };
154
+ }
155
+ function createXrManager(options = {}) {
156
+ const {
157
+ navigator: navigatorOverride,
158
+ defaultMode = "immersive-vr",
159
+ baseSessionInit = DEFAULT_VR_SESSION_INIT,
160
+ onSessionStart,
161
+ onSessionEnd
162
+ } = options;
163
+ assertSessionMode(defaultMode);
164
+ const store = createXrStore();
165
+ let activeSessionEndHandler = null;
166
+ const detachSessionEndHandler = () => {
167
+ const { activeSession } = store.getSnapshot();
168
+ if (activeSession && activeSessionEndHandler && typeof activeSession.removeEventListener === "function") {
169
+ activeSession.removeEventListener("end", activeSessionEndHandler);
170
+ }
171
+ activeSessionEndHandler = null;
172
+ };
173
+ const handleSessionEnded = () => {
174
+ detachSessionEndHandler();
175
+ store.set({
176
+ activeSession: null,
177
+ mode: null,
178
+ isEntering: false
179
+ });
180
+ if (typeof onSessionEnd === "function") {
181
+ onSessionEnd();
182
+ }
183
+ };
184
+ const attachSessionEndHandler = (session) => {
185
+ if (!session || typeof session.addEventListener !== "function") {
186
+ return;
187
+ }
188
+ activeSessionEndHandler = handleSessionEnded;
189
+ session.addEventListener("end", activeSessionEndHandler);
190
+ };
191
+ const getState = () => store.getSnapshot();
192
+ const subscribe = (listener) => store.subscribe(listener);
193
+ const probeSupport = async (modes = [defaultMode]) => {
194
+ const supportedModes = {};
195
+ for (const mode of modes) {
196
+ assertSessionMode(mode);
197
+ supportedModes[mode] = await isXrModeSupported(mode, {
198
+ navigator: navigatorOverride
199
+ });
200
+ }
201
+ store.set({ supportedModes });
202
+ return supportedModes;
203
+ };
204
+ const enterSession = async (mode = defaultMode, sessionInit = {}) => {
205
+ assertSessionMode(mode);
206
+ const existing = store.getSnapshot().activeSession;
207
+ if (existing) {
208
+ return existing;
209
+ }
210
+ store.set({ isEntering: true, lastError: null });
211
+ try {
212
+ const session = await requestXrSession({
213
+ mode,
214
+ sessionInit,
215
+ baseSessionInit,
216
+ navigator: navigatorOverride
217
+ });
218
+ attachSessionEndHandler(session);
219
+ store.set({
220
+ activeSession: session,
221
+ mode,
222
+ isEntering: false,
223
+ lastError: null
224
+ });
225
+ if (typeof onSessionStart === "function") {
226
+ onSessionStart(session, mode);
227
+ }
228
+ return session;
229
+ } catch (error) {
230
+ const message = error instanceof Error ? error.message : String(error ?? "Unknown XR error");
231
+ store.set({
232
+ isEntering: false,
233
+ lastError: message
234
+ });
235
+ throw error;
236
+ }
237
+ };
238
+ const enterVr = async (sessionInit = {}) => {
239
+ return enterSession("immersive-vr", sessionInit);
240
+ };
241
+ const exitSession = async () => {
242
+ const { activeSession } = store.getSnapshot();
243
+ if (!activeSession) {
244
+ return false;
245
+ }
246
+ if (typeof activeSession.end === "function") {
247
+ await activeSession.end();
248
+ }
249
+ if (store.getSnapshot().activeSession) {
250
+ handleSessionEnded();
251
+ }
252
+ return true;
253
+ };
254
+ const dispose = async () => {
255
+ await exitSession();
256
+ detachSessionEndHandler();
257
+ store.reset();
258
+ };
259
+ return {
260
+ store,
261
+ getState,
262
+ subscribe,
263
+ probeSupport,
264
+ enterSession,
265
+ enterVr,
266
+ exitSession,
267
+ dispose
268
+ };
269
+ }
270
+ var defaultVrSessionInit = DEFAULT_VR_SESSION_INIT;
271
+ export {
272
+ createXrManager,
273
+ createXrStore,
274
+ defaultVrSessionInit,
275
+ isXrModeSupported,
276
+ mergeXrSessionInit,
277
+ requestXrSession,
278
+ xrReferenceSpaceTypes,
279
+ xrSessionModes
280
+ };
281
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"sourcesContent":["const DEFAULT_VR_SESSION_INIT = Object.freeze({\n requiredFeatures: [\"local-floor\"],\n optionalFeatures: [\"bounded-floor\", \"hand-tracking\", \"layers\"],\n});\n\nexport const xrSessionModes = Object.freeze([\n \"inline\",\n \"immersive-vr\",\n \"immersive-ar\",\n]);\n\nexport const xrReferenceSpaceTypes = Object.freeze([\n \"viewer\",\n \"local\",\n \"local-floor\",\n \"bounded-floor\",\n \"unbounded\",\n]);\n\nfunction toStringArray(values) {\n if (!Array.isArray(values)) {\n return [];\n }\n return values\n .filter((value) => typeof value === \"string\")\n .map((value) => value.trim())\n .filter(Boolean);\n}\n\nfunction dedupeStrings(values) {\n return [...new Set(toStringArray(values))];\n}\n\nfunction readNavigator(navigatorOverride) {\n const currentNavigator = navigatorOverride ?? globalThis.navigator;\n if (!currentNavigator || typeof currentNavigator !== \"object\") {\n throw new Error(\n \"WebXR navigator unavailable. Provide a browser navigator with navigator.xr.\"\n );\n }\n return currentNavigator;\n}\n\nfunction readXrSystem(navigatorOverride) {\n const currentNavigator = readNavigator(navigatorOverride);\n const xr = currentNavigator.xr;\n if (!xr || typeof xr !== \"object\") {\n throw new Error(\n \"WebXR runtime unavailable. navigator.xr is missing in this environment.\"\n );\n }\n return xr;\n}\n\nfunction assertSessionMode(mode) {\n if (!xrSessionModes.includes(mode)) {\n const available = xrSessionModes.join(\", \");\n throw new Error(\n `Unknown XR session mode \\\"${mode}\\\". Available modes: ${available}.`\n );\n }\n}\n\nexport function mergeXrSessionInit(base = {}, override = {}) {\n const requiredFeatures = dedupeStrings([\n ...toStringArray(base.requiredFeatures),\n ...toStringArray(override.requiredFeatures),\n ]);\n\n const optionalFeatures = dedupeStrings([\n ...toStringArray(base.optionalFeatures),\n ...toStringArray(override.optionalFeatures),\n ]);\n\n const merged = {\n ...base,\n ...override,\n requiredFeatures,\n optionalFeatures,\n };\n\n if (requiredFeatures.length === 0) {\n delete merged.requiredFeatures;\n }\n\n if (optionalFeatures.length === 0) {\n delete merged.optionalFeatures;\n }\n\n return merged;\n}\n\nexport async function isXrModeSupported(\n mode = \"immersive-vr\",\n options = {}\n) {\n assertSessionMode(mode);\n\n const { navigator: navigatorOverride } = options;\n let xr;\n try {\n xr = readXrSystem(navigatorOverride);\n } catch {\n return false;\n }\n\n if (typeof xr.isSessionSupported !== \"function\") {\n return false;\n }\n\n try {\n return Boolean(await xr.isSessionSupported(mode));\n } catch {\n return false;\n }\n}\n\nexport async function requestXrSession(options = {}) {\n const {\n mode = \"immersive-vr\",\n sessionInit = {},\n baseSessionInit = DEFAULT_VR_SESSION_INIT,\n navigator: navigatorOverride,\n } = options;\n\n assertSessionMode(mode);\n\n const xr = readXrSystem(navigatorOverride);\n\n if (typeof xr.requestSession !== \"function\") {\n throw new Error(\"WebXR requestSession API unavailable.\");\n }\n\n const init = mergeXrSessionInit(baseSessionInit, sessionInit);\n return xr.requestSession(mode, init);\n}\n\nexport function createXrStore(initialState = {}) {\n const listeners = new Set();\n let state = {\n activeSession: null,\n mode: null,\n isEntering: false,\n lastError: null,\n supportedModes: {},\n ...initialState,\n };\n\n const notify = () => {\n for (const listener of listeners) {\n listener(state);\n }\n };\n\n return {\n getSnapshot() {\n return state;\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n set(partialState) {\n state = {\n ...state,\n ...partialState,\n };\n notify();\n },\n reset() {\n state = {\n activeSession: null,\n mode: null,\n isEntering: false,\n lastError: null,\n supportedModes: {},\n ...initialState,\n };\n notify();\n },\n };\n}\n\nexport function createXrManager(options = {}) {\n const {\n navigator: navigatorOverride,\n defaultMode = \"immersive-vr\",\n baseSessionInit = DEFAULT_VR_SESSION_INIT,\n onSessionStart,\n onSessionEnd,\n } = options;\n\n assertSessionMode(defaultMode);\n\n const store = createXrStore();\n let activeSessionEndHandler = null;\n\n const detachSessionEndHandler = () => {\n const { activeSession } = store.getSnapshot();\n if (\n activeSession &&\n activeSessionEndHandler &&\n typeof activeSession.removeEventListener === \"function\"\n ) {\n activeSession.removeEventListener(\"end\", activeSessionEndHandler);\n }\n activeSessionEndHandler = null;\n };\n\n const handleSessionEnded = () => {\n detachSessionEndHandler();\n store.set({\n activeSession: null,\n mode: null,\n isEntering: false,\n });\n if (typeof onSessionEnd === \"function\") {\n onSessionEnd();\n }\n };\n\n const attachSessionEndHandler = (session) => {\n if (!session || typeof session.addEventListener !== \"function\") {\n return;\n }\n activeSessionEndHandler = handleSessionEnded;\n session.addEventListener(\"end\", activeSessionEndHandler);\n };\n\n const getState = () => store.getSnapshot();\n\n const subscribe = (listener) => store.subscribe(listener);\n\n const probeSupport = async (modes = [defaultMode]) => {\n const supportedModes = {};\n for (const mode of modes) {\n assertSessionMode(mode);\n supportedModes[mode] = await isXrModeSupported(mode, {\n navigator: navigatorOverride,\n });\n }\n store.set({ supportedModes });\n return supportedModes;\n };\n\n const enterSession = async (mode = defaultMode, sessionInit = {}) => {\n assertSessionMode(mode);\n\n const existing = store.getSnapshot().activeSession;\n if (existing) {\n return existing;\n }\n\n store.set({ isEntering: true, lastError: null });\n\n try {\n const session = await requestXrSession({\n mode,\n sessionInit,\n baseSessionInit,\n navigator: navigatorOverride,\n });\n\n attachSessionEndHandler(session);\n\n store.set({\n activeSession: session,\n mode,\n isEntering: false,\n lastError: null,\n });\n\n if (typeof onSessionStart === \"function\") {\n onSessionStart(session, mode);\n }\n\n return session;\n } catch (error) {\n const message =\n error instanceof Error ? error.message : String(error ?? \"Unknown XR error\");\n store.set({\n isEntering: false,\n lastError: message,\n });\n throw error;\n }\n };\n\n const enterVr = async (sessionInit = {}) => {\n return enterSession(\"immersive-vr\", sessionInit);\n };\n\n const exitSession = async () => {\n const { activeSession } = store.getSnapshot();\n if (!activeSession) {\n return false;\n }\n\n if (typeof activeSession.end === \"function\") {\n await activeSession.end();\n }\n\n // Fallback for test fakes or runtimes that do not emit an end event.\n if (store.getSnapshot().activeSession) {\n handleSessionEnded();\n }\n\n return true;\n };\n\n const dispose = async () => {\n await exitSession();\n detachSessionEndHandler();\n store.reset();\n };\n\n return {\n store,\n getState,\n subscribe,\n probeSupport,\n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AAI;AAAA,MAC9B;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,SAAS,kBAAkB;AAC7E,YAAM,IAAI;AAAA,QACR,YAAY;AAAA,QACZ,WAAW;AAAA,MACb,CAAC;AACD,YAAM;AAAA,IACR;AAAA,EACF;AAEA,QAAM,UAAU,OAAO,cAAc,CAAC,MAAM;AAC1C,WAAO,aAAa,gBAAgB,WAAW;AAAA,EACjD;AAEA,QAAM,cAAc,YAAY;AAC9B,UAAM,EAAE,cAAc,IAAI,MAAM,YAAY;AAC5C,QAAI,CAAC,eAAe;AAClB,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,cAAc,QAAQ,YAAY;AAC3C,YAAM,cAAc,IAAI;AAAA,IAC1B;AAGA,QAAI,MAAM,YAAY,EAAE,eAAe;AACrC,yBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,YAAY;AAC1B,UAAM,YAAY;AAClB,4BAAwB;AACxB,UAAM,MAAM;AAAA,EACd;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,uBAAuB;","names":[]}
@@ -0,0 +1,2 @@
1
+ type,github_handle,full_name,company,email,date,approver
2
+ corporate,Zephod111r,Phillip Hounslow,Plasius LTD,zephod@plasius.co.uk,2025-09-12,Phillip Hounslow (Maintainer)
package/legal/CLA.md ADDED
@@ -0,0 +1,22 @@
1
+ # Contributor License Agreements (CLA)
2
+
3
+ To protect the intellectual property of this project and ensure clarity of rights, all contributors must sign a Contributor License Agreement (CLA) before their first contribution.
4
+
5
+ ## Which CLA should I sign?
6
+
7
+ - **Individual CLA**: If you are contributing personally and not on behalf of an employer, sign the [Individual CLA](INDIVIDUAL_CLA.md).
8
+ - **Corporate CLA**: If you are contributing as part of your work for a company, the company should sign the [Corporate CLA](CORPORATE_CLA.md).
9
+
10
+ ## How to sign
11
+
12
+ 1. Download the appropriate CLA file (Individual or Corporate).
13
+ 2. Fill in the required details, sign, and date it.
14
+ 3. Email a PDF copy of the signed document to **[contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)** with subject: `CLA – Individual` or `CLA – Corporate`.
15
+
16
+ ## Registry
17
+
18
+ All signed CLAs are logged internally in the CLA registry (`CLA-REGISTRY.csv`).
19
+
20
+ ## Questions?
21
+
22
+ If you have any questions about which CLA to sign or how the process works, please email **[contributors@plasius.co.uk](mailtocontributors@plasius.co.uk)**.
@@ -0,0 +1,57 @@
1
+ # Corporate Contributor License Agreement (CLA)
2
+
3
+ ## Purpose
4
+
5
+ This Corporate Contributor License Agreement ("Agreement") is intended to protect the intellectual property rights of the contributors and the project, ensure clear licensing terms for contributions, and maintain trust within the community. By signing this Agreement, the corporation agrees to the terms that facilitate the use, distribution, and modification of contributions under the project's licensing framework.
6
+
7
+ ## Agreement
8
+
9
+ 1. **Representation of Authority**
10
+ The undersigned individual represents and warrants that they have the full legal authority to enter into this Agreement on behalf of the corporation named below ("Corporation") and to grant the rights contained herein.
11
+
12
+ 2. **Grant of Copyright License**
13
+ The Corporation hereby grants to the project maintainers and users a perpetual, worldwide, non-exclusive, royalty-free, irrevocable copyright license to use, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the contributions submitted to the project.
14
+
15
+ 3. **Grant of Patent License**
16
+ The Corporation hereby grants to the project maintainers and users a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under any patent claims that are necessarily infringed by the contributions to make, use, sell, offer for sale, import, and otherwise dispose of the contributions or derivative works thereof.
17
+
18
+ 4. **Warranties and Representations**
19
+ The Corporation represents and warrants that:
20
+
21
+ - The contributions are the original work of the Corporation or that the Corporation has sufficient rights to grant the licenses herein.
22
+ - The submission of the contributions does not violate any agreements or rights of third parties.
23
+
24
+ 5. **No Revocation**
25
+ This license is granted on a perpetual basis and cannot be revoked, provided that the terms of this Agreement are met.
26
+
27
+ 6. **Governing Law**
28
+ This Agreement shall be governed by and construed in accordance with the laws of the United Kingdom, without regard to its conflict of laws principles.
29
+
30
+ 7. **Execution**
31
+
32
+ This Agreement is effective upon signature by the authorized representative of the Corporation. Please sign and date this document, then email a scanned PDF copy to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
33
+
34
+ ---
35
+
36
+ ### **@plasius/gpu-xr**
37
+
38
+ **Corporation Legal Name:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
39
+
40
+ **Authorized Representative:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
41
+
42
+ **Title:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
43
+
44
+ **Email:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
45
+
46
+ **Date:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
47
+
48
+ **Signature:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
49
+
50
+ ---
51
+
52
+ ## How to Sign
53
+
54
+ - Download this file as a template.
55
+ - Fill in the Corporation’s legal name, authorized representative, title, email, date, and provide a signature.
56
+ - Sign and date the document.
57
+ - Send a scanned copy of the signed Agreement to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
@@ -0,0 +1,91 @@
1
+ # Individual Contributor License Agreement (CLA)
2
+
3
+ **Project:** @plasius/gpu-xr (Plasius LTD)
4
+ **Version:** 1.0 — 2025‑09‑12
5
+ **Contact:** [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)
6
+
7
+ ---
8
+
9
+ ## 1. Definitions
10
+
11
+ - **"You"** (or **"Contributor"**) means the individual signing this CLA and submitting Contributions to the Project.
12
+ - **"Contribution"** means any original work of authorship, including code, documentation, data, designs, or feedback that You submit to the Project in any form (e.g., pull request, issue comment, email, file upload).
13
+ - **"Project"** means the @plasius/gpu-xr repositories and related materials owned or managed by **Plasius LTD**.
14
+
15
+ ## 2. Copyright License Grant
16
+
17
+ You hereby grant to Plasius LTD a **perpetual, worldwide, non‑exclusive, transferable, sublicensable, royalty‑free, irrevocable** copyright license to:
18
+
19
+ - use, reproduce, publicly display, publicly perform, modify, create derivative works of, and
20
+ - distribute Contributions in source and object form,
21
+ - and to **sublicense** these rights under any terms Plasius LTD chooses, including proprietary or open‑source licenses.
22
+
23
+ ## 3. Patent License Grant
24
+
25
+ You hereby grant to Plasius LTD and its sublicensees a **perpetual, worldwide, non‑exclusive, transferable, royalty‑free, irrevocable** patent license to **make, have made, use, offer to sell, sell, import, and otherwise transfer** the Contribution and derivative works thereof, where such license applies only to patent claims that You **own or control** and that would be infringed by Your Contribution or its combination with the Project.
26
+
27
+ ## 4. Moral Rights & Attribution
28
+
29
+ To the maximum extent permitted by applicable law, You **waive** and agree not to assert any moral rights (e.g., rights of attribution or integrity) in or to the Contribution against Plasius LTD. Plasius LTD may, but is not required to, credit You.
30
+
31
+ ## 5. Representations & Warranties
32
+
33
+ You represent that:
34
+
35
+ 1. **Originality / Rights:** Each Contribution is Your original creation, or You have sufficient rights to submit it and grant the licenses above.
36
+ 2. **No Confidential Info:** Contributions **do not** include confidential information or trade secrets of any third party.
37
+ 3. **No Infringement:** To the best of Your knowledge, Contributions do not infringe any third‑party IP rights.
38
+ 4. **Employment / Contractor Status:** If Your employer or a third party might claim rights in Your Contribution, You have obtained **written permission** to make the Contribution and grant these licenses (attach or reference below), or Your Contribution is made **outside the scope** of your employment and without using your employer’s confidential information or resources.
39
+ 5. **Compliance:** You will follow the Project’s policies (e.g., Code of Conduct, Security Policy) and applicable laws.
40
+
41
+ ## 6. Third‑Party Code
42
+
43
+ If Your Contribution includes code, data, or other material from a third party, You will **identify the material and its license** in the pull request or submission, and ensure it is **compatible** with the Project’s licensing model. You will not submit material subject to terms that require the Project to disclose proprietary source code (e.g., certain copyleft obligations) unless the Project has **pre‑approved** such inclusion in writing.
44
+
45
+ ## 7. Scope & Duration
46
+
47
+ - This CLA covers **all past and future** Contributions You submit to the Project, unless and until You provide written notice to **revoke** it.
48
+ - Revocation is **not retroactive**: rights granted for prior Contributions remain in effect.
49
+
50
+ ## 8. Disclaimer
51
+
52
+ THE CONTRIBUTION IS PROVIDED “AS IS” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON‑INFRINGEMENT.
53
+
54
+ ## 9. Governing Law & Jurisdiction
55
+
56
+ This CLA is governed by the **laws of England and Wales**, and the courts of England and Wales shall have **exclusive jurisdiction** over any dispute arising out of or relating to it.
57
+
58
+ ## 10. Entire Agreement
59
+
60
+ This CLA is the entire agreement between You and Plasius LTD regarding Contributions. It supersedes any prior discussions relating to Contributions. If any provision is held unenforceable, the remaining provisions remain in full force.
61
+
62
+ ---
63
+
64
+ ## 11. Contributor Information & Signature
65
+
66
+ By signing below, You agree to the terms of this CLA for Your Contributions to the Project.
67
+
68
+ **Full Name:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
69
+
70
+ **Email:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
71
+
72
+ **GitHub Handle:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
73
+
74
+ **Address (optional):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
75
+
76
+ **Employer (if applicable):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
77
+
78
+ **If employed:** ☐ I confirm Contributions are made outside the scope of employment **or** ☐ I have attached my employer’s written permission.
79
+
80
+ **Signature:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
81
+
82
+ **Date (YYYY‑MM‑DD):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
83
+
84
+ _Electronic signatures are accepted. You may type your name in the Signature field and email a PDF copy._
85
+
86
+ **Submission:** Please email the signed CLA to **[contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)** with subject line: `CLA – Individual – <GitHubHandle>`.
87
+
88
+ **(Optional) Attachments / Notes:**
89
+
90
+ - Employer permission letter (if required)
91
+ - Third‑party license disclosures (if any)
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@plasius/gpu-xr",
3
+ "version": "0.1.0",
4
+ "description": "Framework-agnostic WebXR session management for Plasius GPU rendering projects.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "private": false,
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./src/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "README.md",
15
+ "CHANGELOG.md",
16
+ "LICENSE",
17
+ "legal"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./src/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "demo": "python3 -m http.server --directory ..",
30
+ "test": "npm run test:unit",
31
+ "test:unit": "node --test",
32
+ "test:coverage": "c8 --reporter=lcov --reporter=text node --test"
33
+ },
34
+ "keywords": [
35
+ "webxr",
36
+ "xr",
37
+ "vr",
38
+ "immersive",
39
+ "webgpu",
40
+ "plasius"
41
+ ],
42
+ "author": "Plasius LTD <development@plasius.co.uk>",
43
+ "license": "Apache-2.0",
44
+ "devDependencies": {
45
+ "c8": "^10.1.3",
46
+ "tsup": "^8.5.0",
47
+ "typescript": "^5.9.3"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/Plasius-LTD/gpu-xr.git"
52
+ },
53
+ "bugs": {
54
+ "url": "https://github.com/Plasius-LTD/gpu-xr/issues"
55
+ },
56
+ "homepage": "https://github.com/Plasius-LTD/gpu-xr#readme",
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "funding": [
61
+ {
62
+ "type": "patreon",
63
+ "url": "https://www.patreon.com/c/plasiusltd/membership"
64
+ },
65
+ {
66
+ "type": "github",
67
+ "url": "https://github.com/sponsors/Plasius-LTD"
68
+ }
69
+ ]
70
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ export type XrSessionMode = "inline" | "immersive-vr" | "immersive-ar";
2
+
3
+ export type XrReferenceSpaceType =
4
+ | "viewer"
5
+ | "local"
6
+ | "local-floor"
7
+ | "bounded-floor"
8
+ | "unbounded";
9
+
10
+ export interface XrStoreState {
11
+ activeSession: XRSession | null;
12
+ mode: XrSessionMode | null;
13
+ isEntering: boolean;
14
+ lastError: string | null;
15
+ supportedModes: Partial<Record<XrSessionMode, boolean>>;
16
+ }
17
+
18
+ export interface XrStore {
19
+ getSnapshot(): XrStoreState;
20
+ subscribe(listener: (state: XrStoreState) => void): () => void;
21
+ set(partialState: Partial<XrStoreState>): void;
22
+ reset(): void;
23
+ }
24
+
25
+ export interface IsXrModeSupportedOptions {
26
+ navigator?: Navigator | { xr?: unknown };
27
+ }
28
+
29
+ export interface RequestXrSessionOptions {
30
+ mode?: XrSessionMode;
31
+ sessionInit?: XRSessionInit;
32
+ baseSessionInit?: XRSessionInit;
33
+ navigator?: Navigator | { xr?: unknown };
34
+ }
35
+
36
+ export interface XrManagerOptions {
37
+ navigator?: Navigator | { xr?: unknown };
38
+ defaultMode?: XrSessionMode;
39
+ baseSessionInit?: XRSessionInit;
40
+ onSessionStart?: (session: XRSession, mode: XrSessionMode) => void;
41
+ onSessionEnd?: () => void;
42
+ }
43
+
44
+ export interface XrManager {
45
+ store: XrStore;
46
+ getState(): XrStoreState;
47
+ subscribe(listener: (state: XrStoreState) => void): () => void;
48
+ probeSupport(
49
+ modes?: XrSessionMode[]
50
+ ): Promise<Partial<Record<XrSessionMode, boolean>>>;
51
+ enterSession(mode?: XrSessionMode, sessionInit?: XRSessionInit): Promise<XRSession>;
52
+ enterVr(sessionInit?: XRSessionInit): Promise<XRSession>;
53
+ exitSession(): Promise<boolean>;
54
+ dispose(): Promise<void>;
55
+ }
56
+
57
+ export const xrSessionModes: readonly XrSessionMode[];
58
+ export const xrReferenceSpaceTypes: readonly XrReferenceSpaceType[];
59
+ export const defaultVrSessionInit: Readonly<XRSessionInit>;
60
+
61
+ export function mergeXrSessionInit(
62
+ base?: XRSessionInit,
63
+ override?: XRSessionInit
64
+ ): XRSessionInit;
65
+
66
+ export function isXrModeSupported(
67
+ mode?: XrSessionMode,
68
+ options?: IsXrModeSupportedOptions
69
+ ): Promise<boolean>;
70
+
71
+ export function requestXrSession(options?: RequestXrSessionOptions): Promise<XRSession>;
72
+
73
+ export function createXrStore(initialState?: Partial<XrStoreState>): XrStore;
74
+
75
+ export function createXrManager(options?: XrManagerOptions): XrManager;