import type { Engine , RecursivePartial } from "tsparticles" ; import { IConfettiOptions } from "./IConfettiOptions" ; import { loadOptions } from "./options" ; import { tsParticles } from "tsparticles" ; function loadPreset ( engine , confettiOptions , override = false ) { engine . addPreset ( "confetti" , loadOptions ( confettiOptions ) , override ) ; } export function loadConfettiPreset ( main ) { loadPreset ( main , { } , true ) ; } type ConfettiOptions = RecursivePartial < IConfettiOptions > ; type ConfettiFirstParam = string | ConfettiOptions ; export function confetti ( idOrOptions , confettiOptions ? ) { let options ; let id ; if ( typeof idOrOptions === "string" ) { id = idOrOptions ; options = confettiOptions ?? { } ; } else { id = `tsparticles_${ Math . floor ( Math . random ( ) * 1000 ) }` ; options = idOrOptions ; } loadPreset ( tsParticles , options , true ) ; tsParticles . load ( id , { preset : "confetti" } ) ; }