@lightningjs/blits 1.30.1 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/package.json +4 -3
- package/src/router/router.js +2 -0
- package/vite/preCompiler.js +6 -1
- package/.editorconfig +0 -7
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -65
- package/.github/workflows/comment-lint-results.yml +0 -125
- package/.github/workflows/comment-test-results.yml +0 -109
- package/.github/workflows/deploy-docs.yml +0 -27
- package/.github/workflows/run-blits-tests.yml +0 -142
- package/.github/workflows/run-lint.yml +0 -128
- package/.husky/pre-commit +0 -1
- package/.husky/pre-push +0 -1
- package/.vscode/extensions.json +0 -7
- package/.vscode/settings.json +0 -9
- package/banner.png +0 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +0 -19
- package/docs/_sidebar.md +0 -37
- package/docs/built-in/directives.md +0 -50
- package/docs/built-in/for-loop.md +0 -204
- package/docs/built-in/layout.md +0 -168
- package/docs/components/component_state.md +0 -90
- package/docs/components/computed_properties.md +0 -45
- package/docs/components/lifecycle_events.md +0 -42
- package/docs/components/methods.md +0 -45
- package/docs/components/props.md +0 -56
- package/docs/components/user_input.md +0 -186
- package/docs/components/utility_methods.md +0 -320
- package/docs/components/watchers.md +0 -34
- package/docs/essentials/application_root.md +0 -19
- package/docs/essentials/components.md +0 -68
- package/docs/essentials/displaying_images.md +0 -67
- package/docs/essentials/displaying_text.md +0 -135
- package/docs/essentials/element_attributes.md +0 -195
- package/docs/essentials/settings.md +0 -117
- package/docs/essentials/template_syntax.md +0 -83
- package/docs/getting_started/file_structure.md +0 -58
- package/docs/getting_started/getting_started.md +0 -45
- package/docs/getting_started/intro.md +0 -20
- package/docs/index.html +0 -47
- package/docs/performance/lazy-loading.md +0 -161
- package/docs/plugins/global_app_state.md +0 -98
- package/docs/plugins/language.md +0 -172
- package/docs/plugins/text-to-speech-announcer.md +0 -120
- package/docs/plugins/theme.md +0 -176
- package/docs/router/basics.md +0 -175
- package/docs/router/hooks.md +0 -70
- package/docs/router/transitions.md +0 -146
- package/docs/sidebar.json +0 -171
- package/docs/transitions_animations/transitions.md +0 -150
- package/jsconfig.json +0 -12
- package/src/component/setup/props.test.js +0 -238
- package/src/component.test.js +0 -388
- package/src/components/Circle.orig.js +0 -31
- package/src/components/FPScounter.orig.js +0 -121
- package/src/components/RouterView.orig.js +0 -54
- package/src/components/Sprite.orig.js +0 -58
- package/src/components/index.orig.js +0 -28
- package/src/engines/L3/element.test.js +0 -579
- package/src/helpers/deepEqualArray.test.js +0 -127
- package/src/lib/codegenerator/generator.test.js +0 -3801
- package/src/lib/colors/colors.test.js +0 -290
- package/src/lib/componentId.test.js +0 -84
- package/src/lib/eventListeners.test.js +0 -236
- package/src/lib/reactivity/effect.test.js +0 -35
- package/src/lib/reactivity/reactive.test.js +0 -27
- package/src/lib/templateparser/parser.test.js +0 -1411
- package/src/router/router.test.js +0 -473
package/docs/router/hooks.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Router Hooks
|
|
2
|
-
|
|
3
|
-
The Blits router supports hooks that allow you to execute code at specific points during the navigation process.
|
|
4
|
-
|
|
5
|
-
Hooks are defined per route in the optional `hooks` key within the Route configuration object.
|
|
6
|
-
|
|
7
|
-
> Currently, the Blits router only supports the before hook, with additional hooks planned for future releases.
|
|
8
|
-
|
|
9
|
-
## Before hook
|
|
10
|
-
|
|
11
|
-
The before hook is executed before the navigation occurs. It can be used for checks, such as verifying user authentication for a specific route, for pre-fetching data, or for executing logic like sending stats beacons.
|
|
12
|
-
|
|
13
|
-
The before hook is defined as a function that receives 2 arguments: the Route object that is being navigated `to`. And the Route object that is being navigated away `from`.
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
export default Blits.Application({
|
|
17
|
-
// ...
|
|
18
|
-
routes: [
|
|
19
|
-
{
|
|
20
|
-
path: '/',
|
|
21
|
-
component: Home,
|
|
22
|
-
hooks: {
|
|
23
|
-
before(to, from) {
|
|
24
|
-
// custom logic
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
// ...
|
|
30
|
-
})
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
The before hook can optionally return a value, which will influence the behaviour of the route change:
|
|
34
|
-
|
|
35
|
-
- when `false` is returned, the router will fail to finish the routing, and act as if _no matching route was found_
|
|
36
|
-
- when a `string` is returned, the router will interpret this as a _new route path to redirect to_
|
|
37
|
-
- when an `object` is returned, the router will interpret this as a route object, allowing to _modify (or completely replace) the route object_ being navigated to
|
|
38
|
-
|
|
39
|
-
Returning an `object` is a simple, yet powerful, mechanism to add advanced runtime configuration to your routes. A common scenario is to overwrite certain parts of the route object provided in the `to`-argument, such as the route options (such as `inHistory` or `stayAlive`) or define conditional page transitions.
|
|
40
|
-
|
|
41
|
-
It's also possible to add custom data to the route object in the `key` object. Custom data should be an object literal. When the new page loads, the keys in the `data` object are injected into the Component as `props`.
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
export default Blits.Application({
|
|
45
|
-
// ...
|
|
46
|
-
routes: [
|
|
47
|
-
{
|
|
48
|
-
path: '/video/details/:id',
|
|
49
|
-
component: Details,
|
|
50
|
-
hooks: {
|
|
51
|
-
before(to, from) {
|
|
52
|
-
// redirect to an error page when id is not a number
|
|
53
|
-
if(isNaN(to.params.id)) {
|
|
54
|
-
return '/not-valid'
|
|
55
|
-
}
|
|
56
|
-
// set a different transition when navigating from home page
|
|
57
|
-
if(from && from.path === '/home') {
|
|
58
|
-
to.transition = slideInTransition
|
|
59
|
-
}
|
|
60
|
-
// add custom data
|
|
61
|
-
to.data.title = 'Hello World'
|
|
62
|
-
// finally return the modified route object
|
|
63
|
-
return to
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
// ...
|
|
69
|
-
})
|
|
70
|
-
```
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# Router Transitions
|
|
2
|
-
|
|
3
|
-
Page transitions add a layer of visual polish to your application by animating the change between routes.
|
|
4
|
-
|
|
5
|
-
When the router in Blits navigates to a new page, it automatically applies a subtle _fade-in / fade-out_ transition. Blits also allows to specify custom transitions on a per-route basis.
|
|
6
|
-
|
|
7
|
-
## Defining Route Transitions
|
|
8
|
-
|
|
9
|
-
In the Route object, the `transition` key can be used to specify which transition should be applied when navigating _to_ that route.
|
|
10
|
-
|
|
11
|
-
It accepts a _Transition_ object, with 3 optional keys: `before`, `in`, `out`.
|
|
12
|
-
|
|
13
|
-
### Before
|
|
14
|
-
|
|
15
|
-
The `before` key is used to set a property to a certain value _before_ the page transition starts. The properties are set on the page that is being navigated _to_. For example, it can be used to position the page out of screen by setting the `x` value to a negative value, in order to create a _slide in from the right_ effect. Or the `alpha` property can be set to `0` if you want to create a _fade-in_ effect.
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
const pageTransition = {
|
|
19
|
-
// position the new page outside the screen on the left side
|
|
20
|
-
before: {
|
|
21
|
-
prop: 'x',
|
|
22
|
-
value: -1920
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
In order to set multiple properties to an initial state, an Array of objects can be assigned to the `before` key.
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
const pageTransition = {
|
|
31
|
-
// position the new page outside the screen on the left side
|
|
32
|
-
// and set the alpha to 0
|
|
33
|
-
before: [{
|
|
34
|
-
prop: 'x',
|
|
35
|
-
value: -1920
|
|
36
|
-
},{
|
|
37
|
-
prop: 'alpha',
|
|
38
|
-
value: 0
|
|
39
|
-
}]
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### In
|
|
44
|
-
|
|
45
|
-
The `in`-key is used to define how the new page should transition _into_ the screen, given the initial defaults, in combination with any properties set in the optional `before` key.
|
|
46
|
-
|
|
47
|
-
The transition is defined by a _Transition_ object, consisting of:
|
|
48
|
-
|
|
49
|
-
- `prop` - the property to apply the transition on
|
|
50
|
-
- `value` - the value to transition to
|
|
51
|
-
- `duration` (optional) - the duration of the transition in milliseconds (defaults to `300ms`)
|
|
52
|
-
- `easing` (optional) - the easing function applied to the transition (defaults to `ease-in`)
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
const pageTransition = {
|
|
56
|
-
// position the new page outside the screen on the left side
|
|
57
|
-
before: {
|
|
58
|
-
prop: 'x',
|
|
59
|
-
value: -1920
|
|
60
|
-
},
|
|
61
|
-
// transition the new page from outside, into the screen
|
|
62
|
-
in: {
|
|
63
|
-
prop: 'x',
|
|
64
|
-
value: 0,
|
|
65
|
-
duration: 800,
|
|
66
|
-
easing: 'cubic-bezier(0.20, 1.00, 0.80, 1.00)'
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
In order to transition multiple properties, an Array of objects can be assigned to the `in` key.
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
const pageTransition = {
|
|
75
|
-
// position the new page outside the screen on the left side
|
|
76
|
-
// and set the alpha to 0
|
|
77
|
-
before: [{
|
|
78
|
-
prop: 'x',
|
|
79
|
-
value: -1920
|
|
80
|
-
},{
|
|
81
|
-
prop: 'alpha',
|
|
82
|
-
value: 0
|
|
83
|
-
}],
|
|
84
|
-
// transition the new page from outside, into the screen
|
|
85
|
-
// and transition the alpha from 0 to 1
|
|
86
|
-
in: [{
|
|
87
|
-
prop: 'x',
|
|
88
|
-
value: 0,
|
|
89
|
-
duration: 800,
|
|
90
|
-
easing: 'cubic-bezier(0.20, 1.00, 0.80, 1.00)'
|
|
91
|
-
},{
|
|
92
|
-
prop: 'alpha',
|
|
93
|
-
value: 1,
|
|
94
|
-
duration: 500,
|
|
95
|
-
}]
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Out
|
|
100
|
-
|
|
101
|
-
Finally the `out`-key is used to define how the old page should transition _out of_ the screen.
|
|
102
|
-
|
|
103
|
-
Similar to the `in`-transition, the `out`-transition is defined by a _Transition object_, consisting of:
|
|
104
|
-
|
|
105
|
-
- `prop` - the property to apply the transition on
|
|
106
|
-
- `value` - the value to transition to
|
|
107
|
-
- `duration` (optional) - the duration of the transition in milliseconds (defaults to `300ms`)
|
|
108
|
-
- `easing` (optional) - the easing function applied to the transition (defaults to `ease-in`)
|
|
109
|
-
|
|
110
|
-
And in order to transition multiple properties at the same time during the _out_ transition, an Array of transition objects can be supplied.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
const pageTransition = {
|
|
115
|
-
// position the new page outside the screen on the left side
|
|
116
|
-
// and set the alpha to 0
|
|
117
|
-
before: [{
|
|
118
|
-
prop: 'x',
|
|
119
|
-
value: -1920
|
|
120
|
-
},{
|
|
121
|
-
prop: 'alpha',
|
|
122
|
-
value: 0
|
|
123
|
-
}],
|
|
124
|
-
// transition the new page from outside, into the screen
|
|
125
|
-
// and transition the alpha from 0 to 1
|
|
126
|
-
in: [{
|
|
127
|
-
prop: 'x',
|
|
128
|
-
value: 0,
|
|
129
|
-
duration: 800,
|
|
130
|
-
easing: 'cubic-bezier(0.20, 1.00, 0.80, 1.00)'
|
|
131
|
-
},{
|
|
132
|
-
prop: 'alpha',
|
|
133
|
-
value: 1,
|
|
134
|
-
duration: 500,
|
|
135
|
-
}],
|
|
136
|
-
// slide up the old page
|
|
137
|
-
// while rotating
|
|
138
|
-
out: [{
|
|
139
|
-
prop: 'y',
|
|
140
|
-
value: -1080
|
|
141
|
-
},{
|
|
142
|
-
prop: 'rotate',
|
|
143
|
-
value: 720
|
|
144
|
-
}]
|
|
145
|
-
}
|
|
146
|
-
```
|
package/docs/sidebar.json
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"text": "Getting Started",
|
|
4
|
-
"items": [
|
|
5
|
-
{
|
|
6
|
-
"text": "Intro",
|
|
7
|
-
"link": "/getting_started/intro"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"text": "Getting started",
|
|
11
|
-
"link": "/getting_started/getting_started"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"text": "File structure",
|
|
15
|
-
"link": "/getting_started/file_structure"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"text": "Essentials",
|
|
21
|
-
"items": [
|
|
22
|
-
{
|
|
23
|
-
"text": "Application root",
|
|
24
|
-
"link": "/essentials/application_root"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"text": "Component basics",
|
|
28
|
-
"link": "/essentials/components"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"text": "Template syntax",
|
|
32
|
-
"link": "/essentials/template_syntax"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"text": "Supported element attributes",
|
|
36
|
-
"link": "/essentials/element_attributes"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"text": "Displaying images",
|
|
40
|
-
"link": "/essentials/displaying_images"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"text": "Displaying text",
|
|
44
|
-
"link": "/essentials/displaying_text"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"text": "Application settings",
|
|
48
|
-
"link": "/essentials/settings"
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"text": "Components",
|
|
54
|
-
"items": [
|
|
55
|
-
{
|
|
56
|
-
"text": "State",
|
|
57
|
-
"link": "/components/component_state"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"text": "Props",
|
|
61
|
-
"link": "/components/props"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"text": "Computed properties",
|
|
65
|
-
"link": "/components/computed_properties"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
"text": "Watchers",
|
|
69
|
-
"link": "/components/watchers"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"text": "Hooking into lifecycle events",
|
|
73
|
-
"link": "/components/lifecycle_events"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"text": "Handling User input",
|
|
77
|
-
"link": "/components/user_input"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"text": "Methods",
|
|
81
|
-
"link": "/components/methods"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"text": "Utility methods",
|
|
85
|
-
"link": "/components/utility_methods"
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"text": "Transitions and Animations",
|
|
91
|
-
"items": [
|
|
92
|
-
{
|
|
93
|
-
"text": "Transitions",
|
|
94
|
-
"link": "/transitions_animations/transitions"
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"text": "Built-in components",
|
|
100
|
-
"items": [
|
|
101
|
-
{
|
|
102
|
-
"text": "Directives",
|
|
103
|
-
"link": "/built-in/directives"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
"text": "For loop",
|
|
107
|
-
"link": "/built-in/for-loop"
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
"text": "Layout",
|
|
111
|
-
"link": "/built-in/layout.md"
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"text": "Performance",
|
|
117
|
-
"items": [
|
|
118
|
-
{
|
|
119
|
-
"text": "Lazy Loading",
|
|
120
|
-
"link": "/performance/lazy-loading"
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"text": "Router",
|
|
126
|
-
"items": [
|
|
127
|
-
{
|
|
128
|
-
"text": "Basics",
|
|
129
|
-
"link": "/router/basics"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"text": "Hooks",
|
|
133
|
-
"link": "/router/hooks"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
"text": "Transitions",
|
|
137
|
-
"link": "/router/transitions"
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"text": "Plugins",
|
|
143
|
-
"items": [
|
|
144
|
-
{
|
|
145
|
-
"text": "Text-to-Speech / Announcer",
|
|
146
|
-
"link": "/plugins/text-to-speech-announcer"
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
"text": "Language",
|
|
150
|
-
"link": "/plugins/language"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
"text": "Theme",
|
|
154
|
-
"link": "/plugins/theme"
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
"text": "Global App State",
|
|
158
|
-
"link": "/plugins/global_app_state"
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"text": "Performance",
|
|
164
|
-
"items": [
|
|
165
|
-
{
|
|
166
|
-
"text": "Lazy loading",
|
|
167
|
-
"link": "/performance/lazy-loading"
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
]
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Transitions
|
|
2
|
-
|
|
3
|
-
So far we have explored how to create components and draw elements on the screen. But everything has
|
|
4
|
-
been rather static so far.
|
|
5
|
-
|
|
6
|
-
We did learn how to _reactively_ change values and trigger rerenders based on that. So if you try the example below, you'll see that indeed our golden element changes position. But it just jumps from one place to another:
|
|
7
|
-
|
|
8
|
-
```js
|
|
9
|
-
export default Blits.Component('Gold', {
|
|
10
|
-
template: `
|
|
11
|
-
<Element color="gold" w="100" h="100" :x="$x" :y="$y" />
|
|
12
|
-
`,
|
|
13
|
-
state() {
|
|
14
|
-
return {
|
|
15
|
-
x: 0,
|
|
16
|
-
y: 0,
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
input: {
|
|
20
|
-
enter() {
|
|
21
|
-
this.x = this.x + 100
|
|
22
|
-
this.y = this.y + 50
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Using _transitions_ we really make our App come alive.
|
|
28
|
-
|
|
29
|
-
## Applying a transition
|
|
30
|
-
|
|
31
|
-
Blits offers an easy and intuitive way to apply transitions. All you need to do is add the `.transition` modifier to a reactive attribute, and now whenever you change the value referenced in the attribute, it will automatically _smooth_ into the new value.
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
export default Blits.Component('Gold', {
|
|
35
|
-
template: `
|
|
36
|
-
<Element color="gold" w="100" h="100" :x.transition="$x" :y.transition="$y" />
|
|
37
|
-
`,
|
|
38
|
-
state() {
|
|
39
|
-
return {
|
|
40
|
-
x: 0,
|
|
41
|
-
y: 0,
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
input: {
|
|
45
|
-
enter() {
|
|
46
|
-
this.x = this.x + 100
|
|
47
|
-
this.y = this.y + 50
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
If we try out the modified example above, you'll notice how much difference adding a simple transition makes.
|
|
53
|
-
|
|
54
|
-
When the `.transition`-modifier is added to a reactive attribute, a default `ease-in` transition with a duration of `300ms` is applied
|
|
55
|
-
|
|
56
|
-
## Customizing transitions
|
|
57
|
-
|
|
58
|
-
While the default transition will look pretty good out of the box and is great for quickly improving the look of your App, you may want to customize specific transitions.
|
|
59
|
-
|
|
60
|
-
Blits gives you full control over your transitions, with a simple to use format, right inside your template.
|
|
61
|
-
|
|
62
|
-
Instead of referencing your component's state variable directly, you can also supply an inline `object literal`` in the attribute with a `.transition`-modifier. This will allow you to pass a number of options to change the way the transition will work.
|
|
63
|
-
|
|
64
|
-
The transition object must have a `value` key, which references the state variable (or prop or computed property) that triggers the transition.
|
|
65
|
-
|
|
66
|
-
Furthermore, you can specify:
|
|
67
|
-
|
|
68
|
-
- `duration` - the duration of the transition in `ms`
|
|
69
|
-
- `delay` - the time in `ms` after which the transition should initiate
|
|
70
|
-
- `easing` - the easing function of the transition. Can be one of the default easing options listed below, or a custom `cubic-bezier` definition (i.e. `cubic-bezier(0,1.35,.99,-0.07)`).
|
|
71
|
-
|
|
72
|
-
```xml
|
|
73
|
-
<Element color="gold" w="100" h="100"
|
|
74
|
-
:x.transition="{value: $x, duration: 300, easing: 'ease-in-back', delay: 400}"
|
|
75
|
-
:y.transition="{value: $x, duration: 300, easing: 'cubic-bezier(1,-0.64,0.39,1.44)'}">
|
|
76
|
-
</Element>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Besides a reference to the `value`, you can also use dynamic values for the other keys in the transition object. This way you'll be able to dynamically control the delay, duration or easing function.
|
|
80
|
-
|
|
81
|
-
```xml
|
|
82
|
-
<Element color="gold" w="100" h="100"
|
|
83
|
-
:x.transition="{value: $x, duration: $dynamicDuration, delay: $dynamicDelay}">
|
|
84
|
-
</Element>
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Available easing functions
|
|
88
|
-
|
|
89
|
-
- `ease-in`
|
|
90
|
-
- `ease-out`
|
|
91
|
-
- `ease-in-out`
|
|
92
|
-
- `ease-in-sine`
|
|
93
|
-
- `ease-out-sine`
|
|
94
|
-
- `ease-in-out-sine`
|
|
95
|
-
- `ease-in-cubic`
|
|
96
|
-
- `ease-out-cubic`
|
|
97
|
-
- `ease-in-out-cubic`
|
|
98
|
-
- `ease-in-circ`
|
|
99
|
-
- `ease-out-circ`
|
|
100
|
-
- `ease-in-out-circ`
|
|
101
|
-
- `ease-in-back`
|
|
102
|
-
- `ease-out-back`
|
|
103
|
-
- `ease-in-out-back`
|
|
104
|
-
|
|
105
|
-
## Listening to transition events
|
|
106
|
-
|
|
107
|
-
Sometimes you may want to perform an action when a transition _ends_ or when it _starts_.
|
|
108
|
-
|
|
109
|
-
You can easily hook into these transition events by adding a `start` and `end` key to the transition object. Both values should be a function (or a reference to a `method` on your component).
|
|
110
|
-
|
|
111
|
-
The `start` function will be called when the transition actually starts (after a possible specified delay) and the `end` function is called as soon as the transition is finished.
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
export default Blits.Component('Gold', {
|
|
115
|
-
template: `
|
|
116
|
-
<Element color="gold" w="100" h="100"
|
|
117
|
-
:x.transition="{value: $x, start: $transitionBegin, end: $transitionEnd}"
|
|
118
|
-
/>
|
|
119
|
-
`,
|
|
120
|
-
///
|
|
121
|
-
methods: {
|
|
122
|
-
transitionBegin() {
|
|
123
|
-
//
|
|
124
|
-
},
|
|
125
|
-
transitionEnd() {
|
|
126
|
-
//
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
It is also possible to keep track of the entire progress of a transition. Every frametick during a transition (ideally once every 16ms), the renderer reports the progress of the transition. You can hook into this event by specifying a `progress` key on the transition configuration object, with a function to excute.
|
|
132
|
-
|
|
133
|
-
This function is executed _every_ frametick, and receives the current progress and the previous progress as its arguments. The progress is indicated as a value between `0` and `1`, where 0 means start and 1 means finished.
|
|
134
|
-
|
|
135
|
-
```js
|
|
136
|
-
export default Blits.Component('Gold', {
|
|
137
|
-
template: `
|
|
138
|
-
<Element color="gold" w="100" h="100"
|
|
139
|
-
:x.transition="{value: $x, progress: $transitionProgress}"
|
|
140
|
-
/>
|
|
141
|
-
`,
|
|
142
|
-
///
|
|
143
|
-
methods: {
|
|
144
|
-
transitionProgress(progress, previousProgress) {
|
|
145
|
-
if(progress >= 0.5 && previousProgress < 0.5) {
|
|
146
|
-
// halfway through the transition
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
}
|
|
150
|
-
```
|