import { StudioBase } from "./StudioBase" ; import { Display } from "./screen" ; import { Updater } from "./animation/Updater" ; import { System } from "./System" ; import { HistoryService } from "bp/content/changes" ; import { Migration } from "bp/content/patches" ; import { ViewService } from "bp/env/service" ; import type { StudioOptions } from "./StudioOptions" ; import type { Design } from "bp/design" ; import type { JDesign } from "bp/content/json" ; /**
 *  Studio 類別是程式的真正起點，是內部的最上層類別。
 * 它同時負責管理專案的開啟、關閉以及輸出。
  @ shrewd export class Studio extends StudioBase { public readonly $system : System ; public readonly $designMap : Map < number , Design > = new Map ( ) ; public readonly $el : HTMLElement ; public readonly $display : Display ; public readonly $option : StudioOptions ; public readonly $updater : Updater ; constructor ( selector ) { super ( ) ; let el = document . querySelector ( selector ) ; if ( el == null || ! ( el instanceof HTMLElement ) ) { throw new Error ( "selector is not valid" ) ; } this . $option = { } ; this . $el = el ; this . $display = new Display ( this ) ; this . $system = new System ( this ) ; this . $updater = new Updater ( this ) ; Migration . $onDeprecate = ( title ? ) => this . $option . onDeprecate ?. ( title ) ; ViewService . $initialize ( ) ; HistoryService . $initialize ( ) ; } public $createBpsBlob ( id ? ) { let design = id === undefined ? this . $design : this . $designMap . get ( id ) ; if ( ! design ) return null ; let bps = JSON . stringify ( design ) ; return new Blob ( [ bps ] , { type : "application/bpstudio.project+json" } ) ; } protected _tryLoad ( design ) { let result = super . _tryLoad ( design ) ; this . $updater . $update ( ) ; return result ; } protected _designFactory ( design ) { let result = super . _designFactory ( design ) ; result . $LayoutSheet . onZoom = result . $TreeSheet . onZoom = ( zoom ) => this . $display . $zoom ( zoom ) ; this . $updater . $active = true ; return result ; } }