blob: f5e12d491afb7dd2685d0ff0abdcaa45b4f9775d [file] [log] [blame]
Philip Zeyliger272a90e2025-05-16 14:49:51 -07001<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>Sketch Monaco Viewer Demo</title>
7 <script type="module" src="../sketch-monaco-view.ts"></script>
8 <style>
9 body {
10 font-family:
11 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
12 Arial, sans-serif;
13 max-width: 1200px;
14 margin: 0 auto;
15 padding: 2rem;
16 }
17
18 h1 {
19 color: #333;
20 margin-bottom: 2rem;
21 }
22
23 .control-panel {
24 margin-bottom: 2rem;
25 padding: 1rem;
26 background-color: #f0f0f0;
27 border-radius: 4px;
28 }
Autoformatter8c463622025-05-16 21:54:17 +000029
Philip Zeyliger272a90e2025-05-16 14:49:51 -070030 button {
31 padding: 8px 12px;
32 background-color: #4285f4;
33 color: white;
34 border: none;
35 border-radius: 4px;
36 cursor: pointer;
37 margin-right: 8px;
38 }
Autoformatter8c463622025-05-16 21:54:17 +000039
Philip Zeyliger272a90e2025-05-16 14:49:51 -070040 button:hover {
41 background-color: #3367d6;
42 }
Autoformatter8c463622025-05-16 21:54:17 +000043
Philip Zeyliger272a90e2025-05-16 14:49:51 -070044 sketch-monaco-view {
45 margin-top: 20px;
46 height: 500px;
47 }
48 </style>
49 </head>
50 <body>
51 <h1>Sketch Monaco Viewer Demo</h1>
52
53 <div class="control-panel">
54 <p>This is a demo page for the sketch-monaco-view component.</p>
55 <div>
56 <button id="example1">Example 1: JavaScript</button>
57 <button id="example2">Example 2: HTML</button>
58 <button id="example3">Example 3: Go</button>
59 </div>
60 </div>
61
62 <sketch-monaco-view id="diffEditor"></sketch-monaco-view>
Autoformatter8c463622025-05-16 21:54:17 +000063
Philip Zeyliger272a90e2025-05-16 14:49:51 -070064 <script>
Autoformatter8c463622025-05-16 21:54:17 +000065 document.addEventListener("DOMContentLoaded", () => {
66 const diffEditor = document.getElementById("diffEditor");
67
Philip Zeyliger272a90e2025-05-16 14:49:51 -070068 // Set initial example
69 diffEditor.originalCode = `function hello() {
70 console.log("Hello World");
71 return true;
72}`;
Autoformatter8c463622025-05-16 21:54:17 +000073
Philip Zeyliger272a90e2025-05-16 14:49:51 -070074 diffEditor.modifiedCode = `function hello() {
75 // Add a comment
76 console.log("Hello Updated World");
77 return true;
78}`;
Autoformatter8c463622025-05-16 21:54:17 +000079
Philip Zeyliger272a90e2025-05-16 14:49:51 -070080 // Example 1: JavaScript
Autoformatter8c463622025-05-16 21:54:17 +000081 document.getElementById("example1").addEventListener("click", () => {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070082 diffEditor.setOriginalCode(
83 `function calculateTotal(items) {
84 return items
85 .map(item => item.price * item.quantity)
86 .reduce((a, b) => a + b, 0);
87}`,
Autoformatter8c463622025-05-16 21:54:17 +000088 "original.js",
Philip Zeyliger272a90e2025-05-16 14:49:51 -070089 );
Autoformatter8c463622025-05-16 21:54:17 +000090
Philip Zeyliger272a90e2025-05-16 14:49:51 -070091 diffEditor.setModifiedCode(
92 `function calculateTotal(items) {
93 // Apply discount if available
94 return items
95 .map(item => {
96 const price = item.discount ?
97 item.price * (1 - item.discount) :
98 item.price;
99 return price * item.quantity;
100 })
101 .reduce((a, b) => a + b, 0);
102}`,
Autoformatter8c463622025-05-16 21:54:17 +0000103 "modified.js",
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700104 );
105 });
Autoformatter8c463622025-05-16 21:54:17 +0000106
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700107 // Example 2: HTML
Autoformatter8c463622025-05-16 21:54:17 +0000108 document.getElementById("example2").addEventListener("click", () => {
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700109 diffEditor.setOriginalCode(
110 `<!DOCTYPE html>
111<html>
112<head>
113 <title>Demo Page</title>
114</head>
115<body>
116 <h1>Hello World</h1>
117 <p>This is a paragraph.</p>
118</body>
119</html>`,
Autoformatter8c463622025-05-16 21:54:17 +0000120 "original.html",
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700121 );
Autoformatter8c463622025-05-16 21:54:17 +0000122
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700123 diffEditor.setModifiedCode(
124 `<!DOCTYPE html>
125<html>
126<head>
127 <title>Demo Page</title>
128 <meta name="viewport" content="width=device-width, initial-scale=1.0">
129 <link rel="stylesheet" href="styles.css">
130</head>
131<body>
132 <header>
133 <h1>Hello World</h1>
134 </header>
135 <main>
136 <p>This is a paragraph with some <strong>bold</strong> text.</p>
137 </main>
138 <footer>
139 <p>&copy; 2025</p>
140 </footer>
141</body>
142</html>`,
Autoformatter8c463622025-05-16 21:54:17 +0000143 "modified.html",
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700144 );
145 });
Autoformatter8c463622025-05-16 21:54:17 +0000146
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700147 // Example 3: Go
Autoformatter8c463622025-05-16 21:54:17 +0000148 document.getElementById("example3").addEventListener("click", () => {
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700149 diffEditor.setOriginalCode(
150 `package main
151
152import "fmt"
153
154func main() {
155 fmt.Println("Hello, world!")
156}`,
Autoformatter8c463622025-05-16 21:54:17 +0000157 "original.go",
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700158 );
Autoformatter8c463622025-05-16 21:54:17 +0000159
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700160 diffEditor.setModifiedCode(
161 `package main
162
163import (
164 "fmt"
165 "time"
166)
167
168func main() {
169 fmt.Println("Hello, world!")
170 fmt.Printf("The time is %s\n", time.Now().Format(time.RFC3339))
171}`,
Autoformatter8c463622025-05-16 21:54:17 +0000172 "modified.go",
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700173 );
174 });
175 });
176 </script>
177 </body>
178</html>