Reach the canvas through canvasOf, not the viewer

Every file that read the renderer's canvas as rendererOf(viewer)?.canvas
falling back to viewer.canvas, and the share restoration's gesture
listeners on viewer.canvas, now ask canvasOf(viewer). The 20 canvas
reach-throughs leave the viewer access record.
This commit is contained in:
Sameh Khamis committed 2026-11-10 17:18:10 -08:00
1 parent 73735b080a
commit ebbe006924
13 files changed
+30 -43

No files matched your search

+6 -2
View File
@@ -62,7 +62,11 @@ import {
import { onLocaleChange, t, translateKnown } from '../i18n/index.js';
import { fromDegrees } from '../geo/index.js';
import { cssColor } from '../render/color.js';
import { drawOf, findFrame, rendererOf } from '../render/rendererOf.js';
import {
canvasOf as sceneCanvasOf,
drawOf,
findFrame,
} from '../render/rendererOf.js';
/** The longest note a row action leaves under its row, in characters. */
const NOTE_MAX = 200;
/** An action's answer as a row note: trimmed, and cut at a word with an ellipsis. */
@@ -157,7 +161,7 @@ export function initDrawTool({
previewPoints.dispose();
};
/** The canvas the renderer draws in (the viewer's own when none is bound). */
const canvasOf = () => rendererOf(viewer)?.canvas ?? viewer.canvas;
const canvasOf = () => sceneCanvasOf(viewer);
const requestRender = () => findFrame(viewer)?.requestRender('draw-preview');
// Teardown finishes synchronously; `whenSettled()` keeps its promise.
const attaching = Promise.resolve();
+2 -2
View File
@@ -46,7 +46,7 @@ import { unavailablePlaceSearch } from '../search/placeSearch.js';
import { isPickedWorldPosition } from '../data/scenePick.js';
import { heightsOf } from '../queries/heights.js';
import { fromDegrees, toLonLatH } from '../geo/ellipsoid.js';
import { findCamera, findQuery, rendererOf } from '../render/rendererOf.js';
import { canvasOf, findCamera, findQuery } from '../render/rendererOf.js';
/** Prepare only local dateline outlines for planar admission and centering. */
function localOutlineFrame(fp) {
@@ -2292,7 +2292,7 @@ export function createAnnotationResolver({
function pickWorldFromScreen(viewer, nx, ny) {
const query = viewer ? findQuery(viewer) : null;
// The renderer's canvas; a viewer with no renderer bound, its own.
const canvas = rendererOf(viewer)?.canvas ?? viewer?.canvas;
const canvas = canvasOf(viewer);
if (!query || !canvas) return null;
const w = canvas.clientWidth || canvas.width || 0;
const h = canvas.clientHeight || canvas.height || 0;
+2 -2
View File
@@ -12,10 +12,10 @@ import { heightsOf } from '../queries/heights.js';
import { fromDegrees, toLonLatH } from '../geo/ellipsoid.js';
import { distance } from '../geo/vector.js';
import {
canvasOf as sceneCanvasOf,
findCamera,
findFrame,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
/** A label whose detailed outline could not be resolved. */
@@ -93,7 +93,7 @@ export function createScreenAnnotationRenderer(
let passQuery = null;
let passCanvas = null;
// The renderer's canvas; a viewer with no renderer bound, its own.
const canvasOf = () => rendererOf(viewer)?.canvas ?? viewer.canvas;
const canvasOf = () => sceneCanvasOf(viewer);
const records = new Map(); // anno.id -> { key, anno, group, parts }
const leaving = new Map(); // key -> a removed mark's record while it fades out
const byKey = new Map(); // key -> record, live or fading
+1 -4
View File
@@ -71,9 +71,9 @@ import { eyeMoved, eyeRotatedAbout, eyeTurned } from './geo/eyeMoves.js';
import { heightsOf } from './queries/heights.js';
import {
cameraOf,
canvasOf,
findCamera,
findFrame,
rendererOf,
} from './render/rendererOf.js';
let _isCockpitActive = null;
@@ -1613,9 +1613,6 @@ function liveView(camera, pose = camera.pose()) {
return { ...pose, projection, live: true };
}
/** The canvas the renderer draws in (the viewer's own when none is bound). */
const canvasOf = (viewer) => rendererOf(viewer)?.canvas ?? viewer.canvas;
/**
* Whether a projection is a perspective one centred on the view: what the
* keyhole cone below assumes. Column-major, so element 11 is row 3 of
+2 -2
View File
@@ -1,10 +1,10 @@
import { governorRequestRender } from './renderGovernor.js';
import {
cameraOf,
canvasOf,
findCamera,
findFrame,
findQuery,
rendererOf,
} from './render/rendererOf.js';
import {
moonPositionInertial,
@@ -585,7 +585,7 @@ export class CelestialRing {
/** The renderer's canvas; a viewer with no renderer bound, its own. */
_canvas() {
return rendererOf(this.viewer)?.canvas ?? this.viewer.canvas;
return canvasOf(this.viewer);
}
/** Whether the current camera already frames the complete globe inside the keyhole. */
+2 -2
View File
@@ -1,8 +1,8 @@
import {
canvasOf,
findCamera,
findFrame,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
import { dot, sub } from '../geo/vector.js';
import { t, msg, onLocaleChange } from '../i18n/index.js';
@@ -558,7 +558,7 @@ function anchorOnScreen(viewer, anchor, root) {
const pixel = query.project(anchor);
if (!pixel) return null;
// The renderer's canvas; a viewer with no renderer bound, its own.
const canvas = rendererOf(viewer)?.canvas ?? viewer.canvas;
const canvas = canvasOf(viewer);
const canvasBounds = canvas?.getBoundingClientRect?.();
const rootBounds = root.getBoundingClientRect?.();
if (!canvasBounds || !rootBounds) return null;
+2 -2
View File
@@ -1,4 +1,4 @@
import { findCamera, rendererOf } from '../../render/rendererOf.js';
import { canvasOf, findCamera } from '../../render/rendererOf.js';
import { renderedFrames } from '../../data/renderedFrames.js';
import {
fromDegrees,
@@ -130,7 +130,7 @@ export function createMotion({
* renderer is bound), or 0 without either. */
function _viewportHeightPx() {
const viewer = flightState._viewer;
const canvas = rendererOf(viewer)?.canvas ?? viewer?.canvas;
const canvas = canvasOf(viewer);
return Number(canvas?.clientHeight) || 0;
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { findCamera, rendererOf } from '../../render/rendererOf.js';
import { canvasOf, findCamera } from '../../render/rendererOf.js';
import { renderedFrames } from '../../data/renderedFrames.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { eastNorthUp, framePoint } from '../../geo/frames.js';
@@ -89,7 +89,7 @@ export function createMotion({
* renderer is bound), or 0 without either. */
function _viewportHeightPx() {
const viewer = flightState._viewer;
const canvas = rendererOf(viewer)?.canvas ?? viewer?.canvas;
const canvas = canvasOf(viewer);
return Number(canvas?.clientHeight) || 0;
}
+2 -2
View File
@@ -8,10 +8,10 @@ import {
import { horizonFrom } from '../../geo/horizon.js';
import { distance } from '../../geo/vector.js';
import {
canvasOf,
findCamera,
findFrame,
findQuery,
rendererOf,
} from '../../render/rendererOf.js';
/** Equirectangular metres between {lon, lat} points, the short way round ±180°; street scale. */
@@ -77,7 +77,7 @@ function raisedEllipsoid(height) {
/** The CSS size of the canvas the viewer draws on; zeros without one. */
export function canvasSize(viewer) {
const canvas = rendererOf(viewer)?.canvas ?? viewer?.canvas;
const canvas = canvasOf(viewer);
return {
width: canvas?.clientWidth || canvas?.width || 0,
height: canvas?.clientHeight || canvas?.height || 0,
+2 -2
View File
@@ -25,10 +25,10 @@ import {
import { WORLD_OVERLAY_STYLE } from './worldOverlayTokens.js';
import { t } from '../i18n/index.js';
import {
canvasOf,
findCamera,
findFrame,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
/**
@@ -1308,7 +1308,7 @@ function sizeCanvasSurface(canvas, ctx, width, height, dpr) {
*/
function ensureCanvasSize() {
// The renderer's canvas; a viewer with no renderer bound, its own.
const sceneCanvas = rendererOf(_viewer)?.canvas ?? _viewer?.canvas;
const sceneCanvas = canvasOf(_viewer);
if (!_canvas || !sceneCanvas) return false;
const width = Math.max(0, Math.round(Number(sceneCanvas.clientWidth) || 0));
const height = Math.max(0, Math.round(Number(sceneCanvas.clientHeight) || 0));
+1 -13
View File
@@ -1,19 +1,7 @@
{
"src/agent/worldPacket.js": 2,
"src/annotations/drawTool.js": 1,
"src/annotations/resolver.js": 1,
"src/annotations/screenAnnotationRenderer.js": 1,
"src/cameraVerbs.js": 1,
"src/celestialRing.js": 1,
"src/data/bhoteKoshiEmbeddedMedia.js": 1,
"src/data/followed.js": 5,
"src/layers/flights/motion.js": 1,
"src/layers/military/motion.js": 1,
"src/layers/streetLevel/view.js": 1,
"src/layers/vessels/lifecycle.js": 1,
"src/layers/weather/imageryHost.js": 3,
"src/maps/imageryHost.js": 4,
"src/overlays/worldOverlay.js": 1,
"src/ui/shareRestoration.js": 4,
"src/voice/gevActions.js": 1
"src/maps/imageryHost.js": 4
}
+5 -4
View File
@@ -5,6 +5,7 @@ import { t, msg, formatDate } from '../i18n/index.js';
import { SHARE_VIEW_ENTITY_KINDS } from '../share/follow.js';
import { UiLifetime } from './uiLifetime.js';
import { followedOf } from '../data/followed.js';
import { canvasOf } from '../render/rendererOf.js';
import { isWorldTime, worldClock } from '../time/worldClock.js';
// A link made away from live opens at its world time, paused. One without a
@@ -206,14 +207,14 @@ export class ShareRestoration {
this.navigation._stampNavigation(options),
);
};
this.viewer?.canvas?.addEventListener(
canvasOf(this.viewer)?.addEventListener(
'pointerdown',
this._initialShareGestureHandler,
{
passive: true,
},
);
this.viewer?.canvas?.addEventListener(
canvasOf(this.viewer)?.addEventListener(
'wheel',
this._initialShareGestureHandler,
{
@@ -595,11 +596,11 @@ export class ShareRestoration {
share: null,
layers: [],
});
this.viewer?.canvas?.removeEventListener(
canvasOf(this.viewer)?.removeEventListener(
'pointerdown',
this._initialShareGestureHandler,
);
this.viewer?.canvas?.removeEventListener(
canvasOf(this.viewer)?.removeEventListener(
'wheel',
this._initialShareGestureHandler,
);
+1 -4
View File
@@ -24,9 +24,9 @@ import { sphereFromPoints } from '../geo/sphere.js';
import { eyeZoomed } from '../geo/eyeMoves.js';
import {
cameraOf,
canvasOf,
findCamera,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
import { CITY_POIS } from '../cityPois.js';
import { greatCircleKm } from '../geoDistance.js';
@@ -4448,9 +4448,6 @@ function selectedEntityContext(dataManager) {
return summarizeContextRecord(record, { includeProperties: true });
}
/** The canvas the renderer draws in (the viewer's own when none is bound). */
const canvasOf = (viewer) => rendererOf(viewer)?.canvas ?? viewer.canvas;
function visibleEntityContexts(
viewer,
dataManager,