All files / player-skin-sdk/src types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
import type { ChartPlayVariant } from '@be-music/chart-model';
import type {
  CourseView,
  JudgmentKind,
  JudgmentTiming,
  LaneCover,
  PlayOptionChoices,
  PlaySide,
} from '@be-music/player-scene-model';
import type { BeMusicAudioFrame } from './audio.ts';
import type { BeMusicPlayOptions } from './play-options.ts';
import type { BeMusicResultData, GaugeHistorySample, ScoreHistorySample } from './result-data.ts';
import type { BeMusicSkinSetting, BeMusicSkinSettingValues } from './settings.ts';
import type {
  BeMusicCourseBestRecord,
  BeMusicDanRank,
  BeMusicChartImageKind,
  BeMusicChartBestRecord,
  LibraryChart,
  LibraryCourse,
  LibraryEntry,
} from './chart.ts';
 
/**
 * Be-Music Skin format — the code-defined skins the built-in (default) family renders with when no LR2 / beatoraja
 * theme is loaded. Unlike LR2 / beatoraja themes (data files interpreted by a scene), a Be-Music Skin draws screens
 * onto Canvas surfaces or mounts native DOM screens. Canvas drawing can use the Canvas 2D API, raw WebGL / WebGPU, or a
 * framework such as PixiJS or three.js that the skin brings along. The player owns input, timing, audio, judging, and
 * layout, and supplies plain frame data and semantic actions to the skin.
 *
 * Nothing here depends on a rendering framework. Skins are written against the `@be-music/player-skin-sdk` package
 * and declared with its `defineBeMusicSkin`, which checks {@link BeMusicSkin.apiVersion} and the metadata.
 * Hosts pick one with {@link BeMusicSkin.id} from a registry (`createBeMusicSkinRegistry`) and hand it to the scenes in
 * the built-in family's kit (`{ family: 'built-in', skin }`).
 */
export interface BeMusicSkin<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  /** Native DOM screens and a DOM gameplay HUD, mounted independently from Canvas surfaces. */
  readonly dom?: import('./dom.ts').BeMusicDOMSkin;
  /**
   * The skin API revision the skin was written against (`BE_MUSIC_SKIN_API_VERSION` when it was built). Hosts refuse a
   * skin whose revision they don't support and fall back to a built-in one.
   */
  readonly apiVersion: number;
  /** Stable identifier (persisted by hosts, e.g. `'phantom'`). */
  readonly id: string;
  /** Human-readable name for pickers. */
  readonly label: string;
  /** The skin's own release, as a semantic version (`'1.2.0'`). */
  readonly version: string;
  /** Who made the skin. */
  readonly author: BeMusicSkinAuthor;
  /** One or two sentences for skin pickers. */
  readonly description?: string;
  /** Where to find the skin (project page, repository). */
  readonly homepage?: string;
  /** SPDX license identifier of the skin's code and assets (`'MIT'`). */
  readonly license?: string;
  /**
   * CSS font shorthands (`'400 24px "Anton"'`) the skin draws with. Hosts should load the faces (e.g. via Google Fonts)
   * and may `document.fonts.load` these before mounting so the first frame doesn't rasterize with a fallback face.
   */
  readonly fontLoads: readonly string[];
  /** Design canvas the skin draws on and where its gameplay BGA sits. Defaults to the 16:9 `wideStage`. */
  readonly stage?: BeMusicStage;
  /**
   * Design canvas for screens taller than wide (a phone or tablet held upright), e.g. the 9:16 `tallStage`. Hosts draw
   * on it while the screen is portrait, and on {@link stage} otherwise; gameplay stays on {@link stage} for play modes
   * too wide for a portrait playfield (see `supportsPortraitLayout`). A skin without one is always drawn on
   * {@link stage}, scaled down to fit a portrait screen. Pick between the two with `resolveBeMusicStage`.
   */
  readonly portraitStage?: BeMusicStage;
  /** Which canvas context the player creates for each surface. */
  readonly context: K;
  /** Attributes passed to `canvas.getContext` (e.g. `{ alpha: true }`, `{ antialias: true, stencil: true }`). */
  readonly contextAttributes?: CanvasRenderingContext2DSettings | WebGLContextAttributes;
  /**
   * Called once for every new surface before its first draw — create a framework renderer on the canvas, compile
   * shaders, request a GPU device. Drawing waits until a returned promise settles.
   */
  setup?(surface: BeMusicSurface<K>): void | Promise<void>;
  /** Called when the player is done with a surface — release what `setup` created (renderers, GPU resources). */
  teardown?(surface: BeMusicSurface<K>): void;
  readonly gameplay: BeMusicGameplaySkin<K>;
  readonly select: BeMusicSelectSkin<K>;
  readonly result: BeMusicResultSkin<K>;
  /**
   * The decide screen shown between picking a chart and the play (title card, stage file, the chosen options). Hosts
   * mount it only when a skin declares one, and go straight from select to gameplay otherwise.
   */
  readonly decide?: BeMusicDecideSkin<K>;
  /**
   * Options the player can tune for this skin (a colour theme, a judge-text offset, an effect toggle). Hosts build
   * their settings UI from this schema, persist the values per skin, and hand them back on every frame as `settings`,
   * already checked and filled in by {@link resolveBeMusicSkinSettings}. Ids must be unique.
   */
  readonly settings?: readonly BeMusicSkinSetting[];
}
 
/** A skin's maker, as shown in skin pickers and credits. */
export interface BeMusicSkinAuthor {
  readonly name: string;
  /** Profile, home page, or contact URL. */
  readonly url?: string;
}
 
/** Canvas rendering contexts a skin can draw with. */
export interface BeMusicSurfaceContextMap {
  '2d': CanvasRenderingContext2D;
  webgl: WebGLRenderingContext;
  webgl2: WebGL2RenderingContext;
  webgpu: GPUCanvasContext;
}
 
export type BeMusicSurfaceContextKind = keyof BeMusicSurfaceContextMap;
 
/**
 * The canvas a skin draws one screen on. It is sized to the device pixels the stage covers on screen, so drawing at
 * `pixelRatio` canvas pixels per design pixel shows dot by dot.
 */
