@sanox/sangine-core 0.5.0 → 0.5.1

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.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var g=(a,e,t)=>e in a?f(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var d=(a,e,t)=>g(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="sangine-assets-v2";let l=null;async function m(a,e,t){if(typeof caches>"u"){const n=await fetch(t);if(!n.ok)throw new Error(`fetch ${t} failed: ${n.status}`);return n.arrayBuffer()}l??(l=caches.open(y));const i=await l,o=`https://sangine-asset-cache/${a}/${e}`,r=await i.match(o);if(r)return r.arrayBuffer();const s=await fetch(t);if(!s.ok)throw new Error(`fetch ${t} failed: ${s.status}`);return i.put(o,s.clone()).catch(()=>{}),s.arrayBuffer()}const u="/static/sangine/wasm",_="3dd43ad4";class A{constructor(e,t){d(this,"workers");d(this,"idle");d(this,"queue",[]);this.workers=Array.from({length:t},e),this.idle=[...this.workers]}run(e,t){return new Promise((i,o)=>{const r=this.idle.pop();r?this.dispatch(r,e,t,i,o):this.queue.push({request:e,transfer:t,resolve:i,reject:o})})}dispatch(e,t,i,o,r){const s=h=>{o(h.data),c(),this.release(e)},n=h=>{r(h),c(),this.release(e)},c=()=>{e.removeEventListener("message",s),e.removeEventListener("error",n)};e.addEventListener("message",s,{once:!0}),e.addEventListener("error",n,{once:!0}),e.postMessage(t,i??[])}release(e){const t=this.queue.shift();t?this.dispatch(e,t.request,t.transfer,t.resolve,t.reject):this.idle.push(e)}broadcast(e){for(const t of this.workers)t.postMessage(e)}terminate(){for(const e of this.workers)e.terminate()}}class b{constructor(e){d(this,"wasm",null);d(this,"callbackRegistry",{});d(this,"userActionRegistry",{});d(this,"assetsDownloadingRegistry",{});d(this,"windowCreatedPromiseRegistry",{});d(this,"windowCreatedPromiseResolveRegistry",{});d(this,"_inited",!1);d(this,"decodePool");d(this,"_readyPromise");d(this,"_resolveReady");d(this,"_rejectReady");this.config=e,this._readyPromise=new Promise((t,i)=>{this._resolveReady=t,this._rejectReady=i}),this.config=e}async init(){if(!(typeof window>"u")){if(this._inited)return this._readyPromise;try{const t=await import(new URL(`${u}/sangine/sangine.${_}.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const i=Math.min(this.config.numWorkers??(navigator.hardwareConcurrency||2)-1,2);this.decodePool=new A(()=>this.config.createDecodeWorker(),Math.max(i,1)),this.wasm.register_asset_decoder(this.decodeAsset.bind(this)),this.wasm.register_event_listener(this.handleSangineEvent.bind(this)),this._resolveReady()}catch(e){throw this._rejectReady(e),e}return this._readyPromise}}ready(){return this._readyPromise}get inited(){return this._inited}getWasm(){if(!this.wasm)throw new Error("RendererService not initialized");return this.wasm}handleActionChanged(e,t){this.userActionRegistry[e]=t;for(const i of this.callbackRegistry[e].actionChanged)i(t)}handleMeasurementCreated(e,t){for(const i of this.callbackRegistry[e].measurementCreated)i(t)}handleAssetsDownloading(e,t){this.assetsDownloadingRegistry[e]=t;for(const i of this.callbackRegistry[e].assetsDownloading)i(t)}handleUserInteractionStarted(e){for(const t of this.callbackRegistry[e].userInteractionStarted)t()}handleAnnotationCreated(e,t){for(const i of this.callbackRegistry[e].annotationCreated)i(t)}handleSangineEvent(e,t){t==="ready"?this.windowCreatedPromiseResolveRegistry[e]():t==="userInteractionStarted"?this.handleUserInteractionStarted(e):"actionChanged"in t?this.handleActionChanged(e,t.actionChanged.action):"measurementCreated"in t?this.handleMeasurementCreated(e,t.measurementCreated.measurement):"assetsDownloading"in t?this.handleAssetsDownloading(e,t.assetsDownloading.downloading):"annotationCreated"in t&&this.handleAnnotationCreated(e,t.annotationCreated)}createWindow(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");let o;const r=new Promise(n=>{o=n}),s=this.wasm.create_window(e,t,i);return this.windowCreatedPromiseResolveRegistry[s]=o,this.callbackRegistry[s]={actionChanged:[],measurementCreated:[],assetsDownloading:[],userInteractionStarted:[],annotationCreated:[]},this.userActionRegistry[s]="watching",this.windowCreatedPromiseRegistry[s]=r,s}getAssetsDownloading(e){return this.assetsDownloadingRegistry[e]||!1}readUserAction(e){return this.userActionRegistry[e]}windowReady(e){return this.windowCreatedPromiseRegistry[e]}registerCallback(e,t,i){this.callbackRegistry[e][t].push(i)}setWindowAction(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_action(e,t)}destroyWindow(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.destroy_window(e),delete this.callbackRegistry[e],delete this.userActionRegistry[e]}setAnnotationProps(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_props(e,t,i)}setAnnotationKind(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_kind(e,t,i)}addAnnotation(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_insert(e,t,i)}finishAnnotation(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_finish(e)}annotationRemoveLastPoint(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove_last_point(e)}removeAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove(e,t)}animateToAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_annotation(e,t)}setSunProperties(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_sun_properties(e,t)}setAmbientLighting(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_ambient_lighting(e,t)}setLightingMode(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_lighting_mode(e,t)}setNorthCorrection(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_north_correction(e,t)}setGpuMemoryBudgetMb(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_gpu_memory_budget_mb(e,t)}setRenderQuality(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_render_quality(e,t)}readCameraPos(e){if(!this.wasm)throw new Error("WASM not initialized");return this.wasm.read_camera_pos(e)}animateTo(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to(e,t)}setScale(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_scale(e,t)}async decodeAsset(e){if(!this.decodePool)throw new Error("Renderer not initialized");if("texture-file"in e){const{pk:r,url:s,encoding:n,format:c}=e["texture-file"],h=await m("texture",r,s);return n==="ktx2"?this.decodePool.run({kind:"texture-basis",bytes:h,format:c},[h]):this.decodePool.run({kind:"texture-image",bytes:h},[h])}const{pk:t,url:i}=e["model-part-mesh"],o=await m("mesh",t,i);return this.decodePool.run({kind:"model-sbo",bytes:o},[o])}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const R="b6df9f4e",p=0;function M(a){let e=!1,t=null;async function i(){if(e)return;const r=await import(new URL(`${u}/decode/wasm_decode.${R}.js`,a.location.origin).href);await r.default(),await r.init_basis(),t=r,e=!0}a.onmessage=async o=>{const r=o.data;try{if(r.kind==="texture-basis"){await i();const s=new Uint8Array(r.bytes),n=t.transcode_basis(s,r.format);a.postMessage({success:!0,width:n.width,height:n.height,data:n.data.buffer,format:n.format},[n.data.buffer])}else if(r.kind==="texture-image"){const s=new Blob([r.bytes]),n=await createImageBitmap(s),c=new OffscreenCanvas(n.width,n.height),h=c.getContext("2d");if(h===null)throw new Error("Couldnt create canvas");h.drawImage(n,0,0);const w=h.getImageData(0,0,c.width,c.height);a.postMessage({success:!0,width:c.width,height:c.height,data:w.data.buffer,format:p},[w.data.buffer])}else if(r.kind==="model-sbo"){await i();const s=new Uint8Array(r.bytes),n=t.decode_sbo(s);a.postMessage({success:!0,data:n.buffer},[n.buffer])}else{const s=r;throw new Error(`unknown task kind: ${s.kind}`)}}catch(s){a.postMessage({success:!1,error:s.message})}}}exports.RendererService=b;exports.registerDecodeWorker=M;
1
+ "use strict";var f=Object.defineProperty;var g=(a,e,t)=>e in a?f(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var d=(a,e,t)=>g(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="sangine-assets-v2";let l=null;async function m(a,e,t){if(typeof caches>"u"){const n=await fetch(t);if(!n.ok)throw new Error(`fetch ${t} failed: ${n.status}`);return n.arrayBuffer()}l??(l=caches.open(y));const i=await l,o=`https://sangine-asset-cache/${a}/${e}`,r=await i.match(o);if(r)return r.arrayBuffer();const s=await fetch(t);if(!s.ok)throw new Error(`fetch ${t} failed: ${s.status}`);return i.put(o,s.clone()).catch(()=>{}),s.arrayBuffer()}const u="/static/sangine/wasm",_="9ff4232d";class A{constructor(e,t){d(this,"workers");d(this,"idle");d(this,"queue",[]);this.workers=Array.from({length:t},e),this.idle=[...this.workers]}run(e,t){return new Promise((i,o)=>{const r=this.idle.pop();r?this.dispatch(r,e,t,i,o):this.queue.push({request:e,transfer:t,resolve:i,reject:o})})}dispatch(e,t,i,o,r){const s=h=>{o(h.data),c(),this.release(e)},n=h=>{r(h),c(),this.release(e)},c=()=>{e.removeEventListener("message",s),e.removeEventListener("error",n)};e.addEventListener("message",s,{once:!0}),e.addEventListener("error",n,{once:!0}),e.postMessage(t,i??[])}release(e){const t=this.queue.shift();t?this.dispatch(e,t.request,t.transfer,t.resolve,t.reject):this.idle.push(e)}broadcast(e){for(const t of this.workers)t.postMessage(e)}terminate(){for(const e of this.workers)e.terminate()}}class b{constructor(e){d(this,"wasm",null);d(this,"callbackRegistry",{});d(this,"userActionRegistry",{});d(this,"assetsDownloadingRegistry",{});d(this,"windowCreatedPromiseRegistry",{});d(this,"windowCreatedPromiseResolveRegistry",{});d(this,"_inited",!1);d(this,"decodePool");d(this,"_readyPromise");d(this,"_resolveReady");d(this,"_rejectReady");this.config=e,this._readyPromise=new Promise((t,i)=>{this._resolveReady=t,this._rejectReady=i}),this.config=e}async init(){if(!(typeof window>"u")){if(this._inited)return this._readyPromise;try{const t=await import(new URL(`${u}/sangine/sangine.${_}.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const i=Math.min(this.config.numWorkers??(navigator.hardwareConcurrency||2)-1,2);this.decodePool=new A(()=>this.config.createDecodeWorker(),Math.max(i,1)),this.wasm.register_asset_decoder(this.decodeAsset.bind(this)),this.wasm.register_event_listener(this.handleSangineEvent.bind(this)),this._resolveReady()}catch(e){throw this._rejectReady(e),e}return this._readyPromise}}ready(){return this._readyPromise}get inited(){return this._inited}getWasm(){if(!this.wasm)throw new Error("RendererService not initialized");return this.wasm}handleActionChanged(e,t){this.userActionRegistry[e]=t;for(const i of this.callbackRegistry[e].actionChanged)i(t)}handleMeasurementCreated(e,t){for(const i of this.callbackRegistry[e].measurementCreated)i(t)}handleAssetsDownloading(e,t){this.assetsDownloadingRegistry[e]=t;for(const i of this.callbackRegistry[e].assetsDownloading)i(t)}handleUserInteractionStarted(e){for(const t of this.callbackRegistry[e].userInteractionStarted)t()}handleAnnotationCreated(e,t){for(const i of this.callbackRegistry[e].annotationCreated)i(t)}handleSangineEvent(e,t){t==="ready"?this.windowCreatedPromiseResolveRegistry[e]():t==="userInteractionStarted"?this.handleUserInteractionStarted(e):"actionChanged"in t?this.handleActionChanged(e,t.actionChanged.action):"measurementCreated"in t?this.handleMeasurementCreated(e,t.measurementCreated.measurement):"assetsDownloading"in t?this.handleAssetsDownloading(e,t.assetsDownloading.downloading):"annotationCreated"in t&&this.handleAnnotationCreated(e,t.annotationCreated)}createWindow(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");let o;const r=new Promise(n=>{o=n}),s=this.wasm.create_window(e,t,i);return this.windowCreatedPromiseResolveRegistry[s]=o,this.callbackRegistry[s]={actionChanged:[],measurementCreated:[],assetsDownloading:[],userInteractionStarted:[],annotationCreated:[]},this.userActionRegistry[s]="watching",this.windowCreatedPromiseRegistry[s]=r,s}getAssetsDownloading(e){return this.assetsDownloadingRegistry[e]||!1}readUserAction(e){return this.userActionRegistry[e]}windowReady(e){return this.windowCreatedPromiseRegistry[e]}registerCallback(e,t,i){this.callbackRegistry[e][t].push(i)}setWindowAction(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_action(e,t)}destroyWindow(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.destroy_window(e),delete this.callbackRegistry[e],delete this.userActionRegistry[e]}setAnnotationProps(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_props(e,t,i)}setAnnotationKind(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_kind(e,t,i)}addAnnotation(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_insert(e,t,i)}finishAnnotation(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_finish(e)}annotationRemoveLastPoint(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove_last_point(e)}removeAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove(e,t)}animateToAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_annotation(e,t)}setSunProperties(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_sun_properties(e,t)}setAmbientLighting(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_ambient_lighting(e,t)}setLightingMode(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_lighting_mode(e,t)}setNorthCorrection(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_north_correction(e,t)}setGpuMemoryBudgetMb(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_gpu_memory_budget_mb(e,t)}setRenderQuality(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_render_quality(e,t)}readCameraPos(e){if(!this.wasm)throw new Error("WASM not initialized");return this.wasm.read_camera_pos(e)}animateTo(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to(e,t)}setScale(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_scale(e,t)}async decodeAsset(e){if(!this.decodePool)throw new Error("Renderer not initialized");if("texture-file"in e){const{pk:r,url:s,encoding:n,format:c}=e["texture-file"],h=await m("texture",r,s);return n==="ktx2"?this.decodePool.run({kind:"texture-basis",bytes:h,format:c},[h]):this.decodePool.run({kind:"texture-image",bytes:h},[h])}const{pk:t,url:i}=e["model-part-mesh"],o=await m("mesh",t,i);return this.decodePool.run({kind:"model-sbo",bytes:o},[o])}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const R="b6df9f4e",p=0;function M(a){let e=!1,t=null;async function i(){if(e)return;const r=await import(new URL(`${u}/decode/wasm_decode.${R}.js`,a.location.origin).href);await r.default(),await r.init_basis(),t=r,e=!0}a.onmessage=async o=>{const r=o.data;try{if(r.kind==="texture-basis"){await i();const s=new Uint8Array(r.bytes),n=t.transcode_basis(s,r.format);a.postMessage({success:!0,width:n.width,height:n.height,data:n.data.buffer,format:n.format},[n.data.buffer])}else if(r.kind==="texture-image"){const s=new Blob([r.bytes]),n=await createImageBitmap(s),c=new OffscreenCanvas(n.width,n.height),h=c.getContext("2d");if(h===null)throw new Error("Couldnt create canvas");h.drawImage(n,0,0);const w=h.getImageData(0,0,c.width,c.height);a.postMessage({success:!0,width:c.width,height:c.height,data:w.data.buffer,format:p},[w.data.buffer])}else if(r.kind==="model-sbo"){await i();const s=new Uint8Array(r.bytes),n=t.decode_sbo(s);a.postMessage({success:!0,data:n.buffer},[n.buffer])}else{const s=r;throw new Error(`unknown task kind: ${s.kind}`)}}catch(s){a.postMessage({success:!1,error:s.message})}}}exports.RendererService=b;exports.registerDecodeWorker=M;
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- var f = Object.defineProperty;
2
- var g = (a, e, t) => e in a ? f(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
- var d = (a, e, t) => g(a, typeof e != "symbol" ? e + "" : e, t);
1
+ var u = Object.defineProperty;
2
+ var g = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
+ var h = (a, e, t) => g(a, typeof e != "symbol" ? e + "" : e, t);
4
4
  const y = "sangine-assets-v2";
5
5
  let l = null;
6
6
  async function m(a, e, t) {
@@ -17,12 +17,12 @@ async function m(a, e, t) {
17
17
  return i.put(o, s.clone()).catch(() => {
18
18
  }), s.arrayBuffer();
19
19
  }
20
- const u = "/static/sangine/wasm", _ = "3dd43ad4";
20
+ const f = "/static/sangine/wasm", _ = "9ff4232d";
21
21
  class A {
22
22
  constructor(e, t) {
23
- d(this, "workers");
24
- d(this, "idle");
25
- d(this, "queue", []);
23
+ h(this, "workers");
24
+ h(this, "idle");
25
+ h(this, "queue", []);
26
26
  this.workers = Array.from({ length: t }, e), this.idle = [...this.workers];
27
27
  }
28
28
  run(e, t) {
@@ -32,10 +32,10 @@ class A {
32
32
  });
33
33
  }
34
34
  dispatch(e, t, i, o, n) {
35
- const s = (h) => {
36
- o(h.data), c(), this.release(e);
37
- }, r = (h) => {
38
- n(h), c(), this.release(e);
35
+ const s = (d) => {
36
+ o(d.data), c(), this.release(e);
37
+ }, r = (d) => {
38
+ n(d), c(), this.release(e);
39
39
  }, c = () => {
40
40
  e.removeEventListener("message", s), e.removeEventListener("error", r);
41
41
  };
@@ -56,17 +56,17 @@ class A {
56
56
  }
57
57
  class M {
58
58
  constructor(e) {
59
- d(this, "wasm", null);
60
- d(this, "callbackRegistry", {});
61
- d(this, "userActionRegistry", {});
62
- d(this, "assetsDownloadingRegistry", {});
63
- d(this, "windowCreatedPromiseRegistry", {});
64
- d(this, "windowCreatedPromiseResolveRegistry", {});
65
- d(this, "_inited", !1);
66
- d(this, "decodePool");
67
- d(this, "_readyPromise");
68
- d(this, "_resolveReady");
69
- d(this, "_rejectReady");
59
+ h(this, "wasm", null);
60
+ h(this, "callbackRegistry", {});
61
+ h(this, "userActionRegistry", {});
62
+ h(this, "assetsDownloadingRegistry", {});
63
+ h(this, "windowCreatedPromiseRegistry", {});
64
+ h(this, "windowCreatedPromiseResolveRegistry", {});
65
+ h(this, "_inited", !1);
66
+ h(this, "decodePool");
67
+ h(this, "_readyPromise");
68
+ h(this, "_resolveReady");
69
+ h(this, "_rejectReady");
70
70
  this.config = e, this._readyPromise = new Promise((t, i) => {
71
71
  this._resolveReady = t, this._rejectReady = i;
72
72
  }), this.config = e;
@@ -76,7 +76,7 @@ class M {
76
76
  if (this._inited) return this._readyPromise;
77
77
  try {
78
78
  const t = await import(new URL(
79
- `${u}/sangine/sangine.${_}.js`,
79
+ `${f}/sangine/sangine.${_}.js`,
80
80
  window.location.origin
81
81
  ).toString());
82
82
  await t.default(), this.wasm = t, this._inited = !0;
@@ -231,8 +231,8 @@ class M {
231
231
  async decodeAsset(e) {
232
232
  if (!this.decodePool) throw new Error("Renderer not initialized");
233
233
  if ("texture-file" in e) {
234
- const { pk: n, url: s, encoding: r, format: c } = e["texture-file"], h = await m("texture", n, s);
235
- return r === "ktx2" ? this.decodePool.run({ kind: "texture-basis", bytes: h, format: c }, [h]) : this.decodePool.run({ kind: "texture-image", bytes: h }, [h]);
234
+ const { pk: n, url: s, encoding: r, format: c } = e["texture-file"], d = await m("texture", n, s);
235
+ return r === "ktx2" ? this.decodePool.run({ kind: "texture-basis", bytes: d, format: c }, [d]) : this.decodePool.run({ kind: "texture-image", bytes: d }, [d]);
236
236
  }
237
237
  const { pk: t, url: i } = e["model-part-mesh"], o = await m("mesh", t, i);
238
238
  return this.decodePool.run({ kind: "model-sbo", bytes: o }, [o]);
@@ -248,7 +248,7 @@ function E(a) {
248
248
  async function i() {
249
249
  if (e) return;
250
250
  const n = await import(new URL(
251
- `${u}/decode/wasm_decode.${b}.js`,
251
+ `${f}/decode/wasm_decode.${b}.js`,
252
252
  a.location.origin
253
253
  ).href);
254
254
  await n.default(), await n.init_basis(), t = n, e = !0;
@@ -270,10 +270,10 @@ function E(a) {
270
270
  [r.data.buffer]
271
271
  );
272
272
  } else if (n.kind === "texture-image") {
273
- const s = new Blob([n.bytes]), r = await createImageBitmap(s), c = new OffscreenCanvas(r.width, r.height), h = c.getContext("2d");
274
- if (h === null) throw new Error("Couldnt create canvas");
275
- h.drawImage(r, 0, 0);
276
- const w = h.getImageData(0, 0, c.width, c.height);
273
+ const s = new Blob([n.bytes]), r = await createImageBitmap(s), c = new OffscreenCanvas(r.width, r.height), d = c.getContext("2d");
274
+ if (d === null) throw new Error("Couldnt create canvas");
275
+ d.drawImage(r, 0, 0);
276
+ const w = d.getImageData(0, 0, c.width, c.height);
277
277
  a.postMessage(
278
278
  {
279
279
  success: !0,
@@ -2752,57 +2752,57 @@ function __wbg_get_imports() {
2752
2752
  arg0.writeTexture(arg1, arg2, arg3, arg4);
2753
2753
  }, arguments); },
2754
2754
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2755
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2755
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2756
2756
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b);
2757
2757
  return ret;
2758
2758
  },
2759
2759
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2760
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3972, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2760
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3974, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2761
2761
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd8590da73942d3e0);
2762
2762
  return ret;
2763
2763
  },
2764
2764
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
2765
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx: 1642, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2765
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx: 1644, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2766
2766
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h6ff3e7511bd758a3);
2767
2767
  return ret;
2768
2768
  },
2769
2769
  __wbindgen_cast_0000000000000004: function(arg0, arg1) {
2770
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2770
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2771
2771
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_3);
2772
2772
  return ret;
2773
2773
  },
2774
2774
  __wbindgen_cast_0000000000000005: function(arg0, arg1) {
2775
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2775
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2776
2776
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_4);
2777
2777
  return ret;
2778
2778
  },
2779
2779
  __wbindgen_cast_0000000000000006: function(arg0, arg1) {
2780
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("FocusEvent")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2780
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("FocusEvent")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2781
2781
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_5);
2782
2782
  return ret;
2783
2783
  },
2784
2784
  __wbindgen_cast_0000000000000007: function(arg0, arg1) {
2785
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2785
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2786
2786
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_6);
2787
2787
  return ret;
2788
2788
  },
2789
2789
  __wbindgen_cast_0000000000000008: function(arg0, arg1) {
2790
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PageTransitionEvent")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2790
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PageTransitionEvent")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2791
2791
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_7);
2792
2792
  return ret;
2793
2793
  },
2794
2794
  __wbindgen_cast_0000000000000009: function(arg0, arg1) {
2795
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2795
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2796
2796
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_8);
2797
2797
  return ret;
2798
2798
  },
2799
2799
  __wbindgen_cast_000000000000000a: function(arg0, arg1) {
2800
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("WheelEvent")], shim_idx: 1635, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2800
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("WheelEvent")], shim_idx: 1637, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2801
2801
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_9);
2802
2802
  return ret;
2803
2803
  },
2804
2804
  __wbindgen_cast_000000000000000b: function(arg0, arg1) {
2805
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2805
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1642, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2806
2806
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hdb7f99c0126c5c28);
2807
2807
  return ret;
2808
2808
  },
@@ -3371,7 +3371,7 @@ async function __wbg_init(module_or_path) {
3371
3371
  }
3372
3372
 
3373
3373
  if (module_or_path === undefined) {
3374
- module_or_path = new URL('sangine_bg.3dd43ad4.wasm', import.meta.url);
3374
+ module_or_path = new URL('sangine_bg.9ff4232d.wasm', import.meta.url);
3375
3375
  }
3376
3376
  const imports = __wbg_get_imports();
3377
3377
 
@@ -0,0 +1,217 @@
1
+ /* @ts-self-types="./wasm_sbo_decode.d.ts" */
2
+
3
+ //#region exports
4
+
5
+ /**
6
+ * @param {Uint8Array} data
7
+ * @returns {Uint8Array}
8
+ */
9
+ export function decode_sbo(data) {
10
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ret = wasm.decode_sbo(ptr0, len0);
13
+ if (ret[2]) {
14
+ throw takeFromExternrefTable0(ret[1]);
15
+ }
16
+ return takeFromExternrefTable0(ret[0]);
17
+ }
18
+
19
+ //#endregion
20
+
21
+ //#region wasm imports
22
+
23
+ function __wbg_get_imports() {
24
+ const import0 = {
25
+ __proto__: null,
26
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
27
+ throw new Error(getStringFromWasm0(arg0, arg1));
28
+ },
29
+ __wbg_new_from_slice_a3d2629dc1826784: function() { return logError(function (arg0, arg1) {
30
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
31
+ return ret;
32
+ }, arguments); },
33
+ __wbindgen_cast_0000000000000001: function() { return logError(function (arg0, arg1) {
34
+ // Cast intrinsic for `Ref(String) -> Externref`.
35
+ const ret = getStringFromWasm0(arg0, arg1);
36
+ return ret;
37
+ }, arguments); },
38
+ __wbindgen_init_externref_table: function() {
39
+ const table = wasm.__wbindgen_externrefs;
40
+ const offset = table.grow(4);
41
+ table.set(0, undefined);
42
+ table.set(offset + 0, undefined);
43
+ table.set(offset + 1, null);
44
+ table.set(offset + 2, true);
45
+ table.set(offset + 3, false);
46
+ },
47
+ };
48
+ return {
49
+ __proto__: null,
50
+ "./wasm_sbo_decode_bg.js": import0,
51
+ };
52
+ }
53
+
54
+
55
+ //#endregion
56
+
57
+ //#region intrinsics
58
+ function getArrayU8FromWasm0(ptr, len) {
59
+ ptr = ptr >>> 0;
60
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
61
+ }
62
+
63
+ function getStringFromWasm0(ptr, len) {
64
+ ptr = ptr >>> 0;
65
+ return decodeText(ptr, len);
66
+ }
67
+
68
+ let cachedUint8ArrayMemory0 = null;
69
+ function getUint8ArrayMemory0() {
70
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
71
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
72
+ }
73
+ return cachedUint8ArrayMemory0;
74
+ }
75
+
76
+ function logError(f, args) {
77
+ try {
78
+ return f.apply(this, args);
79
+ } catch (e) {
80
+ let error = (function () {
81
+ try {
82
+ return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
83
+ } catch(_) {
84
+ return "<failed to stringify thrown value>";
85
+ }
86
+ }());
87
+ console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
88
+ throw e;
89
+ }
90
+ }
91
+
92
+ function passArray8ToWasm0(arg, malloc) {
93
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
94
+ getUint8ArrayMemory0().set(arg, ptr / 1);
95
+ WASM_VECTOR_LEN = arg.length;
96
+ return ptr;
97
+ }
98
+
99
+ function takeFromExternrefTable0(idx) {
100
+ const value = wasm.__wbindgen_externrefs.get(idx);
101
+ wasm.__externref_table_dealloc(idx);
102
+ return value;
103
+ }
104
+
105
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
106
+ cachedTextDecoder.decode();
107
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
108
+ let numBytesDecoded = 0;
109
+ function decodeText(ptr, len) {
110
+ numBytesDecoded += len;
111
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
112
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
113
+ cachedTextDecoder.decode();
114
+ numBytesDecoded = len;
115
+ }
116
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
117
+ }
118
+
119
+ let WASM_VECTOR_LEN = 0;
120
+
121
+
122
+ //#endregion
123
+
124
+ //#region wasm loading
125
+ let wasmModule, wasm;
126
+ function __wbg_finalize_init(instance, module) {
127
+ wasm = instance.exports;
128
+ wasmModule = module;
129
+ cachedUint8ArrayMemory0 = null;
130
+ wasm.__wbindgen_start();
131
+ return wasm;
132
+ }
133
+
134
+ async function __wbg_load(module, imports) {
135
+ if (typeof Response === 'function' && module instanceof Response) {
136
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
137
+ try {
138
+ return await WebAssembly.instantiateStreaming(module, imports);
139
+ } catch (e) {
140
+ const validResponse = module.ok && expectedResponseType(module.type);
141
+
142
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
143
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
144
+
145
+ } else { throw e; }
146
+ }
147
+ }
148
+
149
+ const bytes = await module.arrayBuffer();
150
+ return await WebAssembly.instantiate(bytes, imports);
151
+ } else {
152
+ const instance = await WebAssembly.instantiate(module, imports);
153
+
154
+ if (instance instanceof WebAssembly.Instance) {
155
+ return { instance, module };
156
+ } else {
157
+ return instance;
158
+ }
159
+ }
160
+
161
+ function expectedResponseType(type) {
162
+ switch (type) {
163
+ case 'basic': case 'cors': case 'default': return true;
164
+ }
165
+ return false;
166
+ }
167
+ }
168
+
169
+ function initSync(module) {
170
+ if (wasm !== undefined) return wasm;
171
+
172
+
173
+ if (module !== undefined) {
174
+ if (Object.getPrototypeOf(module) === Object.prototype) {
175
+ ({module} = module)
176
+ } else {
177
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
178
+ }
179
+ }
180
+
181
+ const imports = __wbg_get_imports();
182
+ if (!(module instanceof WebAssembly.Module)) {
183
+ module = new WebAssembly.Module(module);
184
+ }
185
+ const instance = new WebAssembly.Instance(module, imports);
186
+ return __wbg_finalize_init(instance, module);
187
+ }
188
+
189
+ async function __wbg_init(module_or_path) {
190
+ if (wasm !== undefined) return wasm;
191
+
192
+
193
+ if (module_or_path !== undefined) {
194
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
195
+ ({module_or_path} = module_or_path)
196
+ } else {
197
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
198
+ }
199
+ }
200
+
201
+ if (module_or_path === undefined) {
202
+ module_or_path = new URL('wasm_sbo_decode_bg.63ffe035.wasm', import.meta.url);
203
+ }
204
+ const imports = __wbg_get_imports();
205
+
206
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
207
+ module_or_path = fetch(module_or_path);
208
+ }
209
+
210
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
211
+
212
+ return __wbg_finalize_init(instance, module);
213
+ }
214
+
215
+ export { initSync, __wbg_init as default };
216
+ //#endregion
217
+ export { wasm as __wasm }
@@ -0,0 +1,37 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function decode_sbo(data: Uint8Array): Uint8Array;
5
+
6
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7
+
8
+ export interface InitOutput {
9
+ readonly memory: WebAssembly.Memory;
10
+ readonly decode_sbo: (a: number, b: number) => [number, number, number];
11
+ readonly __wbindgen_externrefs: WebAssembly.Table;
12
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
13
+ readonly __externref_table_dealloc: (a: number) => void;
14
+ readonly __wbindgen_start: () => void;
15
+ }
16
+
17
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
18
+
19
+ /**
20
+ * Instantiates the given `module`, which can either be bytes or
21
+ * a precompiled `WebAssembly.Module`.
22
+ *
23
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
24
+ *
25
+ * @returns {InitOutput}
26
+ */
27
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
28
+
29
+ /**
30
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
31
+ * for everything else, calls `WebAssembly.instantiate` directly.
32
+ *
33
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
34
+ *
35
+ * @returns {Promise<InitOutput>}
36
+ */
37
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const decode_sbo: (a: number, b: number) => [number, number, number];
5
+ export const __wbindgen_externrefs: WebAssembly.Table;
6
+ export const __wbindgen_malloc: (a: number, b: number) => number;
7
+ export const __externref_table_dealloc: (a: number) => void;
8
+ export const __wbindgen_start: () => void;
@@ -1,2 +1,2 @@
1
- export declare const SANGINE_HASH = "3dd43ad4";
1
+ export declare const SANGINE_HASH = "9ff4232d";
2
2
  //# sourceMappingURL=sangine.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const SBO_DECODE_HASH = "63ffe035";
2
+ //# sourceMappingURL=sbo-decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sbo-decode.d.ts","sourceRoot":"","sources":["../../src/wasm-hashes/sbo-decode.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanox/sangine-core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Sangine core renderer runtime (WASM + workers)",
5
5
  "type": "module",
6
6
  "private": false,