import { X as UserConstraint, B as Body } from './UserConstraint-VjSG2l0b.cjs'; /** * Constraint type detection and the UserConstraint codec contract, shared by * the JSON and binary serializers. * * Types are detected with `instanceof`, never `constructor.name`: the * published bundle is minified, so class names do not survive it. */ /** * Tells the serializers how to save and rebuild one `UserConstraint` subclass. * * A UserConstraint's state lives in fields only its subclass knows about, so * it cannot be captured generically. Pass a codec per subclass in * {@link SerializationOptions.userConstraints} — to both the save and the * load call. Without one, instances of that subclass are skipped when saving. * * The base constraint properties (`active`, `stiff`, `frequency`, `damping`, * `maxForce`, `breakUnderForce`, …) and JSON `userData` are saved and * re-applied by the serializer; the codec only handles the subclass's own state. * * @example * ```ts * const ropeCodec: UserConstraintCodec = { * type: "my-game/Rope", // stable — stored in the snapshot * ctor: Rope, * bodies: (c) => [c.body1, c.body2], * save: (c) => ({ length: c.length }), * load: (data, [b1, b2]) => new Rope(b1, b2, data.length as number), * }; * const options = { userConstraints: [ropeCodec] }; * const restored = spaceFromJSON(spaceToJSON(space, options), options); * ``` */ interface UserConstraintCodec { /** * Stable identifier stored in the snapshot. Do not derive it from the class * name — minifiers rename classes. */ type: string; /** The subclass this codec handles; matched with `instanceof`. */ ctor: abstract new (...args: any[]) => T; /** The bodies the constraint links, in the order `load` receives them. */ bodies(constraint: T): (Body | null)[]; /** The subclass's own state. Must survive `JSON.stringify` / `JSON.parse`. */ save(constraint: T): Record; /** Rebuild the constraint from `save()`'s output and the restored bodies. */ load(data: Record, bodies: (Body | null)[]): T; } /** Options shared by `spaceToJSON` / `spaceFromJSON` / `spaceToBinary` / `spaceFromBinary`. */ interface SerializationOptions { /** Codecs for the `UserConstraint` subclasses in the space. */ userConstraints?: readonly UserConstraintCodec[]; } export type { SerializationOptions as S, UserConstraintCodec as U };