mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 01:58:41 +01:00
Merge pull request #3580 from rommapp/claude/youthful-wozniak-ocjhc0
feat(v2): interactive 3D box art on the game detail hero
This commit is contained in:
@@ -73,6 +73,7 @@ class MetadataMediaType(enum.StrEnum):
|
||||
BEZEL = "bezel"
|
||||
BOX2D = "box2d"
|
||||
BOX2D_BACK = "box2d_back"
|
||||
BOX2D_SIDE = "box2d_side"
|
||||
BOX3D = "box3d"
|
||||
MIXIMAGE = "miximage"
|
||||
MIXIMAGE_V2 = "miximage_v2"
|
||||
|
||||
@@ -183,6 +183,7 @@ class SSMetadataMedia(TypedDict):
|
||||
# Resources stored in filesystem
|
||||
bezel_path: str | None
|
||||
box2d_back_path: str | None
|
||||
box2d_side_path: str | None
|
||||
box3d_path: str | None
|
||||
fanart_path: str | None
|
||||
miximage_path: str | None
|
||||
@@ -244,6 +245,7 @@ def extract_media_from_ss_game(rom: Rom, game: SSGame) -> SSMetadataMedia:
|
||||
video_normalized_url=None,
|
||||
bezel_path=None,
|
||||
box2d_back_path=None,
|
||||
box2d_side_path=None,
|
||||
box3d_path=None,
|
||||
fanart_path=None,
|
||||
miximage_path=None,
|
||||
@@ -358,6 +360,10 @@ def extract_media_from_ss_game(rom: Rom, game: SSGame) -> SSMetadataMedia:
|
||||
ss_media["box2d_side_url"] = strip_sensitive_query_params(
|
||||
media["url"], SENSITIVE_KEYS
|
||||
)
|
||||
if MetadataMediaType.BOX2D_SIDE in preferred_media_types:
|
||||
ss_media["box2d_side_path"] = (
|
||||
f"{fs_resource_handler.get_media_resources_path(rom.platform_id, rom.id, MetadataMediaType.BOX2D_SIDE)}/box2d_side.png"
|
||||
)
|
||||
elif media.get("type") == "steamgrid" and not ss_media["steamgrid_url"]:
|
||||
ss_media["steamgrid_url"] = strip_sensitive_query_params(
|
||||
media["url"], SENSITIVE_KEYS
|
||||
|
||||
@@ -208,6 +208,86 @@ class TestExtractMediaFromSsGame:
|
||||
assert result["box2d_url"] is not None
|
||||
assert "box-2D(us)" in result["box2d_url"]
|
||||
|
||||
def _make_game_with_box_faces(self) -> SSGame:
|
||||
"""A game exposing all three box faces: front, back and spine."""
|
||||
return cast(
|
||||
SSGame,
|
||||
{
|
||||
"medias": [
|
||||
{
|
||||
"type": "box-2D",
|
||||
"parent": "jeu",
|
||||
"region": "us",
|
||||
"url": "https://screenscraper.example.com/box-2D",
|
||||
"crc": "aabbccdd",
|
||||
"md5": "deadbeef",
|
||||
"sha1": "cafebabe",
|
||||
"size": "12345",
|
||||
"format": "png",
|
||||
},
|
||||
{
|
||||
"type": "box-2D-back",
|
||||
"parent": "jeu",
|
||||
"region": "us",
|
||||
"url": "https://screenscraper.example.com/box-2D-back",
|
||||
"crc": "11223344",
|
||||
"md5": "feedface",
|
||||
"sha1": "baadf00d",
|
||||
"size": "23456",
|
||||
"format": "png",
|
||||
},
|
||||
{
|
||||
"type": "box-2D-side",
|
||||
"parent": "jeu",
|
||||
"region": "us",
|
||||
"url": "https://screenscraper.example.com/box-2D-side",
|
||||
"crc": "55667788",
|
||||
"md5": "0ddba11",
|
||||
"sha1": "f00dcafe",
|
||||
"size": "34567",
|
||||
"format": "png",
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
def test_box2d_side_path_set_when_in_config(self):
|
||||
"""When 'box2d_side' is in SCAN_MEDIA the spine is persisted locally."""
|
||||
config = _make_config(scan_media=["box2d", "box2d_back", "box2d_side"])
|
||||
rom = self._make_rom()
|
||||
game = self._make_game_with_box_faces()
|
||||
|
||||
with (
|
||||
patch("handler.metadata.ss_handler.cm.get_config", return_value=config),
|
||||
patch(
|
||||
"handler.metadata.ss_handler.fs_resource_handler.get_media_resources_path",
|
||||
side_effect=lambda pid, rid, mt: f"roms/{pid}/{rid}/{mt.value}",
|
||||
),
|
||||
):
|
||||
result = extract_media_from_ss_game(rom, game)
|
||||
|
||||
assert result["box2d_side_url"] is not None
|
||||
assert "box-2D-side" in result["box2d_side_url"]
|
||||
assert result["box2d_side_path"] == "roms/1/100/box2d_side/box2d_side.png"
|
||||
|
||||
def test_box2d_side_path_not_set_when_absent_from_config(self):
|
||||
"""Without 'box2d_side' in SCAN_MEDIA the spine URL is kept but not stored."""
|
||||
config = _make_config(scan_media=["box2d", "box2d_back"])
|
||||
rom = self._make_rom()
|
||||
game = self._make_game_with_box_faces()
|
||||
|
||||
with (
|
||||
patch("handler.metadata.ss_handler.cm.get_config", return_value=config),
|
||||
patch(
|
||||
"handler.metadata.ss_handler.fs_resource_handler.get_media_resources_path",
|
||||
side_effect=lambda pid, rid, mt: f"roms/{pid}/{rid}/{mt.value}",
|
||||
),
|
||||
):
|
||||
result = extract_media_from_ss_game(rom, game)
|
||||
|
||||
assert result["box2d_side_url"] is not None
|
||||
assert result["box2d_side_path"] is None
|
||||
|
||||
def _make_game_with_both_miximage_versions(self) -> SSGame:
|
||||
"""A game that has both mixrbv1 and mixrbv2 (v1 listed first, matching SS API order)."""
|
||||
return cast(
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
# - video_normalized # Normalized video (smaller file size than video)
|
||||
# # Media used for batocera gamelist.xml export
|
||||
# - box2d_back # Back cover art
|
||||
# - box2d_side # Box spine (enables the interactive 3D box on detail pages)
|
||||
# - logo # Transparent logo
|
||||
# # Other media assets (might be used in the future)
|
||||
# - marquee # Custom marquee
|
||||
|
||||
@@ -24,6 +24,7 @@ export type RomSSMetadata = {
|
||||
video_normalized_url?: (string | null);
|
||||
bezel_path?: (string | null);
|
||||
box2d_back_path?: (string | null);
|
||||
box2d_side_path?: (string | null);
|
||||
box3d_path?: (string | null);
|
||||
fanart_path?: (string | null);
|
||||
miximage_path?: (string | null);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Възрастова оценка",
|
||||
"all-styles": "Всички стилове",
|
||||
"backlogged": "В списъка",
|
||||
"box3d-alt": "Въртяща се 3D кутия за {title}",
|
||||
"by": "от",
|
||||
"cant-copy-link": "Линкът не може да бъде копиран, копирай го ръчно",
|
||||
"collections": "Колекции",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Hodnocení věku",
|
||||
"all-styles": "Všechny styly",
|
||||
"backlogged": "Odloženo",
|
||||
"box3d-alt": "Otočná 3D krabice pro {title}",
|
||||
"by": "od",
|
||||
"cant-copy-link": "Nelze zkopírovat odkaz do schránky, zkopírujte ručně",
|
||||
"collections": "Kolekce",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Altersfreigabe",
|
||||
"all-styles": "Alle Stile",
|
||||
"backlogged": "Vorgemerkt",
|
||||
"box3d-alt": "Drehbares 3D-Cover von {title}",
|
||||
"by": "nach",
|
||||
"cant-copy-link": "Link kann nicht in Zwischenablage kopiert werden. Bitte manuell kopieren.",
|
||||
"collections": "Sammlungen",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Age rating",
|
||||
"all-styles": "All Styles",
|
||||
"backlogged": "Backlogged",
|
||||
"box3d-alt": "Rotatable 3D box art for {title}",
|
||||
"by": "by",
|
||||
"cant-copy-link": "Can't copy link to clipboard, copy it manually",
|
||||
"collections": "Collections",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Age rating",
|
||||
"all-styles": "All Styles",
|
||||
"backlogged": "Backlogged",
|
||||
"box3d-alt": "Rotatable 3D box art for {title}",
|
||||
"by": "by",
|
||||
"cant-copy-link": "Can't copy link to clipboard, copy it manually",
|
||||
"collections": "Collections",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Clasificación por edad",
|
||||
"all-styles": "Todos los Estilos",
|
||||
"backlogged": "Pendiente",
|
||||
"box3d-alt": "Carátula 3D giratoria de {title}",
|
||||
"by": "por",
|
||||
"cant-copy-link": "No se pudo copiar el link al portapapeles, copialo manualmente",
|
||||
"collections": "Colecciones",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Classification par âge",
|
||||
"all-styles": "Tous les Styles",
|
||||
"backlogged": "En attente",
|
||||
"box3d-alt": "Boîtier 3D pivotant de {title}",
|
||||
"by": "par",
|
||||
"cant-copy-link": "Impossible de copier le lien dans le presse-papiers, copiez-le manuellement",
|
||||
"collections": "Collections",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Korhatár",
|
||||
"all-styles": "Minden stílus",
|
||||
"backlogged": "Függőben",
|
||||
"box3d-alt": "Forgatható 3D doboz: {title}",
|
||||
"by": "általa",
|
||||
"cant-copy-link": "A linket nem lehet a vágólapra másolni, kézzel kell.",
|
||||
"collections": "Gyűjtemények",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Classificazione età",
|
||||
"all-styles": "Tutti gli Stili",
|
||||
"backlogged": "In attesa",
|
||||
"box3d-alt": "Confezione 3D ruotabile di {title}",
|
||||
"by": "di",
|
||||
"cant-copy-link": "Impossibile copiare il link negli appunti, copialo manualmente",
|
||||
"collections": "Collezioni",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "レーティング",
|
||||
"all-styles": "全スタイル",
|
||||
"backlogged": "未処理",
|
||||
"box3d-alt": "{title} の回転式3Dボックスアート",
|
||||
"by": "by",
|
||||
"cant-copy-link": "クリップボードへのコピー失敗 手動でコピーしてください",
|
||||
"collections": "コレクション",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "연령 제한",
|
||||
"all-styles": "모든 스타일",
|
||||
"backlogged": "나중에 플레이",
|
||||
"box3d-alt": "{title}의 회전 가능한 3D 박스 아트",
|
||||
"by": "분류",
|
||||
"cant-copy-link": "링크를 클립보드에 복사할 수 없습니다. 수동으로 복사합니다",
|
||||
"collections": "시리즈",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Kategoria wiekowa",
|
||||
"all-styles": "Wszystkie Style",
|
||||
"backlogged": "Zaległe",
|
||||
"box3d-alt": "Obracane pudełko 3D dla {title}",
|
||||
"by": "przez",
|
||||
"cant-copy-link": "Nie można skopiować linku do schowka, skopiuj go ręcznie",
|
||||
"collections": "Kolekcje",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Classificação etária",
|
||||
"all-styles": "Todos os Estilos",
|
||||
"backlogged": "Em espera",
|
||||
"box3d-alt": "Caixa 3D giratória de {title}",
|
||||
"by": "por",
|
||||
"cant-copy-link": "Não é possível copiar o link para a área de transferência, copie manualmente",
|
||||
"collections": "Coleções",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Clasificare pe vârstă",
|
||||
"all-styles": "Toate Stilurile",
|
||||
"backlogged": "În așteptare",
|
||||
"box3d-alt": "Cutie 3D rotativă pentru {title}",
|
||||
"by": "de",
|
||||
"cant-copy-link": "Nu s-a putut copia linkul în clipboard, copiază-l manual",
|
||||
"collections": "Colecții",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "Возрастной рейтинг",
|
||||
"all-styles": "Все Стили",
|
||||
"backlogged": "Отложено",
|
||||
"box3d-alt": "Вращающаяся 3D-коробка для {title}",
|
||||
"by": "от",
|
||||
"cant-copy-link": "Не удается скопировать ссылку в буфер обмена, скопируйте ее вручную",
|
||||
"collections": "Коллекции",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "年龄分级",
|
||||
"all-styles": "所有风格",
|
||||
"backlogged": "待办",
|
||||
"box3d-alt": "{title} 的可旋转 3D 包装盒",
|
||||
"by": "根据",
|
||||
"cant-copy-link": "无法将链接复制到剪贴板,请手动复制",
|
||||
"collections": "收藏",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"age-rating": "年龄分级",
|
||||
"all-styles": "所有風格",
|
||||
"backlogged": "待遊玩",
|
||||
"box3d-alt": "{title} 的可旋轉 3D 包裝盒",
|
||||
"by": "依據",
|
||||
"cant-copy-link": "無法複製下載鏈接到剪貼簿,請手動複製",
|
||||
"collections": "收藏庫",
|
||||
|
||||
@@ -4,20 +4,55 @@
|
||||
// the procedural placeholder when empty, and is the destination of the
|
||||
// shared-element morph from the GameCard the user clicked through from —
|
||||
// all of that lives in GameCover now; this just sizes the column.
|
||||
//
|
||||
// When the gallery boxart style is the 3D box AND the rom has the full set
|
||||
// of flat scans (front + back + spine, from ScreenScraper), the hero
|
||||
// upgrades to the interactive RBox3D the user can spin. Anything missing —
|
||||
// a different style, an incomplete set, or a failed image — falls straight
|
||||
// back to the flat GameCover.
|
||||
import { RBox3D } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useUISettings } from "@/composables/useUISettings";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import GameCover from "@/v2/components/shared/GameCover.vue";
|
||||
import { useBoxFaces } from "@/v2/composables/useBoxFaces";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
rom: DetailedRom;
|
||||
alt: string;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const { boxartStyle } = useUISettings();
|
||||
const faces = useBoxFaces(() => props.rom);
|
||||
const box3dFailed = ref(false);
|
||||
|
||||
// Resolved faces, or null when the interactive box can't / shouldn't render.
|
||||
// Returning the concrete object keeps the template free of non-null asserts.
|
||||
const box3d = computed(() => {
|
||||
if (boxartStyle.value !== "box3d_path" || box3dFailed.value) return null;
|
||||
const f = faces.value;
|
||||
if (!f.complete || !f.front || !f.back || !f.spine) return null;
|
||||
return { front: f.front, back: f.back, spine: f.spine };
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="r-v2-det-cover">
|
||||
<RBox3D
|
||||
v-if="box3d"
|
||||
class="r-v2-det-cover__box3d"
|
||||
:front="box3d.front"
|
||||
:back="box3d.back"
|
||||
:spine="box3d.spine"
|
||||
:alt="t('rom.box3d-alt', { title: alt })"
|
||||
@error="box3dFailed = true"
|
||||
/>
|
||||
<GameCover
|
||||
v-else
|
||||
class="r-v2-det-cover__art"
|
||||
:rom="rom"
|
||||
:title="alt"
|
||||
|
||||
78
frontend/src/v2/composables/useBoxFaces/index.ts
Normal file
78
frontend/src/v2/composables/useBoxFaces/index.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
// useBoxFaces — resolves the three flat scans an interactive 3D box needs
|
||||
// (front / back / spine) for a rom, and reports whether the full set is
|
||||
// available.
|
||||
//
|
||||
// * front — the rom's own cover chain (the ScreenScraper box-2D front
|
||||
// becomes the cover on match), webp-rewritten like everywhere
|
||||
// else.
|
||||
// * back — ss_metadata.box2d_back_path
|
||||
// * spine — ss_metadata.box2d_side_path
|
||||
//
|
||||
// Back and spine are persisted locally only when the user enabled the
|
||||
// `box2d_back` / `box2d_side` media types in `scan.media`, so `complete`
|
||||
// is false for most libraries until they opt in and re-scan. RBox3D is
|
||||
// only mounted when `complete` is true; otherwise the surface keeps the
|
||||
// flat cover.
|
||||
import {
|
||||
computed,
|
||||
toValue,
|
||||
type ComputedRef,
|
||||
type MaybeRefOrGetter,
|
||||
} from "vue";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import { FRONTEND_RESOURCES_PATH } from "@/utils";
|
||||
import { useWebpSupport } from "@/v2/composables/useWebpSupport";
|
||||
|
||||
/** The face-relevant slice of a rom — satisfied by both `SimpleRom` and
|
||||
* `DetailedRom`. */
|
||||
export type BoxFacesRom = Pick<
|
||||
SimpleRom,
|
||||
"ss_metadata" | "path_cover_large" | "path_cover_small"
|
||||
>;
|
||||
|
||||
export interface BoxFaces {
|
||||
front: string | null;
|
||||
back: string | null;
|
||||
spine: string | null;
|
||||
/** All three faces resolved → the rom can render as a real 3D box. */
|
||||
complete: boolean;
|
||||
}
|
||||
|
||||
const RASTER_EXT = /\.(png|jpe?g)$/i;
|
||||
|
||||
function resourceUrl(path: string | null | undefined): string | null {
|
||||
return path ? `${FRONTEND_RESOURCES_PATH}/${path}` : null;
|
||||
}
|
||||
|
||||
/** Pure resolution core — no Vue, exported for unit tests. */
|
||||
export function computeBoxFaces(
|
||||
rom: BoxFacesRom,
|
||||
supportsWebp: boolean,
|
||||
): BoxFaces {
|
||||
const localCover = rom.path_cover_large ?? rom.path_cover_small ?? null;
|
||||
const front =
|
||||
localCover && supportsWebp
|
||||
? localCover.replace(RASTER_EXT, ".webp")
|
||||
: localCover;
|
||||
|
||||
const back = resourceUrl(rom.ss_metadata?.box2d_back_path);
|
||||
const spine = resourceUrl(rom.ss_metadata?.box2d_side_path);
|
||||
|
||||
return {
|
||||
front,
|
||||
back,
|
||||
spine,
|
||||
complete: Boolean(front && back && spine),
|
||||
};
|
||||
}
|
||||
|
||||
export function useBoxFaces(
|
||||
rom: MaybeRefOrGetter<BoxFacesRom | null | undefined>,
|
||||
): ComputedRef<BoxFaces> {
|
||||
const { supportsWebp } = useWebpSupport();
|
||||
return computed(() => {
|
||||
const r = toValue(rom);
|
||||
if (!r) return { front: null, back: null, spine: null, complete: false };
|
||||
return computeBoxFaces(r, supportsWebp.value);
|
||||
});
|
||||
}
|
||||
81
frontend/src/v2/composables/useBoxFaces/useBoxFaces.test.ts
Normal file
81
frontend/src/v2/composables/useBoxFaces/useBoxFaces.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import { computeBoxFaces, type BoxFacesRom } from "./index";
|
||||
|
||||
const RES = "/assets/romm/resources";
|
||||
|
||||
// Minimal rom factory — computeBoxFaces only reads the cover chain and the
|
||||
// two ss_metadata path fields. Single cast scoped to the test.
|
||||
function rom(over: Partial<SimpleRom>): BoxFacesRom {
|
||||
const base: Partial<SimpleRom> = {
|
||||
path_cover_large: null,
|
||||
path_cover_small: null,
|
||||
ss_metadata: null,
|
||||
};
|
||||
return { ...base, ...over } as BoxFacesRom;
|
||||
}
|
||||
|
||||
describe("computeBoxFaces", () => {
|
||||
it("is incomplete when the rom only has a cover", () => {
|
||||
const faces = computeBoxFaces(
|
||||
rom({ path_cover_large: "roms/1/1/cover/l.png" }),
|
||||
false,
|
||||
);
|
||||
expect(faces.front).toBe("roms/1/1/cover/l.png");
|
||||
expect(faces.back).toBeNull();
|
||||
expect(faces.spine).toBeNull();
|
||||
expect(faces.complete).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves all three faces and reports complete", () => {
|
||||
const faces = computeBoxFaces(
|
||||
rom({
|
||||
path_cover_large: "roms/1/1/cover/l.png",
|
||||
ss_metadata: {
|
||||
box2d_back_path: "roms/1/1/box2d_back/box2d_back.png",
|
||||
box2d_side_path: "roms/1/1/box2d_side/box2d_side.png",
|
||||
},
|
||||
}),
|
||||
false,
|
||||
);
|
||||
expect(faces.front).toBe("roms/1/1/cover/l.png");
|
||||
expect(faces.back).toBe(`${RES}/roms/1/1/box2d_back/box2d_back.png`);
|
||||
expect(faces.spine).toBe(`${RES}/roms/1/1/box2d_side/box2d_side.png`);
|
||||
expect(faces.complete).toBe(true);
|
||||
});
|
||||
|
||||
it("is incomplete when the spine is missing", () => {
|
||||
const faces = computeBoxFaces(
|
||||
rom({
|
||||
path_cover_large: "roms/1/1/cover/l.png",
|
||||
ss_metadata: { box2d_back_path: "roms/1/1/box2d_back/box2d_back.png" },
|
||||
}),
|
||||
false,
|
||||
);
|
||||
expect(faces.spine).toBeNull();
|
||||
expect(faces.complete).toBe(false);
|
||||
});
|
||||
|
||||
it("rewrites the front cover to webp when supported, leaving faces as png", () => {
|
||||
const faces = computeBoxFaces(
|
||||
rom({
|
||||
path_cover_large: "roms/1/1/cover/l.png",
|
||||
ss_metadata: {
|
||||
box2d_back_path: "roms/1/1/box2d_back/box2d_back.png",
|
||||
box2d_side_path: "roms/1/1/box2d_side/box2d_side.png",
|
||||
},
|
||||
}),
|
||||
true,
|
||||
);
|
||||
expect(faces.front).toBe("roms/1/1/cover/l.webp");
|
||||
expect(faces.back).toBe(`${RES}/roms/1/1/box2d_back/box2d_back.png`);
|
||||
});
|
||||
|
||||
it("falls back to the small cover when the large one is absent", () => {
|
||||
const faces = computeBoxFaces(
|
||||
rom({ path_cover_small: "roms/1/1/cover/s.png" }),
|
||||
false,
|
||||
);
|
||||
expect(faces.front).toBe("roms/1/1/cover/s.png");
|
||||
});
|
||||
});
|
||||
@@ -65,6 +65,7 @@ export * from "./overlays/RDrawer";
|
||||
export * from "./data/RTable";
|
||||
|
||||
// Media
|
||||
export * from "./media/RBox3D";
|
||||
export * from "./media/RPlatformIcon";
|
||||
|
||||
// (GameCard lives under components/GameCard/ — it's a feature
|
||||
|
||||
101
frontend/src/v2/lib/media/RBox3D/RBox3D.stories.ts
Normal file
101
frontend/src/v2/lib/media/RBox3D/RBox3D.stories.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { expect, userEvent } from "storybook/test";
|
||||
import RBox3D from "./RBox3D.vue";
|
||||
|
||||
// Self-contained SVG fixtures so the story needs no network. Named colours
|
||||
// (no hex literals) keep it within the v2 colour policy. The spine is tall
|
||||
// and narrow so the derived box depth looks right.
|
||||
const face = (label: string, w: number, h: number, color: string) =>
|
||||
`data:image/svg+xml,${encodeURIComponent(
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}">` +
|
||||
`<rect width="100%" height="100%" fill="${color}"/>` +
|
||||
`<text x="50%" y="50%" fill="white" font-family="sans-serif" ` +
|
||||
`font-size="${Math.round(Math.min(w, h) / 5)}" text-anchor="middle" ` +
|
||||
`dominant-baseline="middle" transform="rotate(${w < h * 0.4 ? -90 : 0} ${w / 2} ${h / 2})">${label}</text></svg>`,
|
||||
)}`;
|
||||
|
||||
const front = face("FRONT", 286, 400, "rebeccapurple");
|
||||
const back = face("BACK", 286, 400, "darkslateblue");
|
||||
const spine = face("SPINE", 48, 400, "indigo");
|
||||
|
||||
const meta: Meta<typeof RBox3D> = {
|
||||
title: "Media/RBox3D",
|
||||
component: RBox3D,
|
||||
argTypes: {
|
||||
front: { control: "text" },
|
||||
back: { control: "text" },
|
||||
spine: { control: "text" },
|
||||
alt: { control: "text" },
|
||||
autoSpin: { control: "boolean" },
|
||||
initialYaw: { control: { type: "range", min: -180, max: 180, step: 1 } },
|
||||
initialPitch: { control: { type: "range", min: -32, max: 32, step: 1 } },
|
||||
},
|
||||
args: {
|
||||
front,
|
||||
back,
|
||||
spine,
|
||||
alt: "Castlevania",
|
||||
autoSpin: true,
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RBox3D },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width:240px;padding:48px">
|
||||
<RBox3D v-bind="args" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RBox3D>;
|
||||
|
||||
// ── Default: gentle idle drift, drag / arrows / right-stick to rotate ──
|
||||
export const Default: Story = {};
|
||||
|
||||
// ── Static (no auto-spin) — easier to read the faces ──
|
||||
export const Static: Story = {
|
||||
name: "No auto-spin",
|
||||
args: { autoSpin: false, initialYaw: 36, initialPitch: -8 },
|
||||
};
|
||||
|
||||
// ── Side-on, showing the spine ──
|
||||
export const SpineForward: Story = {
|
||||
name: "Spine forward",
|
||||
args: { autoSpin: false, initialYaw: 82, initialPitch: 0 },
|
||||
};
|
||||
|
||||
// ── Interaction: arrow keys (and thus gamepad D-pad) rotate it ──
|
||||
export const KeyboardRotate: Story = {
|
||||
name: "Keyboard rotation",
|
||||
args: { autoSpin: false, initialYaw: 0, initialPitch: 0 },
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const root = canvasElement.querySelector<HTMLElement>(".r-box3d");
|
||||
const box = canvasElement.querySelector<HTMLElement>(".r-box3d__box");
|
||||
expect(root).not.toBeNull();
|
||||
expect(box).not.toBeNull();
|
||||
|
||||
await step("starts at the resting orientation", () => {
|
||||
expect(box!.style.transform).toContain("rotateY(0deg)");
|
||||
expect(box!.style.transform).toContain("rotateX(0deg)");
|
||||
});
|
||||
|
||||
await step("ArrowRight yaws the box", async () => {
|
||||
root!.focus();
|
||||
await userEvent.keyboard("{ArrowRight}");
|
||||
expect(box!.style.transform).toContain("rotateY(14deg)");
|
||||
});
|
||||
|
||||
await step("ArrowUp pitches the box up", async () => {
|
||||
await userEvent.keyboard("{ArrowUp}");
|
||||
expect(box!.style.transform).toContain("rotateX(-14deg)");
|
||||
});
|
||||
|
||||
await step("pitch clamps so the box never flips over", async () => {
|
||||
for (let i = 0; i < 6; i++) await userEvent.keyboard("{ArrowUp}");
|
||||
expect(box!.style.transform).toContain("rotateX(-32deg)");
|
||||
});
|
||||
},
|
||||
};
|
||||
493
frontend/src/v2/lib/media/RBox3D/RBox3D.vue
Normal file
493
frontend/src/v2/lib/media/RBox3D/RBox3D.vue
Normal file
@@ -0,0 +1,493 @@
|
||||
<script setup lang="ts">
|
||||
// RBox3D — a fake-but-believable 3D game box built from three flat scans
|
||||
// (front, back, spine). Six CSS faces under `transform-style: preserve-3d`:
|
||||
// the front/back carry their art, the spine is mirrored onto both left and
|
||||
// right edges, and the top/bottom are tinted "cardboard" edges (tokens, no
|
||||
// literals). Box proportions are derived from the images themselves — the
|
||||
// front's natural ratio sets width/height, the spine's sets the depth — so
|
||||
// a chunky N64 box and a slim DS case both look right without per-platform
|
||||
// tuning.
|
||||
//
|
||||
// Universal input (premise 6): pointer drag rotates it; while focused, the
|
||||
// arrow keys step it (this is what the gamepad D-pad / left stick emit as
|
||||
// synthetic keys), and the right analog stick rotates it continuously (read
|
||||
// directly, so the D-pad can still navigate away). When idle it drifts in a
|
||||
// slow auto-spin — disabled under `prefers-reduced-motion` and paused for a
|
||||
// beat after any manual input. Focus ring is automatic via `tabindex` +
|
||||
// the modality-gated selectors in global.css.
|
||||
//
|
||||
// Primitive boundaries (§II): no stores, no domain knowledge — it takes
|
||||
// three image URLs and a label. The feature composite (CoverColumn) decides
|
||||
// when a rom actually has all three faces and feeds them in.
|
||||
import { computed, onBeforeUnmount, onMounted, ref, type Ref } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
/** Front cover art URL. */
|
||||
front: string;
|
||||
/** Back cover art URL. */
|
||||
back: string;
|
||||
/** Spine (box-2D-side) art URL — mirrored onto both side faces. */
|
||||
spine: string;
|
||||
/** Accessible label (the rom title). Rendered as the box's aria-label. */
|
||||
alt?: string;
|
||||
/** Drift slowly when idle (suppressed under reduced-motion). */
|
||||
autoSpin?: boolean;
|
||||
/** Resting yaw / pitch in degrees, applied before any interaction. */
|
||||
initialYaw?: number;
|
||||
initialPitch?: number;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
alt: "",
|
||||
autoSpin: true,
|
||||
initialYaw: 32,
|
||||
initialPitch: -6,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** The front cover failed to load — the consumer should fall back. */
|
||||
error: [];
|
||||
}>();
|
||||
|
||||
// Tunables.
|
||||
const PITCH_LIMIT = 32; // keep the box readable, never belly-up
|
||||
const DRAG_SENSITIVITY = 0.45; // deg per px
|
||||
const KEY_STEP = 14; // deg per arrow press
|
||||
const STICK_SPEED = 3.2; // deg per frame at full deflection
|
||||
const STICK_DEADZONE = 0.18;
|
||||
const AUTO_SPIN_SPEED = 0.18; // deg per frame when idle
|
||||
const IDLE_RESUME_MS = 2000; // quiet time before auto-spin resumes
|
||||
const FLICK_WINDOW_MS = 60; // release this long after the last move = no flick
|
||||
const MOMENTUM_FRAMES = 12; // how far a flick coasts (× last-frame velocity)
|
||||
const MOMENTUM_MAX = 540; // cap the coast so a hard flick can't whirl forever
|
||||
const DEFAULT_FRONT_RATIO = 0.715; // typical box face w/h until measured
|
||||
const DEFAULT_SPINE_RATIO = 0.12; // depth/height until measured
|
||||
|
||||
const rootEl = ref<HTMLElement | null>(null);
|
||||
const frontImg = ref<HTMLImageElement | null>(null);
|
||||
const spineImg = ref<HTMLImageElement | null>(null);
|
||||
|
||||
// Orientation.
|
||||
const yaw = ref(props.initialYaw);
|
||||
const pitch = ref(props.initialPitch);
|
||||
|
||||
// Measured geometry. `widthPx` comes from a ResizeObserver; the ratios from
|
||||
// the images' natural dimensions on load.
|
||||
const widthPx = ref(0);
|
||||
const frontRatio = ref(DEFAULT_FRONT_RATIO); // front w / h → box w / h
|
||||
const spineRatio = ref(DEFAULT_SPINE_RATIO); // spine w / h → depth / box h
|
||||
|
||||
const heightPx = computed(() =>
|
||||
frontRatio.value > 0 ? widthPx.value / frontRatio.value : 0,
|
||||
);
|
||||
const depthPx = computed(() => heightPx.value * spineRatio.value);
|
||||
|
||||
// Reduced-motion: read once on mount (it gates the idle drift only).
|
||||
const reducedMotion = ref(false);
|
||||
|
||||
// Interaction bookkeeping.
|
||||
const dragging = ref(false);
|
||||
const stickActive = ref(false);
|
||||
// `autoSpinning` and `coasting` drive the transition string, so they're refs;
|
||||
// they're updated from the RAF loop / pointer handlers, never from a computed
|
||||
// (a computed reading `performance.now()` would cache and never resume).
|
||||
const autoSpinning = ref(false);
|
||||
const coasting = ref(false);
|
||||
let lastInteractAt = 0;
|
||||
let lastMoveAt = 0;
|
||||
let dragPointerId: number | null = null;
|
||||
let lastX = 0;
|
||||
let lastY = 0;
|
||||
let velX = 0; // last-frame pointer delta, kept for the flick on release
|
||||
let velY = 0;
|
||||
let rafId = 0;
|
||||
|
||||
// Snap transitions off whenever the box is being driven continuously (drag,
|
||||
// stick, drift); a flick coasts on an ease-out curve, and discrete keyboard
|
||||
// steps ease on a shorter one.
|
||||
const liveMotion = computed(
|
||||
() => dragging.value || stickActive.value || autoSpinning.value,
|
||||
);
|
||||
|
||||
function markInteract() {
|
||||
lastInteractAt = performance.now();
|
||||
}
|
||||
|
||||
function clampPitch(v: number) {
|
||||
return Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, v));
|
||||
}
|
||||
|
||||
// --- Pointer drag -------------------------------------------------------
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
if (dragPointerId !== null) return;
|
||||
dragPointerId = e.pointerId;
|
||||
dragging.value = true;
|
||||
coasting.value = false;
|
||||
velX = 0;
|
||||
velY = 0;
|
||||
lastX = e.clientX;
|
||||
lastY = e.clientY;
|
||||
rootEl.value?.setPointerCapture(e.pointerId);
|
||||
markInteract();
|
||||
}
|
||||
function onPointerMove(e: PointerEvent) {
|
||||
if (e.pointerId !== dragPointerId) return;
|
||||
velX = e.clientX - lastX;
|
||||
velY = e.clientY - lastY;
|
||||
yaw.value += velX * DRAG_SENSITIVITY;
|
||||
pitch.value = clampPitch(pitch.value - velY * DRAG_SENSITIVITY);
|
||||
lastX = e.clientX;
|
||||
lastY = e.clientY;
|
||||
lastMoveAt = performance.now();
|
||||
markInteract();
|
||||
}
|
||||
function endDrag(e: PointerEvent) {
|
||||
if (e.pointerId !== dragPointerId) return;
|
||||
dragPointerId = null;
|
||||
dragging.value = false;
|
||||
// Momentum without a JS decay loop: hand the box the flick velocity as one
|
||||
// extra rotation and let the CSS ease-out curve coast it to a stop. Releasing
|
||||
// after a pause (no recent movement) carries no flick.
|
||||
if (performance.now() - lastMoveAt < FLICK_WINDOW_MS) {
|
||||
const coast = (v: number) =>
|
||||
Math.max(
|
||||
-MOMENTUM_MAX,
|
||||
Math.min(MOMENTUM_MAX, v * DRAG_SENSITIVITY * MOMENTUM_FRAMES),
|
||||
);
|
||||
const dy = coast(velX);
|
||||
const dp = coast(-velY);
|
||||
if (Math.abs(dy) > 1 || Math.abs(dp) > 1) {
|
||||
coasting.value = true;
|
||||
yaw.value += dy;
|
||||
pitch.value = clampPitch(pitch.value + dp);
|
||||
}
|
||||
}
|
||||
velX = 0;
|
||||
velY = 0;
|
||||
markInteract();
|
||||
}
|
||||
|
||||
// --- Keyboard (also the gamepad D-pad / left stick via synthetic keys) ---
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
switch (e.key) {
|
||||
case "ArrowLeft":
|
||||
yaw.value -= KEY_STEP;
|
||||
break;
|
||||
case "ArrowRight":
|
||||
yaw.value += KEY_STEP;
|
||||
break;
|
||||
case "ArrowUp":
|
||||
pitch.value = clampPitch(pitch.value - KEY_STEP);
|
||||
break;
|
||||
case "ArrowDown":
|
||||
pitch.value = clampPitch(pitch.value + KEY_STEP);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// Consume so the arrow doesn't also drive spatial navigation away from a
|
||||
// box the user is actively rotating; Tab / Shift+Tab (and B / LB / RB on a
|
||||
// pad) remain the way out.
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
coasting.value = false;
|
||||
markInteract();
|
||||
}
|
||||
|
||||
// --- RAF: right-stick polling (while focused) + idle drift ---------------
|
||||
function tick() {
|
||||
// Right analog stick, polled directly so it doesn't collide with the
|
||||
// D-pad → arrow-key navigation. Only while the box owns focus.
|
||||
if (rootEl.value && document.activeElement === rootEl.value) {
|
||||
const pads =
|
||||
typeof navigator !== "undefined" && navigator.getGamepads
|
||||
? navigator.getGamepads()
|
||||
: [];
|
||||
let rx = 0;
|
||||
let ry = 0;
|
||||
for (const pad of pads) {
|
||||
if (!pad) continue;
|
||||
const ax = pad.axes[2] ?? 0;
|
||||
const ay = pad.axes[3] ?? 0;
|
||||
if (Math.abs(ax) > Math.abs(rx)) rx = ax;
|
||||
if (Math.abs(ay) > Math.abs(ry)) ry = ay;
|
||||
}
|
||||
const active =
|
||||
Math.abs(rx) > STICK_DEADZONE || Math.abs(ry) > STICK_DEADZONE;
|
||||
stickActive.value = active;
|
||||
if (active) {
|
||||
yaw.value += rx * STICK_SPEED;
|
||||
pitch.value = clampPitch(pitch.value - ry * STICK_SPEED);
|
||||
markInteract();
|
||||
}
|
||||
} else if (stickActive.value) {
|
||||
stickActive.value = false;
|
||||
}
|
||||
|
||||
// Idle drift, evaluated every frame so it resumes once the quiet window
|
||||
// elapses (a computed reading the clock would cache and never restart).
|
||||
const idle = performance.now() - lastInteractAt > IDLE_RESUME_MS;
|
||||
const spin =
|
||||
props.autoSpin &&
|
||||
!reducedMotion.value &&
|
||||
!dragging.value &&
|
||||
!stickActive.value &&
|
||||
idle;
|
||||
autoSpinning.value = spin;
|
||||
if (spin) {
|
||||
coasting.value = false;
|
||||
yaw.value += AUTO_SPIN_SPEED;
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
// --- Image measurement ---------------------------------------------------
|
||||
// The box mirrors the real artwork: the front (box-2D) natural ratio drives
|
||||
// the box width/height, the spine's drives the depth. Defaults only stand in
|
||||
// until the bytes are decoded.
|
||||
function measureRatio(img: HTMLImageElement | null, target: Ref<number>) {
|
||||
if (img && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
||||
target.value = img.naturalWidth / img.naturalHeight;
|
||||
}
|
||||
}
|
||||
const onFrontLoad = (e: Event) =>
|
||||
measureRatio(e.target as HTMLImageElement, frontRatio);
|
||||
const onSpineLoad = (e: Event) =>
|
||||
measureRatio(e.target as HTMLImageElement, spineRatio);
|
||||
|
||||
let ro: ResizeObserver | null = null;
|
||||
onMounted(() => {
|
||||
reducedMotion.value =
|
||||
typeof window !== "undefined" &&
|
||||
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
||||
|
||||
const root = rootEl.value;
|
||||
if (root) {
|
||||
widthPx.value = root.clientWidth;
|
||||
if (typeof ResizeObserver !== "undefined") {
|
||||
ro = new ResizeObserver((entries) => {
|
||||
const w = entries[0]?.contentRect.width ?? 0;
|
||||
if (w > 0) widthPx.value = w;
|
||||
});
|
||||
ro.observe(root);
|
||||
}
|
||||
// Interaction listeners are bound imperatively (not in the template) so
|
||||
// the static box element doesn't trip the no-static-element-interactions
|
||||
// rule — the same approach GameCover takes for its hover motion. The box
|
||||
// is decorative chrome with an optional manipulation affordance.
|
||||
root.addEventListener("pointerdown", onPointerDown);
|
||||
root.addEventListener("pointermove", onPointerMove);
|
||||
root.addEventListener("pointerup", endDrag);
|
||||
root.addEventListener("pointercancel", endDrag);
|
||||
root.addEventListener("keydown", onKeydown);
|
||||
}
|
||||
// A cached cover can already be decoded before the load listener binds —
|
||||
// read its dimensions now so the box adopts box-2D's ratio immediately.
|
||||
measureRatio(frontImg.value, frontRatio);
|
||||
measureRatio(spineImg.value, spineRatio);
|
||||
rafId = requestAnimationFrame(tick);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
ro?.disconnect();
|
||||
cancelAnimationFrame(rafId);
|
||||
const root = rootEl.value;
|
||||
if (root) {
|
||||
root.removeEventListener("pointerdown", onPointerDown);
|
||||
root.removeEventListener("pointermove", onPointerMove);
|
||||
root.removeEventListener("pointerup", endDrag);
|
||||
root.removeEventListener("pointercancel", endDrag);
|
||||
root.removeEventListener("keydown", onKeydown);
|
||||
}
|
||||
});
|
||||
|
||||
// --- Styles --------------------------------------------------------------
|
||||
// Transition picks the curve for the current gesture: none while driven
|
||||
// continuously (drag / stick / drift), a long ease-out to coast a flick, and
|
||||
// a short ease-out for discrete keyboard steps.
|
||||
const boxTransition = computed(() => {
|
||||
if (liveMotion.value) return "none";
|
||||
if (coasting.value) return "transform 0.9s cubic-bezier(0.16, 1, 0.3, 1)";
|
||||
return "transform 0.28s ease-out";
|
||||
});
|
||||
const boxStyle = computed(() => ({
|
||||
transform: `rotateX(${pitch.value}deg) rotateY(${yaw.value}deg)`,
|
||||
transition: boxTransition.value,
|
||||
}));
|
||||
|
||||
const px = (n: number) => `${n}px`;
|
||||
|
||||
const frontStyle = computed(() => ({
|
||||
width: px(widthPx.value),
|
||||
height: px(heightPx.value),
|
||||
transform: `translate(-50%, -50%) translateZ(${depthPx.value / 2}px)`,
|
||||
}));
|
||||
const backStyle = computed(() => ({
|
||||
width: px(widthPx.value),
|
||||
height: px(heightPx.value),
|
||||
transform: `translate(-50%, -50%) rotateY(180deg) translateZ(${depthPx.value / 2}px)`,
|
||||
}));
|
||||
const leftStyle = computed(() => ({
|
||||
width: px(depthPx.value),
|
||||
height: px(heightPx.value),
|
||||
transform: `translate(-50%, -50%) rotateY(-90deg) translateZ(${widthPx.value / 2}px)`,
|
||||
}));
|
||||
const rightStyle = computed(() => ({
|
||||
width: px(depthPx.value),
|
||||
height: px(heightPx.value),
|
||||
transform: `translate(-50%, -50%) rotateY(90deg) translateZ(${widthPx.value / 2}px)`,
|
||||
}));
|
||||
const topStyle = computed(() => ({
|
||||
width: px(widthPx.value),
|
||||
height: px(depthPx.value),
|
||||
transform: `translate(-50%, -50%) rotateX(90deg) translateZ(${heightPx.value / 2}px)`,
|
||||
}));
|
||||
const bottomStyle = computed(() => ({
|
||||
width: px(widthPx.value),
|
||||
height: px(depthPx.value),
|
||||
transform: `translate(-50%, -50%) rotateX(-90deg) translateZ(${heightPx.value / 2}px)`,
|
||||
}));
|
||||
|
||||
const rootStyle = computed(() => ({ aspectRatio: String(frontRatio.value) }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="rootEl"
|
||||
v-bind="$attrs"
|
||||
class="r-box3d"
|
||||
role="img"
|
||||
:aria-label="alt"
|
||||
tabindex="0"
|
||||
:style="rootStyle"
|
||||
>
|
||||
<div class="r-box3d__shadow" />
|
||||
<div class="r-box3d__stage">
|
||||
<div class="r-box3d__box" :style="boxStyle">
|
||||
<img
|
||||
ref="frontImg"
|
||||
class="r-box3d__face r-box3d__face--art"
|
||||
:src="front"
|
||||
:alt="alt"
|
||||
:style="frontStyle"
|
||||
draggable="false"
|
||||
@load="onFrontLoad"
|
||||
@error="emit('error')"
|
||||
/>
|
||||
<img
|
||||
class="r-box3d__face r-box3d__face--art"
|
||||
:src="back"
|
||||
alt=""
|
||||
:style="backStyle"
|
||||
draggable="false"
|
||||
/>
|
||||
<img
|
||||
ref="spineImg"
|
||||
class="r-box3d__face r-box3d__face--art"
|
||||
:src="spine"
|
||||
alt=""
|
||||
:style="leftStyle"
|
||||
draggable="false"
|
||||
@load="onSpineLoad"
|
||||
/>
|
||||
<img
|
||||
class="r-box3d__face r-box3d__face--art"
|
||||
:src="spine"
|
||||
alt=""
|
||||
:style="rightStyle"
|
||||
draggable="false"
|
||||
/>
|
||||
<div class="r-box3d__face r-box3d__face--edge" :style="topStyle" />
|
||||
<div class="r-box3d__face r-box3d__face--edge" :style="bottomStyle" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-box3d {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
/* Let the box bleed past its footprint while turning. */
|
||||
overflow: visible;
|
||||
cursor: grab;
|
||||
touch-action: none;
|
||||
outline: none;
|
||||
/* Dragging the box must rotate it, never start a text / image selection. */
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.r-box3d:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
/* Soft contact shadow on the floor under the box. */
|
||||
.r-box3d__shadow {
|
||||
position: absolute;
|
||||
left: 12%;
|
||||
right: 12%;
|
||||
bottom: -4%;
|
||||
height: 10%;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(
|
||||
ellipse at center,
|
||||
color-mix(in srgb, black 38%, transparent),
|
||||
transparent 70%
|
||||
);
|
||||
filter: blur(6px);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.r-box3d__stage {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
perspective: 1400px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.r-box3d__box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transform-style: preserve-3d;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.r-box3d__face {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
/* Each face is centred on the box origin, then pushed out by its own
|
||||
transform (set inline). backface-visibility hidden keeps the far side
|
||||
from bleeding through the art. */
|
||||
backface-visibility: hidden;
|
||||
border-radius: var(--r-radius-xs);
|
||||
overflow: hidden;
|
||||
/* Faces never capture the pointer — every drag/click lands on the root,
|
||||
which owns the rotation listeners (the imgs are also draggable="false"). */
|
||||
pointer-events: none;
|
||||
}
|
||||
.r-box3d__face--art {
|
||||
display: block;
|
||||
object-fit: cover;
|
||||
background: var(--r-color-cover-placeholder);
|
||||
/* No image smoothing fuzz on pixel-art spines. */
|
||||
box-shadow: inset 0 0 0 1px color-mix(in srgb, black 18%, transparent);
|
||||
}
|
||||
/* Top / bottom cardboard edges — tinted, no print. */
|
||||
.r-box3d__face--edge {
|
||||
background: linear-gradient(
|
||||
var(--r-color-cover-placeholder-bright),
|
||||
var(--r-color-cover-placeholder)
|
||||
);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-box3d__box {
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
1
frontend/src/v2/lib/media/RBox3D/index.ts
Normal file
1
frontend/src/v2/lib/media/RBox3D/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as RBox3D } from "./RBox3D.vue";
|
||||
Reference in New Issue
Block a user