@heliguy-xyz/splat-viewer 1.0.0-rc.2 → 1.0.0-rc.4

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.
@@ -140037,7 +140037,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
140037
140037
  this.focus(result.entity);
140038
140038
  setTimeout(() => {
140039
140039
  const info = this.debugInfo();
140040
- console.log(info);
140040
+ // no-op
140041
140041
  if (!info.boundsRadius) {
140042
140042
  this.focus(result.entity);
140043
140043
  }
@@ -140833,44 +140833,150 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
140833
140833
  if (!this.app)
140834
140834
  return;
140835
140835
  const canvas = this.app.graphicsDevice.canvas;
140836
- // Set the canvas resolution to match the display size with device pixel ratio
140836
+ // debug removed
140837
+ // Ensure canvas and its parent fill available space by default (non-destructive)
140838
+ if (!canvas.style.display)
140839
+ canvas.style.display = 'block';
140840
+ if (!canvas.style.width)
140841
+ canvas.style.width = '100%';
140842
+ if (!canvas.style.height)
140843
+ canvas.style.height = '100%';
140844
+ if (canvas.parentElement) {
140845
+ const ps = canvas.parentElement.style;
140846
+ if (!ps.width)
140847
+ ps.width = '100%';
140848
+ if (!ps.height)
140849
+ ps.height = '100%';
140850
+ // debug removed
140851
+ }
140852
+ // Helper: apply resolution and notify dependents
140853
+ const applyResolution = (width, height) => {
140854
+ if (canvas.width === width && canvas.height === height)
140855
+ return;
140856
+ // track previous size if needed in future
140857
+ canvas.width = width;
140858
+ canvas.height = height;
140859
+ this.app.resizeCanvas(width, height);
140860
+ // debug removed
140861
+ if (this._orbit &&
140862
+ this._orbit.navigationCube &&
140863
+ typeof this._orbit.navigationCube.onCanvasResize === 'function') {
140864
+ this._orbit.navigationCube.onCanvasResize();
140865
+ // debug removed
140866
+ }
140867
+ };
140868
+ // Fallback: compute from CSS box * devicePixelRatio
140837
140869
  const updateResolution = () => {
140838
140870
  const rect = canvas.getBoundingClientRect();
140839
140871
  const pixelRatio = window.devicePixelRatio || 1;
140840
- // Set canvas internal resolution to match display size * pixel ratio
140841
140872
  const width = Math.floor(rect.width * pixelRatio);
140842
140873
  const height = Math.floor(rect.height * pixelRatio);
140843
- if (canvas.width !== width || canvas.height !== height) {
140844
- canvas.width = width;
140845
- canvas.height = height;
140846
- // Update PlayCanvas app resolution
140847
- this.app.resizeCanvas(width, height);
140848
- // Notify navigation cube about canvas resize
140849
- if (this._orbit &&
140850
- this._orbit.navigationCube &&
140851
- typeof this._orbit.navigationCube.onCanvasResize ===
140852
- 'function') {
140853
- this._orbit.navigationCube.onCanvasResize();
140874
+ // debug removed
140875
+ applyResolution(width, height);
140876
+ };
140877
+ // Prefer ResizeObserver entry data (devicePixelContentBoxSize when available)
140878
+ const updateFromEntry = (entry) => {
140879
+ let width = null;
140880
+ let height = null;
140881
+ const dpcb = entry.devicePixelContentBoxSize;
140882
+ if (dpcb && dpcb.length > 0) {
140883
+ width = Math.ceil(dpcb[0].inlineSize);
140884
+ height = Math.ceil(dpcb[0].blockSize);
140885
+ // debug removed
140886
+ }
140887
+ else {
140888
+ const cbs = entry.contentBoxSize;
140889
+ if (cbs && cbs.length > 0) {
140890
+ const pixelRatio = window.devicePixelRatio || 1;
140891
+ width = Math.ceil(cbs[0].inlineSize * pixelRatio);
140892
+ height = Math.ceil(cbs[0].blockSize * pixelRatio);
140893
+ // debug removed
140854
140894
  }
140855
140895
  }
140896
+ if (width !== null && height !== null) {
140897
+ applyResolution(width, height);
140898
+ }
140899
+ else {
140900
+ updateResolution();
140901
+ }
140856
140902
  };
140857
140903
  // Initial resolution setup
140858
140904
  updateResolution();
140905
+ // debug removed
140859
140906
  // Set up resize observer for automatic resolution updates
140860
140907
  if (window.ResizeObserver) {
140861
- this._resizeObserver = new ResizeObserver(() => {
140862
- updateResolution();
140908
+ this._resizeObserver = new ResizeObserver((entries) => {
140909
+ if (!entries || entries.length === 0) {
140910
+ updateResolution();
140911
+ return;
140912
+ }
140913
+ const canvasEntry = entries.find(e => e.target === canvas);
140914
+ if (canvasEntry) {
140915
+ updateFromEntry(canvasEntry);
140916
+ }
140917
+ else {
140918
+ // Fall back to the first entry if canvas wasn't explicitly included
140919
+ if (entries.length > 0) {
140920
+ const firstEntry = entries[0];
140921
+ if (firstEntry) {
140922
+ updateFromEntry(firstEntry);
140923
+ }
140924
+ else {
140925
+ updateResolution();
140926
+ }
140927
+ }
140928
+ else {
140929
+ updateResolution();
140930
+ }
140931
+ }
140863
140932
  });
140864
140933
  // Observe both the canvas and its parent container for resize events
140865
- this._resizeObserver.observe(canvas);
140934
+ try {
140935
+ // Prefer device-pixel-content-box for pixel-perfect canvas sizing
140936
+ ;
140937
+ this._resizeObserver.observe(canvas, {
140938
+ box: 'device-pixel-content-box',
140939
+ });
140940
+ }
140941
+ catch {
140942
+ this._resizeObserver.observe(canvas);
140943
+ }
140944
+ // debug removed
140866
140945
  if (canvas.parentElement) {
140867
140946
  this._resizeObserver.observe(canvas.parentElement);
140947
+ // debug removed
140868
140948
  }
140869
140949
  }
140870
- else {
140871
- // Fallback for browsers without ResizeObserver
140872
- window.addEventListener('resize', updateResolution);
140873
- this._resizeHandler = updateResolution;
140950
+ // Additionally listen to window resize to handle viewport changes
140951
+ // (e.g., when resizing dev tools). This mirrors superSplat behavior
140952
+ // and ensures the canvas always matches the available space.
140953
+ const onWindowResize = () => {
140954
+ updateResolution();
140955
+ };
140956
+ window.addEventListener('resize', onWindowResize);
140957
+ this._resizeHandler = onWindowResize;
140958
+ }
140959
+ /**
140960
+ * Force recalculation of canvas resolution based on current DOM size.
140961
+ * Useful when container layout changes are not captured by the observer.
140962
+ */
140963
+ updateCanvasResolution() {
140964
+ if (!this.app)
140965
+ return;
140966
+ const canvas = this.app.graphicsDevice.canvas;
140967
+ const rect = canvas.getBoundingClientRect();
140968
+ const pixelRatio = window.devicePixelRatio || 1;
140969
+ const width = Math.floor(rect.width * pixelRatio);
140970
+ const height = Math.floor(rect.height * pixelRatio);
140971
+ if (canvas.width !== width || canvas.height !== height) {
140972
+ canvas.width = width;
140973
+ canvas.height = height;
140974
+ this.app.resizeCanvas(width, height);
140975
+ if (this._orbit &&
140976
+ this._orbit.navigationCube &&
140977
+ typeof this._orbit.navigationCube.onCanvasResize === 'function') {
140978
+ this._orbit.navigationCube.onCanvasResize();
140979
+ }
140874
140980
  }
140875
140981
  }
140876
140982
  }
@@ -140902,6 +141008,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
140902
141008
  this._config = { ...DEFAULT_CONFIG };
140903
141009
  this._isInitialized = false;
140904
141010
  this._isDestroyed = false;
141011
+ this._hostResizeObserver = null;
140905
141012
  }
140906
141013
  // Observed attributes that trigger attributeChangedCallback
140907
141014
  static get observedAttributes() {
@@ -141249,6 +141356,22 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
141249
141356
  this._canvas.setAttribute('role', 'img');
141250
141357
  this._canvas.setAttribute('aria-label', '3D Splat Viewer');
141251
141358
  this.appendChild(this._canvas);
141359
+ // Observe host element for size changes and force canvas resolution update
141360
+ try {
141361
+ if (window.ResizeObserver) {
141362
+ this._hostResizeObserver = new ResizeObserver(() => {
141363
+ // Force resolution update in core to sync canvas with host/container
141364
+ try {
141365
+ this._core?.updateCanvasResolution();
141366
+ }
141367
+ catch { }
141368
+ });
141369
+ this._hostResizeObserver.observe(this);
141370
+ if (this.parentElement)
141371
+ this._hostResizeObserver.observe(this.parentElement);
141372
+ }
141373
+ }
141374
+ catch { }
141252
141375
  // Update configuration from attributes
141253
141376
  this._updateConfigFromAttributes();
141254
141377
  // Initialize the core viewer
@@ -141305,6 +141428,11 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
141305
141428
  return;
141306
141429
  }
141307
141430
  try {
141431
+ // Disconnect host resize observer
141432
+ if (this._hostResizeObserver) {
141433
+ this._hostResizeObserver.disconnect();
141434
+ this._hostResizeObserver = null;
141435
+ }
141308
141436
  // Clean up core
141309
141437
  if (this._core) {
141310
141438
  this._core.destroy();
@@ -141424,7 +141552,6 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
141424
141552
  return;
141425
141553
  }
141426
141554
  // Stats handling will be implemented when we add stats functionality
141427
- console.log('Stats change requested:', this.enableStats);
141428
141555
  }
141429
141556
  /**
141430
141557
  * Set up event listeners for the core viewer