

export const attachTransformRuntime = (config: {
  canvas: any;
  handleMoving: (event: any) => void;
  handleScaling: (event: any) => void;
  handleRotating: (event: any) => void;
}) => {
  const { canvas, handleMoving, handleScaling, handleRotating } = config;
  canvas.on('object:moving', handleMoving);
  canvas.on('object:scaling', handleScaling);
  canvas.on('object:rotating', handleRotating);

  return {
    bind() {
      canvas.on('object:moving', handleMoving);
      canvas.on('object:scaling', handleScaling);
      canvas.on('object:rotating', handleRotating);
    },
    unbind() {
      try { canvas.off?.('object:moving', handleMoving); } catch {}
      try { canvas.off?.('object:scaling', handleScaling); } catch {}
      try { canvas.off?.('object:rotating', handleRotating); } catch {}
    },
  };
};
