Skip to content

Commit 0f26d86

Browse files
authored
Merge branch 'main' into fix-issue-1983
2 parents 7c49a3d + 5fe2d64 commit 0f26d86

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

lib/svg/animations.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ describe('getTowerAnimationCSS', () => {
3030
expect(css).not.toContain('@keyframes');
3131
});
3232

33+
it('scales transform-origin for rise animation when scale factor is provided', () => {
34+
const cssScale045 = getTowerAnimationCSS('rise', 0.45);
35+
expect(cssScale045).toContain('transform-origin: 0 4.5px');
36+
37+
const cssScale08 = getTowerAnimationCSS('rise', 0.8);
38+
expect(cssScale08).toContain('transform-origin: 0 8px');
39+
});
40+
41+
it('scales translateY translation for slide animation when scale factor is provided', () => {
42+
const cssScale045 = getTowerAnimationCSS('slide', 0.45);
43+
expect(cssScale045).toContain('transform: translateY(-9px)');
44+
45+
const cssScale08 = getTowerAnimationCSS('slide', 0.8);
46+
expect(cssScale08).toContain('transform: translateY(-16px)');
47+
});
48+
3349
it('includes accessibility support for prefers-reduced-motion', () => {
3450
const css = getTowerAnimationCSS('rise');
3551
expect(css).toContain('prefers-reduced-motion');

lib/svg/animations.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
const TOWER_BASE_Y = 10;
2222

2323
export function getTowerAnimationCSS(
24-
entrance: 'rise' | 'fade' | 'slide' | 'none' = 'rise'
24+
entrance: 'rise' | 'fade' | 'slide' | 'none' = 'rise',
25+
scale = 1.0
2526
): string {
2627
if (entrance === 'none') {
2728
return `
@@ -33,9 +34,10 @@ export function getTowerAnimationCSS(
3334
let keyframes = '';
3435

3536
if (entrance === 'rise') {
37+
const baseY = Math.round(TOWER_BASE_Y * scale * 100) / 100;
3638
baseStyles = `
3739
transform: scaleY(0);
38-
transform-origin: 0 ${TOWER_BASE_Y}px;
40+
transform-origin: 0 ${baseY}px;
3941
animation: grow-up 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
4042
`;
4143
keyframes = `
@@ -56,14 +58,15 @@ export function getTowerAnimationCSS(
5658
}
5759
`;
5860
} else if (entrance === 'slide') {
61+
const slideOffset = Math.round(-20 * scale * 100) / 100;
5962
baseStyles = `
6063
opacity: 0;
61-
transform: translateY(-20px);
64+
transform: translateY(${slideOffset}px);
6265
animation: slide-down 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
6366
`;
6467
keyframes = `
6568
@keyframes slide-down {
66-
from { opacity: 0; transform: translateY(-20px); }
69+
from { opacity: 0; transform: translateY(${slideOffset}px); }
6770
to { opacity: 1; transform: translateY(0); }
6871
}
6972
`;

lib/svg/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function renderStyle(
221221
<style>
222222
@import url('https://fonts.googleapis.com/css2?family=Fira+Code&amp;family=JetBrains+Mono&amp;family=Roboto&amp;family=Syncopate:wght@400;700&amp;family=Space+Grotesk:wght@400;500;600;700&amp;display=swap');
223223
${googleFontsImport}
224-
${getTowerAnimationCSS(entrance)}
224+
${getTowerAnimationCSS(entrance, sf)}
225225
.scan-line {
226226
animation: scan-sweep var(--scan-speed, 8s) linear infinite;
227227
transform-box: fill-box;
@@ -617,7 +617,7 @@ function generateAutoThemeSVG(
617617
:root { --cp-bg: #${light.bg}; --cp-text: #${light.text}; --cp-accent: #${light.accent}; --cp-label-fill: ${lightLabelFill}; --cp-label-opacity: ${lightLabelOpacity}; }
618618
@media (prefers-color-scheme: dark) { :root { --cp-bg: #${dark.bg}; --cp-text: #${dark.text}; --cp-accent: #${dark.accent}; --cp-label-fill: ${darkLabelFill}; --cp-label-opacity: ${darkLabelOpacity}; } }
619619
.cp-bg-fill { fill: var(--cp-bg); } .cp-text-fill { fill: var(--cp-text); color: var(--cp-text); } .cp-accent-fill { fill: var(--cp-accent); color: var(--cp-accent); }
620-
${getTowerAnimationCSS(params.entrance || 'rise')}
620+
${getTowerAnimationCSS(params.entrance || 'rise', sf)}
621621
.scan-line {
622622
animation: scan-sweep var(--scan-speed, 8s) linear infinite;
623623
transform-box: fill-box;
@@ -2014,7 +2014,7 @@ function generateAutoThemeVersusSVG(
20142014
:root { --cp-bg: #${light.bg}; --cp-text: #${light.text}; --cp-accent: #${light.accent}; --cp-label-fill: ${lightLabelFill}; --cp-label-opacity: ${lightLabelOpacity}; }
20152015
@media (prefers-color-scheme: dark) { :root { --cp-bg: #${dark.bg}; --cp-text: #${dark.text}; --cp-accent: #${dark.accent}; --cp-label-fill: ${darkLabelFill}; --cp-label-opacity: ${darkLabelOpacity}; } }
20162016
.cp-bg-fill { fill: var(--cp-bg); } .cp-text-fill { fill: var(--cp-text); color: var(--cp-text); } .cp-accent-fill { fill: var(--cp-accent); color: var(--cp-accent); }
2017-
${getTowerAnimationCSS(params.entrance || 'rise')}
2017+
${getTowerAnimationCSS(params.entrance || 'rise', sf)}
20182018
.scan-line {
20192019
animation: scan-sweep var(--scan-speed, 8s) linear infinite;
20202020
transform-box: fill-box;

0 commit comments

Comments
 (0)