export interface BeMusicSurface<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  canvas: HTMLCanvasElement;
  context: BeMusicSurfaceContextMap[K];
  /** Size in design pixels (the stage size). */
  width: number;
  height: number;
  /**
   * Which of the skin's stages this surface is drawn on: `'portrait'` for {@link BeMusicSkin.portraitStage},
   * `'landscape'` otherwise. Absent means `'landscape'`. The stage (and with it the surface's size) can change between
   * draws when the screen rotates.
   */
  orientation?: BeMusicStageOrientation;
  /** Canvas pixels per design pixel. `'2d'` surfaces come cleared and pre-scaled by it; other contexts apply it. */
  pixelRatio: number;
}
 
/** Axis-aligned rectangle in design pixels. */
export interface BeMusicRect {
  x: number;
  y: number;
  w: number;
  h: number;
}
 
/** Whether a stage is wider than tall (`'landscape'`) or taller than wide (`'portrait'`). */
export type BeMusicStageOrientation = 'landscape' | 'portrait';
 
/** A skin's design canvas (see {@link BeMusicSkin.stage} and {@link BeMusicSkin.portraitStage}). */
export interface BeMusicStage {
  readonly width: number;
  readonly height: number;
  /** Optional lane bounds in design pixels, shared by rendering, note placement and touch input. */
  readonly playfield?: Partial<
    Record<
      GameplayLayoutMode,
      {
        readonly top: number;
        readonly judgementY: number;
        /** Shrinks wide lane banks to leave room for a side HUD; narrower banks retain their widths. */
        readonly maxRight?: number;
        /**
         * Centres a double-play playfield (10 / 14 KEY, and a two-player battle) on this x, so the HUD can sit on both
         * sides of it. The keyboard modes (24 / 48 KEY) and single play keep their place.
         */
        readonly doublePlayCenterX?: number;
        /** Places independent players at opposite edges, leaving the monitor between them. */
        readonly twoPlayerSideInset?: number;
      }
    >
  >;
 
  /**
   * The gameplay BGA rect for a playfield whose rightmost lane ends at `playfieldRight` and leftmost starts at
   * `playfieldLeft`. The scene composites the BGA here and the skin frames the same rect, so the BGA can make room for
   * wide (double play / keyboard) playfields. `twoPlayer` identifies independent banks placed around a central BGA.
   */
  /** Keeps BGA videos at their source aspect; the monitor may widen while retaining its height. */
  readonly fitBGAVideoAspect?: boolean;
  resolveBGARect(playfieldRight: number, playfieldLeft?: number, twoPlayer?: boolean): BeMusicRect;
 
  /**
   * Makes the stage fluid: the host calls it with a design size of the screen's aspect ratio
   * (`resolveFluidStageSize`: the stage's short side kept, its long side following the screen) and draws on the stage
   * it returns, so the screen has no letterbox bars. The host skips it when the screen is turned the other way from the
   * stage (a double play chart kept on the landscape stage of an upright screen). Without it the stage keeps its size
   * and is letterboxed into the screen.
   */
  resize?(size: { width: number; height: number }): BeMusicStage;
}
 
/**
 * How much showmanship a skin should put on: `'full'` (everything), `'reduced'` (no screen shake / full-screen flashes,
 * lighter particle counts — also the sensible default for `prefers-reduced-motion`), or `'off'` (static chrome and a
 * plain hit flash only).
 */
export type BeMusicEffectLevel = 'full' | 'reduced' | 'off';
 
/** A judgement grade, best first (`JudgmentKind` of `@be-music/player-scene-model`). */
export type BeMusicJudgmentKind = JudgmentKind;
 
/** A play side. `'2P'` only exists in double play (`PlaySide` of `@be-music/player-scene-model`). */
export type BeMusicSide = PlaySide;
 
/** An image the host hands a skin (song images, BGA layers): anything `drawImage` / `texImage2D` accepts. */
export type BeMusicImage = CanvasImageSource;
 
/**
 * Visual class of a lane, resolved from its channel — skins pick colours per class. `'wheel-up'` / `'wheel-down'` are
 * the 24 / 48 KEY modes' wheel lanes, on the outer edge of each side where the That-Which-Must-Not-Be-Named modes keep their scratch: draw them
 * apart from the keys (like a scratch) and show which way each one turns.
 */
export type BeMusicLaneKind = 'white' | 'black' | 'scratch' | 'wheel-up' | 'wheel-down';
 
/** One lane of the gameplay layout, in design pixels. */
export interface BeMusicLayoutLane {
  channel: string | undefined;
  kind: BeMusicLaneKind;
  side: BeMusicSide;
  x: number;
  w: number;
}
 
/**
 * Where everything sits on the gameplay stage this frame, as the host resolved it: the stage size, every lane, the
 * playfield's bounds and judgement line, and the BGA rect (from the skin's {@link BeMusicStage}). Skins place their
 * chrome from this instead of computing geometry themselves, so host-side layout changes (double play, keyboard
 * modes, new aspect ratios) reach every skin.
 */
/**
 * How the host lays out the gameplay screen. `'standard'` is the cabinet-style playfield; `'touch'` is for playing on a
 * touch screen: wide, equal-width lanes across most of the stage, a low judgement line, and (on a landscape stage) no
 * BGA.
 */
export type GameplayLayoutMode = 'standard' | 'touch';
 
