import React, { forwardRef, useImperativeHandle } from 'react';
import { useParticleSystem } from '../hooks/useParticleSystem';
import type { ParticleSystemProps, ParticleSystemRef } from '../types';
/**
* Declarative particle system component for React Three Fiber.
*
* Renders a three.quarks ParticleSystem with full configuration via props.
* Must be used within a QuarksProvider.
*
* @example
* ```tsx
* import { QuarksProvider, ParticleSystem } from 'quarks.r3f'
* import { ConeEmitter, SizeOverLife, Bezier } from 'three.quarks'
*
*
*
*
* ```
*/
export const ParticleSystem = forwardRef(
function ParticleSystem(props, ref) {
const { position, rotation, scale, ...systemProps } = props;
const { system, emitter, play, pause, restart, stop } = useParticleSystem(systemProps);
// Expose ref API
useImperativeHandle(ref, () => ({
system,
emitter,
play,
pause,
restart,
stop,
}), [system, emitter, play, pause, restart, stop]);
// Render the emitter as a primitive with transform props
// R3F will apply position/rotation/scale to the Object3D
return (
);
}
);