Format all files
This commit is contained in:
parent
5eb7ea10ad
commit
a777f33fa6
5 changed files with 122 additions and 152 deletions
48
README.md
48
README.md
|
@ -1,47 +1 @@
|
|||
# Svelte + Vite
|
||||
|
||||
This template should help get you started developing with Svelte in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||
|
||||
## Need an official Svelte framework?
|
||||
|
||||
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
||||
|
||||
## Technical considerations
|
||||
|
||||
**Why use this over SvelteKit?**
|
||||
|
||||
- It brings its own routing solution which might not be preferable for some users.
|
||||
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
||||
|
||||
This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
||||
|
||||
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
||||
|
||||
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
||||
|
||||
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
||||
|
||||
**Why include `.vscode/extensions.json`?**
|
||||
|
||||
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
||||
|
||||
**Why enable `checkJs` in the JS template?**
|
||||
|
||||
It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration.
|
||||
|
||||
**Why is HMR not preserving my local component state?**
|
||||
|
||||
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
||||
|
||||
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
||||
|
||||
```js
|
||||
// store.js
|
||||
// An extremely simple external store
|
||||
import { writable } from 'svelte/store'
|
||||
export default writable(0)
|
||||
```
|
||||
# Embroidery Viewer
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
<script>
|
||||
import FileViewer from './lib/FileViewer.svelte'
|
||||
import logo from './assets/logo.webp'
|
||||
import FileViewer from "./lib/FileViewer.svelte";
|
||||
import logo from "./assets/logo.webp";
|
||||
</script>
|
||||
|
||||
<header>
|
||||
<a href="/">
|
||||
<img
|
||||
src={logo}
|
||||
alt="Embroidery viewer logo."
|
||||
width=460
|
||||
height=200
|
||||
/>
|
||||
<img src={logo} alt="Embroidery viewer logo." width="460" height="200" />
|
||||
</a>
|
||||
</header>
|
||||
<main>
|
||||
<FileViewer />
|
||||
</main>
|
||||
<footer>
|
||||
<p>Copyright © 2022 <a href="https://leomurca.xyz" target="_blank" rel="noreferrer" >Leonardo Murça</a>.</p>
|
||||
<p>
|
||||
Copyright © 2022 <a
|
||||
href="https://leomurca.xyz"
|
||||
target="_blank"
|
||||
rel="noreferrer">Leonardo Murça</a
|
||||
>.
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { startFileRead } from '../utils/main';
|
||||
import { startFileRead } from "../utils/main";
|
||||
|
||||
let files;
|
||||
const acceptedFiles = [".pes"];
|
||||
|
@ -10,30 +10,30 @@ function onSubmitHandler(evt) {
|
|||
evt.preventDefault();
|
||||
|
||||
for (var i = 0, file; (file = files[i]); i++) {
|
||||
const canvasContainer = document.getElementById("canvas-container")
|
||||
const canvasCard = document.createElement(`div`)
|
||||
const canvasEl = document.createElement(`canvas`)
|
||||
const fileNameEl = document.createElement(`p`)
|
||||
const canvasContainer = document.getElementById("canvas-container");
|
||||
const canvasCard = document.createElement(`div`);
|
||||
const canvasEl = document.createElement(`canvas`);
|
||||
const fileNameEl = document.createElement(`p`);
|
||||
|
||||
canvasCard.id = `canvas-card-${i}`
|
||||
canvasCard.style['display'] = "flex"
|
||||
canvasCard.style['flex-direction'] = "column"
|
||||
canvasCard.style['justify-content'] = "center"
|
||||
canvasCard.style['align-items'] = "center"
|
||||
canvasCard.style['width'] = "550px"
|
||||
canvasCard.style['height'] = "550px"
|
||||
canvasCard.style['margin-bottom'] = "15px"
|
||||
canvasCard.style['border'] = "2px solid black"
|
||||
canvasCard.id = `canvas-card-${i}`;
|
||||
canvasCard.style["display"] = "flex";
|
||||
canvasCard.style["flex-direction"] = "column";
|
||||
canvasCard.style["justify-content"] = "center";
|
||||
canvasCard.style["align-items"] = "center";
|
||||
canvasCard.style["width"] = "550px";
|
||||
canvasCard.style["height"] = "550px";
|
||||
canvasCard.style["margin-bottom"] = "15px";
|
||||
canvasCard.style["border"] = "2px solid black";
|
||||
|
||||
canvasEl.id = `mycanvas-${i}`
|
||||
canvasEl.id = `mycanvas-${i}`;
|
||||
canvasEl.style["height"] = "80%";
|
||||
canvasEl.style["width"] = "fit-content";
|
||||
|
||||
fileNameEl.textContent = file.name
|
||||
fileNameEl.textContent = file.name;
|
||||
|
||||
canvasCard.appendChild(canvasEl)
|
||||
canvasCard.appendChild(fileNameEl)
|
||||
canvasContainer.appendChild(canvasCard)
|
||||
canvasCard.appendChild(canvasEl);
|
||||
canvasCard.appendChild(fileNameEl);
|
||||
canvasContainer.appendChild(canvasCard);
|
||||
|
||||
if (file) {
|
||||
startFileRead(file, canvasEl);
|
||||
|
@ -45,29 +45,30 @@ function onSubmitHandler(evt) {
|
|||
function handleDragOver(evt) {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
function onDropHandler(evt) {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
onChangeFileHandler(evt)
|
||||
onChangeFileHandler(evt);
|
||||
}
|
||||
|
||||
function onChangeFileHandler(evt) {
|
||||
const changedFiles = evt.dataTransfer ? evt.dataTransfer.files : evt.target.files;
|
||||
const changedFiles = evt.dataTransfer
|
||||
? evt.dataTransfer.files
|
||||
: evt.target.files;
|
||||
let filesToUpload = [];
|
||||
for (var i = 0, file; (file = changedFiles[i]); i++) {
|
||||
if (file) {
|
||||
if (file.size <= maxFileSize) {
|
||||
filesToUpload.push(file);
|
||||
} else {
|
||||
console.log("File too large!")
|
||||
console.log(file)
|
||||
console.log("File too large!");
|
||||
console.log(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
files = filesToUpload
|
||||
files = filesToUpload;
|
||||
}
|
||||
|
||||
function handleOnClick(evt) {
|
||||
|
@ -81,20 +82,36 @@ function handleOnKeydown(evt) {
|
|||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
on:submit={onSubmitHandler}
|
||||
id="form"
|
||||
action="#"
|
||||
enctype="multipart/form-data">
|
||||
<form on:submit={onSubmitHandler} id="form" enctype="multipart/form-data">
|
||||
<h2>Upload files</h2>
|
||||
<p>Max file size is <strong>{maxFileSize/1000}kb</strong>. Accepted formats: <strong>{acceptedFiles.join(",")}</strong>.</p>
|
||||
<p>
|
||||
Max file size is <strong>{maxFileSize / 1000}kb</strong>. Accepted formats:
|
||||
<strong>{acceptedFiles.join(",")}</strong>.
|
||||
</p>
|
||||
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<div id="dropzone" tabindex={0} on:keydown={handleOnKeydown} on:click={handleOnClick} on:dragover={handleDragOver} on:drop={onDropHandler}>
|
||||
<label id="file-label" for="file-input">Drag and drop files here or click to upload.</label>
|
||||
<input id="file-input" type="file" name="files[]" accept={acceptedFiles.join(",")} multiple on:change={onChangeFileHandler} bind:files />
|
||||
<div
|
||||
id="dropzone"
|
||||
tabindex={0}
|
||||
on:keydown={handleOnKeydown}
|
||||
on:click={handleOnClick}
|
||||
on:dragover={handleDragOver}
|
||||
on:drop={onDropHandler}
|
||||
>
|
||||
<label id="file-label" for="file-input"
|
||||
>Drag and drop files here or click to upload.</label
|
||||
>
|
||||
<input
|
||||
id="file-input"
|
||||
type="file"
|
||||
name="files[]"
|
||||
accept={acceptedFiles.join(",")}
|
||||
multiple
|
||||
on:change={onChangeFileHandler}
|
||||
bind:files
|
||||
/>
|
||||
</div>
|
||||
<input type="submit" value="Render files">
|
||||
<input type="submit" value="Render files" />
|
||||
</form>
|
||||
|
||||
<div id="selected-files-container">
|
||||
|
@ -108,10 +125,9 @@ function handleOnKeydown(evt) {
|
|||
{/if}
|
||||
</div>
|
||||
|
||||
<div id="canvas-container" style="width: 100%; heigth: 100vh;"></div>
|
||||
<div id="canvas-container" style="width: 100%; heigth: 100vh;" />
|
||||
|
||||
<style>
|
||||
|
||||
input[type="submit"] {
|
||||
width: 100%;
|
||||
font-size: 20px;
|
||||
|
@ -166,5 +182,4 @@ function handleOnKeydown(evt) {
|
|||
border: 5px dotted #05345f;
|
||||
color: #05345f;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
10
src/main.js
10
src/main.js
|
@ -1,8 +1,8 @@
|
|||
import './app.css'
|
||||
import App from './App.svelte'
|
||||
import "./app.css";
|
||||
import App from "./App.svelte";
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById('app')
|
||||
})
|
||||
target: document.getElementById("app"),
|
||||
});
|
||||
|
||||
export default app
|
||||
export default app;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
import { defineConfig } from "vite";
|
||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [svelte()]
|
||||
})
|
||||
plugins: [svelte()],
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue