srivatsavdamaraju commited on
Commit
4099235
·
verified ·
1 Parent(s): a48c305

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +295 -2
index.html CHANGED
@@ -2,7 +2,7 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>ACCUSAGA AI BASED HTML AI EDITOR</title>
6
  <style>
7
  * {
8
  box-sizing: border-box;
@@ -600,11 +600,89 @@
600
  position: relative;
601
  display: inline-block;
602
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  </style>
604
  </head>
605
  <body>
606
  <div class="container" id="mainContainer">
607
- <h1>🎨 HTML Editor</h1>
608
 
609
  <div class="toolbar">
610
  <button class="btn live-preview" onclick="toggleLivePreview()">
@@ -614,6 +692,7 @@
614
  <button class="btn secondary" onclick="clearEditor()">🗑️ Clear</button>
615
  <button class="btn secondary" onclick="copyRenderedHTML()">📋 Copy HTML</button>
616
  <button class="btn secondary" onclick="exportHTML()">💾 Export</button>
 
617
 
618
  <div class="history-dropdown">
619
  <button class="btn undo-btn" id="undoBtn" onclick="undoChange()" disabled>
@@ -698,6 +777,52 @@
698
  <button class="btn danger" onclick="deleteSelected()">Delete Selected</button>
699
  </div>
700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
  <script>
702
  let livePreviewEnabled = false;
703
  let editingElement = null;
@@ -706,12 +831,14 @@
706
  let isEditorCollapsed = false;
707
  let history = [];
708
  let historyIndex = -1;
 
709
 
710
  // Initialize with default content
711
  window.onload = function() {
712
  loadHTML();
713
  updateWordCount();
714
  saveToHistory();
 
715
  };
716
 
717
  function makeElementsEditable(container) {
@@ -859,6 +986,7 @@
859
  makeElementsEditable(renderedArea);
860
 
861
  showSaveIndicator();
 
862
  }
863
 
864
  function toggleLivePreview() {
@@ -893,6 +1021,7 @@
893
  updateElementCount(0);
894
  clearSelection();
895
  saveToHistory();
 
896
  }
897
  }
898
 
@@ -989,6 +1118,7 @@ ${htmlContent}
989
  loadHTML();
990
  updateWordCount();
991
  saveToHistory();
 
992
  }
993
 
994
  function updateWordCount() {
@@ -1217,10 +1347,170 @@ What specific aspect would you like to focus on?`;
1217
  }
1218
  }
1219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1220
  // Update word count as user types
1221
  document.getElementById('htmlInput').addEventListener('input', updateWordCount);
1222
  document.getElementById('htmlInput').addEventListener('input', () => {
1223
  saveToHistory();
 
1224
  });
1225
 
1226
  // Handle clicks outside of editable elements
@@ -1270,6 +1560,9 @@ What specific aspect would you like to focus on?`;
1270
  e.stopPropagation();
1271
  }
1272
  });
 
 
 
1273
  </script>
1274
  </body>
1275
  </html>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <title>Enhanced Magic Text HTML Editor</title>
6
  <style>
7
  * {
8
  box-sizing: border-box;
 
600
  position: relative;
601
  display: inline-block;
602
  }
