From 39a8fca8fa1715e3f97a9e63b3082e7e0290d1de Mon Sep 17 00:00:00 2001 From: Jianmin Chen <59099858+jianmin-chen@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:34:18 -0500 Subject: [PATCH] Run Prettier --- astro/.gitignore | 3 +- .prettierignore => astro/.prettierignore | 4 +- .prettierrc => astro/.prettierrc | 0 astro/astro.config.mjs | 8 +- astro/package.json | 2 +- astro/public/masonry.min.js | 56 +- astro/src/components/CodeMirror.module.css | 1 - astro/src/components/DropBox.tsx | 8 +- astro/src/components/Editor.module.css | 2 - astro/src/components/Editor.tsx | 20 +- astro/src/components/Error.tsx | 12 +- astro/src/components/Help.module.css | 2 +- astro/src/components/Help.tsx | 31 +- astro/src/components/Navbar.astro | 8 +- astro/src/components/Preview.tsx | 29 +- astro/src/components/Toolbar.tsx | 70 +- astro/src/components/landing/Background.astro | 32 +- .../src/components/landing/ThreeDModel.astro | 24 +- astro/src/css/global.css | 4 +- astro/src/css/reset.css | 41 +- astro/src/env.d.ts | 13 +- astro/src/layouts/Layout.astro | 6 +- astro/src/lib/codemirror/state.ts | 6 +- astro/src/lib/codemirror/widgetButtons.ts | 115 +- .../lib/drawingToolkit/drawingFns/simplify.js | 122 +- .../lib/drawingToolkit/flatten-svg/index.ts | 4 +- astro/src/lib/drawingToolkit/pipe.ts | 4 +- astro/src/lib/drawingToolkit/turtle.ts | 38 +- astro/src/lib/events/addBezierControl.js | 145 +- astro/src/lib/events/addMachineControl.js | 45 +- astro/src/lib/events/addNumberScrubbing.ts | 75 +- astro/src/lib/events/addSrcURLParam.js | 4 +- astro/src/lib/getBitmap.js | 98 +- astro/src/lib/init.js | 27 +- astro/src/lib/lineclip.ts | 12 +- astro/src/lib/removeQueryParam.js | 22 +- astro/src/lib/render.tsx | 4 +- astro/src/lib/run.ts | 69 +- astro/src/lib/runTextReturnTurtles.ts | 12 +- astro/src/lib/saveFile.ts | 63 +- astro/src/lib/state.ts | 8 +- astro/src/pages/assembly.astro | 1 - astro/src/pages/editor.astro | 13 +- astro/src/pages/gallery.astro | 42 +- astro/src/pages/guides.astro | 53 +- astro/src/pages/index.astro | 238 +- astro/src/pages/test.astro | 5 +- astro/src/ui/Button.tsx | 8 +- astro/tailwind.config.mjs | 10 +- astro/yarn-error.log | 6543 ----------------- 50 files changed, 847 insertions(+), 7315 deletions(-) rename .prettierignore => astro/.prettierignore (65%) rename .prettierrc => astro/.prettierrc (100%) delete mode 100644 astro/yarn-error.log diff --git a/astro/.gitignore b/astro/.gitignore index e555fbc8d..ee4be6c9a 100644 --- a/astro/.gitignore +++ b/astro/.gitignore @@ -1,4 +1,5 @@ node_modules .vercel .astro -dist \ No newline at end of file +dist +yarn-error.log \ No newline at end of file diff --git a/.prettierignore b/astro/.prettierignore similarity index 65% rename from .prettierignore rename to astro/.prettierignore index 2c4496072..2787b62ac 100644 --- a/.prettierignore +++ b/astro/.prettierignore @@ -3,6 +3,4 @@ package-lock.json public/* .next/* .vercel/* -*/.vercel -*/*/*.mdx -*/*/*/*.mdx \ No newline at end of file +*/.vercel \ No newline at end of file diff --git a/.prettierrc b/astro/.prettierrc similarity index 100% rename from .prettierrc rename to astro/.prettierrc diff --git a/astro/astro.config.mjs b/astro/astro.config.mjs index e4e8ace16..2fb05e00d 100644 --- a/astro/astro.config.mjs +++ b/astro/astro.config.mjs @@ -1,10 +1,10 @@ -import { defineConfig } from 'astro/config'; -import preact from '@astrojs/preact'; +import { defineConfig } from 'astro/config' +import preact from '@astrojs/preact' -import tailwind from "@astrojs/tailwind"; +import tailwind from '@astrojs/tailwind' // https://astro.build/config export default defineConfig({ site: 'https://blot.hackclub.com', integrations: [preact(), tailwind()] -}); \ No newline at end of file +}) diff --git a/astro/package.json b/astro/package.json index c0c3a854d..2233a5c86 100644 --- a/astro/package.json +++ b/astro/package.json @@ -10,7 +10,7 @@ "preview": "astro preview", "sync": "astro sync", "astro": "astro", - "format": "prettier --ignore-path ../.prettierignore --write . --plugin=prettier-plugin-astro" + "format": "prettier --ignore-path ./.prettierignore --write . --plugin=prettier-plugin-astro" }, "dependencies": { "@astrojs/check": "^0.2.0", diff --git a/astro/public/masonry.min.js b/astro/public/masonry.min.js index 54dc2f1d3..a476807c8 100644 --- a/astro/public/masonry.min.js +++ b/astro/public/masonry.min.js @@ -12,8 +12,8 @@ return e(t, i) }) : 'object' == typeof module && module.exports - ? (module.exports = e(t, require('jquery'))) - : (t.jQueryBridget = e(t, t.jQuery)) + ? (module.exports = e(t, require('jquery'))) + : (t.jQueryBridget = e(t, t.jQuery)) })(window, function (t, e) { 'use strict' function i(i, r, a) { @@ -74,8 +74,8 @@ 'function' == typeof define && define.amd ? define('ev-emitter/ev-emitter', e) : 'object' == typeof module && module.exports - ? (module.exports = e()) - : (t.EvEmitter = e()) + ? (module.exports = e()) + : (t.EvEmitter = e()) })('undefined' != typeof window ? window : this, function () { function t() {} var e = t.prototype @@ -128,8 +128,8 @@ 'function' == typeof define && define.amd ? define('get-size/get-size', e) : 'object' == typeof module && module.exports - ? (module.exports = e()) - : (t.getSize = e()) + ? (module.exports = e()) + : (t.getSize = e()) })(window, function () { 'use strict' function t(t) { @@ -256,8 +256,8 @@ 'function' == typeof define && define.amd ? define('desandro-matches-selector/matches-selector', e) : 'object' == typeof module && module.exports - ? (module.exports = e()) - : (t.matchesSelector = e()) + ? (module.exports = e()) + : (t.matchesSelector = e()) })(window, function () { 'use strict' var t = (function () { @@ -284,8 +284,8 @@ } ) : 'object' == typeof module && module.exports - ? (module.exports = e(t, require('desandro-matches-selector'))) - : (t.fizzyUIUtils = e(t, t.matchesSelector)) + ? (module.exports = e(t, require('desandro-matches-selector'))) + : (t.fizzyUIUtils = e(t, t.matchesSelector)) })(window, function (t, e) { var i = {} ;(i.extend = function (t, e) { @@ -397,8 +397,8 @@ e ) : 'object' == typeof module && module.exports - ? (module.exports = e(require('ev-emitter'), require('get-size'))) - : ((t.Outlayer = {}), (t.Outlayer.Item = e(t.EvEmitter, t.getSize))) + ? (module.exports = e(require('ev-emitter'), require('get-size'))) + : ((t.Outlayer = {}), (t.Outlayer.Item = e(t.EvEmitter, t.getSize))) })(window, function (t, e) { 'use strict' function i(t) { @@ -690,20 +690,20 @@ } ) : 'object' == typeof module && module.exports - ? (module.exports = e( - t, - require('ev-emitter'), - require('get-size'), - require('fizzy-ui-utils'), - require('./item') - )) - : (t.Outlayer = e( - t, - t.EvEmitter, - t.getSize, - t.fizzyUIUtils, - t.Outlayer.Item - )) + ? (module.exports = e( + t, + require('ev-emitter'), + require('get-size'), + require('fizzy-ui-utils'), + require('./item') + )) + : (t.Outlayer = e( + t, + t.EvEmitter, + t.getSize, + t.fizzyUIUtils, + t.Outlayer.Item + )) })(window, function (t, e, i, n, o) { 'use strict' function r(t, e) { @@ -1115,8 +1115,8 @@ 'function' == typeof define && define.amd ? define(['outlayer/outlayer', 'get-size/get-size'], e) : 'object' == typeof module && module.exports - ? (module.exports = e(require('outlayer'), require('get-size'))) - : (t.Masonry = e(t.Outlayer, t.getSize)) + ? (module.exports = e(require('outlayer'), require('get-size'))) + : (t.Masonry = e(t.Outlayer, t.getSize)) })(window, function (t, e) { var i = t.create('masonry') i.compatOptions.fitWidth = 'isFitWidth' diff --git a/astro/src/components/CodeMirror.module.css b/astro/src/components/CodeMirror.module.css index 260bee148..b0e8e28eb 100644 --- a/astro/src/components/CodeMirror.module.css +++ b/astro/src/components/CodeMirror.module.css @@ -6,4 +6,3 @@ height: 100%; width: 100%; } - diff --git a/astro/src/components/DropBox.tsx b/astro/src/components/DropBox.tsx index 41cf1bb79..4313a0d65 100644 --- a/astro/src/components/DropBox.tsx +++ b/astro/src/components/DropBox.tsx @@ -9,7 +9,8 @@ export default function DropBox() { }, []) // Empty dependency array means this effect runs once after initial render return ( -
+ }) + ;['mouseout'].forEach(trigger => window.addEventListener(trigger, function (evt) { droparea.classList.add('hidden') }) diff --git a/astro/src/components/Editor.module.css b/astro/src/components/Editor.module.css index be2cbd8bb..2e2cf8f8a 100644 --- a/astro/src/components/Editor.module.css +++ b/astro/src/components/Editor.module.css @@ -107,5 +107,3 @@ body[data-theme='dark'] { } */ - - diff --git a/astro/src/components/Editor.tsx b/astro/src/components/Editor.tsx index cd978a46c..8dcba527d 100644 --- a/astro/src/components/Editor.tsx +++ b/astro/src/components/Editor.tsx @@ -1,16 +1,16 @@ import { getStore } from '../lib/state.js' import { createListener } from '../lib/createListener.js' import styles from './Editor.module.css' -import CompatWarning from './CompatWarning.jsx' -import Preview from './Preview.jsx' -import Toolbar from './Toolbar.jsx' -import Error from './Error.jsx' -import Console from './Console.jsx' -import GlobalStateDebugger from './GlobalStateDebugger.jsx' -import DropBox from './DropBox.jsx' -import CodeMirror from './CodeMirror.jsx' +import CompatWarning from './CompatWarning.js' +import Preview from './Preview.js' +import Toolbar from './Toolbar.js' +import Error from './Error.js' +import Console from './Console.js' +import GlobalStateDebugger from './GlobalStateDebugger.js' +import DropBox from './DropBox.js' +import CodeMirror from './CodeMirror.js' import { useEffect, useRef, useState } from 'preact/hooks' -import Help from './Help.jsx' +import Help from './Help.js' import preview from '@astrojs/node/preview.js' export default function Editor() { @@ -63,7 +63,7 @@ export default function Editor() { 'flex-direction': 'column', 'overflow': 'none' }}> -
+
diff --git a/astro/src/components/Error.tsx b/astro/src/components/Error.tsx index 7d0d88732..100230f3b 100644 --- a/astro/src/components/Error.tsx +++ b/astro/src/components/Error.tsx @@ -84,8 +84,8 @@ const Snippet = ({
{pos.line}
- -
+ +
{' '.repeat(pos.column)} {message && {message}} @@ -106,15 +106,11 @@ export default function Error() { const { error } = getStore() if (!error) return null - + return (
{error.name} - +
) } diff --git a/astro/src/components/Help.module.css b/astro/src/components/Help.module.css index e0e13f427..17093eb11 100644 --- a/astro/src/components/Help.module.css +++ b/astro/src/components/Help.module.css @@ -87,4 +87,4 @@ body[data-theme='dark'] .helpContent hr { body[data-theme='dark'] .helpContent img { background-color: white; -} \ No newline at end of file +} diff --git a/astro/src/components/Help.tsx b/astro/src/components/Help.tsx index 1ef6cbe75..9dd7b28da 100644 --- a/astro/src/components/Help.tsx +++ b/astro/src/components/Help.tsx @@ -1,14 +1,14 @@ import styles from './Help.module.css' import { useState, useEffect } from 'preact/hooks' import { marked } from 'marked' -import { loadCodeFromString } from "../lib/loadCodeFromString.ts"; +import { loadCodeFromString } from '../lib/loadCodeFromString.ts' marked.setOptions({ - highlight: function (code, language) { - const validLanguage = Prism.languages[language] ? language : 'markup'; - return Prism.highlight(code, Prism.languages[validLanguage], validLanguage); - } -}); + highlight: function (code, language) { + const validLanguage = Prism.languages[language] ? language : 'markup' + return Prism.highlight(code, Prism.languages[validLanguage], validLanguage) + } +}) export default function Help({ toggleClose, @@ -28,7 +28,7 @@ export default function Help({ htmlContent: '' }) - const [helpContent, setHelpContent] = useState(""); + const [helpContent, setHelpContent] = useState('') useEffect(() => { const fetchData = async () => { @@ -37,12 +37,12 @@ export default function Help({ ) const helpData = await helpRes.text() - setHelpContent(marked(helpData)); + setHelpContent(marked(helpData)) if (workshop === null) return - - if (confirm("Clear text editor?")) loadCodeFromString(`// Check the workshop tab to get started + if (confirm('Clear text editor?')) + loadCodeFromString(`// Check the workshop tab to get started const width = 125; const height = 125; @@ -61,8 +61,7 @@ testTurtle.translate( drawTurtles([ testTurtle ]); -`); - +`) const res = await fetch( `https://raw.githubusercontent.com/hackclub/blot/main/guides/${workshop}.md` @@ -71,8 +70,8 @@ drawTurtles([ const result = parseMDFrontMatter(data) - setWorkshopContent(result); - setTab('workshop'); + setWorkshopContent(result) + setTab('workshop') } fetchData() @@ -80,7 +79,9 @@ drawTurtles([ return ( <> -
+
{workshop && ( - + blot
@@ -122,7 +122,11 @@ import GitHubIcon from '../ui/GitHubIcon.tsx' > build guide - + { - mousedown = true; + let mousedown = false + canvasListener('mousedown', '', e => { + mousedown = true }) - canvasListener("mouseup", "", e => { - mousedown = false; + canvasListener('mouseup', '', e => { + mousedown = false }) canvasListener('mousemove', '', (e: MouseEvent) => { @@ -231,17 +230,14 @@ const _redraw = (canvas: HTMLCanvasElement) => { // draw turtles - // turtle path // if(turtles.length === 0) return; const { panX, panY, scale } = panZoomParams - for (const turtle of turtles) { ctx.beginPath() for (const polyline of turtle.path) { - // let paths = polyline.map(([x, y]) => [ // dpr * (panX + x * scale), // -(dpr * (-panY + y * scale)) @@ -250,18 +246,17 @@ const _redraw = (canvas: HTMLCanvasElement) => { // paths = lineclip(paths, [0, 0, width, height]) polyline.forEach((p, i) => { - let [x, y] = p; - x = dpr * (panX + x * scale); - y = -(dpr * (-panY + y * scale)); + let [x, y] = p + x = dpr * (panX + x * scale) + y = -(dpr * (-panY + y * scale)) if (i === 0) ctx.moveTo(x, y) else ctx.lineTo(x, y) }) - } - ctx.strokeStyle = turtle.style.stroke; - ctx.stroke(); + ctx.strokeStyle = turtle.style.stroke + ctx.stroke() - ctx.fillStyle = turtle.style.fill; - if (turtle.style.fill !== "none") ctx.fill(); + ctx.fillStyle = turtle.style.fill + if (turtle.style.fill !== 'none') ctx.fill() } } diff --git a/astro/src/components/Toolbar.tsx b/astro/src/components/Toolbar.tsx index 66bf4ba78..5d2021815 100644 --- a/astro/src/components/Toolbar.tsx +++ b/astro/src/components/Toolbar.tsx @@ -22,7 +22,7 @@ import GitHubIcon from '../ui/GitHubIcon.tsx' import { saveFile } from '../lib/saveFile.ts' import * as prettier from 'prettier' import js_beautify from 'js-beautify' -import { createMask } from "../lib/getBitmap.js"; +import { createMask } from '../lib/getBitmap.js' import { Turtle } from '../lib/drawingToolkit/index.js' export default function Toolbar() { @@ -79,8 +79,8 @@ export default function Toolbar() {
{ - const { turtles } = getStore(); - const { isVisible } = createMask(); + const { turtles } = getStore() + const { isVisible } = createMask() // const newTurtle = new Turtle(); // let lastVisible = false; @@ -109,20 +109,17 @@ export default function Toolbar() { // }) turtles.forEach(turtle => { - turtle - .resample(0.01) - .iteratePath(([x, y], t) => { - const visible = isVisible(x, y); + turtle.resample(0.01).iteratePath(([x, y], t) => { + const visible = isVisible(x, y) - if (!visible) return "BREAK"; + if (!visible) return 'BREAK' }) // turtle.simplify(0.01); - turtle.style.fill = "none"; + turtle.style.fill = 'none' }) - patchStore({ turtles }); - + patchStore({ turtles }) }}> cull hidden lines
@@ -134,46 +131,75 @@ export default function Toolbar() {
machine control