-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_lazy.html
More file actions
209 lines (176 loc) · 5.83 KB
/
example_lazy.html
File metadata and controls
209 lines (176 loc) · 5.83 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SquibView Lazy Loading Example</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><circle cx='16' cy='16' r='14' fill='%23f57c00' stroke='%23000' stroke-width='1'/><path d='M2 16h28M16 2a14 14 0 0114 14 14 14 0 01-14 14 14 14 0 01-14-14A14 14 0 0116 2zm0 0v28M9 16a7 7 0 0014 0 7 7 0 00-14 0z' fill='none' stroke='%23000' stroke-width='1'/></svg>">
<!-- SquibView CSS -->
<link rel="stylesheet" href="../dist/squibview.min.css">
<!-- Shared example styles -->
<link rel="stylesheet" href="examples.css">
<style>
/* Page-specific styles */
.status {
font-family: monospace;
font-size: 14px;
}
#editor1, #editor2 {
height: 600px;
}
</style>
</head>
<body>
<div class="example-header">
<h1 class="example-title">SquibView Lazy Loading Demo</h1>
<p class="example-description">This example demonstrates the lazy-loading build of SquibView. Libraries like Mermaid, Highlight.js, MathJax, Leaflet, and Three.js are loaded only when needed.</p>
<div id="status" class="status">Initializing...</div>
</div>
<!-- First Instance -->
<div class="instance-container">
<div class="instance-label">Instance 1: Full Feature Demo</div>
<div id="editor1" class="editor-container"></div>
</div>
<!-- Second Instance -->
<div class="instance-container">
<div class="instance-label">Instance 2: Testing Duplicate Prevention</div>
<div id="editor2" class="editor-container"></div>
</div>
<script type="module">
import SquibView from '../dist/squibview.lazy.esm.min.js';
const statusEl = document.getElementById('status');
// Track library loading
const originalLog = console.log;
const originalError = console.error;
let loadedLibraries = [];
console.log = function(...args) {
const msg = args.join(' ');
if (msg.includes('SquibView')) {
statusEl.textContent = msg;
}
originalLog.apply(console, args);
};
console.error = function(...args) {
const msg = args.join(' ');
if (msg.includes('SquibView')) {
statusEl.textContent = '❌ ' + msg;
statusEl.style.background = '#ffebee';
}
originalError.apply(console, args);
};
// Monitor script loading
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.tagName === 'SCRIPT') {
const libName =
node.src.includes('mermaid') ? 'Mermaid' :
node.src.includes('highlight') ? 'Highlight.js' :
node.src.includes('mathjax') ? 'MathJax' :
node.src.includes('leaflet') ? 'Leaflet' :
node.src.includes('three') ? 'Three.js' :
'Unknown';
if (libName !== 'Unknown') {
loadedLibraries.push(libName);
statusEl.textContent = `✅ Lazy loaded: ${libName} (Total: ${loadedLibraries.join(', ')})`;
statusEl.style.background = '#e8f5e9';
}
}
});
});
});
observer.observe(document.head, { childList: true });
// Sample content with various features
const sampleContent = `# SquibView Lazy Loading Test
## Markdown Rendering (Built-in)
This basic markdown rendering is handled by the bundled markdown-it library.
- Lists work immediately
- **Bold** and *italic* text
- [Links](https://github.com) work out of the box
## Code Highlighting (Lazy Loaded)
The following code block will trigger lazy loading of highlight.js:
\`\`\`javascript
// This will be syntax highlighted after hljs loads
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
console.log(fibonacci(10));
\`\`\`
## Math Equations (Lazy Loaded)
Inline math: $E = mc^2$ and block math:
$$
\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}
$$
## Mermaid Diagrams (Lazy Loaded)
\`\`\`mermaid
graph TD
A[Start] --> B{Is Lazy Loading?}
B -->|Yes| C[Load Only When Needed]
B -->|No| D[Load Everything]
C --> E[Save Bandwidth]
D --> F[Larger Initial Load]
\`\`\`
## Geographic Data (Lazy Loaded)
\`\`\`geojson
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.4194, 37.7749]
},
"properties": {
"name": "San Francisco",
"description": "Leaflet loads only when this appears!"
}
}
\`\`\`
## 3D Models (Lazy Loaded)
\`\`\`stl
solid cube
facet normal 0 0 1
outer loop
vertex 0 0 1
vertex 1 0 1
vertex 1 1 1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 1
vertex 1 1 1
vertex 0 1 1
endloop
endfacet
endsolid
\`\`\`
`;
// Initialize first editor
statusEl.textContent = 'Initializing Editor 1...';
const editor1 = new SquibView('#editor1', {
initialContent: sampleContent,
view: 'split',
theme: 'default'
});
// Initialize second editor with simpler content
setTimeout(() => {
statusEl.textContent = 'Initializing Editor 2...';
const editor2 = new SquibView('#editor2', {
initialContent: '# Second Instance\n\nThis tests that libraries are not loaded twice.\n\n```javascript\nconst test = "duplicate prevention";\n```',
view: 'split',
theme: 'default'
});
}, 1000);
// Report final status
setTimeout(() => {
if (loadedLibraries.length > 0) {
const unique = [...new Set(loadedLibraries)];
statusEl.textContent = `✅ Successfully lazy loaded: ${unique.join(', ')}`;
statusEl.style.background = '#c8e6c9';
} else {
statusEl.textContent = 'ℹ️ No external libraries needed yet';
}
}, 5000);
</script>
</body>
</html>