JSFiddle - React, Tailwind, and code Playground

by Daniel Kuschny

HTML

<script src="https://cdn.jsdelivr.net/npm/@coderline/alphatab@latest/dist/alphaTab.js"></script>
<button id="play">
Play
</button>
<div id="alphaTab">   
 </div>

CSS

/* Styles for player */
.at-cursor-bar {
  /* Defines the color of the bar background when a bar is played */
  background: rgba(255, 242, 0, 0.25);
}

.at-selection div {
  /* Defines the color of the selection background */
  background: rgba(64, 64, 255, 0.1)
}

.at-cursor-beat {
  /* Defines the beat cursor */
  background: rgba(64, 64, 255, 0.75);
  width: 3px;
}

.at-highlight * {
  /* Defines the color of the music symbols when they are being played (svg) */
  fill: #0078ff;
  stroke: #0078ff;
}

.at-selection-handles {
    position : absolute;
    pointer-events: none;
    z-index: 1001;
    display: inline;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.at-selection-handle {
    position : absolute;
    pointer-events: auto;
    cursor: ew-resize;
    background: #7cb9ff;
    width: 4px;
    opacity: 0;
    transition: opacity 150ms ease-in-out;
    display: none;
}

.at-selection-handle:hover,
.at-selection-handle.at-selection-handle-drag {
    opacity: 1;
}

.at-selection-handle.active {
    display: block;
}

.at-selection-handle-drag *  {
    cursor: ew-resize !important;
}

TypeScript

// Just to make JS Fiddle happy some Types
declare namespace alphaTab {
  type AlphaTabApi = any;
  namespace model {
    type Beat = any;
  }
  namespace rendering {
    type BeatBounds = any;
  }
}
const alphaTab = (globalThis as any).alphaTab;
// end of JS Fiddle types

const el = document.getElementById('alphaTab');
let at = new alphaTab.AlphaTabApi(el, {
  player: {
    enablePlayer: true,
    soundFont:
      'https://cdn.jsdelivr.net/npm/@coderline/alphatab@alpha/dist/soundfont/sonivox.sf2',
  },
});

function createSelectionHandles(element: HTMLElement): { startHandle: HTMLElement; endHandle: HTMLElement } {
    const handleWrapper = document.createElement('div');
    handleWrapper.classList.add('at-selection-handles');
    element.insertBefore(handleWrapper, element.querySelector('at-surface'));

    const startHandle = document.createElement('div');
    startHandle.classList.add('at-selection-handle', 'at-selection-handle-start');
    handleWrapper.appendChild(startHandle);

    const endHandle = document.createElement('div');
    endHandle.classList.add('at-selection-handle', 'at-selection-handle-end');
    handleWrapper.appendChild(endHandle);

    return { startHandle, endHandle };
}

interface HandleDragState {
    isDragging: 'start' | 'end' | undefined;
}
function setupHandleDrag(
    element: HTMLElement,
    handle: HTMLElement,
    dragState: HandleDragState,
    type: HandleDragState['isDragging'],
    onMove: (e: MouseEvent) => void,
    onDragEnd: (e: MouseEvent) => void
) {
    handle.addEventListener(
        'mousedown',
        e => {
            e.preventDefault();
            element.classList.add('at-selection-handle-drag');
            handle.classList.add('at-selection-handle-drag');
            dragState.isDragging = type;
        },
        false
    );
    document.addEventListener(
        'mousemove',
        e => {
            if (dragState.isDragging !== type) {
 ...