@luma.gl/core 9.3.3 → 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/adapter/canvas-observer.d.ts +25 -0
- package/dist/adapter/canvas-observer.d.ts.map +1 -1
- package/dist/adapter/canvas-observer.js +18 -1
- package/dist/adapter/canvas-observer.js.map +1 -1
- package/dist/adapter/canvas-surface.d.ts +17 -0
- package/dist/adapter/canvas-surface.d.ts.map +1 -1
- package/dist/adapter/canvas-surface.js +35 -7
- package/dist/adapter/canvas-surface.js.map +1 -1
- package/dist/adapter/luma.js +1 -1
- package/dist/dist.dev.js +51 -6
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +51 -8
- package/dist/index.cjs.map +2 -2
- package/package.json +2 -2
- package/src/adapter/canvas-observer.ts +27 -1
- package/src/adapter/canvas-surface.ts +61 -11
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.
|
|
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
|
|
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(),
|
|
@@ -2180,7 +2197,7 @@ var _CanvasSurface = class {
|
|
|
2180
2197
|
}
|
|
2181
2198
|
}
|
|
2182
2199
|
_handleResize(entries) {
|
|
2183
|
-
var _a
|
|
2200
|
+
var _a;
|
|
2184
2201
|
if (this.destroyed) {
|
|
2185
2202
|
return;
|
|
2186
2203
|
}
|
|
@@ -2192,11 +2209,7 @@ var _CanvasSurface = class {
|
|
|
2192
2209
|
this.cssWidth = contentBoxSize.inlineSize;
|
|
2193
2210
|
this.cssHeight = contentBoxSize.blockSize;
|
|
2194
2211
|
const oldPixelSize = this.getDevicePixelSize();
|
|
2195
|
-
|
|
2196
|
-
const devicePixelHeight = ((_e = (_d = entry.devicePixelContentBoxSize) == null ? void 0 : _d[0]) == null ? void 0 : _e.blockSize) || contentBoxSize.blockSize * devicePixelRatio;
|
|
2197
|
-
const [maxDevicePixelWidth, maxDevicePixelHeight] = this.getMaxDrawingBufferSize();
|
|
2198
|
-
this.devicePixelWidth = Math.max(1, Math.min(devicePixelWidth, maxDevicePixelWidth));
|
|
2199
|
-
this.devicePixelHeight = Math.max(1, Math.min(devicePixelHeight, maxDevicePixelHeight));
|
|
2212
|
+
this._setDevicePixelSize(this._getDevicePixelSizeFromResizeEntry(entry));
|
|
2200
2213
|
this._updateDrawingBufferSize();
|
|
2201
2214
|
this.device.props.onResize(this, { oldPixelSize });
|
|
2202
2215
|
}
|
|
@@ -2215,6 +2228,29 @@ var _CanvasSurface = class {
|
|
|
2215
2228
|
this.isInitialized = true;
|
|
2216
2229
|
this.updatePosition();
|
|
2217
2230
|
}
|
|
2231
|
+
_getDevicePixelSizeFromResizeEntry(entry) {
|
|
2232
|
+
var _a, _b, _c, _d, _e;
|
|
2233
|
+
const contentBoxSize = assertDefined((_a = entry.contentBoxSize) == null ? void 0 : _a[0]);
|
|
2234
|
+
if (this.props.pixelSizeSource === "css-dpr") {
|
|
2235
|
+
return this._getDevicePixelSizeFromCSSSize(contentBoxSize.inlineSize, contentBoxSize.blockSize);
|
|
2236
|
+
}
|
|
2237
|
+
return {
|
|
2238
|
+
devicePixelWidth: ((_c = (_b = entry.devicePixelContentBoxSize) == null ? void 0 : _b[0]) == null ? void 0 : _c.inlineSize) || contentBoxSize.inlineSize * devicePixelRatio,
|
|
2239
|
+
devicePixelHeight: ((_e = (_d = entry.devicePixelContentBoxSize) == null ? void 0 : _d[0]) == null ? void 0 : _e.blockSize) || contentBoxSize.blockSize * devicePixelRatio
|
|
2240
|
+
};
|
|
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
|
+
}
|
|
2218
2254
|
_resizeDrawingBufferIfNeeded() {
|
|
2219
2255
|
if (this._needsDrawingBufferResize) {
|
|
2220
2256
|
this._needsDrawingBufferResize = false;
|
|
@@ -2233,6 +2269,12 @@ var _CanvasSurface = class {
|
|
|
2233
2269
|
}
|
|
2234
2270
|
const oldRatio = this.devicePixelRatio;
|
|
2235
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
|
+
}
|
|
2236
2278
|
this.updatePosition();
|
|
2237
2279
|
(_b = (_a = this.device.props).onDevicePixelRatioChange) == null ? void 0 : _b.call(_a, this, {
|
|
2238
2280
|
oldRatio
|
|
@@ -2265,6 +2307,7 @@ __publicField(CanvasSurface, "defaultProps", {
|
|
|
2265
2307
|
width: 800,
|
|
2266
2308
|
height: 600,
|
|
2267
2309
|
useDevicePixels: true,
|
|
2310
|
+
pixelSizeSource: "exact",
|
|
2268
2311
|
autoResize: true,
|
|
2269
2312
|
container: null,
|
|
2270
2313
|
visible: true,
|