603
+
604
+ /* PDF Export Styles */
605
+ .pdf-export-btn {
606
+ background: linear-gradient(135deg, #e53e3e, #c53030);
607
+ }
608
+
609
+ .pdf-export-btn:hover {
610
+ box-shadow: 0 5px 15px rgba(229, 62, 62, 0.4);
611
+ }
612
+
613
+ .pdf-modal {
614
+ display: none;
615
+ position: fixed;
616
+ top: 0;
617
+ left: 0;
618
+ width: 100%;
619
+ height: 100%;
620
+ background: rgba(0, 0, 0, 0.5);
621
+ z-index: 2000;
622
+ justify-content: center;
623
+ align-items: center;
624
+ }
625
+
626
+ .pdf-modal.active {
627
+ display: flex;
628
+ animation: fadeIn 0.3s ease;
629
+ }
630
+
631
+ .pdf-modal-content {
632
+ background: white;
633
+ padding: 30px;
634
+ border-radius: 15px;
635
+ max-width: 500px;
636
+ width: 90%;
637
+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
638
+ }
639
+
640
+ .pdf-options {
641
+ display: flex;
642
+ flex-direction: column;
643
+ gap: 15px;
644
+ margin: 20px 0;
645
+ }
646
+
647
+ .pdf-option {
648
+ display: flex;
649
+ align-items: center;
650
+ gap: 10px;
651
+ padding: 10px;
652
+ border: 2px solid #e2e8f0;
653
+ border-radius: 10px;
654
+ cursor: pointer;
655
+ transition: all 0.3s ease;
656
+ }
657
+
658
+ .pdf-option:hover {
659
+ border-color: #667eea;
660
+ background: #f7fafc;
661
+ }
662
+
663
+ .pdf-option.selected {
664
+ border-color: #667eea;
665
+ background: rgba(102, 126, 234, 0.05);
666
+ }
667
+
668
+ .pdf-option input {
669
+ display: none;
670
+ }
671
+
672
+ .pdf-preview {
673
+ max-height: 200px;
674
+ overflow-y: auto;
675
+ border: 1px solid #e2e8f0;
676
+ border-radius: 8px;
677
+ padding: 15px;
678
+ margin: 15px 0;
679
+ background: #f8f9fa;
680
+ }
681
  </style>
682
  </head>
683
  <body>
684
  <div class="container" id="mainContainer">
685
+ <h1>🎨 Enhanced Magic HTML Editor</h1>
686
 
687
  <div class="toolbar">
688
  <button class="btn live-preview" onclick="toggleLivePreview()">
 
692
  <button class="btn secondary" onclick="clearEditor()">🗑️ Clear</button>
693
  <button class="btn secondary" onclick="copyRenderedHTML()">📋 Copy HTML</button>
694
  <button class="btn secondary" onclick="exportHTML()">💾 Export</button>
695
+ <button class="btn pdf-export-btn" onclick="showPDFOptions()">📄 Save as PDF</button>
696
 
697
  <div class="history-dropdown">
698
  <button class="btn undo-btn" id="undoBtn" onclick="undoChange()" disabled>
 
777
  <button class="btn danger" onclick="deleteSelected()">Delete Selected</button>
778
  </div>
779
 
780
+ <!-- PDF Export Modal -->
781
+ <div class="pdf-modal" id="pdfModal">
782
+ <div class="pdf-modal-content">
783
+ <h2 style="margin-top: 0; color: #4a5568;">Export as PDF</h2>
784
+ <p>Choose your preferred export format:</p>
785
+
786
+ <div class="pdf-options">
787
+ <div class="pdf-option" onclick="selectPDFOption('text')">
788
+ <input type="radio" name="pdf-option" id="text-option" value="text" checked>
789
+ <div style="flex: 1;">
790
+ <strong>Text Format</strong>
791
+ <p style="margin: 5px 0 0; font-size: 14px; color: #718096;">
792
+ Best for text content, smaller file size
793
+ </p>
794
+ </div>
795
+ </div>
796
+
797
+ <div class="pdf-option" onclick="selectPDFOption('visual')">
798
+ <input type="radio" name="pdf-option" id="visual-option" value="visual">
799
+ <div style="flex: 1;">
800
+ <strong>Visual Format</strong>
801
+ <p style="margin: 5px 0 0; font-size: 14px; color: #718096;">
802
+ Exact visual representation, larger file size
803
+ </p>
804
+ </div>
805
+ </div>
806
+ </div>
807
+
808
+ <div class="pdf-preview" id="pdfPreview">
809
+ <strong>Preview:</strong>
810
+ <div id="pdfPreviewContent" style="margin-top: 10px; font-size: 14px;">
811
+ <!-- Preview content will be added here -->
812
+ </div>
813
+ </div>
814
+
815
+ <div style="display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;">
816
+ <button class="btn secondary" onclick="closePDFModal()">Cancel</button>
817
+ <button class="btn pdf-export-btn" onclick="generatePDF()">Generate PDF</button>
818
+ </div>
819
+ </div>
820
+ </div>
821
+
822
+ <!-- External Libraries -->
823
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
824
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
825
+
826
  <script>
827
  let livePreviewEnabled = false;
828
  let editingElement = null;
 
831
  let isEditorCollapsed = false;
832
  let history = [];
833
  let historyIndex = -1;
834
+ let selectedPDFOption = 'text';
835
 
836
  // Initialize with default content
837
  window.onload = function() {
838
  loadHTML();
839
  updateWordCount();
840
  saveToHistory();
841
+ updatePDFPreview();
842
  };
843
 
844
  function makeElementsEditable(container) {
 
986
  makeElementsEditable(renderedArea);
987
 
988
  showSaveIndicator();
989
+ updatePDFPreview();
990
  }
991
 
992
  function toggleLivePreview() {
 
1021
  updateElementCount(0);
1022
  clearSelection();
1023
  saveToHistory();
1024
+ updatePDFPreview();
1025
  }
1026
  }
