Skip to content

Commit 9fa5c78

Browse files
committed
update
1 parent dc1536c commit 9fa5c78

2 files changed

Lines changed: 108 additions & 16 deletions

File tree

site/app.js

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,17 @@ async function copyText(value, button) {
192192
flashCopied(button);
193193
}
194194

195-
function setSplitFromClientX(clientX) {
195+
function setSplitFromPointer(clientX, clientY) {
196196
const rect = els.split.getBoundingClientRect();
197+
const isVertical = window.matchMedia("(max-width: 900px)").matches;
198+
199+
if (isVertical) {
200+
const raw = ((clientY - rect.top) / rect.height) * 100;
201+
const clamped = Math.max(20, Math.min(80, raw));
202+
document.documentElement.style.setProperty("--top-height", `${clamped}%`);
203+
return;
204+
}
205+
197206
const raw = ((clientX - rect.left) / rect.width) * 100;
198207
const clamped = Math.max(20, Math.min(80, raw));
199208
document.documentElement.style.setProperty("--left-width", `${clamped}%`);
@@ -302,33 +311,82 @@ function initEvents() {
302311

303312
els.input.addEventListener("scroll", syncYamlScroll, { passive: true });
304313

305-
els.divider.addEventListener("pointerdown", (event) => {
306-
if (window.matchMedia("(max-width: 900px)").matches) {
307-
return;
308-
}
314+
const startDrag = (clientX, clientY) => {
309315
dragging = true;
310-
els.divider.setPointerCapture(event.pointerId);
311-
setSplitFromClientX(event.clientX);
312-
});
316+
document.body.style.userSelect = "none";
317+
document.body.classList.add("is-resizing");
318+
setSplitFromPointer(clientX, clientY);
319+
};
313320

314-
els.divider.addEventListener("pointermove", (event) => {
321+
const moveDrag = (clientX, clientY) => {
315322
if (!dragging) {
316323
return;
317324
}
318-
setSplitFromClientX(event.clientX);
319-
});
325+
setSplitFromPointer(clientX, clientY);
326+
};
320327

321-
els.divider.addEventListener("pointerup", (event) => {
328+
const stopDrag = () => {
322329
if (!dragging) {
323330
return;
324331
}
325332
dragging = false;
326-
els.divider.releasePointerCapture(event.pointerId);
333+
document.body.style.userSelect = "";
334+
document.body.classList.remove("is-resizing");
335+
};
336+
337+
els.divider.addEventListener("pointerdown", (event) => {
338+
event.preventDefault();
339+
startDrag(event.clientX, event.clientY);
327340
});
328341

329-
els.divider.addEventListener("pointercancel", () => {
330-
dragging = false;
342+
window.addEventListener("pointermove", (event) => {
343+
moveDrag(event.clientX, event.clientY);
331344
});
345+
window.addEventListener("pointerup", stopDrag);
346+
window.addEventListener("pointercancel", stopDrag);
347+
348+
els.divider.addEventListener("mousedown", (event) => {
349+
if (event.button !== 0) {
350+
return;
351+
}
352+
event.preventDefault();
353+
startDrag(event.clientX, event.clientY);
354+
});
355+
356+
window.addEventListener("mousemove", (event) => {
357+
moveDrag(event.clientX, event.clientY);
358+
});
359+
window.addEventListener("mouseup", stopDrag);
360+
361+
els.divider.addEventListener(
362+
"touchstart",
363+
(event) => {
364+
const touch = event.touches[0];
365+
if (!touch) {
366+
return;
367+
}
368+
event.preventDefault();
369+
startDrag(touch.clientX, touch.clientY);
370+
},
371+
{ passive: false },
372+
);
373+
374+
window.addEventListener(
375+
"touchmove",
376+
(event) => {
377+
const touch = event.touches[0];
378+
if (!touch) {
379+
return;
380+
}
381+
if (dragging) {
382+
event.preventDefault();
383+
}
384+
moveDrag(touch.clientX, touch.clientY);
385+
},
386+
{ passive: false },
387+
);
388+
window.addEventListener("touchend", stopDrag);
389+
window.addEventListener("touchcancel", stopDrag);
332390

333391
els.copyYamlBtn?.addEventListener("click", () => {
334392
void copyText(els.input.value, els.copyYamlBtn);

site/styles.css

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
--line: rgba(130, 110, 89, 0.22);
99
--muted: #6d675f;
1010
--left-width: 50%;
11+
--top-height: 50%;
1112
--copy-bg: #f8f1e8;
1213
--copy-border: #cbbca9;
1314
--copy-text: #2d241d;
@@ -254,7 +255,7 @@ body::before {
254255
}
255256

256257
.divider {
257-
width: 10px;
258+
width: 8px;
258259
cursor: col-resize;
259260
border-left: 1px solid var(--line);
260261
border-right: 1px solid var(--line);
@@ -263,6 +264,8 @@ body::before {
263264
linear-gradient(180deg, rgba(64, 102, 255, 0.18), rgba(17, 200, 220, 0.18));
264265
position: relative;
265266
flex: 0 0 auto;
267+
touch-action: none;
268+
z-index: 8;
266269
}
267270

268271
.divider::before {
@@ -280,6 +283,29 @@ body::before {
280283
3px 0 0 rgba(115, 121, 147, 0.55);
281284
}
282285

286+
.divider::after {
287+
content: "";
288+
position: absolute;
289+
inset: 0;
290+
left: -6px;
291+
right: -6px;
292+
}
293+
294+
.divider:hover {
295+
box-shadow:
296+
inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
297+
0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
298+
}
299+
300+
body.is-resizing .panel-left,
301+
body.is-resizing .panel-right {
302+
pointer-events: none;
303+
}
304+
305+
body.is-resizing .divider {
306+
pointer-events: auto;
307+
}
308+
283309
.panel-head {
284310
position: relative;
285311
display: flex;
@@ -710,6 +736,14 @@ pre {
710736
width: 100%;
711737
}
712738

739+
.panel-left {
740+
height: var(--top-height);
741+
}
742+
743+
.panel-right {
744+
height: calc(100% - var(--top-height));
745+
}
746+
713747
.panel {
714748
min-width: 0;
715749
}

0 commit comments

Comments
 (0)