From e9f0ffbd29a6344b6d826e99662924006ad6e1cc Mon Sep 17 00:00:00 2001 From: pushkine Date: Tue, 19 May 2020 22:06:50 +0200 Subject: [PATCH] examples --- .../examples/08-motion/01-spring/App.svelte | 197 ++++++++-- .../10-animations/00-animate/App.svelte | 288 ++++++++------- .../examples/11-easing/00-easing/App.svelte | 201 ++++++----- .../11-easing/00-easing/Controls.svelte | 341 +++++++++--------- .../examples/11-easing/00-easing/Grid.svelte | 134 ++++--- .../examples/11-easing/00-easing/eases.js | 42 +-- 6 files changed, 695 insertions(+), 508 deletions(-) diff --git a/site/content/examples/08-motion/01-spring/App.svelte b/site/content/examples/08-motion/01-spring/App.svelte index 9918cf40e8..9c6396598e 100644 --- a/site/content/examples/08-motion/01-spring/App.svelte +++ b/site/content/examples/08-motion/01-spring/App.svelte @@ -1,35 +1,184 @@ + solve_spring(e.clientY, $velocity)} + bind:innerWidth={canvas_width} + bind:innerHeight={canvas_height} />
- + + + + + - + + +
- - - - \ No newline at end of file + + + + diff --git a/site/content/examples/10-animations/00-animate/App.svelte b/site/content/examples/10-animations/00-animate/App.svelte index 279821491b..c3d3559dea 100644 --- a/site/content/examples/10-animations/00-animate/App.svelte +++ b/site/content/examples/10-animations/00-animate/App.svelte @@ -1,147 +1,159 @@ -
- - -
-

todo

