-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-100-CSS-Box-Shadow-Generator.html
More file actions
490 lines (415 loc) · 17.8 KB
/
tool-100-CSS-Box-Shadow-Generator.html
File metadata and controls
490 lines (415 loc) · 17.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 100 - CSS Box Shadow Generator - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<style>
.split-view {
display: grid;
grid-template-columns: 1fr;
gap: 1.5rem;
margin-top: 1rem;
margin-bottom: 2rem;
}
@media (min-width: 900px) {
.split-view { grid-template-columns: 350px 1fr; }
}
.panel {
background: rgba(0,0,0,0.6);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.slider-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.slider-header {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.85rem;
color: #ccc;
}
.slider-val {
font-family: var(--font-mono);
color: #56b6c2;
background: rgba(0,0,0,0.5);
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.8rem;
min-width: 45px;
text-align: center;
border: 1px solid #333;
}
input[type=range] {
width: 100%;
accent-color: #56b6c2;
}
.color-group {
display: flex;
align-items: center;
gap: 1rem;
background: rgba(0,0,0,0.4);
border: 1px solid var(--border-color);
padding: 0.8rem;
border-radius: var(--radius-sm);
}
.color-picker {
width: 40px;
height: 40px;
border: none;
padding: 0;
background: transparent;
cursor: pointer;
border-radius: 4px;
}
.hex-input {
background: transparent;
border: none;
color: #fff;
font-family: var(--font-mono);
font-size: 1rem;
width: 80px;
outline: none;
}
.checkbox-lbl {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.9rem;
color: #ccc;
cursor: pointer;
}
.checkbox-lbl input { accent-color: #56b6c2; width: 16px; height: 16px; cursor: pointer; }
.preview-area {
flex: 1;
background: #e0e0e0;
border-radius: var(--radius-md);
display: flex;
justify-content: center;
align-items: center;
min-height: 400px;
position: relative;
overflow: hidden;
border: 1px solid #aaa;
}
.demo-box {
width: 250px;
height: 250px;
background: #ffffff;
border-radius: 12px;
display: flex;
justify-content: center;
align-items: center;
color: #aaa;
font-weight: bold;
font-size: 1.2rem;
text-align: center;
padding: 2rem;
transition: box-shadow 0.1s;
}
.code-output-container {
margin-top: 1rem;
background: #111;
border: 1px solid #333;
border-radius: var(--radius-sm);
padding: 1.5rem;
font-family: var(--font-mono);
font-size: 14px;
color: #7ee787;
position: relative;
}
.btn-copy {
position: absolute;
top: 1rem;
right: 1rem;
background: rgba(255,255,255,0.1);
color: #fff;
border: 1px solid #444;
padding: 0.4rem 0.8rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.8rem;
}
.btn-copy:hover { background: rgba(255,255,255,0.2); }
/* 3D Canvas wrapper */
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.2;
pointer-events: none;
}
</style>
</head>
<body class="theme-dark">
<div id="canvas-container"></div>
<main class="main-content" style="padding-top:2rem;">
<div class="container" style="max-width: 1300px;">
<div class="tool-header">
<div>
<a href="index.html" class="back-link">← Back to Toolbox</a>
<h1>100. CSS Box Shadow Generator</h1>
</div>
<div>
<select id="theme-select" aria-label="Select Theme">
<option value="dark">Dark Theme</option>
<option value="light">Light Theme</option>
<option value="solarized">Solarized</option>
<option value="neon">Neon Glow</option>
<option value="highcontrast">High Contrast</option>
</select>
</div>
</div>
<div class="split-view">
<!-- Input Panel -->
<div class="panel">
<h3>Shadow Settings</h3>
<div class="slider-group">
<div class="slider-header">
<span>Horizontal Offset (x)</span>
<span class="slider-val" id="val-x">0px</span>
</div>
<input type="range" id="inp-x" min="-100" max="100" value="0">
</div>
<div class="slider-group">
<div class="slider-header">
<span>Vertical Offset (y)</span>
<span class="slider-val" id="val-y">10px</span>
</div>
<input type="range" id="inp-y" min="-100" max="100" value="10">
</div>
<div class="slider-group">
<div class="slider-header">
<span>Blur Radius</span>
<span class="slider-val" id="val-blur">30px</span>
</div>
<input type="range" id="inp-blur" min="0" max="150" value="30">
</div>
<div class="slider-group">
<div class="slider-header">
<span>Spread Radius</span>
<span class="slider-val" id="val-spread">0px</span>
</div>
<input type="range" id="inp-spread" min="-50" max="100" value="0">
</div>
<div>
<label style="font-size:0.8rem; color:#aaa; margin-bottom:0.3rem; display:block;">Shadow Color & Opacity</label>
<div class="color-group">
<input type="color" id="inp-color" class="color-picker" value="#000000">
<input type="text" id="inp-hex" class="hex-input" value="#000000" maxlength="7">
<div style="flex:1; display:flex; flex-direction:column; gap:0.2rem;">
<div class="slider-header" style="font-size:0.75rem;">
<span>Opacity</span>
<span class="slider-val" id="val-opacity">0.3</span>
</div>
<input type="range" id="inp-opacity" min="0" max="1" step="0.05" value="0.3">
</div>
</div>
</div>
<label class="checkbox-lbl">
<input type="checkbox" id="chk-inset">
Inset Shadow
</label>
</div>
<!-- Output Panel -->
<div class="panel" style="background:rgba(0,0,0,0.8);">
<h3>Visual Preview</h3>
<div class="preview-area" id="bg-preview">
<div class="demo-box" id="demo-box">Box Element</div>
</div>
<div class="code-output-container">
<button class="btn-copy" id="btn-copy">Copy CSS</button>
<div id="code-output" style="user-select:all;">box-shadow: 0px 10px 30px 0px rgba(0,0,0,0.3);</div>
</div>
</div>
</div>
</div>
</main>
<footer class="global-footer">
<div class="container">
Made with ❤️ by <a href="https://github.com/Aliriyaj007" target="_blank">Aliriyaj007</a>
</div>
</footer>
<script src="assets/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script>
// UI Elements
const inpX = document.getElementById('inp-x');
const inpY = document.getElementById('inp-y');
const inpBlur = document.getElementById('inp-blur');
const inpSpread = document.getElementById('inp-spread');
const inpColor = document.getElementById('inp-color');
const inpHex = document.getElementById('inp-hex');
const inpOpacity = document.getElementById('inp-opacity');
const chkInset = document.getElementById('chk-inset');
const valX = document.getElementById('val-x');
const valY = document.getElementById('val-y');
const valBlur = document.getElementById('val-blur');
const valSpread = document.getElementById('val-spread');
const valOpacity = document.getElementById('val-opacity');
const demoBox = document.getElementById('demo-box');
const codeOutput = document.getElementById('code-output');
const btnCopy = document.getElementById('btn-copy');
// Logic
function hexToRgb(hex) {
let h = hex.replace('#', '');
if(h.length === 3) h = h[0]+h[0]+h[1]+h[1]+h[2]+h[2];
if(h.length !== 6) return {r:0,g:0,b:0};
return {
r: parseInt(h.substring(0,2), 16),
g: parseInt(h.substring(2,4), 16),
b: parseInt(h.substring(4,6), 16)
};
}
function updateShadow() {
const x = inpX.value;
const y = inpY.value;
const blur = inpBlur.value;
const spread = inpSpread.value;
const hex = inpHex.value;
const op = inpOpacity.value;
const isInset = chkInset.checked ? 'inset ' : '';
// Update Labels
valX.textContent = x + 'px';
valY.textContent = y + 'px';
valBlur.textContent = blur + 'px';
valSpread.textContent = spread + 'px';
valOpacity.textContent = op;
// Sync color picker
inpColor.value = hex;
// Format string
const rgb = hexToRgb(hex);
const rgbaStr = `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${op})`;
const shadowStr = `${isInset}${x}px ${y}px ${blur}px ${spread}px ${rgbaStr}`;
// Apply
demoBox.style.boxShadow = shadowStr;
// Output code
const cssRule = `box-shadow: ${shadowStr};\n-webkit-box-shadow: ${shadowStr};\n-moz-box-shadow: ${shadowStr};`;
const displayRule = `box-shadow: ${shadowStr};`;
// Use simple highlight
codeOutput.innerHTML = `<span style="color:#c678dd;">box-shadow:</span> <span style="color:#e06c75;">${isInset}${x}px ${y}px ${blur}px ${spread}px</span> <span style="color:#61afef;">rgba(</span>${rgb.r}, ${rgb.g}, ${rgb.b}, ${op}<span style="color:#61afef;">)</span>;`;
// Store raw for copy
codeOutput.dataset.raw = displayRule;
update3D(x, y, blur, spread, hex, op, chkInset.checked);
}
// Event Listeners
[inpX, inpY, inpBlur, inpSpread, inpOpacity].forEach(el => {
el.addEventListener('input', updateShadow);
});
inpColor.addEventListener('input', (e) => { inpHex.value = e.target.value; updateShadow(); });
inpHex.addEventListener('input', updateShadow);
chkInset.addEventListener('change', updateShadow);
btnCopy.addEventListener('click', () => {
navigator.clipboard.writeText(codeOutput.dataset.raw);
btnCopy.textContent = 'Copied!';
setTimeout(() => { btnCopy.textContent = 'Copy CSS'; }, 2000);
});
// 3D Scene setup: "A floating object with a dynamic shadow underneath"
let scene, camera, renderer, objectGrp;
let shadowPlane, simLight;
function init3D() {
const container = document.getElementById('canvas-container');
if(!container) return;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.z = 25;
camera.position.y = 15;
camera.position.x = 0;
camera.lookAt(0, 5, 0);
// Need shadow map enabled for real dynamic shadows
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);
// This light moves based on X/Y offsets to cast physical shadow
simLight = new THREE.SpotLight(0xffffff, 1);
simLight.position.set(0, 30, 0);
simLight.castShadow = true;
simLight.shadow.mapSize.width = 1024;
simLight.shadow.mapSize.height = 1024;
simLight.shadow.bias = -0.001;
scene.add(simLight);
// Floating object
objectGrp = new THREE.Group();
scene.add(objectGrp);
const boxGeo = new THREE.BoxGeometry(6, 6, 6);
const boxMat = new THREE.MeshPhongMaterial({ color: 0x56b6c2, shininess: 80 });
const box = new THREE.Mesh(boxGeo, boxMat);
box.castShadow = true;
box.receiveShadow = false;
box.position.y = 8;
objectGrp.add(box);
// Floor to receive shadow
const floorGeo = new THREE.PlaneGeometry(100, 100);
const floorMat = new THREE.MeshPhongMaterial({ color: 0x222222, shininess: 10 });
shadowPlane = new THREE.Mesh(floorGeo, floorMat);
shadowPlane.rotation.x = -Math.PI/2;
shadowPlane.position.y = 0;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate3D();
updateShadow(); // run once
}
// Map CSS params to 3D lighting params
function update3D(x, y, blur, spread, hexStr, op, isInset) {
if(!simLight) return;
// X offset -> Move light opposite X
// Y offset (CSS Y down is positive) -> Move light opposite Z (3D Z is depth)
// Limit bounds so light doesn't break
const maxOffset = 50;
let sx = parseFloat(x);
let sy = parseFloat(y);
// Inverse mapping: CSS shadow right (x > 0) means light is left (x < 0)
simLight.position.x = -sx * 0.3;
// CSS shadow down (y > 0) means light is up/forward (z < 0)
simLight.position.z = -sy * 0.3;
// Blur -> Shadow map soft radius / penumbra
simLight.penumbra = Math.min(1, parseFloat(blur) / 100);
// Spread -> Light distance/angle tweaking (approximate)
simLight.angle = Math.PI/6 + (parseFloat(spread) * 0.01);
// Color / Opacity -> Light color mix (this is hacky but looks neat)
// Actual physical shadows are lack of light, but we can tint the ambient or the spot
if(isInset) {
// Inset: make object hollow or wireframe to simulate
objectGrp.children[0].material.wireframe = true;
} else {
objectGrp.children[0].material.wireframe = false;
}
// Adjust base object color to match selected shadow for aesthetic
objectGrp.children[0].material.emissive.setHex(parseInt(hexStr.replace('#',''), 16));
objectGrp.children[0].material.emissiveIntensity = parseFloat(op) * 0.5;
}
function animate3D() {
requestAnimationFrame(animate3D);
// gentle rotation
objectGrp.rotation.y += 0.005;
objectGrp.rotation.x = Math.sin(Date.now()*0.001) * 0.2;
// gentle bob
objectGrp.position.y = Math.sin(Date.now()*0.002) * 1;
renderer.render(scene, camera);
}
document.addEventListener('DOMContentLoaded', () => {
init3D();
});
</script>
</body>
</html>