export interface BeMusicGameplayLayout {
  /** Independent players (including a side-playfield ghost), rather than one double-play chart. */
  twoPlayer?: boolean;
  /**
   * The layout mode the host resolved. Optional so a layout built by hand stays valid; absent means `'standard'`. In
   * `'touch'` the lanes and playfield bounds already describe the touch geometry and `bga` is `undefined` on a
   * landscape stage, so a skin placing its chrome from this layout needs no mode check — read it only to restyle
   * something for touch play.
   */
  mode?: GameplayLayoutMode;
  /**
   * The orientation of the stage the layout is for. Optional so a layout built by hand stays valid; absent means
   * `'landscape'`. On a portrait stage the lanes span the stage's width in its lower part and the BGA sits above them in
   * both layout modes.
   */
  orientation?: BeMusicStageOrientation;
  stage: { width: number; height: number };
  lanes: readonly BeMusicLayoutLane[];
  playfield: {
    /** Left edge of the leftmost lane / right edge of the rightmost lane. */
    left: number;
    right: number;
    centerX: number;
    /** Top of the lanes, and the judgement line notes land on. */
    top: number;
    judgementY: number;
    /**
     * How far down (negative: up) the player moved the judgment and combo from where the skin puts them, in stage
     * pixels. Absent means 0. A skin adds it to its own judgment position.
     */
    judgeOffsetY?: number;
    /** Horizontal extent of each play side present (`2P` only in double play). */
    sides: Partial<
      Record<BeMusicSide, { left: number; right: number; /** Actual line after per-side LIFT. */ judgementY?: number }>
    >;
  };
  /** The BGA rect, or `undefined` when the playfield leaves no room for one. */
  bga: BeMusicRect | undefined;
}
 
/** How a judgment's timing reads: early, late, or on the note's time. */
export type BeMusicJudgeDetailTone = 'fast' | 'slow' | 'just';
 
/**
 * A judgment's timing as the player asked to see it beside the judgment: `FAST` / `SLOW`, or the offset in
 * milliseconds. `lane` is set when the keys' and the scratch's timing are shown apart.
 */
export interface BeMusicJudgeDetail {
  text: string;
  tone: BeMusicJudgeDetailTone;
  lane?: 'keys' | 'scratch';
}
 
/** One side's recent judgement. */
export interface BeMusicJudgmentState {
  side: BeMusicSide;
  /** PERFECT / GREAT / GOOD / BAD / POOR. Empty when no recent judge. */
  judge?: string;
  combo?: number;
  /**
   * The judge detail to draw with the judgment, when the player turned it on: none, one, or the keys' and the
   * scratch's. Absent or empty means nothing is drawn. A skin draws each `text` in its tone's colour.
   */
  details?: readonly BeMusicJudgeDetail[];
}
 
/** The 2P player's live values in a two-player play (LR2 BATTLE): its own score, combo and gauge. */
export interface BeMusicSecondPlayerRuntime {
  score: number;
  exScore: number;
  exScoreMax: number;
  combo: number;
  maxCombo: number;
  perfect: number;
  great: number;
  good: number;
  bad: number;
  poor: number;
  /** The gauge in percent (0..100). */
  gauge: number;
  clearThreshold?: number;
  gaugeLabel?: string;
  gaugeSurvival?: boolean;
  rank?: string;
}
 
/** The song a NONSTOP play's song info crossfades away from ({@link BeMusicGameplayRuntime.songInfoFade}). */
export interface BeMusicSongInfoFade {
  chartTitle?: string;
  chartArtist?: string;
  chartGenre?: string;
  /** 0 (the old song alone) to 1 (the new song alone). */
  progress: number;
}
 
