chore: test deploy snapshot

This commit is contained in:
2026-05-27 10:43:01 +09:00
parent c1d0f4c1db
commit 4c4b3c8d2c
78 changed files with 10392 additions and 2301 deletions

View File

@@ -14,6 +14,7 @@ type LinkNavigationEvent = {
type OpenExternalLinkOptions = {
event?: LinkNavigationEvent;
onUnsupportedStandalone?: (url: string) => void;
allowSameTabFallback?: boolean;
};
function canUseSessionStorage() {
@@ -66,6 +67,36 @@ function buildExternalWindowTarget() {
return `${EXTERNAL_WINDOW_TARGET_PREFIX}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
}
function openExternalWindow(url: string, target: string) {
if (typeof window === 'undefined') {
return null;
}
const openedWindow = window.open('', target);
if (!openedWindow) {
return null;
}
try {
openedWindow.opener = null;
} catch {
// Ignore opener access failures in restricted runtimes.
}
try {
openedWindow.location.replace(url);
} catch {
try {
openedWindow.location.href = url;
} catch {
// Leave the popup verification fallback to handle blocked navigations.
}
}
return openedWindow;
}
function clickExternalAnchor(url: string, target: string) {
if (typeof document === 'undefined') {
return;
@@ -151,30 +182,24 @@ function openPreviewRuntimeFallback(url: string) {
return true;
}
function scheduleUnsupportedStandaloneFallback(url: string, callback?: (url: string) => void) {
if (typeof window === 'undefined' || typeof document === 'undefined' || !isAppleMobileStandaloneMode()) {
return;
function hasOpenedWindowNavigated(openedWindow: Window | null) {
if (!openedWindow || openedWindow.closed) {
return false;
}
window.setTimeout(() => {
const pageStillVisible = document.visibilityState !== 'hidden';
const pageStillFocused = typeof document.hasFocus !== 'function' || document.hasFocus();
if (pageStillVisible && pageStillFocused) {
if (openPreviewRuntimeFallback(url)) {
return;
}
if (openSameTabFallback(url)) {
return;
}
callback?.(url);
}
}, UNSUPPORTED_STANDALONE_FALLBACK_DELAY_MS);
try {
return openedWindow.location.href !== 'about:blank';
} catch {
return true;
}
}
function schedulePopupBlockedFallback(url: string, callback?: (url: string) => void) {
function scheduleExternalWindowFallback(
url: string,
openedWindow: Window | null,
allowSameTabFallback: boolean,
callback?: (url: string) => void,
) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
@@ -187,7 +212,17 @@ function schedulePopupBlockedFallback(url: string, callback?: (url: string) => v
return;
}
if (openSameTabFallback(url)) {
if (hasOpenedWindowNavigated(openedWindow)) {
return;
}
if (allowSameTabFallback && isAppleMobileStandaloneMode()) {
if (openPreviewRuntimeFallback(url)) {
return;
}
}
if (allowSameTabFallback && openSameTabFallback(url)) {
return;
}
@@ -221,15 +256,14 @@ export function openExternalLinkInNewWindow(url: string, options: OpenExternalLi
persistExternalLinkOpenTimestamp(Date.now());
const target = buildExternalWindowTarget();
const openedWindow = window.open(url, target, 'noopener,noreferrer');
const allowSameTabFallback = options.allowSameTabFallback ?? true;
const openedWindow = openExternalWindow(url, target);
if (openedWindow) {
return;
if (!openedWindow && allowSameTabFallback) {
clickExternalAnchor(url, target);
}
clickExternalAnchor(url, target);
scheduleUnsupportedStandaloneFallback(url, options.onUnsupportedStandalone);
schedulePopupBlockedFallback(url, options.onUnsupportedStandalone);
scheduleExternalWindowFallback(url, openedWindow, allowSameTabFallback, options.onUnsupportedStandalone);
}
export function openChatExternalLink(url: string, event?: LinkNavigationEvent) {