05埋まった行数の値が増える結果カードのストリーム読み込み
結果カード内のスケルトン行ごとに埋まったかどうかの値を持たせ、その値が上から一つずつtrueに変わるたびその行だけが本物のテキストの色調に変わる。
使いどころAI要約・レポートカードが埋まっていく画面、検索結果のプレビュー
LINE_MSFILL_MS--skeleton

<main class="stage">
<div class="ld" id="ld">
<p class="ld__hint">
<svg class="ld__ico" viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M232 56v56a8 8 0 0 1-16 0V91.3l-25.6 25.7A80 80 0 1 1 174 60a8 8 0 1 1-9 13.2A64 64 0 1 0 179.7 128H216a8 8 0 0 1 0 16h-56a8 8 0 0 1-8-8V80a8 8 0 0 1 16 0v20.7L192.7 76A80.1 80.1 0 0 0 64 128a8 8 0 0 1-16 0a96 96 0 0 1 163.6-68.3L224 71.3V56a8 8 0 0 1 8 8" opacity=".2"/><path d="M224 48a8 8 0 0 0-8 8v15.3l-11.7-11.6a96 96 0 1 0 27.6 51.6a8 8 0 0 0-15.8 2.5a80 80 0 1 1-23-43l-25.7 25.7A8 8 0 0 0 173 112h56a8 8 0 0 0 8-8V56a8 8 0 0 0-13-8"/></g></svg>
<span>クリックするかスペースバーを押すと一時停止または再開します</span>
</p>
<div class="ld__field" id="field" role="application" aria-label="カードコンテンツストリーム充填テストパネル" tabindex="0">
<div class="ld__card">
<div class="ld__cardHead"><i></i><i></i><i></i></div>
<div class="ld__line" style="--w:86%" data-i="0"><b class="ld__lineFill"></b></div>
<div class="ld__line" style="--w:64%" data-i="1"><b class="ld__lineFill"></b></div>
<div class="ld__line" style="--w:92%" data-i="2"><b class="ld__lineFill"></b></div>
<div class="ld__line" style="--w:58%" data-i="3"><b class="ld__lineFill"></b></div>
<div class="ld__line" style="--w:78%" data-i="4"><b class="ld__lineFill"></b></div>
<div class="ld__line" style="--w:46%" data-i="5"><b class="ld__lineFill"></b></div>
</div>
<b class="ld__badge" aria-hidden="true"><span class="ld__badgeNum" id="pct">0%</span><span class="ld__badgeUnit">充填</span></b>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// card-content-stream-fill — 스켈레톤 줄마다 채워졌는지 여부를 값으로 두고, 그 값이 위에서부터
// 하나씩 참으로 바뀔 때마다 해당 줄만 실제 텍스트 톤으로 바뀐다. rAF 로 폭·색을 함께 보간 — @keyframes 없음.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-cream;
@include stage($stage-ink);
.ld {
--skeleton: #4a4550;
--text-tone: #{$subject-blue-light};
display: flex; flex-direction: column; gap: $sp-2;
width: 100%; max-width: 424px;
}
.ld__hint {
display: flex; align-items: center; gap: $sp-1; margin: 0;
font-weight: 700; font-size: clamp(10px, 2.8vw, 12px); line-height: 1.35;
color: $subject-cream;
}
.ld__ico { width: 16px; height: 16px; flex: 0 0 auto; color: $subject-blue-light; }
.ld__field {
position: relative; height: 208px;
display: flex; align-items: center;
border-radius: $r-card; overflow: hidden;
background: $subject-ink;
box-shadow: inset 0 0 0 1px rgba($subject-cream, .14);
cursor: pointer;
padding: 0 $sp-4;
}
.ld__field:focus-visible { outline: 2px solid $subject-blue-light; outline-offset: 2px; }
.ld__card {
width: 100%; display: flex; flex-direction: column; gap: $sp-2;
}
.ld__cardHead {
display: flex; gap: $sp-1; margin-bottom: $sp-1;
i { width: 7px; height: 7px; border-radius: $r-pill; background: rgba($subject-cream, .3); display: block; }
}
.ld__line {
position: relative; height: 10px; width: var(--w, 70%);
border-radius: $r-xs;
background: rgba($subject-cream, .12);
overflow: hidden;
}
.ld__lineFill {
display: block; height: 100%; width: 0%;
border-radius: $r-xs;
background: $subject-blue-light;
}
.ld__line.is-active { box-shadow: 0 0 0 1px rgba($subject-blue-light, .35); }
.ld__badge {
position: absolute; right: $sp-2; top: $sp-2;
display: flex; align-items: baseline; gap: $sp-1;
padding: $sp-1 $sp-2; border-radius: $r-pill;
background: rgba($subject-cream, .12);
color: $subject-cream; font-weight: 700; font-size: 11px;
}
.ld__badgeNum { font-size: 13px; color: $stage-yellow; }
.ld__badgeUnit { font-weight: 700; }
@media (max-width: 340px) {
.ld { gap: $sp-1; }
.ld__field { height: 124px; padding: 0 $sp-2; }
.ld__card { gap: $sp-1; }
.ld__badge { font-size: 10px; padding: 0 $sp-1; }
.ld__badgeNum { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
.ld.is-still .ld__field { cursor: default !important; }
.ld.is-still .ld__badge { opacity: .92 !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ld {
--skeleton: #4a4550;
--text-tone: #5b8cf8;
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
max-width: 424px;
}
.ld__hint {
display: flex;
align-items: center;
gap: 4px;
margin: 0;
font-weight: 700;
font-size: clamp(10px, 2.8vw, 12px);
line-height: 1.35;
color: #fff7e6;
}
.ld__ico {
width: 16px;
height: 16px;
flex: 0 0 auto;
color: #5b8cf8;
}
.ld__field {
position: relative;
height: 208px;
display: flex;
align-items: center;
border-radius: 16px;
overflow: hidden;
background: #17141a;
box-shadow: inset 0 0 0 1px rgba(255, 247, 230, 0.14);
cursor: pointer;
padding: 0 16px;
}
.ld__field:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
.ld__card {
width: 100%;
display: flex;
flex-direction: column;
gap: 8px;
}
.ld__cardHead {
display: flex;
gap: 4px;
margin-bottom: 4px;
}
.ld__cardHead i {
width: 7px;
height: 7px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.3);
display: block;
}
.ld__line {
position: relative;
height: 10px;
width: var(--w, 70%);
border-radius: 4px;
background: rgba(255, 247, 230, 0.12);
overflow: hidden;
}
.ld__lineFill {
display: block;
height: 100%;
width: 0%;
border-radius: 4px;
background: #5b8cf8;
}
.ld__line.is-active {
box-shadow: 0 0 0 1px rgba(91, 140, 248, 0.35);
}
.ld__badge {
position: absolute;
right: 8px;
top: 8px;
display: flex;
align-items: baseline;
gap: 4px;
padding: 4px 8px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.12);
color: #fff7e6;
font-weight: 700;
font-size: 11px;
}
.ld__badgeNum {
font-size: 13px;
color: #ffd23f;
}
.ld__badgeUnit {
font-weight: 700;
}
@media (max-width: 340px) {
.ld {
gap: 4px;
}
.ld__field {
height: 124px;
padding: 0 8px;
}
.ld__card {
gap: 4px;
}
.ld__badge {
font-size: 10px;
padding: 0 4px;
}
.ld__badgeNum {
font-size: 11px;
}
}
@media (prefers-reduced-motion: reduce) {
.ld.is-still .ld__field {
cursor: default !important;
}
.ld.is-still .ld__badge {
opacity: 0.92 !important;
}
}(function () {
var LOOP = 2.0;
var LINE_MS = 0.24; // 줄 시작 간격 — 줄마다 채워짐 값이 참이 되는 시각 간격
var FILL_MS = 0.30; // 줄 하나가 채워지는 데 걸리는 시간
var root = document.getElementById('ld');
var field = document.getElementById('field');
var lines = Array.prototype.slice.call(document.querySelectorAll('.ld__line'));
var fills = lines.map(function (l) { return l.querySelector('.ld__lineFill'); });
var pctEl = document.getElementById('pct');
var paused = false;
var t0 = performance.now();
var raf = 0;
function reduced() { return window.matchMedia('(prefers-reduced-motion: reduce)').matches; }
function clamp01(v) { return v < 0 ? 0 : v > 1 ? 1 : v; }
function smooth(t) { return t * t * (3 - 2 * t); }
function hexToRgb(hex) {
var h = hex.replace('#', '').trim();
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
var n = parseInt(h, 16);
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
}
function mix(a, b, t) {
return [Math.round(a[0] + (b[0] - a[0]) * t), Math.round(a[1] + (b[1] - a[1]) * t), Math.round(a[2] + (b[2] - a[2]) * t)];
}
function rgbStr(c) { return 'rgb(' + c[0] + ',' + c[1] + ',' + c[2] + ')'; }
var cs = getComputedStyle(root);
var SKELETON = hexToRgb(cs.getPropertyValue('--skeleton').trim());
var TEXT = hexToRgb(cs.getPropertyValue('--text-tone').trim());
function draw(sec) {
var t = sec % LOOP;
var doneCount = 0;
for (var i = 0; i < lines.length; i++) {
var local = t - i * LINE_MS;
var raw = clamp01(local / FILL_MS);
var eased = smooth(raw);
fills[i].style.width = (eased * 100).toFixed(1) + '%';
fills[i].style.background = rgbStr(mix(SKELETON, TEXT, eased));
lines[i].classList.toggle('is-active', raw > 0 && raw < 1);
if (raw >= 1) doneCount++;
}
pctEl.textContent = Math.round((doneCount / lines.length) * 100) + '%';
}
function togglePause() { paused = !paused; root.classList.toggle('is-paused', paused); }
function restart() { t0 = performance.now(); draw(0); }
function onKey(e) {
if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); togglePause(); }
else if (e.key === 'r' || e.key === 'R') { e.preventDefault(); restart(); }
}
field.addEventListener('click', togglePause);
field.addEventListener('keydown', onKey);
function onResize() {
if (paused || reduced()) draw((performance.now() - t0) / 1000);
}
window.addEventListener('resize', onResize);
function frame(now) {
if (!paused) draw((now - t0) / 1000);
raf = requestAnimationFrame(frame);
}
if (reduced()) {
root.classList.add('is-still');
draw(LOOP * 0.62);
} else {
raf = requestAnimationFrame(frame);
}
})();// CardStream — vanilla 판(run/403/demo/05-ai-processing-loading-card-content-stream-fill/index.html) 의 React 포트.
// 스켈레톤 줄마다 채워졌는지 여부를 값으로 두고, 위에서부터 하나씩 참으로 바뀔 때마다
// 해당 줄만 실제 텍스트 톤으로 바뀐다. rAF 로 폭·색을 함께 보간 — @keyframes 없음.
import { useEffect, useRef } from "react";
import type { CSSProperties } from "react";
import styles from "./CardStream.module.scss";
export type CardStreamProps = {
duration?: string;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
type Box<T> = { current: T };
type KeyEvt = { key: string; preventDefault(): void };
const LOOP = 2.0;
const LINE_MS = 0.24;
const FILL_MS = 0.30;
const WIDTHS = [86, 64, 92, 58, 78, 46];
const FIELD_LABEL = "카드 스트림 채움 실험판";
function clamp01(v: number): number { return v < 0 ? 0 : v > 1 ? 1 : v; }
function smooth(t: number): number { return t * t * (3 - 2 * t); }
function hexToRgb(hex: string): [number, number, number] {
let h = hex.replace("#", "").trim();
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
const n = parseInt(h, 16);
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
}
function mix(a: [number, number, number], b: [number, number, number], t: number): [number, number, number] {
return [Math.round(a[0] + (b[0] - a[0]) * t), Math.round(a[1] + (b[1] - a[1]) * t), Math.round(a[2] + (b[2] - a[2]) * t)];
}
function rgbStr(c: [number, number, number]): string { return "rgb(" + c[0] + "," + c[1] + "," + c[2] + ")"; }
export default function CardStream({
duration = "2s",
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#fff7e6",
}: CardStreamProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const fieldRef = useRef<HTMLDivElement | null>(null);
const lineRefs = useRef<Array<HTMLDivElement | null>>([]) as Box<Array<HTMLDivElement | null>>;
const fillRefs = useRef<Array<HTMLSpanElement | null>>([]) as Box<Array<HTMLSpanElement | null>>;
const pctRef = useRef<HTMLSpanElement | null>(null);
const pausedRef = useRef(false) as Box<boolean>;
const t0Ref = useRef(0) as Box<number>;
const rafRef = useRef(0) as Box<number>;
const skeletonRef = useRef<[number, number, number]>([74, 69, 80]) as Box<[number, number, number]>;
const textRef = useRef<[number, number, number]>([91, 140, 248]) as Box<[number, number, number]>;
const vars: Vars = { "--duration": duration, "--easing": easing, "--color": color };
function reduced(): boolean {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function draw(sec: number): void {
const pctEl = pctRef.current;
const t = sec % LOOP;
let doneCount = 0;
for (let i = 0; i < WIDTHS.length; i++) {
const local = t - i * LINE_MS;
const raw = clamp01(local / FILL_MS);
const eased = smooth(raw);
const fillEl = fillRefs.current[i];
const lineEl = lineRefs.current[i];
if (fillEl) {
fillEl.style.width = (eased * 100).toFixed(1) + "%";
fillEl.style.background = rgbStr(mix(skeletonRef.current, textRef.current, eased));
}
if (lineEl) lineEl.classList.toggle(styles.isActive, raw > 0 && raw < 1);
if (raw >= 1) doneCount++;
}
if (pctEl) pctEl.textContent = Math.round((doneCount / WIDTHS.length) * 100) + "%";
}
function togglePause(): void {
pausedRef.current = !pausedRef.current;
const root = rootRef.current;
if (root) root.classList.toggle("is-paused", pausedRef.current);
}
function restart(): void { t0Ref.current = performance.now(); draw(0); }
function onKey(e: KeyEvt): void {
if (e.key === " " || e.key === "Enter") { e.preventDefault(); togglePause(); }
else if (e.key === "r" || e.key === "R") { e.preventDefault(); restart(); }
}
function onClick(): void { togglePause(); }
function onResize(): void {
if (pausedRef.current || reduced()) draw((performance.now() - t0Ref.current) / 1000);
}
function frame(now: number): void {
if (!pausedRef.current) draw((now - t0Ref.current) / 1000);
rafRef.current = requestAnimationFrame(frame);
}
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const cs = getComputedStyle(root);
skeletonRef.current = hexToRgb(cs.getPropertyValue("--skeleton").trim() || "#4a4550");
textRef.current = hexToRgb(cs.getPropertyValue("--text-tone").trim() || "#5b8cf8");
t0Ref.current = performance.now();
window.addEventListener("resize", onResize);
if (reduced()) {
root.classList.add("is-still");
draw(LOOP * 0.62);
} else {
rafRef.current = requestAnimationFrame(frame);
}
return () => {
window.removeEventListener("resize", onResize);
cancelAnimationFrame(rafRef.current);
};
}, []);
return (
<main className={styles.stage}>
<div className={styles.root} ref={rootRef} style={vars}>
<p className={styles.hint}>
<svg className={styles.ico} viewBox="0 0 256 256" aria-hidden="true"><g fill="currentColor"><path d="M232 56v56a8 8 0 0 1-16 0V91.3l-25.6 25.7A80 80 0 1 1 174 60a8 8 0 1 1-9 13.2A64 64 0 1 0 179.7 128H216a8 8 0 0 1 0 16h-56a8 8 0 0 1-8-8V80a8 8 0 0 1 16 0v20.7L192.7 76A80.1 80.1 0 0 0 64 128a8 8 0 0 1-16 0a96 96 0 0 1 163.6-68.3L224 71.3V56a8 8 0 0 1 8 8" opacity=".2"/><path d="M224 48a8 8 0 0 0-8 8v15.3l-11.7-11.6a96 96 0 1 0 27.6 51.6a8 8 0 0 0-15.8 2.5a80 80 0 1 1-23-43l-25.7 25.7A8 8 0 0 0 173 112h56a8 8 0 0 0 8-8V56a8 8 0 0 0-13-8"/></g></svg>
<span>클릭하거나 스페이스바를 누르면 멈추거나 다시 갑니다</span>
</p>
<div
className={styles.field}
ref={fieldRef}
role="application"
aria-label={FIELD_LABEL}
tabIndex={0}
onClick={onClick}
onKeyDown={onKey}
>
<div className={styles.card}>
<div className={styles.cardHead}><i></i><i></i><i></i></div>
{WIDTHS.map((w, i) => (
<div
key={i}
className={styles.line}
style={{ "--w": w + "%" } as CSSProperties}
ref={(el: HTMLDivElement | null) => { lineRefs.current[i] = el; }}
>
<span className={styles.lineFill} ref={(el: HTMLSpanElement | null) => { fillRefs.current[i] = el; }}></span>
</div>
))}
</div>
<b className={styles.badge} aria-hidden="true"><span className={styles.badgeNum} ref={pctRef}>0%</span><span className={styles.badgeUnit}>채움</span></b>
</div>
</div>
</main>
);
}05 埋まった行数の値が増える結果カードのストリーム読み込み — 計測 累積面積 14.256% · 動いたフレーム 20/23GODRICH オリジナル · SCSS と React は zip に同梱 · AI処理中 アイコン 9パターン — 値で動くローディング
このデモが属する記事
AI処理中 アイコン 9パターン — 値で動くローディング処理中 アイコンとは:軌道半径の値が大きいと粒子は広く散らばるが、値が0に近づくとコアに集まり、その間ハローリングの色相の値は完了色へ動き、トークン番号の値が上がるたびプレビューの文字が一つずつ増える。 この記事のデモをすべて見る

