@ -330,7 +330,7 @@ If the `on:` directive is used without a value, the component will *forward* the
---
Components can emit events using [createEventDispatcher](#docs/createEventDispatcher), or by forwarding DOM events. Listening for component events looks the same as listening for DOM events:
Components can emit events using [createEventDispatcher](docs#createeventdispatcher), or by forwarding DOM events. Listening for component events looks the same as listening for DOM events:
```html
<SomeComponenton:whatever={handler}/>
@ -340,7 +340,9 @@ Components can emit events using [createEventDispatcher](#docs/createEventDispat
### Element bindings
* `bind:property={value}`
* `bind:property={variable}`
* `bind:group={variable}`
* `bind:this={dom_node}`
---
@ -374,6 +376,8 @@ Numeric input values are coerced; even though `input.value` is a string as far a
<inputtype="range"bind:value={num}>
```
#### Binding related elements
---
Inputs that work together can use `bind:group`.
@ -396,6 +400,8 @@ Inputs that work together can use `bind:group`.
A `<select>` value binding corresponds to the `value` property on the selected `<option>`, which can be any value (not just strings, as is normally the case in the DOM).
@ -434,6 +440,8 @@ When the value of an `<option>` matches its text content, the attribute can be o
</select>
```
#### Media elements bindings
---
Media elements (`<audio>` and `<video>`) have their own set of bindings — four *readonly* ones...
@ -462,16 +470,28 @@ Media elements (`<audio>` and `<video>`) have their own set of bindings — four
></video>
```
#### Block-level elements bindings
---
Block-level elements have readonly `clientWidth`, `clientHeight`, `offsetWidth` and `offsetHeight` bindings, measured using a technique similar to [this one](http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/).
Block-level elements have 4 readonly bindings, measured using a technique similar to [this one](http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/):
To get a reference to a DOM node, use `bind:this`.
@ -494,7 +514,8 @@ To get a reference to a DOM node, use `bind:this`.
### Component bindings
* `bind:property={value}`
* `bind:property={variable}`
* `bind:this={component_instance}`
---
@ -652,6 +673,8 @@ The `in:` and `out:` directives are not bidirectional. An in transition will con
{/if}
```
#### Transition parameters
---
Like actions, transitions can have parameters.
@ -666,6 +689,8 @@ Like actions, transitions can have parameters.
{/if}
```
#### Custom transition functions
---
Transitions can use custom functions. If the returned object has a `css` function, Svelte will create a CSS animation that plays on the element.
@ -741,6 +766,8 @@ If a transition returns a function instead of a transition object, the function
---
#### Transitions events
An element with transitions will dispatch the following events in addition to any standard DOM events:
* `introstart`
@ -825,7 +852,7 @@ Named slots allow consumers to target specific areas. They can also have fallbac
<!-- Widget.svelte -->
<div>
<slotname"header">No header was provided</slot>
<slotname="header">No header was provided</slot>
<p>Some content between header and footer</p>
</slot name="footer"></slot>
</div>
@ -988,7 +1015,7 @@ This element makes it possible to insert elements into `document.head`. During s
---
The `<svelte:options>` element provides a place to specify per-component compiler options, which are detailed in the next section. The possible options are:
The `<svelte:options>` element provides a place to specify per-component compiler options, which are detailed in the [compiler section](docs#compile). The possible options are:
* `immutable={true}` — you never use mutable data, so the compiler can do simple referential equality checks to determine if values have changed
* `immutable={false}` — the default. Svelte will be more conservative about whether or not mutable objects have changed
The `svelte/motion` module exports two functions, `tweened` and `spring`, for creating writable stores whose values change over time after `set` and `update`, rather than immediately.
#### tweened
#### `tweened`
* `store = tweened(value: any, options)`
`store = tweened(value: any, options)`
Tweened stores update their values over a fixed duration. The following options are available:
@ -378,9 +403,9 @@ The `interpolator` option allows you to tween between *any* arbitrary values. It
<h1style="color: {$color}">{$color}</h1>
```
#### spring
#### `spring`
* `store = spring(value: any, options)`
`store = spring(value: any, options)`
A `spring` store gradually changes to its target value based on its `stiffness` and `damping` parameters. Whereas `tweened` stores change their values over a fixed duration, `spring` stores change over a duration that is determined by their existing velocity, allowing for more natural-seeming motion in many situations. The following options are available:
@ -390,7 +415,7 @@ A `spring` store gradually changes to its target value based on its `stiffness`
---
As with `tweened` stores, `set` and `update` return a Promise that resolves if the spring settles. The `store.stiffness` and `store.damping` properties can be changed while the spring is in motion, and will take immediate effect.
As with [`tweened`](#tweened) stores, `set` and `update` return a Promise that resolves if the spring settles. The `store.stiffness` and `store.damping` properties can be changed while the spring is in motion, and will take immediate effect.
[See a full example on the spring tutorial.](tutorial/spring)
@ -405,14 +430,14 @@ As with `tweened` stores, `set` and `update` return a Promise that resolves if t
</script>
```
### svelte/transition
### `svelte/transition`
TODO
* fade, fly, slide, draw
* crossfade...
### svelte/animation
### `svelte/animation`
TODO
@ -420,18 +445,22 @@ TODO
TODO
### svelte/easing
### `svelte/easing`
* TODO could have nice little interactive widgets showing the different functions, maybe
### svelte/register
### `svelte/register`
TODO
### Client-side component API
* `const component = new Component(options)`
#### Creating a component
```js
const component = new Component(options)
```
---
@ -465,7 +494,7 @@ Existing children of `target` are left where they are.
---
The `hydrate` option instructs Svelte to upgrade existing DOM (usually from server-side rendering) rather than creating new elements. It will only work if the component was compiled with the `hydratable: true` option.
The `hydrate` option instructs Svelte to upgrade existing DOM (usually from server-side rendering) rather than creating new elements. It will only work if the component was compiled with the [`hydratable: true` option](docs#compile).
Whereas children of `target` are normally left alone, `hydrate: true` will cause any children to be removed. For that reason, the `anchor` option cannot be used alongside `hydrate: true`.
@ -480,7 +509,11 @@ const app = new App({
});
```
* `component.$set(props)`
#### `$set`
```js
component.$set(props)
```
---
@ -489,10 +522,14 @@ Programmatically sets props on an instance. `component.$set({ x: 1 })` is equiva
Calling this method schedules an update for the next microtask — the DOM is *not* updated synchronously.
@ -194,9 +193,9 @@ The `markup` function receives the entire component source text, along with the
> Preprocessor functions may additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation. In current versions of Svelte it will be ignored, but future versions of Svelte may take account of preprocessor sourcemaps.
```js
const svelte = require('svelte/compiler');
const {preprocess} = require('svelte/compiler');
const { code } = svelte.preprocess(source, {
const { code } = preprocess(source, {
markup: ({ content, filename }) => {
return {
code: content.replace(/foo/g, 'bar')
@ -214,11 +213,11 @@ The `script` and `style` functions receive the contents of `<script>` and `<styl
If a `dependencies` array is returned, it will be included in the result object. This is used by packages like [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte) to watch additional files for changes, in the case where your `<style>` tag has an `@import` (for example).
Multiple preprocessors can be used together. The output of the first becomes the input to the second. `markup` functions run first, then `script` and `style`.