const { log } = consoleconst {max} = Math;// โญ๏ธ importimport { $, $all, elem } from'./js/ext/Node_ext.js'; // Node extension// --------------------------------------------------------------------let lastX; // tracks the last observed mouse X positionconstbar=$("#bar");constspan=$('#width');span.textContent =bar.offsetWidth +'px';// bar.onmousedownbar.addEventListener("mousedown", event => {// โญ๏ธ left mouse down // -> 1. register window.onmousemove // -> 2. prevent selectionif (event.button ===0) { lastX =event.clientX;// โญ๏ธ the "mousemove" handler is registered on the whole `window`. // Even if the mouse goes outside of the bar during resizing, // as long as the button is held we still want to update its size.window.addEventListener("mousemove", onDrag);log(`โ window.onmousemove: handler registered ...`);// โญ๏ธ prevent selection (not working for tablets?)event.preventDefault(); }});// window.onmousemovefunctiononDrag(event) {// โญ๏ธ when mouse button released (stops dragging) -> stop resizing// when `event.buttons = 0`, no buttons are down. (note the plural)if (event.buttons ===0) {window.removeEventListener("mousemove", onDrag);log(`โ window.onmousemove: handler removed ...`);return; }// โญ๏ธ when mouse button held (dragging) -> resize barlet dx =event.clientX - lastX;let newWidth =max(10,bar.offsetWidth + dx); // width >= 10pxbar.style.width = newWidth +"px";span.textContent = newWidth +'px'; lastX =event.clientX;}