File size: 19,368 Bytes
77933d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Quantum QR Studio - QR Code Generator & Scanner</title>

    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>

    <!-- Font Awesome CDN -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">

    <!-- Google Fonts (Poppins & Fira Code) -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Fira+Code&display=swap" rel="stylesheet">

    <!-- QR Code Styling Library -->
    <script src="https://unpkg.com/qr-code-styling@1.6.0/lib/qr-code-styling.js"></script>
    <!-- ZXing JS Scanner Library -->
    <script src="https://unpkg.com/@zxing/library@latest/umd/index.min.js"></script>

    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #0f172a; /* bg-slate-900 */
        }
        .mono { font-family: 'Fira Code', monospace; }

        ::-webkit-scrollbar { width: 8px; }
        ::-webkit-scrollbar-track { background: #1e293b; }
        ::-webkit-scrollbar-thumb { background: #475569; border-radius: 10px; }
        ::-webkit-scrollbar-thumb:hover { background: #64748b; }
        
        .tab-btn.active {
            background-color: #0ea5e9; /* bg-sky-500 */
            color: white;
        }
        .fade-in { animation: fadeIn 0.5s ease-in-out; }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="text-slate-200">

    <div class="container mx-auto p-4 md:p-8 max-w-7xl">
        <header class="text-center mb-8">
            <h1 class="text-4xl md:text-5xl font-bold text-white">Quantum <span class="text-sky-400">QR</span> Studio</h1>
            <p class="text-slate-400 mt-2">The ultimate client-side toolkit for QR Codes.</p>
        </header>

        <!-- Tabs Navigation -->
        <div class="mb-6 bg-slate-800 p-2 rounded-xl flex justify-center gap-2 max-w-sm mx-auto">
            <button class="tab-btn w-full py-2 px-4 rounded-lg font-semibold transition active" data-tab="generator">
                <i class="fas fa-qrcode mr-2"></i>Generator
            </button>
            <button class="tab-btn w-full py-2 px-4 rounded-lg font-semibold transition" data-tab="scanner">
                <i class="fas fa-camera mr-2"></i>Scanner
            </button>
        </div>

        <main>
            <!-- Generator Tab -->
            <div id="generator-tab" class="tab-content fade-in">
                <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
                    <!-- Left Side: Controls -->
                    <div class="lg:col-span-2 bg-slate-800/70 p-6 rounded-2xl">
                        <!-- QR Type Selector -->
                        <div class="mb-4">
                            <label for="qr-type" class="block text-sm font-bold mb-2 text-sky-400">QR CODE TYPE</label>
                            <select id="qr-type" class="w-full p-3 bg-slate-700 rounded-lg border-2 border-slate-600 focus:border-sky-500 focus:outline-none">
                                <option value="url">URL</option>
                                <option value="text">Text</option>
                                <option value="wifi">Wi-Fi Network</option>
                                <option value="vcard">vCard (Contact)</option>
                                <option value="sms">SMS</option>
                                <option value="phone">Phone Number</option>
                                <option value="email">Email</option>
                                <option value="upi">UPI Payment</option>
                            </select>
                        </div>
                        
                        <div id="form-container" class="space-y-4"></div>

                        <details class="mt-6 bg-slate-900/50 rounded-lg">
                            <summary class="p-3 cursor-pointer font-semibold text-white">Advanced Customization</summary>
                            <div class="p-4 border-t border-slate-700 grid sm:grid-cols-2 gap-4">
                                <!-- Manual Color Pickers -->
                                <input type="color" id="dot-color" value="#000000" title="Dot Color" class="w-full h-10 p-1 bg-slate-700 rounded-lg">
                                <input type="color" id="bg-color" value="#ffffff" title="Background Color" class="w-full h-10 p-1 bg-slate-700 rounded-lg">
                                
                                <!-- Error Correction -->
                                <select id="error-correction" class="w-full p-2 bg-slate-700 rounded-lg border-2 border-slate-600">
                                    <option value="L">Error Correction: Low</option>
                                    <option value="M" selected>Error Correction: Medium</option>
                                    <option value="Q">Error Correction: Quartile</option>
                                    <option value="H">Error Correction: High</option>
                                </select>
                                
                                <!-- Logo Upload -->
                                <div class="relative">
                                    <input type="file" id="logo-upload" accept="image/png, image/jpeg" class="hidden">
                                    <button onclick="document.getElementById('logo-upload').click()" class="w-full p-2 bg-slate-700 rounded-lg">Upload Logo</button>
                                </div>

                                <!-- ADDED: Randomize Colors Button -->
                                <button id="random-color-btn" class="sm:col-span-2 w-full bg-gradient-to-r from-purple-500 to-pink-500 text-white font-bold py-2 px-4 rounded-lg transition-transform hover:scale-105">
                                    <i class="fas fa-palette mr-2"></i>Randomize Colors
                                </button>
                            </div>
                        </details>
                    </div>

                    <!-- Right Side: QR Preview -->
                    <div class="bg-slate-800/70 p-6 rounded-2xl flex flex-col items-center justify-center">
                        <div id="qr-code-container" class="bg-slate-700 p-4 rounded-lg mb-4">
                             <div id="qr-code"></div>
                        </div>
                        <p class="text-slate-400 text-sm mb-4">QR code updates in real-time</p>
                        <div class="w-full space-y-3">
                            <!-- CHANGED: Only JPG download is available now -->
                            <button id="download-jpg" class="w-full bg-sky-500 hover:bg-sky-600 text-white font-bold py-3 rounded-lg text-lg">
                                <i class="fas fa-download mr-2"></i>Download JPG
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Scanner Tab -->
            <div id="scanner-tab" class="tab-content hidden fade-in">
                 <div class="max-w-2xl mx-auto bg-slate-800/70 p-6 rounded-2xl text-center">
                    <video id="scanner-video" class="w-full rounded-lg mb-4 hidden aspect-video"></video>
                    <div id="permission-prompt" class="mb-4">
                        <p class="mb-4">Allow camera access to start scanning.</p>
                        <button id="start-scan-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg"><i class="fas fa-video mr-2"></i>Use Camera</button>
                    </div>
                    <p class="text-slate-400 my-4">OR</p>
                    <input type="file" id="scan-file-upload" class="hidden" accept="image/*">
                    <button onclick="document.getElementById('scan-file-upload').click()" class="bg-slate-700 hover:bg-slate-600 text-white font-bold py-2 px-4 rounded-lg"><i class="fas fa-upload mr-2"></i>Upload Image</button>
                    <div id="scan-result" class="mt-6 text-left bg-slate-900 p-4 rounded-lg hidden break-words"></div>
                 </div>
            </div>
        </main>
    </div>

    <!-- JavaScript Logic -->
    <script>
    document.addEventListener('DOMContentLoaded', () => {
        const qrCodeEl = document.getElementById('qr-code');
        const qrTypeSelect = document.getElementById('qr-type');
        const formContainer = document.getElementById('form-container');

        const qrCode = new QRCodeStyling({
            width: 250,
            height: 250,
            data: 'https://github.com/AmitK-1234',
            image: '',
            dotsOptions: { color: '#000000', type: 'rounded' },
            backgroundOptions: { color: '#ffffff' },
            imageOptions: { crossOrigin: 'anonymous', margin: 5 },
            cornersSquareOptions: { type: 'extra-rounded' },
            cornersDotOptions: { type: 'dot' },
            qrOptions: { errorCorrectionLevel: 'M' }
        });
        qrCode.append(qrCodeEl);

        const tabButtons = document.querySelectorAll('.tab-btn');
        const tabContents = document.querySelectorAll('.tab-content');
        let activeStream = null;

        tabButtons.forEach(button => {
            button.addEventListener('click', () => {
                tabButtons.forEach(btn => btn.classList.remove('active'));
                button.classList.add('active');
                if (activeStream) stopScan();
                const tabId = button.dataset.tab;
                tabContents.forEach(content => {
                    content.id === `${tabId}-tab` ? content.classList.remove('hidden') : content.classList.add('hidden');
                });
            });
        });

        const forms = {
            url: `<input type="url" id="data" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="https://example.com">`,
            text: `<textarea id="data" class="qr-input w-full p-3 bg-slate-700 rounded-lg" rows="4" placeholder="Enter any text"></textarea>`,
            wifi: `<input type="text" id="wifi-ssid" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Network Name (SSID)"><input type="password" id="wifi-pass" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Password"><select id="wifi-enc" class="qr-input w-full p-3 bg-slate-700 rounded-lg"><option value="WPA">WPA/WPA2</option><option value="WEP">WEP</option><option value="nopass">No Password</option></select>`,
            vcard: `<input type="text" id="vcard-name" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Full Name"><input type="tel" id="vcard-tel" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Phone Number"><input type="email" id="vcard-email" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Email Address">`,
            sms: `<input type="tel" id="sms-tel" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Recipient Phone Number"><textarea id="sms-body" class="qr-input w-full p-3 bg-slate-700 rounded-lg" rows="3" placeholder="SMS Message"></textarea>`,
            phone: `<input type="tel" id="data" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="+1234567890">`,
            email: `<input type="email" id="email-addr" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Recipient Email"><input type="text" id="email-subj" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Subject">`,
            upi: `<input type="text" id="upi-id" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="yourname@bank"><input type="text" id="upi-name" class="qr-input w-full p-3 bg-slate-700 rounded-lg" placeholder="Payee Name">`
        };
        const renderForm = (type) => { formContainer.innerHTML = forms[type]; updateQRCode(); };
        const getQRData = () => {
            let data = ' ';
            try {
                const type = qrTypeSelect.value;
                switch(type) {
                    case 'url': case 'text': data = document.getElementById('data').value || ' '; break;
                    case 'phone': data = `tel:${document.getElementById('data').value || ''}`; break;
                    case 'wifi': data = `WIFI:T:${document.getElementById('wifi-enc').value};S:${document.getElementById('wifi-ssid').value};P:${document.getElementById('wifi-pass').value};;`; break;
                    case 'vcard': data = `BEGIN:VCARD\nVERSION:3.0\nN:${document.getElementById('vcard-name').value}\nTEL:${document.getElementById('vcard-tel').value}\nEMAIL:${document.getElementById('vcard-email').value}\nEND:VCARD`; break;
                    case 'sms': data = `SMSTO:${document.getElementById('sms-tel').value}:${document.getElementById('sms-body').value}`; break;
                    case 'email': data = `mailto:${document.getElementById('email-addr').value}?subject=${encodeURIComponent(document.getElementById('email-subj').value)}`; break;
                    case 'upi': data = `upi://pay?pa=${document.getElementById('upi-id').value}&pn=${encodeURIComponent(document.getElementById('upi-name').value)}&cu=INR`; break;
                }
            } catch (e) {}
            return data;
        };
        const updateQRCode = () => qrCode.update({ data: getQRData() });
        qrTypeSelect.addEventListener('change', () => renderForm(qrTypeSelect.value));
        formContainer.addEventListener('input', updateQRCode);
        
        const dotColorPicker = document.getElementById('dot-color');
        const bgColorPicker = document.getElementById('bg-color');
        dotColorPicker.addEventListener('input', (e) => qrCode.update({ dotsOptions: { color: e.target.value } }));
        bgColorPicker.addEventListener('input', (e) => qrCode.update({ backgroundOptions: { color: e.target.value } }));
        document.getElementById('error-correction').addEventListener('change', (e) => qrCode.update({ qrOptions: { errorCorrectionLevel: e.target.value } }));
        document.getElementById('logo-upload').addEventListener('change', (e) => {
            const file = e.target.files[0];
            if (file) qrCode.update({ image: URL.createObjectURL(file) });
        });
        document.getElementById('download-jpg').addEventListener('click', () => qrCode.download({ name: 'quantum-qr', extension: 'jpeg' }));

        // ADDED: Random Color Palettes and Logic
        const colorPalettes = [
            { dots: '#4a044e', background: '#fbeaff', cornersSquare: '#210023', cornersDot: '#701a75' },
            { dots: '#006d77', background: '#edf6f9', cornersSquare: '#013a40', cornersDot: '#83c5be' },
            { dots: '#d90429', background: '#ffffff', cornersSquare: '#2b2d42', cornersDot: '#ef233c' },
            { dots: '#1d3557', background: '#f1faee', cornersSquare: '#1d3557', cornersDot: '#457b9d' },
            { dots: '#6a040f', background: '#fff3b0', cornersSquare: '#370617', cornersDot: '#9d0208' },
            { dots: '#3a5a40', background: '#ffffff', cornersSquare: '#1a2a1f', cornersDot: '#588157' },
        ];
        document.getElementById('random-color-btn').addEventListener('click', () => {
            const palette = colorPalettes[Math.floor(Math.random() * colorPalettes.length)];
            dotColorPicker.value = palette.dots;
            bgColorPicker.value = palette.background;
            qrCode.update({
                dotsOptions: { color: palette.dots },
                backgroundOptions: { color: palette.background },
                cornersSquareOptions: { color: palette.cornersSquare },
                cornersDotOptions: { color: palette.cornersDot }
            });
        });

        // --- QR Code Scanner Logic ---
        const videoEl = document.getElementById('scanner-video');
        const startScanBtn = document.getElementById('start-scan-btn');
        const scanResultEl = document.getElementById('scan-result');
        const permissionPromptEl = document.getElementById('permission-prompt');
        const codeReader = new ZXing.BrowserMultiFormatReader();
        const startScan = async () => {
            try {
                const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } });
                activeStream = stream;
                videoEl.srcObject = stream;
                videoEl.classList.remove('hidden');
                permissionPromptEl.classList.add('hidden');
                scanResultEl.classList.add('hidden');
                codeReader.decodeFromStream(stream, videoEl, (result, err) => {
                    if (result) {
                        displayScanResult(result.getText());
                        stopScan();
                    }
                });
            } catch (err) {
                alert('Could not access camera. Please check permissions.');
            }
        };
        const stopScan = () => {
            if (activeStream) {
                activeStream.getTracks().forEach(track => track.stop());
                activeStream = null;
            }
            codeReader.reset();
            videoEl.classList.add('hidden');
            permissionPromptEl.classList.remove('hidden');
        };
        document.getElementById('scan-file-upload').addEventListener('change', (e) => {
            const file = e.target.files[0];
            if (!file) return;
            const reader = new FileReader();
            reader.onload = (event) => {
                const img = new Image();
                img.onload = () => {
                    codeReader.decodeFromImageElement(img)
                        .then(result => displayScanResult(result.getText()))
                        .catch(err => {
                            alert('Could not decode QR code from the uploaded image. Please try a clearer, standard QR code.');
                        });
                };
                img.src = event.target.result;
            };
            reader.readAsDataURL(file);
        });
        const displayScanResult = (text) => {
            let content = '';
            if (text.startsWith('http')) {
                content = `<strong>URL:</strong> <a href="${text}" target="_blank" class="text-sky-400 hover:underline">${text}</a>`;
            } else if (text.startsWith('WIFI:')) {
                content = `<strong>Wi-Fi Network:</strong><br><span class="mono">${text}</span>`;
            } else if (text.startsWith('mailto:')) {
                content = `<strong>Email:</strong> <a href="${text}" class="text-sky-400 hover:underline">${text.substring(7)}</a>`;
            } else {
                content = `<strong>Text:</strong><br><p class="mono">${text}</p>`;
            }
            scanResultEl.innerHTML = content;
            scanResultEl.classList.remove('hidden');
        };
        startScanBtn.addEventListener('click', startScan);
        
        renderForm('url');
    });
    </script>
</body>
</html>