import { component } from 'web-cell'; import { Observable } from 'iterable-observer'; @component({ tagName: 'split-view', mode: 'open' }) export class SplitView extends HTMLElement { connectedCallback() { this.classList.add('d-flex', 'w-100'); } toggleDrag({ type, target, pointerId }: PointerEvent) { if (type !== 'pointerup') (target as HTMLElement).setPointerCapture(pointerId); else (target as HTMLElement).releasePointerCapture(pointerId); } async watchLine(element: HTMLElement) { const moving = Observable.fromEvent( element, 'pointermove' ), left = element.previousElementSibling as HTMLElement; const { style } = left, { x } = left.getBoundingClientRect(); for await (const { pointerId, clientX } of moving) if (element.hasPointerCapture(pointerId)) style.width = clientX - x + 'px'; } render() { return ( <>
); } }