/** Live gameplay values for the HUD. */
export interface BeMusicGameplayRuntime {
  /** The song's title, artist and genre: in a NONSTOP play, those of the stage being played. */
  chartTitle?: string;
  chartArtist?: string;
  chartGenre?: string;
  /**
   * While a NONSTOP play's song info crossfades into the next stage's (`chartTitle` and friends are already the new
   * song's): the song it replaces, and how far the crossfade is, 0 (the old song alone) to 1 (the new song alone). A skin
   * draws the old song at `1 - progress` and the new one at `progress`; one that ignores it switches at once.
   */
  songInfoFade?: BeMusicSongInfoFade;
  /** BPM at the playhead: follows the chart's tempo changes (and holds through stops), not just its header BPM. */
  bpm?: number;
  hiSpeed?: number;
  /** Active measured AC floating-speed controls; omitted outside floating mode. */
  floatingHiSpeed?: true;
  score?: number;
  exScore?: number;
  exScoreMax?: number;
  combo?: number;
  maxCombo?: number;
  perfect?: number;
  great?: number;
  good?: number;
  bad?: number;
  poor?: number;
  gauge?: number;
  clearThreshold?: number;
  laneCount?: number;
  laneChannels?: readonly string[];
  playVariant?: ChartPlayVariant;
  /** PERFECT / GREAT / GOOD / BAD / POOR. Empty when no recent judge. */
  lastJudge?: string;
  /** Per-side judgement snapshots. DP renderers can paint 1P / 2P independently from these values. */
  judgeSides?: readonly BeMusicJudgmentState[];
  /** AAA / AA / A / B / C / D / E / F. */
  rank?: string;
  /** The 2P player of a two-player play (LR2 BATTLE); every other figure here is the 1P player's. */
  secondPlayer?: BeMusicSecondPlayerRuntime;
  autoplay?: boolean;
  /** The play is a practice play: a PRACTICE-mode run, or one a seek made practice. */
  practice?: boolean;
  hasBGA?: boolean;
  /** Monotonic play clock (ms) for animation. */
  nowMs?: number;
  /** Song progress in [0, 1] — drives a progress track. */
  progressRatio?: number;
  /** Fractional beat position in [0, 1) — drives beat-synced pulses. */
  beatPhase?: number;
  /** Absolute chart beat, including BPM changes and stops, for beat-synchronised motion. */
  chartBeat?: number;
  /** Directional turntable input, on the pause-aware play clock. */
  scratchInputs?: Readonly<Record<string, { angle: number; direction: 1 | -1; atMs: number }>>;
  /** Input brightness by lane channel, 0 to 1, including the release fade. */
  keyBeams?: Readonly<Record<string, number>>;
  /** Side occupied by a replay ghost, when presented beside the live play. */
  ghostSide?: BeMusicSide;
  /** Active compat ruleset id (`lr2` / `beatoraja` / `____`). */
  rulesetLabel?: string;
  /** Ruleset-scoped gauge id (`GROOVE` / `HARD` / `HAZARD` / ...) labelling the gauge. */
  gaugeLabel?: string;
  /** True for survival gauges — no clear notch. */
  gaugeSurvival?: boolean;
  /** FAST (early GREAT/GOOD) count. */
  fast?: number;
  /** SLOW (late GREAT/GOOD) count. */
  slow?: number;
  /** Playable notes in the chart (0 while unknown). */
  totalNotes?: number;
  /**
   * Milliseconds since the chart's first beat: negative during the intro count-in, `undefined` before the play has
   * been scheduled. Lets chrome stage entrance cut-ins against the real start.
   */
  chartMs?: number;
  /** True while the chart's audio / BGA are still loading (or a BGA video is transcoding) before the play starts. */
  loading?: boolean;
  /** Estimated asset preparation progress from 0 to 1 while loading, when supplied by the host. */
  loadingProgress?: number;
  /** Play-clock ms of the most recent judgement — drives the judge / combo "punch". */
  judgeAtMs?: number;
  /** Play-clock ms and lane class of the most recent key press (or autoplay hit) — drives input-reactive visuals. */
  impulseAtMs?: number;
  impulseKind?: BeMusicLaneKind;
  /** Showmanship level to render at (defaults to `'full'`). */
  effects?: BeMusicEffectLevel;
  /** Live analysis of the mix for audio-reactive chrome (loudness, spectrum, onsets); absent without Web Audio. */
  audio?: BeMusicAudioFrame;
  /**
   * The chart being played — level, difficulty, `#RANK`, `#TOTAL` and the rest of its header via
   * `song.chart.metadata`, plus the same images {@link BeMusicGameplayFrame.chartImage} resolves.
   */
  chart?: LibraryChart;
  /**
   * Signed timing offset (ms) of the most recent timed judgement: positive when the press was late (SLOW), negative
   * when early (FAST), 0 dead on. Only judgements with a timing carry one — autoplay hits, mine BADs and missed notes
   * (POOR without a press) leave it unchanged.
   */
  lastJudgeDeltaMs?: number;
  /**
   * The most recent timed judgements (at most 64), oldest first — drives timing meters. Same rules as
   * {@link lastJudgeDeltaMs}.
   */
  judgeTimings?: readonly BeMusicJudgmentTiming[];
  /**
   * `true` when the player turned the judgment counts off: a skin draws no count of PGREAT to POOR, no FAST / SLOW
   * count and no timing meter during the play. Absent means they are drawn.
   */
  hidesJudgeCounts?: boolean;
  /** SUDDEN+ / HIDDEN+ / LIFT per play side, as fractions of the lane height. */
  laneCovers?: readonly BeMusicLaneCover[];
  /**
   * How long (ms) a note stays on screen, from the edge of the lane cover to the judgement line, at the current speed —
   * BPM, hi-speed and the chart's `#SCROLL` × `#SPEED` at the playhead. 0 while the chart scrolls backwards or stands
   * still, as beatoraja shows it.
   */
  visibleMs?: number;
  /** That-Which-Must-Not-Be-Named-style green number (`visibleMs × 0.6`): the note's on-screen time in frames at 60 Hz. */
  greenNumber?: number;
  /**
   * Lowest, highest, and main BPM of the chart. The main BPM is the BPM the most notes sit at (beatoraja's), the one
   * HS-FIX `'AVERAGE'` pegs the hi-speed to and the replay's `visibleMs` is taken at.
   */
  minBPM?: number;
  maxBPM?: number;
  mainBPM?: number;
  /**
   * Length of the song (ms) and how far the audio has played (ms), on the audio clock: it stops while paused and
   * starts at 0 when the song starts. Remaining time is `songLengthMs - songElapsedMs`. Unlike {@link chartMs}, which is
   * measured from the chart's first beat and runs negative through the count-in, this measures the song as heard.
   */
  songLengthMs?: number;
  songElapsedMs?: number;
  /**
   * Play-clock ms (the {@link nowMs} clock) of moments that happen at most once per play, latched when they occur and
   * `undefined` before: the gauge failing mid-play, the last playable note being judged, and the chart's end (the
   * outro).
   */
  failedAtMs?: number;
  allNotesDoneAtMs?: number;
  outroAtMs?: number;
  /**
   * Play-clock ms when the gauge first rose above its starting value, and when it first reached its maximum.
   * `undefined` until it happens.
   */
  gaugeRiseAtMs?: number;
  gaugeMaxAtMs?: number;
  /**
   * EX-score and gauge samples taken at every judgement so far, the same series the result screen receives. They are
   * the host's live arrays, shared by reference: read them, never mutate them.
   */
  scoreHistory?: readonly ScoreHistorySample[];
  gaugeHistory?: readonly GaugeHistorySample[];
  /**
   * The judge windows of the active ruleset, in ms. Resolved from the chart's `#RANK` when the play starts; a mid-chart
   * `#EXRANK` change is not reflected.
   */
  judgeWindows?: BeMusicJudgeWindows;
  /** The player's best EX score on the chart before this play (MY BEST); omitted without a best record. */
  bestEXScore?: number;
  /**
   * The pacemaker's EX score over the whole chart and its name, when the host sets one; without it a score graph paces
   * against the AAA line ({@link resolveScorePace}).
   */
  targetEXScore?: number;
  /**
   * The pacemaker's EX score at this point of the play, when the host knows it (a replay ghost, at the notes the play
   * has judged); without it a score graph holds {@link targetEXScore} to the share of the chart's notes judged.
   */
  targetPaceEXScore?: number;
  targetLabel?: string;
  /** The course and the stage being played, for a course stage or a NONSTOP run. */
  course?: CourseView;
  /** The signed-in player's name, when the host has one. */
  playerName?: string;
  /** The play tempo: 1 at the chart's own speed; a play at another tempo is practice. */
  tempo?: number;
  /** The 1P lane option (`OFF`, `RANDOM`, `MIRROR`, ...); the 2P player's is not shown. */
  random1P?: string;
}
 
/**
 * One timed judgement: when it happened and how far off the press was. `deltaMs` is positive when late (SLOW) and
 * negative when early (FAST). See {@link binJudgmentTimings} for a histogram. `JudgmentTiming` of `@be-music/player-scene-model`.
 */
export type BeMusicJudgmentTiming = JudgmentTiming;
 
