@onirix/ar-engine-sdk 1.5.7 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ class IndexedDBManager{constructor(e,r){this.dbName=e,this.storeName=r;}async getFromCacheOrFetch(e,r){let t=null;try{t=await this.getFileFromIndexedDB(e);}catch(e){console.log("An error occurred while trying to get element from indexedDB.");}return t||(t=await this.fetchAndCacheFile(r,e)),new Uint8Array(t)}async getFileFromIndexedDB(e){return new Promise(((r,t)=>{const o=indexedDB.open(this.dbName);o.onerror=()=>t(o.error),o.onsuccess=()=>{const s=o.result.transaction(this.storeName,"readonly").objectStore(this.storeName).get(e);s.onsuccess=()=>r(s.result),s.onerror=()=>t(s.error);},o.onupgradeneeded=e=>{e.target.result.createObjectStore(this.storeName);};}))}async saveFileToIndexedDB(e,r){return new Promise(((t,o)=>{const s=indexedDB.open(this.dbName);s.onerror=()=>o(s.error),s.onupgradeneeded=e=>{e.target.result.createObjectStore(this.storeName);},s.onsuccess=()=>{try{const n=s.result.transaction(this.storeName,"readwrite"),a=n.objectStore(this.storeName).put(r,e);a.onsuccess=()=>t(a.result),a.onerror=()=>o(a.error);}catch(e){o(e);}};}))}async fetchAndCacheFile(e,r){const t=await fetch(e),o=await t.arrayBuffer();return await this.saveFileToIndexedDB(r,o),o}}
2
+
3
+ class WorkerNative{constructor(){this.ready=!1;this.indexedDBManager=new IndexedDBManager("onirix-sdk","files"),this.indexedDBManager.getFileFromIndexedDB("SDK_1.6.0").then((async e=>{let t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));const{default:a}=await import(/* webpackIgnore: true, webpackMode: "lazy" */t),r=await a();this.nativeSDK=r,this.fromBuffer=this.nativeSDK._malloc(22e5),this.toBuffer=this.nativeSDK._malloc(22e5),this.ready=!0,postMessage("ready");}));}start(){addEventListener("message",(async e=>{if(!this.ready)return;const t=e.data,a=t.from,r=t.to;this.nativeSDK.HEAPF32.set(a,this.fromBuffer/4),this.nativeSDK.HEAPF32.set(r,this.toBuffer/4);let s=this.nativeSDK._OX_Match(this.fromBuffer,this.toBuffer,t.dtype);postMessage(new Float32Array(this.readMatchingData(this.nativeSDK.HEAPF32,s/4)));}));}readMatchingData(e,t){let a=t,r=[],s=e[a];r.push(s),a++;for(let t=0;t<s;t++)r.push(e[a]),r.push(e[a+1]),a+=2;return r}}const worker=new WorkerNative;worker.start();
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "@onirix/ar-engine-sdk",
3
- "version": "1.5.7",
3
+ "version": "1.6.0",
4
4
  "description": "Onirix AR Engine SDK allows to create Augmented Reality experiences that run in a web browser.",
5
5
  "main": "./dist/ox-sdk.js",
6
6
  "module": "./dist/ox-sdk.esm.js",
7
- "unpkg": "./dist/ox-sdk.umd.js",
7
+ "type": "module",
8
8
  "source": "src/OnirixSDK.js",
9
9
  "scripts": {
10
- "build": "rimraf dist && microbundle --name OnirixSDK --external none --sourcemap false",
11
- "build-dev": "rimraf dist && microbundle --name OnirixSDK --external none --sourcemap true -f esm"
10
+ "build": "rimraf dist && rollup -c && npm run copy-js && npm run copy-onnx-wasm",
11
+ "build-dev": "rimraf dist && rollup -c && npm run copy-js && npm run copy-onnx-wasm",
12
+ "serve": "http-server -c-1 -S -C cert.pem",
13
+ "copy-js": "cp ../wasm/build/*.js dist",
14
+ "copy-onnx-wasm": "cp node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm dist",
15
+ "run-dev": "npm run build-dev && npm run serve"
12
16
  },
13
17
  "author": "Onirix",
14
18
  "license": "Propietary",
@@ -19,10 +23,18 @@
19
23
  ],
20
24
  "dependencies": {
21
25
  "bowser": "^2.11.0",
26
+ "onnxruntime-web": "^1.16.3",
22
27
  "rvfc-polyfill": "^1.0.6"
23
28
  },
24
29
  "devDependencies": {
25
- "microbundle": "^0.14.2",
26
- "rimraf": "^3.0.2"
30
+ "@lopatnov/rollup-plugin-uglify": "^2.1.5",
31
+ "@rollup/plugin-commonjs": "^25.0.7",
32
+ "@rollup/plugin-node-resolve": "^13.3.0",
33
+ "@rollup/plugin-replace": "^5.0.5",
34
+ "rimraf": "^3.0.2",
35
+ "rollup": "^2.79.1",
36
+ "rollup-plugin-minify": "^1.0.3",
37
+ "rollup-plugin-modify": "^3.0.0",
38
+ "terser": "^5.26.0"
27
39
  }
28
40
  }