Format all files

This commit is contained in:
Leonardo Murça 2022-11-11 10:57:53 -03:00
parent 5eb7ea10ad
commit a777f33fa6
5 changed files with 122 additions and 152 deletions

View file

@ -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

View file

@ -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>

View file

@ -1,117 +1,133 @@
<script>
import { startFileRead } from '../utils/main';
import { startFileRead } from "../utils/main";
let files;
const acceptedFiles = [".pes"];
const maxFileSize = 700000;
let files;
const acceptedFiles = [".pes"];
const maxFileSize = 700000;
function onSubmitHandler(evt) {
evt.stopPropagation();
evt.preventDefault();
function onSubmitHandler(evt) {
evt.stopPropagation();
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`)
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`);
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.style["height"] = "80%";
canvasEl.style["width"] = "fit-content";
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);
}
}
document.getElementById("selected-files-container").remove();
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
}
function onDropHandler(evt) {
evt.stopPropagation();
evt.preventDefault();
onChangeFileHandler(evt)
}
function onChangeFileHandler(evt) {
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)
if (file) {
startFileRead(file, canvasEl);
}
}
document.getElementById("selected-files-container").remove();
}
files = filesToUpload
}
function handleOnClick(evt) {
document.getElementById("file-input").click();
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
}
function handleOnKeydown(evt) {
if (evt.key === "Enter") {
function onDropHandler(evt) {
evt.stopPropagation();
evt.preventDefault();
onChangeFileHandler(evt);
}
function onChangeFileHandler(evt) {
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);
}
}
}
files = filesToUpload;
}
function handleOnClick(evt) {
document.getElementById("file-input").click();
}
}
function handleOnKeydown(evt) {
if (evt.key === "Enter") {
document.getElementById("file-input").click();
}
}
</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">
{#if files}
<h2>Selected files:</h2>
{#each Array.from(files) as file}
<div id="selected-file-card">
<p>{file.name} ({file.size/1000} kb) </p>
</div>
{/each}
{/if}
{#if files}
<h2>Selected files:</h2>
{#each Array.from(files) as file}
<div id="selected-file-card">
<p>{file.name} ({file.size / 1000} kb)</p>
</div>
{/each}
{/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;
@ -155,7 +171,7 @@ function handleOnKeydown(evt) {
#canvas-container {
display: flex;
width: 100%;
width: 100%;
justify-content: space-evenly;
flex-wrap: wrap;
margin-top: 50px;
@ -166,5 +182,4 @@ function handleOnKeydown(evt) {
border: 5px dotted #05345f;
color: #05345f;
}
</style>

View file

@ -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;

View file

@ -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()],
});