Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 892acb9

Browse files
authored
Migrate to free GSAP (#33)
* Install free GSAP * Remove paid GSAP tests * Remove paid GSAP plugins usage * Replace GSAP MorphSVG with flubber * Optimize interpolators * Simple transition without morph * Update dependencies * Update version
1 parent c6f7ef3 commit 892acb9

File tree

10 files changed

+3984
-3760
lines changed

10 files changed

+3984
-3760
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ on:
66
# schedule:
77
# - cron: "0 3 * * *"
88

9-
env:
10-
GSAP_TOKEN: ${{secrets.GSAP_TOKEN}}
11-
129
jobs:
1310
build-and-deploy:
1411
runs-on: ubuntu-latest
@@ -28,9 +25,6 @@ jobs:
2825
- name: Prepare Nuxt
2926
run: npx nuxi prepare
3027

31-
- name: Test
32-
run: npm run test
33-
3428
- name: Build Nuxt 3 static site
3529
run: npm run generate
3630

.npmrc

Lines changed: 0 additions & 2 deletions
This file was deleted.

components/d/character/Index.vue

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
import gsap from 'gsap'
3-
42
import idle from '../../../assets/img/character/idle.webp'
53
import idleColor from '../../../assets/img/character/idle-color.webp'
64
import idleOutline from '../../../assets/img/character/idle-outline.webp'
@@ -13,6 +11,7 @@ import profi from '../../../assets/img/character/profi.webp'
1311
import profiColor from '../../../assets/img/character/profi-color.webp'
1412
import profiOutline from '../../../assets/img/character/profi-outline.webp'
1513
import profiOutlineColor from '../../../assets/img/character/profi-outline-color.webp'
14+
import type { CSSProperties } from 'vue'
1615
1716
export type CharacterPose = 'idle' | 'action' | 'profi'
1817
@@ -58,44 +57,19 @@ function getAsset(pose: CharacterPose) {
5857
]
5958
}
6059
61-
let initialSvgPath: ReturnType<typeof resolveComponent>
6260
const useHref = ref(`#${props.pose}-shape`)
63-
64-
switch (props.pose) {
65-
case 'idle':
66-
initialSvgPath = resolveComponent('DCharacterShapeIdle')
67-
break
68-
case 'profi':
69-
initialSvgPath = resolveComponent('DCharacterShapeProfi')
70-
break
71-
case 'action':
72-
initialSvgPath = resolveComponent('DCharacterShapeAction')
73-
break
74-
}
75-
76-
const shapeToAnimate = ref<ComponentPublicInstance | null>(null)
77-
const shapeIdle = ref<ComponentPublicInstance | null>(null)
78-
const shapeAction = ref<ComponentPublicInstance | null>(null)
79-
const shapeProfi = ref<ComponentPublicInstance | null>(null)
61+
const useStyle = reactive<CSSProperties>({})
8062
8163
watch(
8264
() => props.pose,
83-
(newPose, oldPose) => {
65+
async (newPose, oldPose) => {
8466
if (props.noShape) return
85-
const poseShapeMap: Record<CharacterPose, SVGPathElement> = {
86-
idle: shapeIdle.value?.$el,
87-
action: shapeAction.value?.$el,
88-
profi: shapeProfi.value?.$el
89-
}
90-
if (isMorphSVGPluginInstalled()) {
91-
gsap.fromTo(
92-
shapeToAnimate.value?.$el,
93-
{ morphSVG: poseShapeMap[oldPose] },
94-
{ morphSVG: poseShapeMap[newPose], duration: 0.2 }
95-
)
96-
} else {
97-
useHref.value = `#${newPose}-shape`
98-
}
67+
useStyle.transform = 'scale(0.5)'
68+
useStyle.filter = 'blur(10px)'
69+
await new Promise(resolve => setTimeout(resolve, 150))
70+
useHref.value = `#${newPose}-shape`
71+
useStyle.transform = undefined
72+
useStyle.filter = undefined
9973
}
10074
)
10175
</script>
@@ -105,21 +79,17 @@ watch(
10579
<div class="relative isolate w-full h-full">
10680
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
10781
<defs v-if="!noShape">
108-
<DCharacterShapeIdle id="idle-shape" ref="shapeIdle" />
109-
<DCharacterShapeAction id="action-shape" ref="shapeAction" />
110-
<DCharacterShapeProfi id="profi-shape" ref="shapeProfi" />
82+
<DCharacterShapeIdle id="idle-shape" />
83+
<DCharacterShapeAction id="action-shape" />
84+
<DCharacterShapeProfi id="profi-shape" />
11185
</defs>
11286
<g v-if="!noShape">
113-
<component
114-
:is="initialSvgPath"
115-
v-show="isMorphSVGPluginInstalled()"
116-
ref="shapeToAnimate"
117-
:class="shapeClass"
118-
/>
11987
<use
120-
v-show="!isMorphSVGPluginInstalled()"
88+
class="transition-all"
89+
:style="useStyle"
12190
:class="shapeClass"
12291
:href="useHref"
92+
transform-origin="512 512"
12393
/>
12494
</g>
12595
</svg>

composables/calculations.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const cache = new Map<string, any>()
2+
3+
export function useCache<T>(key: string, fn: () => T): T {
4+
if (cache.has(key)) {
5+
return cache.get(key)
6+
}
7+
const value = fn()
8+
cache.set(key, value)
9+
return value
10+
}

0 commit comments

Comments
 (0)