feat: add beacon nexus portal slice (#167)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Successful in 6s
Smoke Test / smoke (pull_request) Failing after 8s

This commit is contained in:
Alexander Whitestone
2026-04-18 15:12:29 -04:00
parent 947ed22057
commit f8d52c923e
9 changed files with 208 additions and 9 deletions

View File

@@ -193,6 +193,73 @@ function spellf(n) {
return parts.join(' ') || 'zero';
}
// === PORTAL HELPERS ===
function getBeaconPortalId() {
try {
const search = (typeof window !== 'undefined' && window.location && typeof window.location.search === 'string')
? window.location.search.replace(/^\?/, '')
: '';
if (!search) return '';
for (const chunk of search.split('&')) {
if (!chunk) continue;
const [rawKey, rawValue = ''] = chunk.split('=');
if (decodeURIComponent(rawKey || '') === 'portal') {
return decodeURIComponent(rawValue.replace(/\+/g, ' ')).trim();
}
}
} catch (e) {}
return '';
}
function isBeaconPortalEmbed() {
try {
const search = (typeof window !== 'undefined' && window.location && typeof window.location.search === 'string')
? window.location.search.replace(/^\?/, '')
: '';
if (!search) return false;
for (const chunk of search.split('&')) {
if (!chunk) continue;
const [rawKey, rawValue = ''] = chunk.split('=');
if (decodeURIComponent(rawKey || '') === 'embedded') {
return decodeURIComponent(rawValue.replace(/\+/g, ' ')) === '1';
}
}
} catch (e) {}
return false;
}
function getBeaconScopedStorageKey(baseKey) {
const portalId = getBeaconPortalId();
return portalId ? `${baseKey}:${portalId}` : baseKey;
}
function getBeaconSaveKey() {
return getBeaconScopedStorageKey('the-beacon-v2');
}
function clearBeaconSaveAndReload() {
try {
if (typeof localStorage !== 'undefined') {
localStorage.removeItem(getBeaconSaveKey());
}
} catch (e) {}
if (typeof location !== 'undefined' && location && typeof location.reload === 'function') {
location.reload();
}
}
function applyPortalMode() {
if (typeof document === 'undefined' || !document.body) return;
const portalId = getBeaconPortalId();
if (portalId) {
document.body.setAttribute('data-portal-id', portalId);
if (document.body.dataset) document.body.dataset.portalId = portalId;
}
if (isBeaconPortalEmbed()) {
document.body.classList.add('portal-embed');
}
}
// NOTE: exportSave() and importSave() are defined in render.js (file-based).
// The clipboard/prompt versions that were here were dead code — render.js
// loads after utils.js and overrides them. Removed to avoid confusion.