Last active
May 13, 2022 09:14
-
-
Save jwx/5aaaac09bd99dd7a48ca5f0d86afcad4 to your computer and use it in GitHub Desktop.
au2-animation-test
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
<base href="/"> | |
</head> | |
<!-- | |
Dumber Gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. | |
The starting module is pointed to "main" (data-main attribute on script) | |
which is your src/main.ts. | |
--> | |
<body> | |
<my-app></my-app> | |
<script src="/dist/entry-bundle.js" data-main="main"></script> | |
</body> | |
</html> |
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
{ | |
"dependencies": { | |
"aurelia": "latest", | |
"@aurelia/router": "latest" | |
} | |
} |
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
import { lifecycleHooks } from '@aurelia/runtime-html'; | |
@lifecycleHooks() | |
export class AnimationHooks { | |
// Only routing hooks are yet supported | |
//public created(vm, controller): void { | |
// vm.element = controller.host; | |
//} | |
public load(vm, _params, _instruction, navigation) { | |
vm.backwards = navigation.navigation.back; | |
} | |
public unload(vm, _instruction, navigation) { | |
vm.backwards = navigation.navigation.back; | |
} | |
// Only routing hooks are yet supported | |
//public attaching() { | |
// return slideIn(vm.element, 750, vm.backwards ? 'left' : 'right'); | |
//} | |
// Only routing hooks are yet supported | |
//public detaching() { | |
// return slideOut(vm.element, 750, vm.backwards ? 'right' : 'left'); | |
//} | |
} |
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
export function promiseAnimation(element: Element, animation: any, duration: number) { | |
let resolve; | |
const promise = new Promise(r => { resolve = r; }); | |
const anim = element.animate(animation, duration); | |
anim.onfinish = () => resolve(); | |
return promise; | |
} | |
export function slideIn(element: Element, duration: number, from: 'left' | 'right' = 'right') { | |
return promiseAnimation(element, { transform: [`translateX(${from === 'left' ? '-' : ''}100%)`, 'translateX(0)'] }, duration); | |
} | |
export function slideOut(element: Element, duration: number, to: 'left' | 'right' = 'left') { | |
return promiseAnimation(element, { transform: ['translateX(0)', `translateX(${to === 'left' ? '-' : ''}100%)`] }, duration); | |
} |
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
import Aurelia from 'aurelia'; | |
import { RouterConfiguration } from '@aurelia/router'; | |
import { AnimationHooks } from './animation-hooks'; | |
import { MyApp } from './my-app'; | |
Aurelia | |
.register(RouterConfiguration.customize({ swapOrder: 'detach-attach-simultaneously', })) | |
.register(AnimationHooks) | |
.app(MyApp) | |
.start(); |
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
a { | |
background-color: #ccc; | |
margin: 0; | |
padding: 10px; | |
display: inline-block; | |
text-decoration: none; | |
} | |
a:hover { | |
background-color: #eee; | |
} | |
a.active { | |
background-color: gold; | |
} | |
au-viewport { | |
display: grid; | |
} | |
au-viewport > * { | |
display: block; | |
position: relative; | |
grid-column: 1; | |
grid-row: 1; | |
} |
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
<!-- | |
Try to create a paired css/scss/sass/less file like my-app.scss. | |
It will be automatically imported based on convention. | |
--> | |
<!-- | |
There is no bundler config you can change in Dumber Gist to | |
turn on shadow DOM. | |
But you can turn shadow DOM on by adding a meta tag in every | |
html template: | |
<use-shadow-dom> | |
--> | |
<import from="./one"></import> | |
<import from="./two"></import> | |
<h1>${message}!</h1> | |
<a load="one">One</a><a load="two">Two</a> | |
<au-viewport></au-viewport> |
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
export class MyApp { | |
public message: string = 'Hello Aurelia 2!'; | |
} |
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
One |
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
import { slideIn, slideOut } from './animations'; | |
export class One { | |
// Once support is there, this would also move to animation-hooks.ts | |
public created(controller): void { | |
this.element = controller.host; | |
} | |
//public load(_params, _instruction, navigation) { | |
// this.backwards = navigation.navigation.back; | |
//} | |
// After the next router release, this method can also be moved to animation-hooks.ts | |
public unload(_instruction, navigation) { | |
this.backwards = navigation.navigation.back; | |
} | |
// Once support is there, this would also move to animation-hooks.ts | |
public attaching() { | |
return slideIn(this.element, 750, this.backwards ? 'left' : 'right'); | |
} | |
// Once support is there, this would also move to animation-hooks.ts | |
public detaching() { | |
return slideOut(this.element, 750, this.backwards ? 'right' : 'left'); | |
} | |
} |
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
Two |
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
import { slideIn, slideOut } from './animations'; | |
export class Two { | |
// Once support is there, this would also move to animation-hooks.ts | |
public created(controller): void { | |
this.element = controller.host; | |
} | |
//public load(_params, _instruction, navigation) { | |
// this.backwards = navigation.navigation.back; | |
//} | |
// After the next router release, this method can also be moved to animation-hooks.ts | |
public unload(_instruction, navigation) { | |
this.backwards = navigation.navigation.back; | |
} | |
// Once support is there, this would also move to animation-hooks.ts | |
public attaching() { | |
debugger; | |
return slideIn(this.element, 750, this.backwards ? 'left' : 'right'); | |
} | |
// Once support is there, this would also move to animation-hooks.ts | |
public detaching() { | |
console.log('two detaching backwards', this.backwards); | |
return slideOut(this.element, 750, this.backwards ? 'right' : 'left'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment