-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathresponsive-breakpoint-tester.html
More file actions
535 lines (486 loc) · 16.3 KB
/
Copy pathresponsive-breakpoint-tester.html
File metadata and controls
535 lines (486 loc) · 16.3 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Responsive Breakpoint Tester | One File Tools</title>
<style>
/* Premium Design Tokens */
:root {
--bg-base: #f4f4f5;
--bg-surface: #ffffff;
--bg-sandbox: #1e1e1e;
--border-color: #e4e4e7;
--border-focus: #3b82f6;
--text-main: #18181b;
--text-muted: #71717a;
--accent: #2563eb;
--accent-hover: #1d4ed8;
--warning-bg: #fffbeb;
--warning-text: #b45309;
--radius-md: 8px;
--radius-lg: 12px;
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
--font-sans: "Inter", system-ui, sans-serif;
--font-mono: "JetBrains Mono", monospace;
--transition: 0.2s ease;
}
[data-theme="dark"] {
--bg-base: #09090b;
--bg-surface: #18181b;
--border-color: #27272a;
--text-main: #f4f4f5;
--text-muted: #a1a1aa;
--accent: #3b82f6;
--warning-bg: rgba(245, 158, 11, 0.1);
--warning-text: #fcd34d;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-sans);
background: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* Application Layout */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
background: var(--bg-surface);
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
}
.brand {
font-weight: 600;
font-size: 1.125rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.workspace {
display: flex;
flex: 1;
overflow: hidden;
flex-direction: column;
}
/* Controls Panel */
.controls {
background: var(--bg-surface);
border-bottom: 1px solid var(--border-color);
padding: 1rem 1.5rem;
display: flex;
flex-direction: column;
gap: 1rem;
flex-shrink: 0;
z-index: 10;
}
.controls-top,
.controls-bottom {
display: flex;
gap: 1rem;
flex-wrap: wrap;
align-items: flex-end;
}
/* Tabs & Inputs */
.tab-group {
display: flex;
background: var(--bg-base);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
overflow: hidden;
}
.tab-btn {
padding: 0.6rem 1rem;
border: none;
background: transparent;
color: var(--text-muted);
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
}
.tab-btn.active {
background: var(--bg-surface);
color: var(--text-main);
box-shadow: var(--shadow-sm);
}
.input-group {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.25rem;
min-width: 300px;
}
.input-label {
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
color: var(--text-muted);
}
.form-input {
padding: 0.6rem 1rem;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
background: var(--bg-base);
color: var(--text-main);
font-family: var(--font-sans);
outline: none;
transition: var(--transition);
}
.form-input:focus {
border-color: var(--border-focus);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.form-input.mono {
font-family: var(--font-mono);
}
.sandbox-area {
display: none;
width: 100%;
}
.sandbox-area.active {
display: flex;
flex-direction: column;
gap: 0.25rem;
flex: 1;
}
.sandbox-textarea {
width: 100%;
height: 100px;
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
background: var(--bg-sandbox);
color: #e5e5e5;
font-family: var(--font-mono);
font-size: 0.875rem;
outline: none;
resize: vertical;
}
.warning-note {
font-size: 0.75rem;
color: var(--warning-text);
background: var(--warning-bg);
padding: 0.5rem 0.75rem;
border-radius: var(--radius-md);
display: flex;
align-items: center;
gap: 0.5rem;
}
/* Presets & Dimensions */
.presets {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.btn {
padding: 0.6rem 1rem;
font-size: 0.875rem;
font-weight: 500;
border-radius: var(--radius-md);
cursor: pointer;
border: 1px solid var(--border-color);
background: var(--bg-surface);
color: var(--text-main);
display: inline-flex;
align-items: center;
gap: 0.5rem;
transition: var(--transition);
}
.btn:hover {
background: var(--bg-base);
}
.btn-primary {
background: var(--accent);
color: white;
border-color: var(--accent);
}
.btn-primary:hover {
background: var(--accent-hover);
color: white;
}
.dim-inputs {
display: flex;
align-items: center;
gap: 0.5rem;
}
.dim-input {
width: 80px;
text-align: center;
}
/* Preview Area */
.preview-wrapper {
flex: 1;
background: var(--bg-base);
position: relative;
overflow: auto;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
}
.frame-container {
background: var(--bg-surface);
border: 1px solid var(--border-color);
border-radius: 4px;
box-shadow: var(--shadow-lg);
transition:
width 0.3s ease,
height 0.3s ease;
position: relative;
display: flex;
flex-direction: column;
overflow: hidden;
transform-origin: top center;
}
.frame-header {
background: var(--bg-base);
border-bottom: 1px solid var(--border-color);
padding: 0.5rem;
text-align: center;
font-family: var(--font-mono);
font-size: 0.75rem;
color: var(--text-muted);
}
.preview-frame {
width: 100%;
height: 100%;
border: none;
background: #ffffff;
}
.scale-info {
position: absolute;
bottom: 1rem;
right: 1rem;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 0.4rem 0.8rem;
border-radius: 20px;
font-size: 0.75rem;
font-family: var(--font-mono);
pointer-events: none;
z-index: 50;
}
.icon-btn {
background: transparent;
border: 1px solid var(--border-color);
color: var(--text-main);
padding: 0.5rem;
border-radius: var(--radius-md);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<header class="header">
<div class="brand">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="3" width="20" height="14" rx="2" ry="2" />
<line x1="8" y1="21" x2="16" y2="21" />
<line x1="12" y1="17" x2="12" y2="21" />
</svg>
Responsive Breakpoint Tester
</div>
<button class="icon-btn" id="themeToggle" aria-label="Toggle Theme">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
</button>
</header>
<main class="workspace">
<section class="controls">
<div class="controls-top">
<div class="tab-group">
<button class="tab-btn active" data-tab="url">URL Mode</button>
<button class="tab-btn" data-tab="sandbox">Local Sandbox</button>
</div>
<div class="input-group" id="urlInputGroup">
<label class="input-label">Target URL</label>
<input type="url" id="urlInput" class="form-input" placeholder="https://example.com" value="https://example.com" />
</div>
<div class="sandbox-area" id="sandboxArea">
<label class="input-label">Raw HTML/CSS</label>
<textarea id="htmlInput" class="sandbox-textarea" placeholder="<h1>Hello World</h1><style>h1 { color: blue; text-align: center; }</style>"></textarea>
</div>
<button class="btn btn-primary" id="renderBtn">Render Preview</button>
</div>
<div class="controls-bottom">
<div class="warning-note" id="xframeWarning">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10" />
<line x1="12" y1="8" x2="12" y2="12" />
<line x1="12" y1="16" x2="12.01" y2="16" />
</svg>
If a site refuses to connect, it likely blocks iframes (X-Frame-Options). Use the Local Sandbox tab instead.
</div>
</div>
<div class="controls-bottom" style="margin-top: 0.5rem; justify-content: space-between">
<div class="presets">
<button class="btn preset-btn" data-w="375" data-h="812">Mobile</button>
<button class="btn preset-btn" data-w="768" data-h="1024">Tablet</button>
<button class="btn preset-btn" data-w="1366" data-h="768">Laptop</button>
<button class="btn preset-btn" data-w="1920" data-h="1080">Desktop</button>
</div>
<div class="dim-inputs">
<label class="input-label">W</label>
<input type="number" id="customW" class="form-input mono dim-input" value="1366" />
<label class="input-label">H</label>
<input type="number" id="customH" class="form-input mono dim-input" value="768" />
<button class="btn" id="rotateBtn" title="Rotate Viewport">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
<path d="M3 3v5h5" />
</svg>
</button>
</div>
</div>
</section>
<section class="preview-wrapper" id="wrapper">
<div class="frame-container" id="frameContainer">
<div class="frame-header" id="frameHeader">1366 x 768</div>
<iframe class="preview-frame" id="previewFrame" title="Responsive Preview"></iframe>
</div>
<div class="scale-info" id="scaleInfo">Scale: 100%</div>
</section>
</main>
<script>
/**
* State & DOM Management
*/
const state = {
mode: "url",
w: 1366,
h: 768
};
const els = {
themeToggle: document.getElementById("themeToggle"),
tabBtns: document.querySelectorAll(".tab-btn"),
urlGroup: document.getElementById("urlInputGroup"),
sandboxArea: document.getElementById("sandboxArea"),
xframeWarning: document.getElementById("xframeWarning"),
urlInput: document.getElementById("urlInput"),
htmlInput: document.getElementById("htmlInput"),
renderBtn: document.getElementById("renderBtn"),
presetBtns: document.querySelectorAll(".preset-btn"),
customW: document.getElementById("customW"),
customH: document.getElementById("customH"),
rotateBtn: document.getElementById("rotateBtn"),
wrapper: document.getElementById("wrapper"),
frameContainer: document.getElementById("frameContainer"),
frameHeader: document.getElementById("frameHeader"),
previewFrame: document.getElementById("previewFrame"),
scaleInfo: document.getElementById("scaleInfo")
};
// Theme Logic
const initTheme = () => {
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.setAttribute("data-theme", "dark");
}
};
els.themeToggle.addEventListener("click", () => {
const isDark = document.documentElement.getAttribute("data-theme") === "dark";
document.documentElement.setAttribute("data-theme", isDark ? "light" : "dark");
});
// Tab Logic
els.tabBtns.forEach((btn) => {
btn.addEventListener("click", (e) => {
els.tabBtns.forEach((b) => b.classList.remove("active"));
e.target.classList.add("active");
state.mode = e.target.dataset.tab;
if (state.mode === "url") {
els.urlGroup.style.display = "flex";
els.sandboxArea.classList.remove("active");
els.xframeWarning.style.display = "flex";
} else {
els.urlGroup.style.display = "none";
els.sandboxArea.classList.add("active");
els.xframeWarning.style.display = "none";
}
});
});
// Core Render Engine
const renderPreview = () => {
if (state.mode === "url") {
let url = els.urlInput.value.trim();
if (url && !url.startsWith("http")) url = "https://" + url;
// Clear srcdoc to allow src to load
els.previewFrame.removeAttribute("srcdoc");
els.previewFrame.src = url || "about:blank";
} else {
// Clear src to allow srcdoc to render
els.previewFrame.removeAttribute("src");
els.previewFrame.srcdoc = els.htmlInput.value;
}
};
// Dimension & Intelligent Scale Logic
const updateDimensions = () => {
els.customW.value = state.w;
els.customH.value = state.h;
els.frameContainer.style.width = `${state.w}px`;
els.frameContainer.style.height = `${state.h}px`;
els.frameHeader.textContent = `${state.w} x ${state.h}`;
applyIntelligentScale();
};
const applyIntelligentScale = () => {
// Give DOM a tick to calculate wrapper size
requestAnimationFrame(() => {
// Remove header height from available space calculation
const padding = 64;
const availableW = els.wrapper.clientWidth - padding;
const availableH = els.wrapper.clientHeight - padding;
const scaleW = availableW / state.w;
const scaleH = availableH / state.h;
// Calculate required scale, maxing out at 1 (100%)
const scale = Math.min(scaleW, scaleH, 1);
if (scale < 1) {
els.frameContainer.style.transform = `scale(${scale})`;
els.scaleInfo.textContent = `Scale: ${Math.round(scale * 100)}% (Fitted)`;
els.scaleInfo.style.display = "block";
} else {
els.frameContainer.style.transform = "scale(1)";
els.scaleInfo.style.display = "none";
}
});
};
// Event Listeners
els.renderBtn.addEventListener("click", renderPreview);
els.presetBtns.forEach((btn) => {
btn.addEventListener("click", (e) => {
state.w = parseInt(e.target.dataset.w);
state.h = parseInt(e.target.dataset.h);
updateDimensions();
});
});
const handleCustomInput = () => {
state.w = parseInt(els.customW.value) || 320;
state.h = parseInt(els.customH.value) || 480;
updateDimensions();
};
els.customW.addEventListener("change", handleCustomInput);
els.customH.addEventListener("change", handleCustomInput);
els.rotateBtn.addEventListener("click", () => {
const temp = state.w;
state.w = state.h;
state.h = temp;
updateDimensions();
});
// Recalculate scale on window resize
window.addEventListener("resize", applyIntelligentScale);
// Bootstrap
initTheme();
updateDimensions();
renderPreview();
</script>
</body>
</html>