import Scene , { SceneItem , Frame } from "scenejs" ; import { hasClass as hasClass2 , addClass as addClass2 , removeClass as removeClass2 , } from "@daybrush/utils" ; import { prefixNames } from "framework-utils" ; import { PREFIX } from "./consts" ; export function prefix ( ... classNames ) { return prefixNames ( PREFIX , ... classNames ) ; } export function findSceneItemByElementStack ( element , scene ) { let target = element ; let item = null ; while ( target && ! item ) { item = findSceneItemByElement ( target , scene ) ; if ( ! item ) { target = target . parentElement ; } } if ( ! target || ! item ) { return [ null , null ] ; } return [ target , item ] ; } export function findSceneItemByElement ( element , scene ) { let target = null ; if ( ! scene ) { return null ; } if ( isScene ( scene ) ) { scene . forEach ( item => { if ( target ) { return ; } target = findSceneItemByElement ( element , item ) ; } ) ; } else { const elements = scene . getElements ( ) ; if ( elements . indexOf ( element ) > - 1 ) { return scene ; } } return target ; } export function hasClass ( target , className ) { return hasClass2 ( target , `${ PREFIX }${ className }` ) ; } export function addClass ( target , className ) { return addClass2 ( target , `${ PREFIX }${ className }` ) ; } export function removeClass ( target , className ) { return removeClass2 ( target , `${ PREFIX }${ className }` ) ; } export function isScene ( value ) { return value && ! ! ( value . constructor as typeof Scene ) . prototype . getItem ; } export function isSceneItem ( value ) { return value && ! ! ( value . constructor as typeof SceneItem ) . prototype . getFrame ; } export function isFrame ( value ) { return value && ! ! ( value . constructor as typeof Frame ) . prototype . toCSS ; }