-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
338 lines (313 loc) · 11.7 KB
/
Copy pathindex.html
File metadata and controls
338 lines (313 loc) · 11.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>icon.gl - Development</title>
<link rel="stylesheet" href="/dist/css/icon.gl.css">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: system-ui, -apple-system, sans-serif;
background: #0a0a0a;
color: #e0e0e0;
min-height: 100vh;
padding: 2rem;
}
header {
text-align: center;
margin-bottom: 2rem;
}
h1 {
font-size: 2.5rem;
font-weight: 300;
}
h1 span { color: #646cff; }
.stats {
display: flex;
justify-content: center;
gap: 2rem;
margin-top: 1rem;
}
.stat { text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: bold; color: #646cff; }
.stat-label { font-size: 0.75rem; color: #888; }
.controls {
display: flex;
justify-content: center;
gap: 1rem;
margin-bottom: 2rem;
flex-wrap: wrap;
position: sticky;
top: 0;
background: #0a0a0a;
padding: 1rem 0;
z-index: 100;
}
input, select {
padding: 0.5rem 1rem;
border: 1px solid #333;
border-radius: 6px;
background: #1a1a1a;
color: #e0e0e0;
font-size: 1rem;
}
input:focus, select:focus {
outline: none;
border-color: #646cff;
}
#search { width: 300px; }
.icon-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 0.5rem;
contain: layout style;
}
.icon-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 1rem 0.5rem;
background: #1a1a1a;
border-radius: 8px;
cursor: pointer;
transition: background 0.15s, transform 0.15s;
/* Critical for performance with many items */
content-visibility: auto;
contain-intrinsic-size: 100px 90px;
}
.icon-item:hover {
background: #252525;
transform: translateY(-2px);
}
.icon-item .icon-svg {
width: var(--icon-size, 2rem);
height: var(--icon-size, 2rem);
margin-bottom: 0.5rem;
color: white;
}
.icon-item .icon-svg svg {
width: 100%;
height: 100%;
stroke: white;
fill: white;
}
.icon-item span {
font-size: 0.65rem;
color: #888;
text-align: center;
word-break: break-all;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.toast {
position: fixed;
bottom: 2rem;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: #646cff;
color: white;
padding: 0.75rem 1.5rem;
border-radius: 6px;
opacity: 0;
transition: all 0.3s;
}
.toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
footer {
text-align: center;
margin-top: 3rem;
padding-top: 2rem;
border-top: 1px solid #333;
color: #666;
}
footer a { color: #646cff; text-decoration: none; }
.status-bar {
text-align: center;
color: #888;
margin-bottom: 1rem;
font-size: 0.9rem;
}
</style>
</head>
<body>
<header>
<h1>icon<span>.gl</span></h1>
<p>Development Server</p>
<div class="stats">
<div class="stat">
<div class="stat-value" id="total-icons">-</div>
<div class="stat-label">Icons</div>
</div>
<div class="stat">
<div class="stat-value" id="total-categories">-</div>
<div class="stat-label">Categories</div>
</div>
</div>
</header>
<div class="controls">
<select id="category">
<option value="">All Categories</option>
</select>
<select id="weight">
<option value="normal" selected>Normal</option>
<option value="bold">Bold</option>
</select>
<input type="text" id="search" placeholder="Search icons...">
<select id="size">
<option value="1.5rem">Small</option>
<option value="2rem" selected>Medium</option>
<option value="3rem">Large</option>
<option value="4rem">X-Large</option>
</select>
</div>
<div class="status-bar" id="status">Loading icons...</div>
<main id="icon-container"></main>
<div class="toast" id="toast">Copied!</div>
<footer>
<p>icon.gl Development Server | <a href="/dist/svg/">Browse SVGs</a> | <a href="/exa/font_demo.html">Font demo (every i_* class)</a></p>
</footer>
<script type="module">
// Eagerly load ALL SVGs at build time using Vite's glob import
const svgModules = import.meta.glob('/dist/svg/**/*.svg', {
eager: true,
query: '?raw',
import: 'default'
});
// Create a map for fast lookup: name -> SVG content
const svgMap = new Map();
for (const [path, content] of Object.entries(svgModules)) {
// Extract filename without extension
// e.g., "/dist/svg/lucide/lucide_search.svg" -> "lucide_search"
// e.g., "/dist/svg/arrows/arrow_up.svg" -> "arrow_up"
const match = path.match(/\/([^/]+)\.svg$/);
if (match) {
svgMap.set(match[1], content);
}
}
console.log(`[icon.gl] Loaded ${svgMap.size} SVGs via import.meta.glob`);
// Load metadata
const [lucideMetadata, iconGlMetadata] = await Promise.all([
fetch('/dist/json/lucide/index.json').then(r => r.json()),
fetch('/dist/json/icongl/index.json').then(r => r.json())
]);
const container = document.getElementById('icon-container');
const searchInput = document.getElementById('search');
const sizeSelect = document.getElementById('size');
const categorySelect = document.getElementById('category');
const weightSelect = document.getElementById('weight');
const statusEl = document.getElementById('status');
const toast = document.getElementById('toast');
// Build icon list from metadata
const allIcons = [];
// Add original icon.gl icons
for (const [cat, icons] of Object.entries(iconGlMetadata.categories)) {
for (const name of icons) {
allIcons.push({
name,
cleanName: name,
category: cat,
tags: [],
source: 'icongl'
});
}
}
// Add Lucide icons (both weights)
for (const [baseName, data] of Object.entries(lucideMetadata.icons)) {
allIcons.push({
name: data.normal,
cleanName: baseName,
category: 'lucide',
tags: data.tags || [],
lucideCategories: data.categories || [],
source: 'lucide',
weight: 'normal'
});
allIcons.push({
name: data.bold,
cleanName: baseName,
category: 'lucide',
tags: data.tags || [],
lucideCategories: data.categories || [],
source: 'lucide',
weight: 'bold'
});
}
// Group by category
const iconsByCategory = {};
allIcons.forEach(icon => {
if (!iconsByCategory[icon.category]) iconsByCategory[icon.category] = [];
iconsByCategory[icon.category].push(icon);
});
// Populate category dropdown
const categories = Object.keys(iconsByCategory).sort();
categories.forEach(cat => {
const opt = document.createElement('option');
opt.value = cat;
const uniqueCount = iconsByCategory[cat].filter(i => i.weight !== 'bold').length;
opt.textContent = `${cat} (${uniqueCount})`;
categorySelect.appendChild(opt);
});
// Update stats
const uniqueIconCount = allIcons.filter(i => i.weight !== 'bold').length;
document.getElementById('total-icons').textContent = uniqueIconCount.toLocaleString();
document.getElementById('total-categories').textContent = categories.length;
// Render icons - all at once, browser handles visibility optimization
function renderIcons(filter = '') {
const size = sizeSelect.value;
const selectedCategory = categorySelect.value;
const selectedWeight = weightSelect.value;
document.documentElement.style.setProperty('--icon-size', size);
// Filter icons
const filteredIcons = allIcons.filter(icon => {
if (selectedCategory && icon.category !== selectedCategory) return false;
if (icon.source === 'lucide' && icon.weight !== selectedWeight) return false;
if (filter) {
const searchLower = filter.toLowerCase();
const matchesName = icon.cleanName.toLowerCase().includes(searchLower);
const matchesTags = icon.tags.some(t => t.toLowerCase().includes(searchLower));
if (!matchesName && !matchesTags) return false;
}
return true;
});
statusEl.textContent = `Showing ${filteredIcons.length.toLocaleString()} icons`;
// Use DocumentFragment for efficient DOM insertion
const fragment = document.createDocumentFragment();
const grid = document.createElement('div');
grid.className = 'icon-grid';
for (const icon of filteredIcons) {
const svg = svgMap.get(icon.name) || '<svg viewBox="0 0 864 864"><text x="432" y="432" text-anchor="middle" fill="#666">?</text></svg>';
const item = document.createElement('div');
item.className = 'icon-item';
item.innerHTML = `
<div class="icon-svg">${svg}</div>
<span>${icon.cleanName}</span>
`;
item.onclick = () => {
navigator.clipboard.writeText(icon.name);
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 1500);
};
grid.appendChild(item);
}
fragment.appendChild(grid);
container.innerHTML = '';
container.appendChild(fragment);
}
// Debounce search for performance
let searchTimeout;
searchInput.addEventListener('input', (e) => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => renderIcons(e.target.value), 150);
});
sizeSelect.addEventListener('change', () => renderIcons(searchInput.value));
categorySelect.addEventListener('change', () => renderIcons(searchInput.value));
weightSelect.addEventListener('change', () => renderIcons(searchInput.value));
// Initial render
renderIcons();
</script>
</body>
</html>