-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReLatto.html
More file actions
610 lines (521 loc) · 28.5 KB
/
Copy pathReLatto.html
File metadata and controls
610 lines (521 loc) · 28.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ReLatto Bar & QR Code Gen</title>
<!-- Load Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Load Inter, Roboto Mono, and Georgia fonts -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&family=Roboto+Mono:wght@400;700&family=Georgia:wght@400;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #f7fafc; /* Light gray background */
}
/* Custom styles for the output area */
#outputCanvas {
max-width: 100%;
height: auto;
border-radius: 0.5rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
/* Style for the main container to handle layout switch (horizontal/vertical panels) */
.content-container-horizontal {
display: grid;
/* CRITICAL FIX: Sets grid ratio explicitly: 1fr (Settings, 25%) / 3fr (Output, 75%) */
grid-template-columns: 1fr 3fr;
gap: 2rem;
}
@media (max-width: 768px) {
.content-container-horizontal {
grid-template-columns: 1fr;
}
}
/* Specific font definitions for dropdown */
.font-inter { font-family: 'Inter', sans-serif; }
.font-roboto-mono { font-family: 'Roboto Mono', monospace; }
.font-georgia { font-family: Georgia, serif; }
</style>
<!-- JsBarcode CDN for Code 39 and 128 -->
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.6/dist/JsBarcode.all.min.js"></script>
<!-- qrcode-generator CDN for QR codes -->
<script src="https://cdn.jsdelivr.net/npm/qrcode-generator/qrcode.min.js"></script>
<!-- jsPDF CDN for PDF generation (NEW) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
</head>
<body class="p-4 md:p-8 min-h-screen">
<header class="mb-8 text-center">
<h1 class="text-4xl font-extrabold text-gray-900 tracking-tight">
<span class="text-indigo-600">ReLatto</span> Bar & QR Code Gen
</h1>
<p class="text-gray-500 mt-2">Professional, customizable code generation for your needs.</p>
</header>
<main id="app-container" class="max-w-6xl mx-auto">
<!-- Main Content Area: Flex or Grid, depending on layout -->
<div id="content-area" class="flex flex-col md:content-container-horizontal">
<!-- 1. Input and Controls Panel (Now correctly 25% width on desktop horizontal layout) -->
<section class="p-6 bg-white rounded-xl shadow-2xl md:mb-0 mb-8 flex-shrink-0">
<h2 class="text-xl font-bold mb-4 text-indigo-700 border-b pb-2">Settings & Data</h2>
<!-- Input Field (Data to Encode) -->
<div class="mb-4">
<label for="codeData" class="block text-sm font-medium text-gray-700 mb-1">
Data to Encode (e.g., URL, Product ID)
</label>
<input type="text" id="codeData" value="ReLatto123" maxlength="100"
class="w-full p-3 border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 transition duration-150 ease-in-out"
placeholder="Enter text or numbers">
</div>
<!-- Type Selection -->
<div class="mb-6">
<label for="codeType" class="block text-sm font-medium text-gray-700 mb-2">
Code Type
</label>
<select id="codeType"
class="w-full p-3 bg-white border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 appearance-none cursor-pointer transition duration-150 ease-in-out">
<option value="QR">QR Code</option>
<option value="CODE128" selected>Barcode (Code 128)</option>
<option value="CODE39">Barcode (Code 39)</option>
</select>
</div>
<h2 class="text-xl font-bold mb-4 text-indigo-700 border-b pb-2">Design & Placement</h2>
<!-- Layout Selection (Panel layout) -->
<div class="mb-4">
<label for="layout" class="block text-sm font-medium text-gray-700 mb-2">
Panel Layout (Desktop Only)
</label>
<select id="layout"
class="w-full p-3 bg-white border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 appearance-none cursor-pointer transition duration-150 ease-in-out">
<option value="vertical">Vertical (Controls on Top)</option>
<option value="horizontal" selected>Horizontal (Controls on Left)</option>
</select>
</div>
<!-- Custom Wording Toggle -->
<div class="mb-4 flex items-center">
<input type="checkbox" id="enableWordingCheck" checked
class="h-4 w-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
onchange="generateCode()">
<label for="enableWordingCheck" class="ml-2 block text-sm font-medium text-gray-700">
Enable Custom Wording
</label>
</div>
<!-- Custom Wording Input -->
<div class="mb-4">
<label for="customWordingInput" class="block text-sm font-medium text-gray-700 mb-1">
Custom Label/Wording
</label>
<input type="text" id="customWordingInput" value="Scan or Check Below"
class="w-full p-3 border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 transition duration-150 ease-in-out"
placeholder="Optional text label on the code image">
</div>
<!-- Text Position Selection -->
<div class="mb-4">
<label for="textPositionSelect" class="block text-sm font-medium text-gray-700 mb-2">
Wording Position
</label>
<select id="textPositionSelect"
class="w-full p-3 bg-white border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 appearance-none cursor-pointer transition duration-150 ease-in-out">
<option value="bottom" selected>Bottom</option>
<option value="top">Top</option>
<option value="left">Left (Vertically Aligned)</option>
<option value="right">Right (Vertically Aligned)</option>
</select>
</div>
<!-- Font Family Selection -->
<div class="mb-4">
<label for="fontFamilySelect" class="block text-sm font-medium text-gray-700 mb-2">
Wording Font
</label>
<select id="fontFamilySelect"
class="w-full p-3 bg-white border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 appearance-none cursor-pointer transition duration-150 ease-in-out">
<option value="Inter" selected class="font-inter">Inter (Sans-Serif)</option>
<option value="Roboto Mono" class="font-roboto-mono">Roboto Mono (Monospace)</option>
<option value="Georgia" class="font-georgia">Georgia (Serif)</option>
</select>
</div>
<!-- Font Weight Selection -->
<div class="mb-6">
<label for="fontWeightSelect" class="block text-sm font-medium text-gray-700 mb-2">
Wording Weight
</label>
<select id="fontWeightSelect"
class="w-full p-3 bg-white border border-gray-300 rounded-lg shadow-sm focus:ring-indigo-500 focus:border-indigo-500 appearance-none cursor-pointer transition duration-150 ease-in-out">
<option value="normal">Normal</option>
<option value="bold" selected>Bold</option>
</select>
</div>
<h2 class="text-xl font-bold mb-4 text-indigo-700 border-b pb-2">Colors</h2>
<!-- Color Pickers -->
<div class="flex space-x-4">
<div class="flex-1">
<label for="codeColorInput" class="block text-sm font-medium text-gray-700 mb-1">
Code Color
</label>
<input type="color" id="codeColorInput" value="#000000"
class="w-full h-10 p-1 border border-gray-300 rounded-lg shadow-sm cursor-pointer">
</div>
<div class="flex-1">
<label for="bgColorInput" class="block text-sm font-medium text-gray-700 mb-1">
BG Color
</label>
<input type="color" id="bgColorInput" value="#FFFFFF"
class="w-full h-10 p-1 border border-gray-300 rounded-lg shadow-sm cursor-pointer">
</div>
</div>
<!-- Error/Message Display -->
<div id="message" class="text-sm p-3 rounded-lg bg-red-100 text-red-700 mt-6 hidden"></div>
</section>
<!-- 2. Output Display Area (Now correctly 75% width on desktop horizontal layout) -->
<section class="flex flex-col items-center justify-center p-6 bg-indigo-50 rounded-xl shadow-inner flex-grow">
<h2 class="text-xl font-semibold mb-4 text-gray-700">Generated Code Preview</h2>
<!-- Output Wrapper: ONLY CANVAS REMAINS -->
<div id="outputWrapper" class="flex items-center justify-center p-4 max-w-full">
<canvas id="outputCanvas" class="flex-shrink-0"></canvas>
</div>
<!-- Download Buttons (NEW) -->
<div class="flex flex-wrap justify-center gap-4 mt-6">
<button id="downloadPngBtn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-150 shadow-lg transform hover:scale-105">
Download PNG
</button>
<button id="downloadJpegBtn" class="bg-yellow-600 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded-lg transition duration-150 shadow-lg transform hover:scale-105">
Download JPEG
</button>
<button id="downloadPdfBtn" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-lg transition duration-150 shadow-lg transform hover:scale-105">
Download PDF
</button>
</div>
</section>
</div>
</main>
<script>
// Global variables for DOM elements
const codeDataInput = document.getElementById('codeData');
const codeTypeSelect = document.getElementById('codeType');
const layoutSelect = document.getElementById('layout');
const customWordingInput = document.getElementById('customWordingInput');
const textPositionSelect = document.getElementById('textPositionSelect');
const fontFamilySelect = document.getElementById('fontFamilySelect');
const fontWeightSelect = document.getElementById('fontWeightSelect');
const enableWordingCheck = document.getElementById('enableWordingCheck');
const codeColorInput = document.getElementById('codeColorInput');
const bgColorInput = document.getElementById('bgColorInput');
const outputCanvas = document.getElementById('outputCanvas');
const messageDiv = document.getElementById('message');
const contentArea = document.getElementById('content-area');
// Download buttons (NEW)
const downloadPngBtn = document.getElementById('downloadPngBtn');
const downloadJpegBtn = document.getElementById('downloadJpegBtn');
const downloadPdfBtn = document.getElementById('downloadPdfBtn');
// Global constants for drawing
const TEXT_AREA_HEIGHT = 40; // Height reserved for text
const CODE_PADDING = 20; // Padding around code inside final canvas
// --- Helper Functions ---
/**
* Displays an error message.
* @param {string} msg
*/
function showMessage(msg) {
messageDiv.textContent = msg;
messageDiv.classList.remove('hidden');
}
/**
* Clears the error message.
*/
function clearMessage() {
messageDiv.classList.add('hidden');
messageDiv.textContent = '';
}
// --- Intermediate Canvas Generation Functions (Now return an intermediate canvas) ---
/**
* Generates a QR Code on an intermediate canvas.
* @returns {object|null} An object { canvas: HTMLCanvasElement, width: number, height: number } or null on error.
*/
function generateQRCode(data, codeColor, bgColor) {
try {
const qr = qrcode(0, 'L'); // Error correction level 'L'
qr.addData(data);
qr.make();
const size = qr.getModuleCount();
// Scale factor to make the QR code visually large (min 256px wide)
const scale = Math.max(Math.floor(256 / size), 4);
const codeSize = size * scale;
const canvas = document.createElement('canvas'); // Intermediate canvas
canvas.width = codeSize;
canvas.height = codeSize;
const ctx = canvas.getContext('2d');
// Draw background (only for the code area)
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, codeSize, codeSize);
// Draw the QR code modules (dots)
for (let r = 0; r < size; r++) {
for (let c = 0; c < size; c++) {
if (qr.isDark(r, c)) {
ctx.fillStyle = codeColor;
ctx.fillRect(c * scale, r * scale, scale, scale);
}
}
}
return { canvas: canvas, width: codeSize, height: codeSize };
} catch (e) {
showMessage("QR Code generation failed. Data might be too long.");
console.error("QR Code Error:", e);
return null;
}
}
/**
* Generates a Barcode (Code 39 or Code 128) on an intermediate canvas.
* @returns {object|null} An object { canvas: HTMLCanvasElement, width: number, height: number } or null on error.
*/
function generateBarcode(data, type, codeColor, bgColor) {
try {
// Use a temporary, hidden canvas for JsBarcode to draw onto
const tempCanvas = document.createElement('canvas');
tempCanvas.style.display = 'none';
document.body.appendChild(tempCanvas);
// JsBarcode will draw and resize this temporary canvas
JsBarcode(tempCanvas, data, {
format: type,
displayValue: false,
width: 2,
height: 100,
margin: 10,
textMargin: 0,
fontSize: 18,
lineColor: codeColor,
background: bgColor,
valid: function(valid) {
if (!valid) {
throw new Error(`Invalid data for ${type}.`);
}
}
});
// Extract dimensions and clone the canvas content to a new one
const codeWidth = tempCanvas.width;
const codeHeight = tempCanvas.height;
const finalCanvas = document.createElement('canvas');
finalCanvas.width = codeWidth;
finalCanvas.height = codeHeight;
finalCanvas.getContext('2d').drawImage(tempCanvas, 0, 0);
document.body.removeChild(tempCanvas); // Clean up temp canvas
return { canvas: finalCanvas, width: codeWidth, height: codeHeight };
} catch (e) {
let errorMsg = `Barcode (${type}) failed: ${e.message}`;
showMessage(errorMsg);
console.error("Barcode Error:", e);
return null;
}
}
/**
* Draws the custom text onto the main canvas.
*/
function drawCustomText(ctx, finalWidth, finalHeight, codeColor, textPosition, codeAreaStart, codeAreaEnd) {
const customText = customWordingInput.value.trim();
const font = fontFamilySelect.value;
const weight = fontWeightSelect.value;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = codeColor; // Use code color for text
ctx.font = `${weight} 16px ${font}`; // Apply weight and font
const centerX = finalWidth / 2;
let textY;
// Determine text position
let effectivePosition = textPosition;
if (textPosition === 'left' || textPosition === 'right') {
// Left/Right options are treated as vertical placement for simplicity on canvas
effectivePosition = (textPositionSelect.selectedIndex === 1) ? 'top' : 'bottom';
}
if (effectivePosition === 'bottom') {
// Draw below the code area, centered in the reserved bottom space
const textAreaY = codeAreaEnd;
textY = textAreaY + CODE_PADDING + (TEXT_AREA_HEIGHT / 2);
} else if (effectivePosition === 'top') {
// Draw above the code area, centered in the reserved top space
const textAreaY = 0;
textY = textAreaY + CODE_PADDING + (TEXT_AREA_HEIGHT / 2);
}
// Draw the text, constraining its width
ctx.fillText(customText, centerX, textY, finalWidth - CODE_PADDING * 2);
}
/**
* Main function to trigger generation and final canvas assembly.
*/
function generateCode() {
const data = codeDataInput.value.trim();
const type = codeTypeSelect.value;
const codeColor = codeColorInput.value;
const bgColor = bgColorInput.value;
const enableWording = enableWordingCheck.checked;
const position = textPositionSelect.value;
// 1. Validate Data
if (!data) {
showMessage("Please enter data to encode.");
outputCanvas.width = 1;
outputCanvas.height = 1;
return;
}
clearMessage();
// 2. Generate Code (Intermediate Canvas)
let codeResult = null;
if (type === 'QR') {
codeResult = generateQRCode(data, codeColor, bgColor);
} else if (type === 'CODE128') {
codeResult = generateBarcode(data, 'CODE128', codeColor, bgColor);
} else if (type === 'CODE39') {
if (!/^[A-Z0-9\-\.\$\/\+\%\s]+$/.test(data)) {
showMessage("Code 39 only supports uppercase letters (A-Z), numbers (0-9), and symbols (-.$/+% space).");
outputCanvas.width = 1;
outputCanvas.height = 1;
return;
}
codeResult = generateBarcode(data, 'CODE39', codeColor, bgColor);
}
if (!codeResult) return; // Stop if code generation failed
const codeCanvas = codeResult.canvas;
const codeWidth = codeResult.width;
const codeHeight = codeResult.height;
// 3. Calculate Final Canvas Size and Offsets
// Calculate space needed for text (if enabled)
const textSpaceHeight = enableWording ? (TEXT_AREA_HEIGHT + CODE_PADDING * 2) : 0;
// Final dimensions
const finalWidth = codeWidth + CODE_PADDING * 2;
const finalHeight = codeHeight + CODE_PADDING * 2 + textSpaceHeight;
// Calculate where the code will be drawn on the final canvas
const codeXOffset = CODE_PADDING;
let codeYOffset = CODE_PADDING; // Default top padding
if (enableWording && position === 'top') {
// If text is on top, shift the code down by the text space
codeYOffset = CODE_PADDING + textSpaceHeight;
} else if (enableWording && (position === 'left' || position === 'right')) {
// For Left/Right, we still use vertical space, defaulting to bottom offset unless 'top' is implicitly selected
if(textPositionSelect.selectedIndex === 1) { // 'top' is index 1
codeYOffset = CODE_PADDING + textSpaceHeight;
}
}
// 4. Assemble Final Canvas
outputCanvas.width = finalWidth;
outputCanvas.height = finalHeight;
const ctx = outputCanvas.getContext('2d');
// 4a. Draw Background
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, finalWidth, finalHeight);
// 4b. Draw Code (Intermediate Canvas)
ctx.drawImage(codeCanvas, codeXOffset, codeYOffset);
// 4c. Draw Text
if (enableWording) {
const codeAreaStart = codeYOffset;
const codeAreaEnd = codeYOffset + codeHeight;
drawCustomText(ctx, finalWidth, finalHeight, codeColor, position, codeAreaStart, codeAreaEnd);
}
// Set canvas background style for consistency
outputCanvas.style.backgroundColor = bgColor;
}
/**
* Handles the main panel layout switching (Horizontal/Vertical).
*/
function updateLayout() {
const layout = layoutSelect.value;
if (layout === 'horizontal') {
contentArea.classList.add('md:content-container-horizontal');
contentArea.classList.remove('flex-col');
} else {
contentArea.classList.remove('md:content-container-horizontal');
contentArea.classList.add('flex-col');
}
}
// --- Download Functions (NEW) ---
/**
* Converts canvas data to Blob and triggers a download.
* @param {string} mimeType The MIME type ('image/png', 'image/jpeg').
* @param {number} [quality] JPEG quality (0 to 1).
* @param {string} fileName The base name for the downloaded file.
*/
function downloadCanvasAsImage(mimeType, quality, fileName) {
// Check if the canvas is empty (e.g., failed generation)
if (outputCanvas.width <= 1 || outputCanvas.height <= 1) {
showMessage("Cannot download: Code generation failed or data is invalid.");
return;
}
const dataURL = outputCanvas.toDataURL(mimeType, quality);
const link = document.createElement('a');
link.href = dataURL;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function downloadPNG() {
const data = codeDataInput.value.trim() || 'barcode';
downloadCanvasAsImage('image/png', 1.0, `${data}.png`);
}
function downloadJPEG() {
const data = codeDataInput.value.trim() || 'barcode';
// Use 0.9 quality for a good balance of size and fidelity
downloadCanvasAsImage('image/jpeg', 0.9, `${data}.jpeg`);
}
function downloadPDF() {
const data = codeDataInput.value.trim() || 'barcode';
// Check for library loading
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
showMessage("PDF library is still loading. Please wait a moment and try again.");
return;
}
// Check if the canvas is empty
if (outputCanvas.width <= 1 || outputCanvas.height <= 1) {
showMessage("Cannot download: Code generation failed or data is invalid.");
return;
}
const { jsPDF } = window.jspdf;
// Get image data from canvas
const imgData = outputCanvas.toDataURL('image/png', 1.0);
// Determine dimensions and orientation for the PDF
const canvasWidth = outputCanvas.width;
const canvasHeight = outputCanvas.height;
const orientation = canvasWidth > canvasHeight ? 'l' : 'p'; // 'l' for landscape, 'p' for portrait
// Create PDF instance, setting the size to fit the canvas with a small margin (e.g., 40pt total padding)
const pdf = new jsPDF({
orientation: orientation,
unit: 'pt',
format: [canvasWidth + 40, canvasHeight + 40]
});
// Calculate centered position
const x = 20; // 20pt margin
const y = 20;
const width = canvasWidth;
const height = canvasHeight;
// Add the image to the PDF
pdf.addImage(imgData, 'PNG', x, y, width, height);
// Save the PDF
pdf.save(`${data}.pdf`);
}
// --- Event Listeners and Initialization ---
// Debounce function to limit rapid calls
let debounceTimer;
const debounceGenerate = () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(generateCode, 300);
};
// Inputs that trigger code generation/redrawing
codeDataInput.addEventListener('input', debounceGenerate);
codeTypeSelect.addEventListener('change', debounceGenerate);
codeColorInput.addEventListener('input', debounceGenerate);
bgColorInput.addEventListener('input', debounceGenerate);
customWordingInput.addEventListener('input', debounceGenerate);
textPositionSelect.addEventListener('change', debounceGenerate);
fontFamilySelect.addEventListener('change', debounceGenerate);
fontWeightSelect.addEventListener('change', debounceGenerate);
enableWordingCheck.addEventListener('change', generateCode); // Immediate change for quick toggle
// Layout change
layoutSelect.addEventListener('change', updateLayout);
// Download Listeners (NEW)
downloadPngBtn.addEventListener('click', downloadPNG);
downloadJpegBtn.addEventListener('click', downloadJPEG);
downloadPdfBtn.addEventListener('click', downloadPDF);
// Initial setup
window.onload = function() {
// Set initial layout and generate code
updateLayout();
generateCode();
};
</script>
</body>
</html>