mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 18:34:02 +00:00
style: format remaining owned runtime modules
This commit is contained in:
1 parent
ae99843c14
commit
2aca7aecbb
94 files changed
+8865
-3151
No files matched your search
+65
-22
@@ -133,9 +133,13 @@ export function scopeTerminusAlpha(heightM) {
|
||||
if (h >= SCOPE_TERMINUS_FAR_M) return SCOPE_OUTSIDE_ALPHA;
|
||||
if (h <= SCOPE_TERMINUS_NEAR_M) return SCOPE_TERMINUS_ALPHA_NEAR;
|
||||
// 0 at the far edge → 1 at the near edge, eased so neither end steps visibly.
|
||||
const t = (SCOPE_TERMINUS_FAR_M - h) / (SCOPE_TERMINUS_FAR_M - SCOPE_TERMINUS_NEAR_M);
|
||||
const t =
|
||||
(SCOPE_TERMINUS_FAR_M - h) / (SCOPE_TERMINUS_FAR_M - SCOPE_TERMINUS_NEAR_M);
|
||||
const eased = t * t * (3 - 2 * t);
|
||||
return SCOPE_OUTSIDE_ALPHA + (SCOPE_TERMINUS_ALPHA_NEAR - SCOPE_OUTSIDE_ALPHA) * eased;
|
||||
return (
|
||||
SCOPE_OUTSIDE_ALPHA +
|
||||
(SCOPE_TERMINUS_ALPHA_NEAR - SCOPE_OUTSIDE_ALPHA) * eased
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +153,11 @@ export function quantizeScopeTerminusAlpha(alpha) {
|
||||
// Round the PRODUCT too: n * 0.005 lands on values like 0.9400000000000001,
|
||||
// which would ride straight into the rgba() string. The quantum is 3-decimal,
|
||||
// so 3 decimals is lossless here.
|
||||
return Math.round(Math.round(a / SCOPE_TERMINUS_QUANTUM) * SCOPE_TERMINUS_QUANTUM * 1000) / 1000;
|
||||
return (
|
||||
Math.round(
|
||||
Math.round(a / SCOPE_TERMINUS_QUANTUM) * SCOPE_TERMINUS_QUANTUM * 1000,
|
||||
) / 1000
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,10 +172,14 @@ export function clampScopeTerminusPct(value) {
|
||||
// boolean — is ABSENT, not zero. (Number(null) === 0 would otherwise pin the
|
||||
// floor on every adaptive write.)
|
||||
const raw = typeof value === 'string' ? value.trim() : value;
|
||||
if (typeof raw !== 'number' && (typeof raw !== 'string' || raw === '')) return null;
|
||||
if (typeof raw !== 'number' && (typeof raw !== 'string' || raw === ''))
|
||||
return null;
|
||||
const pct = Number(raw);
|
||||
if (!Number.isFinite(pct)) return null;
|
||||
return Math.max(SCOPE_TERMINUS_MIN_PCT, Math.min(SCOPE_TERMINUS_MAX_PCT, Math.round(pct)));
|
||||
return Math.max(
|
||||
SCOPE_TERMINUS_MIN_PCT,
|
||||
Math.min(SCOPE_TERMINUS_MAX_PCT, Math.round(pct)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +213,10 @@ export function updateScopeTerminusForHeight(heightM) {
|
||||
* @returns {void}
|
||||
*/
|
||||
function withCoalescedPaint(fn) {
|
||||
if (_coalescingPaint) { fn(); return; } // already inside a scope
|
||||
if (_coalescingPaint) {
|
||||
fn();
|
||||
return;
|
||||
} // already inside a scope
|
||||
_coalescingPaint = true;
|
||||
_paintDirty = false;
|
||||
try {
|
||||
@@ -218,7 +233,9 @@ function withCoalescedPaint(fn) {
|
||||
/** @returns {number} Quantized terminus the CURRENT camera + override imply. */
|
||||
function currentTerminusTarget() {
|
||||
return quantizeScopeTerminusAlpha(
|
||||
_terminusOverride == null ? scopeTerminusAlpha(currentCameraHeightM()) : _terminusOverride,
|
||||
_terminusOverride == null
|
||||
? scopeTerminusAlpha(currentCameraHeightM())
|
||||
: _terminusOverride,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -228,7 +245,10 @@ export function setScopeTerminusOverride(alpha) {
|
||||
} else {
|
||||
// Same supported band as the `sce` hash key: a sub-globe-scale terminus is
|
||||
// a hole in the mask, not a scope, so every entry point floors it.
|
||||
_terminusOverride = Math.max(SCOPE_OUTSIDE_ALPHA, Math.min(1, Number(alpha)));
|
||||
_terminusOverride = Math.max(
|
||||
SCOPE_OUTSIDE_ALPHA,
|
||||
Math.min(1, Number(alpha)),
|
||||
);
|
||||
}
|
||||
// Re-resolve immediately against the live camera so the override is visible
|
||||
// without waiting for the next sample.
|
||||
@@ -256,7 +276,9 @@ export function getScopeTerminusRepaintCount() {
|
||||
}
|
||||
|
||||
/** Backing-store scale actually used by the last draw(). */
|
||||
export function scopeMaskDevicePixelRatio(ratio = (typeof window !== 'undefined' ? window.devicePixelRatio : 1)) {
|
||||
export function scopeMaskDevicePixelRatio(
|
||||
ratio = typeof window !== 'undefined' ? window.devicePixelRatio : 1,
|
||||
) {
|
||||
return Math.min(2, Number(ratio) || 1);
|
||||
}
|
||||
|
||||
@@ -272,7 +294,8 @@ export function scopeMaskDevicePixelRatio(ratio = (typeof window !== 'undefined'
|
||||
* @returns {void}
|
||||
*/
|
||||
function watchDevicePixelRatio() {
|
||||
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
|
||||
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
||||
return;
|
||||
teardownDevicePixelRatioWatch();
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
let query;
|
||||
@@ -292,14 +315,18 @@ function watchDevicePixelRatio() {
|
||||
draw();
|
||||
});
|
||||
};
|
||||
if (typeof query.addEventListener === 'function') query.addEventListener('change', _dprListener, { once: true });
|
||||
else if (typeof query.addListener === 'function') query.addListener(_dprListener);
|
||||
if (typeof query.addEventListener === 'function')
|
||||
query.addEventListener('change', _dprListener, { once: true });
|
||||
else if (typeof query.addListener === 'function')
|
||||
query.addListener(_dprListener);
|
||||
}
|
||||
|
||||
function teardownDevicePixelRatioWatch() {
|
||||
if (_dprQuery && _dprListener) {
|
||||
if (typeof _dprQuery.removeEventListener === 'function') _dprQuery.removeEventListener('change', _dprListener);
|
||||
else if (typeof _dprQuery.removeListener === 'function') _dprQuery.removeListener(_dprListener);
|
||||
if (typeof _dprQuery.removeEventListener === 'function')
|
||||
_dprQuery.removeEventListener('change', _dprListener);
|
||||
else if (typeof _dprQuery.removeListener === 'function')
|
||||
_dprQuery.removeListener(_dprListener);
|
||||
}
|
||||
_dprQuery = null;
|
||||
_dprListener = null;
|
||||
@@ -326,13 +353,18 @@ export function scopeMaskGeometry(width, height, featherRatio = _featherRatio) {
|
||||
centerY: keyhole.centerY,
|
||||
innerR: Math.max(0, keyhole.radius - half),
|
||||
outerR: keyhole.radius + half,
|
||||
maxR: Math.hypot(Math.max(keyhole.centerX, width - keyhole.centerX),
|
||||
Math.max(keyhole.centerY, height - keyhole.centerY)),
|
||||
maxR: Math.hypot(
|
||||
Math.max(keyhole.centerX, width - keyhole.centerX),
|
||||
Math.max(keyhole.centerY, height - keyhole.centerY),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function draw() {
|
||||
if (_coalescingPaint) { _paintDirty = true; return; } // one paint at scope exit
|
||||
if (_coalescingPaint) {
|
||||
_paintDirty = true;
|
||||
return;
|
||||
} // one paint at scope exit
|
||||
if (!_canvas || !_container) return;
|
||||
// SCOPE OFF is the cheapest state, not a painted one: bail out BEFORE the
|
||||
// backing-store resize + clear (a full-viewport allocation) that used to run
|
||||
@@ -377,8 +409,12 @@ function draw() {
|
||||
return;
|
||||
}
|
||||
const gradient = ctx.createRadialGradient(
|
||||
geo.centerX, geo.centerY, geo.innerR,
|
||||
geo.centerX, geo.centerY, geo.outerR,
|
||||
geo.centerX,
|
||||
geo.centerY,
|
||||
geo.innerR,
|
||||
geo.centerX,
|
||||
geo.centerY,
|
||||
geo.outerR,
|
||||
);
|
||||
gradient.addColorStop(0, `rgba(${r},${g},${b},0)`);
|
||||
gradient.addColorStop(1, `rgba(${r},${g},${b},${_terminusAlpha})`);
|
||||
@@ -433,7 +469,8 @@ function watchCameraHeight(viewer) {
|
||||
// throttle bookkeeping, no quantize — the listener is a single compare.
|
||||
// setScopeMaskEnabled(true) re-syncs the alpha it skipped.
|
||||
if (!_enabled) return;
|
||||
const now = (typeof performance !== 'undefined' ? performance.now() : Date.now());
|
||||
const now =
|
||||
typeof performance !== 'undefined' ? performance.now() : Date.now();
|
||||
if (now - _lastTerminusSampleMs < SCOPE_TERMINUS_SAMPLE_MS) return;
|
||||
_lastTerminusSampleMs = now;
|
||||
updateScopeTerminusForHeight(currentCameraHeightM());
|
||||
@@ -449,8 +486,14 @@ function watchCameraHeight(viewer) {
|
||||
}
|
||||
|
||||
function teardownCameraHeightWatch() {
|
||||
if (_cameraSampleRemover) { _cameraSampleRemover(); _cameraSampleRemover = null; }
|
||||
if (_cameraMoveEndRemover) { _cameraMoveEndRemover(); _cameraMoveEndRemover = null; }
|
||||
if (_cameraSampleRemover) {
|
||||
_cameraSampleRemover();
|
||||
_cameraSampleRemover = null;
|
||||
}
|
||||
if (_cameraMoveEndRemover) {
|
||||
_cameraMoveEndRemover();
|
||||
_cameraMoveEndRemover = null;
|
||||
}
|
||||
_lastTerminusSampleMs = -Infinity;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user