Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

feat(docs): stack demos with equal preview columns

rponeebb708aafa9d
diff --git a/docs/.vitepress/theme/components/SvmlDemoCarousel.vue b/docs/.vitepress/theme/components/SvmlDemoCarousel.vue
index a6f761cb..aee90b1c 100644
--- a/docs/.vitepress/theme/components/SvmlDemoCarousel.vue
+++ b/docs/.vitepress/theme/components/SvmlDemoCarousel.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { computed, onBeforeUnmount, onMounted, ref } from "vue";
+import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue";
import {
demoMediaVersion,
demoMediaManifests,
@@ -19,15 +19,15 @@ const cards = [
const { lang } = useData();
const isChinese = computed(() => lang.value.toLowerCase().startsWith("zh"));
const cardLabel = (card: (typeof cards)[number]) => isChinese.value ? card.labelZh : card.labelEn;
-const selectedIndex = ref(0);
-const playingIndex = ref<number | null>(null);
+const playingIndex = ref(0);
const loadedIndices = ref<Set<number>>(new Set());
const manifestPromises = new Map<number, Promise<void>>();
const mediaCacheVersionKey = "svml-demo-media-version";
-let activationId = 0;
-let backgroundPreloadStarted = false;
+const cardElements = new Map<number, HTMLElement>();
+const visibleRatios = new Map<number, number>();
+let cardObserver: IntersectionObserver | null = null;
-const isLoading = computed(() => !loadedIndices.value.has(selectedIndex.value));
+const isLoading = computed(() => loadedIndices.value.size < cards.length);
function loadManifest(manifest: DemoMediaManifest) {
const assets = [
@@ -56,11 +56,8 @@ function preloadDemo(index: number) {
return promise;
}
-async function preloadRemainingDemos(initialIndex: number) {
- for (let offset = 1; offset < cards.length; offset += 1) {
- await preloadDemo((initialIndex + offset) % cards.length);
- }
-
+async function preloadAllDemos() {
+ await Promise.all(cards.map((_, index) => preloadDemo(index)));
try {
window.localStorage.setItem(mediaCacheVersionKey, demoMediaVersion);
} catch {
@@ -76,61 +73,48 @@ function restoreCachedDemos() {
}
loadedIndices.value = new Set(cards.map((_, index) => index));
- playingIndex.value = selectedIndex.value;
- backgroundPreloadStarted = true;
return true;
}
-function transitionDelay(immediate: boolean) {
- if (immediate || window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
- return Promise.resolve();
- }
- return new Promise<void>((resolve) => window.setTimeout(resolve, 850));
+function setCardElement(element: Element | null, index: number) {
+ if (element instanceof HTMLElement) cardElements.set(index, element);
+ else cardElements.delete(index);
}
-async function activateDemo(index: number, immediate = false) {
- if (!immediate && index === selectedIndex.value && playingIndex.value === index) return;
-
- selectedIndex.value = index;
- playingIndex.value = null;
- const currentActivation = ++activationId;
-
- await Promise.all([preloadDemo(index), transitionDelay(immediate)]);
- if (currentActivation !== activationId) return;
-
- playingIndex.value = index;
- if (!backgroundPreloadStarted) {
- backgroundPreloadStarted = true;
- window.setTimeout(() => void preloadRemainingDemos(index), 0);
+function selectMostVisibleCard() {
+ let nextIndex = playingIndex.value;
+ let largestRatio = 0;
+ for (const [index, ratio] of visibleRatios) {
+ if (ratio > largestRatio) {
+ largestRatio = ratio;
+ nextIndex = index;
+ }
}
+ if (largestRatio > 0) playingIndex.value = nextIndex;
}
-function cardPosition(index: number) {
- const offset = (index - selectedIndex.value + cards.length) % cards.length;
- if (offset === 0) return "is-center";
- if (offset === 1) return "is-right";
- return "is-left";
-}
-
-function move(direction: number) {
- const nextIndex = (selectedIndex.value + direction + cards.length) % cards.length;
- void activateDemo(nextIndex);
-}
+function observeCards() {
+ cardObserver = new IntersectionObserver((entries) => {
+ for (const entry of entries) {
+ const index = Number((entry.target as HTMLElement).dataset.demoIndex);
+ visibleRatios.set(index, entry.isIntersecting ? entry.intersectionRatio : 0);
+ }
+ selectMostVisibleCard();
+ }, { threshold: [0, .2, .4, .6, .8, 1] });
-function handleEnded(index: number) {
- if (playingIndex.value !== index) return;
- move(1);
+ for (const element of cardElements.values()) cardObserver.observe(element);
}
onMounted(() => {
- if (!restoreCachedDemos()) void activateDemo(0, true);
+ if (!restoreCachedDemos()) void preloadAllDemos();
+ void nextTick(observeCards);
});
-onBeforeUnmount(() => { activationId += 1; });
+onBeforeUnmount(() => cardObserver?.disconnect());
</script>
<template>
<div
- class="svml-demo-carousel"
+ class="svml-demo-showcase"
:aria-busy="isLoading"
@pointermove="updateDemoPointer"
@pointerleave="clearDemoPointer"
@@ -139,22 +123,15 @@ onBeforeUnmount(() => { activationId += 1; });
<h2><span class="hover-interaction-copy">{{ isChinese ? "悬停标记范围,查看对应画面" : "Hover a marked range to see the corresponding frame" }}</span><span class="touch-interaction-copy">{{ isChinese ? "点击标记范围,查看对应画面" : "Tap a marked range to see the corresponding frame" }}</span></h2>
</header>
- <div class="demo-carousel-stage">
+ <div class="demo-list">
<article
v-for="(card, index) in cards"
:key="card.labelEn"
class="demo-card"
- :class="cardPosition(index)"
- :aria-hidden="index !== selectedIndex"
+ :ref="(element) => setCardElement(element, index)"
+ :data-demo-index="index"
+ :aria-label="cardLabel(card)"
>
- <button
- v-if="index !== selectedIndex"
- class="demo-card-select"
- type="button"
- :aria-label="isChinese ? `查看${cardLabel(card)}演示` : `View the ${cardLabel(card)} demo`"
- @click="activateDemo(index)"
- ></button>
-
<div v-if="!loadedIndices.has(index)" class="demo-loading" role="status" aria-live="polite">
<span class="demo-loading-spinner" aria-hidden="true"></span>
<span>{{ isChinese ? "加载演示素材…" : "Loading demo media…" }}</span>
@@ -162,88 +139,50 @@ onBeforeUnmount(() => { activationId += 1; });
<div
v-else
class="demo-card-content"
- :inert="index !== selectedIndex ? '' : undefined"
>
<component
:is="card.component"
v-bind="card.props"
:active="playingIndex === index"
:show-heading="false"
- @ended="handleEnded(index)"
/>
</div>
</article>
</div>
-
- <nav class="demo-carousel-controls" :aria-label="isChinese ? '切换示例' : 'Switch demos'">
- <button class="arrow-button" type="button" :aria-label="isChinese ? '上一个示例' : 'Previous demo'" @click="move(-1)">
- <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.7 5.3 8 12l6.7 6.7 1.4-1.4-5.3-5.3 5.3-5.3z"/></svg>
- </button>
- <div class="demo-carousel-dots" :aria-label="isChinese ? '选择示例' : 'Choose a demo'">
- <button
- v-for="(card, index) in cards"
- :key="card.labelEn"
- type="button"
- :class="{ active: index === selectedIndex }"
- :aria-label="isChinese ? `查看${cardLabel(card)}演示` : `View the ${cardLabel(card)} demo`"
- :aria-current="index === selectedIndex ? 'true' : undefined"
- @click="activateDemo(index)"
- ></button>
- </div>
- <button class="arrow-button" type="button" :aria-label="isChinese ? '下一个示例' : 'Next demo'" @click="move(1)">
- <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m9.3 5.3-1.4 1.4 5.3 5.3-5.3 5.3 1.4 1.4L16 12z"/></svg>
- </button>
- </nav>
</div>
</template>
<style scoped>
-.svml-demo-carousel { width: calc(100% - 128px); max-width: 1180px; margin: 0 auto; padding: 48px 32px 96px; overflow: visible; box-sizing: border-box; }
-.demo-carousel-stage { display: grid; width: min(100%, 1000px); margin-inline: auto; overflow: visible; perspective: 1600px; }
+.svml-demo-showcase { width: calc(100% - 128px); max-width: 1180px; margin: 0 auto; padding: 48px 32px 96px; box-sizing: border-box; }
+.demo-list { display: grid; gap: 64px; width: min(100%, 1000px); margin-inline: 0; }
.carousel-heading { width: min(100%, 1000px); margin-right: 0; margin-left: 0; }
-.demo-card { position: relative; grid-area: 1 / 1; justify-self: center; width: 100%; overflow: visible; border-radius: 2px; background: transparent; transform-origin: center center; will-change: transform, opacity; transition: transform 850ms cubic-bezier(.16,1,.3,1), opacity 850ms cubic-bezier(.16,1,.3,1); }
-.demo-card.is-center { z-index: 3; opacity: 1; transform: translateX(0) scale(1); }
-.demo-card.is-left { z-index: 1; opacity: .3; transform: translateX(calc(-100% + 34px)) scale(.86); }
-.demo-card.is-right { z-index: 1; opacity: .3; transform: translateX(calc(100% - 34px)) scale(.86); }
-.demo-card-select { position: absolute; z-index: 10; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; }
-.demo-card-select:focus-visible { outline: 2px solid var(--accent); outline-offset: -5px; border-radius: 2px; }
-.demo-card-content { min-width: 0; overflow: hidden; border-radius: 2px; background: #272022; filter: brightness(1); transition: filter 850ms cubic-bezier(.16,1,.3,1); }
-.demo-card.is-left .demo-card-content,
-.demo-card.is-right .demo-card-content { filter: brightness(.82) saturate(.68); }
+.demo-card { width: 100%; min-width: 0; border-radius: 2px; background: transparent; opacity: 0; transform: translateY(18px); animation: demo-card-rise .48s cubic-bezier(.22,1,.36,1) forwards; }
+.demo-card:nth-child(1) { animation-delay: 1.59s; }
+.demo-card:nth-child(2) { animation-delay: 1.75s; }
+.demo-card:nth-child(3) { animation-delay: 1.91s; }
+.demo-card-content { min-width: 0; overflow: hidden; border-radius: 2px; background: #272022; }
.demo-card-content :deep(.svml-demo) { margin-top: 0; }
.demo-card-content :deep(.demo-shell) { box-shadow: none; }
.demo-loading { display: grid; place-content: center; justify-items: center; gap: 14px; min-height: 720px; border: 0; border-radius: 2px; background: #272022; color: #BBAAB0; font-family: var(--font-ui); font-size: 12px; letter-spacing: .04em; }
.demo-loading-spinner { width: 30px; height: 30px; border: 2px solid #EB609133; border-top-color: #49D6E9; border-radius: 50%; animation: demo-loading-spin .7s linear infinite; }
-.demo-carousel-controls { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 22px 0 2px; }
-.demo-carousel-controls button { padding: 0; cursor: pointer; }
-.arrow-button { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--rule); border-radius: 2px; background: transparent; color: var(--ink); transition: color .18s ease, background-color .18s ease; }
-.arrow-button:hover { background: var(--ink); color: var(--paper); }
-.demo-carousel-controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
-.arrow-button svg { width: 21px; height: 21px; fill: currentColor; }
-.demo-carousel-dots { display: flex; align-items: center; gap: 8px; }
-.demo-carousel-dots button { width: 7px; height: 7px; border: 0; border-radius: 50%; background: rgba(233,178,166,.34); transition: background-color 160ms ease; }
-.demo-carousel-dots button.active { background: var(--accent); }
-
@keyframes demo-loading-spin { to { transform: rotate(360deg); } }
+@keyframes demo-card-rise { to { opacity: 1; transform: translateY(0); } }
@media (max-width: 959px) {
- .svml-demo-carousel { width: calc(100% - 96px); }
- .demo-card.is-left { transform: translateX(calc(-100% + 18px)) scale(.88); }
- .demo-card.is-right { transform: translateX(calc(100% - 18px)) scale(.88); }
+ .svml-demo-showcase { width: calc(100% - 96px); }
.demo-loading { min-height: 990px; }
}
@media (max-width: 639px) {
- .svml-demo-carousel { width: 100%; padding-inline: 24px; }
+ .svml-demo-showcase { width: 100%; padding-inline: 24px; }
}
@media (max-width: 520px) {
- .svml-demo-carousel { padding: 48px 24px 72px; }
- .demo-card.is-left { transform: translateX(calc(-100% + 8px)) scale(.9); }
- .demo-card.is-right { transform: translateX(calc(100% - 8px)) scale(.9); }
+ .svml-demo-showcase { padding: 48px 24px 72px; }
+ .demo-list { gap: 32px; }
}
@media (prefers-reduced-motion: reduce) {
- .demo-card { transition-duration: .01ms; }
+ .demo-card { opacity: 1; transform: none; animation: none; }
}
</style>
diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css
index 6bb9e49d..0a982dcf 100644
--- a/docs/.vitepress/theme/style.css
+++ b/docs/.vitepress/theme/style.css
@@ -226,9 +226,7 @@ html.home-page .VPPage { background: var(--paper); }
.hero-statement-viewport-en,
.hero-statement-viewport-zh,
.VPHome .VPHero .actions,
-.VPHome .carousel-heading,
-.VPHome .demo-carousel-stage,
-.VPHome .demo-carousel-controls {
+.VPHome .carousel-heading {
opacity: 0;
transform: translateY(12px);
animation: hero-content-rise .4s cubic-bezier(.22,1,.36,1) forwards;
@@ -237,14 +235,10 @@ html.home-page .VPPage { background: var(--paper); }
.hero-statement-viewport-zh { animation-delay: 1.17s; }
.VPHome .VPHero .actions { animation-delay: 1.31s; }
.VPHome .carousel-heading { animation-delay: 1.45s; }
-.VPHome .demo-carousel-stage { animation-delay: 1.59s; }
-.VPHome .demo-carousel-controls { animation-delay: 1.73s; }
.hero-intro-seen .hero-statement-viewport-en,
.hero-intro-seen .hero-statement-viewport-zh,
.hero-intro-seen .VPHome .VPHero .actions,
-.hero-intro-seen .VPHome .carousel-heading,
-.hero-intro-seen .VPHome .demo-carousel-stage,
-.hero-intro-seen .VPHome .demo-carousel-controls {
+.hero-intro-seen .VPHome .carousel-heading {
opacity: 1;
transform: none;
animation: none;
@@ -293,7 +287,7 @@ html.home-page .VPPage { background: var(--paper); }
.vp-doc .demo-heading h2 { margin: 0; border: 0; padding: 0; color: var(--ink); font-family: var(--font-ui); font-size: clamp(20px, 2vw, 26px); font-weight: 600; line-height: 1.2; letter-spacing: -.025em; }
.VPHome .vp-doc .demo-heading h2 { font-size: 19px; }
.touch-interaction-copy { display: none; }
-.demo-shell { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); min-height: 670px; overflow: hidden; border: 0; border-radius: 2px; background: var(--demo-card-bg); }
+.demo-shell { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: 670px; overflow: hidden; border: 0; border-radius: 2px; background: var(--demo-card-bg); }
.source-panel, .preview-panel { min-width: 0; }
.source-panel { position: relative; border: 0; background: var(--demo-code-bg); }
.preview-panel { display: flex; flex-direction: column; background: var(--demo-preview-bg); }
@@ -421,8 +415,6 @@ html.home-page .VPPage { background: var(--paper); }
.hero-statement-viewport-en,
.hero-statement-viewport-zh,
.VPHome .VPHero .actions,
- .VPHome .carousel-heading,
- .VPHome .demo-carousel-stage,
- .VPHome .demo-carousel-controls { opacity: 1; transform: none; animation: none !important; }
+ .VPHome .carousel-heading { opacity: 1; transform: none; animation: none !important; }
.hero-statement-swap-enter-from, .hero-statement-swap-leave-to { filter: none; transform: none; }
}