blob: 92da292e484be616fbaaa1eaebb3f124b061439b [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 }
29
30 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 }
39
40 button:hover {
41 background-color: #3367d6;
42 }
43
44 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>
63
64 <script>
65 document.addEventListener('DOMContentLoaded', () => {
66 const diffEditor = document.getElementById('diffEditor');
67
68 // Set initial example
69 diffEditor.originalCode = `function hello() {
70 console.log("Hello World");
71 return true;
72}`;
73
74 diffEditor.modifiedCode = `function hello() {
75 // Add a comment
76 console.log("Hello Updated World");
77 return true;
78}`;
79
80 // Example 1: JavaScript
81 document.getElementById('example1').addEventListener('click', () => {
82 diffEditor.setOriginalCode(
83 `function calculateTotal(items) {
84 return items
85 .map(item => item.price * item.quantity)
86 .reduce((a, b) => a + b, 0);
87}`,
88 'original.js'
89 );
90
91 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}`,
103 'modified.js'
104 );
105 });
106
107 // Example 2: HTML
108 document.getElementById('example2').addEventListener('click', () => {
109 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>`,
120 'original.html'
121 );
122
123 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>`,
143 'modified.html'
144 );
145 });
146
147 // Example 3: Go
148 document.getElementById('example3').addEventListener('click', () => {
149 diffEditor.setOriginalCode(
150 `package main
151
152import "fmt"
153
154func main() {
155 fmt.Println("Hello, world!")
156}`,
157 'original.go'
158 );
159
160 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}`,
172 'modified.go'
173 );
174 });
175 });
176 </script>
177 </body>
178</html>