-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.html
More file actions
594 lines (546 loc) · 21 KB
/
test.html
File metadata and controls
594 lines (546 loc) · 21 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Animated Code + Markdown Box</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- highlight.js CSS (light & dark, toggle with JS) -->
<link id="hljs-theme" rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css">
<style>
.info-panel {
border-radius: 7px;
padding: 1em 1.4em;
margin: 1.5em 0;
background: #eaf6ff;
color: #2a3d4d;
border-left: 5px solid #49a1ff;
font-size: 1em;
box-shadow: 0 2px 8px 0 rgba(34,60,80,0.04);
position: relative;
}
.info-panel .info-label {
font-weight: bold;
margin-right: .6em;
letter-spacing: 0.02em;
}
.info-panel.tip { background: #e8fff2; border-left-color: #20c997; color: #125e38; }
.info-panel.warning{ background: #fff8e1; border-left-color: #ffc107; color: #856404; }
.info-panel.important{ background: #fff1f0; border-left-color: #fa5252; color: #8c2f2f; }
.info-panel.info { background: #f1f6fb; border-left-color: #3387d6; color: #28517a; }
[data-theme="dark"] .info-panel {
background: #232a33;
color: #e2eaf3;
border-left-color: #3387d6;
box-shadow: 0 2px 16px 0 rgba(10,24,40,0.16);
}
[data-theme="dark"] .info-panel .info-label {
color: #a6d5fa;
}
[data-theme="dark"] .info-panel.note {
background: #232a33;
border-left-color: #3387d6;
color: #e2eaf3;
}
[data-theme="dark"] .info-panel.tip {
background: #15352a;
border-left-color: #33e6b6;
color: #b4f8e9;
}
[data-theme="dark"] .info-panel.warning {
background: #3b3422;
border-left-color: #ffd464;
color: #ffeab8;
}
[data-theme="dark"] .info-panel.important {
background: #382222;
border-left-color: #ff7a7a;
color: #ffd7d7;
}
[data-theme="dark"] .info-panel.info {
background: #222d39;
border-left-color: #49a1ff;
color: #b8d6fa;
}
:root {
--bg: #f8f9fa;
--fg: #212529;
--card-bg: #fff;
--shadow: 0 6px 32px 0 rgba(0, 0, 0, 0.08);
--code-fg: #3a3a3a;
--code-bg: transparent;
}
[data-theme="dark"] {
--bg: #181a20;
--fg: #eaeaea;
--card-bg: #23272f;
--shadow: 0 6px 32px 0 rgba(0, 0, 0, 0.25);
--code-fg: #cacaca;
--code-bg: transparent;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background: transparent;
color: var(--fg);
width: 100vw;
min-height: 100vh;
font-family: 'SF Pro', 'Segoe UI', Arial, sans-serif;
transition: background .3s, color .3s;
overflow-x: hidden;
}
.site-bg {
position: fixed;
z-index: -2;
inset: 0;
background: var(--bg);
transition: background .3s;
width: 100vw;
height: 100vh;
pointer-events: none;
}
body {
padding-bottom: 2em;
padding-left: 1em;
padding-right: 1em;
}
.bg-code {
position: fixed;
z-index: -1;
inset: 0;
pointer-events: none;
opacity: 0.8;
font-family: 'SF Mono', 'Fira Mono', 'Menlo', monospace;
font-size: 1.1rem;
line-height: 1.4;
color: var(--code-fg);
background: none;
user-select: none;
background: transparent !important;
}
.center-card {
z-index: 2;
background: var(--card-bg);
box-shadow: var(--shadow);
border-radius: 18px;
margin: 7em auto 3em auto;
width: 100%;
max-width: 900px;
min-height: 80vh;
display: flex;
flex-direction: column;
overflow: auto;
padding: 2em 2.5em 2em 2.5em;
box-sizing: border-box;
word-break: break-word;
overflow-wrap: break-word;
}
/* Removed unused .card-header and .card-content styles */
.markdown-main {
width: 100%;
min-width: 0;
max-width: 100%;
box-sizing: border-box;
flex: 1 1 auto;
margin: 0;
padding: 0;
height: auto;
word-break: break-word;
overflow-wrap: break-word;
}
.markdown-main > *:first-child {
margin-top: 1.5em;
}
.markdown-main > *:last-child {
margin-bottom: 1.5em;
}
.md-link,
.toggle-mode {
position: fixed;
top: 1.2em;
z-index: 9;
}
.md-link {
right: 2.5em;
font-size: 0.93em;
opacity: 0.75;
color: var(--fg);
text-decoration: underline;
}
.toggle-mode {
left: 2.5em;
background: none;
border: none;
font-size: 1.3em;
cursor: pointer;
color: var(--fg);
opacity: 0.7;
}
/* Mermaid container adjustment */
.mermaid {
background: none !important;
}
/* Center mermaid diagrams */
.markdown-main .mermaid {
display: flex;
justify-content: center;
align-items: center;
margin: 2em auto !important;
text-align: center;
}
/* Center images in markdown */
.markdown-main img {
display: block;
margin: 2em auto;
max-width: 100%;
text-align: center;
}
.bottom-spacer {
height: 4em;
width: 100%;
pointer-events: none;
}
</style>
</head>
<style>
@media (max-width: 700px) {
body {
padding-left: 0;
padding-right: 0;
}
.center-card {
width: auto;
max-width: 900px;
margin-left: 2.5em;
margin-right: 2.5em;
padding-left: 0.8em;
padding-right: 0.8em;
}
}
</style>
</head>
<body>
<div class="site-bg"></div>
<canvas class="bg-code"></canvas>
<a class="md-link" href="TEST.md" target="_blank">View Markdown</a>
<button class="toggle-mode" title="Toggle dark/light mode" id="toggle-mode">🌓</button>
<div class="center-card">
<div id="markdown-rendered" class="markdown-main">Loading...</div>
</div>
<div class="bottom-spacer"></div>
<!-- Marked.js for markdown parsing -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- highlight.js for syntax highlighting -->
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js"></script>
<!-- Mermaid.js for diagrams -->
<script src="https://cdn.jsdelivr.net/npm/mermaid@10.9.1/dist/mermaid.min.js"></script>
<script>
// Parameters
const codeLines = [
// Python / Django
{lang: "python", code: "def hello_world(request):"},
{lang: "python", code: " return JsonResponse({'message': 'Hello, world!'})"},
{lang: "python", code: "from django.urls import path"},
{lang: "python", code: "urlpatterns = ["},
{lang: "python", code: " path('hello/', hello_world),"},
{lang: "python", code: "]"},
{lang: "python", code: "class User(models.Model):"},
{lang: "python", code: " username = models.CharField(max_length=50)"},
// Go / Gin
{lang: "go", code: "r := gin.Default()"},
{lang: "go", code: "r.GET(\"/ping\", func(c *gin.Context) {"},
{lang: "go", code: " c.JSON(200, gin.H{\"message\": \"pong\"})"},
{lang: "go", code: "})"},
{lang: "go", code: "type User struct {"},
{lang: "go", code: " ID int `json:\"id\"`"},
{lang: "go", code: " Name string `json:\"name\"`"},
{lang: "go", code: "}"},
// C++
{lang: "cpp", code: "#include <bits/stdc++.h>"},
{lang: "cpp", code: "std::vector<int> nums = {1, 2, 3, 4};"},
{lang: "cpp", code: "for (int n : nums) {"},
{lang: "cpp", code: " cout << n << std::endl;"},
{lang: "cpp", code: "}"},
{lang: "cpp", code: "class User {"},
{lang: "cpp", code: "public:"},
{lang: "cpp", code: " std::string username;"},
{lang: "cpp", code: "};"},
// C#
{lang: "csharp", code: "public class UserController : Controller {"},
{lang: "csharp", code: " [HttpGet(\"/api/hello\")]"},
{lang: "csharp", code: " public IActionResult GetHello() => Ok(\"Hello, world!\");"},
{lang: "csharp", code: "}"},
{lang: "csharp", code: "var users = db.Users.Where(u => u.IsActive).ToList();"},
{lang: "csharp", code: "foreach(var user in users) {"},
{lang: "csharp", code: " Console.WriteLine(user.Username);"},
{lang: "csharp", code: "}"},
// Java / Spring Boot
{lang: "java", code: "@RestController"},
{lang: "java", code: "public class HelloController {"},
{lang: "java", code: " @GetMapping(\"/hello\")"},
{lang: "java", code: " public String hello() { return \"Hello, world!\"; }"},
{lang: "java", code: "}"},
{lang: "java", code: "List<User> users = userRepository.findAll();"},
{lang: "java", code: "users.stream().filter(User::isActive).forEach(System.out::println);"},
// Swift / SwiftUI
{lang: "swift", code: "struct ContentView: View {"},
{lang: "swift", code: " var body: some View {"},
{lang: "swift", code: " Text(\"Hello, world!\")"},
{lang: "swift", code: " .padding()"},
{lang: "swift", code: " }"},
{lang: "swift", code: "}"},
{lang: "swift", code: "let users = [\"alice\", \"bob\"]"},
{lang: "swift", code: "for user in users {"},
{lang: "swift", code: " print(user)"},
{lang: "swift", code: "}"},
// Bonus: JavaScript, Bash, keep a few short ones for variety
{lang: "javascript", code: "const foo = () => { return 42; };"},
{lang: "bash", code: "curl https://yazdanra.com/"},
{lang: "bash", code: "echo \"Welcome to the site!\""},
];
const typingSpeed = 22; // ms per char
const wipeDelay = 2200; // ms before wipe
const bgRows = 10; // visible code rows in bg
// Random x positions for bg code lines, mostly outside the center card
function getRandomXPositions(rows) {
let positions = [];
let w = window.innerWidth;
for (let i = 0; i < rows; i++) {
// Put most lines outside 15vw to 85vw (box area ~15vw-85vw), more on the sides
let leftOrRight = Math.random() < 0.5;
let x;
if (leftOrRight) {
x = Math.random() * (w * 0.15); // Left 0-15vw
} else {
x = w * 0.85 + Math.random() * (w * 0.15); // Right 85vw-100vw
}
positions.push(x);
}
return positions;
}
let bgXPositions = getRandomXPositions(bgRows);
let bgRowsState = [];
function initBgRows() {
bgRowsState = [];
for (let i = 0; i < bgRows; i++) {
bgRowsState.push({
codeIdx: Math.floor(Math.random() * codeLines.length),
charIdx: 0,
state: "typing", // or "pause" or "wiping"
nextTime: performance.now() + Math.random() * 900,
wipeDir: Math.random() < 0.5 ? "left" : "right",
wipeStart: 0,
wipeEnd: null,
});
}
}
initBgRows();
window.addEventListener('resize', () => {
resizeCanvas();
bgXPositions = getRandomXPositions(bgRows);
initBgRows();
});
// Animated Code Background
const canvas = document.querySelector('.bg-code');
const ctx = canvas.getContext('2d');
// Color probe for highlight.js theme
const colorProbe = document.createElement('span');
colorProbe.style.display = 'none';
document.body.appendChild(colorProbe);
let width = window.innerWidth, height = window.innerHeight;
let bgContent = Array(bgRows).fill('');
function resizeCanvas() {
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
function drawBgCode() {
ctx.clearRect(0, 0, width, height);
ctx.font = '1.1rem SFMono-Regular,monospace';
ctx.textBaseline = 'top';
for (let i = 0; i < bgRows; i++) {
if (bgContent[i]) {
let lang = codeLines[bgRowsState[i]?.codeIdx % codeLines.length]?.lang || '';
let code = bgContent[i];
let highlighted = lang ? hljs.highlight(code, {language: lang}).value : hljs.highlightAuto(code).value;
// Parse highlighted HTML to apply coloring
let tempDiv = document.createElement('div');
tempDiv.innerHTML = highlighted;
let x = bgXPositions[i];
let y = (i + 0.5) * height / bgRows;
function drawNode(node) {
if (node.nodeType === Node.TEXT_NODE && node.textContent) {
ctx.fillText(node.textContent, x, y);
x += ctx.measureText(node.textContent).width;
} else if (node.nodeType === Node.ELEMENT_NODE) {
let prev = ctx.fillStyle;
if (node.className) {
colorProbe.className = node.className;
const probeColor = window.getComputedStyle(colorProbe).color;
ctx.fillStyle = probeColor || prev;
}
node.childNodes.forEach(drawNode);
ctx.fillStyle = prev;
}
}
tempDiv.childNodes.forEach(drawNode);
} else {
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--code-fg');
ctx.fillText(bgContent[i], bgXPositions[i], (i + 0.5) * height / bgRows);
}
}
}
function animateBgRows(now) {
let redraw = false;
for (let i = 0; i < bgRows; i++) {
let row = bgRowsState[i];
if (now >= row.nextTime) {
if (row.state === "typing") {
const current = codeLines[row.codeIdx % codeLines.length].code;
if (row.charIdx < current.length) {
bgContent[i] = current.slice(0, row.charIdx + 1);
row.charIdx++;
row.nextTime = now + typingSpeed + Math.random() * 50;
redraw = true;
} else {
row.state = "pause";
row.nextTime = now + wipeDelay + Math.random() * 600;
}
} else if (row.state === "pause") {
row.state = "wiping";
row.nextTime = now + 200 + Math.random() * 350;
// On entering wiping, reset wipeStart, wipeEnd
row.wipeStart = 0;
row.wipeEnd = null;
} else if (row.state === "wiping") {
// Animated wipe (left or right)
const current = codeLines[row.codeIdx % codeLines.length].code;
if (row.wipeEnd === null) row.wipeEnd = current.length;
let done = false;
if (row.wipeDir === "left") {
if (row.wipeStart < row.wipeEnd) {
row.wipeStart++;
bgContent[i] = current.slice(row.wipeStart, row.wipeEnd);
row.nextTime = now + typingSpeed + Math.random() * 40;
redraw = true;
} else {
done = true;
}
} else { // right
if (row.wipeEnd > row.wipeStart) {
row.wipeEnd--;
bgContent[i] = current.slice(row.wipeStart, row.wipeEnd);
row.nextTime = now + typingSpeed + Math.random() * 40;
redraw = true;
} else {
done = true;
}
}
if (done) {
bgContent[i] = '';
row.codeIdx = (row.codeIdx + 1 + Math.floor(Math.random() * codeLines.length - 1)) % codeLines.length;
row.charIdx = 0;
row.state = "typing";
row.nextTime = now + Math.random() * 800;
row.wipeDir = Math.random() < 0.5 ? "left" : "right";
row.wipeStart = 0;
row.wipeEnd = null;
redraw = true;
}
}
}
}
if (redraw) drawBgCode();
requestAnimationFrame(animateBgRows);
}
requestAnimationFrame(animateBgRows);
// THEMING
const hljsThemeEl = document.getElementById('hljs-theme');
const toggleBtn = document.getElementById('toggle-mode');
let mode = null;
// Detect system preference, can be overridden
function getSystemTheme() {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
function applyTheme(m) {
document.documentElement.setAttribute('data-theme', m);
mode = m;
// highlight.js theme
hljsThemeEl.href = m === 'dark'
? "https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github-dark.min.css"
: "https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css";
// Mermaid theme
if (window.mermaid) {
mermaid.initialize({startOnLoad: false, theme: m === 'dark' ? 'dark' : 'default'});
rerenderMermaid();
}
// Toggle icon
toggleBtn.textContent = m === 'dark' ? '🌙' : '🌞';
drawBgCode();
}
function toggleTheme() {
let next = mode === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', next);
applyTheme(next);
}
// Init theme
let initialTheme = localStorage.getItem('theme') || getSystemTheme();
applyTheme(initialTheme);
toggleBtn.onclick = toggleTheme;
// Marked.js: support code highlighting & mermaid
marked.setOptions({
highlight: function (code, lang) {
// let highlight.js guess language if not specified
return hljs.highlightAuto(code).value;
}
});
// Render Markdown, including Mermaid diagrams and info panels
function renderMarkdown(mdText) {
// Replace mermaid blocks with <div class="mermaid">...</div>
const mdWithMermaid = mdText.replace(/```mermaid([\s\S]*?)```/g, (match, code) => {
return `<div class="mermaid">${code.trim()}</div>`;
});
document.getElementById('markdown-rendered').innerHTML = marked.parse(mdWithMermaid);
// Highlight code blocks
document.querySelectorAll('#markdown-rendered pre code').forEach(block => {
hljs.highlightElement(block);
});
rerenderMermaid();
// Convert blockquotes like [NOTE!], [TIP!], etc. to info panels
document.querySelectorAll('#markdown-rendered blockquote').forEach(q => {
const text = q.textContent.trim();
let match = text.match(/^\[(NOTE|TIP|WARNING|IMPORTANT|INFO)!\]\s*(.*)$/i);
if (match) {
q.outerHTML = `
<div class="info-panel ${match[1].toLowerCase()}">
<span class="info-label">${match[1]}</span> ${match[2]}
</div>
`;
}
});
}
function rerenderMermaid() {
// Re-initialize all mermaid diagrams
if (!window.mermaid) return;
mermaid.init(undefined, document.querySelectorAll('.mermaid'));
}
// Markdown fetch and render
fetch('TEST.md')
.then(r => r.text())
.then(md => {
renderMarkdown(md);
})
.catch(() => document.getElementById('markdown-rendered').textContent = 'Markdown not found.');
// Re-apply theme on system theme change
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
if (!localStorage.getItem('theme')) {
applyTheme(e.matches ? 'dark' : 'light');
}
});
</script>
</body>
</html>