Skip to content

Commit

Permalink
refactor entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 26, 2024
1 parent d4c018c commit aa972b0
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 123 deletions.
90 changes: 0 additions & 90 deletions css/main.css
Original file line number Diff line number Diff line change
@@ -1,91 +1 @@
/* Base styles */
* {
user-select: none;
}

body {
background-color: black;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

a:hover {
cursor: pointer;
}

canvas {
position: absolute;
z-index: 1;
}

/* Shared Button Styles */
button {
background-color: #202020;
color: #d8d4cf;
border: 1px solid #454545;
border-radius: 4px;
padding: 8px 10px;
cursor: pointer;
transition: background-color 0.2s;
font-size: 20px;
width: 52px;
}

button:hover {
background-color: #3e4446;
}

/* Form Elements */
fieldset {
border: 1px solid #3e4446;
border-radius: 5px;
margin-bottom: 5px;
padding: 10px;
}

legend {
color: #d8d4cf;
padding: 0 5px;
}

i {
color: #fff; /* Ensuring the icons are white */
}

.icon-button {
width: 32px;
height: 32px;
border: none;
border-radius: 4px;
background-color: #333;
align-items: center;
justify-content: center;
background: none;
color: inherit;
font-size: 20px;
cursor: pointer;
padding: 5px;
transition: background-color 0.2s;
transition: transform 0.2s, color 0.2s;
}

.icon-button:hover {
background-color: #444;
color: #66ff66;
transform: scale(1.1);
}

.icon-button:active {
background-color: #555;
transform: scale(1);
}

.icon-button {
}

.icon-button i {
pointer-events: none; /* Prevent accidental selection of the icon */
}


3 changes: 1 addition & 2 deletions css/styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import url('main.css');
@import url('vortex-editor.css');
@import url('notification.css');
@import url('panel.css');

@import url('about-panel.css');
@import url('animation-panel.css');
@import url('chromalink-panel.css');
Expand Down
91 changes: 91 additions & 0 deletions css/vortex-editor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Base styles */
* {
user-select: none;
}

body {
background-color: black;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

a:hover {
cursor: pointer;
}

canvas {
position: absolute;
z-index: 1;
}

/* Shared Button Styles */
button {
background-color: #202020;
color: #d8d4cf;
border: 1px solid #454545;
border-radius: 4px;
padding: 8px 10px;
cursor: pointer;
transition: background-color 0.2s;
font-size: 20px;
width: 52px;
}

button:hover {
background-color: #3e4446;
}

/* Form Elements */
fieldset {
border: 1px solid #3e4446;
border-radius: 5px;
margin-bottom: 5px;
padding: 10px;
}

legend {
color: #d8d4cf;
padding: 0 5px;
}

i {
color: #fff; /* Ensuring the icons are white */
}

.icon-button {
width: 32px;
height: 32px;
border: none;
border-radius: 4px;
background-color: #333;
align-items: center;
justify-content: center;
background: none;
color: inherit;
font-size: 20px;
cursor: pointer;
padding: 5px;
transition: background-color 0.2s;
transition: transform 0.2s, color 0.2s;
}

.icon-button:hover {
background-color: #444;
color: #66ff66;
transform: scale(1.1);
}

.icon-button:active {
background-color: #555;
transform: scale(1);
}

.icon-button {
}

.icon-button i {
pointer-events: none; /* Prevent accidental selection of the icon */
}


7 changes: 1 addition & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
<html lang="en">
<head>
<title>Lightshowz lol</title>
<script type="module" src="js/Main.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pako.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script type="module" src="js/VortexEditor.js"></script>
</head>
<body>
</body>
Expand Down
18 changes: 0 additions & 18 deletions js/Main.js

This file was deleted.

54 changes: 47 additions & 7 deletions js/VortexEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import WelcomePanel from './WelcomePanel.js';
import ChromalinkPanel from './ChromalinkPanel.js';
import UpdatePanel from './UpdatePanel.js';
import Notification from './Notification.js';
import VortexLib from './VortexLib.js';

export default class VortexEditor {
constructor(vortexLib) {
Expand Down Expand Up @@ -104,7 +105,10 @@ export default class VortexEditor {
};
}

initialize() {
async initialize() {
// Load dependencies
await this.loadDependencies();

// Start the lightshow
this.lightshow.start();

Expand Down Expand Up @@ -171,24 +175,54 @@ export default class VortexEditor {
if (isNowMobile !== this.isMobile) {
// when switching from mobile to non mobile update the layout
this.isMobile = isNowMobile;
this.updateStylesheet(this.isMobile);
this.applyLayout();
}
// always shift the lightshow to be centered
this.lightshow.resetToCenter();
});
}

async loadDependencies() {
this.loadStylesheet("mainStyles", "css/styles.css");
this.loadStylesheet("fontsAwesomeStyles", "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css");
await this.loadScript("pako", "https://cdn.jsdelivr.net/npm/[email protected]/dist/pako.min.js");
await this.loadScript("jszip", "https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js");

// Dynamically load ESPTool
window.esptoolPackage = await import(
window.location.hostname === "localhost"
? "/dist/web/index.js"
: "https://cdn.jsdelivr.net/gh/adafruit/Adafruit_WebSerial_ESPTool@latest/dist/web/index.js"
);
}

// Utility to dynamically load a script
loadScript(name, src, isModule = false) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.id = name;
if (isModule) script.type = 'module';
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}

// Utility to dynamically load a stylesheet
loadStylesheet(name, href) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.id = name;
link.href = href;
document.head.appendChild(link);
}

detectMobile() {
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent) || window.innerWidth < 1200;
}

updateStylesheet(isMobile) {
const layoutStylesheet = document.getElementById('layoutStylesheet');
layoutStylesheet.href = isMobile ? 'css/mobile_styles.css' : 'css/styles.css';
}

applyLayout() {
if (this.isMobile) {
this.applyMobileLayout();
Expand Down Expand Up @@ -335,3 +369,9 @@ export default class VortexEditor {
}
}

// Main initialization of VortexLib and Vortex Editor
VortexLib().then(async (vortexLib) => {
// Instantiate and initialize VortexEditor
const vortexEditor = new VortexEditor(vortexLib);
await vortexEditor.initialize();
});

0 comments on commit aa972b0

Please sign in to comment.