/** One play side's lane covers, as fractions (0..1) of the lane height (`LaneCover` of `@be-music/player-scene-model`). */
export type BeMusicLaneCover = LaneCover;
 
/** One judge window: how early and how late (both positive ms) a press still earns the grade. */
export interface BeMusicJudgeWindow {
  earlyMs: number;
  lateMs: number;
}
 
/** The windows of one note class; `emptyPoor` is the window for an empty POOR, when the ruleset has one. */
export type BeMusicJudgeWindowSet = Record<'perfect' | 'great' | 'good' | 'bad', BeMusicJudgeWindow> & {
  emptyPoor?: BeMusicJudgeWindow;
};
 
/** The active ruleset's judge windows per note class. */
export interface BeMusicJudgeWindows {
  note: BeMusicJudgeWindowSet;
  scratch: BeMusicJudgeWindowSet;
  /** The release of a long note that judges its end (charge / hell charge notes). */
  longNoteEnd: BeMusicJudgeWindowSet;
}
 
export interface BeMusicLaneFrame {
  channel: string;
  kind: BeMusicLaneKind;
  x: number;
  w: number;
  top: number;
  /** Judgement line y — notes land with their bottom edge here. */
  bottom: number;
  /** Key-beam intensity in [0, 1]: 1 while held, decaying after release. */
  beam: number;
  /** Play-clock ms of the lane's last key press and release (also for autoplay hits). */
  pressedAtMs?: number;
  releasedAtMs?: number;
  /** True while a long note in this lane is held, and the play-clock ms the hold started. */
  holding?: boolean;
  holdStartedAtMs?: number;
  /**
   * While {@link holding}: the y of the held long note's top this frame (its end as it falls, or the lane's `top` while
   * the end is still above the lane). Hold effects that rise from the judgement line stay under it, so they never cover
   * the end the player lets go at (see `HoldSparkOptions.maxRise`).
   */
  holdTop?: number;
}
 
/**
 * A tap note as drawn this frame: its lane rect and the y its bottom edge sits at. In a chart with a negative `#SCROLL`
 * a note still ahead can sit below the judgement line, down to the bottom of the stage (the player draws such charts
 * the way beatoraja does); clip to the lane's `bottom` to keep nothing below the line.
 */
export interface BeMusicNote {
  /** Source visibility opacity (0..1); omitted means fully visible. Multiply by the skin's own opacity. */
  alpha?: number;
  kind: BeMusicLaneKind;
  x: number;
  w: number;
  y: number;
  /** True when autoplay (or auto-scratch) will hit this note. */
  autoplay?: boolean;
}
 
/**
 * A mine (landmine) note as drawn this frame: its lane rect and the y its bottom edge sits at (below the judgement line
 * when a negative `#SCROLL` puts it there, as for {@link BeMusicNote}). A mine detonates when its lane
 * is held as it crosses the judgement line (under the LR2 ruleset also on a press inside the PGREAT window) and drains
 * the gauge, so draw it as something to avoid. Only handed to skins that set
 * {@link BeMusicGameplaySkin.drawsMines}.
 */
export interface BeMusicMine {
  /** Source visibility opacity (0..1); omitted means fully visible. Multiply by the skin's own opacity. */
  alpha?: number;
  kind: BeMusicLaneKind;
  x: number;
  w: number;
  y: number;
}
 
/**
 * A long note as drawn this frame: its lane rect, tail (top) and head (bottom, held on the line once passed). Like
 * {@link BeMusicNote}, it can reach below the judgement line when a negative `#SCROLL` puts it there.
 */
export interface BeMusicLongNote {
  /** Source visibility opacity (0..1); omitted means fully visible. Multiply by the skin's own opacity. */
  alpha?: number;
  kind: BeMusicLaneKind;
  x: number;
  w: number;
  top: number;
  bottom: number;
  /**
   * How the long note judges: `'ln'` (only the start counts), `'cn'` (charge note: the release is judged too), or
   * `'hcn'` (hell charge note: the gauge drains while it isn't held).
   */
  mode?: BeMusicLongNoteMode;
  /**
   * True when the long note is a back-spin scratch (BSS): a charge note (`'cn'` / `'hcn'`) on a scratch lane, whose tail
   * is judged on a spin the other way rather than on the release (`isBackSpinScratchLongNote`). The built-in skins mark
   * its tail cap with a chevron (`backSpinChevron`); `resolveLongNoteMarks` gathers the marks of every kind.
   */
  backSpinScratch?: boolean;
  /**
   * Where the long note is in its life (see {@link BeMusicLongNoteState}). LR2 draws a dropped long note at half alpha
   * until it goes; the built-in skins do the same. A hell charge note reads `'held'` while it fills the gauge and
   * `'draining'` while it empties it; `resolveHellChargeLook` turns that into a look.
   */
  state?: BeMusicLongNoteState;
  /**
   * Milliseconds since the player let go of this long note early and it was judged dropped; omitted otherwise (also for a
   * long note missed at the head). The built-in skins fade the body's centre line out over this time.
   */
  releasedElapsedMs?: number;
  /** True when autoplay (or auto-scratch) plays this long note. */
  autoplay?: boolean;
}
 
export type BeMusicLongNoteMode = 'ln' | 'cn' | 'hcn';
 
/**
 * Where a long note is in its life:
 *
 * - `'pending'`: not reached yet.
 * - `'held'`: being held. A hell charge note reads `'held'` while it fills the gauge: held, or its tail released at
 *   GOOD or better until the tail passes.
 * - `'draining'`: a hell charge note whose lane is up while it passes the judgement line (let go early, or missed at
 *   the head), so it empties the gauge. It is not lost: pressing the lane makes it fill the gauge again (`'held'`).
 *   Only a hell charge note (`mode: 'hcn'`, a hell-charge back-spin scratch included) reads `'draining'`.
 * - `'dropped'`: missed at the head or let go early, for good (a hell charge note once its tail has passed).
 * - `'done'`: completed.
 */
export type BeMusicLongNoteState = 'pending' | 'held' | 'draining' | 'dropped' | 'done';
 
