Skip to content
This repository has been archived by the owner on May 21, 2023. It is now read-only.

Commit

Permalink
feat: API Sample Templates (#23)
Browse files Browse the repository at this point in the history
* - Added sample template for Transitions Components

* - Updated generated downloads to have naming based on Workspace's name

* - Added interpolation sample

* - Added Random Store template

* - Added missing runtime support for Utilities API
  • Loading branch information
novacbn authored Jul 10, 2022
1 parent b47fb13 commit bbe9e42
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {define_extension} from "@svelte-in-motion/extension";
import {ICodecNames, IPixelFormatNames} from "@svelte-in-motion/encoding";
import {Default, Minimum} from "@svelte-in-motion/type";
import {typeOf} from "@svelte-in-motion/type";
import {PromptDismissError, download_blob, download_buffer} from "@svelte-in-motion/utilities";
import {
PromptDismissError,
download_blob,
download_buffer,
format_slug,
} from "@svelte-in-motion/utilities";

import {NoEditorUserError, NoPreviewUserError, NoWorkspaceUserError} from "../util/errors";
import {zip_frames} from "../util/io";
Expand Down Expand Up @@ -65,7 +70,7 @@ export const EXTENSION_EXPORT = define_extension({

if (!workspace) throw new NoWorkspaceUserError();

const {configuration, editor, preview} = workspace;
const {configuration, editor, metadata, preview} = workspace;

if (!editor) throw new NoEditorUserError();
if (!preview) throw new NoPreviewUserError();
Expand Down Expand Up @@ -120,9 +125,13 @@ export const EXTENSION_EXPORT = define_extension({
is_dismissible: true,
});

const $metadata = get(metadata);

download_blob(
zip,
`svelte-in-motion.frames.${result.start}-${result.end}.${file_path}.zip`
`svelte-in-motion.frames.${result.start}-${result.end}.${format_slug(
$metadata.name
)}.zip`
);
},

Expand All @@ -131,7 +140,7 @@ export const EXTENSION_EXPORT = define_extension({

if (!workspace) throw new NoWorkspaceUserError();

const {configuration, editor, preview} = workspace;
const {configuration, editor, metadata, preview} = workspace;

if (!editor) throw new NoEditorUserError();
if (!preview) throw new NoPreviewUserError();
Expand Down Expand Up @@ -200,9 +209,13 @@ export const EXTENSION_EXPORT = define_extension({

// HACK: / TODO: Update later to support variable video container format

const $metadata = get(metadata);

download_buffer(
video,
`svelte-in-motion.video.${result.start}-${result.end}.${file_path}.webm`,
`svelte-in-motion.video.${result.start}-${result.end}.${format_slug(
$metadata.name
)}.webm`,
`video/webm`
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type {IAppContext} from "@svelte-in-motion/extension";
import {define_extension} from "@svelte-in-motion/extension";

import {
TEMPLATE_SAMPLE_INTERPOLATION,
TEMPLATE_SAMPLE_RANDOM,
TEMPLATE_SAMPLE_TRANSITIONS,
} from "../templates/samples";
import {TEMPLATE_WELCOME} from "../templates/welcome";

export const EXTENSION_TEMPLATES = define_extension({
Expand All @@ -11,5 +16,9 @@ export const EXTENSION_TEMPLATES = define_extension({
const {templates} = app;

templates.push(TEMPLATE_WELCOME);

templates.push(TEMPLATE_SAMPLE_INTERPOLATION);
templates.push(TEMPLATE_SAMPLE_RANDOM);
templates.push(TEMPLATE_SAMPLE_TRANSITIONS);
},
});
250 changes: 250 additions & 0 deletions packages/@svelte-in-motion-builtin-extensions/src/templates/samples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
import {define_template} from "@svelte-in-motion/extension";

export const TEMPLATE_SAMPLE_INTERPOLATION = define_template({
identifier: "samples.interpolation",

paths: {
".svelte-in-motion.json": `
{
"framerate": 60,
"height": 1080,
"maxframes": 120,
"width": 1920
}
`,

"Main.svelte": `
<script>
import { CONTEXT_STATE } from "@svelte-in-motion/core";
const opacity = CONTEXT_STATE.get({
duration: 0.25,
start: 0.65,
end: {
extrapolate: "wrap",
value: 1
},
});
</script>
<div style="--opacity:{$opacity};" />
<style>
div {
display: grid;
background: skyblue;
width: 100vw;
height: 100vh;
opacity: var(--opacity);
}
</style>
`,
},
});

export const TEMPLATE_SAMPLE_RANDOM = define_template({
identifier: "samples.random",

paths: {
".svelte-in-motion.json": `
{
"framerate": 60,
"height": 1080,
"maxframes": 120,
"width": 1920
}
`,

"Main.svelte": `
<script>
import StaticPellet from "./StaticPellet.svelte";
const pellets = new Array(100).fill(null);
</script>
{#each pellets as _, index}
<StaticPellet {index} />
{/each}
<style>
:global(body) {
background: white;
}
</style>
`,

"StaticPellet.svelte": `
<script>
import { CONTEXT_RANDOM_FLOAT } from "@svelte-in-motion/core";
import { random } from "@svelte-in-motion/utilities";
export let index = 0;
$: opacity = random(\`opacity-\${index}\`).float(0.65, 0.9);
$: x = CONTEXT_RANDOM_FLOAT.get({
seed: \`x-\${index}\`,
end: 100,
start: 0,
});
$: y = CONTEXT_RANDOM_FLOAT.get({
seed: \`y-\${index}\`,
end: 100,
start: 0,
});
</script>
<span style="--x:{$x}%;--y:{$y}%;--opacity:{opacity};" />
<style>
:global(body) {
background: white;
}
span {
position: fixed;
background: slategray;
width: 0.25vw;
height: 0.25vw;
top: var(--x);
left: var(--y);
opacity: var(--opacity);
}
</style>
`,
},
});

export const TEMPLATE_SAMPLE_TRANSITIONS = define_template({
identifier: "samples.transitions",

paths: {
".svelte-in-motion.json": `
{
"framerate": 60,
"height": 1080,
"maxframes": 120,
"width": 1920
}
`,

"Main.svelte": `
<script>
import { Fade, Rotate, Scale, Translate } from "@svelte-in-motion/animations";
</script>
<div>
<Fade.In
duration={2}
>
<section>
<code>Fade In</code>
</section>
</Fade.In>
<Fade.Out
duration={2}
>
<section>
<code>Fade Out</code>
</section>
</Fade.Out>
<Rotate.In
duration={2}
start="180deg"
end="0deg"
>
<section>
<code>Rotate In</code>
</section>
</Rotate.In>
<Rotate.Out
duration={2}
start="0deg"
end="180deg"
>
<section>
<code>Rotate Out</code>
</section>
</Rotate.Out>
<Scale.In
duration={2}
>
<section>
<code>Scale In</code>
</section>
</Scale.In>
<Scale.Out
duration={2}
>
<section>
<code>Scale Out</code>
</section>
</Scale.Out>
<Translate.In
duration={2}
start_x="100%"
>
<section>
<code>Translate In</code>
</section>
</Translate.In>
<Translate.Out
duration={2}
end_x="100%"
>
<section>
<code>Translate Out</code>
</section>
</Translate.Out>
</div>
<style>
:global(*) {
box-sizing: border-box;
}
div {
display: grid;
gap: 2rem;
grid-auto-flow: row dense;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(4, 1fr);
width: 100vw;
height: 100vh;
}
section {
display: flex;
align-items: center;
justify-content: center;
background: skyblue;
border: 1px solid black;
color: whitesmoke;
height: 100%;
}
</style>
`,
},
});
1 change: 1 addition & 0 deletions packages/@svelte-in-motion-bundling/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function bundle(options: IBundleOptions): Promise<IBundleError | IB
external: [
"@svelte-in-motion/animations",
"@svelte-in-motion/core",
"@svelte-in-motion/utilities",
"svelte",
"svelte/animate",
"svelte/easing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ commands-workspace-prompt-new-label = Workspaces: New
commands-workspace-prompt-open_recent-description = Open a Workspace that was recently accessed.
commands-workspace-prompt-open_recent-label = Workspaces: Open Recent
templates-samples-interpolation-label = Sample: Interpolation
templates-samples-interpolation-description = Showcase of the Interpolation Store
templates-samples-random-label = Sample: Random
templates-samples-random-description = Showcase of the Random Store
templates-samples-transitions-label = Sample: Transitions
templates-samples-transitions-description = Showcase of the Transitions Components
templates-welcome-label = Welcome to Svelte-In-Motion
templates-welcome-description = Simple welcome message template to introduce syntax and concepts.
Expand Down
3 changes: 3 additions & 0 deletions packages/@svelte-in-motion-runtime/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import * as sim_animations from "@svelte-in-motion/animations";
import * as sim_core from "@svelte-in-motion/core";
import * as sim_screenshot from "@svelte-in-motion/screenshot";
import * as sim_utilities from "@svelte-in-motion/utilities";

window.module = {};
window.module.exports = {};
Expand Down Expand Up @@ -61,6 +62,8 @@
return sim_core;
case "@svelte-in-motion/screenshot":
return sim_screenshot;
case "@svelte-in-motion/utilities":
return sim_utilities;
}

throw new ReferenceError(
Expand Down

0 comments on commit bbe9e42

Please sign in to comment.