-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
401 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const DEFAULT_SLIDE_WIDTH = 960 | ||
export const DEFAULT_SLIDE_HEIGHT = 540 | ||
export const SLIDE_RATIO = DEFAULT_SLIDE_WIDTH / DEFAULT_SLIDE_HEIGHT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { type Block } from '@BlockHub/Block/Block' | ||
|
||
export class Animation { | ||
constructor( | ||
public type: 'Entrance' | 'Emphasis' | 'Exit', | ||
public name: string, | ||
public block: Block, | ||
public propName: string, | ||
public startValue: any, | ||
public endValue: any, | ||
public duration: number, | ||
public delay: number | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { BasicPropName } from '@BlockHub/Block/Block' | ||
import { Animation } from './Animation' | ||
|
||
type TimelineState = 'initial' | 'preview' | 'running' | ||
|
||
export class Timeline { | ||
private _state: TimelineState = 'initial' | ||
private _startTime = 0 | ||
private _animations: Set<Animation> = new Set() | ||
private _previewAnimations: Set<Animation> = new Set() | ||
private _runningAnimations: Set<Animation> = new Set() | ||
|
||
private _tick() { | ||
const animations = this._state === 'running' ? this._runningAnimations : this._previewAnimations | ||
const elapsedTime = Date.now() - this._startTime | ||
for (const animation of animations) { | ||
const { block, propName, startValue, endValue, duration, delay } = animation | ||
let progress | ||
if (elapsedTime < delay) { | ||
progress = 0 | ||
} else if (elapsedTime < delay + duration) { | ||
// time progress -> effect progress | ||
progress = (elapsedTime - delay) / duration | ||
} else { | ||
progress = 1 | ||
animations.delete(animation) | ||
} | ||
block[propName as BasicPropName] = startValue + (endValue - startValue) * progress | ||
} | ||
if (animations.size > 0) { | ||
requestAnimationFrame(this._tick.bind(this)) | ||
} else { | ||
this._state = 'initial' | ||
} | ||
} | ||
|
||
get animations() { | ||
return this._animations | ||
} | ||
|
||
add(animation: Animation) { | ||
this._animations.add(animation) | ||
} | ||
|
||
delete(animation: Animation) { | ||
this._animations.delete(animation) | ||
} | ||
|
||
preview() { | ||
this._state = 'preview' | ||
this._previewAnimations = new Set([...this._animations].slice(-1)) | ||
this._startTime = Date.now() | ||
this._tick() | ||
} | ||
|
||
start() { | ||
this._state = 'running' | ||
this._runningAnimations = new Set([...this._animations]) | ||
this._startTime = Date.now() | ||
this._tick() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script setup lang="ts"> | ||
import { slideManager } from '@Kernel/index' | ||
import { triggerRef } from 'vue' | ||
import { shallowRef } from 'vue' | ||
import { Delete } from '@icon-park/vue-next' | ||
const slide = shallowRef(slideManager.currentSlide) | ||
const animations = shallowRef(slide.value.animations) | ||
const updateAnimations = () => { | ||
slide.value.events.animationChange.on(() => { | ||
animations.value = slide.value.animations | ||
triggerRef(animations) | ||
}) | ||
} | ||
slideManager.events.update.on(() => { | ||
slide.value = slideManager.currentSlide | ||
updateAnimations() | ||
}) | ||
updateAnimations() | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="w-[250px] flex-none flex flex-col gap-[6px] items-center border-l border-secondary-border bg-secondary" | ||
v-if="animations.size" | ||
> | ||
<div class="text-base pt-[10px] pb-[6px]">Animation</div> | ||
<div v-for="animation of animations" class="flex flex-col gap-[2px] w-[220px] p-[10px] shadow bg-white"> | ||
<div class="flex justify-between items-center"> | ||
<span | ||
:style="{ | ||
color: { | ||
Entrance: '#309048FF', | ||
Emphasis: '#DE6C00FF', | ||
Exit: '#ED3D3BFF', | ||
}[animation.type], | ||
}" | ||
>{{ animation.type }}: {{ animation.name }}</span | ||
> | ||
<Delete | ||
theme="outline" | ||
size="24" | ||
fill="#333" | ||
:strokeWidth="2" | ||
class="menu-btn" | ||
@click="slide.deleteAnimation(animation)" | ||
/> | ||
</div> | ||
<div class="flex justify-between"> | ||
<span>Duration:</span><input type="number" class="border w-[90px]" v-model="animation.duration" /> | ||
</div> | ||
<div class="flex justify-between"> | ||
<span>Delay:</span><input type="number" class="border w-[90px]" v-model="animation.delay" /> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script setup lang="ts"> | ||
import { BasicPropName, type Block } from '@BlockHub/Block/Block' | ||
import { BlockViews } from '@BlockHub/BlockHub' | ||
import { ref } from 'vue' | ||
const { block } = defineProps<{ | ||
block: Block | ||
}>() | ||
const { x, y, width, height, rotate } = block | ||
const props = ref({ x, y, width, height, rotate }) | ||
block.props.events.update.on(({ key, to }) => { | ||
if (['x', 'y', 'width', 'height', 'rotate'].includes(key)) { | ||
const name = key as BasicPropName | ||
props.value[name] = to as number | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<component | ||
:key="block.id" | ||
:is="BlockViews[block.type]" | ||
:block="block" | ||
:style="{ | ||
position: 'absolute', | ||
left: `${props.x}px`, | ||
top: `${props.y}px`, | ||
width: `${props.width}px`, | ||
height: `${props.height}px`, | ||
rotate: `${props.rotate}deg`, | ||
}" | ||
></component> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/UserInterface/ToolBar/components/Animations/Animations.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
import Entrance from './components/Entrance.vue' | ||
import Emphasis from './components/Emphasis.vue' | ||
import Exit from './components/Exit.vue' | ||
</script> | ||
|
||
<template> | ||
<Entrance /> | ||
<Emphasis /> | ||
<Exit /> | ||
</template> |
Oops, something went wrong.