export interface BeMusicBomb {
  channel: string;
  kind: BeMusicLaneKind;
  x: number;
  w: number;
  /** Judgement line y of the lane. */
  y: number;
  /** Milliseconds since the hit. */
  elapsedMs: number;
  /** Stable per-hit seed so particle scatter doesn't shimmer frame to frame. */
  seed: number;
  /** The judgement that set the hit off. */
  judge?: BeMusicJudgmentKind;
}
 
/**
 * A measure (bar) line crossing one lane run, as drawn this frame. Like {@link BeMusicNote}, it can sit below the
 * judgement line when a negative `#SCROLL` puts it there.
 */
export interface BeMusicMeasureLine {
  /** Source visibility opacity (0..1); omitted means fully visible. Multiply by the skin's own opacity. */
  alpha?: number;
  side: BeMusicSide;
  /** Left edge and width of the lane run it crosses. */
  x: number;
  w: number;
  y: number;
}
 
/**
 * The BGA layers showing this frame, for a skin that composites the BGA itself ({@link BeMusicGameplaySkin.drawsBGA}).
 * Following the BMS convention, the host hands {@link layer} with pure black (`#000000`) already turned transparent,
 * while {@link base} and {@link poor} are opaque: draw the base and both overlays with plain alpha blending, without keying them again.
 * A bmson layer (whose spec keeps black opaque) and a video layer come as authored. `#SWBGA` animation frames are
 * already picked. Channel opacity (0B–0E) is supplied in `opacity`; the legacy per-slot ARGB tint interpretation
 * remains separate from nanasi's channel-scoped ARGB commands.
 *
 * Images come at their authored size. The BGA rect stands for a 256x256 canvas: to match other BMS players, draw a
 * still image whose long edge is at most 256 px at its own size on that canvas, centered horizontally and against the
 * top edge, and stretch a larger image or a video over the whole rect.
 */
export interface BeMusicBGAFrame {
  /** HDX placement in the BGA viewport: fill, top-centred 100%, or top-centred 80%. Clip to the viewport. */
  bgaMode?: 0 | 1 | 2;
  /** Authored BGA sub-region placement on the 256×256 canvas; other images retain normal placement. */
  origins?: Partial<Record<'base' | 'layer' | 'layer2' | 'poor', { x: number; y: number }>>;
  /** Authored channel opacity (0..1) for each plane; omitted means opaque. */
  opacity?: { base: number; layer: number; layer2: number; poor: number };
  /** NONSTOP stages in back-to-front order, each with its own layers, opacity and crossfade weight. */
  stacks?: Array<Omit<BeMusicBGAFrame, 'stacks'> & { alpha: number }>;
  /** The base layer (`#BMP` on channel 04), or a video frame. */
  base?: BeMusicImage;
  /** The layer drawn over the base (channel 07). */
  layer?: BeMusicImage;
  /** The second overlay (channel 0A), drawn above layer. */
  layer2?: BeMusicImage;
  /** The miss image (channel 06), shown while {@link poorActive}. */
  poor?: BeMusicImage;
  /** True while a POOR is being shown: replace the base and both overlays unless {@link poorOverlays} is true. */
  poorActive: boolean;
  /** Draw the miss image over the normal layers (`#POORBGA 1`), instead of replacing them. */
  poorOverlays?: boolean;
}
 
/**
 * Looks up one of a song's images (`#STAGEFILE`, `#BANNER`, `#BACKBMP`). Images load lazily: the first calls return
 * `undefined` while the image decodes, and the screen is redrawn (on select, `revision` moves) once it is ready. Also
 * `undefined` when the song has no such image or the host doesn't provide images. Look the image up on every draw rather
 * than keeping it: hosts cache a bounded number and may close the least recently used one.
 */
export type BeMusicChartImageLookup = (
  chartEntry: LibraryChart,
  kind: BeMusicChartImageKind,
) => ImageBitmap | undefined;
 
/** Everything on the gameplay screen this frame. */
export interface BeMusicGameplayFrame {
  nowMs: number;
  /** HUD values: score, combo, gauge, judgements, song, loading, … */
  runtime: BeMusicGameplayRuntime;
  /** Stage, lanes, playfield bounds, judgement line, and the BGA rect (leave it transparent: the video is behind). */
  layout: BeMusicGameplayLayout;
  /** Every lane with its key-beam intensity. */
  lanes: readonly BeMusicLaneFrame[];
  notes: readonly BeMusicNote[];
  longNotes: readonly BeMusicLongNote[];
  /** Mine notes still ahead of the player. Always empty unless the skin sets {@link BeMusicGameplaySkin.drawsMines}. */
  mines: readonly BeMusicMine[];
  /** Live hit effects with their age. */
  bombs: readonly BeMusicBomb[];
  /**
   * Measure lines on screen, one per lane run they cross. Always empty unless the skin sets
   * {@link BeMusicGameplaySkin.drawsMeasureLines}.
   */
  measureLines: readonly BeMusicMeasureLine[];
  /** The BGA layers to composite. Always `undefined` unless the skin sets {@link BeMusicGameplaySkin.drawsBGA}. */
  bga: BeMusicBGAFrame | undefined;
  /** Fractional beat position in [0, 1). */
  beatPhase: number;
  effects: BeMusicEffectLevel;
  audio: BeMusicAudioFrame | undefined;
  /** The player's values for the skin's {@link BeMusicSkin.settings}. */
  settings: BeMusicSkinSettingValues;
  chartImage: BeMusicChartImageLookup;
}
 
/** What a BPM GUIDE label marks: a BPM change, a STOP, a `#SCROLL` change or a `#SPEED` change. */
export type BeMusicGuideLabelKind = 'bpm' | 'stop' | 'scroll' | 'speed';
 
/**
 * The look of the BPM GUIDE labels the player draws over the lanes ({@link BeMusicGameplaySkin.guideLabel}). Without
 * one they take beatoraja's monospace, a size relative to the lanes, and its green and yellow (cyan and violet for
 * `#SCROLL` and `#SPEED`). Colours are `0xRRGGBB`; a label's line takes its colour.
 */
