06완료 값이 뒤집히면 반짝임으로 바뀌는 버튼 아이콘
버튼 안 아이콘의 path 값을 스피너 모양에서 반짝임(스파클) 모양으로 미리 정해 두고, 완료 값이 false 에서 true 로 바뀌는 순간 그 path 값만 보간해 모양을 바꾼다.
쓰임AI 액션 버튼(요약하기·다시쓰기), 툴바 AI 아이콘
pathDONEMORPH_MS
<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">
<button class="ld__btn" type="button" tabindex="-1">
<svg class="ld__btnIco" id="btnIco" viewBox="-46 -46 92 92" aria-hidden="true">
<path id="path"></path>
</svg>
</button>
<b class="ld__badge" aria-hidden="true"><span class="ld__badgeNum" id="pct">처리중</span></b>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// button-icon-sparkle-morph — 버튼 아이콘의 path 값을 스피너 모양에서 반짝임(스파클) 모양으로
// 미리 정해 두고, 완료 값이 false 에서 true 로 바뀌는 순간 그 path 값만 보간해 모양을 바꾼다.
// SVG path 정점 보간 + rAF — @keyframes 없음.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-ink;
@include stage($stage-yellow);
.ld {
--spin: #{$subject-blue-deep};
--done: #{$subject-ink};
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-ink;
}
.ld__ico { width: 16px; height: 16px; flex: 0 0 auto; color: $subject-blue-deep; }
.ld__field {
position: relative; height: 208px;
display: flex; align-items: center; justify-content: center;
border-radius: $r-card; overflow: hidden;
background: rgba($subject-ink, .06);
box-shadow: inset 0 0 0 1px rgba($subject-ink, .16);
cursor: pointer;
}
.ld__field:focus-visible { outline: 2px solid $subject-blue-deep; outline-offset: 2px; }
.ld__btn {
position: relative;
display: flex; align-items: center; justify-content: center;
padding: $sp-3;
border: 0; border-radius: $r-pill;
background: $subject-cream;
box-shadow: 0 2px 0 rgba($subject-ink, .12);
cursor: pointer;
}
.ld__btnIco { width: 184px; height: 184px; flex: 0 0 auto; }
.ld__badge {
position: absolute; right: $sp-2; top: $sp-2;
padding: $sp-1 $sp-2; border-radius: $r-pill;
background: rgba($subject-ink, .82);
color: $subject-cream; font-weight: 700; font-size: 11px;
}
@media (max-width: 340px) {
.ld { gap: $sp-1; }
.ld__field { height: 124px; }
.ld__btn { padding: $sp-1; }
.ld__btnIco { width: 100px; height: 100px; }
.ld__badge { font-size: 10px; padding: 0 $sp-1; }
}
@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: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ld {
--spin: #0a4fe8;
--done: #17141a;
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: #17141a;
}
.ld__ico {
width: 16px;
height: 16px;
flex: 0 0 auto;
color: #0a4fe8;
}
.ld__field {
position: relative;
height: 208px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 16px;
overflow: hidden;
background: rgba(23, 20, 26, 0.06);
box-shadow: inset 0 0 0 1px rgba(23, 20, 26, 0.16);
cursor: pointer;
}
.ld__field:focus-visible {
outline: 2px solid #0a4fe8;
outline-offset: 2px;
}
.ld__btn {
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
border: 0;
border-radius: 999px;
background: #fff7e6;
box-shadow: 0 2px 0 rgba(23, 20, 26, 0.12);
cursor: pointer;
}
.ld__btnIco {
width: 184px;
height: 184px;
flex: 0 0 auto;
}
.ld__badge {
position: absolute;
right: 8px;
top: 8px;
padding: 4px 8px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.82);
color: #fff7e6;
font-weight: 700;
font-size: 11px;
}
@media (max-width: 340px) {
.ld {
gap: 4px;
}
.ld__field {
height: 124px;
}
.ld__btn {
padding: 4px;
}
.ld__btnIco {
width: 100px;
height: 100px;
}
.ld__badge {
font-size: 10px;
padding: 0 4px;
}
}
@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 FLIP_AT = LOOP * 0.5; // 완료 값이 뒤집히는 시각
var MORPH_MS = 0.32; // path 값 보간 시간
var ROT_SPEED = 220; // 스피너 회전 속도(도/초)
var R_RING = 26, R_OUT = 40, R_IN = 13;
var root = document.getElementById('ld');
var field = document.getElementById('field');
var path = document.getElementById('path');
var pctEl = document.getElementById('pct');
var paused = false;
var t0 = performance.now();
var raf = 0;
var DONE = false; // 완료 값(초기)
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 pt(ang, r) { return [r * Math.cos(ang), r * Math.sin(ang)]; }
function buildPath(radii, angOffset) {
var d = '';
for (var i = 0; i < 8; i++) {
var ang = angOffset + i * Math.PI / 4;
var p = pt(ang, radii[i]);
d += (i === 0 ? 'M' : 'L') + p[0].toFixed(2) + ',' + p[1].toFixed(2) + ' ';
}
return d + 'Z';
}
function draw(sec) {
var t = sec % LOOP;
var localFlip = t - FLIP_AT;
if (localFlip >= 0) { DONE = true; } else { DONE = false; }
var morphT = DONE ? smooth(clamp01(localFlip / MORPH_MS)) : 0;
var radii = [];
for (var i = 0; i < 8; i++) {
var spinnerR = R_RING;
var sparkleR = (i % 2 === 0) ? R_OUT : R_IN;
radii[i] = spinnerR + (sparkleR - spinnerR) * morphT;
}
var angleOffset = (sec * ROT_SPEED) % 360 * Math.PI / 180;
var rot = DONE ? angleOffset * 0.12 : angleOffset;
path.setAttribute('d', buildPath(radii, rot));
var pulse = 1;
if (DONE && localFlip < 0.5) {
pulse = 1 + 0.22 * Math.sin(clamp01(localFlip / 0.5) * Math.PI);
}
path.setAttribute('transform', 'scale(' + pulse.toFixed(3) + ')');
path.setAttribute('fill', DONE ? 'var(--done)' : 'var(--spin)');
pctEl.textContent = DONE ? '완료' : '처리중';
}
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);
}
})();// SparkleMorph — vanilla 판(run/403/demo/06-ai-processing-loading-button-icon-sparkle-morph/index.html) 의 React 포트.
// 버튼 아이콘의 path 값을 스피너 모양에서 반짝임(스파클) 모양으로 미리 정해 두고, 완료 값이
// false 에서 true 로 바뀌는 순간 그 path 값만 보간해 모양을 바꾼다. SVG 정점 보간 + rAF.
import { useEffect, useRef } from "react";
import type { CSSProperties } from "react";
import styles from "./SparkleMorph.module.scss";
export type SparkleMorphProps = {
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 FLIP_AT = LOOP * 0.5;
const MORPH_MS = 0.32;
const ROT_SPEED = 220;
const R_RING = 26, R_OUT = 40, R_IN = 13;
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 pt(ang: number, r: number): [number, number] { return [r * Math.cos(ang), r * Math.sin(ang)]; }
function buildPath(radii: number[], angOffset: number): string {
let d = "";
for (let i = 0; i < 8; i++) {
const ang = angOffset + i * Math.PI / 4;
const p = pt(ang, radii[i]);
d += (i === 0 ? "M" : "L") + p[0].toFixed(2) + "," + p[1].toFixed(2) + " ";
}
return d + "Z";
}
export default function SparkleMorph({
duration = "2s",
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#17141a",
}: SparkleMorphProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const fieldRef = useRef<HTMLDivElement | null>(null);
const pathRef = useRef<SVGPathElement | null>(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 doneRef = useRef(false) as Box<boolean>;
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 path = pathRef.current;
const pctEl = pctRef.current;
if (!path) return;
const t = sec % LOOP;
const localFlip = t - FLIP_AT;
if (localFlip >= 0) { doneRef.current = true; } else { doneRef.current = false; }
const done = doneRef.current;
const morphT = done ? smooth(clamp01(localFlip / MORPH_MS)) : 0;
const radii: number[] = [];
for (let i = 0; i < 8; i++) {
const spinnerR = R_RING;
const sparkleR = (i % 2 === 0) ? R_OUT : R_IN;
radii[i] = spinnerR + (sparkleR - spinnerR) * morphT;
}
const angleOffset = ((sec * ROT_SPEED) % 360) * Math.PI / 180;
const rot = done ? angleOffset * 0.12 : angleOffset;
path.setAttribute("d", buildPath(radii, rot));
let pulse = 1;
if (done && localFlip < 0.5) {
pulse = 1 + 0.22 * Math.sin(clamp01(localFlip / 0.5) * Math.PI);
}
path.setAttribute("transform", "scale(" + pulse.toFixed(3) + ")");
path.setAttribute("fill", done ? "var(--done)" : "var(--spin)");
if (pctEl) pctEl.textContent = done ? "완료" : "처리중";
}
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(() => {
t0Ref.current = performance.now();
window.addEventListener("resize", onResize);
if (reduced()) {
const root = rootRef.current;
if (root) 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}
>
<button className={styles.btn} type="button" tabIndex={-1}>
<svg className={styles.btnIco} viewBox="-46 -46 92 92" aria-hidden="true">
<path ref={pathRef}></path>
</svg>
</button>
<b className={styles.badge} aria-hidden="true"><span className={styles.badgeNum} ref={pctRef}>처리중</span></b>
</div>
</div>
</main>
);
}06 완료 값이 뒤집히면 반짝임으로 바뀌는 버튼 아이콘 — 측정 누적면적 10.111% · 움직인 프레임 23/23GODRICH 원작 · zip 에 SCSS·React 포함 · AI 로딩 애니메이션 9가지 — 값 하나로 도는 처리중 표시
이 데모가 속한 글
AI 로딩 애니메이션 9가지 — 값 하나로 도는 처리중 표시궤도 반경 값이 크면 입자가 넓게 흩어지는데 값이 0에 가까워지면 코어로 모이고, 그 사이 후광 링의 색상 값은 완료 색 쪽으로 넘어가며, 토큰 순번 값이 오를 때마다 미리보기 글자가 하나씩 늘어난다. 이 아홉 가지 이 글의 데모 전부 보기

