@luma.gl/core 9.3.4 → 9.3.5

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 CHANGED
@@ -1692,7 +1692,7 @@ var _Luma = class {
1692
1692
  VERSION = (
1693
1693
  // Version detection using build plugin
1694
1694
  // @ts-expect-error no-undef
1695
- true ? "9.3.4" : "running from source"
1695
+ true ? "9.3.5" : "running from source"
1696
1696
  );
1697
1697
  spector;
1698
1698
  preregisteredAdapters = /* @__PURE__ */ new Map();
@@ -1862,6 +1862,7 @@ var import_env2 = require("@probe.gl/env");
1862
1862
 
1863
1863
  // dist/adapter/canvas-observer.js
1864
1864
  var CanvasObserver = class {
1865
+ /** Observer options and event callbacks. */
1865
1866
  props;
1866
1867
  _resizeObserver;
1867
1868
  _intersectionObserver;
@@ -1870,12 +1871,19 @@ var CanvasObserver = class {
1870
1871
  _handleDevicePixelRatioChange = () => this._refreshDevicePixelRatio();
1871
1872
  _trackPositionInterval = null;
1872
1873
  _started = false;
1874
+ /** Whether the DOM observers and polling loops have been started. */
1873
1875
  get started() {
1874
1876
  return this._started;
1875
1877
  }
1878
+ /**
1879
+ * Creates an observer coordinator for one HTML canvas.
1880
+ *
1881
+ * @param props - Observer options and event callbacks.
1882
+ */
1876
1883
  constructor(props) {
1877
1884
  this.props = props;
1878
1885
  }
1886
+ /** Starts DOM observation and optional position polling. */
1879
1887
  start() {
1880
1888
  if (this._started || !this.props.canvas) {
1881
1889
  return;
@@ -1884,8 +1892,9 @@ var CanvasObserver = class {
1884
1892
  this._intersectionObserver ||= new IntersectionObserver((entries) => this.props.onIntersection(entries));
1885
1893
  this._resizeObserver ||= new ResizeObserver((entries) => this.props.onResize(entries));
1886
1894
  this._intersectionObserver.observe(this.props.canvas);
1895
+ const box = this.props.resizeObserverBox;
1887
1896
  try {
1888
- this._resizeObserver.observe(this.props.canvas, { box: "device-pixel-content-box" });
1897
+ this._resizeObserver.observe(this.props.canvas, { box });
1889
1898
  } catch {
1890
1899
  this._resizeObserver.observe(this.props.canvas, { box: "content-box" });
1891
1900
  }
@@ -1894,6 +1903,7 @@ var CanvasObserver = class {
1894
1903
  this._trackPosition();
1895
1904
  }
1896
1905
  }
1906
+ /** Stops DOM observation, media-query listeners, and position polling. */
1897
1907
  stop() {
1898
1908
  var _a, _b;
1899
1909
  if (!this._started) {
@@ -1915,6 +1925,7 @@ var CanvasObserver = class {
1915
1925
  (_a = this._resizeObserver) == null ? void 0 : _a.disconnect();
1916
1926
  (_b = this._intersectionObserver) == null ? void 0 : _b.disconnect();
1917
1927
  }
1928
+ /** Reports the current device pixel ratio and arms the media query for its next change. */
1918
1929
  _refreshDevicePixelRatio() {
1919
1930
  var _a;
1920
1931
  if (!this._started) {
@@ -1925,6 +1936,11 @@ var CanvasObserver = class {
1925
1936
  this._observeDevicePixelRatioMediaQuery = matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
1926
1937
  this._observeDevicePixelRatioMediaQuery.addEventListener("change", this._handleDevicePixelRatioChange, { once: true });
1927
1938
  }
1939
+ /**
1940
+ * Starts periodic position callbacks while the observer remains active.
1941
+ *
1942
+ * @param intervalMs - Poll interval in milliseconds.
1943
+ */
1928
1944
  _trackPosition(intervalMs = 100) {
1929
1945
  if (this._trackPositionInterval) {
1930
1946
  return;
@@ -2051,6 +2067,7 @@ var _CanvasSurface = class {
2051
2067
  this._canvasObserver = new CanvasObserver({
2052
2068
  canvas: this.htmlCanvas,
2053
2069
  trackPosition: this.props.trackPosition,
2070
+ resizeObserverBox: this.props.pixelSizeSource === "css-dpr" ? "content-box" : "device-pixel-content-box",
2054
2071
  onResize: (entries) => this._handleResize(entries),
2055
2072
  onIntersection: (entries) => this._handleIntersection(entries),
2056
2073
  onDevicePixelRatioChange: () => this._observeDevicePixelRatio(),
@@ -2192,10 +2209,7 @@ var _CanvasSurface = class {
2192
2209
  this.cssWidth = contentBoxSize.inlineSize;
2193
2210
  this.cssHeight = contentBoxSize.blockSize;
2194
2211
  const oldPixelSize = this.getDevicePixelSize();
2195
- const { devicePixelWidth, devicePixelHeight } = this._getDevicePixelSizeFromResizeEntry(entry);
2196
- const [maxDevicePixelWidth, maxDevicePixelHeight] = this.getMaxDrawingBufferSize();
2197
- this.devicePixelWidth = Math.max(1, Math.min(devicePixelWidth, maxDevicePixelWidth));
2198
- this.devicePixelHeight = Math.max(1, Math.min(devicePixelHeight, maxDevicePixelHeight));
2212
+ this._setDevicePixelSize(this._getDevicePixelSizeFromResizeEntry(entry));
2199
2213
  this._updateDrawingBufferSize();
2200
2214
  this.device.props.onResize(this, { oldPixelSize });
2201
2215
  }
@@ -2218,17 +2232,25 @@ var _CanvasSurface = class {
2218
2232
  var _a, _b, _c, _d, _e;
2219
2233
  const contentBoxSize = assertDefined((_a = entry.contentBoxSize) == null ? void 0 : _a[0]);
2220
2234
  if (this.props.pixelSizeSource === "css-dpr") {
2221
- const devicePixelRatio2 = this.getDevicePixelRatio();
2222
- return {
2223
- devicePixelWidth: Math.round(contentBoxSize.inlineSize * devicePixelRatio2),
2224
- devicePixelHeight: Math.round(contentBoxSize.blockSize * devicePixelRatio2)
2225
- };
2235
+ return this._getDevicePixelSizeFromCSSSize(contentBoxSize.inlineSize, contentBoxSize.blockSize);
2226
2236
  }
2227
2237
  return {
2228
2238
  devicePixelWidth: ((_c = (_b = entry.devicePixelContentBoxSize) == null ? void 0 : _b[0]) == null ? void 0 : _c.inlineSize) || contentBoxSize.inlineSize * devicePixelRatio,
2229
2239
  devicePixelHeight: ((_e = (_d = entry.devicePixelContentBoxSize) == null ? void 0 : _d[0]) == null ? void 0 : _e.blockSize) || contentBoxSize.blockSize * devicePixelRatio
2230
2240
  };
2231
2241
  }
2242
+ _getDevicePixelSizeFromCSSSize(cssWidth, cssHeight) {
2243
+ const devicePixelRatio2 = this.getDevicePixelRatio();
2244
+ return {
2245
+ devicePixelWidth: Math.floor(cssWidth * devicePixelRatio2),
2246
+ devicePixelHeight: Math.floor(cssHeight * devicePixelRatio2)
2247
+ };
2248
+ }
2249
+ _setDevicePixelSize({ devicePixelWidth, devicePixelHeight }) {
2250
+ const [maxDevicePixelWidth, maxDevicePixelHeight] = this.getMaxDrawingBufferSize();
2251
+ this.devicePixelWidth = Math.max(1, Math.min(devicePixelWidth, maxDevicePixelWidth));
2252
+ this.devicePixelHeight = Math.max(1, Math.min(devicePixelHeight, maxDevicePixelHeight));
2253
+ }
2232
2254
  _resizeDrawingBufferIfNeeded() {
2233
2255
  if (this._needsDrawingBufferResize) {
2234
2256
  this._needsDrawingBufferResize = false;
@@ -2247,6 +2269,12 @@ var _CanvasSurface = class {
2247
2269
  }
2248
2270
  const oldRatio = this.devicePixelRatio;
2249
2271
  this.devicePixelRatio = window.devicePixelRatio;
2272
+ if (this.props.pixelSizeSource === "css-dpr") {
2273
+ const oldPixelSize = this.getDevicePixelSize();
2274
+ this._setDevicePixelSize(this._getDevicePixelSizeFromCSSSize(this.cssWidth, this.cssHeight));
2275
+ this._updateDrawingBufferSize();
2276
+ this.device.props.onResize(this, { oldPixelSize });
2277
+ }
2250
2278
  this.updatePosition();
2251
2279
  (_b = (_a = this.device.props).onDevicePixelRatioChange) == null ? void 0 : _b.call(_a, this, {
2252
2280
  oldRatio