mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
Merge branch 'main' into samehkhamis/no-focus-zoom
This commit is contained in:
14 files changed
+621
-269
No files matched your search
@@ -0,0 +1,3 @@
|
||||
- The Bhote Koshi panel's buttons are kit controls, CINEMATIC's pressed
|
||||
state is Vue state, and its media cards are a Vue view (manjunath22466,
|
||||
samehkhamis, #1865).
|
||||
+25
-5
@@ -88,10 +88,9 @@ adapter is gone.
|
||||
`active`); its pressed classes toggle through `classList`, so a class other
|
||||
code adds (a voice highlight) survives a press. Every pressed toggle (a
|
||||
control with `aria-pressed`) in the views is a `UiButton` with `pressed`
|
||||
except two that keep their own `aria-pressed`: Bhote Koshi's cinematic
|
||||
button, whose state the event layer writes into the attributes its panel
|
||||
renders, and Explore's story cards, which are `role="button"` elements,
|
||||
not buttons (`src/ui/kit/viewControls.test.mjs` pins it). Where the
|
||||
except Explore's story cards, which keep their own `aria-pressed` since
|
||||
they are `role="button"` elements, not buttons
|
||||
(`src/ui/kit/viewControls.test.mjs` pins it). Where the
|
||||
converted buttons draw Material symbols (the tilt-map button, the Context
|
||||
header's search and expand, the imported files' row actions and the rail
|
||||
chips' icons), the glyphs are `UiIcon`s with `:size="null"`, so the site
|
||||
@@ -261,6 +260,26 @@ targets in its template, as many as `view.subRings` says, rather than
|
||||
building them in script; the Omnibar's one other `material-symbols-outlined`
|
||||
is a stylesheet selector, and the layer disclosure only names a button in a
|
||||
comment (`src/ui/kit/smallSurfacesControls.test.mjs` pins it).
|
||||
The Bhote Koshi reconstruction panel's buttons (previous and next beat,
|
||||
Play, Play scene, Cinematic, Full story, Open original, Lower gorge, the
|
||||
field reports and Open public map) are ghost `UiButton`s that keep their
|
||||
`data-action` hooks. Cinematic is a pressed toggle with no pressed class,
|
||||
since bhote-koshi.css reads its `aria-pressed`: the event layer presents
|
||||
its state as the record's `pressed`, which the panel passes to the
|
||||
button, instead of writing an `aria-pressed` attribute. The ‹ and ›
|
||||
arrows are text characters. The event's embedded media cards (each
|
||||
anchored witness clip's frame, leader line, title, status and original
|
||||
link, and the hidden YouTube preload) are drawn by
|
||||
`BhoteKoshiMediaCards`, which `src/data/bhoteKoshiEmbeddedMedia.js`
|
||||
renders into its overlay root with `h()` and `render()` on every change,
|
||||
words again on a locale change, and places after each frame; they hold
|
||||
no control, and the original link stays a link. The script still builds
|
||||
the provider SDKs' script and preconnect tags, the overlay root, and the
|
||||
Facebook player node: that node is warmed hidden before its card exists
|
||||
and carried, loaded, into the card's player, where the SDK replaces its
|
||||
contents, so a template could only rebuild it and reload the player; the
|
||||
X post is likewise built by its SDK inside the player
|
||||
(`src/ui/kit/bhoteKoshiControls.test.mjs` pins it).
|
||||
`UiSelect` renders the bare native select (Core's labels sit outside it or
|
||||
come as an `aria-label`) with `v-model`, `options` and `disabled`;
|
||||
options that carry their own attributes come through the slot, a caller's
|
||||
@@ -543,7 +562,8 @@ slot whenever its view is drawn.
|
||||
reconstruction panel (`BhoteKoshiPanel`, last in the context rail,
|
||||
renders what the event layer publishes to the `gev-bhote-koshi-panel`
|
||||
store: each control's text, hidden, disabled, value and attributes as
|
||||
the layer writes them, unchanged frames sending nothing; the rail takes
|
||||
the layer writes them, and the cinematic button's pressed state,
|
||||
unchanged frames sending nothing; the rail takes
|
||||
`bhote-event-active` while it shows), the full-globe celestial ring
|
||||
(`CelestialRing` teleports into the globe container what `CelestialRing`
|
||||
in `src/celestialRing.js` publishes to the `gev-celestial-ring` store and
|
||||
|
||||
@@ -1355,6 +1355,8 @@
|
||||
"src/ui/kit/cockpitControls.test.mjs",
|
||||
"src/ui/kit/smallSurfacesControls.test.mjs",
|
||||
"src/ui/kit/commandDockControls.test.mjs",
|
||||
"src/ui/kit/bhoteKoshiControls.test.mjs",
|
||||
"src/ui/bhoteKoshi/BhoteKoshiMediaCards.vue",
|
||||
"src/ui/kit/missionsRadioControls.test.mjs",
|
||||
"src/ui/kit/drawControls.test.mjs",
|
||||
"src/ui/styles/chip.css",
|
||||
|
||||
@@ -4181,6 +4181,7 @@
|
||||
"src/render/cesium/heights.js",
|
||||
"src/ui/imagerySplit.js",
|
||||
"src/data/bhoteKoshiEmbeddedMedia.js",
|
||||
"src/ui/bhoteKoshi/BhoteKoshiMediaCards.vue",
|
||||
"src/data/bhoteKoshiLocator.js",
|
||||
"src/data/bhoteKoshiIncidentPlaces.js",
|
||||
"src/data/bhoteKoshiFloodPath.js",
|
||||
@@ -5583,6 +5584,7 @@
|
||||
"src/ui/imagerySplit.js",
|
||||
"src/maps/imageryComparison.js",
|
||||
"src/data/bhoteKoshiEmbeddedMedia.js",
|
||||
"src/ui/bhoteKoshi/BhoteKoshiMediaCards.vue",
|
||||
"src/data/bhoteKoshiLocator.js",
|
||||
"src/render/cesium/camera.js",
|
||||
"src/render/cesium/frame.js",
|
||||
|
||||
+173
-179
@@ -6,6 +6,8 @@ import {
|
||||
} from '../render/rendererOf.js';
|
||||
import { dot, sub } from '../geo/vector.js';
|
||||
import { t, msg, onLocaleChange } from '../i18n/index.js';
|
||||
import { h, render as renderVue } from 'vue';
|
||||
import BhoteKoshiMediaCards from '../ui/bhoteKoshi/BhoteKoshiMediaCards.vue';
|
||||
|
||||
const YOUTUBE_HOSTS = new Set([
|
||||
'youtube.com',
|
||||
@@ -98,6 +100,7 @@ export function bhoteEventText(value) {
|
||||
let _xWidgetsPromise = null;
|
||||
let _facebookSdkPromise = null;
|
||||
let _facebookEmbedSequence = 0;
|
||||
let _cardSequence = 0;
|
||||
const youtubeApis = new WeakMap();
|
||||
|
||||
function loadYouTubeApi(documentRef, globalRef) {
|
||||
@@ -682,32 +685,61 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
let record = null;
|
||||
let warmRecord = null;
|
||||
let generation = 0;
|
||||
// Text the cards show, kept as the calls that word it so a locale change
|
||||
// words it again. A node is forgotten once it has left the page.
|
||||
const worded = new Map();
|
||||
function forgetDetached() {
|
||||
for (const node of worded.keys())
|
||||
if (!node.isConnected) worded.delete(node);
|
||||
let destroyed = false;
|
||||
// The cards in the root, in the order they were shown: the current one and
|
||||
// any still leaving. Their text is kept as the calls that word it, so a
|
||||
// locale change words it again.
|
||||
const cards = [];
|
||||
|
||||
/** Render the cards and the YouTube preload into the root, synchronously. */
|
||||
function render() {
|
||||
if (destroyed) return;
|
||||
const warmFrame = warmRecord?.frame;
|
||||
renderVue(
|
||||
h(BhoteKoshiMediaCards, {
|
||||
warm: warmFrame
|
||||
? {
|
||||
key: warmRecord.key,
|
||||
src: warmFrame.src,
|
||||
title: warmFrame.title(),
|
||||
}
|
||||
: null,
|
||||
cards: cards.map((current) => ({
|
||||
id: current.id,
|
||||
provider: current.source.provider,
|
||||
portrait: current.portrait,
|
||||
entering: current.entering,
|
||||
leaving: current.leaving,
|
||||
unavailable: current.unavailable,
|
||||
label: current.label(),
|
||||
title: current.title(),
|
||||
status: current.status(),
|
||||
url: current.source.url,
|
||||
frame: current.frame && {
|
||||
src: current.frame.src,
|
||||
title: current.frame.title(),
|
||||
onLoad: current.frame.onLoad,
|
||||
},
|
||||
bind: current.bind,
|
||||
})),
|
||||
}),
|
||||
root,
|
||||
);
|
||||
}
|
||||
function word(node, property, text) {
|
||||
let properties = worded.get(node);
|
||||
if (!properties) worded.set(node, (properties = new Map()));
|
||||
properties.set(property, text);
|
||||
writeWord(node, property, text());
|
||||
}
|
||||
function writeWord(node, property, value) {
|
||||
if (property === 'textContent' || property === 'title')
|
||||
node[property] = value;
|
||||
else node.setAttribute(property, value);
|
||||
}
|
||||
const offLocale = onLocaleChange(() => {
|
||||
forgetDetached();
|
||||
for (const [node, properties] of worded)
|
||||
for (const [property, text] of properties)
|
||||
writeWord(node, property, text());
|
||||
});
|
||||
const offLocale = onLocaleChange(render);
|
||||
const leavingRecords = new Set();
|
||||
|
||||
/** Word a card's status and draw it. */
|
||||
function setStatus(current, text) {
|
||||
current.status = text;
|
||||
render();
|
||||
}
|
||||
/** Mark a card unavailable or not and draw it. */
|
||||
function setUnavailable(current, unavailable) {
|
||||
current.unavailable = unavailable;
|
||||
render();
|
||||
}
|
||||
|
||||
const prefersReducedMotion = () =>
|
||||
globalRef.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ===
|
||||
true;
|
||||
@@ -848,9 +880,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
if (current.exitTimer != null) globalRef.clearTimeout?.(current.exitTimer);
|
||||
destroyFacebookSession(current.facebookSession);
|
||||
current.youtubeSession?.destroy();
|
||||
current.card?.remove?.();
|
||||
const at = cards.indexOf(current);
|
||||
if (at !== -1) cards.splice(at, 1);
|
||||
leavingRecords.delete(current);
|
||||
forgetDetached();
|
||||
render();
|
||||
}
|
||||
|
||||
const position = () => {
|
||||
@@ -866,7 +899,8 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
current.enterFrame = scheduleFrame(() => {
|
||||
current.enterFrame = null;
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-entering');
|
||||
current.entering = true;
|
||||
render();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -888,9 +922,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
removeRecord(current);
|
||||
return;
|
||||
}
|
||||
current.card.classList.remove('is-entering');
|
||||
current.card.classList.add('is-leaving');
|
||||
current.entering = false;
|
||||
current.leaving = true;
|
||||
leavingRecords.add(current);
|
||||
render();
|
||||
current.exitTimer =
|
||||
globalRef.setTimeout?.(
|
||||
() => removeRecord(current),
|
||||
@@ -900,11 +935,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
|
||||
function clearWarm(key = null) {
|
||||
if (!warmRecord || (key && warmRecord.key !== key)) return;
|
||||
if (warmRecord.facebookSession)
|
||||
destroyFacebookSession(warmRecord.facebookSession);
|
||||
else warmRecord.iframe?.remove?.();
|
||||
const facebookSession = warmRecord.facebookSession;
|
||||
warmRecord = null;
|
||||
forgetDetached();
|
||||
if (facebookSession) destroyFacebookSession(facebookSession);
|
||||
else render();
|
||||
}
|
||||
|
||||
function takeWarmFacebook(key, host) {
|
||||
@@ -944,29 +978,26 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
warmRecord = { key, facebookSession };
|
||||
return true;
|
||||
}
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.className = 'bhote-embedded-media-warmup';
|
||||
iframe.src = embeddedMediaFrameUrl(source, {
|
||||
autoplay: false,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
});
|
||||
word(iframe, 'title', () =>
|
||||
t('Preloading {provider} media', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
);
|
||||
iframe.tabIndex = -1;
|
||||
iframe.setAttribute('aria-hidden', 'true');
|
||||
iframe.loading = 'eager';
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
root.append(iframe);
|
||||
warmRecord = { key, iframe };
|
||||
warmRecord = {
|
||||
key,
|
||||
frame: {
|
||||
src: embeddedMediaFrameUrl(source, {
|
||||
autoplay: false,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
}),
|
||||
title: () =>
|
||||
t('Preloading {provider} media', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
},
|
||||
};
|
||||
render();
|
||||
return true;
|
||||
}
|
||||
|
||||
async function mountX(current, token) {
|
||||
word(current.status, 'textContent', () => t('LOADING X POST…'));
|
||||
setStatus(current, () => t('LOADING X POST…'));
|
||||
try {
|
||||
const api = await xLoader(documentRef, globalRef);
|
||||
if (token !== generation || record !== current) return;
|
||||
@@ -986,14 +1017,12 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
throw new Error(
|
||||
msg('The X post is unavailable or cannot be embedded.'),
|
||||
);
|
||||
word(current.status, 'textContent', () =>
|
||||
t('X POST · PROVIDER CONTROLS'),
|
||||
);
|
||||
setStatus(current, () => t('X POST · PROVIDER CONTROLS'));
|
||||
position();
|
||||
} catch (error) {
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-unavailable');
|
||||
word(current.status, 'textContent', () =>
|
||||
current.unavailable = true;
|
||||
setStatus(current, () =>
|
||||
t('{reason} OPEN ORIGINAL.', {
|
||||
reason: t(String(error?.message || msg('X embed unavailable'))),
|
||||
}),
|
||||
@@ -1010,16 +1039,14 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
session.shouldPlay = autoplay === true;
|
||||
session.onReady = () => {
|
||||
if (token !== generation || record !== current) return;
|
||||
word(current.status, 'textContent', () =>
|
||||
t('FACEBOOK · PROVIDER CONTROLS'),
|
||||
);
|
||||
current.card.classList.remove('is-unavailable');
|
||||
current.status = () => t('FACEBOOK · PROVIDER CONTROLS');
|
||||
setUnavailable(current, false);
|
||||
position();
|
||||
};
|
||||
session.onError = (error) => {
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-unavailable');
|
||||
word(current.status, 'textContent', () =>
|
||||
current.unavailable = true;
|
||||
setStatus(current, () =>
|
||||
t('{reason} OPEN ORIGINAL.', {
|
||||
reason: t(
|
||||
String(error?.message || msg('Facebook embed unavailable')),
|
||||
@@ -1030,9 +1057,7 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
};
|
||||
session.onPlaybackBlocked = () => {
|
||||
if (token !== generation || record !== current) return;
|
||||
word(current.status, 'textContent', () =>
|
||||
t('AUTOPLAY BLOCKED · USE PROVIDER CONTROLS'),
|
||||
);
|
||||
setStatus(current, () => t('AUTOPLAY BLOCKED · USE PROVIDER CONTROLS'));
|
||||
};
|
||||
if (session.ready) session.onReady();
|
||||
else if (session.error) session.onError(session.error);
|
||||
@@ -1078,104 +1103,69 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
if (warmRecord && warmRecord.key !== warmKey) clearWarm();
|
||||
hide({ preserveWarm: true });
|
||||
const token = ++generation;
|
||||
const card = documentRef.createElement('section');
|
||||
const portraitClass = isPortraitMedia(media) ? ' is-portrait' : '';
|
||||
card.className = `bhote-embedded-callout is-${source.provider}${portraitClass}`;
|
||||
card.dataset.provider = source.provider;
|
||||
word(card, 'aria-label', () =>
|
||||
t('Embedded {provider} media for {source}', {
|
||||
provider: providerLabel(source.provider),
|
||||
source: observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source'),
|
||||
}),
|
||||
);
|
||||
const leader = documentRef.createElementNS(
|
||||
'http://www.w3.org/2000/svg',
|
||||
'svg',
|
||||
);
|
||||
leader.classList.add('bhote-embedded-callout-leader');
|
||||
leader.setAttribute('aria-hidden', 'true');
|
||||
leader.innerHTML =
|
||||
'<path pathLength="1" fill="none" stroke="rgba(147,213,228,.72)" stroke-width="1.5"/><circle r="4" fill="#6be8ff" stroke="#ffffff" stroke-width="1.5"/>';
|
||||
const player = documentRef.createElement('div');
|
||||
player.className = 'bhote-embedded-callout-player ui-scroll';
|
||||
const footer = documentRef.createElement('footer');
|
||||
const title = documentRef.createElement('strong');
|
||||
word(title, 'textContent', () =>
|
||||
bhoteEventText(
|
||||
observation?.shortTitle || observation?.title || t('Witness source'),
|
||||
).toUpperCase(),
|
||||
);
|
||||
const status = documentRef.createElement('small');
|
||||
status.setAttribute('role', 'status');
|
||||
word(status, 'textContent', () =>
|
||||
t('{provider} · EMBEDDED SOURCE', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
);
|
||||
const link = documentRef.createElement('a');
|
||||
link.href = source.url;
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
word(link, 'textContent', () => t('OPEN ORIGINAL ↗'));
|
||||
footer.append(title, status, link);
|
||||
const body = documentRef.createElement('div');
|
||||
body.className = 'bhote-embedded-callout-body';
|
||||
// The card takes taps (its container and leader do not); Stories keeps that.
|
||||
body.setAttribute('data-overlay-input', '');
|
||||
body.append(player, footer);
|
||||
card.append(leader, body);
|
||||
root.append(card);
|
||||
record = {
|
||||
const providerName = () => providerLabel(source.provider);
|
||||
const sourceName = () =>
|
||||
observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source');
|
||||
const current = {
|
||||
id: ++_cardSequence,
|
||||
key,
|
||||
source,
|
||||
anchor,
|
||||
card,
|
||||
leader,
|
||||
player,
|
||||
status,
|
||||
portrait: isPortraitMedia(media),
|
||||
entering: false,
|
||||
leaving: false,
|
||||
unavailable: false,
|
||||
label: () =>
|
||||
t('Embedded {provider} media for {source}', {
|
||||
provider: providerName(),
|
||||
source: sourceName(),
|
||||
}),
|
||||
title: () =>
|
||||
bhoteEventText(
|
||||
observation?.shortTitle || observation?.title || t('Witness source'),
|
||||
).toUpperCase(),
|
||||
status: () =>
|
||||
t('{provider} · EMBEDDED SOURCE', { provider: providerName() }),
|
||||
frame: null,
|
||||
frameElement: null,
|
||||
card: null,
|
||||
leader: null,
|
||||
player: null,
|
||||
entered: false,
|
||||
};
|
||||
|
||||
if (source.provider === 'x') {
|
||||
void mountX(record, token);
|
||||
} else if (source.provider === 'facebook') {
|
||||
bindFacebook(record, token, warmKey, autoplay);
|
||||
} else {
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.src = embeddedMediaFrameUrl(source, {
|
||||
autoplay,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
});
|
||||
const controlled =
|
||||
// The elements the card's view draws: placed after each frame, filled by
|
||||
// the provider.
|
||||
current.bind = (name, element) => {
|
||||
if (element) current[name] = element;
|
||||
};
|
||||
let controlled = false;
|
||||
if (source.provider === 'youtube') {
|
||||
const url = new URL(
|
||||
embeddedMediaFrameUrl(source, {
|
||||
autoplay,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
}),
|
||||
);
|
||||
controlled =
|
||||
autoplay &&
|
||||
Number.isFinite(Number(endAtSec)) &&
|
||||
Number(endAtSec) > startAtSec;
|
||||
if (controlled) {
|
||||
const url = new URL(iframe.src);
|
||||
url.searchParams.set('enablejsapi', '1');
|
||||
if (globalRef.location?.origin)
|
||||
url.searchParams.set('origin', globalRef.location.origin);
|
||||
iframe.src = url.href;
|
||||
}
|
||||
word(iframe, 'title', () =>
|
||||
t('{provider} media: {source}', {
|
||||
provider: providerLabel(source.provider),
|
||||
source: observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source'),
|
||||
}),
|
||||
);
|
||||
iframe.allow =
|
||||
'autoplay; encrypted-media; picture-in-picture; fullscreen';
|
||||
iframe.allowFullscreen = true;
|
||||
iframe.loading = 'eager';
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
iframe.addEventListener?.(
|
||||
'load',
|
||||
() => {
|
||||
current.frame = {
|
||||
src: url.href,
|
||||
title: () =>
|
||||
t('{provider} media: {source}', {
|
||||
provider: providerName(),
|
||||
source: sourceName(),
|
||||
}),
|
||||
onLoad: () => {
|
||||
if (token !== generation || record?.key !== key) return;
|
||||
clearWarm(warmKey);
|
||||
if (
|
||||
@@ -1184,38 +1174,41 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
record.youtubeSession.getState().phase,
|
||||
)
|
||||
) {
|
||||
word(status, 'textContent', () =>
|
||||
t('{provider} · PROVIDER CONTROLS', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
setStatus(current, () =>
|
||||
t('{provider} · PROVIDER CONTROLS', { provider: providerName() }),
|
||||
);
|
||||
}
|
||||
position();
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
player.append(iframe);
|
||||
if (controlled) {
|
||||
const current = record;
|
||||
current.youtubeSession = createTrimmedYouTubePlayback({
|
||||
iframe,
|
||||
endAtSec: Number(endAtSec),
|
||||
startAtSec,
|
||||
globalRef,
|
||||
loadApi: () => youtubeLoader(documentRef, globalRef),
|
||||
isCurrent: () => token === generation && record === current,
|
||||
onStatus: (phase) => {
|
||||
if (phase !== 'completed')
|
||||
word(status, 'textContent', () =>
|
||||
t('YOUTUBE {state} · OPEN ORIGINAL', {
|
||||
state: YOUTUBE_PHASE_LABELS[phase]
|
||||
? t(YOUTUBE_PHASE_LABELS[phase])
|
||||
: phase.toUpperCase(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
record = current;
|
||||
cards.push(current);
|
||||
render();
|
||||
|
||||
if (source.provider === 'x') {
|
||||
void mountX(current, token);
|
||||
} else if (source.provider === 'facebook') {
|
||||
bindFacebook(current, token, warmKey, autoplay);
|
||||
} else if (controlled) {
|
||||
current.youtubeSession = createTrimmedYouTubePlayback({
|
||||
iframe: current.frameElement,
|
||||
endAtSec: Number(endAtSec),
|
||||
startAtSec,
|
||||
globalRef,
|
||||
loadApi: () => youtubeLoader(documentRef, globalRef),
|
||||
isCurrent: () => token === generation && record === current,
|
||||
onStatus: (phase) => {
|
||||
if (phase !== 'completed')
|
||||
setStatus(current, () =>
|
||||
t('YOUTUBE {state} · OPEN ORIGINAL', {
|
||||
state: YOUTUBE_PHASE_LABELS[phase]
|
||||
? t(YOUTUBE_PHASE_LABELS[phase])
|
||||
: phase.toUpperCase(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
position();
|
||||
return true;
|
||||
@@ -1223,11 +1216,12 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
|
||||
function destroy() {
|
||||
offLocale();
|
||||
worded.clear();
|
||||
hide({ immediate: true });
|
||||
for (const current of [...leavingRecords]) removeRecord(current);
|
||||
clearWarm();
|
||||
removePostRender?.();
|
||||
destroyed = true;
|
||||
renderVue(null, root);
|
||||
root.remove();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
@@ -12,6 +13,31 @@ import {
|
||||
} from './bhoteKoshiEmbeddedMedia.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
|
||||
// The cards draw provider frames; the tests never load their pages, and the
|
||||
// page's note that each one is not loaded is dropped.
|
||||
window.happyDOM.settings.disableIframePageLoading = true;
|
||||
const consoleError = console.error;
|
||||
console.error = (error, ...rest) => {
|
||||
if (!/Iframe page loading is disabled/.test(String(error?.message)))
|
||||
consoleError(error, ...rest);
|
||||
};
|
||||
|
||||
/**
|
||||
* Embedded media in a fresh globe container of the page, and the overlay
|
||||
* root it renders into.
|
||||
*/
|
||||
function domFixture(options = {}) {
|
||||
document.body.replaceChildren();
|
||||
const container = document.body.appendChild(document.createElement('div'));
|
||||
const media = createBhoteKoshiEmbeddedMedia({
|
||||
viewer: { container },
|
||||
documentRef: document,
|
||||
globalRef: {},
|
||||
...options,
|
||||
});
|
||||
return { media, container, root: container.firstElementChild };
|
||||
}
|
||||
|
||||
test('Pinokio fallback never creates provider DOM or loads SDKs', async () => {
|
||||
const unexpected = () => { throw new Error('Provider resource allocated in Pinokio'); };
|
||||
const media = createBhoteKoshiEmbeddedMedia({
|
||||
@@ -186,31 +212,138 @@ test('trimmed YouTube teardown revokes pending SDK and player callbacks', async
|
||||
});
|
||||
|
||||
test('pausing YouTube removes its frame and rejects a late load from the stopped generation', () => {
|
||||
const nodes = [];
|
||||
class Element extends EventTarget {
|
||||
constructor(tag) { super(); this.tag = tag; this.children = []; this.dataset = {}; this.classList = { add() {}, remove() {} }; nodes.push(this); }
|
||||
setAttribute() {}
|
||||
append(...children) { for (const child of children) { child.parent = this; this.children.push(child); } }
|
||||
remove() { if (this.parent) this.parent.children = this.parent.children.filter((child) => child !== this); this.parent = null; }
|
||||
}
|
||||
const documentRef = {
|
||||
body: new Element('body'),
|
||||
createElement: (tag) => new Element(tag),
|
||||
createElementNS: (_, tag) => new Element(tag),
|
||||
};
|
||||
const media = createBhoteKoshiEmbeddedMedia({ viewer: {}, documentRef, globalRef: {} });
|
||||
const { media, container, root } = domFixture();
|
||||
const options = { observation: { title: 'Clip', media: { sourceUrl: 'https://youtu.be/DbqRexFxv3k' } }, anchor: {}, autoplay: true };
|
||||
assert.equal(media.show(options), true);
|
||||
const frame = nodes.find((node) => node.tag === 'iframe');
|
||||
const card = nodes.find((node) => node.tag === 'section');
|
||||
assert.ok(card.parent);
|
||||
const card = root.querySelector('section');
|
||||
const frame = card.querySelector('iframe');
|
||||
assert.ok(card.isConnected);
|
||||
assert.equal(media.pause(), true);
|
||||
assert.equal(card.parent, null);
|
||||
assert.equal(card.isConnected, false);
|
||||
frame.dispatchEvent(new Event('load'));
|
||||
assert.equal(card.parent, null);
|
||||
assert.equal(root.querySelector('section'), null);
|
||||
assert.equal(media.show(options), true, 'an explicit replay creates a fresh player');
|
||||
assert.notEqual(root.querySelector('section iframe'), frame);
|
||||
media.destroy();
|
||||
assert.equal(container.children.length, 0);
|
||||
});
|
||||
|
||||
test('a card draws its provider, source, status and original link, and words them again in a new locale', async () => {
|
||||
const { setLocale } = await import('../i18n/index.js');
|
||||
const { media, root } = domFixture();
|
||||
assert.equal(media.show({
|
||||
observation: { title: 'Flood footage', media: { sourceUrl: 'https://youtu.be/DbqRexFxv3k', orientation: 'portrait' } },
|
||||
anchor: {},
|
||||
}), true);
|
||||
const card = root.querySelector('section');
|
||||
assert.equal(card.className, 'bhote-embedded-callout is-youtube is-portrait');
|
||||
assert.equal(card.dataset.provider, 'youtube');
|
||||
assert.equal(card.getAttribute('aria-label'), 'Embedded YOUTUBE media for Flood footage');
|
||||
const leader = card.firstElementChild;
|
||||
assert.equal(leader.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(leader.getAttribute('class'), 'bhote-embedded-callout-leader');
|
||||
assert.equal(leader.getAttribute('aria-hidden'), 'true');
|
||||
assert.equal(leader.querySelector('path').getAttribute('pathLength'), '1');
|
||||
assert.equal(leader.querySelector('circle').getAttribute('r'), '4');
|
||||
const body = card.querySelector('.bhote-embedded-callout-body');
|
||||
assert.equal(body.getAttribute('data-overlay-input'), '');
|
||||
const player = body.firstElementChild;
|
||||
assert.equal(player.className, 'bhote-embedded-callout-player ui-scroll');
|
||||
const frame = player.firstElementChild;
|
||||
assert.equal(frame.tagName, 'IFRAME');
|
||||
assert.equal(new URL(frame.src).pathname, '/embed/DbqRexFxv3k');
|
||||
assert.equal(frame.title, 'YOUTUBE media: Flood footage');
|
||||
assert.equal(frame.getAttribute('allow'), 'autoplay; encrypted-media; picture-in-picture; fullscreen');
|
||||
assert.equal(frame.hasAttribute('allowfullscreen'), true);
|
||||
assert.equal(frame.getAttribute('referrerpolicy'), 'strict-origin-when-cross-origin');
|
||||
const [title, status, link] = body.querySelector('footer').children;
|
||||
assert.equal(title.tagName, 'STRONG');
|
||||
assert.equal(title.textContent, 'FLOOD FOOTAGE');
|
||||
assert.equal(status.getAttribute('role'), 'status');
|
||||
assert.equal(status.textContent, 'YOUTUBE · EMBEDDED SOURCE');
|
||||
assert.equal(link.href, 'https://www.youtube.com/watch?v=DbqRexFxv3k');
|
||||
assert.equal(link.target, '_blank');
|
||||
assert.equal(link.rel, 'noopener noreferrer');
|
||||
assert.equal(link.textContent, 'OPEN ORIGINAL ↗');
|
||||
frame.dispatchEvent(new Event('load'));
|
||||
assert.equal(status.textContent, 'YOUTUBE · PROVIDER CONTROLS');
|
||||
try {
|
||||
await setLocale('es');
|
||||
assert.notEqual(link.textContent, 'OPEN ORIGINAL ↗', 'the link is worded again');
|
||||
assert.notEqual(status.textContent, 'YOUTUBE · PROVIDER CONTROLS', 'the status is worded again');
|
||||
assert.ok(root.querySelector('section') === card, 'in place');
|
||||
} finally {
|
||||
await setLocale('en');
|
||||
}
|
||||
media.destroy();
|
||||
});
|
||||
|
||||
test('an X post is built by the provider inside the card and its failure marks the card', async () => {
|
||||
let fail = false;
|
||||
const { media, root } = domFixture({
|
||||
xLoader: async () => ({ widgets: { createTweet: async (id, target) => {
|
||||
if (fail) return null;
|
||||
target.append(Object.assign(document.createElement('div'), { className: 'twitter-tweet', textContent: id }));
|
||||
return {};
|
||||
} } }),
|
||||
});
|
||||
const observation = { title: 'Clip', media: { sourceUrl: 'https://x.com/Indowatchosint/status/2092640554568007958' } };
|
||||
assert.equal(media.show({ observation, anchor: {} }), true);
|
||||
const card = root.querySelector('section');
|
||||
const status = card.querySelector('[role="status"]');
|
||||
assert.equal(status.textContent, 'LOADING X POST…');
|
||||
await new Promise((resolve) => setTimeout(resolve));
|
||||
assert.equal(card.querySelector('.bhote-embedded-callout-player .twitter-tweet').textContent, '2092640554568007958');
|
||||
assert.equal(status.textContent, 'X POST · PROVIDER CONTROLS');
|
||||
assert.equal(card.classList.contains('is-unavailable'), false);
|
||||
media.hide({ immediate: true });
|
||||
fail = true;
|
||||
assert.equal(media.show({ observation, anchor: {} }), true);
|
||||
await new Promise((resolve) => setTimeout(resolve));
|
||||
const failed = root.querySelector('section');
|
||||
assert.ok(failed.classList.contains('is-unavailable'));
|
||||
assert.equal(failed.querySelector('[role="status"]').textContent, 'The X post is unavailable or cannot be embedded. OPEN ORIGINAL.');
|
||||
media.destroy();
|
||||
});
|
||||
|
||||
test('a warmed Facebook player moves into the card and stays through its redraws', async () => {
|
||||
let ready;
|
||||
const { media, root } = domFixture({
|
||||
facebookLoader: async () => ({
|
||||
Event: { subscribe(_name, callback) { ready = callback; }, unsubscribe() {} },
|
||||
XFBML: { parse() {} },
|
||||
}),
|
||||
});
|
||||
const observation = { title: 'Clip', media: { sourceUrl: 'https://www.facebook.com/reel/1571491657757829' } };
|
||||
media.warm({ observation });
|
||||
await Promise.resolve(); await Promise.resolve();
|
||||
const host = root.querySelector('.bhote-embedded-media-warmup');
|
||||
const embed = host.querySelector('.fb-video');
|
||||
assert.equal(media.show({ observation, anchor: {} }), true);
|
||||
const card = root.querySelector('section');
|
||||
const player = card.querySelector('.bhote-embedded-callout-player');
|
||||
assert.ok(host.parentNode === player, 'the warmed player is carried over, not rebuilt');
|
||||
assert.equal(host.className, 'bhote-facebook-player-host');
|
||||
assert.equal(host.hasAttribute('aria-hidden'), false);
|
||||
ready({ type: 'video', id: embed.id, instance: { mute() {}, play() {}, pause() {} } });
|
||||
assert.equal(card.querySelector('[role="status"]').textContent, 'FACEBOOK · PROVIDER CONTROLS');
|
||||
assert.ok(host.parentNode === player, 'a redraw keeps the provider player');
|
||||
media.destroy();
|
||||
});
|
||||
|
||||
test('a leaving card animates out and is removed after its exit', () => {
|
||||
const timers = [];
|
||||
const { media, root } = domFixture({ globalRef: { setTimeout: (fn) => timers.push(fn), clearTimeout() {} } });
|
||||
media.show({ observation: { media: { sourceUrl: 'https://youtu.be/DbqRexFxv3k' } }, anchor: {} });
|
||||
const card = root.querySelector('section');
|
||||
card.hidden = false;
|
||||
media.hide();
|
||||
assert.ok(card.isConnected);
|
||||
assert.ok(card.classList.contains('is-leaving'));
|
||||
assert.equal(card.classList.contains('is-entering'), false);
|
||||
timers.forEach((fn) => fn());
|
||||
assert.equal(card.isConnected, false);
|
||||
media.destroy();
|
||||
assert.equal(documentRef.body.children.length, 0);
|
||||
});
|
||||
|
||||
test('resolves supported embedded callout providers from canonical public URLs', () => {
|
||||
@@ -303,28 +436,8 @@ test('Mailung playback stops at source timestamp 0:07 without changing other cli
|
||||
});
|
||||
|
||||
function preloadFixture(options = {}) {
|
||||
class Element extends EventTarget {
|
||||
constructor(tag) {
|
||||
super(); this.tag = tag; this.children = []; this.dataset = {};
|
||||
this.classList = { add() {}, remove() {}, contains() { return false; } };
|
||||
}
|
||||
setAttribute() {}
|
||||
removeAttribute() {}
|
||||
append(...children) {
|
||||
for (const child of children) { child.remove(); child.parent = this; this.children.push(child); }
|
||||
}
|
||||
remove() {
|
||||
if (this.parent) this.parent.children = this.parent.children.filter(child => child !== this);
|
||||
this.parent = null;
|
||||
}
|
||||
}
|
||||
const documentRef = {
|
||||
body: new Element('body'),
|
||||
createElement: tag => new Element(tag),
|
||||
createElementNS: (_, tag) => new Element(tag),
|
||||
};
|
||||
const media = createBhoteKoshiEmbeddedMedia({ viewer: {}, documentRef, globalRef: {}, ...options });
|
||||
return { media, root: documentRef.body.children[0] };
|
||||
const { media, root } = domFixture(options);
|
||||
return { media, root };
|
||||
}
|
||||
|
||||
for (const operation of ['pause', 'hide', 'destroy']) {
|
||||
@@ -343,16 +456,18 @@ test('camera updates retain a preload until the visible player loads', () => {
|
||||
const observation = { media: { sourceUrl: 'https://youtu.be/DbqRexFxv3k' } };
|
||||
media.warm({ observation });
|
||||
const frame = root.children[0];
|
||||
assert.equal(frame.className, 'bhote-embedded-media-warmup');
|
||||
assert.equal(frame.getAttribute('aria-hidden'), 'true');
|
||||
assert.equal(frame.tabIndex, -1);
|
||||
assert.equal(frame.title, 'Preloading YOUTUBE media');
|
||||
media.hide({ preserveWarm: true });
|
||||
media.warm({ observation });
|
||||
assert.equal(root.children[0], frame);
|
||||
assert.ok(root.children[0] === frame);
|
||||
assert.equal(media.show({ observation, anchor: {} }), true);
|
||||
assert.equal(frame.parent, root, 'keep the preload while the visible player starts');
|
||||
const card = root.children.find(node => node.tag === 'section');
|
||||
const body = card.children.find(node => node.className === 'bhote-embedded-callout-body');
|
||||
const player = body.children.find(node => node.className.split(' ').includes('bhote-embedded-callout-player'));
|
||||
player.children.find(node => node.tag === 'iframe').dispatchEvent(new Event('load'));
|
||||
assert.equal(frame.parent, null, 'visible player readiness releases the preload');
|
||||
assert.ok(frame.parentNode === root, 'keep the preload while the visible player starts');
|
||||
root.querySelector('section .bhote-embedded-callout-body > .bhote-embedded-callout-player > iframe')
|
||||
.dispatchEvent(new Event('load'));
|
||||
assert.equal(frame.isConnected, false, 'visible player readiness releases the preload');
|
||||
media.destroy();
|
||||
assert.equal(root.children.length, 0);
|
||||
});
|
||||
@@ -420,25 +535,9 @@ test('a media card stays between the panels when right-to-left swaps their sides
|
||||
});
|
||||
|
||||
test('a shown card follows its anchor through the renderer ports', () => {
|
||||
class Element extends EventTarget {
|
||||
constructor(tag) {
|
||||
super(); this.tag = tag; this.children = []; this.dataset = {}; this.style = {};
|
||||
this.classList = { add() {}, remove() {}, contains() { return false; } };
|
||||
}
|
||||
setAttribute() {}
|
||||
removeAttribute() {}
|
||||
querySelector() { return null; }
|
||||
getBoundingClientRect() { return { left: 0, top: 0, right: 1000, bottom: 800, width: 1000, height: 800 }; }
|
||||
append(...children) { for (const child of children) { child.remove(); child.parent = this; this.children.push(child); } }
|
||||
remove() { if (this.parent) this.parent.children = this.parent.children.filter((child) => child !== this); this.parent = null; }
|
||||
}
|
||||
const documentRef = {
|
||||
body: new Element('body'),
|
||||
createElement: (tag) => new Element(tag),
|
||||
createElementNS: (_, tag) => new Element(tag),
|
||||
};
|
||||
const listeners = new Set();
|
||||
const viewer = { canvas: { getBoundingClientRect: () => ({ left: 500, top: 500 }) } };
|
||||
const container = document.body.appendChild(document.createElement('div'));
|
||||
const viewer = { container, canvas: { getBoundingClientRect: () => ({ left: 500, top: 500 }) } };
|
||||
let pose = { position: { x: 0, y: 0, z: 0 }, direction: { x: 1, y: 0, z: 0 } };
|
||||
const projected = [];
|
||||
// The renderer's canvas, not the viewer's, places the card.
|
||||
@@ -454,14 +553,18 @@ test('a shown card follows its anchor through the renderer ports', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
const media = createBhoteKoshiEmbeddedMedia({ viewer, documentRef, globalRef: {} });
|
||||
const media = createBhoteKoshiEmbeddedMedia({ viewer, documentRef: document, globalRef: {} });
|
||||
const root = container.firstElementChild;
|
||||
root.getBoundingClientRect = () => ({ left: 0, top: 0, right: 1000, bottom: 800, width: 1000, height: 800 });
|
||||
assert.deepEqual([...listeners].map(([phase]) => phase), ['postRender']);
|
||||
const anchor = { x: 10, y: 0, z: 0 };
|
||||
assert.equal(media.show({ observation: { title: 'Clip', media: { sourceUrl: 'https://youtu.be/DbqRexFxv3k' } }, anchor }), true);
|
||||
const card = documentRef.body.children[0].children.find((node) => node.tag === 'section');
|
||||
const card = root.querySelector('section');
|
||||
assert.equal(card.hidden, false);
|
||||
assert.equal(projected.at(-1), anchor);
|
||||
assert.equal(card.style.left, `${300 + 10 + 42}px`);
|
||||
// The leader runs from the anchor to the card's near edge.
|
||||
assert.equal(card.querySelector('path').getAttribute('d'), `M ${300 + 10 - 352} ${200 + 5 - parseFloat(card.style.top)} L 0 ${Math.max(16, Math.min(360 - 16, 200 + 5 - parseFloat(card.style.top)))}`);
|
||||
// Behind the eye: hidden on the next drawn frame.
|
||||
pose = { ...pose, direction: { x: -1, y: 0, z: 0 } };
|
||||
for (const [, cb] of listeners) cb();
|
||||
|
||||
@@ -989,9 +989,10 @@ function createPanelRecords(event) {
|
||||
textContent: t('▶ PLAY SCENE'),
|
||||
hidden: true,
|
||||
}),
|
||||
// `pressed` is the button's pressed state; the view renders it as one.
|
||||
cinematicButton: panelRecord({
|
||||
textContent: t('◉ CINEMATIC'),
|
||||
attributes: { 'aria-pressed': 'false' },
|
||||
pressed: false,
|
||||
}),
|
||||
storyReplayButton: panelRecord({ textContent: t('↺ FULL STORY') }),
|
||||
corridorButton: panelRecord(),
|
||||
@@ -2860,7 +2861,7 @@ export function createBhoteKoshiEventLayer({
|
||||
'textContent',
|
||||
_cinematicActive ? t('■ RELEASE CAMERA') : t('◉ CINEMATIC'),
|
||||
);
|
||||
setElementAttribute(button, 'aria-pressed', String(_cinematicActive));
|
||||
setElementProperty(button, 'pressed', _cinematicActive);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ function eventPanel() {
|
||||
get textContent() { return record().textContent; },
|
||||
get hidden() { return record().hidden; },
|
||||
get disabled() { return record().disabled; },
|
||||
get pressed() { return record().pressed; },
|
||||
get value() { return typed ?? record().value; },
|
||||
set value(value) { typed = value; },
|
||||
getAttribute: (name) => record().attributes[name] ?? null,
|
||||
@@ -2711,6 +2712,8 @@ test('Bhote Koshi replay restores cinematic ownership unless the operator releas
|
||||
play.dispatch('click');
|
||||
assert.equal(layer.getCinematicState().active, true);
|
||||
assert.equal(layer.getPlaybackState().progress, 0);
|
||||
const cinematicControl = panel.querySelector('[data-action="cinematic"]');
|
||||
assert.equal(cinematicControl.pressed, true, 'the cinematic button is pressed while it owns the camera');
|
||||
assert.equal(layer.getPlaybackState().playing, true);
|
||||
assert.equal(
|
||||
body.children.some((element) => element.id === 'bhote-koshi-story-strap'),
|
||||
@@ -2720,6 +2723,7 @@ test('Bhote Koshi replay restores cinematic ownership unless the operator releas
|
||||
panel.querySelector('[data-action="cinematic"]').dispatch('click');
|
||||
assert.equal(layer.getCinematicState().active, false);
|
||||
assert.equal(viewer._test.cameraTransforms.length, 2);
|
||||
assert.equal(cinematicControl.pressed, false, 'releasing the camera unpresses the button');
|
||||
animationCallbacks[1](91001);
|
||||
assert.equal(play.textContent, '↺ REPLAY');
|
||||
const cameraLookCount = viewer._test.cameraLooks.length;
|
||||
|
||||
@@ -38,7 +38,7 @@ function presentation(patch = {}) {
|
||||
playSceneButton: record({ textContent: '▶ PLAY SCENE', hidden: true }),
|
||||
cinematicButton: record({
|
||||
textContent: '◉ CINEMATIC',
|
||||
attributes: { 'aria-pressed': 'false' },
|
||||
pressed: false,
|
||||
}),
|
||||
storyReplayButton: record({ textContent: '↺ FULL STORY' }),
|
||||
corridorButton: record(),
|
||||
@@ -156,6 +156,10 @@ test('a later presentation updates the controls in place', async (t) => {
|
||||
disabled: true,
|
||||
attributes: { 'aria-label': 'Play Global context' },
|
||||
});
|
||||
next.refs.cinematicButton = record({
|
||||
textContent: '■ RELEASE CAMERA',
|
||||
pressed: true,
|
||||
});
|
||||
next.refs.progressInput = record({ value: '250', hidden: true });
|
||||
next.refs.imagerySection = record({ hidden: true });
|
||||
store.publish(next);
|
||||
@@ -164,6 +168,9 @@ test('a later presentation updates the controls in place', async (t) => {
|
||||
assert.equal(play.textContent, '▶ PLAY SHOT');
|
||||
assert.equal(play.disabled, true);
|
||||
assert.equal(play.getAttribute('aria-label'), 'Play Global context');
|
||||
const cinematic = $('[data-action="cinematic"]');
|
||||
assert.equal(cinematic.getAttribute('aria-pressed'), 'true');
|
||||
assert.equal(cinematic.textContent, '■ RELEASE CAMERA');
|
||||
assert.ok(
|
||||
$('#bhote-koshi-event-panel').classList.contains('bhote-event-scene-beat'),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup>
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
// The Bhote Koshi event's embedded media cards and the hidden YouTube
|
||||
// preload, as src/data/bhoteKoshiEmbeddedMedia.js presents them inside its
|
||||
// overlay root. The owner renders synchronously on every change and places
|
||||
// each card beside its map anchor after each frame (its position, its
|
||||
// leader's line and whether it shows); a card's player is filled by the
|
||||
// provider: the YouTube frame drawn here, or the Facebook player and X post
|
||||
// the provider SDKs build inside it. The card's body takes taps (the root
|
||||
// and the leader do not); Stories keeps that.
|
||||
defineProps({
|
||||
/** `{key, src, title}` of the hidden YouTube preload, or null. */
|
||||
warm: { type: Object, default: null },
|
||||
/**
|
||||
* The cards in insertion order: `{id, provider, portrait, entering,
|
||||
* leaving, unavailable, label, title, status, url, frame, bind}`; `frame`
|
||||
* is `{src, title, onLoad}` for a YouTube card and null otherwise, and
|
||||
* `bind(name, element)` hands the owner the elements it places and fills.
|
||||
*/
|
||||
cards: { type: Array, default: () => [] },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<iframe
|
||||
v-if="warm"
|
||||
:key="warm.key"
|
||||
class="bhote-embedded-media-warmup"
|
||||
:src="warm.src"
|
||||
:title="warm.title"
|
||||
tabindex="-1"
|
||||
aria-hidden="true"
|
||||
loading="eager"
|
||||
referrerpolicy="strict-origin-when-cross-origin"
|
||||
></iframe>
|
||||
<section
|
||||
v-for="card in cards"
|
||||
:key="card.id"
|
||||
:ref="(el) => card.bind('card', el)"
|
||||
class="bhote-embedded-callout"
|
||||
:class="[
|
||||
`is-${card.provider}`,
|
||||
{
|
||||
'is-portrait': card.portrait,
|
||||
'is-entering': card.entering,
|
||||
'is-leaving': card.leaving,
|
||||
'is-unavailable': card.unavailable,
|
||||
},
|
||||
]"
|
||||
:data-provider="card.provider"
|
||||
:aria-label="card.label"
|
||||
>
|
||||
<svg
|
||||
:ref="(el) => card.bind('leader', el)"
|
||||
class="bhote-embedded-callout-leader"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
pathLength="1"
|
||||
fill="none"
|
||||
stroke="rgba(147,213,228,.72)"
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
<circle r="4" fill="#6be8ff" stroke="#ffffff" stroke-width="1.5" />
|
||||
</svg>
|
||||
<div class="bhote-embedded-callout-body" data-overlay-input>
|
||||
<div
|
||||
v-if="card.frame"
|
||||
:ref="(el) => card.bind('player', el)"
|
||||
class="bhote-embedded-callout-player ui-scroll"
|
||||
>
|
||||
<iframe
|
||||
:ref="(el) => card.bind('frameElement', el)"
|
||||
:src="card.frame.src"
|
||||
:title="card.frame.title"
|
||||
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
||||
allowfullscreen
|
||||
loading="eager"
|
||||
referrerpolicy="strict-origin-when-cross-origin"
|
||||
@load.once="card.frame.onLoad"
|
||||
></iframe>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
:ref="(el) => card.bind('player', el)"
|
||||
class="bhote-embedded-callout-player ui-scroll"
|
||||
></div>
|
||||
<footer>
|
||||
<strong>{{ card.title }}</strong>
|
||||
<small role="status">{{ card.status }}</small>
|
||||
<a :href="card.url" target="_blank" rel="noopener noreferrer">{{
|
||||
t('OPEN ORIGINAL ↗')
|
||||
}}</a>
|
||||
</footer>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,119 @@
|
||||
// The Bhote Koshi event's controls are the kit's: its reconstruction panel
|
||||
// hand-writes no <button> and no Material Symbols span, its buttons are ghost
|
||||
// UiButtons that keep their data-action hooks for bhote-koshi.css and the
|
||||
// tests, and its cinematic button is a pressed toggle whose state the event
|
||||
// layer presents as `pressed`, not as an `aria-pressed` it writes. The
|
||||
// embedded media cards are an SFC rather than markup built in script; they
|
||||
// hold no control (the original link stays a link), and the script builds
|
||||
// only what the provider SDKs need: their script and preconnect tags, the
|
||||
// overlay root, and the Facebook player node it warms and carries into a
|
||||
// card.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const read = (file) =>
|
||||
readFileSync(new URL(`../../${file}`, import.meta.url), 'utf8');
|
||||
/** The template block: everything outside script, style and comments. */
|
||||
const template = (file) =>
|
||||
read(file)
|
||||
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
|
||||
.replace(/<!--[\s\S]*?-->/g, '');
|
||||
// An opening tag's attributes, quoted values may hold `>` (`() => x`).
|
||||
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
|
||||
const tags = (markup, name) =>
|
||||
markup.match(new RegExp(String.raw`<${name}\b${ATTRS}>`, 'g')) ?? [];
|
||||
// An attribute's name, outside the quoted values.
|
||||
const names = (attrs) => attrs.replace(/"[^"]*"|'[^']*'/g, '""');
|
||||
|
||||
const PANEL = 'ui/views/panels/BhoteKoshiPanel.vue';
|
||||
const CARDS = 'ui/bhoteKoshi/BhoteKoshiMediaCards.vue';
|
||||
// Per file: its UiButtons, UiCloseButtons, UiSliders and UiIcons.
|
||||
const SURFACES = {
|
||||
// Previous and next beat, Play, Play scene, Cinematic, Full story, Open
|
||||
// original, Lower gorge, a field report (one tag, one per report) and Open
|
||||
// public map; Close; the split and progress sliders.
|
||||
[PANEL]: [10, 1, 2, 0],
|
||||
// The media cards: a frame, a leader, a footer and the original link.
|
||||
[CARDS]: [0, 0, 0, 0],
|
||||
};
|
||||
|
||||
test('the Bhote Koshi views hand-write no button; each is a kit button', () => {
|
||||
for (const [file, [buttons, closes, sliders]] of Object.entries(SURFACES)) {
|
||||
const markup = template(file);
|
||||
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
|
||||
assert.deepEqual(markup.match(/<(select|input)\b/gi) ?? [], [], file);
|
||||
assert.equal(tags(markup, 'UiButton').length, buttons, file);
|
||||
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
|
||||
assert.equal(tags(markup, 'UiSlider').length, sliders, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the Bhote Koshi views hand-write no Material glyph', () => {
|
||||
for (const [file, [, , , icons]] of Object.entries(SURFACES)) {
|
||||
const markup = template(file);
|
||||
assert.deepEqual(markup.match(/material-symbols/g) ?? [], [], file);
|
||||
const found = tags(markup, 'UiIcon');
|
||||
assert.equal(found.length, icons, file);
|
||||
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the cinematic button takes the kit pressed state', () => {
|
||||
for (const file of Object.keys(SURFACES))
|
||||
for (const [tag, attrs] of template(file).matchAll(
|
||||
new RegExp(String.raw`<[A-Za-z][\w-]*\b(${ATTRS})>`, 'g'),
|
||||
)) {
|
||||
assert.doesNotMatch(
|
||||
names(attrs),
|
||||
/(?:^|\s)(?::|v-bind:)?aria-pressed(?=[\s=/]|$)/,
|
||||
tag,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
attrs,
|
||||
/(?:^|\s)(?:v-bind|:)=(?:"[^"]*aria-?pressed[^"]*"|'[^']*aria-?pressed[^']*')/i,
|
||||
tag,
|
||||
);
|
||||
}
|
||||
const pressed = tags(template(PANEL), 'UiButton').filter((tag) =>
|
||||
/\s:pressed=/.test(tag),
|
||||
);
|
||||
assert.equal(pressed.length, 1);
|
||||
assert.match(
|
||||
pressed[0],
|
||||
/^<UiButton data-action="cinematic" :pressed="Boolean\(panel\.refs\.cinematicButton\.pressed\)"/,
|
||||
);
|
||||
// bhote-koshi.css styles the pressed button by its aria-pressed.
|
||||
assert.doesNotMatch(pressed[0], /pressed-class/);
|
||||
// The layer presents the state; it writes no aria-pressed of its own.
|
||||
const layer = read('data/bhoteKoshiEvent.js');
|
||||
assert.doesNotMatch(layer, /aria-pressed/);
|
||||
assert.match(
|
||||
layer,
|
||||
/setElementProperty\(button, 'pressed', _cinematicActive\)/,
|
||||
);
|
||||
});
|
||||
|
||||
test('the media cards are drawn by their view, not built in script', () => {
|
||||
const source = read('data/bhoteKoshiEmbeddedMedia.js');
|
||||
assert.doesNotMatch(source, /innerHTML|insertAdjacentHTML|createElementNS/);
|
||||
// Provider scripts and preconnects, the overlay root, and the Facebook
|
||||
// embed node and its warm host.
|
||||
assert.deepEqual(
|
||||
[...source.matchAll(/createElement\('(\w+)'\)/g)].map((m) => m[1]),
|
||||
['script', 'script', 'script', 'link', 'div', 'div', 'div'],
|
||||
);
|
||||
assert.match(source, /renderVue\(\s*h\(BhoteKoshiMediaCards,/);
|
||||
const cards = template(CARDS);
|
||||
const opening = (name, attribute) =>
|
||||
new RegExp(String.raw`<${name}\b${ATTRS}\s${attribute}${ATTRS}>`);
|
||||
for (const part of [
|
||||
opening('iframe', 'class="bhote-embedded-media-warmup"'),
|
||||
opening('section', 'class="bhote-embedded-callout"'),
|
||||
opening('svg', 'class="bhote-embedded-callout-leader"'),
|
||||
opening('div', 'class="bhote-embedded-callout-body" data-overlay-input'),
|
||||
opening('small', 'role="status"'),
|
||||
opening('a', 'target="_blank" rel="noopener noreferrer"'),
|
||||
])
|
||||
assert.match(cards, part);
|
||||
});
|
||||
@@ -18,9 +18,6 @@ const REPO_ROOT = path.resolve(SRC_ROOT, '..');
|
||||
// The pressed toggles that still hand-write `aria-pressed`, by file: each
|
||||
// pattern matches exactly one of the file's tags, and no other tag may.
|
||||
const HAND_WRITTEN_PRESSED = {
|
||||
// The cinematic button renders the attributes the Bhote Koshi layer
|
||||
// writes for it, `aria-pressed` among them.
|
||||
'src/ui/views/panels/BhoteKoshiPanel.vue': [/^<button\b[^]*\bcinematic/],
|
||||
// Explore's story cards are `role="button"` elements, not buttons.
|
||||
'src/ui/views/stories/ExploreScreen.vue': [
|
||||
/^<div class="card" role="button"/,
|
||||
|
||||
@@ -13,7 +13,8 @@ export const useBhoteKoshiPanelStore = defineStore(
|
||||
/**
|
||||
* `{owner, sceneBeat, refs, beforeDate, afterDate, reports}`, or null while
|
||||
* the event layer is off. Each entry of `refs` holds one control's
|
||||
* `textContent`, `hidden`, `disabled`, `value` and `attributes`.
|
||||
* `textContent`, `hidden`, `disabled`, `value` and `attributes`; the
|
||||
* cinematic button's also holds `pressed`.
|
||||
*/
|
||||
const panel = shallowRef(null);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { useBhoteKoshiPanelStore } from '../../stores/bhoteKoshiPanel.js';
|
||||
import UiButton from '../../kit/UiButton.vue';
|
||||
import UiCloseButton from '../../kit/UiCloseButton.vue';
|
||||
import UiSlider from '../../kit/UiSlider.js';
|
||||
|
||||
@@ -44,30 +45,30 @@ const sliderValue = (event, scale) => Number(event.target.value) / scale;
|
||||
</div>
|
||||
<UiSlider class="bhote-event-range flood" unstyled data-role="progress" min="0" max="1000" :model-value="panel.refs.progressInput.value" :hidden="panel.refs.progressInput.hidden" :disabled="panel.refs.progressInput.disabled" :aria-label="panel.refs.progressInput.attributes['aria-label']" @update:model-value="call('previewProgress', $event / 1000)" @change="call('commitProgress', sliderValue($event, 1000), { final: true })" />
|
||||
<div class="bhote-event-story-nav" :aria-label="t('Story beat navigation')">
|
||||
<button type="button" data-action="previous-beat" :title="t('Previous story beat')" :aria-label="panel.refs.previousButton.attributes['aria-label']" :disabled="panel.refs.previousButton.disabled" @click="call('previousBeat')">‹</button>
|
||||
<UiButton data-action="previous-beat" :title="t('Previous story beat')" :aria-label="panel.refs.previousButton.attributes['aria-label']" :disabled="panel.refs.previousButton.disabled" @click="call('previousBeat')">‹</UiButton>
|
||||
<div class="bhote-event-story-current">
|
||||
<span data-role="beat-index">{{ panel.refs.beatIndex.textContent }}</span>
|
||||
<strong data-role="beat-title" aria-live="polite">{{ panel.refs.beatTitle.textContent }}</strong>
|
||||
<small data-role="beat-meta">{{ panel.refs.beatMeta.textContent }}</small>
|
||||
</div>
|
||||
<button type="button" data-action="next-beat" :title="t('Next story beat')" :aria-label="panel.refs.nextButton.attributes['aria-label']" :disabled="panel.refs.nextButton.disabled" @click="call('nextBeat')">›</button>
|
||||
<UiButton data-action="next-beat" :title="t('Next story beat')" :aria-label="panel.refs.nextButton.attributes['aria-label']" :disabled="panel.refs.nextButton.disabled" @click="call('nextBeat')">›</UiButton>
|
||||
</div>
|
||||
<div class="bhote-event-actions">
|
||||
<button type="button" data-action="play" :aria-label="panel.refs.playButton.attributes['aria-label']" :disabled="panel.refs.playButton.disabled" @click="call('play')">{{ panel.refs.playButton.textContent }}</button>
|
||||
<button type="button" data-action="play-scene" :hidden="panel.refs.playSceneButton.hidden" :title="t('Play the next shot and continue through this scene')" :aria-label="panel.refs.playSceneButton.attributes['aria-label']" :disabled="panel.refs.playSceneButton.disabled" @click="call('playScene')">{{ panel.refs.playSceneButton.textContent }}</button>
|
||||
<button type="button" data-action="cinematic" :aria-pressed="panel.refs.cinematicButton.attributes['aria-pressed']" :hidden="panel.refs.cinematicButton.hidden" :disabled="panel.refs.cinematicButton.disabled" @click="call('toggleCinematic')">{{ panel.refs.cinematicButton.textContent }}</button>
|
||||
<button type="button" data-action="story-replay" :aria-label="panel.refs.storyReplayButton.attributes['aria-label']" :hidden="panel.refs.storyReplayButton.hidden" :disabled="panel.refs.storyReplayButton.disabled" @click="call('replayCinematic')">{{ panel.refs.storyReplayButton.textContent }}</button>
|
||||
<button type="button" data-action="open-source" :hidden="panel.refs.openSourceButton.hidden" :disabled="panel.refs.openSourceButton.disabled" @click="call('openActiveSource')">{{ t('↗ OPEN ORIGINAL') }}</button>
|
||||
<button type="button" data-action="corridor" :hidden="panel.refs.corridorButton.hidden" :disabled="panel.refs.corridorButton.disabled" @click="call('focusCorridor')">{{ t('⌖ LOWER GORGE') }}</button>
|
||||
<UiButton data-action="play" :aria-label="panel.refs.playButton.attributes['aria-label']" :disabled="panel.refs.playButton.disabled" @click="call('play')">{{ panel.refs.playButton.textContent }}</UiButton>
|
||||
<UiButton data-action="play-scene" :hidden="panel.refs.playSceneButton.hidden" :title="t('Play the next shot and continue through this scene')" :aria-label="panel.refs.playSceneButton.attributes['aria-label']" :disabled="panel.refs.playSceneButton.disabled" @click="call('playScene')">{{ panel.refs.playSceneButton.textContent }}</UiButton>
|
||||
<UiButton data-action="cinematic" :pressed="Boolean(panel.refs.cinematicButton.pressed)" :hidden="panel.refs.cinematicButton.hidden" :disabled="panel.refs.cinematicButton.disabled" @click="call('toggleCinematic')">{{ panel.refs.cinematicButton.textContent }}</UiButton>
|
||||
<UiButton data-action="story-replay" :aria-label="panel.refs.storyReplayButton.attributes['aria-label']" :hidden="panel.refs.storyReplayButton.hidden" :disabled="panel.refs.storyReplayButton.disabled" @click="call('replayCinematic')">{{ panel.refs.storyReplayButton.textContent }}</UiButton>
|
||||
<UiButton data-action="open-source" :hidden="panel.refs.openSourceButton.hidden" :disabled="panel.refs.openSourceButton.disabled" @click="call('openActiveSource')">{{ t('↗ OPEN ORIGINAL') }}</UiButton>
|
||||
<UiButton data-action="corridor" :hidden="panel.refs.corridorButton.hidden" :disabled="panel.refs.corridorButton.disabled" @click="call('focusCorridor')">{{ t('⌖ LOWER GORGE') }}</UiButton>
|
||||
</div>
|
||||
</section>
|
||||
<details class="bhote-event-evidence">
|
||||
<summary>{{ t('FIELD REPORTS · {count}', { count: panel.reports.length }) }}</summary>
|
||||
<div class="bhote-event-report-list"><button v-for="(report, index) in panel.reports" :key="index" type="button" class="bhote-event-report" @click="call('openReport', index)"><span>{{ report.label }}</span><small>{{ report.status }}</small></button></div>
|
||||
<div class="bhote-event-report-list"><UiButton v-for="(report, index) in panel.reports" :key="index" class="bhote-event-report" @click="call('openReport', index)"><span>{{ report.label }}</span><small>{{ report.status }}</small></UiButton></div>
|
||||
</details>
|
||||
<div class="bhote-event-credit">
|
||||
<span>{{ t('GEOLOCATIONS · {credit}', { credit: 'GEO GEORGE SHADRACH' }) }}</span>
|
||||
<button type="button" data-action="geolocation-map" @click="call('openGeolocationMap')">{{ t('↗ OPEN PUBLIC MAP') }}</button>
|
||||
<UiButton data-action="geolocation-map" @click="call('openGeolocationMap')">{{ t('↗ OPEN PUBLIC MAP') }}</UiButton>
|
||||
</div>
|
||||
<p class="bhote-event-caveat"><span data-role="caveat">{{ panel.refs.caveat.textContent }}</span><span data-role="imagery-cloud-note" :hidden="panel.refs.imageryCloudNote.hidden">{{ t(' Clouds are preserved from the source imagery.') }}</span></p>
|
||||
</aside>
|
||||
|
||||
Reference in new issue
Block a user