export interface BeMusicGuideLabelStyle {
  /** A CSS font family; load the font through {@link BeMusicSkin.fontLoads}. */
  readonly fontFamily: string;
  /** A CSS font weight, such as `'500'`. */
  readonly fontWeight?: '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | 'normal' | 'bold';
  /** In stage pixels. */
  readonly fontSize?: number;
  readonly colors?: Readonly<Partial<Record<BeMusicGuideLabelKind, number>>>;
}
 
/**
 * The look of the lane covers (SUDDEN+, HIDDEN+ and LIFT) the player paints for a skin ({@link BeMusicGameplaySkin.laneCover}).
 * A cover is opaque: `color` fills it, and diagonal stripes of `stripeColor` at `stripeAlpha` run across it, moving
 * with the cover's inner edge. Colours are `0xRRGGBB`.
 */
export interface BeMusicLaneCoverStyle {
  readonly color: number;
  readonly stripeColor: number;
  /** 0..1. */
  readonly stripeAlpha: number;
  /** A line along the cover's inner edge (the one facing the notes), when set. */
  readonly edgeColor?: number;
  /** 0..1; default 1. */
  readonly edgeAlpha?: number;
}
 
export interface BeMusicGameplaySkin<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  /** Draws one gameplay frame. Called once per frame, right before the player renders. */
  draw(surface: BeMusicSurface<K>, frame: BeMusicGameplayFrame): void;
  /** How long a hit effect lives (ms) before the player retires it. Default 300. */
  readonly bombDurationMs?: number;
  /**
   * Set to `true` when the skin draws mine notes itself from `frame.mines`. Otherwise the player draws them over the
   * skin in its own built-in style, so a skin written before mines reached the frame still shows them.
   */
  readonly drawsMines?: boolean;
  /**
   * Set to `true` when the skin draws the lane covers (SUDDEN+ / HIDDEN+) itself from `runtime.laneCovers`. Otherwise
   * the player draws its own covers over the skin.
   */
  readonly drawsLaneCover?: boolean;
  /** The look of the BPM GUIDE labels and lines the player draws over the skin's lanes. */
  readonly guideLabel?: BeMusicGuideLabelStyle;
  /**
   * How the player paints its lane covers over the skin when {@link drawsLaneCover} is unset: their colour and the
   * faint stripes on them. Without it the covers are black with faint grey stripes.
   */
  readonly laneCover?: BeMusicLaneCoverStyle;
  /**
   * Set to `true` when the skin draws measure lines itself from `frame.measureLines`. Otherwise the player draws its
   * own lines.
   */
  readonly drawsMeasureLines?: boolean;
  /**
   * Set to `true` when the skin composites the BGA itself from `frame.bga`. Otherwise the player shows the BGA behind
   * the skin's canvas, in {@link BeMusicGameplayLayout.bga}.
   */
  readonly drawsBGA?: boolean;
  /**
   * Set to `true` when the skin's DOM gameplay screen ({@link BeMusicSkin.dom}) draws the playfield from
   * `drawPlayfield`. Hosts that mount it create no Canvas surface for gameplay and may take their own canvas out of the
   * page; {@link draw} remains for hosts without DOM screens. Nothing the player draws shows then, so such a skin also
   * draws the BGA, mines, lane covers and measure lines ({@link drawsBGA}, {@link drawsMines}, {@link drawsLaneCover},
   * {@link drawsMeasureLines}).
   */
  readonly drawsOnDOM?: boolean;
}
 
/** Song-list geometry shared by the skin (drawing) and the scene (row hit-testing). */
export interface BeMusicSelectLayout {
  listX: number;
  listTop: number;
  /** Distance from the canvas bottom to the list's last row edge. */
  listBottomInset: number;
  rowHeight: number;
}
 
export interface BeMusicSelectActions {
  play: () => void;
  autoPlay: () => void;
  /** Opens the practice setup for the focused chart, when supported by the host. */
  practice?: () => void;
  activateSearch: () => void;
  /** Sets one play option. Values outside the option's choices are ignored. */
  setPlayOption<K extends keyof BeMusicPlayOptions>(key: K, value: BeMusicPlayOptions[K]): void;
  /** Moves one play option to its next (`step` 1, the default) or previous (`-1`) choice, wrapping around. */
  cyclePlayOption(key: keyof BeMusicPlayOptions, step?: 1 | -1): void;
  /** Opens or closes the focused song's readme (the `.txt` beside the chart), when it has one. */
  toggleReadme: () => void;
}
 
/**
 * The values each play option can take, for options with a fixed set of choices (numeric ones are left out):
 * `PlayOptionChoices` of `@be-music/player-scene-model`.
 */
export type BeMusicPlayOptionChoices = PlayOptionChoices;
 
