Create new
Bindings
Transitions
Animations
Easing
Component composition
Context API
Special elements
Module context
Debugging
Miscellaneous
App.svelte
utils.js
runes
This component is not in runes mode.
To enable runes mode, either start using runes in your code, or add the following to the top of your component:
<svelte:options runes />
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
<script>
import { transitionHelper } from './utils.js';
import { tick } from 'svelte';
let count = 0;
function incrementClick() {
transitionHelper({
async updateDOM() {
count++;
await tick();
}
});
}
</script>
<button on:click={incrementClick}>Increment</button>
<div class="count">{count}</div>
<style>
:global(html) {
background: black;
}
:global(body) {
color: #fff;
}
.count {
font-family: sans-serif;
text-align: center;
position: absolute;
inset: 50% 0 auto;
transform: translateY(-50%);
font-size: 25vw;
view-transition-name: count;
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
›
⌄
⌄
⌄
⌄
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
import { transitionHelper } from './utils.js';
import { tick } from 'svelte';
var root = $.template(`<button>Increment</button> <div class="count svelte-182zsq2"> </div>`, 1);
export default function App($$anchor, $$props) {
$.push($$props, false);
let count = $.mutable_state(0);
function incrementClick() {
transitionHelper({
async updateDOM() {
$.update(count);
await tick();
}
});
}
$.init();
var fragment = root();
var button = $.first_child(fragment);
var div = $.sibling(button, 2);
var text = $.child(div, true);
$.reset(div);
$.template_effect(() => $.set_text(text, $.get(count)));
$.event('click', button, incrementClick);
$.append($$anchor, fragment);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
html {
background: black;
}
body {
color: #fff;
}
.count.svelte-182zsq2 {
font-family: sans-serif;
text-align: center;
position: absolute;
inset: 50% 0 auto;
transform: translateY(-50%);
font-size: 25vw;
view-transition-name: count;
/* This won't be required soon. In fact, it already works without this in Canary */
contain: layout;
}
/* Custom transition */
@keyframes svelte-182zsq2-rotate-out {
to {
transform: rotate(90deg);
}
}
@keyframes svelte-182zsq2-rotate-in {
from {
transform: rotate(-90deg);
}
}
html::view-transition-old(count),
html::view-transition-new(count) {
Root {
css: StyleSheet {...}
- type: "StyleSheet"
- start: 325
- end: 1166
- attributes: []
children: [...] (7)
Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 334
- end: 347
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 334
- end: 347
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 342
- end: 346
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 342
- end: 346
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "html"
- start: 342
- end: 346
}
]- start: 342
- end: 346
}
]
}
]
}- start: 334
- end: 347
}
]- start: 334
- end: 347
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 348
- end: 373
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 352
- end: 369
- property: "background"
- value: "black"
}
]
}- start: 334
- end: 373
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 377
- end: 390
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 377
- end: 390
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 385
- end: 389
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 385
- end: 389
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "body"
- start: 385
- end: 389
}
]- start: 385
- end: 389
}
]
}
]
}- start: 377
- end: 390
}
]- start: 377
- end: 390
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 391
- end: 410
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 395
- end: 406
- property: "color"
- value: "#fff"
}
]
}- start: 377
- end: 410
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 413
- end: 419
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 413
- end: 419
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
ClassSelector {...}
- type: "ClassSelector"
- name: "count"
- start: 413
- end: 419
}
]- start: 413
- end: 419
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 420
- end: 703
children: [...] (8)
Declaration {...}
- type: "Declaration"
- start: 424
- end: 447
- property: "font-family"
- value: "sans-serif"
} Declaration {...}
- type: "Declaration"
- start: 451
- end: 469
- property: "text-align"
- value: "center"
} Declaration {...}
- type: "Declaration"
- start: 473
- end: 491
- property: "position"
- value: "absolute"
} Declaration {...}
- type: "Declaration"
- start: 495
- end: 512
- property: "inset"
- value: "50% 0 auto"
} Declaration {...}
- type: "Declaration"
- start: 516
- end: 543
- property: "transform"
- value: "translateY(-50%)"
} Declaration {...}
- type: "Declaration"
- start: 547
- end: 562
- property: "font-size"
- value: "25vw"
} Declaration {...}
- type: "Declaration"
- start: 566
- end: 593
- property: "view-transition-name"
- value: "count"
} Declaration {...}
- type: "Declaration"
- start: 684
- end: 699
- property: "contain"
- value: "layout"
}
]
}- start: 413
- end: 703
} Atrule {...}
- type: "Atrule"
- start: 731
- end: 797
- name: "keyframes"
- prelude: "rotate-out"
block: Block {...}
- type: "Block"
- start: 753
- end: 797
children: [...] (1)
Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 757
- end: 759
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 757
- end: 759
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "to"
- start: 757
- end: 759
}
]- start: 757
- end: 759
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 760
- end: 794
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 765
- end: 789
- property: "transform"
- value: "rotate(90deg)"
}
]
}- start: 757
- end: 794
}
]
}
} Atrule {...}
- type: "Atrule"
- start: 800
- end: 868
- name: "keyframes"
- prelude: "rotate-in"
block: Block {...}
- type: "Block"
- start: 821
- end: 868
children: [...] (1)
Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 825
- end: 829
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 825
- end: 829
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "from"
- start: 825
- end: 829
}
]- start: 825
- end: 829
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 830
- end: 865
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 835
- end: 860
- property: "transform"
- value: "rotate(-90deg)"
}
]
}- start: 825
- end: 865
}
]
}
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 871
- end: 956
children: [...] (2)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 871
- end: 912
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (2)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 879
- end: 883
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 879
- end: 883
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "html"
- start: 879
- end: 883
}
]- start: 879
- end: 883
}
]
}
]
}- start: 871
- end: 884
} PseudoElementSelector {...}
- type: "PseudoElementSelector"
- name: "view-transition-old"
- start: 884
- end: 905
}
]- start: 871
- end: 912
}
]
} ComplexSelector {...}
- type: "ComplexSelector"
- start: 915
- end: 956
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (2)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 923
- end: 927
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 923
- end: 927
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "html"
- start: 923
- end: 927
}
]- start: 923
- end: 927
}
]
}
]
}- start: 915
- end: 928
} PseudoElementSelector {...}
- type: "PseudoElementSelector"
- name: "view-transition-new"
- start: 928
- end: 949
}
]- start: 915
- end: 956
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 957
- end: 1048
children: [...] (2)
Declaration {...}
- type: "Declaration"
- start: 961
- end: 986
- property: "animation-duration"
- value: "200ms"
} Declaration {...}
- type: "Declaration"
- start: 990
- end: 1044
- property: "animation-name"
- value: "-ua-view-transition-fade-in, rotate-in"
}
]
}- start: 871
- end: 1048
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 1051
- end: 1092
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 1051
- end: 1092
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (2)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 1059
- end: 1063
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 1059
- end: 1063
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "html"
- start: 1059
- end: 1063
}
]- start: 1059
- end: 1063
}
]
}
]
}- start: 1051
- end: 1064
} PseudoElementSelector {...}
- type: "PseudoElementSelector"
- name: "view-transition-old"
- start: 1064
- end: 1085
}
]- start: 1051
- end: 1092
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 1093
- end: 1157
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 1097
- end: 1153
- property: "animation-name"
- value: "-ua-view-transition-fade-out, rotate-out"
}
]
}- start: 1051
- end: 1157
}
]content: {...}
- start: 332
- end: 1158
- styles: "\n\t:global(html) {\n\t\tbackground: black;\n\t}\n\t\n\t:global(body) {\n\t\tcolor: #fff;\n\t}\n\n\t.count {\n\t\tfont-family: sans-serif;\n\t\ttext-align: center;\n\t\tposition: absolute;\n\t\tinset: 50% 0 auto;\n\t\ttransform: translateY(-50%);\n\t\tfont-size: 25vw;\n\t\tview-transition-name: count;\n\t\t/* This won't be required soon. In fact, it already works without this in Canary */\n\t contain: layout;\n\t}\n\n\t/* Custom transition */\n\t@keyframes rotate-out {\n\t\tto {\n\t\t\ttransform: rotate(90deg);\n\t\t}\n\t}\n\n\t@keyframes rotate-in {\n\t\tfrom {\n\t\t\ttransform: rotate(-90deg);\n\t\t}\n\t}\n\n\t:global(html)::view-transition-old(count),\n\t:global(html)::view-transition-new(count) {\n\t\tanimation-duration: 200ms;\n\t\tanimation-name: -ua-view-transition-fade-in, rotate-in;\n\t}\n\n\t:global(html)::view-transition-old(count) {\n\t\tanimation-name: -ua-view-transition-fade-out, rotate-out;\n\t}\n"
- comment: null
}
}- js: []
- start: 238
- end: 323
- type: "Root"
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (5)
Text {...}
- type: "Text"
- start: 236
- end: 238
- raw: "\n\n"
- data: "\n\n"
} RegularElement {...}
- type: "RegularElement"
- start: 238
- end: 290
- name: "button"
attributes: [...] (1)
OnDirective {...}
- start: 246
- end: 271
- type: "OnDirective"
- name: "click"
expression: Identifier {...}
- type: "Identifier"
- start: 256
- end: 270
loc: {...}
start: {...}
- line: 17
- column: 18
}end: {...}
- line: 17
- column: 32
}
}- name: "incrementClick"
}- modifiers: []
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 272
- end: 281
- raw: "Increment"
- data: "Increment"
}
]
}
} Text {...}
- type: "Text"
- start: 290
- end: 291
- raw: " "
- data: " "
} RegularElement {...}
- type: "RegularElement"
- start: 291
- end: 323
- name: "div"
attributes: [...] (1)
Attribute {...}
- type: "Attribute"
- start: 296
- end: 309
- name: "class"
value: [...] (1)
Text {...}
- start: 303
- end: 308
- type: "Text"
- raw: "count"
- data: "count"
}
]
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
ExpressionTag {...}
- type: "ExpressionTag"
- start: 310
- end: 317
expression: Identifier {...}
- type: "Identifier"
- start: 311
- end: 316
loc: {...}
start: {...}
- line: 18
- column: 20
}end: {...}
- line: 18
- column: 25
}
}- name: "count"
}
}
]
}
} Text {...}
- type: "Text"
- start: 323
- end: 325
- raw: "\n\n"
- data: "\n\n"
}
]
}- options: null
instance: Script {...}
- type: "Script"
- start: 0
- end: 236
- context: "default"
content: Program {...}
- type: "Program"
- start: 8
- end: 227
loc: {...}
start: {...}
- line: 1
- column: 0
}end: {...}
- line: 15
- column: 0
}
}body: [...] (4)
ImportDeclaration {...}
- type: "ImportDeclaration"
- start: 10
- end: 56
loc: {...}
start: {...}
- line: 2
- column: 1
}end: {...}
- line: 2
- column: 47
}
}specifiers: [...] (1)
ImportSpecifier {...}
- type: "ImportSpecifier"
- start: 19
- end: 35
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 26
}
}imported: Identifier {...}
- type: "Identifier"
- start: 19
- end: 35
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 26
}
}- name: "transitionHelper"
}local: Identifier {...}
- type: "Identifier"
- start: 19
- end: 35
loc: {...}
start: {...}
- line: 2
- column: 10
}end: {...}
- line: 2
- column: 26
}
}- name: "transitionHelper"
}
}
]source: Literal {...}
- type: "Literal"
- start: 43
- end: 55
loc: {...}
start: {...}
- line: 2
- column: 34
}end: {...}
- line: 2
- column: 46
}
}- value: "./utils.js"
- raw: "'./utils.js'"
}
} ImportDeclaration {...}
- type: "ImportDeclaration"
- start: 58
- end: 88
loc: {...}
start: {...}
- line: 3
- column: 1
}end: {...}
- line: 3
- column: 31
}
}specifiers: [...] (1)
ImportSpecifier {...}
- type: "ImportSpecifier"
- start: 67
- end: 71
loc: {...}
start: {...}
- line: 3
- column: 10
}end: {...}
- line: 3
- column: 14
}
}imported: Identifier {...}
- type: "Identifier"
- start: 67
- end: 71
loc: {...}
start: {...}
- line: 3
- column: 10
}end: {...}
- line: 3
- column: 14
}
}- name: "tick"
}local: Identifier {...}
- type: "Identifier"
- start: 67
- end: 71
loc: {...}
start: {...}
- line: 3
- column: 10
}end: {...}
- line: 3
- column: 14
}
}- name: "tick"
}
}
]source: Literal {...}
- type: "Literal"
- start: 79
- end: 87
loc: {...}
start: {...}
- line: 3
- column: 22
}end: {...}
- line: 3
- column: 30
}
}- value: "svelte"
- raw: "'svelte'"
}
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 92
- end: 106
loc: {...}
start: {...}
- line: 5
- column: 1
}end: {...}
- line: 5
- column: 15
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 96
- end: 105
loc: {...}
start: {...}
- line: 5
- column: 5
}end: {...}
- line: 5
- column: 14
}
}id: Identifier {...}
- type: "Identifier"
- start: 96
- end: 101
loc: {...}
start: {...}
- line: 5
- column: 5
}end: {...}
- line: 5
- column: 10
}
}- name: "count"
}init: Literal {...}
- type: "Literal"
- start: 104
- end: 105
loc: {...}
start: {...}
- line: 5
- column: 13
}end: {...}
- line: 5
- column: 14
}
}- value: 0
- raw: "0"
}
}
]- kind: "let"
} FunctionDeclaration {...}
- type: "FunctionDeclaration"
- start: 110
- end: 226
loc: {...}
start: {...}
- line: 7
- column: 1
}end: {...}
- line: 14
- column: 2
}
}id: Identifier {...}
- type: "Identifier"
- start: 119
- end: 133
loc: {...}
start: {...}
- line: 7
- column: 10
}end: {...}
- line: 7
- column: 24
}
}- name: "incrementClick"
}- expression: false
- generator: false
- async: false
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 136
- end: 226
loc: {...}
start: {...}
- line: 7
- column: 27
}end: {...}
- line: 14
- column: 2
}
}body: [...] (1)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 140
- end: 223
loc: {...}
start: {...}
- line: 8
- column: 2
}end: {...}
- line: 13
- column: 5
}
}expression: CallExpression {...}
- type: "CallExpression"
- start: 140
- end: 222
loc: {...}
start: {...}
- line: 8
- column: 2
}end: {...}
- line: 13
- column: 4
}
}callee: Identifier {...}
- type: "Identifier"
- start: 140
- end: 156
loc: {...}
start: {...}
- line: 8
- column: 2
}end: {...}
- line: 8
- column: 18
}
}- name: "transitionHelper"
}arguments: [...] (1)
ObjectExpression {...}
- type: "ObjectExpression"
- start: 157
- end: 221
loc: {...}
start: {...}
- line: 8
- column: 19
}end: {...}
- line: 13
- column: 3
}
}properties: [...] (1)
Property {...}
- type: "Property"
- start: 162
- end: 217
loc: {...}
start: {...}
- line: 9
- column: 3
}end: {...}
- line: 12
- column: 4
}
}- method: true
- shorthand: false
- computed: false
key: Identifier {...}
- type: "Identifier"
- start: 168
- end: 177
loc: {...}
start: {...}
- line: 9
- column: 9
}end: {...}
- line: 9
- column: 18
}
}- name: "updateDOM"
}- kind: "init"
value: FunctionExpression {...}
- type: "FunctionExpression"
- start: 177
- end: 217
loc: {...}
start: {...}
- line: 9
- column: 18
}end: {...}
- line: 12
- column: 4
}
}- id: null
- expression: false
- generator: false
- async: true
- params: []
body: BlockStatement {...}
- type: "BlockStatement"
- start: 180
- end: 217
loc: {...}
start: {...}
- line: 9
- column: 21
}end: {...}
- line: 12
- column: 4
}
}body: [...] (2)
ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 186
- end: 194
loc: {...}
start: {...}
- line: 10
- column: 4
}end: {...}
- line: 10
- column: 12
}
}expression: UpdateExpression {...}
- type: "UpdateExpression"
- start: 186
- end: 193
loc: {...}
start: {...}
- line: 10
- column: 4
}end: {...}
- line: 10
- column: 11
}
}- operator: "++"
- prefix: false
argument: Identifier {...}
- type: "Identifier"
- start: 186
- end: 191
loc: {...}
start: {...}
- line: 10
- column: 4
}end: {...}
- line: 10
- column: 9
}
}- name: "count"
}
}
} ExpressionStatement {...}
- type: "ExpressionStatement"
- start: 199
- end: 212
loc: {...}
start: {...}
- line: 11
- column: 4
}end: {...}
- line: 11
- column: 17
}
}expression: AwaitExpression {...}
- type: "AwaitExpression"
- start: 199
- end: 211
loc: {...}
start: {...}
- line: 11
- column: 4
}end: {...}
- line: 11
- column: 16
}
}argument: CallExpression {...}
- type: "CallExpression"
- start: 205
- end: 211
loc: {...}
start: {...}
- line: 11
- column: 10
}end: {...}
- line: 11
- column: 16
}
}callee: Identifier {...}
- type: "Identifier"
- start: 205
- end: 209
loc: {...}
start: {...}
- line: 11
- column: 10
}end: {...}
- line: 11
- column: 14
}
}- name: "tick"
}- arguments: []
- optional: false
}
}
}
]
}
}
}
]
}
]- optional: false
}
}
]
}
}
]- sourceType: "module"
}- attributes: []
}
}
The AST is not public API and may change at any point in time