mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00

* Update to latest Node LTS * Add sveltekit * Split tslib into separate @generated and @tslib components SvelteKit's path aliases don't support multiple locations, so our old approach of using @tslib to refer to both ts/lib and out/ts/lib will no longer work. Instead, all generated sources and their includes are placed in a separate out/ts/generated folder, and imported via @generated instead. This also allows us to generate .ts files, instead of needing to output separate .d.ts and .js files. * Switch package.json to module type * Avoid usage of baseUrl Incompatible with SvelteKit * Move sass into ts; use relative links SvelteKit's default sass support doesn't allow overriding loadPaths * jest->vitest, graphs example working with yarn dev * most pages working in dev mode * Some fixes after rebasing * Fix/silence some svelte-check errors * Get image-occlusion working with Fabric types * Post-rebase lock changes * Editor is now checked * SvelteKit build integrated into ninja * Use the new SvelteKit entrypoint for pages like congrats/deck options/etc * Run eslint once for ts/**; fix some tests * Fix a bunch of issues introduced when rebasing over latest main * Run eslint fix * Fix remaining eslint+pylint issues; tests now all pass * Fix some issues with a clean build * Latest bufbuild no longer requires @__PURE__ hack * Add a few missed dependencies * Add yarn.bat to fix Windows build * Fix pages failing to show when ANKI_API_PORT not defined * Fix svelte-check and vitest on Windows * Set node path in ./yarn * Move svelte-kit output to ts/.svelte-kit Sadly, I couldn't figure out a way to store it in out/ if out/ is a symlink, as it breaks module resolution when SvelteKit is run. * Allow HMR inside Anki * Skip SvelteKit build when HMR is defined * Fix some post-rebase issues I should have done a normal merge instead.
106 lines
2.7 KiB
Svelte
106 lines
2.7 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="ts">
|
|
import type { OpChanges, Progress } from "@generated/anki/collection_pb";
|
|
import { runWithBackendProgress } from "@tslib/progress";
|
|
|
|
import { pageTheme } from "$lib/sveltelib/theme";
|
|
|
|
type ResultWithChanges = OpChanges | { changes?: OpChanges };
|
|
|
|
export let task: () => Promise<ResultWithChanges | undefined>;
|
|
export let result: ResultWithChanges | undefined;
|
|
export let error: Error | undefined;
|
|
let label: string = "";
|
|
|
|
function onUpdate(progress: Progress) {
|
|
if (
|
|
progress.value.value &&
|
|
progress.value.case !== "none" &&
|
|
label !== progress.value.value.toString()
|
|
) {
|
|
label = progress.value.value.toString();
|
|
}
|
|
}
|
|
$: (async () => {
|
|
if (!result && !error) {
|
|
try {
|
|
result = await runWithBackendProgress(task, onUpdate);
|
|
} catch (err) {
|
|
if (err instanceof Error) {
|
|
error = err;
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
<!-- spinner taken from https://loading.io/css/; CC0 -->
|
|
{#if !result}
|
|
<div class="progress">
|
|
<div class="spinner" class:nightMode={$pageTheme.isDark}>
|
|
<div />
|
|
<div />
|
|
<div />
|
|
<div />
|
|
</div>
|
|
<div id="label">{label}</div>
|
|
</div>
|
|
{/if}
|
|
|
|
<style lang="scss">
|
|
.progress {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
}
|
|
|
|
.spinner {
|
|
display: block;
|
|
position: relative;
|
|
width: 80px;
|
|
height: 80px;
|
|
margin: 0 auto;
|
|
|
|
div {
|
|
display: block;
|
|
position: absolute;
|
|
width: 64px;
|
|
height: 64px;
|
|
margin: 8px;
|
|
border: 8px solid #000;
|
|
border-radius: 50%;
|
|
animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
border-color: #000 transparent transparent transparent;
|
|
}
|
|
&.nightMode div {
|
|
border-top-color: #fff;
|
|
}
|
|
div:nth-child(1) {
|
|
animation-delay: -0.45s;
|
|
}
|
|
div:nth-child(2) {
|
|
animation-delay: -0.3s;
|
|
}
|
|
div:nth-child(3) {
|
|
animation-delay: -0.15s;
|
|
}
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% {
|
|
transform: rotate(0deg);
|
|
}
|
|
100% {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
#label {
|
|
text-align: center;
|
|
}
|
|
</style>
|