import { toJS } from 'mobx' ; /**
 * simple deep clone polyfill
 */ function cloneDeepPolyfill < T > ( src ) { const map = new Map ( ) ; function _cloneDeep < T > ( src ) { if ( src && typeof src === 'object' ) { if ( map . has ( src ) ) { return map . get ( src ) ; } const ret = ( Array . isArray ( src ) ? [ ] : { } ) as T ; map . set ( src , ret ) ; for ( const key of Object . keys ( src ) as Array < keyof T > ) { ret [ key ] = _cloneDeep ( src [ key ] ) ; } return ret ; } else { return src ; } } const ret = _cloneDeep ( src ) ; map . clear ( ) ; return ret ; } /**
 * native deep clone or simple polyfill
 */ export function cloneDeep < T > ( src ) { if ( typeof window . structuredClone === 'function' ) { return window . structuredClone ( toJS ( src ) ) ; } else { return cloneDeepPolyfill ( toJS ( src ) ) ; } } /**
 * escape simple xss chars
 */ export function xssEscape ( str ) { return str . replace ( /[<>&]/g , ( c ) => { switch ( c ) { case '<' : return '&lt;' ; case '>' : return '&gt;' ; case '&' : return '&amp;' ; default : return c ; } } ) ; }