1027
 
 
1118
  loadHTML();
1119
  updateWordCount();
1120
  saveToHistory();
1121
+ updatePDFPreview();
1122
  }
1123
 
1124
  function updateWordCount() {
 
1347
  }
1348
  }
1349
 
1350
+ // PDF Export Functions
1351
+ function showPDFOptions() {
1352
+ document.getElementById('pdfModal').classList.add('active');
1353
+ updatePDFPreview();
1354
+ }
1355
+
1356
+ function closePDFModal() {
1357
+ document.getElementById('pdfModal').classList.remove('active');
1358
+ }
1359
+
1360
+ function selectPDFOption(option) {
1361
+ selectedPDFOption = option;
1362
+
1363
+ // Update UI
1364
+ document.querySelectorAll('.pdf-option').forEach(el => {
1365
+ el.classList.remove('selected');
1366
+ });
1367
+
1368
+ if (option === 'text') {
1369
+ document.getElementById('text-option').parentElement.classList.add('selected');
1370
+ } else {
1371
+ document.getElementById('visual-option').parentElement.classList.add('selected');
1372
+ }
1373
+
1374
+ updatePDFPreview();
1375
+ }
1376
+
1377
+ function updatePDFPreview() {
1378
+ const previewContent = document.getElementById('pdfPreviewContent');
1379
+ const renderedArea = document.getElementById('renderedArea');
1380
+
1381
+ if (selectedPDFOption === 'text') {
1382
+ const textContent = renderedArea.textContent || renderedArea.innerText || '';
1383
+ const preview = textContent.substring(0, 150) + (textContent.length > 150 ? '...' : '');
1384
+ previewContent.innerHTML = `<div style="white-space: pre-wrap; font-family: monospace;">${preview}</div>`;
1385
+ } else {
1386
+ previewContent.innerHTML = '<div style="color: #718096; font-style: italic;">Visual preview not available. PDF will contain exact visual representation of your content.</div>';
1387
+ }
1388
+ }
1389
+
1390
+ function generatePDF() {
1391
+ closePDFModal();
1392
+
1393
+ if (selectedPDFOption === 'text') {
1394
+ saveAsPDF();
1395
+ } else {
1396
+ saveAsPDFWithScreenshot();
1397
+ }
1398
+ }
1399
+
1400
+ function saveAsPDF() {
1401
+ const { jsPDF } = window.jspdf;
1402
+ const renderedArea = document.getElementById('renderedArea');
1403
+
1404
+ // Create a new PDF instance
1405
+ const doc = new jsPDF();
1406
+
1407
+ // Get the HTML content
1408
+ const content = renderedArea.innerHTML;
1409
+
1410
+ // Add title
1411
+ doc.setFontSize(20);
1412
+ doc.text('HTML Export', 105, 15, { align: 'center' });
1413
+
1414
+ // Add current date
1415
+ const now = new Date();
1416
+ doc.setFontSize(10);
1417
+ doc.text(`Generated on: ${now.toLocaleDateString()} ${now.toLocaleTimeString()}`, 105, 22, { align: 'center' });
1418
+
1419
+ // Add separator line
1420
+ doc.setDrawColor(200, 200, 200);
1421
+ doc.line(10, 25, 200, 25);
1422
+
1423
+ // Convert HTML to PDF
1424
+ doc.setFontSize(12);
1425
+
1426
+ // Create a temporary div to parse HTML content
1427
+ const tempDiv = document.createElement('div');
1428
+ tempDiv.innerHTML = content;
1429
+
1430
+ // Extract text content (simplified version)
1431
+ let textContent = tempDiv.textContent || tempDiv.innerText || '';
1432
+
1433
+ // Clean and format text
1434
+ textContent = textContent.replace(/\s+/g, ' ').trim();
1435
+
1436
+ // Split text into lines that fit PDF width
1437
+ const lines = doc.splitTextToSize(textContent, 180);
1438
+
1439
+ // Add content to PDF
1440
+ let yPosition = 35;
1441
+ const lineHeight = 7;
1442
+ const pageHeight = doc.internal.pageSize.height;
1443
+
1444
+ lines.forEach(line => {
1445
+ // Check if we need a new page
1446
+ if (yPosition > pageHeight - 20) {
1447
+ doc.addPage();
1448
+ yPosition = 20;
1449
+ }
1450
+
1451
+ doc.text(line, 15, yPosition);
1452
+ yPosition += lineHeight;
1453
+ });
1454
+
1455
+ // Add page numbers
1456
+ const pageCount = doc.internal.getNumberOfPages();
1457
+ for (let i = 1; i <= pageCount; i++) {
1458
+ doc.setPage(i);
1459
+ doc.setFontSize(8);
1460
+ doc.text(`Page ${i} of ${pageCount}`, 105, pageHeight - 10, { align: 'center' });
1461
+ }
1462
+
1463
+ // Save the PDF
1464
+ doc.save('html-export.pdf');
1465
+
1466
+ showTemporaryMessage('PDF saved successfully!');
1467
+ }
1468
+
1469
+ function saveAsPDFWithScreenshot() {
1470
+ const { jsPDF } = window.jspdf;
1471
+ const renderedArea = document.getElementById('renderedArea');
1472
+
1473
+ // Use html2canvas to capture the visual representation
1474
+ html2canvas(renderedArea, {
1475
+ scale: 2,
1476
+ useCORS: true,
1477
+ logging: false,
1478
+ width: renderedArea.scrollWidth,
1479
+ height: renderedArea.scrollHeight
1480
+ }).then(canvas => {
1481
+ const imgData = canvas.toDataURL('image/png');
1482
+ const pdf = new jsPDF('p', 'mm', 'a4');
1483
+ const imgWidth = 190;
1484
+ const pageHeight = 280;
1485
+ const imgHeight = (canvas.height * imgWidth) / canvas.width;
1486
+ let heightLeft = imgHeight;
1487
+ let position = 10;
1488
+
1489
+ pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
1490
+ heightLeft -= pageHeight;
1491
+
1492
+ // Add multiple pages if content is too long
1493
+ while (heightLeft >= 0) {
1494
+ position = heightLeft - imgHeight + 10;
1495
+ pdf.addPage();
1496
+ pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
1497
+ heightLeft -= pageHeight;
1498
+ }
1499
+
1500
+ pdf.save('html-screenshot.pdf');
1501
+ showTemporaryMessage('PDF saved successfully!');
1502
+ }).catch(error => {
1503
+ console.error('Error generating PDF:', error);
1504
+ showTemporaryMessage('Error generating PDF. Using text fallback.');
1505
+ saveAsPDF(); // Fallback to text version
1506
+ });
1507
+ }
1508
+
1509
  // Update word count as user types
1510
  document.getElementById('htmlInput').addEventListener('input', updateWordCount);
1511
  document.getElementById('htmlInput').addEventListener('input', () => {
1512
  saveToHistory();
1513
+ updatePDFPreview();
1514
  });
1515
 
1516
  // Handle clicks outside of editable elements
 
1560
  e.stopPropagation();
1561
  }
1562
  });
1563
+
1564
+ // Initialize PDF options
1565
+ selectPDFOption('text');
1566
  </script>
1567
  </body>
1568
  </html>