Place the event's media cards through the renderer's ports and take them off the Cesium list

The embedded media cards find their anchor on screen through the camera
port's pose (whether it is behind the eye) and the query port's
projection, read the renderer's canvas for its offset, and follow the
camera on the frame port's postRender. The card root still goes in the
viewer's container, which is DOM. A test binds the three ports and checks
the card follows its anchor, hides behind the eye, and unsubscribes on
destroy.
This commit is contained in:
Sameh Khamis committed 2026-11-07 06:06:19 -08:00
1 parent cdbbf8c705
commit 4cbfd6e12d
3 files changed
+75 -18

No files matched your search

+53
View File
@@ -10,6 +10,7 @@ import {
publicEmbeddedMediaUrl,
resolveEmbeddedMediaSource,
} from './bhoteKoshiEmbeddedMedia.js';
import { bindRenderer } from '../render/rendererOf.js';
test('Pinokio fallback never creates provider DOM or loads SDKs', async () => {
const unexpected = () => { throw new Error('Provider resource allocated in Pinokio'); };
@@ -417,3 +418,55 @@ test('a media card stays between the panels when right-to-left swaps their sides
assert.ok(left >= 340 + 18, `card at ${left}px lands on the context rail`);
assert.ok(left + 392 <= 1040 - 18, `card at ${left}px lands on the scene panel`);
});
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 }) } };
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.
const unbind = bindRenderer(viewer, {
canvas: { getBoundingClientRect: () => ({ left: 10, top: 5 }) },
camera: { pose: () => pose },
query: { project: (p) => { projected.push(p); return { x: 300, y: 200 }; } },
frame: {
on(phase, cb) {
const entry = [phase, cb];
listeners.add(entry);
return () => listeners.delete(entry);
},
},
});
const media = createBhoteKoshiEmbeddedMedia({ viewer, documentRef, globalRef: {} });
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');
assert.equal(card.hidden, false);
assert.equal(projected.at(-1), anchor);
assert.equal(card.style.left, `${300 + 10 + 42}px`);
// Behind the eye: hidden on the next drawn frame.
pose = { ...pose, direction: { x: -1, y: 0, z: 0 } };
for (const [, cb] of listeners) cb();
assert.equal(card.hidden, true);
media.destroy();
assert.equal(listeners.size, 0);
unbind();
});