Reorganize source structure for better maintainability

- Move from 3-file structure to organized 5-file structure
- Create css/ and js/ subdirectories for better organization
- Split styles into main.css and themes.css for clarity
- Extract configuration constants to separate config.js file
- Rename template.html to index.html for clarity
- Update build.js to handle new organized structure
- Replace magic numbers with CALCULATOR_CONFIG constants

New structure:
  src/
    ├── index.html       (HTML template)
    ├── css/
    │   ├── main.css     (Core styles)
    │   └── themes.css   (Theme variations)
    └── js/
        ├── config.js    (Configuration constants)
        └── calculator.js (Main logic)

This provides a good balance between organization and simplicity,
making the codebase easier to maintain without over-modularization.
This commit is contained in:
Dayowe
2025-08-18 09:05:00 +02:00
parent ba3e0a6a6a
commit 73793f43a1
8 changed files with 545 additions and 491 deletions
+20 -7
View File
@@ -448,7 +448,8 @@
}
/* Dark theme - manual override */
.dog-calculator-container.theme-dark {
.dog-calculator-container.theme-dark {
--bg-primary: #24202d;
--bg-secondary: #312b3b;
--border-color: #433c4f;
@@ -2024,6 +2025,18 @@
</div>
<script>
/**
* Configuration constants for Dog Calorie Calculator
*/
const CALCULATOR_CONFIG = {
defaultTheme: 'system',
defaultScale: 1.0,
maxFoodSources: 5,
minScale: 0.5,
maxScale: 2.0
};
/**
* Dog Calorie Calculator - iframe version
* by Canine Nutrition and Wellness
*/
@@ -2032,10 +2045,10 @@
constructor() {
this.currentMER = 0;
this.isImperial = false;
this.theme = this.getThemeFromURL() || 'system';
this.scale = this.getScaleFromURL() || 1.0;
this.theme = this.getThemeFromURL() || CALCULATOR_CONFIG.defaultTheme;
this.scale = this.getScaleFromURL() || CALCULATOR_CONFIG.defaultScale;
this.foodSources = [];
this.maxFoodSources = 5;
this.maxFoodSources = CALCULATOR_CONFIG.maxFoodSources;
this.init();
}
@@ -2061,7 +2074,7 @@
getScaleFromURL() {
const urlParams = new URLSearchParams(window.location.search);
const scale = parseFloat(urlParams.get('scale'));
return (!isNaN(scale) && scale >= 0.5 && scale <= 2.0) ? scale : null;
return (!isNaN(scale) && scale >= CALCULATOR_CONFIG.minScale && scale <= CALCULATOR_CONFIG.maxScale) ? scale : null;
}
applyTheme() {
@@ -2074,8 +2087,8 @@
const container = document.getElementById('dogCalculator');
if (!container) return;
// Clamp scale between 0.5 and 2.0 for usability
const clampedScale = Math.max(0.5, Math.min(2.0, this.scale));
// Clamp scale between min and max for usability
const clampedScale = Math.max(CALCULATOR_CONFIG.minScale, Math.min(CALCULATOR_CONFIG.maxScale, this.scale));
if (clampedScale !== 1.0) {
container.style.transform = `scale(${clampedScale})`;