- {#each todos.filter(t => !t.done) as todo (todo.id)} - - {/each} -
- -
-

done

- {#each todos.filter(t => t.done) as todo (todo.id)} - - {/each} -
+ { + let [{ length: a }, { length: b }] = list; + if (e.keyCode == 32) { + if (lastShuffle > Date.now() - 100) { + return; + } + lastShuffle = Date.now(); + e = 0; + if (!a) e += 1; + if (!b) e -= 2; + if (!e) e += t = 0.5 + (b - a) / (a + b); + s: if (~e) { + a += b; + let w = 1; + while (animating.get((e = (e = list[(e = +(Math.random() + e > 0.5))])[Math.floor(Math.random() * e.length)]).key)) if (w++ > a) break s; + e.done = !e.done; + list = list; + } + } + }} /> +
+ void (event.key === 'Enter' && add(event.target))} /> + {#each list as todo, i (i)} +
+

{!i ? 'todo' : 'done'}

+ {#each todo as { key, description, done: checked } (key)} + + {/each} +
+ {/each}
diff --git a/site/content/examples/11-easing/00-easing/App.svelte b/site/content/examples/11-easing/00-easing/App.svelte index c33e73518e..dede5413ce 100644 --- a/site/content/examples/11-easing/00-easing/App.svelte +++ b/site/content/examples/11-easing/00-easing/App.svelte @@ -1,106 +1,107 @@ -
- - - - - - - - - - - - - - -
\ No newline at end of file +
+ {#if is_custom} +
+ cubicBezier({bezier}) +
+ {/if} + + + + + + + + + + + +
diff --git a/site/content/examples/11-easing/00-easing/Controls.svelte b/site/content/examples/11-easing/00-easing/Controls.svelte index 66a297323f..d435e52a4f 100644 --- a/site/content/examples/11-easing/00-easing/Controls.svelte +++ b/site/content/examples/11-easing/00-easing/Controls.svelte @@ -1,186 +1,175 @@
-
-

Ease

- {#if mobile} - - {:else} -
    - {#each [...eases] as [name]} -
  • current_ease = name} - > - {name} -
  • - {/each} -
- {/if} -

Type

- {#if mobile } - - {:else} -
    - {#each types as [name, type]} -
  • current_type = type} - > - {name} -
  • - {/each} -
- {/if} -
-

- Duration -

-
- - - - - - -
-
\ No newline at end of file +
+

Ease

+ {#if mobile} + + {:else} +
    + {#each [...eases, [`cubicBezier`]] as [name]} +
  • (current_ease = name)}> + {name} +
  • + {/each} +
+ {/if} +

Type

+ {#if mobile} + + {:else} +
    + {#each types as [name, type]} +
  • (current_type = type)}> + {name} +
  • + {/each} +
+ {/if} +
+

Duration

+
+ + + + + + +
+
diff --git a/site/content/examples/11-easing/00-easing/Grid.svelte b/site/content/examples/11-easing/00-easing/Grid.svelte index e704f46cf7..3c19134ab0 100644 --- a/site/content/examples/11-easing/00-easing/Grid.svelte +++ b/site/content/examples/11-easing/00-easing/Grid.svelte @@ -1,62 +1,98 @@ + bind:this={rect} + x="0" + y="0" + width="1400" + height="1800" + stroke="#ccc" + style="opacity: 0.5" + fill="none" + stroke-width="2" /> {#each { length: 8 } as _, i} - {#if i < 6} - - {/if} - + {#if i < 6} + + {/if} + {/each} - - - \ No newline at end of file + bind:this={rect2} + x="200" + y="400" + width="1000" + height="1000" + stroke="#999" + fill="none" + stroke-width="4" /> + { + const { x, y, width, height } = rect.getBoundingClientRect(); + const _x1 = Math.min(1200, Math.max(200, (e.clientX - x) * (1400 / width))); + const _y1 = Math.min(1800, Math.max(0, (e.clientY - y) * (1800 / height))); + if (selected1) (x1 = _x1), (y1 = _y1); + else if (selected2) (x2 = _x1), (y2 = _y1); + }} + on:mouseup={() => { + selected1 = selected2 = false; + }} /> + +{#if is_custom} + + + (selected1 = true)} /> + (selected2 = true)} /> +{/if} diff --git a/site/content/examples/11-easing/00-easing/eases.js b/site/content/examples/11-easing/00-easing/eases.js index a24246005a..e5489253dc 100644 --- a/site/content/examples/11-easing/00-easing/eases.js +++ b/site/content/examples/11-easing/00-easing/eases.js @@ -1,25 +1,25 @@ -import * as eases from 'svelte/easing'; +import * as eases from 'svelte/easing' -const processed_eases = {}; - -for (const ease in eases) { - if (ease === "linear") { - processed_eases.linear = eases.linear; +const processed_eases = {} +let ease +for (ease in eases) { + if (ease === 'linear') { + processed_eases.linear = eases.linear + } else if (ease === 'cubicBezier') { + continue } else { - const name = ease.replace(/In$|InOut$|Out$/, ''); - const type = ease.match(/In$|InOut$|Out$/)[0]; - - if (!(name in processed_eases)) processed_eases[name] = {}; - processed_eases[name][type] = {}; - processed_eases[name][type].fn = eases[ease]; - - let shape = 'M0 1000'; - for (let i = 1; i <= 1000; i++) { - shape = `${shape} L${(i / 1000) * 1000} ${1000 - eases[ease](i / 1000) * 1000} `; - processed_eases[name][type].shape = shape; + const name = ease.replace(/In$|InOut$|Out$/, '') + ;(processed_eases[name] || (processed_eases[name] = {}))[ease.match(/In$|InOut$|Out$/)[0]] = { + fn: eases[ease], + shape: generate(eases[ease]), } } } +export function generate(easing, from = 0, to = 1000) { + let shape = `M${from} ${to}` + for (let i = from + 1; i <= to; i++) shape += ` L${i} ${to - to * easing(i / to)}` + return shape +} const sorted_eases = new Map([ ['sine', processed_eases.sine], @@ -32,12 +32,12 @@ const sorted_eases = new Map([ ['back', processed_eases.back], ['elastic', processed_eases.elastic], ['bounce', processed_eases.bounce], -]); +]) export const types = [ ['Ease In', 'In'], ['Ease Out', 'Out'], - ['Ease In Out', 'InOut'] -]; + ['Ease In Out', 'InOut'], +] -export { sorted_eases as eases }; \ No newline at end of file +export { sorted_eases as eases }