import type { Mountable } from "bp/class" ; import type { View } from "bp/view/class/View" ; /**
 *  ViewService 服務定義了  Mountable 和  View 物件之間的抽象轉換關係。
  export namespace ViewService { const resolve = [ ] ; const map = new WeakMap ( ) ; let init = false ; export function $initialize ( ) { init = true ; } /** 註冊對應關係 */ export function $register ( ctor , V ) { resolve . push ( [ ctor , V ] ) ; } export function $contains ( target , point ) { if ( ! init ) return false ; let view = map . get ( target ) ; if ( ! view ) return false ; view . $draw ( ) ; return view . $contains ( point ) ; } /** 對於給定的  Mountable 創造出對應的  View export function $createView ( target ) { if ( ! init ) return ; let view ; for ( let [ ctor , V ] of resolve ) { if ( target instanceof ctor ) { view = new V ( target ) ; break ; } } if ( view ) map . set ( target , view ) ; } export function $get ( target ) { if ( ! init ) return null ; return map . get ( target ) ?? null ; } }