/** Everything on the select screen this frame. */
export interface BeMusicSelectFrame {
  designWidth: number;
  designHeight: number;
  nowMs: number;
  /**
   * Increases whenever the select state changes (cursor, folder, search, list contents). Skins that keep a scene graph
   * can rebuild it only when this moves.
   */
  revision: number;
  /** `performance.now()` when the scene was (re)shown — drives entrance animations. */
  sceneStartedAt: number;
  /** `performance.now()` of the last cursor move — drives focus transitions. */
  cursorChangedAt: number;
  entries: readonly LibraryEntry[];
  selectedIndex: number;
  /** First entry index drawn in the list window, and how many rows fit (see `resolveSelectListWindow`). */
  firstVisibleIndex: number;
  visibleRows: number;
  /**
   * Design pixels the list is pulled past its resting place toward later entries (negative: toward earlier ones), less
   * than one row: a finger dragging it, a list gliding after a swipe, or a trackpad mid-scroll. Each whole row turns
   * into a cursor step, so it stays under a row either way, and it is 0 at rest and where the window can't move (the
   * list's ends). Draw the rows that much higher, as `selectListRows` lays them out, and the list follows the finger;
   * a skin that ignores it scrolls a row at a time.
   */
  listScroll: number;
  focusedChart: LibraryChart | undefined;
  /**
   * The course bar under the cursor (`undefined` on a chart or folder bar, and from hosts that predate it). PLAY and
   * AUTO start it; {@link describeCourseCard} gives the lines a card shows for it.
   */
  focusedCourse?: LibraryCourse;
  /** Current folder label (or search label), `undefined` at the library root. */
  folderLabel: string | undefined;
  /** Folder labels from the library root to the current folder. Older hosts may omit this. */
  folderPath?: readonly string[];
  searchQuery: string;
  /**
   * True while the host's text field sits over the search box (the box the skin bound to `actions.activateSearch`):
   * the player is typing there, so draw the box but not its text or placeholder. Absent or false otherwise.
   */
  searchEditing?: boolean;
  totalCharts: number;
  /**
   * Whether the chart under the cursor has a README (a `.txt` file beside it) for {@link BeMusicSelectActions.toggleReadme}
   * to show: draw a README button enabled only then. Absent from hosts that predate it.
   */
  hasReadme?: boolean;
  actions: BeMusicSelectActions;
  effects: BeMusicEffectLevel;
  /** `performance.now()` when a chart was launched and the skin's outro is playing, otherwise `undefined`. */
  launchAt: number | undefined;
  /** What is playing right now: the BGM or the chart preview (see {@link BeMusicAudioFrame}). */
  audio: BeMusicAudioFrame | undefined;
  /** The current play options; change them through {@link BeMusicSelectActions.setPlayOption}. */
  playOptions: Readonly<BeMusicPlayOptions>;
  /** The choices of every play option that has a fixed set. */
  playOptionChoices: BeMusicPlayOptionChoices;
  /** The pointer in design pixels, or `undefined` when it is outside the screen (or there is none). */
  pointer: { x: number; y: number } | undefined;
  /** The player's best record on `song`, or `undefined` when the host keeps none (or it was never played). */
  chartBestRecord(chartEntry: LibraryChart): BeMusicChartBestRecord | undefined;
  /**
   * The player's best record on `course` (a course bar), or `undefined` when the host keeps none, the course was never
   * played, or it is a random course or a NEW COURSE bar. Absent from hosts that predate it.
   */
  courseBestRecord?(course: LibraryCourse): BeMusicCourseBestRecord | undefined;
  /**
   * The player's dan rank in each key mode they hold one in, fewest keys first, under the judge ruleset whose records
   * the screen shows. Empty before any GRADE course is cleared; absent from hosts that keep none.
   */
  danRanks?: readonly BeMusicDanRank[];
  chartImage: BeMusicChartImageLookup;
  /** The player's values for the skin's {@link BeMusicSkin.settings}. */
  settings: BeMusicSkinSettingValues;
  /**
   * Makes the rect (design pixels) run `action` when clicked — e.g. `frame.hit(x, y, w, h, frame.actions.play)`. Hit
   * areas last for the frame they were declared in, so declare them on every draw. `cursor` is the CSS cursor shown
   * over the rect (`'pointer'` by default). Returns whether the pointer is over the rect, for hover states.
   */
  hit(x: number, y: number, w: number, h: number, action: () => void, cursor?: string): boolean;
}
 
export interface BeMusicSelectSkin<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  /** Where the song list sits (the player hit-tests the rows with it). */
  readonly layout: BeMusicSelectLayout;
  /**
   * Where the song list sits on the skin's {@link BeMusicSkin.portraitStage}. Defaults to {@link layout}. See
   * `resolveBeMusicSelectLayout`.
   */
  readonly portraitLayout?: BeMusicSelectLayout;
  /** Search text size in design pixels, shared by the drawn placeholder and the native editing field. */
  readonly searchTextSize?: number;
  readonly portraitSearchTextSize?: number;
  /** Length of the launch outro (ms) the select screen keeps drawing after a chart is picked. Default 0. */
  readonly outroMs?: number;
  /** Draws one select frame. Called every frame while the select screen is shown. */
  draw(surface: BeMusicSurface<K>, frame: BeMusicSelectFrame): void;
}
 
/** Everything on the result screen this frame. */
export interface BeMusicResultFrame {
  designWidth: number;
  designHeight: number;
  result: BeMusicResultData;
  /** That-Which-Must-Not-Be-Named DJ level (`AAA` … `F`). */
  rankLabel: string;
  /** EX-score rate in percent. */
  ratePercent: number;
  /** Milliseconds since the scene mounted, or `Infinity` once the player skipped the entrance. */
  elapsedMs: number;
  /**
   * Milliseconds since the scene mounted, going on after the entrance is skipped or settles: for what keeps moving while
   * the result is shown, such as a course card's stage list scrolling (`resolveResultCourseScroll`).
   */
  shownMs: number;
  nowMs: number;
  effects: BeMusicEffectLevel;
  chartImage: BeMusicChartImageLookup;
  /** The player's values for the skin's {@link BeMusicSkin.settings}. */
  settings: BeMusicSkinSettingValues;
}
 
export interface BeMusicResultSkin<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  /** Draws one result frame. Called every frame while the result screen is shown. */
  draw(surface: BeMusicSurface<K>, frame: BeMusicResultFrame): void;
}
 
/** Everything on the decide screen this frame. */
export interface BeMusicDecideFrame {
  designWidth: number;
  designHeight: number;
  nowMs: number;
  /** Milliseconds since the screen mounted. */
  elapsedMs: number;
  /** The chart about to be played. */
  chart: LibraryChart;
  /** The options the play will run with. */
  playOptions: Readonly<BeMusicPlayOptions>;
  chartImage: BeMusicChartImageLookup;
  effects: BeMusicEffectLevel;
  /** The player's values for the skin's {@link BeMusicSkin.settings}. */
  settings: BeMusicSkinSettingValues;
  audio: BeMusicAudioFrame | undefined;
}
 
export interface BeMusicDecideSkin<K extends BeMusicSurfaceContextKind = BeMusicSurfaceContextKind> {
  /**
   * How long (ms) the screen shows before the play starts. Default 2000. The player can skip ahead (Enter) or go back to
   * select (Escape) meanwhile.
   */
  readonly durationMs?: number;
  /** Draws one decide frame. Called every frame while the decide screen is shown. */
  draw(surface: BeMusicSurface<K>, frame: BeMusicDecideFrame): void;
}